std140 Layout

For Uniform blocks in the rendering pipeline, WGPU follows OpenGL's std140 layout rules, which are strictly defined.

See:

Variable typeSize and Alignment
Scalar bool, int, uint, float, and doubleBoth the size and alignment are the siz eof the scalar in basic machine types.
ivec2Both the size and alignment are twice the size of the underlying scalar type.
vec3 and vec4Both the size and alignment are 4x the size of the underlying scalar type. Note: the underlying scalar type is usually going to be float, which has size and alignment 4.
An array of scalars or vectorsThe size and alignment of each element in the array will be the size of the element type, _rounded up to the multiple of the size of a vec4. The array's size will be this rounded-up element size times the count of elements in the array.
mat4 or mat4[]Same layout as an array of N vectors each with R components (for column-major matrices) or C components (for row-major matrices).
struct or struct[]Structure alignment will be the alignment for the biggest structure member, rounded up to a multiple of the size of a vec4. Each structure will start on this alignment, and its size will be the space needed by its members, according tot he previous rules, rounded up to a multiple of the structure alignment.