Introducing a new way to review your PRs.

Read the announcement

visgl / luma.gl

High-performance Toolkit for WebGL-based Data Visualization

View on GitHub

30 documents · Updated Nov 20, 2026

docs / gpu-simple-graph

GPU Simple Graph workflows

GPU Simple Graph provides a small graph interface for composing GPU-resident values and operations. It supports lazy value recipes, existing evaluator adapters, explicit transfers, and a declarative expression path that lowers into the shared GPU evaluator system. Most graph work stays on the GPU, while graphs with supported CPU operations cross between GPU and CPU stages as part of execution. See gpu-graph-systems, gpu-graph-workflows, and gpu-compute-and-effects for related systems.

Workflow model

The subsystem separates graph description from GPU work. A graph records named values or operations first. Compilation then selects outputs and builds an execution plan. A later run evaluates the selected roots and keeps the results in GPU storage.

The main workflow is:

  1. Create a graph for a device or for declarative graph expressions.
  2. Add values, operations, transfers, supported semantic graph operations, or render passes.
  3. Select named outputs and compile the graph.
  4. Inspect the operation tree or dependency nodes if needed.
  5. Run the compiled graph to materialize GPU vectors and encode any render work.
  6. Invalidate changed graph-owned inputs before a later run when their cached results are stale.
  7. Destroy the compiled graph after all consumers release its results.

The graph builder freezes after compilation. Compilation itself does not dispatch GPU work. It captures the selected roots and the reachable dependency plan so later runs can reuse evaluator state. Render work is kept after evaluator work and can share the caller's command submission on WebGPU.

References: modules/…/gpu-simple-graph.ts• L74-105 modules/…/gpu-simple-graph.ts• L166-243 modules/…/gpu-simple-graph.ts• L274-414 modules/…/gpu-simple-graph.ts• L455-487

Graph values

GPUSimpleGraphValue is a lightweight recipe rather than a GPU allocation. It represents an upload, a numeric constant, borrowed GPU data, or a mapped operation whose inputs are other graph values. The recipe can be reused across compilations because each compilation creates its own evaluator state.

The simpleGraphOperations surface gives graph authors common operations without exposing evaluator construction. It covers arithmetic, vector layout, selection, casts, color conversion, sequences, gathers, and related data transforms. addValue gives a recipe a name that can be selected as an output.

References: modules/…/gpu-simple-graph-value.ts• L39-65 modules/…/gpu-simple-graph-value.ts• L80-127 modules/…/gpu-simple-graph-value.ts• L129-186

Operation adapters

The operation layer lets Simple Graph use the shared evaluator system without taking ownership of caller-owned inputs. GPUSimpleGraphOperation names an existing data or vector evaluator and exposes enough metadata for graph inspection. This is the compatibility path for workflows that already build lazy evaluator expressions.

The evaluator model has two levels. A GPUDataEvaluator describes one logical data chunk and materializes it only when a run needs it. A GPUVectorEvaluator groups ordered chunk evaluators into one logical vector while preserving chunk boundaries. Value operations own evaluator trees created during lowering. Explicit evaluator wrappers and caller-provided GPU data remain borrowed. Evaluators can also write deferred operation results into caller-provided target buffers when the target layout is valid; owned temporary buffers are reused through the evaluator buffer pool.

References: modules/…/gpu-simple-graph-operation.ts• L11-49 modules/…/gpu-data-evaluator.ts• L104-176 modules/…/gpu-data-evaluator.ts• L409-521 modules/…/gpu-data-evaluator.ts• L725-757 modules/…/gpu-vector-evaluator.ts• L43-55 modules/…/gpu-vector-evaluator.ts• L147-213

Transfer operations

Transfer operations make data movement part of the graph plan. An upload borrows CPU data until execution and then writes it into the planned GPU chunks. A copy creates independent GPU storage from a named value and preserves vector chunk boundaries.

Copies do not read data back to the CPU. They can use a shared evaluation scope, which lets their GPU commands join other work before the caller submits or cancels that scope. Selected outputs can also copy into caller-provided GPU targets when the target count matches the result chunks. The same transfer path handles packed and strided rows so the logical vector shape stays unchanged.

References: modules/…/gpu-simple-graph-transfer.ts• L14-69 modules/…/gpu-transfer-execution.ts• L10-73 modules/…/gpu-simple-graph.ts• L64-75 modules/…/gpu-simple-graph.ts• L323-337

Semantic expression path

Simple Graph also accepts the shared GPUGraph semantic operations for a small declarative subset. This path is intended for expressions that describe scalar values and vector math by logical value IDs. It supports float32 scalar literals and scalar copy, add, subtract, multiply, divide, and sqrt, plus float32 vector multiply-add.

The path accepts chains, branches, nested unconditional groups, and multiple selected outputs. It rejects state execution, conditional or loop composites, unsupported semantic operations, repeated writes, and shape or format mismatches. Semantic operation IDs label operations and may repeat. Logical value IDs and explicit evaluator output IDs remain distinct namespaces with stricter uniqueness rules for explicit outputs.

The expression path also supports texture-copy and shader-pass programs on WebGPU. A caller can prepare these programs for command encoding without immediate submission. Other expression runs resolve bindings, execute uploads and copies, evaluate expressions, and return the selected GPU values. Supported CPU operations use a staged path: the graph reads their inputs to the CPU, invokes the operation, uploads its results, and continues with later GPU stages. This path is limited to numeric values without textures or state.

The following diagram shows how a declarative expression moves through the Simple Graph evaluator path.

flowchart LR
  A[Semantic graph values] --> B[Expression plan]
  B --> C[GPU evaluator operations]
  C --> D[GPU vector or texture targets]
  D --> E[GPU execution]
  E --> F[GPU outputs]

References: modules/…/gpu-simple-graph.ts• L107-145 modules/…/gpu-simple-graph.ts• L274-305 modules/…/compiled-gpu-expression-graph.ts• L47-105 modules/…/compiled-gpu-expression-graph.ts• L107-161 modules/…/compiled-gpu-expression-graph.ts• L163-225

Lowering path

Lowering converts graph meaning into the shared lazy evaluator model. SimpleGraphLowering resolves graph values once per compilation, binds external GPU vectors, creates evaluator adapters for semantic operations, and records the resources that the compiled graph owns. Shared graph values therefore remain shared dependencies instead of producing duplicate evaluator trees.

The lowering path preserves physical vector chunks. External bindings must match the declared format, total length, and optional chunk lengths. It does not silently repack data or create temporary storage for unsupported shapes. The semantic subset uses float32 single-assignment values and keeps scalar operations as GPU evaluator stages. Vector multiply-add applies the same scale and add operation to matching chunks.

The expression compiler uses the same evaluator operations while adding GPU expression handling for casts, row operations, and arithmetic that keeps float32 behavior on the GPU. When a graph contains a CPU operation, the expression plan becomes a sequence of numeric stages. GPU stages pass vectors forward, while CPU stages read inputs, run the callback, and upload checked results for the next stage.

References: modules/…/gpu-simple-graph-lowering.ts• L29-48 modules/…/gpu-simple-graph-lowering.ts• L50-114 modules/…/gpu-simple-graph-lowering.ts• L117-170 modules/…/gpu-simple-graph-lowering.ts• L203-229 modules/…/compiled-gpu-expression-graph.ts• L201-433

Execution and ownership

CompiledGPUSimpleGraph evaluates selected roots in dependency order and returns GPU vectors. It evaluates a shared dependency once per run. On WebGPU, a GPUEvaluationScope can defer submission and combine evaluator and render commands on the same device. On WebGL, runSync evaluates the graph and submits render work without CPU readback.

Ownership follows the lowering boundary:

  • Semantic lowering owns the evaluator adapters and derived results that it creates.
  • Explicit evaluator wrappers and input GPU data remain borrowed.
  • destroy() releases owned semantic resources after execution and consumers finish.
  • invalidate() clears changed graph-owned inputs and their owned consumers without touching borrowed evaluator caches.
  • A compiled graph cannot run concurrently with itself or be destroyed during a run.
  • A run with a scope requires an idle scope for the graph's device. The graph remains leased until that scope is submitted or cancelled.

The expression path creates temporary evaluator objects during a run and releases them when the run ends. It keeps scalar arithmetic on the GPU. A declared CPU operation is an explicit stage rather than a fallback: its inputs are read to the CPU and its numeric results are uploaded before the next stage. Texture preparation exposes command encoding for the supported copy and shader-pass cases while leaving submission and cleanup to the caller.

References: modules/…/gpu-simple-graph.ts• L418-497 modules/…/gpu-simple-graph.ts• L499-585 modules/…/gpu-data-evaluator.ts• L409-521 modules/…/gpu-data-evaluator.ts• L725-757 modules/…/gpu-vector-evaluator.ts• L246-263 modules/…/compiled-gpu-expression-graph.ts• L107-161 modules/…/compiled-gpu-expression-graph.ts• L437-456

Color conversion operations

Color conversion is a fixed-width operation that expands RGB or RGBA input rows into RGBA output rows. It accepts uint8, float16, and float32 RGB or RGBA input and produces normalized RGBA8, binary16 RGBA, or binary32 RGBA output. Missing alpha is set to one, and the default output is normalized RGBA8.

The operation keeps the same graph contract across backends. The CPU handler reads the source row layout and writes the converted bytes. The WebGPU handler encodes a compute pass that reads packed or strided rows and writes the selected output format. WebGL uses the CPU handler. The format choice therefore stays independent of the device path.

References: modules/…/convert-colors.ts• L13-75 modules/…/convert-colors.ts• L10-38 modules/…/convert-colors.ts• L13-66 modules/…/color-conversion.ts• L11-51 modules/…/color-conversion.ts• L93-138

Public interface

The public entry point exposes the graph builder, compiled graph types, value recipes, mapped operations, evaluator adapters, transfer operations, scopes, evaluators, inspection helpers, and the former GPGPU operations now absorbed under the graph package. New code should use graph values for declarative composition and evaluator adapters when it must reuse an existing lazy expression.

The public surface keeps the old operation and backend behavior available while placing the subsystem under @luma.gl/graph/gpu-simple-graph. The former standalone GPGPU operation location is no longer the system boundary. Its operation, evaluator, backend, and utility roles now support GPU Simple Graph.

References: modules/…/index.ts• L5-45 modules/…/index.ts• L47-100 modules/…/index.ts• L101-110 modules/…/convert-colors.ts• L67-75

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep graph value recipes, mapped operation signatures, and public exports aligned.
  • Preserve the separate rules for semantic value IDs and explicit evaluator output IDs.
  • Keep lowering ownership distinct from borrowed evaluator and buffer ownership.
  • Check vector chunk counts, lengths, formats, and output-target mapping when transfer or vector behavior changes.
  • Check that expression support and semantic lowering reject unsupported state, control flow, and operation kinds consistently.
  • Preserve device matching and scope leasing when execution, preparation, invalidation, or copy behavior changes.
  • Keep CPU-stage input reads, result shape checks, and uploads aligned when CPU operations are added or changed.
  • Keep render operations after evaluator operations and preserve their parameter contract when graph composition changes.
  • Keep color input and output format rules aligned across the shared contract and CPU, WebGPU, and WebGL handlers.

Important failure modes

TriggerConsequenceGuard
Add work after compilationThe builder rejects the change and cannot be reused for rebuilding.Finish graph construction before compile; create a new graph after a failed compile.
Select an unregistered output or copy inputCompilation fails before GPU execution.Register named outputs and copy sources before selecting or consuming them.
Bind an external vector with a wrong format, length, or chunk partitionLowering rejects the graph because the evaluator cannot safely represent the input.Match the declared semantic vector to the supplied GPU chunks.
Use an unsupported semantic operation, state value, or control-flow groupThe expression or graph path rejects the program.Limit semantic execution to the supported expression subset and unconditional groups.
Use a CPU operation with textures, state, or output targetsCompilation or execution rejects the CPU-stage graph because this path supports numeric stages only and cannot prepare CPU results into caller-owned targets.Keep CPU stages numeric and use ordinary run results for their outputs.
Prepare a non-WebGPU or unsupported expression programPreparation is rejected because the command-encoding path only supports WebGPU texture-copy and shader-pass programs.Use prepare only for those supported WebGPU cases.
Supply the wrong number of output target chunksCompilation fails rather than writing incomplete output storage.Provide one target for each selected vector chunk on the same device.
Provide a target buffer that is too small for a deferred evaluator outputEvaluation rejects the target before writing into caller-owned storage.Match the target buffer size, byte offset, byte stride, and result layout.
Use an unsupported color input formatColor conversion rejects the operation before execution.Use fixed-width uint8, float16, or float32 RGB or RGBA input.
Run with a scope from another device or with a non-idle graphEvaluation is rejected and scoped work may be cancelled on failure.Use one idle scope for the graph device and serialize runs.
Change a named graph-owned input without invalidating itA later run can return cached results based on the old input.Call invalidate() for changed named inputs before evaluation.
Destroy a graph while it runs or while its scoped work is pendingCleanup is rejected or would race with active evaluator resources.Finish or cancel the run before destroy().
Add evaluator work after a render operationThe graph rejects the operation instead of silently changing authored order.Add all evaluator work before render work.

Key files

FileWhy to read it
modules/…/README.mdGives the supported value, semantic expression, lifecycle, and capability model.
modules/…/gpu-simple-graph.tsDefines graph construction, compilation, inspection, invalidation, execution, render ordering, and ownership.
modules/…/gpu-simple-graph-value.tsDefines lightweight values and the mapped operation vocabulary.
modules/…/gpu-simple-graph-lowering.tsShows how values, transfers, bindings, and semantic operations become evaluators.
modules/…/gpu-data-evaluator.tsDefines lazy single-chunk values, target storage, scopes, readback, invalidation, buffer reuse, and ownership.
modules/…/gpu-vector-evaluator.tsDefines chunk-preserving vector evaluation and per-chunk transforms.
modules/…/gpu-simple-graph-transfer.tsDefines upload and GPU-to-GPU copy operation descriptions.
modules/…/gpu-transfer-execution.tsDefines how upload and copy operations move data into GPU storage during execution.
modules/…/compiled-gpu-expression-graph.tsShows the declarative expression, texture preparation, shader-pass, transfer, CPU-stage, and GPU result paths.
modules/…/gpu-cpu-operation.tsDefines the numeric CPU operation contract that can participate in a graph.
modules/…/gpu-cpu-execution.tsShows how CPU and GPU stages exchange values and preserve declared shapes.
modules/…/convert-colors.tsDefines the shared color conversion operation and supported formats.
modules/…/convert-colors.tsDefines CPU color conversion over source offsets and strides.
modules/…/convert-colors.tsDefines WebGPU color conversion and deferred command encoding.
modules/…/color-conversion.tsDefines device-independent color format selection and CPU conversion rules.
modules/…/index.tsDefines the public package surface after the former GPGPU operation system moved here.