GPUComputePassEncoder: end() 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 end() của giao diện GPUComputePassEncoder hoàn tất việc ghi chuỗi lệnh compute pass hiện tại.

Cú pháp

js
end()

Tham số

Không có.

Giá trị trả về

Không có (Undefined).

Kiểm tra hợp lệ

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à GPUComputePassEncoder sẽ trở nên không hợp lệ:

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 GPUCommandEncoder.beginComputePass().

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-end

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

Xem thêm