Jump to content

  • Log In with Google      Sign In   
  • Create Account

FBO with depth-stencil buffer problem on AMD cards


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 theagentd   Members   -  Reputation: 594

Like
0Likes
Like

Posted 07 February 2013 - 01:53 PM

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.



Sponsor:

#2 theagentd   Members   -  Reputation: 594

Like
0Likes
Like

Posted 07 February 2013 - 09:54 PM

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. 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS