Revert "Merge branch 'master' of https://github.com/Vindicus999/WiVRn"

This reverts commit 6212dccc2b, reversing
changes made to 80e31b642a.
This commit is contained in:
Vindicus999
2025-08-24 09:56:21 -04:00
parent 6212dccc2b
commit ea45e9f91b
135 changed files with 2784 additions and 12225 deletions
+11 -18
View File
@@ -13,7 +13,7 @@ if (WIVRN_USE_LIBKTX)
FetchContent_MakeAvailable(libktx)
endif()
if (NOT WIVRN_USE_SYSTEM_BOOST)
if (NOT BOOST_FOUND)
FetchContent_MakeAvailable(boost)
endif()
@@ -51,7 +51,7 @@ if(ANDROID)
else()
add_executable(wivrn)
if (WIVRN_USE_SYSTEM_OPENXR)
if (OpenXR_FOUND)
target_link_libraries(wivrn OpenXR::openxr_loader OpenXR::headers)
else()
FetchContent_MakeAvailable(openxr_loader)
@@ -91,22 +91,7 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
wivrn_compile_glsl(wivrn ${VULKAN_SHADERS})
target_link_libraries(wivrn
Boost::locale
Boost::url
EnTT::EnTT
fastgltf
FreetypeHarfbuzz
glm::glm
imspinner
simdjson
spdlog::spdlog
stb
uni-algo
Vulkan::Vulkan
wivrn-common
wivrn-external
)
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale)
if (WIVRN_USE_LIBKTX)
target_link_libraries(wivrn ktx_read)
@@ -122,6 +107,10 @@ if(NOT ANDROID)
install(TARGETS wivrn)
endif()
target_link_libraries(wivrn simdjson uni-algo wivrn-common wivrn-external)
##############################################################################
# Dear ImGui
#
@@ -151,6 +140,10 @@ target_link_libraries(wivrn-imgui FreetypeHarfbuzz)
target_link_libraries(wivrn wivrn-imgui)
##############################################################################
# EnTT
#
target_link_libraries(wivrn EnTT::EnTT)
##############################################################################
# Vulkan Validation Layer
+129 -103
View File
@@ -28,20 +28,16 @@
#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/to_string.h"
#include "xr/xr.h"
#include <algorithm>
#include <boost/locale.hpp>
#include <boost/url/parse.hpp>
#include <chrono>
#include <ctype.h>
#include <exception>
#include <magic_enum.hpp>
#include <string>
#include <thread>
#include <vector>
@@ -138,7 +134,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/facebook/touch_controller_pro",
.required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME},
.required_extensions = {"XR_FB_touch_controller_pro"},
.max_version = XR_MAKE_VERSION(1, 1, 0),
.input_sources = {
"/user/hand/left/output/haptic",
@@ -251,7 +247,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/meta/touch_controller_plus",
.required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME},
.required_extensions = {"XR_META_touch_controller_plus"},
.max_version = XR_MAKE_VERSION(1, 1, 0),
.input_sources = {
"/user/hand/left/output/haptic",
@@ -352,7 +348,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/bytedance/pico_neo3_controller",
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_BD_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -395,7 +391,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/bytedance/pico4_controller",
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_BD_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -438,7 +434,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/bytedance/pico4s_controller",
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_BD_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -481,7 +477,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/htc/vive_focus3_controller",
.required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_HTC_vive_focus3_controller_interaction"},
.input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -523,7 +519,7 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/ext/hand_interaction_ext",
.required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_EXT_hand_interaction"},
.input_sources = {
"/user/hand/left/input/aim/pose",
"/user/hand/left/input/grip/pose",
@@ -552,14 +548,11 @@ static std::vector<interaction_profile> interaction_profiles{
},
interaction_profile{
.profile_name = "/interaction_profiles/htc/vive_xr_tracker",
.required_extensions = {
XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME,
XR_HTC_PATH_ENUMERATION_EXTENSION_NAME,
},
.required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
},
interaction_profile{
.profile_name = "/interaction_profiles/ext/eye_gaze_interaction",
.required_extensions = {XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME},
.required_extensions = {"XR_EXT_eye_gaze_interaction"},
.input_sources = {
"/user/eyes_ext/input/gaze_ext/pose",
},
@@ -724,13 +717,15 @@ 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<const char *> instance_extensions{};
std::unordered_set<std::string_view> optional_device_extensions{};
#ifndef NDEBUG
bool debug_report_found = false;
bool debug_utils_found = false;
#endif
spdlog::info("Available Vulkan instance extensions:");
std::vector<std::pair<std::string, int>> extensions;
for (vk::ExtensionProperties & i: vk_context.enumerateInstanceExtensionProperties(nullptr))
@@ -739,27 +734,28 @@ 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) and
guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load
{
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
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);
optional_device_extensions.emplace(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
optional_device_extensions.emplace(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
#ifdef __ANDROID__
vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME);
@@ -878,7 +874,6 @@ void application::initialize_vulkan()
.ppEnabledExtensionNames = vk_device_extensions.data(),
.pEnabledFeatures = &device_features,
},
vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{},
#ifdef __ANDROID__
vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{
.samplerYcbcrConversion = VK_TRUE,
@@ -886,22 +881,6 @@ void application::initialize_vulkan()
#endif
};
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
{
auto [feat, fragment_feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
auto & create_feat = device_create_info.get<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
create_feat.primitiveFragmentShadingRate = fragment_feat.primitiveFragmentShadingRate;
create_feat.attachmentFragmentShadingRate = fragment_feat.attachmentFragmentShadingRate;
spdlog::info("Fragment shading rate features: primitive={} attachment={}",
create_feat.primitiveFragmentShadingRate,
create_feat.attachmentFragmentShadingRate);
}
else
{
device_create_info.unlink<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
}
vk_device = xr_system_id.create_device(vk_physical_device, device_create_info.get());
*vk_queue.lock() = vk_device.getQueue(vk_queue_family_index, 0);
@@ -923,16 +902,10 @@ void application::initialize_vulkan()
pipeline_cache = vk::raii::PipelineCache(vk_device, pipeline_cache_info);
allocator.emplace(VmaAllocatorCreateInfo{
.physicalDevice = *vk_physical_device,
.device = *vk_device,
.instance = *vk_instance,
},
#ifndef NDEBUG
debug_utils_found
#else
false
#endif
);
.physicalDevice = *vk_physical_device,
.device = *vk_device,
.instance = *vk_instance,
});
}
void application::log_views()
@@ -979,6 +952,8 @@ void application::initialize_actions()
{
spdlog::debug("Initializing actions");
auto * htc_body = std::get_if<xr::htc_body_tracker>(&body_tracker);
// Build an action set with all possible input sources
std::vector<XrActionSet> action_sets;
xr_actionset = xr::actionset(xr_instance, "all_actions", "All actions");
@@ -992,9 +967,7 @@ void application::initialize_actions()
std::vector<std::string> sources;
for (auto & profile: interaction_profiles)
{
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;
profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
if (profile.profile_name.ends_with("khr/simple_controller"))
{
@@ -1035,15 +1008,15 @@ void application::initialize_actions()
}
if (add_palms)
{
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") //
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") //
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 (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) //
else if (utils::contains(xr_extensions, 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"))
{
@@ -1054,15 +1027,14 @@ void application::initialize_actions()
}
// Dynamically add VIVE XR Trackers to the profile if available
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))
if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME))
{
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 & user_path: htc_body->get_paths())
{
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));
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));
}
}
}
@@ -1110,14 +1082,8 @@ 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"))
{
for (auto & [path, action]: generic_trackers)
{
if (name.starts_with(xr_instance.path_to_string(path)))
action = 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));
}
// Build an action set for each scene
@@ -1154,7 +1120,7 @@ void application::initialize_actions()
xr_bindings.push_back(XrActionSuggestedBinding{
.action = a,
.binding = xr_instance.string_to_path(k.input_source)});
.binding = string_to_path(k.input_source)});
}
}
}
@@ -1171,7 +1137,7 @@ void application::initialize_actions()
for (const auto & name: profile.input_sources)
{
xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)});
xr_bindings.push_back({actions_by_name[name], string_to_path(name)});
}
try
@@ -1191,7 +1157,7 @@ void application::initialize()
{
// LogLayersAndExtensions
assert(!xr_instance);
std::vector<std::string> xr_extensions;
xr_extensions.clear();
// Required extensions
xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME);
@@ -1264,16 +1230,21 @@ void application::initialize()
spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking);
spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking);
spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported());
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;
}
if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))
if (utils::contains(xr_extensions, 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 (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
{
spdlog::info(" OpenXR post-processing extension support: true");
openxr_post_processing_supported = true;
@@ -1281,39 +1252,23 @@ void application::initialize()
switch (xr_system_id.passthrough_supported())
{
case xr::passthrough_type::none:
case xr::system::passthrough_type::no_passthrough:
spdlog::info(" Passthrough: not supported");
break;
case xr::passthrough_type::bw:
case xr::system::passthrough_type::bw:
spdlog::info(" Passthrough: black and white");
break;
case xr::passthrough_type::color:
case xr::system::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, 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);
// 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)
{
auto props = xr_system_id.htc_face_tracking_properties();
xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking);
}
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();
@@ -1322,6 +1277,70 @@ void application::initialize()
spdlog::info(" {}", xr::to_string(i));
}
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)
{
left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
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::fb_face_tracker2>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(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::htc_face_tracker>(xr_instance, xr_session, htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking);
}
if (std::holds_alternative<std::monostate>(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::pico_face_tracker>(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::fb_body_tracker>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(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::htc_body_tracker>(xr_instance, xr_session);
}
if (std::holds_alternative<std::monostate>(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::pico_body_tracker>(xr_instance, xr_session);
}
vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
@@ -1856,6 +1875,13 @@ void application::poll_events()
exit_requested = true;
}
break;
case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED: {
if (auto * htc_body = std::get_if<xr::htc_body_tracker>(&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: {
+82 -13
View File
@@ -28,11 +28,14 @@
#include "utils/thread_safe.h"
#include "vk/vk_allocator.h"
#include "wifi_lock.h"
#include "xr/actionset.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/swapchain.h"
#include "xr/system.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 <atomic>
#include <boost/locale/generator.hpp>
#include <boost/locale/gnu_gettext.hpp>
@@ -123,7 +126,12 @@ class application : public singleton<application>
xr::actionset xr_actionset;
std::vector<std::tuple<XrAction, XrActionType, std::string>> actions;
std::vector<std::pair<XrPath, xr::space>> generic_trackers;
bool hand_tracking_supported = false;
xr::hand_tracker left_hand;
xr::hand_tracker right_hand;
std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker> face_tracker;
std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker> body_tracker;
bool eye_gaze_supported = false;
@@ -133,6 +141,7 @@ class application : public singleton<application>
bool session_focused = false;
bool session_visible = false;
bool debug_extensions_found = false;
std::vector<std::string> xr_extensions;
std::vector<const char *> vk_device_extensions;
std::atomic<bool> exit_requested = false;
std::filesystem::path config_path;
@@ -262,6 +271,16 @@ 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<scene>);
@@ -332,6 +351,16 @@ 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<vk::raii::Queue> & get_queue()
{
return instance().vk_queue;
@@ -347,21 +376,26 @@ 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;
@@ -382,6 +416,21 @@ 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<std::monostate>(instance().face_tracker);
}
static bool get_body_tracking_supported()
{
return !std::holds_alternative<std::monostate>(instance().body_tracker);
}
static bool get_eye_gaze_supported()
{
return instance().eye_gaze_supported;
@@ -392,9 +441,29 @@ public:
return instance().openxr_post_processing_supported;
}
static auto & get_generic_trackers()
static xr::hand_tracker & get_left_hand()
{
return instance().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<std::string> & get_xr_extensions()
{
return instance().xr_extensions;
}
static const std::vector<const char *> & get_vk_device_extensions()
+47 -15
View File
@@ -82,8 +82,6 @@ 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;
@@ -96,7 +94,7 @@ bool configuration::check_feature(feature f) const
case feature::microphone:
break;
case feature::hand_tracking:
if (not system.hand_tracking_supported())
if (not application::get_hand_tracking_supported())
return false;
break;
case feature::eye_gaze:
@@ -104,12 +102,50 @@ bool configuration::check_feature(feature f) const
return false;
break;
case feature::face_tracking:
if (system.face_tracker_supported() == xr::face_tracker_type::none)
return false;
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<xr::htc_face_tracker>(application::get_face_tracker()))
return false;
break;
case model::pico_4_pro:
case model::pico_4_enterprise:
if (not std::holds_alternative<xr::pico_face_tracker>(application::get_face_tracker()))
return false;
break;
default:
if (not std::holds_alternative<xr::fb_face_tracker2>(application::get_face_tracker()))
return false;
break;
}
break;
case feature::body_tracking:
if (system.body_tracker_supported() == xr::body_tracker_type::none)
return false;
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_3s:
if (not std::holds_alternative<xr::fb_body_tracker>(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<xr::htc_body_tracker>(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<xr::pico_body_tracker>(application::get_body_tracker()))
return false;
break;
default:
break;
}
break;
}
}
@@ -145,8 +181,8 @@ void configuration::set_feature(feature f, bool state)
configuration::configuration(xr::system & system)
{
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
features[feature::hand_tracking] = system.hand_tracking_supported();
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
features[feature::hand_tracking] = application::get_hand_tracking_supported();
try
{
simdjson::dom::parser parser;
@@ -178,9 +214,6 @@ configuration::configuration(xr::system & system)
if (auto val = root["resolution_scale"]; val.is_double())
resolution_scale = val.get_double();
if (auto val = root["enable_stream_gui"]; val.is_bool())
enable_stream_gui = val.get_bool();
if (auto val = root["sgsr"]; val.is_object())
parse_sgsr_options(val.get_object());
@@ -207,7 +240,7 @@ configuration::configuration(xr::system & system)
features[i] = val.get_bool();
}
if (system.passthrough_supported() == xr::passthrough_type::none)
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
passthrough_enabled = false;
if (auto val = root["override_foveation_enable"]; val.is_bool())
@@ -233,7 +266,7 @@ configuration::configuration(xr::system & system)
resolution_scale = 1.4;
sgsr = {};
openxr_post_processing = {};
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
}
}
@@ -332,7 +365,6 @@ void configuration::save()
json << ",\"mic_unprocessed_audio\":" << std::boolalpha << mic_unprocessed_audio;
json << ",\"fb_lower_body\":" << std::boolalpha << fb_lower_body;
json << ",\"fb_hip\":" << std::boolalpha << fb_hip;
json << ",\"enable_stream_gui\":" << std::boolalpha << enable_stream_gui;
for (auto & [key, value]: features)
json << "," << key << ":" << std::boolalpha << value;
json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout);
-2
View File
@@ -56,8 +56,6 @@ public:
bool fb_lower_body = false;
bool fb_hip = true;
bool enable_stream_gui = true;
// Snapdragon Game Super Resolution
struct sgsr_settings
{
+8 -8
View File
@@ -18,9 +18,9 @@
*/
#include "shard_accumulator.h"
#include "scenes/stream.h" // IWYU pragma: keep
#include "application.h"
#include "scenes/stream.h"
#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<uint16_t> shard_set::insert(data_shard && shard, xr::instance & instance)
std::optional<uint16_t> shard_set::insert(data_shard && shard)
{
if (empty())
feedback.received_first_packet = instance.now();
feedback.received_first_packet = application::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), instance);
auto shard_idx = current.insert(std::move(shard));
try_submit_frame(shard_idx);
}
else if (frame_diff == 1)
{
next.insert(std::move(shard), instance);
next.insert(std::move(shard));
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 = instance.now();
current.feedback.received_last_packet = application::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 = instance.now();
feedback.received_first_packet = application::now();
auto scene = weak_scene.lock();
if (scene)
scene->send_feedback(feedback);
+2 -10
View File
@@ -34,11 +34,6 @@ using decoder_impl = ::wivrn::ffmpeg::decoder;
#include <optional>
#include <vector>
namespace xr
{
class instance;
}
namespace wivrn
{
@@ -55,7 +50,7 @@ public:
void reset(uint64_t frame_index);
bool empty() const;
std::optional<uint16_t> insert(data_shard &&, xr::instance & instance);
std::optional<uint16_t> insert(data_shard &&);
wivrn::from_headset::feedback feedback{};
@@ -75,13 +70,11 @@ private:
shard_set current;
shard_set next;
std::weak_ptr<scenes::stream> 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<scenes::stream> scene,
@@ -89,8 +82,7 @@ public:
decoder(std::make_shared<decoder_impl>(device, physical_device, description, fps, stream_index, scene, this)),
current(stream_index),
next(stream_index),
weak_scene(scene),
instance(instance)
weak_scene(scene)
{
next.reset(1);
}
+3 -2
View File
@@ -18,6 +18,7 @@
#pragma once
#include "application.h"
#include "utils/alignment.h"
#include "vk/allocation.h"
#include <fastgltf/tools.hpp>
@@ -114,10 +115,10 @@ public:
}
}
buffer_allocation copy_to_gpu(vk::raii::Device & device)
buffer_allocation copy_to_gpu()
{
buffer_allocation gpu_buffer{
device,
application::get_device(),
vk::BufferCreateInfo{
.size = bytes.size(),
.usage = usage},
+4 -11
View File
@@ -345,9 +345,9 @@ imgui_context::imgui_context(
ImGui_ImplVulkan_InitInfo init_info = {
.Instance = *application::get_vulkan_instance(),
.PhysicalDevice = *physical_device,
.Device = *device,
.QueueFamily = queue_family_index,
.PhysicalDevice = *application::get_physical_device(),
.Device = *application::get_device(),
.QueueFamily = application::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::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f);
io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f);
last_display_time = display_time;
// Uses the window list from last frame
@@ -1099,13 +1099,6 @@ ImTextureID imgui_context::load_texture(const std::string & filename)
void imgui_context::free_texture(ImTextureID texture)
{
// Make sure we are done using the texture
std::vector<vk::Fence> fences;
for (auto & f: command_buffers)
fences.push_back(*f.fence);
if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess)
spdlog::error("vkWaitForfences: {}", vk::to_string(result));
textures.erase(texture);
}
+1 -1
View File
@@ -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<buffer_allocation>(staging_buffer.copy_to_gpu(device));
auto buffer = std::make_shared<buffer_allocation>(staging_buffer.copy_to_gpu());
for (auto & i: materials)
i->buffer = buffer;
+31 -9
View File
@@ -28,7 +28,6 @@
#include "vk/allocation.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/specialization_constants.h"
#include <boost/pfr/core.hpp>
#include <entt/entity/entity.hpp>
#include <entt/entt.hpp>
@@ -536,11 +535,34 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info)
auto vertex_shader = load_shader(device, info.shader_name + ".vert");
auto fragment_shader = load_shader(device, info.shader_name + ".frag");
auto specialization = make_specialization_constants(
int32_t(info.nb_texcoords),
VkBool32(info.dithering),
VkBool32(info.alpha_cutout),
VkBool32(info.skinning));
std::array specialization_constants_desc{
vk::SpecializationMapEntry{
.constantID = 0,
.offset = offsetof(pipeline_info, nb_texcoords),
.size = sizeof(int32_t),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = offsetof(pipeline_info, dithering),
.size = sizeof(VkBool32),
},
vk::SpecializationMapEntry{
.constantID = 2,
.offset = offsetof(pipeline_info, alpha_cutout),
.size = sizeof(VkBool32),
},
vk::SpecializationMapEntry{
.constantID = 3,
.offset = offsetof(pipeline_info, skinning),
.size = sizeof(VkBool32),
}};
vk::SpecializationInfo specialization{
.mapEntryCount = specialization_constants_desc.size(),
.pMapEntries = specialization_constants_desc.data(),
.dataSize = sizeof(pipeline_info),
.pData = &info,
};
return vk::raii::Pipeline{
device,
@@ -551,14 +573,14 @@ vk::raii::Pipeline scene_renderer::create_pipeline(const pipeline_info & info)
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = specialization,
.pSpecializationInfo = &specialization,
},
vk::PipelineShaderStageCreateInfo{
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = specialization,
.pSpecializationInfo = &specialization,
},
},
@@ -775,7 +797,7 @@ void scene_renderer::update_material_descriptor_set(renderer::material & materia
device.updateDescriptorSets(write_ds, {});
}
[[maybe_unused]] static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0)
static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0)
{
if (level == 0)
spdlog::info("Node hierarchy:");
+36 -32
View File
@@ -139,42 +139,46 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe
image_allocation text_rasterizer::create_image(vk::Extent2D size)
{
return {device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
.width = size.width,
.height = size.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
},
VmaAllocationCreateInfo{
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"text_rasterizer image"};
image_allocation alloc{device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
.format = text::format,
.extent = {
.width = size.width,
.height = size.height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 1,
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
.sharingMode = vk::SharingMode::eExclusive,
.initialLayout = vk::ImageLayout::eUndefined,
},
VmaAllocationCreateInfo{
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO,
}};
application::set_debug_reports_name<vk::Image>(alloc, "text_rasterizer image");
return alloc;
}
buffer_allocation text_rasterizer::create_buffer(size_t size)
{
return {device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"text_rasterizer buffer"};
buffer_allocation alloc{device,
vk::BufferCreateInfo{
.size = size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
}};
application::set_debug_reports_name<vk::Buffer>(alloc, "text_rasterizer buffer");
return alloc;
}
text_rasterizer::~text_rasterizer()
+3 -1
View File
@@ -51,6 +51,8 @@ scene::scene(key, const meta & current_meta, std::span<const vk::Format> 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:");
@@ -441,7 +443,7 @@ std::pair<entt::entity, components::node &> scene::load_gltf(const std::filesyst
node.layer_mask = layer_mask;
assert(renderer);
scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material());
scene_loader loader(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
loader.add_prefab(world, loader(path), entity);
+1
View File
@@ -103,6 +103,7 @@ 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;
+102 -132
View File
@@ -383,18 +383,9 @@ void scenes::lobby::connect(const configuration::server_data & data)
data.manual);
}
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints)
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(const std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & joints)
{
if (recentering_context and std::get<0>(*recentering_context) != space)
return std::nullopt;
if (not joints)
{
recentering_context.reset();
return std::nullopt;
}
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
const auto & palm = joints[XR_HAND_JOINT_PALM_EXT].first;
const auto & o = palm.pose.orientation;
const auto & p = palm.pose.position;
glm::quat q{o.w, o.x, o.y, o.z};
@@ -402,130 +393,102 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(xr::spaces space,
if (glm::dot(q * glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)) > constants::lobby::recenter_cosangle_min)
{
recentering_context.emplace(space, glm::vec3{}, 0);
return v + glm::vec3(0, constants::lobby::recenter_distance_up, 0) + q * glm::vec3(0, 0, -constants::lobby::recenter_distance_front);
}
recentering_context.reset();
return std::nullopt;
}
std::optional<glm::vec3> scenes::lobby::check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position)
{
xr::spaces controller;
glm::vec3 recenter_position;
float recenter_distance;
std::optional<std::pair<glm::vec3, glm::quat>> aim;
glm::vec3 offset_position;
glm::quat offset_orientation;
if (recentering_context)
if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second)
{
controller = std::get<0>(*recentering_context);
bool state;
switch (controller)
{
case xr::spaces::aim_left:
state = application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second;
break;
case xr::spaces::aim_right:
state = application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second;
break;
default:
return std::nullopt;
}
if (not state)
{
recentering_context.reset();
return std::nullopt;
}
}
else if (auto state = application::read_action_bool(recenter_left_action); state and state->second)
controller = xr::spaces::aim_left;
else if (auto state = application::read_action_bool(recenter_right_action); state and state->second)
controller = xr::spaces::aim_right;
else
return std::nullopt;
auto aim = application::locate_controller(application::space(controller), application::space(xr::spaces::world), predicted_display_time);
if (not aim)
{
// The controller cannot be located
recentering_context.reset();
return std::nullopt;
aim = application::locate_controller(application::space(xr::spaces::aim_left), application::space(xr::spaces::world), predicted_display_time);
std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_left];
}
// Handle controller offset
auto [offset_position, offset_orientation] = input->offset[controller];
aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position;
aim->second = aim->second * offset_orientation;
if (not recentering_context)
if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second)
{
// First frame of recentering
imgui_context::controller_state state{
.active = true,
.aim_position = aim->first,
.aim_orientation = aim->second,
};
aim = application::locate_controller(application::space(xr::spaces::aim_right), application::space(xr::spaces::world), predicted_display_time);
std::tie(offset_position, offset_orientation) = input->offset[xr::spaces::aim_right];
}
imgui_ctx->compute_pointer_position(state);
if (aim)
{
// Handle controller offset
aim->first = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position;
aim->second = aim->second * offset_orientation;
if (state.pointer_position) // TODO: check that the pointer is inside an imgui window
if (not gui_recenter_position or not gui_recenter_distance)
{
auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation);
// First frame where the recenter action is active
imgui_context::controller_state state{
.active = true,
.aim_position = aim->first,
.aim_orientation = aim->second,
};
// Pointer position in world
glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position);
imgui_ctx->compute_pointer_position(state);
// Pointer position in GUI
recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position);
recenter_distance = glm::length(state.aim_position - world_pointer_position);
if (state.pointer_position) // TODO: check that the pointer is inside an imgui window
{
auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation);
// Pointer position in world
glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position);
// Pointer position in GUI
gui_recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position);
gui_recenter_distance = glm::length(state.aim_position - world_pointer_position);
}
else
{
gui_recenter_position = glm::vec3(0, 0, 0);
gui_recenter_distance = constants::lobby::recenter_action_distance;
}
}
else
{
// Use the center of the GUI if the controller points outside of the GUI
recenter_position = glm::vec3(0, 0, 0);
recenter_distance = constants::lobby::recenter_action_distance;
}
// Subsequent frames: find the GUI position that gives the correct world pointer position
glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2);
glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * *gui_recenter_distance;
recentering_context.emplace(controller, recenter_position, recenter_distance);
return std::nullopt;
// I'm sure there's an analytical solution but I can't be bothered to write it so
// let's use a gradient descent instead
auto f = [&](glm::vec3 new_gui_position) {
auto q = compute_gui_orientation(head_position, new_gui_position);
auto M = glm::mat3_cast(q); // plane-to-world transform
glm::vec3 world_pointer_position = new_gui_position + M * *gui_recenter_position;
return world_pointer_position - wanted_world_pointer_position;
};
// One step is usually enough, the solution will continuously improve in the next frames
glm::vec3 gui_position = imgui_ctx->layers()[0].position;
float eps = 0.01;
glm::vec3 obj = f(gui_position);
glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps;
glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps;
glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps;
glm::mat3 jacobian{obj_dx, obj_dy, obj_dz};
gui_position -= glm::inverse(jacobian) * obj;
return gui_position;
}
}
else
{
// Subsequent frames: find the GUI position that gives the correct world pointer position
std::tie(controller, recenter_position, recenter_distance) = *recentering_context;
glm::vec3 controller_direction = -glm::column(glm::mat3_cast(aim->second), 2);
glm::vec3 wanted_world_pointer_position = aim->first + controller_direction * recenter_distance;
// I'm sure there's an analytical solution but I can't be bothered to write it so
// let's use a gradient descent instead
auto f = [&](glm::vec3 new_gui_position) {
auto q = compute_gui_orientation(head_position, new_gui_position);
auto M = glm::mat3_cast(q); // plane-to-world transform
glm::vec3 world_pointer_position = new_gui_position + M * recenter_position;
return world_pointer_position - wanted_world_pointer_position;
};
// One step is usually enough, the solution will continuously improve in the next frames
glm::vec3 gui_position = imgui_ctx->layers()[0].position;
float eps = 0.01;
glm::vec3 obj = f(gui_position);
glm::vec3 obj_dx = (f(gui_position + glm::vec3(eps, 0, 0)) - obj) / eps;
glm::vec3 obj_dy = (f(gui_position + glm::vec3(0, eps, 0)) - obj) / eps;
glm::vec3 obj_dz = (f(gui_position + glm::vec3(0, 0, eps)) - obj) / eps;
glm::mat3 jacobian{obj_dx, obj_dy, obj_dz};
gui_position -= glm::inverse(jacobian) * obj;
return gui_position;
gui_recenter_position.reset();
}
return std::nullopt;
}
std::optional<glm::vec3> scenes::lobby::check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation)
@@ -649,24 +612,26 @@ 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 (left_hand and right_hand)
if (application::get_hand_tracking_supported())
{
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime);
auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime);
hand_model::apply(world, left, right);
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
{
hide_left_controller = true;
if (!new_gui_position)
new_gui_position = check_recenter_gesture(*left);
}
if (right and xr::hand_tracker::check_flags(*right, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
{
hide_right_controller = true;
if (not new_gui_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left);
if (not new_gui_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right);
if (!new_gui_position)
new_gui_position = check_recenter_gesture(*right);
}
}
if (head_position && new_gui_position)
@@ -798,7 +763,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, queue_family_index, renderer->get_default_material());
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
@@ -835,6 +800,12 @@ 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;
@@ -856,18 +827,20 @@ void scenes::lobby::on_focused()
.haptic_output = get_action("right_haptic").first,
},
};
if (system.hand_tracking_supported())
if (auto & hand = application::get_left_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});
imgui_inputs.push_back(
{
.hand = &hand,
});
}
if (auto & hand = application::get_right_hand())
{
imgui_inputs.push_back(
{
.hand = &hand,
});
}
face_tracker = xr::make_face_tracker(instance, system, session);
// 0.4mm / pixel
std::vector<imgui_context::viewport> vps{
@@ -969,9 +942,6 @@ 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<std::monostate>();
loader.reset();
renderer.reset();
+4 -14
View File
@@ -29,9 +29,7 @@
#include "wivrn_config.h"
#include "wivrn_discover.h"
#include "wivrn_packets.h"
#include "xr/face_tracker.h"
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
#include <optional>
#include <vector>
@@ -67,11 +65,6 @@ class lobby : public scene_impl<lobby>
std::optional<imgui_context> imgui_ctx;
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
xr::face_tracker face_tracker;
std::string selected_item;
std::unique_ptr<asset> license;
@@ -101,10 +94,8 @@ class lobby : public scene_impl<lobby>
XrAction recenter_left_action = XR_NULL_HANDLE;
XrAction recenter_right_action = XR_NULL_HANDLE;
// std::optional<glm::vec3> gui_recenter_position;
// std::optional<float> gui_recenter_distance;
// Which controller is used for recentering, position of the pointed point in the GUI, in GUI axes, and distance between the controller and the pointed point during recentering
std::optional<std::tuple<xr::spaces, glm::vec3, float>> recentering_context;
std::optional<glm::vec3> gui_recenter_position;
std::optional<float> gui_recenter_distance;
bool recenter_gui = true;
void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position);
@@ -129,7 +120,6 @@ class lobby : public scene_impl<lobby>
ImTextureID about_picture;
ImTextureID default_icon;
std::unordered_map<std::string, ImTextureID> app_icons;
std::optional<XrTime> timestamp_start_application;
virtual_keyboard keyboard;
@@ -146,7 +136,7 @@ class lobby : public scene_impl<lobby>
void draw_features_status(XrTime predicted_display_time);
void gui_connecting(locked_notifiable<pin_request_data> & request);
void gui_enter_pin(locked_notifiable<pin_request_data> & request);
void gui_connected(XrTime predicted_display_time);
void gui_connected();
void gui_server_list();
void gui_new_server();
void gui_settings();
@@ -162,7 +152,7 @@ class lobby : public scene_impl<lobby>
void connect(const configuration::server_data & data);
std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service service, bool manual_connection);
std::optional<glm::vec3> check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints);
std::optional<glm::vec3> check_recenter_gesture(const std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & joints);
std::optional<glm::vec3> check_recenter_action(XrTime predicted_display_time, glm::vec3 head_position);
std::optional<glm::vec3> check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation);
+34 -68
View File
@@ -34,13 +34,11 @@
#include "utils/overloaded.h"
#include "utils/ranges.h"
#include "version.h"
#include "xr/body_tracker.h"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <filesystem>
#include <glm/gtc/quaternion.hpp>
#include <imspinner.h>
#include <ranges>
#include <spdlog/fmt/fmt.h>
#include <string>
@@ -247,7 +245,6 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
if (next_scene)
{
current_tab = tab::connected;
timestamp_start_application.reset();
ImGui::CloseCurrentPopup();
return;
}
@@ -378,7 +375,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
imgui_ctx->vibrate_on_hover();
}
void scenes::lobby::gui_connected(XrTime predicted_display_time)
void scenes::lobby::gui_connected()
{
if (not next_scene)
{
@@ -403,17 +400,14 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
auto apps = next_scene->get_applications();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
if (apps->empty())
if (apps->applications.empty())
{
CenterTextHV(_("Start an application on the server to start streaming."));
}
else
{
bool app_starting = timestamp_start_application and (predicted_display_time - *timestamp_start_application < 10'000'000'000);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
ImGui::BeginDisabled(app_starting);
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0);
ImGui::Indent(20);
if (server_name.empty())
@@ -432,7 +426,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
ImGui::Indent((usable_window_width - icon_line_width) / 2);
auto t0 = std::chrono::steady_clock::now();
for (const auto [index, app]: utils::enumerate(*apps))
for (const auto [index, app]: utils::enumerate(apps->applications))
{
ImTextureID texture = [&]() -> ImTextureID {
if (app.image.empty())
@@ -463,11 +457,8 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
}();
ImGui::PushStyleColor(ImGuiCol_Button, 0);
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
{
timestamp_start_application = predicted_display_time;
if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0}))
next_scene->start_application(app.id);
}
imgui_ctx->vibrate_on_hover();
ImGui::PopStyleColor(); // ImGuiCol_Button
@@ -479,7 +470,7 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
for (const auto & [app_id, app_icon]: app_icons)
{
if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id))
if (not std::ranges::contains(apps->applications, app_id, &to_headset::application_list::application::id))
to_be_removed.emplace_back(app_id, app_icon);
}
for (const auto & [app_id, app_icon]: to_be_removed)
@@ -490,26 +481,12 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
ScrollWhenDragging();
ImGui::EndChild();
ImGui::EndDisabled();
if (app_starting)
{
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
ImSpinner::SpinnerAng("App starting spinner",
200, // Radius
40, // Thickness
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
6, // Velocity
0.75f * 2 * M_PI // Angle
);
}
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
}
ImGui::PopStyleVar();
ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50});
ImGui::SetCursorPosX(ImGui::GetWindowSize().x - disconnect_size.x - 50);
ImGui::SetCursorPosY(ImGui::GetWindowSize().y - disconnect_size.y - 50);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
@@ -890,7 +867,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(not system.hand_tracking_supported());
ImGui::BeginDisabled(not application::get_hand_tracking_supported());
bool enabled = config.check_feature(feature::hand_tracking);
if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled))
{
@@ -914,7 +891,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(std::holds_alternative<std::monostate>(face_tracker));
ImGui::BeginDisabled(not application::get_face_tracking_supported());
bool enabled = config.check_feature(feature::face_tracking);
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
{
@@ -926,9 +903,8 @@ void scenes::lobby::gui_settings()
imgui_ctx->vibrate_on_hover();
}
auto body_tracker = system.body_tracker_supported();
{
ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none);
ImGui::BeginDisabled(not application::get_body_tracking_supported());
bool enabled = config.check_feature(feature::body_tracking);
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
{
@@ -943,14 +919,19 @@ void scenes::lobby::gui_settings()
}
else
{
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"));
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());
}
}
imgui_ctx->vibrate_on_hover();
}
if (body_tracker == xr::body_tracker_type::fb)
if (std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker()))
{
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
ImGui::Indent();
@@ -976,7 +957,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none);
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
{
setup_passthrough();
@@ -987,13 +968,6 @@ void scenes::lobby::gui_settings()
imgui_ctx->tooltip(_("This feature is not supported by your headset"));
ImGui::EndDisabled();
{
ImGui::Checkbox(_S("Enable in-stream window"), &config.enable_stream_gui);
imgui_ctx->vibrate_on_hover();
if (ImGui::IsItemHovered())
imgui_ctx->tooltip(_("Enables the configuration window to be shown while the game is streaming.\nIf enabled, the window is activated by pressing both thumbsticks."));
}
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
}
@@ -1308,12 +1282,12 @@ void scenes::lobby::gui_first_run()
item{
.f = feature::face_tracking,
.text = _S("Enable face tracking?"),
.supported = not std::holds_alternative<std::monostate>(face_tracker),
.supported = application::get_face_tracking_supported(),
},
item{
.f = feature::body_tracking,
.text = _S("Enable body tracking?"),
.supported = system.body_tracker_supported() != xr::body_tracker_type::none,
.supported = application::get_body_tracking_supported(),
},
};
@@ -1643,22 +1617,11 @@ static auto face_weights()
return res;
}
static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker)
static const char * get_face_icon(XrTime predicted_display_time)
{
static const auto w = face_weights();
wivrn::from_headset::tracking::fb_face2 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;
std::get<xr::fb_face_tracker2>(application::get_face_tracker()).get_weights(predicted_display_time, expression);
if (not expression.is_valid)
return ICON_FA_FACE_MEH;
@@ -1701,7 +1664,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
.icon_disabled = ICON_FA_MICROPHONE_SLASH,
});
if (system.hand_tracking_supported())
if (application::get_hand_tracking_supported())
{
items.push_back({
.f = feature::hand_tracking,
@@ -1722,18 +1685,21 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
if (not std::holds_alternative<std::monostate>(face_tracker))
if (application::get_face_tracking_supported())
{
const char * icon_enabled = std::holds_alternative<xr::fb_face_tracker2>(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 = get_face_icon(predicted_display_time, face_tracker),
.icon_enabled = icon_enabled,
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
});
}
if (system.body_tracker_supported() != xr::body_tracker_type::none)
if (application::get_body_tracking_supported())
{
items.push_back({
.f = feature::body_tracking,
@@ -1807,7 +1773,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
if (*status.charge > 0.995)
icon_nr = 5;
else
icon_nr = instance.now() / 500'000'000 % 5;
icon_nr = application::now() / 500'000'000 % 5;
}
else
icon_nr = std::round((*status.charge) * 4);
@@ -1924,7 +1890,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
gui_connected(predicted_display_time);
gui_connected();
ImGui::End();
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding
}
@@ -2036,7 +2002,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
if (not is_gui_visible(*imgui_ctx, predicted_display_time))
{
if (system.hand_tracking_supported())
if (application::get_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"));
+101 -77
View File
@@ -17,9 +17,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "constants.h"
#include "xr/body_tracker.h"
#include "xr/face_tracker.h"
#include "utils/overloaded.h"
#include "xr/fb_body_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 <glm/gtc/matrix_access.hpp>
#include <glm/gtc/quaternion.hpp>
@@ -40,7 +42,6 @@
#include "utils/ranges.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/specialization_constants.h"
#include "wivrn_packets.h"
#include <algorithm>
#include <mutex>
@@ -188,11 +189,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
self->network_session = std::move(network_session);
self->network_session->send_control([&]() {
from_headset::headset_info_packet info{
.language = application::get_messages_info().language,
.country = application::get_messages_info().country,
.variant = application::get_messages_info().variant,
};
from_headset::headset_info_packet info{};
auto view = self->system.view_configuration_views(self->viewconfig)[0];
view = override_view(view, guess_model());
@@ -254,42 +251,39 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
if (config.check_feature(feature::face_tracking))
{
switch (self->system.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.face_tracking = std::visit(utils::overloaded{
[](std::monostate &) {
return from_headset::face_type::none;
},
[](xr::fb_face_tracker2 &) {
return from_headset::face_type::fb2;
},
[](xr::htc_face_tracker &) {
return from_headset::face_type::htc;
},
[](xr::pico_face_tracker &) {
return from_headset::face_type::fb2;
},
},
application::get_face_tracker());
}
info.num_generic_trackers = 0;
if (config.check_feature(feature::body_tracking))
{
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.num_generic_trackers = std::visit(utils::overloaded{
[&](std::monostate &) {
return size_t(0);
},
[&](auto & b) {
return b.count();
},
},
application::get_body_tracker());
}
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none;
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
info.system_name = std::string(self->system.properties().systemName);
audio::get_audio_description(info);
@@ -317,6 +311,15 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
}
}
{
const auto & info = application::get_messages_info();
self->network_session->send_control(from_headset::get_application_list{
.language = info.language,
.country = info.country,
.variant = info.variant,
});
}
{
const auto & config = application::get_config();
self->override_foveation_enable = config.override_foveation_enable;
@@ -360,7 +363,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
{
self->haptics_actions.emplace(id, haptics_action{
.action = action.first,
.path = self->instance.string_to_path(path),
.path = application::string_to_path(path),
});
}
}
@@ -391,7 +394,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
void scenes::stream::on_focused()
{
gui_status_last_change = instance.now();
gui_status_last_change = application::now();
auto views = system.view_configuration_views(viewconfig);
// stream_view = override_view(views[0], guess_model());
@@ -399,7 +402,7 @@ void scenes::stream::on_focused()
height = views[0].recommendedImageRectHeight;
renderer.emplace(device, physical_device, queue, commandpool);
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
std::string profile = controller_name();
input.emplace(
@@ -467,11 +470,8 @@ void scenes::stream::on_focused()
swapchain_imgui,
std::vector{vp});
if (application::get_config().enable_stream_gui)
{
plots_toggle_1 = get_action("plots_toggle_1").first;
plots_toggle_2 = get_action("plots_toggle_2").first;
}
plots_toggle_1 = get_action("plots_toggle_1").first;
plots_toggle_2 = get_action("plots_toggle_2").first;
recenter_left = get_action("recenter_left").first;
recenter_right = get_action("recenter_right").first;
foveation_pitch = get_action("foveation_pitch").first;
@@ -494,8 +494,6 @@ void scenes::stream::on_unfocused()
loader.reset();
renderer.reset();
clear_swapchains();
left_hand.reset();
right_hand.reset();
imgui_ctx.reset();
swapchain_imgui = xr::swapchain();
@@ -526,16 +524,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
{
if (decoder != decoders[stream].decoder.get())
return;
handle->feedback.received_from_decoder = instance.now();
handle->feedback.received_from_decoder = application::now();
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
}
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
return i.alpha() or not i.empty();
return i.alpha() or not i.frames().empty();
}))
{
state_ = state::streaming;
spdlog::info("Stream scene ready at t={}", instance.now());
spdlog::info("Stream scene ready at t={}", application::now());
}
}
@@ -550,14 +548,15 @@ bool scenes::stream::accumulator_images::alpha() const
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
}
bool scenes::stream::accumulator_images::empty() const
std::vector<uint64_t> scenes::stream::accumulator_images::frames() const
{
std::vector<uint64_t> result;
for (const auto & frame: latest_frames)
{
if (frame)
return false;
result.push_back(frame->feedback.frame_index);
}
return true;
return result;
}
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
@@ -767,15 +766,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
}
if (state_ == state::stalled)
{
network_session->send_control(from_headset::get_application_list{
.language = application::get_messages_info().language,
.country = application::get_messages_info().country,
.variant = application::get_messages_info().variant,
});
application::pop_scene();
}
assert(swapchain);
for (auto & i: decoders)
@@ -808,19 +799,51 @@ void scenes::stream::render(const XrFrameState & frame_state)
const auto & description = i.decoder->desc();
vk::Extent2D image_size = i.decoder->image_size();
std::array useful_size{
float(description.width) / image_size.width,
float(description.height) / image_size.height,
};
spdlog::info("useful size: {}x{} with buffer {}x{}",
description.width,
description.height,
image_size.width,
image_size.height);
auto vert_constants = make_specialization_constants(
float(description.width) / image_size.width,
float(description.height) / image_size.height);
std::array specialization_constants_desc{
vk::SpecializationMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(float),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = sizeof(float),
.size = sizeof(float),
}};
auto frag_constants = make_specialization_constants(
VkBool32(need_srgb_conversion(guess_model())),
VkBool32(i.alpha()));
vk::SpecializationInfo vert_specialization_info;
vert_specialization_info.setMapEntries(specialization_constants_desc);
vert_specialization_info.setData<float>(useful_size);
std::array<VkBool32, 2> constants = {
need_srgb_conversion(guess_model()),
i.alpha(),
};
std::array frag_specialization_constant_desc = {
vk::SpecializationMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(constants[0]),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = sizeof(constants[0]),
.size = sizeof(constants[1]),
},
};
vk::SpecializationInfo frag_specialization_info;
frag_specialization_info.setMapEntries(frag_specialization_constant_desc);
frag_specialization_info.setData<VkBool32>(constants);
// Create graphics pipeline
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
@@ -838,13 +861,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = vert_constants,
.pSpecializationInfo = &vert_specialization_info,
},
{
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = frag_constants,
.pSpecializationInfo = &frag_specialization_info,
}},
.VertexBindingDescriptions = {},
.VertexAttributeDescriptions = {},
@@ -930,7 +953,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
if (not blit_handle or not *i.blit_pipeline)
continue;
blit_handle->feedback.blitted = instance.now();
blit_handle->feedback.blitted = application::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;
@@ -979,10 +1002,6 @@ void scenes::stream::render(const XrFrameState & frame_state)
uint16_t x_offset = 0;
for (auto & out: decoder_output)
{
vk::Extent2D decoder_out_size{
.width = decoder_out_image.info().extent.width,
.height = decoder_out_image.info().extent.height,
};
command_buffer.beginRenderPass(
{
.renderPass = *blit_render_pass,
@@ -1291,7 +1310,10 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
}
// Create outputs for the decoders
decoder_out_size = vk::Extent2D{video_width, video_height};
{
decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32;
vk::ImageCreateInfo image_info{
.flags = vk::ImageCreateFlags{},
.imageType = vk::ImageType::e2D,
@@ -1315,7 +1337,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
vk::ImageViewCreateInfo image_view_info{
.image = vk::Image{decoder_out_image},
.viewType = vk::ImageViewType::e2D,
.format = image_info.format,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.components = {},
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
@@ -1339,8 +1361,8 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
.renderPass = *blit_render_pass,
.attachmentCount = 1,
.pAttachments = &*output.image_view,
.width = image_info.extent.width,
.height = image_info.extent.height,
.width = decoder_out_size.width,
.height = decoder_out_size.height,
.layers = 1,
});
}
@@ -1365,7 +1387,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<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
.decoder = std::make_unique<shard_accumulator>(device, physical_device, item, description.fps, shared_from_this(), stream_index),
});
}
}
@@ -1407,6 +1429,8 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
device,
physical_device,
decoder_out_image,
vk::Extent2D{.width = video_width, .height = video_height},
2,
swapchain_images,
extent,
swapchain.format());
+7 -15
View File
@@ -48,13 +48,6 @@ public:
};
static const size_t image_buffer_size = 3;
struct app
{
std::string id;
std::string name;
std::vector<std::byte> image;
};
private:
static const size_t view_count = 2;
@@ -67,12 +60,12 @@ private:
vk::DescriptorSet descriptor_set = nullptr;
vk::raii::PipelineLayout blit_pipeline_layout = nullptr;
vk::raii::Pipeline blit_pipeline = nullptr;
// latest frames, rolling buffer
// latest frames from oldest to most recent
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, image_buffer_size> latest_frames;
std::shared_ptr<wivrn::shard_accumulator::blit_handle> frame(uint64_t id) const;
bool alpha() const;
bool empty() const;
std::vector<uint64_t> frames() const;
};
wifi_lock::wifi wifi;
@@ -84,9 +77,9 @@ private:
std::unique_ptr<wivrn_session> network_session;
std::atomic<bool> exiting = false;
std::thread network_thread;
thread_safe<to_headset::tracking_control> tracking_control{};
std::mutex tracking_control_mutex;
to_headset::tracking_control tracking_control{};
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
std::atomic<bool> interaction_profile_changed = false;
std::atomic<bool> recenter_requested = false;
std::atomic<XrDuration> display_time_phase = 0;
std::atomic<XrDuration> display_time_period = 0;
@@ -100,6 +93,8 @@ private:
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
vk::raii::RenderPass blit_render_pass = nullptr;
vk::Extent2D decoder_out_size;
vk::Format decoder_out_format;
image_allocation decoder_out_image;
struct renderpass_output
@@ -130,8 +125,6 @@ private:
std::optional<audio> audio_handle;
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
std::optional<input_profile> input;
static inline const uint32_t layer_controllers = 1 << 0;
static inline const uint32_t layer_rays = 1 << 1;
@@ -183,7 +176,7 @@ private:
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
// Last application list received from server
thread_safe<std::vector<app>> applications;
thread_safe<to_headset::application_list> applications;
stream();
@@ -209,7 +202,6 @@ public:
void operator()(to_headset::video_stream_description &&);
void operator()(to_headset::refresh_rate_change &&);
void operator()(to_headset::application_list &&);
void operator()(to_headset::application_icon &&);
void operator()(audio_data &&);
void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr<wivrn::shard_accumulator::blit_handle> handle);
+6 -32
View File
@@ -389,14 +389,8 @@ void scenes::stream::gui_performance_metrics()
ImPlot::PopStyleColor(5);
{
ImGui::Text(
"%s",
fmt::format(
_F("Estimated motion to photons latency: {}ms"),
std::chrono::duration_cast<std::chrono::milliseconds>(
tracking_control.lock()->max_offset)
.count())
.c_str());
std::lock_guard lock(tracking_control_mutex);
ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), std::chrono::duration_cast<std::chrono::milliseconds>(tracking_control.max_offset).count()).c_str());
if (is_gui_interactable())
ImGui::Text("%s", _S("Press the grip button to move the window"));
@@ -423,12 +417,7 @@ void scenes::stream::gui_compact_view()
f(_S("Upload"), 8 * compact_bandwidth_tx * 1e-6, "Mbit/s");
f(_S("CPU time"), compact_cpu_time * 1000, "ms");
f(_S("GPU time"), compact_gpu_time * 1000, "ms");
f(_S("Motion to photon latency"),
std::chrono::duration_cast<std::chrono::microseconds>(
tracking_control.lock()->max_offset)
.count() *
1e-3f,
"ms");
f(_S("Motion to photon latency"), std::chrono::duration_cast<std::chrono::microseconds>(tracking_control.max_offset).count() * 1e-3f, "ms");
ImGui::EndTable();
}
}
@@ -626,8 +615,6 @@ static glm::vec4 compute_ray_limits(const XrPosef & pose, float margin = 0)
void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period)
{
if (not(plots_toggle_1 and plots_toggle_2))
return;
bool interactable = true;
XrSpace world_space = application::space(xr::spaces::world);
auto views = session.locate_views(viewconfig, predicted_display_time, world_space).second;
@@ -645,19 +632,6 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
break;
}
imgui_ctx->set_controllers_enabled(interactable);
if (interactable)
{
if (system.hand_tracking_supported())
{
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
}
else
{
left_hand.reset();
right_hand.reset();
}
if (gui_status != last_gui_status)
{
@@ -889,10 +863,10 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
bool hide_left_controller = false;
bool hide_right_controller = false;
if (left_hand and right_hand)
if (application::get_hand_tracking_supported())
{
auto left = left_hand->locate(world_space, predicted_display_time);
auto right = right_hand->locate(world_space, predicted_display_time);
auto left = application::get_left_hand().locate(world_space, predicted_display_time);
auto right = application::get_right_hand().locate(world_space, predicted_display_time);
if (left and xr::hand_tracker::check_flags(*left, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0))
hide_left_controller = true;
+1 -19
View File
@@ -111,26 +111,8 @@ void scenes::stream::operator()(to_headset::application_list && apps)
std::ranges::sort(apps.applications, [](auto & l, auto & r) {
return una::casesens::collate_utf8(l.name, r.name) < 0;
});
auto locked = applications.lock();
locked->clear();
locked->reserve(apps.applications.size());
for (const auto & i: apps.applications)
{
locked->push_back(app{
.id = std::move(i.id),
.name = std::move(i.name),
});
}
}
void scenes::stream::operator()(to_headset::application_icon && icon)
{
auto locked = applications.lock();
if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end())
it->image = std::move(icon.image);
*locked = std::move(apps);
}
void scenes::stream::start_application(std::string appid)
+55 -95
View File
@@ -24,7 +24,6 @@
#include "vk/allocation.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "vk/specialization_constants.h"
#include <array>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
@@ -38,7 +37,13 @@ struct stream_reprojection::vertex
alignas(8) glm::vec2 position;
// input texture coordinates
alignas(8) glm::vec2 uv;
int32_t shading_rate;
};
struct SgsrSpecializationConstants
{
VkBool32 use_edge_direction;
float edge_threshold;
float edge_sharpness;
};
void stream_reprojection::ensure_vertices(size_t num_vertices)
@@ -69,16 +74,16 @@ stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
stream_reprojection::stream_reprojection(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
image_allocation & input_image,
vk::Image input_image_,
vk::Extent2D input_extent,
uint32_t view_count,
std::vector<vk::Image> output_images_,
vk::Extent2D output_extent,
vk::Format format) :
view_count(input_image.info().arrayLayers),
view_count(view_count),
device(device),
input_extent{
.width = input_image.info().extent.width,
.height = input_image.info().extent.height,
},
input_image(input_image_),
input_extent(input_extent),
output_images(std::move(output_images_)),
output_extent(output_extent)
{
@@ -139,7 +144,7 @@ stream_reprojection::stream_reprojection(
vk::ImageViewCreateInfo iv_info{
.image = input_image,
.viewType = vk::ImageViewType::e2D,
.format = input_image.info().format,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.components = {
.r = vk::ComponentSwizzle::eIdentity,
.g = vk::ComponentSwizzle::eIdentity,
@@ -214,30 +219,50 @@ stream_reprojection::stream_reprojection(
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
const auto & vk_device_extensions = application::get_vk_device_extensions();
bool fragment_shading_rate = false;
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
{
const auto & [prop, rate_prop] = physical_device.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFragmentShadingRatePropertiesKHR>();
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
fragment_shading_rate = rate_prop.fragmentShadingRateNonTrivialCombinerOps and
fragment_feat.primitiveFragmentShadingRate and
fragment_feat.attachmentFragmentShadingRate;
}
// Vertex shader
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
// Fragment shader
std::string fragment_shader_name = "reprojection.frag";
const configuration::sgsr_settings & sgsr = application::get_config().sgsr;
auto sgsr_specialization = make_specialization_constants(
VkBool32(sgsr.use_edge_direction),
float(sgsr.edge_threshold / 255.f),
float(sgsr.edge_sharpness));
vk::SpecializationInfo fragment_specialization_info;
SgsrSpecializationConstants fragment_specialization_constants;
std::vector<vk::SpecializationMapEntry> fragment_specialization_constants_desc;
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
if (sgsr.enabled)
{
fragment_shader_name = "reprojection_sgsr.frag";
vk::raii::ShaderModule fragment_shader = load_shader(device, sgsr.enabled ? "reprojection_sgsr.frag" : "reprojection.frag");
fragment_specialization_constants = {
.use_edge_direction = sgsr.use_edge_direction,
.edge_threshold = float(sgsr.edge_threshold / 255.0),
.edge_sharpness = sgsr.edge_sharpness,
};
fragment_specialization_constants_desc = {
vk::SpecializationMapEntry{
.constantID = 0,
.offset = offsetof(SgsrSpecializationConstants, use_edge_direction),
.size = sizeof(fragment_specialization_constants.use_edge_direction),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = offsetof(SgsrSpecializationConstants, edge_threshold),
.size = sizeof(fragment_specialization_constants.edge_threshold),
},
vk::SpecializationMapEntry{
.constantID = 2,
.offset = offsetof(SgsrSpecializationConstants, edge_sharpness),
.size = sizeof(fragment_specialization_constants.edge_sharpness),
},
};
fragment_specialization_info.setMapEntries(fragment_specialization_constants_desc);
fragment_specialization_info.setDataSize(sizeof(fragment_specialization_constants));
fragment_specialization_info.setPData(&fragment_specialization_constants);
}
vk::raii::ShaderModule fragment_shader = load_shader(device, fragment_shader_name);
// Create graphics pipeline
vk::PipelineLayoutCreateInfo pipeline_layout_info;
@@ -245,7 +270,7 @@ stream_reprojection::stream_reprojection(
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
vk::pipeline_builder pipeline_info_builder{
vk::pipeline_builder pipeline_info{
.flags = {},
.Stages = {
{
@@ -257,7 +282,7 @@ stream_reprojection::stream_reprojection(
.stage = vk::ShaderStageFlagBits::eFragment,
.module = *fragment_shader,
.pName = "main",
.pSpecializationInfo = sgsr.enabled ? sgsr_specialization.info() : nullptr,
.pSpecializationInfo = &fragment_specialization_info,
},
},
.VertexBindingDescriptions = {
@@ -280,12 +305,6 @@ stream_reprojection::stream_reprojection(
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(vertex, uv),
},
{
.location = 2,
.binding = 0,
.format = vk::Format::eR32Sint,
.offset = offsetof(vertex, shading_rate),
},
},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleStrip,
@@ -318,48 +337,6 @@ stream_reprojection::stream_reprojection(
.subpass = 0,
};
vk::GraphicsPipelineCreateInfo pipeline_info(pipeline_info_builder);
// Variable fragment shading
std::array combiner{
vk::FragmentShadingRateCombinerOpKHR::eMax,
vk::FragmentShadingRateCombinerOpKHR::eMax,
};
vk::PipelineFragmentShadingRateStateCreateInfoKHR shading{
.fragmentSize = vk::Extent2D{1, 1},
.combinerOps = combiner,
};
if (fragment_shading_rate)
{
pipeline_info.pNext = &shading;
spdlog::info("Available fragment shading rates:");
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
{
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
{
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
int flags = 0;
if (rate.fragmentSize.width == 4)
flags |= 8;
else if (rate.fragmentSize.width == 2)
flags |= 4;
if (rate.fragmentSize.height == 4)
flags |= 2;
else if (rate.fragmentSize.height == 2)
flags |= 1;
for (int y = std::bit_width(rate.fragmentSize.height) - 1; y < 3; ++y)
{
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
{
if (fragment_sizes[x][y] == 0)
fragment_sizes[x][y] = flags;
}
}
}
}
}
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
// Create image views and framebuffers
@@ -413,21 +390,6 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
return (2 * (p.x.size() + 1) + 1) * p.y.size();
}
int32_t stream_reprojection::shading_rate(int pixels_x, int pixels_y)
{
int x = 0;
if (pixels_x >= 2)
x = 1;
if (pixels_x >= 4)
x = 2;
int y = 0;
if (pixels_y >= 2)
y = 1;
if (pixels_y >= 4)
y = 2;
return fragment_sizes[x][y];
}
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
int destination)
@@ -463,12 +425,10 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
*vertices++ = {
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
.shading_rate = shading_rate(ratio_x, ratio_y),
};
*vertices++ = {
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
.uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size,
.shading_rate = shading_rate(ratio_x, ratio_y),
};
in.x += n_out_x;
out.x += n_out_x * ratio_x;
+4 -10
View File
@@ -41,15 +41,9 @@ class stream_reprojection
vk::raii::RenderPass renderpass = nullptr;
vk::raii::Pipeline pipeline = nullptr;
// Allowed sizes for variable shading rate
// indices are for x, y
// 0 is 1 pixel
// 1 is 2 or 3 pixels
// 2 is 4 pixels or more
int32_t fragment_sizes[3][3] = {};
// Source image
vk::raii::Sampler sampler = nullptr;
vk::Image input_image;
std::vector<vk::raii::ImageView> input_image_views;
std::vector<vk::DescriptorSet> descriptor_sets;
vk::Extent2D input_extent;
@@ -63,13 +57,13 @@ class stream_reprojection
void ensure_vertices(size_t num_vertices);
vertex * get_vertices(size_t view);
int32_t shading_rate(int pixels_x, int pixels_y);
public:
stream_reprojection(
vk::raii::Device & device,
vk::raii::PhysicalDevice & physical_device,
image_allocation & input_image,
vk::Image input_image,
vk::Extent2D input_extent,
uint32_t view_count,
std::vector<vk::Image> output_images,
vk::Extent2D output_extent,
vk::Format format);
+63 -81
View File
@@ -21,10 +21,7 @@
#include "stream.h"
#include "utils/overloaded.h"
#include "wivrn_packets.h"
#include "xr/body_tracker.h"
#include "xr/face_tracker.h"
#include "xr/fb_body_tracker.h"
#include "xr/to_string.h"
#include <magic_enum.hpp>
#include <ranges>
#include <spdlog/spdlog.h>
@@ -380,6 +377,7 @@ void scenes::stream::tracking()
std::vector<from_headset::tracking> tracking;
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
std::vector<from_headset::hand_tracking> hands;
std::array<bool, 2> should_skip_simple_controllers{};
std::vector<from_headset::body_tracking> body;
std::vector<XrView> views;
@@ -387,14 +385,31 @@ void scenes::stream::tracking()
std::vector<serialization_packet> packets;
const bool hand_tracking = config.check_feature(feature::hand_tracking);
std::optional<xr::hand_tracker> left_hand;
std::optional<xr::hand_tracker> right_hand;
const bool face_tracking = config.check_feature(feature::face_tracking);
xr::face_tracker face_tracker;
auto & face_tracker = application::get_face_tracker();
if (face_tracking)
{
// We can't start the face tracking on application initialisation like we do for
// other face trackers due to a Pico runtime bug where face tracking freezes when
// the headset is taken off or the application is quit.
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
face_pico->start();
}
const bool body_tracking = config.check_feature(feature::body_tracking);
xr::body_tracker body_tracker;
auto & body_tracker = application::get_body_tracker();
if (body_tracking)
{
if (auto * body_fb = std::get_if<xr::fb_body_tracker>(&body_tracker))
{
// TODO maybe handle reconnection better, if the settings are changed since
// last connection to running server, the tracker count will mismatch and
// stuff might break
body_fb->stop();
body_fb->start(config.fb_lower_body, config.fb_hip);
}
}
locate_spaces_functor locate_spaces{instance, world_space};
@@ -418,50 +433,11 @@ void scenes::stream::tracking()
timer t(instance);
int samples = 0;
auto control = *tracking_control.lock();
bool interaction_profile_changed = this->interaction_profile_changed.exchange(false);
if (control.enabled[size_t(tid::left_hand)])
to_headset::tracking_control control;
{
if (not left_hand and system.hand_tracking_supported())
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
std::lock_guard lock(tracking_control_mutex);
control = tracking_control;
}
else
left_hand.reset();
if (control.enabled[size_t(tid::right_hand)])
{
if (not right_hand and system.hand_tracking_supported())
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
else
right_hand.reset();
if (face_tracking and control.enabled[size_t(tid::face)])
{
if (std::holds_alternative<std::monostate>(face_tracker))
face_tracker = xr::make_face_tracker(instance, system, session);
}
else
face_tracker.emplace<std::monostate>();
if (body_tracking and control.enabled[size_t(tid::generic_tracker)])
{
if (std::holds_alternative<std::monostate>(body_tracker))
body_tracker = xr::make_body_tracker(
instance,
system,
session,
application::get_generic_trackers(),
config.fb_lower_body,
config.fb_hip);
}
else
body_tracker.emplace<std::monostate>();
if (interaction_profile_changed)
if (auto htc = std::get_if<xr::htc_body_tracker>(&body_tracker))
htc->update_active();
XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000);
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
@@ -493,9 +469,9 @@ void scenes::stream::tracking()
(Δt == 0 or Δt >= prediction - 2 * period))
{
last_hand_sample = t0;
if (left_hand)
if (control.enabled[size_t(tid::left_hand)])
{
auto joints = locate_hands(*left_hand, world_space, t0 + Δt);
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt);
hands.emplace_back(
t0,
t0 + Δt,
@@ -503,9 +479,9 @@ void scenes::stream::tracking()
joints);
}
if (right_hand)
if (control.enabled[size_t(tid::right_hand)])
{
auto joints = locate_hands(*right_hand, world_space, t0 + Δt);
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt);
hands.emplace_back(
t0,
t0 + Δt,
@@ -522,33 +498,37 @@ void scenes::stream::tracking()
}
locate_spaces.resolve(session, t0 + Δt, packet.device_poses);
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & b) {
if (t0 >= last_body_sample + period and
(Δt == 0 or Δt >= prediction - 2 * period))
{
last_body_sample = t0;
if (control.enabled[size_t(tid::generic_tracker)])
if (body_tracking)
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & b) {
if (t0 >= last_body_sample + period and
(Δt == 0 or Δt >= prediction - 2 * period))
{
body.push_back(from_headset::body_tracking{
.production_timestamp = t0,
.timestamp = t0 + Δt,
.poses = b.locate_spaces(t0 + Δt, world_space),
});
last_body_sample = t0;
if (control.enabled[size_t(tid::generic_tracker)])
{
body.push_back(from_headset::body_tracking{
.production_timestamp = t0,
.timestamp = t0 + Δt,
.poses = b.locate_spaces(t0 + Δt, world_space),
});
}
}
}
},
},
body_tracker);
},
},
body_tracker);
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
},
},
face_tracker);
if (face_tracking && control.enabled[size_t(tid::face)])
{
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
ft.get_weights(t0 + Δt, packet.face.emplace<typename std::remove_reference_t<decltype(ft)>::packet_type>());
},
},
face_tracker);
}
}
catch (const std::system_error & e)
{
@@ -649,17 +629,20 @@ void scenes::stream::tracking()
exit();
}
}
if (auto * face_pico = std::get_if<xr::pico_face_tracker>(&face_tracker))
face_pico->stop();
}
void scenes::stream::operator()(to_headset::tracking_control && packet)
{
auto locked = tracking_control.lock();
std::lock_guard lock(tracking_control_mutex);
auto m = size_t(to_headset::tracking_control::id::microphone);
if (audio_handle)
audio_handle->set_mic_state(packet.enabled[m]);
*locked = packet;
locked->min_offset = std::min(locked->min_offset, locked->max_offset);
tracking_control = packet;
tracking_control.min_offset = std::min(tracking_control.min_offset, tracking_control.max_offset);
}
static device_id derived_from(device_id target)
@@ -680,7 +663,6 @@ static device_id derived_from(device_id target)
void scenes::stream::on_interaction_profile_changed(const XrEventDataInteractionProfileChanged &)
{
interaction_profile_changed = true;
std::array path = {
"/user/hand/left",
"/user/hand/right",
+48 -3
View File
@@ -1,4 +1,49 @@
/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#version 450
#extension GL_ARB_shading_language_include : require
#define VSR 0
#include "reprojection.glsl.inc"
#ifdef VERT_SHADER
layout (location = 0) in vec2 vPosition;
layout (location = 1) in vec2 vUV;
layout(location = 0) out vec2 outUV;
void main()
{
gl_Position = vec4(vPosition, 0.0, 1.0);
outUV = vUV;
}
#endif
#ifdef FRAG_SHADER
layout(set = 0, binding = 0) uniform sampler2D texSampler;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = texture(texSampler, inUV).rgba;
}
#endif
-5
View File
@@ -1,5 +0,0 @@
#version 450
#extension GL_ARB_shading_language_include : require
#define VSR 1
#include "reprojection.glsl.inc"
+3 -11
View File
@@ -26,17 +26,9 @@ namespace utils
template <typename Rng, typename T>
bool contains(Rng && range, const T & value)
{
if constexpr (std::is_convertible_v<T, const char *> and
std::is_convertible_v<typename std::decay_t<Rng>::value_type, const char *>)
{
auto it = std::find_if(range.begin(), range.end(), [&](const char * i) { return strcmp(i, value) == 0; });
return it != range.end();
}
else
{
auto it = std::find(range.begin(), range.end(), value);
return it != range.end();
}
auto it = std::find(range.begin(), range.end(), value);
return it != range.end();
}
// Check if all values of range2 are in range1
+5 -49
View File
@@ -19,81 +19,37 @@
#pragma once
#include <spdlog/spdlog.h>
#include <type_traits>
#include <utility>
#include <variant>
#include <openxr/openxr.h>
namespace utils
{
template <typename T, auto Deleter = nullptr>
template <typename T, XrResult deleter(T)>
class handle
{
public:
// true if the deleter is provided when constructing the object
// typically if it's from an OpenXR extension
static constexpr bool runtime_deleter = Deleter == nullptr;
protected:
static const inline T null_value = 0;
T id = null_value;
[[no_unique_address]] std::conditional_t<runtime_deleter, XrResult (*)(T), std::monostate> deleter;
public:
template <typename = void>
requires(not runtime_deleter)
handle()
{}
template <typename = void>
requires(not runtime_deleter)
handle() {}
handle(T id) :
id(id)
{}
template <typename = void>
requires(runtime_deleter)
handle(XrResult (*deleter)(T)) :
deleter(deleter)
{
assert(deleter);
}
template <typename = void>
requires(runtime_deleter)
handle(T id, XrResult (*deleter)(T)) :
id(id), deleter(deleter)
{
assert(deleter);
}
id(id) {}
~handle()
{
if (id != null_value)
{
XrResult res = XR_SUCCESS;
if constexpr (runtime_deleter)
res = deleter(id);
else
res = Deleter(id);
if (not XR_SUCCEEDED(res))
spdlog::warn("Failed to destroy {}", typeid(T).name());
}
deleter(id);
}
handle(handle && other) noexcept :
id(other.id), deleter(other.deleter)
id(other.id)
{
other.id = null_value;
}
handle & operator=(handle && other) noexcept
{
if constexpr (runtime_deleter)
std::swap(deleter, other.deleter);
std::swap(id, other.id);
return *this;
}
-80
View File
@@ -1,80 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "body_tracker.h"
#include "xr/htc_exts.h"
#include "xr/instance.h"
#include "xr/system.h"
xr::body_tracker_type xr::body_tracker_supported(xr::instance & instance, xr::system & system)
{
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME))
{
auto fb_body_properties = system.fb_body_tracking_properties();
if (fb_body_properties.supportsBodyTracking)
return body_tracker_type::fb;
}
if (instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME) and
instance.has_extension(XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME))
return body_tracker_type::htc;
if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME))
{
auto bd_body_properties = system.bd_body_tracking_properties();
if (bd_body_properties.supportsBodyTracking)
return body_tracker_type::pico;
}
return xr::body_tracker_type::none;
}
xr::body_tracker xr::make_body_tracker(xr::instance & instance, xr::system & system, xr::session & session, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips)
{
if (instance.has_extension(XR_FB_BODY_TRACKING_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME) and
instance.has_extension(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME))
{
auto fb_body_properties = system.fb_body_tracking_properties();
if (fb_body_properties.supportsBodyTracking)
return xr::body_tracker(std::in_place_type_t<xr::fb_body_tracker>(),
instance,
session,
full_body,
hips);
}
if (not generic_trackers.empty())
return xr::body_tracker(std::in_place_type_t<xr::htc_body_tracker>(),
session,
generic_trackers);
if (instance.has_extension(XR_BD_BODY_TRACKING_EXTENSION_NAME))
{
auto bd_body_properties = system.bd_body_tracking_properties();
if (bd_body_properties.supportsBodyTracking)
return xr::body_tracker(std::in_place_type_t<xr::pico_body_tracker>(),
instance,
session);
}
return std::monostate();
}
-43
View File
@@ -1,43 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "fb_body_tracker.h"
#include "htc_body_tracker.h"
#include "pico_body_tracker.h"
#include "xr/system.h"
#include <utility>
#include <variant>
#include <vector>
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
using body_tracker = std::variant<std::monostate, xr::fb_body_tracker, xr::htc_body_tracker, xr::pico_body_tracker>;
body_tracker make_body_tracker(xr::instance &, xr::system &, xr::session &, std::vector<std::pair<XrPath, xr::space>> & generic_trackers, bool full_body, bool hips);
body_tracker_type body_tracker_supported(xr::instance &, xr::system &);
} // namespace xr
+1 -1
View File
@@ -17,8 +17,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "xr.h"
#include "xr/check.h"
#include "xr/to_string.h"
#include <system_error>
namespace
-94
View File
@@ -1,94 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "face_tracker.h"
#include "hardware.h"
#include "xr/instance.h"
#include "xr/system.h"
xr::face_tracker_type xr::face_tracker_supported(xr::instance & instance, xr::system & system)
{
if (instance.has_extension(XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
auto properties = system.fb_face_tracking2_properties();
if (properties.supportsVisualFaceTracking)
return xr::face_tracker_type::fb;
}
if (instance.has_extension(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
{
auto properties = system.htc_face_tracking_properties();
if (properties.supportEyeFacialTracking or properties.supportLipFacialTracking)
return xr::face_tracker_type::htc;
}
switch (guess_model())
{
case model::pico_4_pro:
case model::pico_4_enterprise:
// The extension used by Pico is not published
// it doesn't even need to be requested...
if (instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME) and
system.eye_gaze_interaction_properties().supportsEyeGazeInteraction)
return xr::face_tracker_type::pico;
break;
default:
break;
}
return xr::face_tracker_type::none;
}
xr::face_tracker xr::make_face_tracker(xr::instance & instance, xr::system & system, xr::session & session)
{
if (instance.has_extension(XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
auto properties = system.fb_face_tracking2_properties();
if (properties.supportsVisualFaceTracking)
return xr::face_tracker(std::in_place_type_t<xr::fb_face_tracker2>(), instance, session);
}
if (instance.has_extension(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
{
auto properties = system.htc_face_tracking_properties();
if (properties.supportEyeFacialTracking or properties.supportLipFacialTracking)
return xr::face_tracker(
std::in_place_type_t<xr::htc_face_tracker>(),
instance,
session,
properties.supportEyeFacialTracking,
properties.supportLipFacialTracking);
}
switch (guess_model())
{
case model::pico_4_pro:
case model::pico_4_enterprise:
// The extension used by Pico is not published
// it doesn't even need to be requested...
if (instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME) and
system.eye_gaze_interaction_properties().supportsEyeGazeInteraction)
return xr::face_tracker(std::in_place_type_t<xr::pico_face_tracker>(), instance, session);
break;
default:
break;
}
return std::monostate();
}
-40
View File
@@ -1,40 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "fb_face_tracker2.h"
#include "htc_face_tracker.h"
#include "pico_face_tracker.h"
#include "xr/system.h"
#include <variant>
namespace xr
{
class instance;
class session;
using face_tracker = std::variant<std::monostate, xr::fb_face_tracker2, xr::htc_face_tracker, xr::pico_face_tracker>;
face_tracker make_face_tracker(xr::instance &, xr::system &, xr::session &);
face_tracker_type face_tracker_supported(xr::instance &, xr::system &);
} // namespace xr
+42 -17
View File
@@ -17,11 +17,10 @@
*/
#include "fb_body_tracker.h"
#include "application.h"
#include "spdlog/spdlog.h"
#include "xr/instance.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/session.h"
#include "xr/to_string.h"
#include "xr/xr.h"
#include <ranges>
#include <openxr/openxr.h>
@@ -40,33 +39,59 @@ std::vector<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(boo
return {whitelisted_joints.begin(), whitelisted_joints.end()};
}
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool full_body, bool hip) :
handle(inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB")),
xrRequestBodyTrackingFidelityMETA(inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA")),
xrLocateBodyJointsFB(inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB")),
full_body(full_body),
hip(hip)
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
s(s)
{
auto xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
xrRequestBodyTrackingFidelityMETA = inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA");
xrLocateBodyJointsFB = inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB");
xrDestroyBodyTrackerFB = inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB");
}
xr::fb_body_tracker::~fb_body_tracker()
{
stop();
}
void xr::fb_body_tracker::start(bool full_body, bool hip)
{
assert(xrCreateBodyTrackerFB);
this->full_body = full_body;
this->hip = hip;
XrBodyTrackerCreateInfoFB create_info{
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB,
.bodyJointSet = full_body
? XR_BODY_JOINT_SET_FULL_BODY_META
: XR_BODY_JOINT_SET_DEFAULT_FB,
.next = nullptr,
};
create_info.bodyJointSet = full_body
? XR_BODY_JOINT_SET_FULL_BODY_META
: XR_BODY_JOINT_SET_DEFAULT_FB;
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &id));
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle));
// Enable IOBT.
CHECK_XR(xrRequestBodyTrackingFidelityMETA(id, XR_BODY_TRACKING_FIDELITY_HIGH_META));
CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META));
whitelisted_joints = get_whitelisted_joints(full_body, hip);
}
void xr::fb_body_tracker::stop()
{
full_body = false;
hip = false;
if (handle)
{
assert(xrDestroyBodyTrackerFB);
CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr)));
}
}
size_t xr::fb_body_tracker::count() const
{
const auto & config = application::get_config();
return get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
}
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::fb_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{
if (!id)
if (!handle)
return std::nullopt;
assert(xrLocateBodyJointsFB);
@@ -86,7 +111,7 @@ std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_h
.jointLocations = joints.data(),
};
if (auto res = xrLocateBodyJointsFB(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
return std::nullopt;
+13 -3
View File
@@ -20,7 +20,6 @@
#include "wivrn_packets.h"
#include "utils/handle.h"
#include "xr/meta_body_tracking_fidelity.h"
#include <array>
#include <optional>
@@ -31,10 +30,15 @@ namespace xr
class instance;
class session;
class fb_body_tracker : public utils::handle<XrBodyTrackerFB>
class fb_body_tracker
{
XrSession s;
XrBodyTrackerFB handle{};
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
bool full_body{};
bool hip{};
@@ -55,7 +59,13 @@ public:
};
static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(bool full_body, bool hip);
fb_body_tracker(instance & inst, session & s, bool full_body, bool hip);
fb_body_tracker() = default;
fb_body_tracker(instance & inst, session & s);
~fb_body_tracker();
void start(bool lower_body, bool hip);
void stop();
size_t count() const;
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
};
+9 -2
View File
@@ -23,11 +23,18 @@
#include <cstdint>
#include <openxr/openxr.h>
xr::fb_face_tracker2::fb_face_tracker2(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyFaceTracker2FB>("xrDestroyFaceTracker2FB"))
static PFN_xrDestroyFaceTracker2FB xrDestroyFaceTracker2FB{};
XrResult xr::destroy_fb_face_tracker2(XrFaceTracker2FB id)
{
return xrDestroyFaceTracker2FB(id);
}
xr::fb_face_tracker2::fb_face_tracker2(instance & inst, session & s)
{
auto xrCreateFaceTracker2FB = inst.get_proc<PFN_xrCreateFaceTracker2FB>("xrCreateFaceTracker2FB");
xrGetFaceExpressionWeights2FB = inst.get_proc<PFN_xrGetFaceExpressionWeights2FB>("xrGetFaceExpressionWeights2FB");
xrDestroyFaceTracker2FB = inst.get_proc<PFN_xrDestroyFaceTracker2FB>("xrDestroyFaceTracker2FB");
assert(xrCreateFaceTracker2FB);
XrFaceTrackingDataSource2FB data_sources[1];
+5 -1
View File
@@ -27,12 +27,16 @@ namespace xr
class instance;
class session;
class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB>
XrResult destroy_fb_face_tracker2(XrFaceTracker2FB);
class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB, destroy_fb_face_tracker2>
{
PFN_xrGetFaceExpressionWeights2FB xrGetFaceExpressionWeights2FB{};
PFN_xrDestroyFaceTracker2FB xrDestroyFaceTracker2FB{};
public:
using packet_type = wivrn::from_headset::tracking::fb_face2;
fb_face_tracker2() = default;
fb_face_tracker2(instance & inst, session & s);
void get_weights(XrTime time, packet_type & out_expressions);
+10 -3
View File
@@ -23,12 +23,19 @@
#include "xr/session.h"
#include <cassert>
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info) :
handle(inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT"))
static PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT{};
XrResult xr::destroy_hand_tracker(XrHandTrackerEXT id)
{
auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
return xrDestroyHandTrackerEXT(id);
}
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info)
{
static auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
assert(xrCreateHandTrackerEXT);
xrLocateHandJointsEXT = inst.get_proc<PFN_xrLocateHandJointsEXT>("xrLocateHandJointsEXT");
xrDestroyHandTrackerEXT = inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT");
CHECK_XR(xrCreateHandTrackerEXT(session, &info, &id));
}
+3 -1
View File
@@ -28,12 +28,14 @@ namespace xr
{
class instance;
class session;
XrResult destroy_hand_tracker(XrHandTrackerEXT);
class hand_tracker : public utils::handle<XrHandTrackerEXT>
class hand_tracker : public utils::handle<XrHandTrackerEXT, destroy_hand_tracker>
{
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{};
public:
hand_tracker() = default;
hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info);
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
+58 -27
View File
@@ -2,7 +2,6 @@
* WiVRn VR streaming
* Copyright (C) 2025 Awzri <awzri@awzricat.com>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,7 +19,8 @@
#include "htc_body_tracker.h"
#include "xr/details/enumerate.h"
#include "xr/session.h"
#include "xr/htc_exts.h"
#include "xr/xr.h"
#include <openxr/openxr.h>
// Note: This utilizes extensions not present in the OpenXR spec!
@@ -28,25 +28,11 @@
// https://hub.vive.com/apidoc/api/VIVE.OpenXR.Tracker.ViveXRTracker.html
// https://hub.vive.com/apidoc/api/VIVE.OpenXR.VivePathEnumerationHelper.xrEnumeratePathsForInteractionProfileHTCDelegate.html
xr::vive_xr_tracker::vive_xr_tracker(XrPath path, xr::space & space, XrSession session) :
path(path),
space(space)
xr::vive_xr_tracker::vive_xr_tracker(xr::space && space) :
space(std::move(space)) {}
void xr::vive_xr_tracker::set_active(bool active)
{
update_active(session);
}
void xr::vive_xr_tracker::update_active(XrSession session)
{
XrInputSourceLocalizedNameGetInfo get_info{
.type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO,
.next = nullptr,
.sourcePath = path,
.whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT,
};
auto role = xr::details::enumerate<char>(xrGetInputSourceLocalizedName, session, &get_info);
is_active = not role.contains("_");
is_active = active;
}
bool xr::vive_xr_tracker::get_active() const
{
@@ -90,18 +76,63 @@ static wivrn::from_headset::body_tracking::pose locate_space(XrSpace space, XrSp
return res;
}
xr::htc_body_tracker::htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers) :
std::vector<std::string> xr::htc_body_tracker::get_roles()
{
auto paths = get_paths();
std::vector<std::string> roles{};
roles.reserve(paths.size());
for (auto & path: paths)
{
XrInputSourceLocalizedNameGetInfo get_info{
.type = XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO,
.next = nullptr,
.sourcePath = path,
.whichComponents = XR_INPUT_SOURCE_LOCALIZED_NAME_USER_PATH_BIT,
};
roles.emplace_back(xr::details::enumerate<char>(xrGetInputSourceLocalizedName, s, &get_info));
}
return roles;
}
xr::htc_body_tracker::htc_body_tracker(instance & inst, session & s) :
inst(&inst),
s(s)
{
this->trackers.reserve(trackers.size());
for (auto & [path, space]: trackers)
this->trackers.emplace_back(path, space, s);
xrEnumeratePathsForInteractionProfileHTC = inst.get_proc<PFN_xrEnumeratePathsForInteractionProfileHTC>("xrEnumeratePathsForInteractionProfileHTC");
}
std::vector<XrPath> xr::htc_body_tracker::get_paths(XrPath user_path)
{
assert(xrEnumeratePathsForInteractionProfileHTC);
XrPath tracker_profile = inst->string_to_path("/interaction_profiles/htc/vive_xr_tracker");
XrPathsForInteractionProfileEnumerateInfoHTC profile_info{
.type = XR_TYPE_UNKNOWN,
.next = nullptr,
.interactionProfile = tracker_profile,
.userPath = user_path,
};
return xr::details::enumerate<XrPath>(xrEnumeratePathsForInteractionProfileHTC, *inst, profile_info);
}
void xr::htc_body_tracker::add(xr::space && space)
{
trackers.emplace_back(std::move(space));
}
size_t xr::htc_body_tracker::count() const
{
return trackers.size();
}
void xr::htc_body_tracker::update_active()
{
for (auto & tracker: trackers)
tracker.update_active(s);
auto roles = get_roles();
assert(roles.size() >= trackers.size());
for (int i = 0; i < trackers.size(); i++)
trackers[i].set_active(!roles[i].contains('_'));
}
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> xr::htc_body_tracker::locate_spaces(XrTime time, XrSpace reference)
@@ -110,7 +141,7 @@ std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_t
for (int i = 0; i < trackers.size(); i++)
{
auto & tracker = trackers[i];
auto & tracker = trackers.at(i);
wivrn::from_headset::body_tracking::pose pose{
.pose = {},
.flags = 0,
+16 -7
View File
@@ -2,7 +2,6 @@
* WiVRn VR streaming
* Copyright (C) 2025 Awzri <awzri@awzricat.com>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +20,9 @@
#pragma once
#include "wivrn_packets.h"
#include "xr/htc_exts.h"
#include "xr/space.h"
#include <string>
#include <vector>
#include <openxr/openxr.h>
@@ -33,24 +34,32 @@ class session;
class vive_xr_tracker
{
bool is_active = false;
XrPath path;
xr::space & space;
xr::space space;
public:
vive_xr_tracker(XrPath path, xr::space & s, XrSession session);
void update_active(XrSession session);
vive_xr_tracker(xr::space && s);
void set_active(bool active);
bool get_active() const;
XrSpace get_space() const;
};
class htc_body_tracker
{
instance * inst;
XrSession s;
std::vector<vive_xr_tracker> trackers;
public:
htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers);
PFN_xrEnumeratePathsForInteractionProfileHTC xrEnumeratePathsForInteractionProfileHTC{};
std::vector<std::string> get_roles();
public:
htc_body_tracker() = default;
htc_body_tracker(instance & inst, session & s);
std::vector<XrPath> get_paths(XrPath user_path = XR_NULL_PATH);
void add(xr::space && space);
size_t count() const;
void update_active();
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> locate_spaces(XrTime time, XrSpace reference);
};
+31 -21
View File
@@ -18,43 +18,53 @@
*/
#include "htc_face_tracker.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/session.h"
#include <openxr/openxr.h>
static XrFacialTrackerHTC make_tracker(xr::instance & inst, xr::session & s, XrFacialTrackingTypeHTC type)
xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) :
s(s)
{
if (!eye && !lip)
return;
xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
xrGetFacialExpressionsHTC = inst.get_proc<PFN_xrGetFacialExpressionsHTC>("xrGetFacialExpressionsHTC");
xrDestroyFacialTrackerHTC = inst.get_proc<PFN_xrDestroyFacialTrackerHTC>("xrDestroyFacialTrackerHTC");
XrFacialTrackerCreateInfoHTC create_info{
.type = XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC,
.facialTrackingType = type,
.next = nullptr,
};
auto xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
XrFacialTrackerHTC id;
CHECK_XR(xrCreateFacialTrackerHTC(s, &create_info, &id));
return id;
if (eye)
{
create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC;
xrCreateFacialTrackerHTC(s, &create_info, &this->eye);
}
if (lip)
{
create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC;
xrCreateFacialTrackerHTC(s, &create_info, &this->lip);
}
}
static XrFacialTrackerHTC get_eye_tracker(xr::instance & inst, xr::session & s)
xr::htc_face_tracker::~htc_face_tracker()
{
static XrFacialTrackerHTC res = make_tracker(inst, s, XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC);
return res;
}
static XrFacialTrackerHTC get_lip_tracker(xr::instance & inst, xr::session & s)
{
static XrFacialTrackerHTC res = make_tracker(inst, s, XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
return res;
}
if (!xrDestroyFacialTrackerHTC)
return;
xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) :
xrGetFacialExpressionsHTC(inst.get_proc<PFN_xrGetFacialExpressionsHTC>("xrGetFacialExpressionsHTC")),
eye(eye ? get_eye_tracker(inst, s) : XR_NULL_HANDLE),
lip(lip ? get_lip_tracker(inst, s) : XR_NULL_HANDLE)
{
if (eye)
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(eye, nullptr)));
if (lip)
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(lip, nullptr)));
}
void xr::htc_face_tracker::get_weights(XrTime time, packet_type & out_expressions)
{
assert(xrGetFacialExpressionsHTC);
if (!(eye || lip) || !xrGetFacialExpressionsHTC)
return;
XrFacialExpressionsHTC expressions{
.type = XR_TYPE_FACIAL_EXPRESSIONS_HTC,
+9 -3
View File
@@ -19,6 +19,7 @@
#pragma once
#include "utils/handle.h"
#include "wivrn_packets.h"
#include <openxr/openxr.h>
@@ -29,13 +30,18 @@ class session;
class htc_face_tracker
{
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC;
XrFacialTrackerHTC eye;
XrFacialTrackerHTC lip;
XrSession s;
XrFacialTrackerHTC eye{};
XrFacialTrackerHTC lip{};
PFN_xrCreateFacialTrackerHTC xrCreateFacialTrackerHTC{};
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC{};
PFN_xrDestroyFacialTrackerHTC xrDestroyFacialTrackerHTC{};
public:
using packet_type = wivrn::from_headset::tracking::htc_face;
htc_face_tracker() = default;
htc_face_tracker(instance & inst, session & s, bool eye, bool lip);
~htc_face_tracker();
void get_weights(XrTime time, packet_type & out_expressions);
};
+1 -16
View File
@@ -19,9 +19,8 @@
#include "instance.h"
#include "xr.h"
#include "xr/details/enumerate.h"
#include "xr/htc_exts.h"
#include "xr/to_string.h"
#include <algorithm>
#include <cassert>
#include <cstring>
@@ -213,20 +212,6 @@ XrPath xr::instance::string_to_path(const std::string & path)
return p;
}
std::vector<XrPath> xr::instance::enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path)
{
assert(has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME));
static auto xrEnumeratePathsForInteractionProfileHTC = get_proc<PFN_xrEnumeratePathsForInteractionProfileHTC>("xrEnumeratePathsForInteractionProfileHTC");
XrPathsForInteractionProfileEnumerateInfoHTC profile_info{
.type = XR_TYPE_UNKNOWN,
.next = nullptr,
.interactionProfile = interaction_profile,
.userPath = user_path,
};
return xr::details::enumerate<XrPath>(xrEnumeratePathsForInteractionProfileHTC, id, profile_info);
}
bool xr::instance::poll_event(xr::event & buffer)
{
buffer.header.type = XR_TYPE_EVENT_DATA_BUFFER;
-2
View File
@@ -90,8 +90,6 @@ public:
XrPath string_to_path(const std::string & path);
std::string path_to_string(XrPath path);
std::vector<XrPath> enumerate_paths_for_interaction_profile(XrPath interaction_profile, XrPath user_path = XR_NULL_PATH);
void suggest_bindings(const std::string & interaction_profile,
std::vector<XrActionSuggestedBinding> & bindings);
+24 -5
View File
@@ -23,9 +23,27 @@
#include "xr/check.h"
#include "xr/instance.h"
xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, const XrPassthroughLayerCreateInfoFB & info) :
handle(inst.get_proc<PFN_xrDestroyPassthroughLayerFB>("xrDestroyPassthroughLayerFB"))
static PFN_xrDestroyPassthroughLayerFB xrDestroyPassthroughLayerFB{};
static PFN_xrDestroyPassthroughFB xrDestroyPassthroughFB{};
static PFN_xrDestroyPassthroughHTC xrDestroyPassthroughHTC{};
XrResult xr::destroy_passthrough_layer_fb(XrPassthroughLayerFB id)
{
return xrDestroyPassthroughLayerFB(id);
}
XrResult xr::destroy_passthrough_fb(XrPassthroughFB id)
{
return xrDestroyPassthroughFB(id);
}
XrResult xr::destroy_passthrough_htc(XrPassthroughHTC id)
{
return xrDestroyPassthroughHTC(id);
}
xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, const XrPassthroughLayerCreateInfoFB & info)
{
xrDestroyPassthroughLayerFB = inst.get_proc<PFN_xrDestroyPassthroughLayerFB>("xrDestroyPassthroughLayerFB");
PFN_xrCreatePassthroughLayerFB xrCreatePassthroughLayerFB = inst.get_proc<PFN_xrCreatePassthroughLayerFB>("xrCreatePassthroughLayerFB");
CHECK_XR(xrCreatePassthroughLayerFB(s, &info, &id));
}
@@ -33,6 +51,7 @@ xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, con
static XrPassthroughFB create_passthrough_fb(xr::instance & inst, xr::session & s)
{
PFN_xrCreatePassthroughFB xrCreatePassthroughFB = inst.get_proc<PFN_xrCreatePassthroughFB>("xrCreatePassthroughFB");
xrDestroyPassthroughFB = inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB");
XrPassthroughFB id;
XrPassthroughCreateInfoFB info{
@@ -45,7 +64,7 @@ static XrPassthroughFB create_passthrough_fb(xr::instance & inst, xr::session &
}
xr::passthrough_fb::passthrough_fb(instance & inst, session & s) :
handle(create_passthrough_fb(inst, s), inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB")),
utils::handle<XrPassthroughFB, destroy_passthrough_fb>(create_passthrough_fb(inst, s)),
passthrough_layer(inst, s, XrPassthroughLayerCreateInfoFB{
.type = XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB,
.passthrough = id,
@@ -79,10 +98,10 @@ void xr::passthrough_fb::pause()
CHECK_XR(xrPassthroughPauseFB(id));
}
xr::passthrough_htc::passthrough_htc(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyPassthroughHTC>("xrDestroyPassthroughHTC"))
xr::passthrough_htc::passthrough_htc(instance & inst, session & s)
{
PFN_xrCreatePassthroughHTC xrCreatePassthroughHTC = inst.get_proc<PFN_xrCreatePassthroughHTC>("xrCreatePassthroughHTC");
xrDestroyPassthroughHTC = inst.get_proc<PFN_xrDestroyPassthroughHTC>("xrDestroyPassthroughHTC");
XrPassthroughCreateInfoHTC info{
.type = XR_TYPE_PASSTHROUGH_CREATE_INFO_HTC,
+7 -3
View File
@@ -28,13 +28,17 @@ namespace xr
class instance;
class session;
class passthrough_layer_fb : public utils::handle<XrPassthroughLayerFB>
XrResult destroy_passthrough_layer_fb(XrPassthroughLayerFB);
XrResult destroy_passthrough_fb(XrPassthroughFB);
XrResult destroy_passthrough_htc(XrPassthroughHTC);
class passthrough_layer_fb : public utils::handle<XrPassthroughLayerFB, destroy_passthrough_layer_fb>
{
public:
passthrough_layer_fb(instance &, session &, const XrPassthroughLayerCreateInfoFB &);
};
class passthrough_fb : public utils::handle<XrPassthroughFB>
class passthrough_fb : public utils::handle<XrPassthroughFB, destroy_passthrough_fb>
{
PFN_xrPassthroughStartFB xrPassthroughStartFB{};
PFN_xrPassthroughPauseFB xrPassthroughPauseFB{};
@@ -55,7 +59,7 @@ public:
}
};
class passthrough_htc : public utils::handle<XrPassthroughHTC>
class passthrough_htc : public utils::handle<XrPassthroughHTC, destroy_passthrough_htc>
{
XrCompositionLayerPassthroughHTC composition_layer;
+13 -5
View File
@@ -18,15 +18,19 @@
#include "pico_body_tracker.h"
#include "spdlog/spdlog.h"
#include "xr/instance.h"
#include "xr/session.h"
#include "xr/to_string.h"
#include "xr/xr.h"
#include <openxr/openxr.h>
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
handle(inst.get_proc<PFN_xrDestroyBodyTrackerBD>("xrDestroyBodyTrackerBD"))
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
{
return xrDestroyBodyTrackerBD(id);
}
xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s)
{
auto xrCreateBodyTrackerBD = inst.get_proc<PFN_xrCreateBodyTrackerBD>("xrCreateBodyTrackerBD");
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
@@ -41,6 +45,10 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
CHECK_XR(xrCreateBodyTrackerBD(s, &create_info, &id));
}
size_t xr::pico_body_tracker::count() const
{
return joint_whitelist.size();
}
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{
if (!xrLocateBodyJointsBD)
+5 -1
View File
@@ -30,7 +30,9 @@ namespace xr
class instance;
class session;
class pico_body_tracker : public utils::handle<XrBodyTrackerBD>
XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
class pico_body_tracker : public utils::handle<XrBodyTrackerBD, destroy_pico_body_tracker>
{
PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
@@ -46,8 +48,10 @@ public:
XR_BODY_JOINT_RIGHT_FOOT_BD,
};
pico_body_tracker() = default;
pico_body_tracker(instance & inst, session & s);
size_t count() const;
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
};
} // namespace xr
+124 -135
View File
@@ -18,163 +18,152 @@
*/
#include "pico_face_tracker.h"
#include "spdlog/common.h"
#include "spdlog/spdlog.h"
#include "wivrn_packets.h"
#include "xr/instance.h"
#include "xr/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include "xr/session.h"
#include "xr/to_string.h"
#include <mutex>
#include <cstring>
#include <stdexcept>
#include <openxr/openxr.h>
struct xr::pico_face_tracker::impl
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) :
s(s_)
{
const XrSession s;
const PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO;
const PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO;
xrStartEyeTrackingPICO = inst.get_proc<PFN_xrStartEyeTrackingPICO>("xrStartEyeTrackingPICO");
xrStopEyeTrackingPICO = inst.get_proc<PFN_xrStopEyeTrackingPICO>("xrStopEyeTrackingPICO");
xrSetTrackingModePICO = inst.get_proc<PFN_xrSetTrackingModePICO>("xrSetTrackingModePICO");
xrGetFaceTrackingDataPICO = inst.get_proc<PFN_xrGetFaceTrackingDataPICO>("xrGetFaceTrackingDataPICO");
}
xr::pico_face_tracker::~pico_face_tracker()
{
stop();
}
impl(instance & inst, session & s) :
s(s),
xrStopEyeTrackingPICO(inst.get_proc<PFN_xrStopEyeTrackingPICO>("xrStopEyeTrackingPICO")),
xrGetFaceTrackingDataPICO(inst.get_proc<PFN_xrGetFaceTrackingDataPICO>("xrGetFaceTrackingDataPICO"))
void xr::pico_face_tracker::start()
{
if (started)
throw std::invalid_argument("face tracking already started");
CHECK_XR(xrStartEyeTrackingPICO(s));
CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO));
started = true;
}
void xr::pico_face_tracker::stop()
{
if (!started)
return;
if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); !XR_SUCCEEDED(res))
spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res));
started = false;
}
void xr::pico_face_tracker::get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions)
{
out_expressions.is_valid = false;
out_expressions.is_eye_following_blendshapes_valid = false;
if (!started or !xrGetFaceTrackingDataPICO)
return;
XrFaceTrackingDataPICO face_tracking{.time = 0};
if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); !XR_SUCCEEDED(res))
{
auto xrStartEyeTrackingPICO = inst.get_proc<PFN_xrStartEyeTrackingPICO>("xrStartEyeTrackingPICO");
auto xrSetTrackingModePICO = inst.get_proc<PFN_xrSetTrackingModePICO>("xrSetTrackingModePICO");
CHECK_XR(xrStartEyeTrackingPICO(s));
CHECK_XR(xrSetTrackingModePICO(s, XR_TRACKING_MODE_FACE_BIT_PICO));
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res));
return;
}
~impl()
{
if (auto res = xrStopEyeTrackingPICO(s, XR_TRACKING_MODE_FACE_BIT_PICO); not XR_SUCCEEDED(res))
spdlog::warn("Failed to deactivate face tracking: {}", xr::to_string(res));
}
void get_weights(XrTime time, wivrn::from_headset::tracking::fb_face2 & out_expressions)
{
out_expressions.is_valid = false;
out_expressions.is_eye_following_blendshapes_valid = false;
XrFaceTrackingDataPICO face_tracking{.time = 0};
if (auto res = xrGetFaceTrackingDataPICO(s, time, XR_GET_FACE_DATA_DEFAULT_PICO, &face_tracking); !XR_SUCCEEDED(res))
{
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res));
return;
}
if (face_tracking.time == 0)
return;
if (face_tracking.time == 0)
return;
#define MAP_EXPRESSION(fb, pico) \
out_expressions.weights[fb] = face_tracking.blendShapeWeight[pico];
// Map the blendshapes.
out_expressions.weights.fill(0.f);
out_expressions.confidences.fill(1.f);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB, XR_BS_BROWDOWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB, XR_BS_BROWDOWN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_L_FB, XR_BS_CHEEKPUFF_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_R_FB, XR_BS_CHEEKPUFF_PICO);
// XR_FACE_EXPRESSION2_CHEEK_RAISER_L_FB
// XR_FACE_EXPRESSION2_CHEEK_RAISER_R_FB
// XR_FACE_EXPRESSION2_CHEEK_SUCK_L_FB
// XR_FACE_EXPRESSION2_CHEEK_SUCK_R_FB
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_B_FB, XR_BS_MOUTHSHRUGLOWER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB, XR_BS_MOUTHSHRUGUPPER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_L_FB, XR_BS_MOUTHDIMPLE_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_R_FB, XR_BS_MOUTHDIMPLE_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB, XR_BS_EYEBLINK_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB, XR_BS_EYEBLINK_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB, XR_BS_EYELOOKDOWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB, XR_BS_EYELOOKDOWN_R_PICO);
// Map the blendshapes.
out_expressions.weights.fill(0.f);
out_expressions.confidences.fill(1.f);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_L_FB, XR_BS_BROWDOWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_BROW_LOWERER_R_FB, XR_BS_BROWDOWN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_L_FB, XR_BS_CHEEKPUFF_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHEEK_PUFF_R_FB, XR_BS_CHEEKPUFF_PICO);
// XR_FACE_EXPRESSION2_CHEEK_RAISER_L_FB
// XR_FACE_EXPRESSION2_CHEEK_RAISER_R_FB
// XR_FACE_EXPRESSION2_CHEEK_SUCK_L_FB
// XR_FACE_EXPRESSION2_CHEEK_SUCK_R_FB
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_B_FB, XR_BS_MOUTHSHRUGLOWER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_CHIN_RAISER_T_FB, XR_BS_MOUTHSHRUGUPPER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_L_FB, XR_BS_MOUTHDIMPLE_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_DIMPLER_R_FB, XR_BS_MOUTHDIMPLE_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_L_FB, XR_BS_EYEBLINK_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_CLOSED_R_FB, XR_BS_EYEBLINK_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_L_FB, XR_BS_EYELOOKDOWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_DOWN_R_FB, XR_BS_EYELOOKDOWN_R_PICO);
// "out" is left for the left eye, right for the right eye
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKOUT_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKIN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_R_FB, XR_BS_EYELOOKIN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_R_FB, XR_BS_EYELOOKOUT_R_PICO);
// "out" is left for the left eye, right for the right eye
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_L_FB, XR_BS_EYELOOKOUT_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_L_FB, XR_BS_EYELOOKIN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_LEFT_R_FB, XR_BS_EYELOOKIN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_RIGHT_R_FB, XR_BS_EYELOOKOUT_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB, XR_BS_EYELOOKUP_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB, XR_BS_EYELOOKUP_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB, XR_BS_BROWINNERUP_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB, XR_BS_BROWINNERUP_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_DROP_FB, XR_BS_JAWOPEN_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_LEFT_FB, XR_BS_JAWLEFT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_RIGHT_FB, XR_BS_JAWRIGHT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_THRUST_FB, XR_BS_JAWFORWARD_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB, XR_BS_EYESQUINT_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB, XR_BS_EYESQUINT_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB, XR_BS_MOUTHFROWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB, XR_BS_MOUTHFROWN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB, XR_BS_MOUTHSMILE_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB, XR_BS_MOUTHSMILE_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LB_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LT_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RB_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RT_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_L_FB, XR_BS_MOUTHPRESS_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_R_FB, XR_BS_MOUTHPRESS_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_L_FB, XR_BS_MOUTHPUCKER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_R_FB, XR_BS_MOUTHPUCKER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB, XR_BS_MOUTHSTRETCH_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB, XR_BS_MOUTHSTRETCH_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LB_FB, XR_BS_MOUTHROLLLOWER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LT_FB, XR_BS_MOUTHROLLLOWER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RT_FB, XR_BS_MOUTHROLLUPPER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RB_FB, XR_BS_MOUTHROLLUPPER_PICO);
// XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB
// XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIPS_TOWARD_FB, XR_BS_MOUTHCLOSE_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_L_FB, XR_BS_MOUTHLOWERDOWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_R_FB, XR_BS_MOUTHLOWERDOWN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_LEFT_FB, XR_BS_MOUTHLEFT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_RIGHT_FB, XR_BS_MOUTHRIGHT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_L_FB, XR_BS_NOSESNEER_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_R_FB, XR_BS_NOSESNEER_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_L_FB, XR_BS_BROWOUTERUP_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_R_FB, XR_BS_BROWOUTERUP_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB, XR_BS_EYEWIDE_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB, XR_BS_EYEWIDE_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_L_FB, XR_BS_MOUTHUPPERUP_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_R_FB, XR_BS_MOUTHUPPERUP_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_TONGUE_OUT_FB, XR_BS_TONGUEOUT_PICO);
// XR_FACE_EXPRESSION2_TONGUE_TIP_INTERDENTAL_FB
// XR_FACE_EXPRESSION2_TONGUE_TIP_ALVEOLAR_FB
// XR_FACE_EXPRESSION2_TONGUE_FRONT_DORSAL_PALATE_FB
// XR_FACE_EXPRESSION2_TONGUE_MID_DORSAL_PALATE_FB
// XR_FACE_EXPRESSION2_TONGUE_BACK_DORSAL_VELAR_FB
// XR_FACE_EXPRESSION2_TONGUE_RETREAT_FB
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_L_FB, XR_BS_EYELOOKUP_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_EYES_LOOK_UP_R_FB, XR_BS_EYELOOKUP_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_L_FB, XR_BS_BROWINNERUP_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_INNER_BROW_RAISER_R_FB, XR_BS_BROWINNERUP_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_DROP_FB, XR_BS_JAWOPEN_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_LEFT_FB, XR_BS_JAWLEFT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_SIDEWAYS_RIGHT_FB, XR_BS_JAWRIGHT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_JAW_THRUST_FB, XR_BS_JAWFORWARD_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_L_FB, XR_BS_EYESQUINT_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LID_TIGHTENER_R_FB, XR_BS_EYESQUINT_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_L_FB, XR_BS_MOUTHFROWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_DEPRESSOR_R_FB, XR_BS_MOUTHFROWN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_L_FB, XR_BS_MOUTHSMILE_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_CORNER_PULLER_R_FB, XR_BS_MOUTHSMILE_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LB_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_LT_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RB_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_FUNNELER_RT_FB, XR_BS_MOUTHFUNNEL_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_L_FB, XR_BS_MOUTHPRESS_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PRESSOR_R_FB, XR_BS_MOUTHPRESS_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_L_FB, XR_BS_MOUTHPUCKER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_PUCKER_R_FB, XR_BS_MOUTHPUCKER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_L_FB, XR_BS_MOUTHSTRETCH_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_STRETCHER_R_FB, XR_BS_MOUTHSTRETCH_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LB_FB, XR_BS_MOUTHROLLLOWER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_LT_FB, XR_BS_MOUTHROLLLOWER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RT_FB, XR_BS_MOUTHROLLUPPER_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIP_SUCK_RB_FB, XR_BS_MOUTHROLLUPPER_PICO);
// XR_FACE_EXPRESSION2_LIP_TIGHTENER_L_FB
// XR_FACE_EXPRESSION2_LIP_TIGHTENER_R_FB
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LIPS_TOWARD_FB, XR_BS_MOUTHCLOSE_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_L_FB, XR_BS_MOUTHLOWERDOWN_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_LOWER_LIP_DEPRESSOR_R_FB, XR_BS_MOUTHLOWERDOWN_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_LEFT_FB, XR_BS_MOUTHLEFT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_MOUTH_RIGHT_FB, XR_BS_MOUTHRIGHT_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_L_FB, XR_BS_NOSESNEER_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_NOSE_WRINKLER_R_FB, XR_BS_NOSESNEER_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_L_FB, XR_BS_BROWOUTERUP_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_OUTER_BROW_RAISER_R_FB, XR_BS_BROWOUTERUP_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_L_FB, XR_BS_EYEWIDE_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LID_RAISER_R_FB, XR_BS_EYEWIDE_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_L_FB, XR_BS_MOUTHUPPERUP_L_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_UPPER_LIP_RAISER_R_FB, XR_BS_MOUTHUPPERUP_R_PICO);
MAP_EXPRESSION(XR_FACE_EXPRESSION2_TONGUE_OUT_FB, XR_BS_TONGUEOUT_PICO);
// XR_FACE_EXPRESSION2_TONGUE_TIP_INTERDENTAL_FB
// XR_FACE_EXPRESSION2_TONGUE_TIP_ALVEOLAR_FB
// XR_FACE_EXPRESSION2_TONGUE_FRONT_DORSAL_PALATE_FB
// XR_FACE_EXPRESSION2_TONGUE_MID_DORSAL_PALATE_FB
// XR_FACE_EXPRESSION2_TONGUE_BACK_DORSAL_VELAR_FB
// XR_FACE_EXPRESSION2_TONGUE_RETREAT_FB
#undef MAP_EXPRESSION
out_expressions.is_valid = true;
out_expressions.is_eye_following_blendshapes_valid = true;
}
};
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s)
{
// The API has a global start and stop method
// use a shared handle so we can have independent objects
// and start/stop accordingly
static std::mutex mutex;
std::unique_lock lock(mutex);
static std::weak_ptr<impl> instance;
if (auto shared = instance.lock())
{
i = std::move(shared);
return;
}
i = std::make_unique<impl>(inst, s);
instance = i;
}
void xr::pico_face_tracker::get_weights(XrTime time, packet_type & out_expressions)
{
return i->get_weights(time, out_expressions);
out_expressions.is_valid = true;
out_expressions.is_eye_following_blendshapes_valid = true;
}
+13 -2
View File
@@ -20,6 +20,8 @@
#pragma once
#include "wivrn_packets.h"
#include "xr/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include <openxr/openxr.h>
namespace xr
@@ -29,13 +31,22 @@ class session;
class pico_face_tracker
{
struct impl;
std::shared_ptr<impl> i;
PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{};
PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{};
PFN_xrSetTrackingModePICO xrSetTrackingModePICO{};
PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{};
XrSession s;
bool started{};
public:
using packet_type = wivrn::from_headset::tracking::fb_face2;
pico_face_tracker() = default;
pico_face_tracker(instance & inst, session & s);
~pico_face_tracker();
void start();
void stop();
void get_weights(XrTime time, packet_type & out_expressions);
};
} // namespace xr
+8 -9
View File
@@ -19,19 +19,18 @@
#include "session.h"
#include "application.h"
#include "details/enumerate.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "xr/instance.h"
#include "xr/system.h"
#include "xr/to_string.h"
#include <ranges>
#include <vulkan/vulkan.h>
#include <openxr/openxr_platform.h>
xr::session::session(xr::instance & inst, xr::system & sys, vk::raii::Instance & vk_inst, vk::raii::PhysicalDevice & pdev, vk::raii::Device & dev, thread_safe<vk::raii::Queue> & queue, int queue_family_index) :
inst(&inst),
queue(&queue)
xr::session::session(xr::instance & inst, xr::system & sys, vk::raii::Instance & vk_inst, vk::raii::PhysicalDevice & pdev, vk::raii::Device & dev, int queue_family_index) :
inst(&inst)
{
XrGraphicsBindingVulkan2KHR vulkan_binding{
.type = XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR,
@@ -128,7 +127,7 @@ void xr::session::begin_frame()
.type = XR_TYPE_FRAME_BEGIN_INFO,
};
auto lock = queue->lock();
auto lock = application::get_queue().lock();
CHECK_XR(xrBeginFrame(id, &begin_info));
}
@@ -142,7 +141,7 @@ void xr::session::end_frame(XrTime display_time, const std::vector<XrComposition
.layers = layers.data(),
};
auto lock = queue->lock();
auto lock = application::get_queue().lock();
CHECK_XR(xrEndFrame(id, &end_info));
}
@@ -345,14 +344,14 @@ void xr::session::enable_passthrough(xr::system & system)
if (not std::holds_alternative<std::monostate>(passthrough))
return;
if (system.passthrough_supported() == xr::passthrough_type::none)
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
return;
if (inst->has_extension(XR_FB_PASSTHROUGH_EXTENSION_NAME))
if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
passthrough.emplace<xr::passthrough_fb>(*inst, *this);
}
else if (inst->has_extension(XR_HTC_PASSTHROUGH_EXTENSION_NAME))
else if (utils::contains(application::get_xr_extensions(), XR_HTC_PASSTHROUGH_EXTENSION_NAME))
{
passthrough.emplace<xr::passthrough_htc>(*inst, *this);
}
+1 -3
View File
@@ -20,7 +20,6 @@
#pragma once
#include "utils/handle.h"
#include "utils/thread_safe.h"
#include <span>
#include <string>
#include <vector>
@@ -40,11 +39,10 @@ class session : public utils::handle<XrSession, xrDestroySession>
{
instance * inst = nullptr;
xr::passthrough passthrough;
thread_safe<vk::raii::Queue> * queue = nullptr;
public:
session() = default;
session(instance &, system &, vk::raii::Instance &, vk::raii::PhysicalDevice &, vk::raii::Device &, thread_safe<vk::raii::Queue> & queue, int queue_family_index);
session(instance &, system &, vk::raii::Instance &, vk::raii::PhysicalDevice &, vk::raii::Device &, int queue_family_index);
std::vector<XrReferenceSpaceType> get_reference_spaces() const;
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
+7 -28
View File
@@ -19,14 +19,12 @@
#include "system.h"
#include "body_tracker.h"
#include "application.h"
#include "details/enumerate.h"
#include "face_tracker.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "vk/check.h"
#include "xr/check.h"
#include "xr/instance.h"
#include <cassert>
#include <openxr/openxr_platform.h>
@@ -43,12 +41,6 @@ xr::system::system(xr::instance & inst, XrFormFactor formfactor)
CHECK_XR(xrGetSystem(inst, &system_info, &id));
assert(id != XR_NULL_SYSTEM_ID);
if (inst.has_extension(XR_EXT_HAND_TRACKING_EXTENSION_NAME))
hand_tracking_supported_ = hand_tracking_properties().supportsHandTracking;
body_tracker = xr::body_tracker_supported(inst, *this);
face_tracker = xr::face_tracker_supported(inst, *this);
}
XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const
@@ -203,15 +195,16 @@ XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
return body_tracking_prop;
}
xr::passthrough_type xr::system::passthrough_supported() const
xr::system::passthrough_type xr::system::passthrough_supported() const
{
if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
return passthrough_type::color;
if (inst->has_extension(XR_HTC_PASSTHROUGH_EXTENSION_NAME))
const std::vector<std::string> & xr_extensions = application::get_xr_extensions();
if (utils::contains(xr_extensions, XR_HTC_PASSTHROUGH_EXTENSION_NAME))
return passthrough_type::color;
if (inst->has_extension(XR_FB_PASSTHROUGH_EXTENSION_NAME))
if (utils::contains(xr_extensions, XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
XrSystemPassthroughProperties2FB passthrough_prop2{
.type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES2_FB,
@@ -231,7 +224,7 @@ xr::passthrough_type xr::system::passthrough_supported() const
if (passthrough_prop.supportsPassthrough)
{
if (!(passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_BIT_FB))
return passthrough_type::none;
return passthrough_type::no_passthrough;
if (passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_COLOR_BIT_FB)
return passthrough_type::color;
@@ -240,21 +233,7 @@ xr::passthrough_type xr::system::passthrough_supported() const
}
}
return passthrough_type::none;
}
xr::face_tracker_type xr::system::face_tracker_supported() const
{
return face_tracker;
}
xr::body_tracker_type xr::system::body_tracker_supported() const
{
return body_tracker;
}
bool xr::system::hand_tracking_supported() const
{
return hand_tracking_supported_;
return passthrough_type::no_passthrough;
}
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance & vulkan) const
+7 -31
View File
@@ -32,39 +32,19 @@ namespace xr
{
class instance;
enum class passthrough_type
{
none,
bw,
color
};
enum class body_tracker_type
{
none,
fb,
htc,
pico,
};
enum class face_tracker_type
{
none,
fb,
htc,
pico,
};
class system
{
instance * inst = nullptr;
XrSystemId id = XR_NULL_SYSTEM_ID;
bool hand_tracking_supported_ = false;
passthrough_type passthrough;
body_tracker_type body_tracker;
face_tracker_type face_tracker;
public:
enum class passthrough_type
{
no_passthrough,
bw,
color
};
system() = default;
system(const system &) = default;
system & operator=(const system &) = default;
@@ -87,11 +67,7 @@ public:
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
bool hand_tracking_supported() const;
passthrough_type passthrough_supported() const;
face_tracker_type face_tracker_supported() const;
body_tracker_type body_tracker_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
vk::raii::PhysicalDevice physical_device(vk::raii::Instance & vulkan) const;
@@ -17,40 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifdef VERT_SHADER
#pragma once
#if VSR
#extension GL_EXT_fragment_shading_rate: enable
#endif
layout (location = 0) in vec2 vPosition;
layout (location = 1) in vec2 vUV;
layout (location = 2) in int vShadingRate;
layout(location = 0) out vec2 outUV;
void main()
{
gl_Position = vec4(vPosition, 0.0, 1.0);
outUV = vUV;
#if VSR
gl_PrimitiveShadingRateEXT = vShadingRate;
#endif
}
#endif
#ifdef FRAG_SHADER
layout(set = 0, binding = 0) uniform sampler2D texSampler;
layout(location = 0) in vec2 inUV;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = texture(texSampler, inUV).rgba;
}
#endif
#include "actionset.h"
#include "error.h"
#include "instance.h"
#include "session.h"
#include "swapchain.h"
#include "system.h"
#include "xr/check.h"
#include "xr/to_string.h"