Skip to content

Commit

Permalink
(fix) Better no-stats vs no-framepace separation (#2634)
Browse files Browse the repository at this point in the history
* Better no-stats vs no-framepace separation

* millis

* micros

* yield
  • Loading branch information
shinyquagsire23 authored Jan 17, 2025
1 parent 64828ae commit 1e40b10
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions alvr/server_openvr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,24 +383,30 @@ extern "C" fn report_present(timestamp_ns: u64, offset_ns: u64) {
}

extern "C" fn wait_for_vsync() {
// Default 120Hz-ish wait if StatisticsManager isn't up.
// We use 120Hz-ish so that SteamVR doesn't accidentally get
// any weird ideas about our display Hz with its frame pacing.
static PRE_HEADSET_STATS_WAIT_INTERVAL: Duration = Duration::from_millis(8);

// NB: don't sleep while locking SERVER_DATA_MANAGER or SERVER_CORE_CONTEXT
let sleep_duration = if alvr_server_core::settings()
.video
.enforce_server_frame_pacing
{
SERVER_CORE_CONTEXT
.read()
.as_ref()
.and_then(|ctx| ctx.duration_until_next_vsync())
} else {
None
};
let sleep_duration = SERVER_CORE_CONTEXT
.read()
.as_ref()
.and_then(|ctx| ctx.duration_until_next_vsync());

if let Some(duration) = sleep_duration {
thread::sleep(duration);
if alvr_server_core::settings()
.video
.enforce_server_frame_pacing
{
thread::sleep(duration);
} else {
thread::yield_now();
}
} else {
// Fallback to avoid deadlocking people's systems accidentally
thread::sleep(Duration::from_millis(8));
// StatsManager isn't up because the headset hasn't connected,
// safety fallback to prevent deadlocking.
thread::sleep(PRE_HEADSET_STATS_WAIT_INTERVAL);
}
}

Expand Down

0 comments on commit 1e40b10

Please sign in to comment.