GPURenderPassEncoder: setPipeline() 方法

可用性有限

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

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

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

GPURenderPassEncoder 接口的 setPipeline() 方法用于设置后续渲染通道命令使用的 GPURenderPipeline

语法

js
setPipeline(pipeline)

参数

pipeline

用于后续渲染通道命令的 GPURenderPipeline

返回值

无 (Undefined)。

验证

调用 setPipeline() 时必须满足以下条件,否则将生成 GPUValidationError 并且 GPURenderPassEncoder 将失效。

示例

在我们 基本的渲染演示 中,通过 GPUCommandEncoder 记录了多个命令。其中大多数命令源自通过 GPUCommandEncoder.beginRenderPass() 创建的 GPURenderPassEncodersetPipeline() 在适当的位置被调用以设置渲染管线。

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

浏览器兼容性

另见