diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-08-12 14:08:50 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-08-13 08:19:10 +0200 |
commit | cc3918abbc45ccb2716c279a603d1aaee96b974e (patch) | |
tree | 3ad9cea91041fc9f1b7017fb5be77951606a36ca /src | |
parent | 7922cd5272f84ca4180d6ebb45e5a81a45d14a92 (diff) |
RHI/Windows: Fix launching of MSVC binaries on Windows 7
Dynamically resolve CreateDXGIFactory2() which is not present
on the platform.
Task-number: QTBUG-76845
Change-Id: I4d15d72633544a8c11d2b78c8736cd20a2afdff1
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/rhi/qrhid3d11.cpp | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 0c5df600a0..c0b13f1cc8 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -157,6 +157,36 @@ static inline Int aligned(Int v, Int byteAlign) return (v + byteAlign - 1) & ~(byteAlign - 1); } +static IDXGIFactory1 *createDXGIFactory2() +{ + IDXGIFactory1 *result = nullptr; + if (QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7) { + using PtrCreateDXGIFactory2 = HRESULT (WINAPI *)(UINT, REFIID, void **); + QSystemLibrary dxgilib(QStringLiteral("dxgi")); + if (auto createDXGIFactory2 = (PtrCreateDXGIFactory2)dxgilib.resolve("CreateDXGIFactory2")) { + const HRESULT hr = createDXGIFactory2(0, IID_IDXGIFactory2, reinterpret_cast<void **>(&result)); + if (FAILED(hr)) { + qWarning("CreateDXGIFactory2() failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr))); + result = nullptr; + } + } else { + qWarning("Unable to resolve CreateDXGIFactory2()"); + } + } + return result; +} + +static IDXGIFactory1 *createDXGIFactory1() +{ + IDXGIFactory1 *result = nullptr; + const HRESULT hr = CreateDXGIFactory1(IID_IDXGIFactory1, reinterpret_cast<void **>(&result)); + if (FAILED(hr)) { + qWarning("CreateDXGIFactory1() failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr))); + result = nullptr; + } + return result; +} + bool QRhiD3D11::create(QRhi::Flags flags) { Q_UNUSED(flags); @@ -165,19 +195,14 @@ bool QRhiD3D11::create(QRhi::Flags flags) if (debugLayer) devFlags |= D3D11_CREATE_DEVICE_DEBUG; - HRESULT hr; -#if !defined(Q_CC_MINGW) - hasDxgi2 = QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7; - if (hasDxgi2) - hr = CreateDXGIFactory2(0, IID_IDXGIFactory2, reinterpret_cast<void **>(&dxgiFactory)); + dxgiFactory = createDXGIFactory2(); + if (dxgiFactory != nullptr) + hasDxgi2 = true; else -#endif - hr = CreateDXGIFactory1(IID_IDXGIFactory1, reinterpret_cast<void **>(&dxgiFactory)); + dxgiFactory = createDXGIFactory1(); - if (FAILED(hr)) { - qWarning("Failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr))); + if (dxgiFactory == nullptr) return false; - } if (!importedDevice) { IDXGIAdapter1 *adapterToUse = nullptr; |