CommandEncoder
A CommandEncoder records GPU commands that can later be sealed into a CommandBuffer and submitted to a Device.
For conceptual guidance, start with GPU Commands.
Types
CommandEncoderProps
CommandEncoderProps extends ResourceProps.
| Property | Type | Default | Description |
|---|---|---|---|
id? | string | autogenerated | Optional human-readable label used for debugging. |
handle? | unknown | undefined | Supply an existing backend handle instead of letting luma.gl create one. |
userData? | Record<string, unknown> | undefined | Application data stored on the encoder wrapper. |
timeProfilingQuerySet? | QuerySet | null | null | Query set used for automatic pass-level GPU timestamp profiling. |
measureExecutionTime? | boolean | backend default | Reserved backend-specific hint for timing instrumentation. |
Usage
Record explicit copy work:
const commandEncoder = device.createCommandEncoder();
commandEncoder.copyBufferToBuffer({
sourceBuffer,
destinationBuffer,
size: sourceBuffer.byteLength
});
const commandBuffer = commandEncoder.finish();
device.submit(commandBuffer);
Record a render pass:
const commandEncoder = device.createCommandEncoder();
const renderPass = commandEncoder.beginRenderPass({
framebuffer,
clearColor: [0, 0, 0, 1]
});
model.draw(renderPass);
renderPass.end();
device.submit(commandEncoder.finish());
Use the device's default encoder:
const renderPass = device.beginRenderPass({clearColor: [0, 0, 0, 1]});
model.draw(renderPass);
renderPass.end();
device.submit();
Members
device:Device- holds a reference to theDevicethat created thisCommandEncoder.handle:unknown- holds the underlying WebGL or WebGPU command encoder handleprops:CommandEncoderProps- holds a copy of theCommandEncoderPropsused to create thisCommandEncoder.
Methods
constructor(props: CommandEncoderProps)
CommandEncoder is an abstract class and cannot be instantiated directly. Create with device.createCommandEncoder(...).
finish(props?: CommandBufferProps): CommandBuffer
Completes recording and returns a finished CommandBuffer.
beginRenderPass(props?: RenderPassProps): RenderPass
Begins a render pass recorded on this encoder.
beginComputePass(props?: ComputePassProps): ComputePass
Begins a compute pass recorded on this encoder.
copyBufferToBuffer(options)
Copies data from one GPU buffer to another.
copyBufferToTexture(options)
Copies data from a GPU buffer into a texture subresource.
copyTextureToBuffer(options)
Copies data from a texture subresource into a GPU buffer.
copyTextureToTexture(options)
Copies one texture region into another texture region.
resolveQuerySet(querySet, destination, options?)
Resolves query results into a GPU buffer.
writeTimestamp(querySet, queryIndex)
Writes a timestamp into a QuerySet.
Remarks
- On WebGPU, commands are truly recorded onto the encoder and only execute after
submit(). - On WebGL, luma.gl provides a best-effort compatibility layer. Copy operations are portable, but render passes remain effectively immediate-mode.
- If you do not need explicit command-stream control, the resource-level helpers such as
Buffer.write(),Texture.writeData(), andTexture.copyExternalImage()are often the simpler choice.