Probable glsl compiler bug

I’m having some issues while compiling a compute shader with the following code:

… // extensions declarations + includes + uniform buffers
uniform int LOD;
uniform int GRADS;
void main(void){
const ivec2 block = ivec2(gl_GlobalInvocationID.x / 2, gl_GlobalInvocationID.y) / (BASE_SPHERICAL_LIGHTING_BLOCk_SIZE>>LOD);

layout(rgba16f) image2D dstImg =
layout(rgba16f) image2D(GRADS>0 ?
svo.lods[0].lightProbes.convolved_grads[LOD].img :
svo.lods[0].lightProbes.convolved_coeffs[LOD].img);

sampler2D lightProbes = sampler2D(GRADS>0 ?
svo.lods[0].lightProbes.grads[LOD].tex :
svo.lods[0].lightProbes.coeffs[LOD].tex);

if(isLightProbeAllocated(block, lightProbes)){ // this always returns true at runtime
vec3 v = convolve_light_probe(LOD, lightProbes); // non-zero return value
imageStore(dstImg, ivec2(gl_GlobalInvocationID), vec4(v, 0.0f));
}else{
imageStore(dstImg, ivec2(gl_GlobalInvocationID), vec4(1, 1, 1, 0.0f)); // this is never called
}

}

which does not work: dstImg contains only zeroes after execution.
However, the program works once the else statement is removed, even though the else statement is never called at runtime:

if(isLightProbeAllocated(block, lightProbes)){ // this always returns true at runtime
vec3 v = convolve_light_probe(LOD, lightProbes); // non-zero return value
imageStore(dstImg, ivec2(gl_GlobalInvocationID), vec4(v, 0.0f));
}

Long story short, removing the else statement makes it work even though this path of the code is not used at runtime anyway.

I’m suspecting a compiler bug. What should I do?
Driver version is 520.61.05 on ubuntu 18.04 with an rtx A6000.

Hi there @utilisateur2281 and welcome to the NVIDIA developer forums.

Well, a quick search in our internal issues database did not show anything, so I am not sure about a GLSL compiler bug kicking in on an else statement.

I assume you check dstImg for its content inside the main function? Since it only has local scope.

Might still be worth a try to take it out and also try unrolling the conditionals on initialization.

Other than that, very hard to say without knowing the actual input to imageStore() since it can still decide it to be invalid, in which case it will not write anything.

I wrote a small executable showing the problem.

I run the two versions of the shader on the exact same inputs so dstImg cannot change.

The version without the else statement works as intended.

The version with the else statement writes a black value even though none of the code paths should write such value.

glslTest.zip (4.22 MB)

I forgot to mention the executable is for windows.

I tested it on windows 11 with driver version 528.79

Thanks for your time.