ComputePipeline
Quick answer
ComputePipeline is a compiled compute shader bound to an entry point, created by device.createComputePipeline({shader, entryPoint}). It has no vertex inputs or color attachments, and all data arrives through bindings. Build it once, cache it, and record a ComputePass for each dispatch.
device. createComputePipeline ({ shader, entryPoint }) → ComputePipeline
Key points
- Requires a Shader compiled with stage 'compute' plus a matching entryPoint.
- Creation is expensive, so keep pipelines outside the frame loop.
- Works only on WebGPU; the WebGL backend cannot create compute pipelines.
Example
const wgsl = `
@group(0) @binding(0) var<storage, read_write> values: array<f32>;
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
let i = id.x;
if (i < arrayLength(&values)) {
values[i] = values[i] * 2.0;
}
}
`;
const cs = device.createShader({
stage: 'compute',
language: 'wgsl',
source: wgsl
});
const pipeline = device.createComputePipeline({
shader: cs,
entryPoint: 'main'
});if (device.type !== 'webgpu') {
console.warn('当前后端不支持计算管线');
}
Notes
- A mismatched entryPoint name compiles but produces zero invocations.
- Bindings used by the shader must exist before dispatch or the pass errors.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). ComputePipeline. https://www.jingweizhi.com/en/lumagl/api/compute-pipeline.html (accessed 2026-11-03).