Sign in to follow this  
Funkymunky

HLSL: next free register binding

Recommended Posts

I have a shader that #includes two other pieces of code.  Each of those #include files declares a Texture2D.  Is there any way to know in my main code what the currently "free" register is?  Like:

 

.

// Effect1.hlsl
Texture2D fx1;
...

// Effect2.hlsl
Texture2D fx2;
...

// Main.hlsl
#include "Effect1.hlsl"
#include "Effect2.hlsl"

Texture2D firstTexture : register(t#)
Texture2D secondTexture : register(t#)
...

.

 

Is there any way to know what those t#'s would be (in this case t2 and t3)?  Perhaps by some trick of a preprocessor directive with a #define passed from the engine code?  I know that explicitly declaring the register is optional, but I'm still curious.

Edited by Funkymunky

Share this post


Link to post
Share on other sites

I know that explicitly declaring the register is optional

That's the answer - if you want them to automatically go into the next free slot, leave off the explicit register declaration.
 
In my shader system I add these kinds of extensions by but machine-generating the code that declares resources (and declare resources in a declarative DSL alongside the HLSL code).

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