Bug 495260 - On Wayland, NVIDIA GPU with open kernel modules gets better FPS with triple buffering on
Summary: On Wayland, NVIDIA GPU with open kernel modules gets better FPS with triple b...
Status: RESOLVED UPSTREAM
Alias: None
Product: kwin
Classification: Plasma
Component: performance (show other bugs)
Version: 6.2.2
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-23 18:52 UTC by patchouli
Modified: 2025-03-11 19:44 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
kwin perf statistics DP-1.csv (2.08 MB, application/gzip)
2024-11-06 07:37 UTC, patchouli
Details

Note You need to log in before you can comment on or make changes to this bug.
Description patchouli 2024-10-23 18:52:30 UTC
SUMMARY

KWin suffers from low FPS on desktop (210-220 FPS). In gaming, it could be 240 for certain games (I experience that in osu-lazer), while some other more demanding games such as Counter-Strike 2 would make KWin render at 150 FPS, while the game hits 500-600 FPS. KWin will render closer to 240 FPS (but not quite there yet; somewhere around 200) if I limit the game to 240 FPS or enable V-Sync.

If I downgrade KWin to 6.2.0 (while keeping the rest of the DE at 6.2.1 or 6.2.2), the issue resolves and my display output is buttery smooth once again. Upgrading KWin to 6.2.1 regresses the performance significantly. It is not fixed in 6.2.2.

STEPS TO REPRODUCE
1. Set display to 240Hz
2. Enable FPS effect on desktop
3. Use the desktop and look at KWin's FPS
4. Try gaming and look at KWin's FPS

OBSERVED RESULT

On desktop, FPS will be around 210-220. In games, it could be either 240, or as low as 130 despite the games rendering at *much* higher FPS.

EXPECTED RESULT

KWin is expected to render at my monitor's refresh rate - 240Hz, just like it does in 6.2.0.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.2.2
KDE Frameworks Version: 6.7.0
Qt Version: 6.8.0
Kernel Version: 6.11.5-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 32 × 13th Gen Intel® Core™ i9-13900K
Memory: 31.1 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 4090/PCIe/SSE2

ADDITIONAL INFORMATION

Using proprietary nvidia-open drivers. Tested on 560 and 565.

I cannot attach screenshots showing KWin's FPS because screenshots taken with Spectacle do not display the effect.
Comment 1 patchouli 2024-10-23 21:01:43 UTC
I followed an advice I got on Reddit and used `git bisect` to find the offending commit, and it seems to have been this one:

    b3358350b67b39ecea8fd4234df4ad8c0fa99017 is the first bad commit
    commit b3358350b67b39ecea8fd4234df4ad8c0fa99017
    Author: Xaver Hugl <xaver.hugl@gmail.com>
    Date:   Sat Oct 12 20:14:16 2024 +0000

        backends/drm: disable triple buffering on NVidia by default
        
        There's some unresolved glitches on multi gpu systems. Until that's taken care of,
        triple buffering is disabled by default on NVidia unless the environment variable
        KWIN_DRM_DISABLE_TRIPLE_BUFFERING=0 is set
        
        BUG: 494547
        BUG: 494407
        
        
        (cherry picked from commit 0133431c1d4b8a07ff5027df7f59928382562b38)
        
        Co-authored-by: Xaver Hugl <xaver.hugl@gmail.com>

    src/backends/drm/drm_output.cpp | 5 +++--
    1 file changed, 3 insertions(+), 2 deletions(-)
Comment 2 Zamundaaa 2024-10-24 14:05:48 UTC
Just to make sure, if you put KWIN_DRM_DISABLE_TRIPLE_BUFFERING=0 into /etc/environment and reboot, the issue is also gone in 6.2.2?
Comment 3 patchouli 2024-10-24 15:03:30 UTC
(In reply to Zamundaaa from comment #2)
> Just to make sure, if you put KWIN_DRM_DISABLE_TRIPLE_BUFFERING=0 into
> /etc/environment and reboot, the issue is also gone in 6.2.2?

Yes, my KWin performance is significantly better if I set the environment variable to 0.
Comment 4 patchouli 2024-10-24 15:06:35 UTC
Sorry for the double-comment, it's my first time using the bug tracker and I don't see the ability to edit. I wanted to mention that I have a single monitor (plugged in to my NVIDIA GPU) and a single GPU. I disabled my on-board graphics entirely. So I don't think the commit shouldn't have applied to me at all because I'm not even a multi-GPU user.
Comment 5 Zamundaaa 2024-11-04 21:59:43 UTC
Okay. That's pretty weird, you shouldn't need triple buffering with a dedicated GPU.

Please set the KWIN_LOG_PERFORMANCE_DATA=1 environment variable; after a reboot KWin will dump a .csv file with some performance data into your home directory. If you attach that here after a few minutes of usage where the problem occurs, maybe it's possible to figure out why frames get dropped.
Comment 6 patchouli 2024-11-06 07:37:08 UTC
Created attachment 175570 [details]
kwin perf statistics DP-1.csv

kwin perf statistics DP-1.csv after 6-7 minutes of playing a game and experiencing the KWin performance issue.
Comment 7 patchouli 2024-11-06 10:55:37 UTC
After some extra tinkering I found the following:

- Plasma on X11 does not have the issue.
- Going from the open kernel modules NVIDIA drivers to the closed kernel modules (`nvidia-open` to `nvidia` on Arch Linux) and disabling the GSP firmware fixes the issue
- Other Wayland compositors (Hyprland and GNOME) do not have the issue either, even with the GSP firmware enabled and while using the open kernel modules. So for some reason, KWin (Wayland) works very poorly with this enabled and other compositors do not suffer from the same issue. The GPU scores identically (within margin of error) on benchmarks with either the open kernel modules, or the closed ones with the GSP firmware disabled on various OpenGL benchmarks.
- Triple buffering also exhibits the issue, just on a much lower frequency and not to the same degree. I read on the implementation and it’s supposed to increase the performance for lower end hardware; and my RTX 4090 is somehow also affected by that too.
Comment 8 Zamundaaa 2025-03-11 19:44:16 UTC
> Going from the open kernel modules NVIDIA drivers to the closed kernel modules (`nvidia-open` to `nvidia` on Arch Linux) and disabling the GSP firmware fixes the issue
Then this is one of the GSP issues that are well known. It has to be resolved on the driver side.