Recompiler: add BVH box-grow ULP, ray NaN/Inf inactivation, and triangle mode 0 #3288

Merged
Foniass merged 1 commit from upstream-pr/3288 into main 2026-11-29 12:20:55 +00:00
Foniass commented 2026-11-29 05:37:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T05:37:25Z.


The emulated ray intersection (image_bvh_intersect_ray / image_bvh64_intersect_ray, direct DXIL and HLSL) now follows RDNA2 in three places where it did not:

  • Box grow: the BVH descriptor's box-grow field (word 1 [30:23]) expands every child box by that many ULPs before the slab test, so rays that graze a box edge hit it as on the console.
  • NaN / Inf rays: a NaN in the origin, direction, inverse direction or tmax, or an Inf in the origin, inactivates the ray (a clean miss) instead of producing garbage hits.
  • Triangle return mode 0: descriptor word 3 bit 24 selects the triangle result layout. Mode 1 (barycentrics) was the only one implemented; mode 0 returns (t numerator, denominator, triangle id + type, hit status). XCL's own BVH descriptors (desc::bvh_words) now set mode 1 explicitly, so what they produce does not change.

What is in it

  • crates/xcl/src/gpu/dxil/lower_image.rs, crates/xcl/src/gpu/recomp/emit.rs: the three behaviours in both translators
  • crates/xcl/src/gpu/desc.rs: bvh_words word 3 = 1 << 24 (mode 1, as before by default); its view test and the test title's raytracing_surface expectation updated to match
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_bvh_box_grow_nan_inactivation_and_tri_mode0

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on a173b472: 2605 passed, 4 failed, 49 ignored. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3: E_OUTOFMEMORY from CreateComputePipelineState at seeds 70 / 545 / 1019 / 1507, the same as on main on this machine (they pass on another RTX 5070 Ti). SKIPPED GPU tests: 44 notices, almost all no wave64.
  • Retail title: 60 s smoke run below (it uses ray tracing; the shader caches were rebuilt cold for this head).

Regression run

main:

xcl-smoke v1
commit: b10cc4c6766adc947c2054ada4a2af98be15108d
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1565 (PresentX 1565)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16026 MB

this PR:

xcl-smoke v1
commit: a173b472930ab5b109eb8dff9f1c5a21563363a6
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1656 (PresentX 1656)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18067 MB

Not tested

  • AMD GPUs; the three behaviours come from the amd-dev commit, I did not check them against the RDNA2 ISA documentation or console hardware (the new GPU test checks the implementation against its own expected values)
  • whether the retail title's ray-traced passes look different (frames only)

AI use

  • Claude Code with Claude Opus 5.5: ported the commit to main with the matching test updates from a later amd-dev commit, ran the tests and the smoke run, wrote this description.
  • Original code: amd-dev f9fd4bfb (raylitebull), test updates from a46703b6.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5547956819 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3288). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T05:37:25Z. --- The emulated ray intersection (`image_bvh_intersect_ray` / `image_bvh64_intersect_ray`, direct DXIL and HLSL) now follows RDNA2 in three places where it did not: - **Box grow:** the BVH descriptor's box-grow field (word 1 [30:23]) expands every child box by that many ULPs before the slab test, so rays that graze a box edge hit it as on the console. - **NaN / Inf rays:** a NaN in the origin, direction, inverse direction or tmax, or an Inf in the origin, inactivates the ray (a clean miss) instead of producing garbage hits. - **Triangle return mode 0:** descriptor word 3 bit 24 selects the triangle result layout. Mode 1 (barycentrics) was the only one implemented; mode 0 returns (t numerator, denominator, triangle id + type, hit status). XCL's own BVH descriptors (`desc::bvh_words`) now set mode 1 explicitly, so what they produce does not change. **What is in it** - `crates/xcl/src/gpu/dxil/lower_image.rs`, `crates/xcl/src/gpu/recomp/emit.rs`: the three behaviours in both translators - `crates/xcl/src/gpu/desc.rs`: `bvh_words` word 3 = `1 << 24` (mode 1, as before by default); its view test and the test title's `raytracing_surface` expectation updated to match - `crates/xcl/src/gpu/recomp/tests.rs`: `gpu_bvh_box_grow_nan_inactivation_and_tri_mode0` **Tested** - NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke - `cargo test --workspace --no-fail-fast -- --test-threads=4` on a173b472: 2605 passed, 4 failed, 49 ignored. The 4 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3`: `E_OUTOFMEMORY` from `CreateComputePipelineState` at seeds 70 / 545 / 1019 / 1507, the same as on main on this machine (they pass on another RTX 5070 Ti). SKIPPED GPU tests: 44 notices, almost all `no wave64`. - Retail title: 60 s smoke run below (it uses ray tracing; the shader caches were rebuilt cold for this head). **Regression run** main: ``` xcl-smoke v1 commit: b10cc4c6766adc947c2054ada4a2af98be15108d gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1565 (PresentX 1565) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16026 MB ``` this PR: ``` xcl-smoke v1 commit: a173b472930ab5b109eb8dff9f1c5a21563363a6 gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1656 (PresentX 1656) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 18067 MB ``` **Not tested** - AMD GPUs; the three behaviours come from the amd-dev commit, I did not check them against the RDNA2 ISA documentation or console hardware (the new GPU test checks the implementation against its own expected values) - whether the retail title's ray-traced passes look different (frames only) **AI use** - Claude Code with Claude Opus 5.5: ported the commit to main with the matching test updates from a later amd-dev commit, ran the tests and the smoke run, wrote this description. - Original code: amd-dev `f9fd4bfb` (raylitebull), test updates from `a46703b6`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
andrewDoing commented 2026-11-29 05:54:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T05:54:28Z.


Two finite ray/box cases distinguish this PR's world-coordinate growth from AMD GPURT's published software intersection reference. On a173b472 both XCL translators agreed with each other, but they differed from that reference in both directions at grow=4.

AMD's RDNA2 ISA guide defines the unsigned box-growth field at bits 62:55 and the triangle return layout at bit 120 (tables 49–50). It does not specify the growth calculation in that table. AMD's software implementation projects the unexpanded slabs, then compares the near distance to the far distance multiplied by 1 + grow * 2^-24. The PR instead steps each world-space box minimum/maximum outward before projection. RDNA2 ISA guide · GPURT projected intervals · GPURT growth comparison

I dispatched an encoded IMAGE_BVH_INTERSECT_RAY on RTX 5070 (616.92) through HLSL→DXIL and direct DXIL, with one valid Box32 child. All direction and inverse-direction components were +1, tmax=65536. Four cases repeated across 64 lanes and two fresh processes. Each table entry gives the grow=0 / grow=4 result.

Input CPU, GPURT projected calculation XCL, both GPU backends
Origin (0,0,0), box (2,0,0)–(4,1.875,4) miss / miss miss / miss
Translate both preceding origin and box by +1,048,576 on X miss / miss miss / hit
Origin (−32768,−32768,−32768), box (1.00390625,0,−1)–(2,1,2) miss / hit miss / miss
Same far origin, box (1,0,−1)–(2,1.25,2) hit / hit hit / hit

The translated pair has the same exactly representable projected interval (near 2, far 1.875). The third case crosses the reference's post-projection tolerance. A child hit here means traversal would visit the child; it does not establish a final triangle hit. These cases could distinguish the conventions on an actual RDNA2 GPU before settling the expected regression values. This was software BVH execution on NVIDIA, without hardware DXR RayQuery, a console trace, or retail image measurements.

AI-assisted fixture and verification.

<!-- greyfinch-sync:ivall/xcl:comment:7251529748 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3288#issuecomment-7251529748). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T05:54:28Z. --- Two finite ray/box cases distinguish this PR's world-coordinate growth from AMD GPURT's published software intersection reference. On `a173b472` both XCL translators agreed with each other, but they differed from that reference in **both directions** at grow=4. AMD's RDNA2 ISA guide defines the unsigned box-growth field at bits 62:55 and the triangle return layout at bit 120 (tables 49–50). It does not specify the growth calculation in that table. AMD's software implementation projects the unexpanded slabs, then compares the near distance to the far distance multiplied by `1 + grow * 2^-24`. The PR instead steps each world-space box minimum/maximum outward before projection. [RDNA2 ISA guide](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [GPURT projected intervals](https://github.com/GPUOpen-Drivers/gpurt/blob/7b226d48b46b7e92fec3b9ecc5712e5bf2bf3dd9/src/shaders/IntersectCommon.hlsl#L393-L423) · [GPURT growth comparison](https://github.com/GPUOpen-Drivers/gpurt/blob/7b226d48b46b7e92fec3b9ecc5712e5bf2bf3dd9/src/shaders/IntersectCommon.hlsl#L511-L518) I dispatched an encoded `IMAGE_BVH_INTERSECT_RAY` on RTX 5070 (616.92) through HLSL→DXIL and direct DXIL, with one valid Box32 child. All direction and inverse-direction components were +1, tmax=65536. Four cases repeated across 64 lanes and two fresh processes. Each table entry gives the grow=0 / grow=4 result. | Input | CPU, GPURT projected calculation | XCL, both GPU backends | |---|---|---| | Origin (0,0,0), box (2,0,0)–(4,1.875,4) | miss / miss | miss / miss | | Translate both preceding origin and box by +1,048,576 on X | miss / miss | **miss / hit** | | Origin (−32768,−32768,−32768), box (1.00390625,0,−1)–(2,1,2) | **miss / hit** | miss / miss | | Same far origin, box (1,0,−1)–(2,1.25,2) | hit / hit | hit / hit | The translated pair has the same exactly representable projected interval (near 2, far 1.875). The third case crosses the reference's post-projection tolerance. A child hit here means traversal would visit the child; it does not establish a final triangle hit. These cases could distinguish the conventions on an actual RDNA2 GPU before settling the expected regression values. This was software BVH execution on NVIDIA, without hardware DXR RayQuery, a console trace, or retail image measurements. AI-assisted fixture and verification.
Kalmarv commented 2026-11-29 07:54:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T07:54:00Z.


merge-check
base: fa204595
head: a173b472
verdict: safe to merge

Merged cleanly onto origin/main (fa204595) in a 5-PR batch (#3288, #3290, #3292, #3294, #3300) and verified on NVIDIA GeForce RTX 5070 Ti with DXC 1.9.2609.5:

  • Targeted BVH GPU tests (gpu_bvh_box_grow_nan_inactivation_and_tri_mode0, gpu_bvh64_intersect_ray_across_memory_windows_and_grazing, gpu_bvh_intersect_ray, gpu_bvh_triangle_types_2_and_3, gpu_bvh_node_in_an_unmapped_window_returns_a_miss, gpu_built_bvh_nodes_match_the_cpu_node_test): all passed on RTX 5070 Ti.
  • gpu::: 853 passed, 0 failed, 24 ignored (10.45 s, including fuzz_validate_and_gpu_0..3).
  • hle::d3d12x:: (--test-threads=1, skipping 2 known main #3187 uma_driver mixed-window tests): 1144 passed, 0 failed, 3 ignored (30.21 s).
  • Remaining xcl --lib (--test-threads=1): 0 failed.
  • -p xcl --test e2e (after rebuilding xcl-testtitle): 5 passed, 0 failed (including D3D12 debug layer + DRED).
  • GitHub CI (Build and test (Windows, no GPU) and PR description): green.
<!-- greyfinch-sync:ivall/xcl:comment:7252759594 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3288#issuecomment-7252759594). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T07:54:00Z. --- merge-check base: fa204595 head: a173b472 verdict: safe to merge Merged cleanly onto `origin/main` (`fa204595`) in a 5-PR batch (`#3288`, `#3290`, `#3292`, `#3294`, `#3300`) and verified on NVIDIA GeForce RTX 5070 Ti with DXC 1.9.2609.5: - Targeted BVH GPU tests (`gpu_bvh_box_grow_nan_inactivation_and_tri_mode0`, `gpu_bvh64_intersect_ray_across_memory_windows_and_grazing`, `gpu_bvh_intersect_ray`, `gpu_bvh_triangle_types_2_and_3`, `gpu_bvh_node_in_an_unmapped_window_returns_a_miss`, `gpu_built_bvh_nodes_match_the_cpu_node_test`): all passed on RTX 5070 Ti. - `gpu::`: 853 passed, 0 failed, 24 ignored (10.45 s, including `fuzz_validate_and_gpu_0..3`). - `hle::d3d12x::` (`--test-threads=1`, skipping 2 known `main` `#3187` `uma_driver` mixed-window tests): 1144 passed, 0 failed, 3 ignored (30.21 s). - Remaining `xcl --lib` (`--test-threads=1`): 0 failed. - `-p xcl --test e2e` (after rebuilding `xcl-testtitle`): 5 passed, 0 failed (including D3D12 debug layer + DRED). - GitHub CI (`Build and test (Windows, no GPU)` and `PR description`): green.
throny commented 2026-11-29 09:01:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:01:36Z.


merge-check claim
head: a173b47293

<!-- greyfinch-sync:ivall/xcl:comment:7253485933 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3288#issuecomment-7253485933). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:01:36Z. --- merge-check claim head: a173b472930ab5b109eb8dff9f1c5a21563363a6
throny commented 2026-11-29 09:20:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:20:40Z.


merge-check
base: d8bd9a38
head: a173b47293
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2619 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at d8bd9a38: 2618 passed, 0 failed, 49 ignored. The new GPU test ran on this card.
review: no correctness finding in the code. Box growth by descriptor ULPs, rays with NaN or infinity made inactive, and the triangle return mode without barycentrics are implemented the same way in both translators; XCL's own descriptors set the bit that keeps barycentrics, and the test title follows the new descriptor word. What I cannot confirm from the code is the console behaviour it models: that 16-bit boxes grow in f32 ULPs after conversion, and what the id word holds in the mode without barycentrics. The description should say where those two come from.
performance: not measured.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

<!-- greyfinch-sync:ivall/xcl:comment:7253699693 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3288#issuecomment-7253699693). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:20:40Z. --- merge-check base: d8bd9a38 head: a173b472930ab5b109eb8dff9f1c5a21563363a6 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2619 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at d8bd9a38: 2618 passed, 0 failed, 49 ignored. The new GPU test ran on this card. review: no correctness finding in the code. Box growth by descriptor ULPs, rays with NaN or infinity made inactive, and the triangle return mode without barycentrics are implemented the same way in both translators; XCL's own descriptors set the bit that keeps barycentrics, and the test title follows the new descriptor word. What I cannot confirm from the code is the console behaviour it models: that 16-bit boxes grow in f32 ULPs after conversion, and what the id word holds in the mode without barycentrics. The description should say where those two come from. performance: not measured. verdict: safe to merge hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
xcl-dev/xcl!3288
No description provided.