Add StorageBuffer.set(index, value) for single-element GPU updates#8772
Add StorageBuffer.set(index, value) for single-element GPU updates#8772aashu2006 wants to merge 1 commit intoprocessing:dev-2.0from
Conversation
504f178 to
e2ceec3
Compare
|
hii @davepagurek, thanks for waiting! as there isn’t a way to update a single buffer element without re-uploading the whole buffer, it can get expensive for large cases like 10k particles. since For struct buffers the offset is I reused the existing also added the type checks with clearer errors, plus unit tests for both float and struct buffers including checks that neighbouring elements stay unchanged. let me know if you would like anything adjusted! |
Resolves #8749
Changes
I've added a
set(index, value)method top5.StorageBufferthat updates a single element in a buffer without rewriting the whole thing.Before this, updating one particle out of thousands required a full GPU -> CPU read, a JS edit, then a full CPU -> GPU write back. Now you can do:
This works by using
GPUQueue.writeBuffer()with a byte offset, so only one element's bytes are sent to the GPU.What changed:
src/webgpu/p5.RendererWebGPU.jsadded set(index, value) to StorageBuffer
added JSDoc and examples
test/unit/webgpu/p5.RendererWebGPU.jsadded 7 unit tests for float buffers, struct buffers, bounds checks, and type validation
PR Checklist
npm run lintpasses