Jump to content
Posted 05 December 2011 - 07:30 PM
Posted 05 December 2011 - 09:08 PM
Posted 05 December 2011 - 11:41 PM
Posted 06 December 2011 - 07:45 AM
Posted 06 December 2011 - 10:33 AM
Let's say I have 500 draw calls per frame and all 500 draw calls use the same shader and that shader uses one constant buffer. Let's also assume that the data in the constant buffer needs to be built dynamically for each draw call. What would be the most desirable way to update the constant buffers, in terms of efficiency?
A) Create a single constant buffer and call Map/Unmap on that same constant buffer before each draw call.
B) Create 500 constant buffers, one for each draw call, and call Map/Unmap on the draw call's own constant buffer.
C) Or, another idea?
I know that for (A) the driver will rename the buffer each time I Map it, discarding the previous contents which is fine. But is it ok to expect that the driver can handle hundreds or even thousands of renames per frame? And I assume the rename process consumes some time, too.
On the other hand, (B) avoids the renaming and any associated overhead at the expense of possibly more video memory being consumed (500 constant buffers, even if fewer draw calls are actually used) and more code complexity.
Posted 06 December 2011 - 01:22 PM
Is there any reason you can't generate the data up front, before issuing draw calls, then build one large cbuffer and index in the shader based on an instance ID? Maybe split this up over a few buffers depending on cbuffer size so you aren't updating a massive chunk of data in one go.
So; [generate all data] -> [bind] -> [draw objects as required with indexing]
Generating data at render time seems like Bad Voodoo to me anyway; render time should just be rendering, sort your data out before hand.
Posted 06 December 2011 - 04:29 PM
Posted 06 December 2011 - 06:25 PM
Posted 06 December 2011 - 06:49 PM
Posted 06 December 2011 - 06:55 PM