D3DXSHADER Flags

The D3DXSHADER flags are used for parsing, compiling, or assembling shaders.

Parser flags

Parse time flags are only used by the effect system (before effect compilation) when you create an effect compiler. For example, you could create a compiler object with D3DXSHADER_PACKMATRIX_COLUMNMAJOR, and then use that compiler object repeatedly with different compiler flags to generate specialized code.

Constant Description
D3DXSHADER_PACKMATRIX_COLUMNMAJOR
/Zpc
Unless explicitly specified, matrices will be packed in column-major order (each vector will be in a single column) when passed to and from the shader. This is generally more efficient because it allows vector-matrix multiplication to be performed using a series of dot products.
D3DXSHADER_PACKMATRIX_ROWMAJOR
/Zpr
Unless explicitly specified, matrices will be packed in row-major order (each vector will be in a single row) when passed to or from the shader.

Compiler flags

The DirectX 10 HLSL compiler is now the default compiler. See Effect-Compiler Tool for details.

The following table details the flags available in Direct3D 9 and Direct3D 10. The value for the flag is the equivalent fxc option.

Constant/value Description
D3DXSHADER_AVOID_FLOW_CONTROL
/Gfa
This is a hint to the compiler to avoid using flow-control instructions.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_DEBUG
/Zi
Insert debug filename, line numbers, and type and symbol information during shader compile.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY
/Gec
Compile ps_1_x shaders as ps_2_0. Effects that specify ps_1_x targets will instead compile to ps_2_0 targets because this is the minimum shader version supported by the version of the shader compiler shipped with DirectX 10. This flag has no effect when used with higher level compile targets.
Direct3D 9 - no
Direct3D 10 - yes
D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT
N/A
Force the compiler to compile against the next highest available software target for pixel shaders. This flag also turns optimizations off and debugging on.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT
N/A
Force the compiler to compile against the next highest available software target for vertex shaders. This flag also turns optimizations off and debugging on.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_IEEE_STRICTNESS
/Gis
Disable optimizations that may cause the output of a compiled shader program to differ from the output of a program compiled with the DirectX 9 shader compiler due to small precision erros in floating point math.
Direct3D 9 - no
Direct3D 10 - yes
D3DXSHADER_NO_PRESHADER
/Op
Disables preshaders. The compiler will not pull out static expressions for evaluation on the host CPU. Additionally, the compiler will not loft any expressions when compiling stand-alone functions.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_OPTIMIZATION_LEVEL0
/O0
Lowest optimization level. May produce slower code but will do so more quickly. This may be useful in a highly iterative shader development cycle.
Direct3D 9 - no
Direct3D 10 - yes
D3DXSHADER_OPTIMIZATION_LEVEL1
/O1
Second lowest optimization level.
Direct3D 9 - no
Direct3D 10 - yes
D3DXSHADER_OPTIMIZATION_LEVEL2
/O2
Second highest optimization level.
Direct3D 9 - no
Direct3D 10 - yes
D3DXSHADER_OPTIMIZATION_LEVEL3
/O3
Highest optimization level. Will produce best possible code but may take significantly longer to do so. This will be useful for final builds of an application where performance is the most important factor.
Direct3D 9 - no
Direct3D 10 - yes
D3DXSHADER_PARTIALPRECISION
/Gpp
Force all computations in the resulting shader to occur at partial precision. This may result in faster evaluation of shaders on some hardware.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_PREFER_FLOW_CONTROL
/Gfp
This is a hint to the compiler to prefer using flow-control instructions.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_SKIPOPTIMIZATION
/Od
Instruct the compiler to skip optimization steps during code generation. Unless you are trying to isolate a problem in your code and you suspect the compiler, using this option is not recommended.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_SKIPVALIDATION
/Vd
Do not validate the generated code against known capabilities and constraints. This option is recommended only when compiling shaders that are known to work (that is, shaders that have compiled before without this option). Shaders are always validated by the runtime before they are set to the device.
Direct3D 9 - yes
Direct3D 10 - yes
D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
/LD
Enable the use of the original Direct3D 9 HLSL compiler. OCT2006_d3dx9_31_x86.cab or OCT2006_d3dx9_31_x64.cab must be included as part of the applications redist. This flag is required to compile ps_1_x shaders without using the promotion flag to ps_2_0. Specifying this flag when obtaining an ID3DXEffectCompiler interface causes subsequent calls to CompileEffect and CompileShader through this object to use the legacy compiler.
Direct3D 9 - yes
Direct3D 10 - no

Assembler flags

Assembler flags are used by the effect system to optimize shader and effect assembly code.

Constant Description
D3DXSHADER_DEBUG
Insert debug filename, line numbers, and type and symbol information during shader compile.
D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT
Force the compiler to compile against the next highest available software target for pixel shaders. This flag also turns optimizations off and debugging on.
D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT
Force the compiler to compile against the next highest available software target for vertex shaders. This flag also turns optimizations off and debugging on.
D3DXSHADER_SKIPVALIDATION
Do not validate the generated code against known capabilities and constraints. This option is recommended only when compiling shaders that are known to work (that is, shaders that have compiled before without this option). Shaders are always validated by the runtime before they are set to the device.

Remarks

The effect system will use parser flags when called by the following functions:

The effect system will use compiler flags when called by the following functions:

In addition, you can use compiler flags when creating an effect by calling D3DXCreateEffect (or D3DXCreateEffectFromFile or D3DXCreateEffectFromResource).

  • If you pass in an uncompiled .fx file, the effect system will use the flag input parameter during compilation.
  • If you pass in a compiled effect, the effect system will ignore the compiler flags since they are not needed to load the effect.

The effect system will use assembler flags when called by the following functions:

Applying compiler flags or assembler flags to the incorrect API will fail shader validation. Check the Direct3D error code return value from the function with the DirectX Error Lookup Tool (DXErr.exe) to help track down this error. You can get DXErr.exe and learn about it from the DirectX SDK. For info about the DirectX SDK, see Where is the DirectX SDK?.

Requirements

Requirement Value
Header
D3dx9shader.h

See also

D3DX Constants