Bug 490383

Summary: On device with nvidia dgpu, desktop extremely laggy and kwin spams kwin_wayland_drm: Presentation failed! Invalid argument
Product: [Plasma] kwin Reporter: fanzhuyifan
Component: platform-drmAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED UPSTREAM    
Severity: major CC: kdedev, nate, postix, xaver.hugl
Priority: NOR Keywords: regression
Version First Reported In: git master   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: drm-debug.log

Description fanzhuyifan 2024-07-17 05:02:46 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


STEPS TO REPRODUCE
1. Plug in external monitor on wayland session
2. Desktop becomes extremely laggy and kwin spams " kwin_wayland_drm: Presentation failed! Invalid argument"

ADDITIONAL INFORMATION
Only happens with kwin master, and not kwin 6.1.2. So this suggests some regression in between.
Using the proprietary nvidia drivers. Happens with both 550.90 and 555.58.

Will try a bisection when I have time.. Building kwin just takes soo long...


SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.1.2
KDE Frameworks Version: 6.4.0
Qt Version: 6.8.0
Kernel Version: 6.9.9-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 20 × 13th Gen Intel® Core™ i9-13900H
Memory: 15.2 GiB of RAM
Graphics Processor: Mesa Intel® Graphics
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ROG Zephyrus G16 GU603VV_GU603VV
System Version: 1.0
Comment 1 fanzhuyifan 2024-07-17 07:26:43 UTC
First bad commit is 2799c270b4a7ac96971d6bcc889f347adfcaf558. See https://invent.kde.org/plasma/kwin/-/merge_requests/6041
Comment 2 Zamundaaa 2024-07-17 14:59:09 UTC
Could you get a drm debug log for the failing commits? https://invent.kde.org/plasma/kwin/-/wikis/Debugging-DRM-issues
KWin git master started to use the crtc drm properties for direct scanout with color management; this sounds a lot like the driver rejects commits that had a positive atomic test in actual presentation.
Comment 3 fanzhuyifan 2024-07-17 23:50:25 UTC
I forgot to mention that this is not consistently reproducible. Not sure what exactly triggers the problem. Sometimes rebooting fixes the issue, and sometimes not. Haven't been able to reproduce today. Will upload the drm logs when I see this again.
Comment 4 fanzhuyifan 2024-07-19 04:54:58 UTC
Created attachment 171771 [details]
drm-debug.log
Comment 5 Zamundaaa 2024-07-21 17:23:22 UTC
Is the external output actually connected to the NVidia GPU? The log says the failing atomic commits happen on the Intel driver. Sadly it doesn't explain *why* they fail though
Comment 6 fanzhuyifan 2024-07-21 17:31:49 UTC
(In reply to Zamundaaa from comment #5)
> Is the external output actually connected to the NVidia GPU? The log says
> the failing atomic commits happen on the Intel driver. Sadly it doesn't
> explain *why* they fail though

Yes, the external output is connected to the nvidia gpu. Also I realized that I get "kwin_wayland_drm: Presentation failed! Invalid argument" in the logs even when I disconnect the external monitor. I just didn't realize the issue was still occurring since the lagging gets much better.
Comment 7 fanzhuyifan 2024-07-22 04:30:06 UTC
The issue disappear after commenting out the degamma code here: https://invent.kde.org/plasma/kwin/-/blob/b9ace07d743ec78fe0a6d2ef9b3f445e38791a6b/src/backends/drm/drm_crtc.cpp#L62.
Specifically, lines 62-65. 

Another piece of relevant information: the bug only seems to appear after waking from suspend to ram, but does not always happen after waking.
Comment 8 fanzhuyifan 2024-07-30 20:28:41 UTC
Should I file a report upstream to https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/?
Comment 9 Zamundaaa 2024-07-31 13:36:42 UTC
Yes please. If it doesn't get resolved quickly, please ping me again about it; I think just not using the degamma lut on i915 would be acceptable for 6.2.
Comment 10 Bug Janitor Service 2024-07-31 14:28:07 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6188
Comment 11 fanzhuyifan 2024-08-01 02:21:15 UTC
Upstream bug report: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/11810

For some reason cannot enter it into the url field.