Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been trying to get a tutorial Direct X 11 application running for some time now. I'm being stymied when I try to create the vertex shader. Setting the Direct X Debug setting reveals that I am getting this error.

D3D11 ERROR: ID3D11Device::CreateVertexShader: Encoded Vertex Shader size doesn't match specified size. [ STATE_CREATION ERROR #166: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE]

I have compiled the hlsl shader code using Visual Studio 2012 Express into "shaders.cso" and that appears to load okay. According to the HRESULT return from D3DReadFileToBlob. However, the CreateVertexShader call returns "E_INVALIDARG One or more arguments are invalid."

After this the program fails on a Draw attempt.

I have checked the size of the blob buffer and it is the same size as the shaders.cso file.

I have included the code which sets this up below.

void InitPipeline()
{
    HRESULT hr;

    // load and compile the two shaders
    ID3DBlob *VS = nullptr, *PS = nullptr;
    ID3DBlob *errorBlob = nullptr;

    const D3D_SHADER_MACRO defines[] = {"EXAMPLE_DEFINE", "1", NULL, NULL};
    UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    flags |= D3DCOMPILE_DEBUG;
#endif
    hr = D3DReadFileToBlob(L"shaders.cso", &VS);


    // encapsulate both shaders into shader objects
    auto vbs = VS->GetBufferSize();
    auto vbp = VS->GetBufferPointer();


    hr = dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), nullptr, &pVS); // This function returns "E_INVALIDARG One or more arguments are invalid." and pVS is returned as NULL

    // set the shader objects
    devcon->VSSetShader(pVS, 0, 0);

    // create the input layout object
    D3D11_INPUT_ELEMENT_DESC ied[] =
    {
        {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
    };

    dev->CreateInputLayout(ied, 2, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout);
    devcon->IASetInputLayout(pLayout);
}

For reference this is the shader code.

cbuffer ConstantBuffer
{
    float4x4 matFinal;
}

struct VOut
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
};

VOut main(float4 position : POSITION, float4 color : COLOR)
{
    VOut output;

    output.position = mul(matFinal, position);
    output.color = color;

    return output;
}

I'll admit to not knowing much about shader code. Honestly, I'd prefer to do without it at this stage of re-learning D3D, but it appears to be required to use DX11.

Can anyone shed any light on this?

share|improve this question

put on hold as off-topic by Josh Petrie yesterday

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about debugging a problem in your project must present a concise selection of code and context so as to allow a reader to diagnose the issue without needing to read all of your code or to engage in extensive back-and-forth dialog. For more information, see this meta thread." – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Note I don't really have a good suggestion as to why you are getting this weird result. Are you mixing the use of Windows 8 and the legacy DirectX SDK in this project? You may find that using DirectX Tool Kit a bit easier as it provides a number of ready-to-use stock shaders. –  Chuck Walbourn Jul 1 at 6:26
    
Thanks Chuck. I gave up on this some time ago, but thanks for the tip on the DX toolkit, I'll check it out when I get a bit of time. Cheers. –  John Judd Jul 3 at 5:18

Browse other questions tagged or ask your own question.