Graphics Reference
In-Depth Information
texture lookup operations. All major GPU designs include additional hardware functional-
ity to implement these sampling operations, so using them is generally much faster than
trying to emulate the same sampling process from within a programmable shader.
Options that can be specified with a sampler state object include the texture coordi-
nate addressing mode used to determine the location to be sampled, the type of filtering to
be performed during the sampling process, several LOD parameters, a border color to line
the texture with, and a comparison function that can be used to modify the data returned by
the sampling functions. This provides quite a range of different types of sampling that can
be performed, and these options can have quite a potent effect on the performance of a tex-
ture sample operation. It is thus important to properly configure the object for the intended
use case of the texture being sampled.
Sampler state objects are actually not resources in the same sense as buffers and
textures, but they are managed like resources in the programmable pipeline, so we are
including them here. We will explore them in more detail in the following sections by first
considering how they are created and then briefly reviewing how they are used in the pro-
grammable shader stages.
Creating Sampler State Objects
Before looking at the details of how a sampler object is used in a shader program, we first
need to understand what exactly it is capable of doing. This is best described by looking
at the process used to create the sampler object, since all of its various options must be
specified during the creation process. Like the other object types we have seen throughout
this chapter, a sampler state object is created by filling out a description structure and then
passing that structure to a device method. In this case, we use the ID3DllDevice:: Create
SamplerState() method to generate a ID3DllSamplerState object. The description
structure is shown in Listing 2.47.
struct D3D11_SAMPLER_DESC {
D3D11_FILTER Filter;
D3D11_TEXTURE_ADDRESS_M0DE AddressU;
D3D11_TEXTURE_ADDRESS_M0DE AddressV;
D3D11_TEXTURE_ADDRESS_M0DE AddressW;
FLOAT
MipLODBias;
UINT
MaxAnisotropy;
D3D11_C0MPARIS0N_FUNC
ComparisonFunc;
FLOAT
BorderColor[4];
FLOAT
MinLOD;
FLOAT
MaxLOD;
}
Listing 2.47. The D3D11_SAMPLER_DESC structure and its members.
Search WWH ::




Custom Search