Structure builder and rays: dispatches counted in threads, empty slots never entered, pages that are not there never hit; vertex signatures as DXC orders them

From DexNom/VIctory (GPL-3.0-or-later) bc3cd4b0 and 5f4c3df4:
- DispatchX's flag 0x20 says the counts are threads (bc3cd4b0). Taken for
  groups, a rehydration stage ran up to 64 times its threads and stored over
  the structures after its own. The lanes past the count leave at once, in
  every builder program of one dimension without a group barrier (there: in
  two, by digest). VICTORY_THREAD_DIMENSIONS=0: as before.
- A child that is not there may have inverted infinite bounds: it was entered
  at minus infinity, came first and ended the walk (bc3cd4b0).
- A node in a page without a copy reads zeros, a child and a box: no hit
  (bc3cd4b0).
- Signature rows in the order of their names; vertex outputs interpolated as
  the title's PSV0 says; an unread input packed beside a per-vertex one is
  constant too (5f4c3df4), with their tests.
Every shader is translated again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 09:39:18 -06:00
1 parent 972bb4b0f8
commit 810efe5829
11 files changed
+443 -44

No files matched your search

+54 -2
View File
@@ -87,9 +87,33 @@ enum Stop {
}
pub(crate) fn lower(parts: &Parts) -> Result<Lowered, ShaderError> {
lower_counted(parts, counted_in_threads(parts))
}
/// Whether the title dispatches the program by a count of threads whose last
/// group may be partial: the structure builder's programs of one dimension.
/// Their lanes past the count must not run (they count the lanes of a wave
/// and store). Not where a group barrier would wait for lanes that left, nor
/// where two host waves of 32 stand for a console wave (they exchange, which
/// takes all lanes).
fn counted_in_threads(parts: &Parts) -> bool {
let crate::native::StageIo::Cs(cs) = &parts.native.io else {
return false;
};
cs.threads[0] > 1
&& cs.threads[1..] == [1, 1]
&& crate::spill::is_spilled(parts.native)
&& (!parts.native.wave64 || host_max_wave() >= 64)
&& !parts.p.blocks.iter().flat_map(|b| &b.insts).any(|i| i.name() == "s_barrier")
}
/// [`lower`]; `counted`: the lanes past a dispatch's count of threads leave
/// at once (`shader.rs` `USER_DISPATCH_THREADS_X`; after DexNom/VIctory
/// bc3cd4b0, which does so for two of the programs by their digests).
pub(super) fn lower_counted(parts: &Parts, counted: bool) -> Result<Lowered, ShaderError> {
let mut bad = HashMap::new();
loop {
match Lower::new(parts, &bad).run() {
match Lower::new(parts, &bad).run(counted) {
Ok(l) => return Ok(l),
Err(Stop::Retry(v, why)) => {
if bad.insert(v, why).is_some() {
@@ -262,6 +286,8 @@ struct Lower<'a> {
/// In the instruction being lowered: the host copy its root view's bytes
/// are in ([`Lower::root_memory`]).
root_copy: Option<V>,
/// Whether the page [`Lower::memory`] last looked for has a copy.
page_there: Option<V>,
mask_phis: HashMap<Value, V>,
pending_masks: Vec<(V, usize, usize)>,
data_phis: Vec<(V, usize, usize)>,
@@ -1576,6 +1602,7 @@ impl<'a> Lower<'a> {
stale: HashSet::new(),
coherent: HashSet::new(),
root_copy: None,
page_there: None,
ordered: if x.native.stage == HwStage::Ps {
ordered_section(p)
} else {
@@ -2257,8 +2284,32 @@ impl<'a> Lower<'a> {
Ok(self.s.m.bin(c, Bin::Or, first, total))
}
fn run(mut self) -> Result<Lowered, Stop> {
fn run(mut self, counted: bool) -> Result<Lowered, Stop> {
let p = self.x.p;
if counted {
// Before anything else, so that wave counts, reads of the first
// lane and stores know only the lanes that run.
let original = self.s.entry;
let width = self.s.threads.expect("compute thread count")[0];
let limit = self.host_word(RootType::Other(super::shader::USER_DISPATCH_THREADS_X), 0, width);
let Val::I32(group) = self.compute_id("groupId.i32", 94, 0) else {
unreachable!()
};
let Val::I32(thread) = self.thread_id(0) else {
unreachable!()
};
let width = self.s.m.i32(width);
let first = self.s.m.bin(original, Bin::Mul, group, width);
let x = self.s.m.bin(original, Bin::Add, first, thread);
let zero = self.s.m.i32(0);
let all = self.s.m.cmp(original, pred::EQ, limit, zero);
let inside = self.s.m.cmp(original, pred::IULT, x, limit);
let runs = self.s.m.bin(original, Bin::Or, all, inside);
let (body, done) = (self.s.m.new_block(), self.s.m.new_block());
self.s.m.terminate(original, Term::CondBr(runs, body, done));
self.s.m.terminate(done, Term::Ret);
self.s.entry = body;
}
self.find_coherent();
let order = crate::ir::reverse_postorder(&p.blocks);
for (n, &b) in order.iter().enumerate() {
@@ -3077,6 +3128,7 @@ impl<'a> Lower<'a> {
);
self.end_guarded(noting, &[]);
let c = self.cur;
self.page_there = Some(self.s.m.cmp(c, pred::NE, copy, zero));
let copy = if store {
let closed = self.s.m.cmp(c, pred::SLT, number, zero);
self.s.m.select(c, closed, zero, copy)