Sign in to follow this  
fortia

ID3D10InputLayout/ID3D11InputLayout

Recommended Posts

fortia    276
Hi, I'm sort of puzzled about the details below and can't seem to find clear answers in the docs. I have two shaders, S1 and S2, with DIFFERENT input elements and two vertex buffers with DIFFERENT vertex layout, VB1 and VB2. Now, creating an input layout object requires two things: - The shader - The vertex declaration for the vertices in the vertex buffer. We assume all combinations: - S1+VB1 - S1+VB2 - S2+VB1 - S2+VB2 yield valid input layout objects when created separately. That is both vertex buffers satisfy the needs of both shaders. But do I really have to create an input layout object for every permutation of shader+vb that I use or is there a way to reuse them? The docs say: "You can create a single input-layout object for many shaders, as long as all of the shader-input signatures exactly match." This would suggest that I could create only two (instead of four layout objects): - IL1 for S1+VB1 and S1+VB2 - IL2 for S2+VB1 and S2+VB2 But since VB1 and VB2 have different vertex layout I'm not so sure this would work. Has anyone tried? It would be truly disappointing having to create input layout objects for every permutation of shader+geometry. I do not really organize my resources by layout so basically this is where I would have to end up. Is that costly? Anyway, the only thing I can keep track of here is if objects use the same shaders or the same geometry. I do not have anything that sorts shaders by their input signatures or something. I don't know how microsoft thought it possible to manage such a thing :). But one thing that makes me curious... Does the directx runtime automatically prevent duplicates from being created like it does with for instance blend states?

Share this post


Link to post
Share on other sites
DieterVW    724
You don't need to make a layout to match each buffer to every shader. This requirement is only there to help verify that the layout will work with the shader you provided. D3D10 allows the user to define semantics and inputs and there has to be some good way to ensure that the two will work together. However, after making one such layout, any shader with a matching signature can use the same layout.

Sorting shaders by signature wouldn't be a big problem. A signature comparison is easy with the reflection api. And you only need to match layout objects to shaders, the order matters less.

Share this post


Link to post
Share on other sites
fortia    276
Although... one final question remains now.

If I have a shader with the following input:


struct VS_IN
{
float3 position : POSITION;
float3 normal : NORMAL;
};


and have two VBs one with position and normal, the other with position, normal and texcoord.

When creating separate input layout objects for these two VBs together with the shader, it is possible to use both of these VBs with this shader.

But I have a hard time figuring out how the hardware could possibly figure out the mapping from vertex buffer to shader.


Mapping for the first case:
VBPosition -> ShaderPosition
VBNormal -> ShaderNormal

Mapping for the second case(?) (make use of knowledge of vertex stride?):
VBPosition -> ShaderPosition
VBNormal -> ShaderNormal
VBTexcoord -> into the void?

What if texcoord in the VB is squeezed in between position and normal instead?
Then it would definately not exist some way for the hardware to figure it out,
right? But wouldn't an input layout object create the correct mapping here as well?
VBPosition ->ShaderPosition
VBTexcoord -> into the void
VBNormal -> ShaderNormal


Now, have I understood things correctly?

Share this post


Link to post
Share on other sites
DieterVW    724
D3D requires the signature and input structure to define the elements in the same order. It will not remap anything for you and will error out if the orders are different.

You can however have vertex buffers or inputs that exceed the amount of data the next stage accepts. This means that you can have p,n,t input with a vertex shader only using p,n.


Some of these questions are answered here:
ID3D11Device::CreateInputLayout

I can't find the other reference for this right now but it should be in the Programming guide for D3D10.

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