victory-gta6: this fork's changes on top of VIctory main (ffe310e)

World rendering, lighting, frame-rate and memory work for Grand Theft Auto VI
(Xbox Series X profile) on one Windows PC with an NVIDIA RTX 4070. The README
describes the state, the changes and the credits. Based on VIctory by Marvisak
and contributors (GPL-3.0-or-later); XCL by ivall and contributors was used as
a reference. No game files are included.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
fxcelessandClaude Fable 5.2 committed 2026-11-24 13:02:18 -05:00
1 parent ffe310eb20
commit 578d459c34
61 files changed
+32259 -1274

No files matched your search

+193 -7
View File
@@ -20,18 +20,139 @@ pub(crate) fn folder() -> Option<&'static PathBuf> {
/// too, and their draws traced at debug level.
pub(crate) fn listed(n: u64) -> bool {
static LIST: std::sync::OnceLock<Vec<u64>> = std::sync::OnceLock::new();
LIST.get_or_init(|| {
let list = std::env::var("VICTORY_CAPTURE_FRAMES").unwrap_or_default();
let named = LIST
.get_or_init(|| {
let list = std::env::var("VICTORY_CAPTURE_FRAMES").unwrap_or_default();
list.split(',')
.filter_map(|f| f.trim().parse().ok())
.collect()
})
.contains(&n);
// `VICTORY_CAPTURE_WORLD`: also the 2nd and the 6th frame after the first
// one that ran 500 draws or more (a title's first 3D frames: their
// numbers depend on how long the menus were shown), and the 30th and
// the 80th (Grand Theft Auto VI opens with a cutscene made in the
// engine: later shots of it, in case the first is dark by design).
//
// `VICTORY_CAPTURE_WORLD_ALSO` (comma-separated): more frames counted
// from that first one (Grand Theft Auto VI's blue patches show from
// about the 118th frame on, when the window's model has arrived and
// the reflections hold values: none of the four above has them).
static ALSO: std::sync::OnceLock<Vec<u64>> = std::sync::OnceLock::new();
let also = ALSO.get_or_init(|| {
let list = std::env::var("VICTORY_CAPTURE_WORLD_ALSO").unwrap_or_default();
list.split(',')
.filter_map(|f| f.trim().parse().ok())
.collect()
})
.contains(&n)
});
let first = WORLD.load(std::sync::atomic::Ordering::Relaxed);
let after = n.wrapping_sub(first);
named || first != u64::MAX && ([2, 6, 30, 80].contains(&after) || also.contains(&after))
}
/// With a capture folder, for the frames [`listed`]: `what` is added to
/// the frame's `frame-<n>-ops.txt`, one line per draw, dispatch, copy or
/// drop in the order recorded (the title records on several threads, so
/// lines of different lists interleave; each names its list). The file
/// says which pass writes which target, to find the pass whose output
/// stays empty.
#[cfg(feature = "diagnostics")]
pub(crate) fn op(list: usize, what: impl FnOnce() -> String) {
use std::io::Write;
let frame = crate::queue::presented() + 1;
if !listed(frame) {
// Before the world: the last lines are kept, and written out when
// it starts (`before-world-ops.txt`): what the title drew just
// before (Grand Theft Auto VI shows a title card there, whose text
// did not show).
if world_on() && WORLD.load(std::sync::atomic::Ordering::Relaxed) == u64::MAX {
// At most 300 lines of a frame: the world's first frame alone
// (thousands of operations, recorded before it is known to be
// the world's) pushed everything before it out.
static IN_FRAME: std::sync::Mutex<(u64, u32)> = std::sync::Mutex::new((0, 0));
{
let mut in_frame = IN_FRAME.lock().unwrap_or_else(|e| e.into_inner());
if in_frame.0 != frame {
*in_frame = (frame, 0);
}
in_frame.1 += 1;
if in_frame.1 > 300 {
return;
}
}
let what = what();
let mut ring = RING.lock().unwrap_or_else(|e| e.into_inner());
if ring.len() >= RING_LINES {
ring.pop_front();
}
ring.push_back(format!("frame {frame} list {list:#x} {what}"));
}
return;
}
let Some(folder) = folder() else {
return;
};
static FILE: std::sync::Mutex<Option<(u64, u64, std::fs::File)>> = std::sync::Mutex::new(None);
let what = what();
let mut file = FILE.lock().unwrap_or_else(|e| e.into_inner());
if file.as_ref().is_none_or(|f| f.0 != frame) {
let Ok(made) = std::fs::File::create(folder.join(format!("frame-{frame}-ops.txt"))) else {
return;
};
*file = Some((frame, 0, made));
}
if let Some((_, n, f)) = file.as_mut() {
*n += 1;
let _ = writeln!(f, "{n} list {list:#x} {what}");
}
}
/// The last lines of [`op`] before the world.
#[cfg(feature = "diagnostics")]
static RING: std::sync::Mutex<std::collections::VecDeque<String>> =
std::sync::Mutex::new(std::collections::VecDeque::new());
#[cfg(feature = "diagnostics")]
const RING_LINES: usize = 6000;
/// Whether `VICTORY_CAPTURE_WORLD` is set.
fn world_on() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_CAPTURE_WORLD").is_some())
}
/// The first frame that ran 500 draws or more (`VICTORY_CAPTURE_WORLD`).
static WORLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(u64::MAX);
/// At the present of `frame`: the draws run on the host so far.
pub(crate) fn frame_drew(frame: u64, drawn: u64) {
use std::sync::atomic::Ordering::Relaxed;
static LAST: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
let before = LAST.swap(drawn, Relaxed);
if world_on()
&& drawn.saturating_sub(before) >= 500
&& WORLD.compare_exchange(u64::MAX, frame, Relaxed, Relaxed).is_ok()
{
tracing::info!(frame, "the first frame of 500 draws or more: frames {} and {} are captured", frame + 2, frame + 6);
#[cfg(feature = "diagnostics")]
if let Some(folder) = folder() {
let lines: Vec<String> = std::mem::take(&mut *RING.lock().unwrap_or_else(|e| e.into_inner())).into();
let _ = std::fs::write(folder.join("before-world-ops.txt"), lines.join("
"));
}
}
}
/// Whether frame `n` is saved.
pub(crate) fn wanted(n: u64) -> bool {
folder().is_some() && (n.is_power_of_two() || listed(n))
// Before the world, with `VICTORY_CAPTURE_WORLD`: every 16th frame too
// (small pictures of menus, loading screens and title cards).
let before_world = world_on() && n % 16 == 0 && WORLD.load(std::sync::atomic::Ordering::Relaxed) == u64::MAX;
// In the world: every 8th frame's picture, a timeline of the opening
// cutscene (its shots do not fall on the same frame numbers from run to
// run, so single frames cannot be compared between runs).
let first = WORLD.load(std::sync::atomic::Ordering::Relaxed);
let in_world = world_on() && first != u64::MAX && n > first && (n - first) % 8 == 0;
folder().is_some() && (n.is_power_of_two() || listed(n) || before_world || in_world)
}
/// Saves 8-bit RGBA or BGRA rows (`pitch` bytes apart) as frame `n`.
@@ -281,6 +402,26 @@ fn dump_one(
}
let pitch = f.RowPitch as usize;
let rows = std::slice::from_raw_parts(data.cast::<u8>(), pitch * f.Height as usize);
// A 24-bit depth plane comes back as 32-bit words: which depth values
// (low 24 bits) and which top bytes it holds, the most common first.
if matches!(d.Format.0, 44..=47) {
let mut depths = std::collections::HashMap::<u32, u32>::new();
let mut tops = std::collections::HashMap::<u32, u32>::new();
for y in 0..f.Height as usize {
for x in 0..f.Width as usize {
let at = y * pitch + x * 4;
let w = u32::from_le_bytes(rows[at..at + 4].try_into().unwrap_or([0; 4]));
*depths.entry(w & 0xff_ffff).or_default() += 1;
*tops.entry(w >> 24).or_default() += 1;
}
}
let most = |m: std::collections::HashMap<u32, u32>| {
let mut v: Vec<(u32, u32)> = m.into_iter().collect();
v.sort_by_key(|e| std::cmp::Reverse(e.1));
(v.len(), v.into_iter().take(12).collect::<Vec<_>>())
};
tracing::info!(?resource, depths = ?most(depths), top_bytes = ?most(tops), "24-bit depth plane values (value, texels)");
}
if let Some(rgba) = to_rgba(f.Format.0 as u32, f.Width as usize, f.Height as usize, pitch, rows) {
let name = format!(
"frame-{frame}-{i:02}-{resource:?}-{}x{}-f{}",
@@ -384,9 +525,54 @@ fn to_rgba(format: u32, w: usize, h: usize, pitch: usize, rows: &[u8]) -> Option
(0.0, finite.fold(0.0f32, f32::max))
};
let range = (high - low).max(1e-20);
tracing::info!(format, low, high, "target values");
// How much of the target holds anything: a lit scene and one bright
// lamp on black have the same highest value.
let above = values.iter().filter(|v| v.iter().any(|c| c.is_finite() && *c > low)).count();
let nonzero_percent = above as f32 * 100.0 / values.len().max(1) as f32;
tracing::info!(format, low, high, nonzero_percent, "target values");
// Small float colour targets (the 1x1 luminance and exposure targets):
// every texel's four channels as numbers. The picture has no alpha and
// eight bits a channel.
if matches!(format, 1..=2 | 9..=10) && w * h <= 16 {
for y in 0..h {
for x in 0..w {
let b = px(x, y, n);
let texel: [f32; 4] = if n == 16 {
[0, 1, 2, 3].map(|i| f32::from_bits(u32_at(b, i)))
} else {
[0, 1, 2, 3].map(|i| half(u16_at(b, i)))
};
tracing::info!(format, x, y, ?texel, "target texel");
}
}
}
// R32_UINT targets hold packed light (the title reads them back as
// R9G9B9E5): as floats their low, high and share above the lowest say
// nothing. How many texels hold any bit, and the highest channel value
// of the packed reading.
if format == 42 {
let (mut set, mut packed_high) = (0usize, 0f32);
for y in 0..h {
for x in 0..w {
let v = u32_at(px(x, y, 4), 0);
set += usize::from(v != 0);
let scale = 2f32.powi((v >> 27) as i32 - 24);
for k in 0..3 {
packed_high = packed_high.max((v >> (9 * k) & 0x1ff) as f32 * scale);
}
}
}
let nonzero_bits_percent = set as f32 * 100.0 / (w * h).max(1) as f32;
tracing::info!(format, nonzero_bits_percent, packed_high, "target values as packed light");
}
// Float colours (scene light) go through a cube root: scaled linearly,
// a night scene under one lamp of 50 units came out all black.
let curved = matches!(format, 1..=2 | 9..=10 | 26);
for v in values {
let c = v.map(|c| (((c - low) / range).clamp(0.0, 1.0) * 255.0) as u8);
let c = v.map(|c| {
let t = ((c - low) / range).clamp(0.0, 1.0);
((if curved { t.cbrt() } else { t }) * 255.0) as u8
});
out.extend([c[0], c[1], c[2], 255]);
}
Some(out)