Skip to content

Bindings

Bindings are the resources a kernel can access.

const node = v.pass(kernel, {
input,
output,
multiplier
});

The object keys become WGSL variable names. If the shader uses input, the bindings object must contain input.

fn main(gid: vec3u) {
output[gid.x] = input[gid.x] * multiplier;
}

Bindings can be:

ValueUse
BufferPacked storage-buffer data
RawBufferUser-packed storage-buffer data
UniformSmall configuration values
HandleA buffer handle from a previous v.pass()

Plain numbers, strings, and objects are not bindings. Wrap scalar configuration values in Uniform.

const multiplier = new Uniform(2, 'f32');
const node = v.pass(kernel, { input, output, multiplier });

Every buffer-like binding on a node gets a handle. You can pass that handle into another node.

const A = v.pass(doubleKernel, { input, output: mid });
const B = v.pass(offsetKernel, { input: A.output, output: result });

Volten records the dependency, so running B also runs A first.

v.run(B);

Volten generates WGSL declarations from the binding values.

const input = new Buffer([1, 2, 3, 4], 'f32', 'r');
const output = new Buffer([0, 0, 0, 0], 'f32', 'rw');
const multiplier = new Uniform(2, 'f32');

Equivalent generated declarations:

@group(0) @binding(0) var<storage, read> input: array<f32>;
@group(0) @binding(1) var<storage, read_write> output: array<f32>;
@group(0) @binding(2) var<uniform> multiplier: f32;