Graphics Reference
In-Depth Information
{
// Handle the error here...
// Resources can't be writable by both CPU and GPU simultaneously!
}
// 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.10. A method for creating a structured buffer.
We split the size information into a count of the number of structures to include in the
buffer, and a structsize parameter to indicate the size of each structure in bytes. These
are then used to calculate the overall byte width of the buffer. In addition, each of the three
usage scenarios discussed above is represented in the code listing; they differentiate them-
selves with the CPU access, usage, and bind flags.
Resource view requirements. We have already seen that the only resource views that can
be used with a buffer or structured buffer are the shader resource view and the unordered
access view. In fact, these are the only ways to bind these buffers to the pipeline. For stan-
dard buffer types, the format must be provided directly in the SRV description structure.
For structured buffer resources, the format should be set to DXGI_F0RMAT_UNKNOWN, since
there won't be a DXGI format available to match all possible structure types. Instead, the
format is derived from the HLSL structure declaration in the shader program, and the size
of the elements is provided by the application when the buffer resource is created.
The shader resource view description structure for buffer resources requires specifi-
cation of the beginning element, and of the number of elements to include in the view. This
may select the entire range of elements in the buffer, or it can be used to select a subset of
the total resource. This effectively maps the selected data to the [0, width-1] range when
viewed from HLSL, with all other accesses considered out of bounds. These values are
specified in the D3D11_BUFFER_SRV structure, as shown in Listing 2.11.
ID3DllShaderResourceView* CreateBufferSRV( ID3DllResource* pResource )
{
D3D11_SHADER_RES0URCE_VIEW_DESC desc;
Search WWH ::




Custom Search