Graphics Reference
In-Depth Information
bind flags. A byte address buffer must also be created with the D3D11_RES0URCE_MISC_
BUFFER_ALLOW_RAW_VIEWS miscellaneous flag. An example method for creating such a
resource is provided in Listing 2.16.
lD3DHBuffer* CreateRawBuffer( UINT size,
bool GPUWritable,
D3D11_SUBRES0URCE_DATA* pData )
{
D3D11_BUFFER_DESC d esc;
desc.ByteWidth = size;
desc.MiscFlagS = D3D11_RES0URCE_MISC_BUFFER_ALL0W_RAW_VIEWS;
desc.StructureByteStride = 0;
// Select the appropriate usage and CPU access flags based on the passed
// in flags
desc.BindFlags = D3D11_BIND_SHADER_RES0URCE | D3D11_BIND_UN0RDERED_ACCESS;
desc.Usage = D3D11_USAGE_DEFAULT;
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.16. A method for creating byte address buffer resources.
Resource view requirements. A byte address buffer can be used in two different ways. It
can be attached to the pipeline with a shader resource view for read-only access to the buf-
fer, or it can be attached to the pipeline with an unordered access view that provides read
and write access to the buffer. While the shader resource view provides read-only access,
it is available to all of the programmable shader stages. The unordered access view is only
available in the compute and pixel shader stages. The formats for the resource views must
be the DXGI_FORMAT_R32_TYPELESS in both cases. When an unordered access view is used,
it must also be created with the D3D11_BUFFER_UAV_FLAG_RAW to indicate that it would
supply access to data as a byte address buffer.
HLSL byte address buffer objects. Once the buffers have been created and appropriate
resource views are available for binding the resources to the pipeline, the HLSL program
Search WWH ::




Custom Search