KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.9k stars 815 forks source link

Trivial boolean bitwise assignment compiler bug? #3609

Closed pablode closed 1 month ago

pablode commented 1 month ago

The compilation of following snippet

#version 460

layout (location = 0) out vec4 fragColor;

void main()
{
    bool someValue = false;

    someValue |= true;

    fragColor = vec4(someValue ? 1.0 : 0.0);
}

fails with

ERROR: C:\local\Temp\b2ebf39f-0f47-4c4f-a9b2-b14cbd760824.tmp:9: 'assign' :  cannot convert from ' const bool' to ' temp bool'
ERROR: C:\local\Temp\b2ebf39f-0f47-4c4f-a9b2-b14cbd760824.tmp:9: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

SPIR-V is not generated for failed compile or link

contrary to what I would expect.

https://shader-playground.timjones.io/1a0c89e120d03eb2b9f813ae8ba26a62

arcady-lunarg commented 1 month ago

This gives an funny error message if you try this variation:

bool someValue = false;
bool someOtherValue = true;
someValue |= someOtherValue

results in ERROR: 0:10: 'assign' : cannot convert from ' temp bool' to ' temp bool'. I need to check what the GLSL spec actually allows here, but it seems like should be allowed.

arcady-lunarg commented 1 month ago

In Section 5.9 of the GLSL spec you can see that there is a section explaining that bitwise operations are not allowed on boolean values:

The bitwise operators and (&), exclusive-or (^), and inclusive-or (|). The operands must be of type signed or unsigned integers or integer vectors.

However, the error message provided by glslang is rather inscrutable and does not make it at all clear what the problem is.

pablode commented 1 month ago

Ah, that explains it. I guess I was spoilt by C/C++ 😅 Thank you, and yes, a better error message would be helpful.