From 3a02198156acb617648a846cad78d1218163680e Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sat, 16 Mar 2024 18:14:25 +0100 Subject: [PATCH] Automatically enable passthrough if color passthrough is supported --- client/application.cpp | 17 +++++++++++++---- client/application.h | 13 +++++++------ client/scenes/lobby.cpp | 7 ++++--- client/scenes/lobby.h | 2 +- client/scenes/lobby_gui.cpp | 2 +- client/xr/instance.cpp | 15 +++++++++++---- client/xr/instance.h | 14 ++++++++++---- client/xr/system.cpp | 23 +++++++++++++++++++---- client/xr/system.h | 9 ++++++++- 9 files changed, 74 insertions(+), 28 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index 2cd4d0d7..9cf8f834 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -18,8 +18,6 @@ */ #include "application.h" -#include "hardware.h" -#include "magic_enum.hpp" #include "openxr/openxr.h" #include "scene.h" #include "spdlog/common.h" @@ -395,7 +393,7 @@ void application::initialize_vulkan() spdlog::info("Available Vulkan instance extensions:"); for(vk::ExtensionProperties& i: vk_context.enumerateInstanceExtensionProperties(nullptr)) { - spdlog::info(" {}", i.extensionName); + spdlog::info(" {} (version {})", i.extensionName, i.specVersion); #ifndef NDEBUG if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) @@ -804,7 +802,18 @@ void application::initialize() } } - spdlog::info("Passthrough: {}", xr_system_id.passthrough_supported() ? "supported" : "not supported"); + switch(xr_system_id.passthrough_supported()) + { + case xr::system::passthrough_type::no_passthrough: + spdlog::info("Passthrough: not supported"); + break; + case xr::system::passthrough_type::bw: + spdlog::info("Passthrough: black and white"); + break; + case xr::system::passthrough_type::color: + spdlog::info("Passthrough: color"); + break; + } vk::CommandPoolCreateInfo cmdpool_create_info; diff --git a/client/application.h b/client/application.h index ce0690d6..3cf6a5cd 100644 --- a/client/application.h +++ b/client/application.h @@ -24,23 +24,24 @@ #include #endif +#include "utils/singleton.h" +#include "vk/vk_allocator.h" #include "xr/xr.h" #include #include #include #include +#include +#include #include -#include +#include +#include #include +#include #include #include #include #include -#include "vk/vk_allocator.h" -#include "utils/singleton.h" -#include -#include -#include class scene; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 17b0ffcc..7c164e77 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -187,6 +187,9 @@ scenes::lobby::lobby() if (std::getenv("WIVRN_AUTOCONNECT")) force_autoconnect = true; + passthrough_supported = system.passthrough_supported(); + passthrough_enabled = passthrough_supported == xr::system::passthrough_type::color; + try { simdjson::dom::parser parser; @@ -265,9 +268,7 @@ scenes::lobby::lobby() spdlog::info("Using format {}", vk::to_string(swapchain_format)); - passthrough_supported = system.passthrough_supported(); - - if (passthrough_supported) + if (passthrough_supported != xr::system::passthrough_type::no_passthrough) { if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME)) { diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index fcd12ba2..9300a467 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -89,7 +89,7 @@ class lobby : public scene_impl std::vector swapchains_controllers; xr::swapchain swapchain_imgui; vk::Format swapchain_format; - bool passthrough_supported; + xr::system::passthrough_type passthrough_supported; xr::passthrough passthrough; void save_config(); diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 4bad1e7d..675670b3 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -383,7 +383,7 @@ void scenes::lobby::gui_settings() } vibrate_on_hover(); - ImGui::BeginDisabled(!passthrough_supported); + ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); if (ImGui::Checkbox("Enable video passthrough in lobby", &passthrough_enabled)) { save_config(); diff --git a/client/xr/instance.cpp b/client/xr/instance.cpp index f847fc5b..c1bfe4ef 100644 --- a/client/xr/instance.cpp +++ b/client/xr/instance.cpp @@ -74,10 +74,10 @@ xr::instance::instance(std::string_view application_name, std::vector(xrEnumerateInstanceExtensionProperties, nullptr)) + auto all_extensions = xr::instance::extensions(); + for (XrExtensionProperties & i: all_extensions) { - spdlog::info(" {}", i.extensionName); + spdlog::info(" {} (version {})", i.extensionName, i.extensionVersion); #ifndef NDEBUG if (!strcmp(i.extensionName, "XR_EXT_debug_utils")) { @@ -90,7 +90,14 @@ xr::instance::instance(std::string_view application_name, std::vector #endif -#include "error.h" #include "utils/handle.h" #include "xr/check.h" -#include #include #include -#include +#include #include #include #include @@ -51,7 +49,7 @@ class instance : public utils::handle { std::string runtime_version; std::string runtime_name; - std::unordered_set loaded_extensions; + std::unordered_map loaded_extensions; public: #if defined(XR_USE_PLATFORM_ANDROID) @@ -98,5 +96,13 @@ public: { return loaded_extensions.find(extension_name) != loaded_extensions.end(); } + + uint32_t extension_version(const std::string & extension_name) + { + auto it = loaded_extensions.find(extension_name); + if (it != loaded_extensions.end()) + return it->second; + return 0; + } }; } // namespace xr diff --git a/client/xr/system.cpp b/client/xr/system.cpp index cd7b671f..35c285b6 100644 --- a/client/xr/system.cpp +++ b/client/xr/system.cpp @@ -21,6 +21,7 @@ #include "application.h" #include "details/enumerate.h" +#include "openxr/openxr.h" #include "utils/contains.h" #include "vk/check.h" #include "xr/check.h" @@ -84,17 +85,22 @@ XrSystemHandTrackingPropertiesEXT xr::system::hand_tracking_properties() const return hand_tracking_prop; } -bool xr::system::passthrough_supported() const +xr::system::passthrough_type xr::system::passthrough_supported() const { const std::vector& xr_extensions = application::get_xr_extensions(); if (utils::contains(xr_extensions, XR_HTC_PASSTHROUGH_EXTENSION_NAME)) - return true; + return passthrough_type::color; if (utils::contains(xr_extensions, XR_FB_PASSTHROUGH_EXTENSION_NAME)) { + XrSystemPassthroughProperties2FB passthrough_prop2{ + .type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES2_FB, + }; + XrSystemPassthroughPropertiesFB passthrough_prop { .type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES_FB, + .next = &passthrough_prop2, }; XrSystemProperties prop{ @@ -103,10 +109,19 @@ bool xr::system::passthrough_supported() const }; CHECK_XR(xrGetSystemProperties(*inst, id, &prop)); - return passthrough_prop.supportsPassthrough; + if (passthrough_prop.supportsPassthrough) + { + if (!(passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_BIT_FB)) + return passthrough_type::no_passthrough; + + if (passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_COLOR_BIT_FB) + return passthrough_type::color; + + return passthrough_type::bw; + } } - return false; + return passthrough_type::no_passthrough; } vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance& vulkan) const diff --git a/client/xr/system.h b/client/xr/system.h index 28593af6..8f4abbdf 100644 --- a/client/xr/system.h +++ b/client/xr/system.h @@ -39,6 +39,13 @@ class system XrSystemId id = XR_NULL_SYSTEM_ID; public: + enum class passthrough_type + { + no_passthrough, + bw, + color + }; + system() = default; system(const system &) = default; system & operator=(const system &) = default; @@ -55,7 +62,7 @@ public: XrSystemProperties properties() const; XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const; - bool passthrough_supported() const; + passthrough_type passthrough_supported() const; XrGraphicsRequirementsVulkan2KHR graphics_requirements() const; vk::raii::PhysicalDevice physical_device(vk::raii::Instance& vulkan) const;