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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.