There are a number of questions regarding the "Launch using dedicated graphics card" option in Ubuntu: this one, this one, or this one, for example. But none of them are asking the question I really want to know.
I want to understand what this option does, especially in the context of my system: the motherboard has integrated Intel graphics and an Nvidia Graphics card. I have three monitors attached to the ports on the Nvidia card and nothing attached to the onboard graphics.
When I see "Launch using dedicated graphics card", I imagine something like this: the desktop is running on (using the hardware of and being rendered in the memory of) the integrated graphics and the contents of this window I've just opened with this option are running on the other graphics card and somehow the output is piped through the integrated graphics (kind of like "picture-in-picture"?).
But given that I'm not using the onboard graphics at all, aren't my applications already running on the dedicated graphics card?
I suspect that my understanding of this option is wrong. Can anyone clarify what this option does?
I had the exact same question, none of the valiables like
__GLX_VENDOR_LIBRARY_NAME=nvidia
,__NV_PRIME_RENDER_OFFLOAD=1
,__VK_LAYER_NV_optimus=NVIDIA_only
,DRI_PRIME=1
produced the same result.I even tried to search in gnome-shell source code but the functions aren't in gnome-shell repo.
I finally ACCIDENTALLY stumbled upon switechroo-controls package,
I tried
switcherooctl launch <command>
which replicates the gnome shell behaviour. Then I had an epiphany to search for switcheroo in gnome-shell repo.Which confirms it, more intuitive proof (I am a fedora user):
TLDR
In answer to your exact question: Gnome does it by using a library
switcheroo-control
.Practical answer: you can do the same thing with
switcherooctl launch <command>
EDIT: I am not sure if the command works on ubuntu, but debian and ubuntu repositories have the package
switcheroo-control
.This is the tree of extracted
switcheroo-control
package (deb).Edit: Ok I found the problem, when setting the variable if you set like
VAR=value
, this is a regular variable, whileexport VAR=value
makes it accessible to subprocesses (REF)after this,any one of the variables work for me,
export __GLX_VENDOR_LIBRARY_NAME=nvidia
,export __NV_PRIME_RENDER_OFFLOAD=1
,export __VK_LAYER_NV_optimus=NVIDIA_only
,export DRI_PRIME=1
(they have their own different functions)so use
switchrootctl launch <command>
or, export above variables and launch the process. you can even create a aliasEx:
alias dgpu="export __GLX_VENDOR_LIBRARY_NAME=nvidia && export __NV_PRIME_RENDER_OFFLOAD=1 &&"
and then
dgpu <command>
this is the environment variables set by switchroot-control (in my case).
I'm not sure it's the only effect, but from what I can find on my laptop it sets the DRI_PRIME environment variable for the process that is started.
In my case to
DRI_PRIME=pci-0000_01_00_0
I couldn't really find much info on how exactly this has an effect, but some info can be found here.