GPUQueue: submit() 方法
注意:此功能在 Web Workers 中可用。
GPUQueue 接口的 submit() 方法会调度一个或多个 GPUCommandBuffer 对象所表示的命令缓冲区的执行,由 GPU 来处理。
语法
js
submit(commandBuffers)
参数
commandBuffers-
一个
GPUCommandBuffer对象数组,其中包含待入队以供 GPU 处理的命令。该数组不得包含重复的GPUCommandBuffer对象 — 每个命令缓冲区在每次submit()调用中只能提交一次。
返回值
无 (Undefined)。
验证
调用 submit() 时必须满足以下条件,否则将生成 GPUValidationError,并且 GPUQueue 将失效。
submit()调用中引用的GPUCommandBuffer对象数组不包含重复项。- 在已编码命令中使用的所有
GPUBuffer、GPUTexture和GPUQuerySet对象都可用,即未处于不可用状态(如果GPUBuffer当前被 映射)或已销毁(通过destroy()方法)。 - 在已编码命令中使用的所有
GPUExternalTexture对象都未过期(它们在通过importExternalTexture()导入后不久会自动过期)。 - 如果在已编码命令中使用的
GPUQuerySet对象类型为"occlusion"查询,则该对象尚未被使用,除了通过GPURenderPassEncoder.beginOcclusionQuery()使用。
示例
在我们的 基本渲染演示 中,通过 GPUCommandEncoder 记录了许多命令。
js
// …
// Create GPUCommandEncoder
const commandEncoder = device.createCommandEncoder();
// Create GPURenderPassDescriptor to tell WebGPU which texture to draw into, then initiate render pass
const renderPassDescriptor = {
colorAttachments: [
{
clearValue: clearColor,
loadOp: "clear",
storeOp: "store",
view: context.getCurrentTexture().createView(),
},
],
};
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
// Draw a triangle
passEncoder.setPipeline(renderPipeline);
passEncoder.setVertexBuffer(0, vertexBuffer);
passEncoder.draw(3);
// End the render pass
passEncoder.end();
// …
通过 GPUCommandEncoder 编码的命令使用 GPUCommandEncoder.finish() 方法重新编码为一个 GPUCommandBuffer。然后通过 submit() 调用将命令缓冲区传递给队列,准备由 GPU 处理。
js
device.queue.submit([commandEncoder.finish()]);
注意: 请参阅 WebGPU 示例 以查找更多队列示例。
规范
| 规范 |
|---|
| WebGPU # dom-gpuqueue-submit |
浏览器兼容性
加载中…