Skip to content

v.read()

Use v.read() when JavaScript needs GPU results.

const result = await v.read(buffer);

v.read() accepts:

| Target | Result | | --- | --- | | Buffer | Typed array when possible, otherwise ArrayBuffer | | RawBuffer | ArrayBuffer | | Node | Record of declared outputs | | Handle | Result from the concrete buffer behind the handle | | ReadTarget[] | Array of results |

const values = await v.read(buffer);
// Float32Array [...]

Primitive Buffer types return matching typed arrays when Volten can infer one.

Structured buffers return ArrayBuffer; use unpack() to decode them.

Reading a node returns only declared outputs.

const kernel = new Kernel(`...`, {
outputs: ['result']
});
const node = v.pass(kernel, { input, result });
v.run(node);
const outputs = await v.read(node);
// { result: Float32Array [...] }

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

const data = await v.read(node.data);
const [a, b] = await v.read([bufferA, nodeB.output]);

Volten deduplicates concrete buffers internally, so reading the same backing buffer through multiple handles does not copy it more than once.