Send both min and max prediction times

This commit is contained in:
Patrick Nicolas
2025-01-30 08:58:31 +01:00
parent b97c8b29b5
commit 06b5fd7e6c
5 changed files with 18 additions and 17 deletions
+1 -1
View File
@@ -327,7 +327,7 @@ std::vector<XrCompositionLayerQuad> scenes::stream::plot_performance_metrics(XrT
ImPlot::PopStyleColor(5); ImPlot::PopStyleColor(5);
{ {
std::lock_guard lock(tracking_control_mutex); std::lock_guard lock(tracking_control_mutex);
ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), std::chrono::duration_cast<std::chrono::milliseconds>(tracking_control.offset).count()).c_str()); ImGui::Text("%s", fmt::format(_F("Estimated motion to photons latency: {}ms"), std::chrono::duration_cast<std::chrono::milliseconds>(tracking_control.max_offset).count()).c_str());
} }
ImGui::End(); ImGui::End();
+5 -14
View File
@@ -192,7 +192,6 @@ void scenes::stream::tracking()
XrTime last_hand_sample = t0; XrTime last_hand_sample = t0;
std::vector<from_headset::tracking> tracking; std::vector<from_headset::tracking> tracking;
std::vector<from_headset::hand_tracking> hands; std::vector<from_headset::hand_tracking> hands;
int skip_samples = 0;
const bool hand_tracking = config.check_feature(feature::hand_tracking); const bool hand_tracking = config.check_feature(feature::hand_tracking);
const bool face_tracking = config.check_feature(feature::face_tracking); const bool face_tracking = config.check_feature(feature::face_tracking);
@@ -220,9 +219,11 @@ void scenes::stream::tracking()
control = tracking_control; control = tracking_control;
} }
XrDuration prediction = std::clamp<XrDuration>(control.offset.count(), 0, 80'000'000); XrDuration prediction = std::clamp<XrDuration>(control.max_offset.count(), 0, 80'000'000);
auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000); auto period = std::max<XrDuration>(display_time_period.load(), 1'000'000);
for (XrDuration Δt = 0; Δt <= prediction + period / 2; Δt += period, ++samples) for (XrDuration Δt = display_time_phase - t0 % period + (control.min_offset.count() / period) * period;
Δt <= prediction + period / 2;
Δt += period, ++samples)
{ {
auto & packet = tracking.emplace_back(); auto & packet = tracking.emplace_back();
packet.production_timestamp = t0; packet.production_timestamp = t0;
@@ -283,23 +284,12 @@ 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 + skip_samples * period;
}
} }
XrDuration busy_time = t.count(); XrDuration busy_time = t.count();
// Target: polling between 1 and 5ms, with 20% busy time // Target: polling between 1 and 5ms, with 20% busy time
tracking_period = std::clamp<XrDuration>(std::lerp(tracking_period, busy_time * 5, 0.2), min_tracking_period, max_tracking_period); tracking_period = std::clamp<XrDuration>(std::lerp(tracking_period, busy_time * 5, 0.2), min_tracking_period, max_tracking_period);
if (samples and busy_time / samples > 2'000'000)
{
skip_samples = busy_time / 2'000'000;
}
#ifdef __ANDROID__ #ifdef __ANDROID__
if (next_battery_check < now and control.enabled[size_t(tid::battery)]) if (next_battery_check < now and control.enabled[size_t(tid::battery)])
{ {
@@ -363,4 +353,5 @@ void scenes::stream::operator()(to_headset::tracking_control && packet)
audio_handle->set_mic_sate(packet.enabled[m]); audio_handle->set_mic_sate(packet.enabled[m]);
tracking_control = packet; tracking_control = packet;
tracking_control.min_offset = std::min(tracking_control.min_offset, tracking_control.max_offset);
} }
+2 -1
View File
@@ -483,7 +483,8 @@ struct tracking_control
last = microphone, last = microphone,
}; };
std::chrono::nanoseconds offset; std::chrono::nanoseconds min_offset;
std::chrono::nanoseconds max_offset;
std::array<bool, size_t(id::last) + 1> enabled; std::array<bool, size_t(id::last) + 1> enabled;
}; };
+2 -1
View File
@@ -104,7 +104,8 @@ void wivrn::tracking_control_t::send(wivrn_connection & connection, bool now)
return; return;
connection.send_stream(to_headset::tracking_control{ connection.send_stream(to_headset::tracking_control{
.offset = std::chrono::nanoseconds(max.exchange(0)), .min_offset = std::chrono::nanoseconds(min.exchange(80'000'000)),
.max_offset = std::chrono::nanoseconds(max.exchange(0)),
.enabled = enabled, .enabled = enabled,
}); });
if (not now) if (not now)
+8
View File
@@ -50,6 +50,7 @@ struct wivrn_comp_target_factory;
class tracking_control_t class tracking_control_t
{ {
using T = std::chrono::nanoseconds::rep; using T = std::chrono::nanoseconds::rep;
std::atomic<T> min;
std::atomic<T> max; std::atomic<T> max;
std::chrono::steady_clock::time_point next_sample; std::chrono::steady_clock::time_point next_sample;
std::mutex mutex; std::mutex mutex;
@@ -68,6 +69,13 @@ public:
while (prev < sample and max.compare_exchange_weak(prev, sample)) while (prev < sample and max.compare_exchange_weak(prev, sample))
{ {
} }
if (sample > 0)
{
prev = min;
while (prev > sample and min.compare_exchange_weak(prev, sample))
{
}
}
} }
void send(wivrn_connection & connection, bool now = false); void send(wivrn_connection & connection, bool now = false);