Frame interval and refresh overrides, live key input for test drives

VICTORY_FRAME_INTERVAL_US paces frames at another interval than the
title asks (it asks 33.333 ms); VICTORY_DISPLAY_REFRESH adds a refresh
rate above 60 Hz to the display mode list. VICTORY_KEYS_FILE lets a
driver script press the stand-in pad's buttons while the title runs.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Fable 5.2 committed 2026-11-26 14:57:18 +05:30
1 parent 545f89019e
commit 2f0fbe147a
3 files changed
+189 -42

No files matched your search

+44 -18
View File
@@ -248,9 +248,29 @@ fn display_size() -> (u32, u32) {
})
}
/// The console's mode list: one 4K mode at 60 Hz (the title looks
/// for a 120 Hz one to allow 120 Hz frame intervals).
/// shortcut: fixed mode, not the host display's; report the host's rates if
/// The refresh rates the mode list offers: 60 Hz, and with
/// `VICTORY_DISPLAY_REFRESH=<hz>` (61..=240, e.g. 120) that rate too, as a
/// console on a television with a faster mode lists it. The title looks for
/// a 120 Hz mode to allow 120 Hz frame intervals.
fn refresh_rates() -> &'static [u32] {
static RATES: std::sync::OnceLock<Vec<u32>> = std::sync::OnceLock::new();
RATES.get_or_init(|| {
let mut rates = vec![60];
if let Some(hz) = std::env::var("VICTORY_DISPLAY_REFRESH").ok().and_then(|v| v.trim().parse::<u32>().ok()) {
if (61..=240).contains(&hz) {
rates.push(hz);
} else {
tracing::warn!(hz, "VICTORY_DISPLAY_REFRESH outside 61..=240: ignored");
}
}
tracing::info!(?rates, "display refresh rates reported to the title");
rates
})
}
/// The console's mode list: the display size at each rate of
/// [`refresh_rates`] (by default one mode at 60 Hz).
/// shortcut: fixed modes, not the host display's; report the host's rates if
/// a title paces by them.
extern "system" fn modes(
_: This,
@@ -263,26 +283,32 @@ extern "system" fn modes(
let Some(count) = (unsafe { count.as_mut() }) else {
return E_INVALIDARG;
};
let rates = refresh_rates();
let n = rates.len() as u32;
if out.is_null() {
*count = 1;
*count = n;
return S_OK;
}
if *count < 1 {
// As DXGI: what fits is written; a short buffer says so and keeps its count.
let fits = (*count).min(n) as usize;
let (width, height) = display_size();
for (i, &hz) in rates.iter().take(fits).enumerate() {
let mode = Mode {
width,
height,
refresh: [hz, 1],
format: 0,
scanlines: 1, // progressive
scaling: 0,
flags: 0,
};
// SAFETY: checked non-null; `i` < the title's `count`.
unsafe { out.add(i).write(mode) };
}
if *count < n {
return MORE_DATA;
}
*count = 1;
let (width, height) = display_size();
let mode = Mode {
width,
height,
refresh: [60, 1],
format: 0,
scanlines: 1, // progressive
scaling: 0,
flags: 0,
};
// SAFETY: checked non-null; room for `count` >= 1 modes.
unsafe { out.write(mode) };
*count = n;
S_OK
}
+25 -5
View File
@@ -39,6 +39,25 @@ fn clock() -> std::sync::MutexGuard<'static, Option<Clock>> {
CLOCK.lock().unwrap_or_else(|e| e.into_inner())
}
/// `VICTORY_FRAME_INTERVAL_US=<n>`: frames begin every `n` microseconds
/// whatever interval the title sets (16667: 60 a second, 8333: 120, 1000:
/// as fast as frames are made). The title sets 33,333 us (30 a second)
/// against the 60 Hz mode it is offered; it times its own frames with the
/// performance counter, so a shorter interval is a higher frame rate, not a
/// faster game. Values outside 1,000..=1,000,000 are ignored.
fn interval_override() -> Option<Duration> {
static OVERRIDE: std::sync::OnceLock<Option<Duration>> = std::sync::OnceLock::new();
*OVERRIDE.get_or_init(|| {
let us = std::env::var("VICTORY_FRAME_INTERVAL_US").ok()?.trim().parse::<u64>().ok()?;
let interval = (1_000..=1_000_000).contains(&us).then(|| Duration::from_micros(us));
match interval {
Some(interval) => tracing::info!(?interval, "VICTORY_FRAME_INTERVAL_US: frame interval overridden"),
None => tracing::warn!(us, "VICTORY_FRAME_INTERVAL_US outside 1000..=1000000: ignored"),
}
interval
})
}
/// Device method: a frame every `length` microseconds. The period is how
/// many intervals a frame may take to reach the display (pipeline depth),
/// not part of the rate.
@@ -46,14 +65,15 @@ pub(crate) extern "system" fn set_interval(
_: This,
_output: This,
length: u32,
_period: u32,
_flags: u32,
period: u32,
flags: u32,
) -> HRESULT {
let interval = match length {
let asked = match length {
0 => SIXTIETH,
us => Duration::from_micros(u64::from(us)),
};
tracing::info!(?interval, "frame interval");
let interval = interval_override().unwrap_or(asked);
tracing::info!(?asked, ?interval, period, flags, "frame interval");
// A new interval starts from now, after the last tick handed out.
let first = LAST
.iter()
@@ -105,7 +125,7 @@ fn next_tick(kind: u32) -> (u64, Duration) {
let mut clock = clock();
let c = clock.get_or_insert_with(|| Clock {
start: Instant::now(),
interval: SIXTIETH,
interval: interval_override().unwrap_or(SIXTIETH),
first: 0,
});
let elapsed = c.start.elapsed().as_nanos();