Sign in to follow this  
jeffreyp23

CreateVertexShader fails

Recommended Posts

jeffreyp23    178
Hello,

I'm getting some strange error when trying to compile my vertex shader :
[source]
D3D11: ERROR: ID3D11Device::CreateVertexShader: Encoded Vertex Shader size doesn't match specified size. [ STATE_CREATION ERROR #166: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ]
[/source]

I already searched with Google but i couldn't find anything useful.
Here is my code :

c++
[source]

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;
}
[/source]
Vertex shader :
[source]

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;
}
[/source]

Pixel Shader :
[source]

float4 main(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}
[/source]

I'm using SM 4.

Thanks in advance.

Share this post


Link to post
Share on other sites
Hornsj3    195
It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile. Edited by Hornsj3

Share this post


Link to post
Share on other sites
jeffreyp23    178
[quote name='Hornsj3' timestamp='1341058590' post='4954293']
It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.
[/quote]

I'm using visual studio 11. So i compile it from there : )
Also the buffer size isn't 0. Edited by Jeffreyp

Share this post


Link to post
Share on other sites
Hornsj3    195
[quote name='Jeffreyp' timestamp='1341060941' post='4954299']
[quote name='Hornsj3' timestamp='1341058590' post='4954293']
It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.
[/quote]

I'm using visual studio 11. So i compile it from there : )
Also the buffer size isn't 0.
[/quote]

Am I missing something or maybe you don't know that shaders have to be compiled to byte code? What function are you calling to compile the shader into bytecode?

Share this post


Link to post
Share on other sites
jeffreyp23    178
[quote name='Hornsj3' timestamp='1341064189' post='4954312']
[quote name='Jeffreyp' timestamp='1341060941' post='4954299']
[quote name='Hornsj3' timestamp='1341058590' post='4954293']
It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.
[/quote]

I'm using visual studio 11. So i compile it from there : )
Also the buffer size isn't 0.
[/quote]

Am I missing something or maybe you don't know that shaders have to be compiled to byte code? What function are you calling to compile the shader into bytecode?
[/quote]

I found the problem. I did put the hlsl files instead of the cso files at
[source]
D3DReadFileToBlob
[/source]
It is working now. Thanks : ) Edited by Jeffreyp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this