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 |
瀏覽器相容性
載入中…