GPURenderPassEncoder: phương thức setPipeline()
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 GPURenderPassEncoder đặt GPURenderPipeline để sử dụng cho các lệnh lần thực thi kết xuất tiếp theo.
Cú pháp
setPipeline(pipeline)
Tham số
pipeline-
GPURenderPipelineđể sử dụng cho các lệnh lần thực thi kết xuất tiếp theo.
Giá trị trả về
Không có (Undefined).
Xác thực
Các tiêu chí sau phải được đáp ứng khi gọi setPipeline(), nếu không GPUValidationError sẽ được tạo ra và GPURenderPassEncoder sẽ không hợp lệ:
- Nếu
GPURenderPipelineghi vào thành phần độ sâu của tệp đính kèm độ sâu/stencil,depthReadOnly(như được chỉ định trong descriptor của lệnh gọiGPUCommandEncoder.beginRenderPass()nguồn gốc) làtrue. - Nếu
GPURenderPipelineghi vào thành phần stencil của tệp đính kèm độ sâu/stencil,stencilReadOnly(như được chỉ định trong descriptor của lệnh gọiGPUCommandEncoder.beginRenderPass()nguồn gốc) làtrue.
Ví dụ
Trong demo kết xuất cơ bản của chúng tôi, một số lệnh được ghi lại thông qua GPUCommandEncoder. Hầu hết các lệnh này xuất phát từ GPURenderPassEncoder được tạo thông qua GPUCommandEncoder.beginRenderPass(). setPipeline() được gọi tại vị trí thích hợp để đặt đường ống kết xuất.
// …
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()]);
// …
Thông số kỹ thuật
| Specification |
|---|
| WebGPU> # dom-gpurendercommandsmixin-setpipeline> |