Skip to content

Outputs

Kernel outputs tell Volten which bindings should be returned when you read a primitive kernel node.

const doubleValues = kernel({
shader: `
fn main(gid: vec3u) {
result[gid.x] = input[gid.x] * 2.0;
}
`,
outputs: ['result']
});

Then read the node:

const node = doubleValues({ input, result });
v.run(node);
const output = await v.read(node);
// { result: Float32Array [...] }

The simplest form is an array of binding names.

const computeResults = kernel({
shader: `...`,
outputs: ['result', 'debug']
});

Those names must match buffer-like bindings passed to the callable kernel.

const node = computeResults({
input,
result,
debug
});

You do not need declared outputs for in-place work.

const doubleInPlace = kernel({
shader: `
fn main(gid: vec3u) {
data[gid.x] = data[gid.x] * 2.0;
}
`
});
const node = doubleInPlace({ data });
v.run(node);
const result = await v.read(data);

If a kernel has no declared outputs, read the concrete buffer or handle directly.