You can use Visual Studio to compile your pixel and vertex shaders
It started to annoy me that if I made some stupid syntactic error with one of my shaders that it would, for lack of a better term, explode my application at runtime.
So I looked into using the "Custom Build Step" feature in Visual Studio (iirc, this exists in all of the recent/future versions). When I had this working, any syntactic errors pop up as regular build errors in the IDE. As per usual, double clicking on the entry jumps to the relevant line in the HLSL source code.
- Import the pixel shader, vertex shader or effect files into your solution.
- Select one of the files, right click on it, select "Properties" from the menu
- In the first 'General' page, make sure "Excluded From Build" is set to No. Make sure the "Tool" is set to "Custom Build Tool"
- In the 'General' page found inside the 'Custom Build Step' folder you need to do the real work
- Set the "Command Line" to whatever is appropriate for how you wish to compile your shader. A neat trick is that you can use the %DXSDK_DIR% macro to get a relative rather than absolute path. I use the following example for the "Debug" configuration: "%DXSDK_DIR%Utilities\Bin\x86\fxc.exe" /Tps_2_0 /E"main" /Fc"$(OutDir)\[ps_2_0] FinalPass.html" /Cc "Shader Code\FinalPass.psh" /nologo /Zi and "%DXSDK_DIR%Utilities\Bin\x86\fxc.exe" /Tps_2_0 /E"main" /Fc"$(OutDir)\[ps_2_0] FinalPass.html" /Cc "Shader Code\FinalPass.psh" /nologo for the "Release" configuration.
- Next up, set a friendly message in the "Description" field - I use "Compiling 'FinalPass.psh' as ps_2_0"
- Finally, you need to specify the 'Outputs'. This one is important as VStudio tends to scream a lot if it's wrong [smile]. Basically you just need to list all of the files that you're expecting the "Command Line" to create: "$(OutDir)\[ps_2_0] FinalPass.html" is what I'm using.
- Now, go back to step #1 for the next file [oh]
So, if you now screw up your shaders you might see this in your build log:
------ Build started: Project: HDR Demo, Configuration: Debug Win32 ------
Compiling 'FinalPass.psh' as ps_2_0
Shader Code\FinalPass.psh(49): error X3333: Error occured between keyboard and chair.
compilation failed; no code produced
Project : error PRJ0019: A tool returned an error code from "Compiling 'FinalPass.psh' as ps_2_0"
Build Time 0:00
Build log was saved at "file://k:\Development\Projects\HDR Demo\Debug\BuildLog.htm"
HDR Demo - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
I'm not using it fully, as my code also recompiles the files at load-time, but it is a fairly simple step to make sure you're not making any more stupid mistakes than you have to... [wink]