-
Notifications
You must be signed in to change notification settings - Fork 344
Description
There's multiple places where WebGPU returns promises to the applications, some of which conceptually happen on the same timeline:
- No specific timeline:
GPU.requestAdapterGPUAdapter.requestDeviceGPUDevice.createReadyComputePipelineGPUDevice.createReadyRenderPipelineGPUCanvasContext.getSwapChainPreferredFormat
- Device timeline:
GPUDevice.lostGPUDevice.popErrorScopeGPUShaderModule.compilationInfo
- Queue timeline:
GPUCommandBuffer.executionTimeGPUFence.onCompletionGPUBuffer.mapAsync
No timeline: it seems that the promises associated with no specific timeline shouldn't have ordering guarantees and can resolve in any order.
Device timeline: for device timeline promises, it seems they should resolve in the order they were requested? For example two calls to popErrorScope should be resolved in the same order. compilationInfo is a bit more tricky:
let p1 = device.popErrorScope();
let shaderModule = device.createShaderModule(...);
let p2 = device.popErrorScope();
let compilationInfo = shaderModule.compilationInfo();
let p3 = device.popErrorScope();What should be the resolution order: p1 p2 compilationInfo p3 because the compilation info was requested between p2 and p3, or p1 compilationInfo p2 p3 because the shader module was compiled between p1 and p2?
Queue timeline: that's where the resolution order seems like it would matter most, because it easy to imagine developers using a fence completion signal to know if a buffer finished mapping and it is safe to call getMappedRange on a buffer (and likewise for GPUCommandBuffer.executionTime):
buffer.mapAsync(GPUMapMode.READ);
queue.signal(fence, 3);
// after this I know the buffer is mapped!
await fence.onCompletion(3);
range = buffer.getMappedRange();The issue here is that it is the fence signal event that happens before the buffer mapping is completed. So what is supposed to happen with the following?
queue.signal(fence, 2);
let p = buffer.mapAsync(GPUMapMode.READ)
let q = fence.onCompletion(2);
// Which resolves first?Anyways, there's so many small interactions to consider so we should come up with a spec abstraction to describe the order in which promises resolve.