Graphics Reference
In-Depth Information
ID3DllUnorderedAccessView* pView = 0;
HRESULT hr = g_pDevice->CreateUnorderedAccessView( pResource, &desc,
&pView );
return( pView );
}
Listing 2.12. A method for creating an unordered access view for a buffer or structured buffer resource.
The listing shows the setting of the D3D11_BUFFER_UAV_FLAG_C0UNTER flag, with the
append and raw flags commented out. This flag is used to provide a counter for the buffer
resource that is accessible through HLSL. This counter is operated by using the methods of
the HLSL buffer resource object, as described in the following section.
HLSL structured buffer resource object. Since this type of buffer resource is available
in the programmable shader stages, it is necessary to understand how it can be accessed
through HLSL. Fortunately, the resource object declaration and usage are fairly straightfor-
ward. A structured buffer requires that the corresponding structure be defined in the shader
program. Once a suitable structure is available, the structured buffer is declared with a
template-like syntax. A sample declaration is shown in Listing 2.13, taken from the fluid
simulation demo described in Chapter 12.
// Declare the structure that represents one fluid column's state
struct GridPoint
{
float Height;
float4 Flow;
};
// Declare the input and output resources
RWStructuredBuffer<GridPoint> NewWaterState : register( u0 );
StructuredBuffer<GridPoint> CurrentWaterState : register( t0 );
Listing 2.13. A declaration in HLSL of a standard buffer, a structured buffer, and read/write standard and
structured buffers.
In this code listing, we see that there are actually two different ways to declare a struc-
tured buffer—with StructuredBuffer<> and with RWStructuredBuffero. These two
forms represent the differences between a structured buffer bound to the pipeline with a
shader resource view (for read-only access) and with an unordered access view (for read and
write access), respectively. This is also indicated by the register statements, with the read/
write resource using a u# register and the read-only resource using a t# register. The choice
of the declaration type will determine which type of resource view the application will have
to use to bind the resource to the programmable shader stage for use in this shader program.
Once the object is declared, we can see that there is a simple way to interact with the
structured buffer from within HLSL. The individual elements are accessed with an array
Search WWH ::




Custom Search