'D3DCompileFromFile function throwing exception and not working?
I recently tried to pick up DirectX12 and already ran into my first issue. The D3DCompileFromFile function just doesn't seem to work. I am using it as follows:
ComPtr<ID3DBlob> vertex_shader_blob;
throw_if_failed(D3DCompileFromFile(L"basic_vertex_shader.hlsl", nullptr, nullptr, "main", "vs_6_5", 0, 0, &vertex_shader_blob, nullptr));
I have the d3dcompiler.h included, the d3dcompiler.lib linked and have the d3dcompiler_47.dll in the same directory as the .exe. My working directory is set to the correct path and the D3DReadFileToBlob function works perfect using the same file name (of course using the .cso file and not the .hlsl). My entry function is called main and the vs_6_5 target works fine when using the built-in Visual Studio compiler.
What I have already tried:
Changing the path to the full system path, which doesn't change the ourcome. I originally had compile flags (D3DCOMPILE_DEBUG), but removed them, however, this also did not change the outcome. Changing to the target to different version such as vs_5_0, also doesn't help.
The HRESULT output is 0x8876086c, however, I was not able to find any error code matching this value.
My throw_if_failed function is the usual:
static inline void throw_if_failed(HRESULT hr)
{
#ifdef AC_DEBUG
if (FAILED(hr))
{
throw std::exception();
}
#endif // AC_DEBUG
}
and the exact console output is as follows:
Exception thrown at 0x00007FFD45474F69 in demo.exe: Microsoft C++ exception: std::exception at memory location 0x0000006AA6FCE2E8.
Unhandled exception at 0x00007FFD45474F69 in demo.exe: Microsoft C++ exception: std::exception at memory location 0x0000006AA6FCE2E8.
During the hours spent trying to resolve this issue I also noticed that according to microsoft, the D3DCompileFromFile function returns a Direct3D 11 return code, even though the website was updated recently? Which makes me question its viability with DirectX12.
Now you might wonder why I would want to use the D3DCompileFromFile function if the D3DReadFileToBlob function works fine? Well, it's more about principle and finding out where I went wrong to better understand what I am dealing with.
Edit: When using the Visual Studio built-in hlsl compiler, vs_6_5 works completely fine. Additionally, according to the DirectX Caps Viewer, my GTX 1070 supports D3D_FEATURE_LEVEL_12_1 and Shader model 6.5.
Solution 1:[1]
Ok, I just found the solution: The d3dcompiler is only viable for Shader Model 2 - 5.1. I have to use the dcx compiler for anything newer, this is kind of hidden on the Microsoft docs page. (I know that image only shows reflection functions, but the way I understood it in general, is that the dcx compiler is the future) Anyway, I can confirm, that the dcx compiler works perfectly fine.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adam |
