From 737dd9595058a457fdd8f336ee8630cb1e2c57bb Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 6 Sep 2023 14:54:07 +0200 Subject: [PATCH] rhi: Map DXGI_ADAPTER_FLAG_SOFTWARE onto the driverInfo's CpuDevice Fixes: QTBUG-116756 Change-Id: I6218ea3f59716873853b8bf83b18e0a799eedcc3 Reviewed-by: Andy Nichols --- src/gui/rhi/qrhi.cpp | 8 +++++--- src/gui/rhi/qrhid3d11.cpp | 18 +++++++++--------- src/gui/rhi/qrhid3d12.cpp | 8 ++------ src/gui/rhi/qrhid3dhelpers.cpp | 10 ++++++++++ src/gui/rhi/qrhid3dhelpers_p.h | 3 +++ 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 92bfcda041..0728d7824d 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -8419,9 +8419,11 @@ const char *QRhi::backendName() const /*! \enum QRhiDriverInfo::DeviceType - Specifies the graphics device's type, when the information is available. In - practice this is only applicable with Vulkan and Metal. With others the - value will always be UnknownDevice. + Specifies the graphics device's type, when the information is available. + + In practice this is only applicable with Vulkan and Metal. With Direct 3D + 11 and 12, using an adapter with the software flag set leads to the value + \c CpuDevice. Otherwise, and with OpenGL, the value is always UnknownDevice. \value UnknownDevice \value IntegratedDevice diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index e875eac414..310e47027a 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -247,9 +247,7 @@ bool QRhiD3D11::create(QRhi::Flags flags) if (!activeAdapter && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) { activeAdapter = adapter; adapterLuid = desc.AdapterLuid; - driverInfoStruct.deviceName = name.toUtf8(); - driverInfoStruct.deviceId = desc.DeviceId; - driverInfoStruct.vendorId = desc.VendorId; + QRhiD3D::fillDriverInfo(&driverInfoStruct, desc); qCDebug(QRHI_LOG_INFO, " using this adapter"); } else { adapter->Release(); @@ -330,12 +328,14 @@ bool QRhiD3D11::create(QRhi::Flags flags) if (SUCCEEDED(dev->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast(&dxgiDev)))) { IDXGIAdapter *adapter = nullptr; if (SUCCEEDED(dxgiDev->GetAdapter(&adapter))) { - DXGI_ADAPTER_DESC desc; - adapter->GetDesc(&desc); - adapterLuid = desc.AdapterLuid; - driverInfoStruct.deviceName = QString::fromUtf16(reinterpret_cast(desc.Description)).toUtf8(); - driverInfoStruct.deviceId = desc.DeviceId; - driverInfoStruct.vendorId = desc.VendorId; + IDXGIAdapter1 *adapter1 = nullptr; + if (SUCCEEDED(adapter->QueryInterface(__uuidof(IDXGIAdapter1), reinterpret_cast(&adapter1)))) { + DXGI_ADAPTER_DESC1 desc; + adapter1->GetDesc1(&desc); + adapterLuid = desc.AdapterLuid; + QRhiD3D::fillDriverInfo(&driverInfoStruct, desc); + adapter1->Release(); + } adapter->Release(); } dxgiDev->Release(); diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 38f1a366d7..3215336db5 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -254,9 +254,7 @@ bool QRhiD3D12::create(QRhi::Flags flags) if (!activeAdapter && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) { activeAdapter = adapter; adapterLuid = desc.AdapterLuid; - driverInfoStruct.deviceName = name.toUtf8(); - driverInfoStruct.deviceId = desc.DeviceId; - driverInfoStruct.vendorId = desc.VendorId; + QRhiD3D::fillDriverInfo(&driverInfoStruct, desc); qCDebug(QRHI_LOG_INFO, " using this adapter"); } else { adapter->Release(); @@ -290,9 +288,7 @@ bool QRhiD3D12::create(QRhi::Flags flags) if (desc.AdapterLuid.LowPart == adapterLuid.LowPart && desc.AdapterLuid.HighPart == adapterLuid.HighPart) { - driverInfoStruct.deviceName = QString::fromUtf16(reinterpret_cast(desc.Description)).toUtf8(); - driverInfoStruct.deviceId = desc.DeviceId; - driverInfoStruct.vendorId = desc.VendorId; + QRhiD3D::fillDriverInfo(&driverInfoStruct, desc); break; } } diff --git a/src/gui/rhi/qrhid3dhelpers.cpp b/src/gui/rhi/qrhid3dhelpers.cpp index 3ee5ae5832..ba704805d4 100644 --- a/src/gui/rhi/qrhid3dhelpers.cpp +++ b/src/gui/rhi/qrhid3dhelpers.cpp @@ -155,6 +155,16 @@ std::pair createDxcCompiler() } #endif +void fillDriverInfo(QRhiDriverInfo *info, const DXGI_ADAPTER_DESC1 &desc) +{ + const QString name = QString::fromUtf16(reinterpret_cast(desc.Description)); + info->deviceName = name.toUtf8(); + info->deviceId = desc.DeviceId; + info->vendorId = desc.VendorId; + info->deviceType = (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) ? QRhiDriverInfo::CpuDevice + : QRhiDriverInfo::UnknownDevice; +} + } // namespace QT_END_NAMESPACE diff --git a/src/gui/rhi/qrhid3dhelpers_p.h b/src/gui/rhi/qrhid3dhelpers_p.h index f8919a23ad..ebacf7387e 100644 --- a/src/gui/rhi/qrhid3dhelpers_p.h +++ b/src/gui/rhi/qrhid3dhelpers_p.h @@ -17,6 +17,7 @@ #include #include +#include #include @@ -45,6 +46,8 @@ IDCompositionDevice *createDirectCompositionDevice(); std::pair createDxcCompiler(); #endif +void fillDriverInfo(QRhiDriverInfo *info, const DXGI_ADAPTER_DESC1 &desc); + } // namespace QT_END_NAMESPACE