Skip to content

Scale Values

This is the smallest useful Volten shape: one mutable buffer, one kernel, one run.

import { volten, Buffer, Kernel } from '@volten/core';
const v = await volten();
const data = new Buffer([1, 2, 3, 4], 'f32', 'rw');
const scale = new Kernel(`
fn main(gid: vec3u) {
data[gid.x] = data[gid.x] * 2.0;
}
`);
const node = v.pass(scale, { data });
v.run(node);
console.log(await v.read(data));
// Float32Array [2, 4, 6, 8]

data is read and written by the shader, so the buffer uses 'rw' access.

Learn more: Buffers, Writing Kernels, v.run().