Bug 487780

Summary: Fullscreen game stutter when Plasma receives notifications.
Product: [Plasma] kwin Reporter: Robert <robert.bielski>
Component: performanceAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: kde.roundish, linx.system.adm, massimiliano.torromeo, miranda, nate, xaver.hugl
Priority: NOR    
Version: 6.0.5   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 6.2.0
Sentry Crash Report:
Attachments: attachment-3246432-0.html
attachment-4014901-0.html

Description Robert 2024-05-30 03:58:12 UTC
***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***

SUMMARY
When playing fullscreen games, in particular games using Steam Proton and DXVK (most likely all fullscreen games), there is a momentary drop in frame rate as the desktop notification is received and again as it disappears. It is important to clarify that nothing actually renders over the game, only the momentary stutter that corresponds with the time the notification would appear on the desktop had the game not been running fullscreen. This should not be happening since nothing is actually rendered over the game and nothing should be disturbing the rendering process with direct scanout working consistently. This happens with all notifications and is most noticeable for me with KDE Connect messages from my phone.

STEPS TO REPRODUCE
1. Make sure "Screen Tearing: Allow in fullscreen windows" is enabled in Plasma display configuration.
2. Launch a Vulkan game in fullscreen mode.
3. Set VSync in the game or a constant frame rate so that the game is perfectly smooth (Preferably use a Vulkan hood such as DXVK_HUD with frametimes graph overlay).
4. Trigger a desktop notification such as a text message with KDE Connect via Android.
5. Observe a sudden momentary stutter and corresponding spike in the frametime graph when a notification comes in to the desktop such as KDE Connect and once again when it disappears.

OBSERVED RESULT
A momentary stutter and spike in frametime is observed when Plasma gets a notification in an otherwise perfectly smooth VSync'd game experience.

EXPECTED RESULT
The frame rate should remain perfectly smooth with no stutter during background notification reception and frametimes should be consistent all the time.

SOFTWARE/OS VERSIONS

Operating System: EndeavourOS 
KDE Plasma Version: 6.0.5
KDE Frameworks Version: 6.2.0
Qt Version: 6.7.1
Kernel Version: 6.9.2-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 32 × AMD Ryzen 9 5950X 16-Core Processor
Memory: 62.7 GiB of RAM
Graphics Processor: AMD Radeon RX 5700 XT
Manufacturer: Gigabyte Technology Co., Ltd.
Product Name: X570 AORUS XTREME
System Version: -CF

ADDITIONAL INFORMATION
Mesa 24.1.0 with RADV drivers.
Comment 1 Zamundaaa 2024-06-05 10:00:05 UTC
Can you test the same scenario after putting
KWIN_DRM_NO_DIRECT_SCANOUT=1
into /etc/environment and rebooting? Do you still see stutter then?
Comment 2 Robert 2024-06-06 02:01:08 UTC
Created attachment 170194 [details]
attachment-3246432-0.html

Yes, I will do that when I get the chance tomorrow and follow up with you. Thanks,

Robert


________________________________
From: Zamundaaa <bugzilla_noreply@kde.org>
Sent: June 5, 2024 6:00 AM
To: robert.bielski@outlook.com <robert.bielski@outlook.com>
Subject: [kwin] [Bug 487780] Fullscreen game stutter when Plasma receives notifications.

https://bugs.kde.org/show_bug.cgi?id=487780

Zamundaaa <xaver.hugl@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REPORTED                    |NEEDSINFO
                 CC|                            |xaver.hugl@gmail.com
         Resolution|---                         |WAITINGFORINFO

--- Comment #1 from Zamundaaa <xaver.hugl@gmail.com> ---
Can you test the same scenario after putting
KWIN_DRM_NO_DIRECT_SCANOUT=1
into /etc/environment and rebooting? Do you still see stutter then?

--
You are receiving this mail because:
You reported the bug.
Comment 3 Robert 2024-06-06 17:59:04 UTC
Just following up, I can confirm that after setting the environment variable KWIN_DRM_NO_DIRECT_SCANOUT=1 and rebooting, there is no stutter present and everything is perfectly smooth in the same gaming scenario when receiving desktop notifications. This likely points to a bug in the direct scanout implementation.
Comment 4 Zamundaaa 2024-06-09 16:42:01 UTC
okay, then direct scanout is definitely getting interrupted, when it shouldn't be.
Do you have any effects that would be acting on notifications?
Comment 5 Robert 2024-06-10 16:47:17 UTC
Created attachment 170350 [details]
attachment-4014901-0.html

Reviewing the Desktop Effects KCM, the only thing that stands out is the effect called "Fading Popups" as they seem to smoothly fade in and out when they show and disappear. I didn't make any changes to this module and use the default effect settings as packaged by Arch/EndeavourOS. Thanks for looking into this minor, but still important issue.

________________________________
From: Zamundaaa <bugzilla_noreply@kde.org>
Sent: June 9, 2024 12:42 PM
To: robert.bielski@outlook.com <robert.bielski@outlook.com>
Subject: [kwin] [Bug 487780] Fullscreen game stutter when Plasma receives notifications.

https://bugs.kde.org/show_bug.cgi?id=487780

Zamundaaa <xaver.hugl@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
         Resolution|WAITINGFORINFO              |---
             Status|NEEDSINFO                   |CONFIRMED

--- Comment #4 from Zamundaaa <xaver.hugl@gmail.com> ---
okay, then direct scanout is definitely getting interrupted, when it shouldn't
be.
Do you have any effects that would be acting on notifications?

--
You are receiving this mail because:
You reported the bug.
Comment 6 Bug Janitor Service 2024-07-10 16:18:59 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6086
Comment 7 Zamundaaa 2024-07-11 15:02:51 UTC
Git commit de8bd8f12664f054165d64d18e8b3febfa71d4d9 by Xaver Hugl.
Committed on 11/07/2024 at 14:54.
Pushed by zamundaaa into branch 'master'.

plugins/fadingpopups: don't block direct scanout

The effect only modifies the opacity of individual windows that
WorkspaceScene::scanoutCandidate will reject anyways, so there's no reason
for it to block direct scanout.
Once a more proper solution for blocking direct scanout on individual items
is in place, this can be removed again

M  +1    -1    autotests/integration/dont_crash_cancel_animation.cpp
M  +1    -0    src/plugins/fadingpopups/package/metadata.json
M  +8    -2    src/scripting/scriptedeffect.cpp
M  +3    -1    src/scripting/scriptedeffect.h

https://invent.kde.org/plasma/kwin/-/commit/de8bd8f12664f054165d64d18e8b3febfa71d4d9
Comment 8 Zamundaaa 2024-07-11 15:15:02 UTC
Git commit 07e9d09611d1de307b7ce9724fc5dcea5a9cc4d7 by Xaver Hugl.
Committed on 11/07/2024 at 15:06.
Pushed by zamundaaa into branch 'Plasma/6.1'.

plugins/fadingpopups: don't block direct scanout

The effect only modifies the opacity of individual windows that
WorkspaceScene::scanoutCandidate will reject anyways, so there's no reason
for it to block direct scanout.
Once a more proper solution for blocking direct scanout on individual items
is in place, this can be removed again


(cherry picked from commit de8bd8f12664f054165d64d18e8b3febfa71d4d9)

Co-authored-by: Xaver Hugl <xaver.hugl@gmail.com>

M  +1    -1    autotests/integration/dont_crash_cancel_animation.cpp
M  +1    -0    src/plugins/fadingpopups/package/metadata.json
M  +8    -2    src/scripting/scriptedeffect.cpp
M  +3    -1    src/scripting/scriptedeffect.h

https://invent.kde.org/plasma/kwin/-/commit/07e9d09611d1de307b7ce9724fc5dcea5a9cc4d7
Comment 9 Robert 2024-07-18 02:50:22 UTC
Awesome, thanks for fixing it, much appreciated.
Comment 10 Robert 2024-07-30 02:21:04 UTC
I'm just following up on this bug and have noticed that despite having 6.1.3 and the latest updates, there is still a pronounced stutter that occurs consistently when notifications are received.

I'm not sure if this is now direct scanout being interrupted or another problem with the code.
Comment 11 Robert 2024-08-14 20:54:11 UTC
I believe that all the code paths that block direct scanout are not solved for this use case. After further evaluation, your patch does improve things as the stutter only happens once now and it's not caused by the notification pop up. I believe that when the new notifications icon appears within the system tray on the panel, this also blocks direct scanout once and this is probably the stutter I observe now.

I'm going to re-open the bug, it's not a huge issue, however, if you have some time, you might want to look into this, thanks.
Comment 12 Keno 2024-08-18 23:04:30 UTC
This issue still occurs for me under KDE 6.1.4. Every single notification causes a frametime spike/framedrop.

Tested with openSUSE Tumbleweed, kernel 6.10.5 under Wayland. VRR is enabled and I use a dual monitor setup.
CPU: AMD Ryzen 9 7950X3D
GPU: AMD Radeon RX 7800 XT
Comment 13 Zamundaaa 2024-08-19 12:01:08 UTC
There are some remaining code paths that can block direct scanout - namely effects that haven't been fixed, or that may need to block direct scanout in some situations. There's a new API in 6.2 that effects can use though, https://invent.kde.org/plasma/kwin/-/merge_requests/6203, which blocks direct scanout only when really necessary. It's implemented for all built in effects, and external javascript effects automatically make use of this API too.