My vertex shader has both a constant buffer and a variable buffer. When I go to Map() and set their data, however, I have no idea how to tell the two buffers apart.
My code is as follows, and you can see that I'm using "Subresource 1" which is NOT what I want - I really want buffer 1, or slot 1, or something to say "the second of the two buffers":
virtual HRESULT SetVSShaderConstants() override
{
HRESULT hr = S_OK;
auto pd3dImmediateContext = DXUTGetD3D11DeviceContext();
D3D11_MAPPED_SUBRESOURCE MappedResource;
V(pd3dImmediateContext->Map(_pVSCBNeverChanges, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource));
auto pCB = reinterpret_cast<VSCBBilliardBallNeverChanges *>(MappedResource.pData);
pCB->_cameraPosition = _vertexShaderConstants._cameraPosition;
pd3dImmediateContext->Unmap(_pVSCBNeverChanges, 0);
return hr;
}
virtual HRESULT SetVSShaderVariables() override
{
HRESULT hr = S_OK;
auto pd3dImmediateContext = DXUTGetD3D11DeviceContext();
D3D11_MAPPED_SUBRESOURCE MappedResource;
V(pd3dImmediateContext->Map(_pVSCBChangesEveryFrame, 1, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource));
auto pCB = reinterpret_cast<VSCBBilliardBallChangesEveryFrame *>(MappedResource.pData);
pCB->_viewMatrix = _vertexShaderVariables._viewMatrix;
pCB->_worldInverseTransposeMatrix = _vertexShaderVariables._worldInverseTransposeMatrix;
pCB->_worldMatrix = _vertexShaderVariables._worldMatrix;
pCB->_worldViewProjectionMatrix = _vertexShaderVariables._worldViewProjectionMatrix;
pd3dImmediateContext->Unmap(_pVSCBChangesEveryFrame, 1);
return hr;
}
And here are the two buffers in the vertex shader itself:
cbuffer VSCBBilliardBallNeverChanges : register (b0)
{
float4 _cameraPosition;
}
cbuffer VSCBBilliardBallChangesEveryFrame : register (b1)
{
float4x4 _worldMatrix;
float4x4 _worldInverseTransposeMatrix;
float4x4 _worldViewProjectionMatrix;
float4x4 _viewMatrix;
};