Format of compiled directx9 shader files?
Asked Answered
P

3

5

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)

Pastor answered 30/3, 2010 at 13:51 Comment(0)
R
0

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!

Rhubarb answered 31/3, 2010 at 13:4 Comment(1)
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.Pastor
S
10

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

Samiel answered 1/7, 2010 at 7:18 Comment(0)
R
0

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!

Rhubarb answered 31/3, 2010 at 13:4 Comment(1)
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.Pastor
N
0

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.

Nerva answered 6/7, 2012 at 16:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.