Sign in to follow this  
brekehan

Input Slots

Recommended Posts

I read on msdn that the 4th param of an entry in a D3D10_INPUT_ELEMENT_DESC tells what input slot to use. However the entire D3D10_INPUT_ELEMENT_DESC is supposed to be for one vertex buffer. Then when I read about input slots, it says that one input slot is used per vertex buffer in the case of multiple buffers. Why would I give a input slot param per entry if the whole thing is for one vertex buffer which goes in one slot? I am not understanding input slots. Can someone explain them with more clarity? Where and how do I change which input slot is being used in the HLSL and in the application code in the case of multiple buffers? It appears you bind an entire array of vertex buffers at once, not one at a time...

Share this post


Link to post
Share on other sites
I am not sure if I am right on this, but here is how I think it works.

The D3D10_INPUT_ELEMENT_DESCs is use to describe the what information is going to the shader and where it should come from. Hence the input slots basically refers to the array indexes when you bind the vertex buffer. I think the max is 16? In short, if you put the input slot as 2, it tells the shader "Get this part of the data from the third vertex buffer (zero base indexing)". This is normally done for multiple buffers like spliting them to Geometry, Texture buffers etc. Hence if you have (my test app input element desc)

D3D10_INPUT_ELEMENT_DESC InputLayoutDesc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 1, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
};

Position will come from the VertexBuffer[0], and Texcoord will come from VertexBuffer[1]

Hope this helps.

Share this post


Link to post
Share on other sites
Ok, that is the way I read it too. However, I was thinking that one description has to be created for each vertex buffer. However, I now believe one description is created for the entire array of vertex buffers. Is that correct?

The example from MSDN:

[source ="cpp"]
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ L"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ L"TEXTURE0", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12,
D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ L"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 20,
D3D10_INPUT_PER_VERTEX_DATA, 0 },
};




is saying that I will need to bind an array of two vertex buffers.. One for position and texture data.. Another containing the normals.

This one description is used to create a layout. The layout is then bound one time for passes that are going to expect this format. However, I may switch and use one or more different vertex buffers in the middle of rendering my frame on say, pass 3, in which case I need a new description and need to create and bind a new layout.

Is that all corrrect?

[Edited by - brekehan on January 18, 2009 3:48:03 AM]

Share this post


Link to post
Share on other sites
You are basically right. As long as the vertex data location changes, you will need a new description to inform the shader on the correct location to retrive the appropriate data.

If you do not change it, the shader is just going to go ahead and take the data at the original location, even if the current vertex buffer bounded now contains a different logical information.

For example, in your case, if in pass3 you change your VertexBuffer[1] to hold tangent data instead of normals data, and everything stays the same, the shader is just going to take the normals from VertexBuffer[1], because the descriptor tells it to. Even though logically VertexBuffer[1] now contains tangent data the shader would never know.

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