Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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};
#if defined( DEBUG ) || defined( _DEBUG )
    flags |= D3DCOMPILE_DEBUG;
    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[] =
        {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},

    dev->CreateInputLayout(ied, 2, VS->GetBufferPointer(), VS->GetBufferSize(), &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

closed as off-topic by Josh Petrie Dec 17 '14 at 18:00

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 '14 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 '14 at 5:18
I came here only to realize that my binary shaders were full of 0s for some reason. – RelativeGames Dec 31 '14 at 11:18

Browse other questions tagged or ask your own question.