GPUComputePassEncoder: end() 方法

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

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

GPUComputePassEncoder 接口的 end() 方法用于完成当前计算通道命令序列的记录。

语法

js
end()

参数

无。

返回值

无 (Undefined)。

验证

调用 end() 时必须满足以下标准,否则将生成 GPUValidationError,并且 GPUComputePassEncoder 将变为无效:

  • GPUComputePassEncoder 处于打开状态(即尚未通过调用 end() 结束)。
  • 在该编码器上进行的任何 pushDebugGroup() 调用,在调用 end() 之前都有一个对应的 popDebugGroup() 调用。

示例

在我们 基本的计算演示 中,通过 GPUCommandEncoder 记录了多个命令。其中大部分命令源自通过 GPUCommandEncoder.beginComputePass() 创建的 GPUComputePassEncoder

js
const BUFFER_SIZE = 1000;

// …

// Create GPUCommandEncoder to encode commands to issue to the GPU
const commandEncoder = device.createCommandEncoder();

// Initiate render pass
const passEncoder = commandEncoder.beginComputePass();

// Issue commands
passEncoder.setPipeline(computePipeline);
passEncoder.setBindGroup(0, bindGroup);
passEncoder.dispatchWorkgroups(Math.ceil(BUFFER_SIZE / 64));

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

// Copy output buffer to staging buffer
commandEncoder.copyBufferToBuffer(
  output,
  0, // Source offset
  stagingBuffer,
  0, // Destination offset
  BUFFER_SIZE,
);

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

// …

规范

规范
WebGPU
# dom-gpucomputepassencoder-end

浏览器兼容性

另见