Graphics Reference
In-Depth Information
finally be drawn with the ID3DllDeviceContext: :DrawInstancedIndirect() method,
with a single instance provided. This would allow the GPU-generated content within the
AppendStructuredBuffer to be rendered directly, without the CPU ever knowing how
many items exist within the buffer itself.
Creating indirect argument buffers. Creating a indirect argument buffer is quite simi-
lar to the other creation methods we have seen before. It also follows the same usage
control semantics that we have seen. In general, if we want to be able to generate the
data on the GPU and then subsequently use the buffer as input to the pipeline, we must
select the default usage flag to provide both read and write access to the GPU. In addi-
tion, to indicate to the runtime that this buffer will be used for indirect arguments, the
D3D11_RES0URCE_MISC_DRAWINDIRECT_ARGS miscellaneous flag must be specified. The
ByteWidth parameter should be a 4-byte multiple, since the input arguments to the draw
and dispatch methods are all 32-bit variables. A sample method for creating these buffers
is provided in Listing 2.18.
ID3DllBuffer* CreateIndirectArgsBuffer( UINT size, D3D11_SUBRES0URCE_DATA* pData )
{
D3D11_BUFFER_DESC desc;
desc.ByteWidth = size;
desc.MiscFlagS = D3Dll_RES0URCE_MISC_DRAWINDIRECT_ARGS;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.StructureByteStride = 0;
desc.BindFlags = 0;
desc.CPUAccessFlags = 0;
// Create the buffer with the specified configuration
ID3DllBuffer* pBuffer = 0;
HRESULT hr = g_pDevice->CreateBuffer( &desc, pData, &pBuffer );
if ( FAILED( hr ) )
{
// Handle the error here...
return( 0 );
}
return( pBuffer );
}
Listing 2.18. A sample method for creating a buffer resource to be used as an indirect arguments buffer.
Resource view requirements. An indirect argument buffer is used in two different phases.
First, it is loaded by the GPU or CPU with the data that will eventually represent the pa-
rameters to a pipeline invocation call. Second, it is passed as input to a draw/dispatch call
by the CPU. The first case may require a resource view, while the second case does not.
Search WWH ::




Custom Search