Loading shaders in D3D11

Started by
5 comments, last by InvalidPointer 12 years, 2 months ago
Shader loading code is as follows:
bool QuantumGameEngine::QuantumGraphics::CVertexShader::CompileShaderFromFile(LPCWSTR pSrcFile,
D3D10_SHADER_MACRO* pDefines,
LPD3D10INCLUDE pInclude,
LPCSTR pFunctionName,
LPCSTR pProfile,
UINT Flags1,
UINT Flags2,
ID3DX11ThreadPump* pPump){
//Compile our shader
if(FAILED(D3DX11CompileFromFileW(pSrcFile, pDefines, pInclude, pFunctionName, pProfile, Flags1, Flags2, pPump, &this->pShaderBlob, &this->pErrors, NULL))){
this->log(LEVEL_ERROR, "Failed to compile shaders");
if(this->pShaderBlob){
MessageBox(NULL, reinterpret_cast<LPCWSTR>(this->pShaderBlob->GetBufferPointer()), L"FAIL", MB_OK);
} else {
MessageBox(NULL, L"FAIL", L"FAIL", MB_OK);
}
return false;
}
//Turn the blob into a shader
if(FAILED(this->pGC->pDevice->CreateVertexShader(this->pShaderBlob->GetBufferPointer(), this->pShaderBlob->GetBufferSize(), NULL, &this->pVertexShader))){
this->log(LEVEL_ERROR, "Failed to turn blob into shader object");
return false;
}
//Release the blob because we don't need it
this->pShaderBlob->Release();
this->pShaderBlob = nullptr;
//Release the errors
if(this->pErrors){
this->pErrors->Release();
this->pErrors = nullptr;
}
return true;
}


Code that is used to call shader loading code:

if(!this->pVS->CompileShaderFromFile(L"Shaders\\shaders.hlsl", NULL, NULL, "VertexShader", "vs_5_0", NULL, NULL, NULL)){
this->log(LEVEL_ERROR, "Failed to compile vertex shader");
return false;
}
if(!this->pPS->CompileShaderFromFile(L"Shaders\\shaders.hlsl", NULL, NULL, "PixelShader", "ps_5_0", NULL, NULL, NULL)){
this->log(LEVEL_ERROR, "Failed to compile pixel shader");
return false;
}


The call always returns with D3DX11CompileFromFileW failing and the shader error blob to be null. I never had any troubles with compiling shaders in DX9 and DX10...

EDIT: Here is shader code:
struct VIn {
float4 position : POSITION;
float4 color : COLOR;
};
struct VOut {
float4 position : SV_POSITION;
float4 color : COLOR;
};
VOut VertexShader(VIn in){
VOut out;
out.position = in.position;
out.color = in.color;
return out;
}
float4 PixelShader(VOut in) : SV_TARGET {
return in.color;
}
Follow and support my game engine (still in very basic development)? Link
Advertisement
The compiler errors won't be in pShaderBlob, they'll be in pErrors.
Oops... I overlooked that.

EDIT: By setting it to pErrors, I get this error from the compile function:
[spoiler]Error message: C:\Important Stuff\Quantum Game Engine\Quantum Game Engine\StemVGC\Shaders\shaders.hlsl(11,6): error X3000: syntax error: unexpected token 'VertexShader'[/spoiler]
Follow and support my game engine (still in very basic development)? Link
Problem solved... It seems as if you cannot name things in or out or VertexShader or PixelShader.
Follow and support my game engine (still in very basic development)? Link
Yeah those are reserved keywords for effect files.
Apart from that, are there any other key details I need to note for writing shaders for D3D11?
Follow and support my game engine (still in very basic development)? Link
There's always the MSDN documentation available on Microsoft's website and/or your local DXSDK installation. The only thing it doesn't go over in extreme depth is optimization, and this is mainly because the specific method(s) are going to be different every card generation and frequently can contradict best practices for GPUs designed by competing IHVs. Textbook example of the latter is the old ATi/AMD vector-based ALU (doing things on single floats at a time is wasteful, though not necessarily slower per se) vs. the nVidia superscalar architecture, but I guess the new Radeon 7000s are actually moving over.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

This topic is closed to new replies.

Advertisement