KhronosGroup / GLSL

GLSL Shading Language Issue Tracker
324 stars 96 forks source link

Clarify compilation of unbound array #231

Open Try opened 5 months ago

Try commented 5 months ago

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:

  1. compiler deduces size automatically, based of largest array index used in shader code 1.1 OpTypeArray with size of one is emitted, if array was never used in code
  2. if GL_EXT_nonuniform_qualifier enabled usually OpTypeRuntimeArray will be used - resulting into 'true' unbound array
  3. if GL_EXT_nonuniform_qualifier enabled and array not been used - OpTypeArray with size of 1 will 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.