Graphics Reference
In-Depth Information
One of the key features of HLSL in D3D11 is that the same language is used to author
shader programs for all shader stages. This provides a consistent set of standard features
for all stages, allowing common code to be shared among shader programs written for each
stage of the pipeline. Authoring in a high level language also allows many of the low-level
details of the underlying graphics hardware to be abstracted, allowing shader programs to
extract performance from a wide range of graphics hardware.
6.2 Usage Process
Figure 6.1 shows the typical sequence for authoring and running an HLSL program.
6.2.1 Authoring and Compilation
The usage process begins by authoring the shader program in HLSL. Typically, this is done
by creating a standard ASCII text file containing the code for one or more shader programs.
This can be done with any standard text editor or development environment. Once the code
for the program is completed, it is compiled by the D3D shader compiler. The compiler is
accessed through the D3DCompile function exported by the D3DCompiler DLL, or through
the command line by using the standalone fxc.exe tool. There are also D3DX helper
functions (D3DXCompileFromFile\D3DXCompileFromResource) that simplify the process
of compiling directly from a file or from an embedded resource. In all cases, the compiler
accepts configuration parameters, in addition to code itself. These parameters indicate the
entry point function, the shader profile to use for compilation, a list of preprocessor macro
definitions, a list of additional files to be included by the preprocessor, and a list of com-
pilation flags (including optimization and debug options). If compilation fails or warnings
are produced, the D3DCompile and D3DX functions store the warning or error messages in a
string embedded in an ID3D10Blob object. As with C++ compilation, these messages include
an informative message and a line number, so that the errors or warnings can be easily found
and corrected. If fxc.exe is used, the messages will simply be output to the command line.
For debug builds of applications, it is typically desirable to compile shader programs
with the D3D10_SHADER_DEBUG (/Zi switch in fxc) flag enabled. This causes the compiler
to embed debug information into the bytecode stream, which can be used to map instruc-
tions and constants back to their respective lines in the HLSL source code. This enables
source-level debugging of shader programs, which can be much more convenient than
directly debugging the assembly. Note that it may also be desirable to disable optimizations
by using D3D10_SHADER_SKIP_OPTIMIZATIONS (/Od switch in fxc), as this will prevent
instruction reordering and folding, making it easier to debug the programs.
Search WWH ::




Custom Search