Todo: Currently just copied and pasted from various sources, needs to be cleaned up.
If saving values to 90-nvidia.conf, defaults will change to discrete gpu but switcheroo will not show opposite options in right click menu. Need to figure out how to change that.
Sources:
https://wiki.archlinux.org/title/PRIME
https://www.reddit.com/r/Fedora/comments/w7pb15/comment/ihm3mia
Create a file ~/.config/environment.d/90-nvidia.conf with the following contents:
__NV_PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia
__VK_LAYER_NV_optimus=NVIDIA_only
Reboot.
Everything (OpenGL and Vulkan) should be using the NVIDIA GPU by default.
For GNOME integration, install switcheroo-control and enable switcheroo-control.service.
GNOME will respect the PrefersNonDefaultGPU property in the desktop entry. Alternatively, you can launch applications with GPU by right clicking on the icon and choosing Launch using Discrete Graphics Card.
Wayland needs less configuration than Xorg. There seems to be also preliminary support for GPU hotplugging in KDE's KWin and GNOME's Mutter (Issue 17 and Merge request 1562).
To use your discrete card prepend the DRI_PRIME= environment variable. The following examples assume a system with an Intel integrated card, an NVIDIA internal GPU and an AMD external GPU.
To use the integrated Intel chip, no modifications are required, since it is already the default:
glxinfo | grep 'OpenGL renderer'
OpenGL renderer string: Mesa Intel(R) Xe Graphics (TGL GT2)
For the AMD card with opensource drivers:
DRI_PRIME=pci-0000_06_00_0 glxinfo | grep 'OpenGL renderer'
OpenGL renderer string: AMD Radeon RX 5700 XT (navi10, LLVM 14.0.6, DRM 3.46, 5.18.17-hardened1-1-hardened)
For the NVIDIA card with proprietary drivers:
DRI_PRIME=pci-0000_01_00_0 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep 'OpenGL renderer string'
OpenGL renderer string: NVIDIA GeForce RTX 3050 Ti Laptop GPU/PCIe/SSE2
Multiple GPUs can be used at the same time on the same machine with Wayland. Note: Hotplugging an external GPU is enabled with a limitation: re-logging is necessary to load the correct kernel modules.
See the mesa3d documentation for PRIME: https://docs.mesa3d.org/envvars.html
All Xwayland applications should work out of the box just like they do on Xorg. However, as of driver version 525.85, for native Wayland applications, only OpenGL works, provided you have modesetting enabled.