I'm learning DirectX11 and since I'm beginning to write some shader code I don't understand the difference between binding slots and HLSL registers. The shader model 5.0 introduced the keyword register
, that I assumed is a synonym for slot but it's not.
What I know: I know that a register is 4 floats (16 bytes), and that a variable cannot straddle two registers so padding is added according to HLSL packing rules. I also know that if I compile two shaders (say, vertex and pixel shader) in from the same file the register specified are by shader usage so if I use register b0 two times everything compiles fine if resources are accessed by each shader indipendently.
but what about this:
cbuffer Transform : register(b0)
{
float4x4 worldMatrix;
};
cbuffer clipPlane : register(b1)
{
float4 clipPlane;
};
I bind my resources to the shader like this:
Game::GetInstance()->GetDeviceContext()->PSSetConstantBuffers(0, 1, &mCameraConstantBuffer);
Game::GetInstance()->GetDeviceContext()->PSSetConstantBuffers(1, 1, &mLightsConstantBuffer);
But if a register is 4 floats shouldn't the two resource overlap? What about sampler and shader resource registers?
Can someone provide me with a reference about the structure of these registers? MSDN documentation is really of no help sometimes.