After connecting my laptop that has hybrid graphics to my external monitor, I noticed that my external monitor was running at half the set frame rate on KDE Plasma even though it ran perfectly fine on Windows. I tried searching for solutions but found none of them really worked; most solutions focused on NVIDIA drivers and parameters, and while some parameters did make it a little better, it was still very noticeable.
Turns out that the issue was caused by KWin rendering the external monitor using the integrated graphics card instead of the dedicated NVIDIA card even though the HDMI output was directly connected to the NVIDIA card. So the culprit here was Reverse Prime.
The Solution
For those with BIOS options to switch the GPU, you can set it to use the NVIDIA card and it should work perfectly fine. But if you don’t have that option, move on to the following solutions depending on if you are in X11 or Wayland.
X11
EnvyControl can be used to easily switch between the integrated and dedicated GPUs. Changing from Hybrid mode to Nvidia should fix the issue. On Arch Linux, EnvyControl is available in the AUR:
yay -S envycontrol
Releases for other distributions can be found on their GitHub at https://github.com/bayasdev/envycontrol.
After installing it, run the following and restart; it should fix the issue.
sudo envycontrol -s nvidia
Wayland
I mostly use KDE Plasma and sometimes GNOME, so the following solutions apply to those two. If you are having issues on any other desktop environment, you can try looking for a way to change the primary GPU used.
- First, run
lspcito find the PCI address of GPUs.
lspci | grep -E "NVIDIA|Graphics"
This should give similar output as the following.
01:00.0 VGA compatible controller: NVIDIA Corporation GA107M [GeForce RTX 3050 Mobile] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GA107 High Definition Audio Controller (rev a1)
00:02.0 VGA compatible controller: Intel Corporation CometLake-H GT2 [UHD Graphics] (rev 05)
For KDE Plasma, we tell kwin_wayland to explicitly use the NVIDIA GPU for rendering through the KWIN_DRM_DEVICES environment variable in /etc/environment.
- Add the variable
KWIN_DRM_DEVICESto/etc/environment. In my case, it looks like this:
KWIN_DRM_DEVICES="/dev/dri/by-path/pci-0000\:01\:00.0-card:/dev/dri/by-path/pci-0000\:00\:02.0-card"
Here the order takes priority; we add the address of the NVIDIA GPU first to ensure that it is used for rendering. You will need to change the addresses according to your PCI address. After doing this, reboot your system, and your external display should be smooth.
For GNOME, we add a udev rule to select primary GPU.
- First verify your Nvidia GPU’s DRM device node. Run:
ls -l /dev/dri/
This should output something similar as the following.
drwxr-xr-x 2 root root 120 Dec 20 13:59 by-path
crw-rw----+ 1 root video 226, 0 Dec 20 13:59 card0
crw-rw----+ 1 root video 226, 1 Dec 20 13:59 card1
crw-rw-rw- 1 root render 226, 128 Dec 20 13:59 renderD128
crw-rw-rw- 1 root render 226, 129 Dec 20 13:59 renderD129
Now, check the PCI address of our card0 and card1 to determine which one is Nvidia GPU.
- Run
lspcicommand from above if you haven’t already. - Run
readlink -f /sys/class/drm/cardX/deviceto find the PCI address.
readlink -f /sys/class/drm/card0/device
For me, this outputs
/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0
This matches my Nvidia GPU’s address of 01:00.0. So for me card0 is Nvidia GPU.
- Create a new udev rule in
/etc/udev/rules.d/(path may vary depending on distribution).
sudo nano /etc/udev/rules.d/61-mutter-preferred-primary-gpu.rules
- Add the line
ENV{DEVNAME}=="/dev/dri/cardX", TAG+="mutter-device-preferred-primary", replacing cardX with card number of your Nvidia GPU.
ENV{DEVNAME}=="/dev/dri/card0", TAG+="mutter-device-preferred-primary"
And we are done; after a reboot the sluggish experience should be gone. The only downside is that the battery life decreases significantly, and your VRAM usage will also be a little higher as everything is rendered on the NVIDIA GPU.
Credits:
- https://forums.developer.nvidia.com/t/nvidia-please-get-it-together-with-external-monitors-on-wayland/301684
- https://www.reddit.com/r/archlinux/comments/134q5fz/external_monitor_input_feels_laggy_and_slow/
- https://www.reddit.com/r/kde/comments/18tqx2k/laggy_display_when_using_egpu_on_fedora_kde_spin/
- https://tongkl.com/kde-plasma-laggy-external-monitor/
- https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1562
- https://darkghosthunter.medium.com/bluefin-making-your-nvidia-dgpu-primary-for-external-monitors-0b5a293a4b9f