فهرست منبع

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.
KoLolX3 3 روز پیش
والد
کامیت
3dd467ccee
1فایلهای تغییر یافته به همراه14 افزوده شده و 0 حذف شده
  1. 14 0
      crates/victory-shader/src/emit/lower.rs

+ 14 - 0
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<Value> = 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;