Jump to content
  • Advertisement
Sign in to follow this  
Volks

CreateInputLayout Help

This topic is 1330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Edited by Volks

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites


{ "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.

Share this post


Link to post
Share on other sites

 


{ "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.

Share this post


Link to post
Share on other sites

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.

Edited by MJP

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!