Skip to content

Commit

Permalink
fix(server_openvr): Fix CPU/GPU deadlocking at 100% usage before the …
Browse files Browse the repository at this point in the history
…headset connects (#2495)

* Fix CPU/GPU deadlocking at 100% usage before the headset connects

* Temporary stats manager and nits

* Remove optimize_game_render_latency
  • Loading branch information
shinyquagsire23 authored Nov 9, 2024
1 parent 55313e0 commit a448c49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
14 changes: 13 additions & 1 deletion alvr/server_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,21 @@ impl ServerCoreContext {

let (events_sender, events_receiver) = mpsc::channel();

// Create a temporary StatisticsManager until a headset connects
let initial_settings = SESSION_MANAGER.read().settings().clone();
let stats = StatisticsManager::new(
initial_settings.connection.statistics_history_size,
Duration::from_secs_f32(1.0 / 90.0),
if let Switch::Enabled(config) = &initial_settings.headset.controllers {
config.steamvr_pipeline_frames
} else {
0.0
},
);

let connection_context = Arc::new(ConnectionContext {
events_sender,
statistics_manager: RwLock::new(None),
statistics_manager: RwLock::new(Some(stats)),
bitrate_manager: Mutex::new(BitrateManager::new(256, 60.0)),
tracking_manager: RwLock::new(TrackingManager::new()),
decoder_config: Mutex::new(None),
Expand Down
20 changes: 6 additions & 14 deletions alvr/server_openvr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,13 @@ extern "C" fn report_present(timestamp_ns: u64, offset_ns: u64) {

extern "C" fn wait_for_vsync() {
// NB: don't sleep while locking SERVER_DATA_MANAGER or SERVER_CORE_CONTEXT
let sleep_duration = if alvr_server_core::settings()
.video
.optimize_game_render_latency
{
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())
.unwrap_or(Duration::from_millis(50));

if let Some(duration) = sleep_duration {
thread::sleep(duration);
}
thread::sleep(sleep_duration);
}

pub extern "C" fn shutdown_driver() {
Expand Down
5 changes: 0 additions & 5 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,6 @@ pub struct VideoConfig {
#[schema(gui(slider(min = 0.50, max = 0.99, step = 0.01)))]
pub buffering_history_weight: f32,

#[schema(strings(help = "This works only on Windows"))]
#[schema(flag = "real-time")]
pub optimize_game_render_latency: bool,

#[schema(flag = "steamvr-restart")]
pub encoder_config: EncoderConfig,

Expand Down Expand Up @@ -1347,7 +1343,6 @@ pub fn session_settings_default() -> SettingsDefault {
preferred_fps: 72.,
max_buffering_frames: 2.0,
buffering_history_weight: 0.90,
optimize_game_render_latency: true,
bitrate: BitrateConfigDefault {
gui_collapsed: false,
mode: BitrateModeDefault {
Expand Down

0 comments on commit a448c49

Please sign in to comment.