Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extreme stuttering in Apex Legends #2085

Closed
ThatOneCalculator opened this issue Apr 17, 2023 · 59 comments
Closed

Extreme stuttering in Apex Legends #2085

ThatOneCalculator opened this issue Apr 17, 2023 · 59 comments
Labels
bug Something isn't working reason-unknown The cause of this is unknown

Comments

@ThatOneCalculator
Copy link
Contributor

Apex Legends stutters immensely when compared to GNOME despite being launched the exact same way (Lutris with gamescope enabled)

@ThatOneCalculator ThatOneCalculator added the bug Something isn't working label Apr 17, 2023
@vaxerski
Copy link
Member

sway?

@lou-perret
Copy link

It works fine for me on Steam, did you try it ?

@ThatOneCalculator
Copy link
Contributor Author

Sway is weird and refuses to launch apps for me, but Wayfire (built as wayfire-git from the aur) gives the sane performance as GNOME, so it does appear to be Hyprland specific.

@ThatOneCalculator
Copy link
Contributor Author

It works fine for me on Steam, did you try it ?

Lutris just acts as a launcher for Steam games, although I did try Steam directly and got the same results.

@Edgars-Cirulis
Copy link
Contributor

Same here but with other games, Games stuttering compared to KDE in my case.

@vaxerski
Copy link
Member

but Wayfire (built as wayfire-git from the aur) gives the sane performance as GNOME, so it does appear to be Hyprland specific.

wf doesn't use wlroots-git. It might be a wlr issue after all.

Can anyone check sway-git?

@mistakenelf
Copy link

Apex works well for me through steam. I will say a fresh apex install stutters for me at first until it compiles/caches shaders. Not sure if that’s what your experiencing or not

@ThatOneCalculator
Copy link
Contributor Author

Nah, I went into firing range for almost half an hour and it was still constantly stuttering.

@Edgars-Cirulis
Copy link
Contributor

Tested sway-git it seems it gave me fluid experience on gaming compared to hyprland, but I had mouse issues on sway.

@Edgars-Cirulis
Copy link
Contributor

Any news?

@vaxerski
Copy link
Member

No, idk what's up

@ThatOneCalculator ThatOneCalculator added the reason-unknown The cause of this is unknown label Apr 18, 2023
@Edgars-Cirulis
Copy link
Contributor

Edgars-Cirulis commented Apr 19, 2023

Maybe updating to the latest version of wlroots will fix it? I've seen that they've made a lot of changes. Non-git sway seems have for me have some stuttering.

@vaxerski
Copy link
Member

we are not that far behind -git.

@Edgars-Cirulis
Copy link
Contributor

we are not that far behind -git.

Still it's a try.

@Zeioth
Copy link

Zeioth commented Apr 24, 2023

Try to isolate the issue. It runs perfectly fine on my end. Both on Sway and Hyprland.

@Edgars-Cirulis
Copy link
Contributor

Does it present on latest -git version wlroots had update

@ThatOneCalculator
Copy link
Contributor Author

I can test tomorrow

@Zeioth
Copy link

Zeioth commented Apr 30, 2023

I can confirm. The problem is present on hyprland-git+wlroots-git but not on wlroots+hyprland. The bug is several stuttering and -10 -20 fps

@GrabbenD
Copy link

GrabbenD commented Apr 30, 2023

I've noticed this as well..
Sway/GameScope is visibly smoother than Hyprland (GIT).
Although according to Mangohud, frametimes and fps are very similar (makes me wonder if it's something else)?

GPU: AMD Radeon RX 6800 XT
CPU: Ryzen 9 5950X

@vaxerski
Copy link
Member

I can confirm. The problem is present on hyprland-git+wlroots-git but not on wlroots+hyprland. The bug is several stuttering and -10 -20 fps

Hyprland bundles wlroots, your system wlroots don't matter.

If this is a regression, I'd like a git bisect to be done.

@Edgars-Cirulis
Copy link
Contributor

I can confirm. The problem is present on hyprland-git+wlroots-git but not on wlroots+hyprland. The bug is several stuttering and -10 -20 fps

Could you test with kernel command line parameter gpu_sched.sched_policy=0

@GrabbenD
Copy link

GrabbenD commented Apr 30, 2023

@vaxerski I noticed that if I move with just the keyboard, the stuttering isn't visible (Halo Infinite in my instance but it's most likely the same issue as with Apex Legends). The stuttering/jitter is extreme when moving the mouse even though the frametime is low and fps relatively high.

Could this be related?
https://gitlab.freedesktop.org/drm/amd/-/issues/2186

This issue was mentioned here as well
https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/44#note_897546

One thing that hasn't been mentioned here yet might warrant a protocol for VRR: the hardware cursor. When the application controls the refresh rate a hardware cursor will refresh slowly and stutter, when the cursor controls the refresh rate the application content will appear to stutter. There is also the option of refreshing the panel with a multiple of the application refresh rate while the cursor is changing but that has its limits in hardware and might still cause stutter with strongly fluctuating frame times, though the latter could be somewhat alleviated with present-timing.

What I implemented for KWin is to always give the cursor precedence (I think in Sway it's the same?) and we'll give the user the option to disable that (for fullscreen) but that's far from ideal. While apps that explicitly want to control their timing could always draw a software cursor (or with present-timing only when VRR presentation occurs) that's not really a good solution either.

@Edgars-Cirulis
Copy link
Contributor

@vaxerski I noticed that if I move with just the keyboard, the game is completely smooth (Halo Infinite in my instance but it's most likely the same issue as with Apex Legends). The stuttering only occurs when I actually move the mouse.

Could this be related?

One thing that hasn't been mentioned here yet might warrant a protocol for VRR: the hardware cursor. When the application controls the refresh rate a hardware cursor will refresh slowly and stutter, when the cursor controls the refresh rate the application content will appear to stutter. There is also the option of refreshing the panel with a multiple of the application refresh rate while the cursor is changing but that has its limits in hardware and might still cause stutter with strongly fluctuating frame times, though the latter could be somewhat alleviated with present-timing.
What I implemented for KWin is to always give the cursor precedence (I think in Sway it's the same?) and we'll give the user the option to disable that (for fullscreen) but that's far from ideal. While apps that explicitly want to control their timing could always draw a software cursor (or with present-timing only when VRR presentation occurs) that's not really a good solution either.
(https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/44#note_897546)

Could you test with kernel command line parameter gpu_sched.sched_policy=0

@GrabbenD
Copy link

There's no difference with gpu_sched.sched_policy=0 on a RX 6800 XT :/

@Edgars-Cirulis
Copy link
Contributor

There's no difference with gpu_sched.sched_policy=0 on a RX 6800 XT :/

Does enabling vsync fixes stuttering?

@GrabbenD
Copy link

GrabbenD commented Apr 30, 2023

Does enabling vsync fixes stuttering?

I've tried enabling/disabling these to no avail:

  • Direct scanout
  • VRR
  • VFR
  • 10 bit colors
  • Low/high refresh rate
  • Vulkan/GLES2 renderer
  • WLR_DRM_NO_ATOMIC env
  • WLR_NO_HARDWARE_CURSORS env
  • Mouse acceleration

I may be wrong but it seems like this issue is correlated to the mouse cursor, moving around in game with just the keyboard isn't as jittery/stuttery.

For Sway/wlroots, there's some workarounds (patches) here if it's indeed the mouse cursor causing it (but Hyprland would need to be tweaked to use this patch which is outside of my expertise):

@GrabbenD
Copy link

@ThatOneCalculator This is how the stuttering looks on my end. Is it the same as yours?

https://youtu.be/LuTYTEaJJyI
https://youtu.be/LuTYTEaJJyI

@Edgars-Cirulis
Copy link
Contributor

@ThatOneCalculator This is how the stuttering looks on my end. Is it the same as yours?

https://youtu.be/LuTYTEaJJyI https://youtu.be/LuTYTEaJJyI

Try switching to linux-lts kernel. It should fix.

@GrabbenD
Copy link

GrabbenD commented May 2, 2023

Thanks for the update @Zeioth

  • Did you try Halo Infinite? (It's free on Steam)
  • What's your distro?
  • Which GPU?
  • Did you try it with GameScope? (On my end it almost fixes stuttering completely)
  • Is your FPS below your monitor's fresh rate?

I'm in progress of trying OpenSuSE instead of NixOS.

@GrabbenD
Copy link

GrabbenD commented May 3, 2023

Update: the stuttering in NixOS (hyprland-git 2e28e88) is worse than with OpenSuSE Tumbleweed (Hyprland v0.24.1). OpenSuSE improves fps by 20-30 & decreases frametime with 3-4ms since they're using x64_86-v3 optimization level with LTO+PGO.

Turns out the stuttering only happens when the game runs below my monitor's refresh rate even with vrr=1

~> hyprctl monitors
Monitor DP-3 (ID 0):
	3840x1600@119.982002 at 0x0
	description: Dell Inc. Dell AW3821DW #HLAYMxgwABTR (DP-3)
	make: Dell Inc.
	model: Dell AW3821DW
	serial: #HLAYMxgwABTR
	active workspace: 2 (2)
	reserved: 0 0 0 0
	scale: 1.00
	transform: 0
	focused: yes
	dpmsStatus: 1
	vrr: 1

My monitor's Freesync range is 1-144 hz and it even has a dedicated GSync Ultimate chip :/

For clarification, I pretty much only installed Hyprland, xdg, MESA, codecs, kernel-firmware, pipewire, steam, mangohud & gamemoded while testing this.

@GrabbenD
Copy link

GrabbenD commented May 4, 2023

Another update:

  1. Changing power profile for the GPU (/dev/dri/card0) greatly improved 1% lows and avg fps but the stuttering is still visible when fps falls below monitor's refresh rate:

    # /etc/udev/rules.d/30-amdgpu.rules
    KERNEL=="card0", SUBSYSTEM=="drm", DRIVERS=="amdgpu", ATTR{device/power_dpm_force_performance_level}="manual", ATTR{device/pp_power_profile_mode}="1"
    

    (see: https://gitlab.freedesktop.org/drm/amd/-/issues/1500#note_1854170)

  2. Furthermore I tried using async frames (MESA_VK_WSI_PRESENT_MODE) but it looks like it's not supported by wl-roots yet.
    (see: https://docs.mesa3d.org/envvars.html#envvar-MESA_VK_WSI_PRESENT_MODE)
    (reference: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/65 & https://patchwork.freedesktop.org/series/107683/)

  3. Does enabling vsync fixes stuttering?

    Current conclusion: vsync off (ingame) + vrr=0 (Hyprland) performs exactly the same as: vsync off (ingame) + vrr=1 (Hyprland)
    (it vastly reduces stuttering but it's still there when fps < refresh rate)

It seems like Variable Refresh Rate (VRR) in Hyprland doesn't actually adjust monitor's refresh rate in that case? I have no way of verifying this in my panel unfortunately

@GrabbenD
Copy link

GrabbenD commented May 4, 2023

@ThatOneCalculator If your intermittent stuttering is actually caused by frame drops and not something else like the old fTPM stutter bug in AMD CPUs, I don't think there is much we can do about it until the VRR implementation gets improved: #927

Workaround:
#927 (comment)

Related issues:

Other/gaming related:

@grappas
Copy link

grappas commented May 6, 2023

@ThatOneCalculator Isn't that connected?
#1919
Check it with hyprctl keyword debug:overlay true

@GrabbenD
Copy link

GrabbenD commented May 7, 2023

Great find @grappas!
On my end VRR/vsync seems to be the culprit as the compositor's FPS is correct (debug:overlay=1 + misc:vfr=0):
1683493231-wayshot

@grappas
Copy link

grappas commented May 8, 2023

Great find @grappas! On my end VRR/vsync seems to be the culprit as the compositor's FPS is correct (debug:overlay=1 + misc:vfr=0): 1683493231-wayshot

But just to be sure check it CPU bottlenecked (lowest settings possible).

@GrabbenD
Copy link

GrabbenD commented May 21, 2023

Workaround for VRR stuttering: #927 (comment)


But just to be sure check it CPU bottlenecked (lowest settings possible).

Sure @grappas, I can reproduce your issue by forcing my game to be CPU bound. Let's continue the discussion here: #1919 (comment) (since it's unclear if this PR is about stuttering from VRR or resource starvation as the author isn't replying).

@roman3pm
Copy link

roman3pm commented Oct 3, 2023

Same here on sway. For me is the only way to smooth run Apex is turn screen mode to Windowed and run sway with -Dnoscanout. Switch to Fullscreen or Borderless causes immediate stuttering. Removing noscanout option completely disables vrr. Really annoying but it works for now. Can someone else check that Windowed mode helps with stuttering?

@vaxerski
Copy link
Member

vaxerski commented Oct 3, 2023

why not try on -git with tearing?

@roman3pm
Copy link

roman3pm commented Oct 4, 2023

why not try on -git with tearing?

Can confirm it works but personally not a fan of tearing. Fells pretty stuttery even witn 200+ fps on 144Hz monitor. I'm looking for smooth vrr gameplay, but this game even with regular vsync is kinda of a mess.

@GrabbenD
Copy link

GrabbenD commented Oct 4, 2023

I have not found any way to resolve this in Hyprland 🙁
It has the worst stuttering in comparison to Sway, KDE (Wayland) and RiverWM.
However, I have a really good solution for Sway:

There's 2 parts to this problem

  1. Atomic Modesetting causes mouse's polling rate to affect your monitor's refresh rate. Here's is the new workaround for Sway 1.6 (check this comment for Sway 1.9-dev compatible patches).
    As a reference, here's the outdated solution to this issue.
  2. Direct scanout causes the monitor to run at max refresh rate, here's a workaround for Sway
  3. Extra: make sure VSync is disabled in-game to avoid having multiple buffers
  4. Extra: try to force enable VRR with kernel boot argument on AMD

I've tried this with a RX 6800 XT + Ryzen 9 5950X (fTPM off) + 1000Hz mouse and confirmed this issue exists in multiple monitors in Arch Linux, Fedora & OpenSuSE Tumbleweed:

  • AOC Q32G1WG4
  • MSI MAG27CQ
  • Alienware AW3821DW

why not try on -git with tearing?

Thanks for the idea but this makes it worse, the stuttering is still there and in-game textures are completely smeared out due to tearing.

@vaxerski
Copy link
Member

vaxerski commented Oct 4, 2023

no. 1. has no fix for us AFAIK, it requires a wlroots patch.
no. 2. misc:no_direct_scanout exists and is on by default

@GrabbenD
Copy link

GrabbenD commented Oct 5, 2023

@vaxerski
My monitor's built-in FPS counter reports 6 HZ in desktop when VRR is enabled with Sway. However, with Hyprland it's stuck at 120Hz all the time, even when playing games at 80 FPS. What's strange is that the monitor claims adaptive sync is enabled when using Hyprland. I'm guessing something in Hyprland is constantly pushing max FPS to the screen - maybe to make the animations buttersmooth?

I've tried isolating this issue with various combinations of settings to no avail:

  • misc:vrr 2/1
  • misc:vfr 1/0
  • misc:no_direct_scanout 1/0
  • debug:damage_tracking 2/1/0

I'm not sure what else to try, I've back revising this issue once in a while since March of this year (when I started using Hyprland)

@vaxerski
Copy link
Member

vaxerski commented Oct 5, 2023

what if you enable tearing? without that it will push 2x fps of your game most likely

@grappas
Copy link

grappas commented Oct 6, 2023

However, with Hyprland it's stuck at 120Hz all the time,

It's actually a gamescope thing. If you want i.e. 240Hz you want to set -r 480.

@GrabbenD
Copy link

GrabbenD commented Oct 6, 2023

Thanks for taking a look guys!

what if you enable tearing? without that it will push 2x fps of your game most likely

My games are GPU bounds
I'm getting stable 80-90 FPS
Enabling tearing gives me the same result as @roman3pm, it's still stuttering since the monitor is stuck at 120 HZ

It's actually a gamescope thing. If you want i.e. 240Hz you want to set -r 480.

I don't use Gamescope since I haven't found any performance difference when it's running in nested mode. Nonetheless I tried gamescope -f -r 120 -- %command% and gamescope -f -r 240 -- %command% but the monitor is still stuck at 120 HZ


@vaxerski
When I say the monitor is stuck at 120 HZ, I mean it. It never dips below 120 HZ in Hyprland (in desktop / when watching youtube / playing Steam games / switching workspaces).
I find it strange that I can reproduce this issue on 3 different monitors
I'm currently running Arch Linux with pretty much defaults settings everywhere, I only installed MESA drivers, Pipewire, Wireplumber, Pavucontrol, Steam, Halo Infinite, Brave browser & Foot terminal.

@grappas
Copy link

grappas commented Oct 6, 2023

Have you tried forcing fps with mangohud?

@GrabbenD
Copy link

GrabbenD commented Oct 6, 2023

Have you tried forcing fps with mangohud?

Are you thinking about forcing vsync through MangoHud? Gave this a shot but it made no diference:

# ~/.config/MangoHud/MangoHud.conf

### Vulkan VSync [0-3] 0 = adaptive; 1 = off; 2 = mailbox; 3 = on
vsync=0

### OpenGL VSync [0-N] 0 = off; >=1 = wait for N v-blanks, N > 1 acts as a FPS limiter (FPS = display refresh rate / N)
gl_vsync=1

Considering I have to disable direct scanout in Sway to get the right refresh rate (which I verify with my monitor's OSD), there's probably a similar bug somewhere in Hyprland but I'm not sure how to go about finding it 🙁

@roman3pm
Copy link

roman3pm commented Oct 7, 2023

To uncap fps without vsync in Apex you should switch mangohud's vsync=1 (means off) and in game switch to triple buffering and maybe include launch command +fps_max 300. It helps a bit if you play with tearing on.
Try to play in windowed mode. I saw some pro player streamers plays in windowed mode in OS Windows too. Something strange with this game.
By the way I think Apex devs should pay attention to this. CS2 runs perfectly smooth without any tinkering at all with vsync off.

@ParetoOptimalDev
Copy link

ParetoOptimalDev commented Jan 6, 2024

To uncap fps without vsync in Apex you should switch mangohud's vsync=1 (means off) and in game switch to triple buffering and maybe include launch command +fps_max 300. It helps a bit if you play with tearing on.
Try to play in windowed mode. I saw some pro player streamers plays in windowed mode in OS Windows too. Something strange with this game.

Apex plays fine without stuttering in KDE fullscreen though.

In hyprland though I still get stuttering.

EDIT: It's only smooth in KDE+X11 for me. KDE+wayland equally horrible stuttering to hyprland.

@ParetoOptimalDev
Copy link

Updated workaround I found in another issue is to launch gamescope in embedded mode in another tty:

So press Ctrl+alt+F2, then after replacing your monitor dimensions and frame rate:

https://github.com/ValveSoftware/gamescope/issues/995gamescope -W 1920 -H 1080 -r 144 --adaptive-sync -e -f -- steam

Though things seemed less good with a limited frame rate for me so I do:

https://github.com/ValveSoftware/gamescope/issues/995gamescope -W 1920 -H 1080 --adaptive-sync -e -f -- steam

@GrabbenD
Copy link

GrabbenD commented Jan 8, 2024

@ParetoOptimalDev Next time just leave the link to the workaround instead of making your own half-assed copy & paste with missing details

#927 (comment)

@ParetoOptimalDev
Copy link

ParetoOptimalDev commented Jan 8, 2024

@ParetoOptimalDev Next time just leave the link to the workaround instead of making your own half-assed copy & paste with missing details

#927 (comment)

Don't be an asshole for no reason @GrabbenD

@rurigk
Copy link

rurigk commented Mar 1, 2024

I only noticed stuttering in games in 2 situations
If i use gamescope some games like Apex stutters for me
If i have vrr enabled in my monitor the GPU is stuck at 96mhz (linux 6.7.6)

I have a 6700XT and R7 2700X the monitor is a Samsung Odyssey G5 32" 165hz

@wyqydsyq
Copy link

wyqydsyq commented Jul 4, 2024

Not related to Apex Legends specifically but I've been intermittently having this issue on UE5 based games as well.
Occurring in Mortal Online 2 and Gray Zone Warfare. It's most severe when game FPS is lower than my monitor refresh rate (165hz), if I FPS limit a game to 60fps it's practically motion-sickness inducing. Making sure the game's FPS matches or exceeds my refresh rate minimizes the effect but it is still noticeable.

There is no significant input lag and the game itself seems to be running perfectly smooth, it's just as if the compositor is trying to draw an old frame at the same time the game is sending a new frame to GPU, so the GPU flickers between displaying both.

Tried enabling Hyprland tearing and setting immediate mode on the windows, ingame vsync on/off, no difference.

Edit:
Okay, new development, running Mortal Online 2 in DX11 mode completely eliminates the issue. Leads me to think this may be some compatibility issue specifically between VKD3D and Hyprland/wlroots, as it doesn't occur for me using DXVK (DX11) or on GNOME Wayland

@wyqydsyq
Copy link

Not running -git build but the OpenSUSE TW repo recently updated to 0.42. I can't speak for OP since I don't play Apex Legends but the (mostly UE5 via VKD3D but also happened in BG3 using Vulkan renderer) games that were exhibiting this stuttering for me under wlroots all seem to be fixed now under aquamarine, so it definitely seems to have been a wlroots-specific issue at least in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reason-unknown The cause of this is unknown
Projects
None yet
Development

No branches or pull requests