Jump to content
  • Advertisement
Sign in to follow this  

Constant buffer updating strategy for DirectX10/11

This topic is 2766 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 currently designing a small rendering engine with DirectX11.

In DirectX 10/11, we must update world, view, projection transforms to a constant buffer, and set the constant buffer to device slot before drawing it.

There are two constant buffer updating strategies coming into my mind:

1. Allocate a constant buffer for each rendering object. Each object update its world transform to its constant when it is changed. Then, we just set different constant buffers to the device when rendering different objects.

2. Allocate a global constant buffer. Each object update its world transform to the global constant buffer just before drawing.


Which one is better?

Share this post


Link to post
Share on other sites
Advertisement
I think what he is asking, is should he use one constant buffer for each mesh to be rendered or should he use one constant buffer for all meshes and update the values in between the draw calls. If that is the case, then my opinion is that using one constant buffer for every object is probably going to use more video memory than is practical (depending on the number of objects of course).

My advice is to test out using a single buffer for all objects and update in between draw calls (this is what I currently use with the Hieroglyph 3 engine). Then make up a test version that uses individual constant buffers and compare performance. My bet is that the work done in a draw call is significantly more expensive than the cost of uploading a few matrices to a CB, which effectively neutralizes the issues with updating. If it does show up to be a problem, you could always use a small number of CBs and update them in a ring buffer for each draw call to get rid of any latency in the updates between draw calls.

Probably just using one buffer is fine though [grin].

Share this post


Link to post
Share on other sites
With constant buffers, what you really do is avoid changing their contents as much as possible. This is why the general advice is to group constants by how often you change them, so that you can avoid changing constant buffers where the constants only change once per frame (like your camera matrices, for instance).

With the case of a world matrix or other data that changes for each object you draw, you're going to end up setting it before each draw. Not much you can do about that, unless you have meshes that are static and will always have the same world matrix in which case you could create a constant buffer for each of them and never have to change it. But for your dynamic meshes, it will probably just waste resources if you create a constant buffer per mesh since it's going to change every draw call anyway.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!