CompiledEffect Direct3D Sample |
This sample shows how an Effect object can be compiled when the project is built and loaded directly as a binary file at run time.
Source: | (SDK root)\Samples\Managed\Direct3D\CompiledEffect |
---|---|
Executable: | (SDK root)\Samples\Managed\Direct3D\Bin\x86\csCompiledEffect.exe |
Large-scale projects may contain dozens or even hundreds of shader and effect files. Compiling these files at run time can cause a noticeable delay during initialization, and this delay is incurred each and every time the project is run; instead, these files can be compiled as part of your project build process, eliminating the need for any further compilation during program execution. Since these files will only need to be compiled when changes are made, no additional build time is spent on effect files which have already been compiled. Note that when developing or debugging effect files it is still beneficial to compile at run time, which allows more debugging flexibility. Also note that the process illustrated in this sample is identical whether compiling a complete Effect object or individual shaders. The only change would be the target profile command line passed to the compiler.
The code is very similar to the BasicHLSL sample except for a couple important differences:
The program used to compile shaders at build time is fxc. This command-line utility ships with the software development kit (SDK), and wraps the EffectCompiler calls used to perform the compilation. It's interesting to note that you could create your own shader compiler fairly easily using the EffectCompiler class, but fxc should be flexible enough for most needs. The commands used to build release and debug versions of a hypothetical MyEffect.fx file are:
Release: | fxc /Tfx_2_0 /FoMyEffect.fxo MyEffect.fx |
---|---|
Debug: | fxc /Od /Zi /Tfx_2_0 /FoMyEffect.fxo MyEffect.fx |
Run fxc without any arguments for usage information.
To configure the build environment using Microsoft Visual Studio .NET, complete the following steps.
Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center