Render through public Qt API: OpenGL and Vulkan backends, --graphics-api

Replace the QRhi rendering in OverlayController (private Qt API) with the
render backends of the vrdashboard template (src/render/), which use public
Qt API only (QQuickRenderTarget::fromOpenGLTexture / fromVulkanImage). The
binary then runs on another Qt 6 patch release, e.g. the Steam Frame's system
Qt.

The Vulkan backend also does what SteamVR requires and the QRhi path lacked:
the required instance/device extensions and the HMD's GPU (via
openvr_init::renderInterop()), VK_FORMAT_R8G8B8A8_UNORM, and the transition to
TRANSFER_SRC_OPTIMAL after each frame.

- New option --graphics-api opengl|vulkan (default opengl, no fallback).
- Shutdown() calls VR_Shutdown before the render target and Qt's device go
  (crash on the Steam Frame with Vulkan otherwise); it runs only once.
- Mouse y is flipped on every platform: SteamVR reports it in GL convention.
- Render delay 5 -> 16 ms (about 60 fps).
- GuiPrivate is no longer needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Matthias Janetschek
2026-10-07 13:41:13 +02:00
co-authored by Claude Opus 5.5
parent 423ea57db7
commit 4826686a4d
15 changed files with 1243 additions and 140 deletions
+34 -1
View File
@@ -1,6 +1,7 @@
#include "utils/setup.h"
#include "settings/settings.h"
#include "openvr/ovr_settings_wrapper.h"
#include "render/RenderBackend.h"
#include <QtLogging>
#include <QtDebug>
@@ -46,6 +47,37 @@ int main( int argc, char* argv[] )
openvr_init::initializeOpenVR(
openvr_init::OpenVrInitializationType::Overlay );
// Render backend (render/RenderBackend.h). Created after OpenVR, because
// the Vulkan backend needs SteamVR's device requirements
// (openvr_init::renderInterop()), and before OverlayController, because
// QQuickWindow::setGraphicsApi() must run before any QQuickWindow exists
// (OverlayController owns one).
GraphicsApi graphicsApi = GraphicsApi::OpenGL;
if ( !parseGraphicsApi( commandLineArgs.graphicsApi, &graphicsApi ) )
{
qCritical() << "Unknown graphics API:" << commandLineArgs.graphicsApi
<< "(expected opengl or vulkan)";
return ReturnErrorCode::GENERAL_FAILURE;
}
std::unique_ptr<RenderBackend> renderBackend
= createRenderBackend( graphicsApi );
if ( !renderBackend )
{
qCritical() << "Graphics API" << commandLineArgs.graphicsApi
<< "is not compiled into this build";
return ReturnErrorCode::GENERAL_FAILURE;
}
QString renderBackendError;
if ( !renderBackend->initialize( openvr_init::renderInterop(),
&renderBackendError ) )
{
qCritical() << renderBackend->name()
<< "initialization failed:" << renderBackendError;
return ReturnErrorCode::GENERAL_FAILURE;
}
QQuickWindow::setGraphicsApi( renderBackend->graphicsApi() );
try
{
QQmlEngine qmlEngine;
@@ -61,7 +93,8 @@ int main( int argc, char* argv[] )
std::unique_ptr<advsettings::OverlayController> controller(
new advsettings::OverlayController( commandLineArgs.desktopMode,
commandLineArgs.forceNoSound,
qmlEngine ) );
qmlEngine,
std::move( renderBackend ) ) );
//const auto url
// = QUrl( ":/qt/qml/AdvancedSettings/src/res/qml/common/mainwidget.qml" );
QQmlComponent component( &qmlEngine, ":/qt/qml/AdvancedSettings/src/res/qml/common/mainwidget.qml" );