diff --git a/README.md b/README.md index 384f15b90c..8a663576b4 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,9 @@ next to `xcl.exe`, directly next to `xcl.exe`, in `%LOCALAPPDATA%\XCL\D3D12\`, o (NVIDIA) console wave64 compute, geometry and mesh programs run as two 32-lane halves that exchange masks and lane values ([`docs/wave64-on-wave32.md`](docs/wave64-on-wave32.md)) – slower than 64-lane waves, most for groups of several waves; wave64 vertex and pixel shaders that read lanes 32–63 - can still differ there. With `XCL_DIRECT_DXIL=1` and `XCL_PER_LANE=1`, compute groups + can still differ there. Recognized compiler-pattern wave64 vertex and pixel min/max/and/or + reductions are rebuilt over the lanes the GPU launched; other missing-lane reads and scalar + spills can still differ in partial waves. With `XCL_DIRECT_DXIL=1` and `XCL_PER_LANE=1`, compute groups made up of complete native waves can use the per-lane form for branches on whole-wave masks; split-wave64 programs that access LDS stay on the HLSL path to preserve instruction order between their two hardware wave32 halves. diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index c0b5e2396a..58bdbc1bd6 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -238,6 +238,9 @@ fn translate_on_this_thread( return Err("split wave64 LDS access needs the HLSL path".into()); } let leaders: BTreeSet = cfg.blocks.iter().filter_map(|b| b.insts.first().map(|&i| cfg.insts[i].pc)).collect(); + if gfx && !crate::gpu::recomp::graphics_reductions(&cfg.insts, &leaders, o.wave64).reads.is_empty() { + return Err("graphics whole-wave reduction needs the HLSL path".into()); + } let mut lw = Lw::new(&cfg.insts, &leaders, o, &entry); let uses_lds = lw.lds.is_some(); let res = lw.res; diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 08b4624379..18ff390242 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -17,7 +17,7 @@ pub(super) enum Flow { } pub(super) struct Em { - /// whole-wave reductions (`wave32_reductions`) + /// whole-wave reductions (`graphics_reductions`) pub reductions: super::Reductions, opt: Options, out: String, @@ -4129,9 +4129,11 @@ impl Em { } "v_readlane_b32" => { let t = self.t(); - // the end of a whole-wave reduction (`wave32_reductions`) - if let Some((seed, op)) = self.reductions.reads.get(&d.pc) { - self.line(&format!("uint {t} = xcl_red_{op}(xcl_seed_{seed:x});")); + // the end of a compiler whole-wave reduction (`graphics_reductions`) + if let Some(red) = self.reductions.reads.get(&d.pc).copied() { + let scope = if red.scope == super::ReductionScope::Whole64 { "64" } else { "" }; + self.line(&format!("uint {t} = xcl_red{scope}_{}(xcl_seed_{:x});", red.op, red.seed)); + self.write32(&Dst::V(red.accum), &t); self.write32(&dst, &t); return Ok(()); } @@ -6402,12 +6404,13 @@ void xcl_s_barrier() { } "#; -/// Whole-wave reductions of wave32 VS / PS programs (`wave32_reductions`). The console's combine +/// Whole-wave reductions of graphics programs (`graphics_reductions`). The console combines /// the lanes through DPP and permlane steps that pass partial results through lanes that were /// never launched (`s_or_saveexec -1` runs them); here those lanes do not exist and the steps /// read 0 from them, so a wave that is not full lost the words of live lanes. The lanes of each -/// half of a 64-lane wave are a console wave of their own. A helper lane is in no wave -/// operation and gets the result of a live lane of its quad (every quad has one). +/// half of a 64-lane hardware wave is a wave32 console wave of its own; a wave64 program reduces +/// the launched hardware wave once. A helper lane is in no wave operation and gets the result of +/// a live lane of its quad (every quad has one). const PRELUDE_REDUCE: &str = r#" uint xcl_red_share(uint r) { #ifdef XCL_PIXEL @@ -6435,6 +6438,10 @@ uint xcl_red_min(uint x) { uint a = WaveActiveMin(select(xcl_half == 0u, x, 0xFFFFFFFFu)), b = WaveActiveMin(select(xcl_half == 0u, 0xFFFFFFFFu, x)); return xcl_red_share(select(xcl_half == 0u, a, b)); } +uint xcl_red64_or(uint x) { return xcl_red_share(WaveActiveBitOr(x)); } +uint xcl_red64_max(uint x) { return xcl_red_share(WaveActiveMax(x)); } +uint xcl_red64_and(uint x) { return xcl_red_share(WaveActiveBitAnd(x)); } +uint xcl_red64_min(uint x) { return xcl_red_share(WaveActiveMin(x)); } "#; /// Pixel shaders: masks hold the helper lanes (#105). After `s_wqm` the helper pixels of a diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index e9a8429b7f..ec2ceca33c 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -976,20 +976,35 @@ fn structurable_uncached(c: &Ctx, lo: u64, hi: u64, exit: Option, nest: usi Some(pending) } -/// The whole-wave reductions of a wave32 program (`wave32_reductions`). +#[derive(Clone, Copy, PartialEq, Eq)] +pub(crate) enum ReductionScope { + Half32, + Whole64, +} + +#[derive(Clone, Copy)] +pub(crate) struct Reduction { + pub seed: u64, + pub accum: u64, + pub op: &'static str, + pub scope: ReductionScope, +} + +/// The compiler's whole-wave reductions in vertex and pixel shaders. #[derive(Default)] pub struct Reductions { /// pc of a `v_cndmask` that starts one → the VGPR it writes - pub seeds: std::collections::BTreeMap, - /// pc of the `v_readlane` that ends one → (its seed's pc, the operation: `xcl_red_`) - pub reads: std::collections::BTreeMap, + pub(crate) seeds: std::collections::BTreeMap, + /// pc of the `v_readlane` that ends one → its reduction + pub(crate) reads: std::collections::BTreeMap, } -/// The reductions the console's compiler makes over the lanes of a wave32 wave: +/// The reductions the console's compiler makes over the lanes of a graphics wave: /// `s_or_saveexec_b32 s, -1` (every lane runs, launched or not), `v_cndmask v, identity, value, /// mask`, three DPP8 steps (within 2, 4 and 8 lanes), a DPP row mirror, `v_permlanex16 w, v`, one more -/// step and `v_readlane s, v, 0` – nothing else in between, all in one basic block. -fn wave32_reductions(insts: &[Decoded], leaders: &std::collections::BTreeSet) -> Reductions { +/// step and `v_readlane s, v, 0`. Wave64 adds a read of lane 32 and one last combine before that +/// read. Nothing else is in between and the sequence is all in one basic block. +pub(crate) fn graphics_reductions(insts: &[Decoded], leaders: &std::collections::BTreeSet, wave64: bool) -> Reductions { let op_of = |d: &Decoded| match d.inst.name { "V_OR_B32" => Some(("or", 128)), "V_MAX_U32" => Some(("max", 128)), @@ -999,6 +1014,11 @@ fn wave32_reductions(insts: &[Decoded], leaders: &std::collections::BTreeSet| sel.is_some_and(|s| s >> (k + 1) == n >> (k + 1) && (s ^ n) >> k & 1 == 1); let mut out = Reductions::default(); for (i, seed) in insts.iter().enumerate() { - if seed.inst.name != "V_CNDMASK_B32" || seed.variant != rdna2::Variant::Plain { + if seed.inst.name != "V_CNDMASK_B32" || seed.variant != rdna2::Variant::Plain || !unmodified(seed) { continue; } // the every-lane section it is in, with no other EXEC write before the end - let Some(open) = insts[..i].iter().rev().take(6).position(|d| d.inst.name == "S_OR_SAVEEXEC_B32" && f(d, "SSRC0") == Some(193)) else { continue }; + let opener = if wave64 { "S_OR_SAVEEXEC_B64" } else { "S_OR_SAVEEXEC_B32" }; + let Some(open) = insts[..i].iter().rev().take(6).position(|d| d.inst.name == opener && f(d, "SSRC0") == Some(193)) else { continue }; let open = i - 1 - open; - let steps: Vec<&Decoded> = insts[i + 1..].iter().filter(|d| !idle(d)).take(7).collect(); - let [a, b, c, mirror, cross, last, read] = steps[..] else { continue }; + // In a wave64 reduction the select mask is the old EXEC, optionally narrowed further. + // Proving that makes every never-launched lane's seed the identity. + if wave64 { + let (Some(saved), Some(mask)) = (f(&insts[open], "SDST"), f(seed, "SRC2")) else { continue }; + let Some(narrow) = (open + 1..i).rev().find(|&j| !idle(&insts[j])) else { continue }; + let narrow_inst = &insts[narrow]; + if narrow_inst.inst.name != "S_AND_B64" + || f(narrow_inst, "SDST") != Some(mask) + || ![f(narrow_inst, "SSRC0"), f(narrow_inst, "SSRC1")].contains(&Some(saved)) + { + continue; + } + let overwrites = |d: &Decoded, pair: u64| rdna2::sgpr_uses(d).1.iter().any(|&s| s == pair || s == pair + 1); + if insts[open + 1..narrow].iter().any(|d| overwrites(d, saved)) + || insts[narrow + 1..i].iter().any(|d| overwrites(d, mask)) + { + continue; + } + } + let n = if wave64 { 9 } else { 7 }; + let steps: Vec<&Decoded> = insts[i + 1..].iter().filter(|d| !idle(d)).take(n).collect(); + if steps.len() != n { + continue; + } + let (a, b, c, mirror, cross, last) = (steps[0], steps[1], steps[2], steps[3], steps[4], steps[5]); let Some((op, identity)) = op_of(a) else { continue }; let (_, w) = rdna2::vgpr_uses(seed); let [v] = w[..] else { continue }; @@ -1022,30 +1066,83 @@ fn wave32_reductions(insts: &[Decoded], leaders: &std::collections::BTreeSet Result { em.upper = Some(a); } } - if !opt.wave64 && matches!(opt.mode, Mode::Vertex(_) | Mode::Pixel(_)) { - em.reductions = wave32_reductions(&insts, &leaders); + if matches!(opt.mode, Mode::Vertex(_) | Mode::Pixel(_)) { + em.reductions = graphics_reductions(&insts, &leaders, opt.wave64); } em.max_vgpr = insts .iter() diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 8049734fb4..c297f8277e 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2474,6 +2474,115 @@ fn spill_slots(slot: fn(u32) -> u32) -> Vec { code } +/// The compiler's whole-wave reduction: wave64 adds the upper half through lane 32. +fn whole_reduction(op: &str, identity: u64, out: u64, wave64: bool, saved_mask: bool, upper_lane: u64, clobber: Option) -> Vec { + let width = if wave64 { "B64" } else { "B32" }; + let mut c = vec![ins(&format!("S_OR_SAVEEXEC_{width}"), "ENC_SOP1", &[("SDST", 30), ("SSRC0", 193)], None)]; + if clobber == Some(30) { + c.push(ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 30), ("SSRC0", 193)], None)); + } else if clobber == Some(31) { + c.push(ins("S_MOV_B32", "ENC_SOP1", &[("SDST", 31), ("SSRC0", 193)], None)); + } else if clobber == Some(203) { + c.push(ins("S_ANDN2_WREXEC_B64", "ENC_SOP1", &[("SDST", 40), ("SSRC0", 42)], None)); + } + c.push(ins( + &format!("S_AND_{width}"), + "ENC_SOP2", + &[("SDST", 10), ("SSRC0", 18), ("SSRC1", if saved_mask { 30 } else { 20 })], + None, + )); + if clobber == Some(10) { + c.push(ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 10), ("SSRC0", 193)], None)); + } else if clobber == Some(11) { + c.push(ins("S_MOV_B32", "ENC_SOP1", &[("SDST", 11), ("SSRC0", 193)], None)); + } + c.push(ins("V_CNDMASK_B32", "ENC_VOP3", &[("VDST", 6), ("SRC0", identity), ("SRC1", V + 13), ("SRC2", 10)], None)); + if clobber == Some(126) { + c.push(ins("V_CMPX_EQ_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 6)], None)); + } + let names = ["LANE_SEL_0", "LANE_SEL_1", "LANE_SEL_2", "LANE_SEL_3", "LANE_SEL_4", "LANE_SEL_5", "LANE_SEL_6", "LANE_SEL_7"]; + for (step, mut sel) in [[1u64, 0, 3, 2, 5, 4, 7, 6], [2, 3, 0, 1, 6, 7, 4, 5], [4, 5, 6, 7, 0, 1, 2, 3]].into_iter().enumerate() { + if clobber == Some(200) && step == 0 { + sel[0] = 0; + } + let mut f = vec![("VDST", 6u64), ("SRC0", 0xE9), ("VSRC0", 6), ("VSRC1", 6)]; + f.extend(names.iter().copied().zip(sel)); + c.push(ins(op, "VOP2_VOP_DPP8", &f, None)); + } + let mut cross = vec![("VDST", 7), ("SRC0", V + 6), ("SRC1", 128), ("SRC2", 128)]; + if clobber == Some(201) { + cross.push(("NEG", 1)); + } + c.extend([ + ins(op, "VOP2_VOP_DPP16", &[("VDST", 6), ("SRC0", 0xFA), ("VSRC0", 6), ("VSRC1", 6), ("DPP_CTRL", 0x140), ("ROW_MASK", 0xF), ("BANK_MASK", 0xF)], None), + ins("V_PERMLANEX16_B32", "ENC_VOP3", &cross, None), + ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", V + 7), ("VSRC1", 6)], None), + ]); + if wave64 { + c.extend([ + ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", 10), ("SRC0", V + 6), ("SRC1", 128 + upper_lane)], None), + ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", if clobber == Some(202) { 11 } else { 10 }), ("VSRC1", 6)], None), + ]); + } + c.extend([ + ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", out), ("SRC0", V + 6), ("SRC1", 128)], None), + ins(&format!("S_MOV_{width}"), "ENC_SOP1", &[("SDST", 126), ("SSRC0", 30)], None), + ]); + c.concat() +} + +#[test] +fn graphics_whole_reductions_use_wave_ops() { + let translated = |code: &[u8], wave64: bool, mode| translate(code, &Options { mode, wave64, ..Default::default() }).unwrap().hlsl; + for (op, identity, name) in [ + ("V_OR_B32", 128, "or"), + ("V_MAX_U32", 128, "max"), + ("V_AND_B32", 193, "and"), + ("V_MIN_U32", 193, "min"), + ] { + let code = program_of(&[whole_reduction(op, identity, 40, true, true, 32, None)]); + let hlsl = translated(&code, true, Mode::Pixel(draw_psi())); + let call = format!("= xcl_red64_{name}(xcl_seed_"); + let p = hlsl.find(&call).unwrap_or_else(|| panic!("{op}:\n{hlsl}")); + assert!(hlsl[p..hlsl.len().min(p + 300)].contains("v6 = select("), "{op}: accumulator not repaired:\n{hlsl}"); + } + let code32 = program_of(&[whole_reduction("V_MIN_U32", 193, 40, false, true, 32, None)]); + let hlsl32 = translated(&code32, false, Mode::Pixel(draw_psi())); + assert!(hlsl32.contains("= xcl_red_min(xcl_seed_") && !hlsl32.contains("= xcl_red64_min(xcl_seed_"), "{hlsl32}"); + + let min64 = program_of(&[whole_reduction("V_MIN_U32", 193, 40, true, true, 32, None)]); + let vs = translated(&min64, true, Mode::Vertex(draw_vsi())); + assert!(vs.contains("= xcl_red64_min(xcl_seed_"), "{vs}"); + for bad in [ + whole_reduction("V_MIN_U32", 193, 40, true, false, 32, None), + whole_reduction("V_MIN_U32", 193, 40, true, true, 31, None), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(30)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(31)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(10)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(11)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(126)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(200)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(201)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(202)), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, Some(203)), + whole_reduction("V_ADD_NC_U32", 128, 40, true, true, 32, None), + ] { + let hlsl = translated(&program_of(&[bad]), true, Mode::Pixel(draw_psi())); + assert!(!hlsl.contains("= xcl_red64_"), "{hlsl}"); + } + + let o = crate::gpu::dxil::kernel::KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 }; + let e = crate::gpu::dxil::kernel::translate_pixel(&min64, o, &draw_psi()).err().expect("direct DXIL accepted a partial-wave reduction"); + assert!(e.contains("graphics whole-wave reduction needs the HLSL path"), "{e}"); + let trivial = program_of(&[ins( + "EXP", + "ENC_EXP", + &[("TGT", 0), ("EN", 0xf), ("VSRC0", 2), ("VSRC1", 3), ("VSRC2", 2), ("VSRC3", 3), ("DONE", 1), ("VM", 1)], + None, + )]); + crate::gpu::dxil::kernel::translate_pixel(&trivial, o, &draw_psi()).expect("a non-reduction PS must stay on direct DXIL"); +} + /// The whole-wave reduction of the retail pixel shaders (`upper_lanes`), run as a wave64 PS: /// identity into the lanes outside the mask, DPP8 xor 1 / 2 / 4, row_mirror, the other row /// through `v_permlanex16`, `v_readlane` 32 for the upper half's result, `v_readlane` 0 for @@ -2489,29 +2598,6 @@ fn gpu_wave64_ps_whole_wave_reductions() { if !gpu_ready() { return; } - let reduce = |op: &str, identity: u64, out: u64| -> Vec { - let mut c = vec![ - ins("S_OR_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 30), ("SSRC0", 193)], None), - ins("S_AND_B64", "ENC_SOP2", &[("SDST", 10), ("SSRC0", 18), ("SSRC1", 30)], None), - ins("V_CNDMASK_B32", "ENC_VOP3", &[("VDST", 6), ("SRC0", identity), ("SRC1", V + 13), ("SRC2", 10)], None), - ]; - let names = ["LANE_SEL_0", "LANE_SEL_1", "LANE_SEL_2", "LANE_SEL_3", "LANE_SEL_4", "LANE_SEL_5", "LANE_SEL_6", "LANE_SEL_7"]; - for sel in [[1u64, 0, 3, 2, 5, 4, 7, 6], [2, 3, 0, 1, 6, 7, 4, 5], [4, 5, 6, 7, 0, 1, 2, 3]] { - let mut f = vec![("VDST", 6u64), ("SRC0", 0xE9), ("VSRC0", 6), ("VSRC1", 6)]; - f.extend(names.iter().copied().zip(sel)); - c.push(ins(op, "VOP2_VOP_DPP8", &f, None)); - } - c.extend([ - ins(op, "VOP2_VOP_DPP16", &[("VDST", 6), ("SRC0", 0xFA), ("VSRC0", 6), ("VSRC1", 6), ("DPP_CTRL", 0x140), ("ROW_MASK", 0xF), ("BANK_MASK", 0xF)], None), - ins("V_PERMLANEX16_B32", "ENC_VOP3", &[("VDST", 7), ("SRC0", V + 6), ("SRC1", 128), ("SRC2", 128)], None), - ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", V + 7), ("VSRC1", 6)], None), - ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", 10), ("SRC0", V + 6), ("SRC1", 128 + 32)], None), - ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", 10), ("VSRC1", 6)], None), - ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", out), ("SRC0", V + 6), ("SRC1", 128)], None), - ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 126), ("SSRC0", 30)], None), - ]); - c.concat() - }; let code = program_of(&[ // v12 = pixel number y·16 + x, v13 = v12 + 1, s[18:19] = the odd pixels ins("V_CVT_U32_F32", "ENC_VOP1", &[("VDST", 10), ("SRC0", V + 2)], None), @@ -2525,8 +2611,8 @@ fn gpu_wave64_ps_whole_wave_reductions() { ins("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 62), ("SRC0", V + 12)], None), ins("V_MBCNT_LO_U32_B32", "ENC_VOP3", &[("VDST", 15), ("SRC0", 193), ("SRC1", 128)], None), ins("V_MBCNT_HI_U32_B32", "ENC_VOP3", &[("VDST", 15), ("SRC0", 193), ("SRC1", V + 15)], None), - reduce("V_MIN_U32", 193, 40), - reduce("V_ADD_NC_U32", 128, 41), + whole_reduction("V_MIN_U32", 193, 40, true, true, 32, None), + whole_reduction("V_ADD_NC_U32", 128, 41, true, true, 32, None), ins("S_AND_B64", "ENC_SOP2", &[("SDST", 0), ("SSRC0", 18), ("SSRC1", 126)], None), ins("S_FF1_I32_B64", "ENC_SOP1", &[("SDST", 0), ("SSRC0", 0)], None), ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", 43), ("SRC0", V + 13), ("SRC1", 0)], None), @@ -2558,6 +2644,11 @@ fn gpu_wave64_ps_whole_wave_reductions() { assert_eq!(got, want, "pixel {id} (lane {lane}, wave of pixel {first}): min / sum over the odd pixels, waterfall read"); } } + // Six covered pixels in three quads, with the rest of the hardware wave unlaunched. + let small = draw_console(None, Some(&code), &[[0.0, 0.0], [3.2, 0.0], [0.0, 3.2]]); + for i in [0usize, 1, 2, 16, 17, 32] { + assert_eq!(small[i][0] as u32, 2, "pixel {i}, partial wave: min over odd covered pixels"); + } } /// SGPR spill slots in lanes 0..47 of a VGPR (`spill_slots`) in a wave64 PS: slots ≥ 32 do diff --git a/docs/wave64-on-wave32.md b/docs/wave64-on-wave32.md index dbc87e46da..0efd9c9e9a 100644 --- a/docs/wave64-on-wave32.md +++ b/docs/wave64-on-wave32.md @@ -268,24 +268,18 @@ left unsafe. Only a program with a constant or a slot to read gets the form: the for 613 programs (the 436 reductions and the 287 with spill slots, which overlap), all of which DXC compiles. Tests on the GPU: `gpu_wave64_ps_whole_wave_reductions` (the pack's reduction as min and as a sum, and the waterfall read, checked per hardware wave -against a console wave of the same lanes), `gpu_wave64_ps_spill_slots` (whole target and a +against a console wave of the same lanes and for min in a partial three-quad wave), +`gpu_wave64_ps_spill_slots` (whole target and a 6-pixel triangle), `gpu_wave64_vs_spill_slots_and_identity` (a wave of 3 vertices). ### What is still not exact -**Lanes the PC did not launch, inside a wave** – on every GPU and wave size, and before this -change too. The console runs whole-wave code in all 64 lanes, inactive ones included; the -translation runs it only in the lanes the PC GPU launched. In a partial wave, the reduction's -DPP / `v_permlanex16` steps read lanes that were never launched (undefined) instead of the -identity the console put there – not only lanes 32..63. The lanes ≥ 32 of a 32-lane wave are -handled above because they are all missing and all hold the identity; a lane missing among -launched ones holds a partial result that the translation does not have. Making that exact -needs the reduction recognised as a whole (`WaveActiveMin` / `Max` / `BitOr` over the -launched lanes, with the identity for the lanes outside the mask) – not done. Measured on an -RTX 5070 Ti (the reduction of `gpu_wave64_ps_whole_wave_reductions` drawn as a 3-quad -triangle, lanes 12..31 not launched): those lanes read 0, so a min reduction (identity -1) -gives 0, while max / or / sum (identity 0) and the waterfall read are right. 325 of the 436 -reduction programs have a min reduction (322 a max, 433 an or). +The compiler's exact min/max/and/or whole-wave reduction pattern is recognised as a whole and +rebuilt with a wave operation over the launched lanes. Lanes outside its saved mask hold the +operation's identity, so omitting console lanes the PC did not launch does not change the result. +The three-quad case that previously made min return 0 is covered by +`gpu_wave64_ps_whole_wave_reductions`. Other whole-wave sequences that do not match this exact +pattern can still read undefined values from lanes the PC did not launch. Spill slots of lanes that were not launched are also still lost in the native form (GPUs with 64-lane waves, which keep the HLSL as it was), and in the 32-lane form for slots ≥ 32 when the