Skip to content

Commit 64828ae

Browse files
authored
feat(server_openvr): ✨ Add "Enforce server frame pacing" (#2632)
1 parent 481e5ed commit 64828ae

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

alvr/server_openvr/src/lib.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,24 @@ extern "C" fn report_present(timestamp_ns: u64, offset_ns: u64) {
384384

385385
extern "C" fn wait_for_vsync() {
386386
// NB: don't sleep while locking SERVER_DATA_MANAGER or SERVER_CORE_CONTEXT
387-
let sleep_duration = SERVER_CORE_CONTEXT
388-
.read()
389-
.as_ref()
390-
.and_then(|ctx| ctx.duration_until_next_vsync())
391-
.unwrap_or(Duration::from_millis(8));
387+
let sleep_duration = if alvr_server_core::settings()
388+
.video
389+
.enforce_server_frame_pacing
390+
{
391+
SERVER_CORE_CONTEXT
392+
.read()
393+
.as_ref()
394+
.and_then(|ctx| ctx.duration_until_next_vsync())
395+
} else {
396+
None
397+
};
392398

393-
thread::sleep(sleep_duration);
399+
if let Some(duration) = sleep_duration {
400+
thread::sleep(duration);
401+
} else {
402+
// Fallback to avoid deadlocking people's systems accidentally
403+
thread::sleep(Duration::from_millis(8));
404+
}
394405
}
395406

396407
pub extern "C" fn shutdown_driver() {

alvr/session/src/settings.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,12 @@ Blend: corresponds to un-premultiplied alpha"))]
602602
#[schema(gui(slider(min = 0.50, max = 0.99, step = 0.01)))]
603603
pub buffering_history_weight: f32,
604604

605+
#[schema(strings(
606+
help = r"This works only on Windows. It shouldn't be disabled except in certain circumstances when you know the VR game will not meet the target framerate."
607+
))]
608+
#[schema(flag = "real-time")]
609+
pub enforce_server_frame_pacing: bool,
610+
605611
#[schema(flag = "steamvr-restart")]
606612
pub encoder_config: EncoderConfig,
607613

@@ -1418,6 +1424,7 @@ pub fn session_settings_default() -> SettingsDefault {
14181424
preferred_fps: 72.,
14191425
max_buffering_frames: 2.0,
14201426
buffering_history_weight: 0.90,
1427+
enforce_server_frame_pacing: true,
14211428
bitrate: BitrateConfigDefault {
14221429
gui_collapsed: false,
14231430
mode: BitrateModeDefault {

0 commit comments

Comments
 (0)