Files
yawn/docs/guide/compute.md
T
Ampandheaust 9768765d74 Replace addons with conventional handles
Provide the single-loadout Scene API, SAB-backed meshes, cameras, materials, lights, workers, post effects, and tutorial playgrounds. Batch matching row growth so active GPU loadouts refresh once.

Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae
Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
2026-08-20 06:39:30 +00:00

1.3 KiB

Compute passes

Compute shaders are graph data, not core code. Declare the shared rows/resources a shader needs and attach the pass to Scene.

const velocity = await scene.ensureRows("velocity", 4096, 16, "f32");

const simulation = new ComputePass({
  id: "integrate",
  code: `
    @group(0) @binding(0)
    var<storage, read_write> velocity: array<vec4<f32>>;

    @compute @workgroup_size(64)
    fn main(@builtin(global_invocation_id) id: vec3<u32>) {
      if (id.x < arrayLength(&velocity)) {
        velocity[id.x].y -= 0.001;
      }
    }
  `,
  buffers: [{ id: "velocity", array: "velocity", usage: ["storage"] }],
  bindings: [{ group: 0, binding: 0, resource: "velocity" }],
  dispatch: [64, 1, 1],
});

await scene.addComputePass(simulation);

The graph DAG places an unqualified custom compute pass after light clustering and makes forward rendering depend on all custom compute passes. Use after to specify other dependencies.

await simulation.update({ dispatch: [128, 1, 1] });
await scene.removeComputePass(simulation);

Both operations are infrequent graph/loadout messages. Existing source row changes are direct SAB writes.

<script setup> import Playground from "../.vitepress/Playground.vue"; </script>