Ray tracing: a child that is not there is a miss, whatever its box #213

Open
github-bot wants to merge 1 commit from github-bot/gh-213 into main AGit
Owner

@⁠Pablo-Barros on GitHub · 2026-11-24 22:35 UTC · original
Pablo-Barros:bvh/missing-child-is-a-miss → main · +67 −12 · 4 files · 1 commits · open

What and why

The node test took a child whose pointer is 0xffff_ffff for a hit whenever the ray entered its box, in the CPU reference (bvh.rs) and in the emitted DXIL (emit/intersect.rs). Its result dword was 0xffff_ffff either way, but sorted it came with a finite distance, so it could stand before a child that is there. A traversal that stops at the first "none" would then miss that child.

Both now test the pointer too: a child that is not there is a miss, as the reference's description of the result already said. Unsorted output does not change.

What it moves in the emitted code: two integer instructions per child (a compare and an and). The parity tests' program (the 64-bit form) goes from 519 to 527 instructions by dxc -dumpbin; apart from block numbering, the rest of it is the same.

Validation

Machine: RTX 3070 8 GB (32-lane waves), driver 610.88, Windows 11 Pro 26300 with the in-box D3D12 runtime, Rust 1.98.1. Based on 2119b0e.

  • The reference's new test is the reproducer of #173: a child that is not there whose box is entered first, one child behind it, and two that are not there with their boxes at the ray's origin, in both node widths. Without the change it fails: sorted, the reference returns [ffffffff, ffffffff, ffffffff, 8].
  • The card tests run the same node and ray. With the reference corrected and the emitter not, the four parity tests fail on the card (got [ffffffff, ffffffff, ffffffff, 8], want [8, ffffffff, ffffffff, ffffffff]). With both corrected, they pass on the hardware adapter and on WARP (no skipped line).
  • cargo test -p victory-shader --lib -- bvh:: intersect_tests: 22 passed, 0 failed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and again with --all-features: no warnings.
  • cargo test --workspace --locked: 497 passed, 0 failed, 7 ignored (main's 496 and the new test).
  • cargo xtask policy: 169 files ok.

Not known

  • What the console returns for such a child, and whether the title's builder ever leaves a box under one. The cases of #173 are synthetic, and nothing here was run with the title: ray tracing is off by default. docs/fork-ray-tracing.md lists it with the other assumptions.

Reproducer and first patch: @⁠Bennet0k in #173. AI-assisted patch (the emitter change, the tests and the validation).

Fixes #173

**@⁠Pablo-Barros** on GitHub · 2026-11-24 22:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/213) `Pablo-Barros:bvh/missing-child-is-a-miss` → `main` · +67 −12 · 4 files · 1 commits · open ## What and why The node test took a child whose pointer is `0xffff_ffff` for a hit whenever the ray entered its box, in the CPU reference (`bvh.rs`) and in the emitted DXIL (`emit/intersect.rs`). Its result dword was `0xffff_ffff` either way, but sorted it came with a finite distance, so it could stand before a child that is there. A traversal that stops at the first "none" would then miss that child. Both now test the pointer too: a child that is not there is a miss, as the reference's description of the result already said. Unsorted output does not change. What it moves in the emitted code: two integer instructions per child (a compare and an and). The parity tests' program (the 64-bit form) goes from 519 to 527 instructions by `dxc -dumpbin`; apart from block numbering, the rest of it is the same. ## Validation Machine: RTX 3070 8 GB (32-lane waves), driver 610.88, Windows 11 Pro 26300 with the in-box D3D12 runtime, Rust 1.98.1. Based on `2119b0e`. - The reference's new test is the reproducer of #173: a child that is not there whose box is entered first, one child behind it, and two that are not there with their boxes at the ray's origin, in both node widths. Without the change it fails: sorted, the reference returns `[ffffffff, ffffffff, ffffffff, 8]`. - The card tests run the same node and ray. With the reference corrected and the emitter not, the four parity tests fail on the card (`got [ffffffff, ffffffff, ffffffff, 8]`, `want [8, ffffffff, ffffffff, ffffffff]`). With both corrected, they pass on the hardware adapter and on WARP (no `skipped` line). - `cargo test -p victory-shader --lib -- bvh:: intersect_tests`: 22 passed, 0 failed. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and again with `--all-features`: no warnings. - `cargo test --workspace --locked`: 497 passed, 0 failed, 7 ignored (main's 496 and the new test). - `cargo xtask policy`: 169 files ok. ## Not known - What the console returns for such a child, and whether the title's builder ever leaves a box under one. The cases of #173 are synthetic, and nothing here was run with the title: ray tracing is off by default. `docs/fork-ray-tracing.md` lists it with the other assumptions. Reproducer and first patch: @⁠Bennet0k in #173. AI-assisted patch (the emitter change, the tests and the validation). Fixes #173
The node test's reference (bvh.rs) and its emitter (emit/intersect.rs)
took a child whose pointer is 0xffff_ffff for a hit whenever the ray
entered its box. Its result dword was "none" either way, but sorted it
came with a finite distance, so it could stand before a child that is
there; a traversal that stops at the first "none" would then miss that
child.

Both now test the pointer too: a child that is not there is a miss, as
the reference's description of the result already said. The box test's
emitted code grows by two integer instructions per child (a compare and
an and): the parity tests' program (the 64-bit form) goes from 519 to
527 instructions.

The reference's new test is the reproducer of #173: a child that is not
there whose box is entered first, one child behind it, and two that are
not there with their boxes at the ray's origin, in both node widths. The
card tests run the same node and ray. With the reference corrected and
the emitter not, the four parity tests fail on the card; corrected, they
pass on the card and on WARP.

Not known: what the console returns for such a child, and whether the
title's builder ever leaves a box under one. The cases of #173 are
synthetic. docs/fork-ray-tracing.md lists it with the other assumptions.

Reproducer and patch: @Bennet0k, #173.

Co-Authored-By: GLM <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:30 +00:00
Author
Owner

@⁠pr0vId3nce on GitHub · 2026-11-25 13:56 UTC · original

Hardware result for this fixture: an RDNA2 GPU returns [8, ffffffff, ffffffff, ffffffff]

I ran this PR's MISSING_FIRST node and ray (children [ffffffff, 8, ffffffff, ffffffff], the boxes of the test, ray from the origin along +z, extent 10) through the real instruction: image_bvh64_intersect_ray and image_bvh_intersect_ray, run natively from raw words on a Ryzen 9 7900X's iGPU (gfx1036, RDNA2 with the ray accelerators, driver 32.0.21042.62) through the AMD driver's own amd_comgr/HIP DLLs.

sorted not sorted
RDNA2 GPU (32-bit and 16-bit node, both instruction forms) 00000008 ffffffff ffffffff ffffffff ffffffff 00000008 ffffffff ffffffff
4e17478b9: bvh.rs, and its DXIL on an RTX 4080, the AMD iGPU and WARP ffffffff ffffffff ffffffff 00000008 ffffffff 00000008 ffffffff ffffffff
4e17478b9 with this PR's condition in bvh.rs 00000008 ffffffff ffffffff ffffffff ffffffff 00000008 ffffffff ffffffff

A second node, children [8, ffffffff, 18, 1ffffffc] with boxes entered at 10, 5, 20 and 15 along +x: the GPU returns 00000008 1ffffffc 00000018 ffffffff, 4e17478b9 returns ffffffff 00000008 1ffffffc 00000018. Only ffffffff is special: with children 8, fffffffe, 7fffffff, fffffff8 the GPU returns all four, in entry order.

So the expected value here (and in #173) is what the hardware does.

Scope: desktop RDNA2, not the console. Synthetic nodes, no game data. I did not build this branch; the third row is its bvh.rs condition applied to 4e17478b9 on the CPU.

AI-assisted (Claude Code); the runs are from my machine.

**@⁠pr0vId3nce** on GitHub · 2026-11-25 13:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/213#issuecomment-7164508496) **Hardware result for this fixture: an RDNA2 GPU returns `[8, ffffffff, ffffffff, ffffffff]`** I ran this PR's `MISSING_FIRST` node and ray (children `[ffffffff, 8, ffffffff, ffffffff]`, the boxes of the test, ray from the origin along +z, extent 10) through the real instruction: `image_bvh64_intersect_ray` and `image_bvh_intersect_ray`, run natively from raw words on a Ryzen 9 7900X's iGPU (gfx1036, RDNA2 with the ray accelerators, driver 32.0.21042.62) through the AMD driver's own amd_comgr/HIP DLLs. | | sorted | not sorted | |---|---|---| | RDNA2 GPU (32-bit and 16-bit node, both instruction forms) | `00000008 ffffffff ffffffff ffffffff` | `ffffffff 00000008 ffffffff ffffffff` | | `4e17478b9`: `bvh.rs`, and its DXIL on an RTX 4080, the AMD iGPU and WARP | `ffffffff ffffffff ffffffff 00000008` | `ffffffff 00000008 ffffffff ffffffff` | | `4e17478b9` with this PR's condition in `bvh.rs` | `00000008 ffffffff ffffffff ffffffff` | `ffffffff 00000008 ffffffff ffffffff` | A second node, children `[8, ffffffff, 18, 1ffffffc]` with boxes entered at 10, 5, 20 and 15 along +x: the GPU returns `00000008 1ffffffc 00000018 ffffffff`, `4e17478b9` returns `ffffffff 00000008 1ffffffc 00000018`. Only `ffffffff` is special: with children `8, fffffffe, 7fffffff, fffffff8` the GPU returns all four, in entry order. So the expected value here (and in #173) is what the hardware does. Scope: desktop RDNA2, not the console. Synthetic nodes, no game data. I did not build this branch; the third row is its `bvh.rs` condition applied to `4e17478b9` on the CPU. _AI-assisted (Claude Code); the runs are from my machine._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/213/head:github-bot/gh-213'
git switch 'github-bot/gh-213'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-213'
git switch 'github-bot/gh-213'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-213'
git switch 'github-bot/gh-213'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-213'
git switch 'main'
git merge --squash 'github-bot/gh-213'
git switch 'main'
git merge --ff-only 'github-bot/gh-213'
git switch 'main'
git merge 'github-bot/gh-213'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.