• 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
mrheisenberg

Is automatic state monitoring necessary in a renderer?

6 posts in this topic

My renderer(based on D3D11) is currently built a lot like the one from the Hieroglyph3 engine.Its something like this:

class Renderer
{
     static ImmediateContextManager Immediate; //Encapsulates an immediate context, inherits from DeferredContextManager
     static vector<DeferredContextManager> Deferred; //Each one encapsulates a deferred context
    

    //ID3D11Device functionality - encapsulating methods, like CreateBuffer, CreateTexture, etc.
};

 

In the ContextManager each time you set some state it checks if it's been set before and this way it prevents redundant API calls.However that's quite a lot of if checks involved for each object I render.I thought about sorting objects by material type, but that means first I need to sort by shader, then by texture, then by vertex buffer and pretty much anything that would require a state change in the pipeline, and that's a huge amount of sorting each frame and sometimes I still end up with cases where a redundant API calls i made.Basically:

-for automatic state monitoring you get tons of branching each time you render an object
-for sorting you have to perform a huge amount of sorts to make sure everything turns out ok

The performance hits of both these methods get noticed with large amounts of objects on scene.The sorting actually comes up way heavier when I do it(I use Quicksort3), than just using the state monitoring method.Maybe I should make some combination of the two?

0

Share this post


Link to post
Share on other sites

You don't need to do multiple sorts in order to sort by multiple criteria. For each criteria, you just need to be able to map it to an integer with N bits. So lets say you were sorting by shader and by texture. If you come up with a system that assigns a unique 16-bit ID for each shader and and a similar system for assigning a 16-bit ID for each texture, you could combine those two into a single 32-bit integer. When combining you just want the higher-precedence criteria to go into the higher bits, and the lower-precedence criteria into the lower bits. So in your case if you want to sort first by shader then sort by texture, you would do sortID = (shaderID << 16) | textureID. Then you just sort one using your combined sort ID.

2

Share this post


Link to post
Share on other sites

Similar to MJP and LS above, I create and array of structs that contain a 32bit sorting key, and a 32bit draw item index, then sort that array using a radix sort.
After that, I iterate through all the draw items (using the sorted indices) and ignore any redundant states (hopefully there is now a lot of redundancy thanks to the sorting pass).

Ideally, you'd structure your code so that you can disable these features (maybe a #define) so that you can validate that it's actually an optimization.

Ok just one question - why a 32bit draw item index - do you mean an integer?Why not just a direct pointer to the draw item?Isn't that the fastest possible way?

Also a question about L.Spiro's link - he talks about depth sorting, but what if I plan to instance a lot of objects?I just add their transform matrices to the instance buffer and pass instanceCount to the draw call.Does the way they are depth sorted correspond to how the GPU draws them?Or does it just draw them in random order(when instancing)?

0

Share this post


Link to post
Share on other sites


do you mean an integer?

Yes.

Though my sortables always use more than that (try to at least fit it within a 64-bit integer though) plus the depth component, which is why I sort indices rather than the sortables themselves.

 


Why not just a direct pointer to the draw item?

Because what is used to sort is only a subset of what a mesh (or mesh part) actually is; sending a pointer to a mesh/sub-mesh off to a render queue means the render knows far more than it needs to know to do its job.  All it needs is a small structure or key to use for sorting.  Fill it out and send it one.  Don’t create unnecessary dependencies.

 


Does the way they are depth sorted correspond to how the GPU draws them?

They are drawn in the order specified by your instance buffer.  Except when drawing translucent objects, instancing is preferred over anything else as it implicitly means no shader swapping, texture swapping, vertex-buffer swapping, index-buffer swapping, etc.  Any gains by drawing front-to-back on opaque objects is completely trumped by this, so ignore depth.

 

 

L. Spiro

0

Share this post


Link to post
Share on other sites

Do you use command lists and deferred contexts?I imagine they would complicate the sorting if you split the renderables between the different deferred contexts on different threads.Like if you have a system that automatically distributes draw calls and it messes up the draw order.

Also to add - I'm not using a second vertex buffer as an instance buffer, I'm using a buffer bound as a SRV, so I suppose my method is less efficient.The people from DICE said this technique is used in Battlefield 2, but they didn't mention anything like draw order.

Edited by mrheisenberg
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