What are the alignment rules for a dynamic arrays in SPIR-V with std430?


#1

The spec says

An array has a base alignment equal to the base alignment of its element type, rounded up to a multiple of 16.

I assume the size for a static array is trivially size_of(elem_type) * length but what about a dynamic array?

There are no pointers in the logical mode, does that mean the size of a dynamic array is 0?

I don’t know which offsets I should apply to the following struct

struct Data {
    float i1;
    f32[] arr;
    float i2;
}

Or in SPIR-V notation


%Data = OpTypeStruct %float %_runtimearr_float %float

Can this be done, or do the same rules of GLSL apply here where you are only allowed to have exactly one dynamic array inside a buffer block, and it has to be the last one?


#2

The base alignment is used to constraint the address of the start of the array. The base alignment is not tied to whether the array is of fixed size or is a runtime array.

A runtime array is only ever allowed as the last element of the block. So your example is not valid.