-
Notifications
You must be signed in to change notification settings - Fork 942
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
Non-blocking API #1451
Comments
I think having a |
I can add a variation of |
We are going to need to discuss this with @Kangz. Do you have thoughts on poll-based (or asynchronous) way of getting the next texture from the swapchain? |
In vulkan,
My assumption was that the timeout in gfx-hal functions similar, but I may be wrong on that. My plan is to use this to create a function in WGPU that will simply poll for an image, and return the image to the caller if one has been acquired, or return that none could be acquired yet. Since |
That is not true. You need a driver / reactor (There doesn't seem to be a conclusive name. Tokio calls it a driver atm) that calls the waker when the future is ready. |
Thanks @kvark for the head's up. @LaylConway as far as I can see, no other synchronous WebGPU function can block. I wasn't able to find spec language for Vulkan that guarantees that
WebGPU's |
Ok, great, thanks for feedback! |
You either want to pass some callback or specify some small timeout for the future. Otherwise that will either deadlock or be a really hot spinloop. (Or really just use tokio's |
I think I'll have to do a bit more research into The main reason I didn't want to go with Once I can get a few outstanding questions of this implementation idea answered, I'll see if I can put together a PR. |
I made an attempt at implementing this. However it seems that on my (recently updated) NVIDIA driver, acquiring an image never blocks. Instead, presenting blocks. I'm not sure how to move forward from here. To me it seems like this isn't how the API is designed to work, and NVIDIA has a problem with their driver implementation. |
This is surprising and worthy of following up with Nvidia. But does it matter to the API here? Presenting is a one-way command, whether it blocks or not doesn't really matter to the caller, unlike acquiring the image, which has to return something. |
It keeps a thread busy though. I'm rendering to multiple windows, so this is something I'll have to keep in mind as it could keep the rendering thread busy just waiting instead of drawing other windows, slowing down the rest. |
I see. We only have NVidia + Vulkan to blame for that. Want to raise an issue on, say, https://github.com/KhronosGroup/Vulkan-Docs ? That would be great, I'll be happy to assist in discussions, where possible. |
I may later raise an issue there, not sure if this is a docs issue though. There's some other issues that make trying to acquire an image non-blocking hard. I'm trying out a different approach in my code right now which does just shift the blocking tasks to |
Interesting. I do admit the new swapchain model is guilty of sometimes ignoring the timeouts. We need to fix that (having issues filed, etc), as well as the panic thing you are describing. |
I'm going to close this as stale as so much has changed, there are still similar issues open - the current idea is to move get_current_texture onto another thread. There will also be ways to control frame timing such that get_current_texture never waits. See #2650 for another tool that will help you achieve this. |
I'm honestly not sure entirely where I should post this, given the different projects that cover what goes into wgpu, but I figured I would put it here, even if perhaps it needs to be delegated upstream.
I've been working with projects that require rendering across multiple windows, as well as trying to fit the entire project on an async runtime (tokio in my case) to parallelize my projects better, and make better use of worker threads.
At this time WGPU has a function that prevents me from rendering to multiple windows efficiently without creating a thread per window, or putting WGPU rendering code on the tokio runtime. Specifically the function
SwapChain::get_next_texture
.On native platforms, this function will block until the next texture is available. This means that, without using 1 thread per window, all rendering and updating of all windows will stall whenever an attempt is made to render to one window, without any way to in advance detect if it will block.
This also means it can't be used on a tokio runtime, as multiple windows being rendered to will effectively stall worker threads until it's done blocking.
It would be nice if there was an alternative function, or a feature on this function, to never block but instead poll. At the very least the Vulkan backend supports this behavior on acquiring the next swapchain image. This would also make it possible to implement a
Future
around the SwapChain and use WGPU on a tokio runtime without blocking the worker thread.Currently, I don't know if there's any other functions in WGPU that have similar issues, but if there are it would be nice to, where possible, have similar non-blocking APIs available.
The text was updated successfully, but these errors were encountered: