GPUComputePassEncoder
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.
Giao diện GPUComputePassEncoder của WebGPU API mã hóa các lệnh liên quan đến điều khiển giai đoạn compute shader, được phát ra bởi GPUComputePipeline. Đây là một phần trong hoạt động mã hóa tổng thể của GPUCommandEncoder.
Một compute pipeline chứa một giai đoạn compute duy nhất, trong đó compute shader nhận dữ liệu tổng quát, xử lý song song trên một số lượng workgroup được chỉ định, rồi trả kết quả vào một hoặc nhiều buffer.
Một phiên bản đối tượng GPUComputePassEncoder được tạo thông qua thuộc tính GPUCommandEncoder.beginComputePass().
Thuộc tính phiên bản
Phương thức phiên bản
dispatchWorkgroups()-
Gửi đi một lưới workgroup cụ thể để thực hiện công việc do
GPUComputePipelinehiện tại đảm nhiệm. dispatchWorkgroupsIndirect()-
Gửi đi một lưới workgroup, được định nghĩa bởi các tham số của
GPUBuffer, để thực hiện công việc doGPUComputePipelinehiện tại đảm nhiệm. end()-
Hoàn tất việc ghi chuỗi lệnh compute pass hiện tại.
insertDebugMarker()-
Đánh dấu một điểm cụ thể trong chuỗi lệnh mã hóa bằng một nhãn.
popDebugGroup()-
Kết thúc một debug group, được bắt đầu bởi lời gọi
pushDebugGroup(). pushDebugGroup()-
Bắt đầu một debug group, được đánh dấu bằng nhãn chỉ định, và sẽ chứa tất cả các lệnh mã hóa tiếp theo cho đến khi phương thức
popDebugGroup()được gọi. setBindGroup()-
Đặt
GPUBindGroupđể sử dụng cho các lệnh compute tiếp theo, cho một chỉ mục nhất định. setPipeline()-
Đặt
GPUComputePipelineđể sử dụng cho compute pass này.
Ví dụ
Trong bản demo compute cơ bản của chúng tôi, 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().
// …
// Create GPUCommandEncoder to encode commands to issue to the GPU
const commandEncoder = device.createCommandEncoder();
// Create GPUComputePassEncoder to 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 compute 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> # gpucomputepassencoder> |