0
\$\begingroup\$

The input layout

D3D11_INPUT_ELEMENT_DESC layout[] = {
            {"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},
            {"Transform", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
            {"Transform", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1},
            {"Transform", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 32, D3D11_INPUT_PER_INSTANCE_DATA, 1},
            {"Transform", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 48, D3D11_INPUT_PER_INSTANCE_DATA, 1},
            {"Color", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 64, D3D11_INPUT_PER_INSTANCE_DATA, 1},
};

The vertex shader

cbuffer CBuf
{
    matrix model;
    matrix modelViewProj;
};
struct VSIn
{
    float3 pos : Position;
    float3 n : Normal;
    row_major float4x4 transform : Transform;
    float4 color : Color;
};
struct VSOut
{
    float3 worldPos : Position;
    float3 normal : Normal;
    float4 pos : SV_Position;
    float4 color : Color;
};
VSOut main(VSIn input)
{
    VSOut vso;
    vso.worldPos = (float3) mul(float4(input.pos, 1.0f), input.transform);
    vso.normal = mul(input.n, (float3x3) input.transform);
    vso.pos = mul(float4(input.pos, 1.0f), modelViewProj);
    vso.color = input.color;
    return vso;
}

The error

ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'Transform'/0, but the declaration doesn't provide a matching name.
D3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'Transform'/1, but the declaration doesn't provide a matching name.
D3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'Transform'/2, but the declaration doesn't provide a matching name.
D3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'Transform'/3, but the declaration doesn't provide a matching name.
D3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'Color'/0, but the declaration doesn't provide a matching name.

[Error Code] 0x80070057 (2147942487)
[Error String] E_INVALIDARG
[Description] The parameter is incorrect.

The error is thrown on CreateInputLayout before I draw anything to screen. I previously had this whole setup working with normal non instanced drawing. I understand that the error means the input layout doesn't match the shader declaration but I can't see which part does not match. VSIn contains a semantic name for Position, Normal, Transform and Color.

Research:

So for what I have tried after reading the above:

  • Use D3D11_APPEND_ALIGNED_ELEMENT instead of manually calculating the offsets
  • Split up the Transform matrix into four float4s with numbered semantic names
  • Binding just the color and removing the transform from both the input description and the shader (same error but only concerning color).
  • Ensure the shader that is loaded is the correct shader
  • Delete the generated .cso file to make sure the shader recompiles
  • Change the semantic names to different strings in case of reserved identifiers
\$\endgroup\$
1
  • \$\begingroup\$ Can you show your CreateInputLayout call, and particularly verify the vertex shader signature you're passing to it? \$\endgroup\$ Aug 29 at 4:15

2 Answers 2

3
\$\begingroup\$

The problem was I was not calculating the number of elements in the CreateInputLayout call. It was fixed at 2 elements.

Incorrect

pDevice->Get()->CreateInputLayout(
            layout, 2u,
            out.pBytecodeBlob->GetBufferPointer(),
            out.pBytecodeBlob->GetBufferSize(),
            &out.pInputLayout
);

Correct

int iNumElements = sizeof(layout) / sizeof(D3D11_INPUT_ELEMENT_DESC);
pDevice->Get()->CreateInputLayout(
            layout, iNumElements,
            out.pBytecodeBlob->GetBufferPointer(),
            out.pBytecodeBlob->GetBufferSize(),
            &out.pInputLayout
);
\$\endgroup\$
0
\$\begingroup\$

In the input layout, you are including the color attribute in the same vertex buffer slot as the transform matrix. Edit the color attribute element in the input layout to use vb slot 2:

{"Color", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 2, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1}
\$\endgroup\$
1
  • \$\begingroup\$ Thanks @maico-de-blasio I have tried using vb slot 2 for Color and that does not fix the issue. I have 2 vertex buffers, the normal vertex buffer and the instance buffer and since Transform and Color are in the instance buffer I have set their slot to 1. Also I should add this error happens when creating the layout not when binding the buffers. \$\endgroup\$
    – koreus737
    Aug 29 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .