Shader: VICTORY_BVH_MISS ends ray walks at the root

While the BVH builder is off its nodes are stale: VICTORY_BVH_MISS=1 makes every box and triangle test a miss instead of walking them (no hang, about 10 ms a frame less). It is part of the shader cache key.
This commit is contained in:
trustno1-coder authored and GitHub committed 2026-11-25 15:44:02 -08:00
1 parent afd84de12f
commit 24a479d329
1 file changed
+21 -2
+21 -2
View File
@@ -59,6 +59,14 @@ struct Ray {
inverse: [V; 3],
}
/// LOCAL (from our wt5): `VICTORY_BVH_MISS=1` (off by default): the node test
/// misses every node. While the structure builder is off the structures are
/// never built, and a walk of what lies in their memory is not the console's.
fn bvh_miss() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_BVH_MISS").is_some_and(|v| v == "1"))
}
impl<'a> Lower<'a> {
/// `image_bvh_intersect_ray` and `image_bvh64_intersect_ray`.
pub(super) fn bvh(&mut self, inst: &Inst, b: usize, i: usize) -> Result<(), Why> {
@@ -191,11 +199,22 @@ impl<'a> Lower<'a> {
.m
.terminate(leaf_block, Term::CondBr(is_triangle, triangle_block, join));
self.cur = box_block;
let boxes = self.bvh_boxes(at, kind, &ray, sort);
// LOCAL (from our wt5): with `VICTORY_BVH_MISS=1` every node is missed
// without being read: a box returns no child and a triangle the
// triangle miss, so a walk ends at its first node.
let boxes = if bvh_miss() {
[self.s.m.i32(bvh::NONE); 4]
} else {
self.bvh_boxes(at, kind, &ray, sort)
};
let box_end = self.cur;
self.s.m.terminate(box_end, Term::Br(join));
self.cur = triangle_block;
let triangle = self.bvh_triangle(at, kind, &ray);
let triangle = if bvh_miss() {
bvh::MISS.map(|f| self.s.m.i32(f.to_bits()))
} else {
self.bvh_triangle(at, kind, &ray)
};
let triangle_end = self.cur;
self.s.m.terminate(triangle_end, Term::Br(join));
self.cur = join;