tracking frequency is now a divisor of display period
This commit is contained in:
@@ -455,6 +455,8 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
|||||||
|
|
||||||
display_time_phase = frame_state.predictedDisplayTime % frame_state.predictedDisplayPeriod;
|
display_time_phase = frame_state.predictedDisplayTime % frame_state.predictedDisplayPeriod;
|
||||||
display_time_period = frame_state.predictedDisplayPeriod;
|
display_time_period = frame_state.predictedDisplayPeriod;
|
||||||
|
real_display_period = last_display_time ? frame_state.predictedDisplayTime - last_display_time : frame_state.predictedDisplayPeriod;
|
||||||
|
last_display_time = frame_state.predictedDisplayTime;
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ private:
|
|||||||
std::atomic<bool> recenter_requested = false;
|
std::atomic<bool> recenter_requested = false;
|
||||||
std::atomic<XrDuration> display_time_phase = 0;
|
std::atomic<XrDuration> display_time_phase = 0;
|
||||||
std::atomic<XrDuration> display_time_period = 0;
|
std::atomic<XrDuration> display_time_period = 0;
|
||||||
|
XrTime last_display_time = 0;
|
||||||
|
std::atomic<XrDuration> real_display_period = 0;
|
||||||
std::optional<std::thread> tracking_thread;
|
std::optional<std::thread> tracking_thread;
|
||||||
|
|
||||||
std::shared_mutex decoder_mutex;
|
std::shared_mutex decoder_mutex;
|
||||||
|
|||||||
@@ -186,7 +186,9 @@ void scenes::stream::tracking()
|
|||||||
|
|
||||||
XrSpace view_space = application::space(xr::spaces::view);
|
XrSpace view_space = application::space(xr::spaces::view);
|
||||||
XrSpace world_space = application::space(xr::spaces::world);
|
XrSpace world_space = application::space(xr::spaces::world);
|
||||||
XrDuration tracking_period = min_tracking_period;
|
XrDuration tracking_period = min_tracking_period; // target period for 20% busy time
|
||||||
|
XrDuration current_tracking_period = tracking_period; // divider of frame period
|
||||||
|
int period_adjust = 0;
|
||||||
|
|
||||||
XrTime t0 = instance.now();
|
XrTime t0 = instance.now();
|
||||||
XrTime last_hand_sample = t0;
|
XrTime last_hand_sample = t0;
|
||||||
@@ -288,7 +290,7 @@ void scenes::stream::tracking()
|
|||||||
|
|
||||||
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.1), min_tracking_period, max_tracking_period);
|
||||||
|
|
||||||
#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)])
|
||||||
@@ -335,7 +337,18 @@ void scenes::stream::tracking()
|
|||||||
|
|
||||||
network_session->send_stream(std::move(packets));
|
network_session->send_stream(std::move(packets));
|
||||||
|
|
||||||
t0 += tracking_period;
|
if (period_adjust == 0)
|
||||||
|
{
|
||||||
|
if (auto p = real_display_period.load())
|
||||||
|
{
|
||||||
|
period_adjust = (p / tracking_period);
|
||||||
|
current_tracking_period = p / period_adjust;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
--period_adjust;
|
||||||
|
|
||||||
|
t0 += current_tracking_period;
|
||||||
}
|
}
|
||||||
catch (std::exception & e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user