hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
19.75k stars 839 forks source link

Cursor lagging in games #5611

Open LachlanS7 opened 5 months ago

LachlanS7 commented 5 months ago

Hyprland Version

System/Version info ```sh Hyprland, built from branch main at commit ccbdce7c8528781020b39ddf4498277df5e5e78d (input: send an empty relative event after constraint motion events). Date: Tue Apr 16 01:52:25 2024 Tag: v0.39.0-9-gccbdce7c, commits: 4453 flags: (if any) System Information: System name: Linux Node name: topos Release: 6.8.6-arch1-1 Version: #1 SMP PREEMPT_DYNAMIC Mon, 15 Apr 2024 14:05:39 +0000 GPU information: 2d:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 22 [Radeon RX 6700/6700 XT/6750 XT / 6800M/6850M XT] [1002:73df] (rev c5) (prog-if 00 [VGA controller]) os-release: NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch BUILD_ID=rolling ANSI_COLOR="38;2;23;147;209" HOME_URL="https://archlinux.org/" DOCUMENTATION_URL="https://wiki.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues" PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/" LOGO=archlinux-logo plugins: ```

Bug or Regression?

Bug

Description

Hi there!

I have an issue where my cursor lags in games (really only DX11 Baldur's Gate 3, but I believe I have seen it in other games before, but can't find direct evidence from a short search). I have confirmed that this issue is not present in KDE Plasma (Wayland) and Sway, and persists after playing around with the variables

This issue is also not solved by gamescope (still not present when running with gamescope on other WMs/DEs). I have also tried patching my kernel using the patches here, and this didn't make a difference. Capping my framerate does understandably help (as the GPU isn't as stressed), but the issue is still prevalent unless I cap the FPS significantly, and I don't believe I should need to cap my framerate for my cursor to be smooth. I have also tried a "minimal" Hyprland config, and this didn't change anything (view the config below).

Minimal config tried ``` monitor=DP-1,2560x1440@165,0x0,1 env = XDG_SESSION_TYPE,wayland env = XDG_CURRENT_DESKTOP,Hyprland env = XDG_SESSION_DESKTOP,Hyprland general { border_size = 0 no_border_on_floating = true gaps_in = 0 gaps_out = 0 layout = dwindle extend_border_grab_area = 0 hover_icon_on_border = false no_cursor_warps = false apply_sens_to_raw = false } decoration { rounding = 0 drop_shadow = false shadow_range = 0 shadow_scale = 0 blur { enabled = false passes = 0 } } animations { enabled = false first_launch_animation = false } input { kb_layout = us follow_mouse = 1 sensitivity = 0 force_no_accel = false } xwayland { force_zero_scaling = true use_nearest_neighbor = false } misc { vrr = 2 } dwindle { pseudotile = yes preserve_split = yes } $mainMod = SUPER bind = $mainMod, RETURN, exec, foot bind = $mainMod, D, exec, wofi --show drun bind = $mainMod, C, killactive bind = $mainMod, F, fullscreen bind = $mainMod, 1, workspace, 1 bind = $mainMod, 2, workspace, 2 bind = $mainMod SHIFT, 1, movetoworkspace, 1 bind = $mainMod SHIFT, 2, movetoworkspace, 2 ```

This issue is further complicated by enabling debug:overlay, which was reporting the fps to be ~25 when the game was claiming ~70fps.

How to reproduce

Run Baldur's Gate 3 on Hyprland with DX11, and set the settings to stress your GPU. The cursor should feel jittery with both vrr on and off.

Crash reports, logs, images, videos

I recorded two videos using the same settings, one on KDE Plasma (Wayland), and the other on Hyprland.

https://github.com/hyprwm/Hyprland/assets/57027406/0a26adae-1171-4561-bdb5-74234997a785

https://github.com/hyprwm/Hyprland/assets/57027406/ef50aec5-457f-43c0-96fc-78613a4a3b2f

As you can tell, the cursor on the Hyprland one is noticeably jittery, meanwhile, the animations and the KDE Plasma one is smooth. (please ignore the frametimes. This is an artifact of recording it. The frametime graphs looks similar when not recording).

p.s. special thank you to unknown6195 on Discord, for their help trying to debug this issue.

donovanglover commented 5 months ago

FWIW I can reproduce huge fps drops when moving the cursor around in wine applications like osu! (e.g. 60 to 1-20).

The faster the mouse moves the more lag there is. Doesn't happen when moving the mouse slowly. Lags less (60 to 30 instead of 1) when holding down the right mouse button.

For me I think this started sometime after 0.34.0. No lag with the trackpad

EvilBoi123 commented 3 months ago

wait, wtf? i just realize this. I thought it is my driver or dxvk side of fault.

Minimal config tried This issue is further complicated by enabling debug:overlay, which was reporting the fps to be ~25 when the game was claiming ~70fps.

yeah thats, the problem, even with dxvk overlay, the framerate told a false fps, it reported higher than it actually render on screen somehow.

LachlanS7 commented 3 months ago

wait, wtf? i just realize this. I thought it is my driver or dxvk side of fault.

Minimal config tried This issue is further complicated by enabling debug:overlay, which was reporting the fps to be ~25 when the game was claiming ~70fps.

yeah thats, the problem, even with dxvk overlay, the framerate told a false fps, it reported higher than it actually render on screen somehow.

Ohh, you've seen this issue too. Do you recall what you were doing when you noticed it?

EvilBoi123 commented 3 months ago

Ohh, you've seen this issue too. Do you recall what you were doing when you noticed it?

Nothing really, one day i just want to try KDE but somehow it is much smoother there. So you could say i played my game lagging all this time without noticing.

For me I think this started sometime after 0.34.0. No lag with the trackpad

but since @donovanglover says it's starts from 0.34.0 i'd say maybe its started from there is the good bisect, i'll have to try out this later, once i return to my library.

EvilBoi123 commented 3 months ago

yeah, i've recompiled v0.34, the cursor and framerate was smoother there. v0.35 onwards have this issue introduced. compiling with legacyrenderer also wouldn't help.

LachlanS7 commented 3 months ago

yeah, i've recompiled v0.34, the cursor and framerate was smoother there. v0.35 onwards have this issue introduced. compiling with legacyrenderer also wouldn't help.

Oh wow! Thank you for trying this. I'll give this a shot and report back as soon as my exams are over in a few days.

EvilBoi123 commented 2 months ago

okay, i have some findings to share. It turns out after testing with wayfire, it seems somehow the wayfire were also affected by this. Same goes to sway, but sway somehow is less laggy than other wlroots based compositor out there.

KDE desktop were not affected by this maybe because they were not wlroots? My guess would be it maybe the wlroots side of fault.

I also realized when i launch one of my game, all the wlroots compositor will open it in tiling mode insted of fullscreen, which is weird, all this time it should work and it launches normally in KDE.

izmyname commented 2 months ago

okay, i have some findings to share. It turns out after testing with wayfire, it seems somehow the wayfire were also affected by this. Same goes to sway, but sway somehow is less laggy than other wlroots based compositor out there.

KDE desktop were not affected by this maybe because they were not wlroots? My guess would be it maybe the wlroots side of fault.

I also realized when i launch one of my game, all the wlroots compositor will open it in tiling mode insted of fullscreen, which is weird, all this time it should work and it launches normally in KDE.

I suggest you test it on the latest hyprland-git, since the compositor is no longer wlroots based.

LachlanS7 commented 1 month ago

Sorry for the wait. I've tried aquamarine, and I've found that despite trying it before, no_hardware_cursors = true has substantially improved my cursor issues on Baldur's Gate 3.

Having said this, either no_hardware_cursors = true or no_direct_scanout = true has caused visual stuttering in games. From limited testing, this doesn't happen with those using vulkan (definitely those using DXVK not sure about DX12). The stuttering looks like that in #6359, so I suspect they might be related.

LachlanS7 commented 1 month ago

I noticed that #7110 was merged, and decided to try it out. I believe my build before was just before this MR was accepted (built <24 hours ago), hence I believe my following observations are as a result of this MR. It seems like my stuttering issues have been resolved, however, I need no_hardware_cursors = true or else games will permanently freeze. Furthermore, the cursor stutter I had in BG3 has returned.

EvilBoi123 commented 1 month ago

Sorry for the wait. I've tried aquamarine, and I've found that despite trying it before, no_hardware_cursors = true has substantially improved my cursor issues on Baldur's Gate 3.

Having said this, either no_hardware_cursors = true or no_direct_scanout = true has caused visual stuttering in games. From limited testing, this doesn't happen with those using vulkan (definitely those using DXVK not sure about DX12). The stuttering looks like that in #6359, so I suspect they might be related.

hmm i don't know, the issue still persist even after i'm experiment around with no_hardware_cursors but the good thing is, my game now fullscreen on default, not like the previous version. So it is still improvements.

LachlanS7 commented 1 month ago

hmm i don't know, the issue still persist even after i'm experiment around with no_hardware_cursors but the good thing is, my game now fullscreen on default, not like the previous version. So it is still improvements.

Huh. I suspect our issues might be unrelated then. I thought I noticed general mouse stutter on all games in the past, but I'm not sure if I can still notice it (it was always subtle). I will try test for your specific issue more in a lil while.

EvilBoi123 commented 1 month ago

hmm i don't know, the issue still persist even after i'm experiment around with no_hardware_cursors but the good thing is, my game now fullscreen on default, not like the previous version. So it is still improvements.

Huh. I suspect our issues might be unrelated then. I thought I noticed general mouse stutter on all games in the past, but I'm not sure if I can still notice it (it was always subtle). I will try test for your specific issue more in a lil while.

my games runs fine and all but the thing is when my game renders 30 fps, my cursor would also renders at those fps. Other compositor would always render at refresh rate of monitor regardless of what fps their games renders at.