Skip to content

Conversation

almarklein
Copy link
Member

Adds GPUPromise or GPUFuture, not sure yet whether to go for a more Pythonic or JS-like API.

The idea is that the async methods of the wgpu API will no longer have async in front, but instead return the promise object. This object can be awaited, sync waited, and also handled with a callback.

The callback-approach is new, and makes it possible to handle things asynchronously when not in async code. This opens up doors for improved performance, and a more sync workflow that's still portable. It will e.g. make the rendercanvas "bitmap" present-mode more performant, and allow us to resolve some issues related to timing events and draws.

Example of intended use:

>>> p = wgpu.gpu.request_adapter_async()
>>> p
<GPUPromise pending  at 0x107ead400>

>>> await p:
<wgpu.backends.wgpu_native.GPUAdapter object at 0x107eaeba0>

>>> p.wait()
<wgpu.backends.wgpu_native.GPUAdapter object at 0x107eaeba0>

>>> p.then(lambda adapter: print("got", adapter))
got <wgpu.backends.wgpu_native.GPUAdapter object at 0x107eaeba0>

"""
# TODO: allow calling multiple times
# TODO: allow calling after being resolved -> tests!
# TODO: return another promise, so we can do chaining? Or maybe not interesting for this use-case...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be pretty crucial to me!

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 this pull request may close these issues.

2 participants