[BUG] Compiler issues internal error: "IF statement nested too deeply"

Bug report and files:


Fragment shader: the associated fragment shader is large, so I won’t paste it, but it can be found here:


This is accepted by glslangValidator and by a recent Intel driver, but the NVIDIA compiler gives an internal error, a snippet of which is:

Internal error: assembly compile error for fragment shader at offset 5906:
-- error message --
line 309, column 7:  error: IF statement nested too deeply.
line 347, column 6:  error: ENDIF without matching IF.
-- internal assembly text --
OPTION NV_bindless_texture;
# cgc version 3.4.0001, build date Oct  1 2016
# command line args:
#vendor NVIDIA Corporation
#version COP Build Date Oct  1 2016
#profile gp5fp
#program main
#semantic injectionSwitch
#var float2 injectionSwitch :  : c[0] : -1 : 1
PARAM c[1] = { program.local[0] };
SGT.F R0.y, c[0].x, {1, 0, 0, 0}.x;
TRUNC.U.CC HC.x, R0.y;
MOV.U R0.x, {1, 0, 0, 0};
IF    NE.x;
MOV.U R0.x, {0, 0, 0, 0};
MOV.U.CC RC.x, R0;
IF    NE.x;
SGT.F R0.y, {1, 0, 0, 0}.x, c[0];
TRUNC.U.CC HC.x, R0.y;
IF    NE.x;
SGT.F R0.y, c[0].x, {1, 0, 0, 0}.x;
TRUNC.U.CC HC.x, R0.y;
IF    NE.x;
MOV.U R0.x, {0, 0, 0, 0};

It’s a very large shader and I doubt anyone would write a shader with so many conditionals in practice, so perhaps it’s OK for the compiler to reject this. But the error message is an internal error, with lots of low-level code output; it would be more graceful to complain about nesting depth at the source level.

In fact, although there are a lot of conditionals, the nesting is not deep.

  1. Operating system version.

Windows 10

  1. Graphics hardware.

GeForce GTX 770. Driver: 373.06

  1. Reproducer project.
    We have provided the fragment shader at the above link.

  2. Description of single steps to reproduce the problem.
    Compile and link the fragment shader.

  3. Description of the expected result.
    No link error.