Shaders: dispatch BVH box/triangle/box16 ALU by node type and hoist ray sign check #2206

Closed
github-bot wants to merge 1 commit from gh-pr/2206/head into gh-pr/2206/base
Owner

@⁠RVZO6 on GitHub · 2026-11-25 07:59 UTC · original
RVZO6:rvzo/bvh-dispatch → main · +876 −43 · 2 files · 1 commits · closed without merging

bvh_lanes in crates/victory-shader/src/emit/lower/bvh.rs currently evaluates box, triangle, and instance/procedural intersection ALU unconditionally for every lane and then selects among the results. Inside bvh_box, it also unpacks all 24 fp16 coordinates via dx.op.legacyF16ToF32 even for box32 nodes and repeats the ray.inv >= 0 sign check 12 times across the four child boxes.

Claimed on #1633 (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155420630).

The change

  • crates/victory-shader/src/emit/lower/bvh.rs:
    • Keep all node_dwords / Lower::memory loads in the entry block before branching (so no memory/page-table load moves into a new divergent branch — safe on WARP and all GPUs).
    • Branch pure intersection ALU in bvh_lanes by node type (box vs triangle vs other) and merge the four i32 result words via phis so coherent waves skip unused intersection paths.
    • Inside bvh_box, guard the 24 legacyF16ToF32 unpacks behind an is16 branch against the box32 f32 bitcasts (joining via 24 f32 phis) and hoist the 3-axis ray.inv >= 0 sign check once across all four child boxes without altering FP evaluation order.
  • crates/victory-shader/src/emit/bvh_tests.rs:
    • Add zero-GPU DXIL bitcode CFG + dxil.dll validation test bvh_dispatch_branches_by_node_type_and_guards_box16 verifying node-type dispatch, is16 gating, hoisted ray sign check, and WARP-safe load placement (including guarded BVH lowering).
    • Add GPU/WARP execution test coherent_and_mixed_node_types_on_the_gpu_equal_the_reference checking both coherent and mixed-lane waves against the software reference.

Not a duplicate of

No open PR or CLAIMS.md entry branches bvh_lanes by node type, guards box16 fp16 unpacking, or hoists the ray sign check in crates/victory-shader/src/emit/lower/bvh.rs.

Tested

  • Fork windows-latest MSVC + Windows WARP SM 6.6 CI run 45570823602 (Clippy clean, Clippy, diagnostics build clean, Tests: 731 passed; 0 failed; 10 ignored, victory-shader: 262 passed; 0 failed; 3 ignored, xtask: 6 passed; 0 failed):
    • emit::bvh_tests::bvh_dispatch_branches_by_node_type_and_guards_box16 ... ok
    • emit::bvh_tests::coherent_and_mixed_node_types_on_the_gpu_equal_the_reference ... ok (executed on Windows WARP SM 6.6)
    • All 16 emit::bvh_tests:: tests passed.

Not run: the title; any hardware GPU. The title was not used in these tests.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 07:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2206) `RVZO6:rvzo/bvh-dispatch` → `main` · +876 −43 · 2 files · 1 commits · closed without merging `bvh_lanes` in `crates/victory-shader/src/emit/lower/bvh.rs` currently evaluates box, triangle, and instance/procedural intersection ALU unconditionally for every lane and then selects among the results. Inside `bvh_box`, it also unpacks all 24 fp16 coordinates via `dx.op.legacyF16ToF32` even for box32 nodes and repeats the `ray.inv >= 0` sign check 12 times across the four child boxes. Claimed on #1633 (`https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7155420630`). ## The change - `crates/victory-shader/src/emit/lower/bvh.rs`: - Keep all `node_dwords` / `Lower::memory` loads in the entry block before branching (so no memory/page-table load moves into a new divergent branch — safe on WARP and all GPUs). - Branch pure intersection ALU in `bvh_lanes` by node type (`box` vs `triangle` vs `other`) and merge the four `i32` result words via phis so coherent waves skip unused intersection paths. - Inside `bvh_box`, guard the 24 `legacyF16ToF32` unpacks behind an `is16` branch against the box32 `f32` bitcasts (joining via 24 `f32` phis) and hoist the 3-axis `ray.inv >= 0` sign check once across all four child boxes without altering FP evaluation order. - `crates/victory-shader/src/emit/bvh_tests.rs`: - Add zero-GPU DXIL bitcode CFG + `dxil.dll` validation test `bvh_dispatch_branches_by_node_type_and_guards_box16` verifying node-type dispatch, `is16` gating, hoisted ray sign check, and WARP-safe load placement (including guarded BVH lowering). - Add GPU/WARP execution test `coherent_and_mixed_node_types_on_the_gpu_equal_the_reference` checking both coherent and mixed-lane waves against the software reference. ## Not a duplicate of No open PR or `CLAIMS.md` entry branches `bvh_lanes` by node type, guards `box16` fp16 unpacking, or hoists the ray sign check in `crates/victory-shader/src/emit/lower/bvh.rs`. ## Tested - Fork `windows-latest` MSVC + Windows WARP SM 6.6 CI run [`45570823602`](https://github.com/RVZO6/VIctory/actions/runs/45570823602) (`Clippy` clean, `Clippy, diagnostics build` clean, `Tests`: **`731 passed; 0 failed; 10 ignored`**, `victory-shader`: **`262 passed; 0 failed; 3 ignored`**, `xtask`: **`6 passed; 0 failed`**): - `emit::bvh_tests::bvh_dispatch_branches_by_node_type_and_guards_box16 ... ok` - `emit::bvh_tests::coherent_and_mixed_node_types_on_the_gpu_equal_the_reference ... ok` (executed on Windows WARP SM 6.6) - All 16 `emit::bvh_tests::` tests passed. **Not run:** the title; any hardware GPU. The title was not used in these tests. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Branch pure BVH intersection ALU in bvh_lanes by node type (box vs triangle vs instance/procedural) after all node_dwords loads complete, merging the four i32 results with phis so coherent waves skip unused paths without moving Lower::memory into new divergent branches.

Inside bvh_box, guard the 24 legacyF16ToF32 unpacks behind an is16 branch against the box32 f32 bitcasts (joining via 24 f32 phis) and hoist the ray.inv >= 0 sign check once across all four child boxes without altering FP evaluation order.

Add a zero-GPU DXIL bitcode CFG + dxil.dll validation test covering all node-type/box16/hoisted-sign/WARP-load invariants (including guarded BVH lowering), plus a coherent-wave and mixed-lane GPU/WARP test.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:58:24 +00:00
github-bot closed this pull request 2026-11-26 04:58:24 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 10:52 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head c7963ef3 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 10:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2206#issuecomment-7160278856) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head c7963ef3 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:29 UTC · original

Automated triage for the maintainers.

In emit/lower/bvh.rs, the PR replaces the selects in bvh_lanes with branches and phis by node type, splits bvh_box into box16 and box32 blocks, and hoists the ray.inv >= 0 compare. By my reading the results are the same as on main (box for ty & 6 == 4, triangle for ty < 4, otherwise INVALID), and CI passes. A dump-based run found no change in validation counts.

It is a performance change, but it comes with no measurement. Branching per lane inside a wave can be slower than the current branch-free selects when node types differ across lanes, which is the normal case during traversal. Please add a before/after timing: a GPU or WARP microbenchmark of the lowered shader, or frame times in the title. The 800 added test lines in emit/bvh_tests.rs are also a lot for a change that keeps behaviour; tests that pin the CFG shape will break on any later rework. A smaller test of equivalent results would serve better.

A measured gain would change this verdict.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2206#issuecomment-7163855120) <!-- victory-triage v1 head=c7963ef3392ed3e5fc4df9c29f4f270821c19fc6 verdict=needs-work at=2026-11-25T13:30:00Z --> Automated triage for the maintainers. In `emit/lower/bvh.rs`, the PR replaces the `select`s in `bvh_lanes` with branches and phis by node type, splits `bvh_box` into box16 and box32 blocks, and hoists the `ray.inv >= 0` compare. By my reading the results are the same as on `main` (box for `ty & 6 == 4`, triangle for `ty < 4`, otherwise `INVALID`), and CI passes. A dump-based run found no change in validation counts. It is a performance change, but it comes with no measurement. Branching per lane inside a wave can be slower than the current branch-free selects when node types differ across lanes, which is the normal case during traversal. Please add a before/after timing: a GPU or WARP microbenchmark of the lowered shader, or frame times in the title. The 800 added test lines in `emit/bvh_tests.rs` are also a lot for a change that keeps behaviour; tests that pin the CFG shape will break on any later rework. A smaller test of equivalent results would serve better. A measured gain would change this verdict. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:14 UTC · original

Closing per triage feedback: per-lane BVH branching needs a real GPU/title traversal benchmark to ensure divergent rays do not regress, which I cannot measure without hardware GPU + title.

**@⁠RVZO6** on GitHub · 2026-11-25 17:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2206#issuecomment-7169203256) Closing per triage feedback: per-lane BVH branching needs a real GPU/title traversal benchmark to ensure divergent rays do not regress, which I cannot measure without hardware GPU + title.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/Marvisak--VIctory!2206
No description provided.