ComputePass
Quick answer
ComputePass records compute dispatches against one ComputePipeline. Create it with device.beginComputePass, call setPipeline then setBindings, dispatch workgroup counts with dispatchWorkgroups(x, y, z), and finish with end(). It requires the WebGPU backend and cannot run on WebGL, and dispatch sizes derive from the workgroup size declared in the shader.
device. beginComputePass ( props ?) → ComputePass
Key points
- dispatchWorkgroups takes workgroup counts, not invocation counts.
- setBindings must be called after setPipeline inside the pass.
- end() returns control to the CommandEncoder that opened the pass.
Example
const COUNT = 65536;
const WORKGROUP_SIZE = 64;
const pass = device.beginComputePass();
pass.setPipeline(pipeline);
pass.dispatch(Math.ceil(COUNT / WORKGROUP_SIZE));
pass.end();
device.submit();/* 缓冲区里依次是 x、y、z 三个 u32 工作组数量 */
const args = device.createBuffer({
data: new Uint32Array([1024, 1, 1])
});
const pass = device.beginComputePass();
pass.setPipeline(pipeline);
pass.dispatchIndirect(args, 0);
pass.end();
device.submit();
Notes
- Dispatching element counts without dividing by workgroup size under-covers data.
- WebGL devices expose no compute pass, so feature-detect before calling.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). ComputePass. https://www.jingweizhi.com/en/lumagl/api/compute-pass.html (accessed 2026-11-03).