diff --git a/crates/victory-shader/src/emit/halves_tests.rs b/crates/victory-shader/src/emit/halves_tests.rs index 7c996c684..99346523c 100644 --- a/crates/victory-shader/src/emit/halves_tests.rs +++ b/crates/victory-shader/src/emit/halves_tests.rs @@ -253,6 +253,33 @@ fn the_test_programs_are_what_their_comments_say() { "buffer_store_dword v7, v16, s[40:43], 0 offen offset:24", ], ), + ( + sum_after_a_loop_lanes_leave(), + &[ + "v_and_b32 v5, 3, v0", + "v_mov_b32 v6, 0", + "s_mov_b64 s[4:5], exec", + "v_cmp_lt_u32 vcc, v6, v5", + "s_and_b64 exec, exec, vcc", + "s_cbranch_execz", + "v_add_nc_u32 v6, 1, v6", + "s_branch", + "s_mov_b64 exec, s[4:5]", + "v_cvt_f32_u32 v3, v6", + ], + ), + ( + loops_sharing_a_latch(), + &[ + "s_add_u32 s22, s22, 1", + "s_cmp_lt_u32 s22, 3", + "s_add_u32 s20, s20, 1", + "s_cmp_gt_u32 s20, 2", + "s_mov_b32 s22, 0", + "s_add_u32 s21, s21, 1", + "v_mov_b32 v1, s21", + ], + ), ( dpp_row_mask(), &[ @@ -1610,18 +1637,6 @@ fn lds_in_a_loop_in_halves_matches_the_console_on_every_gpu() { assert!(failed.is_empty(), "{}", failed.join("\n")); } -/// `v_permlane16_b32` or `v_permlanex16_b32` with the FI and BOUND_CTRL bits -/// (`op_sel` bits 0 and 1, word bits 11 and 12): lane `l` takes the value -/// of `v0` from its own row of 16 (or the other row of its half), the lane -/// its nibble of `s8` (lanes 0 to 7) or `s9` (lanes 8 to 15) names. -const fn permlane16(other_row: bool, fetch_inactive: bool, bound_ctrl: bool) -> [u32; 2] { - let opcode = if other_row { 0xD778_0001 } else { 0xD777_0001 }; - [ - opcode | (fetch_inactive as u32) << 11 | (bound_ctrl as u32) << 12, - 0x0024_1100, - ] -} - /// The selectors: every nibble of `s8` is odd and every one of `s9` is even. const PERM_LOW: u32 = 0x1357_9BDF; @@ -1629,408 +1644,85 @@ const PERM_HIGH: u32 = 0x2468_ACE0; /// What `v1` holds before an instruction that may leave it alone. const PERM_OLD: u32 = 0xAAAA; -/// Keep arbitrary high bits in the same-row fixture's source data. -const PERM_PAYLOAD: u32 = 0xDEAD_BE00; -/// Per workgroup lane: `v0` (its thread id, or a raw value made from the -/// workgroup and thread ids for the same-row form), permuted first with all -/// lanes active, then with only even lanes active and every FI/BOUND_CTRL -/// combination. The same-row form also checks full EXEC with BOUND_CTRL -/// set. Each masked or potentially out-of-bounds read starts with `v1` -/// holding [`PERM_OLD`]. EXEC is whole again for every store. -#[cfg(windows)] -fn permlane16_program(lanes: u32, other_row: bool) -> Vec { - let wave64 = lanes > 32; - let full = |w: &mut Vec| { - w.push(if wave64 { - 0xBEFE_04C1 // s_mov_b64 exec, -1 - } else { - 0xBEFE_03C1 // s_mov_b32 exec_lo, -1 - }); - }; - let even = |w: &mut Vec| { - w.push(if wave64 { - 0xBEFE_040A // s_mov_b64 exec, s[10:11] - } else { - 0xBEFE_030A // s_mov_b32 exec_lo, s10 - }); - }; - let mut w = PROLOGUE.to_vec(); - if other_row { - w.push(0x3420_0085); // v_lshlrev_b32 v16, 5, v0 - } else { - w.extend([ - 0x8F02_8801, // s_lshl_b32 s2, s1 (group id X), 8 - 0x4A22_0002, // v_add_nc_u32 v17, s2, v0 - 0x3420_2285, // v_lshlrev_b32 v16, 5, v17 - 0x3A00_22FF, - PERM_PAYLOAD, // v_xor_b32 v0, PERM_PAYLOAD, v17 - ]); - } - w.extend([ - 0xBE88_03FF, - PERM_LOW, // s_mov_b32 s8, PERM_LOW - 0xBE89_03FF, - PERM_HIGH, // s_mov_b32 s9, PERM_HIGH - 0xBE8A_03FF, - 0x5555_5555, // s_mov_b32 s10, 0x55555555 - 0xBE8B_03FF, - 0x5555_5555, // s_mov_b32 s11, 0x55555555 - ]); - if !other_row { - w.extend([0x7E02_02FF, PERM_OLD]); // v_mov_b32 v1, PERM_OLD - } - w.extend(permlane16(other_row, false, false)); - w.extend(store(1, 0)); - for (slot, (fi, bc)) in [(false, false), (false, true), (true, false), (true, true)] - .into_iter() - .enumerate() - { - w.extend([0x7E02_02FF, PERM_OLD]); // v_mov_b32 v1, PERM_OLD - even(&mut w); - w.extend(permlane16(other_row, fi, bc)); - full(&mut w); - w.extend(store(1, 4 * (slot as u32 + 1))); - } - if !other_row { - w.extend([0x7E02_02FF, PERM_OLD]); // v_mov_b32 v1, PERM_OLD - w.extend(permlane16(false, false, true)); - w.extend(store(1, 20)); - } - w.push(S_ENDPGM); - w +/// A single result in v3, stored after the body restores EXEC. +fn literal_program(body: &[u32]) -> Vec { + [ + PROLOGUE.as_slice(), + &[0x3420_0085, 0x7E06_0280], // v16 = v0 * 32; v3 = 0 + body, + &store(3, 0), + &[S_ENDPGM], + ] + .concat() } -/// What the console gives [`permlane16_program`]'s lane `l`. An FI read -/// from a lane that was never launched has no documented input value. -fn permlane16_console(l: u32, group: u32, threads: u32, other_row: bool) -> [Option; 6] { - let in_row = l % 16; - let selectors = if in_row >= 8 { PERM_HIGH } else { PERM_LOW }; - let row = if other_row { (l / 16) ^ 1 } else { l / 16 }; - let source = row * 16 + ((selectors >> (4 * (in_row % 8))) & 15); - let value = if other_row { - source +/// A nonempty mixed EXEC takes the direct edge to the join. Inactive +/// lanes remain inactive there. The first popcount forces a numeric mask +/// in the narrowed block, and the joined popcount supplies the result. +fn literal_mask_join(high_only: bool) -> Vec { + literal_program(&[ + 0x7D86_00A8, // v_cmp_le_u32 vcc, 40, v0 + 0xBE94_246A, // s_and_saveexec_b64 s[20:21], vcc + 0xBF88_0006, // s_cbranch_execz restore + 0xBE8C_107E, // s_bcnt1_i32_b64 s12, exec + 0xBF89_0001, // s_cbranch_execnz join + if high_only { 0xBEFF_0380 } else { 0xBEFE_04C1 }, // s_mov_b32 exec_hi, 0 or s_mov_b64 exec, -1 + 0xBE8D_107E, // join: s_bcnt1_i32_b64 s13, exec + 0x7E1A_020D, // v_mov_b32 v13, s13 + 0x4A06_1A0C, // v_add_nc_u32 v3, s12, v13 + 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] + ]) +} + +/// Both scalar lane reads happen under an EXEC mask with no low lanes. +fn literal_lane_reads(first: bool) -> Vec { + let read: &[u32] = if first { + &[0x7E14_0500] // v_readfirstlane_b32 s10, v0 } else { - (256 * group + source) ^ PERM_PAYLOAD - }; - let active = |lane: u32| lane.is_multiple_of(2); - let result = |masked: bool, fi: bool, bc: bool| { - if masked && !active(l) { - Some(PERM_OLD) - } else if fi { - (source < threads).then_some(value) - } else if source < threads && (!masked || active(source)) { - Some(value) - } else if bc { - Some(0) - } else { - Some(PERM_OLD) - } + &[0xD760_000A, 0x0201_6500] // v_readlane_b32 s10, v0, 50 }; - [ - result(false, false, false), - result(true, false, false), - result(true, false, true), - result(true, true, false), - result(true, true, true), - result(false, false, true), - ] + let mut body = vec![ + 0x7D86_00A8, // v_cmp_le_u32 vcc, 40, v0 + 0xBE94_246A, // s_and_saveexec_b64 s[20:21], vcc + 0xBF88_0000 | (read.len() as u32 + 1), // s_cbranch_execz restore + ]; + body.extend(read); + body.extend([ + 0x7E06_020A, // v_mov_b32 v3, s10 + 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] + ]); + // The first-lane case also names the console lanes. + body.extend([0xD765_0001, 0x0001_00C1]); // v_mbcnt_lo_u32_b32 v1, -1, 0 + literal_program(&body) } -/// The hand-encoded words are the instructions their comments name. -#[test] -fn the_permlane16_programs_are_what_their_comments_say() { - for (words, opcode) in [ - (permlane16(true, false, false), "v_permlanex16_b32"), - (permlane16(true, true, true), "v_permlanex16_b32"), - (permlane16(false, false, false), "v_permlane16_b32"), - (permlane16(false, true, true), "v_permlane16_b32"), - ] { - let p = ir::build( - &[words[0], words[1], S_ENDPGM] - .iter() - .flat_map(|w| w.to_le_bytes()) - .collect::>(), - false, - 32, - ) - .expect("ir::build"); - assert_eq!(p.blocks[0].insts[0].name(), opcode); - } +/// Separate writes select the upper half before reading its first lane. +fn literal_exec_dwords() -> Vec { + literal_program(&[ + 0xBE94_047E, // s_mov_b64 s[20:21], exec + 0xBEFE_0380, // s_mov_b32 exec_lo, 0 + 0xBEFF_03C1, // s_mov_b32 exec_hi, -1 + 0xBF88_0002, // s_cbranch_execz restore + 0x7E14_0500, // v_readfirstlane_b32 s10, v0 + 0x7E06_020A, // v_mov_b32 v3, s10 + 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] + ]) } -/// The lanes of each row read the other row of their 32-lane half through -/// their selector nibbles, and an inactive source lane gives the old value, -/// zero or its register as FI and BOUND_CTRL say, on every hardware -/// adapter, in console waves of 32 and of 64 (in halves and whole). -#[test] -#[cfg(windows)] -fn permlanex16_picks_lanes_as_the_console_does_on_every_gpu() { - let mut failed = Vec::new(); - for lanes in [32, 64] { - let want: Vec = (0..lanes) - .flat_map(|l| { - permlane16_console(l, 0, lanes, true) - .into_iter() - .take(5) - .map(|value| value.expect("full cross-row fixtures")) - }) - .collect(); - failed.extend(differences_in( - lanes == 64, - &permlane16_program(lanes, true), - lanes, - 5, - &want, - 0, - false, - false, - )); - } - assert!(failed.is_empty(), "{}", failed.join("\n")); -} - -/// Lane 0 selects an odd lane (nibble 15) and lane 8 selects an even lane -/// (nibble 0). Lane 32 stays in the same half for either row choice. -#[test] -fn the_permlane16_model_follows_the_instructions() { - assert_eq!( - permlane16_console(0, 0, 64, true), - [31, PERM_OLD, 0, 31, 31, 31].map(Some) - ); - assert_eq!(permlane16_console(8, 0, 64, true), [Some(16); 6]); - assert_eq!( - permlane16_console(1, 0, 64, true), - [29, PERM_OLD, PERM_OLD, PERM_OLD, PERM_OLD, 29].map(Some) - ); - assert_eq!(permlane16_console(16, 0, 64, true)[0], Some(15)); - assert_eq!(permlane16_console(32, 0, 64, true)[0], Some(63)); - assert_eq!(permlane16_console(48, 0, 64, true)[0], Some(47)); - assert_eq!( - permlane16_console(0, 0, 64, false), - [ - 0xDEAD_BE0F, - PERM_OLD, - 0, - 0xDEAD_BE0F, - 0xDEAD_BE0F, - 0xDEAD_BE0F - ] - .map(Some) - ); - assert_eq!(permlane16_console(8, 0, 64, false), [Some(PERM_PAYLOAD); 6]); - assert_eq!(permlane16_console(32, 1, 64, false)[0], Some(0xDEAD_BF2F)); - assert_eq!( - permlane16_console(64, 0, 79, false), - [Some(PERM_OLD), Some(PERM_OLD), Some(0), None, None, Some(0)] - ); -} - -fn same_row_permlane16_native(threads: u32) -> NativeProgram { - let words = permlane16_program(threads, false); - let mut n = native(&words, threads > 32, threads, 0); - let StageIo::Cs(cs) = &mut n.io else { - unreachable!() - }; - cs.rsrc2 |= 1 << 7; // group id X in s1, after the user-data SGPR - n -} - -#[test] -fn same_row_permlane16_uses_host_lanes_without_an_exchange() { - let n = same_row_permlane16_native(64); - let l = super::with_thread_ticket(false, || lowered(&n, true)) - .expect("a live same-row permute lowers in wave64 halves"); - assert_eq!(l.wave_size, Some(32)); - assert!(l.uses_lane_index); - assert_eq!(l.barriers, 0); -} - -/// The last 16-lane row is complete at 80 and 112 threads. At 79 threads -/// some selectors name the missing lane. Check both BOUND_CTRL outcomes -/// for those reads with FI clear. -#[test] -#[cfg(windows)] -fn same_row_permlane16_matches_the_console_on_hardware() { - let _one = super::valu_tests::ONE_AT_A_TIME - .lock() - .unwrap_or_else(|e| e.into_inner()); - let hosts = Host::each_hardware(); - if hosts.is_empty() { - eprintln!("no SM 6.6 hardware device; skipped same-row permlane16"); - return; - } - let workgroups = 3; - let mut completed = 0; - let mut checked_lanes = 0; - let mut checked_dwords = 0; - for (adapter, host) in &hosts { - for threads in [32, 64, 79, 80, 96, 112, 128, 256] { - let n = same_row_permlane16_native(threads); - let bytes = crate::dxbc::build(&[]); - let container = crate::dxbc::Container::parse(&bytes).expect("empty test container"); - let (p, st) = - crate::range::build(&n.patched_code(), n.wave64, n.vgprs).expect("range::build"); - let st = st.expect("structure"); - let res = resource::track(&p, &n.layout, n.stage, Some(&st)).expect("track"); - let io = io::raise(&p, &n).expect("io::raise"); - let shader = super::emit_with( - &container, - &n, - &p, - &st, - &io, - &res, - super::Options { - host_wave32: true, - narrow_waves: true, - ..Default::default() - }, - ) - .expect("production translation of same-row permlane16"); - let label = format!("{adapter}: {threads} threads"); - if let Ok(mut v) = - validator::Validator::load(validator::Validator::default_path().as_deref()) - { - v.validate(&mut shader.dxil.clone()) - .unwrap_or_else(|e| panic!("{label}: DXIL validation: {e}")); - } - let (root, pso) = host - .compute_pipeline(&shader) - .unwrap_or_else(|e| panic!("{label}: pipeline creation: {e}")); - let ud = vec![0; shader.user_data_dwords().max(1) as usize]; - let out = host - .dispatch( - &root, - &pso, - &Dispatch { - roots: vec![(0, Root::Constants(ud))], - views: &[ - View::Texture(1, 1, &[[0.0; 4]]), - View::Buffer { - data: &[0; 4], - stride: Stride::Structured(16), - }, - View::RawUav(workgroups * 256 * 8), - ], - samplers: &[], - groups: [workgroups, 1, 1], - }, - ) - .unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}")); - assert_eq!(out.len(), 1, "{label}: readback UAV count"); - assert_eq!( - out[0].len(), - (workgroups * 256 * 8) as usize, - "{label}: readback length" - ); - for group in 0..workgroups { - for lane in 0..threads { - let offset = ((group * 256 + lane) * 8) as usize; - for (slot, expected) in permlane16_console(lane, group, threads, false) - .into_iter() - .enumerate() - { - if let Some(expected) = expected { - assert_eq!( - out[0][offset + slot], - expected, - "{label}: workgroup {group}, lane {lane}, slot {slot}" - ); - checked_dwords += 1; - } - } - } - } - completed += 1; - checked_lanes += threads * workgroups; - eprintln!("{label}: pipeline created, {workgroups} workgroups completed and checked"); - } - } - assert!(completed > 0 && checked_lanes > 0 && checked_dwords > 0); - eprintln!( - "same-row permlane16: {completed} hardware dispatches, {checked_lanes} lanes and {checked_dwords} defined dwords checked" - ); -} - -/// A single result in v3, stored after the body restores EXEC. -fn literal_program(body: &[u32]) -> Vec { - [ - PROLOGUE.as_slice(), - &[0x3420_0085, 0x7E06_0280], // v16 = v0 * 32; v3 = 0 - body, - &store(3, 0), - &[S_ENDPGM], - ] - .concat() -} - -/// A nonempty mixed EXEC takes the direct edge to the join. Inactive -/// lanes remain inactive there. The first popcount forces a numeric mask -/// in the narrowed block, and the joined popcount supplies the result. -fn literal_mask_join(high_only: bool) -> Vec { - literal_program(&[ - 0x7D86_00A8, // v_cmp_le_u32 vcc, 40, v0 - 0xBE94_246A, // s_and_saveexec_b64 s[20:21], vcc - 0xBF88_0006, // s_cbranch_execz restore - 0xBE8C_107E, // s_bcnt1_i32_b64 s12, exec - 0xBF89_0001, // s_cbranch_execnz join - if high_only { 0xBEFF_0380 } else { 0xBEFE_04C1 }, // s_mov_b32 exec_hi, 0 or s_mov_b64 exec, -1 - 0xBE8D_107E, // join: s_bcnt1_i32_b64 s13, exec - 0x7E1A_020D, // v_mov_b32 v13, s13 - 0x4A06_1A0C, // v_add_nc_u32 v3, s12, v13 - 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] - ]) -} - -/// Both scalar lane reads happen under an EXEC mask with no low lanes. -fn literal_lane_reads(first: bool) -> Vec { - let read: &[u32] = if first { - &[0x7E14_0500] // v_readfirstlane_b32 s10, v0 - } else { - &[0xD760_000A, 0x0201_6500] // v_readlane_b32 s10, v0, 50 - }; - let mut body = vec![ - 0x7D86_00A8, // v_cmp_le_u32 vcc, 40, v0 - 0xBE94_246A, // s_and_saveexec_b64 s[20:21], vcc - 0xBF88_0000 | (read.len() as u32 + 1), // s_cbranch_execz restore - ]; - body.extend(read); - body.extend([ - 0x7E06_020A, // v_mov_b32 v3, s10 - 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] - ]); - // The first-lane case also names the console lanes. - body.extend([0xD765_0001, 0x0001_00C1]); // v_mbcnt_lo_u32_b32 v1, -1, 0 - literal_program(&body) -} - -/// Separate writes select the upper half before reading its first lane. -fn literal_exec_dwords() -> Vec { - literal_program(&[ - 0xBE94_047E, // s_mov_b64 s[20:21], exec - 0xBEFE_0380, // s_mov_b32 exec_lo, 0 - 0xBEFF_03C1, // s_mov_b32 exec_hi, -1 - 0xBF88_0002, // s_cbranch_execz restore - 0x7E14_0500, // v_readfirstlane_b32 s10, v0 - 0x7E06_020A, // v_mov_b32 v3, s10 - 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] - ]) -} - -/// Lane 40 is inactive when the scalar write targets it. -fn literal_lane_write() -> Vec { - literal_program(&[ - 0x7D88_0094, // v_cmp_gt_u32 vcc, 20, v0 - 0xBE94_246A, // s_and_saveexec_b64 s[20:21], vcc - 0xBF88_0005, // s_cbranch_execz restore - 0xD761_0003, - 0x0001_50B7, // v_writelane_b32 v3, 55, 40 - 0xD760_000A, - 0x0201_5103, // v_readlane_b32 s10, v3, 40 - 0x7E06_020A, // v_mov_b32 v3, s10 - 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] - ]) +/// Lane 40 is inactive when the scalar write targets it. +fn literal_lane_write() -> Vec { + literal_program(&[ + 0x7D88_0094, // v_cmp_gt_u32 vcc, 20, v0 + 0xBE94_246A, // s_and_saveexec_b64 s[20:21], vcc + 0xBF88_0005, // s_cbranch_execz restore + 0xD761_0003, + 0x0001_50B7, // v_writelane_b32 v3, 55, 40 + 0xD760_000A, + 0x0201_5103, // v_readlane_b32 s10, v3, 40 + 0x7E06_020A, // v_mov_b32 v3, s10 + 0xBEFE_0414, // restore: s_mov_b64 exec, s[20:21] + ]) } /// Lanes leave independently as their counter reaches zero. SCC is set @@ -4559,6 +4251,456 @@ fn a_first_lane_read_of_a_multiply_accumulate_matches_the_console_on_every_gpu() assert!(failed.is_empty(), "{}", failed.join("\n")); } +/// Each lane counts to the low two bits of its thread id in a loop it leaves +/// on its own, whose back edge is unconditional (`s_branch`): lowering caps +/// that back edge at the loop iteration limit. Then the console compiler's +/// whole-wave sum of the counts ([`reduction`] of `v_cvt_f32_u32 v3, v6`). +/// Per thread, one dword at `l * 32`: its console wave's sum. +fn sum_after_a_loop_lanes_leave() -> Vec { + let sum = reduction(V_ADD_F32, 0x80, 0x7E06_0D06); + let mut w = PROLOGUE.to_vec(); + w.extend([ + 0x3420_0085, // v_lshlrev_b32 v16, 5, v0 + 0x360A_0083, // v_and_b32 v5, 3, v0 + 0x7E0C_0280, // v_mov_b32 v6, 0 + 0xBE84_047E, // s_mov_b64 s[4:5], exec + 0x7D82_0B06, // v_cmp_lt_u32 vcc, v6, v5 + 0x87FE_6A7E, // s_and_b64 exec, exec, vcc + 0xBF88_0002, // s_cbranch_execz (past the s_branch) + 0x4A0C_0C81, // v_add_nc_u32 v6, 1, v6 + 0xBF82_FFFB, // s_branch (back to the v_cmp) + 0xBEFE_0404, // s_mov_b64 exec, s[4:5] + ]); + w.extend(&sum[PROLOGUE.len() + 1..]); + w +} + +/// Two scalar loops whose latches share a block, as the console compiler +/// lays them out: the latch branches back to the inner loop's header three +/// times and otherwise falls through to the outer loop's header, which runs +/// twice. Both targets of that branch are back edges. Per thread, one dword +/// at `l * 32`: the inner loop's passes, 6. +fn loops_sharing_a_latch() -> Vec { + let mut w = PROLOGUE.to_vec(); + w.extend([ + 0x3420_0085, // v_lshlrev_b32 v16, 5, v0 + 0xBE94_0380, // s_mov_b32 s20, 0 + 0xBE95_0380, // s_mov_b32 s21, 0 + 0xBF82_0003, // s_branch (to the outer header) + 0x8016_8116, // s_add_u32 s22, s22, 1 (the shared latch) + 0xBF0A_8316, // s_cmp_lt_u32 s22, 3 + 0xBF85_0004, // s_cbranch_scc1 (back to the inner header) + 0x8014_8114, // s_add_u32 s20, s20, 1 (the outer header) + 0xBF08_8214, // s_cmp_gt_u32 s20, 2 + 0xBF85_0003, // s_cbranch_scc1 (out of both loops) + 0xBE96_0380, // s_mov_b32 s22, 0 + 0x8015_8115, // s_add_u32 s21, s21, 1 (the inner header) + 0xBF82_FFF7, // s_branch (to the shared latch) + 0x7E02_0215, // v_mov_b32 v1, s21 + ]); + w.extend(store(1, 0)); + w.push(S_ENDPGM); + w +} + +/// A reduction after a loop the lanes leave one by one, whose back edge is +/// capped at the loop iteration limit ([`sum_after_a_loop_lanes_leave`]): +/// the console runs the loop to its end, so with the cap taken as never +/// reached every lane of the group runs the reduction together and the +/// halves pass each other their sums. Only with the cap's barriers refused +/// (`VICTORY_CAP_BARRIERS=1`) is a lane taken to have left at the cap, and +/// the reduction refused. +#[test] +fn a_reduction_after_a_loop_lanes_leave_passes_between_halves() { + let words = sum_after_a_loop_lanes_leave(); + for threads in [64, 96, 128] { + // The lockstep loops of #591 may now translate this shape even with + // the cap's barriers, so the refusal is no longer required. + let why = super::with_cap_barriers(true, || refusal(&words, threads, 0)); + assert!( + why == "translated" || why.contains("a wave reduction over both 32-lane halves"), + "{threads}: {why}" + ); + let translated = super::with_cap_barriers(false, || refusal(&words, threads, 0)); + assert_eq!(translated, "translated", "{threads}"); + } + assert_eq!(refusal(&words, 32, 0), "translated"); +} + +/// [`sum_after_a_loop_lanes_leave`] on every hardware adapter gives the +/// console's sums, in a group of 64 (one console wave in two halves), of 96 +/// (the second console wave has no upper half) and of 128 (two). +#[test] +#[cfg(windows)] +fn a_reduction_after_a_loop_lanes_leave_matches_the_console_on_every_gpu() { + let words = sum_after_a_loop_lanes_leave(); + let mut failed = Vec::new(); + for threads in [64, 96, 128] { + let want: Vec = (0..threads) + .map(|l| (console_reduction(threads, l, |a, b| a + b, |t| t & 3) as f32).to_bits()) + .collect(); + failed.extend(super::with_cap_barriers(false, || { + differences(&words, threads, 1, &want) + })); + } + assert!(failed.is_empty(), "{}", failed.join("\n")); +} + +/// [`loops_sharing_a_latch`] in whole-wave halves: each side of the shared +/// latch's branch counts its own loop's passes under the iteration limit. +#[test] +fn a_branch_back_to_two_loops_runs_in_whole_wave_halves() { + let n = native(&loops_sharing_a_latch(), true, 64, 0); + let literal = lower_halves(&n, true, false, true).expect("whole-wave halves"); + assert_eq!(literal.wave_size, Some(32)); +} + +/// [`loops_sharing_a_latch`] in whole-wave halves on every hardware adapter +/// gives the console's count in every lane. +#[test] +#[cfg(windows)] +fn a_branch_back_to_two_loops_matches_the_console_on_every_gpu() { + let words = loops_sharing_a_latch(); + let failed = differences_in(true, &words, 64, 1, &[6; 64], 0, false, true); + assert!(failed.is_empty(), "{}", failed.join("\n")); +} + +/// `v_permlane16_b32` or `v_permlanex16_b32` with the FI and BOUND_CTRL bits +/// (`op_sel` bits 0 and 1, word bits 11 and 12): lane `l` takes the value +/// of `v0` from its own row of 16 (or the other row of its half), the lane +/// its nibble of `s8` (lanes 0 to 7) or `s9` (lanes 8 to 15) names. +const fn permlane16(other_row: bool, fetch_inactive: bool, bound_ctrl: bool) -> [u32; 2] { + let opcode = if other_row { 0xD778_0001 } else { 0xD777_0001 }; + [ + opcode | (fetch_inactive as u32) << 11 | (bound_ctrl as u32) << 12, + 0x0024_1100, + ] +} + +/// Keep arbitrary high bits in the same-row fixture's source data. +const PERM_PAYLOAD: u32 = 0xDEAD_BE00; + +/// Per workgroup lane: `v0` (its thread id, or a raw value made from the +/// workgroup and thread ids for the same-row form), permuted first with all +/// lanes active, then with only even lanes active and every FI/BOUND_CTRL +/// combination. The same-row form also checks full EXEC with BOUND_CTRL +/// set. Each masked or potentially out-of-bounds read starts with `v1` +/// holding [`PERM_OLD`]. EXEC is whole again for every store. +#[cfg(windows)] +fn permlane16_program(lanes: u32, other_row: bool) -> Vec { + let wave64 = lanes > 32; + let full = |w: &mut Vec| { + w.push(if wave64 { + 0xBEFE_04C1 // s_mov_b64 exec, -1 + } else { + 0xBEFE_03C1 // s_mov_b32 exec_lo, -1 + }); + }; + let even = |w: &mut Vec| { + w.push(if wave64 { + 0xBEFE_040A // s_mov_b64 exec, s[10:11] + } else { + 0xBEFE_030A // s_mov_b32 exec_lo, s10 + }); + }; + let mut w = PROLOGUE.to_vec(); + if other_row { + w.push(0x3420_0085); // v_lshlrev_b32 v16, 5, v0 + } else { + w.extend([ + 0x8F02_8801, // s_lshl_b32 s2, s1 (group id X), 8 + 0x4A22_0002, // v_add_nc_u32 v17, s2, v0 + 0x3420_2285, // v_lshlrev_b32 v16, 5, v17 + 0x3A00_22FF, + PERM_PAYLOAD, // v_xor_b32 v0, PERM_PAYLOAD, v17 + ]); + } + w.extend([ + 0xBE88_03FF, + PERM_LOW, // s_mov_b32 s8, PERM_LOW + 0xBE89_03FF, + PERM_HIGH, // s_mov_b32 s9, PERM_HIGH + 0xBE8A_03FF, + 0x5555_5555, // s_mov_b32 s10, 0x55555555 + 0xBE8B_03FF, + 0x5555_5555, // s_mov_b32 s11, 0x55555555 + ]); + if !other_row { + w.extend([0x7E02_02FF, PERM_OLD]); // v_mov_b32 v1, PERM_OLD + } + w.extend(permlane16(other_row, false, false)); + w.extend(store(1, 0)); + for (slot, (fi, bc)) in [(false, false), (false, true), (true, false), (true, true)] + .into_iter() + .enumerate() + { + w.extend([0x7E02_02FF, PERM_OLD]); // v_mov_b32 v1, PERM_OLD + even(&mut w); + w.extend(permlane16(other_row, fi, bc)); + full(&mut w); + w.extend(store(1, 4 * (slot as u32 + 1))); + } + if !other_row { + w.extend([0x7E02_02FF, PERM_OLD]); // v_mov_b32 v1, PERM_OLD + w.extend(permlane16(false, false, true)); + w.extend(store(1, 20)); + } + w.push(S_ENDPGM); + w +} + +/// What the console gives [`permlane16_program`]'s lane `l`. An FI read +/// from a lane that was never launched has no documented input value. +fn permlane16_console(l: u32, group: u32, threads: u32, other_row: bool) -> [Option; 6] { + let in_row = l % 16; + let selectors = if in_row >= 8 { PERM_HIGH } else { PERM_LOW }; + let row = if other_row { (l / 16) ^ 1 } else { l / 16 }; + let source = row * 16 + ((selectors >> (4 * (in_row % 8))) & 15); + let value = if other_row { + source + } else { + (256 * group + source) ^ PERM_PAYLOAD + }; + let active = |lane: u32| lane.is_multiple_of(2); + let result = |masked: bool, fi: bool, bc: bool| { + if masked && !active(l) { + Some(PERM_OLD) + } else if fi { + (source < threads).then_some(value) + } else if source < threads && (!masked || active(source)) { + Some(value) + } else if bc { + Some(0) + } else { + Some(PERM_OLD) + } + }; + [ + result(false, false, false), + result(true, false, false), + result(true, false, true), + result(true, true, false), + result(true, true, true), + result(false, false, true), + ] +} + +/// The hand-encoded words are the instructions their comments name. +#[test] +fn the_permlane16_programs_are_what_their_comments_say() { + for (words, opcode) in [ + (permlane16(true, false, false), "v_permlanex16_b32"), + (permlane16(true, true, true), "v_permlanex16_b32"), + (permlane16(false, false, false), "v_permlane16_b32"), + (permlane16(false, true, true), "v_permlane16_b32"), + ] { + let p = ir::build( + &[words[0], words[1], S_ENDPGM] + .iter() + .flat_map(|w| w.to_le_bytes()) + .collect::>(), + false, + 32, + ) + .expect("ir::build"); + assert_eq!(p.blocks[0].insts[0].name(), opcode); + } +} + +/// The lanes of each row read the other row of their 32-lane half through +/// their selector nibbles, and an inactive source lane gives the old value, +/// zero or its register as FI and BOUND_CTRL say, on every hardware +/// adapter, in console waves of 32 and of 64 (in halves and whole). +#[test] +#[cfg(windows)] +fn permlanex16_picks_lanes_as_the_console_does_on_every_gpu() { + let mut failed = Vec::new(); + for lanes in [32, 64] { + let want: Vec = (0..lanes) + .flat_map(|l| { + permlane16_console(l, 0, lanes, true) + .into_iter() + .take(5) + .map(|value| value.expect("full cross-row fixtures")) + }) + .collect(); + failed.extend(differences_in( + lanes == 64, + &permlane16_program(lanes, true), + lanes, + 5, + &want, + 0, + false, + false, + )); + } + assert!(failed.is_empty(), "{}", failed.join("\n")); +} + +/// Lane 0 selects an odd lane (nibble 15) and lane 8 selects an even lane +/// (nibble 0). Lane 32 stays in the same half for either row choice. +#[test] +fn the_permlane16_model_follows_the_instructions() { + assert_eq!( + permlane16_console(0, 0, 64, true), + [31, PERM_OLD, 0, 31, 31, 31].map(Some) + ); + assert_eq!(permlane16_console(8, 0, 64, true), [Some(16); 6]); + assert_eq!( + permlane16_console(1, 0, 64, true), + [29, PERM_OLD, PERM_OLD, PERM_OLD, PERM_OLD, 29].map(Some) + ); + assert_eq!(permlane16_console(16, 0, 64, true)[0], Some(15)); + assert_eq!(permlane16_console(32, 0, 64, true)[0], Some(63)); + assert_eq!(permlane16_console(48, 0, 64, true)[0], Some(47)); + assert_eq!( + permlane16_console(0, 0, 64, false), + [ + 0xDEAD_BE0F, + PERM_OLD, + 0, + 0xDEAD_BE0F, + 0xDEAD_BE0F, + 0xDEAD_BE0F + ] + .map(Some) + ); + assert_eq!(permlane16_console(8, 0, 64, false), [Some(PERM_PAYLOAD); 6]); + assert_eq!(permlane16_console(32, 1, 64, false)[0], Some(0xDEAD_BF2F)); + assert_eq!( + permlane16_console(64, 0, 79, false), + [Some(PERM_OLD), Some(PERM_OLD), Some(0), None, None, Some(0)] + ); +} + +fn same_row_permlane16_native(threads: u32) -> NativeProgram { + let words = permlane16_program(threads, false); + let mut n = native(&words, threads > 32, threads, 0); + let StageIo::Cs(cs) = &mut n.io else { + unreachable!() + }; + cs.rsrc2 |= 1 << 7; // group id X in s1, after the user-data SGPR + n +} + +#[test] +fn same_row_permlane16_uses_host_lanes_without_an_exchange() { + let n = same_row_permlane16_native(64); + let l = super::with_thread_ticket(false, || lowered(&n, true)) + .expect("a live same-row permute lowers in wave64 halves"); + assert_eq!(l.wave_size, Some(32)); + assert!(l.uses_lane_index); + assert_eq!(l.barriers, 0); +} + +/// The last 16-lane row is complete at 80 and 112 threads. At 79 threads +/// some selectors name the missing lane. Check both BOUND_CTRL outcomes +/// for those reads with FI clear. +#[test] +#[cfg(windows)] +fn same_row_permlane16_matches_the_console_on_hardware() { + let _one = super::valu_tests::ONE_AT_A_TIME + .lock() + .unwrap_or_else(|e| e.into_inner()); + let hosts = Host::each_hardware(); + if hosts.is_empty() { + eprintln!("no SM 6.6 hardware device; skipped same-row permlane16"); + return; + } + let workgroups = 3; + let mut completed = 0; + let mut checked_lanes = 0; + let mut checked_dwords = 0; + for (adapter, host) in &hosts { + for threads in [32, 64, 79, 80, 96, 112, 128, 256] { + let n = same_row_permlane16_native(threads); + let bytes = crate::dxbc::build(&[]); + let container = crate::dxbc::Container::parse(&bytes).expect("empty test container"); + let (p, st) = + crate::range::build(&n.patched_code(), n.wave64, n.vgprs).expect("range::build"); + let st = st.expect("structure"); + let res = resource::track(&p, &n.layout, n.stage, Some(&st)).expect("track"); + let io = io::raise(&p, &n).expect("io::raise"); + let shader = super::emit_with( + &container, + &n, + &p, + &st, + &io, + &res, + super::Options { + host_wave32: true, + narrow_waves: true, + ..Default::default() + }, + ) + .expect("production translation of same-row permlane16"); + let label = format!("{adapter}: {threads} threads"); + if let Ok(mut v) = + validator::Validator::load(validator::Validator::default_path().as_deref()) + { + v.validate(&mut shader.dxil.clone()) + .unwrap_or_else(|e| panic!("{label}: DXIL validation: {e}")); + } + let (root, pso) = host + .compute_pipeline(&shader) + .unwrap_or_else(|e| panic!("{label}: pipeline creation: {e}")); + let ud = vec![0; shader.user_data_dwords().max(1) as usize]; + let out = host + .dispatch( + &root, + &pso, + &Dispatch { + roots: vec![(0, Root::Constants(ud))], + views: &[ + View::Texture(1, 1, &[[0.0; 4]]), + View::Buffer { + data: &[0; 4], + stride: Stride::Structured(16), + }, + View::RawUav(workgroups * 256 * 8), + ], + samplers: &[], + groups: [workgroups, 1, 1], + }, + ) + .unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}")); + assert_eq!(out.len(), 1, "{label}: readback UAV count"); + assert_eq!( + out[0].len(), + (workgroups * 256 * 8) as usize, + "{label}: readback length" + ); + for group in 0..workgroups { + for lane in 0..threads { + let offset = ((group * 256 + lane) * 8) as usize; + for (slot, expected) in permlane16_console(lane, group, threads, false) + .into_iter() + .enumerate() + { + if let Some(expected) = expected { + assert_eq!( + out[0][offset + slot], + expected, + "{label}: workgroup {group}, lane {lane}, slot {slot}" + ); + checked_dwords += 1; + } + } + } + } + completed += 1; + checked_lanes += threads * workgroups; + eprintln!("{label}: pipeline created, {workgroups} workgroups completed and checked"); + } + } + assert!(completed > 0 && checked_lanes > 0 && checked_dwords > 0); + eprintln!( + "same-row permlane16: {completed} hardware dispatches, {checked_lanes} lanes and {checked_dwords} defined dwords checked" + ); +} + /// A `while` loop as the console compiler lays one out: the entry jumps to /// the test, which branches back to the body while lanes stay; the body /// falls into the test. The body reads the first lane's thread id diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 668635067..41dbb8073 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -21,6 +21,7 @@ use crate::resource::{Address, CODE, MEMORY, Resources, Role, Site, Source, USER use crate::structure::{Atom, Bool, LaneExit, Map, Set, Structured}; mod atomics; +mod back_edges; mod pages; mod barriers; mod bvh; @@ -11213,10 +11214,9 @@ impl<'a> Lower<'a> { && back(self, taken) && back(self, not_taken) { - return Err(unsupported( - offset, - "a wave64 branch with two loop back edges", - )); + let term = self.two_back_edges(b, cond, taken, not_taken); + self.s.m.terminate(self.cur, term); + return Ok(()); } // (No `xor` of a compare: a loop exit testing one hung the // AMD driver.) diff --git a/crates/victory-shader/src/emit/lower/back_edges.rs b/crates/victory-shader/src/emit/lower/back_edges.rs new file mode 100644 index 000000000..be314e37e --- /dev/null +++ b/crates/victory-shader/src/emit/lower/back_edges.rs @@ -0,0 +1,48 @@ +//! A branch both of whose targets are loop back edges, each under the loop +//! iteration limit ([`LOOP_LIMIT`]). + +use super::*; + +impl Lower<'_> { + /// The terminator of IR block `b`'s branch on `cond` whose both targets, + /// `taken` and `not_taken`, are loop headers it jumps back to (two + /// nested loops whose latches share a block, say). A single back edge + /// leaves its loop at the limit by the branch's other side, a forward + /// one; here both sides go back, so each gets a block of its own that + /// counts the iteration of its loop and, at the limit, leaves the + /// program as an unconditional back edge does ([`Lower::abort_block`]). + /// Below the limit both go where the console goes. In whole-wave control + /// flow every lane of the console wave takes the same side, with the + /// same counts, so the halves reach the limit together. + pub(super) fn two_back_edges( + &mut self, + b: usize, + cond: V, + taken: usize, + not_taken: usize, + ) -> Term { + let side = |l: &mut Self, to: usize| { + let c = l.cur; + let (phi, _) = l.counters[&to]; + let one = l.s.m.i32(1); + let next = l.s.m.bin(c, Bin::Add, phi, one); + let limit = l.s.m.i32(super::super::loop_limit()); + let ok = l.s.m.cmp(c, pred::IULT, next, limit); + let check = l.s.m.new_block(); + l.counters + .get_mut(&to) + .expect("header") + .1 + .push((next, check)); + // The header's phis take this edge's values from `check`. + l.edges.insert((b, to), check); + let abort = l.abort_block(); + let header = l.block[to].expect("reachable"); + l.s.m.terminate(check, Term::CondBr(ok, header, abort)); + check + }; + let t = side(self, taken); + let f = side(self, not_taken); + Term::CondBr(cond, t, f) + } +} diff --git a/crates/victory-shader/src/emit/lower/barriers.rs b/crates/victory-shader/src/emit/lower/barriers.rs index c1a45af79..4155b65a0 100644 --- a/crates/victory-shader/src/emit/lower/barriers.rs +++ b/crates/victory-shader/src/emit/lower/barriers.rs @@ -159,7 +159,10 @@ pub(crate) fn split_wave_barriers_with_step( /// walk back from the latch stops at a block every lane runs together, /// though: every lane reconverges there before the cap exit, so a divergent /// branch earlier than that, whose arms already reconverged there, is no -/// escape. +/// escape. The escape half, and the blocks it takes out of step, are only +/// worked out with the cap's barriers refused (`VICTORY_CAP_BARRIERS=1`, +/// [`crate::emit::cap_barriers_refused`]); otherwise no lane is taken to +/// leave at the cap, as before the loop-cap analysis. /// /// With `need_step` false the step half is left out unless the program has /// an `s_barrier` after a capped back edge, the only reader of the escape @@ -197,12 +200,20 @@ pub(crate) fn step_and_cap_with( // The unconditional back edges, (latch, header): lowering counts the // loop's iterations and at the limit leaves the program from the latch // with an early return. - let capped: Vec<(usize, usize)> = (0..n) - .filter_map(|b| match exits[b] { - LaneExit::Jump(t) if back(b, t) => Some((b, t)), - _ => None, - }) - .collect(); + // Only with the cap's barriers refused (`VICTORY_CAP_BARRIERS=1`): + // otherwise translations take the cap as never reached, as the console + // runs every loop to its end, and keep the barriers after it, the + // halves' too ([`crate::emit::cap_barriers_refused`]). + let capped: Vec<(usize, usize)> = if crate::emit::cap_barriers_refused() { + (0..n) + .filter_map(|b| match exits[b] { + LaneExit::Jump(t) if back(b, t) => Some((b, t)), + _ => None, + }) + .collect() + } else { + Vec::new() + }; if !need_step && (capped.is_empty() || !p diff --git a/crates/victory-shader/src/emit/lower/halves.rs b/crates/victory-shader/src/emit/lower/halves.rs index c058c8aba..d59f7ba84 100644 --- a/crates/victory-shader/src/emit/lower/halves.rs +++ b/crates/victory-shader/src/emit/lower/halves.rs @@ -700,7 +700,12 @@ pub(super) fn needs_first_lane( /// iteration limit: the latch leaves the program there too. That generated /// exit is block `n` here, a terminal exit just like a `Ret`, so a closed /// loop with a capped back edge does not look like it has no way out (which -/// would make everything post-dominate its branches). +/// would make everything post-dominate its branches). A loop that has a way +/// out of its own gets that exit only with the cap's barriers refused +/// (`VICTORY_CAP_BARRIERS=1`, [`crate::emit::cap_barriers_refused`]): +/// otherwise the cap is taken as never reached there, as the console runs +/// the loop to its end, and the blocks after it post-dominate the branches +/// before it as they do on the console. pub(super) fn branch_regions(p: &Program, st: &Structured) -> Option)>> { branch_regions_with(p, &st.exits) } @@ -717,8 +722,16 @@ pub(super) fn branch_regions_with( for (r, &b) in order.iter().enumerate() { rpo[b] = r; } + // Blocks with a way to the program's end of their own: with the cap + // taken as never reached, their loops leave by it. + let ends = if crate::emit::cap_barriers_refused() { + vec![false; n] + } else { + reaches_end(exits)? + }; let capped = |b: usize| { matches!(exits[b], LaneExit::Jump(t) if rpo[b] != usize::MAX && rpo[t] <= rpo[b]) + && !ends[b] }; // Block `n` is the virtual exit of every capped latch. let m = n + 1; @@ -796,6 +809,35 @@ pub(super) fn branch_regions_with( Some(regions) } +/// Per block, whether a path of `exits` leads from it to an end of the +/// program. None with an indirect exit. +fn reaches_end(exits: &[LaneExit]) -> Option> { + let n = exits.len(); + let mut preds: Vec> = vec![Vec::new(); n]; + let mut stack = Vec::new(); + for (b, e) in exits.iter().enumerate() { + match *e { + LaneExit::Jump(t) => preds[t].push(b), + LaneExit::Branch { + taken, not_taken, .. + } => { + preds[taken].push(b); + preds[not_taken].push(b); + } + LaneExit::End => stack.push(b), + LaneExit::Indirect => return None, + } + } + let mut ends = vec![false; n]; + while let Some(b) = stack.pop() { + if std::mem::replace(&mut ends[b], true) { + continue; + } + stack.extend(preds[b].iter().copied().filter(|&q| !ends[q])); + } + Some(ends) +} + /// The thread id's x (`v0` on entry) of a wave64 compute program whose /// console waves are runs of 64 ids along x (a group 64-aligned along x, /// or one row): `id >> 6` and up is one value per console wave. diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index a5e2148fd..6d1f82abf 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -499,16 +499,22 @@ pub struct UserData { pub dword: u32, } -/// Whether an `s_barrier` that a lane may miss at a capped loop's iteration -/// limit makes the shader untranslatable (`VICTORY_CAP_BARRIERS=1`). Off by -/// default: the refusal added with the loop-cap analysis left the tile-list, -/// lighting and temporal anti-aliasing programs out and the world was drawn -/// black on M3 Max and M5 Pro Macs (#497), where keeping their barrier, as -/// before, drew it. Tests always run with the refusal on. +/// Whether a group barrier that a lane may miss at a capped loop's +/// iteration limit makes the shader untranslatable (`VICTORY_CAP_BARRIERS=1`): +/// an `s_barrier`, and the barriers through which the two 32-lane halves of +/// a console wave64 pass each other values (`lower::halves`), which the +/// blocks after such a loop then do not get. Off by default: the console +/// runs a loop to its end, and the limit is the host's guard against data it +/// has not mirrored yet, so off, a translation is the console's wherever +/// the limit is not reached. The refusal added with the loop-cap analysis +/// left the tile-list, lighting and temporal anti-aliasing programs out and +/// the world was drawn black on M3 Max and M5 Pro Macs (#497), where keeping +/// their barrier, as before, drew it. Tests run with the refusal on unless +/// they turn it off ([`with_cap_barriers`]). pub fn cap_barriers_refused() -> bool { #[cfg(test)] { - true + CAP_BARRIERS.get() } #[cfg(not(test))] { @@ -517,6 +523,20 @@ pub fn cap_barriers_refused() -> bool { } } +#[cfg(test)] +thread_local! { + static CAP_BARRIERS: std::cell::Cell = const { std::cell::Cell::new(true) }; +} + +/// Runs `f` with [`cap_barriers_refused`] answering `on` on this thread. +#[cfg(test)] +pub(crate) fn with_cap_barriers(on: bool, f: impl FnOnce() -> R) -> R { + let was = CAP_BARRIERS.replace(on); + let r = f(); + CAP_BARRIERS.set(was); + r +} + /// `VICTORY_CAP_BARRIERS`'s value as a switch: only `1` turns the refusal on. #[cfg_attr(test, allow(dead_code))] fn cap_barriers_from(value: Option<&str>) -> bool { diff --git a/docs/macos.md b/docs/macos.md index 50e06f579..3a241aeb2 100644 --- a/docs/macos.md +++ b/docs/macos.md @@ -342,7 +342,7 @@ None of these changes the default, except `VICTORY_OUTPUT`, which sets the title | `VICTORY_OUTPUT=x` | Sets the title's output size, one of its own modes: 1280x720, 1664x936, 1920x1080, 2560x1440 or 3840x2160. It patches the title's code at load, only where the bytes match build 1.0.2.1, and logs `resolution: ... Done` for each site. Without it the size is 1280x720 on a Mac (see above) and the title's own size elsewhere; `0`, or `none`, leaves the title's own size alone. On a 16 GB M4 (Series X), 1280x720 brought the GPU time of a world frame from about 8.4 s to 0.86 s. Ported from avatarmanz/VIctory-7900XTX. | | `VICTORY_RENDER_SCALE=` | 0.5 to 1.0: the title's own upscaler's render scale (2/3 by default, Series X). Not yet tested on a Mac. | | `VICTORY_UPSCALER=<6\|7>` | Makes the title pick its own upscaler (6) or FidelityFX (7). On Series S with `VICTORY_OUTPUT=1280x720`, FSR4 refuses the size ("maxUpscaleSize must be 1920x1080") and the title crashes with a divide by zero about a minute later; with `VICTORY_UPSCALER=6` it runs (M4, 16 GB). | -| `VICTORY_CAP_BARRIERS=1` | Refuses a shader that has an `s_barrier` a lane may miss at a capped loop's iteration limit (the lane leaves the program there while the others wait). Off by default: the refusal left the tile-list, lighting and temporal anti-aliasing programs out and the world was drawn black on M3 Max and M5 Pro Macs (#497), and keeping their barrier, as before, drew it. Turn it on to look for a hang that those barriers may cause. | +| `VICTORY_CAP_BARRIERS=1` | Refuses a shader that has an `s_barrier` a lane may miss at a capped loop's iteration limit (the lane leaves the program there while the others wait), and a wave64 compute shader on a host of 32-lane waves whose two halves pass each other values after such a loop (those pass through group barriers too). Off by default: the refusal left the tile-list, lighting and temporal anti-aliasing programs out and the world was drawn black on M3 Max and M5 Pro Macs (#497), and keeping their barrier, as before, drew it. Turn it on to look for a hang that those barriers may cause. | | `VICTORY_STEP_OVER=pool` | Steps over the title's "no free element" traps: an `int3` followed by `xor r, r`, the shape of a full fixed-size pool's allocator, whose caller then gets the NULL it already checks for. Series 1.0.2.1 hits one at `+0x5149aec` (the instance lists' pool, Marvisak/VIctory#698) about 20 minutes into the opening when frames take seconds. A list of hex offsets also works. | | `VICTORY_WINDOW_SECONDARY=1` | Opens the game window on the only non-primary display. | | `VICTORY_WINDOW_SECONDARY=x,y` | Opens the game window on the display that holds the desktop point `x,y`, for layouts with more than one extra display (a Sidecar iPad beside two monitors, say). |