godotengine / godot

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

VSync Mailbox causes 100% GPU usage #89856

Open Anixias opened 7 months ago

Anixias commented 7 months ago

Tested versions

v4.3.dev5.mono.official [89f70e98d]

System information

Windows 11 - Vulkan and DirectX 12 - Forward+ and Mobile

Issue description

The project was having extremely horrible jitter of frames (constantly switching back to old frames randomly, causing disorienting blur and horrible artifacts), so I tried every VSync mode. Mailbox completely fixed the issue I was facing, but instead of using less than 15% of my GPU on other modes, Mailbox mode instantly forces my GPU to 100% regardless of rendering complexity. It will remain at 100% (never dipping lower) until the game is closed.

Note that my horrible rendering issue only appears in Forward+ and Mobile. Vsync Enabled in Compatibility does not have the issue I was facing.

Steps to reproduce

  1. Use VSync Mailbox mode in Forward+ or Mobile rendering mode
  2. Presumably render something. In my case, I have a simple grid of lines rendering in 2d.
  3. Open Task Manager and view the Performance tab

Minimal reproduction project (MRP)

N/A

mrjustaguy commented 7 months ago

This is expected, as it's rendering as many frames as the CPU can possibly send to it, and Mailbox only works on forward and mobile renderers - https://docs.godotengine.org/en/stable/classes/class_displayserver.html

VSyncMode >VSYNC_MAILBOX = 3 Displays the most recent image in the queue on vertical blanking intervals, while rendering to the other images (no tearing is >visible). Framerate is unlimited (notwithstanding Engine.max_fps). Although not guaranteed, the images can be rendered as fast as possible, which may reduce input lag (also called "Fast" V-Sync mode). VSYNC_MAILBOX works best when at least twice as many frames as the display refresh rate are rendered. Behaves like VSYNC_ENABLED when using the Compatibility rendering method.

The issue you are having with other modes is a known issue however - https://github.com/godotengine/godot/issues/84137

This is also why mailbox is resolving it, as it's brute forcing the issue away by rendering many more frames, ensuring that the frame that gets displayed is newer then the last one displayed.

Calinou commented 7 months ago

I'm surprised Mailbox V-Sync results in much higher GPU utilization than Disabled V-Sync though, as both are pretty much rendering the same framerate in most situations.

Unfortunately, not many Vulkan games expose mailbox V-Sync to the user so you could check this in applications other than Godot.