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-26 07:44:15 +0000
commit8ed9df0eb5de7c7484879933ccb77e11474a7670 (patch)
tree0b44ea9687708bc27c862bddd1dc34afea628c4d
parent4cbdd7a69ab68e6b2d69d8b28514e040c99100b4 (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 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)
-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();