Files
6gbvram---16gb-ram/crates/victory-gpu/src/copystat.rs
T
MarvisandClaude Fable 5.2 2849477415 Run Grand Theft Auto VI from first boot into the world
The title now boots through every first-boot and menu screen at its own
30 fps, drawing with translated shaders, with input, sound, saves and
loading served; it reaches the world, where the host GPU path still
fails (see "Not working yet").

Loader and runtime
- Crash reports unwind properly, name C++ throws and host GPU failures,
  carry the title's last debug lines and are appended to crashes.log.
- Thread notices on our own threads, reentrant late DLL loading, exit in
  the console's order, relaunch on a launch-new-game request.
- Offline guard: the title cannot reach the network (sockets, name
  lookups, WinHTTP, the media source resolver); by-name lookups and
  loads follow the import rules.
- Every runtime area the title calls is served (networking hint,
  packages, store, saves, display, UI, speech stubs, user, async pool).
  Saves persist; an update is one rename and survives a kill at any step.
- DirectStorage reads for real: shared worker pool, priorities, zlib and
  BCPack. BCPack is our own decoder; the format's constant tables ship in
  crates/victory-formats/src/bcpack-tables.bin (the asset policy's one
  exception, see docs/asset-policy.md).
- GameInput from XInput pads and the keyboard, with a keyboard stand-in
  pad; console timers (1 ms) for the whole process.
- Audio: XMA2 decoding on the emulated contexts, Opus on the decoder
  queues, the DSP interface as a stub; title memory placed below 2^40.
- Console texture layouts (sizes, tiling, detiling) and the layout
  library's imports.

GPU
- Draws, mesh dispatches and compute dispatches run on the host with
  shaders translated at first use and cached on disk; descriptor heaps,
  views, root signatures, barriers and host texture states; rectangle
  lists; comparison samplers.
- Title memory reaches the host through persistent mirrors that copy
  only pages written since the last copy; shader-written buffers are
  copied back.
- Presentation with frame pacing per event kind; framerate in the window
  caption.

Shaders
- DXIL emission for vertex, pixel, compute and mesh programs from the
  console's native code, with a differential test suite against the PC
  compile. World set: mesh 8,191 of 8,506, vertex/pixel 10,617 of
  12,346, compute 1,643 of 2,539; utility set complete.

Build
- Debugging aids (debug logs, frame capture, stack dumps, scripted keys,
  the host debug layer, the software adapter) exist only with the
  `diagnostics` feature; `[profile.diag]` keeps that build apart.

Not working yet
- In the world the host device is removed within seconds (descriptor
  handling fixes are in, unproven by a surviving run) and frames present
  black.
- 64-bit image atomics, merged geometry stages and the BVH builder's own
  shaders do not translate; reverb is silent.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-23 23:10:01 +01:00

148 lines
5.2 KiB
Rust

//! Diagnostics: where the submission copies of title memory go (which
//! ranges, how often, of what memory) and what limits their rate, logged
//! with the frame-rate line. `VICTORY_COPY_MODE=plain` copies without the
//! mapped-page guard, `none` skips the copies (both for timing only).
use std::collections::HashMap;
use std::sync::Mutex;
use std::sync::atomic::{AtomicU64, Ordering::Relaxed};
/// Counters since the last line.
pub(crate) enum C {
Submissions,
Copies,
CopyBytes,
Refreshes,
RefreshBytes,
Skipped,
SkippedBytes,
Runs,
RunUs,
Queries,
QueryUs,
MoveUs,
Unmapped,
/// Write-watch askings and their time.
Watches,
WatchUs,
/// Bytes of watched ranges checked, and of those found unchanged.
Checked,
Unchanged,
/// Copies that met an unmapped page.
Fallbacks,
/// Writes taken by the guard on view memory.
GuardFaults,
/// Texture bytes detiled after a watched write; hashed; detiled after a
/// hash change.
TexWatched,
TexHashed,
TexChanged,
}
const COUNTERS: usize = 22;
static COUNT: [AtomicU64; COUNTERS] = [const { AtomicU64::new(0) }; COUNTERS];
pub(crate) fn add(c: C, n: u64) {
COUNT[c as usize].fetch_add(n, Relaxed);
}
/// How copies run: 0 guarded (as always), 1 plain, 2 not at all.
pub(crate) fn mode() -> u8 {
static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new();
*MODE.get_or_init(|| match std::env::var("VICTORY_COPY_MODE").as_deref() {
Ok("plain") => 1,
Ok("none") => 2,
_ => 0,
})
}
/// Per source range (start, length): copies, bytes, microseconds, memory type.
type Ranges = HashMap<(usize, usize), (u64, u64, u64, u32)>;
static RANGES: Mutex<Option<Ranges>> = Mutex::new(None);
/// A copy of `len` bytes from `src` (memory type `kind`) took `us`.
pub(crate) fn range(src: usize, len: usize, us: u64, kind: u32) {
let mut map = RANGES.lock().unwrap_or_else(|e| e.into_inner());
let e = map
.get_or_insert_with(HashMap::new)
.entry((src, len))
.or_insert((0, 0, 0, kind));
e.0 += 1;
e.1 += len as u64;
e.2 += us;
}
fn page_faults() -> u64 {
use windows_sys::Win32::System::ProcessStatus::{
K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS,
};
use windows_sys::Win32::System::Threading::GetCurrentProcess;
let mut c = PROCESS_MEMORY_COUNTERS {
cb: size_of::<PROCESS_MEMORY_COUNTERS>() as u32,
..Default::default()
};
// SAFETY: our own process and a sized structure.
unsafe { K32GetProcessMemoryInfo(GetCurrentProcess(), &mut c, c.cb) };
u64::from(c.PageFaultCount)
}
/// Logs the counters per frame over `frames` frames, and the ranges that
/// took most bytes.
pub(crate) fn log(frames: f64) {
static FAULTS: AtomicU64 = AtomicU64::new(0);
let faults = page_faults();
let faults = faults - FAULTS.swap(faults, Relaxed).min(faults);
let c: Vec<f64> = COUNT
.iter()
.map(|a| a.swap(0, Relaxed) as f64 / frames)
.collect();
let mb = |v: f64| v / 1e6;
let ms = |v: f64| v / 1e3;
tracing::info!(
"copies per frame: {:.1} submissions; {:.0} title copies {:.1} MB; {:.0} refreshes {:.1} MB, \
{:.0} skipped {:.1} MB; {:.0} runs {:.1} ms; {:.0} queries {:.2} ms, moves {:.2} ms, \
{:.2} MB unmapped; {:.0} page faults; {:.0} watches {:.2} ms, {:.1} MB checked, {:.1} MB \
unchanged; {:.1} fallbacks; {:.0} guard faults; textures {:.1} MB watched and \
changed, {:.1} MB hashed, {:.1} MB of them changed",
c[C::Submissions as usize],
c[C::Copies as usize],
mb(c[C::CopyBytes as usize]),
c[C::Refreshes as usize],
mb(c[C::RefreshBytes as usize]),
c[C::Skipped as usize],
mb(c[C::SkippedBytes as usize]),
c[C::Runs as usize],
ms(c[C::RunUs as usize]),
c[C::Queries as usize],
ms(c[C::QueryUs as usize]),
ms(c[C::MoveUs as usize]),
mb(c[C::Unmapped as usize]),
faults as f64 / frames,
c[C::Watches as usize],
ms(c[C::WatchUs as usize]),
mb(c[C::Checked as usize]),
mb(c[C::Unchanged as usize]),
c[C::Fallbacks as usize],
c[C::GuardFaults as usize],
mb(c[C::TexWatched as usize]),
mb(c[C::TexHashed as usize]),
mb(c[C::TexChanged as usize]),
);
let ranges = RANGES.lock().unwrap_or_else(|e| e.into_inner()).take();
let mut ranges: Vec<_> = ranges.into_iter().flatten().collect();
ranges.sort_by_key(|&(_, (_, bytes, _, _))| std::cmp::Reverse(bytes));
for ((src, len), (n, bytes, us, _)) in ranges.into_iter().take(10) {
use windows_sys::Win32::System::Memory::{MEMORY_BASIC_INFORMATION, VirtualQuery};
// SAFETY: plain data filled in by the query.
let mut info: MEMORY_BASIC_INFORMATION = unsafe { std::mem::zeroed() };
// SAFETY: a valid out pointer of the right size.
unsafe { VirtualQuery(src as *const _, &mut info, size_of_val(&info)) };
let kind = info.Type;
tracing::info!(
" copied from {src:#x}+{len:#x} (memory {kind:#x}): {:.1}x/frame, {:.2} MB/frame, {:.2} ms/frame",
n as f64 / frames,
bytes as f64 / 1e6 / frames,
us as f64 / 1e3 / frames
);
}
}