Frame rate switch: VICTORY_FRAME_INTERVAL_MS (our clock) and the title's own 30 fps setting patched to match (off by default)

The title asks for 33,333 us (SetFrameIntervalX) because its graphics
settings hold a frame rate of 30 (settings +0x210): +0x1e0fb30 and
+0x22434a0 turn it into a frame time (+0x98f84ac), +0x247ab10 picks the
interval from it and the display's 60/120 Hz (a 120 Hz mode alone changes
nothing at 30), and +0x120530 is a QueryPerformanceCounter limiter of its
own at the same rate.

VICTORY_FRAME_INTERVAL_MS=<ms> (16.667, 8.333, 0 = no wait): frame.rs ticks
at that interval whatever the title sets; the loader makes the two loads of
the setting "mov eax, rate; nop" (rate = 1000/ms rounded, 0 = the title's
own "no limit"), with the original bytes checked. VICTORY_TITLE_FPS=<n>|off
overrides the rate or leaves the title alone. Diagnostics:
VICTORY_TIMER_LOG=1 logs the title's timers once a second and frame pacing
bands every 5 s.

Ported from Belobug/VIctory-Belobug-AMD 49cb83b (author: local); the descriptor-site module of renderer port 2 left out. Our VICTORY_FRAME_INTERVAL_US (our clock alone) still works; VICTORY_FRAME_INTERVAL_MS is read first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 authored and readmet3xt-lab committed 2026-11-27 01:08:53 +05:30
1 parent a83bc910a7
commit bacb402091
6 files changed
+468 -5

No files matched your search

+64
View File
@@ -244,6 +244,29 @@ pub fn run(
// SAFETY: the image stays mapped, and nothing of it has run yet.
unsafe { victory_loader::write_sites::apply_asked(&image_name, image.base(), size) };
}
// The frame rate (VICTORY_FRAME_INTERVAL_MS, off without it): our frame
// clock ticks at that interval (victory-gpu), and the title is given
// the matching rate in place of its setting's 30 (VICTORY_TITLE_FPS
// overrides it; `off` leaves the title alone).
#[cfg(windows)]
if execute && let Some(ms) = victory_loader::frame_rate::asked_interval_ms() {
use victory_loader::frame_rate::{Patched, SITES, apply, title_interval_us, title_rate};
let asked = std::env::var("VICTORY_TITLE_FPS").ok();
match title_rate(ms, asked.as_deref()) {
Some(rate) => {
let size = image.info().size_of_image as usize;
// SAFETY: the image stays mapped and nothing of it has run yet.
let done = unsafe { apply(image.base(), size, rate, &SITES) };
let patched = done.iter().filter(|d| **d == Patched::Done).count();
println!(
"frame rate: our clock {ms} ms; the title's rate {rate} ({patched} of {} loads of its setting patched; it asks for {} us at 60 Hz)",
SITES.len(),
title_interval_us(rate, false)
);
}
None => println!("frame rate: our clock {ms} ms; the title's own rate (30) left as it is"),
}
}
if !execute {
println!("not executing (pass --execute to start the title)");
return Ok(());
@@ -281,6 +304,7 @@ fn diagnostics(image: &victory_loader::LoadedImage, cfg: &victory_core::Config)
victory_loader::profile_on_schedule(victory_hle::frame_phase);
victory_hle::modules::audio::capture::start();
watch(image.base(), image.info().size_of_image as usize);
timers(image.base(), image.info().size_of_image as usize);
poke(image.base(), image.info().size_of_image as usize);
// Debugging aid: `VICTORY_CRASH_SAVE=<rva>:<len>,...` (hex) writes those
// title ranges to `crash-<rva>.bin` in the cache dir on a crash.
@@ -329,6 +353,46 @@ fn watch(base: usize, size: usize) {
});
}
/// Debugging aid: `VICTORY_TIMER_LOG=1` logs the title's timers once a
/// second (`victory_loader::frame_rate`): its frame time and limiter flag,
/// and each timer's two times, step in seconds and in milliseconds. Whether
/// game time keeps to the wall clock at any frame rate is read from these.
#[cfg(all(windows, feature = "diagnostics"))]
fn timers(base: usize, size: usize) {
use victory_loader::frame_rate::{FRAME_US, LIMITER_ON, TIMERS};
if std::env::var("VICTORY_TIMER_LOG").ok().as_deref() != Some("1") {
return;
}
if TIMERS.iter().chain([&FRAME_US, &LIMITER_ON]).any(|&rva| rva + 0x14 > size) {
return;
}
std::thread::spawn(move || {
let start = std::time::Instant::now();
let u32_at = |rva: usize| {
// SAFETY: inside the mapped image (checked above), title data.
unsafe { ((base + rva) as *const u32).read_volatile() }
};
loop {
std::thread::sleep(std::time::Duration::from_secs(1));
let timers: Vec<String> = TIMERS
.iter()
.map(|&t| {
let step = f32::from_bits(u32_at(t + 0xc));
format!("{} {} {step:.4} {}", u32_at(t), u32_at(t + 4), u32_at(t + 0x10))
})
.collect();
eprintln!(
"VIctory: the title's timers at {} ms: frame_us {} limiter {} frames {}; timers (time ms, frames, step s, step ms): {}",
start.elapsed().as_millis(),
u32_at(FRAME_US),
u32_at(LIMITER_ON) & 0xff,
victory_hle::frames_begun(),
timers.join(" | ")
);
}
});
}
/// Debugging aid: `VICTORY_POKE=<rva>:<byte>,...` (hex) writes the byte at
/// each title+rva twice a second. A title that ends itself when its main
/// loop has not ticked for a while (Grand Theft Auto VI: 30 s) runs on