Experimental GPU workflows
The experimental workflows in the graph package provide GPU-first data models and simulations for paths, polygons, flow fields, particles, fluids, and scientific trajectories. They keep large state near the GPU so applications can connect data preparation, simulation, and rendering without a required particle or geometry readback. The APIs are experimental and may change or be removed. This page complements the parent GPU graph systems page and the related GPU physics and engine render loop pages.
Experimental scope
Graph package boundary
The graph package exposes the experimental GPU data contracts and simulation inputs through one focused entry point. Its model surface prepares path and polygon data for GPU use. Its simulation surface covers tiled flow fields, visual particle advection, MLS-MPM fluids, and scientific flow tracing. Path rendering is now part of the engine graph model layer. The engine consumes the prepared path state from the graph package.
References: modules/…/index.ts• L5-63 modules/…/index.ts• L5-31 modules/…/index.ts• L5-50 modules/…/path-attribute-model.ts• L147-188
These workflows share GPU resources and command-graph scheduling, but they do not form one required pipeline. An application can use a model for rendering, a simulation for GPU state, or both together. The application still controls when commands are submitted and when borrowed resources are released, except for self-submitting steps such as visual flow particle advancement.
References: modules/…/scientific-flow-graph.ts• L114-141 modules/…/mls-mpm-fluid-simulation.ts• L388-445 modules/…/flow-particle-simulation.ts• L54-57 modules/…/flow-particle-simulation.ts• L217-239
GPU model workflows
Path models
Path workflows turn variable-length path rows into renderable segments. The graph package prepares GPU path inputs and expansion state. The engine's PathAttributeModel consumes that prepared state together with a GPU table and draws the resulting segments. This split lets path preparation and path rendering integrate without moving the generated geometry back to the CPU.
The workflow preserves source row identity and optional style or time data as paths become segments. Storage-backed inputs keep each source batch's offsets and bindings together. Row-level colors and widths must stay aligned with path rows. Vertex-level colors and timestamps must follow the same variable-length offsets as the path vertices.
References: modules/…/index.ts• L5-24 modules/…/index.ts• L5-20 modules/…/path-storage-gpu-inputs.ts• L11-20 modules/…/path-storage-gpu-inputs.ts• L30-59 modules/…/path-storage-gpu-inputs.ts• L134-193 modules/…/path-attribute-model.ts• L109-177 modules/…/path-attribute-model.ts• L187-216
Polygon models
Polygon models render filled polygon batches from prepared GPU positions and indices. Attribute-backed and storage-backed forms support the same broad rendering workflow while allowing data to arrive in different GPU layouts.
Polygon batches retain source row identity and optional color data for interaction and styling. The generated contract also carries vertex row indices and triangle indices. A model validates row counts and keeps positions, colors, and row indices aligned at every vertex.
References: modules/…/index.ts• L18-24 modules/…/index.ts• L22-31 modules/…/polygon-gpu-inputs.ts• L11-71 modules/…/polygon-gpu-inputs.ts• L73-102
Flow field workflows
Flow field atlas
The flow field atlas stores a regular velocity grid in a fixed-capacity GPU texture. Applications can update or clear tiles in place, then let particle simulations observe the next complete field snapshot without reallocating the grid.
The field contract keeps bounds, coordinate type, velocity units, and validity together. Missing samples remain invalid, and interpolation rejects a cell when any required sample is missing. The application owns tile timing, loading order, and eviction.
References: modules/…/flow-field-atlas.ts• L1-120 modules/…/flow-particle-field.ts• L7-20 modules/…/README.md• L58-99
Flow particle simulation
Flow particle simulation advects a fixed-capacity particle set through a borrowed velocity field. It keeps current and previous particle textures on the GPU so a renderer can draw motion trails without reading particle positions back to JavaScript.
The simulation supports Cartesian and longitude/latitude domains. It uses bounded midpoint steps, deterministic respawning, and explicit validity checks. Long frame gaps are capped and reported instead of causing one large jump. A zero-time step pauses without changing the state. A normal step submits its own GPU work, while the application remains responsible for keeping the borrowed field valid and consuming the returned textures before the next reuse.
References: modules/…/index.ts• L26-32 modules/…/flow-particle-simulation.ts• L15-57 modules/…/flow-particle-simulation.ts• L168-247 modules/…/README.md• L24-56
Fluid simulation workflows
MLS-MPM fluid simulation
MLS-MPM fluid simulation models a two-dimensional weakly compressible fluid from particles and a shared grid. It supports seeded or explicit particles, gravity, pressure-like stiffness, damping, and an optional local force. The updated particle buffer can feed a storage-backed renderer or another GPU pass.
Each encoded interval uses safe numerical substeps. Every substep follows the same high-level cycle:
- Clear the fluid grid.
- Transfer particle state to the grid.
- Update grid motion and material response.
- Transfer the result back to the particle state.
The simulation records this work into a caller-owned command encoder. It does not submit the commands itself, so the fluid step can join a larger GPU workflow.
References: modules/…/mls-mpm-fluid-simulation.ts• L201-210 modules/…/mls-mpm-fluid-simulation.ts• L388-445 modules/…/mls-mpm-fluid-simulation.ts• L489-577
Scientific flow workflows
Scientific vector fields
Scientific vector fields adapt regular grid data into a GPU-resident velocity field. The input keeps valid samples distinct from missing samples, and geographic metadata can define the bounds when the field uses longitude and latitude.
The field is a two-dimensional collocated grid. It supports Cartesian or geographic coordinates and optional periodic longitude. It does not provide a fluid solver, three-dimensional transport, or adaptive error control by itself.
References: modules/…/scientific-flow-field.ts• L8-36 modules/…/scientific-flow-field.ts• L41-117 modules/…/SCIENTIFIC-FLOW.md• L20-39
Scientific flow graph
The scientific flow graph provides fixed-step particle advection over a steady field or a pair of time-adjacent fields. It samples the field in space and uses RK2 or RK4 integration to produce current and previous particle buffers for direct rendering. Its compute path requires WebGPU and keeps particle state in storage buffers.
For time-varying fields, the application advances within the resident snapshot interval and rotates to the next snapshot at the endpoint. The graph does not fetch, extrapolate, or loop field data. It bounds each step by field cell speed and a fixed time limit. This keeps time ownership with the application and makes snapshot changes explicit.
References: modules/…/scientific-flow-graph.ts• L14-30 modules/…/scientific-flow-graph.ts• L114-186 modules/…/scientific-flow-compute.ts• L72-105 modules/…/scientific-flow-compute.ts• L158-218 modules/…/SCIENTIFIC-FLOW.md• L41-89
Scientific flow tracer
The scientific flow tracer provides adaptive forward tracing for cases where a fixed step is not enough. Each particle tracks its own progress and reports whether it is active, expired, outside the domain, blocked by missing data, or stopped by tolerance or numerical limits.
The tracer processes one bounded dispatch at a time. A request can remain pending when particles need more work, and the caller continues that same request before starting another horizon. Particle positions stay in GPU buffers. Readback returns trace counts, work results, and optional GPU timing rather than the full particle set. Adaptive tracing requires WebGPU.
The following diagram shows how both scientific workflows turn field data into renderable state, with adaptive tracing adding per-particle diagnostics.
flowchart LR
A[Regular vector field] --> B[GPU velocity field]
B --> C[Bilinear sampling]
C --> D[Fixed-step RK2 or RK4]
D --> E[GPU particle buffers]
B --> F[Adaptive forward tracing]
F --> G[GPU particles and diagnostics]
E --> H[Renderer]
G --> H
References: modules/…/scientific-flow-tracer.ts• L19-75 modules/…/scientific-flow-tracer.ts• L105-142 modules/…/scientific-flow-tracer.ts• L242-283 modules/…/scientific-flow-tracer.ts• L394-481 modules/…/SCIENTIFIC-FLOW.md• L92-119
Workflow composition
GPU data-to-visual flow
The workflows form a simple data-to-visual path. Application data becomes a GPU field, geometry, or particle state. A model or simulation transforms that state, and a renderer consumes the result without requiring a CPU copy.
flowchart LR
A[Application data] --> B[GPU field, geometry, or state]
B --> C[Graph path or polygon preparation]
C --> D[Engine path rendering]
B --> E[Flow or fluid simulation]
E --> F[GPU particle state]
D --> G[Rendered result]
F --> G
The key boundary is ownership. The graph package prepares input and simulation resources. The engine path model consumes prepared path state for rendering. Borrowed fields, command encoders, and output textures or buffers remain under application control. Some workflows submit their own steps, while others record work for the caller. The application must submit recorded work before rotating snapshots, advancing reused state, or releasing resources used by that work.
References: modules/…/index.ts• L5-63 modules/…/index.ts• L5-31 modules/…/path-attribute-model.ts• L205-216 modules/…/flow-particle-simulation.ts• L54-57 modules/…/scientific-flow-graph.ts• L128-141 modules/…/mls-mpm-fluid-simulation.ts• L388-445
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the graph experimental exports and the engine path model contract aligned.
- Preserve the distinction between graph-prepared path state and engine-owned rendering behavior.
- Preserve the distinction between caller-owned field resources and simulation-owned state resources.
- Keep path ranges, source row identity, style streams, timestamps, and generated segment data aligned.
- Keep polygon positions, row indices, triangle indices, vertex counts, row identity, and color mode aligned across batches.
- Keep flow bounds, coordinate type, units, validity values, and tile sample layout consistent.
- Keep particle state texture or buffer reuse rules aligned with render timing and the next simulation step.
- Keep fluid stage order, particle ping-pong state, stable substep limits, and command submission ownership aligned.
- Keep scientific snapshot dimensions, bounds, coordinate type, endpoint rules, and time intervals compatible.
- Keep fixed-step integration limits separate from adaptive tracer tolerance, pending requests, and stop-status behavior.
- Keep WebGPU and floating-point render-target support checks aligned with the advertised workflow.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The graph path preparation state and engine path table describe different rows or batches | Rendering can map visible segments to the wrong source data or fail during drawing | Keep prepared path rows, generated batches, and the engine table aligned |
| Path timestamps or vertex colors use offsets that differ from path vertices | Time or style data can attach to the wrong segment | Copy and preserve the same variable-length offsets for each vertex-aligned stream |
| A caller releases a borrowed field before simulation work finishes | The next step can sample destroyed or changed GPU data | Keep the field alive until submitted work completes, then destroy the simulation before its borrowed field |
| A flow tile uses the wrong lattice bounds or duplicates a border sample | Interpolation crosses the wrong location or leaves tile seams invalid | Use whole-grid sample bounds and one shared regular lattice |
| A field contains missing or non-finite velocity data | Particles can stop, respawn, or become invalid at the affected cell | Mark missing samples invalid and upload finite velocity values only |
| A caller uses particle output after the next reused step | Rendering can read overwritten state or lose the intended previous frame | Consume current and previous state before the next step or reset |
| A fluid encode exceeds the safe substep budget or device buffer limits | Encoding fails instead of producing a stable fluid update | Check support and reduce the interval or solver size |
| A temporal scientific field pair has different grid or coordinate metadata | Snapshot rotation or advection is rejected | Keep both snapshots compatible and rotate only at the interval endpoint |
| A scientific tracer request remains pending but the caller starts another request | The tracer rejects the request and its per-particle progress is not advanced | Call continue() until the current horizon completes |
| A scientific workflow runs without WebGPU support | Compute or adaptive tracing cannot start | Check the device type before selecting the scientific workflow |
| A path or polygon batch loses source alignment | Rendering or picking maps visible data to the wrong source row | Preserve offsets, indices, row IDs, and vertex-aligned attributes together |
Key files
| File | Why to read it |
|---|---|
| modules/…/index.ts | Shows the graph package experimental entry point and public workflow surface |
| modules/…/index.ts | Shows the graph package path and polygon GPU input surface |
| modules/…/path-attribute-model.ts | Shows how the engine consumes prepared path state for rendering |
| modules/…/path-storage-gpu-inputs.ts | Explains storage-backed path batches and alignment rules |
| modules/…/polygon-gpu-inputs.ts | Defines the generated polygon batch contract and alignment checks |
| modules/…/polygon-storage-model.ts | Explains storage-backed polygon batches and rendering |
| modules/…/index.ts | Shows the public flow, fluid, and scientific simulation surface |
| modules/…/README.md | Defines the flow field and visual particle workflow |
| modules/…/flow-field-atlas.ts | Defines tiled GPU field updates |
| modules/…/flow-particle-simulation.ts | Defines GPU particle advection, self-submitting steps, and state reuse |
| modules/…/mls-mpm-fluid-simulation.ts | Defines the fluid workflow and its four-stage update cycle |
| modules/…/scientific-flow-graph.ts | Defines fixed-step scientific advection and snapshot flow |
| modules/…/scientific-flow-compute.ts | Defines the WebGPU compute path, bounded steps, and particle buffers |
| modules/…/scientific-flow-tracer.ts | Defines adaptive tracing, continuation, and diagnostic outcomes |
| modules/…/SCIENTIFIC-FLOW.md | Gives the scientific field and time-dependent workflow contract |