DirectX11 Constant Cache

  • Tags : directx11
  • time :

Constant cache

1 What is the function of constant caching

When rendering sprites, we use position, rotation, and scaling values to construct the sprite's world matrix. Once the world matrix is constructed, we use constant caching to pass it to the vertex shader for high-speed data transportation. Constant caching is used to send model view matrices to vertex shaders, enabling them to transform the input geometry.

2 How to create a constant cache

Constant cache, like all other DirectX 11 caches, is of type ID3D11BUFFER. A constant cache describes the BindFlags member of an object as D3D11 by setting the cache to describe it_ BIND_ CONSTANT_ BUFFER to create.

3 Example code for creating constant cache
    //create constant cache 
D3D11_BUFFER_DESC constDesc;
ZeroMemory( &constDesc, sizeof( constDesc ) );
constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constDesc.ByteWidth = sizeof( XMMATRIX );
constDesc.Usage = D3D11_USAGE_DEFAULT;
d3dResult = d3dDevice_->CreateBuffer( &constDesc, 0, &mvpCB_ );
if( FAILED( d3dResult ) )
{
  return false;
}