GPURenderPassEncoder: end() 方法

可用性有限

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

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

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

GPURenderPassEncoder 介面的 end() 方法用於完成當前渲染通道命令序列的錄製。

語法

js
end()

引數

無。

返回值

無 (Undefined)。

驗證

呼叫 end() 時必須滿足以下條件,否則將生成 GPUValidationError 錯誤,並且 GPURenderPassEncoder 將變得無效:

  • GPURenderPassEncoder 處於開啟狀態(即,尚未透過 end() 呼叫結束)。
  • 當前渲染通道上沒有活動的遮擋查詢(即,沒有透過 beginOcclusionQuery() 啟動)。
  • 當前渲染通道的除錯堆疊為空(即,當前沒有透過 pushDebugGroup() 開啟的渲染通道除錯組)。
  • 在此渲染通道中編碼的繪製命令數量小於或等於 GPUCommandEncoder.beginRenderPass() 描述符中設定的 maxDrawCount 屬性。

示例

在我們 基礎渲染演示中,透過 GPUCommandEncoder 錄製了多個命令。其中大多數命令源自透過 GPUCommandEncoder.beginRenderPass() 建立的 GPURenderPassEncoder。在適當的位置呼叫 end() 來結束渲染通道。

js
// …

const renderPipeline = device.createRenderPipeline(pipelineDescriptor);

// Create GPUCommandEncoder to issue commands to the GPU
// Note: render pass descriptor, command encoder, etc. are destroyed after use, fresh one needed for each frame.
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 the triangle
passEncoder.setPipeline(renderPipeline);
passEncoder.setVertexBuffer(0, vertexBuffer);
passEncoder.draw(3);

// End the render pass
passEncoder.end();

// End frame by passing array of command buffers to command queue for execution
device.queue.submit([commandEncoder.finish()]);

// …

規範

規範
WebGPU
# dom-gpurenderpassencoder-end

瀏覽器相容性

另見