Graphics Reference
In-Depth Information
6.5 Resource Objects
HLSL provides several types of resource objects that allow HLSL shader programs to
interact with the various resource types available in D3D11. Each object type exposes the
functionality of the resource through a set of methods that can be called on a declared object
of that type. Most of these methods provide a means of reading data from the resource when
given an address or index, while some also provide information about the resource itself. In
the case of read/write resources, methods are also exposed for writing to the resource data.
All of the read-only resource objects correspond to a type of shader resource view,
while the read/write resource objects correspond to a type of unordered access view.
As with constant buffers, each declaration of a resource object is mapped by the com-
piler to a register index that corresponds to the slot passed to *SSetShaderResources,
OMSetRenderTargetsAndUnorderedAccessViews, or CSSetUnorderedAccessViews.
Like constant buffers, the register can be manually specified when declaring the resource
object, using the register keyword. For shader resource views the registers are t0 through
tl27, and for unordered access views the registers are u0 through u7. Refer to Chapter 2 for
more information regarding resources, and how they are bound to the pipeline.
6.5.1 Buffers
The buffer resource objects correspond to a shader resource view created for an
ID3D11Buffer resource. For the most part, they have a very simple interface that con-
sists of methods for obtaining the size of the resource, a Load method for reading a value
when given an address, and an array operator for reading a value when given an index.
In cases where a buffer can contain different types, the data type returned by the Load
method or array operator is specified using a template-like syntax. Listing 6.16 demon-
strates declaration of a standard Buffer object with float4 return type, corresponding to
DXGI_FORMAT_R32G32B32A32_FLOAT.
Buffer<float4> Float4Buffer : register(t0) ;
Listing 6.16. Declaring a float4 buffer.
Buffer
The Buffer object is the simplest resource object type in HLSL. A Buffer provides read-
only access to its data through the Load method and an array operator, both of which return
the data at the specified index. It also provides the GetDimensions method for querying
the size of the buffer in bytes.
Search WWH ::




Custom Search