大网数据广告活动
Web 标准与前端开发

GPUQueue: onSubmittedWorkDone() method

· 52CE 我爱测

The **`onSubmittedWorkDone()`** method of the GPUQueue interface returns a Promise that resolves when all the work submitted to the GPU via this `GPUQueue` at the point the method is called has been processed.

WebGPU API

The onSubmittedWorkDone() method of the GPUQueue interface returns a Promise that resolves when all the work submitted to the GPU via this GPUQueue at the point the method is called has been processed.

This includes the completion of any GPUBuffer.mapAsync calls made on GPUBuffers used in commands submitted to the queue, before onSubmittedWorkDone() is called.

Note: In most cases, you do not need to call onSubmittedWorkDone(). You do not need to call it for mapping a buffer. mapAsync guarantees work submitted to the queue before calling mapAsync happens before the mapAsync returns (see WebGPU spec).

The two use cases for onSubmittedWorkDone

  1. Waiting for multiple buffer mapping (slow)

    // good
    await Promise.all([
      buffer1.mapAsync(),
      buffer2.mapAsync(),
      buffer3.mapAsync(),
    ]);
    data1 = buffer1.getMappedRange();
    data2 = buffer2.getMappedRange();
    data3 = buffer3.getMappedRange();
    
    // works but slow
    buffer1.mapAsync();
    buffer2.mapAsync();
    buffer3.mapAsync();
    await device.queue.onSubmittedWorkDone();
    data1 = buffer1.getMappedRange();
    data2 = buffer2.getMappedRange();
    data3 = buffer3.getMappedRange();
    

    The reason the second method is slow is, the implementation may be able to map the buffers before all the submitted work is done. For example, if all the buffers are finished being used, but more work (unrelated to the buffers) is already submitted, then you'll end up waiting longer using the second method than the first.

  2. Throttling work

    If you are doing heavy compute work and you submit too much work at once, the browser may kill your work. You can throttle the work by only submitting more work when the work you've already submitted is done.

Syntax

onSubmittedWorkDone()

Parameters

None.

Return value

A Promise that resolves with undefined.

Examples

device.queue.submit([commandEncoder.finish()]);
device.queue.onSubmittedWorkDone().then(() => {
  console.log("All submitted commands processed.");
});

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。