• Advertisement
Sign in to follow this  

FBO with depth-stencil buffer problem on AMD cards

This topic is 1811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

 

 

TL;DR: I'm sampling the depth values from a depth-stencil texture while at the same time having it bound to an FBO with depth testing enabled but depth writing disabled, and on some cards I'm getting random flickering all over the screen.

 

 

I'm currently writing a deferred lighting renderer, and it's working great on my Nvidia Geforce GTX 295. The engine first draws the geometry information to two GL_RGBA16F g-buffers plus a depth-stencil buffer. Then in the lighting pass I pass in those 3 textures, and render my lights as spheres. I render all my lights spheres twice. The first pass marks pixels that cannot be hit by light with the stencil buffer, and the second lights pixels that pass both the depth and stencil test.

 

//Mark pixels that are too far away from the camera to be affected by the light
glCullFace(GL_BACK);
glStencilFunc(GL_ALWAYS, 0, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glColorMask(false, false, false, false);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);

//Light pixels that passed the too-far-away-test AND the depth test.
//This filters out only the pixels that actually are affected by light.
glCullFace(GL_FRONT);
glStencilFunc(GL_EQUAL, 0, 0xFF);
glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
glColorMask(true, true, true, true);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);

 

This works fine on my graphics card and produces perfect results. However, when I test the same program on an AMD Radeon HD 5870, I get randomly flickering squares all over the screen. It looks very much like what happens on my graphics card if I sample a texture while at the same time writing to it with an FBO, causing a race condition between writing and reading during overdraw. It's true that I have the depth-stencil texture both bound as a texture input to the shader so I can reconstruct position from depth while also having it bound to the FBO so I can do stencil and depth testing, but I have disabled depth WRITING so there shouldn't be a problem, right? It shouldn't be a problem since I'm not writing to it.

Share this post


Link to post
Share on other sites
Advertisement

Seems like this is a bug in the AMD drivers. I solved it by creating a depth-stencil renderbuffer and blitting the depth-stencil texture to it, then use the renderbuffer for depth testing and the texture to reconstruct position. Both had to be in depth-stencil format though or else the AMD driver would whine during the blit. 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement