AnsweredAssumed Answered

[BUG REPORT] texelFetch shader crash on MSAA FBO

Question asked by aussiebacom on Jan 18, 2015
Latest reply on Jan 21, 2015 by aussiebacom

I have a shader that runs into an issue when using the texelFetch on a multiple FBO. Debugging the issue also crashes CodeXL in Debug mode.


#version 400
precision mediump float;


#define FBO_DIFFUSE_AO 0
#define FBO_NORMALS 2
#define FBO_EMISSIVE 3
#define FBO_DEPTH 4

// :: In Information ::
in vec2 TexCoord0;    // Co-ordinate of screen UV
in vec2 TexCoord1; // Co-ordinate from center of screen

// : Texture Maps :
uniform sampler2DMS TextureSampler[NUM_MATERIAL_TEXTURES];
uniform samplerCube EnvironmentMap;

// :: Uniforms ::
layout (std140) uniform Static_Data {    // Per Window Initialization
    uniform mat4 ProjectionMatrix;
    uniform vec2 TexelSize;
    uniform float FarCullDistance;
    uniform float NearCullDistance;
    uniform float CullDistanceRatio;
    uniform float Time;
    uniform uint Samples;
layout (std140) uniform Dynamic_Data { // Per Frame
    uniform mat4 ViewMatrix;
    uniform mat4 ViewProjectionMatrix;

void main()
    vec3 Color;
    ivec2 TexCoord2 = ivec2(TexCoord0 / TexelSize);
    float depth = texelFetch(TextureSampler[FBO_DEPTH], TexCoord2, 0).x;
    gl_FragData[0] = vec4(depth,0.0,0.0,1.0);


When trying to output the value of the depth texture into the red channel of the bound FBO, OpenGL goes into a bit of a fit. The shader works fine when replacing the first two terms with either TexCoord0 or TexCoord1 and when having bound the current framebuffer to 0 it outputs the expected gradient of black, red, green and yellow over the screen. I have tested each value in the two uniform blocks other than time to verify that they work and all results are successful.

The original shader this was being used in worked perfectly prior to adding Uniform Buffer Objects to the system thus I have reason to believe that there is a bug in the driver.


Accessing the bound environment map by does output texture information to the screen. Without crashing the application.

gl_FragData[0] = texture(EnvironmentMap, vec3(1.0,TexCoord0));



Other Uniform Buffers are working correctly to draw to the other geometry assuming that they are correctly being drawn to the MSAA FBO. As a test I have ensured that all texture samplers inside of the shader are bound before hand to be sure, hence why the environment map is working.


    //// Render Deferred Geometry
    glBindFramebuffer(GL_FRAMEBUFFER, BloomFrameBufferObject);
    const GLuint Buffers[] = {                    // Create a constant array to store the color buffer attachment locations
        GL_COLOR_ATTACHMENT0 + GBuffer_BloomTextureType::TextureType_OutputDeferred
    glDrawBuffers(1, Buffers);                    // Assign current FrameBufferObject Color Buffers
    glBindFramebuffer(GL_FRAMEBUFFER, 0);    // Output to screen

    // :: Assign Read Buffers from Deferred Output ::
    glActiveTexture(GL_TEXTURE0 + GBuffer_DeferredTextureType::TextureType_Specular);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, DeferredBufferTextures[GBuffer_DeferredTextureType::TextureType_Specular]);
    glActiveTexture(GL_TEXTURE0 + GBuffer_DeferredTextureType::TextureType_Normals);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, DeferredBufferTextures[GBuffer_DeferredTextureType::TextureType_Normals]);
    glActiveTexture(GL_TEXTURE0 + GBuffer_DeferredTextureType::TextureType_Depth);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, DeferredBufferTextures[GBuffer_DeferredTextureType::TextureType_Depth]);
    glActiveTexture(GL_TEXTURE0 + GBuffer_DeferredTextureType::TextureType_Emissive);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, DeferredBufferTextures[GBuffer_DeferredTextureType::TextureType_Emissive]);
    glActiveTexture(GL_TEXTURE0 + GBuffer_DeferredTextureType::TextureType_Diffuse);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, DeferredBufferTextures[GBuffer_DeferredTextureType::TextureType_Diffuse]);
    if (EnvironmentMap != NULL)  EnvironmentMap->Bind(GL_TEXTURE7);
        glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

    glDisable(GL_DEPTH_TEST);                        // Enables Depth Testing
    glDepthMask(GL_FALSE);                            // Use Depth Masking
    glBindBuffer(GL_UNIFORM_BUFFER, 0);
    GLint numbers[Material::TextureParameters::NUM_MAX_TEXTUREPARAMETERS] = { 0, 1, 2, 3, 4, 5, 6 };
    Shaders.Render_Deferred->setUniform("TextureSampler", (GLsizei)Material::TextureParameters::NUM_MAX_TEXTUREPARAMETERS, numbers);
    Shaders.Render_Deferred->setUniform("EnvironmentMap", 7);


The error occurs at the end of this segment of code where the shader unbind function simple calls a glUseProgram(0) and then a mutex unlock. The error occurs immediately upon calling the glUseProgram function. Visual studio returns Unhandeled exception at 0x5E4E4F9B (atioglxx.dll) in # 0xC000005: Access violation reading location 0x000000A5.


Using latest AMD Catalyst Omega:

Driver Packaging Version    14.501.1003-141120a-178000C
Catalyst Version    14.12 AMD Catalyst Omega Software
Provider    Advanced Micro Devices, Inc.
2D Driver Version
2D Driver File Path    /REGISTRY/MACHINE/SYSTEM/ControlSet001/Control/Class/{4d36e968-e325-11ce-bfc1-08002be10318}/0000
Direct3D Version
OpenGL Version
Mantle Driver Version
Mantle API Version    98304
AMD Catalyst Control Center Version    2014.1120.2123.38423
AMD Audio Driver Version