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]>
This commit is contained in:
MarvisandClaude Fable 5.2 committed 2026-11-23 23:10:01 +01:00
1 parent bc3070991a
commit 2849477415
107 files changed
+42526 -868

No files matched your search

+162
View File
@@ -0,0 +1,162 @@
//! Console primitive types the host lacks. A rectangle list gives three
//! corners per rectangle, the second the one between the other two, and
//! the hardware adds the fourth at `v0 + v2 - v1` (Grand Theft Auto VI's
//! full-screen rectangles come as top left, bottom left, bottom right); on
//! the host each rectangle becomes two triangles, with the fourth vertex
//! made from the other three on the CPU.
//!
//! shortcut: the fourth vertex is computed from vertex inputs, not from
//! vertex shader outputs as the hardware does; that is the same for vertex
//! shaders linear in their inputs (blits, 2D quads). Inputs in formats
//! [`components`] does not know keep the first vertex's value.
/// Expands `rects` rectangles of `stride`-byte vertices from `src` into six
/// vertices each in `dst`: `(v0, v1, v2)` and `(v0, v2, v3)`, so both
/// triangles turn the same way. `elements` are (byte offset, format).
pub(crate) fn expand_rects(src: &[u8], dst: &mut [u8], stride: usize, elements: &[(u32, u32)]) {
for (rect, out) in src
.chunks_exact(3 * stride)
.zip(dst.chunks_exact_mut(6 * stride))
{
let v = |i: usize| &rect[i * stride..(i + 1) * stride];
for (slot, i) in [0, 1, 2, 0, 2].into_iter().enumerate() {
out[slot * stride..(slot + 1) * stride].copy_from_slice(v(i));
}
let fourth = &mut out[5 * stride..];
fourth.copy_from_slice(v(0));
for &(offset, format) in elements {
let at = offset as usize;
let Some((n, kind)) = components(format) else {
continue;
};
for c in 0..n {
let get = |i: usize| kind.read(&v(i)[at..], c);
let value = get(0) + get(2) - get(1);
kind.write(&mut fourth[at..], c, value);
}
}
}
}
#[derive(Clone, Copy)]
enum Kind {
F32,
F16,
Unorm8,
Unorm16,
}
/// Component count and kind of the vertex formats rectangles use.
fn components(format: u32) -> Option<(usize, Kind)> {
Some(match format {
2 => (4, Kind::F32),
6 => (3, Kind::F32),
16 => (2, Kind::F32),
41 => (1, Kind::F32),
10 => (4, Kind::F16),
34 => (2, Kind::F16),
54 => (1, Kind::F16),
11 => (4, Kind::Unorm16),
35 => (2, Kind::Unorm16),
28 | 29 | 87 | 91 => (4, Kind::Unorm8),
_ => return None,
})
}
impl Kind {
fn bytes(self) -> usize {
match self {
Kind::F32 => 4,
Kind::F16 | Kind::Unorm16 => 2,
Kind::Unorm8 => 1,
}
}
fn read(self, at: &[u8], c: usize) -> f32 {
let b = &at[c * self.bytes()..];
match self {
Kind::F32 => f32::from_le_bytes([b[0], b[1], b[2], b[3]]),
Kind::F16 => half_to_f32(u16::from_le_bytes([b[0], b[1]])),
Kind::Unorm16 => f32::from(u16::from_le_bytes([b[0], b[1]])) / 65535.0,
Kind::Unorm8 => f32::from(b[0]) / 255.0,
}
}
fn write(self, at: &mut [u8], c: usize, v: f32) {
let n = self.bytes();
let b = &mut at[c * n..(c + 1) * n];
match self {
Kind::F32 => b.copy_from_slice(&v.to_le_bytes()),
Kind::F16 => b.copy_from_slice(&f32_to_half(v).to_le_bytes()),
Kind::Unorm16 => {
b.copy_from_slice(&((v.clamp(0.0, 1.0) * 65535.0).round() as u16).to_le_bytes())
}
Kind::Unorm8 => b[0] = (v.clamp(0.0, 1.0) * 255.0).round() as u8,
}
}
}
fn half_to_f32(h: u16) -> f32 {
let sign = u32::from(h >> 15) << 31;
let exp = u32::from((h >> 10) & 0x1f);
let man = u32::from(h & 0x3ff);
let bits = match (exp, man) {
(0, 0) => sign,
// Subnormal: scale the mantissa.
(0, m) => {
let v = m as f32 * 2f32.powi(-24);
return if sign != 0 { -v } else { v };
}
(31, m) => sign | 0x7f80_0000 | m << 13,
(e, m) => sign | (e + 112) << 23 | m << 13,
};
f32::from_bits(bits)
}
fn f32_to_half(v: f32) -> u16 {
let bits = v.to_bits();
let sign = ((bits >> 16) & 0x8000) as u16;
let exp = ((bits >> 23) & 0xff) as i32 - 127 + 15;
let man = bits & 0x7f_ffff;
if exp >= 31 {
return sign | 0x7c00; // too large: infinity
}
if exp <= 0 {
return sign; // too small: zero
}
sign | (exp as u16) << 10 | ((man + 0x1000) >> 13) as u16
}
#[cfg(test)]
mod tests {
use super::*;
/// A rectangle of float2 positions and RGBA8 colors, given as top
/// left, bottom left, bottom right: the fourth corner completes the
/// parallelogram at the top right.
#[test]
fn rectangles_get_their_fourth_corner() {
let vertex = |x: f32, y: f32, r: u8| {
let mut v = Vec::new();
v.extend(x.to_le_bytes());
v.extend(y.to_le_bytes());
v.extend([r, 0, 0, 255]);
v
};
let src: Vec<u8> = [
vertex(-1.0, 1.0, 0),
vertex(-1.0, -1.0, 100),
vertex(1.0, -1.0, 150),
]
.concat();
let mut dst = vec![0u8; 6 * 12];
expand_rects(&src, &mut dst, 12, &[(0, 16), (8, 28)]);
assert_eq!(dst[..36], src[..]);
assert_eq!(dst[36..48], src[..12]);
assert_eq!(dst[48..60], src[24..36]);
assert_eq!(dst[60..], vertex(1.0, 1.0, 50)[..]);
assert_eq!(f32_to_half(1.5), 0x3e00);
assert_eq!(half_to_f32(0x3e00), 1.5);
assert_eq!(half_to_f32(0xc000), -2.0);
}
}