I'm starting out learning graphics programming with DX11 and Win32 and so far I haven't found many quality resources. At the moment I'm trying to string together a few tutorrials (some based on DX10) to try and learn the basics. The tutorial I was reading used a D3DX function to compile shaders but as far as I understand, this library is deprecated? After some digging, I found the D3DCompileFromFile() function which I'm trying to use.
Here is my c++ code:
HINSTANCE d3d_compiler_lib = LoadLibrary("D3DCompiler_47.DLL");
assert(d3d_compiler_lib != NULL);
typedef HRESULT (WINAPI *d3d_shader_compile_func)(
LPCWSTR,
const D3D_SHADER_MACRO *,
ID3DInclude *,
LPCSTR,
LPCSTR,
UINT,
UINT,
ID3DBlob **,
ID3DBlob **);
d3d_shader_compile_func D3DCompileFromFile = (d3d_shader_compile_func)GetProcAddress(
d3d_compiler_lib,
"D3DCompileFromFile");
assert(D3DCompileFromFile != NULL);
ID3D10Blob *vs, *ps;
hresult = D3DCompileFromFile(
L"basic.shader",
NULL,
NULL,
"VertexShader",
"vs_4_0",
0,
0,
&vs,
NULL);
assert(hresult == S_OK); // Fails here
hresult = D3DCompileFromFile(
L"basic.shader",
NULL,
NULL,
"PixelShader",
"ps_4_0",
0,
0,
&ps,
NULL);
assert(hresult == S_OK);
FreeLibrary(d3d_compiler_lib);
In the failing assertion, hresult is 'E_FAIL', which according to MSDN, means: "Attempted to create a device with the debug layer enabled and the layer is not installed." I'm a bit lost at this point. I am also not 100% sure my D3DCompileFromFile signature is correct... It does match the version on MSDN though.
Any ideas as to why this might be failing? I tried putting in the wrong file name and got (as expected) hresult == D3D11_ERROR_FILE_NOT_FOUND. So at least this is some indication that I haven't totally screwed up the function call.
For reference, here is the shader file. I was able to compile it successfully using an online HLSL compiler.
struct VOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
VOut VertexShader(float4 position : POSITION, float4 color : COLOR)
{
VOut output;
output.position = position;
output.color = color;
return output;
}
float4 PixelShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}
Thanks for your time