-
-
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
First class async support #391
Comments
Clarification: Right now we've implemented all async functions with polling, in a blocking fashion. It still needs to be investigated if the API exposed by wgpu-native enables a true async implementation in wgpu-py. |
Proposed approach
We should probably just try and see how far we get. |
Update: From the point of view of the API we have full async support, and we have examples to demonstrate it. There's still changes coming up from wgpu-native, which will probably take a while. I moved this issue to the backlog, but since the upcoming improvements in wgpu-native are an implementation detail for us, I think we can actually close this issue. |
Introduction
WebGPU defines certain functions and props as async, so that in an async setting, there is less wait time. Would make a lot of sense to also support that in wgpu-py.
Would be great if we can make this work without forcing asyncio, but also supporting e.g. trio.
At the moment the async API of
wgpu-native
is a bit crude (there is a function to poll its loop). Last I heard was that this API will change at some point. So might be worth waiting for that.In our code, all async methods have an
_async
suffix, and they all have a sync version of the function (that simply waits).Aync parts in WebGPU spec
Updated on 25-09-2024
Methods that are async-only in WebGPU:
gpu.request_adapter_async()
gpu.enumerate_adapters_async()
adapter.request_device_async()
buffer.map_async()
device.lost_async
shadermodule.get_compilation_info_async()
queue.on_submitted_work_done_async()
Method that have both a sync and async variant:
create_compute_pipeline()
create_render_pipeline()
Considerations
createRenderPipelineAsync
andmapAsync
?_sync
to indicate that an async variant is available?Thoughts
I think I'd like to try making wgpu-py async according to the spec, dropping the sync versions. Let's see how far we can take that. In render engines, one could run "draw iteration" on asyncio, if necessary with
loop.run_until_complete()
. Also when inside Qt.If we can make that work, we're more compliant, avoid busy waiting in user code, and remove the biggest hurlde to move to the browser.
Async in wgpu-native
01-10-2024
At the time of writing, this is still somewhat in flux.
References:
State:
wgpuDevicePoll()
(inwgpu.h
).wgpuInstanceProcessEvents()
is added as we speak: Implement wgpuInstanceProcessEvents gfx-rs/wgpu-native#430The text was updated successfully, but these errors were encountered: