summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2023-09-07 18:02:00 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-25 08:45:03 +0000
commit864b08394d1e6d366d7c136ffc50e27adfd08447 (patch)
tree30df6ca1ea94eb415c08b34a3954df0945eebc25
parentcc057a2df56bdb0f959576a44a53c8d1efdaea6a (diff)
Band aid fix for crashing D3D11 Warp setupv6.5.36.5.3
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 <allan.jensen@qt.io> (cherry picked from commit 8cef10f4faa9f2a5982e3cb780100cbc62209b07) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit fd3fd9ea0cb669c29382a473cb6f0e763205a8a7) (cherry picked from commit 4e273b2b305dcbf8967863af83e42c1a081a7d9c)
-rw-r--r--src/core/web_engine_context.cpp34
1 files changed, 34 insertions, 0 deletions
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 <math.h>
+#include <QtGui/private/qrhi_p.h>
#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<QRhi> 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<const QRhiD3D11NativeHandles *>(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();