Integration Direct3D 12 in Qt
-
Hello. I use Qt 5.12.3 and Qt Creator 4.9.1 to create an application using Direct3D 12. I wrote the following testing code:
using uint = unsigned int; ComPtr<IDXGIFactory4> dx_dxgiFactory(nullptr); std::vector<ComPtr<IDXGIAdapter1>> adapters; ComPtr<IDXGIAdapter1> adapter(nullptr); ComPtr<ID3D12Device1> dx_Device(nullptr); D3D_FEATURE_LEVEL dx_featureLevels [] = { D3D_FEATURE_LEVEL_12_1, D3D_FEATURE_LEVEL_12_0, D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1 }; if(FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&dx_dxgiFactory)))) return -1; for(uint i(0); dx_dxgiFactory->EnumAdapters1(i, adapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND;i++) adapters.push_back(adapter); for(auto&& a: adapters) { // DXGI_ADAPTER_DESC1 desc; // a->GetDesc1(&desc); // qDebug() << QString::fromStdWString(std::wstring(desc.Description)); for(auto&& l: dx_featureLevels) if(SUCCEEDED(D3D12CreateDevice(a.Get(), l, IID_PPV_ARGS(dx_Device.GetAddressOf())))) { qDebug() << "OK"; return 1; } } return -1;
This code works fine in release, if you debug at each step, but then, when i call the D3D12CreateDevice, I have error :
Screenshot
However, the method returns S_OK. Why is this happening?
PS : I have two graphic adapter - Intel HD Graphics 620 & nVidia GeForce 950M. I use a low-performance adapter Intel by default. I import the following variable, for using high-performance nVidia adapter :extern "C" { __declspec(dllexport) unsigned int NvOptimusEnablement = 1; }
This gives me the ability to get the first nVidia graphics card when listing all adapters. But this doesnt solve the problem, the error still remains.
I tried also inserting the code in a try - catch block, but it doesn't stop the exception :try { for(auto&& a: adapters) { // DXGI_ADAPTER_DESC1 desc; // a->GetDesc1(&desc); // qDebug() << QString::fromStdWString(std::wstring(desc.Description)); for(auto&& l: dx_featureLevels) if(SUCCEEDED(D3D12CreateDevice(a.Get(), l, IID_PPV_ARGS(dx_Device.GetAddressOf())))) { qDebug() << "OK"; return 1; } } } catch(...) { qDebug() << "error create dx12 device"; // unreachable code ! }
Please, help me :)
PS : I'm using the 64 bit MSVC compiler 2017 -
@range36rus Did you try to ask in a Direct3D related forum as this isn't related to Qt?
Chances to get an answer are higher then asking people who have experience with Direct3D. -
@jsulm I ran the same code in Visual Studio and didn't have any problems
-
@range36rus said in Integration Direct3D 12 in Qt:
I ran the same code in Visual Studio and didn't have any problems
Did you use the same compiler and run the debugger?
-
@JKSH Yes of course
-
@range36rus said in Integration Direct3D 12 in Qt:
Yes of course
And just to double-check: You're compiling exactly the same source code in both IDEs? In other words, you're also linking to the Qt libraries in Visual Studio?
If that's the case, you'll need to identify what's different in the 2 builds (compiler options, defined flags, etc). Your Makefile might contain a clue.
-
@JKSH Yes, I created two simple console applications and added required libraries to them. Compiler keys are identical. I checked carefully. A one project have a mistake, and another doesn't have For example, a project with subprojects have this error, but QT Widgets does not have (but not always). Heisenbug?