<sk-compute-node>

← prev index next →

Runs your own WGSL compute shader on the GPU to generate data — vertex positions, particle state, a simulation step — that the rest of the scene reads.

Remarks

The compute node is the concrete member of the AbstractComputeNodecompute-and-custom-WGSL family: it runs its own compute dispatch on the GPU timeline — its own command buffer, possibly multi-step (steps-per-frame) and stateful / self-re-arming (continuous) — decoupled from any consumer. Consumers read its TYPED outputs by key (output.0 …) via a compute-node="#id" reference on a compute-buffer-* source.

The element owns the binding ABI (group 0): the record-typed output storage array, the 32-byte params uniform (time/progress/output_size/output_count/output_stride), and the packed named-uniform block (<sk-wgsl-uniform> children, read via the generated skUniform_<name>() accessors). The author supplies ONLY the @compute @workgroup_size(…) fn main kernel — declaring bindings in author WGSL is a validation error.

Outputs are slices of one shared buffer, padded so each slice starts on a 256-byte boundary (minStorageBufferOffsetAlignment); records for output i live at [i * output_stride, i * output_stride + output_size).

A kernel writes its OWN slice through output (invocation-owned, so race-free), but reads any SIBLING slice through previous — a per-step snapshot of output the scaffold also binds at group 0. Cross-slice reads through output race the sibling invocation's own write and are undefined per the WGSL spec; previous holds the committed previous-step state, so a neighbour-reading continuous sim (e.g. n-body) evolves deterministically regardless of GPU invocation order.

Serve these docs to run the live example. WebGPU needs a secure context — open this page via grunt serve rather than double-clicking the file. The Markup tab works from disk.

Attributes

AttributeTypeDefaultDescription
id <id> The element's unique identifier — the standard HTML global id attribute.
draggable <boolean> false Gets whether this node can be dragged.
wgsl <string> "" The author compute kernel: a `@compute
src <string> URL of an external .wgsl file providing the kernel, mirroring
output-kind <compute-output-kind> ("spline-polyline" | "point-matrices" | "color-array" | "color-stops") "spline-polyline" The typed output contract.
output-count <number> 1 Number of typed outputs the node produces (computed-property keys
output-size <number> 1 Records per output (e.g. vertices per polyline).
steps-per-frame <number> 1 Compute dispatches per frame (sub-steps).
continuous <boolean> false Whether the node re-arms itself every frame (a continuous, stateful
progress <number> 0 Animatable progress value (0 to 1).

Event handler attributes

Standard DOM event-handler content attributes — the value is JavaScript run when the event fires. They behave exactly as on any HTML element.

onclick, ondblclick, onauxclick, oncontextmenu, onpointerdown, onpointerup, onpointermove, onpointercancel, onpointerover, onpointerout, onpointerenter, onpointerleave, ongotpointercapture, onlostpointercapture, onwheel, ondragstart, ondrag, ondragenter, ondragover, ondragleave, ondrop, ondragend, onload, onerror