Playing with buffers π΄ΒΆ
WIP In this version of the guide, this chapter moves back in the βgetting startedβ section, between command queue and the first (compute) shader.
In this chapter:
We see how to create and manipulate buffers.
We refine our control of asynchronous operations.
BuffersΒΆ
Asynchronous operationsΒΆ
The good wayΒΆ
To keep track of ongoing asynchronous operations, each function that starts such an operation returns a WGPUFuture
, which is some sort of internal ID that identifies the operation:
WGPUFuture adapterRequest = wgpuInstanceRequestAdapter(instance, &options, callbackInfo);
Note
Although it is technically just an integer value, the WGPUFuture
should be treated as an opaque handle, i.e., one should not try to deduce anything from the very value of this ID.
This future can then be passed to wgpuInstanceWaitAny
to mean βwait until this asynchronous operation completesβ! Here is the signature of wgpuInstanceWaitAny
:
WGPUWaitStatus wgpuInstanceWaitAny(WGPUInstance instance, size_t futureCount, WGPUFutureWaitInfo * futures, uint64_t timeoutNS);
uint64_t timeoutNS = 200 * 1000; // 200 ms
WGPUWaitStatus status = wgpuInstanceWaitAny(instance, 1, &adapterRequest, timeoutNS);