Recompiler: select vertices for BVH triangle node types 2 and 3 #1959

Manually merged
github merged 1 commit from gh-pr/1959/head into gh-pr/1959/base 2026-11-26 05:11:34 +00:00
Owner

@⁠n-romanovich on GitHub · 2026-11-24 23:52 UTC · original
n-romanovich:recomp/bvh-triangle-types-2-3 → main · +108 −8 · 4 files · 1 commits · merged 2026-11-25 01:21 UTC

Fixes #1917.

GFX10 triangle nodes pack up to four triangles across five vertices:

  • type 0: (v0, v1, v2) at byte offsets (0, 12, 24)
  • type 1: (v1, v3, v2) at byte offsets (12, 36, 24)
  • type 2: (v2, v3, v4) at byte offsets (24, 36, 48)
  • type 3: (v2, v4, v0) at byte offsets (24, 48, 0)

Previously bvh::intersect_node, emit.rs bvh_intersect, and dxil/lower_image.rs bvh_intersect only checked type == 1 and fell back to type 0 (v0, v1, v2) for types 2 and 3.

What is in it

  • crates/xcl/src/gpu/bvh.rs: select (o0, o1, o2) across node types 0..=3 in intersect_node, and add unit test triangle_node_types_0_to_3_select_expected_vertices.
  • crates/xcl/src/gpu/recomp/emit.rs: update bvh_intersect to select vertex offsets for types 0..=3.
  • crates/xcl/src/gpu/dxil/lower_image.rs: update bvh_intersect to select vertex offsets for types 0..=3.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_bvh_triangle_types_2_and_3.

Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti.

  • cargo test -p xcl --lib bvh -- --test-threads=4: 13 passed, 0 failed, 0 ignored (949 filtered out)
  • cargo test --workspace -- --test-threads=4: 986 passed, 0 failed, 45 ignored
    • SKIPPED: 21 gpu::recomp wave64 / refused per-lane f16 tests (no wave64 / refused per-lane f16), shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode is required, 0x887A002D), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)

Regression run
Main (f5136a640a69be3ce072e1ea8939e97d005b4cb1):

xcl-smoke v1
commit: f5136a640a69be3ce072e1ea8939e97d005b4cb1
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17295 MB

PR (f7bd213ca7d5ade6785a4a9aa3be2eb6491f754d):

xcl-smoke v1
commit: f7bd213ca7d5ade6785a4a9aa3be2eb6491f754d
gpu: NVIDIA GeForce RTX 5060 Ti
title: FILES
seconds: 60
exit: 0x0
frames shown: 1476 (PresentX 1476)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14825 MB

Not tested

  • macOS / Linux (crate targets Windows only).
  • AMD / wave64-capable GPU.

AI use

  • Antigravity (model name not provided): implemented the fix and CPU/GPU tests, ran the test suite and smoke.ps1 runs.
**@⁠n-romanovich** on GitHub · 2026-11-24 23:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959) `n-romanovich:recomp/bvh-triangle-types-2-3` → `main` · +108 −8 · 4 files · 1 commits · merged 2026-11-25 01:21 UTC Fixes #1917. GFX10 triangle nodes pack up to four triangles across five vertices: - type `0`: `(v0, v1, v2)` at byte offsets `(0, 12, 24)` - type `1`: `(v1, v3, v2)` at byte offsets `(12, 36, 24)` - type `2`: `(v2, v3, v4)` at byte offsets `(24, 36, 48)` - type `3`: `(v2, v4, v0)` at byte offsets `(24, 48, 0)` Previously `bvh::intersect_node`, `emit.rs` `bvh_intersect`, and `dxil/lower_image.rs` `bvh_intersect` only checked `type == 1` and fell back to type `0` (`v0, v1, v2`) for types `2` and `3`. **What is in it** - `crates/xcl/src/gpu/bvh.rs`: select `(o0, o1, o2)` across node types `0..=3` in `intersect_node`, and add unit test `triangle_node_types_0_to_3_select_expected_vertices`. - `crates/xcl/src/gpu/recomp/emit.rs`: update `bvh_intersect` to select vertex offsets for types `0..=3`. - `crates/xcl/src/gpu/dxil/lower_image.rs`: update `bvh_intersect` to select vertex offsets for types `0..=3`. - `crates/xcl/src/gpu/recomp/tests.rs`: add GPU test `gpu_bvh_triangle_types_2_and_3`. **Tested** Hardware: Windows 11 x64, NVIDIA GeForce RTX 5060 Ti. - `cargo test -p xcl --lib bvh -- --test-threads=4`: 13 passed, 0 failed, 0 ignored (`949 filtered out`) - `cargo test --workspace -- --test-threads=4`: 986 passed, 0 failed, 45 ignored - `SKIPPED`: 21 `gpu::recomp` wave64 / refused per-lane f16 tests (`no wave64` / refused per-lane f16), `shaders::tests::pso_measurement_compiles_an_exact_synthetic_record` (`Windows Developer Mode is required`, `0x887A002D`), `heap_window_out_of_memory_falls_back_to_the_switch_form` (`no heap windows`) **Regression run** Main (`f5136a640a69be3ce072e1ea8939e97d005b4cb1`): ``` xcl-smoke v1 commit: f5136a640a69be3ce072e1ea8939e97d005b4cb1 gpu: NVIDIA GeForce RTX 5060 Ti title: FILES seconds: 60 exit: 0x0 frames shown: 1503 (PresentX 1503) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17295 MB ``` PR (`f7bd213ca7d5ade6785a4a9aa3be2eb6491f754d`): ``` xcl-smoke v1 commit: f7bd213ca7d5ade6785a4a9aa3be2eb6491f754d gpu: NVIDIA GeForce RTX 5060 Ti title: FILES seconds: 60 exit: 0x0 frames shown: 1476 (PresentX 1476) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14825 MB ``` **Not tested** - macOS / Linux (crate targets Windows only). - AMD / wave64-capable GPU. **AI use** - Antigravity (model name not provided): implemented the fix and CPU/GPU tests, ran the test suite and `smoke.ps1` runs.
Fixes #1917.

GFX10 triangle nodes pack up to four triangles across five vertices:
type 0=(v0,v1,v2), type 1=(v1,v3,v2), type 2=(v2,v3,v4), type 3=(v2,v4,v0).
bvh::intersect_node, emit.rs bvh_intersect, and dxil/lower_image.rs
bvh_intersect previously handled only type 1 and fell back to type 0
for types 2 and 3.

Update all three paths to select the hardware vertices for types 0..3
and add CPU + GPU unit tests covering types 2 and 3.

Tested: cargo test --workspace -- --test-threads=4.

Assisted-by: Antigravity (model name not provided)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:32 +00:00
github manually merged commit f7bd213ca7 into gh-pr/1959/base 2026-11-26 05:11:34 +00:00
Author
Owner

@⁠Anon64 on GitHub · 2026-11-24 23:57 UTC · original

Independent check of this PR's head f7bd213 on NVIDIA, with tests written separately from yours (I had the same fix locally before I saw this PR, so I ran my tests against your code instead of opening a second one).

The tests (local only, not pushed):

  • One node with five distinct vertices in z = 5, laid out so that the four triangles of types 0..=3 are all different.
  • Per type, a ray down +z through that triangle's centroid must hit at t = 5.
  • Per type, a ray through a point of another triangle only must miss. For types 1–3 that point is in triangle 0, which is what the old code tested.
  • each_triangle_type_tests_its_own_vertices in bvh::tests checks the CPU mirror.
  • gpu_each_triangle_type_tests_its_own_vertices runs one IMAGE_BVH_INTERSECT_RAY over those 8 rays on the GPU. It checks hit / miss and t against the expected values and against bvh::intersect_node.

Results:

main 20cf130 (without the fix) this PR f7bd213
CPU test fails: type 2: the ray through its centroid hits … [inf, 1.0, 0.0, 0.0] passes
GPU, HLSL path fails at lane 4 (type 2) passes
GPU, XCL_DIRECT_DXIL=1 (your lower_image.rs change) fails at lane 4 (type 2) passes

On this PR's head, your triangle_node_types_0_to_3_select_expected_vertices and gpu_bvh_triangle_types_2_and_3 and the existing BVH tests (gpu_bvh_intersect_ray, gpu_triangle_pair_and_box16_nodes, gpu_built_bvh_nodes_match_the_cpu_node_test, gpu_bvh64_intersect_ray_across_memory_windows_and_grazing) pass on both paths: 8 passed, 0 failed each.

Tested: RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, DXC 1.8.2502.11, cargo test -p xcl --release --lib -- each_triangle_type triangle_node_types gpu_triangle_pair gpu_built_bvh gpu_bvh.

Not tested: the whole suite; AMD hardware, so not against a real RDNA2 image_bvh_intersect_ray; a title that packs more than two triangles in a node.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

**@⁠Anon64** on GitHub · 2026-11-24 23:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7147972164) Independent check of this PR's head `f7bd213` on NVIDIA, with tests written separately from yours (I had the same fix locally before I saw this PR, so I ran my tests against your code instead of opening a second one). **The tests (local only, not pushed):** - One node with five distinct vertices in z = 5, laid out so that the four triangles of types 0..=3 are all different. - Per type, a ray down +z through that triangle's centroid must hit at t = 5. - Per type, a ray through a point of another triangle only must miss. For types 1–3 that point is in triangle 0, which is what the old code tested. - `each_triangle_type_tests_its_own_vertices` in `bvh::tests` checks the CPU mirror. - `gpu_each_triangle_type_tests_its_own_vertices` runs one `IMAGE_BVH_INTERSECT_RAY` over those 8 rays on the GPU. It checks hit / miss and t against the expected values and against `bvh::intersect_node`. **Results:** | | `main` `20cf130` (without the fix) | this PR `f7bd213` | |---|---|---| | CPU test | fails: `type 2: the ray through its centroid hits … [inf, 1.0, 0.0, 0.0]` | passes | | GPU, HLSL path | fails at lane 4 (type 2) | passes | | GPU, `XCL_DIRECT_DXIL=1` (your `lower_image.rs` change) | fails at lane 4 (type 2) | passes | On this PR's head, your `triangle_node_types_0_to_3_select_expected_vertices` and `gpu_bvh_triangle_types_2_and_3` and the existing BVH tests (`gpu_bvh_intersect_ray`, `gpu_triangle_pair_and_box16_nodes`, `gpu_built_bvh_nodes_match_the_cpu_node_test`, `gpu_bvh64_intersect_ray_across_memory_windows_and_grazing`) pass on both paths: 8 passed, 0 failed each. **Tested:** RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, DXC 1.8.2502.11, `cargo test -p xcl --release --lib -- each_triangle_type triangle_node_types gpu_triangle_pair gpu_built_bvh gpu_bvh`. **Not tested:** the whole suite; AMD hardware, so not against a real RDNA2 `image_bvh_intersect_ray`; a title that packs more than two triangles in a node. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 00:11 UTC · original

AMD run with native 64-lane waves, which this PR lists as not tested (the other report here is NVIDIA).

Tested: pass, head f7bd213 applied on main 80f4819, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 464 passed, 2 failed, 21 ignored. gpu_bvh_triangle_types_2_and_3 and triangle_node_types_0_to_3_select_expected_vertices ok. The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3, which fail the same way on main 80f4819 without this PR on this card (seeds 722 and 1599), so they are not from this change.
  • NVIDIA RTX 3060, driver 32.0.16.1088: 466 passed, 0 failed, 21 ignored. Both new tests ok.

Not tested: Linux; the whole workspace suite; a title.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 00:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7148249781) AMD run with native 64-lane waves, which this PR lists as not tested (the other report here is NVIDIA). **Tested:** pass, head `f7bd213` applied on `main` `80f4819`, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17. `cargo test -p xcl --lib -- gpu:: --test-threads=4`: - AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, waves 32..64: 464 passed, 2 failed, 21 ignored. `gpu_bvh_triangle_types_2_and_3` and `triangle_node_types_0_to_3_select_expected_vertices` ok. The 2 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` and `_3`, which fail the same way on `main` `80f4819` without this PR on this card (seeds 722 and 1599), so they are not from this change. - NVIDIA RTX 3060, driver 32.0.16.1088: 466 passed, 0 failed, 21 ignored. Both new tests ok. **Not tested:** Linux; the whole workspace suite; a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:29 UTC · original

The vertex selection matches hardware. boykopovar/AnyPS5#24128 measured image_bvh_intersect_ray on gfx1036 through their hardware oracle. Type 2 is (v2, v3, v4) and type 3 is (v2, v4, v0), with v4 at dwords 12–14 and the id at dword 15, which is what this PR uses at (24, 36, 48) and (24, 48, 0).

RTX 3070 (Ampere, driver 616.56, Windows 11, debug) at f7bd213: the dxil::/bvh:: units (122 passed) and the gpu_ tests with XCL_DIRECT_DXIL=0 and 1 (111 passed each, including the new one) all pass.

The same measurement found two more triangle-node rules that XCL doesn't follow yet. Both are outside this PR's scope; listing them in case someone wants a follow-up:

  • Miss in barycentric mode: hardware returns t = ±inf with the sign of the denominator, the real denominator, and the barycentric numerators computed from it. bvh_intersect (HLSL and bvh::intersect_node) returns (+inf, 1.0, 0, 0).
  • Triangle-id return mode (T# dword 3 bit 24): hardware returns (t, denominator, id + type, …), and on a miss (+inf, 1.0, id + type, 0), wrapping at 2^32. XCL always returns barycentrics.

Not measured there: a zero or NaN denominator. Their hits are f32 Möller–Trumbore, a few ULP from the hardware's, as XCL's are.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-25 00:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7148567753) The vertex selection matches hardware. boykopovar/AnyPS5#24128 measured `image_bvh_intersect_ray` on gfx1036 through their hardware oracle. Type 2 is (v2, v3, v4) and type 3 is (v2, v4, v0), with v4 at dwords 12–14 and the id at dword 15, which is what this PR uses at (24, 36, 48) and (24, 48, 0). RTX 3070 (Ampere, driver 616.56, Windows 11, debug) at `f7bd213`: the `dxil::`/`bvh::` units (122 passed) and the `gpu_` tests with `XCL_DIRECT_DXIL=0` and `1` (111 passed each, including the new one) all pass. The same measurement found two more triangle-node rules that XCL doesn't follow yet. Both are outside this PR's scope; listing them in case someone wants a follow-up: - **Miss in barycentric mode:** hardware returns t = ±inf with the sign of the denominator, the real denominator, and the barycentric numerators computed from it. `bvh_intersect` (HLSL and `bvh::intersect_node`) returns `(+inf, 1.0, 0, 0)`. - **Triangle-id return mode** (T# dword 3 bit 24): hardware returns `(t, denominator, id + type, …)`, and on a miss `(+inf, 1.0, id + type, 0)`, wrapping at 2^32. XCL always returns barycentrics. Not measured there: a zero or NaN denominator. Their hits are f32 Möller–Trumbore, a few ULP from the hardware's, as XCL's are. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 00:39 UTC · original · edited 2026-11-25 00:51 UTC

Intel Arc A770 test report at f7bd213ca7d5ade6785a4a9aa3be2eb6491f754d

Tested on Intel Arc A770 driver 32.0.101.9175, Ryzen 7 3800X, Windows 11 Enterprise Evaluation 26200.9974, Rust 1.100.0 MSVC debug, DXC/DXIL 1.9.2609.5. The clean test head still matched GitHub after the runs. With XCL_ADAPTER=A770, XCL_REQUIRE_GPU=wave64 and XCL_PER_LANE=0, ran cargo test -p xcl --lib gpu_bvh_triangle_types_2_and_3 -- --nocapture --test-threads=1 twice.

Backend Result
XCL_DIRECT_DXIL=0 (HLSL + DXC) 1 passed, 0 failed, 0 ignored, 0 skipped. 2.65 s.
XCL_DIRECT_DXIL=1 (direct DXIL) 1 passed, 0 failed, 0 ignored, 0 skipped. 1.04 s.

The test executed on both backends. The elapsed times are single test runs rather than a performance comparison. Stale build-script artifacts prevented the initial launch. Refreshing Cargo's input timestamps fixed the build without source edits.

Not tested the PR base, CPU mirror test, full suite, retail smoke or native AMD behavior.

AI use Codex in T3 Code (gpt-6.2-sol) ran the tests and prepared the report. The coordinator verified both logs and the PR head.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 00:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7148744997) · edited 2026-11-25 00:51 UTC **Intel Arc A770 test report at `f7bd213ca7d5ade6785a4a9aa3be2eb6491f754d`** **Tested** on Intel Arc A770 driver `32.0.101.9175`, Ryzen 7 3800X, Windows 11 Enterprise Evaluation `26200.9974`, Rust `1.100.0` MSVC debug, DXC/DXIL `1.9.2609.5`. The clean test head still matched GitHub after the runs. With `XCL_ADAPTER=A770`, `XCL_REQUIRE_GPU=wave64` and `XCL_PER_LANE=0`, ran `cargo test -p xcl --lib gpu_bvh_triangle_types_2_and_3 -- --nocapture --test-threads=1` twice. | Backend | Result | |---|---| | `XCL_DIRECT_DXIL=0` (HLSL + DXC) | 1 passed, 0 failed, 0 ignored, 0 skipped. 2.65 s. | | `XCL_DIRECT_DXIL=1` (direct DXIL) | 1 passed, 0 failed, 0 ignored, 0 skipped. 1.04 s. | The test executed on both backends. The elapsed times are single test runs rather than a performance comparison. Stale build-script artifacts prevented the initial launch. Refreshing Cargo's input timestamps fixed the build without source edits. **Not tested** the PR base, CPU mirror test, full suite, retail smoke or native AMD behavior. **AI use** Codex in T3 Code (`gpt-6.2-sol`) ran the tests and prepared the report. The coordinator verified both logs and the PR head.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 01:08 UTC · original

Vertex selection across bvh.rs, emit.rs, and lower_image.rs ((0, 12, 24), (12, 36, 24), (24, 36, 48), (24, 48, 0)), Build and test + PR description, and AMD + NVIDIA + Intel verification all pass on f7bd213.

Remaining before merge: please let us know if you plan to address @⁠maritzaloas96-ship-it's two minor test nits (dropping the redundant assert!(hit2[1] != 1.0 || ...) check in bvh.rs and adding a type-3 outside miss ray in gpu_bvh_triangle_types_2_and_3), or if this head is final.

**@⁠raylitebull** on GitHub · 2026-11-25 01:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7149247605) Vertex selection across `bvh.rs`, `emit.rs`, and `lower_image.rs` (`(0, 12, 24)`, `(12, 36, 24)`, `(24, 36, 48)`, `(24, 48, 0)`), `Build and test` + `PR description`, and AMD + NVIDIA + Intel verification all pass on `f7bd213`. **Remaining before merge:** please let us know if you plan to address @⁠maritzaloas96-ship-it's two minor test nits (dropping the redundant `assert!(hit2[1] != 1.0 || ...)` check in `bvh.rs` and adding a type-3 outside miss ray in `gpu_bvh_triangle_types_2_and_3`), or if this head is final.
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-25 01:12 UTC · original

@⁠raylitebull, this head (f7bd213) is final — both points are minor test-only nits, and all code and hardware checks are already green on it. Happy to leave it as-is for merge.

**@⁠n-romanovich** on GitHub · 2026-11-25 01:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7149308719) @⁠raylitebull, this head (`f7bd213`) is final — both points are minor test-only nits, and all code and hardware checks are already green on it. Happy to leave it as-is for merge.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:59 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 02:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1959#issuecomment-7151473766) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.