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

Increased input-to-screen latency on vulkan #6932

Open
adrian17 opened this issue Jan 16, 2025 · 5 comments
Open

Increased input-to-screen latency on vulkan #6932

adrian17 opened this issue Jan 16, 2025 · 5 comments
Labels
api: vulkan Issues with Vulkan area: wsi Issues with swapchain management or windowing help required We need community help to make this happen.

Comments

@adrian17
Copy link

adrian17 commented Jan 16, 2025

Description
Some users (of Ruffle) reported noticeable lag between input and game response, we were very surprised to realize that it doesn't seem to be related to event handling and that it only happens on Vulkan wgpu backend.

Repro steps
In general: write any code that's based on user input, observe the latency between user input and visible response.

Specific repro:
https://github.com/adrian17/wgpu-latency-repro
(This is based on tutorial code https://github.com/sotrh/learn-wgpu/tree/master/code/beginner/tutorial4-buffer , I just updated wgpu and added code to make the triangle follow the mouse)

Just run the code with cargo run --release, move the mouse and observe the triangle following the mouse. Test with different wgpu::Backends values.

Expected vs observed behavior
On DX12 and GL, the triangle seems to follow the cursor very closely, seems to be a frame behind the OS cursor, the latency isn't really noticeable unless I pause the recording. (GL seems to occasionally lag behind slightly more, but that might be my observation error)
On Vulkan, the triangle very noticeably lags behind the cursor.

Extra materials
Vulkan demo:

repro_vulkan.mp4

DX12 demo:

repro_dx12.mp4

Platform
Windows 10, tested on wgpu 0.23, 0.24.

@cwfitzgerald cwfitzgerald added type: question Further information is requested area: wsi Issues with swapchain management or windowing labels Jan 16, 2025
@cwfitzgerald
Copy link
Member

Try playing with https://wgpu.rs/doc/wgpu/type.SurfaceConfiguration.html#structfield.desired_maximum_frame_latency and see if that helps things out?

@adrian17
Copy link
Author

Reducing it to 1 indeed seems to reduce visible latency a bit, but it's still noticeably worse than on DX12.

I know it's not much of a scientific measurement, but to my naked eye on DX12 (no matter what desired_maximum_frame_latency value I use) the drawn cursor appears nearly glued to the OS cursor, while with Vulkan it always seems to be trailing behind.

@Wumpf
Copy link
Member

Wumpf commented Jan 17, 2025

Someone documented this here as well and was able to demonstrate it for the different backends

@cwfitzgerald cwfitzgerald added api: vulkan Issues with Vulkan help required We need community help to make this happen. and removed type: question Further information is requested labels Jan 17, 2025
@aloucks
Copy link
Contributor

aloucks commented Jan 18, 2025

You're using Fifo with Vulkan and Mailbox with DX12. I'm not sure why the surface caps are reported in different orders but when you keep the present mode fixed, the discrepancy with the backends goes away. Both DX12 and Vulkan have high latency with Fifo and both have less latency with Mailbox or Immediate. Interestingly, the GL backend has less latency that Vulkan and DX12 in Fifo mode.

@adrian17
Copy link
Author

Oops, you're right. That said, the original issue in Ruffle was present even though we already only used Fifo there.

And indeed, when I force present_mode: wgpu::PresentMode::Fifo in the reproduction code, I still see the difference (it's less visible on 30/60fps recordings, but more obvious on an 144hz monitor). Across values of desired_maximum_frame_latency between 1 and 10, it always feels like the dx12 latency is several frames lower / halved.

Here's another repro, with Fifo, desired_maximum_frame_latency: 1 and a cursor movement based on SystemTime. Top is Vulkan, bottom is DX12. Vulkan variant is visibly behind. (for reference, the source for this is at https://github.com/adrian17/wgpu-latency-repro/tree/system-time-comparison )

chrome_2025-01-18_12-58-24.mp4

(With Mailbox, they appear equal. However, Vulkan+Mailbox appears to use way more CPU, seemingly a full core all the time. Is this a driver quirk, to be expected...? Mentioning this on a side, since the main topic is about Fifo latency.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vulkan Issues with Vulkan area: wsi Issues with swapchain management or windowing help required We need community help to make this happen.
Projects
None yet
Development

No branches or pull requests

4 participants