GPUQueue: submit() 方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

注意:此功能在 Web Workers 中可用。

GPUQueue 介面的 submit() 方法會排程一個或多個 GPUCommandBuffer 物件所表示的命令緩衝區的執行,由 GPU 來處理。

語法

js
submit(commandBuffers)

引數

commandBuffers

一個 GPUCommandBuffer 物件陣列,其中包含待入隊以供 GPU 處理的命令。該陣列不得包含重複的 GPUCommandBuffer 物件 — 每個命令緩衝區在每次 submit() 呼叫中只能提交一次。

返回值

無 (Undefined)。

驗證

呼叫 submit() 時必須滿足以下條件,否則將生成 GPUValidationError,並且 GPUQueue 將失效。

示例

在我們的 基本渲染演示 中,透過 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

瀏覽器相容性

另見