diff --git a/client/application.cpp b/client/application.cpp index 384dee76..c4a2227c 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -28,16 +28,20 @@ #include "utils/files.h" #include "vk/check.h" #include "wifi_lock.h" +#include "wivrn_packets.h" #include "xr/actionset.h" #include "xr/check.h" +#include "xr/htc_exts.h" +#include "xr/htc_face_tracker.h" #include "xr/meta_body_tracking_fidelity.h" -#include "xr/xr.h" +#include "xr/to_string.h" #include #include #include #include #include #include +#include #include #include #include @@ -134,7 +138,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/facebook/touch_controller_pro", - .required_extensions = {"XR_FB_touch_controller_pro"}, + .required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -247,7 +251,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/meta/touch_controller_plus", - .required_extensions = {"XR_META_touch_controller_plus"}, + .required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME}, .max_version = XR_MAKE_VERSION(1, 1, 0), .input_sources = { "/user/hand/left/output/haptic", @@ -348,7 +352,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico_neo3_controller", - .required_extensions = {"XR_BD_controller_interaction"}, + .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -391,7 +395,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4_controller", - .required_extensions = {"XR_BD_controller_interaction"}, + .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -434,7 +438,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/bytedance/pico4s_controller", - .required_extensions = {"XR_BD_controller_interaction"}, + .required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -477,7 +481,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_focus3_controller", - .required_extensions = {"XR_HTC_vive_focus3_controller_interaction"}, + .required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/output/haptic", "/user/hand/right/output/haptic", @@ -519,7 +523,7 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/ext/hand_interaction_ext", - .required_extensions = {"XR_EXT_hand_interaction"}, + .required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/hand/left/input/aim/pose", "/user/hand/left/input/grip/pose", @@ -548,11 +552,14 @@ static std::vector interaction_profiles{ }, interaction_profile{ .profile_name = "/interaction_profiles/htc/vive_xr_tracker", - .required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"}, + .required_extensions = { + XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME, + XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, + }, }, interaction_profile{ .profile_name = "/interaction_profiles/ext/eye_gaze_interaction", - .required_extensions = {"XR_EXT_eye_gaze_interaction"}, + .required_extensions = {XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME}, .input_sources = { "/user/eyes_ext/input/gaze_ext/pose", }, @@ -717,15 +724,13 @@ void application::initialize_vulkan() spdlog::info("Using Vulkan validation layer"); layers.push_back("VK_LAYER_KHRONOS_validation"); } + bool debug_report_found = false; + bool debug_utils_found = false; #endif std::vector instance_extensions{}; std::unordered_set optional_device_extensions{}; -#ifndef NDEBUG - bool debug_report_found = false; - bool debug_utils_found = false; -#endif spdlog::info("Available Vulkan instance extensions:"); std::vector> extensions; for (vk::ExtensionProperties & i: vk_context.enumerateInstanceExtensionProperties(nullptr)) @@ -734,26 +739,23 @@ void application::initialize_vulkan() #ifndef NDEBUG if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME)) + { debug_report_found = true; + instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); + } - if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and + guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load + { debug_utils_found = true; + instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + } #endif } std::ranges::sort(extensions); for (const auto & [extension_name, spec_version]: extensions) spdlog::info(" {} (version {})", extension_name, spec_version); -#ifndef NDEBUG - if (debug_utils_found && debug_report_found) - { - // debug_extensions_found = true; - // spdlog::info("Using debug extensions"); - instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); - // instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - } -#endif - vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME); @@ -958,8 +960,6 @@ void application::initialize_actions() { spdlog::debug("Initializing actions"); - auto * htc_body = std::get_if(&body_tracker); - // Build an action set with all possible input sources std::vector action_sets; xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions"); @@ -973,7 +973,9 @@ void application::initialize_actions() std::vector sources; for (auto & profile: interaction_profiles) { - profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version; + profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and + profile.min_version <= api_version and + profile.max_version > api_version; if (profile.profile_name.ends_with("khr/simple_controller")) { @@ -1014,15 +1016,15 @@ void application::initialize_actions() } if (add_palms) { - if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) // - and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // + if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or xr_instance.has_extension(XR_KHR_MAINTENANCE1_EXTENSION_NAME)) // + and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose")) { spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name); profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose"); profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose"); } - else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) // + else if (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) // and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") // and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose")) { @@ -1033,14 +1035,15 @@ void application::initialize_actions() } // Dynamically add VIVE XR Trackers to the profile if available - if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME)) + if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and + xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME)) { - for (const auto & user_path: htc_body->get_paths()) + XrPath tracker_profile = xr_instance.string_to_path("/interaction_profiles/htc/vive_xr_tracker"); + for (const auto & user_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile)) { - for (const auto & input_path: htc_body->get_paths(user_path)) - { - profile.input_sources.push_back(path_to_string(user_path) + path_to_string(input_path)); - } + generic_trackers.emplace_back(user_path, nullptr); + for (const auto & input_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile, user_path)) + profile.input_sources.push_back(xr_instance.path_to_string(user_path) + xr_instance.path_to_string(input_path)); } } @@ -1088,8 +1091,14 @@ void application::initialize_actions() spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a); else if (name == "/user/eyes_ext/input/gaze_ext/pose") spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a); - else if (name.contains("/input/entity_htc/pose") && htc_body) - htc_body->add(xr_session.create_action_space(a)); + else if (name.contains("/input/entity_htc/pose")) + { + for (auto & [path, action]: generic_trackers) + { + if (name.starts_with(xr_instance.path_to_string(path))) + action = xr_session.create_action_space(a); + } + } } // Build an action set for each scene @@ -1126,7 +1135,7 @@ void application::initialize_actions() xr_bindings.push_back(XrActionSuggestedBinding{ .action = a, - .binding = string_to_path(k.input_source)}); + .binding = xr_instance.string_to_path(k.input_source)}); } } } @@ -1143,7 +1152,7 @@ void application::initialize_actions() for (const auto & name: profile.input_sources) { - xr_bindings.push_back({actions_by_name[name], string_to_path(name)}); + xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)}); } try @@ -1163,7 +1172,7 @@ void application::initialize() { // LogLayersAndExtensions assert(!xr_instance); - xr_extensions.clear(); + std::vector xr_extensions; // Required extensions xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME); @@ -1236,21 +1245,16 @@ void application::initialize() spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking); spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking); - if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME)) - { - XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties(); - spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking); - hand_tracking_supported = hand_tracking_properties.supportsHandTracking; - } + spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported()); - if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) + if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME)) { XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties(); spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction); eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction; } - if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) + if (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME)) { spdlog::info(" OpenXR post-processing extension support: true"); openxr_post_processing_supported = true; @@ -1258,93 +1262,45 @@ void application::initialize() switch (xr_system_id.passthrough_supported()) { - case xr::system::passthrough_type::no_passthrough: + case xr::passthrough_type::none: spdlog::info(" Passthrough: not supported"); break; - case xr::system::passthrough_type::bw: + case xr::passthrough_type::bw: spdlog::info(" Passthrough: black and white"); break; - case xr::system::passthrough_type::color: + case xr::passthrough_type::color: spdlog::info(" Passthrough: color"); break; } + spdlog::info(" Face tracker: {}", magic_enum::enum_name(xr_system_id.face_tracker_supported())); + spdlog::info(" Body tracker: {}", magic_enum::enum_name(xr_system_id.body_tracker_supported())); + // Log view configurations and blend modes log_views(); initialize_vulkan(); - xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue_family_index); - - { - auto spaces = xr_session.get_reference_spaces(); - spdlog::info("{} reference spaces", spaces.size()); - for (XrReferenceSpaceType i: spaces) - spdlog::info(" {}", xr::to_string(i)); - } + xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index); spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW); spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE); config.emplace(xr_system_id); - if (hand_tracking_supported) + // HTC face tracker fails if created later + // we can destroy it right away, it actually stores static handles + if (xr_system_id.face_tracker_supported() == xr::face_tracker_type::htc) { - left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT); - right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT); + auto props = xr_system_id.htc_face_tracking_properties(); + xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking); } - if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME)) { - XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties(); - spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking); - if (fb_face2_properties.supportsVisualFaceTracking) - face_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(face_tracker) && utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME)) - { - XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties(); - spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking); - spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking); - if (htc_face_properties.supportEyeFacialTracking || htc_face_properties.supportLipFacialTracking) - face_tracker.emplace(xr_instance, xr_session, htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking); - } - - if (std::holds_alternative(face_tracker) && eye_gaze_supported) - { - switch (guess_model()) - { - case model::pico_4_pro: - case model::pico_4_enterprise: - spdlog::info(" PICO face tracking support: true"); - face_tracker.emplace(xr_instance, xr_session); - break; - default: - break; - } - } - - if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME})) - { - XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties(); - spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking); - if (fb_body_properties.supportsBodyTracking) - body_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(body_tracker) && utils::contains_all(xr_extensions, std::array{XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME})) - { - spdlog::info(" HTC body tracking support: true"); - body_tracker.emplace(xr_instance, xr_session); - } - - if (std::holds_alternative(body_tracker) && utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME)) - { - XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties(); - spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking); - if (bd_body_properties.supportsBodyTracking) - body_tracker.emplace(xr_instance, xr_session); + auto spaces = xr_session.get_reference_spaces(); + spdlog::info("{} reference spaces", spaces.size()); + for (XrReferenceSpaceType i: spaces) + spdlog::info(" {}", xr::to_string(i)); } vk::CommandPoolCreateInfo cmdpool_create_info; @@ -1881,13 +1837,6 @@ void application::poll_events() exit_requested = true; } break; - case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: { - if (auto * htc_body = std::get_if(&body_tracker)) - { - htc_body->update_active(); - } - } - break; case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING: break; case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: { diff --git a/client/application.h b/client/application.h index cb17f87e..368983fa 100644 --- a/client/application.h +++ b/client/application.h @@ -28,14 +28,11 @@ #include "utils/thread_safe.h" #include "vk/vk_allocator.h" #include "wifi_lock.h" -#include "xr/fb_body_tracker.h" -#include "xr/fb_face_tracker2.h" -#include "xr/hand_tracker.h" -#include "xr/htc_body_tracker.h" -#include "xr/htc_face_tracker.h" -#include "xr/pico_body_tracker.h" -#include "xr/pico_face_tracker.h" -#include "xr/xr.h" +#include "xr/actionset.h" +#include "xr/instance.h" +#include "xr/session.h" +#include "xr/swapchain.h" +#include "xr/system.h" #include #include #include @@ -126,12 +123,7 @@ class application : public singleton xr::actionset xr_actionset; std::vector> actions; - bool hand_tracking_supported = false; - xr::hand_tracker left_hand; - xr::hand_tracker right_hand; - - std::variant face_tracker; - std::variant body_tracker; + std::vector> generic_trackers; bool eye_gaze_supported = false; @@ -141,7 +133,6 @@ class application : public singleton bool session_focused = false; bool session_visible = false; bool debug_extensions_found = false; - std::vector xr_extensions; std::vector vk_device_extensions; std::atomic exit_requested = false; std::filesystem::path config_path; @@ -271,16 +262,6 @@ public: return std::make_pair(position, orientation); } - static XrPath string_to_path(const std::string & s) - { - return instance().xr_instance.string_to_path(s); - } - - static std::string path_to_string(XrPath p) - { - return instance().xr_instance.path_to_string(p); - } - void run(); static void push_scene(std::shared_ptr); @@ -351,16 +332,6 @@ public: // #endif } - static XrTime now() - { - return instance().xr_instance.now(); - } - - static uint32_t queue_family_index() - { - return instance().vk_queue_family_index; - } - static thread_safe & get_queue() { return instance().vk_queue; @@ -376,26 +347,21 @@ public: return intent; } - static vk::raii::PhysicalDevice & get_physical_device() - { - return instance().vk_physical_device; - } - static const vk::PhysicalDeviceProperties & get_physical_device_properties() { return instance().physical_device_properties; } - static vk::raii::Device & get_device() - { - return instance().vk_device; - } - static vk::raii::Instance & get_vulkan_instance() { return instance().vk_instance; } + static xr::system & get_system() + { + return instance().xr_system_id; + } + static vk::raii::PipelineCache & get_pipeline_cache() { return instance().pipeline_cache; @@ -416,21 +382,6 @@ public: return instance().last_scene_cpu_time; } - static bool get_hand_tracking_supported() - { - return instance().hand_tracking_supported; - } - - static bool get_face_tracking_supported() - { - return !std::holds_alternative(instance().face_tracker); - } - - static bool get_body_tracking_supported() - { - return !std::holds_alternative(instance().body_tracker); - } - static bool get_eye_gaze_supported() { return instance().eye_gaze_supported; @@ -441,29 +392,9 @@ public: return instance().openxr_post_processing_supported; } - static xr::hand_tracker & get_left_hand() + static auto & get_generic_trackers() { - return instance().left_hand; - } - - static xr::hand_tracker & get_right_hand() - { - return instance().right_hand; - } - - static auto & get_face_tracker() - { - return instance().face_tracker; - } - - static auto & get_body_tracker() - { - return instance().body_tracker; - } - - static const std::vector & get_xr_extensions() - { - return instance().xr_extensions; + return instance().generic_trackers; } static const std::vector & get_vk_device_extensions() diff --git a/client/configuration.cpp b/client/configuration.cpp index ea0ec8d8..a8b2bf09 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -82,6 +82,8 @@ bool configuration::check_feature(feature f) const { std::lock_guard lock(mutex); + auto & system = application::get_system(); + auto it = features.find(f); if (it == features.end()) return false; @@ -94,7 +96,7 @@ bool configuration::check_feature(feature f) const case feature::microphone: break; case feature::hand_tracking: - if (not application::get_hand_tracking_supported()) + if (not system.hand_tracking_supported()) return false; break; case feature::eye_gaze: @@ -102,50 +104,12 @@ bool configuration::check_feature(feature f) const return false; break; case feature::face_tracking: - switch (guess_model()) - { - case model::htc_vive_focus_3: - case model::htc_vive_focus_vision: - case model::htc_vive_xr_elite: - if (not std::holds_alternative(application::get_face_tracker())) - return false; - break; - case model::pico_4_pro: - case model::pico_4_enterprise: - if (not std::holds_alternative(application::get_face_tracker())) - return false; - break; - default: - if (not std::holds_alternative(application::get_face_tracker())) - return false; - break; - } + if (system.face_tracker_supported() == xr::face_tracker_type::none) + return false; break; case feature::body_tracking: - switch (guess_model()) - { - case model::meta_quest_3: - case model::meta_quest_3s: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - case model::htc_vive_focus_3: - case model::htc_vive_xr_elite: - case model::htc_vive_focus_vision: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - case model::pico_neo_3: - case model::pico_4: - case model::pico_4s: - case model::pico_4_pro: - case model::pico_4_enterprise: - if (not std::holds_alternative(application::get_body_tracker())) - return false; - break; - default: - break; - } + if (system.body_tracker_supported() == xr::body_tracker_type::none) + return false; break; } } @@ -181,8 +145,8 @@ void configuration::set_feature(feature f, bool state) configuration::configuration(xr::system & system) { - passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; - features[feature::hand_tracking] = application::get_hand_tracking_supported(); + passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; + features[feature::hand_tracking] = system.hand_tracking_supported(); try { simdjson::dom::parser parser; @@ -243,7 +207,7 @@ configuration::configuration(xr::system & system) features[i] = val.get_bool(); } - if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough) + if (system.passthrough_supported() == xr::passthrough_type::none) passthrough_enabled = false; if (auto val = root["override_foveation_enable"]; val.is_bool()) @@ -269,7 +233,7 @@ configuration::configuration(xr::system & system) resolution_scale = 1.4; sgsr = {}; openxr_post_processing = {}; - passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color; + passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color; } } diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index 6b6106ce..900c05ee 100644 --- a/client/decoder/shard_accumulator.cpp +++ b/client/decoder/shard_accumulator.cpp @@ -18,9 +18,9 @@ */ #include "shard_accumulator.h" -#include "application.h" -#include "scenes/stream.h" +#include "scenes/stream.h" // IWYU pragma: keep #include "spdlog/spdlog.h" +#include "xr/instance.h" namespace wivrn { @@ -63,10 +63,10 @@ static bool is_complete(const shard_set & shards) return true; } -std::optional shard_set::insert(data_shard && shard) +std::optional shard_set::insert(data_shard && shard, xr::instance & instance) { if (empty()) - feedback.received_first_packet = application::now(); + feedback.received_first_packet = instance.now(); auto idx = shard.shard_idx; if (idx >= data.size()) @@ -121,12 +121,12 @@ void shard_accumulator::push_shard(video_stream_data_shard && shard) } else if (frame_diff == 0) { - auto shard_idx = current.insert(std::move(shard)); + auto shard_idx = current.insert(std::move(shard), instance); try_submit_frame(shard_idx); } else if (frame_diff == 1) { - next.insert(std::move(shard)); + next.insert(std::move(shard), instance); if (is_complete(next)) { debug_why_not_sent(current); @@ -191,7 +191,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) if (not frame_complete) return; - current.feedback.received_last_packet = application::now(); + current.feedback.received_last_packet = instance.now(); current.feedback.sent_to_decoder = current.feedback.received_last_packet; data_shard::timing_info_t timing_info = data_shards.back()->timing_info.value_or(data_shard::timing_info_t{}); current.feedback.encode_begin = timing_info.encode_begin; @@ -216,7 +216,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) void shard_accumulator::send_feedback(wivrn::from_headset::feedback & feedback) { if (not feedback.received_last_packet) - feedback.received_first_packet = application::now(); + feedback.received_first_packet = instance.now(); auto scene = weak_scene.lock(); if (scene) scene->send_feedback(feedback); diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index 4777de7f..406c0c49 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -34,6 +34,11 @@ using decoder_impl = ::wivrn::ffmpeg::decoder; #include #include +namespace xr +{ +class instance; +} + namespace wivrn { @@ -50,7 +55,7 @@ public: void reset(uint64_t frame_index); bool empty() const; - std::optional insert(data_shard &&); + std::optional insert(data_shard &&, xr::instance & instance); wivrn::from_headset::feedback feedback{}; @@ -70,11 +75,13 @@ private: shard_set current; shard_set next; std::weak_ptr weak_scene; + xr::instance & instance; public: explicit shard_accumulator( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, + xr::instance & instance, const wivrn::to_headset::video_stream_description::item & description, float fps, std::weak_ptr scene, @@ -82,7 +89,8 @@ public: decoder(std::make_shared(device, physical_device, description, fps, stream_index, scene, this)), current(stream_index), next(stream_index), - weak_scene(scene) + weak_scene(scene), + instance(instance) { next.reset(1); } diff --git a/client/render/gpu_buffer.h b/client/render/gpu_buffer.h index 7f03c03e..892dc3fb 100644 --- a/client/render/gpu_buffer.h +++ b/client/render/gpu_buffer.h @@ -18,7 +18,6 @@ #pragma once -#include "application.h" #include "utils/alignment.h" #include "vk/allocation.h" #include @@ -115,10 +114,10 @@ public: } } - buffer_allocation copy_to_gpu() + buffer_allocation copy_to_gpu(vk::raii::Device & device) { buffer_allocation gpu_buffer{ - application::get_device(), + device, vk::BufferCreateInfo{ .size = bytes.size(), .usage = usage}, diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp index 1f762af9..75556eca 100644 --- a/client/render/imgui_impl.cpp +++ b/client/render/imgui_impl.cpp @@ -345,9 +345,9 @@ imgui_context::imgui_context( ImGui_ImplVulkan_InitInfo init_info = { .Instance = *application::get_vulkan_instance(), - .PhysicalDevice = *application::get_physical_device(), - .Device = *application::get_device(), - .QueueFamily = application::queue_family_index(), + .PhysicalDevice = *physical_device, + .Device = *device, + .QueueFamily = queue_family_index, .Queue = *queue.get_unsafe(), .RenderPass = *renderpass, .MinImageCount = 2, @@ -718,7 +718,7 @@ void imgui_context::new_frame(XrTime display_time) ImPlot::SetCurrentContext(plot_context); if (last_display_time) - io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f); + io.DeltaTime = std::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f); last_display_time = display_time; // Uses the window list from last frame diff --git a/client/render/scene_loader.cpp b/client/render/scene_loader.cpp index 66ba86a4..07ceddfe 100644 --- a/client/render/scene_loader.cpp +++ b/client/render/scene_loader.cpp @@ -785,7 +785,7 @@ entt::registry scene_loader::operator()(const std::filesystem::path & gltf_path) // Copy the staging buffer to the GPU spdlog::debug("Uploading scene data ({} bytes) to GPU memory", staging_buffer.size()); - auto buffer = std::make_shared(staging_buffer.copy_to_gpu()); + auto buffer = std::make_shared(staging_buffer.copy_to_gpu(device)); for (auto & i: materials) i->buffer = buffer; diff --git a/client/scene.cpp b/client/scene.cpp index feeb29fe..684922ee 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -51,8 +51,6 @@ scene::scene(key, const meta & current_meta, std::span support queue_family_index(application::instance().vk_queue_family_index), current_meta(current_meta) { - passthrough_supported = system.passthrough_supported(); - swapchain_format = vk::Format::eUndefined; spdlog::info("Supported swapchain formats:"); @@ -443,7 +441,7 @@ std::pair scene::load_gltf(const std::filesyst node.layer_mask = layer_mask; assert(renderer); - scene_loader loader(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); + scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material()); loader.add_prefab(world, loader(path), entity); diff --git a/client/scene.h b/client/scene.h index e84bbcea..9593100c 100644 --- a/client/scene.h +++ b/client/scene.h @@ -103,7 +103,6 @@ public: protected: vk::Format swapchain_format; vk::Format depth_format; - xr::system::passthrough_type passthrough_supported; bool composition_layer_depth_test_supported; bool composition_layer_color_scale_bias_supported; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 2e9a8218..27fa5a17 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -649,10 +649,10 @@ void scenes::lobby::render(const XrFrameState & frame_state) if (!new_gui_position and head_position) new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first); - if (application::get_hand_tracking_supported()) + if (left_hand and right_hand) { - auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime); - auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime); + auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime); + auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime); hand_model::apply(world, left, right); @@ -798,7 +798,7 @@ void scenes::lobby::on_focused() // assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; })); renderer.emplace(device, physical_device, queue, commandpool); - loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material()); + loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material()); lobby_entity = load_gltf("ground.gltf", layer_lobby).first; @@ -835,12 +835,6 @@ void scenes::lobby::on_focused() xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first; #endif - if (application::get_hand_tracking_supported()) - { - hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); - hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); - } - recenter_left_action = get_action("recenter_left").first; recenter_right_action = get_action("recenter_right").first; @@ -862,21 +856,19 @@ void scenes::lobby::on_focused() .haptic_output = get_action("right_haptic").first, }, }; - if (auto & hand = application::get_left_hand()) + + if (system.hand_tracking_supported()) { - imgui_inputs.push_back( - { - .hand = &hand, - }); - } - if (auto & hand = application::get_right_hand()) - { - imgui_inputs.push_back( - { - .hand = &hand, - }); + left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT); + right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT); + hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers); + hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers); + imgui_inputs.push_back({.hand = &*left_hand}); + imgui_inputs.push_back({.hand = &*right_hand}); } + face_tracker = xr::make_face_tracker(instance, system, session); + // 0.4mm / pixel std::vector vps{ { @@ -977,6 +969,9 @@ void scenes::lobby::on_unfocused() world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools input.reset(); + left_hand.reset(); + right_hand.reset(); + face_tracker.emplace(); loader.reset(); renderer.reset(); diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index e68040ce..d527ec9c 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -29,6 +29,7 @@ #include "wivrn_config.h" #include "wivrn_discover.h" #include "wivrn_packets.h" +#include "xr/face_tracker.h" #include #include @@ -66,6 +67,11 @@ class lobby : public scene_impl std::optional imgui_ctx; + std::optional left_hand; + std::optional right_hand; + + xr::face_tracker face_tracker; + std::string selected_item; std::unique_ptr license; diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index 152bcd70..f25126be 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -34,6 +34,7 @@ #include "utils/overloaded.h" #include "utils/ranges.h" #include "version.h" +#include "xr/body_tracker.h" #include #include #include @@ -889,7 +890,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not application::get_hand_tracking_supported()); + ImGui::BeginDisabled(not system.hand_tracking_supported()); bool enabled = config.check_feature(feature::hand_tracking); if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled)) { @@ -913,7 +914,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } { - ImGui::BeginDisabled(not application::get_face_tracking_supported()); + ImGui::BeginDisabled(std::holds_alternative(face_tracker)); bool enabled = config.check_feature(feature::face_tracking); if (ImGui::Checkbox(_S("Enable face tracking"), &enabled)) { @@ -925,8 +926,9 @@ void scenes::lobby::gui_settings() imgui_ctx->vibrate_on_hover(); } + auto body_tracker = system.body_tracker_supported(); { - ImGui::BeginDisabled(not application::get_body_tracking_supported()); + ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none); bool enabled = config.check_feature(feature::body_tracking); if (ImGui::Checkbox(_S("Enable body tracking"), &enabled)) { @@ -941,19 +943,14 @@ void scenes::lobby::gui_settings() } else { - std::visit(utils::overloaded{ - [](auto &) {}, - [this](xr::fb_body_tracker &) { - imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); - }, - }, - application::get_body_tracker()); + if (body_tracker == xr::body_tracker_type::fb) + imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions")); } } imgui_ctx->vibrate_on_hover(); } - if (std::holds_alternative(application::get_body_tracker())) + if (body_tracker == xr::body_tracker_type::fb) { ImGui::BeginDisabled(not config.check_feature(feature::body_tracking)); ImGui::Indent(); @@ -979,7 +976,7 @@ void scenes::lobby::gui_settings() ImGui::EndDisabled(); } - ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough); + ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none); if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled)) { setup_passthrough(); @@ -1311,12 +1308,12 @@ void scenes::lobby::gui_first_run() item{ .f = feature::face_tracking, .text = _S("Enable face tracking?"), - .supported = application::get_face_tracking_supported(), + .supported = not std::holds_alternative(face_tracker), }, item{ .f = feature::body_tracking, .text = _S("Enable body tracking?"), - .supported = application::get_body_tracking_supported(), + .supported = system.body_tracker_supported() != xr::body_tracker_type::none, }, }; @@ -1646,11 +1643,22 @@ static auto face_weights() return res; } -static const char * get_face_icon(XrTime predicted_display_time) +static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker) { static const auto w = face_weights(); wivrn::from_headset::tracking::fb_face2 expression; - std::get(application::get_face_tracker()).get_weights(predicted_display_time, expression); + const char * result = nullptr; + std::visit(utils::overloaded{ + [](std::monostate &) {}, + [&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; }, + [&](auto & ft) { + ft.get_weights(predicted_display_time, expression); + }, + }, + face_tracker); + + if (result) + return result; if (not expression.is_valid) return ICON_FA_FACE_MEH; @@ -1693,7 +1701,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) .icon_disabled = ICON_FA_MICROPHONE_SLASH, }); - if (application::get_hand_tracking_supported()) + if (system.hand_tracking_supported()) { items.push_back({ .f = feature::hand_tracking, @@ -1714,21 +1722,18 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) }); } - if (application::get_face_tracking_supported()) + if (not std::holds_alternative(face_tracker)) { - const char * icon_enabled = std::holds_alternative(application::get_face_tracker()) - ? get_face_icon(predicted_display_time) - : ICON_FA_FACE_KISS_WINK_HEART; items.push_back({ .f = feature::face_tracking, .tooltip_enabled = _("Face tracking is enabled"), .tooltip_disabled = _("Face tracking is disabled"), - .icon_enabled = icon_enabled, + .icon_enabled = get_face_icon(predicted_display_time, face_tracker), .icon_disabled = ICON_FA_FACE_MEH_BLANK, }); } - if (application::get_body_tracking_supported()) + if (system.body_tracker_supported() != xr::body_tracker_type::none) { items.push_back({ .f = feature::body_tracking, @@ -1802,7 +1807,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time) if (*status.charge > 0.995) icon_nr = 5; else - icon_nr = application::now() / 500'000'000 % 5; + icon_nr = instance.now() / 500'000'000 % 5; } else icon_nr = std::round((*status.charge) * 4); @@ -2031,7 +2036,7 @@ std::vector> scenes::lobby::draw_gui(XrTi if (not is_gui_visible(*imgui_ctx, predicted_display_time)) { - if (application::get_hand_tracking_supported()) + if (system.hand_tracking_supported()) display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window")); else display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window")); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 50dca0a8..63ab4a21 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -17,11 +17,9 @@ * along with this program. If not, see . */ #include "constants.h" -#include "utils/overloaded.h" -#include "xr/fb_body_tracker.h" +#include "xr/body_tracker.h" +#include "xr/face_tracker.h" #include "xr/fb_face_tracker2.h" -#include "xr/htc_body_tracker.h" -#include "xr/pico_body_tracker.h" #include "xr/space.h" #include #include @@ -256,39 +254,42 @@ std::shared_ptr scenes::stream::create(std::unique_ptrsystem.face_tracker_supported()) + { + case xr::face_tracker_type::none: + info.face_tracking = from_headset::face_type::none; + break; + case xr::face_tracker_type::fb: + case xr::face_tracker_type::pico: + info.face_tracking = from_headset::face_type::fb2; + break; + case xr::face_tracker_type::htc: + info.face_tracking = from_headset::face_type::htc; + break; + } } info.num_generic_trackers = 0; if (config.check_feature(feature::body_tracking)) { - info.num_generic_trackers = std::visit(utils::overloaded{ - [&](std::monostate &) { - return size_t(0); - }, - [&](auto & b) { - return b.count(); - }, - }, - application::get_body_tracker()); + switch (self->system.body_tracker_supported()) + { + case xr::body_tracker_type::none: + break; + case xr::body_tracker_type::fb: + info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size(); + break; + case xr::body_tracker_type::htc: + info.num_generic_trackers = application::get_generic_trackers().size(); + break; + case xr::body_tracker_type::pico: + info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size(); + break; + } } info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right); - info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough; + info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none; info.system_name = std::string(self->system.properties().systemName); audio::get_audio_description(info); @@ -359,7 +360,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrhaptics_actions.emplace(id, haptics_action{ .action = action.first, - .path = application::string_to_path(path), + .path = self->instance.string_to_path(path), }); } } @@ -390,7 +391,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrget_default_material()); + loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material()); std::string profile = controller_name(); input.emplace( @@ -493,6 +494,8 @@ void scenes::stream::on_unfocused() loader.reset(); renderer.reset(); clear_swapchains(); + left_hand.reset(); + right_hand.reset(); imgui_ctx.reset(); swapchain_imgui = xr::swapchain(); @@ -523,7 +526,7 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p { if (decoder != decoders[stream].decoder.get()) return; - handle->feedback.received_from_decoder = application::now(); + handle->feedback.received_from_decoder = instance.now(); std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]); } @@ -532,7 +535,7 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p })) { state_ = state::streaming; - spdlog::info("Stream scene ready at t={}", application::now()); + spdlog::info("Stream scene ready at t={}", instance.now()); } } @@ -927,7 +930,7 @@ void scenes::stream::render(const XrFrameState & frame_state) if (not blit_handle or not *i.blit_pipeline) continue; - blit_handle->feedback.blitted = application::now(); + blit_handle->feedback.blitted = instance.now(); if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000) state_ = stream::state::stalled; ++blit_handle->feedback.times_displayed; @@ -1362,7 +1365,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y); decoders.push_back(accumulator_images{ - .decoder = std::make_unique(device, physical_device, item, description.fps, shared_from_this(), stream_index), + .decoder = std::make_unique(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index), }); } } diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 391d2a9b..146b6752 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -86,6 +86,7 @@ private: std::thread network_thread; thread_safe tracking_control{}; std::array, 2> interaction_profiles; // left and right hand + std::atomic interaction_profile_changed = false; std::atomic recenter_requested = false; std::atomic display_time_phase = 0; std::atomic display_time_period = 0; @@ -129,6 +130,8 @@ private: std::optional