• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ill

Hardware Occlusion Queries, why use them next frame?

6 posts in this topic

So working with Hardware occlusion queries, I see many tutorials and game developers saying to use them a frame later due to stalling and all that.

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?
0

Share this post


Link to post
Share on other sites
The difference with your example of deferred rendering is that with a deferred render, or any technique that has multiple render passes, is that you never actually read back that render target on the CPU. You're only using the data as a texture that's being fed into the next render pass. So there's never a stall from having to copy the data back to the CPU.

With occlusion queries though you need to read them back on the CPU side. That's why developers wait a frame with them.
2

Share this post


Link to post
Share on other sites
At least OpenGL has conditional render which in theory would allow the occlusion queries also to stay on the GPU. I found this to work reasonably well on new hardware (gtx560ti) but very badly on my gtx260m. On the new hardware using the conditional render in the same pass as the queries gave me a speed up of factor 1.5-5 depending on the amount of occlusion. But it would actually reduce performance on the older GPU.

I have an example of this here: [url="https://github.com/progschj/OpenGL-Examples/blob/master/10queries_conditional_render.cpp"]https://github.com/p...onal_render.cpp[/url]

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
2

Share this post


Link to post
Share on other sites
[quote name='ill' timestamp='1342756724' post='4961165']
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?
[/quote]
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 [i]independently [/i]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 [i]more or less some kind of [/i]busy waiting (aka flushing the command queue, the CPU is not actually busy waiting, but your processing thread is paused at least).

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

[quote name='ill' timestamp='1342756724' post='4961165']
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?
[/quote]
Occ queries, much like geometry shaders, sounds awesome first, but fall short of your expectation once you understand their limitations. Edited by Ashaman73
1

Share this post


Link to post
Share on other sites
OK thanks guys. That really cleared it up. I can see how rendering to textures and all that avoids the stalls I thought were the same thing as using occlusion queries. The CPU side just has the texture or buffer name and doesn't need the data, while the GPU actually uses the data in them.
0

Share this post


Link to post
Share on other sites
People are talking about software occlusion culling. I think Frostbite guys had an article where they describe it. Basically, they maintain a low resolution software depth buffer - pretty much an array of floats. They generate this buffer by rendering big occlusion low res geometry that happens to be in front of the camera. For example big planes, "hidden inside" the walls, or low res version of the building itself. They are using software rasterizer to draw those triangles into the software depth buffer. So far, everything is done on the CPU side. When the buffer is filled with depth values from the potential occluders, they simply check other objects bounding volumes against that buffer and decide to draw or not to draw.
At least, that's the way I get it.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0