Write WebGPU buffer data directly from its storage - #9379
Conversation
WebgpuBuffer#unlock allocated a Uint8Array of the buffer size and copied the storage into it on every upload, to pad the data to the multiple of 4 that writeBuffer requires. Uniform buffer storage is always a multiple of 16 bytes and vertex and index buffers mostly are, so the copy was almost always redundant and created garbage per upload - once per changed uniform buffer per frame. The data is now written straight from its storage, honouring the byte offset of a typed array view, and only odd-sized data goes through a padded copy.
Build size reportThis PR changes the size of the minified bundles.
|
mvaligursky
left a comment
There was a problem hiding this comment.
Automated PR review by Codex (GPT-5).
No actionable findings. The direct path deliberately passes the backing ArrayBuffer, so dataOffset and size remain byte-based regardless of the original typed-array element type; offset views are bounded by their own byteLength, and odd logical sizes still go through a zero-padded multiple-of-four copy. The vertex, index, and persistent-uniform callers keep their CPU storage consistent with the allocated GPU size, and WebGL is untouched.
Validation performed: the new focused tests pass (4/4), the full unit suite passes (2889 passing, 2 pending), git diff --check passes, and all current CI checks are green. Following byte-exact rendering verification criteria, I did not run a real-WebGPU GPU readback or a controlled before/after pixel matrix locally, so actual-device equivalence is supported by the byte-range analysis and tests rather than an independently captured zero-diff result.
Removes a per-upload allocation and copy from the WebGPU buffer upload path.
Changes:
WebgpuBuffer#unlockallocated aUint8Arrayof the GPU buffer size and copied the storage into it on every upload, to pad the data to the multiple of 4 thatwriteBufferrequires. Uniform buffer storage is always a multiple of 16 bytes and vertex and index buffers mostly are, so the copy was almost always redundant, and it produced garbage on every upload of a persistent buffer. The data is now written directly from its storage, honouring the byte offset of a typed array view, and only odd-sized data goes through a padded copy.RangeErrorfrom the copy.ArrayBufferstorage and the padded odd-size path.Performance: