From bd264e23b6855e10fe9d56ceec8955f820278bda Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 30 Jan 2026 10:34:43 +0100 Subject: [PATCH] Limit extrapolation based on production time --- server/driver/polynomial_interpolator.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/driver/polynomial_interpolator.h b/server/driver/polynomial_interpolator.h index 0a669257..94504482 100644 --- a/server/driver/polynomial_interpolator.h +++ b/server/driver/polynomial_interpolator.h @@ -33,6 +33,7 @@ #include #include "openxr/openxr.h" +#include "wivrn_config.h" template class polynomial_interpolator @@ -104,7 +105,11 @@ public: Eigen::Matrix A; Eigen::Matrix b; - XrTime production_timestamp = std::numeric_limits::lowest(); + const XrTime production_timestamp = std::ranges::max(data | std::ranges::views::transform(&sample::production_timestamp)); + // Maximum is the minimum of now + max_extrapolation_ns (outside of this function) + // and production_ts + 1.1 * max_extrapolation_ns + // This allows a small buffer so that polynomial extrapolation fills the gap of networking hiccups + timestamp = std::min(timestamp, production_timestamp + (wivrn::max_extrapolation_ns * 11) / 10); int row = 0; for (const auto && [i, sample]: std::ranges::enumerate_view(data)) @@ -116,8 +121,6 @@ public: float weight = 1. / (1. + std::pow(abs_Δt / float(window), 3.)); - production_timestamp = std::max(production_timestamp, sample.production_timestamp); - float Δt = (sample.timestamp - timestamp) * 1.e-9; float Δtⁱ = 1; for (int i = 0; i <= polynomial_order; ++i)