I have the following Fragment Shader
#version 460
layout(location = 0) out vec4 Helligkeit;
void main( void ){
//Declaring "sip" as ivec2 yields the erroneous behaviour ...
ivec2 sip = ivec2(-1);
//... declaring it as an int[2] however does not
//int sip[2];
//sip[0] = sip[1] = -1;
//Doing arithmetics on "sip" gives strange results if array subscripting is used with non-constant expressions on vectors
int jkl = sip[gl_PrimitiveID%2]; // using a built-in per-shader variables like gl_PrimitiveID does give the error but uniform variables do as well
int asdf = 1-sip[gl_PrimitiveID%2]; // defining "asdf" as 1-jkl however does NOT yield the error
if( 1-jkl != asdf ) // This clause should never be true!
Helligkeit = vec4(1.0f, 0.0f, 0.0f, 1.0f);
else
Helligkeit = vec4(0.0f, 1.0f, 0.0f, 1.0f);
}
and the result I observe running it is a red drawing on the screen i.e. 1-jkl does not equal asdf despite them computing the same expression semantically. In fact the value of asdf is -2147483648 i.e. the smallest signed 32-bit integer.
I don't think this is correct behaviour and might be a bug in the GLSL compiler.
This behaviour does not occur when "sip" is declared as an array of integers or when jkl and asdf are adressing "sip" with a constant expression. However, the GLSL specification does explicitly allow non-constant expressions for vector subscripting (GLSL core spec, section 5.5).
I have attached a zip file with a Visual C++ 2015 project demonstrating the error which contains the following relevant files:
- Quelle1.cpp The C++ file that sets all the OpenGL context up
- Shaders/test.vert A trivial VS
- Shaders/test.frag The FS already shown above
I'm using an RX 480 card on Windows 7 64-bit with the following driver versions:
Radeon Settings Version - 2019.0326.2353.42986
View Release Notes - https://www.amd.com/en/support/kb/release-notes/rn-rad-win-19-4-1
Driver Packaging Version - 18.50.31.01-190326a-340999C-RadeonSoftwareAdrenalin2019
Provider - Advanced Micro Devices, Inc.
2D Driver Version - 8.1.1.1634
Direct3D® Version - 9.14.10.01377
OpenGL® Version - 25.20.15000.13547
OpenCL™ Version - 10.0.2766.5
AMD Audio Driver Version - 7.12.0.7728
Vulkan™ Driver Version - 2.0.78
Vulkan™ API Version - 1.1.101