CreateInputLayout Help

Started by
6 comments, last by ryan20fun 9 years, 6 months ago

Hi, for some reason when i call ID3D10Device::CreateInputLayout it fails but ID3D10Device1::CreateInputLayout succeeds? Any idea what could be the problem? It fails with E_INVALIDARG.

Advertisement

Can you post some code where you set the parameters to pass to CreateInputLayout?

My current game project Platform RPG

VOID
CreateInputLayout( ID3D10Device* Device )
{
    HRESULT hr;
    ID3D10Blob *compiledFx = 0, *errorMsgs = 0;
    ID3D10Effect *effect;
    ID3D10EffectPass* effectPass;
    ID3D10EffectTechnique* effectTechnique;
    D3D10_PASS_DESC passDesc;
    
    D3D10_INPUT_ELEMENT_DESC layoutDesc[ ] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "COLOR", 0, DXGI_FORMAT_B8G8R8A8_UNORM, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0 }
    };
    
    CHAR effectFile[ ] = \
    "Texture2D SpriteTex;"
    "SamplerState samLinear {"
    "     Filter = MIN_MAG_MIP_LINEAR;"
    "     AddressU = WRAP;"
    "     AddressV = WRAP;"
    "};"
    "struct VertexIn {"
    "     float3 PosNdc : POSITION;"
    "     float2 Tex    : TEXCOORD;"
    "     float4 Color  : COLOR;"
    "};"
    "struct VertexOut {"
    "     float4 PosNdc : SV_POSITION;"
    "     float2 Tex    : TEXCOORD;"
    "     float4 Color  : COLOR;"
    "};"
    "VertexOut VS(VertexIn vin) {"
    "     VertexOut vout;"
    "     vout.PosNdc = float4(vin.PosNdc, 1.0f);"
    "     vout.Tex    = vin.Tex;"
    "     vout.Color  = vin.Color;"
    "     return vout;"
    "};"
    "float4 PS(VertexOut pin) : SV_Target {"
    "     return pin.Color*SpriteTex.Sample(samLinear, pin.Tex);"
    "};"
    "technique10 SpriteTech {"
    "     pass P0 {"
    "         SetVertexShader( CompileShader( vs_4_0, VS() ) );"
    "         SetGeometryShader( NULL );"
    "         SetPixelShader( CompileShader( ps_4_0, PS() ) );"
    "     }"
    "}";


    D3DCompile(
        effectFile, 
        strlen( effectFile ), 
        0, 
        0, 
        0, 
        "SpriteTech", 
        "fx_4_0", 
        0, 
        0, 
        &compiledFx, 
        &errorMsgs
        );


    D3D10CreateEffectFromMemory(
        compiledFx->GetBufferPointer(),
        compiledFx->GetBufferSize(),
        0,
        Device,
        NULL,
        &effect
        );


    compiledFx->Release();


    effectTechnique = effect->GetTechniqueByName( "SpriteTech" );
    effectPass = effectTechnique->GetPassByIndex(0);


    effectPass->GetDesc(&passDesc);
    
    hr = device->CreateInputLayout(
        layoutDesc,
        sizeof( layoutDesc ) / sizeof( layoutDesc[ 0 ] ),
        passDesc.pIAInputSignature,
        passDesc.IAInputSignatureSize,
        &inputLayout
        );


    if (FAILED(hr))
    {
        OutputDebugStringW(L"ID3D10Device::CreateInputLayout failed!");
        //return;
    }
}

I can't make it any simpler than this

Perhaps its expecting the color component to come at an offset of 16, But if that is the case then I think it is strange as my understanding is that it is just a raw data stream and you just tell it where to find the data.

OR it could be to do with alignment?

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.


{ "COLOR", 0, DXGI_FORMAT_B8G8R8A8_UNORM, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0 }

According to this page, it would seem that DXGI_FORMAT_B8G8R8A8_UNORM is not available for D3D10. I'd guess that you'd have no trouble not using a 10.1 device if you used the R8G8B8A8_UNORM (or something similar that's acceptable for your needs) format instead.


{ "COLOR", 0, DXGI_FORMAT_B8G8R8A8_UNORM, 0, 20, D3D10_INPUT_PER_VERTEX_DATA, 0 }

According to this page, it would seem that DXGI_FORMAT_B8G8R8A8_UNORM is not available for D3D10. I'd guess that you'd have no trouble not using a 10.1 device if you used the R8G8B8A8_UNORM (or something similar that's acceptable for your needs) format instead.

That worked. A big thanks to you both.

If you create your device using the D3D10_CREATE_DEVICE_DEBUG flag, then you will get helpful messages in the debugger output window telling exactly why failures like this are occuring. It will also tell you about runtime errors that normally just cause silent failures, such as binding a texture as both a shader resource view and a render target view simultaneously. I always enable it for debug builds, since it can catch a lot of bugs.

If you create your device using the D3D10_CREATE_DEVICE_DEBUG flag, then you will get helpful messages in the debugger output window telling exactly why failures like this are occuring. It will also tell you about runtime errors that normally just cause silent failures, such as binding a texture as both a shader resource view and a render target view simultaneously. I always enable it for debug builds, since it can catch a lot of bugs.

Also: I found you needed the newer Windows SDK on Windows 8 because of Direct3D11.1 and so the debug layer would not work.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

This topic is closed to new replies.

Advertisement