Sign in to follow this  

DrawCall Batching

Recommended Posts

Hey guys, I wanted to get some advice on how you implement draw call merging. As of right now I handle batching dynamically. Elements are submitted to the rendering pipeline using a "CRenderObject".. this contains information such as the constant buffer holding the world transform/etc.. the vertex/index buffers... the material.. the drawcall values, i.e firstIndexID...indexCount..etc,  and any render flags necessary for shader passes. There are different Render Objects that have different rendering batching policies. For Example.. a CStaticMeshRenderObject is batched based on the source mesh, the submesh index, the material, and the render flags... For each generated batch, a CStaticMeshRenderObject allocates memory out of the structured buffer pool and fills the data with world transform info.. and etc. a CSkinnedMeshRenderObject is batched based on the same parameters of a CStaticMeshRenderObject.. but a CSkinnedRenderObject fills the structured buffer with skinning data. a CSpriteParticleRenderObject is batched based on material and render flags... and it fills  dynamic vertex and index buffers for rendering.. and etc... 


My Rendering pipeline is currently :

  Perform Frustum Culling 

  For Each visible Scene Object 

    - Collect all CRenderObjects 

 For each rendering pass 

    - For Each CRenderObject that supports batching ,

    - Batch based on per CRenderObject heuristic 

   -  For Each batched group of CRenderObjects , allocate the required data for the batch.

Lock all global pools for rendering 

 For each rendering pass

   - generate command lists 

   - etc...


The problem with this method is that it's done every frame, I wanted to know if anyone has a better method for drawcall batching that supports things such as skeletal mesh instancing. I know that ACU uses gpu instancing for their Crowd System.. but I don't know if they do it at higher level, or more like my low level implementation. Thank you.





Share this post

Link to post
Share on other sites

In my engine, I use the object pointer, sub mesh index, and then a special 'instanceId' which is usually zero. But in the case of skeletal animation, the instanceId becomes the id of the animation playing in my instanced animation manager. This makes the drawing object unique during sorting. And when the group goes to draw, the bone constants are set once, (I use a call back to the mesh instance to get these). As like any other object, a transform for each object is stuffed into a constant buffer, and the draw occurs. 


I batch my instances every frame. My thought being that the camera is always moving in a game, or if its not, objects are coming into and out of the frame all the time so the best fit instance list almost always changes. Last time I profiled figuring out batches was super super low amount of time compared to culling, sorting draw items and generating draw commands.

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