Jump to content
  • Advertisement

Recommended Posts

Hi Guys,

I understand how to create input layouts etc... But I am wondering is it at all possible to derive an input layout from a shader and create the input layout directly from this? (Rather than manually specifying the input layout format?)

Thanks in advance :)

 

Share this post


Link to post
Share on other sites
Advertisement

Yeah, if you reflect on your vertex shaders, you can discover which attributes it consumes, e.g. the asm dump from one of my shaders includes:

// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION                 0   xyz         0     NONE   float   xyz 
// TEXCOORD                 0   xy          1     NONE   float   xy  
// NORMAL                   0   xyz         2     NONE   float   xyz 
// TANGENT                  0   xyz         3     NONE   float   xyz 
// POINTCLOUDINDEX          0   x           4     NONE    uint   x   

As well as this though, you need to know the structure of how your vertices are stored in RAM. Once you have both bits of information, you can automatically match them to each other and generate an input layout.

Share this post


Link to post
Share on other sites

It is doable, but maybe not the best practice. You can use D3DReflect API to retrieve shader source information from the compiled blob. From it you can retrieve your vertex shader inputs and semantics. But you should watch out because vertex buffers will use type conversion to convert between memory layout and how the shaders will view them, and you can only deduce that from the input semantic string. So make sure that they are consistent and decide on the CPU side what kind of vertex packing you want for a given semantic by comparing strings.

Also, as far as I know, you can't use the shader reflection or shader compilation APIs when you release on the Windows Store.

Share this post


Link to post
Share on other sites

I had the same question some time ago. My conclusions where that it's a good idea to use D3DReflect, but that it's also a good idea to define a number of combinations you want to support, because in the end most likely you also need the structs with the data (loading mesh data and storing it somewhere etc.). If you want I can paste some of the code on how I did it, let me know,

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks for the replies, guys. Gives me a couple of things to think about trying.

I wonder if the creation of the input layout requires the full shader to compare against, or whether it would succeed with just a valid 'input section'.

If the latter is the case, we might be able to create an 'fvf blob' on the fly by 'engineering' a valid shader input.

Edited by lonewolff

Share this post


Link to post
Share on other sites
2 hours ago, lonewolff said:

I wonder if the creation of the input layout requires the full shader to compare against, or whether it would succeed with just a valid 'input section'.

You can share input layouts between multiple different vertex shaders, as long as they all have the same "input section" as you call it :)

I actually (ab)use this feature and pre-compile one shader for each of my vertex-input-structures, who's only use is being passed to CreateInputLayout. These fake shaders are basically empty, besides reading the required vertex input attributes (and making sure those reads aren't optimized out, by summing them and returning the result).

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

  • 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!