Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LeStahL opened this issue Aug 8, 2024 · 1 comment

Comments

@LeStahL
Copy link

LeStahL commented Aug 8, 2024

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:

  • loop index variable gets renamed to the same id as the fragment output
  • loop { scope gets removed because it's a single-statement loop and thus loop variable declaration overwrites fragment output variable
@LeStahL
Copy link
Author

LeStahL commented Aug 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant