刚写了个小测试程序,却偶然发现GLSL中buffer的对齐似乎不太对劲。我的声明是这样的:
layout(std430, binding = 1) buffer PickBuffer{vec3 Result[];};
但是使用中发现,无论是输入还是输出,都与CPU端不一致,似乎每个元素都是vec4才对。但是std430应该要求紧密对齐吧?试试vec2的结果是对的。
GLSL的规范中是这样写的:
When using
the
std430
storage layout, shader storage blocks will be laid out in buffer storage
identically to uniform and shader storage blocks using the
std140
layout, except that the base alignment and stride of arrays of scalars and vectors in rule 4 and of structures in rule 9 are not rounded up a multiple of the base alignment of a
vec4
.