Shaders: per-lane descriptors chosen by control flow

A waterfall loop whose descriptor dwords are VGPR phis stopped with "a
descriptor read from the first lane of a phi" (294 programs of the
title on #307, all at if/else joins of two s_load_dwordx4 descriptors
copied into VGPRs). An EXEC if/else leaves two phis per dword: the
flow block's joins an arm's dwords with what lanes that skipped the arm
held before (inputs, unrelated loads and arithmetic in the title), the
join after the other arm picks per path. Only lanes that never read the
descriptor bring those other values, so tracing every edge fails.

Tracing (resource::track now takes the program's per-lane form):
- per-lane phis of one block are traced on each edge into it that the
  lanes accessing the descriptor can take, from structure's lane
  conditions (new Structured::reach, the exits' conditions, and
  Bools::meet, a read-only satisfiability check); the trace starts from
  what holds in the access's block. Edges no such lane takes are None
  in the new Source::LanePhi { block, args };
- every per-lane write it follows (v_mov_b32 copies, v_cndmask_b32,
  global_load_dword*) must run in all those lanes: a guarded one fails
  with "a per-lane descriptor written where some lanes may keep the old
  one". On #307 an else arm without its s_cbranch_execz traced as the
  second descriptor for every lane;
- a loop header's phi fails with "a descriptor read from the first lane
  of a phi at a loop header", words defined after the join with "a
  descriptor partly joined by control flow"; without the per-lane form
  (structurisation failed) the join is refused.

Lowering computes each traced edge's heap index at its predecessor's end
(through lane_heap_index, so loads, per-lane loads, choices and nested
joins work), joins them with a phi (0 on untaken edges) and makes the
handle non-uniform. The waterfall compares need no change.

Tests: the if/else of two loaded image descriptors, a join of a per-lane
load and a v_cndmask choice, nested arms choosing a buffer descriptor
with lanes that skip both and do not load (pruned only by the access's
condition), a loop header phi, and an unskipped else arm. On #307's head
the three join programs fail with "...of a phi" and the unskipped arm is
traced as one descriptor for all lanes. On an RTX 5070 and WARP, each
lane reads its own arm's texture or buffer; the shaders pass dxil.dll
1.8.2502.11. Reversing the phi's inputs fails validation, flipping the
heap index fails the GPU check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
r4.andClaude Opus 5.5 committed 2026-11-24 06:59:46 +02:00
1 parent 6285e19a8a
commit 6638098cee
8 files changed
+1114 -66

No files matched your search

+38
View File
@@ -99,6 +99,8 @@ impl Hasher for Fx {
const TERMINAL: u32 = u32::MAX;
const MAX_NODES: usize = 1 << 21;
/// Case splits [`Bools::meet`] makes before it gives up.
const MAX_MEET: usize = 1 << 16;
impl Bools {
fn new() -> Self {
@@ -221,6 +223,38 @@ impl Bools {
self.ite(a, nb, b)
}
/// Whether some lane can satisfy every `(b, holds)` of `all` at once:
/// `b` where `holds`, its negation where not. Yes when the search grows
/// too large to finish.
pub fn meet(&self, all: &[(Bool, bool)]) -> bool {
let mut budget = MAX_MEET;
self.meet_in(all.to_vec(), &mut budget)
}
fn meet_in(&self, mut all: Vec<(Bool, bool)>, budget: &mut usize) -> bool {
let fails = |&(b, holds): &(Bool, bool)| b == if holds { Bool::FALSE } else { Bool::TRUE };
if all.iter().any(fails) {
return false;
}
all.retain(|&(b, _)| b != Bool::FALSE && b != Bool::TRUE);
if all.is_empty() || *budget == 0 {
return true;
}
*budget -= 1;
let top = |b: Bool| self.nodes[b.0 as usize].0;
let v = all.iter().map(|&(b, _)| top(b)).min().expect("not empty");
[false, true].into_iter().any(|value| {
let next = all
.iter()
.map(|&(b, holds)| {
let (lo, hi) = self.split(b, v);
(if value { hi } else { lo }, holds)
})
.collect();
self.meet_in(next, budget)
})
}
fn implies(&mut self, a: Bool, b: Bool) -> bool {
let nb = self.not(b);
self.and(a, nb) == Bool::FALSE
@@ -306,6 +340,9 @@ pub struct Structured {
/// enough (lanes outside EXEC then never get there, so a VGPR write
/// needs no old value). Always `None` for scalar instructions.
pub guards: Vec<Vec<Option<Bool>>>,
/// Per block: what holds in every lane that enters it (over forward
/// edges; a loop header forgets what its loop redefines).
pub reach: Vec<Bool>,
/// The lane's bit of each lane-mask value, by its low dword's value.
pub masks: HashMap<Value, Bool>,
/// Wave64 masks: low dword's value by the high dword's.
@@ -587,6 +624,7 @@ impl<'a> Lanes<'a> {
bools: self.b,
exits,
guards,
reach: cond.to_vec(),
})
}