这是indexloc提供的服务,不要输入任何密码
Skip to content

Ordering of promise resolution. #962

@Kangz

Description

@Kangz

There's multiple places where WebGPU returns promises to the applications, some of which conceptually happen on the same timeline:

  • No specific timeline:
    • GPU.requestAdapter
    • GPUAdapter.requestDevice
    • GPUDevice.createReadyComputePipeline
    • GPUDevice.createReadyRenderPipeline
    • GPUCanvasContext.getSwapChainPreferredFormat
  • Device timeline:
    • GPUDevice.lost
    • GPUDevice.popErrorScope
    • GPUShaderModule.compilationInfo
  • Queue timeline:
    • GPUCommandBuffer.executionTime
    • GPUFence.onCompletion
    • GPUBuffer.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.

Metadata

Metadata

Assignees

Labels

copyeditingPure editorial stuff (copyediting, *.bs file syntax, etc.)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions