Rebase almost everything to Master
This commit is contained in:
+21
-14
@@ -13,7 +13,7 @@ if (WIVRN_USE_LIBKTX)
|
||||
FetchContent_MakeAvailable(libktx)
|
||||
endif()
|
||||
|
||||
if (NOT BOOST_FOUND)
|
||||
if (NOT WIVRN_USE_SYSTEM_BOOST)
|
||||
FetchContent_MakeAvailable(boost)
|
||||
endif()
|
||||
|
||||
@@ -51,7 +51,7 @@ if(ANDROID)
|
||||
else()
|
||||
add_executable(wivrn)
|
||||
|
||||
if (OpenXR_FOUND)
|
||||
if (WIVRN_USE_SYSTEM_OPENXR)
|
||||
target_link_libraries(wivrn OpenXR::openxr_loader OpenXR::headers)
|
||||
else()
|
||||
FetchContent_MakeAvailable(openxr_loader)
|
||||
@@ -91,7 +91,22 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
|
||||
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
|
||||
wivrn_compile_glsl(wivrn SHADERS ${VULKAN_SHADERS})
|
||||
|
||||
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::url Boost::locale)
|
||||
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
|
||||
)
|
||||
|
||||
if (WIVRN_USE_LIBKTX)
|
||||
target_link_libraries(wivrn ktx_read)
|
||||
@@ -107,10 +122,6 @@ if(NOT ANDROID)
|
||||
install(TARGETS wivrn)
|
||||
endif()
|
||||
|
||||
target_link_libraries(wivrn simdjson uni-algo wivrn-common wivrn-external)
|
||||
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Dear ImGui
|
||||
#
|
||||
@@ -140,10 +151,6 @@ target_link_libraries(wivrn-imgui FreetypeHarfbuzz)
|
||||
target_link_libraries(wivrn wivrn-imgui)
|
||||
|
||||
|
||||
##############################################################################
|
||||
# EnTT
|
||||
#
|
||||
target_link_libraries(wivrn EnTT::EnTT)
|
||||
|
||||
##############################################################################
|
||||
# Vulkan Validation Layer
|
||||
@@ -230,7 +237,7 @@ add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png
|
||||
DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS})
|
||||
|
||||
add_custom_target(assets ALL DEPENDS
|
||||
${ASSETS_DIR}/wivrn.png)
|
||||
${ASSETS_DIR}/wivrn.png)
|
||||
|
||||
add_dependencies(wivrn assets)
|
||||
|
||||
@@ -251,8 +258,8 @@ if(ANDROID)
|
||||
add_custom_target(assets-android ALL DEPENDS
|
||||
${ASSETS_DIR}/wivrn.ktx2
|
||||
${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
|
||||
${ASSETS_DIR}/vr_splash.png)
|
||||
|
||||
${ASSETS_DIR}/vr_splash.png
|
||||
)
|
||||
add_dependencies(assets-android assets)
|
||||
add_dependencies(wivrn assets-android)
|
||||
endif()
|
||||
|
||||
+131
-159
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
|
||||
#include "hardware.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "scene.h"
|
||||
@@ -26,18 +26,23 @@
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/files.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "vk/check.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/actionset.h"
|
||||
#include "xr/check.h"
|
||||
#include "xr/htc_exts.h"
|
||||
#include "xr/htc_face_tracker.h"
|
||||
#include "xr/meta_body_tracking_fidelity.h"
|
||||
#include "xr/xr.h"
|
||||
#include "xr/to_string.h"
|
||||
#include <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>
|
||||
@@ -67,7 +72,6 @@ struct interaction_profile
|
||||
std::string profile_name;
|
||||
std::vector<std::string> required_extensions;
|
||||
XrVersion min_version = XR_MAKE_VERSION(1, 0, 0);
|
||||
XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive
|
||||
std::vector<std::string> input_sources;
|
||||
bool available;
|
||||
};
|
||||
@@ -134,8 +138,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"},
|
||||
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.required_extensions = {XR_FB_TOUCH_CONTROLLER_PRO_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/left/output/haptic_trigger_fb",
|
||||
@@ -247,8 +250,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"},
|
||||
.max_version = XR_MAKE_VERSION(1, 1, 0),
|
||||
.required_extensions = {XR_META_TOUCH_CONTROLLER_PLUS_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -348,7 +350,7 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/bytedance/pico_neo3_controller",
|
||||
.required_extensions = {"XR_BD_controller_interaction"},
|
||||
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -391,7 +393,7 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/bytedance/pico4_controller",
|
||||
.required_extensions = {"XR_BD_controller_interaction"},
|
||||
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -434,7 +436,7 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/bytedance/pico4s_controller",
|
||||
.required_extensions = {"XR_BD_controller_interaction"},
|
||||
.required_extensions = {XR_BD_CONTROLLER_INTERACTION_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -477,7 +479,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"},
|
||||
.required_extensions = {XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/output/haptic",
|
||||
"/user/hand/right/output/haptic",
|
||||
@@ -519,7 +521,7 @@ static std::vector<interaction_profile> interaction_profiles{
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/ext/hand_interaction_ext",
|
||||
.required_extensions = {"XR_EXT_hand_interaction"},
|
||||
.required_extensions = {XR_EXT_HAND_INTERACTION_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/hand/left/input/aim/pose",
|
||||
"/user/hand/left/input/grip/pose",
|
||||
@@ -548,11 +550,14 @@ 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", "XR_HTC_path_enumeration"},
|
||||
.required_extensions = {
|
||||
XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME,
|
||||
XR_HTC_PATH_ENUMERATION_EXTENSION_NAME,
|
||||
},
|
||||
},
|
||||
interaction_profile{
|
||||
.profile_name = "/interaction_profiles/ext/eye_gaze_interaction",
|
||||
.required_extensions = {"XR_EXT_eye_gaze_interaction"},
|
||||
.required_extensions = {XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME},
|
||||
.input_sources = {
|
||||
"/user/eyes_ext/input/gaze_ext/pose",
|
||||
},
|
||||
@@ -649,6 +654,7 @@ VkBool32 application::vulkan_debug_report_callback(
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
bool my_error = true;
|
||||
if (level >= spdlog::level::warn)
|
||||
{
|
||||
bool validation_layer_found = false;
|
||||
@@ -659,10 +665,13 @@ VkBool32 application::vulkan_debug_report_callback(
|
||||
|
||||
if (validation_layer_found && i.library != "libVkLayer_khronos_validation.so")
|
||||
spdlog::log(level, "{:#016x}: {} + {:#x}", i.pc, i.library, i.pc - i.library_base);
|
||||
|
||||
if (i.library == "libopenxr_loader.so")
|
||||
my_error = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (level >= spdlog::level::err)
|
||||
if (level >= spdlog::level::err and my_error)
|
||||
abort();
|
||||
#endif
|
||||
|
||||
@@ -717,15 +726,13 @@ void application::initialize_vulkan()
|
||||
spdlog::info("Using Vulkan validation layer");
|
||||
layers.push_back("VK_LAYER_KHRONOS_validation");
|
||||
}
|
||||
bool debug_report_found = false;
|
||||
bool debug_utils_found = false;
|
||||
#endif
|
||||
|
||||
std::vector<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))
|
||||
@@ -734,28 +741,27 @@ void application::initialize_vulkan()
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME))
|
||||
{
|
||||
debug_report_found = true;
|
||||
instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
|
||||
if (!strcmp(i.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) and
|
||||
guess_model() != model::oculus_quest) // Quest 1 lies, the extension won't load
|
||||
{
|
||||
debug_utils_found = true;
|
||||
instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
std::ranges::sort(extensions);
|
||||
for (const auto & [extension_name, spec_version]: extensions)
|
||||
spdlog::info(" {} (version {})", extension_name, spec_version);
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (debug_utils_found && debug_report_found)
|
||||
{
|
||||
// debug_extensions_found = true;
|
||||
// spdlog::info("Using debug extensions");
|
||||
instance_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
// instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
|
||||
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);
|
||||
@@ -874,6 +880,7 @@ void application::initialize_vulkan()
|
||||
.ppEnabledExtensionNames = vk_device_extensions.data(),
|
||||
.pEnabledFeatures = &device_features,
|
||||
},
|
||||
vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{},
|
||||
#ifdef __ANDROID__
|
||||
vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{
|
||||
.samplerYcbcrConversion = VK_TRUE,
|
||||
@@ -881,6 +888,22 @@ 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);
|
||||
|
||||
@@ -902,10 +925,16 @@ 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,
|
||||
});
|
||||
.physicalDevice = *vk_physical_device,
|
||||
.device = *vk_device,
|
||||
.instance = *vk_instance,
|
||||
},
|
||||
#ifndef NDEBUG
|
||||
debug_utils_found
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
void application::log_views()
|
||||
@@ -952,8 +981,6 @@ 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");
|
||||
@@ -967,7 +994,8 @@ void application::initialize_actions()
|
||||
std::vector<std::string> sources;
|
||||
for (auto & profile: interaction_profiles)
|
||||
{
|
||||
profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
|
||||
profile.available = std::ranges::all_of(profile.required_extensions, [&](auto & ext) { return xr_instance.has_extension(ext); }) and
|
||||
profile.min_version <= api_version;
|
||||
|
||||
if (profile.profile_name.ends_with("khr/simple_controller"))
|
||||
{
|
||||
@@ -1008,15 +1036,15 @@ void application::initialize_actions()
|
||||
}
|
||||
if (add_palms)
|
||||
{
|
||||
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or xr_instance.has_extension(XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
|
||||
{
|
||||
spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name);
|
||||
profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
|
||||
profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
|
||||
}
|
||||
else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
|
||||
else if (xr_instance.has_extension(XR_EXT_PALM_POSE_EXTENSION_NAME) //
|
||||
and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
|
||||
and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
|
||||
{
|
||||
@@ -1027,14 +1055,15 @@ void application::initialize_actions()
|
||||
}
|
||||
|
||||
// Dynamically add VIVE XR Trackers to the profile if available
|
||||
if (htc_body && utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME))
|
||||
if (utils::contains(profile.required_extensions, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME) and
|
||||
xr_instance.has_extension(XR_HTC_PATH_ENUMERATION_EXTENSION_NAME))
|
||||
{
|
||||
for (const auto & user_path: htc_body->get_paths())
|
||||
XrPath tracker_profile = xr_instance.string_to_path("/interaction_profiles/htc/vive_xr_tracker");
|
||||
for (const auto & user_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile))
|
||||
{
|
||||
for (const auto & input_path: htc_body->get_paths(user_path))
|
||||
{
|
||||
profile.input_sources.push_back(path_to_string(user_path) + path_to_string(input_path));
|
||||
}
|
||||
generic_trackers.emplace_back(user_path, nullptr);
|
||||
for (const auto & input_path: xr_instance.enumerate_paths_for_interaction_profile(tracker_profile, user_path))
|
||||
profile.input_sources.push_back(xr_instance.path_to_string(user_path) + xr_instance.path_to_string(input_path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1082,8 +1111,14 @@ void application::initialize_actions()
|
||||
spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a);
|
||||
else if (name == "/user/eyes_ext/input/gaze_ext/pose")
|
||||
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
|
||||
else if (name.contains("/input/entity_htc/pose") && htc_body)
|
||||
htc_body->add(xr_session.create_action_space(a));
|
||||
else if (name.contains("/input/entity_htc/pose"))
|
||||
{
|
||||
for (auto & [path, action]: generic_trackers)
|
||||
{
|
||||
if (name.starts_with(xr_instance.path_to_string(path)))
|
||||
action = xr_session.create_action_space(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build an action set for each scene
|
||||
@@ -1120,7 +1155,7 @@ void application::initialize_actions()
|
||||
|
||||
xr_bindings.push_back(XrActionSuggestedBinding{
|
||||
.action = a,
|
||||
.binding = string_to_path(k.input_source)});
|
||||
.binding = xr_instance.string_to_path(k.input_source)});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1137,7 +1172,7 @@ void application::initialize_actions()
|
||||
|
||||
for (const auto & name: profile.input_sources)
|
||||
{
|
||||
xr_bindings.push_back({actions_by_name[name], string_to_path(name)});
|
||||
xr_bindings.push_back({actions_by_name[name], xr_instance.string_to_path(name)});
|
||||
}
|
||||
|
||||
try
|
||||
@@ -1157,7 +1192,7 @@ void application::initialize()
|
||||
{
|
||||
// LogLayersAndExtensions
|
||||
assert(!xr_instance);
|
||||
xr_extensions.clear();
|
||||
std::vector<std::string> xr_extensions;
|
||||
|
||||
// Required extensions
|
||||
xr_extensions.push_back(XR_KHR_CONVERT_TIMESPEC_TIME_EXTENSION_NAME);
|
||||
@@ -1230,21 +1265,16 @@ void application::initialize()
|
||||
spdlog::info(" Orientation tracking: {}", (bool)properties.trackingProperties.orientationTracking);
|
||||
spdlog::info(" Position tracking: {}", (bool)properties.trackingProperties.positionTracking);
|
||||
|
||||
if (utils::contains(xr_extensions, XR_EXT_HAND_TRACKING_EXTENSION_NAME))
|
||||
{
|
||||
XrSystemHandTrackingPropertiesEXT hand_tracking_properties = xr_system_id.hand_tracking_properties();
|
||||
spdlog::info(" Hand tracking support: {}", (bool)hand_tracking_properties.supportsHandTracking);
|
||||
hand_tracking_supported = hand_tracking_properties.supportsHandTracking;
|
||||
}
|
||||
spdlog::info(" Hand tracking support: {}", xr_system_id.hand_tracking_supported());
|
||||
|
||||
if (utils::contains(xr_extensions, XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))
|
||||
if (xr_instance.has_extension(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME))
|
||||
{
|
||||
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties();
|
||||
spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction);
|
||||
eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction;
|
||||
}
|
||||
|
||||
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
|
||||
if (xr_instance.has_extension(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
|
||||
{
|
||||
spdlog::info(" OpenXR post-processing extension support: true");
|
||||
openxr_post_processing_supported = true;
|
||||
@@ -1252,93 +1282,45 @@ void application::initialize()
|
||||
|
||||
switch (xr_system_id.passthrough_supported())
|
||||
{
|
||||
case xr::system::passthrough_type::no_passthrough:
|
||||
case xr::passthrough_type::none:
|
||||
spdlog::info(" Passthrough: not supported");
|
||||
break;
|
||||
case xr::system::passthrough_type::bw:
|
||||
case xr::passthrough_type::bw:
|
||||
spdlog::info(" Passthrough: black and white");
|
||||
break;
|
||||
case xr::system::passthrough_type::color:
|
||||
case xr::passthrough_type::color:
|
||||
spdlog::info(" Passthrough: color");
|
||||
break;
|
||||
}
|
||||
|
||||
spdlog::info(" Face tracker: {}", magic_enum::enum_name(xr_system_id.face_tracker_supported()));
|
||||
spdlog::info(" Body tracker: {}", magic_enum::enum_name(xr_system_id.body_tracker_supported()));
|
||||
|
||||
// Log view configurations and blend modes
|
||||
log_views();
|
||||
|
||||
initialize_vulkan();
|
||||
|
||||
xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue_family_index);
|
||||
|
||||
{
|
||||
auto spaces = xr_session.get_reference_spaces();
|
||||
spdlog::info("{} reference spaces", spaces.size());
|
||||
for (XrReferenceSpaceType i: spaces)
|
||||
spdlog::info(" {}", xr::to_string(i));
|
||||
}
|
||||
xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index);
|
||||
|
||||
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
|
||||
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
|
||||
|
||||
config.emplace(xr_system_id);
|
||||
|
||||
if (hand_tracking_supported)
|
||||
// HTC face tracker fails if created later
|
||||
// we can destroy it right away, it actually stores static handles
|
||||
if (xr_system_id.face_tracker_supported() == xr::face_tracker_type::htc)
|
||||
{
|
||||
left_hand = xr_session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
auto props = xr_system_id.htc_face_tracking_properties();
|
||||
xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking);
|
||||
}
|
||||
|
||||
if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME))
|
||||
{
|
||||
XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties();
|
||||
spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking);
|
||||
if (fb_face2_properties.supportsVisualFaceTracking)
|
||||
face_tracker.emplace<xr::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);
|
||||
auto spaces = xr_session.get_reference_spaces();
|
||||
spdlog::info("{} reference spaces", spaces.size());
|
||||
for (XrReferenceSpaceType i: spaces)
|
||||
spdlog::info(" {}", xr::to_string(i));
|
||||
}
|
||||
|
||||
vk::CommandPoolCreateInfo cmdpool_create_info;
|
||||
@@ -1348,50 +1330,47 @@ void application::initialize()
|
||||
vk_cmdpool = vk::raii::CommandPool{vk_device, cmdpool_create_info};
|
||||
|
||||
initialize_actions();
|
||||
load_locale();
|
||||
}
|
||||
|
||||
void application::load_locale()
|
||||
{
|
||||
gen.add_messages_domain("wivrn");
|
||||
std::locale loc = gen("");
|
||||
|
||||
messages_info.encoding = "UTF-8";
|
||||
if (config->locale.empty())
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
jni::klass java_util_Locale("java/util/Locale");
|
||||
auto default_locale = java_util_Locale.call<jni::object<"java/util/Locale">>("getDefault");
|
||||
jni::klass java_util_Locale("java/util/Locale");
|
||||
auto default_locale = java_util_Locale.call<jni::object<"java/util/Locale">>("getDefault");
|
||||
|
||||
// if (auto language = default_locale.call<jni::string>("toString"))
|
||||
if (auto language = default_locale.call<jni::string>("getLanguage"))
|
||||
messages_info.language = language;
|
||||
|
||||
if (auto country = default_locale.call<jni::string>("getCountry"))
|
||||
messages_info.country = country;
|
||||
|
||||
messages_info.encoding = "UTF-8";
|
||||
// if (auto language = default_locale.call<jni::string>("toString"))
|
||||
if (auto language = default_locale.call<jni::string>("getLanguage"))
|
||||
messages_info.language = language;
|
||||
|
||||
if (auto country = default_locale.call<jni::string>("getCountry"))
|
||||
messages_info.country = country;
|
||||
#else
|
||||
auto & facet = std::use_facet<boost::locale::info>(loc);
|
||||
messages_info.language = facet.language();
|
||||
messages_info.country = facet.country();
|
||||
messages_info.encoding = "UTF-8";
|
||||
auto & facet = std::use_facet<boost::locale::info>(loc);
|
||||
messages_info.language = facet.language();
|
||||
messages_info.country = facet.country();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
auto pos = config->locale.find("_");
|
||||
messages_info.language = config->locale.substr(0, pos);
|
||||
if (pos != std::string::npos)
|
||||
messages_info.country = config->locale.substr(pos + 1);
|
||||
}
|
||||
|
||||
spdlog::info("Current locale: language {}, country {}, encoding {}", messages_info.language, messages_info.country, messages_info.encoding);
|
||||
|
||||
messages_info.paths.push_back("locale");
|
||||
|
||||
messages_info.domains.push_back(boost::locale::gnu_gettext::messages_info::domain("wivrn"));
|
||||
messages_info.callback = [](const std::string & file_name, const std::string & encoding) {
|
||||
std::vector<char> buffer;
|
||||
try
|
||||
{
|
||||
asset file(file_name);
|
||||
buffer.resize(file.size());
|
||||
memcpy(buffer.data(), file.data(), file.size());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
return buffer;
|
||||
};
|
||||
|
||||
messages_info.callback = open_locale_file;
|
||||
loc = std::locale(loc, boost::locale::gnu_gettext::create_messages_facet<char>(messages_info));
|
||||
|
||||
std::locale::global(loc);
|
||||
@@ -1875,13 +1854,6 @@ 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: {
|
||||
|
||||
+13
-81
@@ -28,13 +28,11 @@
|
||||
#include "utils/thread_safe.h"
|
||||
#include "vk/vk_allocator.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/fb_face_tracker2.h"
|
||||
#include "xr/hand_tracker.h"
|
||||
#include "xr/htc_body_tracker.h"
|
||||
#include "xr/htc_face_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/pico_face_tracker.h"
|
||||
#include "xr/actionset.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/swapchain.h"
|
||||
#include "xr/system.h"
|
||||
#include <atomic>
|
||||
#include <boost/locale/generator.hpp>
|
||||
#include <boost/locale/gnu_gettext.hpp>
|
||||
@@ -125,12 +123,7 @@ class application : public singleton<application>
|
||||
xr::actionset xr_actionset;
|
||||
std::vector<std::tuple<XrAction, XrActionType, std::string>> actions;
|
||||
|
||||
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;
|
||||
std::vector<std::pair<XrPath, xr::space>> generic_trackers;
|
||||
|
||||
bool eye_gaze_supported = false;
|
||||
|
||||
@@ -140,7 +133,6 @@ 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;
|
||||
@@ -270,16 +262,6 @@ public:
|
||||
return std::make_pair(position, orientation);
|
||||
}
|
||||
|
||||
static XrPath string_to_path(const std::string & s)
|
||||
{
|
||||
return instance().xr_instance.string_to_path(s);
|
||||
}
|
||||
|
||||
static std::string path_to_string(XrPath p)
|
||||
{
|
||||
return instance().xr_instance.path_to_string(p);
|
||||
}
|
||||
|
||||
void run();
|
||||
|
||||
static void push_scene(std::shared_ptr<scene>);
|
||||
@@ -350,16 +332,6 @@ public:
|
||||
// #endif
|
||||
}
|
||||
|
||||
static XrTime now()
|
||||
{
|
||||
return instance().xr_instance.now();
|
||||
}
|
||||
|
||||
static uint32_t queue_family_index()
|
||||
{
|
||||
return instance().vk_queue_family_index;
|
||||
}
|
||||
|
||||
static thread_safe<vk::raii::Queue> & get_queue()
|
||||
{
|
||||
return instance().vk_queue;
|
||||
@@ -375,26 +347,21 @@ public:
|
||||
return intent;
|
||||
}
|
||||
|
||||
static vk::raii::PhysicalDevice & get_physical_device()
|
||||
{
|
||||
return instance().vk_physical_device;
|
||||
}
|
||||
|
||||
static const vk::PhysicalDeviceProperties & get_physical_device_properties()
|
||||
{
|
||||
return instance().physical_device_properties;
|
||||
}
|
||||
|
||||
static vk::raii::Device & get_device()
|
||||
{
|
||||
return instance().vk_device;
|
||||
}
|
||||
|
||||
static vk::raii::Instance & get_vulkan_instance()
|
||||
{
|
||||
return instance().vk_instance;
|
||||
}
|
||||
|
||||
static xr::system & get_system()
|
||||
{
|
||||
return instance().xr_system_id;
|
||||
}
|
||||
|
||||
static vk::raii::PipelineCache & get_pipeline_cache()
|
||||
{
|
||||
return instance().pipeline_cache;
|
||||
@@ -415,21 +382,6 @@ public:
|
||||
return instance().last_scene_cpu_time;
|
||||
}
|
||||
|
||||
static bool get_hand_tracking_supported()
|
||||
{
|
||||
return instance().hand_tracking_supported;
|
||||
}
|
||||
|
||||
static bool get_face_tracking_supported()
|
||||
{
|
||||
return !std::holds_alternative<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;
|
||||
@@ -440,29 +392,9 @@ public:
|
||||
return instance().openxr_post_processing_supported;
|
||||
}
|
||||
|
||||
static xr::hand_tracker & get_left_hand()
|
||||
static auto & get_generic_trackers()
|
||||
{
|
||||
return instance().left_hand;
|
||||
}
|
||||
|
||||
static xr::hand_tracker & get_right_hand()
|
||||
{
|
||||
return instance().right_hand;
|
||||
}
|
||||
|
||||
static auto & get_face_tracker()
|
||||
{
|
||||
return instance().face_tracker;
|
||||
}
|
||||
|
||||
static auto & get_body_tracker()
|
||||
{
|
||||
return instance().body_tracker;
|
||||
}
|
||||
|
||||
static const std::vector<std::string> & get_xr_extensions()
|
||||
{
|
||||
return instance().xr_extensions;
|
||||
return instance().generic_trackers;
|
||||
}
|
||||
|
||||
static const std::vector<const char *> & get_vk_device_extensions()
|
||||
|
||||
+18
-82
@@ -82,6 +82,8 @@ bool configuration::check_feature(feature f) const
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
|
||||
auto & system = application::get_system();
|
||||
|
||||
auto it = features.find(f);
|
||||
if (it == features.end())
|
||||
return false;
|
||||
@@ -94,7 +96,7 @@ bool configuration::check_feature(feature f) const
|
||||
case feature::microphone:
|
||||
break;
|
||||
case feature::hand_tracking:
|
||||
if (not application::get_hand_tracking_supported())
|
||||
if (not system.hand_tracking_supported())
|
||||
return false;
|
||||
break;
|
||||
case feature::eye_gaze:
|
||||
@@ -102,50 +104,12 @@ bool configuration::check_feature(feature f) const
|
||||
return false;
|
||||
break;
|
||||
case feature::face_tracking:
|
||||
switch (guess_model())
|
||||
{
|
||||
case model::htc_vive_focus_3:
|
||||
case model::htc_vive_focus_vision:
|
||||
case model::htc_vive_xr_elite:
|
||||
if (not std::holds_alternative<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;
|
||||
}
|
||||
if (system.face_tracker_supported() == xr::face_tracker_type::none)
|
||||
return false;
|
||||
break;
|
||||
case feature::body_tracking:
|
||||
switch (guess_model())
|
||||
{
|
||||
case model::meta_quest_3:
|
||||
case model::meta_quest_3s:
|
||||
if (not std::holds_alternative<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;
|
||||
}
|
||||
if (system.body_tracker_supported() == xr::body_tracker_type::none)
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -181,8 +145,8 @@ void configuration::set_feature(feature f, bool state)
|
||||
|
||||
configuration::configuration(xr::system & system)
|
||||
{
|
||||
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
|
||||
features[feature::hand_tracking] = application::get_hand_tracking_supported();
|
||||
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
|
||||
features[feature::hand_tracking] = system.hand_tracking_supported();
|
||||
try
|
||||
{
|
||||
simdjson::dom::parser parser;
|
||||
@@ -214,8 +178,8 @@ configuration::configuration(xr::system & system)
|
||||
if (auto val = root["resolution_scale"]; val.is_double())
|
||||
resolution_scale = val.get_double();
|
||||
|
||||
if (auto val = root["sgsr"]; val.is_object())
|
||||
parse_sgsr_options(val.get_object());
|
||||
if (auto val = root["enable_stream_gui"]; val.is_bool())
|
||||
enable_stream_gui = val.get_bool();
|
||||
|
||||
if (auto val = root["openxr_post_processing"]; val.is_object())
|
||||
parse_openxr_post_processing_options(val.get_object());
|
||||
@@ -240,7 +204,7 @@ configuration::configuration(xr::system & system)
|
||||
features[i] = val.get_bool();
|
||||
}
|
||||
|
||||
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
|
||||
if (system.passthrough_supported() == xr::passthrough_type::none)
|
||||
passthrough_enabled = false;
|
||||
|
||||
if (auto val = root["override_foveation_enable"]; val.is_bool())
|
||||
@@ -254,6 +218,9 @@ configuration::configuration(xr::system & system)
|
||||
|
||||
if (auto val = root["first_run"]; val.is_bool())
|
||||
first_run = val.get_bool();
|
||||
|
||||
if (auto val = root["locale"]; val.is_string())
|
||||
locale = val.get_string().value();
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
@@ -264,31 +231,11 @@ configuration::configuration(xr::system & system)
|
||||
preferred_refresh_rate.reset();
|
||||
minimum_refresh_rate.reset();
|
||||
resolution_scale = 1.4;
|
||||
sgsr = {};
|
||||
openxr_post_processing = {};
|
||||
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
|
||||
passthrough_enabled = system.passthrough_supported() == xr::passthrough_type::color;
|
||||
}
|
||||
}
|
||||
|
||||
void configuration::parse_sgsr_options(simdjson::simdjson_result<simdjson::dom::object> sgsr_root)
|
||||
{
|
||||
sgsr = {};
|
||||
if (auto val = sgsr_root["enabled"]; val.is_bool())
|
||||
sgsr.enabled = val.get_bool();
|
||||
|
||||
if (auto val = sgsr_root["upscaling_factor"]; val.is_double())
|
||||
sgsr.upscaling_factor = val.get_double();
|
||||
|
||||
if (auto val = sgsr_root["use_edge_direction"]; val.is_bool())
|
||||
sgsr.use_edge_direction = val.get_bool();
|
||||
|
||||
if (auto val = sgsr_root["edge_threshold"]; val.is_double())
|
||||
sgsr.edge_threshold = val.get_double();
|
||||
|
||||
if (auto val = sgsr_root["edge_sharpness"]; val.is_double())
|
||||
sgsr.edge_sharpness = val.get_double();
|
||||
}
|
||||
|
||||
void configuration::parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> openxr_post_processing_root)
|
||||
{
|
||||
openxr_post_processing = {};
|
||||
@@ -304,17 +251,6 @@ static std::ostream & operator<<(std::ostream & stream, feature f)
|
||||
return stream << "\"" << magic_enum::enum_name(f) << "\"";
|
||||
}
|
||||
|
||||
static std::ostream & write_sgsr(std::ofstream & stream, const configuration::sgsr_settings & sgsr)
|
||||
{
|
||||
stream << "{\"enabled\":" << std::boolalpha << sgsr.enabled;
|
||||
stream << ",\"upscaling_factor\":" << sgsr.upscaling_factor;
|
||||
stream << ",\"use_edge_direction\":" << std::boolalpha << sgsr.use_edge_direction;
|
||||
stream << ",\"edge_threshold\":" << sgsr.edge_threshold;
|
||||
stream << ",\"edge_sharpness\":" << sgsr.edge_sharpness;
|
||||
stream << "}";
|
||||
return stream;
|
||||
}
|
||||
|
||||
static std::ostream & write_openxr_post_processing(std::ofstream & stream, const configuration::openxr_post_processing_settings & openxr_post_processing)
|
||||
{
|
||||
stream << "{\"super_sampling\":" << openxr_post_processing.super_sampling;
|
||||
@@ -357,14 +293,13 @@ void configuration::save()
|
||||
if (minimum_refresh_rate)
|
||||
json << ",\"minimum_refresh_rate\":" << *minimum_refresh_rate;
|
||||
json << ",\"resolution_scale\":" << resolution_scale;
|
||||
json << ",\"sgsr\":";
|
||||
write_sgsr(json, sgsr);
|
||||
json << ",\"openxr_post_processing\":";
|
||||
write_openxr_post_processing(json, openxr_post_processing);
|
||||
json << ",\"passthrough_enabled\":" << std::boolalpha << passthrough_enabled;
|
||||
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);
|
||||
@@ -372,5 +307,6 @@ void configuration::save()
|
||||
json << ",\"override_foveation_pitch\":" << override_foveation_pitch;
|
||||
json << ",\"override_foveation_distance\":" << override_foveation_distance;
|
||||
json << ",\"first_run\":" << std::boolalpha << first_run;
|
||||
json << ",\"locale\":" << json_string(locale);
|
||||
json << "}";
|
||||
}
|
||||
|
||||
+3
-11
@@ -56,16 +56,7 @@ public:
|
||||
bool fb_lower_body = false;
|
||||
bool fb_hip = true;
|
||||
|
||||
// Snapdragon Game Super Resolution
|
||||
struct sgsr_settings
|
||||
{
|
||||
bool enabled = false;
|
||||
float upscaling_factor = 1.5;
|
||||
bool use_edge_direction = true;
|
||||
float edge_threshold = 4.0;
|
||||
float edge_sharpness = 2.0;
|
||||
};
|
||||
sgsr_settings sgsr{};
|
||||
bool enable_stream_gui = true;
|
||||
|
||||
// XR_FB_composition_layer_settings extension flags
|
||||
struct openxr_post_processing_settings
|
||||
@@ -83,6 +74,8 @@ public:
|
||||
|
||||
bool first_run = true;
|
||||
|
||||
std::string locale;
|
||||
|
||||
bool check_feature(feature f) const;
|
||||
void set_feature(feature f, bool state);
|
||||
|
||||
@@ -90,7 +83,6 @@ private:
|
||||
mutable std::mutex mutex;
|
||||
std::map<feature, bool> features;
|
||||
|
||||
void parse_sgsr_options(simdjson::simdjson_result<simdjson::dom::object> root);
|
||||
void parse_openxr_post_processing_options(simdjson::simdjson_result<simdjson::dom::object> root);
|
||||
|
||||
public:
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
|
||||
#include "shard_accumulator.h"
|
||||
#include "application.h"
|
||||
#include "scenes/stream.h"
|
||||
#include "scenes/stream.h" // IWYU pragma: keep
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "xr/instance.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
@@ -63,10 +63,10 @@ static bool is_complete(const shard_set & shards)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<uint16_t> shard_set::insert(data_shard && shard)
|
||||
std::optional<uint16_t> shard_set::insert(data_shard && shard, xr::instance & instance)
|
||||
{
|
||||
if (empty())
|
||||
feedback.received_first_packet = application::now();
|
||||
feedback.received_first_packet = instance.now();
|
||||
|
||||
auto idx = shard.shard_idx;
|
||||
if (idx >= data.size())
|
||||
@@ -121,12 +121,12 @@ void shard_accumulator::push_shard(video_stream_data_shard && shard)
|
||||
}
|
||||
else if (frame_diff == 0)
|
||||
{
|
||||
auto shard_idx = current.insert(std::move(shard));
|
||||
auto shard_idx = current.insert(std::move(shard), instance);
|
||||
try_submit_frame(shard_idx);
|
||||
}
|
||||
else if (frame_diff == 1)
|
||||
{
|
||||
next.insert(std::move(shard));
|
||||
next.insert(std::move(shard), instance);
|
||||
if (is_complete(next))
|
||||
{
|
||||
debug_why_not_sent(current);
|
||||
@@ -191,7 +191,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
|
||||
if (not frame_complete)
|
||||
return;
|
||||
|
||||
current.feedback.received_last_packet = application::now();
|
||||
current.feedback.received_last_packet = instance.now();
|
||||
current.feedback.sent_to_decoder = current.feedback.received_last_packet;
|
||||
data_shard::timing_info_t timing_info = data_shards.back()->timing_info.value_or(data_shard::timing_info_t{});
|
||||
current.feedback.encode_begin = timing_info.encode_begin;
|
||||
@@ -216,7 +216,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx)
|
||||
void shard_accumulator::send_feedback(wivrn::from_headset::feedback & feedback)
|
||||
{
|
||||
if (not feedback.received_last_packet)
|
||||
feedback.received_first_packet = application::now();
|
||||
feedback.received_first_packet = instance.now();
|
||||
auto scene = weak_scene.lock();
|
||||
if (scene)
|
||||
scene->send_feedback(feedback);
|
||||
|
||||
@@ -19,27 +19,30 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "decoder/android/android_decoder.h"
|
||||
using decoder_impl = ::wivrn::android::decoder;
|
||||
#else
|
||||
#include "decoder/ffmpeg/ffmpeg_decoder.h"
|
||||
using decoder_impl = ::wivrn::ffmpeg::decoder;
|
||||
#endif
|
||||
|
||||
#include "decoder.h"
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
}
|
||||
|
||||
namespace scenes
|
||||
{
|
||||
class stream;
|
||||
}
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
class shard_accumulator
|
||||
{
|
||||
std::shared_ptr<decoder_impl> decoder;
|
||||
std::shared_ptr<decoder> decoder_;
|
||||
|
||||
public:
|
||||
using data_shard = wivrn::to_headset::video_stream_data_shard;
|
||||
@@ -50,7 +53,7 @@ public:
|
||||
void reset(uint64_t frame_index);
|
||||
bool empty() const;
|
||||
|
||||
std::optional<uint16_t> insert(data_shard &&);
|
||||
std::optional<uint16_t> insert(data_shard &&, xr::instance & instance);
|
||||
|
||||
wivrn::from_headset::feedback feedback{};
|
||||
|
||||
@@ -70,19 +73,22 @@ 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,
|
||||
uint8_t stream_index) :
|
||||
decoder(std::make_shared<decoder_impl>(device, physical_device, description, fps, stream_index, scene, this)),
|
||||
decoder_(decoder::make(device, physical_device, description, fps, stream_index, scene, this)),
|
||||
current(stream_index),
|
||||
next(stream_index),
|
||||
weak_scene(scene)
|
||||
weak_scene(scene),
|
||||
instance(instance)
|
||||
{
|
||||
next.reset(1);
|
||||
}
|
||||
@@ -91,20 +97,20 @@ public:
|
||||
|
||||
auto & desc() const
|
||||
{
|
||||
return decoder->desc();
|
||||
return decoder_->description;
|
||||
}
|
||||
|
||||
vk::Sampler sampler()
|
||||
{
|
||||
return decoder->sampler();
|
||||
return decoder_->sampler();
|
||||
}
|
||||
|
||||
vk::Extent2D image_size()
|
||||
const vk::Extent2D extent()
|
||||
{
|
||||
return decoder->image_size();
|
||||
return decoder_->extent();
|
||||
}
|
||||
|
||||
using blit_handle = decoder_impl::blit_handle;
|
||||
using blit_handle = decoder::blit_handle;
|
||||
|
||||
private:
|
||||
void try_submit_frame(std::optional<uint16_t> shard_idx);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "application.h"
|
||||
#include "utils/alignment.h"
|
||||
#include "vk/allocation.h"
|
||||
#include <fastgltf/tools.hpp>
|
||||
@@ -115,10 +114,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
buffer_allocation copy_to_gpu()
|
||||
buffer_allocation copy_to_gpu(vk::raii::Device & device)
|
||||
{
|
||||
buffer_allocation gpu_buffer{
|
||||
application::get_device(),
|
||||
device,
|
||||
vk::BufferCreateInfo{
|
||||
.size = bytes.size(),
|
||||
.usage = usage},
|
||||
|
||||
@@ -345,9 +345,9 @@ imgui_context::imgui_context(
|
||||
|
||||
ImGui_ImplVulkan_InitInfo init_info = {
|
||||
.Instance = *application::get_vulkan_instance(),
|
||||
.PhysicalDevice = *application::get_physical_device(),
|
||||
.Device = *application::get_device(),
|
||||
.QueueFamily = application::queue_family_index(),
|
||||
.PhysicalDevice = *physical_device,
|
||||
.Device = *device,
|
||||
.QueueFamily = queue_family_index,
|
||||
.Queue = *queue.get_unsafe(),
|
||||
.RenderPass = *renderpass,
|
||||
.MinImageCount = 2,
|
||||
@@ -718,7 +718,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
ImPlot::SetCurrentContext(plot_context);
|
||||
|
||||
if (last_display_time)
|
||||
io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.0166f);
|
||||
io.DeltaTime = std::clamp((display_time - last_display_time) * 1e-9f, 0.001f, 0.0166f);
|
||||
last_display_time = display_time;
|
||||
|
||||
// Uses the window list from last frame
|
||||
@@ -1099,6 +1099,13 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
auto buffer = std::make_shared<buffer_allocation>(staging_buffer.copy_to_gpu(device));
|
||||
|
||||
for (auto & i: materials)
|
||||
i->buffer = buffer;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#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>
|
||||
@@ -532,34 +533,11 @@ 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");
|
||||
|
||||
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,
|
||||
};
|
||||
auto specialization = make_specialization_constants(
|
||||
int32_t(info.nb_texcoords),
|
||||
VkBool32(info.dithering),
|
||||
VkBool32(info.alpha_cutout),
|
||||
VkBool32(info.skinning));
|
||||
|
||||
return vk::raii::Pipeline{
|
||||
device,
|
||||
@@ -570,14 +548,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,
|
||||
|
||||
},
|
||||
},
|
||||
@@ -794,7 +772,7 @@ void scene_renderer::update_material_descriptor_set(renderer::material & materia
|
||||
device.updateDescriptorSets(write_ds, {});
|
||||
}
|
||||
|
||||
static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0)
|
||||
[[maybe_unused]] static void print_scene_hierarchy(const entt::registry & scene, entt::entity root = entt::null, int level = 0)
|
||||
{
|
||||
if (level == 0)
|
||||
spdlog::info("Node hierarchy:");
|
||||
|
||||
@@ -139,46 +139,42 @@ text_rasterizer::text_rasterizer(vk::raii::Device & device, vk::raii::PhysicalDe
|
||||
|
||||
image_allocation text_rasterizer::create_image(vk::Extent2D size)
|
||||
{
|
||||
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;
|
||||
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"};
|
||||
}
|
||||
|
||||
buffer_allocation text_rasterizer::create_buffer(size_t size)
|
||||
{
|
||||
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;
|
||||
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"};
|
||||
}
|
||||
|
||||
text_rasterizer::~text_rasterizer()
|
||||
|
||||
+1
-3
@@ -51,8 +51,6 @@ 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:");
|
||||
|
||||
@@ -443,7 +441,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, application::queue_family_index(), renderer->get_default_material());
|
||||
scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
|
||||
loader.add_prefab(world, loader(path), entity);
|
||||
|
||||
|
||||
@@ -103,7 +103,6 @@ public:
|
||||
protected:
|
||||
vk::Format swapchain_format;
|
||||
vk::Format depth_format;
|
||||
xr::system::passthrough_type passthrough_supported;
|
||||
bool composition_layer_depth_test_supported;
|
||||
bool composition_layer_color_scale_bias_supported;
|
||||
|
||||
|
||||
+135
-119
@@ -383,9 +383,18 @@ void scenes::lobby::connect(const configuration::server_data & data)
|
||||
data.manual);
|
||||
}
|
||||
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(const std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & joints)
|
||||
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)
|
||||
{
|
||||
const auto & palm = joints[XR_HAND_JOINT_PALM_EXT].first;
|
||||
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 & o = palm.pose.orientation;
|
||||
const auto & p = palm.pose.position;
|
||||
glm::quat q{o.w, o.x, o.y, o.z};
|
||||
@@ -393,102 +402,130 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(const std::array<
|
||||
|
||||
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)
|
||||
{
|
||||
std::optional<std::pair<glm::vec3, glm::quat>> aim;
|
||||
glm::vec3 offset_position;
|
||||
glm::quat offset_orientation;
|
||||
xr::spaces controller;
|
||||
glm::vec3 recenter_position;
|
||||
float recenter_distance;
|
||||
|
||||
if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second)
|
||||
if (recentering_context)
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).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];
|
||||
}
|
||||
|
||||
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 (not gui_recenter_position or not gui_recenter_distance)
|
||||
controller = std::get<0>(*recentering_context);
|
||||
bool state;
|
||||
switch (controller)
|
||||
{
|
||||
// First frame where the recenter action is active
|
||||
imgui_context::controller_state state{
|
||||
.active = true,
|
||||
.aim_position = aim->first,
|
||||
.aim_orientation = aim->second,
|
||||
};
|
||||
case xr::spaces::aim_left:
|
||||
state = application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second;
|
||||
break;
|
||||
|
||||
imgui_ctx->compute_pointer_position(state);
|
||||
case xr::spaces::aim_right:
|
||||
state = application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second;
|
||||
break;
|
||||
|
||||
if (state.pointer_position) // TODO: check that the pointer is inside an imgui window
|
||||
{
|
||||
auto M = glm::mat3_cast(imgui_ctx->layers()[0].orientation);
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Pointer position in world
|
||||
glm::vec3 world_pointer_position = imgui_ctx->rw_from_vp(*state.pointer_position);
|
||||
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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// First frame of recentering
|
||||
imgui_context::controller_state state{
|
||||
.active = true,
|
||||
.aim_position = aim->first,
|
||||
.aim_orientation = aim->second,
|
||||
};
|
||||
|
||||
imgui_ctx->compute_pointer_position(state);
|
||||
|
||||
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
|
||||
recenter_position = glm::transpose(M) * (world_pointer_position - imgui_ctx->layers()[0].position);
|
||||
recenter_distance = glm::length(state.aim_position - world_pointer_position);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
recentering_context.emplace(controller, recenter_position, recenter_distance);
|
||||
return std::nullopt;
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_recenter_position.reset();
|
||||
}
|
||||
// Subsequent frames: find the GUI position that gives the correct world pointer position
|
||||
std::tie(controller, recenter_position, recenter_distance) = *recentering_context;
|
||||
|
||||
return std::nullopt;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<glm::vec3> scenes::lobby::check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation)
|
||||
@@ -612,26 +649,24 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
if (!new_gui_position and head_position)
|
||||
new_gui_position = check_recenter_action(frame_state.predictedDisplayTime, head_position->first);
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
if (left_hand and right_hand)
|
||||
{
|
||||
auto left = application::get_left_hand().locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto right = application::get_right_hand().locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto left = left_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
auto right = right_hand->locate(world_space, frame_state.predictedDisplayTime);
|
||||
|
||||
hand_model::apply(world, left, right);
|
||||
|
||||
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 (!new_gui_position)
|
||||
new_gui_position = check_recenter_gesture(*right);
|
||||
}
|
||||
|
||||
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 (head_position && new_gui_position)
|
||||
@@ -763,7 +798,7 @@ void scenes::lobby::on_focused()
|
||||
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
|
||||
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
|
||||
|
||||
@@ -800,12 +835,6 @@ void scenes::lobby::on_focused()
|
||||
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
|
||||
#endif
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
{
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
|
||||
}
|
||||
|
||||
recenter_left_action = get_action("recenter_left").first;
|
||||
recenter_right_action = get_action("recenter_right").first;
|
||||
|
||||
@@ -827,21 +856,19 @@ void scenes::lobby::on_focused()
|
||||
.haptic_output = get_action("right_haptic").first,
|
||||
},
|
||||
};
|
||||
if (auto & hand = application::get_left_hand())
|
||||
|
||||
if (system.hand_tracking_supported())
|
||||
{
|
||||
imgui_inputs.push_back(
|
||||
{
|
||||
.hand = &hand,
|
||||
});
|
||||
}
|
||||
if (auto & hand = application::get_right_hand())
|
||||
{
|
||||
imgui_inputs.push_back(
|
||||
{
|
||||
.hand = &hand,
|
||||
});
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
|
||||
imgui_inputs.push_back({.hand = &*left_hand});
|
||||
imgui_inputs.push_back({.hand = &*right_hand});
|
||||
}
|
||||
|
||||
face_tracker = xr::make_face_tracker(instance, system, session);
|
||||
|
||||
// 0.4mm / pixel
|
||||
std::vector<imgui_context::viewport> vps{
|
||||
{
|
||||
@@ -882,21 +909,7 @@ void scenes::lobby::on_focused()
|
||||
|
||||
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 3000, 1300);
|
||||
|
||||
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps);
|
||||
|
||||
std::string image;
|
||||
/* Could be used for more patriotics logos
|
||||
|
||||
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
auto tm = std::localtime(&t);
|
||||
|
||||
switch (tm->tm_mon)
|
||||
{
|
||||
default:
|
||||
image = "wivrn";
|
||||
break;
|
||||
}
|
||||
*/
|
||||
image = "wivrn";
|
||||
try
|
||||
{
|
||||
@@ -942,6 +955,9 @@ void scenes::lobby::on_unfocused()
|
||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||
|
||||
input.reset();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
face_tracker.emplace<std::monostate>();
|
||||
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
|
||||
+14
-4
@@ -29,7 +29,9 @@
|
||||
#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>
|
||||
@@ -65,6 +67,11 @@ 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;
|
||||
|
||||
@@ -94,8 +101,10 @@ 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;
|
||||
// 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;
|
||||
bool recenter_gui = true;
|
||||
void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position);
|
||||
|
||||
@@ -120,6 +129,7 @@ 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;
|
||||
|
||||
@@ -136,7 +146,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();
|
||||
void gui_connected(XrTime predicted_display_time);
|
||||
void gui_server_list();
|
||||
void gui_new_server();
|
||||
void gui_settings();
|
||||
@@ -152,7 +162,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(const std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> & joints);
|
||||
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_action(XrTime predicted_display_time, glm::vec3 head_position);
|
||||
std::optional<glm::vec3> check_recenter_gui(glm::vec3 head_position, glm::quat head_orientation);
|
||||
|
||||
|
||||
+68
-34
@@ -35,11 +35,13 @@
|
||||
#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>
|
||||
@@ -246,6 +248,7 @@ 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;
|
||||
}
|
||||
@@ -376,7 +379,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_connected()
|
||||
void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
{
|
||||
if (not next_scene)
|
||||
{
|
||||
@@ -401,14 +404,17 @@ void scenes::lobby::gui_connected()
|
||||
|
||||
auto apps = next_scene->get_applications();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||
if (apps->applications.empty())
|
||||
if (apps->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::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 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::Indent(20);
|
||||
if (server_name.empty())
|
||||
@@ -427,7 +433,7 @@ void scenes::lobby::gui_connected()
|
||||
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
||||
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
for (const auto [index, app]: utils::enumerate(apps->applications))
|
||||
for (const auto [index, app]: utils::enumerate(*apps))
|
||||
{
|
||||
ImTextureID texture = [&]() -> ImTextureID {
|
||||
if (app.image.empty())
|
||||
@@ -458,8 +464,11 @@ void scenes::lobby::gui_connected()
|
||||
}();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, 0, {icon_width, 0}))
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
||||
{
|
||||
timestamp_start_application = predicted_display_time;
|
||||
next_scene->start_application(app.id);
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||
|
||||
@@ -471,7 +480,7 @@ void scenes::lobby::gui_connected()
|
||||
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->applications, app_id, &to_headset::application_list::application::id))
|
||||
if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id))
|
||||
to_be_removed.emplace_back(app_id, app_icon);
|
||||
}
|
||||
for (const auto & [app_id, app_icon]: to_be_removed)
|
||||
@@ -482,12 +491,26 @@ void scenes::lobby::gui_connected()
|
||||
|
||||
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::SetCursorPosX(ImGui::GetWindowSize().x - disconnect_size.x - 50);
|
||||
ImGui::SetCursorPosY(ImGui::GetWindowSize().y - disconnect_size.y - 50);
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 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));
|
||||
@@ -905,7 +928,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
{
|
||||
ImGui::BeginDisabled(not application::get_hand_tracking_supported());
|
||||
ImGui::BeginDisabled(not system.hand_tracking_supported());
|
||||
bool enabled = config.check_feature(feature::hand_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable hand tracking"), &enabled))
|
||||
{
|
||||
@@ -929,7 +952,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
{
|
||||
ImGui::BeginDisabled(not application::get_face_tracking_supported());
|
||||
ImGui::BeginDisabled(std::holds_alternative<std::monostate>(face_tracker));
|
||||
bool enabled = config.check_feature(feature::face_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
|
||||
{
|
||||
@@ -941,8 +964,9 @@ void scenes::lobby::gui_settings()
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
auto body_tracker = system.body_tracker_supported();
|
||||
{
|
||||
ImGui::BeginDisabled(not application::get_body_tracking_supported());
|
||||
ImGui::BeginDisabled(body_tracker == xr::body_tracker_type::none);
|
||||
bool enabled = config.check_feature(feature::body_tracking);
|
||||
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
|
||||
{
|
||||
@@ -957,19 +981,14 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::visit(utils::overloaded{
|
||||
[](auto &) {},
|
||||
[this](xr::fb_body_tracker &) {
|
||||
imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
|
||||
},
|
||||
},
|
||||
application::get_body_tracker());
|
||||
if (body_tracker == xr::body_tracker_type::fb)
|
||||
imgui_ctx->tooltip(_("Requires 'Hand and body tracking' to be enabled in the Quest movement tracking settings,\notherwise body data will be guessed from controller and headset positions"));
|
||||
}
|
||||
}
|
||||
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
if (std::holds_alternative<xr::fb_body_tracker>(application::get_body_tracker()))
|
||||
if (body_tracker == xr::body_tracker_type::fb)
|
||||
{
|
||||
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
|
||||
ImGui::Indent();
|
||||
@@ -995,7 +1014,7 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
|
||||
ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none);
|
||||
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
|
||||
{
|
||||
setup_passthrough();
|
||||
@@ -1006,6 +1025,13 @@ 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
|
||||
}
|
||||
|
||||
@@ -1237,12 +1263,12 @@ void scenes::lobby::gui_first_run()
|
||||
item{
|
||||
.f = feature::face_tracking,
|
||||
.text = _S("Enable face tracking?"),
|
||||
.supported = application::get_face_tracking_supported(),
|
||||
.supported = not std::holds_alternative<std::monostate>(face_tracker),
|
||||
},
|
||||
item{
|
||||
.f = feature::body_tracking,
|
||||
.text = _S("Enable body tracking?"),
|
||||
.supported = application::get_body_tracking_supported(),
|
||||
.supported = system.body_tracker_supported() != xr::body_tracker_type::none,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1572,11 +1598,22 @@ static auto face_weights()
|
||||
return res;
|
||||
}
|
||||
|
||||
static const char * get_face_icon(XrTime predicted_display_time)
|
||||
static const char * get_face_icon(XrTime predicted_display_time, xr::face_tracker & face_tracker)
|
||||
{
|
||||
static const auto w = face_weights();
|
||||
wivrn::from_headset::tracking::fb_face2 expression;
|
||||
std::get<xr::fb_face_tracker2>(application::get_face_tracker()).get_weights(predicted_display_time, expression);
|
||||
const char * result = nullptr;
|
||||
std::visit(utils::overloaded{
|
||||
[](std::monostate &) {},
|
||||
[&](xr::htc_face_tracker &) { result = ICON_FA_FACE_SMILE_WINK; },
|
||||
[&](auto & ft) {
|
||||
ft.get_weights(predicted_display_time, expression);
|
||||
},
|
||||
},
|
||||
face_tracker);
|
||||
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (not expression.is_valid)
|
||||
return ICON_FA_FACE_MEH;
|
||||
@@ -1619,7 +1656,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
.icon_disabled = ICON_FA_MICROPHONE_SLASH,
|
||||
});
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
if (system.hand_tracking_supported())
|
||||
{
|
||||
items.push_back({
|
||||
.f = feature::hand_tracking,
|
||||
@@ -1640,21 +1677,18 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
});
|
||||
}
|
||||
|
||||
if (application::get_face_tracking_supported())
|
||||
if (not std::holds_alternative<std::monostate>(face_tracker))
|
||||
{
|
||||
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 = icon_enabled,
|
||||
.icon_enabled = get_face_icon(predicted_display_time, face_tracker),
|
||||
.icon_disabled = ICON_FA_FACE_MEH_BLANK,
|
||||
});
|
||||
}
|
||||
|
||||
if (application::get_body_tracking_supported())
|
||||
if (system.body_tracker_supported() != xr::body_tracker_type::none)
|
||||
{
|
||||
items.push_back({
|
||||
.f = feature::body_tracking,
|
||||
@@ -1728,7 +1762,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
|
||||
if (*status.charge > 0.995)
|
||||
icon_nr = 5;
|
||||
else
|
||||
icon_nr = application::now() / 500'000'000 % 5;
|
||||
icon_nr = instance.now() / 500'000'000 % 5;
|
||||
}
|
||||
else
|
||||
icon_nr = std::round((*status.charge) * 4);
|
||||
@@ -1845,7 +1879,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();
|
||||
gui_connected(predicted_display_time);
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding, ImGuiStyleVar_FramePadding
|
||||
}
|
||||
@@ -1957,7 +1991,7 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
|
||||
if (not is_gui_visible(*imgui_ctx, predicted_display_time))
|
||||
{
|
||||
if (application::get_hand_tracking_supported())
|
||||
if (system.hand_tracking_supported())
|
||||
display_recentering_tip(*imgui_ctx, _("Press the grip button or put your palm up\nto move the main window"));
|
||||
else
|
||||
display_recentering_tip(*imgui_ctx, _("Press the grip button to move the main window"));
|
||||
|
||||
+95
-389
@@ -17,11 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "constants.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/body_tracker.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include "xr/fb_face_tracker2.h"
|
||||
#include "xr/htc_body_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/space.h"
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
@@ -40,8 +38,6 @@
|
||||
#include "utils/contains.h"
|
||||
#include "utils/named_thread.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
@@ -49,6 +45,11 @@
|
||||
#include <thread>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "wivrn_config.h"
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
#include "vk/renderdoc.h"
|
||||
#endif
|
||||
|
||||
using namespace wivrn;
|
||||
|
||||
// clang-format off
|
||||
@@ -151,7 +152,8 @@ static const std::array supported_depth_formats{
|
||||
};
|
||||
|
||||
scenes::stream::stream() :
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats)
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats),
|
||||
blitters{blitter(device, 0), blitter(device, 1)}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -189,7 +191,11 @@ 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{};
|
||||
from_headset::headset_info_packet info{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
};
|
||||
|
||||
auto view = self->system.view_configuration_views(self->viewconfig)[0];
|
||||
view = override_view(view, guess_model());
|
||||
@@ -251,46 +257,49 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
if (config.check_feature(feature::face_tracking))
|
||||
{
|
||||
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());
|
||||
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.num_generic_trackers = 0;
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
info.num_generic_trackers = std::visit(utils::overloaded{
|
||||
[&](std::monostate &) {
|
||||
return size_t(0);
|
||||
},
|
||||
[&](auto & b) {
|
||||
return b.count();
|
||||
},
|
||||
},
|
||||
application::get_body_tracker());
|
||||
switch (self->system.body_tracker_supported())
|
||||
{
|
||||
case xr::body_tracker_type::none:
|
||||
break;
|
||||
case xr::body_tracker_type::fb:
|
||||
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
|
||||
break;
|
||||
case xr::body_tracker_type::htc:
|
||||
info.num_generic_trackers = application::get_generic_trackers().size();
|
||||
break;
|
||||
case xr::body_tracker_type::pico:
|
||||
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
|
||||
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
|
||||
info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none;
|
||||
info.system_name = std::string(self->system.properties().systemName);
|
||||
|
||||
audio::get_audio_description(info);
|
||||
if (not(config.check_feature(feature::microphone)))
|
||||
info.microphone = {};
|
||||
|
||||
info.supported_codecs = decoder_impl::supported_codecs();
|
||||
info.supported_codecs = decoder::supported_codecs();
|
||||
return info;
|
||||
}());
|
||||
|
||||
@@ -311,15 +320,6 @@ 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;
|
||||
@@ -363,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 = application::string_to_path(path),
|
||||
.path = self->instance.string_to_path(path),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -394,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 = application::now();
|
||||
gui_status_last_change = instance.now();
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
// stream_view = override_view(views[0], guess_model());
|
||||
@@ -402,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, application::queue_family_index(), renderer->get_default_material());
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
@@ -470,8 +470,11 @@ void scenes::stream::on_focused()
|
||||
swapchain_imgui,
|
||||
std::vector{vp});
|
||||
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
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;
|
||||
}
|
||||
recenter_left = get_action("recenter_left").first;
|
||||
recenter_right = get_action("recenter_right").first;
|
||||
foveation_pitch = get_action("foveation_pitch").first;
|
||||
@@ -494,6 +497,8 @@ void scenes::stream::on_unfocused()
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
clear_swapchains();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
|
||||
imgui_ctx.reset();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
@@ -524,16 +529,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 = application::now();
|
||||
handle->feedback.received_from_decoder = instance.now();
|
||||
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
|
||||
}
|
||||
|
||||
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
|
||||
return i.alpha() or not i.frames().empty();
|
||||
return i.alpha() or not i.empty();
|
||||
}))
|
||||
{
|
||||
state_ = state::streaming;
|
||||
spdlog::info("Stream scene ready at t={}", application::now());
|
||||
spdlog::info("Stream scene ready at t={}", instance.now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,15 +553,14 @@ bool scenes::stream::accumulator_images::alpha() const
|
||||
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
|
||||
}
|
||||
|
||||
std::vector<uint64_t> scenes::stream::accumulator_images::frames() const
|
||||
bool scenes::stream::accumulator_images::empty() const
|
||||
{
|
||||
std::vector<uint64_t> result;
|
||||
for (const auto & frame: latest_frames)
|
||||
{
|
||||
if (frame)
|
||||
result.push_back(frame->feedback.frame_index);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
|
||||
@@ -766,138 +770,17 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
if (state_ == state::stalled)
|
||||
application::pop_scene();
|
||||
|
||||
assert(swapchain);
|
||||
for (auto & i: decoders)
|
||||
{
|
||||
if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline)
|
||||
{
|
||||
// Create blit pipeline
|
||||
// Create VkDescriptorSetLayout with an immutable sampler
|
||||
vk::DescriptorSetLayoutBinding sampler_layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = &sampler,
|
||||
};
|
||||
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,
|
||||
});
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info{
|
||||
.bindingCount = 1,
|
||||
.pBindings = &sampler_layout_binding,
|
||||
};
|
||||
|
||||
i.descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
|
||||
i.descriptor_set = device.allocateDescriptorSets(
|
||||
vk::DescriptorSetAllocateInfo{
|
||||
.descriptorPool = *blit_descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*i.descriptor_set_layout,
|
||||
})[0]
|
||||
.release();
|
||||
|
||||
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);
|
||||
|
||||
std::array specialization_constants_desc{
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(float),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(float),
|
||||
.size = sizeof(float),
|
||||
}};
|
||||
|
||||
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");
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*i.descriptor_set_layout,
|
||||
};
|
||||
|
||||
i.blit_pipeline_layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.Stages = {{
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &vert_specialization_info,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &frag_specialization_info,
|
||||
}},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
|
||||
// and scissors is still used, put a vector with one element
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
}},
|
||||
.MultisampleState = {{
|
||||
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
||||
}},
|
||||
.ColorBlendAttachments = {
|
||||
{.colorWriteMask = i.alpha() ? vk::ColorComponentFlagBits::eA
|
||||
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *i.blit_pipeline_layout,
|
||||
.renderPass = *blit_render_pass,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
i.blit_pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
}
|
||||
application::pop_scene();
|
||||
}
|
||||
|
||||
assert(swapchain);
|
||||
if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout)
|
||||
throw std::runtime_error("Vulkan fence timeout");
|
||||
|
||||
@@ -928,11 +811,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
std::array<int, view_count> image_indices;
|
||||
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_begin(*vk_instance);
|
||||
#endif
|
||||
command_buffer.reset();
|
||||
|
||||
vk::CommandBufferBeginInfo begin_info;
|
||||
begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
|
||||
command_buffer.begin(begin_info);
|
||||
command_buffer.begin(vk::CommandBufferBeginInfo{
|
||||
.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit,
|
||||
});
|
||||
|
||||
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
||||
|
||||
@@ -947,13 +832,12 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
std::array<wivrn::to_headset::foveation_parameter, 2> foveation{};
|
||||
bool use_alpha = false;
|
||||
|
||||
// Blit images from the decoders
|
||||
for (auto [i, blit_handle]: std::views::zip(decoders, current_blit_handles))
|
||||
for (auto & blit_handle: current_blit_handles)
|
||||
{
|
||||
if (not blit_handle or not *i.blit_pipeline)
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
|
||||
blit_handle->feedback.blitted = application::now();
|
||||
blit_handle->feedback.blitted = instance.now();
|
||||
if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000)
|
||||
state_ = stream::state::stalled;
|
||||
++blit_handle->feedback.times_displayed;
|
||||
@@ -964,27 +848,12 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
foveation = blit_handle->view_info.foveation;
|
||||
use_alpha = blit_handle->view_info.alpha;
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.imageView = *blit_handle->image_view,
|
||||
.imageLayout = vk::ImageLayout::eGeneral,
|
||||
};
|
||||
|
||||
vk::WriteDescriptorSet descriptor_write{
|
||||
.dstSet = i.descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(descriptor_write, {});
|
||||
if (*blit_handle->current_layout != vk::ImageLayout::eGeneral)
|
||||
if (blit_handle->current_layout == vk::ImageLayout::eUndefined)
|
||||
{
|
||||
vk::ImageMemoryBarrier barrier{
|
||||
.srcAccessMask = vk::AccessFlagBits::eNone,
|
||||
.dstAccessMask = vk::AccessFlagBits::eMemoryRead,
|
||||
.oldLayout = *blit_handle->current_layout,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eGeneral,
|
||||
.image = blit_handle->image,
|
||||
.subresourceRange = {
|
||||
@@ -995,72 +864,22 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
};
|
||||
|
||||
command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier);
|
||||
*blit_handle->current_layout = vk::ImageLayout::eGeneral;
|
||||
blit_handle->current_layout = vk::ImageLayout::eGeneral;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t x_offset = 0;
|
||||
for (auto & out: decoder_output)
|
||||
// Blit images from the decoders
|
||||
std::array<blitter::output, view_count> blitted;
|
||||
for (auto [i, b]: utils::enumerate(blitters))
|
||||
{
|
||||
command_buffer.beginRenderPass(
|
||||
{
|
||||
.renderPass = *blit_render_pass,
|
||||
.framebuffer = *out.frame_buffer,
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = decoder_out_size,
|
||||
},
|
||||
.clearValueCount = 0,
|
||||
},
|
||||
vk::SubpassContents::eInline);
|
||||
|
||||
for (const auto & decoder: decoders)
|
||||
b.begin(command_buffer);
|
||||
for (auto [j, blit_handle]: utils::enumerate(current_blit_handles))
|
||||
{
|
||||
if (not *decoder.blit_pipeline)
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
if (decoder.alpha() and not use_alpha)
|
||||
continue;
|
||||
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *decoder.blit_pipeline);
|
||||
|
||||
const auto & description = decoder.decoder->desc();
|
||||
int x0 = description.offset_x - x_offset;
|
||||
int y0 = description.offset_y;
|
||||
int x1 = x0 + description.width * description.subsampling;
|
||||
int y1 = y0 + description.height * description.subsampling;
|
||||
|
||||
vk::Viewport viewport{
|
||||
.x = (float)x0,
|
||||
.y = (float)y0,
|
||||
.width = float(description.width * description.subsampling),
|
||||
.height = float(description.height * description.subsampling),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
};
|
||||
|
||||
x0 = std::clamp<int>(x0, 0, decoder_out_size.width);
|
||||
x1 = std::clamp<int>(x1, 0, decoder_out_size.width);
|
||||
y0 = std::clamp<int>(y0, 0, decoder_out_size.height);
|
||||
y1 = std::clamp<int>(y1, 0, decoder_out_size.height);
|
||||
|
||||
vk::Rect2D scissor{
|
||||
.offset = {.x = x0, .y = y0},
|
||||
.extent = {.width = (uint32_t)(x1 - x0), .height = (uint32_t)(y1 - y0)},
|
||||
};
|
||||
|
||||
command_buffer.setViewport(0, viewport);
|
||||
command_buffer.setScissor(0, scissor);
|
||||
|
||||
command_buffer.bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
*decoder.blit_pipeline_layout,
|
||||
0,
|
||||
decoder.descriptor_set,
|
||||
nullptr);
|
||||
command_buffer.draw(3, 1, 0, 0);
|
||||
b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout);
|
||||
}
|
||||
command_buffer.endRenderPass();
|
||||
x_offset += decoder_out_size.width;
|
||||
blitted[i] = b.end(command_buffer);
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
@@ -1071,7 +890,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
int32_t max_height = 0;
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
{
|
||||
extents[i] = reprojector->defoveated_size(foveation[i]);
|
||||
extents[i] = defoveator->defoveated_size(foveation[i]);
|
||||
max_width = std::max(max_width, extents[i].width);
|
||||
max_height = std::max(max_height, extents[i].height);
|
||||
}
|
||||
@@ -1101,7 +920,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
// defoveate the image
|
||||
int image_index = swapchain.acquire();
|
||||
swapchain.wait();
|
||||
reprojector->reproject(command_buffer, foveation, image_index);
|
||||
defoveator->defoveate(command_buffer, foveation, blitted, image_index);
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
|
||||
@@ -1109,6 +928,9 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
vk::SubmitInfo submit_info;
|
||||
submit_info.setCommandBuffers(*command_buffer);
|
||||
queue.lock()->submit(submit_info, *fence);
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_end(*vk_instance);
|
||||
#endif
|
||||
swapchain.release();
|
||||
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view(view_count);
|
||||
@@ -1275,119 +1097,15 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
}
|
||||
|
||||
video_stream_description = description;
|
||||
|
||||
const uint32_t video_width = description.width / view_count;
|
||||
const uint32_t video_height = description.height;
|
||||
|
||||
// Create renderpass
|
||||
{
|
||||
vk::AttachmentDescription color_desc{
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::RenderPassCreateInfo renderpass_info{
|
||||
.flags = {},
|
||||
};
|
||||
renderpass_info.setAttachments(color_desc);
|
||||
renderpass_info.setSubpasses(subpass);
|
||||
|
||||
blit_render_pass = vk::raii::RenderPass(device, renderpass_info);
|
||||
}
|
||||
|
||||
// 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,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.extent = {video_width, video_height, 1},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = view_count,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
};
|
||||
|
||||
VmaAllocationCreateInfo alloc_info{
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
};
|
||||
|
||||
decoder_out_image = image_allocation{device, image_info, alloc_info};
|
||||
|
||||
vk::ImageViewCreateInfo image_view_info{
|
||||
.image = vk::Image{decoder_out_image},
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
auto & output = decoder_output[view];
|
||||
|
||||
image_view_info.subresourceRange.baseArrayLayer = view;
|
||||
output.image_view = vk::raii::ImageView(device, image_view_info);
|
||||
|
||||
output.frame_buffer = vk::raii::Framebuffer(
|
||||
device,
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *blit_render_pass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*output.image_view,
|
||||
.width = decoder_out_size.width,
|
||||
.height = decoder_out_size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
vk::DescriptorPoolSize pool_size{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = uint32_t(2 * description.items.size()),
|
||||
};
|
||||
blit_descriptor_pool = vk::raii::DescriptorPool(
|
||||
device,
|
||||
vk::DescriptorPoolCreateInfo{
|
||||
.maxSets = uint32_t(2 * description.items.size()),
|
||||
.poolSizeCount = 1,
|
||||
.pPoolSizes = &pool_size,
|
||||
});
|
||||
}
|
||||
for (auto & b: blitters)
|
||||
b.reset(description);
|
||||
|
||||
for (const auto & [stream_index, item]: utils::enumerate(description.items))
|
||||
{
|
||||
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, item, description.fps, shared_from_this(), stream_index),
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1400,15 +1118,6 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
const uint32_t video_width = video_stream_description->width / view_count;
|
||||
const uint32_t video_height = video_stream_description->height;
|
||||
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
{
|
||||
const float upscaling_factor = sgsr.upscaling_factor;
|
||||
spdlog::info("Using SGSR with an upscale factor of {}", upscaling_factor);
|
||||
swapchain_width *= upscaling_factor;
|
||||
swapchain_height *= upscaling_factor;
|
||||
}
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
|
||||
swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
@@ -1425,12 +1134,9 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
for (auto & image: swapchain.images())
|
||||
swapchain_images.push_back(image.image);
|
||||
|
||||
reprojector.emplace(
|
||||
defoveator.emplace(
|
||||
device,
|
||||
physical_device,
|
||||
decoder_out_image,
|
||||
vk::Extent2D{.width = video_width, .height = video_height},
|
||||
2,
|
||||
swapchain_images,
|
||||
extent,
|
||||
swapchain.format());
|
||||
|
||||
+19
-23
@@ -23,8 +23,9 @@
|
||||
#include "decoder/shard_accumulator.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include "scene.h"
|
||||
#include "scenes/blitter.h"
|
||||
#include "scenes/input_profile.h"
|
||||
#include "stream_reprojection.h"
|
||||
#include "stream_defoveator.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "wivrn_client.h"
|
||||
@@ -48,6 +49,13 @@ 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;
|
||||
|
||||
@@ -56,16 +64,12 @@ private:
|
||||
struct accumulator_images
|
||||
{
|
||||
std::unique_ptr<wivrn::shard_accumulator> decoder;
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::DescriptorSet descriptor_set = nullptr;
|
||||
vk::raii::PipelineLayout blit_pipeline_layout = nullptr;
|
||||
vk::raii::Pipeline blit_pipeline = nullptr;
|
||||
// latest frames from oldest to most recent
|
||||
// latest frames, rolling buffer
|
||||
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;
|
||||
std::vector<uint64_t> frames() const;
|
||||
bool empty() const;
|
||||
};
|
||||
|
||||
wifi_lock::wifi wifi;
|
||||
@@ -77,9 +81,9 @@ private:
|
||||
std::unique_ptr<wivrn_session> network_session;
|
||||
std::atomic<bool> exiting = false;
|
||||
std::thread network_thread;
|
||||
std::mutex tracking_control_mutex;
|
||||
to_headset::tracking_control tracking_control{};
|
||||
thread_safe<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;
|
||||
@@ -90,21 +94,10 @@ private:
|
||||
std::shared_mutex decoder_mutex;
|
||||
std::optional<to_headset::video_stream_description> video_stream_description;
|
||||
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
|
||||
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;
|
||||
std::array<blitter, view_count> blitters;
|
||||
|
||||
struct renderpass_output
|
||||
{
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
vk::raii::Framebuffer frame_buffer = nullptr;
|
||||
};
|
||||
std::array<renderpass_output, view_count> decoder_output;
|
||||
|
||||
std::optional<stream_reprojection> reprojector;
|
||||
std::optional<stream_defoveator> defoveator;
|
||||
|
||||
vk::raii::Fence fence = nullptr;
|
||||
vk::raii::CommandBuffer command_buffer = nullptr;
|
||||
@@ -125,6 +118,8 @@ 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;
|
||||
@@ -176,7 +171,7 @@ private:
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||
|
||||
// Last application list received from server
|
||||
thread_safe<to_headset::application_list> applications;
|
||||
thread_safe<std::vector<app>> applications;
|
||||
|
||||
stream();
|
||||
|
||||
@@ -202,6 +197,7 @@ 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);
|
||||
|
||||
+260
-250
@@ -17,13 +17,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stream_reprojection.h"
|
||||
#include "stream_defoveator.h"
|
||||
#include "application.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/ranges.h"
|
||||
#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>
|
||||
@@ -31,22 +32,21 @@
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
struct stream_reprojection::vertex
|
||||
struct stream_defoveator::vertex
|
||||
{
|
||||
// output image position
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates
|
||||
alignas(8) glm::vec2 uv;
|
||||
// input texture coordinates + shading rate in the first 4 bits of x
|
||||
alignas(8) glm::uvec2 uv;
|
||||
};
|
||||
|
||||
struct SgsrSpecializationConstants
|
||||
struct vert_pc
|
||||
{
|
||||
VkBool32 use_edge_direction;
|
||||
float edge_threshold;
|
||||
float edge_sharpness;
|
||||
glm::ivec4 rgb_rect;
|
||||
glm::ivec4 a_rect;
|
||||
};
|
||||
|
||||
void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
void stream_defoveator::ensure_vertices(size_t num_vertices)
|
||||
{
|
||||
vk::BufferCreateInfo create_info{
|
||||
.size = num_vertices * sizeof(vertex) * view_count,
|
||||
@@ -65,212 +65,81 @@ void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
vertices_size = num_vertices * sizeof(vertex);
|
||||
}
|
||||
|
||||
stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
|
||||
stream_defoveator::vertex * stream_defoveator::get_vertices(size_t view)
|
||||
{
|
||||
assert(buffer);
|
||||
return reinterpret_cast<vertex *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * vertices_size);
|
||||
}
|
||||
|
||||
stream_reprojection::stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
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(view_count),
|
||||
device(device),
|
||||
input_image(input_image_),
|
||||
input_extent(input_extent),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a)
|
||||
{
|
||||
vk::SamplerCreateInfo sampler_info{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.mipmapMode = vk::SamplerMipmapMode::eNearest,
|
||||
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
|
||||
.mipLodBias = 0.0f,
|
||||
.anisotropyEnable = VK_FALSE,
|
||||
.maxAnisotropy = 1,
|
||||
.compareEnable = VK_FALSE,
|
||||
.compareOp = vk::CompareOp::eNever,
|
||||
.minLod = 0.0f,
|
||||
.maxLod = 0.0f,
|
||||
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
|
||||
.unnormalizedCoordinates = VK_FALSE,
|
||||
};
|
||||
auto & target = a ? pipeline_a[view] : pipeline_rgb[view];
|
||||
if (*target.pipeline)
|
||||
return target;
|
||||
|
||||
if (utils::contains(application::get_vk_device_extensions(), VK_IMG_FILTER_CUBIC_EXTENSION_NAME))
|
||||
sampler_info.magFilter = vk::Filter::eCubicIMG;
|
||||
|
||||
sampler = vk::raii::Sampler(device, sampler_info);
|
||||
std::array samplers{rgb, a};
|
||||
int32_t alpha = a ? 1 : 0;
|
||||
|
||||
// Create VkDescriptorSetLayout
|
||||
vk::DescriptorSetLayoutBinding layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
};
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info;
|
||||
layout_info.setBindings(layout_binding);
|
||||
|
||||
descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
|
||||
|
||||
std::array pool_size{
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
std::array layout_binding{
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = uint32_t(alpha + 1),
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = samplers.data(),
|
||||
},
|
||||
};
|
||||
|
||||
vk::DescriptorPoolCreateInfo pool_info{
|
||||
.maxSets = view_count,
|
||||
.poolSizeCount = pool_size.size(),
|
||||
.pPoolSizes = pool_size.data(),
|
||||
target.descriptor_set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
|
||||
.bindingCount = layout_binding.size(),
|
||||
.pBindings = layout_binding.data(),
|
||||
});
|
||||
|
||||
target.ds = device.allocateDescriptorSets(vk::DescriptorSetAllocateInfo{
|
||||
.descriptorPool = *ds_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*target.descriptor_set_layout,
|
||||
})[0]
|
||||
.release();
|
||||
|
||||
// pipeline layout
|
||||
vk::PushConstantRange pc_range{
|
||||
.stageFlags = vk::ShaderStageFlagBits::eVertex,
|
||||
.size = sizeof(vert_pc),
|
||||
};
|
||||
|
||||
descriptor_pool = vk::raii::DescriptorPool(device, pool_info);
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*target.descriptor_set_layout,
|
||||
.pushConstantRangeCount = 1,
|
||||
.pPushConstantRanges = &pc_range,
|
||||
};
|
||||
|
||||
// Create image views and descriptor sets
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
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))
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = input_image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
.g = vk::ComponentSwizzle::eIdentity,
|
||||
.b = vk::ComponentSwizzle::eIdentity,
|
||||
.a = vk::ComponentSwizzle::eIdentity,
|
||||
},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = view,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
vk::ImageView input_image_view = *input_image_views.emplace_back(device, iv_info);
|
||||
|
||||
vk::DescriptorSetAllocateInfo ds_info{
|
||||
.descriptorPool = *descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*descriptor_set_layout,
|
||||
};
|
||||
|
||||
auto descriptor_set = descriptor_sets.emplace_back(device.allocateDescriptorSets(ds_info)[0].release());
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.sampler = *sampler,
|
||||
.imageView = input_image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
},
|
||||
{});
|
||||
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;
|
||||
}
|
||||
|
||||
// Create renderpass
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.initialLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
// Vertex shader
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
||||
|
||||
// Fragment shader
|
||||
std::string fragment_shader_name = "reprojection.frag";
|
||||
auto specialization = make_specialization_constants(
|
||||
int32_t(alpha),
|
||||
VkBool32(need_srgb_conversion(guess_model())));
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
|
||||
|
||||
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";
|
||||
|
||||
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;
|
||||
pipeline_layout_info.setSetLayouts(*descriptor_set_layout);
|
||||
|
||||
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
vk::pipeline_builder pipeline_info_builder{
|
||||
.flags = {},
|
||||
.Stages = {
|
||||
{
|
||||
@@ -282,7 +151,7 @@ stream_reprojection::stream_reprojection(
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &fragment_specialization_info,
|
||||
.pSpecializationInfo = specialization,
|
||||
},
|
||||
},
|
||||
.VertexBindingDescriptions = {
|
||||
@@ -302,25 +171,15 @@ stream_reprojection::stream_reprojection(
|
||||
{
|
||||
.location = 1,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.format = vk::Format::eR32G32Uint,
|
||||
.offset = offsetof(vertex, uv),
|
||||
},
|
||||
},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
.Viewports = {{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = (float)output_extent.width,
|
||||
.height = (float)output_extent.height,
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
}},
|
||||
.Scissors = {{
|
||||
.offset = {.x = 0, .y = 0},
|
||||
.extent = output_extent,
|
||||
}},
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
@@ -332,12 +191,109 @@ stream_reprojection::stream_reprojection(
|
||||
.ColorBlendAttachments = {{
|
||||
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
||||
}},
|
||||
.layout = *layout,
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *target.layout,
|
||||
.renderPass = *renderpass,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
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 << 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
target.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||
return target;
|
||||
}
|
||||
|
||||
stream_defoveator::stream_defoveator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format) :
|
||||
device(device),
|
||||
physical_device(physical_device),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
{
|
||||
// Create renderpass
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_ref,
|
||||
};
|
||||
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
vk::DescriptorPoolSize pool_size{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = view_count * 4,
|
||||
};
|
||||
|
||||
ds_pool = device.createDescriptorPool(vk::DescriptorPoolCreateInfo{
|
||||
.maxSets = view_count * 2,
|
||||
.poolSizeCount = 1,
|
||||
.pPoolSizes = &pool_size,
|
||||
});
|
||||
|
||||
// Create image views and framebuffers
|
||||
output_image_views.reserve(output_images.size() * view_count);
|
||||
@@ -390,9 +346,25 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
uint32_t stream_defoveator::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_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
int destination)
|
||||
{
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
@@ -401,6 +373,7 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
const auto out_size = defoveated_size(foveation[view]);
|
||||
auto vertices = get_vertices(view);
|
||||
const auto & [px, py] = foveation[view];
|
||||
assert(px.size() % 2 == 1);
|
||||
@@ -408,67 +381,64 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const int n_ratio_y = (py.size() - 1) / 2;
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
glm::vec2 in(0), out(0); // pixel coordinates
|
||||
glm::vec2 in_pixel_size(1. / input_extent.width,
|
||||
1. / input_extent.height);
|
||||
glm::vec2 out_pixel_size(2. / output_extent.width,
|
||||
2. / output_extent.height);
|
||||
command_buffer.setScissor(
|
||||
0,
|
||||
vk::Rect2D{
|
||||
.extent = {.width = uint32_t(out_size.width), .height = uint32_t(out_size.height)},
|
||||
});
|
||||
command_buffer.setViewport(
|
||||
0,
|
||||
vk::Viewport{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = float(out_size.width),
|
||||
.height = float(out_size.height),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
});
|
||||
|
||||
glm::uvec2 in(0);
|
||||
glm::vec2 out(-0.5 * out_size.width, -0.5 * out_size.height); // pixel coordinates
|
||||
glm::vec2 out_pixel_size(2. / out_size.width,
|
||||
2. / out_size.height);
|
||||
for (auto [iy, n_out_y]: utils::enumerate_range(py))
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
|
||||
in.x = 0;
|
||||
out.x = 0;
|
||||
out.x = -0.5 * out_size.width;
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in | rate,
|
||||
};
|
||||
*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,
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
}
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
in.y += n_out_y;
|
||||
out.y += n_out_y * ratio_y;
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
command_buffer.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eTopOfPipe,
|
||||
vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
vk::ImageMemoryBarrier{
|
||||
.srcAccessMask = {},
|
||||
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.image = output_images[destination],
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = view_count,
|
||||
},
|
||||
});
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
vk::RenderPassBeginInfo begin_info{
|
||||
@@ -480,9 +450,49 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
},
|
||||
};
|
||||
|
||||
const auto & input = inputs[view];
|
||||
auto & pipeline = ensure_pipeline(view, input.sampler_rgb, input.sampler_a);
|
||||
|
||||
std::array image_info{
|
||||
vk::DescriptorImageInfo{
|
||||
.sampler = input.sampler_rgb,
|
||||
.imageView = input.rgb,
|
||||
.imageLayout = input.layout_rgb,
|
||||
},
|
||||
vk::DescriptorImageInfo{
|
||||
.sampler = input.sampler_a,
|
||||
.imageView = input.a,
|
||||
.imageLayout = input.layout_a,
|
||||
},
|
||||
};
|
||||
|
||||
std::array descriptor_writes{
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = pipeline.ds,
|
||||
.dstBinding = 0,
|
||||
.descriptorCount = input.sampler_a ? 2u : 1u,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = image_info.data(),
|
||||
},
|
||||
};
|
||||
|
||||
vert_pc pc{
|
||||
.rgb_rect = glm::ivec4(input.rect_rgb.offset.x,
|
||||
input.rect_rgb.offset.y,
|
||||
input.rect_rgb.extent.width,
|
||||
input.rect_rgb.extent.height),
|
||||
.a_rect = glm::ivec4(input.rect_a.offset.x,
|
||||
input.rect_a.offset.y,
|
||||
input.rect_a.extent.width,
|
||||
input.rect_a.extent.height),
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(descriptor_writes, {});
|
||||
|
||||
command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline);
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[view], {});
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline.pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipeline.layout, 0, pipeline.ds, {});
|
||||
command_buffer.pushConstants<vert_pc>(*pipeline.layout, vk::ShaderStageFlagBits::eVertex, 0, pc);
|
||||
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
|
||||
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
@@ -502,7 +512,7 @@ static uint16_t count_pixels(const std::vector<uint16_t> & param)
|
||||
return res;
|
||||
}
|
||||
|
||||
XrExtent2Di stream_reprojection::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
XrExtent2Di stream_defoveator::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
{
|
||||
return {
|
||||
count_pixels(view.x),
|
||||
|
||||
@@ -19,34 +19,42 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "blitter.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
class stream_reprojection
|
||||
class stream_defoveator
|
||||
{
|
||||
struct vertex;
|
||||
const uint32_t view_count;
|
||||
static const uint32_t view_count = 2;
|
||||
// Vertex buffer
|
||||
buffer_allocation buffer;
|
||||
size_t vertices_size = 0;
|
||||
|
||||
vk::raii::Device & device;
|
||||
vk::raii::PhysicalDevice & physical_device;
|
||||
|
||||
// Graphic pipeline
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::raii::DescriptorPool descriptor_pool = nullptr;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::RenderPass renderpass = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
vk::raii::DescriptorPool ds_pool = nullptr;
|
||||
struct pipeline_t
|
||||
{
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::DescriptorSet ds;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
};
|
||||
pipeline_t pipeline_rgb[view_count];
|
||||
pipeline_t pipeline_a[view_count];
|
||||
|
||||
// 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;
|
||||
// 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
|
||||
uint32_t fragment_sizes[3][3] = {};
|
||||
|
||||
// Destination images
|
||||
std::vector<vk::Image> output_images;
|
||||
@@ -57,22 +65,23 @@ class stream_reprojection
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
uint32_t shading_rate(int pixels_x, int pixels_y);
|
||||
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
|
||||
|
||||
public:
|
||||
stream_reprojection(
|
||||
stream_defoveator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
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);
|
||||
|
||||
stream_reprojection(const stream_reprojection &) = delete;
|
||||
stream_defoveator(const stream_defoveator &) = delete;
|
||||
|
||||
void reproject(
|
||||
void defoveate(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
int destination);
|
||||
|
||||
XrExtent2Di defoveated_size(const wivrn::to_headset::foveation_parameter &) const;
|
||||
|
||||
@@ -389,8 +389,14 @@ void scenes::stream::gui_performance_metrics()
|
||||
|
||||
ImPlot::PopStyleColor(5);
|
||||
{
|
||||
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());
|
||||
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());
|
||||
|
||||
if (is_gui_interactable())
|
||||
ImGui::Text("%s", _S("Press the grip button to move the window"));
|
||||
@@ -417,7 +423,12 @@ 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.max_offset).count() * 1e-3f, "ms");
|
||||
f(_S("Motion to photon latency"),
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
tracking_control.lock()->max_offset)
|
||||
.count() *
|
||||
1e-3f,
|
||||
"ms");
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
@@ -615,6 +626,8 @@ 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;
|
||||
@@ -632,6 +645,19 @@ 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)
|
||||
{
|
||||
@@ -863,10 +889,10 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
bool hide_left_controller = false;
|
||||
bool hide_right_controller = false;
|
||||
|
||||
if (application::get_hand_tracking_supported())
|
||||
if (left_hand and right_hand)
|
||||
{
|
||||
auto left = application::get_left_hand().locate(world_space, predicted_display_time);
|
||||
auto right = application::get_right_hand().locate(world_space, predicted_display_time);
|
||||
auto left = left_hand->locate(world_space, predicted_display_time);
|
||||
auto right = 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;
|
||||
|
||||
@@ -111,8 +111,26 @@ 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 = std::move(apps);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void scenes::stream::start_application(std::string appid)
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
#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>
|
||||
@@ -377,7 +380,6 @@ 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;
|
||||
|
||||
@@ -385,31 +387,14 @@ 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);
|
||||
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();
|
||||
}
|
||||
xr::face_tracker face_tracker;
|
||||
|
||||
const bool body_tracking = config.check_feature(feature::body_tracking);
|
||||
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);
|
||||
}
|
||||
}
|
||||
xr::body_tracker body_tracker;
|
||||
|
||||
locate_spaces_functor locate_spaces{instance, world_space};
|
||||
|
||||
@@ -433,11 +418,50 @@ void scenes::stream::tracking()
|
||||
timer t(instance);
|
||||
int samples = 0;
|
||||
|
||||
to_headset::tracking_control control;
|
||||
auto control = *tracking_control.lock();
|
||||
bool interaction_profile_changed = this->interaction_profile_changed.exchange(false);
|
||||
|
||||
if (control.enabled[size_t(tid::left_hand)])
|
||||
{
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
control = tracking_control;
|
||||
if (not left_hand and system.hand_tracking_supported())
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
}
|
||||
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);
|
||||
@@ -469,9 +493,9 @@ void scenes::stream::tracking()
|
||||
(Δt == 0 or Δt >= prediction - 2 * period))
|
||||
{
|
||||
last_hand_sample = t0;
|
||||
if (control.enabled[size_t(tid::left_hand)])
|
||||
if (left_hand)
|
||||
{
|
||||
auto joints = locate_hands(application::get_left_hand(), world_space, t0 + Δt);
|
||||
auto joints = locate_hands(*left_hand, world_space, t0 + Δt);
|
||||
hands.emplace_back(
|
||||
t0,
|
||||
t0 + Δt,
|
||||
@@ -479,9 +503,9 @@ void scenes::stream::tracking()
|
||||
joints);
|
||||
}
|
||||
|
||||
if (control.enabled[size_t(tid::right_hand)])
|
||||
if (right_hand)
|
||||
{
|
||||
auto joints = locate_hands(application::get_right_hand(), world_space, t0 + Δt);
|
||||
auto joints = locate_hands(*right_hand, world_space, t0 + Δt);
|
||||
hands.emplace_back(
|
||||
t0,
|
||||
t0 + Δt,
|
||||
@@ -498,37 +522,33 @@ void scenes::stream::tracking()
|
||||
}
|
||||
locate_spaces.resolve(session, t0 + Δt, packet.device_poses);
|
||||
|
||||
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))
|
||||
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)])
|
||||
{
|
||||
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.push_back(from_headset::body_tracking{
|
||||
.production_timestamp = t0,
|
||||
.timestamp = t0 + Δt,
|
||||
.poses = b.locate_spaces(t0 + Δt, world_space),
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
body_tracker);
|
||||
}
|
||||
},
|
||||
},
|
||||
body_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);
|
||||
}
|
||||
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)
|
||||
{
|
||||
@@ -629,20 +649,17 @@ 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)
|
||||
{
|
||||
std::lock_guard lock(tracking_control_mutex);
|
||||
auto locked = tracking_control.lock();
|
||||
auto m = size_t(to_headset::tracking_control::id::microphone);
|
||||
if (audio_handle)
|
||||
audio_handle->set_mic_state(packet.enabled[m]);
|
||||
|
||||
tracking_control = packet;
|
||||
tracking_control.min_offset = std::min(tracking_control.min_offset, tracking_control.max_offset);
|
||||
*locked = packet;
|
||||
locked->min_offset = std::min(locked->min_offset, locked->max_offset);
|
||||
}
|
||||
|
||||
static device_id derived_from(device_id target)
|
||||
@@ -663,6 +680,7 @@ 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",
|
||||
|
||||
@@ -1,49 +1,4 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#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
|
||||
#extension GL_ARB_shading_language_include : require
|
||||
#define VSR 0
|
||||
#include "reprojection.glsl.inc"
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifdef VERT_SHADER
|
||||
|
||||
#if VSR
|
||||
#extension GL_EXT_fragment_shading_rate: enable
|
||||
#endif
|
||||
|
||||
|
||||
layout (location = 0) in vec2 vPosition;
|
||||
layout (location = 1) in uvec2 vUV;
|
||||
|
||||
layout(location = 0) out vec4 outUV;
|
||||
|
||||
layout(push_constant) uniform pc
|
||||
{
|
||||
ivec4 rgb_rect;
|
||||
ivec4 a_rect;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(vPosition, 0.0, 1.0);
|
||||
#if VSR
|
||||
gl_PrimitiveShadingRateEXT = int(bitfieldExtract(vUV.x, 28, 4));
|
||||
vec2 uv = bitfieldInsert(vUV, uvec2(0), 28, 4);
|
||||
#else
|
||||
vec2 uv = vUV;
|
||||
#endif
|
||||
outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw;
|
||||
outUV.zw = (uv + a_rect.xy) / a_rect.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
|
||||
layout(constant_id = 0) const int alpha = 1;
|
||||
layout(constant_id = 1) const bool do_srgb = false;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D rgb[alpha + 1];
|
||||
|
||||
layout(location = 0) in vec4 inUV;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
float sRGB_to_linear(float x)
|
||||
{
|
||||
if (x <= 0.04045)
|
||||
return x / 12.92;
|
||||
return pow((x + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
vec4 sRGB_to_linear_rgba(vec4 x)
|
||||
{
|
||||
return vec4(
|
||||
sRGB_to_linear(x.r),
|
||||
sRGB_to_linear(x.g),
|
||||
sRGB_to_linear(x.b),
|
||||
x.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (alpha == 1)
|
||||
outColor = vec4(texture(rgb[0], inUV.xy).rgb, texture(rgb[1], inUV.zw).r);
|
||||
else
|
||||
outColor = texture(rgb[0], inUV.xy).rgba;
|
||||
|
||||
if (do_srgb)
|
||||
{
|
||||
outColor = sRGB_to_linear_rgba(outColor);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
#version 450
|
||||
#extension GL_ARB_shading_language_include : require
|
||||
#define VSR 1
|
||||
#include "reprojection.glsl.inc"
|
||||
|
||||
+11
-3
@@ -26,9 +26,17 @@ namespace utils
|
||||
template <typename Rng, typename T>
|
||||
bool contains(Rng && range, const T & value)
|
||||
{
|
||||
auto it = std::find(range.begin(), range.end(), value);
|
||||
|
||||
return it != range.end();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all values of range2 are in range1
|
||||
|
||||
+49
-5
@@ -19,37 +19,81 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
template <typename T, XrResult deleter(T)>
|
||||
|
||||
template <typename T, auto Deleter = nullptr>
|
||||
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:
|
||||
handle() {}
|
||||
template <typename = void>
|
||||
requires(not runtime_deleter)
|
||||
handle()
|
||||
{}
|
||||
|
||||
template <typename = void>
|
||||
requires(not runtime_deleter)
|
||||
handle(T id) :
|
||||
id(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);
|
||||
}
|
||||
|
||||
~handle()
|
||||
{
|
||||
if (id != null_value)
|
||||
deleter(id);
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
handle(handle && other) noexcept :
|
||||
id(other.id)
|
||||
id(other.id), deleter(other.deleter)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -17,10 +17,11 @@
|
||||
*/
|
||||
|
||||
#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/xr.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/to_string.h"
|
||||
#include <ranges>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
@@ -39,59 +40,33 @@ 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) :
|
||||
s(s)
|
||||
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)
|
||||
{
|
||||
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;
|
||||
auto xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
|
||||
|
||||
XrBodyTrackerCreateInfoFB create_info{
|
||||
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB,
|
||||
.next = nullptr,
|
||||
.bodyJointSet = full_body
|
||||
? XR_BODY_JOINT_SET_FULL_BODY_META
|
||||
: XR_BODY_JOINT_SET_DEFAULT_FB,
|
||||
};
|
||||
create_info.bodyJointSet = full_body
|
||||
? XR_BODY_JOINT_SET_FULL_BODY_META
|
||||
: XR_BODY_JOINT_SET_DEFAULT_FB;
|
||||
|
||||
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle));
|
||||
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &id));
|
||||
|
||||
// Enable IOBT.
|
||||
CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META));
|
||||
CHECK_XR(xrRequestBodyTrackingFidelityMETA(id, 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 (!handle)
|
||||
if (!id)
|
||||
return std::nullopt;
|
||||
|
||||
assert(xrLocateBodyJointsFB);
|
||||
@@ -111,7 +86,7 @@ std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_h
|
||||
.jointLocations = joints.data(),
|
||||
};
|
||||
|
||||
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
|
||||
if (auto res = xrLocateBodyJointsFB(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
|
||||
{
|
||||
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
|
||||
return std::nullopt;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include "xr/meta_body_tracking_fidelity.h"
|
||||
#include <array>
|
||||
#include <optional>
|
||||
@@ -30,15 +31,10 @@ namespace xr
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
class fb_body_tracker
|
||||
class fb_body_tracker : public utils::handle<XrBodyTrackerFB>
|
||||
{
|
||||
XrSession s;
|
||||
XrBodyTrackerFB handle{};
|
||||
|
||||
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
|
||||
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
|
||||
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
|
||||
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
|
||||
|
||||
bool full_body{};
|
||||
bool hip{};
|
||||
@@ -59,13 +55,7 @@ public:
|
||||
};
|
||||
static std::vector<XrFullBodyJointMETA> get_whitelisted_joints(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;
|
||||
fb_body_tracker(instance & inst, session & s, bool full_body, bool hip);
|
||||
|
||||
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> locate_spaces(XrTime time, XrSpace reference);
|
||||
};
|
||||
|
||||
@@ -23,18 +23,11 @@
|
||||
#include <cstdint>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
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)
|
||||
xr::fb_face_tracker2::fb_face_tracker2(instance & inst, session & s) :
|
||||
handle(inst.get_proc<PFN_xrDestroyFaceTracker2FB>("xrDestroyFaceTracker2FB"))
|
||||
{
|
||||
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];
|
||||
|
||||
@@ -27,16 +27,12 @@ namespace xr
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
XrResult destroy_fb_face_tracker2(XrFaceTracker2FB);
|
||||
|
||||
class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB, destroy_fb_face_tracker2>
|
||||
class fb_face_tracker2 : public utils::handle<XrFaceTracker2FB>
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -23,19 +23,12 @@
|
||||
#include "xr/session.h"
|
||||
#include <cassert>
|
||||
|
||||
static PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT{};
|
||||
|
||||
XrResult xr::destroy_hand_tracker(XrHandTrackerEXT id)
|
||||
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info) :
|
||||
handle(inst.get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT"))
|
||||
{
|
||||
return xrDestroyHandTrackerEXT(id);
|
||||
}
|
||||
|
||||
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info)
|
||||
{
|
||||
static auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,12 @@ namespace xr
|
||||
{
|
||||
class instance;
|
||||
class session;
|
||||
XrResult destroy_hand_tracker(XrHandTrackerEXT);
|
||||
|
||||
class hand_tracker : public utils::handle<XrHandTrackerEXT, destroy_hand_tracker>
|
||||
class hand_tracker : public utils::handle<XrHandTrackerEXT>
|
||||
{
|
||||
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{};
|
||||
|
||||
public:
|
||||
hand_tracker() = default;
|
||||
hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info);
|
||||
|
||||
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* 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
|
||||
@@ -19,8 +20,7 @@
|
||||
|
||||
#include "htc_body_tracker.h"
|
||||
#include "xr/details/enumerate.h"
|
||||
#include "xr/htc_exts.h"
|
||||
#include "xr/xr.h"
|
||||
#include "xr/session.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
// Note: This utilizes extensions not present in the OpenXR spec!
|
||||
@@ -28,11 +28,25 @@
|
||||
// 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(xr::space && space) :
|
||||
space(std::move(space)) {}
|
||||
void xr::vive_xr_tracker::set_active(bool active)
|
||||
xr::vive_xr_tracker::vive_xr_tracker(XrPath path, xr::space & space, XrSession session) :
|
||||
path(path),
|
||||
space(space)
|
||||
{
|
||||
is_active = 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("_");
|
||||
}
|
||||
bool xr::vive_xr_tracker::get_active() const
|
||||
{
|
||||
@@ -76,63 +90,18 @@ static wivrn::from_headset::body_tracking::pose locate_space(XrSpace space, XrSp
|
||||
return res;
|
||||
}
|
||||
|
||||
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),
|
||||
xr::htc_body_tracker::htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers) :
|
||||
s(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();
|
||||
this->trackers.reserve(trackers.size());
|
||||
for (auto & [path, space]: trackers)
|
||||
this->trackers.emplace_back(path, space, s);
|
||||
}
|
||||
|
||||
void xr::htc_body_tracker::update_active()
|
||||
{
|
||||
auto roles = get_roles();
|
||||
assert(roles.size() >= trackers.size());
|
||||
for (int i = 0; i < trackers.size(); i++)
|
||||
trackers[i].set_active(!roles[i].contains('_'));
|
||||
for (auto & tracker: trackers)
|
||||
tracker.update_active(s);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -141,7 +110,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.at(i);
|
||||
auto & tracker = trackers[i];
|
||||
wivrn::from_headset::body_tracking::pose pose{
|
||||
.pose = {},
|
||||
.flags = 0,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* 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,9 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/htc_exts.h"
|
||||
#include "xr/space.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
@@ -34,32 +33,24 @@ class session;
|
||||
class vive_xr_tracker
|
||||
{
|
||||
bool is_active = false;
|
||||
xr::space space;
|
||||
XrPath path;
|
||||
xr::space & space;
|
||||
|
||||
public:
|
||||
vive_xr_tracker(xr::space && s);
|
||||
void set_active(bool active);
|
||||
vive_xr_tracker(XrPath path, xr::space & s, XrSession session);
|
||||
void update_active(XrSession session);
|
||||
bool get_active() const;
|
||||
XrSpace get_space() const;
|
||||
};
|
||||
|
||||
class htc_body_tracker
|
||||
{
|
||||
instance * inst;
|
||||
XrSession s;
|
||||
std::vector<vive_xr_tracker> trackers;
|
||||
|
||||
PFN_xrEnumeratePathsForInteractionProfileHTC xrEnumeratePathsForInteractionProfileHTC{};
|
||||
|
||||
std::vector<std::string> get_roles();
|
||||
|
||||
public:
|
||||
htc_body_tracker() = default;
|
||||
htc_body_tracker(instance & inst, session & s);
|
||||
htc_body_tracker(session & s, std::vector<std::pair<XrPath, xr::space>> & trackers);
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -18,53 +18,43 @@
|
||||
*/
|
||||
|
||||
#include "htc_face_tracker.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) :
|
||||
s(s)
|
||||
static XrFacialTrackerHTC make_tracker(xr::instance & inst, xr::session & s, XrFacialTrackingTypeHTC type)
|
||||
{
|
||||
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,
|
||||
.next = nullptr,
|
||||
.facialTrackingType = type,
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
auto xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
|
||||
XrFacialTrackerHTC id;
|
||||
CHECK_XR(xrCreateFacialTrackerHTC(s, &create_info, &id));
|
||||
return id;
|
||||
}
|
||||
|
||||
xr::htc_face_tracker::~htc_face_tracker()
|
||||
static XrFacialTrackerHTC get_eye_tracker(xr::instance & inst, xr::session & s)
|
||||
{
|
||||
if (!xrDestroyFacialTrackerHTC)
|
||||
return;
|
||||
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 (eye)
|
||||
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(eye, nullptr)));
|
||||
if (lip)
|
||||
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(lip, nullptr)));
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
void xr::htc_face_tracker::get_weights(XrTime time, packet_type & out_expressions)
|
||||
{
|
||||
if (!(eye || lip) || !xrGetFacialExpressionsHTC)
|
||||
return;
|
||||
assert(xrGetFacialExpressionsHTC);
|
||||
|
||||
XrFacialExpressionsHTC expressions{
|
||||
.type = XR_TYPE_FACIAL_EXPRESSIONS_HTC,
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
@@ -30,18 +29,13 @@ class session;
|
||||
|
||||
class htc_face_tracker
|
||||
{
|
||||
XrSession s;
|
||||
XrFacialTrackerHTC eye{};
|
||||
XrFacialTrackerHTC lip{};
|
||||
PFN_xrCreateFacialTrackerHTC xrCreateFacialTrackerHTC{};
|
||||
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC{};
|
||||
PFN_xrDestroyFacialTrackerHTC xrDestroyFacialTrackerHTC{};
|
||||
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC;
|
||||
XrFacialTrackerHTC eye;
|
||||
XrFacialTrackerHTC lip;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
+16
-1
@@ -19,8 +19,9 @@
|
||||
|
||||
#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>
|
||||
@@ -284,6 +285,20 @@ 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;
|
||||
|
||||
@@ -90,6 +90,8 @@ 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);
|
||||
|
||||
|
||||
@@ -23,27 +23,9 @@
|
||||
#include "xr/check.h"
|
||||
#include "xr/instance.h"
|
||||
|
||||
static PFN_xrDestroyPassthroughLayerFB xrDestroyPassthroughLayerFB{};
|
||||
static PFN_xrDestroyPassthroughFB xrDestroyPassthroughFB{};
|
||||
static PFN_xrDestroyPassthroughHTC xrDestroyPassthroughHTC{};
|
||||
|
||||
XrResult xr::destroy_passthrough_layer_fb(XrPassthroughLayerFB id)
|
||||
xr::passthrough_layer_fb::passthrough_layer_fb(instance & inst, session & s, const XrPassthroughLayerCreateInfoFB & info) :
|
||||
handle(inst.get_proc<PFN_xrDestroyPassthroughLayerFB>("xrDestroyPassthroughLayerFB"))
|
||||
{
|
||||
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));
|
||||
}
|
||||
@@ -51,7 +33,6 @@ 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{
|
||||
@@ -64,7 +45,7 @@ static XrPassthroughFB create_passthrough_fb(xr::instance & inst, xr::session &
|
||||
}
|
||||
|
||||
xr::passthrough_fb::passthrough_fb(instance & inst, session & s) :
|
||||
utils::handle<XrPassthroughFB, destroy_passthrough_fb>(create_passthrough_fb(inst, s)),
|
||||
handle(create_passthrough_fb(inst, s), inst.get_proc<PFN_xrDestroyPassthroughFB>("xrDestroyPassthroughFB")),
|
||||
passthrough_layer(inst, s, XrPassthroughLayerCreateInfoFB{
|
||||
.type = XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB,
|
||||
.passthrough = id,
|
||||
@@ -98,10 +79,10 @@ void xr::passthrough_fb::pause()
|
||||
CHECK_XR(xrPassthroughPauseFB(id));
|
||||
}
|
||||
|
||||
xr::passthrough_htc::passthrough_htc(instance & inst, session & s)
|
||||
xr::passthrough_htc::passthrough_htc(instance & inst, session & s) :
|
||||
handle(inst.get_proc<PFN_xrDestroyPassthroughHTC>("xrDestroyPassthroughHTC"))
|
||||
{
|
||||
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,
|
||||
|
||||
@@ -28,17 +28,13 @@ namespace xr
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
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>
|
||||
class passthrough_layer_fb : public utils::handle<XrPassthroughLayerFB>
|
||||
{
|
||||
public:
|
||||
passthrough_layer_fb(instance &, session &, const XrPassthroughLayerCreateInfoFB &);
|
||||
};
|
||||
|
||||
class passthrough_fb : public utils::handle<XrPassthroughFB, destroy_passthrough_fb>
|
||||
class passthrough_fb : public utils::handle<XrPassthroughFB>
|
||||
{
|
||||
PFN_xrPassthroughStartFB xrPassthroughStartFB{};
|
||||
PFN_xrPassthroughPauseFB xrPassthroughPauseFB{};
|
||||
@@ -59,7 +55,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class passthrough_htc : public utils::handle<XrPassthroughHTC, destroy_passthrough_htc>
|
||||
class passthrough_htc : public utils::handle<XrPassthroughHTC>
|
||||
{
|
||||
XrCompositionLayerPassthroughHTC composition_layer;
|
||||
|
||||
|
||||
@@ -18,19 +18,15 @@
|
||||
|
||||
#include "pico_body_tracker.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "xr/xr.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/to_string.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
|
||||
|
||||
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)
|
||||
xr::pico_body_tracker::pico_body_tracker(instance & inst, session & s) :
|
||||
handle(inst.get_proc<PFN_xrDestroyBodyTrackerBD>("xrDestroyBodyTrackerBD"))
|
||||
{
|
||||
auto xrCreateBodyTrackerBD = inst.get_proc<PFN_xrCreateBodyTrackerBD>("xrCreateBodyTrackerBD");
|
||||
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
|
||||
@@ -45,10 +41,6 @@ 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)
|
||||
|
||||
@@ -30,9 +30,7 @@ namespace xr
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
|
||||
|
||||
class pico_body_tracker : public utils::handle<XrBodyTrackerBD, destroy_pico_body_tracker>
|
||||
class pico_body_tracker : public utils::handle<XrBodyTrackerBD>
|
||||
{
|
||||
PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
|
||||
|
||||
@@ -48,10 +46,8 @@ 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
|
||||
|
||||
+135
-124
@@ -18,152 +18,163 @@
|
||||
*/
|
||||
|
||||
#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 <cstring>
|
||||
#include <stdexcept>
|
||||
#include <mutex>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) :
|
||||
s(s_)
|
||||
struct xr::pico_face_tracker::impl
|
||||
{
|
||||
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();
|
||||
}
|
||||
const XrSession s;
|
||||
const PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO;
|
||||
const 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))
|
||||
impl(instance & inst, session & s) :
|
||||
s(s),
|
||||
xrStopEyeTrackingPICO(inst.get_proc<PFN_xrStopEyeTrackingPICO>("xrStopEyeTrackingPICO")),
|
||||
xrGetFaceTrackingDataPICO(inst.get_proc<PFN_xrGetFaceTrackingDataPICO>("xrGetFaceTrackingDataPICO"))
|
||||
{
|
||||
spdlog::warn("Unable to get face tracking data: xrGetFaceTrackingDataPICO returned {}", xr::to_string(res));
|
||||
return;
|
||||
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));
|
||||
}
|
||||
|
||||
if (face_tracking.time == 0)
|
||||
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;
|
||||
|
||||
#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;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#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
|
||||
@@ -31,22 +29,13 @@ class session;
|
||||
|
||||
class pico_face_tracker
|
||||
{
|
||||
PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{};
|
||||
PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{};
|
||||
PFN_xrSetTrackingModePICO xrSetTrackingModePICO{};
|
||||
PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{};
|
||||
|
||||
XrSession s;
|
||||
bool started{};
|
||||
struct impl;
|
||||
std::shared_ptr<impl> i;
|
||||
|
||||
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
|
||||
|
||||
@@ -19,18 +19,19 @@
|
||||
|
||||
#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, int queue_family_index) :
|
||||
inst(&inst)
|
||||
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)
|
||||
{
|
||||
XrGraphicsBindingVulkan2KHR vulkan_binding{
|
||||
.type = XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR,
|
||||
@@ -127,7 +128,7 @@ void xr::session::begin_frame()
|
||||
.type = XR_TYPE_FRAME_BEGIN_INFO,
|
||||
};
|
||||
|
||||
auto lock = application::get_queue().lock();
|
||||
auto lock = queue->lock();
|
||||
CHECK_XR(xrBeginFrame(id, &begin_info));
|
||||
}
|
||||
|
||||
@@ -141,7 +142,7 @@ void xr::session::end_frame(XrTime display_time, const std::vector<XrComposition
|
||||
.layers = layers.data(),
|
||||
};
|
||||
|
||||
auto lock = application::get_queue().lock();
|
||||
auto lock = queue->lock();
|
||||
CHECK_XR(xrEndFrame(id, &end_info));
|
||||
}
|
||||
|
||||
@@ -344,14 +345,14 @@ void xr::session::enable_passthrough(xr::system & system)
|
||||
if (not std::holds_alternative<std::monostate>(passthrough))
|
||||
return;
|
||||
|
||||
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
|
||||
if (system.passthrough_supported() == xr::passthrough_type::none)
|
||||
return;
|
||||
|
||||
if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME))
|
||||
if (inst->has_extension(XR_FB_PASSTHROUGH_EXTENSION_NAME))
|
||||
{
|
||||
passthrough.emplace<xr::passthrough_fb>(*inst, *this);
|
||||
}
|
||||
else if (utils::contains(application::get_xr_extensions(), XR_HTC_PASSTHROUGH_EXTENSION_NAME))
|
||||
else if (inst->has_extension(XR_HTC_PASSTHROUGH_EXTENSION_NAME))
|
||||
{
|
||||
passthrough.emplace<xr::passthrough_htc>(*inst, *this);
|
||||
}
|
||||
|
||||
+3
-1
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -39,10 +40,11 @@ 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 &, int queue_family_index);
|
||||
session(instance &, system &, vk::raii::Instance &, vk::raii::PhysicalDevice &, vk::raii::Device &, thread_safe<vk::raii::Queue> & queue, 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}});
|
||||
|
||||
+28
-7
@@ -19,12 +19,14 @@
|
||||
|
||||
#include "system.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "body_tracker.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>
|
||||
|
||||
@@ -41,6 +43,12 @@ 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
|
||||
@@ -195,16 +203,15 @@ XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
|
||||
return body_tracking_prop;
|
||||
}
|
||||
|
||||
xr::system::passthrough_type xr::system::passthrough_supported() const
|
||||
xr::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;
|
||||
|
||||
const std::vector<std::string> & xr_extensions = application::get_xr_extensions();
|
||||
if (utils::contains(xr_extensions, XR_HTC_PASSTHROUGH_EXTENSION_NAME))
|
||||
if (inst->has_extension(XR_HTC_PASSTHROUGH_EXTENSION_NAME))
|
||||
return passthrough_type::color;
|
||||
|
||||
if (utils::contains(xr_extensions, XR_FB_PASSTHROUGH_EXTENSION_NAME))
|
||||
if (inst->has_extension(XR_FB_PASSTHROUGH_EXTENSION_NAME))
|
||||
{
|
||||
XrSystemPassthroughProperties2FB passthrough_prop2{
|
||||
.type = XR_TYPE_SYSTEM_PASSTHROUGH_PROPERTIES2_FB,
|
||||
@@ -224,7 +231,7 @@ xr::system::passthrough_type xr::system::passthrough_supported() const
|
||||
if (passthrough_prop.supportsPassthrough)
|
||||
{
|
||||
if (!(passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_BIT_FB))
|
||||
return passthrough_type::no_passthrough;
|
||||
return passthrough_type::none;
|
||||
|
||||
if (passthrough_prop2.capabilities & XR_PASSTHROUGH_CAPABILITY_COLOR_BIT_FB)
|
||||
return passthrough_type::color;
|
||||
@@ -233,7 +240,21 @@ xr::system::passthrough_type xr::system::passthrough_supported() const
|
||||
}
|
||||
}
|
||||
|
||||
return passthrough_type::no_passthrough;
|
||||
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_;
|
||||
}
|
||||
|
||||
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance & vulkan) const
|
||||
|
||||
+31
-7
@@ -32,19 +32,39 @@ 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;
|
||||
@@ -67,7 +87,11 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user