-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add better async support for wgpu-native #609
Conversation
I'm answering this in the mean comments, since I want to be able to read back what I write later 😄 Good question. The short answer is no. Such an API would require wgpu-native to run a separate thread or something, which will introduce other complications, which is why they did not go this route. The longer answer: in (probably) the next release of wgpu-native, we can use
One problem with the above: it'd bind us to But in the end, the current solution works pretty well. Yes, it turns your CPU to 100%, but the wait time for these functions is typically very short, and other async tasks can run while this happens. BTW: I also added a section in the top comment on the upcoming API, with links to docs that explain it. |
I am updating the examples so |
Oh, I have a codegen issue to fix before this can be merged. |
Well, good to hear some improvement is coming later on. Futures are designed to solve this problem specifically. All we need is a callback to resolve the future. :) |
Relates to #391
This PR adds support for true async behavior for wgpu-native, to the extend that this is implemented in wgpu-native.
What this does
WgpuWaitable
as a basic component to use for async methods.Notes
request_adapter()
andrequest_device()
are not really async in native (only in wasm/remote implementations?)wgpuDeviceCreateRenderPipelineAsync
is not yet implemented 🤷buffer.map_async()
.webgpu.h
is in the process of being changed, so we will have to modify the code later, but it will likely be good that we have our basics in place. See below.The new upcoming wgpu-native API
(Also added this info to #391)
In the new API, wgpu-native methods that are async will return a "GPUFuture". This future can be polled (similar to what we do now), and there will be a call to wait for the future:
wgpuInstanceWaitAny()
. The latter, however, won't help make it async in Python. There is an idea for an API to expose OS-level constructs so proper integration with an event loop is possible.