Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Better no-stats vs no-framepace separation #2634

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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