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 45c6e80601
commit 6fa814fba5
61 files changed
+32259 -1274

No files matched your search

+144 -18
View File
@@ -33,7 +33,7 @@
use crate::ShaderError;
use crate::gfx10::{Fields, Operand};
use crate::ir::{Inst, Program, Reg, Value};
use crate::ir::{Exit, Inst, Program, Reg, Value, operand_reads};
use crate::native::{HwStage, NativeProgram, PsInput, StageIo, Usage};
use crate::resource::Site;
@@ -138,6 +138,11 @@ pub enum Interp {
/// One vertex's value (`v_interp_mov_f32`), as encoded: 0 for P10,
/// 1 for P20, 2 for P0 (the provoking vertex).
Vertex { attribute: Attribute, vertex: u8 },
/// A half of an interpolation whose i or j is computed rather than
/// loaded: each half evaluates as the hardware does, from the
/// attribute's vertex values (`v_interp_p1*`: P0 + i P10, with P10 =
/// P1 - P0; `v_interp_p2*`: its old dst + j P20, with P20 = P2 - P0).
Weighted { attribute: Attribute },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -238,13 +243,52 @@ pub fn raise(p: &Program, native: &NativeProgram) -> Result<Io, ShaderError> {
(loaded, &[][..], &[][..])
}
(StageIo::Ms(ms), HwStage::Ms) => {
let group = p.inputs.iter().find(|i| i.0 == Reg::V(5)).map(|i| i.1);
// The group input, and the phis that may carry it past a join.
let mut group: Vec<Value> = p
.inputs
.iter()
.filter(|i| i.0 == Reg::V(5))
.map(|i| i.1)
.collect();
// No lane is active over the EXEC-zero edge of s_cbranch_execz or
// _execnz, the same case as a partial-EXEC write below.
let no_lanes = |q: usize, b: usize| match (
p.blocks[q].insts.last().map(Inst::name),
p.blocks[q].exit,
) {
(Some("s_cbranch_execz"), Exit::Branch { taken, not_taken }) => {
taken == b && not_taken != b
}
(Some("s_cbranch_execnz"), Exit::Branch { taken, not_taken }) => {
not_taken == b && taken != b
}
_ => false,
};
while let Some(v) = p
.blocks
.iter()
.enumerate()
.flat_map(|(b, k)| k.phis.iter().map(move |f| (b, f)))
.find_map(|(b, f)| {
let mut args = f.args.iter().zip(&p.blocks[b].preds);
let carried = args.any(|(a, &q)| group.contains(a) && !no_lanes(q, b));
(carried && !group.contains(&f.value)).then_some(f.value)
})
{
group.push(v);
}
// The group input holds the same value in every lane only as the
// first lane reads it; a VGPR write reads its old value too.
// first lane reads it. A write to v5 reads its old value too, which
// only lanes outside EXEC keep.
// shortcut: writes that may keep the old v5 in active lanes
// (v_fmac_f32's accumulator, a 16-bit half or d16 load,
// v_writelane_b32, v_movreld_b32, DPP that skips lanes) and
// partial-EXEC writes pass; check those too if a mesh program
// writes v5 that way.
let per_lane = p.blocks.iter().flat_map(|b| &b.insts).find(|i| {
group.is_some_and(|g| i.reads.contains(&(Reg::V(5), g)))
i.read(Reg::V(5)).is_some_and(|v| group.contains(&v))
&& i.name() != "v_readfirstlane_b32"
&& i.write(Reg::V(5)).is_none()
&& (i.write(Reg::V(5)).is_none() || operand_reads(p, i).contains(&Reg::V(5)))
});
if let Some(i) = per_lane {
return Err(unsupported(
@@ -352,7 +396,7 @@ pub fn raise(p: &Program, native: &NativeProgram) -> Result<Io, ShaderError> {
&barycentric,
)
.map_err(|what| unsupported(at, what))?;
io.interps.push((site, interp.with(attribute)));
push_pair(&mut io, site, interp, attribute);
}
_ => return Err(unsupported(at, "an interpolation form")),
}
@@ -368,7 +412,7 @@ pub fn raise(p: &Program, native: &NativeProgram) -> Result<Io, ShaderError> {
let interp = halves
.pair(&v.src[0], read(2), read(1), &barycentric)
.map_err(|what| unsupported(at, what))?;
io.interps.push((site, interp.with(attribute)));
push_pair(&mut io, site, interp, attribute);
}
_ => return Err(unsupported(at, "an interpolation form")),
},
@@ -439,22 +483,39 @@ fn ps_vgprs(addr: u32) -> Vec<(u8, Input)> {
out
}
/// An interpolation before its attribute is known.
/// An interpolation before its attribute is known: `barycentric` none
/// when i or j is computed.
struct Pair {
barycentric: Barycentric,
barycentric: Option<Barycentric>,
first: Vec<Site>,
}
impl Pair {
fn with(self, attribute: Attribute) -> Interp {
Interp::Interpolated {
attribute,
barycentric: self.barycentric,
first: self.first,
match self.barycentric {
Some(barycentric) => Interp::Interpolated {
attribute,
barycentric,
first: self.first,
},
None => Interp::Weighted { attribute },
}
}
}
/// Records interpolation `pair` at `site`, and its first halves too when
/// they evaluate on their own (computed barycentrics).
fn push_pair(io: &mut Io, site: Site, pair: Pair, attribute: Attribute) {
if pair.barycentric.is_none() {
for &f in &pair.first {
if !io.interps.iter().any(|(s, _)| *s == f) {
io.interps.push((f, Interp::Weighted { attribute }));
}
}
}
io.interps.push((site, pair.with(attribute)));
}
/// Finds the first halves of interpolations.
struct Halves<'a> {
p: &'a Program,
@@ -465,7 +526,9 @@ struct Halves<'a> {
impl Halves<'_> {
/// The interpolation whose second half reads the first half's result
/// `acc`, the barycentric `j`, and attribute `attr`: every first half
/// must read the same attribute channel and the same kind's i.
/// must read the same attribute channel. With j and every first half's
/// i loaded as one kind's, the pair interpolates with that kind;
/// otherwise each half evaluates on its own (`Interp::Weighted`).
fn pair(
&self,
attr: &Operand,
@@ -479,8 +542,9 @@ impl Halves<'_> {
&mut Vec::new(),
&mut first,
)?;
let Some((kind, 1)) = barycentric(j) else {
return Err("an interpolation with computed barycentrics");
let mut kind = match barycentric(j) {
Some((kind, 1)) => Some(kind),
_ => None,
};
for &(b, i) in &first {
let inst = &self.p.blocks[b].insts[i];
@@ -499,8 +563,8 @@ impl Halves<'_> {
if a != *attr {
return Err("interpolation halves of different attributes");
}
if barycentric(i) != Some((kind, 0)) {
return Err("an interpolation with computed barycentrics");
if kind.is_some_and(|k| barycentric(i) != Some((k, 0))) {
kind = None;
}
}
Ok(Pair {
@@ -634,6 +698,33 @@ mod tests {
assert!(raise(&other, &pixel(vec![TEXCOORD], 2)).is_err());
}
#[test]
fn computed_barycentrics_evaluate_each_half() {
// i scaled before the first half: both halves stand on their own.
let p = program(&[
0x1006_00F0, // v_mul_f32 v3, 0.5, v0
0xC808_0003, // v_interp_p1_f32 v2, v3, attr0.x
0xC809_0001, // v_interp_p2_f32 v2, v1, attr0.x
S_ENDPGM,
]);
let io = raise(&p, &pixel(vec![TEXCOORD], 2)).unwrap();
let attribute = Attribute {
usage: Usage::Generic,
row: 1,
channel: 0,
high: false,
};
let mut interps = io.interps.clone();
interps.sort_by_key(|i| i.0);
assert_eq!(
interps,
[
((0, 1), Interp::Weighted { attribute }),
((0, 2), Interp::Weighted { attribute }),
]
);
}
#[test]
fn mesh_inputs_and_primitive_export() {
let mesh = |words: &[u32]| {
@@ -669,6 +760,41 @@ mod tests {
assert_eq!(io.exports[0].target, Target::Primitive);
// The group input is uniform only as the first lane reads it.
assert!(mesh(&[0x7E02_0305, S_ENDPGM]).is_err()); // v_mov_b32 v1, v5
// Also as an operand of a write to v5, or after a join.
let per_lane: [&[u32]; 5] = [
&[0x4A0A_0305, S_ENDPGM], // v_add_nc_u32 v5, v5, v1
&[0x7E0A_0D05, S_ENDPGM], // v_cvt_f32_u32 v5, v5
&[0xDC30_8000, 0x0500_0005, S_ENDPGM], // global_load_dword v5, v5, s[0:1]
&[0x7E0A_CB01, S_ENDPGM], // v_swap_b32 v5, v1
&[
0xBF06_8001, // s_cmp_eq_u32 s1, 0
0xBF85_0001, // s_cbranch_scc1 -> 0xc
0x7E0A_0280, // v_mov_b32 v5, 0
0x7E02_0305, // 0xc: v_mov_b32 v1, v5
S_ENDPGM,
],
];
let accepted: Vec<_> = per_lane.iter().filter(|w| mesh(w).is_ok()).collect();
assert!(accepted.is_empty(), "accepted: {accepted:08X?}");
// Overwriting v5 reads the group input only for lanes outside EXEC:
// v_mov_b32 v5, 0; v_mov_b32 v1, v5.
assert!(mesh(&[0x7E0A_0280, 0x7E02_0305, S_ENDPGM]).is_ok());
// Skipping that write with s_cbranch_execz is the same case: under the
// same mask, the read sees only the 0.
let reuse = [
0x7E04_0505, // v_readfirstlane_b32 s2, v5
0x7D88_0084, // v_cmp_gt_u32 vcc, 4, v0
0xBE86_246A, // s_and_saveexec_b64 s[6:7], vcc
0xBF88_0001, // s_cbranch_execz -> 0x14
0x7E0A_0280, // v_mov_b32 v5, 0
0x88FE_067E, // 0x14: s_or_b64 exec, exec, s[6:7]
0xBE86_246A, // s_and_saveexec_b64 s[6:7], vcc
0xBF88_0001, // s_cbranch_execz -> 0x24
0x7E02_0305, // v_mov_b32 v1, v5
0x88FE_067E, // 0x24: s_or_b64 exec, exec, s[6:7]
S_ENDPGM,
];
assert_eq!(mesh(&reuse).map(|_| ()), Ok(()));
}
#[test]