Graphics Reference
In-Depth Information
some type of physical simulation that is later used for rendering a representation of the re-
sults of the simulation. In this case, the GPU will require read and write access to the buffer
so that it can read the contents, perform some updates, and then write the results back into
the buffer. Each of these three scenarios will require different settings for the usage, CPU
Access, and bind flags used when creating the buffer.
In addition to these flags, we must also provide some additional size information
when using structured buffers. All types of buffers have required the specification of the
ByteWidth parameter, which indicates the desired size of the buffer in bytes. Structured
buffers require us to also specify the size of the structure element being used. This in-
formation is used as the step size when the resource is accessed by one of the program-
mable pipeline stages. The other requirement for using structured buffers is to indicate that
the buffer resource will indeed be used as a structured buffer. This is done by setting the
D3D11_RESOURCE_MISC_BUFFER_STRUCTURED miscellaneous flag. A typical sample cre-
ation is shown in Listing 2.10.
ID3DllBuffer* CreateStructuredBuffer( UINT count ,
UINT structsize,
bool CPUWritable,
bool GPUWritable,
D3D11_SUBRES0URCE_DATA* pData )
{
D3D11_BUFFER_DESC desc;
desc.ByteWidth = count * structsize;
desc.MiscFlagS = D3D11_RES0URCE_MISC_BUFFER_STRUCTURED;
desc.StructureByteStride = structsize;
// Select the appropriate usage and CPU access flags based on the passed in flags
if ( !CPUWritable && IGPUWritable )
{
desc.BindFlagS = D3D11_BIND_SHADER_RES0URCE;
desc.Usage = D3D11_USAGE_IMMUTABLE;
desc.CPUAccessFlags = 0;
}
else if ( CPUWritable && IGPUWritable )
{
desc.BindFlagS = D3D11_BIND_SHADER_RES0URCE;
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
}
else if ( ICPUWritable && GPUWritable )
{
desc.BindFlagS = D3D11_BIND_SHADER_RES0URCE |
D3D11_BIND_UN0RDERED_ACCESS;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
}
else if ( CPUWritable && GPUWritable )
Search WWH ::




Custom Search