GPUComputePassEncoder: setPipeline() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Phương thức setPipeline() của giao diện GPUComputePassEncoder đặt GPUComputePipeline để sử dụng cho compute pass này.

Cú pháp

js
setPipeline(pipeline)

Tham số

pipeline

GPUComputePipeline để sử dụng cho compute pass này.

Giá trị trả về

Không có (Undefined).

Ví dụ

Trong bản demo compute cơ bản, một số lệnh được ghi thông qua GPUCommandEncoder. Phần lớn các lệnh này xuất phát từ GPUComputePassEncoder được tạo qua beginComputePass(). Lời gọi setPipeline() được sử dụng phù hợp để đặt pipeline sử dụng cho pass này.

js
const BUFFER_SIZE = 1000;

// …

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

// Initiate compute 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()]);

// …

Thông số kỹ thuật

Specification
WebGPU
# dom-gpucomputepassencoder-setpipeline

Tương thích trình duyệt

Xem thêm