Hardware Occlusion Queries, why use them next frame?
#1 Members - Reputation: 228
Posted 19 July 2012 - 09:58 PM
What I don't get is how occlusion queries are different from, for example, multiple render passes. In deferred shading, you render to a G buffer, and afterwards you get the buffer back and use it instead in the lighting shaders pass. Wouldn't that cause some kind of stall just like getting back occlusion query results?
I'm working on kind of a hybrid algorithm using a unifrom grid.
I have a first pass to determine which uniform grid cells are completely occluded. My view frustum traverses the grid front to back and I render simplified artist defined geometry for large occluders to the depth buffer with color write off. This geometry would have to be fully containable by the real geometry. At the same time, I draw the grid cell itself with depth and color write off and issue an occlusion query for it. The cells are queried against the large artist defined occluders to see if any cells in the scene can be completely filtered out.
After this I retreive the hardware query results for the cells, then send all objects to the renderer in the cells I determined to be visible. The depth buffer is still populated by the simplified large occluders I used in the last pass.
So in the second pass of the frame I now do the standard, draw simple bounding box for each object with color and depth write off and issue a query for it, then render it next frame in the second pass for real if it passed by using the occlusion query result next frame.
So I'm wondering if my first pass is a bad idea. I read that Battlefield 3 and Cryengine 3 do this kind of thing with software occlusion queries instead to avoid the CPU stall and use the results in the same frame instead of next frame. Am I effectively halfing my frame rate by doing this with hardware queries?
#2 Members - Reputation: 481
Posted 19 July 2012 - 10:17 PM
With occlusion queries though you need to read them back on the CPU side. That's why developers wait a frame with them.
#3 Members - Reputation: 775
Posted 19 July 2012 - 11:09 PM
I have an example of this here: https://github.com/p...onal_render.cpp
Edit: DX seems to have this functionality as well I just wasn't sure at the point of writing the post since I'm not really experienced with DX
Edited by japro, 19 July 2012 - 11:25 PM.
#4 Members - Reputation: 4606
Posted 20 July 2012 - 06:42 AM
When you call the graphics API, your command is most of the time enqueued in a command queue, the GPU will process this command queue independently of the API call. We talk about a stall, when you enqueue a command which requires an immediate feedback, in this case the CPU has to wait until the GPU has processed all commands up to the according API call, which is more or less some kind of busy waiting (aka flushing the command queue, the CPU is not actually busy waiting, but your processing thread is paused at least).What I don't get is how occlusion queries are different from, for example, multiple render passes. In deferred shading, you render to a G buffer, and afterwards you get the buffer back and use it instead in the lighting shaders pass. Wouldn't that cause some kind of stall just like getting back occlusion query results?
Therefore it is very important to almost never call such a feedback API function to optimise the usage of CPU and GPU. A simple OGL error checking call can already flush the command queue, requesting the result of an occlusion query will flush the command queue up to the occlusion query command at least, therefore the safest way to check it, is once the framebuffer is displayed (most likely in the next frame when the framebuffer has been swapped).
Occ queries, much like geometry shaders, sounds awesome first, but fall short of your expectation once you understand their limitations.So I'm wondering if my first pass is a bad idea. I read that Battlefield 3 and Cryengine 3 do this kind of thing with software occlusion queries instead to avoid the CPU stall and use the results in the same frame instead of next frame. Am I effectively halfing my frame rate by doing this with hardware queries?
Edited by Ashaman73, 20 July 2012 - 06:45 AM.
#6 Members - Reputation: 228
Posted 23 July 2012 - 03:06 AM
#7 Members - Reputation: 304
Posted 23 July 2012 - 11:21 PM
At least, that's the way I get it.






