How is constant buffer allocation handled in DX11?

Posted by Marek on Game Development See other posts from Game Development or by Marek
Published on 2012-03-22T12:36:20Z Indexed on 2012/03/22 17:43 UTC
Read the original article Hit count: 305

Filed under:
|

I'm starting with DX11 and I'm not sure if I'm doing the things right. I want to have both pixel and vertex shader program in one file. Both use some shared and some different constant buffers. So it looks like this:

Shader.fx

cbuffer ForVS : register(b0) 
{
    float4x4 wvp;
};

cbuffer ForVSandPS : register(b1) 
{
    float4 stuff;
    float4 stuff2;
};

cbuffer ForVS2 : register(b2) 
{
    float4 stuff;
    float4 stuff2;
};

cbuffer ForPS : register(b3) 
{
    float4 stuff;
    float4 stuff2;
};  

....

And in code I use

mContext->VSSetConstantBuffers( 0, 1, bufferVS);
mContext->VSSetConstantBuffers( 1, 1, bufferVS_PS);
mContext->VSSetConstantBuffers( 2, 1, bufferVS2);

mContext->PSSetConstantBuffers( 1, 1, bufferVS_PS);
mContext->PSSetConstantBuffers( 3, 1, bufferPS);

The numbering of buffers in PS is what bugs me, is it alright to bind random slots to shaders (in this example 1 and 3)? Does that mean it still uses just two buffers or does it initialize 0 and 2 buffer pointers to empty?

Thank you.

© Game Development or respective owner

Related posts about c++

Related posts about directx