I enabled the new "NVIDIA On-Demand" option in the NVIDIA X Server Settings. Now everything uses the iGPU by default, which should be better for battery life (at least, that's what I'm hoping for).
I'd like some applications (like Blender, for example) to use the dGPU by default.
According to the documentation:
To configure a graphics application to be offloaded to the NVIDIA GPU screen, set the environment variable
__NV_PRIME_RENDER_OFFLOAD
to1
. If the graphics application uses Vulkan or EGL, that should be all that is needed. If the graphics application uses GLX, then also set the environment variable__GLX_VENDOR_LIBRARY_NAME
tonvidia
, so that GLVND loads the NVIDIA GLX driver.
So I just created a shell script to act as a proxy to the Blender executable:
~/.local/bin/blender
#!/usr/bin/env bash
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
blender="$HOME/opt/blender-2.82a-linux64/blender"
exec -a "$0" "$blender" "$@"
This works fine, but it isn't a particularly clean solution.
The NVIDIA settings have an "Application Profiles" section where you can add application-specific profiles.
(Application profiles documentation)
There are all kinds of OpenGL-related options, but I couldn't find any setting to select which GPU is used. Is this not possible using the application profiles? Is there a cleaner alternative to the environment variables?
What worked for me is adding these lines in the .desktop files of the applications I want to use the dgpu by default.
What it also does is replace the launch using dedicated graphics option with the launch using integrated graphics option. This works on ubuntu 22.04, I'm not sure about backwards compatibility but I believe it should work on impish, focal, and bionic as well.