Search code examples
directxfile-formathlsld3dx

Format of compiled directx9 shader files?


Is the format of compiled pixel and vertex shader object files as produced by fxc.exe documented anywhere either officially or unofficially?

I'd like to be able to read the constant name to register assignments from the shader files. I know that the effects framework in D3DX can do this, but I need to avoid using D3DX as it may not be installed on user's machines and I don't need it for anything else so I want to avoid them having to run the directx update.

If the effects framework can do it, then so can I if I can find out the file format but I can' seem to find it documented anywhere.

(this is for use in directx9)


Solution

  • Microsoft deliberately keep this information away from you. As you are using DirectX 9 its relatively easy to backward engineer the format though. If you write a simple piece of shader assembly you can check out what he compiled code returned at the other side is. By making modifications to the assembler you can see how they byte code changes. You will start to see patterns in how registers are handled and where the instruction is encoded. You can thus, slowly but surely, work out the byte code. It won't be too quick though!