Open
Description
Description
Consider this simple struct:
const testStruct = struct({
a: { type: "vec3" },
b: { type: "vec3" },
});
Because of the WebGPU data memory layout restrictions, vec3 elements have to be aligned to a multiple of 16 bytes in memory. So the correct size of the above struct in memory is 32 bytes. However the structTypeNode gives a length of 6 elements = 24 bytes, so 8 bytes short. In consequence, when creating instancedArrays with this struct, not enough memory is allocated on the GPU for the array.
See attached fiddle for an example, where an array of length 2 is created, but the second element is cut off in memory.
Right now a workaround is to do the alignment calculations manually and pass a TypedArray of the correct size when creating the instancedArray.
Live example
Version
r175-dev