Graphics Reference
In-Depth Information
Figure 2.17. A particle system implementation using "append" and "consume" buffers.
buffer. Since each particle is updated in isolation from the others, the particle order within
the buffer is completely irrelevant to the updating procedure. In addition, since the buffers
maintain a count of the number of elements contained in the buffers, the update procedure
can add or remove particles as needed. The buffers' internal counter tracks the total number
of elements that are currently residing in the buffer. Because of this, there is no need to
synchronize between GPU threads for accessing the correct number of particle elements.
This particle system example is depicted in Figure 2.17.
Creating append/consume buffers. To create a buffer that can be used as an append
or consume buffer, we require a slightly more restrictive creation process. Since the buf-
fers are intended for read/write access by the programmable shader stages, we require the
D3D11_USAGE_DEFAULT usage flag to be used. In addition, the bind flag must include the
D3D11_BIND_UN0RDERED_ACCESS flag to allow use of an unordered access view and will
typically also include the D3D11_BIND_SHADER_RES0URCE flag as well. This also indicates
that the CPU is not capable of directly accessing the buffer contents, due to the default us-
age flag. The remainder of the configurations can be selected as we have already seen in
the "Buffer/Structured Buffer Resources" section. An example creation method is shown
in Listing 2.14.
ID3DllBuffer* CreateAppendConsumeBuffer( UINT size,
UINT structsize,
D3D11_SUBRES0URCE_DATA* pData )
{
D3D11_BUFFER_DESC desc;
desc.ByteWidth = size * 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
desc.BindFlagS = D3Dll_BIND_SHADER_RESOURCE | D3Dll_BIND_UNORDERED_ACCESS;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.CPUAccessFlags = 0;
Search WWH ::




Custom Search