GPUComputePassEncoder: setPipeline() 方法

可用性有限

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

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

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

setPipeline() 方法是 GPUComputePassEncoder 接口的一部分,用于为此计算通道设置要使用的 GPUComputePipeline

语法

js
setPipeline(pipeline)

参数

pipeline

为此计算通道要使用的 GPUComputePipeline

返回值

无 (Undefined)。

示例

在我们的 基础计算演示 中,通过 GPUCommandEncoder 记录了多个命令。其中大多数命令都源自通过 beginComputePass() 创建的 GPUComputePassEncodersetPipeline() 调用会根据需要用于设置此通道要使用的管线。

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-setpipeline

浏览器兼容性

另见