Bug 2188449 - Games stutter badly when vsync in the games is disabled
Summary: Games stutter badly when vsync in the games is disabled
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: kernel
Version: 38
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Florian Müllner
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-04-20 19:26 UTC by klaussemmler
Modified: 2023-08-06 09:17 UTC (History)
23 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:


Attachments (Terms of Use)
Wreckfest Fullscreen (8.33 KB, text/plain)
2023-04-21 14:14 UTC, klaussemmler
no flags Details
Superposition Windowed (2.73 KB, text/plain)
2023-04-21 14:15 UTC, klaussemmler
no flags Details
Superposition Fullscreen (2.46 KB, text/plain)
2023-04-21 14:15 UTC, klaussemmler
no flags Details
Wreckfest Fullscreen Scratch Build (7.91 KB, text/plain)
2023-04-21 14:52 UTC, klaussemmler
no flags Details
Superposition Fullscreen Scratch Build (2.82 KB, text/plain)
2023-04-21 14:52 UTC, klaussemmler
no flags Details
Wreckfest Windowed Scratch Build (2.81 KB, text/plain)
2023-04-21 14:53 UTC, klaussemmler
no flags Details

Description klaussemmler 2023-04-20 19:26:07 UTC
Since the update to Fedora 38 and with that the gnome 44 desktop, games and other 3D applications, that have not vsync enabled are very jittery and stuttery. The framerate itself is as good as before but games do not feel smooth at all. This is also reproducible with benchmarks like Unigine Superposition. Enabling vsync fixes the jitter / stutter nearly completely as side from some rare hangs.

Reproducible: Always

Steps to Reproduce:
1. Open a 3D applications like Unigine Superposition or a game like Wreckfest.
2. If necessary, disable vsync.
3. Run the 3D application.
4. Use the 3D application/move around in the game.
Actual Results:  
The game/application, even though framerate is high (>60) stutter/jitters very badly. 

Expected Results:  
The game/application, should run smoothly with vsync disabled.

The system specs are as follows:

CPU: AMD Ryzen 5 5600
GPU: AMD RX Vega 56
GPU Driver: Mesa 23.0.2
Linux Kernel: 6.2.11
Desktop: Gnome 44
Session: Wayland

If this is the wrong category/component, please put this report into the right place as I am not sure what the culprit is and just guessed based on the behaviour.

Comment 1 Michel Dänzer 2023-04-21 08:37:02 UTC
Does

 gpu_sched.sched_policy=0

on the kernel command line make any difference?

Comment 2 klaussemmler 2023-04-21 10:19:00 UTC
Hello Michel, 

thank you for the fast reply!

Sadly, this did not improve it but I also noticed something new. Not just the 3d application, but also the mouse cursor gets stuttery/jittery. It basically mimics the behaviour of the 3d application. When I close the 3d application, the cursors moves smoothly again. I could see this while running unigine superposition in windowed mode. Using fullscreen does not change anything.

Comment 3 klaussemmler 2023-04-21 12:11:40 UTC
I also tried the X11 Session of Gnome and the issue still persists. So it is not bound to the Wayland session.

Comment 4 Jonas Ådahl 2023-04-21 12:38:21 UTC
Can you see if https://koji.fedoraproject.org/koji/taskinfo?taskID=100209917 makes a difference? It has some experimental patches applied that changes how X11 windows are managed. Note, there might be bugs causing glitchyness etc so be prepared for that.

Comment 5 klaussemmler 2023-04-21 12:48:16 UTC
I will try that. I also did some tests with other games. It seems, that flatpaks are less susceptible to this issue. I also found out that xonotic for example has no issue with stuttering or jitter. There are just some small occasional hangs, which is not optimal, but usable.

Comment 6 klaussemmler 2023-04-21 13:01:51 UTC
I tried the linked package and it did not improve the stuttering. What it did was removing the black squares that got sometimes rendered first when opening an application so it is better than before. Is there some kind of debug information I could gather to make tracking down the issue easier? If yes, how can I do it?

Comment 7 Jonas Ådahl 2023-04-21 13:47:57 UTC
When running the game in fullscreen mode, alt tab to a terminal, run

    sleep 5 && xwininfo -root -tree >& xwintree.txt

and quickly (within 3-4 seconds) alt tab back to the game. Wait for a few seconds, then upload the xwintree.txt file.

Comment 8 klaussemmler 2023-04-21 14:14:00 UTC
I uploaded three log files.

One was with Unigine Superposition Fullscreen, one with Unigine Superposition Windowed and one with Wreckfest Fullscreen. Superposition in Fullscreen was actually pretty okay, but Wreckfest in Fullscreen and Superposition Windowed were really bad.

Comment 9 klaussemmler 2023-04-21 14:14:42 UTC
Created attachment 1958820 [details]
Wreckfest Fullscreen

Comment 10 klaussemmler 2023-04-21 14:15:13 UTC
Created attachment 1958821 [details]
Superposition Windowed

Comment 11 klaussemmler 2023-04-21 14:15:35 UTC
Created attachment 1958822 [details]
Superposition Fullscreen

Comment 12 Jonas Ådahl 2023-04-21 14:26:13 UTC
Was that with the scratch build installed, then you logging out and in again? The way windows are managed when windowed seems to be how they work with what is currently the version in F38.

Anyhow, the suspicion I had was that some window management changes related to window decorations would be the cause of at least the issues when running fullscreen, and that the scratch build would fix the issue if so was the case, but looking at the attached files, it doesn't seem to be that. In the fullscreen case, both Superposition and Wreckfest both have their windows completely undecorated, thus are both unaffected by the window decoration changes between F37 and F38.

Comment 13 klaussemmler 2023-04-21 14:30:12 UTC
No, this was with the build from the fedora repositories. I will redo the testing the patched version.

Comment 14 Michel Dänzer 2023-04-21 14:36:26 UTC
(In reply to klaus.semmler from comment #3)
> I also tried the X11 Session of Gnome and the issue still persists.

Does it affect the mouse cursor in that case as well?

Comment 15 klaussemmler 2023-04-21 14:38:21 UTC
@mdaenzer yes it does.

Comment 16 Michel Dänzer 2023-04-21 14:44:02 UTC
(In reply to klaus.semmler from comment #15)
> @mdaenzer yes it does.

Sounds like a kernel issue then. If you still have an old kernel from F37 lying around, might be interesting to try that.

Comment 17 klaussemmler 2023-04-21 14:51:48 UTC
I sadly do not have an F37 Kernel around anymore. Is there another possibility to use an older kernel aside from compiling?

Comment 18 klaussemmler 2023-04-21 14:52:24 UTC
Created attachment 1958857 [details]
Wreckfest Fullscreen Scratch Build

Comment 19 klaussemmler 2023-04-21 14:52:43 UTC
Created attachment 1958858 [details]
Superposition Fullscreen Scratch Build

Comment 20 klaussemmler 2023-04-21 14:53:32 UTC
Created attachment 1958859 [details]
Wreckfest Windowed Scratch Build

Comment 21 klaussemmler 2023-04-21 14:54:28 UTC
@jadahl I attached the logs created with the mutter scratch build.

Comment 22 Jonas Ådahl 2023-04-21 14:55:35 UTC
Thanks, that confirms that the behavior is the same with and without, and that it's not related to the decoration changes.

Comment 23 klaussemmler 2023-04-21 14:57:38 UTC
@mdaenzer I retested X11 and the cursor is not stuttering there so I think the kernel is not the culprit. Sorry for posting the wrong information!

Comment 24 klaussemmler 2023-04-21 14:57:54 UTC
@

Comment 25 klaussemmler 2023-04-21 15:00:04 UTC
@jadahl Can I install the repository version of mutter again or is the scratch build still necessary for testing? And sorry for the empty comment! My browser decided to just send this comment oO.

Comment 26 Jonas Ådahl 2023-04-21 15:01:35 UTC
You can install the repository version again.

Comment 27 klaussemmler 2023-04-21 15:20:33 UTC
Is there any other data I can provide to help out?

Comment 28 Michel Dänzer 2023-04-21 15:31:18 UTC
Can you try this:

1. Press Alt-F2
2. At the prompt, enter "lg"
3. In the debug window which pops down, go to the Flags tab, scroll down to ClutterDrawDebugFlag and enable PAINT_DAMAGE_REGION
4. Press Esc to close the debug window

You should now see areas of the desktop getting updated flashing in red/green. If so, does any part of the screen flash in red/green while the test apps are fullscreen?

(Use the same procedure to disable PAINT_DAMAGE_REGION again)

Comment 29 klaussemmler 2023-04-21 15:46:27 UTC
The fullscreen apps are not flashing in any color. It seems odd to me, that the apps are smooth with vsync enabled and stuttery/jittery without vsync.

Comment 30 Michel Dänzer 2023-04-21 16:08:44 UTC
(In reply to klaus.semmler from comment #29)
> The fullscreen apps are not flashing in any color.

To be clear, the desktop is flashing while no app is fullscreen though, right?

> It seems odd to me, that the apps are smooth with vsync enabled and stuttery/jittery without vsync.

Indeed, and it's still pointing to a kernel issue, at least in the fullscreen case. mutter 44 explicitly waits for the GPU to finish drawing to client buffers before using them for direct scanout, but the amdgpu kernel driver seems to fail to update the HW cursor & scanout buffer for the next display refresh cycle for some reason.

Comment 31 klaussemmler 2023-04-21 16:36:07 UTC
Yes, the desktop and the apps on it flash. Mostly red. Are there some logs from the kernel driver that could help with debugging?

Comment 32 klaussemmler 2023-04-21 17:25:38 UTC
The apps in fullscreen did not flash, just to be clear.

Comment 33 klaussemmler 2023-04-22 08:03:45 UTC
As a debugging measure, I tried to force the high dpm power state to force the maximum clock speed with the following command:

echo high > /sys/class/drm/card1/device/power_dpm_force_performance_level

This had no effect on the issue sadly.

Comment 34 klaussemmler 2023-04-22 08:14:55 UTC
The next thing I treid was to disable resizable bar in the bios of my system. This also did not yield any improvement.

Comment 35 klaussemmler 2023-04-22 09:25:16 UTC
I now tried to reproduce the issues when running Unigine Superposition from an Live ISO. I first tried the KDE Spin to see if the issue still occurs. And interestingly the issue did not occur. With KDE, the rendering was always smooth. Windowed and in Fullscreen. I then tried the Workstation ISO with Gnome as default desktop. With the workstation ISO I could reproduce the stuttering I encounter on my desktop. As the kernel and mesa packages were the same on both ISOs, I think the issue is not the kernel but the compositor or desktop.

Comment 36 klaussemmler 2023-04-22 15:25:29 UTC
I now took some time to install KDE on my PC and had mixed results. On one Hand Unigine Superposition is smooth like in the Live ISO, but Wreckfest is still stuttery/has microstutter. Sometimes it is smooth, but on other parts of an track, it stutters. Different proton versions did not change anything. Using VSync still fixes this problem. Now I am out of ideas on what to test further.

Comment 37 klaussemmler 2023-04-29 18:00:11 UTC
As my Vega 56 seemed to be defective as it shut down for no reason quite often, I replaced it with an Radeon RX6600. Sadly the issues still persist.

Comment 38 klaussemmler 2023-05-03 13:38:36 UTC
Would profiling Unigine Superposition with an app like Sysprof help to track down the issue?

Comment 39 klaussemmler 2023-05-03 20:59:34 UTC
@mdaenzer Sorry for the noise but I actually have some interesting debugging results.

I tested the Fedora 37 Live Media with kernel 6.0.7 and everything rendered smoothly, no stuttering whatsoever.
Then I tested Manjaro 22.1 with kernel 6.1.25 and here again everything rendered smoothly.
Then, as a control, I tried Ubuntu 23.04, which also used kernel version 6.2 like Fedora 38 and the stuttering/jittering was back.

So this issue got introduced with kernel version 6.2 and is not isolated to Fedora as Ubuntu has the same issue.
I therefore changed the affected component from mutter to kernel as the issue seems to be introduced with kernel version 6.2.

Comment 40 Michel Dänzer 2023-05-04 16:47:06 UTC
(In reply to klaus.semmler from comment #39)
> So this issue got introduced with kernel version 6.2 and is not isolated to
> Fedora as Ubuntu has the same issue.

Sounds like https://gitlab.freedesktop.org/drm/amd/-/issues/2516 then.

The fact that gpu_sched.sched_policy=0 on the kernel command line doesn't help indicates that there was a second regression separate from the commit identified there. Bisecting the kernel between 6.1 & 6.2 with gpu_sched.sched_policy=0 on the kernel command line should allow identifying that second regression.

Comment 41 klaussemmler 2023-05-04 17:09:56 UTC
Ah, good to know there is already an open issue. Sadly I never had bisected kernel issues and don't know how to do it. Also the pc with this issue is my main pc and ending up bricking it would be problematic.

Comment 42 klaussemmler 2023-05-15 22:10:32 UTC
@mdaenzer I tried a fedora rawhide live image with the 14th may as the build date with linux kernel 6.4.0 RC1 and the issue still persists.

Comment 43 Michel Dänzer 2023-05-16 09:21:40 UTC
(In reply to klaus.semmler from comment #42)
> @mdaenzer I tried a fedora rawhide live image with the 14th may
> as the build date with linux kernel 6.4.0 RC1 and the issue still persists.

That's not surprising, since no fix has been proposed, nor has there been any more information about which specific commit between 6.1 & 6.2 introduced the issue (see comment 40).

Comment 44 klaussemmler 2023-07-23 13:13:37 UTC
If I am not mistaken, there seems to be a fix for this on the mesa side of things, if I understand this correctly:

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23965

I found this MR here: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9189

Would like to test the mesa patch, but I don't want to bork my work setup.
 A copr repository would simplify testing a lot and would make a rollback very easy.

Comment 45 Michel Dänzer 2023-07-24 14:25:08 UTC
(In reply to klaus.semmler from comment #44)
> If I am not mistaken, there seems to be a fix for this on the mesa side of
> things, if I understand this correctly:
> 
> https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23965
> 
> I found this MR here: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9189

That issue was bisected to a change which landed in kernel 5.18/5.19, so it's unlikely to be the same issue as this.

If if was, running the game with the environment variable `radv_zero_vram=false` should give mostly the same performance benefit as the Mesa MR above (assuming the game uses Vulkan).

Comment 46 klaussemmler 2023-08-06 09:17:08 UTC
After the update to Mesa 23.1.5, the issues improves a bit. Now Superposition has good Framepacing in Fullscreen and borderless window mode. Only in windowed mode it has still terrible framepacing. Other games like Wreckfest did not improve. I will try to bisect the issue when time allows it. Sadly that is not the case currently, but at least the mesa update improves stuff a bit.


Note You need to log in before you can comment on or make changes to this bug.