cancel
Showing results for 
Search instead for 
Did you mean: 

OpenGL & Vulkan

spaceengineer
Journeyman III

GLSL compiler crash/bug

I wrote incorrect code, and spend good half a day figuring out what is wrong. This is because AMD shader compiler crashes or reports weird errors log while compiling the shader. Lets look at this code:

float heightmapCubicV(sampler2D tex, ivec2 uvi, float uvf, int ofsV)
{
    return interpolate(
        texelFetchOffset(tex, uvi, 0, ivec2(-1, ofsV)).w,
        texelFetchOffset(tex, uvi, 0, ivec2( 0, ofsV)).w,
        texelFetchOffset(tex, uvi, 0, ivec2( 1, ofsV)).w,
        texelFetchOffset(tex, uvi, 0, ivec2( 2, ofsV)).w,
        uvf);
}

I forgot what offset vector in the texelFetchOffset must be a constant expression (should write  const int ofsV  in the function declaration). But it works on NVidia, and this is bad! The more weird issue is what AMD shader compiler sometimes crashes on trying to compile this, even if the function is not called in the code. Important note: this code is typed in the vertex shader -- if I move it to the pixel shader, no errors happening!

Sometimes compiler did not crashes, but reports strange things using glGetInfoLogARB():

[MT] ERROR: Compiling shader "#/shaders/planet.glsl":
Vertex shader failed to compile with the following errors:
ERROR: 0:75: error(#198) Redefinition error: HeightMap
ERROR: 0:76: error(#198) Redefinition error: NormMap
ERROR: 0:77: error(#198) Redefinition error: DiffMap
ERROR: 0:78: error(#198) Redefinition error: RoughMap
ERROR: 0:116: error(#198) Redefinition error: Radiuses
ERROR: 0:117: error(#198) Redefinition error: NodeCenter
ERROR: 0:118: error(#198) Redefinition error: VSFetchParams
ERROR: 0:119: error(#198) Redefinition error: VSFetchParams2
ERROR: 0:120: error(#198) Redefinition error: ModelViewProj
ERROR: 0:122: error(#198) Redefinition error: NLights

... (cut) ...

There are obviously no redefinitions in the code. To me, it looks like the parser corrupts its own memory and starts to parse the code from the beginning again. If I modify the function to this:

float heightmapCubicV(sampler2D tex, ivec2 uvi, float uvf, int ofsV)
{
    return texelFetchOffset(tex, uvi, 0, ivec2(-1, ofsV)).w;

}

then glGetInfoLogARB() reports an error as expected:

[MT] ERROR: Compiling shader "#/shaders/planet.glsl":
Vertex shader failed to compile with the following errors:
ERROR: 0:1123: error(#30) Built-in function parameter type check fail: offset must be a constant/literal in texture functions.
ERROR: error(#273) 1 compilation errors. No code generated

So I think there is a bug in the GLSL compiler -- it breaks itself down if there are more that one incorrect use of texelFetchOffset with a non-constant offset. Also, changing int ofsV  to  const int ofsV  in the function declaration does not help, the same error message/bug occurs.

Driver version is 19.1.1, also tested on 19.1.2.

0 Likes
2 Replies
dorisyan
Staff

Hi spaceengineer‌, could you provide a minimal code that can reproduce this problem? By the way, I'd like to know some info about your OS and graphics card. Thanks!

0 Likes

Hi, GPU is PowerColor RX 580. I have no time to make an isolated demo. Do you know some OpenGL/GLSL/Visual Studio C++ framework, where I can just change some shader to illustrate the problem? Something like vertex shader terrain demo.

0 Likes