Introduction
Are you having frame rate issues in video games? Battery life tanking fast? These could be caused by having multiple graphics cards, and using the wrong one.
Today many laptops and desktops have two graphics cards. An integrated one for normal light usage, and a discrete one for more robust power usage, like gaming.
Selecting the right graphics card for each situation will improve both frame rate and battery life..
Today I am going to identify and control multiple graphics cards with Linux, as simply as possible. A valuable skill for your Linux tool box
I would be remiss if I did not point out that this process can be dependent to some extent on Linux Distribution, desktop environment, and hardware
In this video I am using a MSI laptop running Fedora Linux with a KDE Plasma desktop. Your millage with this process might vary if your setup is significantly different from mine.
Identifying Hardware
From the Desktop: If you are using KDE Plasma, like me, then just open the KDE Info Center to identify your GPU (Graphics Processing Unit). For example the summary page shows both my Integrated and Discrete GPUS.

Most desktops should have similar functionality. Window Mangers on the other hand might not. You will have to check your particular setup. However, not to worry, because this can also be done from the terminal.
In the terminal just type the following to find your GPUs. The lspci command is short for List PCI Device, which is what a GPU should be. The vertical bar is a pipe, which feeds the output of the command lspci to the command grep. The grep command (Global Regular Expression search and Print) is a filter. It will search each line from lspci for the term VGA. Only lines with VGA in them will be outputted. It mainly stops you form having to search a long list of PCE devices.

Note the leading numbers of each line, 00 and 01. These will be important later.
Graphics Drivers
Unfortunately I need to be a little vague in this section. To get full functionality out of a GPU, the correct drivers need to be installed. Most GPUs will function with generic drivers, that’s how some distributions provide an installation screen. But for full functionality you need the actual dedicated drivers.
The reason for being vague here is both hardware and Distribution can change what you actually need to load. On the hardware side, the choices basically come down to three; Intel, AMD, and Nvidia. And there can be significant differences on how drivers for these different cards these are handled between between distributions. And depending on how old the hardware is, on top of this one has to be concerned with different versions of the same software.
The best advice, check the distributions documentation
Additional Software
In this article I will be using a function from the Mesa 3D library, specifically the environmental variable DRI_PRIME. You can find a short description of this at their web site (https://docs.mesa3d.org/envvars.html).
Most major distributions have packages for Mesa. It is just a matter of finding them. In your browser search engine type mesa 3d package <Distribution Name>. For example mesa 3d package Debian. This should point you to installation instructions. Note some distributions may have one package, and others may have multiple packages.
There is also a flatpak version available from flathub, which is another way to get the libraries installed. Since I do not use Ubuntu or snap, I can’t say if there is a snap package or not, but I would suspect there is.
I should also note there is something in the Gnome Desktop called switcheroo-control, that is suppose to allow the user to select GPUs. I know it exists, but I don’t use Gnome, so have never tried it.
Control GPU Usage via DRI_PRIME
Case 1: You are plugged in all the time, and/or not worried about power usage. In this case you might want your best GPU used all the time. To accomplish this we will edit the /etc/environment file. This file requires administrative access to edit. As long as you have that, you can use a graphical text editor or terminal text editor.
Remember those numbers from our earlier use of lspci? Those are how we select a graphics card. In the environment file you need to add a line that says DRI_PRIME=<GPU Number>. For the example above our Nvidia GPU is 01. we can drop the zero and add a line that says DRI_PRIME=1.
Next time we reboot, the Nvidia GPU will be used for everything. You can verify this with glxinfo | egrep “OpenGL vendor|OpenGL renderer”. This command will report what GPU is being used by everything. Note glxinfo comes with mesa, and egrep is a variation on grep that allows multiple arguments.

Also worth noting, I have not black listed the nouveau drivers yet, even though they are not installed. So I get the error regarding them.
Case 2: You only want to use your discrete GPU for specific application. This consumes less power overall and is something you might want to do on a laptop running on batteries to slow power drain when you can’t always recharge.
Note this example uses the KDE menu system, but should be easy to adapt. Technically you could use it with a <applciaiton>.desktop launcher file, but I have not tried that yet.
I right click on the menu launcher and select Edit Application from the drop down. Next I select my category and application. In this case I will be selecting the graphics category, and the program Blender under that. Then in the launch command I will add DRI_PRIME=1 before the program executable. Once this is done I save and exit.

Now when I run Blender, it will use my discrete GPU instead of the integrated one, which is the current system default.
I can already hear the question. “Okay but I use Steam (or Lutris) and my games don’t show up in the menu. How do I run them with the Discrete GPU?
As an example I will use Steam. If you go into your Steam Library, and right click on your game, then select properties from the drop down, a Window will open. And at the bottom of this window is a text box labeled Launch Options. This is where you enter the DRI_PRIME=1.

While the exact steps are somewhat different in Lutris, it is basically the same principle. You can set the GPU from an applications configuration menu.
Conclusion
This article presented a way, while running Linux, to control which Graphics Card or Graphics Processor Unit (GPU) is used with either individual applications, or the entire system. The two main reasons for wanting to do this are better video performance or better power utilization.
While it is possible to run graphics intensive applications form a integrated GPU, as performance has improved significantly over the last few years, discrete GPUs are still the way to go for best performance.
However best graphical performance tends to be at odds with economical power performance. That is to say there is a price for improved graphics performance , and it is power consumption.
That being said, on hybrid laptops or dual GPU computers, it behooves the end user to understand how to select the proper GPU for the situation (graphics performance vs power economy). This article has shown one way of doing this using the Mesa 3D open source Open GPL libraries. And the odds are if you are running Linux, you might already have them installed, so you might as well use them.