Effect Compiler Integration

How to integrate the Effect Compiler into Visual Studio

I wrote a rule file in order to be able to compile Direct3D / HLSL effect files directly in Visual Studio. The default way is to compile all .fx files at runtime, but as files are getting bigger, compile time increases radidly. However, in most cases it is not required to recompile the effects every time you run your application.

Usually you would call D3D10CompileShader(..) or a similiar function which calls fxc.exe internally. If you want Visual Studio to take of the compiling process you have to add a custom build rule. It will be called only if the source file has changed since the last compilation or the compiled version does not exist.

The compiling process can be adjusted using the "Property Pages" for every file individually as if it was a C/C++ or some other known file type. The output file is a binary effect data file and has the extension .cfx (any other endling is valid, too). It can be read in by D3DX10CreateEffectFromFile(..) for example.

Another big advantage is that syntax errors will be displayed in Visual Studios "Output Window". Double-clicking on the error message will bring you directly to the erroneous line in the corresponding effect file.

Place the extracted file in your VCProjectDefaults folder in your VC install directory.
Example: C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults

It has been tested to work with Visual Studio 2005 and Visual Studio 2008, but any other editon should be fine, too.

There is no further installation process required. Just add a .fx file to your project and the following dialog should pop up.

Alternatively, you can right-click on your project in the "Solution Explorer" and choose "Custom Build Rules". This is also where you can modify the build rules.

Right-clicking on a .fx file in your project opens up the following dialog.

If everything works fine, you should be able to compile your shader file just like a regular source file.