Skip to content

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

@LeStahL

Description

@LeStahL

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions