Graphics Reference
In-Depth Information
parameters to a shader entry point function marked as uniform will be placed inside an-
other default constant buffer, named $Params.
6.4.2 Texture Buffers
Since constant buffers are optimized for small sizes and uniform access patterns, they can
have undesirable performance characteristics in certain situations. One common situation
is an array of bone matrices used for skinning. In this scenario, each vertex contains one or
more indices indicating which bone in the array should be used to transform the position
and normal. On many hardware types, this access pattern will cause the threads executing
the shader program to serialize their access to the bone data, stalling their execution.
To rectify this issue, D3D11 allows a special type of constant buffer known as a
texture buffer. A texture buffer uses the same syntax for declaring constants and accessing
them in a shader program. However, under the hood, memory access will be done through
the texture fetching pipeline. Thus it will have the same cached, asynchronous access pat-
tern as a texture sample. Listing 6.15 demonstrates declaration and usage of a texture buffer
in a vertex shader program.
cbuffer VSConstants : register(cb0)
{
float4x4 WVPMatrix;
}
tbuffer Bones : register(t0)
{
float4x4 BoneMatrices[256];
}
float4 VSMain( in float4 VtxPosition : POSITION,
in uint Bonelndex : BONEINDEX ) : SV_Position
{
float4x4 boneMatrix = BoneMatrices [BoneIndex];
float4 skinnedPos = mul( VtxPosition, boneMatrix );
return mul( skinnedPos, WVPMatrix );
}
Listing 6.1 5. Using a texture buffer in a vertex shader program.
One important point to keep in mind when declaring a texture buffer is that it must
be mapped to a texture register, rather than a constant buffer register. Also, the host ap-
plication must create a shader resource view for the texture buffer and bind it through
*SSetShaderResources, as opposed to calling *SSetConstantBuffers. The texture buf-
fer resource itself must also be created as a texture resource, rather than a buffer resource.
Search WWH ::




Custom Search