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/check.h"
#include "xr/htc_exts.h"
#include "xr/htc_face_tracker.h"
#include "xr/meta_body_tracking_fidelity.h"
#include "xr/to_string.h"
#include <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);
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();
spdlog::info("{} reference spaces", spaces.size());
@@ -1289,11 +1303,6 @@ void application::initialize()
spdlog::info(" {}", xr::to_string(i));
}
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
config.emplace(xr_system_id);
vk::CommandPoolCreateInfo cmdpool_create_info;
cmdpool_create_info.queueFamilyIndex = vk_queue_family_index;
cmdpool_create_info.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer;
+21 -31
View File
@@ -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,
+3 -9
View File
@@ -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);
};