Fix HTC face tracker

The tracker must be created precisely between the session creation and
session begin, or else it would fail when we access it with
XR_RUNTIME_FAILURE.
As it is not possible to recreate one later, disable the destroy and
store the handles in static variables so we can access them later,
behaving as if we were actually destroying and recreating one.
This commit is contained in:
Patrick Nicolas
2025-08-20 22:11:43 +02:00
parent bebd2cd97e
commit b5e5586ef6
3 changed files with 38 additions and 45 deletions
+14 -5
View File
@@ -32,6 +32,7 @@
#include "xr/actionset.h" #include "xr/actionset.h"
#include "xr/check.h" #include "xr/check.h"
#include "xr/htc_exts.h" #include "xr/htc_exts.h"
#include "xr/htc_face_tracker.h"
#include "xr/meta_body_tracking_fidelity.h" #include "xr/meta_body_tracking_fidelity.h"
#include "xr/to_string.h" #include "xr/to_string.h"
#include <algorithm> #include <algorithm>
@@ -1282,6 +1283,19 @@ void application::initialize()
xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index); xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue, vk_queue_family_index);
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
config.emplace(xr_system_id);
// HTC face tracker fails if created later
// we can destroy it right away, it actually stores static handles
if (xr_system_id.face_tracker_supported() == xr::face_tracker_type::htc)
{
auto props = xr_system_id.htc_face_tracking_properties();
xr::htc_face_tracker(xr_instance, xr_session, props.supportEyeFacialTracking, props.supportLipFacialTracking);
}
{ {
auto spaces = xr_session.get_reference_spaces(); auto spaces = xr_session.get_reference_spaces();
spdlog::info("{} reference spaces", spaces.size()); spdlog::info("{} reference spaces", spaces.size());
@@ -1289,11 +1303,6 @@ void application::initialize()
spdlog::info(" {}", xr::to_string(i)); spdlog::info(" {}", xr::to_string(i));
} }
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
config.emplace(xr_system_id);
vk::CommandPoolCreateInfo cmdpool_create_info; vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index; cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer; cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
+21 -31
View File
@@ -18,53 +18,43 @@
*/ */
#include "htc_face_tracker.h" #include "htc_face_tracker.h"
#include "wivrn_packets.h"
#include "xr/instance.h" #include "xr/instance.h"
#include "xr/session.h" #include "xr/session.h"
#include <openxr/openxr.h> #include <openxr/openxr.h>
xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) : static XrFacialTrackerHTC make_tracker(xr::instance & inst, xr::session & s, XrFacialTrackingTypeHTC type)
s(s)
{ {
if (!eye && !lip)
return;
xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
xrGetFacialExpressionsHTC = inst.get_proc<PFN_xrGetFacialExpressionsHTC>("xrGetFacialExpressionsHTC");
xrDestroyFacialTrackerHTC = inst.get_proc<PFN_xrDestroyFacialTrackerHTC>("xrDestroyFacialTrackerHTC");
XrFacialTrackerCreateInfoHTC create_info{ XrFacialTrackerCreateInfoHTC create_info{
.type = XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC, .type = XR_TYPE_FACIAL_TRACKER_CREATE_INFO_HTC,
.next = nullptr, .facialTrackingType = type,
}; };
auto xrCreateFacialTrackerHTC = inst.get_proc<PFN_xrCreateFacialTrackerHTC>("xrCreateFacialTrackerHTC");
if (eye) XrFacialTrackerHTC id;
{ CHECK_XR(xrCreateFacialTrackerHTC(s, &create_info, &id));
create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC; return id;
xrCreateFacialTrackerHTC(s, &create_info, &this->eye);
}
if (lip)
{
create_info.facialTrackingType = XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC;
xrCreateFacialTrackerHTC(s, &create_info, &this->lip);
}
} }
xr::htc_face_tracker::~htc_face_tracker() static XrFacialTrackerHTC get_eye_tracker(xr::instance & inst, xr::session & s)
{ {
if (!xrDestroyFacialTrackerHTC) static XrFacialTrackerHTC res = make_tracker(inst, s, XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC);
return; 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) xr::htc_face_tracker::htc_face_tracker(instance & inst, session & s, bool eye, bool lip) :
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(eye, nullptr))); xrGetFacialExpressionsHTC(inst.get_proc<PFN_xrGetFacialExpressionsHTC>("xrGetFacialExpressionsHTC")),
if (lip) eye(eye ? get_eye_tracker(inst, s) : XR_NULL_HANDLE),
CHECK_XR(xrDestroyFacialTrackerHTC(std::exchange(lip, nullptr))); lip(lip ? get_lip_tracker(inst, s) : XR_NULL_HANDLE)
{
} }
void xr::htc_face_tracker::get_weights(XrTime time, packet_type & out_expressions) void xr::htc_face_tracker::get_weights(XrTime time, packet_type & out_expressions)
{ {
if (!(eye || lip) || !xrGetFacialExpressionsHTC) assert(xrGetFacialExpressionsHTC);
return;
XrFacialExpressionsHTC expressions{ XrFacialExpressionsHTC expressions{
.type = XR_TYPE_FACIAL_EXPRESSIONS_HTC, .type = XR_TYPE_FACIAL_EXPRESSIONS_HTC,
+3 -9
View File
@@ -19,7 +19,6 @@
#pragma once #pragma once
#include "utils/handle.h"
#include "wivrn_packets.h" #include "wivrn_packets.h"
#include <openxr/openxr.h> #include <openxr/openxr.h>
@@ -30,18 +29,13 @@ class session;
class htc_face_tracker class htc_face_tracker
{ {
XrSession s; PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC;
XrFacialTrackerHTC eye{}; XrFacialTrackerHTC eye;
XrFacialTrackerHTC lip{}; XrFacialTrackerHTC lip;
PFN_xrCreateFacialTrackerHTC xrCreateFacialTrackerHTC{};
PFN_xrGetFacialExpressionsHTC xrGetFacialExpressionsHTC{};
PFN_xrDestroyFacialTrackerHTC xrDestroyFacialTrackerHTC{};
public: public:
using packet_type = wivrn::from_headset::tracking::htc_face; 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(instance & inst, session & s, bool eye, bool lip);
~htc_face_tracker();
void get_weights(XrTime time, packet_type & out_expressions); void get_weights(XrTime time, packet_type & out_expressions);
}; };