Skip to content

Commit 39da243

Browse files
committed
Add more detailed GPU information to logs
RHI and ANGLE may use different GPUs and this may lead to various errors. Try to detect these cases from log messages. Enable the following logging rules to compare GPUs in use: QT_LOGGING_RULES="qt.webenginecontext=true;qt.webengine.compositor=true" Pick-to: 6.9 Task-number: QTBUG-135786 Change-Id: I1097acf3d20128b259533a3657532d068f244752 Reviewed-by: Moss Heim <[email protected]> Reviewed-by: Allan Sandfeld Jensen <[email protected]>
1 parent 05ef4f8 commit 39da243

File tree

3 files changed

+119
-4
lines changed

3 files changed

+119
-4
lines changed

src/core/content_client_qt.cpp

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "content_client_qt.h"
55

6+
#include "compositor/compositor.h"
7+
68
#include "base/command_line.h"
79
#include "base/files/file_util.h"
810
#include "base/json/json_string_value_serializer.h"
@@ -29,7 +31,7 @@
2931
#include <QLibraryInfo>
3032
#include <QString>
3133
#include <QSysInfo>
32-
34+
#include <QThread>
3335

3436
#if BUILDFLAG(ENABLE_LIBRARY_CDMS)
3537
#include "media/cdm/cdm_paths.h" // nogncheck
@@ -485,4 +487,104 @@ blink::OriginTrialPolicy *ContentClientQt::GetOriginTrialPolicy()
485487
return origin_trial_policy_.get();
486488
}
487489

490+
void ContentClientQt::SetGpuInfo(const gpu::GPUInfo &gpu_info)
491+
{
492+
if (Q_LIKELY(!lcWebEngineCompositor().isDebugEnabled()))
493+
return;
494+
495+
base::CommandLine *commandLine = base::CommandLine::ForCurrentProcess();
496+
const bool isBrowserProcess = !commandLine->HasSwitch(switches::kProcessType);
497+
const bool isMainThread = QThread::currentThread() == qApp->thread();
498+
499+
// Limit this to the main thread of the browser process for now.
500+
if (!isBrowserProcess || !isMainThread)
501+
return;
502+
503+
if (!gpu_info.IsInitialized()) {
504+
// This is probably not an issue but suspicious.
505+
qCDebug(lcWebEngineCompositor, "Failed to initialize GPUInfo.");
506+
return;
507+
}
508+
509+
const gpu::GPUInfo::GPUDevice &primary = gpu_info.gpu;
510+
511+
// Do not print the info again if the device hasn't been changed.
512+
// Change of the device is unexpected: we don't support or implement fallback yet.
513+
// It is suspicious if the info is logged twice.
514+
if (m_gpuInfo && m_gpuInfo->gpu.device_string == primary.device_string)
515+
return;
516+
m_gpuInfo = gpu_info;
517+
518+
auto deviceToString = [](const gpu::GPUInfo::GPUDevice &device) -> QString {
519+
if (device.vendor_id == 0x0)
520+
return "Disabled"_L1;
521+
522+
QString log;
523+
524+
// TODO: Factor vendor translation out from QtWebEngineCore::GPUInfo.
525+
// Only name the most commmon desktop GPU hardware vendors for now.
526+
switch (device.vendor_id) {
527+
case 0x1002:
528+
log += "AMD"_L1;
529+
break;
530+
case 0x10DE:
531+
log += "Nvidia"_L1;
532+
break;
533+
case 0x8086:
534+
log += "Intel"_L1;
535+
break;
536+
default:
537+
log += "vendor id: 0x"_L1 + QString::number(device.vendor_id, 16);
538+
}
539+
540+
log += ", device id: 0x"_L1 + QString::number(device.device_id, 16);
541+
542+
if (!device.driver_vendor.empty()) {
543+
log += ", driver: "_L1 + QLatin1StringView(device.driver_vendor) + u' '
544+
+ QLatin1StringView(device.driver_version);
545+
}
546+
log += ", system device id: 0x"_L1 + QString::number(device.system_device_id, 16);
547+
548+
log += ", preference: "_L1;
549+
switch (device.gpu_preference) {
550+
case gl::GpuPreference::kNone:
551+
log += "None"_L1;
552+
break;
553+
case gl::GpuPreference::kDefault:
554+
log += "Default"_L1;
555+
break;
556+
case gl::GpuPreference::kLowPower:
557+
log += "LowPower"_L1;
558+
break;
559+
case gl::GpuPreference::kHighPerformance:
560+
log += "HighPerformance"_L1;
561+
break;
562+
}
563+
564+
log += ", active: "_L1 + (device.active ? "yes"_L1 : "no"_L1);
565+
return log;
566+
};
567+
568+
QString log;
569+
if (gpu_info.gl_vendor.empty() || gpu_info.gl_vendor == "Disabled") {
570+
log += "ANGLE is disabled:\n"_L1;
571+
log += " GL Renderer: "_L1 + QLatin1StringView(gpu_info.gl_renderer) + u'\n';
572+
log += " Software Renderer: "_L1 + (primary.IsSoftwareRenderer() ? "yes"_L1 : "no"_L1)
573+
+ u'\n';
574+
log += " Primary GPU: "_L1 + deviceToString(primary) + u'\n';
575+
} else {
576+
log += QLatin1StringView(gpu_info.display_type) + " display is initialized:\n"_L1;
577+
log += " GL Renderer: "_L1 + QLatin1StringView(gpu_info.gl_renderer) + u'\n';
578+
log += " "_L1 + QString::number(gpu_info.GpuCount()) + " GPU(s) detected:\n"_L1;
579+
log += " "_L1 + deviceToString(primary) + u'\n';
580+
for (auto &secondary : gpu_info.secondary_gpus)
581+
log += " "_L1 + deviceToString(secondary) + u'\n';
582+
583+
log += " NVIDIA Optimus: "_L1 + (gpu_info.optimus ? "enabled"_L1 : "disabled"_L1) + u'\n';
584+
log += " AMD Switchable: "_L1 + (gpu_info.amd_switchable ? "enabled"_L1 : "disabled"_L1);
585+
}
586+
587+
qCDebug(lcWebEngineCompositor, "%ls", qUtf16Printable(log));
588+
}
589+
488590
} // namespace QtWebEngineCore

src/core/content_client_qt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#include "base/synchronization/lock.h"
1010
#include "components/embedder_support/origin_trials/origin_trial_policy_impl.h"
1111
#include "content/public/common/content_client.h"
12+
#include "gpu/config/gpu_info.h"
1213
#include "ui/base/layout.h"
1314

1415
#include <memory>
16+
#include <optional>
1517

1618
namespace QtWebEngineCore {
1719

@@ -29,11 +31,13 @@ class ContentClientQt : public content::ContentClient {
2931
gfx::Image &GetNativeImageNamed(int resource_id) override;
3032
std::u16string GetLocalizedString(int message_id) override;
3133
blink::OriginTrialPolicy *GetOriginTrialPolicy() override;
34+
void SetGpuInfo(const gpu::GPUInfo &gpu_info) override;
3235

3336
private:
3437
// Used to lock when |origin_trial_policy_| is initialized.
3538
base::Lock origin_trial_policy_lock_;
3639
std::unique_ptr<embedder_support::OriginTrialPolicyImpl> origin_trial_policy_;
40+
std::optional<gpu::GPUInfo> m_gpuInfo;
3741
};
3842

3943
} // namespace QtWebEngineCore

src/core/web_engine_context.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class GPUInfo
266266
}
267267

268268
Vendor vendor() const { return m_vendor; }
269+
QString deviceName() const { return m_deviceName; }
269270
QString getAdapterLuid() const { return m_adapterLuid; }
270271

271272
private:
@@ -288,6 +289,7 @@ class GPUInfo
288289
}
289290
if (d3d11Rhi) {
290291
m_vendor = vendorIdToVendor(d3d11Rhi->driverInfo().vendorId);
292+
m_deviceName = QString::fromUtf8(d3d11Rhi->driverInfo().deviceName);
291293

292294
const QRhiD3D11NativeHandles *handles =
293295
static_cast<const QRhiD3D11NativeHandles *>(d3d11Rhi->nativeHandles());
@@ -301,8 +303,10 @@ class GPUInfo
301303
QRhiMetalInitParams params;
302304
QScopedPointer<QRhi> metalRhi(
303305
QRhi::create(QRhi::Metal, &params, QRhi::Flags(), nullptr));
304-
if (metalRhi)
306+
if (metalRhi) {
305307
m_vendor = deviceNameToVendor(QLatin1StringView(metalRhi->driverInfo().deviceName));
308+
m_deviceName = QString::fromUtf8(metalRhi->driverInfo().deviceName);
309+
}
306310
}
307311
#endif
308312

@@ -312,8 +316,10 @@ class GPUInfo
312316
params.fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
313317
QScopedPointer<QRhi> glRhi(
314318
QRhi::create(QRhi::OpenGLES2, &params, QRhi::Flags(), nullptr));
315-
if (glRhi)
319+
if (glRhi) {
316320
m_vendor = deviceNameToVendor(QLatin1StringView(glRhi->driverInfo().deviceName));
321+
m_deviceName = QString::fromUtf8(glRhi->driverInfo().deviceName);
322+
}
317323
}
318324
#endif
319325

@@ -333,6 +339,7 @@ class GPUInfo
333339
// see https://www.phoronix.com/news/Mesa-20.1-Vulkan-Dev-Selection
334340
// Try to detect this case and at least warn about it.
335341
m_vendor = vendorIdToVendor(vulkanRhi->driverInfo().vendorId);
342+
m_deviceName = QString::fromUtf8(vulkanRhi->driverInfo().deviceName);
336343
}
337344
}
338345
}
@@ -343,6 +350,7 @@ class GPUInfo
343350
}
344351

345352
Vendor m_vendor = Unknown;
353+
QString m_deviceName;
346354
QString m_adapterLuid;
347355
};
348356

@@ -430,7 +438,8 @@ static void logContext(const std::string &glType, base::CommandLine *cmd)
430438
log += "QSG RHI Backend: "_L1 + QSGRhiSupport::instance()->rhiBackendName() + u'\n';
431439
log += "QSG RHI Backend Supported: "_L1 + (usingSupportedSGBackend() ? "yes"_L1 : "no"_L1)
432440
+ u'\n';
433-
log += "GPU Vendor: "_L1
441+
log += "QSG RHI Device: "_L1 + GPUInfo::instance()->deviceName() + u'\n';
442+
log += "QSG RHI GPU Vendor: "_L1
434443
+ QLatin1StringView(GPUInfo::vendorToString(GPUInfo::instance()->vendor())) + u'\n';
435444
log += u'\n';
436445

0 commit comments

Comments
 (0)