Initialize QRhiD3D12::activeAdapter for imported device path

This commit makes it so the QRhiD3D12::activeAdapter is set when
using an imported device. QD3D12MemoryAllocator::create would
crash before as it would attempt to call IDXGIAdapter1::GetDesc1
on the passed uninitalized pointer. With this change using an
imported device with the d3d12 rhi backend will no longer crash
the application.

Fixes: QTBUG-122007
Pick-to: 6.6
Change-Id: Iadc67fee0c7ee70ac904f66a523acd3b1a63e42b
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
(cherry picked from commit 95c20ffac3473f9188df363aebcb911589645806)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Oliver Dawes 2024-02-06 17:43:43 +00:00 committed by Qt Cherry-pick Bot
parent 6ae9a8441e
commit c56553ae3d

View File

@ -292,14 +292,20 @@ bool QRhiD3D12::create(QRhi::Flags flags)
for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) { for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
DXGI_ADAPTER_DESC1 desc; DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc); adapter->GetDesc1(&desc);
adapter->Release();
if (desc.AdapterLuid.LowPart == adapterLuid.LowPart if (desc.AdapterLuid.LowPart == adapterLuid.LowPart
&& desc.AdapterLuid.HighPart == adapterLuid.HighPart) && desc.AdapterLuid.HighPart == adapterLuid.HighPart)
{ {
activeAdapter = adapter;
QRhiD3D::fillDriverInfo(&driverInfoStruct, desc); QRhiD3D::fillDriverInfo(&driverInfoStruct, desc);
break; break;
} else {
adapter->Release();
} }
} }
if (!activeAdapter) {
qWarning("No adapter");
return false;
}
qCDebug(QRHI_LOG_INFO, "Using imported device %p", dev); qCDebug(QRHI_LOG_INFO, "Using imported device %p", dev);
} }