D3DBook:State Objects

From GDWiki
Jump to: navigation, search

Contents

State Objects

Direct3D 10 use state objects to control the non programmable parts of the pipeline. As the control different parts the five state object types differs in their details but there are some general aspects that are valid for every type. Like the Direct3D resources every state object is a full COM object with its own reference counter. It needs to be explicit created and destroyed. As creation could be an expensive operation it should be done in advance like memory based resource and shader creation. But there is a limit how much state objects could be created per device. Direct3D 10 allows you to have 4096 state objects from any type. To make it easier to stay inside this limitation Direct3D does only create a new state object that contented against this limit if you haven't already created an object with the same configuration. In the case there is already a matching state object the create function will return it. You still have to release it at the end because the internal reference count would be increased.

Input Layout

The Input Layout state object is a special case in this group of five. While the other four are only containers for multiple states the input layout is more complex. It is responsible to manage the transfer from the assigned vertex buffers to the input registers of the vertex shader. To do this job it needs detailed information's about the layout of the vertex buffers and the input registers that the shader use. To make your life easier the create method will extract the necessary register information direct from a provided shader in its byte code form. But the vertex buffer layout needs still to be described with an array of D3D10_INPUT_ELEMENT_DESC structures. Each array element stands for one entry in the buffers. Beside of the semantic information that is necessary to bind everything together the D3D10_INPUT_ELEMENT_DESC structures contains the information about the input assembler slot were the buffer will be assigned, the format of the data and the offset from the beginning of the vertex. Additional it provides the option to use the same values for multiple instances.

Image:D3D10_gif_12.gif


Figure 12: Input Layout State.

The semantic information's that are used to link the vertex data to the shader inputs are stored as human readable strings. During the creation process Direct3D 10 will look up the provided element array to find for each of the shader input registers the matching counterpart. Then it will pass this information to the driver which will build a fixed transfer description for later usage. This will free Direct3D 10 to build the right linking every time something is drawn but it force the application to create an own input layout for every used combination of vertex buffer layouts and shader input registers.

Rasterizer

The rasterizer state object is a collection of 10 states that control the behavior of the rasterizer pipeline state. As the rasterizer is responsible to finally build the primitives from the provided vertices and convert them to pixel the states cover this whole process.

Image:D3D10_gif_13.gif


Figure 13: Rasterizer State.

Depth Stencil State

Every pixel that survives the pixel shading process will end up in the output merger were one part of the following operations are done from a depth stencil unit that is controlled by a depth stencil state object. This object contains three states that control the depth operations and additional eleven states for the two-side stencil operations.

Image:D3D10_gif_14.gif


Figure 14: Depth Stencil State.

As the stencil unit requires a reference value that is not part of the state object you need to provide it every time the depth stencil state object is assigned to the pipeline with OMSetDepthStencilState.

Blend State

The second part of the output merger stage is configured with a blend state object. These collections of nine states control how the up to 8 pixel shader outputs should be stored in the assigned target resources.

Image:D3D10_gif_15.gif


Figure 15: Blend State.

Again this unit needs more states than the state object contains. They blend factor and multi sample mask need to provide during the activation of the state object with OMSetBlendState.

Sampler State

The sampler state object is another special kind of state object. As every other one it is responsible to control a fixed function unit in the pipeline but it is used together with the programmable shader stages. Another peculiarity is that every one of the three shader stages provides 16 slots for sampler stages objects. Therefore it is the only state object type that can have more than one active object at the same time. The ten states it groups together control how a sampler unit that is part of a shader unit should read the data that is accessible over a shader resource view.

Image:D3D10_gif_16.gif


Figure 16: Sampler State.
Personal tools