Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Can I read somewhere about optimizations that HLSL compiler performs?

For example, in some codes I have different variables that get a constant value (just to let myself adjust the shader with other values) and I use them later in some mathematical expressions, but actually it can be precalculated earlier. Does the compiler do such thing?

It's just an example, I would like to know most of these things.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I don't think any such spec exists publicly, but you can disassemble your compiled shaders using the D3DDisassemble API function, or using fxc /Fc at the command line. If you write some example shaders and look at the disassembly, this will give you some idea of the optimizations it does.

Note that this assembly is a machine-independent intermediate language (IL). Shaders in D3D get compiled to this IL first by Microsoft's compiler, then they get compiled again to the actual GPU machine instructions by the GPU vendor's compiler which is part of their D3D driver. The second stage requires vendor tools to get at, like AMD's ShaderAnalyzer, and NVIDIA's ShaderPerf (although it looks like it hasn't been updated in awhile - no support for the latest NVIDIA GPUs or for 5_0 profiles). Some further optimizations may be done by the second stage of compilation, and those tools will let you see it to some extent.

share|improve this answer
add comment

The compiler can do some very effective optimization. The best way to find out what it can do is to use a tool like http://developer.amd.com/tools/graphics-development/gpu-shaderanalyzer/ which will show you the disassembly for a shader.

The one thing that it doesn't do is to move calculations between shader code and CPU code.

share|improve this answer
    
+1 for mentioning optimizing by offloading stuff to the CPU. –  Robert Rouhani Jan 20 '13 at 15:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.