diff --git a/crates/victory-gpu/src/pipeline/make.rs b/crates/victory-gpu/src/pipeline/make.rs index 138fb2b..02bb959 100644 --- a/crates/victory-gpu/src/pipeline/make.rs +++ b/crates/victory-gpu/src/pipeline/make.rs @@ -318,11 +318,15 @@ fn workers() -> bool { let spawned = std::thread::Builder::new() .name(format!("victory-pipelines-{i}")) .spawn(|| { - // Below the title's own threads (loading, recording). + // Below the title's own threads (loading, recording), + // and the streaming one, which is below normal itself + // (`VICTORY_PIPELINE_LOWEST=0`: level with it, as before). + let lowest = std::env::var_os("VICTORY_PIPELINE_LOWEST").is_none_or(|v| v != "0"); // SAFETY: a plain call on our own thread. unsafe { use windows::Win32::System::Threading::*; - let _ = SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL); + let priority = if lowest { THREAD_PRIORITY_LOWEST } else { THREAD_PRIORITY_BELOW_NORMAL }; + let _ = SetThreadPriority(GetCurrentThread(), priority); } loop { next().make(); diff --git a/crates/victory-hle/src/runtime.rs b/crates/victory-hle/src/runtime.rs index f26b96f..a42c89f 100644 --- a/crates/victory-hle/src/runtime.rs +++ b/crates/victory-hle/src/runtime.rs @@ -258,6 +258,25 @@ pub fn use_console_timers() { ); timeBeginPeriod(1); } + ahead_of_other_programs(); +} + +/// The title's streaming thread runs below normal priority (on the console +/// nobody else wants its core) and does all of the title's loading: a +/// program that keeps the processors busy at normal priority (a build, a +/// virus scan) starved it, loading took 40 to 60 s instead of 28 to 33, and +/// the opening ran without the models that were to be there (runs cpu-1, +/// play-1125-0203). The process runs above normal, as long as it runs. +/// `VICTORY_PROCESS_PRIORITY=normal`: as it was started. +#[cfg(windows)] +fn ahead_of_other_programs() { + use windows_sys::Win32::System::Threading::{ABOVE_NORMAL_PRIORITY_CLASS, GetCurrentProcess, SetPriorityClass}; + if std::env::var_os("VICTORY_PROCESS_PRIORITY").is_some_and(|v| v == "normal" || v == "0") { + return; + } + // SAFETY: a plain process setting. + let set = unsafe { SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS) } != 0; + tracing::info!(set, "the process runs above normal priority (VICTORY_PROCESS_PRIORITY=normal: not)"); } #[cfg(test)]