Search code examples
vulkanspir-v

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


The spec says

[140] An array has a base alignment equal to the base alignment of its element type, rounded up to a multiple of 16. .... [430] except for array and structure base alignment which do not need to be 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;
    float[] 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?


Solution

  • Vulkan, in Appendix A, defines the execution environment for SPIR-V; as such, it can impose limits on what it allows in shaders beyond that of the SPIR-V specification. In that appendix, it says:

    OpTypeRuntimeArray must only be used for the last member of an OpTypeStruct that is in the StorageBuffer storage class decorated as Block, or that is in the Uniform storage class decorated as BufferBlock.