KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.99k stars 827 forks source link

valid shader with implicit `for` and `if` scope marked as invalid by glslangValidator #3690

Open LeStahL opened 1 month ago

LeStahL commented 1 month ago

Hi!

The shader

#version 450

out vec3 v;
void main()
{
  vec3 i;
  for(int v=0;v<500;v++)
    if(v>1)
      i+=9;
  v=abs(gl_FragCoord.y)<.3?
    i*1.1:
    i;
}

seems to get identified as invalid by glslangValidator although it is valid (see specification).

Output of glslangValidator:

ERROR: 0:10: 'assign' :  cannot convert from ' temp 3-component vector of float' to ' temp int'
ERROR: 0:12: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

I use Glslang Version: 11:14.3.0 to reproduce.

(Related to https://github.com/laurentlb/shader-minifier/issues/435).

arcady-lunarg commented 1 month ago

I think your reading of the spec here is correct and glslang is incorrectly producing an error here, as the inner v should have its scope start right after the first semicolon of the for loop and shadow the outer v.