Skip to content

Nvidia GPU offloading for "hybrid" mode

Robin Lange edited this page Oct 31, 2020 · 6 revisions

Since version 435.17 the Nvidia driver can be used in "offloading" mode, meaning it can render frames without being connected to a display server and send them to another GPU that will handle the presentation.

In practice for Optimus laptop users, it means you can have your desktop running on the low-power Intel GPU and only use the Nvidia GPU for intensive applications such as games. This is very similar to how Optimus works on Windows, and is provided by the hybrid mode of optimus-manager.

Requirements

You need a recent version of the Nvidia driver and the X server package. The versions currently in the stable repositories of Archlinux and Manjaro should work.

To check if offloading is available, switch to hybrid mode with optimus-manager and run xrandr --listproviders. You must see a line ending with name:NVIDIA-G0 (maybe with a different number).

Caveats

One major limitation of the GPU offloading method is that the nvidia kernel module has to be running when the X server starts, and cannot be unloaded afterwards. Which means that the usual power-off method such as bbswitch cannot be used, and the GPU will keep consuming power, even if you are not running any application on it. The power draw is relatively low since the card automatically downclocks itself, but still much higher than intel mode with power management options like bbswitch (when they work). It will impact your battery life.

There is an exception to this: is if your system is recent enough, there is a chance that it may support advanced power management from inside the Nvidia driver, allowing it to be fully turned off when not in use. Check out the power management wiki for more details. But beware that this is still an experimental feature.

It used to be that external video outputs wired to the Nvidia card would not work in hybrid mode, but this feature was added in driver version 450.51.

Setup

Unlike Windows, GPU-intensive applications are not automatically sent to the more powerful card. You need to set three environment variables:

  • __NV_PRIME_RENDER_OFFLOAD=1
  • __GLX_VENDOR_LIBRARY_NAME="nvidia"
  • __VK_LAYER_NV_optimus="NVIDIA_only"

Any OpenGL or Vulkan application running with those variables will be offloaded to the Nvidia GPU. See the official Nvidia documentation for more details.

It is not recommended to set those variables system-wide (like in /etc/environment), since it would defeat the point of hybrid mode, and can also break desktop compositing on some environment (resulting in a black screen).

Alternatively, you can install the package nvidia-prime and use the launcher prime-run, which sets those variables for you.

For applications running from command line

Here is an example with the test application glxgears from the package mesa-demos:

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME="nvidia" __VK_LAYER_NV_optimus="NVIDIA_only" __GL_SHOW_GRAPHICS_OSD=1 glxgears

Or alternatively with nvidia-prime :

__GL_SHOW_GRAPHICS_OSD=1 prime-run glxgears

The variable __GL_SHOW_GRAPHICS_OSD=1 is not required for offloading but displays an FPS overlay specific to Nvidia. If you see it, it means glxgears is running on the Nvidia GPU.

Here is what you should see (notice the Nvidia overlay):

glxgears_offloading

For Steam

To have Steam launch a game on the Nvidia GPU, set its launch options to

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME="nvidia" __VK_LAYER_NV_optimus="NVIDIA_only" %command%

or

prime-run %command%

If you already had launch options for this game, you can add them back after %command%.

Another option is to offload Steam itself to the GPU. In this case, every game you launch from Steam will run on the Nvidia GPU.

For Lutris

Similarly, you can make Lutris use the Nvidia GPU by having it set those three environment variables before launching a game. See the Lutris Wiki for this.