vr: add OpenXR headset output, VR tracker and VR controller input behind --vr (#1726)

This commit is contained in:
Leandro Bras
2026-10-20 02:17:17 +02:00
committed by nmzik
parent 0cad4672e9
commit 742fe17173
17 changed files with 1637 additions and 28 deletions
@@ -1,6 +1,3 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_vulkan.h>
#include "common/assert.h"
#include "common/common.h"
#include "common/emulatorConfig.h"
@@ -14,6 +11,7 @@
#include "graphics/host_gpu/renderer/render.h"
#include "graphics/host_gpu/renderer/renderContext.h"
#include "graphics/host_gpu/vulkanCommon.h"
#include "graphics/presentation/openxrHeadset.h"
#include "graphics/presentation/presenter.h"
#include "graphics/presentation/systemOverlay.h"
#include "graphics/presentation/videoOut.h"
@@ -23,6 +21,8 @@
#include "libs/controller.h"
#include "loader/systemContent.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_vulkan.h>
#include <algorithm>
#include <cstdio>
#include <cstring>
@@ -170,6 +170,8 @@ static void VulkanFindPhysicalDevice(vk::Instance instance, vk::SurfaceKHR surfa
LOGF("Vulkan GPU index %d is unavailable; selecting automatically\n",
Config::GetGpuIndex());
}
} else if (vk::PhysicalDevice headset; Vr::OpenXrPhysicalDevice(instance, headset)) {
devices = {headset}; // The headset runtime renders on this GPU.
}
vk::PhysicalDevice best_device = nullptr;
@@ -876,8 +878,11 @@ void WindowContext::CreateVulkan() {
}
VULKAN_HPP_DEFAULT_DISPATCHER.init(get_instance_proc_addr);
Vr::OpenXrInit();
VulkanExtensions r;
VulkanGetExtensions(r);
Vr::OpenXrAppendExtensions(r.required_extensions, r.available_extensions, false);
VulkanCheckInstanceVersion();
vk::ApplicationInfo app_info {};
@@ -1051,6 +1056,7 @@ void WindowContext::CreateVulkan() {
device_extensions.push_back(VK_EXT_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_EXTENSION_NAME);
device_extensions.push_back(VK_EXT_ATTACHMENT_FEEDBACK_LOOP_DYNAMIC_STATE_EXTENSION_NAME);
}
Vr::OpenXrAppendExtensions(device_extensions, available_extensions, true);
}
graphic_ctx.device = VulkanCreateDevice(graphic_ctx, device_extensions);
@@ -1068,6 +1074,7 @@ void WindowContext::CreateVulkan() {
render_context = std::make_unique<RenderContext>(graphic_ctx);
LibKernel::Memory::InstallGpuResources(render_context.get());
presenter = std::make_unique<Presenter>(*this);
Vr::OpenXrStartSession(graphic_ctx);
}
void WindowContext::RefreshSurfaceCapabilities() {
@@ -1090,6 +1097,7 @@ void WindowContext::RecreateSurface() {
}
WindowContext::~WindowContext() {
Vr::OpenXrShutdown();
ShutdownSystemOverlayInput();
presenter.reset();
LibKernel::Memory::InstallGpuResources(nullptr);