Jump to content
  • Advertisement
Sign in to follow this  
infinitas

How should I organise state/draw/etc calls? (is this batching?)

This topic is 3830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not entirely sure what batching is, I've never been specifically told, but judging from it's name; it's organising your renderings so you only have to do a specific call as few times as possible. I was wonder what calls cause the biggest performance hit. i.e. Would it be better to order by vertex type? Or by textures used? Or by blendings? Or by ...? etc. Obviously it's going to be different under different circumstances, but I was wondering what other people do, how other people order their rendering loops, and what techniques do people use to ensure maximum throughput. I was thinking about taking all my entities that wish to be rendered into an ordered list, basing the order on certain properties (which I/V Buffer they use, which texture(s) they use, etc). Then looping through it and rendering away, only updating the list when a new entity is created or some such way. What do other people do? Edit: Sorry, not really the right forum; I was going to ask about specific DX10 calls and their "weights", but I ended up generalising it (though that is my goal to figure out).

Share this post


Link to post
Share on other sites
Advertisement
Batching refers to drawing as many triangles as you can using a single "Draw" call. For modern graphics card (shader model 3.0 and shader model 4.0) the preferred method of batching is to use hardware instancing. There are samples in the SDK that demonstrate how to use instancing to render multiple instances of the same mesh, both for D3D9 and D3D10.

Share this post


Link to post
Share on other sites
Ahh... I'm already doing that, lol. Meh.
But what about the rest of the things?
How do people organise what gets called in what order? Do people just render things as they want in no order? Or do people order them based on something some how?

Share this post


Link to post
Share on other sites
It's commonly done by blending mode, then by depth (if required), then by shader, then by texture.

We sort by blending mode first because there are two completely separate paths for rendering opaque and translucent objects. Then we sort by depth if required (if rendering non-opaque objects), because for that to work correctly, we absolutely have to preserve stacking order. Then we sort by shader, because it's more likely for lots of objects to share a shader rather than texture, and also because changing shader is usually more expensive than changing texture. Then we sort by texture.

Note that shaders have shader constants that can change, so you would have to sort by 'shader state' or 'shader instance' or whatever, not just by shader pointer. In other words, each time you change one of the shader constants, you would have to break the batch. Unless of course, you design your game to never need to do that more than once per frame per shader.

The best design practice is to create something like a 'Graphics' class, that takes care of all the low level batching in the most efficient way possible. That way, once you write and debug it, you can just send a bunch of polygons with arbitrary textures, blending modes and shaders and have all the rendering taken care of without worrying.

Then you can also do cool stuff like displaying how many triangles were rendered, how many textures were used, how many batches had to be made, the total size of all active textures, whether they all managed to fit on the video card, how long the rendering took, fill performance, etc, etc. Enough data to make intelligent decisions about what your engine can and cannot do, so your artists know what is possible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!