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 0769cc9dc8
commit bc83b16387
11 files changed
+443 -44

No files matched your search

+64 -24
View File
@@ -46,8 +46,9 @@ enum NodeAt {
Buffer { handle: V, byte: V },
/// In title memory: the raw view of the host copy holding the node's
/// first 64 bytes and the node's byte in it ([`Lower::bvh_memory`]),
/// and the node's address, for the second half of a 128-byte node.
Memory { handle: V, byte: V, low: V, high: V },
/// the node's address, for the second half of a 128-byte node, and
/// whether there is a copy.
Memory { handle: V, byte: V, low: V, high: V, mapped: V },
}
/// The ray operands, as floats.
@@ -163,12 +164,13 @@ impl<'a> Lower<'a> {
// One look for the node's copy, before the branches: a
// node is 64 bytes on 64, so its first half lies in one
// 64 KiB page whatever its kind.
let (handle, byte) = self.bvh_memory(low, high, guard);
let (handle, byte, mapped) = self.bvh_memory(low, high, guard);
NodeAt::Memory {
handle,
byte,
low,
high,
mapped,
}
}
};
@@ -225,7 +227,7 @@ impl<'a> Lower<'a> {
/// host copy holding the address and the byte in that view
/// ([`Lower::memory`]: a page the host has no copy of reads zeros and
/// is left for the host to fetch, for lanes that run).
fn bvh_memory(&mut self, low: V, high: V, guard: Option<V>) -> (V, V) {
fn bvh_memory(&mut self, low: V, high: V, guard: Option<V>) -> (V, V, V) {
#[cfg(test)]
if let Some((slot, base)) = TEST_MEMORY.get() {
// The buffer at heap slot `slot` holds the bytes from title
@@ -242,34 +244,49 @@ impl<'a> Lower<'a> {
let inside = self.s.m.bin(c, Bin::And, in_low, in_high);
let outside = self.s.m.i32(0xffff_ff00);
let at = self.s.m.select(c, inside, at, outside);
return (handle, at);
return (handle, at, inside);
}
self.memory(low, high, guard, false)
let (handle, byte) = self.memory(low, high, guard, false);
let mapped = self.page_there.expect("memory says");
(handle, byte, mapped)
}
/// `count` dwords of the node from its byte `base` + `offset` (`base`
/// computed, `offset` fixed; none of the node's bytes past 127), read
/// four at a time.
/// The second 64 bytes of a 128-byte node: in a page, and in a copy, of
/// their own maybe. Goes on in another block.
fn bvh_second_half(&mut self, at: NodeAt) -> NodeAt {
match at {
NodeAt::Buffer { handle, byte } => {
let size = self.s.m.i32(64);
let byte = self.s.m.bin(self.cur, Bin::Add, byte, size);
NodeAt::Buffer { handle, byte }
}
NodeAt::Memory { low, high, .. } => {
let (low, high) = self.address_plus(low, high, 64);
// Every lane in this block runs the instruction.
let (handle, byte, mapped) = self.bvh_memory(low, high, None);
NodeAt::Memory {
handle,
byte,
low,
high,
mapped,
}
}
}
}
/// `count` dwords of 64 bytes of a node from their byte `base` + `offset`
/// (`base` computed, `offset` fixed), read four at a time.
fn bvh_node_words(&mut self, at: NodeAt, base: Option<V>, offset: u32, count: u32) -> Vec<V> {
let (undef, align) = (self.s.m.undef(self.s.t.i32), self.s.m.i32(4));
// The second half of a 128-byte node may lie in the next 64 KiB
// page, which may be in another copy: its own look, made once.
let mut second = None;
let (handle, start_byte) = match at {
NodeAt::Buffer { handle, byte } | NodeAt::Memory { handle, byte, .. } => (handle, byte),
};
let mut out = Vec::with_capacity(count as usize);
for start in (0..count).step_by(4) {
let n = (count - start).min(4);
let node_byte = offset + 4 * start;
let (handle, mut byte) = match at {
NodeAt::Buffer { handle, byte } => (handle, byte),
NodeAt::Memory { handle, byte, .. } if node_byte < 64 => (handle, byte),
NodeAt::Memory { low, high, .. } => *second.get_or_insert_with(|| {
let (low, high) = self.address_plus(low, high, 64);
// Every lane in this block runs the instruction.
let (handle, byte) = self.bvh_memory(low, high, None);
let (k64, c) = (self.s.m.i32(64), self.cur);
(handle, self.s.m.bin(c, Bin::Sub, byte, k64))
}),
};
let mut byte = start_byte;
let c = self.cur;
if let Some(b) = base {
byte = self.s.m.bin(c, Bin::Add, byte, b);
@@ -328,7 +345,9 @@ impl<'a> Lower<'a> {
// 32-bit floats: 24 dwords from byte 16.
self.cur = wide_block;
let k16 = self.s.m.i32(16);
let words = self.bvh_node_words(at, None, 16, 24);
let mut words = self.bvh_node_words(at, None, 16, 12);
let second = self.bvh_second_half(at);
words.extend(self.bvh_node_words(second, None, 0, 12));
let floats: Vec<V> = words.iter().map(|&w| self.as_float(w)).collect();
// (The look for the second half goes on in another block.)
let wide_block = self.cur;
@@ -356,6 +375,21 @@ impl<'a> Lower<'a> {
}
self.s.m.terminate(half_block, Term::Br(join));
self.cur = join;
// A page that is not there reads zeros, which are a child and a box:
// no child of it is hit. (The last two boxes of a 128-byte node are in
// its second half.)
let there = match (at, second) {
(NodeAt::Memory { mapped: first, .. }, NodeAt::Memory { mapped: last, .. }) => {
let i1t = self.s.m.type_of(first);
let mapped = self.s.m.phi(join, i1t);
self.s
.m
.set_phi(mapped, vec![(last, wide_block), (first, half_block)]);
let both = self.s.m.bin(join, Bin::And, first, mapped);
Some([first, first, both, both])
}
_ => None,
};
let mut coords = Vec::with_capacity(24);
for n in 0..24 {
let phi = self.s.m.phi(join, f32t);
@@ -405,6 +439,12 @@ impl<'a> Lower<'a> {
let on = self.s.m.bin(c, Bin::Xor, off, on);
let hit = self.s.m.bin(c, Bin::And, through, before);
let hit = self.s.m.bin(c, Bin::And, hit, on);
let child = self.s.m.cmp(c, pred::NE, children[n], none);
let hit = self.s.m.bin(c, Bin::And, hit, child);
let hit = match there {
Some(there) => self.s.m.bin(c, Bin::And, hit, there[n]),
None => hit,
};
ids[n] = self.s.m.select(c, hit, children[n], none);
distances[n] = self.s.m.select(c, hit, enter, infinity);
}