Bug 487833

Summary: Graphical glitches in plasma 6.1 when AMD GPU is used on AMD/NVIDIA hybrid GPU system
Product: [Plasma] kwin Reporter: Lucas Lima <lima.lucas.ma>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: andreas.d.korb, fanzhuyifan, kde, nate, postix, pranav.3943, vlad.zahorodnii, xaver.hugl
Priority: NOR    
Version: 6.1.90   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.1.3
Sentry Crash Report:
Attachments: Graphical Glitches in 6.1.90 with triple buffering
Screen Cast when running with Tripple Buffering

Description Lucas Lima 2024-05-31 12:26:07 UTC
SUMMARY

Windows and other screen components seem to be glitching in kwin 6.1 beta in wayland 
The issue can be seeing happening here: https://youtu.be/3SYpui4vV-Q

STEPS TO REPRODUCE
1. Move windows around, or enter full-screen in a video in Firefox.
2. 
3. 

OBSERVED RESULT

The screen should glitch with what appears to be content from the windows behind it.

EXPECTED RESULT

Only the contents of the current screen should be shown

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux, Kernel 6.9.2-arch1-1
KDE Plasma Version: 6.1 Beta
KDE Frameworks Version: 6.2
Qt Version: 6.7.1
Mesa Version: 24.1.0-1

ADDITIONAL INFORMATION
This is in a Hybrid Graphics system with AMD Integrated graphics and Nvidia Discrete graphics, using the AMD graphics as the main renderer.
The issues doesn't seem to happen if I use the Nvidia graphics as the primary renderer using KWIN_DRM_DEVICES
Comment 1 David Redondo 2024-06-05 09:53:45 UTC
Does it only happen with Konsole? Is your konsole slightly transparent?
Comment 2 Lucas Lima 2024-06-05 13:45:09 UTC
No, it happens around many applications. I'm not using any transparency in Konsole.
As mentioned, it also happens when displaying a YouTube video in full-screen.

Here's an example of it happening in Firefox: https://youtu.be/xUSUyo_cfNo
Comment 3 David Redondo 2024-06-06 12:01:36 UTC
Thank you quite anooying indeed. To which card are the screens connected?
Comment 4 Lucas Lima 2024-06-06 12:11:35 UTC
So my hardware is the following:

~ lspci -nnk | grep VGA                                                                                  
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA104M [GeForce RTX 3080 Mobile / Max-Q 8GB/16GB] [10de:249c] (rev a1)
06:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne [Radeon Vega Series / Radeon Vega Mobile Series] [1002:1638] (rev c4)
---

I have a setup to change the main renderer using KWIN_DRM_DEVICES as the following line in /etc/enviroment (please note that there are udev rules to setup those paths mentioned here)

1. KWIN_DRM_DEVICES=/dev/dri/fixed-reference/amd-card:/dev/dri/fixed-reference/nvidia-card

Or when I want when I want to use the nvidia card:

2. KWIN_DRM_DEVICES=/dev/dri/fixed-reference/nvidia-card:/dev/dri/fixed-reference/amd-card

Surprisingly enough, the issue seems to happen only when I'm using the amd-card as the primary renderer. When using 2., the issue doens't seem to happen.
Comment 5 Zamundaaa 2024-06-12 23:22:47 UTC
Can reproduce with Intel + NVidia as well. Replacing the egl explicit sync code used for multi gpu copies in the drm backend with glFinish() makes the glitches go away, so this might be a driver issue.
Comment 6 Lucas Lima 2024-07-01 22:54:43 UTC
Looks like more users are facing the same issue in reddit: https://www.reddit.com/r/kde/comments/1dt0wlj/display_issues_after_nvidia_555_driver_update/
Comment 7 Zamundaaa 2024-07-02 12:46:22 UTC
As the egl explicit sync code was already used in 6.0, I bisected this to figure out what changed and the glitches only happen with triple buffering. As a workaround you can set KWIN_DRM_DISABLE_TRIPLE_BUFFERING=1 for KWin.
Comment 8 Bug Janitor Service 2024-07-02 12:49:25 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6033
Comment 9 Zamundaaa 2024-07-02 13:06:52 UTC
Git commit b437c65815b2898564748f3be48c4145671a750f by Xaver Hugl.
Committed on 02/07/2024 at 12:48.
Pushed by zamundaaa into branch 'Plasma/6.1'.

backends/drm: disable triple buffering on NVidia

Until we figure out what's wrong, it's best to leave it disabled

M  +1    -1    src/backends/drm/drm_output.cpp

https://invent.kde.org/plasma/kwin/-/commit/b437c65815b2898564748f3be48c4145671a750f
Comment 10 Lucas Lima 2024-07-05 12:11:58 UTC
Hey guys, sorry to bring the bad news but this is still happening in kwin_wayland 6.1.2 when using the AMD graphics as the primary.
Using KWIN_DRM_DISABLE_TRIPLE_BUFFERING=1 makes it go away.

Here's some evidence: https://youtu.be/Bp9Lkkh_On8
Comment 11 Zamundaaa 2024-07-05 13:24:13 UTC
The patch didn't make it into 6.1.2, it's only in 6.1.3
Comment 12 Lucas Lima 2024-07-05 13:27:21 UTC
Apologies! Thought it was included based on the change log: https://kde.org/announcements/changelogs/plasma/6/6.1.1-6.1.2/
Comment 13 Andreas Korb 2024-07-17 11:05:23 UTC
The changelog for the Nvidia driver 550.100 [0]:

> Fixed a bug that caused OpenGL triple buffering to behave like double buffering.

[0] https://www.nvidia.com/Download/driverResults.aspx/228542/en-us/
Comment 14 Zamundaaa 2024-07-17 12:40:43 UTC
That's about a different thing, but also great to see that fixed
Comment 15 Lucas Lima 2024-10-05 15:07:40 UTC
Hi, 

Sadly, I have to re-open this since the situation seems to have gotten worse with 6.1.2.
Here's the behavior and the configuration that causes it:
- Desktop corruption: 
  KWIN_DRM_DEVICES=/dev/dri/by-vendor/amd:/dev/dri/by-vendor/nvidia, with KWIN_DRM_DISABLE_TRIPLE_BUFFERING unset, or 
  KWIN_DRM_DEVICES=/dev/dri/by-vendor/nvidia:/dev/dri/by-vendor/amd and KWIN_DRM_DISABLE_TRIPLE_BUFFERING=0
- No corruption: 
    KWIN_DRM_DEVICES=/dev/dri/by-vendor/amd:/dev/dri/by-vendor/nvidia, with KWIN_DRM_DISABLE_TRIPLE_BUFFERING=1 or
    KWIN_DRM_DEVICES=/dev/dri/by-vendor/nvidia:/dev/dri/by-vendor/amd and KWIN_DRM_DISABLE_TRIPLE_BUFFERING unset

I've attached a video highlighting the issue. I've also attached a screen recording that interestingly doesn't capture the issue. 

Here are the system details again:
Operating System: Arch Linux 
KDE Plasma Version: 6.1.90
KDE Frameworks Version: 6.6.0
Qt Version: 6.8.0
Kernel Version: 6.11.1-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 9 5900HS with Radeon Graphics
Memory: 15,0 GiB of RAM
Graphics Processor: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne / NVIDIA GeForce RTX 3080 Laptop GPU/PCIe/SSE2
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ROG Zephyrus G15 GA503QS_GA503QS
System Version: 1.0
Comment 16 Lucas Lima 2024-10-05 15:09:10 UTC
Created attachment 174463 [details]
Graphical Glitches in 6.1.90 with triple buffering

Captured when running with AMD card as primary and KWIN_DRM_DISABLE_TRIPLE_BUFFERING unset
Comment 17 Lucas Lima 2024-10-05 15:11:19 UTC
Created attachment 174464 [details]
Screen Cast when running with Tripple Buffering

This is a screen recording done with Triple Buffering enabled, which interestingly enough doesn't show the issue.
Comment 18 Lucas Lima 2024-10-08 22:13:05 UTC
Updating to the 6.2.0 release fixed the issue.