GPUCommandGraph
Use GPUCommandGraph and CompiledGPUCommandGraph from @luma.gl/graph/gpu-graph or
@luma.gl/graph for execution scheduling.
Use GPUGraph to author semantic operations and GPUGraphCompiler to lower them to
this command graph. Option and result types retain their GPUCommandGraph prefixes.
Graph analytics live separately in @luma.gl/graph/gpu-graph-algorithms, using GPUGraphAlgorithmsData.
Overviewโ
GPUCommandGraph<Parameters> declares fixed-capacity WebGPU buffer and texture resources plus
ordered compute, render, and copy nodes. compile() returns a CompiledGPUCommandGraph through the
legacy synchronous pipeline-creation path. await compileAsync() prepares independent pipelines in
parallel where the backend supports it. Both forms return a graph that owns transient resources and
node state but borrows every import. Render nodes can resolve multisampled attachments and consume
explicitly numbered, frame-scoped swapchain and external-image bindings.
See Choosing a GPU Data-Processing API for guidance on when to use a command graph, portable GPGPU evaluators, or lower-level compute helpers.
At a glance
| Question | Answer |
|---|---|
| Problem | Compose reusable compute, copy, and render work into one validated execution plan. |
| Reads / writes | Nodes declare every logical resource range they read or write. |
| Ownership | Imports remain caller-owned; compiled graphs own transients and node-created state. |
| Output contract | Immutable topology and capacities with per-encoding parameters and compatible imports. |
| Expected work | Node estimates report logical nodes, physical passes, commands, bytes, and invocations. |
| Chunks | Graph vectors preserve ordered chunks; each contributor documents its support. |
| Conditions / budgets | CPU predicates, GPU indirect conditions, and resumable execution plans are first-class. |
| Neighborhood | application resources and contributors โ GPUCommandGraph โ caller encoder and submission. |
When to use itโ
Use a command graph for repeated multi-pass GPU work whose capacities and resource shapes are known while frame parameters and imported resources change. Visibility plus compaction and indirect drawing, simulation plus rendering, and GPU analysis pipelines are representative workloads.
Use direct command encoding for a one-off pass or a sequence that is already simple and local. A command graph does not own submission, presentation, the frame loop, or unbounded allocation. See Execution and composition for the mental model, terminology, hazard scheduling, conditions, resumable work, budgets, and instrumentation.
For changing batch topology, GPUIncrementalExecution caches explicit per-batch results and submits changed batches followed by a merge. It provides revision tracking, replacement/removal semantics, and work counters around ordinary command graphs.
Quick usageโ
This example composes reduction, histogram, and grid-binning nodes in one reusable graph:
const graph = new GPUCommandGraph<{time: number}>(device, {id: 'simulation'});
const source = graph.importBuffer(
{id: 'source', byteLength: sourceBuffer.byteLength, usage: sourceBuffer.usage},
sourceBuffer
);
const scratch = graph.createTransientBuffer({
id: 'scratch',
byteLength: sourceBuffer.byteLength,
usage: Buffer.STORAGE
});
graph.addComputePass({
id: 'update',
resources: [
{buffer: source, usage: 'storage-read'},
{buffer: scratch, usage: 'storage-write'}
],
compile: ({device}) => makeExecutableNode(device)
});
const compiledGraph = await graph.compileAsync();
const encoding = compiledGraph.encode(device.commandEncoder, {parameters: {time}});
console.log(encoding.stats.cpuEncodeTimeMilliseconds);
Lifecycle and ownershipโ
A graph definition is mutable until compile() or compileAsync() is called. Compilation freezes the definition,
infers a stable node order, plans transient allocation reuse, creates physical transients, and calls
each node's compile callback once. The returned CompiledGPUCommandGraph can then be encoded
repeatedly with different parameters and compatible imported-resource replacements.
Prefer compileAsync() for WebGPU graphs with multiple shader pipelines. It begins every independent
compute and render pipeline compilation before awaiting completion, and its promise resolves only
when all node executables are ready to encode. This moves compilation latency behind an explicit
awaitable preparation boundary and gives the browser and driver an opportunity to compile pipelines
concurrently. It does not submit commands, execute a warm-up decode, or wait for queue work. Use the
synchronous compile() only when immediate construction is required or when measuring compatibility
with an older integration.
Node callbacks that construct Kernel, Computation, or Model instances need no special handling: the graph
collects their asynchronous pipeline work automatically. A custom node that prepares some other
asynchronous resource can provide compileAsync(context) alongside its required synchronous
compile(context) callback. compileAsync() prefers that callback for the node; compile() always
uses the synchronous callback.
Imported buffers, textures, external textures, GPUData, and GPUVectorLike chunks are borrowed.
importGPUVector() accepts structural vectors as well as GPUVector instances. The
compiled graph owns only node-created resources, physical transients, and cached texture
views/framebuffers. Calling destroy() releases those owned resources and never destroys an
import.
Extension librariesโ
Small algorithm libraries can implement the structural GPUGraphCommandProducer interface:
class GPUAlgorithm implements GPUGraphCommandProducer {
getCommandNodes<Parameters>(graph: GPUCommandGraph<Parameters>): readonly GPUCommandGraphNode<Parameters>[] {
const output = createTransientView(
graph,
'algorithm-output',
'uint32',
outputCapacity,
Buffer.STORAGE | Buffer.INDIRECT
);
// Return compute, render, or copy nodes that use output.
return [createGPUComputeCommandNode({id: 'algorithm', resources: [{buffer: output, usage: 'storage-write'}], compile: compileAlgorithm})];
}
}
graph.add(new GPUAlgorithm());
Pass a GPUCommandGraphEntry<Parameters> to GPUCommandGraph.add(). A node can be a
concrete command, a producer, a group exposing getNodes(), or an array of nodes.
The command graph passes itself to each producer's getCommandNodes(graph) and
recursively expands the result in depth-first order. Concrete compute, render,
and copy commands are scheduled in that order. Additions after compilation fail
before any producer is invoked.
To inspect a producer's results before scheduling, call getCommandNodes(graph)
directly. Pass the returned list to graph.add(nodes) to expand nested producers.
Use addGPUCommandNodes(graph, nodes) when the list contains only concrete commands.
A primitive only declares resources and constructs nodes. It does not compile the graph, encode commands, submit work, or read results back. This keeps ownership and scheduling with the application and allows independently authored primitives to compose without a runtime registry.
The exported createTransientView() helper creates packed, graph-owned typed storage for
fixed-width VertexFormat values. Variable-length vertex-list<...> and value-list<...> formats
require an explicit adapter that owns their offsets and value counts; the helper rejects them before
declaring a graph resource. Its optional usage argument replaces the default Buffer.STORAGE value
and must retain Buffer.STORAGE while adding flags such as Buffer.INDIRECT. Lengths must be
non-negative safe integers.
getViewBinding() returns the 256-byte-aligned buffer range containing a logical
GPUGraphDataView. getViewElementOffset() returns the corresponding offset in 32-bit shader
elements. Bindable views must occupy at least one complete row inside the logical buffer and their
byte offsets must be divisible by four.
Buffer APIsโ
importBuffer(descriptor, defaultBuffer?)โ
Declares caller-owned storage. A default Buffer or DynamicBuffer may be supplied during graph
construction, or the caller may provide a compatible override to each encoding. Represent each
physical buffer with one logical handle whenever any graph access writes to it. Separate active
handles may resolve to the same physical buffer only when every access through both handles is
read-only. The same rule applies to DynamicBuffer wrappers and per-encoding overrides.
createTransientBuffer(descriptor)โ
Declares graph-owned scratch storage. Compatible logical transients with non-overlapping lifetimes may share one physical buffer.
createDataView(handle, props)โ
Creates a GPUGraphDataView<T extends GPUVectorFormat> with format, length, byteOffset,
byteStride, and rowByteLength metadata.
importGPUData(id, data)โ
Imports the backing allocation and preserves the supplied GPUData range.
importGPUVector(id, vector)โ
Imports every fixed-width GPUData chunk without packing and returns a GPUGraphVectorView. Chunk
order, vector metadata, per-chunk offsets, and shared backing buffers are preserved. Interleaved and
variable-length vectors require explicit adapters and are rejected.
Choosing a buffer featureโ
Use importBuffer() when the application already owns persistent storage, such as source data,
published results, or an indirect draw buffer. Use createTransientBuffer() for an intermediate
that exists only while this graph executes; the compiler can safely reuse its allocation after its
last scheduled use. Use createDataView() to describe a typed range of either kind of buffer.
Use importGPUData() when one table chunk is the unit of work. Use importGPUVector() when the
source arrived in several record batches and those boundaries matter. Importing a vector preserves
its existing buffers, offsets, ordering, and empty chunks; it does not concatenate or upload rows.
Multiple chunks backed by the same physical buffer reuse one canonical graph handle.
Physical buffer overlap and writable aliasesโ
Scheduling tracks buffer hazards by logical GPUGraphBufferHandle, not by individual byte ranges.
Two independently imported handles that resolve to one physical buffer would therefore hide a
read-after-write or write-after-write dependency from the scheduler. Before recording any node,
each encode() resolves defaults, DynamicBuffer wrappers, and options.buffers replacements to
their actual physical buffers and applies these rules:
| Active graph resources | Result | Why |
|---|---|---|
| Two handles share a buffer and both are read-only | Allowed | Concurrent reads cannot corrupt each other. |
Two handles share a buffer and either has storage-write, storage-read-write, or copy-destination usage | Rejected before any node runs | Distinct handles cannot express the required write hazard. |
| Several views share one canonical handle across different nodes | Allowed and ordered | Every access participates in the same inferred hazard chain. |
| One shader node declares overlapping storage-binding ranges and either is writable | Rejected when the node is added | WebGPU forbids writable binding aliases inside one shader pass, including views that overlap only after binding-offset alignment. |
| An otherwise duplicated import is not referenced by any graph node | Allowed | Inactive imports cannot race with graph commands. |
| An encoding override introduces writable overlap | That encoding is rejected | Compatibility is checked against current physical bindings, not just graph defaults. |
The safe pattern is to import shared storage once and derive each logical range from that handle:
const sharedStorage = graph.importBuffer(
{id: 'shared-storage', byteLength: sharedBuffer.byteLength, usage: Buffer.STORAGE},
sharedBuffer
);
const rows = graph.createDataView(sharedStorage, {format: 'uint32', length: rowCount});
graph.addComputePass({
id: 'update-shared-rows',
resources: [{buffer: rows, usage: 'storage-read-write'}],
compile: () => ({encode: encodeUpdatedRows})
});
Do not work around this check by importing the same writable physical allocation under separate IDs. If two independently authored primitives need it, pass them the same handle or typed view. When one shader needs distinct input and output bindings in a shared allocation, their aligned binding ranges must not overlap; otherwise expose the shared range through one read-write binding. Validation never destroys caller-owned imports; after a rejected override, the caller can retry with distinct buffers or the original compatible defaults.
Primitive multi-chunk supportโ
The multi-chunk column means that the primitive directly accepts a GPUGraphVectorView and computes
one globally correct result across its ordered GPUGraphDataView chunks. A โ primitive still accepts
its documented atomic graph resources; callers must select, adapt, or explicitly pack chunks.
| Primitive | Primary graph input | Multi-chunk GPUGraphVectorView |
|---|---|---|
GPUScan | Scalar GPUGraphDataView or GPUGraphVectorView | โ |
GPUCompaction | Scalar GPUGraphDataViews or matching GPUGraphVectorViews | โ |
GPUMask | Scalar masks or matching mask GPUGraphVectorViews | โ |
GPUHierarchyLayout | Parent state, child state, heights, and offsets | โ |
GPUGraphTraversal | Packed CSR or aligned local CSR partitions with global neighbor IDs | โ |
GPUAncestorProjection | Source-aligned parent, mask, and output views | โ |
GPUSort | Key and value GPUGraphDataViews | โ |
GPUReduction | Scalar GPUGraphDataView or GPUGraphVectorView | โ |
GPUHistogram | Scalar GPUGraphDataView or GPUGraphVectorView | โ |
GPUGridBinning | Position GPUGraphDataView or GPUGraphVectorView | โ |
GPUGridAggregation | Aligned position and weight views or vectors | โ |
GPUGroupAggregation | Dense group-key view or vector with optional aligned mask | โ |
GPUHashIndex | One packed unsigned-key GPUGraphDataView | โ |
GPUBatchHashIndex | Ordered unsigned-key chunks and optional aligned values or validity | โ |
GPUHashIndexQuery | One packed left-key GPUGraphDataView and a shared hash index | โ |
GPUHashJoin | One packed left-key GPUGraphDataView and a shared hash index | โ |
GPUBatchHashJoin | Ordered left-key chunks and a shared single- or multi-batch right index | โ |
GPUIndexPickingTarget | Texture and readback resources | โ |
DrawCommandBuffer | Indirect command buffer | โ |
Texture APIsโ
importTexture(descriptor, defaultTexture?)โ
Declares a caller-owned Texture or ready DynamicTexture. Texture descriptors are exact rather
than capacity-based: format, dimension, extent, mip count, and sample count must match at every
encoding, while concrete usage must contain every declared flag. Recompile canvas-sized graphs
after a device-pixel resize. Separate active imported handles cannot resolve to the same physical
texture when either handle writes. Read-only aliases remain valid.
Retained texture history without copiesโ
GPUTextureHistory owns
exactly two descriptor-identical textures. Import their initial roles once, compile the graph, and
replace both role bindings when encoding later frames:
import {Texture} from '@luma.gl/core/api';
import {GPUCommandGraph, GPUGraphFrame, GPUGraphFrameHistory, GPUTextureHistory} from '@luma.gl/graph/gpu-graph';
const descriptor = {
format: 'rgba16float' as const,
width,
height,
usage: Texture.SAMPLE | Texture.STORAGE
};
const history = new GPUTextureHistory(device, {id: 'radiance', ...descriptor});
const graph = new GPUCommandGraph(device, {id: 'temporal-renderer'});
const previous = graph.importTexture(
{id: 'previous-radiance', ...descriptor},
history.previousTexture
);
const current = graph.importTexture(
{id: 'current-radiance', ...descriptor},
history.currentTexture
);
graph.addComputePass({
id: 'accumulate-radiance',
resources: [
{texture: previous, usage: 'sampled'},
{texture: current, usage: 'storage-write'}
],
compile: ({device}) => createAccumulationExecutable(device, previous, current)
});
const compiledGraph = graph.compile();
const histories = new GPUGraphFrameHistory(
device,
[{history, previous: 'previous-radiance', current: 'current-radiance'}],
{camera: initialCamera}
);
function encodeFrame(camera: CameraSnapshot, shouldPresent: boolean) {
using frame = new GPUGraphFrame(device.createCommandEncoder());
const bindings = histories.beginFrame(frame, {camera});
compiledGraph.encode(frame, {
parameters: undefined,
textures: bindings.textures
});
if (shouldPresent) frame.submit();
}
Use bindings.valid to select the reset path, and bindings.previousState for metadata such
as the last submitted camera. Supply copied or immutable CPU snapshots. A frame can stage multiple
history groups and other graph commands before one explicit submission. Begin a history group
only for effects that write it in that frame. Scope exit publishes
submitted history or discards the pending state and the encoder. Use a dedicated encoder and
stage resource writes on it if those writes also need to be discardable. The texture pairs remain
owned by their original caller.
Use await frame.submitChecked() in place of frame.submit() to validate the WebGPU queue
submission before publishing history. The promise resolves once WebGPU accepts the submission
and the frame publishes its history, without waiting for execution to finish. If submission fails,
the promise rejects and the frame discards its pending history. Calling complete() while
validation is pending leaves settlement to the checked submission.
Pass that same frame to RayTracingSceneRenderer.render(options, frame) to stage the ray tracer's
camera, sampling counters, acceleration work, and history with other command graphs. Discarding
a frame keeps the last submitted ray-tracing state.
History textures are persistent importTexture() resources, not importFrameTexture() resources.
The latter represents fresh presentation attachments and intentionally rejects reuse across frame
IDs. reset() restores the original role order but does not clear either texture; shaders must
explicitly invalidate stale samples after a camera cut, topology change, or resize.
Physical texture overlap and writable aliasesโ
Texture hazard inference tracks views belonging to one logical GPUGraphTextureHandle. Importing the
same physical texture twice under separate handles would hide cross-handle write hazards, even if
one binding is supplied through an encoding override or numbered frame texture. Before recording any
node, encode() resolves the concrete textures and applies these rules:
| Active imported resources | Result |
|---|---|
| Two handles share a physical texture and both are read-only | Allowed. |
Two handles share a physical texture and either declares storage-write, storage-read-write, render-attachment, or copy-destination | Rejected before recording any node. |
| Multiple texture views share one canonical imported handle | Allowed; overlapping ranges participate in inferred texture hazards. |
| A duplicate import is unused by all graph nodes | Allowed. |
| A persistent override or frame binding introduces writable overlap | Only that encoding is rejected; corrected bindings can be retried. |
Import writable shared storage once and derive all mip, layer, or aspect ranges from that canonical
handle with createTextureView(). Retained-history previous/current roles must resolve to two
different physical textures on every encoding.
importFrameTexture(descriptor)โ
Declares a borrowed texture with no persistent default. Each encoding supplies
frameTextures[id] = {texture, frameId}. All frame textures in one encoding must use the same
non-negative frame ID, and that ID must increase on every later encoding of the compiled graph.
This contract is intended for swapchain color attachments and any matching frame-local depth or resolve resources. The application acquires the textures before encoding and presents them after submission. The graph validates exact descriptor compatibility and ownership, but never acquires, presents, treats an earlier frame binding as reusable, or destroys the imported texture.
importExternalTexture(descriptor)โ
Declares a frame-scoped, sampled-only external image with fixed width and height. Each encoding
supplies externalTextures[id] = {texture, frameId}. The frame ID must be non-negative, strictly
increase for that handle, and match every frameTextures and externalTextures binding supplied
to the same encoding. The concrete ExternalTexture wrapper must also be fresh; incrementing the
frame ID cannot make an earlier opaque browser binding valid again.
Only render nodes may declare {externalTexture, usage: 'sampled'}. Each render node must declare every external image it samples, even when another node already
declares the same image. Its executable resolves the current snapshot with getExternalTexture(handle). This intentionally rules out views, copies, storage,
attachments, transient allocation, and implicit conversion. Use a normal Texture import when a
workflow needs those operations.
const video = graph.importExternalTexture({id: 'video', width, height});
graph.addRenderPass({
id: 'sample-video',
resources: [{externalTexture: video, usage: 'sampled'}],
compile: () => ({
encode: ({renderPass, getExternalTexture}) => {
model.setBindings({videoTexture: getExternalTexture(video)});
model.draw(renderPass);
}
})
});
const externalTexture = device.createExternalTexture({source: videoElement});
compiledGraph.encode(device.commandEncoder, {
parameters,
externalTextures: {video: {texture: externalTexture, frameId}}
});
Acquire the concrete binding immediately before encoding. Media clocks and decoder queues stay outside the graph, and a WebGL or reusable-storage path should copy the source into a normal texture explicitly.
createTransientTexture(descriptor)โ
Declares graph-owned texture storage. Non-overlapping logical textures reuse one physical texture when their descriptors match apart from ID and usage. The allocation is created with the union of their usage flags.
createTextureView(texture, props?)โ
Creates a GPUGraphTextureView with normalized aspect, mip, and array-layer ranges. Texture hazards
are inferred only between overlapping ranges. Handle-level uses conservatively cover the complete
texture.
Render attachments and resolvesโ
addRenderPass() accepts graph-managed color and depth/stencil views. A multisampled color view
can provide a corresponding single-sample entry in resolveTargets:
graph.addRenderPass({
id: 'render-msaa',
attachments: {
colorAttachments: [multisampledColor],
resolveTargets: [frameColor],
depthStencilAttachment: multisampledDepth
},
compile: () => renderExecutable
});
Resolve arrays have one entry per color attachment; null skips a slot. Every non-null target
must match its source format, extent, mip, layer, and aspect, use one sample, and resolve a source
with more than one sample. Source, depth, and other render attachments retain matching sample
counts. Resolve targets participate in ordinary graph hazards, so later sampling or copying is
ordered after the render pass.
Multisample resolve is currently a WebGPU contract. Render-pass callbacks cannot also supply their own framebuffer or resolve targets when graph attachments are present.
Declare a fullscreen drawโ
Use graph.add({command: 'drawFullscreen', ...}) for a WebGPU post-processing pass.
The command draws one triangle over the target. Its generated vertex shader supplies UV
coordinates at @location(0) with the origin at the top left. A fragment shader can write
multiple color attachments by returning outputs at the matching locations.
graph.add({
command: 'drawFullscreen',
id: 'tint',
attachments: {colorAttachments: [outputView]},
inputs: {
textures: {image: {source: inputView}},
samplers: {imageSampler: sampler},
uniforms: {tint: {source: tintBuffer}}
},
fragment: {
source: `
@group(0) @binding(0) var image: texture_2d<f32>;
@group(0) @binding(1) var imageSampler: sampler;
@group(0) @binding(2) var<uniform> tint: vec4f;
@fragment fn fragmentMain(@location(0) uv: vec2f) -> @location(0) vec4f {
return textureSample(image, imageSampler, uv) * tint;
}`
}
});
Here inputView and outputView are graph texture views, tintBuffer is a graph buffer
handle with Buffer.UNIFORM usage, and sampler is a device sampler. The binding names match
the WGSL declarations. The scheduler tracks resource accesses from the inputs and attachments.
Replacing an imported resource at encode time updates its binding for that draw.
The fragment form creates a graph-owned pipeline at compilation using the attachment formats
and sample count. The default entry point is fragmentMain. Supply fragment.entryPoint to
override it. Provide an explicit fragment.shaderLayout when the WGSL scanner cannot infer the bindings.
To reuse a caller-owned triangle-list pipeline that generates its own vertices, set
pipeline on the descriptor in place of fragment. Both forms accept pass for render-pass properties
such as clearColor, or a function of the current encoding parameters that returns those properties.
The compiled graph releases pipelines it creates. Caller-provided pipelines and samplers remain
owned by the caller.
Caller-owned per-encoding framebuffersโ
A render node without graph-managed attachments can select an existing application framebuffer
through its compiled executable's getRenderPassProps() callback:
const graph = new GPUCommandGraph<{framebuffer: Framebuffer}>(device);
graph.addRenderPass({
id: 'present-offscreen',
resources: [{texture: tracedImage, usage: 'sampled'}],
compile: () => ({
getRenderPassProps: ({parameters}) => ({framebuffer: parameters.framebuffer}),
encode: ({renderPass}) => model.draw(renderPass)
})
});
const compiledGraph = graph.compile();
compiledGraph.encode(commandEncoder, {parameters: {framebuffer: firstTarget}});
compiledGraph.encode(otherCommandEncoder, {parameters: {framebuffer: secondTarget}});
Changing the compatible framebuffer does not recompile the graph, and both framebuffers remain caller-owned. The graph still opens and closes the render pass; acquiring or destroying the framebuffer and submitting each command encoder remain the application's responsibilities. Render pipelines must match the selected target's color and depth/stencil formats, so callers should recreate incompatible pipelines when those formats change.
Because an application-provided framebuffer is not a declared graph resource, the graph cannot
infer hazards for its attachment textures or order later nodes that sample them. Import the target
texture and declare graph-managed attachments when later work in the same graph depends on its
output. A node cannot combine graph-managed attachments with a callback-provided framebuffer.
Node APIs and graph commandsโ
A graph command is a reusable description of GPU work, not a second command queue or a hidden
submission API. compile() or await compileAsync() prepares node executables once;
encode(commandEncoder, options)
records them into the application's existing CommandEncoder; the application decides when to
submit that encoder. This distinction lets analytics, rendering, and explicitly requested
readback share one dependency-ordered execution without taking ownership of the frame loop.
| Feature | Why it exists | Typical use |
|---|---|---|
addComputePass() | Schedule shader dispatch alongside its declared buffer and texture hazards. | Filtering, scans, sorting, hash-index construction, aggregation, and indirect-command generation. |
addRenderPass() | Schedule drawing with graph-managed attachments or compatible caller-owned framebuffers. | Scene rendering, picking, off-screen layers, and multisampled frame composition. |
addCopyPass() | Express transfers or encoder-level operations in the same ordered graph. | Explicit compact-result readback, staging uploads, and copying finished render targets. |
dependsOn | Describe an ordering requirement that no shared graph resource can express. | External side effects, timestamp boundaries, and application-owned synchronization. |
Repeated encode() | Reuse compiled pipelines and scratch allocations with new parameters or imports. | Interactive filters, animation frames, changing selections, and reusable query plans. |
createExecution() | Advance one graph invocation through bounded dependency-ordered submissions. | Large aggregations, index builds, and background analysis that must not monopolize a frame. |
Declare commandsโ
Pass a descriptor to commandGraph.add() with a command, an id, and the fields for that operation.
The operation selects the compute, copy, or render pass. The graph tracks resource accesses
from the operands, compiles the pipeline once, and resolves the current physical resources
at each encoding.
| Layer | What you write | Discriminator |
|---|---|---|
| Semantic operation | graph.add(gpuOperation, props) | An operation definition has a type such as 'scan'. |
| Command descriptor | commandGraph.add({command: 'dispatch', id, source, bindings, workgroups}) | The command selects the GPU command. |
| Callback pass | commandGraph.addComputePass({id, resources, compile}) | The lowered node has a pass type such as 'compute'. |
| Operation | Required fields | What it records |
|---|---|---|
dispatch | WGSL source, bindings, and workgroups: [x, y, z] | One dispatch with fixed workgroup counts. |
dispatchIndirect | WGSL source, bindings, and an INDIRECT buffer | One dispatch using three uint32 counts from the buffer. An optional byteOffset selects a four-byte-aligned record. |
writeBuffer | destination, byteLength, and getData | A CPU-to-GPU upload ordered with the surrounding commands. |
copyRows | source and destination data views | A copy respecting both views' offsets and strides. Layout requirements |
copyTexture | source and destination texture views | A copy of compatible mip and layer ranges, one command per mip. |
drawFullscreen | attachments and a fragment or pipeline | A fullscreen triangle with graph-managed attachments. |
Sequence dispatchesโ
Add one descriptor per dispatch. Call add() for each descriptor or pass an array to add a
sequence. For example, if a histogram dispatch writes counts and a prefix dispatch reads
counts, add the histogram first. Their declared access modes give the scheduler a
write-to-read dependency. Use dependsOn: ['histogram'] for an ordering requirement that
shared resources cannot express.
Adjacent compute nodes can share one physical compute pass while keeping individual node IDs, resource accesses, and diagnostics. Copies and renders end the current compute pass. A timestamped encoding gives each compute node its own pass for measurement.
Match bindings to WGSLโ
Each binding specifies the WGSL variable name and its resource. group defaults to zero.
A binding's default location is its zero-based index among entries in that group. Entries
can be interleaved across groups. Set location explicitly for sparse binding numbers. For
example, an entry with group: 1, location: 3 matches @group(1) @binding(3).
| Resource | Binding fields |
|---|---|
| Storage buffer or data view | buffer and usage: 'storage-read', 'storage-write', or 'storage-read-write' |
| Uniform buffer | buffer and usage: 'uniform' |
| Fixed storage or uniform bytes | data and usage: 'storage-read' or 'uniform' |
| Sampled texture view | texture, usage: 'sampled', and sampleType |
| Storage texture view | texture and the storage access mode used by the shader |
| Device sampler | sampler and optional samplerType for a non-filtering or comparison sampler |
A data view binds an aligned storage range. Use getViewElementOffset(view) in the generated
shader to index its first row. For example, bind an r32float texture for textureLoad with
sampleType: 'unfilterable-float'. The graph derives the view dimension and storage format
from the texture view and tracks its mip, layer, and aspect range.
For fixed bytes, pass a Uint32Array, Int32Array, or Float32Array. Pack the values to
match the WGSL layout, including any required padding. The graph snapshots the array when you
add the command. Each compilation owns the resulting GPU buffer and releases it when destroyed.
Set entryPoint if the shader entry point has a name other than main. Direct dispatches
can use GPU predicates. An indirect dispatch takes its geometry from GPU memory and can use
a CPU condition. Use a callback pass for custom encoding, such as workgroup counts computed
from CPU parameters immediately before recording.
Upload shader parameters per runโ
Use writeBuffer when the application supplies new shader data on each encoding.
getData(parameters) packs those parameters into an array-buffer view. The destination needs
Buffer.COPY_DST usage. The offset defaults to zero. The offset and the positive byte length
must be multiples of four and fit the destination. Return exactly byteLength bytes.
const commandGraph = new GPUCommandGraph<{gain: number}>(device);
const settings = commandGraph.createTransientBuffer({
id: 'gain',
byteLength: 4,
usage: Buffer.COPY_DST | Buffer.UNIFORM
});
const values = commandGraph.importBuffer(
{id: 'values', byteLength: valueBuffer.byteLength, usage: valueBuffer.usage},
valueBuffer
);
commandGraph.add([
{
command: 'writeBuffer',
id: 'upload-gain',
destination: settings,
byteLength: 4,
getData: ({gain}) => Float32Array.of(gain)
},
{
command: 'dispatch',
id: 'scale-values',
source: `
@group(0) @binding(0) var<storage, read_write> values: array<f32>;
@group(1) @binding(0) var<uniform> gain: f32;
@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) index: vec3u) {
if (index.x < arrayLength(&values)) {
values[index.x] *= gain;
}
}`,
workgroups: [Math.ceil(valueBuffer.byteLength / (64 * 4)), 1, 1],
bindings: [
{name: 'values', buffer: values, usage: 'storage-read-write'},
{name: 'gain', buffer: settings, usage: 'uniform', group: 1}
]
}
]);
const compiledGraph = commandGraph.compile();
compiledGraph.encode(encoder, {parameters: {gain: 0.5}});
compiledGraph.encode(encoder, {parameters: {gain: 0.25}});
Here valueBuffer is a caller-owned storage buffer of float32 values. Both encodings can
share one encoder and submission. Each dispatch sees its own gain because its upload is
recorded before it as a buffer copy. Use an inline data binding for a value that stays fixed
across encodings.
Budgeted execution across framesโ
compiledGraph.createExecution({maximumInvocationCount}) creates a resumable cursor over one graph
invocation. Budgets can additionally cap nodes, commands, bytes read, and bytes written per
submission. Each encodeNext() call records the next contiguous dependency-ordered range fitting
all supplied limits. The graph still does not own submission or animation scheduling: applications
submit one returned step when their frame loop admits background work.
const budget = {
maximumInvocationCount: 262_144,
maximumReadByteLength: 16 * 1024 * 1024,
maximumWriteByteLength: 8 * 1024 * 1024
};
const executionOptions = {
latencyPriority: 'background' as const,
publicationPolicy: 'progressive' as const
};
const plan = compiledGraph.getExecutionPlan(budget, executionOptions);
if (plan.oversizedStepCount > 0) {
showWarning(`${plan.oversizedStepCount} indivisible operations exceed the frame budget`);
}
const execution = compiledGraph.createExecution(budget, executionOptions);
function encodeBackgroundStep(): void {
const commandEncoder = device.createCommandEncoder();
const step = execution.encodeNext(commandEncoder, {parameters});
device.submit(commandEncoder.finish());
if (!step.completed) requestAnimationFrame(encodeBackgroundStep);
}
getExecutionPlan() is a dry run: it returns immutable step boundaries, complete static cost
totals, and an oversized-step count before commands enter the GPU queue. This lets an application
explain expensive work, lower its budget, or require confirmation without speculative execution.
Progress from encodeNext() is based on planned submissions, so it remains stable when nodes have
very different costs.
Use {breakBeforeNode: 'present'} when a caller owns the timing of a specific scheduled node.
For example, a splat renderer can encode projection and sorting, draw the prepared data into a host
pass, and resume its standalone presentation later. The named node starts a new step. Tighter
budgets can split the preceding work into multiple steps. Submit steps in order on the same queue.
Every execution carries an explicit interactive, normal, or background latency priority.
The graph exposes it on the immutable plan and every returned step so an application scheduler can
arbitrate several ready executions without guessing from graph IDs. Priority does not reorder
nodes or bypass dependencies.
Nodes are the atomic scheduling unit. An operation that may span frames should contribute bounded
partition nodesโtypically initialization, independently sized accumulation partitions, and
finalizationโand annotate invocation, command, read-byte, and write-byte bounds. Queue submission
order preserves buffer dependencies between steps. A node larger than any requested budget is
encoded by itself so execution always makes progress, and its step reports exceedsBudget: true.
Intermediate outputs remain application-private until the cursor reports completion by default.
Controlled partial publicationโ
A node may declare a coherent result boundary with publication: {id, completeness}. With the
default publicationPolicy: 'final', these boundaries do not alter execution and only complete
graph output is publishable. With publicationPolicy: 'progressive', the planner closes a step at
each declared boundary. After that command buffer completes on the GPU queue, step.publishable
is true and step.publications identifies the application results that are safe to consume.
graph.addCopyPass({
id: 'summary-ready',
resources: [{buffer: summary, usage: 'storage-read'}],
publication: {id: 'summary', completeness: 'partial'},
compile: () => ({encode: () => {}})
});
The resource read makes the coherence boundary depend on all prior summary writes, and later
writes depend on the boundary. A publication node may encode real copy work or be a no-command
boundary as above. The application must still wait for submitted work before reading or presenting
the result. execution.publishedProgress advances only at safe boundaries; ordinary encoding
progress can continue independently.
Measured budget feedbackโ
GPUCommandGraphExecutionBudgetController calibrates the next execution from measured
queue-completion time. It scales every configured budget dimension together, preventing a faster
invocation target from silently violating command or memory-traffic constraints. Tail steps are
normalized by their consumed fraction of the current budget, so a small final partition does not
incorrectly inflate the next execution.
const controller = new GPUCommandGraphExecutionBudgetController({
initialBudget: budget,
latencyPriority: 'interactive'
});
const execution = compiledGraph.createExecution(controller.budget);
while (!execution.completed) {
const encoder = device.createCommandEncoder();
const step = execution.encodeNext(encoder, {parameters});
const startTime = performance.now();
device.submit(encoder.finish());
await device.handle.queue.onSubmittedWorkDone();
controller.observeStep(step, performance.now() - startTime, execution.budget);
}
An execution plan remains immutable after creation: timing feedback affects later graph executions, not work already encoded or submitted. Passing the execution's original budget keeps every step's saturation measurement tied to the plan that produced it even while the controller learns a future budget. Applications should normally keep separate controllers for operations with different kernels, such as index construction, aggregation, and causal traversal.
Latency priority supplies a queue-time target of 4 ms for interactive, 8 ms for normal, or
16 ms for background. targetStepMilliseconds remains available as an explicit override. The
controller uses measurements to tune later immutable plans toward that target.
Adapter-local kernel autotuningโ
Execution budgets answer โhow much work belongs in one submission?โ
GPUCommandGraphAutotuner answers the separate question โwhich equivalent kernel should do that
work on this adapter?โ Create one tuner for the device and share it across graphs:
const adapter = getGPUCommandGraphAdapterIdentity(device);
const autotuner = new GPUCommandGraphAutotuner({
adapter,
profile: loadApplicationProfile(adapter.key)
});
const graph = new GPUCommandGraph(device, {autotuner});
const selection = autotuner.selectKernel({
operation: 'GPUScan',
workloadSize: rowCount,
candidates: [
{id: 'subgroups', supported: device.features.has('subgroups')},
{id: 'portable'}
]
});
Selection is deterministic. Each supported variant is explored until minimumSampleCount samples
exist in the current power-of-two workload bucket. Later decisions use the lowest estimated GPU
duration, falling back to the nearest measured bucket when an exact bucket is unavailable. Setting
explorationEnabled: false makes uncalibrated choices use candidate order.
Annotate equivalent nodes so one timing report can update the profile:
graph.addComputePass({
id: 'scan-level-0',
workload: {
operation: 'GPUScan',
variant: selection.variant,
maximumInvocationCount: rowCount
},
resources,
compile: compileSelectedScan(selection.variant)
});
const report = await inspectorObservation.recordGPUTimings(encoding);
if (report) {
autotuner.observeTimingReport(report, compiledGraph.preflight);
saveApplicationProfile(autotuner.exportProfile());
}
exportProfile() returns JSON-safe adapter identity and timing aggregates. The application decides
whether to keep it in memory, persist it, or discard it. A profile with a different adapter key is
ignored. GPU Core performs no browser-storage access, and observations affect only graphs compiled
after the next selection decision; an already compiled graph never changes kernels underneath an
execution.
addComputePass(node)โ
Use a compute node whenever a shader reads or writes resources that other graph features consume.
The graph manages the ComputePass; the executable only records dispatch commands. Consecutive
compute nodes normally share one physical pass, preserving their individual execution order and
debug groups without paying repeated pass-management overhead. A render or copy node always closes
the active compute pass before recording its own commands. Declaring every input as storage-read
and every output as storage-write lets later compute, render, or copy nodes automatically wait
for the produced data.
graph.addComputePass({
id: 'select-visible-rows',
resources: [
{buffer: inputRows, usage: 'storage-read'},
{buffer: visibilityMask, usage: 'storage-write'}
],
compile: ({device}) => createVisibilityExecutable(device)
});
Primitives such as GPUBatchHashIndex, GPUScan, and GPUHashJoin use this same public graph
contract: primitive.getCommandNodes(graph) contributes compute nodes but does not compile, submit, or
read back the graph on the application's behalf.
addRenderPass(node)โ
Use a render node when graph-produced buffers or textures feed a draw, or when a draw produces a
texture consumed by a later pass. Declare sampled and vertex inputs normally and supply graph-owned
attachments when the graph should resolve the framebuffer. Multisampled attachments can provide
resolveTargets; attachment writes then participate in ordinary texture hazard ordering.
graph.addRenderPass({
id: 'draw-visible-instances',
resources: [{buffer: visibleRows, usage: 'vertex'}],
attachments: {colorAttachments: [frameColor]},
compile: () => ({encode: encodeVisibleInstances})
});
The graph owns the RenderPass lifecycle. The executable records drawing commands; it must not
end the pass, submit the encoder, or replace a graph-managed framebuffer. When no attachments are
declared, getRenderPassProps() may choose a compatible caller-owned framebuffer for each
encoding.
addCopyPass(node)โ
Use a copy node when an operation belongs directly on the application's CommandEncoder, such as
copying one small summary into an explicitly requested readback buffer. Copying is never implied by
graph execution: an application that keeps all results GPU-resident should not add a readback
node. Declare the source and destination so transfers are ordered after producers and before
subsequent consumers.
graph.addCopyPass({
id: 'copy-result-summary',
resources: [
{buffer: resultSummary, usage: 'copy-source'},
{buffer: readbackSummary, usage: 'copy-destination'}
],
compile: () => ({encode: encodeSummaryCopy})
});
Explicit dependencies and repeated encodingsโ
Prefer declared resource uses because they explain both ordering and transient lifetimes. Add
dependsOn: ['upstream-node-id'] only when an application-visible dependency has no corresponding
buffer or texture hazard. Compile the complete graph once, then supply fresh parameters or
compatible imported buffers and textures through later encode() calls. Writable physical-buffer
and physical-texture overlap are revalidated for every encoding before any node records work.
Buffer nodes declare storage, uniform, copy, indirect, vertex, and index uses. Texture nodes declare
sampled, storage, render-attachment, and copy uses. Render attachments are automatically treated
as read-write resources. dependsOn adds explicit ordering where resources do not express the
dependency.
Executable contexts expose getBuffer(), getTexture(), getTextureView(), and
getExternalTexture(). Concrete ordinary texture views and framebuffers are cached for repeated
encodings and rebuilt when an imported texture is replaced. Non-default views over frame-scoped
ordinary textures are refreshed for each frame ID; external textures never enter either cache.
CompiledGPUCommandGraphโ
encode(commandEncoder, options)โ
Records every compiled node. options.parameters is forwarded to callbacks. options.buffers may
override imported buffers by ID if capacity and usage remain compatible. options.textures
overrides exact-size imported textures. It returns a GPUCommandGraphEncoding with synchronous
whole-graph and per-node CPU encoding statistics.
Defaults, DynamicBuffer and DynamicTexture wrappers, per-encoding replacements, and numbered
frame-texture bindings must not introduce writable aliases between separate active logical handles.
Read-only aliases remain valid. All resource validation occurs before the first node executes.
encode() never submits, maps, reads, or grows resources.
Consecutive compute nodes share one physical compute pass by default. Node order, resource hazards,
debug groups, and individual CPU measurements remain unchanged; render and copy nodes form strict
pass boundaries. Set options.coalesceComputePasses to false when separate passes are required.
encoding.stats.computePassCount reports the actual number of physical compute passes, and
encoding.stats.coalescedComputeNodeCount reports how many nodes reused an already-open pass.
options.frameTextures and options.externalTextures form one coherent frame transaction. The
graph validates every binding before advancing its remembered frame IDs, so a rejected replacement
can be corrected and retried without partially consuming a frame.
If the caller's encoder has a timestamp query set, compute and render passes record timestamp pairs
without changing graph code. Compute-pass coalescing is automatically disabled for that encoding
so every compute node retains its own GPU timestamp pair. encoding.canReadGPUTimings reports
whether any pairs were captured. After submitting the command buffer, await encoding.readTimings() explicitly reads per-node and total GPU durations. The read is never
automatic, and copy nodes remain CPU-timed until the portable command-encoder API exposes
standalone timestamp writes.
Reports and their nodes retain the existing cpuEncodeTimeMilliseconds and
gpuTimeMilliseconds durations and expose span endpoints:
cpuEncodeStartTimeMillisecondsandcpuEncodeEndTimeMillisecondsuseperformance.now()(orDate.now()as a fallback), and are also available synchronously inencoding.stats.gpuStartTimeMillisecondsandgpuEndTimeMillisecondsuse the WebGPU timestamp clock. Subtract a shared GPU origin when building a trace. This clock is not correlated with CPU timestamps or wall time. Endpoints are converted to numbers in milliseconds; durations are computed from the integer nanosecond difference before conversion to preserve precision.
Graph GPU endpoints enclose the measured passes, including gaps between them. The existing GPU duration remains the sum of measured node durations, so it can differ from that span. Copy nodes and skipped nodes have no GPU endpoints; duration-only backends omit GPU endpoints rather than synthesizing positions. CPU endpoints are optional in the types for compatibility with externally constructed reports, but graph encoding always supplies them, including for skipped nodes. These fields can be exported as JSON span rows without converting bigint values.
capabilitiesโ
Snapshots graph-relevant adapter information: timestamp-query support, software-adapter status, maximum buffer and storage-binding sizes, and compute invocation and dispatch limits. Applications can report or gate advanced diagnostics without inspecting backend handles.
statsโ
Reports node order; imported, logical, and physical buffer and texture counts; declared or estimated bytes; combined logical and owned-transient memory; and separate buffer and texture reuse percentages. Imported bytes describe borrowed capacity and are never counted as graph-owned memory.
Benchmarking protocolโ
Performance comparisons should warm the graph, then record encoding.stats, optional
readTimings() results, and compiledGraph.stats without adding readback to the normal frame loop. Use
the same adapter and viewport for each run and include:
- empty, one-row, workgroup-boundary, and immediately-over-boundary inputs;
- the trace viewer's 250,000, 1,000,000, and 4,000,000 span capacities;
- sparse and dense dependency neighborhoods;
- repeated parameter-only updates that do not recompile the graph.
Report adapter capabilities with the measurements so software and hardware results are not mixed. CPU encode, GPU execution, logical memory, physical transient memory, and reuse percentage are separate values and should not be collapsed into one score.
destroy()โ
Destroys compiled node resources, cached views/framebuffers, and physical transients. Imported buffers, textures, and external-image bindings remain caller-owned.
GPUCommandGraphInspectorโ
GPUCommandGraphInspector is a data-only collector for one or more compiled graphs. Its non-owning
observation handle registers a graph and records synchronous CPU measurements whenever encoding is
routed through the handle. Optional GPU timestamp readback remains explicit and happens only after
the caller submits the command buffer:
import {GPUCommandGraphInspector} from '@luma.gl/graph/gpu-graph/diagnostics';
const inspector = new GPUCommandGraphInspector({maxSamples: 120});
const observation = inspector.observeGraph(compiledGraph);
const commandEncoder = device.createCommandEncoder();
const encoding = observation.encode(commandEncoder, {parameters: {time}});
device.submit(commandEncoder.finish());
if (encoding.canReadGPUTimings) {
await observation.recordGPUTimings(encoding);
}
// The application remains responsible for any diagnostic-buffer readback.
observation.recordCounters({candidates, matches});
const snapshot = inspector.getSnapshot();
observation.detach();
readResource(graphId, nodeId, resourceIndex) explicitly reads a bounded preview from the latest
recorded encoding, after application submission. It returns tightly packed bytes and, for textures,
the preview dimensions and format. This reads current allocation contents, not historical per-node
values, and can submit a diagnostic copy. Unsupported or expired resources reject with an explanation.
See Graph Resources for the panel, limits,
and required resource usage.
getSnapshot() returns an immutable view of every registered graph in registration order. Each
graph snapshot includes its compile-time stats and capabilities, encoding and failed-timing-read
counts, bounded whole-graph CPU and GPU duration summaries, application-defined scalar counter
summaries, and per-node summaries in compiled schedule order. Duration and counter summaries contain
the retained sample count plus latest, p50, and p95 values. Counters remain in first-observed order.
Pass getNodeGroup to the constructor to add application-specific semantic groups to node snapshots;
pass maxSamples to bound every retained history.
The inspector does not submit commands, poll frames, render a panel, or read GPU timestamps
automatically. An observation does not own or destroy its graph. detach() stops that observation
and removes its registration when it is still current; an old handle cannot remove a replacement
with the same graph ID or publish delayed counters into it. A handle accepts timing reads only for
encodings it produced and records at most one GPU sample per encoding. recordCounters() only
stores caller-provided finite, non-negative values; it does not read a buffer or synchronize the
device. clear() removes all registrations. The lower-level registerGraph(), recordEncoding(),
recordGPUTimings(), and recordCounters() methods remain available for applications that cannot
route graph activity through an observation handle.
Reusable GPU Trace panelโ
The examples provide GPUTracePanel in examples/gpu-trace-panel.ts. Add its panel
to an example panel collection, then pass it an already collected timing report:
const tracePanel = new GPUTracePanel();
// Include tracePanel.panel in the application's panel collection.
tracePanel.update(await encoding.readTimings(), compiledGraph.id);
Call readTimings() after submission, or reuse the report returned by
observation.recordGPUTimings(encoding) to avoid an extra read. For a CPU-only preview,
tracePanel.update(encoding.stats, compiledGraph.id) works before GPU readback completes.
The panel retains only the latest report across unmounts, shows separate CPU and GPU clocks,
keeps gaps between node spans, and exposes node details on hover and keyboard focus.
GPUTracePanelRenderer provides the same view directly inside an HTMLElement with
update(report, label) and destroy() methods. GPU Trace Viewer, Billion-Point Spatial Atlas, and GPU Spatial Taxi use this panel.
Estimated combined CPU/GPU timelineโ
WebGPU timing reports may include clockCorrelation, captured at command-buffer submission.
Add clockCorrelation.offsetMilliseconds to a raw GPU endpoint to place it on the CPU
performance.now() timeline. Durations and raw endpoints remain unchanged. This is an estimate,
not an exact clock synchronization API. uncertaintyMilliseconds represents the half-width of
the submission/completion latency interval; hardware/browser timestamp quantization adds further
uncertainty. sampledAtCpuTimeMilliseconds identifies the CPU time of the completion observation.
Each profiled WebGPU encoder resolves its timestamps into private buffers before later submissions
can reuse the query slots. The encoder's captureTimestampQuerySet(querySet) returns a snapshot
that remains associated with that encoding, including when read after newer submissions. Abandoned
encodings reject snapshot reads, and submitted snapshot buffers are released after readback even
when no caller reads the report. Direct QuerySet.readResults() continues to read mutable query-set
state; use encoder snapshots when submission identity matters.
The device correlator intersects compatible bounds from recent submissions, expires the history after one second, and resets on inconsistent intervals. It assumes a stable offset over that short window. It does not wait synchronously or submit calibration work. Correlation is omitted when valid bounds or GPU endpoints are unavailable; WebGL remains duration-only.
The reusable GPU Trace panel offers Combined timeline (estimated) when correlation is available.
Both lanes then share one origin and scale, and the panel displays alignment uncertainty. Separate
CPU/GPU timelines remain the default. No extra ClockSync graph operation is required.
For sampled WebGPU diagnostics, commandEncoder.withTimeProfilingQuerySet?.(querySet, encode)
scopes automatic pass timestamps to a synchronous encoding callback. Supply a fresh timestamp query
set for each scope and retain it until submission and timing readback complete. The encoder restores
the caller's profiling query set and slot count afterward, including when encoding throws. This
WebGPU-only hook avoids enabling a device-wide profiler for every frame; unsupported encoders can
encode normally and report CPU spans. The Graph Explorer examples use this path for sampled traces.
Describing operationsโ
Compute, render, and copy nodes accept an optional description string. Use it to explain
application intent, for example description: 'Resolve contact and joint constraints.'.
Descriptions are plain text displayed in GPU Graph and GPU Trace tooltips. They are retained
in compiled preflight reports, encoding statistics, timing reports, and inspector snapshots,
including when those reports are serialized to JSON. They do not affect scheduling or execution.
Tooltips also show declared resource inputs and outputs, access modes, buffer byte ranges, and available view formats, row counts, and texture dimensions. These are static declarations, not measured traffic or a readback of buffer contents. Serializable resource summaries are retained in preflight reports and traces.
Buffer and texture managementโ
See Buffers and textures for logical values, views, imported and transient ownership, hazard tracking, history, resizing, and encoding contracts.
Inspecting compute kernelsโ
Pass {kernelMetadata: 'layout'} to graph.compile() or graph.compileAsync() to include
declared entry points, workgroup dimensions, and binding layouts in preflight. Use 'source'
to also include available WGSL. Default compilation omits these details.
const compiledGraph = graph.compile({kernelMetadata: 'layout'});
inspector.registerGraph(compiledGraph);
const nodes = inspector.getSnapshot().graphs[0].preflight?.nodes;
GPUScan and GPUSegmentedScan supply metadata. Custom compute nodes can supply a kernel
declaration through graph.addComputePass() or createGPUComputeCommandNode().
Pacing repeated submissionsโ
Use GPUCommandGraphSubmissionPacer when an animation loop owns submission and
should leave headroom between graph executions. It allows one tracked submission
at a time and chooses the next cooldown from the observed queue-completion time.
The default targets a 50% duty cycle with a cooldown between 8 and 250 ms.
Queue-completion time includes waiting behind other work on the queue.
Check isReady() before encoding a batch. Submit with the application's usual
queue ownership, then pass its completion promise to trackSubmission(). The
pacer preserves completion errors and can accept later submissions after the
minimum cooldown. The ANARI Observatory and Playground use this policy for live
ray tracing. They feed lastSubmissionMilliseconds into the renderer budget
so intentional idle time does not lower ray resolution. Offline captures retain
their deterministic scheduling.
The pacer controls how often work is submitted. Use the execution budget controller and bounded dispatches for graphs that also need to reduce work per submission.
For application-sized dispatches, call the budget controller's
observeInvocations() with the measured invocation count, GPU duration, and
budget used for that submission. Its recommendation applies to future batches.
The live ANARI examples use this to vary trace coverage at sweep boundaries
while reusing their progressive history.
Capturing intermediate buffer valuesโ
GPUBufferCapture copies a typed view into a caller-owned output view at its position in the
command graph. A later operation can overwrite the source or reuse its transient allocation while
the copied snapshot remains available. Submit the graph before reading the output buffer. Each
encoding replaces the same snapshot, so read it before submitting another encoding when every
run must be retained.
import {GPUBufferCapture} from '@luma.gl/graph/gpu-graph/diagnostics';
graph.add(new GPUBufferCapture({id: 'scan-snapshot', source: prefixes, output: snapshotView}));
The views have equal format, length, and row width, and use distinct buffers. The output is an
imported buffer with COPY_DST usage; add COPY_SRC when reading it back. The graph supplies copy
usage for transient sources, while imported sources need COPY_SRC. Offsets, strides, and row
widths are multiples of four bytes. Packed views use one copy; strided views copy each logical row
and preserve output padding. Empty views add no commands.
A capture inserts a copy boundary between compute passes. Its preflight entry reports the copy count and bytes read and written. The caller owns snapshot allocation and destruction.
Reusing GPU-gated iteration batchesโ
GPUIterationBatch compiles a fixed number of rounds and reuses that graph across submissions.
A borrowed four-byte active buffer holds a uint32 continuation flag. Nonzero permits work and
zero means convergence. Supply COPY_SRC | COPY_DST usage and initialize it before a new solve.
The executor reads this word once after each submission, then submits another batch if needed.
import {GPUIterationBatch} from '@luma.gl/graph/gpu-graph';
const iterations = new GPUIterationBatch(device, {
active: continuationBuffer,
iterationsPerBatch: 16,
createIteration: ({graph, active, index}) => makeRelaxationNodes(graph, active, index)
});
const status = await iterations.run({maximumIterations: 1000, parameters: undefined});
iterations.destroy();
The factory builds unconditional compute nodes and gives each round distinct node and scratch
IDs. Annotate every node's exact direct dispatch with setGPUComputeDispatchWorkgroups(node, [x, y, z]). The executor generates indirect gates for those dispatches. The final node of a round
clears active on convergence; remaining rounds dispatch zero workgroups. Caller-owned state
buffers carry algorithm state across batches. Import shared buffers through importGPUData or
importGPUVector so repeated round factories use the same logical handle. Per-round scratch is
local to the compiled batch. The factory receives a scalar view from a sealed arena and can create
ordinary transient buffers for its own scratch.
run enforces the total budget, compiling a shorter final batch when needed. scheduledIterations
is an upper bound because gating can skip converged rounds. budgetExhausted reports an active
continuation flag at the budget limit, and a later run can continue from that state. Overlapping
runs and destruction during a run are rejected. destroy releases compiled resources; input and
state buffers remain caller-owned. The caller can use the returned batch count and compiled node
count to compare execution with an unrolled plan.