Files
6gbvram---16gb-ram/crates/victory-gpu/src/sampler.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

120 lines
4.0 KiB
Rust

//! Samplers as the host describes them, from the console's sampler
//! description (`CreateSamplerX`), which names the hardware's sampler
//! fields. (Immediate samplers in shader code come decoded with the
//! translation.)
use windows::Win32::Graphics::Direct3D12::*;
/// The fields both forms share.
#[derive(Debug, Clone, Copy, PartialEq)]
struct Fields {
/// Point 0, bilinear 1, anisotropic point 2, anisotropic bilinear 3.
mag: u32,
min: u32,
/// None 0, point 1, linear 2.
mip: u32,
/// Plain 0, minimum 1, maximum 2.
mode: u32,
/// Host address modes.
address: [u32; 3],
anisotropy: u32,
/// Host comparison function.
compare: u32,
min_lod: f32,
max_lod: f32,
bias: f32,
border: [f32; 4],
}
impl Fields {
fn host(&self) -> D3D12_SAMPLER_DESC {
let linear = |f: u32| u32::from(f == 1 || f == 3);
let aniso = self.mag >= 2 || self.min >= 2;
// The console compares when the instruction says so, with the
// sampler's function; the host needs a comparison sampler for that.
// A sampler given a real test (less ... greater-or-equal) is one;
// never, always and none are plain samplers.
const LESS: u32 = 2;
const GREATER_EQUAL: u32 = 7;
let compares = (LESS..=GREATER_EQUAL).contains(&self.compare);
let reduction = match self.mode {
1 => 2,
2 => 3,
_ => u32::from(compares),
};
let filter = if aniso {
0x55
} else {
linear(self.min) << 4 | linear(self.mag) << 2 | u32::from(self.mip == 2)
};
D3D12_SAMPLER_DESC {
Filter: D3D12_FILTER((reduction << 7 | filter) as i32),
AddressU: D3D12_TEXTURE_ADDRESS_MODE(self.address[0] as i32),
AddressV: D3D12_TEXTURE_ADDRESS_MODE(self.address[1] as i32),
AddressW: D3D12_TEXTURE_ADDRESS_MODE(self.address[2] as i32),
MipLODBias: self.bias,
MaxAnisotropy: if aniso {
self.anisotropy.clamp(1, 16)
} else {
1
},
ComparisonFunc: D3D12_COMPARISON_FUNC(self.compare.max(1) as i32),
BorderColor: self.border,
MinLOD: self.min_lod,
// Without a mip filter the console samples mip 0 only.
MaxLOD: if self.mip == 0 {
self.min_lod
} else {
self.max_lod
},
}
}
}
/// The console's sampler description (27 words): flags, magnification,
/// minification, mip and depth filters, filter mode, three address modes,
/// minimum and maximum LOD, LOD bias, secondary bias, anisotropy, its bias
/// and threshold, comparison, border color, then tuning words.
pub(crate) fn console(words: &[u32; 27]) -> D3D12_SAMPLER_DESC {
let f = |i: usize| f32::from_bits(words[i]);
Fields {
mag: words[1],
min: words[2],
mip: words[3],
mode: words[5],
address: [words[6], words[7], words[8]],
min_lod: f(9),
max_lod: f(10),
bias: f(11),
anisotropy: words[13],
compare: words[16],
border: [f(17), f(18), f(19), f(20)],
}
.host()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn console_descriptions_decode() {
let mut w = [0u32; 27];
w[1] = 1; // bilinear magnification
w[2] = 0; // point minification
w[3] = 2; // linear mips
w[6..9].copy_from_slice(&[3, 3, 3]);
w[10] = 1000.0f32.to_bits();
let d = console(&w);
assert_eq!(d.Filter.0, 0x5, "min point, mag and mip linear");
assert_eq!(d.AddressW, D3D12_TEXTURE_ADDRESS_MODE_CLAMP);
assert_eq!(d.MaxLOD, 1000.0);
// A less-or-equal test makes a comparison sampler; never does not.
w[16] = 4;
assert_eq!(console(&w).Filter.0, 0x85);
assert_eq!(console(&w).ComparisonFunc, D3D12_COMPARISON_FUNC_LESS_EQUAL);
w[16] = 1;
assert_eq!(console(&w).Filter.0, 0x5);
}
}