Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


CreateVertexShader fails


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Jeffreyp   Members   -  Reputation: 178

Like
0Likes
Like

Posted 30 June 2012 - 06:08 AM

Hello,

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.

Sponsor:

#2 Hornsj3   Members   -  Reputation: 191

Like
0Likes
Like

Posted 30 June 2012 - 06:16 AM

It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.

Edited by Hornsj3, 30 June 2012 - 06:20 AM.


#3 Jeffreyp   Members   -  Reputation: 178

Like
0Likes
Like

Posted 30 June 2012 - 06:55 AM

It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.


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

Edited by Jeffreyp, 30 June 2012 - 06:56 AM.


#4 Hornsj3   Members   -  Reputation: 191

Like
1Likes
Like

Posted 30 June 2012 - 07:49 AM


It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.


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


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?

#5 Jeffreyp   Members   -  Reputation: 178

Like
1Likes
Like

Posted 30 June 2012 - 08:05 AM



It doesn't look like you are compiling it anywhere.

Check out D3DCompileFromFile.


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


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?


I found the problem. I did put the hlsl files instead of the cso files at
D3DReadFileToBlob

It is working now. Thanks : )

Edited by Jeffreyp, 30 June 2012 - 08:06 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS