GPURenderPassEncoder: phương thức end()

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 end() của giao diện GPURenderPassEncoder hoàn thành việc ghi lại chuỗi lệnh của lần thực thi kết xuất hiện tại.

Cú pháp

js
end()

Tham số

Không có.

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 end(), nếu không GPUValidationError sẽ được tạo ra và GPURenderPassEncoder sẽ không hợp lệ:

  • GPURenderPassEncoder đang mở (tức là chưa kết thúc bằng lệnh gọi end()).
  • Không có truy vấn occlusion nào (tức là đã được bắt đầu qua beginOcclusionQuery()) đang hoạt động trên lần thực thi kết xuất hiện tại.
  • Ngăn xếp gỡ lỗi cho lần thực thi kết xuất hiện tại trống (tức là không có nhóm gỡ lỗi lần thực thi kết xuất nào đang mở, như được mở bởi pushDebugGroup()).
  • Số lệnh vẽ được mã hóa trong lần thực thi kết xuất này nhỏ hơn hoặc bằng thuộc tính maxDrawCount được đặt trong descriptor GPUCommandEncoder.beginRenderPass().

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(). end() được gọi tại vị trí thích hợp để kết thúc lần thực thi kết xuất.

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

// …

Thông số kỹ thuật

Specification
WebGPU
# dom-gpurenderpassencoder-end

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

Xem thêm