Jump to content
  • Advertisement
Sign in to follow this  
Sepiantum

DX11 Loading shaders in D3D11

This topic is 2509 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}

Share this post


Link to post
Share on other sites
Advertisement
The compiler errors won't be in pShaderBlob, they'll be in pErrors.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!