I'm new to Direct3D 11, transitioning from DX9.
Question: How do context->UpdateSubresource and shaders work together? I.e., how does the context know where in the shader to stuff the subresource?
Background:
I have several shaders with contant buffers using this #include:
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
cbuffer cbNeverChanges : register(b0)
{
float4 lightDir;
};
cbuffer cbChangeOnResize : register(b1)
{
matrix Projection;
};
cbuffer cbChangesEveryFrame : register(b2)
{
matrix View;
matrix World;
float4 vMeshColor;
};
I created 3 buffers, all from the same D3D11_BUFFER_DESC, changing only the ByteWidth, one to match in size each of the buffers in the shader. I update the corresponding buffer on resize, and per frame, as necessary. For example, when the window is resized, I update the context (buffer resize), followed by:
// Re-initialize the projection matrix
g_Projection = XMMatrixPerspectiveFovLH(XM_PIDIV4, width / (FLOAT)height, 0.01f, 100.0f);
CBChangeOnResize cbChangesOnResize;
cbChangesOnResize.mProjection = XMMatrixTranspose(g_Projection);
g_pImmediateContext->UpdateSubresource(g_pCBChangeOnResize, 0, NULL, &cbChangesOnResize, 0, 0);
Everything works. So I'm curious - when a shader is set, how do the appropriate buffers in the GPU get set from those context subresources?
Other than the size of the structure (e.g., CBChangeOnResize above), there appears to be no information for the context to map a particular subresource to a particular buffer in the GPU. How does it work?