| Memory Array - Alignment Buffers and Pains | |
Going to talk about memory and how it isn't always what you think it is! Especially for long sequential blocks of data!
For example the below implementation copies from array0 to array1 ! What could be simplier? Both are just an array of floats. However, in WGSL the array1 is stored as array< vec3<f32> > - which is common as you might want to group every 3 values as positions or vectors (x,y,z) - but what you might not be aware of is how it's stored in memory on the GPU!!
As the vec3<f32> is a structure - so all structures are aligned to 16 byte boundaries!
If the memory definitions are like this:
@group(0) @binding(0) var<storage, read> array0 : array< vec3<f32> >; @group(0) @binding(1) var<storage, read_write> array1 : array< f32 >;
And the WGSL code to copy array0 to array1 is:
|