PDA

View Full Version : Occlusion query - use simple shaders and geometry or not?



mlfarrell
09-14-2014, 10:24 PM
Way back in the day I used to use frustum culling and octrees to boost the performance of my 3D scene rendering. Nowadays I hope to accomplish this much easier with occlusion queries using GL_SAMPLES_PASSED.

My question is this, I have quite a few individual VAO mesh objects in my scene and I don't want to issue a whole new series of draw calls for these, even if they are drawing a simple cube geometry with a flat shader. I've already noticed a slight performance drop testing this theory rendering the entire scene with just flat cubes in place of the objects.

What I'd rather do is just attach the queries to the actual live geometry drawing itself (one query per mesh) and use this information to determine whether or not to draw the geometry during the next frame. I plan on doing this asynchronously to avoid stalling the pipeline during the query retrieval.

Are there any serious performance implications that I should be aware of in doing this? Is it a bad idea to query GL_SAMPLES_PASSED during a production render of geometry?

At this point, I'm looking for the lesser of two evils.

edit: I just realized I'm an idiot. I need the simple geometry pass determine if the objects need to be drawn again

Dark Photon
09-15-2014, 07:25 AM
Yes, querying values back from CPU to GPU is bad for performance and should be avoided (includes occlusion queries). You can use conditional rendering to possibly speed this up, but it depends on driver implementation. Another possibility is to do your own occlusion queries in the shader with data that's already on the GPU which almost definitely doesn't involve any GPU->CPU readback.

mlfarrell
09-15-2014, 05:29 PM
Thanks for the tip, I think I'll go with conditional rendering. I'm targeting only the Mac platform, specifically OpenGL 3.3 and higher

One last question, what is the best method for rendering the simple query geometry. Render it to offscreen low-resolution FBO with no color buffer?

malexander
09-16-2014, 07:14 AM
Yep, that'll work.

You can also render it to your main window/FBO with color and depth writes disabled, and your depth test enabled. No extra resources, doesn't affect your main window or FBO.