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

浏览器兼容性

另见