High-level shader language (HLSL) shaders and assembly shaders can be compiled from the command line using a group of four tools provided in the DirectX SDK.
Tool Name | Tool Description |
---|---|
fxc.exe | Compiles HLSL shaders. |
flink.exe | Links HLSL fragments. |
vsa.exe | Compiles assembly vertex shaders. |
psa.exe | Compiles assembly pixel shaders. |
These tools can be found at the following location:
(SDK root)\Utilities\Bin\x86\
Compatibility Chart
D3D9 | D3D9 EX | D3D10 | 64-bit | XP | Vista |
---|---|---|---|---|---|
Yes |
No |
Yes (fxc.exe only) |
Yes |
Yes |
Yes |
tool [switches] filename |
---|
Where tool is one of the compiler tools, switches is one of the optional switches listed below and filename indicates the file to be compiled.
These switches can be used with any of the compiler tools
Switch Name | Description |
---|---|
/Cc | Display color-coded assembly listings |
/D id=text | Define a macro. |
/Fc file | Generate assembly code listing file. |
/Fh file | Generate header containing object code. |
/Fo file | Generate object file. |
/Fx file | Generate assembly code and hexadecimal listing file. |
/Gfa | Avoid flow control constructs. |
/Gfp | Prefer flow control constructs. |
/I path | Additional include path. |
/Vd | Disable validation. |
/Vi | Display additional details about the include process. |
/Vn name | Use name as variable name in header file. |
/Zi | Enables HLSL debugging information. |
/nologo | Suppress copyright message. |
These switches are only used with the Fxc and Flink tools.
Switch Name | Description |
---|---|
/E name | Identify the entry point or fragment name. Use this to specify a specific shader or fragment in a file to compile. |
/Gpp | Force partial precision. |
/Od | Disable optimizations. |
/Op | Disable preshaders. |
/T profile | Identify the target profile, which is one of the following:
|
/Zpc | Pack matrices in column-major order. |
/Zpr | Pack matrices in row-major order. |
Use the fxc tool with files that contain HLSL code.
Using the CompiledEffect Sample, the following is an example of compiling the code in the CompiledEffect.fx file for a fx_2_0 target profile:
// For a release build fxc /T fx_2_0 /Fo CompiledEffect.fxo CompiledEffect.fx // For a debug build fxc /Od /Zi /T fx_2_0 /Fo CompiledEffect.fxo CompiledEffect.vsh
The debug options include additional options to disable compiler optimizations and enable debug information like line numbers, symbols, and so on. The binary representation of the shader is written to a file called CompiledEffect.fxo, which is an arbitrary abbreviation for the fxc output file.
Fxc can also be used to compile a shader within an effect. For instance, to compile the Ripple shader in the HLSLwithoutEffects Sample:
fxc /T vs_2_0 /E Ripple /Fo HLSLwithoutEffects.fxo HLSLwithoutEffects.vsh
Use the vsa and psa tools to compile files containing assembly vertex or pixel shader code. This code can be written by a developer or it could be the output of a shader compiled by fxc with the /Fc switch. For instance, compiling the HLSLwithoutEffects.vsh file to an assembly vertex shader: results in an assembly file that can be compiled by vsa:
fxc /T vs_2_0 /E Ripple /Fc HLSLwithoutEffects.vs HLSLwithoutEffects.vsh
vsa /Fo HLSLwithoutEffects.vso HLSLwithoutEffects.vs
Pixel shaders can be compiled using psa in a similar way.
Use Flink with HLSL code fragments. All fragments listed will be linked in the order specified in the command line. For instance, this command will link two fragments in the FragmentLinker sample:
flink /E ProjectionFragment_Animated /E AmbientDiffuseFragment /T vs_1_1 /Fo FragmentLinker.fxo FragmentLinker.fx
D3DXAssembleShader, D3DXDisassembleShader, ID3DXFragmentLinker