From 576a922ea21ec5f962b0d2644dd3b12a18d1487f Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Thu, 16 Jan 2025 16:21:00 -0700 Subject: [PATCH 1/4] Better no-stats vs no-framepace separation --- alvr/server_openvr/src/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/alvr/server_openvr/src/lib.rs b/alvr/server_openvr/src/lib.rs index df47d8f754..14c3217fde 100644 --- a/alvr/server_openvr/src/lib.rs +++ b/alvr/server_openvr/src/lib.rs @@ -383,6 +383,11 @@ 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 @@ -392,16 +397,13 @@ extern "C" fn wait_for_vsync() { .read() .as_ref() .and_then(|ctx| ctx.duration_until_next_vsync()) + .unwrap_or(PRE_HEADSET_STATS_WAIT_INTERVAL) } else { - None + // Fallback to avoid deadlocking people's systems accidentally + Duration::from_micros(1000) }; - if let Some(duration) = sleep_duration { - thread::sleep(duration); - } else { - // Fallback to avoid deadlocking people's systems accidentally - thread::sleep(Duration::from_millis(8)); - } + thread::sleep(sleep_duration); } pub extern "C" fn shutdown_driver() { From 9c51111f33e31849ba894ebbf371a3f87cdb4f1d Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Thu, 16 Jan 2025 16:45:03 -0700 Subject: [PATCH 2/4] millis --- alvr/server_openvr/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alvr/server_openvr/src/lib.rs b/alvr/server_openvr/src/lib.rs index 14c3217fde..a7b0ed7fc8 100644 --- a/alvr/server_openvr/src/lib.rs +++ b/alvr/server_openvr/src/lib.rs @@ -400,7 +400,7 @@ extern "C" fn wait_for_vsync() { .unwrap_or(PRE_HEADSET_STATS_WAIT_INTERVAL) } else { // Fallback to avoid deadlocking people's systems accidentally - Duration::from_micros(1000) + Duration::from_millis(1) }; thread::sleep(sleep_duration); From 5cb64007641ea38ee57f2e7e9b8e580cb24a2a5c Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Thu, 16 Jan 2025 17:27:10 -0700 Subject: [PATCH 3/4] micros --- alvr/server_openvr/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alvr/server_openvr/src/lib.rs b/alvr/server_openvr/src/lib.rs index a7b0ed7fc8..83d5a95cd6 100644 --- a/alvr/server_openvr/src/lib.rs +++ b/alvr/server_openvr/src/lib.rs @@ -400,7 +400,7 @@ extern "C" fn wait_for_vsync() { .unwrap_or(PRE_HEADSET_STATS_WAIT_INTERVAL) } else { // Fallback to avoid deadlocking people's systems accidentally - Duration::from_millis(1) + Duration::from_micros(1) }; thread::sleep(sleep_duration); From c1ee19de9f16824904065782d246a592249202b3 Mon Sep 17 00:00:00 2001 From: shinyquagsire23 Date: Thu, 16 Jan 2025 17:56:42 -0700 Subject: [PATCH 4/4] yield --- alvr/server_openvr/src/lib.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/alvr/server_openvr/src/lib.rs b/alvr/server_openvr/src/lib.rs index 83d5a95cd6..4089d4ab63 100644 --- a/alvr/server_openvr/src/lib.rs +++ b/alvr/server_openvr/src/lib.rs @@ -389,21 +389,25 @@ extern "C" fn wait_for_vsync() { 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()) - .unwrap_or(PRE_HEADSET_STATS_WAIT_INTERVAL) + let sleep_duration = SERVER_CORE_CONTEXT + .read() + .as_ref() + .and_then(|ctx| ctx.duration_until_next_vsync()); + + if let Some(duration) = 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 - Duration::from_micros(1) - }; - - thread::sleep(sleep_duration); + // StatsManager isn't up because the headset hasn't connected, + // safety fallback to prevent deadlocking. + thread::sleep(PRE_HEADSET_STATS_WAIT_INTERVAL); + } } pub extern "C" fn shutdown_driver() {