For example, instead of:
VertexShader.hlsl
cbuffer VSPerInstance : register(b0){
matrix World, View, Projection;
};
PixelShader.hlsl
cbuffer PSPerInstance : register(b0){
float4 AmbientColor;
float4 DiffuseColor;
float4 SpecularColor;
float4 EmissiveColor;
};
I could have:
MyInclude.hlsl
cbuffer PerInstance : register(b0){
matrix World, View, Projection;
float4 AmbientColor;
float4 DiffuseColor;
float4 SpecularColor;
float4 EmissiveColor;
};
In a include file, when updating the constant buffer this would reduce the number of calls to ID3D11DeviceContext::Map
, although I would still have to copy the same amount of bytes and set the constant buffer for each stage, like: ID3D11DeviceContext::VSSetShader
, ID3D11DeviceContext::PSSetShader
, etc.
So my question is, is it even legal to set the same constant buffer in multiple shader stages? And is there anything negative about it that I should reconsider? Since I started learning Direct3D programming, all the examples that I have seem use individual buffers for each stage as in the first example, so I don't know if this is a good practice.
Just to make things clearer, I'm still using more than one constant buffer anyway, I have one constant buffer for each frequency of update, one for each instance, for each partition, for each draw call...