I have this push constant block:
layout(push_constant) uniform PC {
vec4 value1;
vec4 value2;
uint values[2];
uint value3;
uint value4;
} pc;
And a corresponding struct in C:
struct {
float value1[4];
float value2[4];
uint32_t values[2];
uint32_t padding1__[2];
uint32_t value3;
uint32_t value4;
};
Note that the padding was inserted to respect std140 (arrays of scalar values should be padded to the nearest alignment of vec4).
But upon debugging it seems that value3
and value4
take the value of padding1__[0]
and padding1__[1]
respectively instead of the desired values.
Section 4.4.5 of the OpenGL Shading Language specification says:
The initial state of compilation when generating SPIR-V is as if the following were declared:
layout(std140, column_major) uniform; layout(std430, column_major) buffer;
However, when push_constant is declared, the default layout of the buffer will be std430. There is no method to globally set this default.
So the block doesn't use the std140 layout, but instead it uses std430, as such removing the padding fixes the problem