Port NVIDIA Wave32 lowering, smooth movie-plane uploads, XMA audio fixes, and 32GB RAM residency budgets

This commit is contained in:
codec_d committed 2026-11-25 15:31:19 -08:00
1 parent 45e90f4de8
commit 3bcc96f9bb
11 files changed
+463 -110

No files matched your search

+43 -7
View File
@@ -423,6 +423,7 @@ enum MaskData {
/// What a value holding a lane mask read as a number stops with.
pub(super) const LANE_MASK: Why = "a lane mask read as data";
pub(super) const DIVERGENT_MASK_EXCHANGE: Why = "a lane mask exchanged where not every lane runs";
/// A mask with lanes outside EXEC where it is written, read as a number where the lanes that
/// run that block are not all of the wave.
pub(super) const MASK_ELSEWHERE: Why = "a lane mask holding lanes elsewhere read as data";
@@ -546,7 +547,7 @@ fn need(block: usize) {
/// wave-uniform data in VGPRs and fetches it with `v_readfirstlane`.
/// shortcut: a value joined by a phi counts only where every predecessor is a block all lanes
/// run (no lane branch can have split the arriving lanes); loop-carried values never do.
fn lane_uniform(p: &Program, st: &Structured, all: &[bool]) -> HashSet<Value> {
fn lane_uniform(p: &Program, st: &Structured, all: &[bool], ordered_lds: bool) -> HashSet<Value> {
let is_mask = |v: Value| st.masks.contains_key(&v) || st.highs.contains_key(&v);
let mut same: HashSet<Value> = HashSet::new();
for b in crate::ir::reverse_postorder(&p.blocks) {
@@ -559,6 +560,9 @@ fn lane_uniform(p: &Program, st: &Structured, all: &[bool]) -> HashSet<Value> {
}
for (i, inst) in block.insts.iter().enumerate() {
let name = inst.name();
if st.guards[b][i].is_some() {
continue; // lanes outside EXEC keep another value
}
let ops: Vec<Operand> = match &inst.fields {
Fields::Valu(v)
if v.dpp.is_none()
@@ -569,11 +573,18 @@ fn lane_uniform(p: &Program, st: &Structured, all: &[bool]) -> HashSet<Value> {
{
v.src.clone()
}
Fields::Ds {
addr: Some(Operand::Vector { reg, dwords: 1 }),
gds: false,
..
} if ordered_lds && name == "ds_read_b32" => {
if inst.read(Reg::V(*reg)).is_some_and(|a| same.contains(&a)) {
same.extend(inst.writes.iter().map(|w| w.1));
}
continue;
}
_ => continue,
};
if st.guards[b][i].is_some() {
continue; // lanes outside EXEC keep another value
}
let alike = ops.iter().all(|op| match *op {
Operand::Vector { reg, .. } => {
// every dword of the operand the instruction reads from that register on
@@ -1175,6 +1186,13 @@ thread_local! {
}
pub(super) fn reads_mask_as_data(st: &Structured, i: &Inst) -> bool {
// A scalar select uses the condition of the whole guest wave, even
// when the preceding mask operation has no scalar-dword consumers.
if matches!(i.fields, Fields::Sop { .. } | Fields::Valu(_))
&& i.read(Reg::Scc).is_some_and(|s| st.scc_some.contains_key(&s))
{
return true;
}
let is_mask = |v: Value| st.masks.contains_key(&v) || st.highs.contains_key(&v);
let ops: Vec<&Operand> = match &i.fields {
// A mask operation (its result a mask) is no data use.
@@ -1678,7 +1696,9 @@ impl<'a> Lower<'a> {
local_ok: false,
local_any: LOCAL_ANY.get(),
uniform: match &exchange {
Some((_, false, all)) if !LOCAL_WAVES.get() => lane_uniform(p, x.st, all),
Some((_, false, all)) if !LOCAL_WAVES.get() => {
lane_uniform(p, x.st, all, split_lds && super::group_sync() != 0)
}
_ => HashSet::new(),
},
own_bits: match &exchange {
@@ -3526,7 +3546,7 @@ impl<'a> Lower<'a> {
} else if !self.exchange.as_ref().is_some_and(|e| e.1) && !b.is_none_or(|b| self.all_lanes(b)) {
// (a group of 32 or fewer has no other half to exchange with)
need(b.unwrap_or(0));
return Err("a lane mask exchanged where not every lane runs");
return Err(DIVERGENT_MASK_EXCHANGE);
}
xy = self.exchange_halves(at, xy.0);
}
@@ -4227,7 +4247,7 @@ impl<'a> Lower<'a> {
}
if !made.is_none_or(|b| self.all_lanes(b)) {
need(made.unwrap_or(0));
return Err("a lane mask exchanged where not every lane runs");
return Err(DIVERGENT_MASK_EXCHANGE);
}
let some = self.s.m.cast(at, Cast::ZExt, some, i32t);
let (lo, hi) = self.exchange_halves(at, some);
@@ -6026,6 +6046,13 @@ impl<'a> Lower<'a> {
fn scc_in(&mut self, inst: &Inst) -> Result<V, Why> {
let v = inst.read(Reg::Scc).ok_or("an unread SCC")?;
if self.x.st.scc_some.contains_key(&v)
&& matches!(self.vals.get(&v), None | Some(Val::Missing(_)))
{
let x = self.scc_some(v)?;
self.vals.insert(v, Val::Bit(x));
return Ok(x);
}
match self.get(v) {
Ok(Val::Bit(x)) => Ok(x),
Ok(_) => Err("SCC without a value"),
@@ -7694,6 +7721,15 @@ impl<'a> Lower<'a> {
unreachable!()
};
let name = inst.name();
if let Some(&source) = self.x.res.restored_lanes.get(&(b, i)) {
// This lane was overwritten by a uniform scalar. The previous
// contents of other lanes can be unknown (a reduction scratch).
let word = match source {
crate::resource::Moved::Value(v) => self.i32_of(v)?,
crate::resource::Moved::Const(k) => self.s.m.i32(k),
};
return self.write_i(inst, word, None);
}
if self.x.res.waterfall.compares.contains(&(b, i)) {
// The first lane's dwords of a waterfall loop are each lane's
// own (see `resource::Waterfall`).
+58 -6
View File
@@ -511,7 +511,24 @@ pub fn emit(
// lost the card in a submission of two programs that had just moved to it
// (`ptfx_CS_lightAtlas_Sprite` and `_Trail`). The 32-lane programs' form below, which
// has no barrier, stays on.
let wide_on = std::env::var_os("VICTORY_WAVE_WIDE").is_some_and(|v| v == "1");
let wide_option = std::env::var_os("VICTORY_WAVE_WIDE");
// Both archived kernels use one logical wave per group and have
// validated wave32 PSOs on RTX. Explicit policy wins.
let scene_kernel = matches!(native.io, crate::native::StageIo::Cs(cs) if cs.threads.iter().product::<u32>() == 64)
&& matches!(
c.digest,
[0x58, 0x1d, 0xab, 0x2c, 0xd8, 0xbc, 0xf2, 0x2e, 0x5c, 0x96, 0x4b, 0x98, 0xe9, 0x03, 0x48, 0xd1]
| [0x24, 0x31, 0xbb, 0xe7, 0xdc, 0x15, 0x4a, 0xd7, 0x59, 0xd2, 0x0b, 0xc9, 0x54, 0x82, 0x9c, 0x1c]
);
let wide_on = wide_option.as_ref().map_or(scene_kernel, |v| v == "1");
// A single guest wave can iterate an active-lane loop until both host
// halves have finished. The precise latch and convergence conditions
// for the driver compute route are checked by widen().
let driver_loop = wide_option.is_none()
&& c.part(FourCC::DXIL).is_none()
&& c.part(FourCC::ACCC).is_some()
&& matches!(&original, Err(ShaderError::Unsupported { what, .. })
if *what == lower::DIVERGENT_MASK_EXCHANGE);
// exact first: each host wave on its own where that is exact (the idiom, every
// form; no barriers), then the other exact forms; then approximate
for exact in [true, false] {
@@ -533,7 +550,7 @@ pub fn emit(
// Still stopped where not every lane runs: the per-lane branches around
// those places taken as the console takes them, by the whole wave at once
// ([`widen`]), at two group barriers per such branch.
if wide_on {
if wide_on || driver_loop {
let bases = [
deep.as_ref().map(|f| &f.0),
forms[1].1.as_ref().map(|f| &f.0),
@@ -541,7 +558,7 @@ pub fn emit(
Some(p),
];
if let Some(base) = bases.into_iter().flatten().next() {
let again = widen(c, native, base, why);
let again = widen(c, native, base, why, driver_loop);
report("wave-wide branches", &again);
if done(&again) {
return again.map(|(shader, _)| shader);
@@ -603,7 +620,7 @@ pub fn emit(
&& what == lower::LANE_MASK
&& std::env::var_os("VICTORY_WAVE_WIDE").is_none_or(|v| v != "0") =>
{
let again = widen(c, native, p, std::env::var_os("VICTORY_WAVE_WHY").is_some());
let again = widen(c, native, p, std::env::var_os("VICTORY_WAVE_WHY").is_some(), false);
match again {
Ok(_) => again,
Err(_) => emit_program(c, native, p, st, io, res),
@@ -611,7 +628,17 @@ pub fn emit(
}
other => other,
};
let original = original.map(|(shader, _)| shader);
let supported = |(shader, wave): (HostShader, Option<u32>)| {
if wave == Some(64) && lower::host_max_wave() == 32 {
Err(ShaderError::Unsupported {
offset: 0,
what: "no wave32 lowering for this wave64 program",
})
} else {
Ok(shader)
}
};
let original = original.and_then(supported);
// Retry unsupported programs only. Threading can separate an unknown
// register value from its apparent use on a mutually exclusive path.
if !matches!(original, Err(ShaderError::Unsupported { .. })) {
@@ -625,7 +652,7 @@ pub fn emit(
let st = structure::structure(&p)?;
let io = io::raise(&p, native)?;
let res = resource::track(&p, &native.layout, native.stage, Some(&st))?;
emit_program(c, native, &p, &st, &io, &res).map(|(shader, _)| shader)
emit_program(c, native, &p, &st, &io, &res).and_then(supported)
}
/// `p` (a console wave64 compute program on a host of 32-lane waves) with the per-lane
@@ -640,6 +667,7 @@ fn widen(
native: &NativeProgram,
p: &ir::Program,
why: bool,
active_loop_only: bool,
) -> Result<(HostShader, Option<u32>), ShaderError> {
const NOT: ShaderError = ShaderError::Unsupported {
offset: 0,
@@ -687,6 +715,30 @@ fn widen(
}
return r;
}
if active_loop_only {
// Only a single backward branch on the SCC just set by
// s_andn2_wrexec_b64. This instruction restricts EXEC to the
// unfinished lanes. The guest repeats the loop if *either*
// half still has work, while individual vector writes retain
// their EXEC predicates.
let [latch] = more.as_slice() else {
return r;
};
let block = &p.blocks[*latch];
let [.., update, branch] = block.insts.as_slice() else {
return r;
};
if !wide.is_empty()
|| update.name() != "s_andn2_wrexec_b64"
|| branch.name() != "s_cbranch_scc1"
|| !matches!(
block.exit,
ir::Exit::Branch { taken, not_taken } if taken <= *latch && not_taken > *latch
)
{
return r;
}
}
wide.extend(more);
}
}