mirror of
https://github.com/lobomfz/VIctory-xmem.git
synced 2026-12-06 05:48:38 +00:00
Benchmark routes: VICTORY_BENCH_ROUTE=downtown|drive
Two fixed, reproducible routes built into the layer, so every machine benchmarks the same places the same way without mods (game 1.0.2.1). - victory-loader bench_route: a minimal script-native caller. Handlers are found by their 1.0.2.1 offsets and each checked by the id its cold block writes; PLAYER_PED_ID's handler is hooked for a per-frame tick in one elected game script thread (the approach of ViceHook, MIT). Every call goes through an SEH-guarded stub: a fault stops the route, not the game. Nothing is hooked without the variable. - downtown: a noclip flight over a 2400 m square at (-2600, -1000), 30 m/s, 40 m over the smoothed ground, camera sweeping, in a Blista: the city's densest blocks (found by a frame-rate scout over the map). - drive: the game's AI drives a Blista around a loop on the roads in the hills from (-2556, 6948), with traffic (about 3.5 min a lap). - Both set 12:00 (clock paused), held sunny weather and no wanted level. - With VICTORY_BENCH, the run is timed from the route's start (nothing skipped) and bench_stats.txt names the route; run.sh does not carry the route over into the restart after a benchmark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
goldfishdev
parent
6921ddb4ff
commit
2d1a3ec6b7
34
README.md
34
README.md
@ -213,6 +213,40 @@ log is made. The game restarts with your settings; a crash also writes results
|
||||
and restarts. Uploading to the [PortWatch](https://portwatch-vi.xyz/lab/#report)
|
||||
form is manual.
|
||||
|
||||
### Benchmark routes
|
||||
|
||||
```sh
|
||||
./run.sh play VICTORY_BENCH=nort VICTORY_BENCH_ROUTE=downtown
|
||||
./run.sh play VICTORY_BENCH=rt VICTORY_BENCH_ROUTE=drive
|
||||
./run.sh play VICTORY_BENCH_ROUTE=drive # just watch it, no recording
|
||||
```
|
||||
|
||||
`VICTORY_BENCH_ROUTE` takes the player along a fixed route, built into
|
||||
VIctory (no mods needed), so runs on different machines see the same places
|
||||
the same way. Coordinates are fixed in the code, not taken from your save.
|
||||
Both start 15 seconds after the player appears in the world, set the time to
|
||||
12:00 with the clock paused and the weather to clear (`sunny`, held), allow no
|
||||
wanted level (a police chase would make runs differ), and make
|
||||
the player invincible.
|
||||
|
||||
- `downtown`: a noclip flight around a 2400 m square over the city (corner
|
||||
-2600, -1000), at 30 m/s, 40 m above the ground (following it, smoothed),
|
||||
in a Dinka Blista with collision off, the camera sweeping 60 degrees each
|
||||
way every 6 seconds. One lap is about 5 min 20 s.
|
||||
- `drive`: the player is put at -2556, 6948 in a Dinka Blista, and the
|
||||
game's own AI drives a loop through the hills on its roads: to -2399, 7172,
|
||||
-2566, 7202, back to the start and around again (about 3.5 minutes a lap),
|
||||
with traffic on (it reacts to traffic itself, so no two runs are exactly
|
||||
alike). The waypoints are points the AI was seen to reach on the road. A leg
|
||||
not done in 180 seconds is skipped.
|
||||
With `VICTORY_BENCH`, the run's time and its figures start when the route
|
||||
starts (none are left out), and `bench_stats.txt` names the route. The game log
|
||||
has a `bench route:` line for the start, each lap or leg, and anything that
|
||||
stops the route; a route that cannot run (another game build, a fault in a game
|
||||
call) stops with a warning and the benchmark carries on where the player is.
|
||||
The routes need game build 1.0.2.1 (Xbox Series) and do not mix with ViceHook,
|
||||
which hooks the same game function.
|
||||
|
||||
## Diagnostics and development
|
||||
|
||||
Build the diagnostics profile with `PROFILE=diag ./build.sh`. Page sampling, RT
|
||||
|
||||
@ -442,6 +442,14 @@ pub fn run(
|
||||
// SAFETY: as above.
|
||||
unsafe { victory_loader::range_allocator::apply(image.base(), size) };
|
||||
}
|
||||
// A fixed benchmark route (VICTORY_BENCH_ROUTE=downtown|drive, off
|
||||
// without it): the game's script tick hooked to take the player along.
|
||||
#[cfg(windows)]
|
||||
if execute {
|
||||
let size = image.info().size_of_image as usize;
|
||||
// SAFETY: the image stays mapped and nothing of it has run yet.
|
||||
unsafe { victory_loader::bench_route::apply_asked(image.base(), size) };
|
||||
}
|
||||
if !execute {
|
||||
println!("not executing (pass --execute to start the title)");
|
||||
return Ok(());
|
||||
|
||||
@ -2,6 +2,10 @@
|
||||
//! `VICTORY_BENCH=rt` or `nort` over the user's settings, and the game
|
||||
//! closes itself after `VICTORY_BENCH_MINUTES`. Here: what was asked, and
|
||||
//! the frame rate figures.
|
||||
//!
|
||||
//! `VICTORY_BENCH_ROUTE` adds a fixed route the player is taken along (see
|
||||
//! [`Route`]; driven by `victory_loader::bench_route`). In a benchmark run
|
||||
//! with a route, the run's clock and its figures start when the route does.
|
||||
|
||||
/// Minutes at the start left out of the figures (loading and menus), in
|
||||
/// runs of at least twice this.
|
||||
@ -49,6 +53,115 @@ pub fn presses_enter() -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
/// A fixed route for benchmark runs (`VICTORY_BENCH_ROUTE`): the same
|
||||
/// places, the same way, on every machine (game build 1.0.2.1).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum Route {
|
||||
/// `downtown`: a noclip flight around a 2400 m square over the city, at
|
||||
/// 30 m/s, 40 m above the ground, the camera sweeping side to side.
|
||||
Downtown,
|
||||
/// `drive`: the game's AI drives the player's car around a fixed loop of
|
||||
/// waypoints, with traffic.
|
||||
Drive,
|
||||
}
|
||||
|
||||
impl Route {
|
||||
/// The route `VICTORY_BENCH_ROUTE` names (case ignored), if any.
|
||||
pub fn parse(name: &str) -> Option<Route> {
|
||||
match name.trim().to_ascii_lowercase().as_str() {
|
||||
"downtown" => Some(Route::Downtown),
|
||||
"drive" => Some(Route::Drive),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Its name, as `VICTORY_BENCH_ROUTE` takes it.
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
Route::Downtown => "downtown",
|
||||
Route::Drive => "drive",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The route asked for with `VICTORY_BENCH_ROUTE`, if a known one.
|
||||
pub fn route() -> Option<Route> {
|
||||
static ROUTE: std::sync::OnceLock<Option<Route>> = std::sync::OnceLock::new();
|
||||
*ROUTE.get_or_init(|| {
|
||||
std::env::var("VICTORY_BENCH_ROUTE")
|
||||
.ok()
|
||||
.and_then(|v| Route::parse(&v))
|
||||
})
|
||||
}
|
||||
|
||||
static ROUTE_STARTED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
/// The route is under way (or gave up): a benchmark run starts its clock.
|
||||
pub fn set_route_started() {
|
||||
ROUTE_STARTED.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Whether the route asked for has started (or gave up).
|
||||
pub fn route_started() -> bool {
|
||||
ROUTE_STARTED.load(std::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// The `downtown` flight: the square's corner (x, y), the ground height the
|
||||
/// flight is measured from where the ground has not streamed in yet, the
|
||||
/// side in metres, the speed in m/s and the height above the ground.
|
||||
pub const DOWNTOWN_CORNER: (f32, f32) = (-2600.0, -1000.0);
|
||||
pub const DOWNTOWN_GROUND: f32 = 5.0;
|
||||
pub const DOWNTOWN_SIDE: f32 = 2400.0;
|
||||
pub const DOWNTOWN_SPEED: f32 = 30.0;
|
||||
pub const DOWNTOWN_UP: f32 = 40.0;
|
||||
|
||||
/// The `drive` loop's waypoints (absolute map x, y), driven in order and
|
||||
/// around again; the car starts at the first, facing the second. Points the
|
||||
/// game's AI was seen to reach on its roads (a dirt road in the hills): off
|
||||
/// the road network its route finding stalls.
|
||||
pub const DRIVE_WAYPOINTS: [(f32, f32); 3] =
|
||||
[(-2556.0, 6948.0), (-2399.0, 7172.0), (-2566.0, 7202.0)];
|
||||
|
||||
/// The game's heading (degrees, 0 north, counter-clockwise) of travel from
|
||||
/// `from` to `to`.
|
||||
pub fn heading(from: (f32, f32), to: (f32, f32)) -> f32 {
|
||||
(-(to.0 - from.0)).atan2(to.1 - from.1).to_degrees()
|
||||
}
|
||||
|
||||
/// Where the `downtown` flight is `seconds` after it started: (x, y), the
|
||||
/// heading, and the laps completed. Corner, then +x, +y, back -x, -y.
|
||||
pub fn downtown_at(seconds: f32) -> ((f32, f32), f32, u32) {
|
||||
let side = DOWNTOWN_SIDE;
|
||||
let corners = [
|
||||
(0.0, 0.0),
|
||||
(side, 0.0),
|
||||
(side, side),
|
||||
(0.0, side),
|
||||
(0.0, 0.0),
|
||||
];
|
||||
let travelled = seconds.max(0.0) * DOWNTOWN_SPEED;
|
||||
let d = travelled % (4.0 * side);
|
||||
let leg = ((d / side) as usize).min(3);
|
||||
let f = (d - leg as f32 * side) / side;
|
||||
let (a, b) = (corners[leg], corners[leg + 1]);
|
||||
let (x0, y0) = DOWNTOWN_CORNER;
|
||||
let at = (x0 + a.0 + (b.0 - a.0) * f, y0 + a.1 + (b.1 - a.1) * f);
|
||||
(at, heading(a, b), (travelled / (4.0 * side)) as u32)
|
||||
}
|
||||
|
||||
/// The camera's sweep (radians, relative to the heading) `seconds` into the
|
||||
/// flight: +-60 degrees over a 6 s period.
|
||||
pub fn downtown_sweep(seconds: f32) -> f32 {
|
||||
(seconds * std::f32::consts::TAU / 6.0).sin() * 60f32.to_radians()
|
||||
}
|
||||
|
||||
/// The flight's height over smoothed ground `ground` (none yet: the
|
||||
/// reference height).
|
||||
pub fn downtown_height(ground: Option<f32>) -> f32 {
|
||||
let floor = DOWNTOWN_GROUND + DOWNTOWN_UP;
|
||||
ground.map_or(floor, |g| floor.max(g + DOWNTOWN_UP))
|
||||
}
|
||||
|
||||
/// The times between presented frames, in seconds.
|
||||
#[derive(Default)]
|
||||
pub struct Recorder {
|
||||
@ -84,6 +197,11 @@ impl Recorder {
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
self.summary_skipping(skip)
|
||||
}
|
||||
|
||||
/// The figures, leaving out the first `skip` seconds of frames.
|
||||
pub fn summary_skipping(&self, skip: f64) -> Option<Summary> {
|
||||
let mut at = 0.0;
|
||||
let first = self.frames.iter().position(|dt| {
|
||||
at += dt;
|
||||
@ -159,4 +277,36 @@ mod tests {
|
||||
assert_eq!(r.summary().unwrap().frames, 100);
|
||||
assert_eq!(Recorder::default().summary(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn routes_are_named_as_documented() {
|
||||
assert_eq!(Route::parse("downtown"), Some(Route::Downtown));
|
||||
assert_eq!(Route::parse(" Drive "), Some(Route::Drive));
|
||||
assert_eq!(Route::parse("beach"), None);
|
||||
assert_eq!(Route::Drive.name(), "drive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_flight_goes_around_the_square() {
|
||||
let close = |a: f32, b: f32| (a - b).abs() < 0.01;
|
||||
let ((x, y), h, laps) = downtown_at(0.0);
|
||||
assert!(close(x, -2600.0) && close(y, -1000.0) && laps == 0);
|
||||
// East first (heading -90: the game's headings turn left from north).
|
||||
assert!(close(h, -90.0));
|
||||
let ((x, y), h, _) = downtown_at(40.0);
|
||||
assert!(close(x, -2600.0 + 1200.0) && close(y, -1000.0) && close(h, -90.0));
|
||||
let ((x, y), h, _) = downtown_at(100.0);
|
||||
assert!(close(x, -200.0) && close(y, -1000.0 + 600.0) && close(h, 0.0));
|
||||
let ((x, y), _, laps) = downtown_at(320.0 + 10.0);
|
||||
assert!(close(x, -2300.0) && close(y, -1000.0) && laps == 1);
|
||||
assert!(close(downtown_sweep(1.5), 60f32.to_radians()));
|
||||
assert!(close(downtown_height(None), 45.0));
|
||||
assert!(close(downtown_height(Some(100.0)), 140.0));
|
||||
assert!(close(downtown_height(Some(-20.0)), 45.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_drive_starts_toward_the_first_leg() {
|
||||
assert!(heading(DRIVE_WAYPOINTS[0], DRIVE_WAYPOINTS[1]) < 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,11 @@
|
||||
//! timed from the first one, and when the time is up the frame about to be
|
||||
//! presented, panel included, is saved as `screenshot.png` with the figures
|
||||
//! (`bench_stats.txt`) in `VICTORY_BENCH_DIR`, and the game ends.
|
||||
//!
|
||||
//! With a route (`VICTORY_BENCH_ROUTE`) the frames are timed from the
|
||||
//! route's start instead, and none are left out of the figures; a route that
|
||||
//! has not started after [`ROUTE_WAIT`] of frames is given up on and the run
|
||||
//! is timed from then.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
@ -11,8 +16,13 @@ use victory_core::bench::{self, Recorder};
|
||||
use windows::Win32::Graphics::Direct3D12::*;
|
||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||
|
||||
/// The longest a benchmark run waits for its route to start.
|
||||
const ROUTE_WAIT: Duration = Duration::from_secs(600);
|
||||
|
||||
#[derive(Default)]
|
||||
struct Run {
|
||||
/// The first frame presented, while waiting for the route.
|
||||
first: Option<Instant>,
|
||||
started: Option<Instant>,
|
||||
last: Option<Instant>,
|
||||
sampled: Option<Instant>,
|
||||
@ -45,6 +55,16 @@ pub(crate) fn presented(memory: impl FnOnce() -> (u64, u64)) {
|
||||
}
|
||||
let now = Instant::now();
|
||||
with(|r| {
|
||||
if r.started.is_none() && bench::route().is_some() && !bench::route_started() {
|
||||
if now.duration_since(*r.first.get_or_insert(now)) < ROUTE_WAIT {
|
||||
return;
|
||||
}
|
||||
tracing::warn!(
|
||||
"benchmark: the route did not start in {} s; timing the run from now",
|
||||
ROUTE_WAIT.as_secs()
|
||||
);
|
||||
bench::set_route_started();
|
||||
}
|
||||
r.started.get_or_insert(now);
|
||||
if let Some(last) = r.last.replace(now) {
|
||||
r.frames.add(now.duration_since(last).as_secs_f64());
|
||||
@ -146,8 +166,16 @@ pub(crate) fn finish(shot: Option<ReadBack>) -> ! {
|
||||
Err(e) => tracing::warn!(error = %e, "benchmark: no screenshot"),
|
||||
}
|
||||
}
|
||||
let route = bench::route();
|
||||
if let Some(route) = route {
|
||||
text.push_str(&format!("route={}\n", route.name()));
|
||||
}
|
||||
with(|r| {
|
||||
if let Some(s) = r.frames.summary() {
|
||||
let summary = match route {
|
||||
Some(_) => r.frames.summary_skipping(0.0),
|
||||
None => r.frames.summary(),
|
||||
};
|
||||
if let Some(s) = summary {
|
||||
text.push_str(&format!(
|
||||
"seconds={:.0}\nframes={}\naverage={:.1}\nlow_1pct={:.1}\nlowest={:.1}\nhighest={:.1}\n",
|
||||
s.seconds, s.frames, s.average, s.low_1pct, s.lowest, s.highest
|
||||
|
||||
1273
crates/victory-loader/src/bench_route.rs
Normal file
1273
crates/victory-loader/src/bench_route.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,8 @@
|
||||
//! point on a thread with the stack size the image asks for; from then
|
||||
//! on, pass every thread start and end on to the attached images.
|
||||
|
||||
#[cfg(windows)]
|
||||
pub mod bench_route;
|
||||
#[cfg(windows)]
|
||||
mod console_insn;
|
||||
mod crash;
|
||||
|
||||
6
run.sh
6
run.sh
@ -3,7 +3,7 @@
|
||||
mapfile -d '' given < <(env -0)
|
||||
restart_env=()
|
||||
for kv in "${given[@]}"; do
|
||||
case "$kv" in VICTORY_BENCH=*|VICTORY_BENCH_MINUTES=*) ;; *) restart_env+=("$kv");; esac
|
||||
case "$kv" in VICTORY_BENCH=*|VICTORY_BENCH_MINUTES=*|VICTORY_BENCH_ROUTE=*) ;; *) restart_env+=("$kv");; esac
|
||||
done
|
||||
source "$(dirname "$(readlink -f "$0")")/env.sh"
|
||||
mode=$1; shift
|
||||
@ -138,7 +138,7 @@ if [ "$mode" = play ] && [[ ${VICTORY_BENCH:-} =~ ^(rt|nort)$ ]]; then
|
||||
benchdir=$root/local/benchmark/$(date +%Y%m%d-%H%M%S)-$bench
|
||||
mkdir -p "$benchdir"
|
||||
export VICTORY_BENCH_DIR=$(win "$benchdir")
|
||||
echo "Benchmark (ray tracing $([ "$bench" = rt ] && echo on || echo off)): the game closes itself after $VICTORY_BENCH_MINUTES min of frames. Results: $benchdir"
|
||||
echo "Benchmark (ray tracing $([ "$bench" = rt ] && echo on || echo off)${VICTORY_BENCH_ROUTE:+, route $VICTORY_BENCH_ROUTE}): the game closes itself after $VICTORY_BENCH_MINUTES min of frames. Results: $benchdir"
|
||||
fi
|
||||
if [ "${MUTE:-0}" = 1 ]; then source "$root/tools/mute.sh"; mute; fi
|
||||
# lsfg-vk (Lossless Scaling frame generation, a Vulkan layer) only when asked for, by naming the profile
|
||||
@ -307,7 +307,7 @@ if [ -n "$bench" ] && [ -z "$again" ]; then
|
||||
fi
|
||||
if [ -n "$again" ]; then
|
||||
restart_args=()
|
||||
for kv in "$@"; do case "$kv" in VICTORY_BENCH=*|VICTORY_BENCH_MINUTES=*) ;; *) restart_args+=("$kv");; esac; done
|
||||
for kv in "$@"; do case "$kv" in VICTORY_BENCH=*|VICTORY_BENCH_MINUTES=*|VICTORY_BENCH_ROUTE=*) ;; *) restart_args+=("$kv");; esac; done
|
||||
[[ $next =~ ^(rt|nort):([0-9]+)$ ]] && restart_args+=("VICTORY_BENCH=${BASH_REMATCH[1]}" "VICTORY_BENCH_MINUTES=${BASH_REMATCH[2]}")
|
||||
echo "Restarting the game..."
|
||||
# Let the old session give its memory back first: the RAM cap of the next
|
||||
|
||||
@ -45,6 +45,7 @@ Version: ${version:-you: git log -1 in the build folder}
|
||||
Upscaler: $fsr
|
||||
Render: 2560x1440 upscaled to a 3840x2160 output
|
||||
Ray tracing: $([ "$rt" = rt ] && echo On || echo Off)
|
||||
Route: ${s[route]:-none (free roam)}
|
||||
Frame generation, RSR, NIS: none
|
||||
you: also check nothing in your driver or desktop adds them
|
||||
(AFMF, lsfg-vk, gamescope upscaling).
|
||||
|
||||
Reference in New Issue
Block a user