Store eye gaze relative to view

This commit is contained in:
Patrick Nicolas committed 2026-02-04 09:37:26 +01:00
1 parent 02b212483c
commit 67f4ced505
8 files changed
+58 -54

No files matched your search

+8 -25
View File
@@ -366,21 +366,6 @@ void scenes::stream::tracking()
if (not std::ranges::contains(pattern, device_id::HEAD, &to_headset::tracking_control::sample::device))
pattern.push_back({.device = device_id::HEAD});
// FIXME: eye tracking shouldn't had a special case
// eye-tracked foveation needs eye and head pose in the same tracking packet
if (spaces[device_id::EYE_GAZE])
{
size_t sz = pattern.size();
for (size_t i = 0; i < sz; ++i)
{
if (pattern[i].device == device_id::HEAD)
pattern.push_back({
.device = device_id::EYE_GAZE,
.prediction_ns = pattern[i].prediction_ns,
});
}
}
if (hand_tracking)
{
if (std::ranges::contains(pattern, device_id::LEFT_HAND, &to_headset::tracking_control::sample::device))
@@ -478,12 +463,13 @@ void scenes::stream::tracking()
const auto & item = pattern[pattern_position];
auto at_time = t0 + item.prediction_ns;
// Don't merge items that are too far from the current one
if (std::abs(tracking.timestamp - at_time) > 1'000'000)
break;
switch (item.device)
{
case device_id::HEAD:
// Don't merge items that are too far from the current one
if (std::abs(tracking.timestamp - at_time) > 1'000'000)
goto subpattern_end;
tracking.view_flags = session.locate_views(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, tracking.timestamp, view_space, views);
assert(views.size() == tracking.views.size());
for (auto [i, j]: std::views::zip(views, tracking.views))
@@ -503,15 +489,13 @@ void scenes::stream::tracking()
case wivrn::device_id::LEFT_POKE:
case wivrn::device_id::RIGHT_PINCH_POSE:
case wivrn::device_id::RIGHT_POKE:
case wivrn::device_id::EYE_GAZE:
// Don't merge items that are too far from the current one
if (std::abs(tracking.timestamp - at_time) > 1'000'000)
goto subpattern_end;
locate_spaces.add_space(item.device, spaces[item.device], tracking.timestamp, tracking.device_poses);
break;
case wivrn::device_id::EYE_GAZE:
// Eye gaze uses view pose as the origin
tracking.device_poses.push_back(locate_space(item.device, spaces[item.device], spaces[wivrn::device_id::HEAD], tracking.timestamp));
break;
case wivrn::device_id::FACE:
if (std::abs(tracking.timestamp - at_time) > 1'000'000)
goto subpattern_end;
std::visit(utils::overloaded{
[](std::monostate &) {},
[&](auto & ft) {
@@ -557,7 +541,6 @@ void scenes::stream::tracking()
break;
}
}
subpattern_end:
locate_spaces.resolve(session, tracking.timestamp, tracking.device_poses);
}
catch (const std::system_error & e)
+1 -1
View File
@@ -39,7 +39,7 @@
namespace wivrn
{
static constexpr int protocol_revision = 0;
static constexpr int protocol_revision = 1;
enum class device_id : uint8_t
{
+9 -2
View File
@@ -67,6 +67,13 @@ void wivrn::tracking_control::resolve(XrDuration frame_time, XrDuration latency)
XrDuration step = frame_time;
switch (device_id(device))
{
// High frequency, but not extrapolation
case device_id::EYE_GAZE:
req.min_prediction = latency;
req.max_prediction = frame_time + latency;
step = 3'000'000;
break;
// High frequency polling for those
case device_id::HEAD:
case device_id::LEFT_GRIP:
@@ -77,11 +84,11 @@ void wivrn::tracking_control::resolve(XrDuration frame_time, XrDuration latency)
case device_id::RIGHT_PALM:
case device_id::LEFT_PINCH_POSE:
case device_id::RIGHT_PINCH_POSE:
case device_id::EYE_GAZE:
step = 3'000'000;
break;
// Face tracking can't extrapolate
case device_id::FACE:
// Face tracking can't extrapolate
res.pattern.push_back({
.device = device_id(device),
.prediction_ns = 0,
+7
View File
@@ -651,6 +651,13 @@ static void comp_wivrn_flush(struct comp_target * ct)
r->StartFrameCapture(NULL, NULL);
#endif
if (cn->cnx.get_info().eye_gaze)
{
// FIXME: actually get the gaze data here
auto now = os_monotonic_get_ns();
cn->cnx.add_tracking_request(device_id::EYE_GAZE, cn->c->base.layer_accum.data.display_time_ns, now, now);
}
vk::CommandBuffer cmd;
// apply foveation for current frame
if (cn->c->base.frame_params.one_projection_layer_fast_path)
+6 -2
View File
@@ -34,13 +34,13 @@
namespace wivrn
{
wivrn_eye_tracker::wivrn_eye_tracker(xrt_device * hmd, wivrn_session & cnx) :
wivrn_eye_tracker::wivrn_eye_tracker(wivrn_session & cnx) :
xrt_device{
.name = XRT_DEVICE_EYE_GAZE_INTERACTION,
.device_type = XRT_DEVICE_TYPE_EYE_TRACKER,
.str = "WiVRn Eye Tracker",
.serial = "WiVRn Eye Tracker",
.tracking_origin = hmd->tracking_origin,
.tracking_origin = &origin,
.input_count = 1,
.inputs = &gaze_input,
.supported = {
@@ -50,6 +50,10 @@ wivrn_eye_tracker::wivrn_eye_tracker(xrt_device * hmd, wivrn_session & cnx) :
.get_tracked_pose = method_pointer<&wivrn_eye_tracker::get_tracked_pose>,
.destroy = [](xrt_device *) {},
},
origin{
.type = XRT_TRACKING_TYPE_ATTACHABLE,
.initial_offset = XRT_POSE_IDENTITY,
},
gaze_input{
.active = true,
.name = XRT_INPUT_GENERIC_EYE_GAZE_POSE,
+3 -1
View File
@@ -24,6 +24,7 @@
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_tracking.h"
#include <cstdint>
#include <mutex>
@@ -34,6 +35,7 @@ class wivrn_session;
class wivrn_eye_tracker : public xrt_device
{
xrt_tracking_origin origin;
std::mutex mutex;
xrt_input gaze_input;
pose_list gaze;
@@ -41,7 +43,7 @@ class wivrn_eye_tracker : public xrt_device
public:
using base = xrt_device;
wivrn_eye_tracker(xrt_device * hmd, wivrn_session &);
wivrn_eye_tracker(wivrn_session &);
xrt_result_t update_inputs();
void update_tracking(const from_headset::tracking &, const clock_offset &);
+6 -22
View File
@@ -22,7 +22,6 @@
#include "wivrn_foveation.h"
#include "driver/xrt_cast.h"
#include "math/m_api.h"
#include "utils/wivrn_vk_bundle.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
@@ -347,26 +346,12 @@ void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, c
const uint8_t orientation_ok = from_headset::tracking::orientation_valid | from_headset::tracking::orientation_tracked;
eye_x[0] = tracking.views[0].pose.position.x;
eye_x[1] = tracking.views[1].pose.position.x;
std::optional<xrt_quat> head;
for (const auto & pose: tracking.device_poses)
if (tracking.view_flags & XR_VIEW_STATE_POSITION_VALID_BIT)
{
if (pose.device != device_id::HEAD)
continue;
if ((pose.flags & orientation_ok) != orientation_ok)
return;
head = xrt_cast(pose.pose.orientation);
break;
eye_x[0] = tracking.views[0].pose.position.x;
eye_x[1] = tracking.views[1].pose.position.x;
}
if (!head.has_value())
return;
for (const auto & pose: tracking.device_poses)
{
if (pose.device != device_id::EYE_GAZE)
@@ -375,9 +360,8 @@ void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, c
if ((pose.flags & orientation_ok) != orientation_ok)
return;
xrt_quat qgaze = xrt_cast(pose.pose.orientation);
math_quat_unrotate(&qgaze, &head.value(), &gaze);
break;
gaze = xrt_cast(pose.pose.orientation);
return;
}
}
@@ -399,7 +383,7 @@ static void fill_ubo(
bool flip,
size_t offset,
size_t size,
int count)
[[maybe_unused]] int count)
{
assert(params.size() % 2 == 1);
const int n_ratio = (params.size() - 1) / 2;
+18 -1
View File
@@ -216,7 +216,8 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
#endif
if (get_info().eye_gaze || is_forced_extension("EXT_eye_gaze_interaction"))
{
eye_tracker = std::make_unique<wivrn_eye_tracker>(&hmd, *this);
// The tracker space needs to be attached to the head pose once the space overseer is created
eye_tracker = std::make_unique<wivrn_eye_tracker>(*this);
static_roles.eyes = eye_tracker.get();
xdevs[xdev_count++] = eye_tracker.get();
}
@@ -367,6 +368,22 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
out_xspovrs);
self->space_overseer = *out_xspovrs;
if (self->eye_tracker)
{
xrt_space * head_space;
auto res = xrt_space_overseer_create_pose_space(self->space_overseer, &self->hmd, XRT_INPUT_GENERIC_HEAD_POSE, &head_space);
if (res == XRT_SUCCESS)
{
res = xrt_space_overseer_attach_device(self->space_overseer, self->eye_tracker.get(), head_space);
xrt_space_reference(&head_space, NULL);
}
if (res != XRT_SUCCESS)
{
U_LOG_W("failed to initialize eye tracker");
self->eye_tracker = nullptr;
}
}
auto dump_file = std::getenv("WIVRN_DUMP_TIMINGS");
if (dump_file)
{