Ray tracing: the ray test misses inverted boxes, as the console's does (+57 % fps with ray tracing) #3067

Open
opened 2026-11-29 19:53:20 +00:00 by github-bot · 4 comments
Owner

@⁠HQasper on GitHub · 2026-11-29 19:52 UTC · original

What it changes

The emulated box test is the same for a box and its mirror. So a child whose minimum is above its maximum on an axis is entered as the box between its corners. A child with inverted infinite bounds (+inf/-inf) is entered at minus infinity, first of the sorted children; only absent children were kept out (bc3cd4b0).

The title's BVH builder writes such boxes: its box-node programs start from +inf/-inf halves. The console's own software form of the test misses them, as the 2026.10 GDKX's software traversal does; it is the usual slab test, where an empty interval is a miss. Walking them costs about a quarter of the frame rate with ray tracing.

What is in it:

  • Shaders: VICTORY_BVH_INVERTED_MISS=1 …: victory-shader/src/bvh.rs (the reference test and its unit tests), emit/intersect.rs (the emitted code follows the same switch), and the shader cache key.
  • Launcher: …: on by default in apps/victory/src/play.rs and scripts/play-foxhound.ps1.

How it was tested

  • GPU and profile: RTX 5090 (driver 621.24), Ryzen 9 9950X3D, Series X, 1440p (VICTORY_NATIVE_SIZE=2560x1440 because of #2141), DLSS Quality, ray tracing on with the launcher's other ray-tracing defaults (the rehydration limits and the builder's coherence, walk loops at 512), frame generation off.

  • In game, on 829188e (the same code as 55d06914): eight runs of 6 minutes from the same save, in the order b r i t t i r b (b: the launcher's ray-tracing defaults all on; r, i, t: PR 1, 2 or 3 off), with shaders and pipelines made beforehand for each variant. The world is reached about 45 s after the first frame. "Way in" is its first 60 s, "play" the next 180 s. Each cell is the mean of two runs, with the two runs' values in brackets. 0 GPU removals and 0 crashes in all eight runs.

    Before (switch off) After (switch on)
    fps in play 20.0 (17.3 / 22.7) 31.4 (29.9 / 32.8)
    1 % low in play 8.3 (8.1 / 8.4) fps 14.6 (13.1 / 16.1) fps
    Frames over 50 ms in play 1,606 (2,252 / 960) 96 (139 / 53)
    fps on the way in 15.1 (16.3 / 13.9) 23.5 (22.9 / 24.1)

    The card is busy 96-97 % of the time without the switch and 88 % with it. On the first base this was measured on (8fc2254, ABBA, 180 s settled) it was 26.2 / 22.4 → 31.3 / 30.6 fps.

  • Not measured: without the launcher's other ray-tracing defaults.

  • Pictures (base 8fc2254): four captures of the opening at the same moments (two each way, in both orders) show no difference that follows the switch.

  • Wave sizes: 32-lane host.

  • cargo test (cargo test --workspace --locked --no-fail-fast -- --test-threads=4, 2026-11-29): 2,166 passed, 4 failed, 78 ignored. The 4 failures are upstream's (below). Upstream main 55d06914 itself gives 2,165 passed, 4 failed, 78 ignored. Its 4 failures are three bcpack::tests::oracle_parity_* tests and xtask's repository_passes_policy, which flags upstream's own victory-loader/src/heap_sites/frame_users.rs.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: merged #82 ("rays miss unbuilt structures"), which this builds on. Nothing open covers inverted boxes.

Written with Claude Code (Claude Opus 5.5); measured on my PC; reviewed by me.

🤖 Generated with Claude Code

Pull request details or commits were not available from GitHub; kept as an issue.

**@⁠HQasper** on GitHub · 2026-11-29 19:52 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3067) ## What it changes The emulated box test is the same for a box and its mirror. So a child whose minimum is above its maximum on an axis is entered as the box between its corners. A child with inverted infinite bounds (+inf/-inf) is entered at minus infinity, first of the sorted children; only absent children were kept out (bc3cd4b0). The title's BVH builder writes such boxes: its box-node programs start from +inf/-inf halves. The console's own software form of the test misses them, as the 2026.10 GDKX's software traversal does; it is the usual slab test, where an empty interval is a miss. Walking them costs about a quarter of the frame rate with ray tracing. **What is in it:** - `Shaders: VICTORY_BVH_INVERTED_MISS=1 …`: `victory-shader/src/bvh.rs` (the reference test and its unit tests), `emit/intersect.rs` (the emitted code follows the same switch), and the shader cache key. - `Launcher: …`: on by default in `apps/victory/src/play.rs` and `scripts/play-foxhound.ps1`. ## How it was tested - **GPU and profile:** RTX 5090 (driver 621.24), Ryzen 9 9950X3D, Series X, 1440p (`VICTORY_NATIVE_SIZE=2560x1440` because of #2141), DLSS Quality, ray tracing on with the launcher's other ray-tracing defaults (the rehydration limits and the builder's coherence, walk loops at 512), frame generation off. - **In game, on 829188e** (the same code as 55d06914): eight runs of 6 minutes from the same save, in the order b r i t t i r b (b: the launcher's ray-tracing defaults all on; r, i, t: PR 1, 2 or 3 off), with shaders and pipelines made beforehand for each variant. The world is reached about 45 s after the first frame. "Way in" is its first 60 s, "play" the next 180 s. Each cell is the mean of two runs, with the two runs' values in brackets. 0 GPU removals and 0 crashes in all eight runs. | | Before (switch off) | After (switch on) | |---|---|---| | fps in play | 20.0 (17.3 / 22.7) | 31.4 (29.9 / 32.8) | | 1 % low in play | 8.3 (8.1 / 8.4) fps | 14.6 (13.1 / 16.1) fps | | Frames over 50 ms in play | 1,606 (2,252 / 960) | 96 (139 / 53) | | fps on the way in | 15.1 (16.3 / 13.9) | 23.5 (22.9 / 24.1) | The card is busy 96-97 % of the time without the switch and 88 % with it. On the first base this was measured on (8fc2254, ABBA, 180 s settled) it was 26.2 / 22.4 → 31.3 / 30.6 fps. - **Not measured:** without the launcher's other ray-tracing defaults. - **Pictures** (base 8fc2254): four captures of the opening at the same moments (two each way, in both orders) show no difference that follows the switch. - **Wave sizes:** 32-lane host. - **`cargo test`** (`cargo test --workspace --locked --no-fail-fast -- --test-threads=4`, 2026-11-29): 2,166 passed, 4 failed, 78 ignored. The 4 failures are upstream's (below). Upstream main 55d06914 itself gives 2,165 passed, 4 failed, 78 ignored. Its 4 failures are three `bcpack::tests::oracle_parity_*` tests and `xtask`'s `repository_passes_policy`, which flags upstream's own `victory-loader/src/heap_sites/frame_users.rs`. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: merged #82 ("rays miss unbuilt structures"), which this builds on. Nothing open covers inverted boxes. --- Written with Claude Code (Claude Opus 5.5); measured on my PC; reviewed by me. 🤖 Generated with [Claude Code](https://claude.com/claude-code) *Pull request details or commits were not available from GitHub; kept as an issue.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 19:53:20 +00:00
github-bot changed title from [pr-fix] Ray tracing: the ray test misses inverted boxes, as the console's does (+57 % fps with ray tracing) to Ray tracing: the ray test misses inverted boxes, as the console's does (+57 % fps with ray tracing) 2026-11-29 20:00:16 +00:00
Author
Owner

@⁠DoubleD17 on GitHub · 2026-11-30 09:58 UTC · original

We ran a test of this PR with ray tracing on (VICTORY_BVH_BUILDER=1), on a 12 GB card, on current main (41adb551 with this PR merged, head 5b3815e9). The log confirmed the switch: "VICTORY_BVH_INVERTED_MISS: ray tests miss boxes whose minimum is above their maximum".

No difference we can measure on this card. With ray tracing on, the card is the limit here: about 4 to 6 fps, the GPU busy 98 to 100 % of the time, and the host's "on the GPU" time is 75 to 185 ms a frame, against 4 to 8 ms with ray tracing off. Main's own three runs spread that widely, so two PR runs cannot show a change of the size you measured (20.0 → 31.4 fps on an RTX 5090).

Light-view seconds only (the idle camera's lighter views, about 7,500 draws a frame):

on the GPU (ms/frame) main at that point fps main at that point CPU prep (ms/frame) main at that point
run 1 115.2 112.3 4.7 5.1 111.6 103.4
run 2 121.5 145.2 4.5 3.9 116.7 114.1
mean difference −10.4 ms +3.7 % +5.4 ms

Main's three runs: 75.5, 184.3 and 125.9 ms on the GPU; 5.8, 3.6 and 4.1 fps.

Memory: ray tracing on fills this card. In the last 100 s of each run, shared memory was 10.3 and 11.0 GB with this PR and 10.6 to 10.8 GB on main, with dedicated memory at 10.5 to 10.7 GB in all of them. With ray tracing off, main's shared memory was 8.5 to 9.0 GB. So on a 12 GB card part of the ray-tracing data probably lives in system memory, which may be why the GPU time moves so much from run to run and why we do not see the gain.

Picture: 0 defects in this PR's three runs (a burst of 80 frames at the end of each, plus a capture at 120 s). The boxes it now misses did not leave holes or missing shadows that we could see.

Setup:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution), frame generation off, ray tracing on;
  • the PR merged locally onto main 41adb551, against 41adb551 itself, each with a preload made with these settings;
  • a warm-up run per build, then two PR runs among three main runs, 150 s each, every run from the same save, restored before each run;
  • medians of the 5 s host lines on the light-view seconds after the first 20 s, each run compared with main's runs interpolated in time.

AI Assisted

**@⁠DoubleD17** on GitHub · 2026-11-30 09:58 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3067#issuecomment-7274940557) We ran a test of this PR with ray tracing on (`VICTORY_BVH_BUILDER=1`), on a 12 GB card, on current main (41adb551 with this PR merged, head 5b3815e9). The log confirmed the switch: "VICTORY_BVH_INVERTED_MISS: ray tests miss boxes whose minimum is above their maximum". **No difference we can measure on this card.** With ray tracing on, the card is the limit here: about 4 to 6 fps, the GPU busy 98 to 100 % of the time, and the host's "on the GPU" time is 75 to 185 ms a frame, against 4 to 8 ms with ray tracing off. Main's own three runs spread that widely, so two PR runs cannot show a change of the size you measured (20.0 → 31.4 fps on an RTX 5090). Light-view seconds only (the idle camera's lighter views, about 7,500 draws a frame): | | on the GPU (ms/frame) | main at that point | fps | main at that point | CPU prep (ms/frame) | main at that point | |---|---|---|---|---|---|---| | run 1 | 115.2 | 112.3 | 4.7 | 5.1 | 111.6 | 103.4 | | run 2 | 121.5 | 145.2 | 4.5 | 3.9 | 116.7 | 114.1 | | **mean difference** | **−10.4 ms** | | **+3.7 %** | | **+5.4 ms** | | Main's three runs: 75.5, 184.3 and 125.9 ms on the GPU; 5.8, 3.6 and 4.1 fps. **Memory:** ray tracing on fills this card. In the last 100 s of each run, shared memory was 10.3 and 11.0 GB with this PR and 10.6 to 10.8 GB on main, with dedicated memory at 10.5 to 10.7 GB in all of them. With ray tracing off, main's shared memory was 8.5 to 9.0 GB. So on a 12 GB card part of the ray-tracing data probably lives in system memory, which may be why the GPU time moves so much from run to run and why we do not see the gain. **Picture:** 0 defects in this PR's three runs (a burst of 80 frames at the end of each, plus a capture at 120 s). The boxes it now misses did not leave holes or missing shadows that we could see. **Setup:** - Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11; - Series X, 1440p with DLAA (DLSS at native resolution), frame generation off, ray tracing on; - the PR merged locally onto main 41adb551, against 41adb551 itself, each with a preload made with these settings; - a warm-up run per build, then two PR runs among three main runs, 150 s each, every run from the same save, restored before each run; - medians of the 5 s host lines on the light-view seconds after the first 20 s, each run compared with main's runs interpolated in time. AI Assisted
Author
Owner

@⁠HQasper on GitHub · 2026-11-30 15:50 UTC · original

Thanks for testing, and for the picture check: 0 defects is the main thing we wanted to know. The gain we measured (20.0 → 31.4 fps) was on a 32 GB RTX 5090 where ray tracing stays in video memory, so on a 12 GB card that spills into shared memory the run-to-run spread can hide it; we're not changing the PR because of this.

**@⁠HQasper** on GitHub · 2026-11-30 15:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3067#issuecomment-7283690310) Thanks for testing, and for the picture check: 0 defects is the main thing we wanted to know. The gain we measured (20.0 → 31.4 fps) was on a 32 GB RTX 5090 where ray tracing stays in video memory, so on a 12 GB card that spills into shared memory the run-to-run spread can hide it; we're not changing the PR because of this.
Author
Owner

@⁠KruIN689 on GitHub · 2026-11-30 20:37 UTC · original

Tested together with #3063 on an RTX 5080 16 GB: numbers and setup in #3063 (latest comment). In the last comparable pair: +39 % fps, 13x fewer frames over 50 ms, no picture defects seen. (Claude Code, for KruIN689.)

**@⁠KruIN689** on GitHub · 2026-11-30 20:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3067#issuecomment-7291215402) Tested together with #3063 on an RTX 5080 16 GB: numbers and setup in https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/3063 (latest comment). In the last comparable pair: +39 % fps, 13x fewer frames over 50 ms, no picture defects seen. (Claude Code, for KruIN689.)
Author
Owner

@⁠upipibi on GitHub · 2026-12-01 04:47 UTC · original

Review of #3067 (head ad12947b): AMD's public reference agrees that inverted boxes are misses, and the emitted code matches the PR's reference on the card. Synthetic tests only: no game files. The fps gain is the in-game reports above, not mine.

AMD's form of the test. AMD's ray-tracing library GPURT (MIT) has a software form of the hardware box test, used where the intrinsic isn't. It is fast_intersect_bbox in src/shaders/IntersectCommon.hlsl#L393-L441, with the traverse rule at #L515-L518.

  • It takes each axis's entry and exit by the sign of the ray's inverse direction, not as the smaller and larger of the two. So a box whose minimum is above its maximum gives an entry after its exit: an empty interval, a miss, in either direction.
  • NaN intervals are made misses too.
  • A hit needs min_t <= max_t * (1 + grow * 2^-24), with grow defaulting to 6 ulps (RayTracingBoxGrowthNumUlpsDefault, gpurt.h:115).

Differential test. I ported that function and its traverse rule to Rust next to boxes_as. Then I compared, for one present child, whether it's entered: 1,000,000 random rays and boxes per row (origin and box corners in ±10, extent 30, seeded xorshift).

case boxes_as without the switch vs GPURT with INVERTED_MISS vs GPURT
ordinary boxes 0 differ 0 differ
inverted on one axis 26,175 differ 0
inverted on all axes, or +inf/-inf 513,020 differ 0
flat on an axis (min = max) 0 0
inverted by only 1-8 ulps 3,889 4,142, all "PR misses, GPURT enters"
ray parallel to an axis, origin on a face 48,828 48,828 (the same either way)

So on the cases this PR is about, it brings the test to exactly what AMD's does. Two smaller differences:

  • A box inverted by a few ulps. GPURT enters it: through the 6-ulp growth, and even with no growth, 899 of them through rounding. The explicit min > max compare misses it. A sign-selected slab like GPURT's would match it as well. The title's +inf/-inf halves and properly ordered boxes aren't affected, so this is minor.
  • Axis-parallel rays starting on a face. These differ with and without the switch, so it isn't this PR's doing. It also depends on how min3/max3 treat NaN, which I assumed to be "the other value".

The emitted code on the card. intersect_tests' scene has only one inverted box, on a child that isn't there, so the new compare in emit/intersect.rs never decides a hit there. I added a node whose present children have a box inverted on x ([31, -1, -1, 29, 1, 1]) and a +inf/-inf box, in both widths:

let mut turned = lined;
turned[0] = [31.0, -1.0, -1.0, 29.0, 1.0, 1.0];
turned[2] = [f32::INFINITY, f32::INFINITY, f32::INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY];
box_nodes.push((s.add(nodes::box32(ids, turned), 32), 5));
box_nodes.push((s.add(nodes::box16(ids, turned), 16), 4));

RTX 3070, driver 621.40, cargo test -p victory-shader --lib -- emit::intersect_tests --test-threads=1:

  • VICTORY_BVH_INVERTED_MISS=1: 12 passed, 0 failed.
  • =0: 12 passed, 0 failed.
  • Negative control, the emitted compare switched off while the reference keeps it (=1): 8 passed, 4 failed, the four node tests at intersect_tests.rs:591.

So those lines make the card tests cover this PR's change, and they might be worth adding. The bvh tests pass, 19 of 19.

Tested with the help of Claude Code (Claude Opus 5.5).

**@⁠upipibi** on GitHub · 2026-12-01 04:47 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3067#issuecomment-7301101919) Review of #3067 (head ad12947b): **AMD's public reference agrees that inverted boxes are misses, and the emitted code matches the PR's reference on the card.** Synthetic tests only: no game files. The fps gain is the in-game reports above, not mine. **AMD's form of the test.** AMD's ray-tracing library GPURT (MIT) has a software form of the hardware box test, used where the intrinsic isn't. It is `fast_intersect_bbox` in [`src/shaders/IntersectCommon.hlsl#L393-L441`](https://github.com/GPUOpen-Drivers/gpurt/blob/7b226d48b46b7e92fec3b9ecc5712e5bf2bf3dd9/src/shaders/IntersectCommon.hlsl#L393-L441), with the traverse rule at [#L515-L518](https://github.com/GPUOpen-Drivers/gpurt/blob/7b226d48b46b7e92fec3b9ecc5712e5bf2bf3dd9/src/shaders/IntersectCommon.hlsl#L515-L518). - It takes each axis's entry and exit by the sign of the ray's inverse direction, not as the smaller and larger of the two. So a box whose minimum is above its maximum gives an entry after its exit: an empty interval, a miss, in either direction. - NaN intervals are made misses too. - A hit needs `min_t <= max_t * (1 + grow * 2^-24)`, with `grow` defaulting to 6 ulps (`RayTracingBoxGrowthNumUlpsDefault`, `gpurt.h:115`). **Differential test.** I ported that function and its traverse rule to Rust next to `boxes_as`. Then I compared, for one present child, whether it's entered: 1,000,000 random rays and boxes per row (origin and box corners in ±10, extent 30, seeded xorshift). | case | `boxes_as` without the switch vs GPURT | with `INVERTED_MISS` vs GPURT | |---|---|---| | ordinary boxes | 0 differ | 0 differ | | inverted on one axis | 26,175 differ | **0** | | inverted on all axes, or +inf/-inf | 513,020 differ | **0** | | flat on an axis (min = max) | 0 | 0 | | inverted by only 1-8 ulps | 3,889 | 4,142, all "PR misses, GPURT enters" | | ray parallel to an axis, origin on a face | 48,828 | 48,828 (the same either way) | So on the cases this PR is about, it brings the test to exactly what AMD's does. Two smaller differences: - **A box inverted by a few ulps.** GPURT enters it: through the 6-ulp growth, and even with no growth, 899 of them through rounding. The explicit `min > max` compare misses it. A sign-selected slab like GPURT's would match it as well. The title's +inf/-inf halves and properly ordered boxes aren't affected, so this is minor. - **Axis-parallel rays starting on a face.** These differ with and without the switch, so it isn't this PR's doing. It also depends on how `min3`/`max3` treat NaN, which I assumed to be "the other value". **The emitted code on the card.** `intersect_tests`' scene has only one inverted box, on a child that isn't there, so the new compare in `emit/intersect.rs` never decides a hit there. I added a node whose present children have a box inverted on x (`[31, -1, -1, 29, 1, 1]`) and a +inf/-inf box, in both widths: ```rust let mut turned = lined; turned[0] = [31.0, -1.0, -1.0, 29.0, 1.0, 1.0]; turned[2] = [f32::INFINITY, f32::INFINITY, f32::INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY]; box_nodes.push((s.add(nodes::box32(ids, turned), 32), 5)); box_nodes.push((s.add(nodes::box16(ids, turned), 16), 4)); ``` RTX 3070, driver 621.40, `cargo test -p victory-shader --lib -- emit::intersect_tests --test-threads=1`: - `VICTORY_BVH_INVERTED_MISS=1`: 12 passed, 0 failed. - `=0`: 12 passed, 0 failed. - Negative control, the emitted compare switched off while the reference keeps it (`=1`): 8 passed, 4 failed, the four node tests at `intersect_tests.rs:591`. So those lines make the card tests cover this PR's change, and they might be worth adding. The `bvh` tests pass, 19 of 19. *Tested with the help of Claude Code (Claude Opus 5.5).*
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA#3067
No description provided.