Bug 481750

Summary: Periodic flicker on secondary monitor with fullscreen window on any monitor
Product: [Plasma] kwin Reporter: Johan Sköld <johan>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: nate, xaver.hugl
Priority: NOR Keywords: qt6
Version First Reported In: 5.93.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 6.0.0
Sentry Crash Report:
Attachments: Image shifting on monitor before it turns off.

Description Johan Sköld 2024-02-24 07:53:51 UTC
SUMMARY

Using wayland with two monitors:

- Dell AW3423DW, 3440x1440 @ 175 Hz, DisplayPort
- cocopar 133LR, 1920x1080 @ 60 Hz, HDMI

My GPU is an AMD RX 6900 XT, and I'm using the RADV vulkan drivers (v. 24.0.1). The AMDVLK drivers are not installed.

Whenever I have a window in fullscreen on the Dell monitor, the cocopar will flicker from time to time. As in it goes black for a second or two before coming back on. Sometimes I can go several minutes without seeing the flicker, other times it happens again within seconds.

It seems to happen very frequently when toggling fullscreen on or off, so that's a fast way to repro. If I force atomic modesetting off (`KWIN_DRM_NO_AMS=1`) it's a 100% repro rate whenever toggling fullscreen on or off.

STEPS TO REPRODUCE
1. Have two monitors connected and configured to extend the desktop.
2. Toggle fullscreen on or off in some application on one monitor.

OBSERVED RESULT

The second monitor turns off and on again.

EXPECTED RESULT

The second monitor does not turn off.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 6.7.6-zen1-1-zen / 6.0 RC2
KDE Plasma Version: 5.93.0
KDE Frameworks Version: 5.249.0
Qt Version: 6.7.0

ADDITIONAL INFORMATION

- The Dell monitor never flickers, it's always the cocopar.
- Toggling fullscreen on or off on the cocopar also causes it to flicker.
- The same setup worked in an older version of plasma (unsure of what version, but whatever was in arch's repos a few months ago), with `KWIN_DRM_NO_AMS=1`. Unsure about without.
- The same setup also works in sway, with or without atomic modesetting.
Comment 1 Johan Sköld 2024-02-24 08:08:19 UTC
To clarify: It flickers regardless of if a window is fullscreened on my first or second monitor. I wrote most of the original summary before verifying that, and forgot to update parts of it.
Comment 2 Johan Sköld 2024-02-24 08:22:26 UTC
Sorry, one more thing to add that I just noticed. If I open Spectacle and press "Rectangular Region", the monitor flickers off/on every single time I move the mouse cursor. Regardless of which monitor I move it on.

And I thought to check `journalctl`. Looking at the last 50 thousand lines, just about every single line says:

feb 24 00:13:58 pc kwin_wayland[2937]: kwin_scene_opengl: 0x2: GL_INVALID_OPERATION in glUniformMatrix(matrix size mismatch)

The even remotely relevant lines that don't say that are:

feb 24 00:09:34 pc kwin_wayland[2937]: kwin_core: Cannot grant a token to KWin::ClientConnection(0x592bbe8e7690)
[...]
feb 24 00:10:16 pc systemd[2870]: Starting Spectacle screenshot capture utility...
[...]
feb 24 00:10:16 pc spectacle[6436]: QApplication: invalid style override 'adwaita-dark' passed, ignoring it.
                                            Available styles: Breeze, Oxygen, Windows, Fusion
[...]
feb 24 00:10:16 pc spectacle[6436]: kpipewire_record_logging: VAAPI: Failed to initialize display
feb 24 00:10:16 pc spectacle[6436]: kpipewire_record_logging: DRM device not found
feb 24 00:10:16 pc spectacle[6436]: kpipewire_record_logging: VAAPI: Failed to initialize display
feb 24 00:10:16 pc spectacle[6436]: kpipewire_record_logging: DRM device not found
feb 24 00:10:16 pc systemd[2870]: Started Spectacle screenshot capture utility.
[...]
feb 24 00:10:16 pc plasmashell[3214]: QQuickItem: Cannot set FocusScope once item has children and is in a window.
[...]
feb 24 00:11:18 pc plasmashell[3214]: error creating screencast "Could not find window id 0"
Comment 3 Zamundaaa 2024-02-25 03:12:48 UTC
Thanks for the report, this should already be fixed in 6.0.0 with https://invent.kde.org/plasma/kwin/-/commit/a649be64db7c66eee5ed26e26ea3f5aeb45552d8
Comment 4 Johan Sköld 2024-02-25 05:21:14 UTC
Created attachment 166080 [details]
Image shifting on monitor before it turns off.

Thanks for the link. I applied that patch to version 5.93.0 of kwin and built it, and while it did get rid of the journalctl spam, my monitor still flickers when I enter or exit fullscreen with some window, and occasionally while just having a window fullscreened. So the original problem is still there.

If it helps, just before the monitor turns off the image shifts a bit. When entering fullscreen it shifts down, while when leaving fullscreen it shifts up. Attaching a slow-mo clip of what it looks like when entering fullscreen on my other monitor (just out of view).
Comment 5 Zamundaaa 2024-02-26 14:07:14 UTC
That's, uhh, beyond weird. If you disable direct scanout with KWIN_DRM_NO_DIRECT_SCANOUT=1, does that make a difference?
Comment 6 Johan Sköld 2024-02-26 17:41:42 UTC
It does not, the same thing still happens. Even more weirdly, it happens when I fullscreen a transparent window as well, so I don't think direct scanout would be active either way?

Although I just realized what's causing it. I remembered my second monitor technically supports VRR, but tends to flicker when it's enabled (only in Linux though, likely a driver bug). Both my monitors had VRR set to "Automatic". If I disable it on the second monitor the flicker stops. Is it possible that KWin enabled VRR on the second monitor too when fullscreening something on my main monitor? Otherwise this may also be some driver bug.
Comment 7 Bug Janitor Service 2024-02-27 13:54:31 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/5312
Comment 8 Zamundaaa 2024-02-27 13:56:25 UTC
That MR should fix vrr wrongly enabling on the second screen; the display content shifting and turning off is a driver bug though - most likely it doesn't handle the refresh rate going below the minimum refresh rate correctly. You can report that at https://gitlab.freedesktop.org/drm/amd/-/issues
Comment 9 Zamundaaa 2024-02-27 14:27:36 UTC
Git commit af4e12c5fc03c4d5981a92010d7a50c3a2187d12 by Xaver Hugl.
Committed on 27/02/2024 at 14:20.
Pushed by zamundaaa into branch 'master'.

comopsitor: only activate VRR if the active window is on the current screen

M  +1    -1    src/compositor.cpp

https://invent.kde.org/plasma/kwin/-/commit/af4e12c5fc03c4d5981a92010d7a50c3a2187d12
Comment 10 Zamundaaa 2024-02-27 14:46:08 UTC
Git commit 75b741128ebd662e832dae333a683dbd3a5317de by Xaver Hugl.
Committed on 27/02/2024 at 14:33.
Pushed by zamundaaa into branch 'Plasma/6.0'.

comopsitor: only activate VRR if the active window is on the current screen
(cherry picked from commit af4e12c5fc03c4d5981a92010d7a50c3a2187d12)

M  +1    -1    src/compositor.cpp

https://invent.kde.org/plasma/kwin/-/commit/75b741128ebd662e832dae333a683dbd3a5317de