Shader variable register mapping in DirectX9

Started by
1 comment, last by Kjell Andersson 8 years, 6 months ago

I'm in the process of abstracting away the D3D9 usage in an application in order to be able to slowly migrate to a newer API in the future.

The first step in this is to create a DX9 rendering back-end that supports the current functionality but without using the legacy D3DX interfaces.

My problem right now comes to the introspection of the shader code in order to map data into constant buffers, i.e. shader variables and texture input.

I'm trying to use the D3DCompile(), CreateVertexShader(), SetVertexShaderConstant() interfaces instead of the D3DX and effect framework and thus need to be able to map variable names to register numbers that can be passed to the SetVertexShaderConstant() function.

If you don't specify any registers manually in your shader, the compiler automatically assigns them, but how do you get that information out from the compiled shader?

Is there a way to do this mapping table automatically instead of manually specifying register usage in the shader and then creating a mapping table outside of the shader?

Advertisement
You can use D3DX reflection stuff, parse the bytecode yourself, or ask the compiler to output asm text and parse that.

However:

I'm in the process of abstracting away the D3D9 usage in an application in order to be able to slowly migrate to a newer API in the future.

All of the newer APIs use cbuffers/UBOs instead of individual constants. Creating an abstraction around the D3D9 model of individual constant registers will cause you major grief later. I would recommend emulating cbuffers on D3D9 instead.

Great input that I should work towards a cbuffer friendly interface!

This topic is closed to new replies.

Advertisement