From 0fb50259978cffce4b896ea032df23a524bcffd6 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 16 Aug 2023 12:51:15 +0100 Subject: [PATCH] d/steamvr_lh: Only use the relation history buffer for poses Also enables prediction to be toggled on. --- src/xrt/drivers/steamvr_lh/device.cpp | 28 +++++++++++++++++++-------- src/xrt/drivers/steamvr_lh/device.hpp | 6 ++++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/xrt/drivers/steamvr_lh/device.cpp b/src/xrt/drivers/steamvr_lh/device.cpp index 4cd27d893..9246fc3d3 100644 --- a/src/xrt/drivers/steamvr_lh/device.cpp +++ b/src/xrt/drivers/steamvr_lh/device.cpp @@ -38,6 +38,7 @@ #define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) DEBUG_GET_ONCE_BOOL_OPTION(lh_emulate_hand, "LH_EMULATE_HAND", true) +DEBUG_GET_ONCE_BOOL_OPTION(lh_prediction, "LH_PREDICTION", false) // Each device will have its own input class. struct InputClass @@ -312,8 +313,9 @@ ControllerDevice::update_hand_tracking(struct xrt_hand_joint_set *out) auto curl_values = u_hand_tracking_curl_values{pinky, ring, middle, index, thumb}; struct xrt_space_relation hand_relation = {}; - - m_relation_history_get(relation_hist, last_pose_timestamp, &hand_relation); + uint64_t last_ns{0}; // Not used. + // Currently we only return the latest pose. + m_relation_history_get_latest(relation_hist, &last_ns, &hand_relation); u_hand_sim_simulate_for_valve_index_knuckles(&curl_values, get_xrt_hand(), &hand_relation, out); @@ -396,19 +398,29 @@ ControllerDevice::get_hand_tracking(enum xrt_input_name name, *out_timestamp_ns = hand_tracking_timestamp; } +void +Device::get_pose(uint64_t at_timestamp_ns, xrt_space_relation *out_relation) +{ + if (debug_get_bool_option_lh_prediction()) { + m_relation_history_get(this->relation_hist, at_timestamp_ns, out_relation); + } else { + // Without prediction just use the latest, also disables history. + uint64_t last_ns{0}; // Not used. + m_relation_history_get_latest(this->relation_hist, &last_ns, out_relation); + } +} + void HmdDevice::get_tracked_pose(xrt_input_name name, uint64_t at_timestamp_ns, xrt_space_relation *out_relation) { - *out_relation = relation; - // TODO: figure this out, it's not doing anything like this - // at_timestamp_ns += vsync_to_photon_ns == 0.f ? 11000000L : static_cast(vsync_to_photon_ns); + Device::get_pose(at_timestamp_ns, out_relation); } void ControllerDevice::get_tracked_pose(xrt_input_name name, uint64_t at_timestamp_ns, xrt_space_relation *out_relation) { xrt_space_relation rel = {}; - m_relation_history_get(relation_hist, last_pose_timestamp, &rel); + Device::get_pose(at_timestamp_ns, &rel); xrt_pose pose_offset = XRT_POSE_IDENTITY; vive_poses_get_pose_offset(input_class->name, device_type, name, &pose_offset); @@ -633,11 +645,11 @@ Device::update_pose(const vr::DriverPose_t &newPose) } else { relation.relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; } - this->relation = relation; + uint64_t ts = chrono_timestamp_ns(); uint64_t ts_offset = static_cast(newPose.poseTimeOffset * 1000000.0); ts += ts_offset; - last_pose_timestamp = ts; + m_relation_history_push(relation_hist, &relation, ts); } diff --git a/src/xrt/drivers/steamvr_lh/device.hpp b/src/xrt/drivers/steamvr_lh/device.hpp index 3145c08d8..a3e236d4a 100644 --- a/src/xrt/drivers/steamvr_lh/device.hpp +++ b/src/xrt/drivers/steamvr_lh/device.hpp @@ -40,7 +40,6 @@ class Device : public xrt_device { public: - xrt_space_relation relation = XRT_SPACE_RELATION_ZERO; m_relation_history *relation_hist; virtual ~Device(); @@ -54,6 +53,10 @@ public: void update_pose(const vr::DriverPose_t &newPose); + //! Helper to access the @ref relation_hist member. + void + get_pose(uint64_t at_timestamp_ns, xrt_space_relation *out_relation); + void handle_properties(const vr::PropertyWrite_t *batch, uint32_t count); @@ -70,7 +73,6 @@ protected: inline static xrt_vec3 chaperone_center{}; inline static xrt_quat chaperone_yaw = XRT_QUAT_IDENTITY; const InputClass *input_class; - uint64_t last_pose_timestamp{0}; float vsync_to_photon_ns{0.f};