Screen corruption PRIME (with RTX 3060 being preferred device)

There is massive screen corruption on a PRIME laptop with multiple screens attached, when the NVIDIA card is the primary DRM device.

It seems as if planes are (re)painted / refreshed with a significant offset, resulting in either black rectangles, pixel garbage, or some blitted(?) stale content.

My producing setup (@amrits / NVIDIA was able to repro a different issue of mine with local hardware, see end of posting for those details):

Hardware:

  • Dell 7610 + RTX 3060 (3072x1920) == Intel iGPU
  • Screen 4K == 3840x2160 connected to HDMI out == Intel iGPU
  • Screen 2.5K == 2560x1440 connected to DisplayPort out == NVIDIA dGPU

Software:

  • Fedora 37 + rpmfusion NVIDIA drivers 525 (based on local experiments I expect the same issue to be present everywhere)
  • KDE (5.27.3) - effectively, this is a Fedora KDE spin
  • Wayland
  • force the NVIDIA device as the primary DRM device (i.e. NVIDIA renders everywhere, Intel is idle) by way of setting the environment variable KWIN_DRM_DEVICES before KDE starts such that
echo $KWIN_DRM_DEVICES 
/dev/dri/card1:/dev/dri/card0

where card1 is NVIDIA, card0 is Intel (for my hardware). Theoretically, forcing this in the BIOS should work, too, but my BIOS does not offer this option.

Note that you can set this environment variable in /etc/environment; alternatively, for your user’s KDE environment, simply

KDE_ENV_LOCATION=$HOME/.config/plasma-workspace/env
KDE_STARTUP_SCRIPT=$KDE_ENV_LOCATION/force-nvidia-primary.sh

mkdir -p $KDE_ENV_LOCATION
cat > $KDE_STARTUP_SCRIPT <<EOF
KWIN_DRM_DEVICES=/dev/dri/card1:/dev/dri/card0
EOF

chmod u+x $KDE_STARTUP_SCRIPT

Validate from a running desktop environment / KDE konsole that echo $KWIN_DRM_DEVICES yields the expected results.

Setup:

Displays are set up in KDE such that, from right to left(!)

  • laptop (== right-most screen)
  • 4K screen
  • 2.5K screen (== left-most screen)

… with all screens aligned at the top.

The critical factor seems to be that the 4K screen is physically connected to the Intel iGPU (in my case the HDMI output), but drawn on by the NVIDIA GPU (which “owns” the DisplayPort output).

Actions to reproduce:

  • Start Firefox (or “Kate” editor of KDE - affects XWayland + native Wayland alike)
  • move the Firefox window to the middle screen, i.e. to the 4K screen
  • resize the Firefox window such that it covers roughly 80% of the screen’s native resolution; the exact size does not matter, but the larger, the more obvious
  • use the mouse to wiggle the Firefox window all over the screen

Defective behaviour:

Notice how on that middle screen you will get a lot of of corrupted content shown in areas which are not affected by redraws at all. So Firefox itself draws perfectly fine, but anything around it gets corrupted.

The attached screenshot shows the effect of this: Notice the empty Kate window I put onto the left-most screen, the empty Kate window on the right-most screen, and, on the middle screen a single Firefox window with all the corruption from wiggling the window with the mouse.

It’s totally surprising (to me) that this is limited to just the middle screen, but I suspect that it has to do with this screen being at 4K resolution, that something might be overflowing.

I can sometimes produce similarly broken behaviour with only two screens; for that simply remove the 2.5K screen. Having all three screens attached makes the problem just so much more visible and more trivial to reproduce.

Additional context:

@amrits may have hardware to reproduce this for NVIDIA - the system mentioned in High CPU usage on xorg when the external monitor is plugged in - #62 by amrits (Acer Predator PH315-53) sounds like it might be suitable to reproduce this behaviour.