cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

aussiebacom
Journeyman III

[BUG REPORT] texelFetch shader crash on MSAA FBO

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 NUM_MATERIAL_TEXTURES 7



#define FBO_DIFFUSE_AO 0


#define FBO_SPECULAR_GLOSS 1


#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));






environemnt_map_works.pnggeometry_render_to_front.png

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);


    else


    {


        glActiveTexture(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);


    Shaders.Render_Deferred->Bind();


    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);


    DrawScreenQuad();


    Shaders.Render_Deferred->Unbind();


}






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    8.01.01.1443


2D Driver File Path    /REGISTRY/MACHINE/SYSTEM/ControlSet001/Control/Class/{4d36e968-e325-11ce-bfc1-08002be10318}/0000


Direct3D Version    9.14.10.01080


OpenGL Version    6.14.10.13283


Mantle Driver Version    9.1.10.0045


Mantle API Version    98304


AMD Catalyst Control Center Version    2014.1120.2123.38423


AMD Audio Driver Version    9.0.0.9905





0 Likes
1 Reply
aussiebacom
Journeyman III

Found the source of the problem. By using an array of multisample samplers in the shader there is an error when accessing any sampler greater than index 0. Unsure as to the cause of this problem as of yet but by changing the above shader code to the new below fixes the issue.


#version 400


precision mediump float;



// :: In Information ::


in vec2 TexCoord0;    // Co-ordinate of screen UV


in vec2 TexCoord1; // Co-ordinate from center of screen



// : Texture Maps :


uniform samplerCube EnvironmentMap;


uniform sampler2DMS Texture0,Texture1,Texture2,Texture3,Texture4;



#define FBO_DIFFUSE_AO Texture0


#define FBO_SPECULAR_GLOSS Texture1


#define FBO_NORMALS Texture2


#define FBO_EMISSIVE Texture3


#define FBO_DEPTH Texture4



// :: 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);


    vec4 color = texelFetch(FBO_DEPTH, TexCoord2, 0);


    gl_FragData[0] = color;


}


The change from using the TextureSampler array and binding each sampler as individual's resolves the issue.

0 Likes