Merge branch 'WiVRn:master' into sneed

This commit is contained in:
Just some guy
2025-06-15 19:41:44 +00:00
committed by GitHub
103 changed files with 3862 additions and 4066 deletions
+54 -4
View File
@@ -19,6 +19,7 @@
#include "application.h"
#include "asset.h"
#include "hardware.h"
#include "openxr/openxr.h"
#include "scene.h"
#include "spdlog/common.h"
@@ -30,6 +31,7 @@
#include "wifi_lock.h"
#include "xr/actionset.h"
#include "xr/check.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h"
#include <algorithm>
#include <boost/locale.hpp>
@@ -1039,6 +1041,10 @@ void application::initialize()
opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME);
opt_extensions.push_back(XR_HTC_FACIAL_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_FACE_TRACKING2_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_BODY_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME);
opt_extensions.push_back(XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME);
opt_extensions.push_back(XR_BD_BODY_TRACKING_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_PALM_POSE_EXTENSION_NAME);
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
@@ -1103,6 +1109,24 @@ void application::initialize()
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 (eye_gaze_supported)
{
switch (guess_model())
{
case model::pico_4_pro:
case model::pico_4_enterprise:
pico_face_tracking_supported = true;
break;
default:
pico_face_tracking_supported = false;
break;
}
}
else
pico_face_tracking_supported = false;
spdlog::info(" PICO face tracking support: {}", (bool)pico_face_tracking_supported);
}
if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME))
@@ -1121,6 +1145,20 @@ void application::initialize()
htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking;
}
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);
fb_body_tracking_supported = fb_body_properties.supportsBodyTracking;
}
if (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);
pico_body_tracking_supported = bd_body_properties.supportsBodyTracking;
}
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
{
spdlog::info(" OpenXR post-processing extension support: true");
@@ -1180,6 +1218,21 @@ void application::initialize()
htc_face_tracker_lip = xr_session.create_htc_face_tracker(XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
}
if (pico_face_tracking_supported)
{
pico_face_tracker = xr_session.create_pico_face_tracker();
}
if (fb_body_tracking_supported)
{
fb_body_tracker = xr_session.create_fb_body_tracker();
}
if (pico_body_tracking_supported)
{
pico_body_tracker = xr_session.create_pico_body_tracker();
}
vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
@@ -1356,11 +1409,7 @@ application::application(application_info info) :
}
};
#ifdef __ANDROID__
wifi = wifi_lock::make_wifi_lock(app_info.native_app->activity->clazz);
#else
wifi = std::make_shared<wifi_lock>();
#endif
// Initialize the loader for this platform
PFN_xrInitializeLoaderKHR initializeLoader = nullptr;
@@ -1376,6 +1425,7 @@ application::application(application_info info) :
}
#else
wifi = std::make_shared<wifi_lock>();
config_path = xdg_config_home() / "wivrn";
cache_path = xdg_cache_home() / "wivrn";
#endif
+40
View File
@@ -21,9 +21,11 @@
#include "configuration.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_face_tracker.h"
#include "xr/pico_face_tracker.h"
#ifdef __ANDROID__
#include <android_native_app_glue.h>
#endif
@@ -133,6 +135,14 @@ class application : public singleton<application>
bool htc_face_tracking_lip_supported = false;
xr::htc_face_tracker htc_face_tracker_lip;
bool pico_face_tracking_supported = false;
xr::pico_face_tracker pico_face_tracker;
bool fb_body_tracking_supported = false;
xr::fb_body_tracker fb_body_tracker;
bool pico_body_tracking_supported = false;
xr::pico_body_tracker pico_body_tracker;
bool eye_gaze_supported = false;
bool openxr_post_processing_supported = false;
@@ -436,6 +446,21 @@ public:
return instance().htc_face_tracking_lip_supported;
}
static bool get_pico_face_tracking_supported()
{
return instance().pico_face_tracking_supported;
}
static bool get_fb_body_tracking_supported()
{
return instance().fb_body_tracking_supported;
}
static bool get_pico_body_tracking_supported()
{
return instance().pico_body_tracking_supported;
}
static bool get_eye_gaze_supported()
{
return instance().eye_gaze_supported;
@@ -471,6 +496,21 @@ public:
return instance().htc_face_tracker_lip;
}
static xr::pico_face_tracker & get_pico_face_tracker()
{
return instance().pico_face_tracker;
}
static xr::fb_body_tracker & get_fb_body_tracker()
{
return instance().fb_body_tracker;
}
static xr::pico_body_tracker & get_pico_body_tracker()
{
return instance().pico_body_tracker;
}
static const std::vector<std::string> & get_xr_extensions()
{
return instance().xr_extensions;
+33
View File
@@ -111,11 +111,37 @@ bool configuration::check_feature(feature f) const
if (not(application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()))
return false;
break;
case model::pico_4_pro:
case model::pico_4_enterprise:
if (not application::get_pico_face_tracking_supported())
return false;
break;
default:
if (not application::get_fb_face_tracking2_supported())
return false;
break;
}
break;
case feature::body_tracking:
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_3s:
if (not application::get_fb_body_tracking_supported())
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 application::get_pico_body_tracking_supported())
return false;
break;
default:
break;
}
break;
}
}
#ifdef __ANDROID__
@@ -198,6 +224,11 @@ configuration::configuration(xr::system & system)
if (auto val = root["mic_unprocessed_audio"]; val.is_bool())
mic_unprocessed_audio = val.get_bool();
if (auto val = root["fb_lower_body"]; val.is_bool())
fb_lower_body = val.get_bool();
if (auto val = root["fb_hip"]; val.is_bool())
fb_hip = val.get_bool();
if (auto val = root["virtual_keyboard_layout"]; val.is_string())
virtual_keyboard_layout = val.get_string().value();
@@ -320,6 +351,8 @@ void configuration::save()
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;
for (auto & [key, value]: features)
json << "," << key << ":" << std::boolalpha << value;
json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout);
+3
View File
@@ -54,6 +54,9 @@ public:
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
bool fb_lower_body = false;
bool fb_hip = true;
// Snapdragon Game Super Resolution
struct sgsr_settings
{
+35 -3
View File
@@ -71,13 +71,25 @@ static model guess_model_()
if (manufacturer == "Pico")
{
if (model == "Pico Neo 3")
const auto pico_model = get_property("pxr.vendorhw.product.model");
spdlog::info(" pxr.vendorhw.product.model = \"{}\":", pico_model);
if (pico_model == "Pico Neo 3")
return model::pico_neo_3;
if (model == "A9210")
if (pico_model == "PICO 4")
return model::pico_4;
if (pico_model == "PICO 4 Ultra")
return model::pico_4s;
spdlog::info("manufacturer={}, model={}, device={} assuming Pico 4", manufacturer, model, device);
if (pico_model == "PICO 4 Pro")
return model::pico_4_pro;
if (pico_model == "PICO 4 Enterprise")
return model::pico_4_enterprise;
spdlog::info("manufacturer={}, model={}, device={}, pico_model={} assuming Pico 4", manufacturer, model, device, pico_model);
return model::pico_4;
}
if (manufacturer == "HTC")
@@ -145,6 +157,8 @@ XrViewConfigurationView override_view(XrViewConfigurationView view, model m)
return scale_view(view, 1832);
case model::pico_4:
case model::pico_4s:
case model::pico_4_pro:
case model::pico_4_enterprise:
return scale_view(view, 2160);
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
@@ -172,6 +186,8 @@ bool need_srgb_conversion(model m)
case model::pico_neo_3:
case model::pico_4:
case model::pico_4s:
case model::pico_4_pro:
case model::pico_4_enterprise:
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
case model::htc_vive_xr_elite:
@@ -201,6 +217,8 @@ const char * permission_name(feature f)
case model::pico_neo_3:
case model::pico_4:
case model::pico_4s:
case model::pico_4_pro:
case model::pico_4_enterprise:
return "com.picovr.permission.EYE_TRACKING";
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
@@ -222,6 +240,9 @@ const char * permission_name(feature f)
case model::pico_neo_3:
case model::pico_4:
case model::pico_4s:
case model::pico_4_pro:
case model::pico_4_enterprise:
return "com.picovr.permission.FACE_TRACKING";
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
case model::htc_vive_xr_elite:
@@ -230,6 +251,15 @@ const char * permission_name(feature f)
return nullptr;
}
__builtin_unreachable();
case feature::body_tracking:
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_3s:
return "com.oculus.permission.BODY_TRACKING";
default:
return nullptr;
}
}
__builtin_unreachable();
}
@@ -257,6 +287,8 @@ std::string controller_name()
return "pico-neo3";
case model::pico_4:
case model::pico_4s: // TODO: split when we have the pico-4s 3d model
case model::pico_4_pro:
case model::pico_4_enterprise:
return "pico-4";
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
+3
View File
@@ -35,6 +35,8 @@ enum class model
pico_neo_3,
pico_4,
pico_4s,
pico_4_pro,
pico_4_enterprise,
htc_vive_focus_3,
htc_vive_xr_elite,
htc_vive_focus_vision,
@@ -48,6 +50,7 @@ enum class feature
hand_tracking,
eye_gaze,
face_tracking,
body_tracking,
};
model guess_model();
+65 -3
View File
@@ -727,7 +727,7 @@ void scenes::lobby::gui_settings()
ImGui::EndDisabled();
}
{
ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()));
ImGui::BeginDisabled(not(application::get_fb_face_tracking2_supported() or application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported()));
bool enabled = config.check_feature(feature::face_tracking);
if (ImGui::Checkbox(_S("Enable face tracking"), &enabled))
{
@@ -740,6 +740,58 @@ void scenes::lobby::gui_settings()
vibrate_on_hover();
}
{
ImGui::BeginDisabled(not(application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported()));
bool enabled = config.check_feature(feature::body_tracking);
if (ImGui::Checkbox(_S("Enable body tracking"), &enabled))
{
config.set_feature(feature::body_tracking, enabled);
config.save();
}
ImGui::EndDisabled();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
if (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled)
{
tooltip(_("This feature is not supported by your headset"));
}
else
{
if (application::get_fb_body_tracking_supported())
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"));
else if (application::get_pico_body_tracking_supported())
tooltip(_("Uses the Pico Motion Trackers to track body joint positions"));
}
}
vibrate_on_hover();
}
if (application::get_fb_body_tracking_supported())
{
ImGui::BeginDisabled(not config.check_feature(feature::body_tracking));
ImGui::Indent();
if (ImGui::Checkbox(_S("Enable lower body tracking"), &config.fb_lower_body))
{
config.save();
}
vibrate_on_hover();
if (ImGui::IsItemHovered())
tooltip(_("Estimate lower body joint positions using Generative Legs\nRequires 'Hand and body tracking' to be enabled in the Quest movement tracking settings"));
ImGui::BeginDisabled(not config.fb_lower_body);
if (ImGui::Checkbox(_S("Enable hip tracking"), &config.fb_hip))
{
config.save();
}
vibrate_on_hover();
if (ImGui::IsItemHovered())
tooltip(_("Only takes affect with lower body tracking enabled\nMay be desired when using another source of hip tracking"));
ImGui::EndDisabled();
ImGui::Unindent();
ImGui::EndDisabled();
}
ImGui::BeginDisabled(passthrough_supported == xr::system::passthrough_type::no_passthrough);
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
{
@@ -1422,7 +1474,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())
if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported() or application::get_pico_face_tracking_supported())
{
items.push_back({
.f = feature::face_tracking,
@@ -1433,6 +1485,16 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
});
}
if (application::get_fb_body_tracking_supported() or application::get_pico_body_tracking_supported())
{
items.push_back({
.f = feature::body_tracking,
.tooltip_enabled = _("Body tracking is enabled"),
.tooltip_disabled = _("Body tracking is disabled"),
.icon_enabled = ICON_FA_PERSON,
});
}
// Get statuses
for (auto & i: items)
{
@@ -1459,7 +1521,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
if (&i != &items.front())
ImGui::SameLine();
auto pos = ImGui::GetCursorPos();
if (ImGui::Button(i.enabled ? i.icon_enabled : i.icon_disabled))
if (ImGui::Button(fmt::format("{}##{}", i.enabled ? i.icon_enabled : i.icon_disabled, i.icon_enabled).c_str()))
{
// button doesn't alter the bool
config.set_feature(i.f, not i.enabled);
+33 -10
View File
@@ -17,6 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "utils/overloaded.h"
#include "xr/fb_body_tracker.h"
#define GLM_FORCE_RADIANS
#include "stream.h"
@@ -220,6 +221,17 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.face_tracking = from_headset::face_type::fb2;
else if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())
info.face_tracking = from_headset::face_type::htc;
else if (application::get_pico_face_tracking_supported())
info.face_tracking = from_headset::face_type::pico;
}
info.num_generic_trackers = 0;
if (config.check_feature(feature::body_tracking))
{
if (application::get_fb_body_tracking_supported())
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
else if (application::get_pico_body_tracking_supported())
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
}
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
@@ -858,10 +870,16 @@ void scenes::stream::render(const XrFrameState & frame_state)
}
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
reprojector->set_foveation(foveation);
// Unfoveate the image to the real pose
reprojector->reproject(command_buffer, image_index);
// defoveate the image
auto extents = reprojector->reproject(command_buffer, foveation, image_index);
for (size_t i = 0; i < view_count; ++i)
{
extents[i] = {
.width = std::min(extents[i].width, swapchain.width()),
.height = std::min(extents[i].height, swapchain.height()),
};
}
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
@@ -906,10 +924,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
.swapchain = swapchain,
.imageRect = {
.offset = {0, 0},
.extent = {
swapchain.width(),
swapchain.height(),
},
.extent = extents[view],
},
.imageArrayIndex = view,
},
@@ -1159,8 +1174,8 @@ void scenes::stream::setup_reprojection_swapchain()
const uint32_t video_width = video_stream_description->width / view_count;
const uint32_t video_height = video_stream_description->height;
uint32_t swapchain_width = video_width / video_stream_description->foveation[0].x.scale;
uint32_t swapchain_height = video_height / video_stream_description->foveation[0].y.scale;
uint32_t swapchain_width = video_stream_description->defoveated_width / view_count;
uint32_t swapchain_height = video_stream_description->defoveated_height;
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
if (sgsr.enabled)
@@ -1187,7 +1202,15 @@ void scenes::stream::setup_reprojection_swapchain()
for (auto & image: swapchain.images())
swapchain_images.push_back(image.image);
reprojector.emplace(device, physical_device, decoder_out_image, 2, swapchain_images, extent, swapchain.format(), *video_stream_description);
reprojector.emplace(
device,
physical_device,
decoder_out_image,
vk::Extent2D{.width = video_width, .height = video_height},
2,
swapchain_images,
extent,
swapchain.format());
}
scene::meta & scenes::stream::get_meta_scene()
+142 -133
View File
@@ -20,30 +20,24 @@
#include "stream_reprojection.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 <array>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <spdlog/spdlog.h>
#include <vk_mem_alloc.h>
#include <vulkan/vulkan_core.h>
#include <vulkan/vulkan_raii.hpp>
namespace
struct stream_reprojection::vertex
{
struct uniform
{
// Foveation parameters
alignas(8) glm::vec2 a;
alignas(8) glm::vec2 b;
alignas(8) glm::vec2 lambda;
alignas(8) glm::vec2 xc;
// output image position
alignas(8) glm::vec2 position;
// input texture coordinates
alignas(8) glm::vec2 uv;
};
} // namespace
const int nb_reprojection_vertices = 128;
struct SgsrSpecializationConstants
{
@@ -52,24 +46,47 @@ struct SgsrSpecializationConstants
float edge_sharpness;
};
void stream_reprojection::ensure_vertices(size_t num_vertices)
{
vk::BufferCreateInfo create_info{
.size = num_vertices * sizeof(vertex) * view_count,
.usage = vk::BufferUsageFlagBits::eVertexBuffer,
.sharingMode = vk::SharingMode::eExclusive,
};
if (create_info.size <= buffer.info().size)
return;
VmaAllocationCreateInfo alloc_info{
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
};
buffer = buffer_allocation(device, create_info, alloc_info);
vertices_size = num_vertices * sizeof(vertex);
}
stream_reprojection::vertex * stream_reprojection::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 extent,
vk::Format format,
const wivrn::to_headset::video_stream_description & description) :
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_)),
extent(extent)
output_extent(output_extent)
{
foveation_parameters = description.foveation;
vk::PhysicalDeviceProperties properties = physical_device.getProperties();
vk::SamplerCreateInfo sampler_info{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
@@ -93,35 +110,12 @@ stream_reprojection::stream_reprojection(
sampler = vk::raii::Sampler(device, sampler_info);
uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1;
uniform_size = uniform_size - uniform_size % properties.limits.minUniformBufferOffsetAlignment;
vk::BufferCreateInfo create_info{
.size = uniform_size * view_count,
.usage = vk::BufferUsageFlagBits::eUniformBuffer,
.sharingMode = vk::SharingMode::eExclusive,
};
VmaAllocationCreateInfo alloc_info{
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
};
buffer = buffer_allocation(device, create_info, alloc_info);
// Create VkDescriptorSetLayout
std::array layout_binding{
vk::DescriptorSetLayoutBinding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
},
vk::DescriptorSetLayoutBinding{
.binding = 1,
.descriptorType = vk::DescriptorType::eUniformBuffer,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment,
},
vk::DescriptorSetLayoutBinding layout_binding{
.binding = 0,
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eFragment,
};
vk::DescriptorSetLayoutCreateInfo layout_info;
@@ -134,10 +128,6 @@ stream_reprojection::stream_reprojection(
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = (uint32_t)view_count,
},
vk::DescriptorPoolSize{
.type = vk::DescriptorType::eUniformBuffer,
.descriptorCount = (uint32_t)view_count,
},
};
vk::DescriptorPoolCreateInfo pool_info{
@@ -153,7 +143,7 @@ stream_reprojection::stream_reprojection(
{
vk::ImageViewCreateInfo iv_info{
.image = input_image,
.viewType = vk::ImageViewType::e2DArray,
.viewType = vk::ImageViewType::e2D,
.format = vk::Format::eA8B8G8R8SrgbPack32,
.components = {
.r = vk::ComponentSwizzle::eIdentity,
@@ -186,13 +176,7 @@ stream_reprojection::stream_reprojection(
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
vk::DescriptorBufferInfo buffer_info{
.buffer = buffer,
.offset = uniform_size * view,
.range = sizeof(uniform),
};
std::array write{
device.updateDescriptorSets(
vk::WriteDescriptorSet{
.dstSet = descriptor_set,
.dstBinding = 0,
@@ -201,17 +185,7 @@ stream_reprojection::stream_reprojection(
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
.pImageInfo = &image_info,
},
vk::WriteDescriptorSet{
.dstSet = descriptor_set,
.dstBinding = 1,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eUniformBuffer,
.pBufferInfo = &buffer_info,
},
};
device.updateDescriptorSets(write, {});
{});
}
// Create renderpass
@@ -248,40 +222,6 @@ stream_reprojection::stream_reprojection(
// Vertex shader
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
int vertex_specialization_constants[] = {
foveation_parameters[0].x.scale < 1,
foveation_parameters[0].y.scale < 1,
nb_reprojection_vertices,
nb_reprojection_vertices,
};
std::array vertex_specialization_constants_desc{
vk::SpecializationMapEntry{
.constantID = 0,
.offset = 0,
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 1,
.offset = sizeof(int),
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 2,
.offset = 2 * sizeof(int),
.size = sizeof(int),
},
vk::SpecializationMapEntry{
.constantID = 3,
.offset = 3 * sizeof(int),
.size = sizeof(int),
},
};
vk::SpecializationInfo vertex_specialization_info;
vertex_specialization_info.setMapEntries(vertex_specialization_constants_desc);
vertex_specialization_info.setData<int>(vertex_specialization_constants);
// Fragment shader
std::string fragment_shader_name = "reprojection.frag";
@@ -337,7 +277,6 @@ stream_reprojection::stream_reprojection(
.stage = vk::ShaderStageFlagBits::eVertex,
.module = *vertex_shader,
.pName = "main",
.pSpecializationInfo = &vertex_specialization_info,
},
{
.stage = vk::ShaderStageFlagBits::eFragment,
@@ -346,22 +285,41 @@ stream_reprojection::stream_reprojection(
.pSpecializationInfo = &fragment_specialization_info,
},
},
.VertexBindingDescriptions = {},
.VertexAttributeDescriptions = {},
.VertexBindingDescriptions = {
{
.binding = 0,
.stride = sizeof(vertex),
.inputRate = vk::VertexInputRate::eVertex,
},
},
.VertexAttributeDescriptions = {
{
.location = 0,
.binding = 0,
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(vertex, position),
},
{
.location = 1,
.binding = 0,
.format = vk::Format::eR32G32Sfloat,
.offset = offsetof(vertex, uv),
},
},
.InputAssemblyState = {{
.topology = vk::PrimitiveTopology::eTriangleList,
.topology = vk::PrimitiveTopology::eTriangleStrip,
}},
.Viewports = {{
.x = 0,
.y = 0,
.width = (float)extent.width,
.height = (float)extent.height,
.width = (float)output_extent.width,
.height = (float)output_extent.height,
.minDepth = 0,
.maxDepth = 1,
}},
.Scissors = {{
.offset = {.x = 0, .y = 0},
.extent = extent,
.extent = output_extent,
}},
.RasterizationState = {{
.polygonMode = vk::PolygonMode::eFill,
@@ -411,8 +369,8 @@ stream_reprojection::stream_reprojection(
vk::FramebufferCreateInfo fb_create_info{
.renderPass = *renderpass,
.width = extent.width,
.height = extent.height,
.width = output_extent.width,
.height = output_extent.height,
.layers = 1,
};
fb_create_info.setAttachments(*output_image_views.back());
@@ -422,28 +380,82 @@ stream_reprojection::stream_reprojection(
}
}
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int destination)
static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p)
{
// strips are constructed like this:
// 0 2 4
// 1 3 5 5*
// there is one such line per value in y
// the last element is repeated to break the line
return (2 * (p.x.size() + 1) + 1) * p.y.size();
}
std::vector<XrExtent2Di> stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
int destination)
{
if (destination < 0 || destination >= (int)output_images.size())
throw std::runtime_error("Invalid destination image index");
ensure_vertices(std::max(required_vertices(foveation[0]), required_vertices(foveation[1])));
std::vector<XrExtent2Di> out_extents(view_count, XrExtent2Di{});
for (size_t view = 0; view < view_count; ++view)
{
auto & ubo = *reinterpret_cast<uniform *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * uniform_size);
if (foveation_parameters[view].x.scale < 1)
auto vertices = get_vertices(view);
const auto & [px, py] = foveation[view];
assert(px.size() % 2 == 1);
assert(py.size() % 2 == 1);
const int n_ratio_y = (py.size() - 1) / 2;
const int n_ratio_x = (px.size() - 1) / 2;
for (auto [ix, n_out_x]: utils::enumerate_range(px))
{
ubo.a.x = foveation_parameters[view].x.a;
ubo.b.x = foveation_parameters[view].x.b;
ubo.lambda.x = foveation_parameters[view].x.scale / foveation_parameters[view].x.a;
ubo.xc.x = foveation_parameters[view].x.center;
// number of output pixels per source pixels
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
out_extents[view].width += ratio_x * n_out_x;
}
if (foveation_parameters[view].y.scale < 1)
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);
for (auto [iy, n_out_y]: utils::enumerate_range(py))
{
ubo.a.y = foveation_parameters[view].y.a;
ubo.b.y = foveation_parameters[view].y.b;
ubo.lambda.y = foveation_parameters[view].y.scale / foveation_parameters[view].y.a;
ubo.xc.y = foveation_parameters[view].y.center;
// number of output pixels per source pixels
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
out_extents[view].height += ratio_y * n_out_y;
in.x = 0;
out.x = 0;
for (auto [ix, n_out_x]: utils::enumerate_range(px))
{
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
*vertices++ = {
.position = out * out_pixel_size - glm::vec2(1),
.uv = in * in_pixel_size,
};
*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,
};
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,
};
*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,
};
*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,
};
in.y += n_out_y;
out.y += n_out_y * ratio_y;
}
}
@@ -473,19 +485,16 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, in
.framebuffer = *framebuffers[destination * view_count + view],
.renderArea = {
.offset = {0, 0},
.extent = extent,
.extent = output_extent,
},
};
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.draw(6 * nb_reprojection_vertices * nb_reprojection_vertices, 1, 0, 0);
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
command_buffer.endRenderPass();
}
}
void stream_reprojection::set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation)
{
foveation_parameters = foveation;
return out_extents;
}
+14 -11
View File
@@ -26,10 +26,13 @@
class stream_reprojection
{
struct vertex;
const uint32_t view_count;
// Uniform buffer
// Vertex buffer
buffer_allocation buffer;
size_t uniform_size;
size_t vertices_size = 0;
vk::raii::Device & device;
// Graphic pipeline
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
@@ -43,32 +46,32 @@ class stream_reprojection
vk::Image input_image;
std::vector<vk::raii::ImageView> input_image_views;
std::vector<vk::DescriptorSet> descriptor_sets;
vk::Extent2D input_extent;
// Destination images
std::vector<vk::Image> output_images;
std::vector<vk::raii::ImageView> output_image_views;
std::vector<vk::raii::Framebuffer> framebuffers;
vk::Extent2D extent;
vk::Extent2D output_extent;
// Foveation
std::array<wivrn::to_headset::foveation_parameter, 2> foveation_parameters;
void ensure_vertices(size_t num_vertices);
vertex * get_vertices(size_t view);
public:
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 extent,
vk::Format format,
const wivrn::to_headset::video_stream_description & description);
vk::Extent2D output_extent,
vk::Format format);
stream_reprojection(const stream_reprojection &) = delete;
void reproject(
std::vector<XrExtent2Di> reproject(
vk::raii::CommandBuffer & command_buffer,
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
int destination);
void set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation);
};
+77 -4
View File
@@ -232,9 +232,11 @@ void scenes::stream::tracking()
XrTime t0 = instance.now();
XrTime last_hand_sample = t0;
XrTime last_body_sample = t0;
std::vector<from_headset::tracking> tracking;
std::vector<from_headset::tracking> tracking_pool; // pre-allocated objects
std::vector<from_headset::hand_tracking> hands;
std::vector<from_headset::body_tracking> body;
std::vector<XrView> views;
std::vector<from_headset::trackings> merged_tracking;
@@ -248,6 +250,36 @@ void scenes::stream::tracking()
face_tracking = from_headset::face_type::fb2;
else if (application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported())
face_tracking = from_headset::face_type::htc;
else if (application::get_pico_face_tracking_supported())
{
face_tracking = from_headset::face_type::pico;
// 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.
application::get_pico_face_tracker().start();
}
}
enum
{
body_none,
body_fb,
body_pico,
} body_tracking = body_none;
if (config.check_feature(feature::body_tracking))
{
if (application::get_fb_body_tracking_supported())
{
body_tracking = body_fb;
// 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
application::get_fb_body_tracker().stop();
application::get_fb_body_tracker().start(config.fb_lower_body, config.fb_hip);
}
else if (application::get_pico_body_tracking_supported())
body_tracking = body_pico;
}
on_interaction_profile_changed({});
@@ -258,6 +290,7 @@ void scenes::stream::tracking()
{
tracking.clear();
hands.clear();
body.clear();
XrTime now = instance.now();
if (now < t0)
@@ -327,6 +360,30 @@ void scenes::stream::tracking()
locate_hands(application::get_right_hand(), world_space, t0 + Δt));
}
if (body_tracking != body_none and 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)])
{
auto & body_packet = body.emplace_back(from_headset::body_tracking{
.production_timestamp = t0,
.timestamp = t0 + Δt,
});
switch (body_tracking)
{
case body_none:
__builtin_unreachable();
case body_fb:
body_packet.poses = application::get_fb_body_tracker().locate_spaces(t0 + Δt, world_space);
break;
case body_pico:
body_packet.poses = application::get_pico_body_tracker().locate_spaces(t0 + Δt, world_space);
break;
}
}
}
if (control.enabled[size_t(tid::face)])
{
switch (face_tracking)
@@ -334,10 +391,10 @@ void scenes::stream::tracking()
case wivrn::from_headset::face_type::none:
break;
case wivrn::from_headset::face_type::fb2:
application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace());
application::get_fb_face_tracker2().get_weights(t0 + Δt, packet.face.emplace<wivrn::from_headset::tracking::fb_face2>());
break;
case wivrn::from_headset::face_type::htc:
auto & face_htc = packet.face_htc.emplace();
case wivrn::from_headset::face_type::htc: {
auto & face_htc = packet.face.emplace<wivrn::from_headset::tracking::htc_face>();
face_htc.eye_active = false;
face_htc.lip_active = false;
if (application::get_htc_face_tracking_eye_supported())
@@ -345,6 +402,10 @@ void scenes::stream::tracking()
if (application::get_htc_face_tracking_lip_supported())
application::get_htc_face_tracker_lip().get_weights(t0 + Δt, face_htc);
break;
}
case wivrn::from_headset::face_type::pico:
application::get_pico_face_tracker().get_weights(t0 + Δt, packet.face.emplace<wivrn::from_headset::tracking::fb_face2>());
break;
}
}
}
@@ -396,7 +457,7 @@ void scenes::stream::tracking()
merged_tracking.back().items.emplace_back(std::move(item));
}
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size()));
packets.resize(std::max(packets.size(), merged_tracking.size() + hands.size() + body.size()));
size_t packet_count = 0;
for (const auto & i: merged_tracking)
{
@@ -413,6 +474,15 @@ void scenes::stream::tracking()
wivrn_session::stream_socket_t::serialize(packet, i);
}
}
for (const auto & i: body)
{
if (i.poses)
{
auto & packet = packets[packet_count++];
packet.clear();
wivrn_session::stream_socket_t::serialize(packet, i);
}
}
network_session->send_stream(std::span(packets.data(), packet_count));
@@ -438,6 +508,9 @@ void scenes::stream::tracking()
exit();
}
}
if (face_tracking == from_headset::face_type::pico)
application::get_pico_face_tracker().stop();
}
void scenes::stream::operator()(to_headset::tracking_control && packet)
+4 -45
View File
@@ -21,56 +21,15 @@
#ifdef VERT_SHADER
layout (constant_id = 0) const bool use_foveation_x = false;
layout (constant_id = 1) const bool use_foveation_y = false;
layout (constant_id = 2) const int nb_x = 64;
layout (constant_id = 3) const int nb_y = 64;
layout(set = 0, binding = 1) uniform UniformBufferObject
{
vec2 a;
vec2 b;
vec2 lambda;
vec2 xc;
}
ubo;
layout (location = 0) in vec2 vPosition;
layout (location = 1) in vec2 vUV;
layout(location = 0) out vec2 outUV;
vec2 positions[6] = vec2[](
vec2(0, 0), vec2(1, 0), vec2(0, 1),
vec2(1, 0), vec2(0, 1), vec2(1, 1));
vec2 unfoveate(vec2 uv)
{
uv = 2 * uv - 1;
if (use_foveation_x && use_foveation_y)
{
uv = ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc;
}
else
{
if (use_foveation_x)
{
uv.x = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y;
}
if (use_foveation_y)
{
uv.y = (ubo.lambda * tan(ubo.a * uv + ubo.b) + ubo.xc).y;
}
}
return uv;
}
void main()
{
vec2 quad_size = 1 / vec2(nb_x, nb_y);
int cell_id = gl_VertexIndex / 6;
vec2 top_left = quad_size * vec2(cell_id % nb_x, cell_id / nb_x);
outUV = top_left + positions[gl_VertexIndex % 6] * quad_size;
gl_Position = vec4(unfoveate(outUV), 0.0, 1.0);
gl_Position = vec4(vPosition, 0.0, 1.0);
outUV = vUV;
}
#endif
+144
View File
@@ -0,0 +1,144 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "fb_body_tracker.h"
#include "spdlog/spdlog.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/xr.h"
#include <ranges>
#include <openxr/openxr.h>
static_assert(xr::fb_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
std::vector<XrFullBodyJointMETA> xr::fb_body_tracker::get_whitelisted_joints(bool full_body, bool hip)
{
auto whitelisted_joints = std::ranges::filter_view(xr::fb_body_tracker::joint_whitelist, [=](auto joint) {
if (!full_body && (joint == XR_FULL_BODY_JOINT_HIPS_META || joint >= XR_FULL_BODY_JOINT_LEFT_UPPER_LEG_META))
return false;
if (!hip && joint == XR_FULL_BODY_JOINT_HIPS_META)
return false;
return true;
});
return {whitelisted_joints.begin(), whitelisted_joints.end()};
}
xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s) :
s(s)
{
xrCreateBodyTrackerFB = inst.get_proc<PFN_xrCreateBodyTrackerFB>("xrCreateBodyTrackerFB");
xrRequestBodyTrackingFidelityMETA = inst.get_proc<PFN_xrRequestBodyTrackingFidelityMETA>("xrRequestBodyTrackingFidelityMETA");
xrLocateBodyJointsFB = inst.get_proc<PFN_xrLocateBodyJointsFB>("xrLocateBodyJointsFB");
xrDestroyBodyTrackerFB = inst.get_proc<PFN_xrDestroyBodyTrackerFB>("xrDestroyBodyTrackerFB");
}
xr::fb_body_tracker::~fb_body_tracker()
{
stop();
}
void xr::fb_body_tracker::start(bool full_body, bool hip)
{
assert(xrCreateBodyTrackerFB);
this->full_body = full_body;
this->hip = hip;
XrBodyTrackerCreateInfoFB create_info{
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_FB,
.next = nullptr,
};
create_info.bodyJointSet = full_body
? XR_BODY_JOINT_SET_FULL_BODY_META
: XR_BODY_JOINT_SET_DEFAULT_FB;
CHECK_XR(xrCreateBodyTrackerFB(s, &create_info, &handle));
// Enable IOBT.
CHECK_XR(xrRequestBodyTrackingFidelityMETA(handle, XR_BODY_TRACKING_FIDELITY_HIGH_META));
whitelisted_joints = get_whitelisted_joints(full_body, hip);
}
void xr::fb_body_tracker::stop()
{
full_body = false;
hip = false;
if (handle)
{
assert(xrDestroyBodyTrackerFB);
CHECK_XR(xrDestroyBodyTrackerFB(std::exchange(handle, nullptr)));
}
}
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)
return std::nullopt;
assert(xrLocateBodyJointsFB);
XrBodyJointsLocateInfoFB locate_info{
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_FB,
.next = nullptr,
.baseSpace = reference,
.time = time,
};
std::array<XrBodyJointLocationFB, XR_FULL_BODY_JOINT_COUNT_META> joints{};
XrBodyJointLocationsFB joint_locations{
.type = XR_TYPE_BODY_JOINT_LOCATIONS_FB,
.next = nullptr,
.jointCount = (uint32_t)(full_body ? XR_FULL_BODY_JOINT_COUNT_META : (XrFullBodyJointMETA)XR_BODY_JOINT_COUNT_FB),
.jointLocations = joints.data(),
};
if (auto res = xrLocateBodyJointsFB(handle, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("xrLocateBodyJointsFB returned {}", xr::to_string(res));
return std::nullopt;
}
if (!joint_locations.isActive)
{
spdlog::warn("Body tracker is not active.");
return std::nullopt;
}
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
int num_poses = 0;
for (auto joint: whitelisted_joints)
{
const auto & joint_loc = joints[joint];
wivrn::from_headset::body_tracking::pose pose{
.pose = joint_loc.pose,
.flags = 0,
};
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
{
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
}
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
{
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
}
poses[num_poses++] = pose;
}
return poses;
}
+71
View File
@@ -0,0 +1,71 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "wivrn_packets.h"
#include "xr/meta_body_tracking_fidelity.h"
#include <array>
#include <optional>
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
class fb_body_tracker
{
XrSession s;
XrBodyTrackerFB handle{};
PFN_xrCreateBodyTrackerFB xrCreateBodyTrackerFB{};
PFN_xrRequestBodyTrackingFidelityMETA xrRequestBodyTrackingFidelityMETA{};
PFN_xrLocateBodyJointsFB xrLocateBodyJointsFB{};
PFN_xrDestroyBodyTrackerFB xrDestroyBodyTrackerFB{};
bool full_body{};
bool hip{};
std::vector<XrFullBodyJointMETA> whitelisted_joints{};
public:
static constexpr std::array joint_whitelist{
XR_FULL_BODY_JOINT_HIPS_META,
XR_FULL_BODY_JOINT_CHEST_META,
XR_FULL_BODY_JOINT_LEFT_ARM_LOWER_META,
XR_FULL_BODY_JOINT_RIGHT_ARM_LOWER_META,
XR_FULL_BODY_JOINT_LEFT_LOWER_LEG_META,
XR_FULL_BODY_JOINT_RIGHT_LOWER_LEG_META,
XR_FULL_BODY_JOINT_LEFT_FOOT_TRANSVERSE_META,
XR_FULL_BODY_JOINT_RIGHT_FOOT_TRANSVERSE_META,
};
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();
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
+87
View File
@@ -0,0 +1,87 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "pico_body_tracker.h"
#include "spdlog/spdlog.h"
#include "xr/xr.h"
#include <openxr/openxr.h>
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
{
return xrDestroyBodyTrackerBD(id);
}
xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h)
{
id = h;
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
}
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)
return std::nullopt;
XrBodyJointsLocateInfoBD locate_info{
.type = XR_TYPE_BODY_JOINTS_LOCATE_INFO_BD,
.next = nullptr,
.baseSpace = reference,
.time = time,
};
std::array<XrBodyJointLocationBD, XR_BODY_JOINT_COUNT_BD> joints{};
XrBodyJointLocationsBD joint_locations{
.type = XR_TYPE_BODY_JOINT_LOCATIONS_BD,
.next = nullptr,
.jointLocationCount = joints.size(),
.jointLocations = joints.data(),
};
if (auto res = xrLocateBodyJointsBD(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("Unable to get body joints: xrLocateBodyJointsBD returned {}", xr::to_string(res));
return std::nullopt;
}
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
int num_poses = 0;
for (auto joint: joint_whitelist)
{
const auto & joint_loc = joints[joint];
wivrn::from_headset::body_tracking::pose pose{
.pose = joint_loc.pose,
.flags = 0,
};
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
poses[num_poses++] = pose;
}
return poses;
}
+55
View File
@@ -0,0 +1,55 @@
/*
* WiVRn VR streaming
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "utils/handle.h"
#include "wivrn_packets.h"
#include <array>
#include <optional>
#include <openxr/openxr.h>
namespace xr
{
class instance;
XrResult destroy_pico_body_tracker(XrBodyTrackerBD);
class pico_body_tracker : public utils::handle<XrBodyTrackerBD, destroy_pico_body_tracker>
{
PFN_xrLocateBodyJointsBD xrLocateBodyJointsBD{};
public:
static constexpr std::array joint_whitelist{
XR_BODY_JOINT_PELVIS_BD,
XR_BODY_JOINT_LEFT_ELBOW_BD,
XR_BODY_JOINT_RIGHT_ELBOW_BD,
XR_BODY_JOINT_LEFT_KNEE_BD,
XR_BODY_JOINT_RIGHT_KNEE_BD,
XR_BODY_JOINT_LEFT_FOOT_BD,
XR_BODY_JOINT_RIGHT_FOOT_BD,
};
pico_body_tracker() = default;
pico_body_tracker(instance & inst, XrBodyTrackerBD h);
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
+169
View File
@@ -0,0 +1,169 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "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/session.h"
#include "xr/to_string.h"
#include <cstring>
#include <stdexcept>
#include <openxr/openxr.h>
xr::pico_face_tracker::pico_face_tracker(instance & inst, session & s_) :
s(s_)
{
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();
}
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))
{
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);
// "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
#undef MAP_EXPRESSION
out_expressions.is_valid = true;
out_expressions.is_eye_following_blendshapes_valid = true;
}
+51
View File
@@ -0,0 +1,51 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 galister <galister@librevr.org>
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
*
* 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 "wivrn_packets.h"
#include "xr/pico_eye_types.h"
#include "xr/pico_eye_types_reflection.h"
#include <openxr/openxr.h>
namespace xr
{
class instance;
class session;
class pico_face_tracker
{
PFN_xrStartEyeTrackingPICO xrStartEyeTrackingPICO{};
PFN_xrStopEyeTrackingPICO xrStopEyeTrackingPICO{};
PFN_xrSetTrackingModePICO xrSetTrackingModePICO{};
PFN_xrGetFaceTrackingDataPICO xrGetFaceTrackingDataPICO{};
XrSession s;
bool started{};
public:
pico_face_tracker() = default;
pico_face_tracker(instance & inst, session & s);
~pico_face_tracker();
void start();
void stop();
void get_weights(XrTime time, struct wivrn::from_headset::tracking::fb_face2 & out_expressions);
};
} // namespace xr
+30
View File
@@ -23,7 +23,9 @@
#include "details/enumerate.h"
#include "openxr/openxr.h"
#include "utils/contains.h"
#include "xr/fb_body_tracker.h"
#include "xr/instance.h"
#include "xr/pico_body_tracker.h"
#include "xr/system.h"
#include <ranges>
#include <vulkan/vulkan.h>
@@ -136,6 +138,34 @@ xr::htc_face_tracker xr::session::create_htc_face_tracker(XrFacialTrackingTypeHT
CHECK_XR(xrCreateFacialTrackerHTC(id, &create_info, &ft));
return {*inst, ft, facialTrackingType};
}
xr::pico_face_tracker xr::session::create_pico_face_tracker()
{
return {*inst, *this};
}
xr::fb_body_tracker xr::session::create_fb_body_tracker()
{
return {*inst, *this};
}
xr::pico_body_tracker xr::session::create_pico_body_tracker()
{
XrBodyTrackerCreateInfoBD create_info{
.type = XR_TYPE_BODY_TRACKER_CREATE_INFO_BD,
.next = nullptr,
.jointSet = XR_BODY_JOINT_SET_FULL_BODY_JOINTS_BD,
};
XrBodyTrackerBD bt;
auto xrCreateBodyTrackerBD = inst->get_proc<PFN_xrCreateBodyTrackerBD>("xrCreateBodyTrackerBD");
assert(xrCreateBodyTrackerBD);
CHECK_XR(xrCreateBodyTrackerBD(id, &create_info, &bt));
return {*inst, bt};
}
std::vector<vk::Format> xr::session::get_swapchain_formats() const
{
std::vector<vk::Format> formats;
+6
View File
@@ -26,10 +26,13 @@
#include <vulkan/vulkan_raii.hpp>
#include <openxr/openxr.h>
#include "fb_body_tracker.h"
#include "fb_face_tracker2.h"
#include "hand_tracker.h"
#include "htc_face_tracker.h"
#include "passthrough.h"
#include "pico_body_tracker.h"
#include "pico_face_tracker.h"
#include "space.h"
namespace xr
@@ -52,6 +55,9 @@ public:
hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT);
fb_face_tracker2 create_fb_face_tracker2();
htc_face_tracker create_htc_face_tracker(XrFacialTrackingTypeHTC);
pico_face_tracker create_pico_face_tracker();
fb_body_tracker create_fb_body_tracker();
pico_body_tracker create_pico_body_tracker();
std::vector<vk::Format> get_swapchain_formats() const;
+36
View File
@@ -141,6 +141,42 @@ XrSystemFacialTrackingPropertiesHTC xr::system::htc_face_tracking_properties() c
return face_tracking_prop;
}
XrSystemBodyTrackingPropertiesFB xr::system::fb_body_tracking_properties() const
{
if (!id)
throw std::invalid_argument("this");
XrSystemBodyTrackingPropertiesFB body_tracking_prop{
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_FB,
};
XrSystemProperties prop{
.type = XR_TYPE_SYSTEM_PROPERTIES,
.next = &body_tracking_prop,
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return body_tracking_prop;
}
XrSystemBodyTrackingPropertiesBD xr::system::bd_body_tracking_properties() const
{
if (!id)
throw std::invalid_argument("this");
XrSystemBodyTrackingPropertiesBD body_tracking_prop{
.type = XR_TYPE_SYSTEM_BODY_TRACKING_PROPERTIES_BD,
};
XrSystemProperties prop{
.type = XR_TYPE_SYSTEM_PROPERTIES,
.next = &body_tracking_prop,
};
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
return body_tracking_prop;
}
xr::system::passthrough_type xr::system::passthrough_supported() const
{
if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
+2
View File
@@ -64,6 +64,8 @@ public:
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_interaction_properties() const;
XrSystemFaceTrackingProperties2FB fb_face_tracking2_properties() const;
XrSystemFacialTrackingPropertiesHTC htc_face_tracking_properties() const;
XrSystemBodyTrackingPropertiesFB fb_body_tracking_properties() const;
XrSystemBodyTrackingPropertiesBD bd_body_tracking_properties() const;
passthrough_type passthrough_supported() const;
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
-27
View File
@@ -1,27 +0,0 @@
/*
* 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/>.
*/
#include "xr.h"
#include "spdlog/fmt/fmt.h"
std::string xr::to_string(XrVersion version)
{
return fmt::format("{}.{}.{}", XR_VERSION_MAJOR(version), XR_VERSION_MINOR(version), XR_VERSION_PATCH(version));
}
+1 -33
View File
@@ -26,36 +26,4 @@
#include "swapchain.h"
#include "system.h"
#include "xr/check.h"
#include <cstddef>
#include <string>
#include <openxr/openxr_reflection.h>
namespace xr
{
#define XR_ENUM_CASE_STR(name, val) \
case name: \
return #name;
#define XR_ENUM_STR(enumType) \
constexpr const char * to_string(enumType e) \
{ \
switch (e) \
{ \
XR_LIST_ENUM_##enumType(XR_ENUM_CASE_STR) default : return "Unknown"; \
} \
}
XR_ENUM_STR(XrResult);
XR_ENUM_STR(XrFormFactor);
XR_ENUM_STR(XrViewConfigurationType);
XR_ENUM_STR(XrEnvironmentBlendMode);
XR_ENUM_STR(XrReferenceSpaceType);
XR_ENUM_STR(XrActionType);
XR_ENUM_STR(XrEyeVisibility);
XR_ENUM_STR(XrSessionState);
XR_ENUM_STR(XrObjectType);
XR_ENUM_STR(XrStructureType);
std::string to_string(XrVersion version);
} // namespace xr
#include "xr/to_string.h"