webgpu-native / webgpu-headers

https://webgpu-native.github.io/webgpu-headers/
BSD 3-Clause "New" or "Revised" License
379 stars 43 forks source link

WGPUFuture #199

Open kainino0x opened 1 year ago

kainino0x commented 1 year ago

I've been working on this for a while, but haven't filed a tracking issue until now.

The main problem is that ProcessEvents is a polling-based API, so there's no way to get notified/woken when an event happens (like posix poll, or vkWaitForFences). A bunch of other issues also crop up around:

Expect more from me on this soon.

This issue also subsumes:


TODO:

kainino0x commented 1 year ago

After a bunch of discussion in the webgpu.h meeting we've decided we'll tentatively go forward with my proposal, except for the OS-interop bits that are very tricky and may or may not turn out to be necessary. (Chromium will most likely end up with interesting answers about what we decide to do.)

Slide-deck version of the WGPUFuture proposal: https://docs.google.com/presentation/d/1_0lZlaja_9IJxBMZaQGKvAV8bPZoOosNouiF1WiuEBw/edit?usp=sharing Full 14-page document with lots of implementation details, links about how things work in backend APIs and OSes, alternatives considered, etc.: https://docs.google.com/document/d/1qJRTJRY318ZEqhK6ryw4P-91FumYQfOnNP6LpANYy6A/edit?usp=sharing

EDIT: Forgot to paste the meeting notes from aug 10:

kainino0x commented 1 year ago

Making some tweaks to make it so we can choose not to polyfill and incrementally improve later:

kainino0x commented 1 year ago
kainino0x commented 1 year ago
kainino0x commented 1 year ago
  • Move these features/limits out to a substruct of instance descriptor, add a top-level function that can populate that struct with the supported features.

Just a note: This struct has to be extensible, but WGPUInstanceDescriptor is also extensible, so we end up with:

typedef struct WGPUInstanceFeatures {
    WGPUChainedStruct const * nextInChain;
} WGPUInstanceFeatures WGPU_STRUCTURE_ATTRIBUTE;

typedef struct WGPUInstanceDescriptor {
    WGPUChainedStruct const * nextInChain;
    WGPUInstanceFeatures features;
} WGPUInstanceDescriptor WGPU_STRUCTURE_ATTRIBUTE;

WGPU_EXPORT WGPUSomeStatusEnum wgpuGetInstanceFeatures(WGPUInstanceFeatures* features) WGPU_FUNCTION_ATTRIBUTE;

This is kind of redundant but I guess it's fine? We could extend only one or the other, and/or make wgpuGetInstanceFeatures take a WGPUInstanceDescriptor, but those solutions seem worse.

kainino0x commented 1 year ago

meeting:

kainino0x commented 1 year ago

We forgot to revisit the question of how to report errors but I think one of the points of always returning a future (as I did in an earlier version of the proposal already) was that now we can return the null future when there's an error, so I propose that being our error mechanism. (With implementation-defined logging for the details.)

kainino0x commented 1 year ago

Oh, Loko pointed out that if it's an enum (rather than flags that have invalid combinations) then we can probably just crash if you pass (WGPUCallbackMode)1337

kainino0x commented 10 months ago

Dec 21 meeting

kainino0x commented 9 months ago

Jan 11 meeting:

kainino0x commented 7 months ago

Mar 7 meeting:

kainino0x commented 6 months ago

Issues @lokokung raised during implementation of DeviceLost:

kainino0x commented 6 months ago

Mar 28 meeting:

kainino0x commented 1 month ago

Docs were added in #314!

almarklein commented 3 weeks ago

Docs were added in https://github.com/webgpu-native/webgpu-headers/pull/314!

It looks like that pr also adds new functions to the spec. What part of WGPUFuture is still missing now? I'm curious to what extent I can already start implementing async support in wgpu-py 😊

kainino0x commented 2 weeks ago

I don't remember for sure, probably WGPUFuture is more or less landed, though there are some changes we need to make to the async functions' signatures for various reasons. I'll review at some point soon....

That said, this header doesn't yet match wgpu-native or Dawn, so please use the header that corresponds with your implementation. (Dawn has implemented WGPUFuture hasn't done all the signature changes yet either.)

almarklein commented 2 weeks ago

Thanks for your reply!

this header doesn't yet match wgpu-native or Dawn

It's on the way 🚀 https://github.com/gfx-rs/wgpu-native/pull/427

Reading through some of the docs referenced here, I saw that if one uses the futures for all events (once its implemented) its not longer necessary to call wgpuInstanceProcessEvents(). But I also read somewhere that process events "check in-flight GPU work and free resources no longer used by GPU". Is the latter no longer the case?

PJB3005 commented 2 weeks ago

It's on the way 🚀 gfx-rs/wgpu-native#427

Just FYI, my PR doesn't really implement WGPUFuture as I don't think wgpu currently has the necessary infrastructure. wgpuInstanceWaitAny is just unimplemented!() right now.

kainino0x commented 2 weeks ago

But I also ready somewhere that process events "check in-flight GPU work and free resources no longer used by GPU". Is the latter no longer the case?

IIRC we want to guarantee that stuff like this happens periodically as long as you're submitting work (e.g. in queue.submit()).

Though I did have an unused proposal for a function that would do this, if we find it's needed: https://docs.google.com/document/d/1qJRTJRY318ZEqhK6ryw4P-91FumYQfOnNP6LpANYy6A/edit#heading=h.l3149w38ebmt