Jump to content

  • Log In with Google      Sign In   
  • Create Account


Loading shaders in D3D11


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
6 replies to this topic

#1 Sepiantum   Members   -  Reputation: 102

Like
0Likes
Like

Posted 01 February 2012 - 06:21 PM

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

Sponsor:

#2 MJP   Moderators   -  Reputation: 10913

Like
0Likes
Like

Posted 01 February 2012 - 06:41 PM

The compiler errors won't be in pShaderBlob, they'll be in pErrors.

#3 Sepiantum   Members   -  Reputation: 102

Like
0Likes
Like

Posted 01 February 2012 - 06:43 PM

Oops... I overlooked that.

EDIT: By setting it to pErrors, I get this error from the compile function:
Spoiler

Follow and support my game engine (still in very basic development)? Link

#4 Sepiantum   Members   -  Reputation: 102

Like
0Likes
Like

Posted 01 February 2012 - 06:59 PM

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

#5 MJP   Moderators   -  Reputation: 10913

Like
0Likes
Like

Posted 01 February 2012 - 07:29 PM

Yeah those are reserved keywords for effect files.

#6 Sepiantum   Members   -  Reputation: 102

Like
0Likes
Like

Posted 01 February 2012 - 08:21 PM

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

#7 InvalidPointer   Members   -  Reputation: 1422

Like
0Likes
Like

Posted 01 February 2012 - 11:21 PM

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.




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