0
votes

I'm creating a shader management system instead of using the Effects 11 library. I have a couple of questions about resource management for shaders.

If I have a Constant Buffer set to a certain register in the shader code, does it need to be set to that register when I set it on the device? What if I have multiple shaders that use that register?

Are constant buffers maintained in memory between draws, or are they cleared? Say for example I have a constant buffer that is not changed from the last draw, do I need to set it again?

Is it slower to set constant buffers one at a time or all at once?

Thanks in advance.

1

1 Answers

2
votes

Yes, you need to set to that register, think of it as a constant buffer slot.

Yes, it will keep there until you switch it by another.

"Is it slower to set constant buffers one at a time or all at once?"

What do you mean by "all at once"?

Anyway, check this nvidia presentation for great info on cbuffer management: https://developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf

Note that pixel shaders and vertex shaders (different shader types) use different registers EVEN if you are using the exactly same "variable" on the hlsl code. Thats handled for you, the thing to note is that to update the cbuffer to the register, you use the pixel shader version of the d3d function(VSSetConstantBuffer vs PSSetConstantBuffer, etc.). Thats for all types of shaders of course.

So for example, in the hlsl code, you can have 2 constant buffers using the same slot(register), BUT, remember to not use both on the same shader..Or, again, you can use the same constant buffer on both shaders, just remember that its not really the same.