-
Notifications
You must be signed in to change notification settings - Fork 53
Description
As I am upgrading my WebGPU programming guide (WIP version), I am looking for the best way to progressively introduce methods for polling async operations.
The very first case of async operation is the adapter request, for which wgpuInstanceProcessEvents is the most straightforward/less verbose solution:
wgpuInstanceProcessEvents(instance);
while (!userData.requestEnded) {
// Waiting for 100 ms to avoid asking too often to process events
sleepForMilliseconds(100);
wgpuInstanceProcessEvents(instance);
}(I know in practice the very first wgpuInstanceProcessEvents invokes the callback and turns userData.requestEnded, but I'm playing by the standard.)
Now I'm looking for a "natural" way to introduce wgpuInstanceWaitAny in a case where it brings something that the wgpuInstanceProcessEvents pattern cannot do well. I can think of several reasons:
-
Using
wgpuInstanceWaitAnymakes it possible to query the completness of theWGPUFutureinstead of maintaining my ownuserData.requestEnded. But this requires to hold theWGPUFuture, and to create theWGPUFutureInfo, so it ends up being more verbose. -
Using
wgpuInstanceWaitAnyallows for more reactivity because the 100ms would become a timeout instead of being a non-breakable time increment. Of course it is important, but timed wait are not always available, so it is also verbose for something happening in an introductory chapter. -
Using
wgpuInstanceWaitAnymay only invoke the callback associated with the queried futures. First, is that true? (ignoring the AllowSpontaneous ones ofc). And I don't have a simple scenario where this is needed. -
Do you have other ideas? I am missing something obvious or is
wgpuInstanceWaitAnymeant for advanced use cases or to write the inner bits of abstraction layers?