StructTypeNode: Fix memory length calculations (#32375)#32377
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
Edit: Disregard this, adressed with the next commit! To note here: Examples: getLength() for this struct now returns 8 (32 bytes), which is correct for a buffer with a single element, e.g. getLength() for this struct now returns 4 (16 bytes), which is correct for a buffer with a single element, e.g. Maybe to fully address this, there would need to be a getLength() function that also takes the number of elements of this struct into account? |
|
Ok, I added another commit that adresses above concerns. getLength() should now also return correct lengths for structs with different alignments. getLength() now doesn't necessary return multiples of 4 anymore, but multiples of the biggest alignment value within the struct. (following https://webgpufundamentals.org/webgpu/lessons/webgpu-memory-layout.html#a-struct-array-size-alignment) |
|
I think the next step is to align |
Fixed #32375.
Description
This change fixes the memory length calculation for the StructTypeNode so three.js allocates enough memory for custom structs.
I have also renamed the getByteBoundaryFromType() function to getAlignmentFromType() and fixed the values for mat3/mat4 according to https://webgpufundamentals.org/webgpu/lessons/webgpu-memory-layout.html