Sign in to follow this  
Kjell Andersson

Shader variable register mapping in DirectX9

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this