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

瀏覽器相容性

另見