Most of the information on how to use PIX with Xna is readiliy available on the net. Two issues took me a while to finally get my shader’s source code to display in PIX for my Xna applications though:
- Xna will add debug information to shaders compiled with the default processor if you’re running a debug build. Apparently you should take that quite literally: your project configuration should actually be named “Debug”. In stead of using the DEBUG preprocessor define, it seems they are doing a string compare on the configuration name. I renamed my project configs since my build is set up a bit more complex than just Debug/Release, and didn’t have shader debug info in PIX
- To resolve this, I extended the content pipeline with my own basic effect processor that adds the debug flag depending on the DEBUG preprocessor define. What I didn’t know was that Effect.CompileEffectFromSource doesn’t do anything with the CompilerOptions.Debug flag, since PIX needs a link between the source file and the debug info. In stead, use Effect.CompileEffectFromFile.
Here’s the code for my custom effect processor:
[ContentProcessor(DisplayName = "Effect - Hyperion Effect Debug Processor")]
public class EffectDebugProcessor : EffectProcessor
{
public override CompiledEffect Process(EffectContent input, ContentProcessorContext context)
{
CompiledEffect compiledEffect = Effect.CompileEffectFromFile(
input.Identity.SourceFilename,
null,
null,
CompilerOptions.NoPreShader
#if DEBUG
| CompilerOptions.Debug
| CompilerOptions.SkipOptimization
| CompilerOptions.AvoidFlowControl
#endif
,
context.TargetPlatform
);
if (!compiledEffect.Success)
{
compiledEffect = Effect.CompileEffectFromFile(
input.Identity.SourceFilename,
null,
null,
CompilerOptions.NoPreShader
#if DEBUG
| CompilerOptions.Debug
| CompilerOptions.AvoidFlowControl
#endif
,
context.TargetPlatform
);
}
return compiledEffect;
}
}
