Sync predictions with display time
This commit is contained in:
@@ -353,6 +353,9 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
if (exiting)
|
||||
application::pop_scene();
|
||||
|
||||
display_time_phase = frame_state.predictedDisplayTime % frame_state.predictedDisplayPeriod;
|
||||
display_time_period = frame_state.predictedDisplayPeriod;
|
||||
|
||||
std::shared_lock lock(decoder_mutex);
|
||||
if (decoders.empty() or not frame_state.shouldRender)
|
||||
{
|
||||
|
||||
@@ -80,7 +80,9 @@ private:
|
||||
std::thread network_thread;
|
||||
std::mutex local_floor_mutex;
|
||||
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::shared_mutex decoder_mutex;
|
||||
|
||||
@@ -193,8 +193,9 @@ void scenes::stream::tracking()
|
||||
timer t(instance);
|
||||
|
||||
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
|
||||
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::fb_face2 fb_face2{};
|
||||
@@ -264,6 +265,10 @@ void scenes::stream::tracking()
|
||||
e.code().value() != XR_ERROR_TIME_INVALID)
|
||||
throw;
|
||||
}
|
||||
|
||||
// Make sure predictions are phase-synced with display time
|
||||
if (Δt == 0 and prediction)
|
||||
Δt = display_time_phase - t0 % period;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
Reference in New Issue
Block a user