laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code
https://ctrl-alt-test.fr/minifier/
Apache License 2.0
438 stars 32 forks source link

Loop index renaming and bracket removal overwrites fragment output in main block scope #435

Open LeStahL opened 1 month ago

LeStahL commented 1 month ago

Ok this one is kinda obscure to track down - I'm using shader_minifier v1.4.0. Minifying the shader

#version 450

out vec3 v;

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

results in the invalid minified 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;
}

which has the glslangValidator output

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.

The problem has two causes:

LeStahL commented 1 month ago

Actually, I am not so sure that this is actually a shader_minifier bug: This should be possible to do per specification (the minified shader should be valid) And indeed, I'm able to compile it successfully using glCompileShader.

Might make sense to report this in the glslang repository as glslangValidator seems to wrongly complain here.