From 864b08394d1e6d366d7c136ffc50e27adfd08447 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 7 Sep 2023 18:02:00 +0200 Subject: Band aid fix for crashing D3D11 Warp setup Rhi can decide to run D3D11 with the software rendering through the software adapter aka "Microsoft Basic Render Driver". This unfortunately does not work well with ANGLE as it can use another adapter and sharing resources between qt and skia can fail. Try to guess which adapter might be used by rhi support or rhi backing store support classes and pass luid for ANGLE. Unfortunately this solution is far from perfect as it creates QRhi just to check what might be used later, however the user can select something totally different with QQuickGraphicsConfiguration. At lest for now we respect QSG_RHI_PREFER_SOFTWARE_RENDERER and QT_D3D_ADAPTER_INDEX. Moreover this patch should cover the case when rhi retrys with DXGI_ADAPTER_FLAG_SOFTWARE adapter if accelerated adapter fails. This is just a band aid patch to support windows on vm and we should come up with better solution. Fixes: QTBUG-116445 Change-Id: I416dd82d688726ce872dc276570fe455d733a48e Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 8cef10f4faa9f2a5982e3cb780100cbc62209b07) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit fd3fd9ea0cb669c29382a473cb6f0e763205a8a7) (cherry picked from commit 4e273b2b305dcbf8967863af83e42c1a081a7d9c) --- src/core/web_engine_context.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index be462a22d..973da88a7 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -4,6 +4,7 @@ #include "web_engine_context.h" #include +#include #include "base/base_switches.h" #include "base/bind.h" @@ -177,6 +178,31 @@ bool usingSoftwareDynamicGL() #endif } +#if defined(Q_OS_WIN) +static QString getAdapterLuid() { + static const bool preferSoftwareDevice = qEnvironmentVariableIntValue("QSG_RHI_PREFER_SOFTWARE_RENDERER"); + QRhiD3D11InitParams rhiParams; + QRhi::Flags flags; + if (preferSoftwareDevice) { + flags |= QRhi::PreferSoftwareRenderer; + } + QScopedPointer rhi(QRhi::create(QRhi::D3D11,&rhiParams,flags,nullptr)); + // mimic what QSGRhiSupport and QBackingStoreRhi does + if (!rhi && !preferSoftwareDevice) { + flags |= QRhi::PreferSoftwareRenderer; + rhi.reset(QRhi::create(QRhi::D3D11, &rhiParams, flags)); + } + if (rhi) { + const QRhiD3D11NativeHandles *handles = + static_cast(rhi->nativeHandles()); + Q_ASSERT(handles); + return QString("%1,%2").arg(handles->adapterLuidHigh).arg(handles->adapterLuidLow); + } else { + return QString(); + } +} +#endif + static bool openGLPlatformSupport() { return QGuiApplicationPrivate::platformIntegration()->hasCapability( @@ -727,6 +753,14 @@ WebEngineContext::WebEngineContext() } #endif +#if defined(Q_OS_WIN) + if (QQuickWindow::graphicsApi() == QSGRendererInterface::Direct3D11) { + const QString luid = getAdapterLuid(); + if (!luid.isEmpty()) + parsedCommandLine->AppendSwitchASCII(switches::kUseAdapterLuid, luid.toStdString()); + } +#endif + initializeFeatureList(parsedCommandLine, enableFeatures, disableFeatures); GLContextHelper::initialize(); -- cgit v1.2.3