我正在尝试使用 SPIR-V专业化常量来定义统一块中数组的大小。
#version 460 core
layout(constant_id = 0) const uint count = 0;
layout(binding = 0) uniform Uniform
{
vec4 foo[count];
uint bar[count];
};
void main() {}
count = 0
在着色器中声明,编译失败并显示:
array size must be a positive integer
使用count = 1
和专业化 5,代码编译但在运行时链接失败,并抱怨别名:
error: different uniforms (named Uniform.foo[4] and Uniform.bar[3]) sharing the same offset within a uniform block (named Uniform) between shaders
error: different uniforms (named Uniform.foo[3] and Uniform.bar[2]) sharing the same offset within a uniform block (named Uniform) between shaders
error: different uniforms (named Uniform.foo[2] and Uniform.bar[1]) sharing the same offset within a uniform block (named Uniform) between shaders
error: different uniforms (named Uniform.foo[1] and Uniform.bar[0]) sharing the same offset within a uniform block (named Uniform) between shaders
似乎统一块的布局(每个成员的偏移量)在专业化期间不受影响,因此foo
重叠bar
。
显式偏移也不起作用,并导致相同的链接错误:
layout(binding = 0, std140) uniform Uniform
{
layout(offset = 0) vec4 foo[count];
layout(offset = count) uint bar[count];
};
这是预期的行为吗?俯瞰?可以使用专门化常量来定义数组的大小吗?