Jump to content

  • Log In with Google      Sign In   
  • Create Account


Constant buffers for static geometry


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Promit   Moderators   -  Reputation: 6621

Like
0Likes
Like

Posted 11 February 2013 - 11:16 AM

I'm having trouble finding resources on what the best way to handle this particular situation is. I've got a lot of static world geometry that is divided into objects with their own per-object constants. The constants are mainly the world matrix and a handful of other vectors, ie very small. In GL or 11.1 I'd create a single giant constant buffer and bind ranges for rendering. I'm not sure how to handle it in 11, though. There's a couple ways I can think of doing it:

1) Thousands of tiny immutable constant buffers, bind appropriate one for each draw call.

2) Just a few dynamic buffers, rewrite them for each draw call.

3) Create giant constant buffer(s), fill up a dynamic constant buffer each draw call with an index into the giant one.

 

I'm inclined to #1 right now, doesn't seem to be any advice on constant buffer sizing out there.


Edited by Promit, 11 February 2013 - 05:28 PM.


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7822

Like
1Likes
Like

Posted 11 February 2013 - 12:01 PM

D3D11 has a max of 4096 shader-addressable float4s in a cbuffer, but in terms of performance and sizing it's not a limit I've personally ever come close to.  That's not relevant to the rest of my post because I'm going to suggest something completely different here.

 

An option 4 you may be interested in is to (ab)use instancing to get similar behaviour to D3D11.1 - under this setup you'd create a large vertex buffer containing all of your per-object data, set it to a stream defined for D3D11_INPUT_PER_INSTANCE_DATA with a step rate of 1, then use the Draw*Instanced calls to draw a single instance of each object (i.e. InstanceCount 1 and StartInstanceLocation as appropriate to index into the buffer).  Caveat is that I have no idea how this would perform by comparison to the other options (I suspect however that it may even be substantially faster than your D3D11.1 method as you only need to bind the buffer once per frame rather than binding a new range of it per object, but I honestly don't know), but it would nicely avoid the need to upload lots of dynamic data as well as sidestep the max cbuffer size.


Edited by mhagain, 11 February 2013 - 12:26 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 Jason Z   Crossbones+   -  Reputation: 4905

Like
2Likes
Like

Posted 11 February 2013 - 01:57 PM

Hi Promit,

 

If all of this data is immutable, then why not just set your code up to work both ways and try it out?  The difference in the code can be driven by your shader files, which is where you will be defining your constant buffer sizes, so it should just be a matter of modifying your shader files accordingly to be big or small.

 

Unfortunately, I think the reason you can't find a best practice is because it probably doesn't exist - you are trading context calls (with lots of small buffers) with memory access latency (when using very large buffers) and the performance of those will likely be driver and GPU dependent.  So I would have to recommend putting it to the test and see how it works in your own environment and scenes.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS