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

Cache Vulkan physical device info to avoid stuttering during resize #182

Closed
jansol opened this issue Sep 28, 2024 · 4 comments · Fixed by #183
Closed

Cache Vulkan physical device info to avoid stuttering during resize #182

jansol opened this issue Sep 28, 2024 · 4 comments · Fixed by #183

Comments

@jansol
Copy link

jansol commented Sep 28, 2024

Based on some quick & dirty println!-profiling, the culprit for Zed's clunky resize performance appears to be in Context::resize(...) in blade-graphics' vulkan code. Further, the vast majority of time in that function appears to be spent in get_physical_device_surface_formats (I've seen it peak over 2000µs on my system) and get_physical_device_surface_present_modes (less bad but also frequently peaks somewhere in the order of 500µs).

Both of these are querying capabilities of the physical device, which are unlikely to change and as such should be trivial to cache. In the event that they change (e.g. due to the window to another monitor that is attached to a different GPU? Or the display mode getting changed while the application is running?) I believe swapchain creating would either fail or presenting would throw a "suboptimal swapchain" or similar error that can be used to force re-querying those device attributes.

@kvark
Copy link
Owner

kvark commented Sep 28, 2024

It's quite unfortunate that get_physical_device_surface_formats is so slow. I wonder if there is a way to explicitly query something like "which monitor is the surface currently on?", so that we can avoid this.
But avoiding unconditionally would be rather strange - you can't expect swapchain creation to gracefully fail, since this would be straight undefined behavior. Vulkan user is supposed to query the formats before recreating the swapchain...

@kvark
Copy link
Owner

kvark commented Sep 28, 2024

The other thing we could do is - avoid swapchain recreation entirely for as long as possible. I.e. if the window is resized, we could allow the "suboptimal" presentation on that surface. As soon as the resize ends, we should actually recreate the surface upon seeing "suboptimal".

@kvark
Copy link
Owner

kvark commented Sep 28, 2024

Now that I re-read the issue, I'm getting more doubt. If get_physical_device_surface_formats is peaking at 2000 us, that's still only 2ms, which is significantly less than our frame budget of 16ms. Alone, it's not a reason for stuttering.

Either way, I'm merging #183, which should resolve at least this call. Let me know if it works!

@jansol
Copy link
Author

jansol commented Sep 28, 2024

You are right, it does not entirely fix the stuttering. The start of a resize does feel markedly more smooth though! Stuttering now only starts after around a second of continuous resize movement (and stopping for a moment makes it become smooth again.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants