SPIR-V 中带有 std430 的动态数组的对齐规则是什么?
What are the alignment rules for a dynamic arrays in SPIR-V with std430?
规范说
[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.
我假设静态数组的大小是微不足道的 size_of(elem_type) * length
但动态数组呢?
逻辑模式中没有指针,是不是动态数组的大小为0?
我不知道应该对以下结构应用哪些偏移量
struct Data {
float i1;
float[] arr;
float i2;
}
或者用 SPIR-V 表示法
%Data = OpTypeStruct %float %_runtimearr_float %float
这可以做到吗,或者是否可以在这里应用相同的 GLSL 规则,在缓冲区块中只允许有一个动态数组,而且它必须是最后一个?
Vulkan,在附录 A 中,定义了 SPIR-V 的执行环境;因此,它可以对超出 SPIR-V 规范的着色器允许的内容施加限制。在该附录中,它说:
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
.
规范说
[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.
我假设静态数组的大小是微不足道的 size_of(elem_type) * length
但动态数组呢?
逻辑模式中没有指针,是不是动态数组的大小为0?
我不知道应该对以下结构应用哪些偏移量
struct Data {
float i1;
float[] arr;
float i2;
}
或者用 SPIR-V 表示法
%Data = OpTypeStruct %float %_runtimearr_float %float
这可以做到吗,或者是否可以在这里应用相同的 GLSL 规则,在缓冲区块中只允许有一个动态数组,而且它必须是最后一个?
Vulkan,在附录 A 中,定义了 SPIR-V 的执行环境;因此,它可以对超出 SPIR-V 规范的着色器允许的内容施加限制。在该附录中,它说:
OpTypeRuntimeArray
must only be used for the last member of anOpTypeStruct
that is in theStorageBuffer
storage class decorated asBlock
, or that is in theUniform
storage class decorated asBufferBlock
.