Most appropriate sub-area of p5.js?
p5.js version
2.2.3
Web browser and version
Chrome 147.0.7727.137
Operating system
MacOSX 26.4.1
Steps to reproduce this
Steps:
- Create a WebGPU sketch that uses
buildComputeShader().
- Inside the compute callback, define a helper function that returns an array, for example
return [1, 2].
- Read from that returned value using computed indexing like
arr[0].
- Call
buildComputeShader(errorCallback) and then try errorShader.inspectHooks().
Snippet:
let shader;
let errorShader;
let storage;
const COUNT = 10;
async function setup() {
await createCanvas(400, 400, WEBGPU);
noLoop();
background(100);
storage = createStorage(new Float32Array(COUNT));
shader = buildComputeShader(callback);
shader.inspectHooks();
console.log("======Compute shader source:======");
console.log(shader.computeSrc());
console.log("================================");
errorShader = buildComputeShader(errorCallback);
errorShader.inspectHooks();
console.log("======Error shader source:======");
console.log(errorShader.computeSrc());
console.log("================================");
}
function errorCallback() {
let data = uniformStorage(storage);
function getArray() {
return [1, 2];
}
let arr = getArray();
data[index.x] = arr[0] + arr[1] + index.x;
}
function callback() {
let data = uniformStorage(storage);
function getNumber() {
return float(index.x);
}
let num = getNumber();
data[index.x] = num;
}
async function draw() {
compute(shader, COUNT);
const data = await storage.read();
console.log(data);
}
Console error:
Uncaught (in promise) Error: get() can only be used on storage buffers
Expected behavior:
buildComputeShader(errorCallback) should either:
- support indexing into a helper-returned array/vector-like value, or
- fail with a clearer compile/transpile error explaining that this pattern is unsupported.
It should also ideally still be possible to inspect the generated hooks/source for debugging.
Actual behavior:
buildComputeShader(errorCallback) throws before errorShader.inspectHooks() can run, so the shader is never returned and its generated source cannot be inspected.
The scalar-return version works:
function getNumber() {
return float(index.x);
}
but the array-return version fails when indexing the returned value with arr[0].
Additional notes:
From local repo inspection, this looks like a p5.strands transpilation issue rather than a WGSL compile error:
- array literals are transformed into strands values
- computed indexing like
arr[0] is rewritten into .get(0)
.get() currently appears to only work for storage buffers
So the bug seems to be specifically that non-storage array/vector indexing is being routed through the storage-buffer access path.
Most appropriate sub-area of p5.js?
p5.js version
2.2.3
Web browser and version
Chrome 147.0.7727.137
Operating system
MacOSX 26.4.1
Steps to reproduce this
Steps:
buildComputeShader().return [1, 2].arr[0].buildComputeShader(errorCallback)and then tryerrorShader.inspectHooks().Snippet:
Console error:
Uncaught (in promise) Error: get() can only be used on storage buffersExpected behavior:
buildComputeShader(errorCallback)should either:It should also ideally still be possible to inspect the generated hooks/source for debugging.
Actual behavior:
buildComputeShader(errorCallback)throws beforeerrorShader.inspectHooks()can run, so the shader is never returned and its generated source cannot be inspected.The scalar-return version works:
but the array-return version fails when indexing the returned value with
arr[0].Additional notes:
From local repo inspection, this looks like a
p5.strandstranspilation issue rather than a WGSL compile error:arr[0]is rewritten into.get(0).get()currently appears to only work for storage buffersSo the bug seems to be specifically that non-storage array/vector indexing is being routed through the storage-buffer access path.