Sync predictions with display time
This commit is contained in:
@@ -353,6 +353,9 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
|||||||
if (exiting)
|
if (exiting)
|
||||||
application::pop_scene();
|
application::pop_scene();
|
||||||
|
|
||||||
|
display_time_phase = frame_state.predictedDisplayTime % frame_state.predictedDisplayPeriod;
|
||||||
|
display_time_period = frame_state.predictedDisplayPeriod;
|
||||||
|
|
||||||
std::shared_lock lock(decoder_mutex);
|
std::shared_lock lock(decoder_mutex);
|
||||||
if (decoders.empty() or not frame_state.shouldRender)
|
if (decoders.empty() or not frame_state.shouldRender)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ private:
|
|||||||
std::thread network_thread;
|
std::thread network_thread;
|
||||||
std::mutex local_floor_mutex;
|
std::mutex local_floor_mutex;
|
||||||
xr::space local_floor;
|
xr::space local_floor;
|
||||||
std::atomic<std::chrono::nanoseconds::rep> tracking_prediction_offset;
|
std::atomic<std::chrono::nanoseconds::rep> tracking_prediction_offset = 0;
|
||||||
|
std::atomic<XrDuration> display_time_phase = 0;
|
||||||
|
std::atomic<XrDuration> display_time_period = 0;
|
||||||
std::optional<std::thread> tracking_thread;
|
std::optional<std::thread> tracking_thread;
|
||||||
|
|
||||||
std::shared_mutex decoder_mutex;
|
std::shared_mutex decoder_mutex;
|
||||||
|
|||||||
@@ -193,8 +193,9 @@ void scenes::stream::tracking()
|
|||||||
timer t(instance);
|
timer t(instance);
|
||||||
|
|
||||||
XrDuration prediction = std::min<XrDuration>(tracking_prediction_offset, 80'000'000);
|
XrDuration prediction = std::min<XrDuration>(tracking_prediction_offset, 80'000'000);
|
||||||
|
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
|
||||||
// 1 or 2 samples
|
// 1 or 2 samples
|
||||||
for (XrDuration Δt = 0; Δt <= prediction; Δt += std::max<XrDuration>(1, prediction))
|
for (XrDuration Δt = 0; Δt <= prediction + period / 2; Δt += period)
|
||||||
{
|
{
|
||||||
from_headset::hand_tracking hands{};
|
from_headset::hand_tracking hands{};
|
||||||
from_headset::fb_face2 fb_face2{};
|
from_headset::fb_face2 fb_face2{};
|
||||||
@@ -264,6 +265,10 @@ void scenes::stream::tracking()
|
|||||||
e.code().value() != XR_ERROR_TIME_INVALID)
|
e.code().value() != XR_ERROR_TIME_INVALID)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure predictions are phase-synced with display time
|
||||||
|
if (Δt == 0 and prediction)
|
||||||
|
Δt = display_time_phase - t0 % period;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
|||||||
+13
-4
@@ -61,10 +61,19 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only keep one predicted value
|
// Discard outdated predictions
|
||||||
// It should be the last one
|
if (t != produced)
|
||||||
if (not data.empty() and t != produced and data.back().at_timestamp_ns != data.back().produced_timestamp)
|
{
|
||||||
data.pop_back();
|
for (auto it = data.begin(); it != data.end();)
|
||||||
|
{
|
||||||
|
if (it->at_timestamp_ns == it->produced_timestamp // not a prediction
|
||||||
|
or it->produced_timestamp >= produced // recent prediction
|
||||||
|
or it->at_timestamp_ns > t + 1'000'000) // we don't have far enough data yet
|
||||||
|
++it;
|
||||||
|
else
|
||||||
|
it = data.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Insert the new sample
|
// Insert the new sample
|
||||||
auto it = std::lower_bound(data.begin(), data.end(), t, [](TimedData & sample, uint64_t t) { return sample.at_timestamp_ns < t; });
|
auto it = std::lower_bound(data.begin(), data.end(), t, [](TimedData & sample, uint64_t t) { return sample.at_timestamp_ns < t; });
|
||||||
|
|||||||
Reference in New Issue
Block a user