Question

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)

Was it helpful?

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!

OTHER TIPS

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).

Microsoft has put the format specification online here: Direct3D Shader Codes.

It refers to constants by name, however (eg. D3DSIO_DCL), so you'll likely still need the Windows DDK to get any use out of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top