views:

75

answers:

2

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)

+1  A: 

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!

Goz
Thanks for the answer, which agrees with what I'd found elsewhere. I've decided to go with a different approach and compile the shaders using my own program using D3DX on a build machine rather than using fxc, and then I can use the D3DX interface to obtain the constant table data and write it out in my own format for my program to use.
John Burton
+1  A: 

From MSDN:

Asm Shader Reference (Windows)

Shader Binary Format

The bitwise layout of the shader instruction stream is defined in D3d9types.h. If you want to design your own shader compiler or construction tools and you want more information about the shader token stream, refer to the Direct3D 9 Driver Development Kit (DDK).

So you can either look through 'D3d9type.h' and try to figure it out that way (had a quick look and could see the enums/types you should need, but not how its structured), or download the DDK and read the official documentation.


Some more info can be found here: Direct3D Shader Codes (expand the tree on the left hand side of the screen to get all the info).

Grant Peters