diff options
author | Pasi Petäjäjärvi <pasi.petajajarvi@qt.io> | 2023-06-20 17:07:32 +0300 |
---|---|---|
committer | Pasi Petäjäjärvi <pasi.petajajarvi@qt.io> | 2023-08-15 12:14:35 +0000 |
commit | 622256ccade9db1d6acc7db784bfdf3d7f10fd2a (patch) | |
tree | c35168ce0b60f7d2decea698f44f424ca1f11676 | |
parent | d8c1feb99547c3b2b6ba63b2783330ef94a61ce3 (diff) |
Add option to run tests with Vulkan backend
Change-Id: Iec76a086657ad8cda88c4590f68f55b0636bf958
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r-- | src/main.cpp | 25 | ||||
-rw-r--r-- | src/options.h | 2 | ||||
-rw-r--r-- | src/resultrecorder.cpp | 110 |
3 files changed, 97 insertions, 40 deletions
diff --git a/src/main.cpp b/src/main.cpp index f7b7c83..5dda24c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ Options Options::instance; static const char *subprocessOptionString = "subprocess-mode"; +static const char *useVulkanOptionString = "use-vulkan"; QStringList processCommandLineArguments(const QCoreApplication &app) { @@ -162,6 +163,10 @@ QStringList processCommandLineArguments(const QCoreApplication &app) QStringLiteral("1.0")); parser.addOption(hardwareMultiplierOption); + QCommandLineOption useVulkanOption(QStringLiteral("use-vulkan"), + QStringLiteral("Change graphics backend to use Vulkan instead of OpenGL")); + parser.addOption(useVulkanOption); + parser.addPositionalArgument(QStringLiteral("input"), QStringLiteral("One or more QML files or a directory of QML files to benchmark")); const QCommandLineOption &helpOption = parser.addHelpOption(); @@ -199,8 +204,10 @@ QStringList processCommandLineArguments(const QCoreApplication &app) Options::instance.frameCountInterval = parser.value(frameCountInterval).toInt(); Options::instance.destroyViewEachRun = parser.isSet(destroyViewOption); Options::instance.timeout = parser.value(timeoutOption).toInt(); + Options::instance.useVulkan = parser.isSet(useVulkanOption); - if (QGuiApplication::platformName() == QLatin1String("eglfs")) + if (QGuiApplication::platformName() == QLatin1String("eglfs") + || QGuiApplication::platformName() == QLatin1String("vkkhrdisplay")) Options::instance.fullscreen = true; if (Options::instance.fullscreen && qGuiApp->primaryScreen() != nullptr) { @@ -439,9 +446,8 @@ int main(int argc, char **argv) qmlRegisterType<TestModel>("QmlBench", 1, 0, "TestModel"); qmlRegisterSingletonType<QmlBench>("QmlBench", 1, 0, "QmlBench", qmlbench_singleton_provider); - QScopedPointer<QCoreApplication> app; - bool needsGui = false; + bool useVulkan = false; for (int i = 0; i < argc; ++i) { // strstr because the actual option looks like "--foo" not "foo". // not perfect, but good enough. @@ -449,8 +455,21 @@ int main(int argc, char **argv) needsGui = true; break; } + if (strstr(argv[i], useVulkanOptionString) != NULL) { + useVulkan = true; + } + } + + if (useVulkan) { + qputenv("QSG_RHI_BACKEND", QByteArray("vulkan")); +#if !defined(VK_USE_PLATFORM_ANDROID_KHR) && !defined(VK_USE_PLATFORM_MACOS_MVK) && !defined(VK_USE_PLATFORM_WIN32_KHR) && !defined(VK_USE_PLATFORM_XCB_KHR) + qputenv("QT_QPA_PLATFORM", QByteArray("vkkhrdisplay")); +#endif } + QScopedPointer<QCoreApplication> app; + + if (needsGui) { app.reset(new QGuiApplication(argc, argv)); } else { diff --git a/src/options.h b/src/options.h index 9798cba..cb396ac 100644 --- a/src/options.h +++ b/src/options.h @@ -54,6 +54,7 @@ struct Options , hardwareMultiplier(1.0) , destroyViewEachRun(false) , timeout(10*60*1000) + , useVulkan(false) { } @@ -78,6 +79,7 @@ struct Options QList<Benchmark> benchmarks; bool destroyViewEachRun; int timeout; + bool useVulkan; static Options instance; }; diff --git a/src/resultrecorder.cpp b/src/resultrecorder.cpp index 430a697..1d8a883 100644 --- a/src/resultrecorder.cpp +++ b/src/resultrecorder.cpp @@ -39,6 +39,10 @@ #include <iostream> #include <cmath> +#if QT_CONFIG(vulkan) +#include <QVulkanInstance> +#endif + #include "resultrecorder.h" #include "options.h" @@ -80,50 +84,82 @@ void ResultRecorder::startResults(const QString &id) m_results["qt"] = QT_VERSION_STR; m_results["command-line"] = qApp->arguments().join(' '); - // The following code makes the assumption that an OpenGL context the GUI - // thread will get the same capabilities as the render thread's OpenGL - // context. Not 100% accurate, but it works... - QOpenGLContext context; - context.create(); - QOffscreenSurface surface; - // In very odd cases, we can get incompatible configs here unless we pass the - // GL context's format on to the offscreen format. - surface.setFormat(context.format()); - surface.create(); - if (!context.makeCurrent(&surface)) { - qWarning() << "failed to acquire GL context to get version info."; - return; - } - - QOpenGLFunctions *func = context.functions(); + if (Options::instance.useVulkan) { +#if QT_CONFIG(vulkan) + QVulkanInstance inst; + QVariantMap vulkanInfo; + vulkanInfo["API version"] = inst.supportedApiVersion().toString(); + + QVariantMap vulkanExtensions = vulkanInfo["extensions"].toMap(); + QVariantList vulkanExtensionInfo; + + for (auto &ext : inst.supportedExtensions()) { + vulkanExtensionInfo = vulkanExtensions[ext.name].toList(); + vulkanExtensionInfo.append(ext.version); + vulkanExtensions[ext.name] = vulkanExtensionInfo; + } + vulkanInfo["extensions"] = vulkanExtensions; + + QVariantMap vulkanLayers = vulkanInfo["layers"].toMap(); + QVariantList vulkanLayerInfo; + + for (auto &layer : inst.supportedLayers()) { + vulkanLayerInfo = vulkanLayers[layer.name].toList(); + vulkanLayerInfo.append(layer.specVersion.toString()); + vulkanLayerInfo.append(layer.version); + vulkanLayerInfo.append(layer.description); + vulkanLayers[layer.name] = vulkanLayerInfo; + } + vulkanInfo["layers"] = vulkanLayers; + + m_results["vulkan"] = vulkanInfo; +#endif + } else { + // The following code makes the assumption that an OpenGL context the GUI + // thread will get the same capabilities as the render thread's OpenGL + // context. Not 100% accurate, but it works... + QOpenGLContext context; + context.create(); + QOffscreenSurface surface; + // In very odd cases, we can get incompatible configs here unless we pass the + // GL context's format on to the offscreen format. + surface.setFormat(context.format()); + surface.create(); + if (!context.makeCurrent(&surface)) { + qWarning() << "failed to acquire GL context to get version info."; + return; + } + + QOpenGLFunctions *func = context.functions(); #if QT_VERSION >= 0x050300 - const char *vendor = (const char *) func->glGetString(GL_VENDOR); - const char *renderer = (const char *) func->glGetString(GL_RENDERER); - const char *version = (const char *) func->glGetString(GL_VERSION); + const char *vendor = (const char *) func->glGetString(GL_VENDOR); + const char *renderer = (const char *) func->glGetString(GL_RENDERER); + const char *version = (const char *) func->glGetString(GL_VERSION); #else - Q_UNUSED(func); - const char *vendor = (const char *) glGetString(GL_VENDOR); - const char *renderer = (const char *) glGetString(GL_RENDERER); - const char *version = (const char *) glGetString(GL_VERSION); + Q_UNUSED(func); + const char *vendor = (const char *) glGetString(GL_VENDOR); + const char *renderer = (const char *) glGetString(GL_RENDERER); + const char *version = (const char *) glGetString(GL_VERSION); #endif - if (!Options::instance.printJsonToStdout) { - std::cout << "ID: " << id.toStdString() << std::endl; - std::cout << "OS: " << prettyProductName.toStdString() << std::endl; - std::cout << "QPA: " << QGuiApplication::platformName().toStdString() << std::endl; - std::cout << "GL_VENDOR: " << vendor << std::endl; - std::cout << "GL_RENDERER: " << renderer << std::endl; - std::cout << "GL_VERSION: " << version << std::endl; - } + if (!Options::instance.printJsonToStdout) { + std::cout << "ID: " << id.toStdString() << std::endl; + std::cout << "OS: " << prettyProductName.toStdString() << std::endl; + std::cout << "QPA: " << QGuiApplication::platformName().toStdString() << std::endl; + std::cout << "GL_VENDOR: " << vendor << std::endl; + std::cout << "GL_RENDERER: " << renderer << std::endl; + std::cout << "GL_VERSION: " << version << std::endl; + } - QVariantMap glInfo; - glInfo["vendor"] = vendor; - glInfo["renderer"] = renderer; - glInfo["version"] = version; + QVariantMap glInfo; + glInfo["vendor"] = vendor; + glInfo["renderer"] = renderer; + glInfo["version"] = version; - m_results["opengl"] = glInfo; + m_results["opengl"] = glInfo; - context.doneCurrent(); + context.doneCurrent(); + } } void ResultRecorder::recordWindowSize(const QSize &windowSize) |