From 25b0f888cab67fc3653c7e17257075ff4c8e932a Mon Sep 17 00:00:00 2001 From: Dathinel <221246794+Dathinel@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:25:14 -0500 Subject: [PATCH 1/2] Test probe: compare direct and joined reads of a shader timestamp (cherry picked from commit 4b2ea70f0940a4317dc934000d249dce0fce50f6) --- crates/victory-shader/src/emit/lower.rs | 37 ++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index ca5e898..8b8302a 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -6565,8 +6565,8 @@ mod tests { const S_ENDPGM: u32 = 0xBF81_0000; - /// Lowers a compute program of constants: whether it translates. - fn lowers(words: &[u32]) -> Result<(), crate::ShaderError> { + /// Whether a synthetic compute program translates with these input registers. + fn lowers(words: &[u32], rsrc2: u32) -> Result<(), crate::ShaderError> { let code: Vec = words.iter().flat_map(|w| w.to_le_bytes()).collect(); let native = NativeProgram { stage: HwStage::Cs, @@ -6575,7 +6575,7 @@ mod tests { layout: vec![], used: vec![], io: StageIo::Cs(ComputeIo { - rsrc2: 0, + rsrc2, threads: [1, 1, 1], }), code, @@ -6626,10 +6626,39 @@ mod tests { S_ENDPGM, ]; for words in [add, sub] { - lowers(&words).unwrap(); + lowers(&words, 0).unwrap(); } } + #[test] + fn a_missing_value_stays_missing_through_two_live_joins() { + let mut words = [ + 0xF490_0180, + 0, // s_memtime s[6:7] + 0xBF06_8000, // s_cmp_eq_u32 s0, 0 (s0 = group id X) + 0xBF85_0001, // skip the first overwrite + 0xBE86_0380, // s_mov_b32 s6, 0 + 0xBF06_8101, // s_cmp_eq_u32 s1, 1 (s1 = group id Y) + 0xBF85_0001, // skip the second overwrite + 0xBE86_0381, // s_mov_b32 s6, 1 + 0xBF07_8006, // s_cmp_lg_u32 s6, 0 + 0xBF85_0001, // use the result to branch + 0xBE83_0380, + S_ENDPGM, + ]; + let group_ids_xy = 3 << 7; + // Compare to a direct read so future timestamp support works in both cases. + let refusal = |code: &[u32]| match lowers(code, group_ids_xy) { + Ok(()) => None, + Err(crate::ShaderError::Unsupported { what, .. }) => Some(what), + Err(error) => panic!("{error}"), + }; + let direct = [&words[..2], &words[8..]].concat(); + assert_eq!(refusal(&words), refusal(&direct)); + words[8] = 0xBF07_8000; // read the group id instead; the timestamp is dead + lowers(&words, group_ids_xy).expect("dead timestamp"); + } + #[test] fn buffer_formats_by_number() { // The numbers the disassembler names 8_8_8_8_UNORM, 16_16_SNORM, From 3dd467ccee8d6612fa41aa17537c0b182477ceac Mon Sep 17 00:00:00 2001 From: KoLolX3 <94136289+KoLolX3@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:36:08 -0800 Subject: [PATCH 2/2] Shaders: a phi that only another read phi consumes is live too fill_phis treats a phi no one read directly as dead and fills a value with no DXIL form (an unsupported s_memtime result, say) with zero. When that value reaches a read through two joins, the first phi is only read by the second, so it was never marked read: the read lowered with a zero where the same value read directly is refused with "a scalar memory read as data". Mark the incoming phis of every read phi as read, transitively, before the phis are filled. The reproducer from #604 now agrees for the direct and the joined read, and the dead control (the timestamp replaced by a group id) still lowers. --- crates/victory-shader/src/emit/lower.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 8b8302a..c22339d 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -6508,6 +6508,20 @@ impl<'a> Lower<'a> { fn fill_phis(&mut self) -> Result<(), Stop> { let p = self.x.p; + // A phi that only another read phi consumes is live too. Without this, a value with no DXIL form that + // reaches a read through two joins is taken for dead at the first join and replaced by zero below, and the + // lowering accepts what it refuses when the same value is read directly. + let mut work: Vec = self.read_phis.iter().copied().collect(); + while let Some(v) = work.pop() { + let Some(&(b, i)) = self.phi_at.get(&v) else { + continue; + }; + for &arg in &p.blocks[b].phis[i].args { + if self.phi_at.contains_key(&arg) && self.read_phis.insert(arg) { + work.push(arg); + } + } + } for (v, b, i) in std::mem::take(&mut self.data_phis) { let phi = &p.blocks[b].phis[i]; let bit = phi.reg == Reg::Scc;