INSTRUCTION ORDER AND INSTRUCTION COUNTS

The order in which instructions appear in a pixel shader is determined by the shader version. There are five different types of instructions that can be in a pixel shader. The very first instruction must be the shader version declaration, followed by the constant definitions. The phase instruction is found only in PS 1.4 shaders. None of these instructions count toward the total number of instructions; only the two remaining types, the texture addressing and the arithmetic instructions, count toward the total instruction count.

DirectX 9 update

 

Significant changes were made to pixel shaders between versions 1.3 and 1.4 due to the addition of the phase instruction in PS 1.4. The phase instruction was removed for PS 2.0 shaders and arithmetic and texture addressing instructions could be mixed.

Note 

Destination registers are independent of the read port count restrictions.

For Pixel Shaders 1.0 Through 1.3

Texture addressing instructions must precede the color-blending instructions. There can be a maximum of eight arithmetic instructions and a maximum of four texture instructions. For PS 1.0, there's an additional limitation in that the total number of instructions is limited to eight (Figure 8.1).

click to expand
Figure 8.1: Constant, texture addressing, and arithmetic instructions for pixel shaders 1.0 through 1.3.

The syntax for the texture address computation operation is included within the shader program itself in the form of texture declarations. These control how address perturbation operations are applied to the color values sampled from the textures during their preloading into the temporary register file for use in the body of the pixel shader.

For Pixel Shaders 1.4

Order is much more significant for PS 1.4 with the introduction of the phase instruction, and the number of instructions that can be in each phase is limited as well. If there is no phase instruction, then everything after the vs and def instructions is treated as being in phase two. There can be only one phase instruction in a shader.

Phase one and two instructions must be in the order shown in Figure 8.2, and each can consist of up to six texture addressing instructions and up to eight arithmetic instructions.

click to expand
Figure 8.2: Phase instruction in pixel shaders 1.4.

Thus you can have up to a total of 28 instructions in a PS 1.4 shader, not including the version, define, or phase instructions. There are also more restrictions on which registers can be the source or destination registers. This can vary between the phase of the pixel shader and the individual instruction. See the reference section for an instruction about which registers can be used in each phase. After the phase instruction, the alpha component of the temporary registers is lost, and the alpha channels are uninitialized.

For Pixel Shaders 2.0

There can be a maximum of 32 texture instructions and 64 arithmetic instructions, and they can be in any order in the shader.



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net