Sign in to follow this  
brekehan

Input Layout and technique

Recommended Posts

Why is the input layout depedent on the technique? All effects I've seen use the same input layout throughout. What's an example of the input layout changing within an effect? I have moved the process of creating an input layout several times from class to class and am not really sure where to stick it and its creating circular dependancies I don't want to have to toy with. Is creating an input layout expensive? Am I being wasteful if I create and bind for every object in my render loop?

Share this post


Link to post
Share on other sites
The input layout actually depends on the Pass signature, not the technique. This means that if you have several passes in one technique, you might need several input signatures.

In frequent cases, each VS can have a different input signature. Each pass can have a different VS. Each input signature requires an input layout.

An example of two passes requiring different input layouts would be a z-prepass that doesn't use lighting data, and doesn't need normals, and a second lighting pass that uses normals. Each has a different input signature, and so you'd use two different input layouts for each pass of the same technique.

Hope this helps.

Share this post


Link to post
Share on other sites
While neither of these snippets is real code, I want to try and get the procedure down...So you are saying this old code:


m_d3dDevice.IASetInputLayout(m_vertexLayout);
m_d3dDevice.IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
m_d3dDevice.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
m_d3dDevice.IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

D3D10_TECHNIQUE_DESC techDesc;
m_technique->GetDesc(&techDesc);

for(UINT pass = 0; pass < techDesc.Passes; ++pass)
{
m_technique->GetPassByIndex(pass)->Apply(0);
m_d3dDevice.DrawIndexed(m_numIndices, 0, 0);
}






Could become something like this:



D3D10_TECHNIQUE_DESC techDesc;
m_technique->GetDesc(&techDesc);

for(UINT pass = 0; pass < techDesc.Passes; ++pass)
{
m_d3dDevice.IASetInputLayout(m_vertexLayout[pass]);
m_d3dDevice.IASetVertexBuffers(0, 1, &m_vertexBuffer[pass], &stride[pass], &offset);
m_d3dDevice.IASetIndexBuffer(m_indexBuffer[pass], DXGI_FORMAT_R32_UINT, 0);
m_d3dDevice.IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

m_technique->GetPassByIndex(pass)->Apply(0);
m_d3dDevice.DrawIndexed(m_numIndices[pass], 0, 0);
}





So, if I understand correctly, in my real code, where my draw code is that iterates through the passes of the technique, is going to be the place where I need to:

query the vertex desc of the polygon(s) I am about to draw
query if an input layout has been created already pairing that vertex desc with the technique and pass
if not, then create one
bind the input layout

So I am going to have a collection of input layouts where the key is
a structure of
{
vertexDesc
effectName
techniqueName
pass number
}

Because I wouldn't want to have every mesh create its own input layout(s), when several meshes would be using the same, correct?


[Edited by - brekehan on January 17, 2009 2:53:43 PM]

Share this post


Link to post
Share on other sites
Ok, after more thought and reading:

If a pass knows the vertex format it expects and it will not change for a single pass,

Why do the DirectX interfaces not allow me to obtain the vertex format from the pass of a technique, instead of my having to tell the DirectX interfaces the vertex format I am about to feed the pass?

I looked over D3D10_PASS_DESC and all it has is a pointer to the input signature, but no data that tells me what it expects.

Share this post


Link to post
Share on other sites
Each pass should have an his own input layout, but if you have several passes with same vertex struct, the same layout works.

And remember that a layout with Position, Normal and Texcoord will work also on pass with only Position and Normal.

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