Shaders: support BVH a16 ray directions and unsorted box nodes #1794

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

@⁠ESAT586 on GitHub · 2026-11-24 22:42 UTC · original
ESAT586:shader/bvh-a16-and-unsorted-boxes → main · +383 −75 · 3 files · 1 commits · open

Summary

Extends image_bvh_intersect_ray and image_bvh64_intersect_ray emulation on top of 70564ae to support two previously refused RDNA2 ray-tracing forms:

  1. 16-bit packed ray directions (16):
    • Unpacks the three 16 direction dwords (dir.x|dir.y, dir.z|inv.x, inv.y|inv.z) via dx.op.legacyF16ToF32 (8 address dwords for 32-bit pointers, 9 for 64-bit pointers via contiguous or NSA addressing; ields.rs already decodes both), while keeping
      ay_extent and
      ay_origin.xyz in 32.
    • Guards against unsupported d16 results cleanly by name.
  2. Unsorted box nodes (ox_sort_en = 0, descriptor bit 63 clear):
    • Updates
      esource::bvh_descriptor to accept descriptor dword 1 with bit 31 either set or clear — including descriptors whose dword 1 comes straight from s_lshr_b64 with no s_or_b32, as well as chained set_bits — while continuing to refuse unemulated flags (non-zero ox_growth, node-count bounds, riangle_return_mode == 0).
    • Skips emitting the 5-comparator sorting network in vh_box when ox_sort_en is statically
**@⁠ESAT586** on GitHub · 2026-11-24 22:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1794) `ESAT586:shader/bvh-a16-and-unsorted-boxes` → `main` · +383 −75 · 3 files · 1 commits · open ## Summary Extends image_bvh_intersect_ray and image_bvh64_intersect_ray emulation on top of 70564ae to support two previously refused RDNA2 ray-tracing forms: 1. **16-bit packed ray directions (16)**: - Unpacks the three 16 direction dwords (dir.x|dir.y, dir.z|inv.x, inv.y|inv.z) via dx.op.legacyF16ToF32 (8 address dwords for 32-bit pointers, 9 for 64-bit pointers via contiguous or NSA addressing; ields.rs already decodes both), while keeping ay_extent and ay_origin.xyz in 32. - Guards against unsupported d16 results cleanly by name. 2. **Unsorted box nodes (ox_sort_en = 0, descriptor bit 63 clear)**: - Updates esource::bvh_descriptor to accept descriptor dword 1 with bit 31 either set or clear — including descriptors whose dword 1 comes straight from s_lshr_b64 with no s_or_b32, as well as chained set_bits — while continuing to refuse unemulated flags (non-zero ox_growth, node-count bounds, riangle_return_mode == 0). - Skips emitting the 5-comparator sorting network in vh_box when ox_sort_en is statically
Support 16-bit packed ray directions (16) and disabled box sorting
(ox_sort_en = 0, descriptor bit 63) in image_bvh_intersect_ray and
image_bvh64_intersect_ray:

- Unpack the three 16 dwords (dir.x|dir.y, dir.z|inv.x,
  inv.y|inv.z) via legacyF16ToF32 (8 address dwords for 32-bit
  pointers, 9 for 64-bit) while keeping ray extent and origin in f32,
  and guard against unsupported d16 results.
- Accept BVH descriptors with bit 63 (ox_sort_en) clear as well as
  set in 
esource::bvh_descriptor (including descriptors whose dword 1
  uses the shifted base high dword directly with no s_or_b32, or
  chained set_bits), while continuing to refuse unemulated flags
  (non-zero box growth, node count bounds, triangle return mode 0).
- Skip emitting the 5-comparator distance sort network in vh_box
  when ox_sort_en is statically 0 (Source::Built), and dynamically
  select sorted vs. slot-order children from dword 1 bit 31 for raw
  title-memory descriptors (Nodes::Raw).
- Add unit and end-to-end GPU + WARP + DXIL-validated tests covering
  32-bit and 64-bit (NSA) 16 intersections, unsorted box nodes on
  both root and title-memory descriptors, and negative tests for
  still-refused flags.

AI disclosure: implemented with Gemini 4 Neon (High Mode) using only
synthetic test cases and RDNA2 ISA documentation; zero game binaries or
copyrighted assets were accessed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:44:48 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:50 UTC · original

NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, 72ebd96 (on main 70564ae). cargo test -p victory-shader --locked -- bvh: 18 passed, 0 failed. That includes the GPU ones: intersections_with_a16_on_the_gpu_equal_the_reference, unsorted_box_intersections_on_the_gpu_equal_the_reference, intersections_on_the_gpu_equal_the_reference, the 64-bit pointer form and the title-memory nodes.

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

**@⁠upipibi** on GitHub · 2026-11-24 22:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1794#issuecomment-7146712958) NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `72ebd96` (on `main` `70564ae`). `cargo test -p victory-shader --locked -- bvh`: 18 passed, 0 failed. That includes the GPU ones: `intersections_with_a16_on_the_gpu_equal_the_reference`, `unsorted_box_intersections_on_the_gpu_equal_the_reference`, `intersections_on_the_gpu_equal_the_reference`, the 64-bit pointer form and the title-memory nodes. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

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

Automated triage for the maintainers.

Merge candidate. image_bvh{,64}_intersect_ray (crates/victory-shader/src/emit/lower/bvh.rs) now accepts a16 and box nodes with sorting disabled; resource.rs accepts descriptors with bit 63 clear. I checked the a16 operand layout (three dwords dir.x|dir.y, dir.z|inv.x, inv.y|inv.z, low half first, extent and origin kept f32) against the RDNA2 ISA's ray-tracing operand description, which the commit cites; legacyF16ToF32 is DXIL op 131 as used. With sorting off, children come back in slot order with misses left as the invalid pointer in place; the sort network is skipped statically for built descriptors and selected at run time from dword 1 bit 31 for raw ones. Still-unemulated flags (box growth, node bound, return mode 0) and d16 results stay refused.

One caveat for the reviewer: the reference the tests compare against is the PR's own, so they check consistency, not hardware; a run of a title shader that uses a16 would be the stronger check. An RTX 3070 run in this thread passed all 18 BVH tests.

CI: no check runs on the head commit.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1794#issuecomment-7154777850) <!-- victory-triage v1 head=72ebd96862cd9ef556089168d59b0b2341366dfe verdict=merge-candidate at=2026-11-25T07:00:00Z --> Automated triage for the maintainers. **Merge candidate.** `image_bvh{,64}_intersect_ray` (`crates/victory-shader/src/emit/lower/bvh.rs`) now accepts `a16` and box nodes with sorting disabled; `resource.rs` accepts descriptors with bit 63 clear. I checked the a16 operand layout (three dwords `dir.x|dir.y`, `dir.z|inv.x`, `inv.y|inv.z`, low half first, extent and origin kept f32) against the RDNA2 ISA's ray-tracing operand description, which the commit cites; `legacyF16ToF32` is DXIL op 131 as used. With sorting off, children come back in slot order with misses left as the invalid pointer in place; the sort network is skipped statically for built descriptors and selected at run time from dword 1 bit 31 for raw ones. Still-unemulated flags (box growth, node bound, return mode 0) and `d16` results stay refused. One caveat for the reviewer: the reference the tests compare against is the PR's own, so they check consistency, not hardware; a run of a title shader that uses a16 would be the stronger check. An RTX 3070 run in this thread passed all 18 BVH tests. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:02 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head 72ebd96862cd merged cleanly onto main (63bcca43c6a0; adds 0 bytes to emit/lower.rs, staying at 520,563 B):

  • Code review (crates/victory-shader/src/emit/lower/bvh.rs:593-687, 734-752, resource.rs:1384-1415):
    • a16 unpacking keeps d16 rejected, extracts low/high 16-bit halves from the 3 packed ray-direction/inverse-direction dwords (w & 0xFFFF / logical w >> 16), and widens via DXIL op 131 legacyF16ToF32 (preserving ±0/±Inf/NaN/subnormals).
    • Unsorted box nodes: resource.rs peels nested s_or_b32/s_bitset1_b32 constant flag bits via set_bits, accepts bit 63 (box_sort_en) as either 0 or 1, and continues rejecting any other unmodeled flag bits (flags & !0x8000_0000 != 0) or non-1 triangle return mode; Source::Built skips the 5-stage sorting network statically when false, while Nodes::Raw dynamically selects sorted vs child-slot order from d[1] & 0x8000_0000.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • bvh_tests emit::lower::tests: 51/51 passed across RTX 5090 and WARP (bvh_tests explicit VICTORY_WARP=1: 18/18 passed), including the new a16 and unsorted box GPU reference tests.

Clean and stays completely out of lower.rs's 512 KiB budget; LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1794#issuecomment-7179378080) Code review and RTX 5090 + WARP + DXIL verification at head `72ebd96862cd` merged cleanly onto `main` (`63bcca43c6a0`; adds 0 bytes to `emit/lower.rs`, staying at `520,563` B): - **Code review (`crates/victory-shader/src/emit/lower/bvh.rs:593-687, 734-752`, `resource.rs:1384-1415`)**: - `a16` unpacking keeps `d16` rejected, extracts low/high 16-bit halves from the 3 packed ray-direction/inverse-direction dwords (`w & 0xFFFF` / logical `w >> 16`), and widens via DXIL op 131 `legacyF16ToF32` (preserving `±0`/`±Inf`/`NaN`/subnormals). - Unsorted box nodes: `resource.rs` peels nested `s_or_b32`/`s_bitset1_b32` constant flag bits via `set_bits`, accepts bit 63 (`box_sort_en`) as either `0` or `1`, and continues rejecting any other unmodeled flag bits (`flags & !0x8000_0000 != 0`) or non-1 triangle return mode; `Source::Built` skips the 5-stage sorting network statically when `false`, while `Nodes::Raw` dynamically selects sorted vs child-slot order from `d[1] & 0x8000_0000`. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `bvh_tests emit::lower::tests`: **51/51 passed** across RTX 5090 and WARP (`bvh_tests` explicit `VICTORY_WARP=1`: **18/18 passed**), including the new `a16` and unsorted box GPU reference tests. Clean and stays completely out of `lower.rs`'s 512 KiB budget; LGTM.
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/1794/head:github-bot/gh-1794'
git switch 'github-bot/gh-1794'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1794'
git switch 'github-bot/gh-1794'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1794'
git switch 'github-bot/gh-1794'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1794'
git switch 'main'
git merge --squash 'github-bot/gh-1794'
git switch 'main'
git merge --ff-only 'github-bot/gh-1794'
git switch 'main'
git merge 'github-bot/gh-1794'
git push origin 'main'
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!1794
No description provided.