Switching graphics cards with NVIDIA PRIME Render Offload

I’m posting this because recently someone (in the openSUSE Chinese forums) asked for help on how to switch graphics cards using switcherooctl.

I realized that the wiki doesn’t document the use of environment variables to switch the graphics card, except for suse-prime and openSUSE’s current recommendation of switcherooctl. This method is actually documented in the archlinux wiki, and it works for Wayland as well.

I documented it on the openSUSE Chinese wiki two years ago, but then I forgot about it until someone asked for help recently.


Install the graphics driver

See ​​SDB:NVIDIA Drivers for details.

Check the software version

  • Use Plasma 5.20.2 or higher.
  • Make sure the NVIDIA closed-source driver version is not less than 495.44.
  • Make sure the Qt version is higher than Qt5.15.0
  • Make sure the Nvidia EGL library is installed, its package name in the openSUSE software repository is libnvidia-egl-wayland11.

To use Plasma Wayland sessions with hardware acceleration on XWayland applications, you need to make sure your system has installed:

  • Xorg 1.20.12 and higher;
  • XWayland 21.1.2 and higher;
  • libxcb 1.1.7 and higher.

The above conditions are generally met automatically for Tumbleweed users.

Remove suse-prime

suse-prime only works under X11, and it will affect the following operations.

sudo zypper rm -u suse-prime

If you have installed additional modules based on SDB:NVIDIA_SUSE_Prime, please uninstall them as well:

sudo zypper rm bbswitch-kmp-default

Then reboot the system.

Using the modesetting driver

Use the following command to check if the driver is running in modesettings mode:

sudo cat /sys/module/nvidia_drm/parameters/modeset

The terminal output should be “Y”.

If not, open YaST, find and open Boot Loader → Kernel Parameters (K), fill in nvidia-drm.modeset=1 in Optional Kernel Command Line Parameters (P), save the settings and exit YaST.

Then reboot the system.

Login

Select Plasma (wayland) on the KDE login screen and enter the desktop.

prime-run

According to the official documentation, to let the program call NVIDIA graphics card, you can use the following command:

__NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia [command]

You can write this command as a shell script named prime-run and put it in $PATH:

#!/bin/bash
__NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia "$@"

Then use this command to run the application:

prime-run [application name, command or script]

Others

To see which applications are using xwayland, you can install xlsclients:

sudo zypper in xlsclients

Then run xlsclients directly to list the programs currently using xwayland.

NVIDIA Optimus

For more information on various NVIDIA Optimus options, see NVIDIA Optimus - archlinux wiki.

Envycontrol

EnvyControl is a CLI tool for easy GPU switching on Nvidia Optimus laptops under Linux.

There is currently an experimental package on OBS, which can be used, or installed manually:

Clone the repository (for example, clone to ~/bin or ~/.local/bin):

cd ~/bin && git clone https://github.com/bayasdev/envycontrol.git

Then write in the ~/.bashrc file:

alias envycontrol="python3 $HOME/bin/envycontrol/envycontrol.py"

Reload the bash shell configuration

source ~/.bashrc

Use EnvyControl to set the graphics mode to Hybrid:

sudo envycontrol -s hybrid --rtd3

After the settings are completed, reboot the system.

For other details, see the project readme file.

Reference

@white-poplar That is very dependent of the hybrid setup, your assumption is both cards are type 300 (VGA), some systems are only good with Prime Render Offload as can be Display Controllers (generally AMD) and 3D Controllers. Likewise some hardware vendors do funky stuff with their hybrid setups…

In most use cases with modern hardware switcherooctl should just work with laptops or desktop systems.

2 Likes

This method works for me on my old computer (Intel i5-8250u + Nvidia MX150, which is several years old).
Computers with relatively new hardware in recent years should be similar to mine. Like:

poplar@Greysia:~> lspci | grep VGA
03:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Navi 33 [Radeon RX 7600/7600 XT/7600M XT/7600S/7700S / PRO W7600] (rev c7)
69:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Phoenix1 (rev c2)

The documentation for switcherooctl is also problematic in that it does not fully document the setup steps. The first time I tried to use it, it didn’t work as expected and the app didn’t work on the specified GPU.

I didn’t realize that switcherooctl needed to call the systemd service, and switcherooctl doesn’t state that this is the case in its manual page, so I wrote about my confusion in last year’s news translation.

switcherooctl 似乎对 AMD 显卡不生效。

en: switcherooctl does not seem to work for AMD cards.

Then a few days ago someone figured out a post I made last year asking me how to use switcherooctl. Then @marguerite, the site admin of openSUSE Chinese community forum, mentioned in another help thread that switcherooctl needs to call a systemd service.

sudo systemctl enable switcheroo-control 
sudo systemctl start switcheroo-control 
sudo systemctl status switcheroo-control

The need for enabling the service is noted in the wiki…
https://en.opensuse.org/SDB:NVIDIA_Switcheroo_Control

1 Like

Thank you for your reply. I will update the entry of openSUSE Chinese Wiki tomorrow.

Synchronized a new entry, added some notes and references.

https://zh.opensuse.org/index.php?title=Special:最近更改&limit=500&days=30