General-purpose GPU computation
The modules/graph package provides luma.gl's general-purpose GPU computation layer. It turns typed values, vectors, tables, and textures into reusable work that can run as lazy operations or as explicit WebGPU command graphs. The former @luma.gl/gpgpu facilities now use graph package entry points, so computation results can move between data processing, graph algorithms, physics, and rendering without an unnecessary CPU round trip. See GPU compute and effects, GPU simple graph, GPU graph workflows, and Rendering effects for related views.
Computation model
The computation layer has two related models. Simple data work is described as a lazy value graph, while larger workloads declare resources and passes in an explicit command graph.
Lazy operation graphs
GPUDataEvaluator describes one fixed-width data result without running it. An operation records its inputs and dependencies, then materializes the result only when the caller evaluates it. The public operations cover arithmetic and common row transforms such as casts, color conversion, dot products, comparisons, extents, gathers, interleaves, selections, sequences, swizzles, lengths, and segmented maps. Constants and existing GPU data can take part in the same graph.
The evaluator selects a CPU, WebGL, or WebGPU handler from the device and operation. This lets one data expression keep the same meaning across backends, while a caller can choose a GPU path when the data should stay resident. GPUSimpleGraph adds named inputs, state, outputs, and compiled graph-shaped expressions around this evaluator model.
This flow shows how a data expression becomes a reusable GPU value.
flowchart LR
A[CPU values or GPU data] --> B[Lazy evaluators]
B --> C[Operation dependencies]
C --> D[Backend evaluation]
D --> E[GPU vector result]
E --> F[Later compute or rendering]
References: modules/…/index.ts• L5-109 modules/…/operation.ts• L35-99 modules/…/backend-registry.ts• L15-18 modules/…/arithmetic.ts• L9-16
Semantic graph expressions
GPUGraph is a backend-independent description of scalar, vector, and texture values. It separates declared inputs and state from operations, then compiles the description for a device. GPUExpressionOperation adds named numeric expressions to this model. It accepts a small, checked expression language for scalar and vector arithmetic, component selection, vector construction, numeric casts, common math functions, comparisons, and conditional selection. Float-to-integer casts truncate by default or round ties away from zero when integerRounding: 'nearest' is selected. Compilation resolves references and row formats before execution, so the expression result must match its declared output.
GPUSimpleGraph connects this semantic model to the older evaluator operations and can preserve caller-controlled WebGPU submission where supported. This model is useful when an application wants named values and a stable program shape across repeated runs. It is distinct from the lower-level command graph, which describes concrete resource use and pass order.
This model keeps expression meaning separate from the device-specific work that runs it.
flowchart LR
A[Named scalar and vector values] --> B[Numeric expression]
B --> C[Reference and format checks]
C --> D[Compiled graph operation]
D --> E[Backend execution]
References: modules/…/gpu-graph.ts• L36-57 modules/…/gpu-graph-value.ts• L12-43 modules/…/gpu-expression-operation.ts• L11-67 modules/…/gpu-expression-operation.ts• L107-116 modules/…/gpu-expression-operation.ts• L119-196 modules/…/gpu-expression-operation.ts• L231-325 modules/…/gpu-expression-plan.ts• L152-216 modules/…/index.ts• L680-687
Evaluator inspection and cleanup
Evaluator inspection gives a read-only description of outputs, dependencies, row counts, and formats before execution. cleanEvaluate materializes selected roots and releases intermediate storage that no root still uses. Together, these facilities let applications inspect planned work and keep temporary GPU memory from extending beyond the result lifetime.
References: modules/…/gpu-evaluator-inspection.ts• L8-83 modules/…/clean-evaluate.ts• L13-65 modules/…/index.ts• L87-98
Evaluation scopes
GPUEvaluationScope is an explicit WebGPU submission boundary for supported lazy operations. It records dependent evaluations into one command encoder, then submits or cancels the complete group. Results may feed commands recorded on that encoder, but the caller must not use them as completed data before submission.
The scope also keeps temporary results and borrowed resources valid until submission or cancellation. A dependency or submission error cancels the scope instead of exposing a partial result.
References: modules/…/gpu-evaluation-scope.ts• L11-18 modules/…/gpu-evaluation-scope.ts• L19-76 modules/…/operation.ts• L63-75
GPU data structures
The data layer gives computation a common view of values in GPU memory. It keeps logical row shape, physical byte layout, chunk boundaries, and ownership visible to both compute and rendering users.
GPU data and vectors
GPUData represents one typed GPU data range. GPUDataView describes a non-owning typed range over a buffer. GPUVector presents one logical vector as a buffer, an interleaved buffer, several ordered chunks, or appendable data. A vector records its format, row count, scalar stride, byte stride, row size, and ownership rules.
These distinctions allow a computation to borrow existing storage, write into a caller-selected range, or preserve a chunked source without packing it first. GPUVectorEvaluator applies one lazy transform to each chunk and rebuilds the vector with the same order and boundaries.
References: modules/…/gpu-vector.ts• L23-166 modules/…/gpu-data.ts• L1-120 modules/…/gpu-data-view.ts• L1-80 modules/…/gpu-vector-evaluator.ts• L43-59 modules/…/gpu-vector-evaluator.ts• L147-213
Formats and ownership
Formats state how scalar values and fixed or variable lists map to GPU bytes. Views add the row offset, stride, and length needed to use a subrange safely. A resource can be owned by the vector or borrowed from a caller, so a result can be handed to another graph or renderer without transferring destruction by accident.
Fixed-width data is the main input contract for lazy evaluators. Variable-length and interleaved data use the vector and graph-view paths that understand their layout rather than being treated as one ordinary numeric row.
References: modules/…/gpu-vector-format.ts• L1-120 modules/…/gpu-data-view.ts• L1-80 modules/…/gpu-vector.ts• L265-329 modules/…/gpu-data-evaluator.ts• L257-297
Execution primitives
Execution primitives connect assembled shader programs to luma.gl passes. They keep shader assembly, resource ownership, and scheduling above the primitive so the same kernel can serve several higher-level workflows.
Compute and render kernels
Kernel is a reusable WebGPU compute program. It accepts bindings for each dispatch and supports direct or GPU-driven indirect dispatch. RenderKernel is the matching WebGL and WebGPU draw primitive. It accepts bindings and vertex state for each draw and supports direct and WebGPU indirect draws.
The kernels own compiled shader and pipeline state, but they do not own application data, uniforms, geometry policy, or command submission. This makes them suitable for evaluator backends, command-graph nodes, and specialized algorithms.
References: modules/…/kernel.ts• L15-48 modules/…/kernel.ts• L123-145 modules/…/render-kernel.ts• L15-55 modules/…/render-kernel.ts• L162-212
Dynamic resources
Dynamic buffers and textures provide reusable resource bindings for data whose contents or size change between runs. They sit below the graph and kernel layers, which decide when a resource is read, written, or attached to a pass.
References: modules/…/dynamic-buffer.ts• L1-80 modules/…/dynamic-texture.ts• L1-90 modules/…/texture-binding-source.ts• L1-80 modules/…/index.ts• L125-160
Parallel operation families
The graph package exposes reusable operations that turn common data tasks into graph nodes. These operations accept graph data views or ordered vector chunks, validate their input and output contracts, and leave execution and submission to the containing command graph.
Prefix scans and segmented operations
GPUScan produces inclusive or exclusive prefix sums over packed unsigned values. It can use optional flags to restart the prefix within one logical input. Ordered vector chunks remain part of one scan, so a chunk boundary does not create a segment by itself.
GPUSegmentedScan and GPUSegmentedReduction use CSR-style segment offsets to process each segment independently. They support prefix sums or sum, minimum, and maximum reductions. These operations provide the basic grouping and offset work used by indexing, compaction, and other GPU data flows.
References: modules/…/gpu-scan.ts• L27-59 modules/…/gpu-scan.ts• L60-127 modules/…/gpu-segmented-scan.ts• L18-31 modules/…/gpu-segmented-reduction.ts• L21-38 modules/…/index.ts• L135-191
Spatial grids
GPUGridBinning maps finite two-dimensional positions into bounded row-major cells and writes the number of points per cell. GPUGridAggregation uses the same cell model to accumulate weighted sums, minimums, maximums, or means. Bounds may be fixed values or a GPU-resident row, which lets a later graph stage change the spatial domain without rebuilding the operation.
GPUGridIndex builds a cell-to-object layout for two- or three-dimensional positions. GPUGridIndexQuery then returns capacity-bounded candidate IDs for point, bounds, or radius selections. These are coarse candidates: exact geometry checks remain the responsibility of the next stage. Counts and overflow flags make capacity loss visible to the caller.
This flow shows how point data becomes a reusable spatial query result.
flowchart LR
A[Position chunks] --> B[Grid coordinates]
B --> C[Cell counts or aggregates]
C --> D[Offsets and object IDs]
D --> E[Point bounds or radius query]
E --> F[Candidate IDs and status]
References: modules/…/gpu-grid-coordinate.ts• L5-23 modules/…/gpu-grid-binning.ts• L32-60 modules/…/gpu-grid-aggregation.ts• L28-63 modules/…/gpu-grid-index-internals.ts• L26-52 modules/…/gpu-grid-index-query.ts• L25-63 modules/…/gpu-grid-index-query.ts• L116-130
Bounded dispatch
GPU operations use a shared dispatch planner that maps a linear workload into a three-dimensional WebGPU dispatch. The planner checks element limits and device workgroup limits before graph nodes are created, so large workloads fail as a clear planning error instead of silently addressing the wrong rows.
The same bound-aware indexing rule is shared by scans and spatial operations. This keeps chunked data and large flat arrays within device limits while preserving one logical row index for each invocation.
References: modules/…/gpu-dispatch-utils.ts• L8-52 modules/…/gpu-dispatch-utils.ts• L55-75 modules/…/gpu-scan.ts• L966-982 modules/…/gpu-grid-index-internals.ts• L276-287
Explicit command graphs
GPUCommandGraph is the explicit WebGPU execution model for multi-pass work. The caller declares imported resources, graph-owned transient resources, typed data views, and compute, render, or copy nodes. Compilation derives dependency order, resource hazards, transient lifetimes, and executable pass state; encoding and queue submission remain under caller control.
The compiler infers dependencies from declared resource access and explicit predecessor links. It orders conflicting work, reuses compatible transient allocations when lifetimes do not overlap, and rejects cycles or unsafe writable aliases. Compiled graphs also expose resource and workload preflight data before submission.
The compiled graph can be reused with new imported resources. A dry-run execution plan can divide dependency-ordered work by node, command, invocation, and byte budgets. The caller can choose interactive, normal, or background priority and can publish final or declared intermediate results.
This flow shows the separation between resource declaration, scheduling, and submission.
flowchart LR
A[Imported buffers and textures] --> B[Typed graph views]
B --> C[Compute render and copy nodes]
C --> D[Graph compilation]
D --> E[Hazards and transient lifetimes]
E --> F[Caller-controlled encoding]
F --> G[Queue submission]
G --> H[GPU-resident results]
References: modules/…/gpu-command-graph.ts• L670-698 modules/…/gpu-command-graph.ts• L917-1039 modules/…/gpu-command-graph.ts• L1402-1545 modules/…/gpu-command-graph-compiler.ts• L120-186 modules/…/gpu-command-graph-compiler.ts• L653-755
Graph resources and views
Graph handles name physical buffers and textures inside the graph. Data views describe typed ranges over those handles, while resource-use declarations tell the compiler which nodes read, write, copy, or attach each resource. Imported resources remain caller-owned; graph-owned transient resources are released with the compiled graph.
The graph can import fixed-width chunks from a GPUVector without packing them. This preserves source batching and lets specialized workflows operate on data that already belongs to another subsystem. Frame-scoped textures and sampled external images are supplied for one numbered encoding and remain owned by the caller.
References: modules/…/gpu-command-graph-types.ts• L145-225 modules/…/gpu-command-graph-types.ts• L285-364 modules/…/gpu-command-graph.ts• L700-841 modules/…/gpu-command-graph.ts• L843-915 modules/…/gpu-command-graph.ts• L1877-2031
Compute workflow families
The graph package applies the same data and execution model to common GPU workloads. The workflows below are product-level uses of the primitives rather than separate execution systems.
Data interchange and analysis
Arrow adapters convert columns, record batches, tables, matrices, temporal values, and GeoArrow values into GPUVector data and can provide explicit readback. Parquet and other parsing surfaces plan GPU decode and decompression while retaining CPU fallback plans when the input or device does not fit the GPU path.
Vector search imports embedding tables and supports similarity search, K-means, and IVF-Flat indexing. These workflows keep chunked data and bounded intermediate state on the GPU so search or analysis can be repeated without rebuilding the source representation.
| Family | Main result | Typical execution shape |
|---|---|---|
| Arrow and GeoArrow | GPU vectors and table batches | Conversion between column formats and GPU layouts |
| Parquet and compression | Decoded column values | Planned decode and decompression graph stages |
| Vector search | Scores, source IDs, labels, or an index | Bounded WebGPU passes over embedding chunks |
| Graph algorithms | Topology, degrees, paths, components, or layouts | Repeated graph passes over GPU-resident data |
References: modules/…/index.ts• L5-39 modules/…/index.ts• L176-203 modules/…/index.ts• L5-39 modules/…/index.ts• L6-27 modules/…/index.ts• L6-50
Geometry and point clouds
Geometry workflows derive mesh normals and smoothing results from graph data views. Point-cloud workflows support radius filtering, voxel downsampling, and sparse octree indexing. They use typed positions and indices as graph resources and write results to caller-provided views.
The octree workflow groups immutable positions by bounded Morton keys, then emits node records, point ranges, and a status record. The status makes rejected points and capacity overflow visible to the caller before the result is used.
References: modules/…/index.ts• L5-8 modules/…/gpu-mesh-normals.ts• L9-79 modules/…/index.ts• L5-10 modules/…/gpu-pointcloud-octree.ts• L14-86
Time-series summaries
GPUTimeSeriesEnvelope reduces a selected sample range into uniform bins. Each bin keeps minimum, maximum, first, and last values with their source IDs, plus valid and missing counts. The workflow resets and merges output vectors across source chunks, so the summary remains GPU-resident and preserves missing data.
References: modules/…/index.ts• L5-8 modules/…/gpu-time-series-envelope.ts• L13-68 modules/…/gpu-time-series-envelope.ts• L70-193
GPU physics
The physics surfaces provide experimental WebGPU worlds for sphere motion and bounded rigid-body simulation. They keep state, contact data, diagnostics, and optional event or query data in GPU resources and add their ordered work to a command graph.
The application owns the clock and submission boundary. It reads state, diagnostics, events, or queries only through explicit APIs. Capacity limits are part of the workflow contract, so dropped work or recovery decisions must be checked through the published status and diagnostic data.
References: modules/…/index.ts• L5-14 modules/…/index.ts• L40-118 modules/…/gpu-sphere-world.ts• L161-187 modules/…/gpu-rigid-body-world.ts• L71-127
Result handoff
Computation results are intended to remain luma.gl GPU data. A result can become an input to another evaluator, a graph view, a specialized workflow, or a rendering resource. CPU readback is an explicit boundary for inspection, control, or export rather than a required step between GPU operations.
Ownership follows the creator of storage. Evaluator-owned temporary buffers can be reclaimed after root evaluation, borrowed buffers remain with the caller, and compiled command graphs release only their transient resources. This contract lets independent systems share results without sharing destruction responsibility.
References: modules/…/clean-evaluate.ts• L25-65 modules/…/gpu-vector.ts• L323-420 modules/…/gpu-command-graph.ts• L1851-1875 modules/…/gpu-data-evaluator.ts• L724-735
Change checklist
When these files or sections are changed, remember to consider these:
- Keep evaluator row formats, vector metadata, backend handlers, and graph data views aligned when a data layout changes.
- Keep chunk order and chunk lengths aligned when changing vector transforms or graph imports.
- Register new operations in every backend that the public operation contract supports, and mark deferred handlers as scope-safe only when they record without submitting.
- Keep expression syntax, numeric format rules, output declarations, integer cast rounding, and expression kernel lowering aligned when changing
GPUExpressionOperation. - Keep resource-use declarations complete for every command-graph node. Missing write or read uses can change dependency order and transient allocation.
- Keep workload estimates and bounded dispatch layouts aligned when changing a migrated operation. A wrong estimate can break resumable scheduling even when direct execution works.
- Keep scan modes, segment flags, and CSR offset lengths aligned with the data written by downstream index and compaction operations.
- Keep grid bounds, cell dimensions, row-major output lengths, candidate capacities, and overflow status fields aligned across spatial operations.
- Keep kernel bindings and vertex layouts aligned with the shader interface when changing a compute or render primitive.
- Preserve ownership boundaries when a result is passed between evaluators, graph views, Arrow adapters, and rendering resources.
- Update package subpath exports when moving a former gpgpu facility into the graph package.
- Keep workflow status, diagnostics, and capacity contracts aligned with the buffers that specialized workflows write.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An operation has no handler for the selected device | Evaluation fails before a valid result is produced | Use a supported backend or register a matching handler |
| A deferred operation does not support evaluation scopes | Scoped evaluation is rejected instead of being submitted implicitly | Use immediate evaluation or a scope-safe WebGPU handler |
| Scoped data is read before submission | The caller can observe incomplete work | Keep scoped results inside the encoder until submit() |
| An expression uses unsupported syntax or a texture input | Compilation rejects the operation before execution | Keep expressions in the documented numeric subset and use numeric graph values |
| An expression uses incompatible row widths or numeric formats | Compilation rejects the expression or its output type | Use matching widths or scalar broadcast, and use explicit casts for arithmetic |
| A float-to-integer expression cast uses an unexpected rounding mode | Integer results differ from the caller's expected values | Select truncate or nearest explicitly when the result depends on rounding |
| Evaluator rows or vector chunks have incompatible layouts | The result cannot satisfy one vector format contract | Align type, component count, normalization, format, and byte layout |
| A scan output is shorter than its input or segment flags do not cover the input | The operation is rejected before graph nodes are added | Allocate output and flag views for the logical input length |
| Segment offsets do not describe the output segments | Segmented results can select the wrong ranges or produce invalid data | Keep offsets ordered, bounded, and one element longer than the segment output |
| Grid dimensions do not match the row-major output or candidate capacity | Grid work is rejected or query results set overflow and are incomplete | Size outputs from the cell count or candidate capacity and inspect status fields |
| A position or bound is non-finite or outside the spatial domain | The point is ignored or no query cell is selected | Validate finite inputs and ordered bounds before accepting results |
| A dispatch exceeds the device's three-dimensional workgroup limit | Planning fails instead of producing a complete workload | Split the operation into bounded chunks or use a device with larger limits |
| A graph node omits a resource use or writable resources alias | Hazard order or output data can be wrong | Declare every resource use and keep active writable handles distinct |
| A compiled graph is changed or used after destruction | New work is rejected or later encoding accesses released state | Finish declarations before compile and keep the compiled graph alive through encoding |
| A point-cloud output lacks capacity or contains out-of-bounds points | The octree status reports overflow or rejected points and output is not valid | Size output views correctly and inspect the status record |
| A physics workload exceeds bounded contact, pair, event, or device limits | Work is dropped, rejected, or recovered according to the selected policy | Run capacity checks and inspect diagnostics before accepting state |
| A caller destroys borrowed storage before graph work completes | Later GPU work reads released buffers | Keep caller-owned buffers alive until all commands and readback finish |
Key files
| File | Why to read it |
|---|---|
| modules/…/package.json | Current package entry points for graph, data, parsing, search, geometry, point-cloud, time-series, and physics surfaces |
| modules/…/index.ts | Top-level public exports for command graphs, kernels, data, and graph values |
| modules/…/index.ts | Public exports for migrated general-purpose GPU operations, grid workflows, command graphs, and execution helpers |
| modules/…/gpu-expression-operation.ts | Named numeric expression contract, supported expression language, and cast rounding choice |
| modules/…/index.ts | Lazy evaluators, evaluation scopes, common operations, backend registration, and cleanup exports |
| modules/…/operation.ts | Operation dependency and backend selection contract |
| modules/…/gpu-data-evaluator.ts | Lazy fixed-width data model, materialization, target storage, readback, and ownership |
| modules/…/gpu-vector-evaluator.ts | Chunk-preserving vector transforms and materialization |
| modules/…/gpu-vector.ts | Vector formats, chunks, layouts, appendable data, and ownership |
| modules/…/kernel.ts | Reusable WebGPU dispatch primitive |
| modules/…/render-kernel.ts | Reusable WebGL and WebGPU draw primitive |
| modules/…/gpu-command-graph.ts | Explicit resource declaration, compilation, encoding, bounded execution, and cleanup |
| modules/…/gpu-command-graph-types.ts | Logical resource handles, typed views, node contracts, conditions, workload estimates, and preflight reports |
| modules/…/gpu-command-graph-compiler.ts | Dependency ordering, transient resource reuse, resource summaries, and compile-time checks |
| modules/…/gpu-dispatch-utils.ts | Shared bounded dispatch and linear invocation rules |
| modules/…/gpu-scan.ts | General prefix scans over packed and chunked GPU data |
| modules/…/gpu-segmented-scan.ts | Independent prefix scans over CSR-style segments |
| modules/…/gpu-segmented-reduction.ts | Independent sum, minimum, and maximum reductions over CSR-style segments |
| modules/…/gpu-grid-binning.ts | Spatial cell counts from two-dimensional positions |
| modules/…/gpu-grid-aggregation.ts | Weighted spatial cell statistics |
| modules/…/gpu-grid-index-query.ts | Coarse point, bounds, and radius candidate queries over a grid index |
| modules/…/gpu-grid-coordinate.ts | Shared coordinate mapping used by grid operations |
| modules/…/index.ts | Arrow, GeoArrow, and GPU vector interchange surface |
| modules/…/index.ts | GPU decode and decompression planning and execution surface |
| modules/…/index.ts | Embedding import, similarity search, clustering, and IVF-Flat surface |
| modules/…/gpu-mesh-normals.ts | Example graph workflow for indexed mesh processing |
| modules/…/gpu-pointcloud-octree.ts | Example bounded spatial index workflow and status contract |
| modules/…/gpu-time-series-envelope.ts | Chunk-aware GPU time-series summary workflow |
| modules/…/index.ts | Public sphere and rigid-body simulation, diagnostics, events, queries, and recovery surface |