I'm getting some strange error when trying to compile my vertex shader :
D3D11: ERROR: ID3D11Device::CreateVertexShader: Encoded Vertex Shader size doesn't match specified size. [ STATE_CREATION ERROR #166: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ]
I already searched with Google but i couldn't find anything useful.
Here is my code :
c++
ID3DBlob *VS, *PS;
ID3D11VertexShader *m_pVS;
ID3D11PixelShader *m_pPS;
if(FAILED(D3DReadFileToBlob(pixelShader.c_str(), &PS)))
{
shader.isValid = false;
return;
}
if(FAILED(D3DReadFileToBlob(vertexShader.c_str(), &VS)))
{
shader.isValid = false;
return;
}
auto i = VS->GetBufferSize();
if(FAILED(m_pimpl->m_pDevice->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &m_pVS)))
{
std::cout << std::endl <<"Warning : failed to create vertex shader at file : " << " " << vertexShader.c_str() << std::endl;
shader.isValid = false;
return;
}
if(FAILED(m_pimpl->m_pDevice->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &m_pPS)))
{
std::cout << std::endl <<"Warning : failed to create pixel shader at file : " << " " << pixelShader.c_str() << std::endl;
shader.isValid = false;
return;
}
Vertex shader :
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;
}
Pixel Shader :
float4 main(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}
I'm using SM 4.
Thanks in advance.






