Bug 472663

Summary: Wayland compositor performance affects mouse cursor
Product: [Plasma] kwin Reporter: Linus Kardell <linus.kardell>
Component: compositingAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: ledo.kane, nate, qydwhotmail, techsav, xaver.hugl
Priority: NOR    
Version: 5.27.6   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.0
Sentry Crash Report:

Description Linus Kardell 2023-07-26 13:21:27 UTC
SUMMARY
When the kwin_wayland compositing can't keep up, it doesn't just make the desktop stutter, it also makes the cursor stutter. This can be noticed due to bug 452119, but I notice especially now because my laptop has switched to llvmpipe after an update for some reason, making kwin_wayland run at about 1-2 FPS. On X11, by contrast, the mouse cursor remains perfectly smooth even if the compositor performs poorly.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20230724
KDE Plasma Version: 5.27.6
KDE Frameworks Version: 5.108.0
Qt Version: 5.15.10
Kernel Version: 6.4.4-1-default (64-bit)
Graphics Platform: Wayland
Processors: 8 × AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx
Memory: 29.3 Gibyte of RAM
Graphics Processor: llvmpipe
Manufacturer: Acer
Product Name: Aspire A315-41
System Version: V1.18
Comment 1 Zamundaaa 2023-07-31 15:31:31 UTC
This can't be fixed in the foreseeable future with llvmpipe as long as it doesn't support either implicit or explicit synchronization with KMS. Fixing it with other drivers is in the works though
Comment 2 Linus Kardell 2023-08-01 11:54:27 UTC
Is https://invent.kde.org/plasma/kwin/-/merge_requests/3828 supposed to improve this?
Comment 3 Zamundaaa 2023-08-01 14:13:37 UTC
I don't think it will make a big difference; it reduces latency when the system can keep up but otherwise it still requires rendering to be fast enough.
https://invent.kde.org/plasma/kwin/-/merge_requests/4268 will make it so that rendering being too slow will be less bad, but it will still drag the cursor refresh rate down to how fast the rest of the screen can render.
I'll close this bug report with a link to the merge request once there's one that actually makes big improvements in this area
Comment 4 Zamundaaa 2023-09-11 13:10:30 UTC
Git commit 4c397a95263d9c8e73d536ab1c2ac2caaeec60e2 by Xaver Hugl.
Committed on 11/09/2023 at 15:02.
Pushed by zamundaaa into branch 'master'.

backends/drm: split commits for the cursor and primary plane

And reorder and merge atomic commits where possible to ensure the cursor always
stays smooth

M  +29   -2    src/backends/drm/drm_commit.cpp
M  +9    -3    src/backends/drm/drm_commit.h
M  +99   -15   src/backends/drm/drm_commit_thread.cpp
M  +1    -0    src/backends/drm/drm_commit_thread.h
M  +45   -30   src/backends/drm/drm_pipeline.cpp
M  +1    -2    src/backends/drm/drm_pipeline.h

https://invent.kde.org/plasma/kwin/-/commit/4c397a95263d9c8e73d536ab1c2ac2caaeec60e2
Comment 5 Fushan Wen 2023-09-16 05:05:45 UTC
*** Bug 463955 has been marked as a duplicate of this bug. ***
Comment 6 Rean 2023-11-30 16:49:04 UTC
This issue was fixed but seems to have come back in the new Plasma 6 beta. The mouse is again lagging when composer performance drops. I tested this before in the earlier Plasma 6 Alpha, and the mouse lag was completely gone even when the desktop was running at 10 fps.
Comment 7 Rean 2023-11-30 18:15:53 UTC
(In reply to Zamundaaa from comment #4)
> Git commit 4c397a95263d9c8e73d536ab1c2ac2caaeec60e2 by Xaver Hugl.
> Committed on 11/09/2023 at 15:02.
> Pushed by zamundaaa into branch 'master'.
> 
> backends/drm: split commits for the cursor and primary plane
> 
> And reorder and merge atomic commits where possible to ensure the cursor
> always
> stays smooth
> 
> M  +29   -2    src/backends/drm/drm_commit.cpp
> M  +9    -3    src/backends/drm/drm_commit.h
> M  +99   -15   src/backends/drm/drm_commit_thread.cpp
> M  +1    -0    src/backends/drm/drm_commit_thread.h
> M  +45   -30   src/backends/drm/drm_pipeline.cpp
> M  +1    -2    src/backends/drm/drm_pipeline.h
> 
> https://invent.kde.org/plasma/kwin/-/commit/
> 4c397a95263d9c8e73d536ab1c2ac2caaeec60e2

There is likely a regression lately.
Comment 8 Zamundaaa 2023-12-02 18:42:36 UTC
Are you on Intel? Due to driver bugs we had to disable the improvements by default for Intel users, see bug 476860
Comment 9 Rean 2023-12-02 20:58:21 UTC
(In reply to Zamundaaa from comment #8)
> Are you on Intel? Due to driver bugs we had to disable the improvements by
> default for Intel users, see bug 476860

Yeah, I'm using an Intel iGPU. I didn't have any of the issues that's mentioned in that bug report, but the mouse lagginess was fixed, and now it's back to being bad again. Maybe not every Intel iGPU has the issue mentioned here: https://bugs.kde.org/show_bug.cgi?id=476860.
Comment 10 Rean 2023-12-02 21:03:53 UTC
(In reply to Zamundaaa from comment #8)
> Are you on Intel? Due to driver bugs we had to disable the improvements by
> default for Intel users, see bug 476860

Is there env veriable that can be set to get this back or no?
Comment 11 Rean 2023-12-02 21:15:45 UTC
Never mind, I found the environment verifiable on https://invent.kde.org/plasma/kwin/-/merge_requests/4632. merge request. Everything is good now the mouse great again. This issue does not affect me, so I can set KWIN_DRM_DISABLE_BUFFER_READABILITY_CHECKS=0. with no issues whatsoever, I don't get the stuttering or half-fps issues.
Comment 12 Rean 2023-12-02 21:42:50 UTC
Also, when readability checks are disabled, I get slight micro freezes as well. I was wondering what was causing that. It seems my Intel iGPU actually get performance issues when readability checks is disabled, and i guess some older igpu's get performance issues with it enabled. This is definitely a strange issue, at least for me. I get way better performance with it on.
Comment 13 Rean 2023-12-05 01:08:22 UTC
Never mind about the micro freezes I mentioned before. After a few days of testing, the micro freezes seem to happen whether I have the readability checks enabled or disabled. Enabling readability checks doesn't make the micro freezes any worse or better, but it makes the mouse lag under heavy loads go away, so I'll leave it enabled since it's not what's causing the freezes; something else is.
Comment 14 Zamundaaa 2023-12-11 16:41:00 UTC
*** Bug 478402 has been marked as a duplicate of this bug. ***