Bug 458549

Summary: Random whole screen flashes/flicker on the desktop on Wayland when using AMS
Product: [Plasma] kwin Reporter: nf.pereira
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: CLOSED UPSTREAM    
Severity: major CC: nate, xaver.hugl
Priority: NOR    
Version: 5.25.4   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
URL: https://gitlab.freedesktop.org/drm/amd/-/issues/1991
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: debug plasma-kwin_wayland.txt
drm-debug.zip

Description nf.pereira 2022-08-31 13:37:34 UTC
SUMMARY
***
On Wayland, the whole screen flashes or flickers randomly every few seconds. Seems more frequent if an application, for example Firefox, is open, but happens even with just the desktop and nothing else.
The screen flashes for what seems a single frame and then stays normal until the next flash. I can't find a pattern.

If necessary I can record a video of the issue at slow-motion.

Using KWIN_DRM_NO_AMS=1 on /etc/environment fixes the issue.
***


STEPS TO REPRODUCE
1. Login into Plasma Wayland.
2. Wait a few seconds or minutes while moving the cursor or windows around.
3. Observe screen flashing at random.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch
KDE Plasma Version: 5.25.4
KDE Frameworks Version: 5.97.0
Qt Version: 5.15.5

ADDITIONAL INFORMATION
Hardware:
CPU: AMD Ryzen 7 3700X
GPU: AMD Radeon RX 6800
Dual monitor setup: 1440p @ 180hz primary and 1080p @ 60hz secondary
Comment 1 nf.pereira 2022-08-31 13:38:56 UTC
Forgot to mention this is on a clean Arch install.
Comment 2 Nate Graham 2022-08-31 20:07:40 UTC
Can you paste the output of qdbus org.kde.KWin /KWin supportInformation?

Also helpful would be the output of drm_info, which you may have to install a new package to get.
Comment 3 nf.pereira 2022-09-01 14:21:31 UTC
Sure thing! Here goes:

qdbus: https://pastebin.com/xmGxH2j8
drm_info: https://pastebin.com/J6eEFZ6S

I've also noticed my primary screen (the 1440p one) is the only one that flashes. My 1080p secondary screen does not seem to flash.

Additionally, I've tested 180hz, 165hz and 60hz on the affected screen, but all refresh rates tested flash the screen all the same. The only difference being that at 60hz the flash seems longer, which is expected, as a single frame lasts longer at 60hz.

I believe this bug might be masked for many users by the fact all users of this graphics card family also being affected by the cursor corruption bug in AMDGPU, which requires KWIN_DRM_NO_AMS=1 to work around on Wayland, which means they also don't observe this flashing bug.
https://gitlab.freedesktop.org/drm/amd/-/issues/1513

Please tell me if I can help in any other way.
Comment 4 Nate Graham 2022-09-01 16:10:34 UTC
Thanks a lot for the info!
Comment 5 Zamundaaa 2022-09-01 17:44:06 UTC
There's a few things you can do to narrow the source of this problem down. Unset KWIN_DRM_NO_AMS and 
1. set QT_LOGGING_RULES="kwin_wayland_*.debug=true" instead, reproduce the problem and upload the output of "journalctl --user-unit=plasma-kwin_wayland" here
2. enable drm debug logging and record the output of dmesg with the problem happening at least once, and upload that here. See https://invent.kde.org/plasma/kwin/-/wikis/Debugging-DRM-issues for how to do that
3. set KWIN_DRM_USE_MODIFIERS=0 instead, check if the problem still happens
4. set KWIN_DRM_PREFER_COLOR_DEPTH=24 instead, check if the problem still happens
Comment 6 nf.pereira 2022-09-02 20:34:39 UTC
Created attachment 151789 [details]
debug plasma-kwin_wayland.txt
Comment 7 nf.pereira 2022-09-02 20:35:06 UTC
Created attachment 151790 [details]
drm-debug.zip
Comment 8 nf.pereira 2022-09-02 20:36:41 UTC
(In reply to Zamundaaa from comment #5)
> There's a few things you can do to narrow the source of this problem down.
> Unset KWIN_DRM_NO_AMS and 
> 1. set QT_LOGGING_RULES="kwin_wayland_*.debug=true" instead, reproduce the
> problem and upload the output of "journalctl
> --user-unit=plasma-kwin_wayland" here
Done. Attached it to the bug with the name "debug plasma-kwin_wayland.txt"

> 2. enable drm debug logging and record the output of dmesg with the problem
> happening at least once, and upload that here. See
> https://invent.kde.org/plasma/kwin/-/wikis/Debugging-DRM-issues for how to
> do that
Done. Attached as "drm-debug.zip". I had to zip it to fit the upload constraints.


> 3. set KWIN_DRM_USE_MODIFIERS=0 instead, check if the problem still happens
This seems to fix the problem! I used it for half an hour without the problem ever manifesting.


> 4. set KWIN_DRM_PREFER_COLOR_DEPTH=24 instead, check if the problem still
> happens
This does not fix it. After a minute or two, the screen flashed.
Comment 9 Zamundaaa 2022-09-03 20:32:16 UTC
KWIN_DRM_NO_AMS=1 effectively contains what KWIN_DRM_USE_MODIFIERS=0 does, so that explains why disabling AMS also solves the problem.

The only error I see is that with KWIN_DRM_NO_AMS=1 set you get a large amount of these:
> kwin_wayland_drm: Page flip failed: Device or resource busy
which isn't necessarily ideal but with atomic modesetting enabled there's not a single warning or anything that I think would be relevant.

As KWin has no information about the monitor flickering it can't do anything against it. The two things that could be at fault are either the GPU driver or possibly even the scanout hardware in the GPU. I recommend you to report this at https://gitlab.freedesktop.org/drm/amd/-/issues and use the KWIN_DRM_USE_MODIFIERS=0 workaround until it's fixed
Comment 10 nf.pereira 2022-09-03 22:10:52 UTC
(In reply to Zamundaaa from comment #9)
> The only error I see is that with KWIN_DRM_NO_AMS=1 set you get a large
> amount of these:
> > kwin_wayland_drm: Page flip failed: Device or resource busy
> which isn't necessarily ideal but with atomic modesetting enabled there's
> not a single warning or anything that I think would be relevant.

KWIN_DRM_NO_AMS was not set when I saved those logs, as per your instructions.
All the logs I posted here are with everything at defaults with no environment variables changed.
Comment 11 nf.pereira 2022-09-03 22:24:53 UTC
(In reply to Zamundaaa from comment #9)
> I recommend you to report
> this at https://gitlab.freedesktop.org/drm/amd/-/issues and use the
> KWIN_DRM_USE_MODIFIERS=0 workaround until it's fixed

Indeed a bug has been opened for this issue here:
https://gitlab.freedesktop.org/drm/amd/-/issues/1991

It seems it's related to the GPU not ramping the VRAM frequency up to the necessary level.
I'm closing this as it's unrelated to KDE then.

Thanks for the help and sorry for the trouble!