Jump to content
  • Advertisement
Sign in to follow this  
Waaayoff

Adding some type of metadata in HLSL?

This topic is 1057 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using the D3D shader reflection function to generate my vertex input layout, however I need to specify whether a variable is per-vertex or per-instance and as far as I know there is no official HLSL way to do this.

 

I thought about adding my own metadata structure at the top of the file, parse it and pass the rest of the shader to D3DCompile (instead of D3DCompileFromFile). Does this sound like a good idea? What is the generally used approach?

Share this post


Link to post
Share on other sites
Advertisement

That's what I do. I use special comment blocks like this:

/*[FX]
...Lua...
*/
...HLSL...

I extract any text within those magic comment blocks and run it in the Lua VM -- the code calls metadata-collecting functions, allowing me to later save that metadata alongside the shader on disc.
The HLSL is then passed off to FXC and compiled (and saved along with the metadata).

Share this post


Link to post
Share on other sites

I think that the "best practices" approach for 11 is to just treat all members of the input layout as per-vertex and shove all per-instance data into a cbuffer instead of a second input stream.  Then you don't have to worry about fixing gaps in the HLSL/reflection like this one.

 

That said, I ran into the same issue a few years back and came to the same basic conclusion for solving it.  Like Hodgman, I stored that metadata to separate files that lived and were loaded alongside my shaders.

Share this post


Link to post
Share on other sites

I honestly wouldn't make this distinction in HLSL code at all.  You're correct that HLSL itself doesn't distinguish between the two, which means that so far as the shader itself is concerned the difference doesn't exist.  This means that you get to be able to use the same shader for instanced passes as you use for non-instanced passes (e.g you could use a vertex buffer with stride 0) which gives you greater flexibility.

Share this post


Link to post
Share on other sites

you could use set a specific "prefix" or "suffix" for the interesting variables.

 

Something like this:

float3 v_pos;
float3 v_normal;
int      i_idx;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!