Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Input Layout Question

Started by Quat Sep 15, 2010 at 11:30 AM 5 replies 2k views
Original Post
Quat
Quat
The docs say the following:

Quote:

You can create a single input-layout object for many shaders, as long as all of the shader-input signatures exactly match.


But, does Direct3D 10+ define the behavior if the shader input signature only contains a subset of the input-layout? For example, suppose I have my usual mesh vertex structure, say for example:

struct Vertex
{
Vector3 Pos;
Vector3 Normal;
Vector3 UV;
};

but I want to draw depth only to a render target. The shader signature for the depth shader only needs the POSITION vertex attribute:

struct VS_IN
{
float3 Pos : POSITION;
};

Is it defined in Direct3D the behavior if I reuse the input layout corresponding to Vertex? Is it equivalent to defining:

struct VS_IN
{
float3 Pos : POSITION;
float3 Normal : NORMAL;
float2 UV : TEXCOORD;
};

and just ignoring Normal and UV in the depth pass?
-----Quat
Demirug
Demirug
DX9 removes unused elements from the signature. DX10 and up will keep them.
Quat
Quat
Thanks for the reply, but it doesn't really answer my question. My question is, what if I use this in the vertex shader:

struct VS_IN
{
float3 Pos : POSITION;
};

and use the input-layout based on:

struct Vertex
{
Vector3 Pos;
Vector3 Normal;
Vector3 UV;
};

Is this guaranteed to work in Direct3D 10+?
-----Quat
Demirug
Demirug
No, this will not work as the input signature is different.
Quat
Quat
Quote:

DX9 removes unused elements from the signature. DX10 and up will keep them.


OK, I found out though that you can have a fat vertex declaration, say:

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 },};


and a vertex shader input:

struct VS_IN{float3 Pos : POSITION;};


And you can create a valid input layout from the "fat" vertex description to the smaller input signature. So you can get from a larger vertex to a smaller, but you have to create a separate input layout for that mapping.

-----Quat
Quat
Quat
Quote:

No, this will not work as the input signature is different.


How come this works with the CascadedShadowMaps11 sample? They create one input layout for rendering both the scene and depth:

const D3D11_INPUT_ELEMENT_DESC layout_mesh[] =    {        { "POSITION",  0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },        { "NORMAL",    0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },        { "TEXCOORD",  0, DXGI_FORMAT_R32G32_FLOAT,    0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },    };        V_RETURN( pd3dDevice->CreateInputLayout(         layout_mesh, ARRAYSIZE( layout_mesh ),         m_pvsRenderSceneBlob[0]->GetBufferPointer(),        m_pvsRenderSceneBlob[0]->GetBufferSize(),         &m_pVertexLayoutMesh ) );


But in RenderCascadeShadow.hlsl they have:

struct VS_INPUT{    float4 vPosition    : POSITION;};


but they set pVertexLayoutMesh, which is based in the input signature in RenderCascadeScene.hlsl:

struct VS_INPUT{    float4 vPosition                        : POSITION;    float3 vNormal                          : NORMAL;    float2 vTexcoord                        : TEXCOORD0;};

-----Quat
standby01
standby01
I agree with Demirug.

D3D10 and above enhanced Vertext validation.

Each input-layout object is created based on a shader signature; this allows the API to validate the input-layout-object elements against the shader-input signature to make sure that there is an exact match of types and semantics. You can create a single input-layout object for many shaders, as long as all of the shader-input SIGNATURES EXACTLY MATCH.

In CascadedShadowMaps11 there are two places Input-Layout Objects are created.
one is for g_strUIEffectFile(line 628 to 639, DXUTgui.cpp), and the other is for RenderCascadeScene.hlsl(line 233 to 244, CascadedShadowsManager.cpp), while the vertex shader defined in RenderCascadeShadow.hlsl doesn't create primitives, so no D3D11_INPUT_ELEMENT_DESC struct and Input-Layout Object created for it.
Jimmy Chen

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.