CommandBuffer
Quick answer
CommandBuffer is the immutable product of CommandEncoder.finish, holding recorded render passes, compute passes and copy commands. Submit it once through the device queue, after which it is consumed. Keep references mainly for debugging, timing and inspecting the recorded command stream.
encoder. finish () → CommandBuffer
Key points
- Created only by encoder.finish(); there is no public constructor.
- Submitted with device.queue.submit([commandBuffer]) on WebGPU.
- Exposes the recorded passes and copies for inspection and profiling.
Example
const encoder = device.createCommandEncoder({ id: 'gbuffer' });
const pass = encoder.beginRenderPass({
framebuffer: fbo,
clearColor: [0, 0, 0, 1]
});
pass.setPipeline(pipeline);
pass.setVertexArray(vertexArray);
pass.draw({ vertexCount: 36 });
pass.end();
const commandBuffer = encoder.finish();
device.submit(commandBuffer);const encoder = device.createCommandEncoder({
id: 'frame-' + frameIndex,
userData: { pass: 'terrain', frame: frameIndex }
});
/* ……录制…… */
const cb = encoder.finish();
device.submit(cb);
cb.destroy();
Notes
- Reusing a submitted buffer throws, so record a fresh encoder every frame.
- Holding a finished buffer across frames keeps stale resource references alive.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). CommandBuffer. https://www.jingweizhi.com/en/lumagl/api/command-buffer.html (accessed 2026-11-03).