Reading shader constant definitions (d3d9)

Started by
4 comments, last by Nik02 14 years ago
Is there any way to map shader external variable names to their constant register number given a shader file that has been pre compiled using fxc.exe without using the d3dx library? I'd rather not use that library in my application as I have no other need for it, and it significantly complicates deployment of my program if I use it. I can't find anything in the core of directx9, or any documentation at all on the format of the compiled shader object files so was wondering if anyone could point me to any relevant information, or suggest a better approach. I'm currently setting explicit constant numbers on my variables and accessing them by index in the C++ code which works well but seems a bit fragile and not very scalable in future when I have more shaders with different parameters,
Advertisement
I don't believe the bytecode format is documented, at least on the D3D side of things.
I had an idea while sleeping...

As part of my build I'm already running a script to compile my shaders by using fxc.exe. I could instead make a small program which uses D3DX to compile the shaders and write them out to a file, and at that point I can get at the constant table and write that out in my own format too. I have no problem with using D3DX on my build machine, I just don't want end users to need it for this. Does that make sense as a thing to do?

One question then, this sounds like I just need a command line utility with no window. Is there any way to use a direct3d device that will be needed for this without having a window? I guess I could make a hidden window but that seems inelegent somehow.
You don't need a device instance to compile shaders.

Niko Suni

Oh, you are correct. Well that makes it even easier.
Quote:Original post by MJP
I don't believe the bytecode format is documented, at least on the D3D side of things.


The shader IL tokens are documented in the Windows DDK, but the convention of mapping symbols to registers is not (it is purely D3D side stuff). It is conceivable that the system uses comment tokens interleaved with the actual instructions for that (but I haven't checked this).

Niko Suni

This topic is closed to new replies.

Advertisement