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.
CreateVertexShader fails
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.
[quote name='Hornsj3' timestamp='1341058590' post='4954293']
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.
[/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 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.
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 : )
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement