On my NVIDIA GPU these 2 shaders work fine:
// VS
#version 450
layout(location = 0) in vec4 inPosition;
layout(location = 0) out struct {
vec2 dummy;
uvec4 variableInStruct;
} testStruct;
void main(void)
{
gl_Position = inPosition;
testStruct.variableInStruct = uvec4(4, 16, 64, 256);
}
// PS
#version 450
layout(location = 0) out vec4 fragColor;
layout(location = 0) in flat struct {
vec2 dummy;
uvec2 variableInStruct;
} testStruct;
void main(void)
{
float result = 0.0;
result = float(testStruct.variableInStruct.x == 4) *
float(testStruct.variableInStruct.y == 16);
fragColor = vec4(result);
}
In the program PS input { <2 x float>, <2 x i32> } is only a subset of VS output { <2 x float>, <4 x i32> }, and it works fine on some hardware.
Did GLSL/Vulkan spec mention anything (legality, code examples) about such cases?