?/TD> |
Microsoft DirectX 9.0 |
Pixel shaders depend on registers to get vertex data, to output pixel data to the rasterizer, to hold temporary results during calculations and to identify texture sampling stages. There are several types of registers, each with a unique functionality. This section contains reference information for the input and output registers implemented by pixel shader version 1_X.
Registers hold data for use by the pixel shader. Registers are fully described in the following sections.
Versions | |||||
---|---|---|---|---|---|
Name | Type | 1_1 | 1_2 | 1_3 | 1_4 |
cn | Constant register | 8 | 8 | 8 | 8 |
rn | Temporary register | 2 | 2 | 2 | 6 |
tn | Texture register | 4 | 4 | 4 | 6 |
vn | Color register | 2 | 2 | 2 | 2 in phase 2 |
Pixel shader versions | 1_1 | 1_2 | 1_3 | 1_4 | 2_0 | 2_sw | 2_x | 3_0 | 3_sw |
---|---|---|---|---|---|---|---|---|---|
Constant Registers | x | x | x | x | x | x | x | x | x |
Shader pre-processing will fail CreatePixelShader on any shader that attempts to read from a temporary register that has not been written by a previous instruction. D3DXAssembleShader will fail similarly, assuming validation is enabled (do not use D3DXASM_SKIPVALIDATION).
Pixel shader versions | 1_1 | 1_2 | 1_3 | 1_4 | 2_0 | 2_sw | 2_x | 3_0 | 3_sw |
---|---|---|---|---|---|---|---|---|---|
Temporary Registers | x | x | x | x | x | x | x | x | x |
For pixel shader version 1_1 to 1_3, texture registers contain texture data, organized in four fixed-point values. Texture data is loaded into a texture register when a texture is sampled. Texture sampling uses texture coordinates to look up, or sample, a color value at the specified (u,v,w,q) coordinates while taking into account the texture stage state attributes. The texture coordinate data is interpolated from the vertex texture coordinate data and is associated with a specific texture stage. There is a default one-to-one association between texture stage number and texture coordinate declaration order. By default, the first set of texture coordinates defined in the vertex format is associated with texture stage 0.
For these pixel shader versions, texture registers behave just like temporary registers when used by arithmetic instructions.
For pixel shader version 1_4, texture registers (t#) contain read-only texture coordinate data. This means that the texture coordinate set and the texture stage number are independent from each other. The texture stage number (from which to sample a texture) is determined by the destination register number (r0 to r5). For the texld instruction, the texture coordinate set is determined by the source register (t0 to t5), so the texture coordinate set can be mapped to any texture stage. In addition, the source register (specifying texture coordinates) for texld can also be a temporary register (r#), in which case the contents of the temporary register are used as texture coordinates.
For this pixel shader version, texture registers contain texture coordinate data and are also available to texture addressing instructions as source parameters.
Pixel shader versions | 1_1 | 1_2 | 1_3 | 1_4 | 2_0 | 2_sw | 2_x | 3_0 | 3_sw |
---|---|---|---|---|---|---|---|---|---|
Texture Registers | x | x | x | x | x | x | x | x | x |
If the shade mode is set to D3DSHADE_FLAT, the application iteration of both vertex colors (diffuse and specular) is disabled. Regardless of the shade mode, fog will still be iterated by the pipeline if pixel fog is enabled. Keep in mind that fog is applied later in the pipeline than the pixelshader.
It is common to load the v0 register with the vertex diffuse color data. It is also common to load the v1 register with the vertex specular color data.
Input color data values are clamped (saturated) to the range 0 through 1 because this is the valid input range for color registers in the pixel shader.
Pixel shaders have read only access to color registers. The contents of these registers are iterated values, but iteration is performed at much lower precision than texture coordinates.
Pixel shader versions | 1_1 | 1_2 | 1_3 | 1_4 | 2_0 | 2_sw | 2_x | 3_0 | 3_sw |
---|---|---|---|---|---|---|---|---|---|
Color Registers | x | x | x | x | x | x | x | x | x |
The read port limit specifies the number of different registers of each register type that can be used as a source register in a single instruction.
Versions | |||||
---|---|---|---|---|---|
Name | Type | 1_1 | 1_2 | 1_3 | 1_4 |
cn | Constant register | 2 | 2 | 2 | 2 |
rn | Temporary register | 2 | 2 | 2 | 3 |
tn | Texture register | 2 | 3 | 3 | 1 |
vn | Color register | 2 | 2 | 2 | 2 in phase 2 |
For example, the color registers for almost all versions have a read port limit of two. This means that a single instruction can use a maximum of two different color registers (v0 and v1 for instance) as source registers. This example shows two color registers being used in the same instruction.
The register types are identified according to read-only (RO) capability or read/write (RW) capability in the following table. Read-only registers can be used only as source registers in an instruction; they can never be used as a destination register.
Versions | |||||
---|---|---|---|---|---|
Name | Type | 1_1 | 1_2 | 1_3 | 1_4 |
cn | Constant register | RO | RO | RO | RO |
rn | Temporary register | RW | RW | RW | RW |
tn | Texture register | See following note | RW | RW | RW |
vn | Color register | RO | RO | RO | RO |
Registers that are RW capable can be used to store intermediate results. This includes the temporary registers and texture registers for some of the shader versions.
The range is the maximum and minimum register data value. The ranges vary based on the type of register. The ranges for some of the registers can be queried from the device caps using GetDeviceCaps.
Name | Type | Range | Versions |
---|---|---|---|
cn | Constant register | -1 to +1 | All versions |
rn | Temporary register | - MaxPixelShaderValue to + MaxPixelShaderValue | All versions |
tn | Texture register | - MaxPixelShaderValue to + MaxPixelShaderValue | 1_1 to 1_3 |
tn | Texture register | - MaxTextureRepeat to + MaxTextureRepeat | 1_4 |
vn | Color register | 1_4 |
Early pixel shader hardware represents data in registers using a fixed-point number. This limits precision to a maximum of approximately eight bits for the fractional part of a number. Keep this in mind when designing a shader.
For pixel shader version 1_1 to 1_3, MaxTextureRepeat must be a minimum of one. For 1_4, MaxTextureRepeat must be a minimum of eight.