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-22 14:31:56 +0000
commitfd3fd9ea0cb669c29382a473cb6f0e763205a8a7 (patch)
tree60b3d64f6d62d4df2e4f3b714919528df8139859
parent24ad45f904ef7198f7c7f9d184625916e322fbb9 (diff)
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 Pick-to: 6.6.0 6.5 6.5.3 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>
-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 545205de8..74c0b1672 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/functional/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(
@@ -721,6 +747,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();