GLSL
GLSL copied to clipboard
Clarify compilation of unbound array
In GLSL it's possible to declare 'unbound' array of descriptors, by writing something like:
layout(binding = 0) uniform sampler2D texture[];
This has about 3 different behaviors in glslang compiler:
- compiler deduces size automatically, based of largest array index used in shader code
1.1
OpTypeArraywith size of one is emitted, if array was never used in code - if
GL_EXT_nonuniform_qualifierenabled usuallyOpTypeRuntimeArraywill be used - resulting into 'true' unbound array - if
GL_EXT_nonuniform_qualifierenabled and array not been used -OpTypeArraywith size of1will be emitted
Behavior 3, may cause different shader stages to be incompatible with each-other, when array declared in both vertex&fragment but used only in one of stages.
Proposal:
When GL_EXT_nonuniform_qualifier is in use, only OpTypeRuntimeArray must be used, for unbound array.