Jump to content
  • Advertisement
Sign in to follow this  
360GAMZ

DX11 [DX11] Do I need to set all slots for SetConstantBuffers()?

This topic is 2591 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

The ID3D11DeviceContext methods ??SetConstantBuffers(), ??SetShaderResources(), ??SetSamplers(), and IASetVertexBuffers() all allow you to set 1 or more objects using the StartSlot, NumBuffers, etc. parameters. Do I need to explicitely clear (by passing in NULL for an object pointer) slots that were previously set to valid objects, but that I no longer need, each time I call one of the above methods()? Or does calling the method clear all slots outside the range of StartSlot to StartSlot-NumBuffers-1?

For example, if a pixel shader's constant buffers were set like this:

ID3D11Buffer *Buffs[4] = { pBuf0, pBuf1, pBuf2, pBuf3 };
pDC->PSSetConstantBuffers( 0, 4, Buffs );
// Draw some stuff here

When it's time to draw something else, I need to set the constant buffers again. But this time, I only need two. Can I do this:

ID3D11Buffer *Buffs[2] = { pBuf4, pBuf5 };
pDC->PSSetConstantBuffers( 0, 2, Buffs );
// Draw some stuff here

Will that clear out the pBuf2 and pBuf3 buffers that were bound the previous time? Or, do I need to explicitely unbind them like this:

ID3D11Buffer *Buffs[4] = { pBuf4, pBuf5, NULL, NULL };
pDC->PSSetConstantBuffers( 0, 4, Buffs );
// Draw some stuff here


Same question applies to ??SetConstantBuffers(), ??SetShaderResources(), ??SetSamplers(), and IASetVertexBuffers().

Share this post


Link to post
Share on other sites
Advertisement
Those methods are keeping slots intact when you are not overriding them, meaning that you need to explicitly set to null slots that you want to clear, as you specified:
[source]
ID3D11Buffer *Buffs[4] = { pBuf4, pBuf5, NULL, NULL };
pDC->PSSetConstantBuffers( 0, 4, Buffs );
[/source]
You can double check this behavior yourself by trying XXGetConstantBuffers method.

Share this post


Link to post
Share on other sites
Keep in mind also, that if a buffer is set but won't be used in a rendering pass, it is also ok as long as you don't need to try to modify the contents of the buffer. In other words, if you would only need to 'turn off' unused buffer, then you don't really need the extra API call.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!