godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.12k stars 19.94k forks source link

Microstuttering on Windows with VSync #71391

Open TinkerWorX opened 1 year ago

TinkerWorX commented 1 year ago

Godot version

v4.0.beta10.mono.official [d0398f62f]

System information

Windows 11 22H2, GeForce GTX 1080, GeForce Game Ready Driver 528.02, default backend (Vulkan?)

Issue description

On my machine I get micro stutters more or less consistently. In Godot 3 there was the following setting that fixed the issue: image I am unable to find this setting in Godot 4, which means I'm now dealing with persistent micro stutters.

Steps to reproduce

Make any project with a camera that can move and some objects that are visible, observe the stutters in the camera as it moves around, make sure vsync is enabled.

Minimal reproduction project

N/A

Calinou commented 1 year ago

Related to https://github.com/godotengine/godot/issues/71361.

Vsync via Compositor was removed because it had lots of issues, such as arbitrarily enforcing half refresh rate V-Sync on some setups.

@TinkerWorX Please upload a minimal reproduction project to make this easier to troubleshoot.

Can you reproduce this after switching to the Mobile rendering method in the advanced Project Settings? Also try the Compatibility rendering method.

Also, does this only occur on startup or does it keep occurring after several minutes of running the project? Does this occur when the editor is not open in the background? Does this occur in an exported project in release mode?

strellydev commented 1 year ago

Hello, I don't know if this is the same issue, but when using the Vulkan renderer and having VSync on the game stutters quite a lot if I run it from the editor. In fact, with Vsync, it rarely reaches 60FPS, hovering around 57-58.

This does not happen when I don't have vsync on, or when running the exported version of the game and using vsync on it.

Calinou commented 1 year ago

Hello, I don't know if this is the same issue, but when using the Vulkan renderer and having VSync on the game stutters quite a lot if I run it from the editor.

Do you have the remote scene tree visible in the editor when running the project? This may cause stuttering as per https://github.com/godotengine/godot/issues/13219.

strellydev commented 1 year ago

Do you have the remote scene tree visible in the editor when running the project? This may cause stuttering as per #13219.

Interesting, I didn't have auto switch to remote scene tree on, but by setting both Remote Scene Tree Refresh Interval and Remote Inspector Referesh Interval to 0.1 like a comment in that issue suggested, all the stuttering was gone.

Thanks!

Zireael07 commented 1 year ago

That refresh interval trick should be documented somewhere imho

Calinou commented 1 year ago

It's strange that decreasing these settings from their default resolves the stuttering for you. There are 2 possibilities here:

strellydev commented 1 year ago

It's strange that decreasing these settings from their default resolves the stuttering for you. There are 2 possibilities here:

* Lower interval means less data is sent between ticks, leading to less time spent blocking on updates.

* Stuttering still occurs, but is so common you end up not noticing it. I recommend using an external frametime graph tool like RTSS or MangoHud to confirm this.

Hmm... Yeah it seems yesterday was a fluke, it's been stuttering today as well. But I'm not even on the remote scene tree.

Calinou commented 7 months ago

@TinkerWorX Can you (or anyone else) still reproduce this bug in Godot 4.2.1 or any later release?

If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this report (a MRP is a zipped Godot project with the minimal elements necessary to reliably trigger the bug). You can upload ZIP files in an issue comment with a drag and drop.

Also, we need more information about your setup:

Calinou commented 6 months ago

Closing due to lack of response. Please comment if you can still reproduce this bug on the latest Godot version.

PS: Since no minimal reproduction project was included in the original bug report, please upload one as well to ease troubleshooting.

TinkerWorX commented 4 months ago

Apologies for not updating this, real life got in the way, here's some more documentation, as of v4.3.dev4.mono.official [df78c0636], where the issue still persists.

Here's a project used for testing: JitterBug.zip You can switch between vsync modes in the project settings.

Here's an example video. The quality is bad because any conventional screen recording wouldn't catch the issue, so I had to grab a 240 FPS video from my phone. Ignore any vertical movement, that's just the camera not being still, it's the horizontal movement that is interesting.

The top movement has vsync enabled, and shows clear stuttering. The bottom movement has vsync disabled, and shows smooth movement.

https://github.com/godotengine/godot/assets/1730988/dbfe6dc8-b18a-441b-bf29-e8e82ce1c9fd

Every other setting is identical, other than vsync mode.

Just to add, I'm using a 75Hz display with AMD FreeSync. In 75Hz mode, there is stutter with vsync enabled and tiny jumps with vsync disabled. In 60Hz mode, there is stutter with vsync enabled and no perceptible jumps with vsync disabled, likely because the physics rate is set to 60 as well.

Calinou commented 4 months ago

Can you reproduce this with the Compatibility rendering method? If not, this is likely a duplicate of https://github.com/godotengine/godot/issues/84137.

TinkerWorX commented 4 months ago

I get the same microstuttering with Compatibility rendering. This is a bug I've been following for a long time, even before Godot, and my conclusion is that it's related to the Windows compositor and certain combinations of hardware. It's never an issue with DirectX, only with OpenGL/Vulkan. Would be great if we could have the Vsync via Compositor option back, and then just make it a setting for my players, so if it does bug or cause issues, they can just opt to not use it.

EDIT: Just wanted to add, it might still be the same issue possibly, but for me running with Compatibility doesn't fix the issue.

Calinou commented 4 months ago

It's never an issue with DirectX, only with OpenGL/Vulkan.

Remember that on NVIDIA, you can force any OpenGL/Vulkan app to be presented via DXGI in the driver options: https://github.com/godotengine/godot-proposals/issues/5692#issuecomment-1405829216

Godot 4.3 also has a Direct3D 12 rendering driver which you can try:

Rendering via Direct3D automatically uses DXGI by design on all vendors, not just NVIDIA.

TinkerWorX commented 4 months ago

I'll try the NVIDIA DXGI setting. Initial test didn't fix anything, but I'll need to do a few more tests where I also reboot my system.

I tried to use Direct3D12, but Godot refuses to launch when I do that, but maybe I was missing that dll, I guess I need to file a different issue for that if it still doesn't work.

TinkerWorX commented 4 months ago

A quick update, using the DirectX Shader Compiler and Direct3D 12 mode alleviates the issue.

D3D12 12_0 - Forward+ - Using Device #0: NVIDIA - NVIDIA GeForce GTX 1080

I assume the above log message confirms it's now using Direct3D 12 instead.

maridany1999 commented 2 months ago

Using Direct3D 12 and Exclusive Fullscreen was the only settings that fixed this issue for me.

Also, I experimented all other settings with no success (Direct3D 12 and Window Mode, Vulkan and Exclusive Fullscreen Mode, etc), it would always randomly stutter, and after minimizing and focusing the window again would fix it temporarily. When it started to stutter, everything in the profiler, Monitors, Video RAM, etc, seemed normal (including the FPS which were stable at 60 for me).