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

GPUQueue

· 52CE 我爱测

The **`GPUQueue`** interface of the WebGPU API controls execution of encoded commands on the GPU.

WebGPU API

The GPUQueue interface of the WebGPU API controls execution of encoded commands on the GPU.

A device's primary queue is accessed via the GPUDevice.queue property.

Instance properties

  • GPUQueue.label
    • : A string providing a label that can be used to identify the object, for example in GPUError messages or console warnings.

Instance methods

  • GPUQueue.copyExternalImageToTexture
    • : Copies a snapshot taken from a source image, video, or canvas into a given GPUTexture.
  • GPUQueue.onSubmittedWorkDone
    • : 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.
  • GPUQueue.submit
    • : Schedules the execution of command buffers represented by one or more GPUCommandBuffer objects by the GPU.
  • GPUQueue.writeBuffer
    • : Writes a provided data source into a given GPUBuffer.
  • GPUQueue.writeTexture
    • : Writes a provided data source into a given GPUTexture.

Examples

In our basic render demo, we define some vertex data in a Float32Array that we'll use to draw a triangle:

const vertices = new Float32Array([
  0.0, 0.6, 0, 1, 1, 0, 0, 1, -0.5, -0.6, 0, 1, 0, 1, 0, 1, 0.5, -0.6, 0, 1, 0,
  0, 1, 1,
]);

To use this data in a render pipeline, we need to put it into a GPUBuffer. First we'll create the buffer:

const vertexBuffer = device.createBuffer({
  size: vertices.byteLength, // make it big enough to store vertices in
  usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
});

To get the data into the buffer we can use the GPUQueue.writeBuffer function, which lets the user agent determine most efficient way to copy the data over:

device.queue.writeBuffer(vertexBuffer, 0, vertices, 0, vertices.length);

Later on, a set of commands is encoded into a GPUCommandBuffer using the GPUCommandEncoder.finish() method. The command buffer is then passed into the queue via a GPUQueue.submit call, ready to be processed by the GPU.

device.queue.submit([commandEncoder.finish()]);

[!NOTE] Study the WebGPU samples to find more queue examples.

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

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

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