Running Java/Minecraft with the Nvidia GPU

12,619

Solution 1

First,

Inside your 'NVIDIA X Server Settings' window, underneath a drop-down menu called something like "GPU 0 (GeForce GTX .....)" there is an option for creating Application Profiles appropriately titled such. Click it.

Creating Application Profiles

Once in this window, you should see two tabs. One called Rules, and the other called Profiles. Click the Profiles tab and then click the green plus button just beneath it to add a new profile.Name this profile what you want (something memorable) and add all listed settings (They're what Minecraft actually needs and avoids redundancies):

  • GLAllowFXAAUsage = true
  • GLGSyncAllowed = true
  • GLShaderDiskCache = true
  • GLThreadedOptimizations = true
  • GLSyncToVblank = true

Once your list is complete and looks like mine, click the green plus button at the bottom of the window to save the current profile.

Select the setting from the drop-down menu under the "Source File" entry and click the green plus button to add it to the list.

Source File should be left alone. This is the location where these profile settings are saved. Ubuntu generates this location for you by default. DO NOT edit this.

Adding New Profiles

Next,

We need to add rules to this profile such as, which process ID's can utilize it's power and if this rule applies to all programs that use the GPU.

Click the rules tab and add a new rule using the green plus button. In a section of this window called Rule Pattern there's a drop-down menu and a text entry. In the drop-down menu select Always Applies and in the text entry field type Java.

In a section called Rule Profile there should be a drop-down menu. Click on that and select the Profile you just created. A list of all the NVIDIA GL settings you added should appear in the list space below. If this is true for you click the green plus button at the bottom of the window to save.

Adding New Rules

Then,

If you have followed all these steps correctly your NVIDIA x Server Settings Application Profiles window on Rules tab should look something like this:

| Priority  | Pattern    | Profile Settings
--------------------------------------------
| 1         | [true]Java | GLAllowFXAAUsage=true,GL... 

Completed Application Profile Example

Lastly,

Save the new configuration you just created by clicking the disk icon with the green down arrow.

You may now close the NVIDIA Server Settings window, start Minecraft and Enjoy. If you have any questions pertaining to this thread or my post, or if you have any issues with this configuration please let me know. Use my profile link.


EXTRAS

In the rules tab, you can create a new rule with the Always Applies feature to the process ID of a running instance of Minecraft. Use the terminal and type

ps -U root -u root -N

locate a process called Java. Looks like this:

4307 tty1     01:44:08 java

Copy the PID number (in my case: 4307) and use that in the text entry labeled "Matches this String". Save and exit.

NOTE: This doesn't work all the time and has to be updated frequently because the PID changes.

Solution 2

I've done it! I've found it! I found a hack that works!

Make a script at any desired location. Save the file path for later. I personally put mine at ~/.minecraft/launch.sh. Copy and paste the following:

#!/bin/bash
/usr/bin/prime-run /usr/bin/java "$@"

Your java or prime-run executables may be found somewhere else. To find them, simply type these into your terminal

which java
which prime-run

prime-run is used by Nvidia to launch any program using the GPU. I installed prime-run by installing the proprietary Nvidia drivers. See instructions by your Linux distro on how to install them.

The $@ variable contains all the arguments passed to the script.

Don't forget to make the script executable!

chmod +x ~/.minecraft/launch.sh

Open up the Minecraft launcher, and go to the Installations tab. You'll have to do this with each installation, which is fine for me since I usually play on the latest Fabric release.

Installations Tab, Hovering over "edit."

Once you've hit Edit, you'll want to hit the MORE OPTIONS submenu at the bottom, and change the Java executable path.

The "more options" submenu, highlighting "Java Executable"

Find the script from above, and set it as the new "executable." Load up the game, join a world, press F3 and double check that it's using your Nvidia GPU!

Without the GPU: enter image description here With the GPU: F3 debug menu, showcasing the GPU being used. (To notice the differences, look at the top right for the hardware list.)


This is more of a hack than anything, but it works and now I can play modded and stream without my laptop dying on me. I hope this helps everyone well.

EDIT: Don't place the script in the ~/.minecraft/launcher/launch.sh directory. Whenever the launcher updates, it'll be removed. Placing it outside the directory, over in ~/.minecraft/launch.sh works fine.

EDIT 2: If you ever get stuck on the "Finalizing" stage when launching, it's because the launch.sh script isn't executable! Make sure to add the executable bit onto the file.

EDIT 3: Make sure the Bash arguments are quoted! If they aren't quoted, then this means that not all arguments will be respected, which could lead to lower or higher ram usage than specified.

Share:
12,619

Related videos on Youtube

A Person Who Dislikes Windows
Author by

A Person Who Dislikes Windows

Updated on September 18, 2022

Comments

  • A Person Who Dislikes Windows
    A Person Who Dislikes Windows over 1 year

    I have ripped the web up trying to figure this out. Bumblebee hasn't helped. I want to run Minecraft on the Nvidia GPU in my laptop. As far as I can tell, Ubuntu default runs it with Intel because Minecraft runs inside of Java, which, obviously, is not generally GPU intensive. I'm using Bionic Beaver, and the optirun command is broken. It throws an error that the nvidia-fallback.service is disabled, but trying to enable it reveals that the file doesn't exist. As far as I can tell, this is a Bionic Beaver problem. The primusrun command seems to work, but now I can't make it run Minecraft specifically. I feel like the problem could be fixed with an Nvidia application profile for Java runtime, but I don't understand the documentation on Nvidia's website. If someone can just post a rule key that forces an application to use Nvidia (and actually works; I found one, but it's "not recognized"), that would be great.

    specs: Lenovo y520 laptop i5 CPU Intel 620 HD/Nvidia geforce 1050 ti 8 gb ram Ubuntu 18.04

    if I missed any specs, please tell me, I'm new to posting questions.

  • Flo
    Flo about 4 years
    Very good information! Do you know how enable SLI?