hwrt: add DXR 1.1 BLAS/TLAS registry and XboxBvhBuilder HLE (#339) #347

Closed
Androtim wants to merge 4 commits from upstream-pr/347 into main
Androtim commented 2026-12-02 14:54:38 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T14:54:38Z.


Implements the core Phase 2 Native DXR 1.1 infrastructure for #339 behind \VICTORY_HW_RT=1\ (off by default; zero RT-off impact):

  • *\ ictory-gpu::hwrt* (hwrt.rs, budget.rs, sanitize.rs):
    • Feature gate checking \VICTORY_HW_RT=1, \D3D12_RAYTRACING_TIER_1_1, \device_shader_model >= 6.5, and \ID3D12Device5.
    • DXR 1.1 BLAS/TLAS registry keyed by console GPU VA with \PERFORM_UPDATE\ refit parity checks, \LeasePool\ scratch/instance leases, per-frame BLAS build throttling (\Budget/\Backlog), LRU eviction (\BlasLru\ + GPU instance feedback readback), and \WriteBufferImmediate\ size responses aligned to 256 bytes.
    • GPU compute sanitization (\SANITIZE_HLSL: \clamp_ib\ / \copy_vb) and \D3D12_RAYTRACING_INSTANCE_DESC::AccelerationStructure\ VA remapping (\REMAP_HLSL).
  • *\ ictory-hle::modules::xboxbvh* (xboxbvh.rs):
    • Intercepts all 12 C++ exports of \XboxBvhBuilder.dll, registered in \modules::all()\ only when \ ictory_gpu::hwrt::requested()\ is true.
  • Minimal hooks in \host.rs\ (\HostList::hold\ / \Deferred::held), \watch.rs\ (\ itle_memory_freed), and \lib.rs.

Verification

  • \cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib hwrt:: -- --test-threads=1\ (21 passed; 0 failed — CPU logic + \d3dcompiler_47\ HLSL compile checks for \REMAP_HLSL\ and \SANITIZE_HLSL)
  • \cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle -- --test-threads=1\ (238 passed, 3 ignored benchmarks + 1 integration test passed)
  • \cargo +1.98.1-x86_64-pc-windows-gnu xtask policy --staged\ (\8 files ok)
  • \cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings\ & --all-features\ (0 warnings)

Adapted from GPL-3.0 upstream implementations in \TrustNo1-Coder/Darner\ and
eadmet3xt-lab/foxhound.

<!-- greyfinch-sync:Androtim/MiniVI:issue:5608937172 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/347). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T14:54:38Z. --- Implements the core Phase 2 Native DXR 1.1 infrastructure for #339 behind \VICTORY_HW_RT=1\ (off by default; zero RT-off impact): - **\ ictory-gpu::hwrt\** ([hwrt.rs](crates/victory-gpu/src/hwrt.rs), [budget.rs](crates/victory-gpu/src/hwrt/budget.rs), [sanitize.rs](crates/victory-gpu/src/hwrt/sanitize.rs)): - Feature gate checking \VICTORY_HW_RT=1\, \D3D12_RAYTRACING_TIER_1_1\, \device_shader_model >= 6.5\, and \ID3D12Device5\. - DXR 1.1 BLAS/TLAS registry keyed by console GPU VA with \PERFORM_UPDATE\ refit parity checks, \LeasePool\ scratch/instance leases, per-frame BLAS build throttling (\Budget\/\Backlog\), LRU eviction (\BlasLru\ + GPU instance feedback readback), and \WriteBufferImmediate\ size responses aligned to 256 bytes. - GPU compute sanitization (\SANITIZE_HLSL\: \clamp_ib\ / \copy_vb\) and \D3D12_RAYTRACING_INSTANCE_DESC::AccelerationStructure\ VA remapping (\REMAP_HLSL\). - **\ ictory-hle::modules::xboxbvh\** ([xboxbvh.rs](crates/victory-hle/src/modules/xboxbvh.rs)): - Intercepts all 12 C++ exports of \XboxBvhBuilder.dll\, registered in \modules::all()\ only when \ ictory_gpu::hwrt::requested()\ is true. - Minimal hooks in \host.rs\ (\HostList::hold\ / \Deferred::held\), \watch.rs\ (\ itle_memory_freed\), and \lib.rs\. ### Verification - \cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib hwrt:: -- --test-threads=1\ (21 passed; 0 failed — CPU logic + \d3dcompiler_47\ HLSL compile checks for \REMAP_HLSL\ and \SANITIZE_HLSL\) - \cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-hle -- --test-threads=1\ (238 passed, 3 ignored benchmarks + 1 integration test passed) - \cargo +1.98.1-x86_64-pc-windows-gnu xtask policy --staged\ (\8 files ok\) - \cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets -- -D warnings\ & \--all-features\ (0 warnings) Adapted from GPL-3.0 upstream implementations in \TrustNo1-Coder/Darner\ and \ eadmet3xt-lab/foxhound\.
Androtim commented 2026-12-02 16:04:08 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T16:04:08Z.


Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

Solid foundational DXR 1.1 infrastructure for #339, cleanly gated behind VICTORY_HW_RT=1 (off by default). CI is passing, and the lock hierarchy in HwRtManager (blas_table -> queue -> lru -> as_map -> shown) is acyclic.

Verified Changes

  • crates/victory-gpu/src/host.rs: Minimal addition of Deferred::held (Vec<Box<dyn Any + Send>>), HostList::hold, Deferred::reset clamping, and HostList::untouched check.
  • crates/victory-gpu/src/hwrt.rs & crates/victory-gpu/src/hwrt/budget.rs:
    • Capability gate (can_enable / supported) checks D3D12_RAYTRACING_TIER_1_1, SM >= 6.5, and ID3D12Device5.
    • Per-frame BLAS build throttling (BlasQueue / Budget / Backlog), VRAM-budgeted LRU eviction (BlasLru + GPU instance feedback readback via Feedback), scratch/work LeasePool, and PERFORM_UPDATE refit parity checks (geom_keys_from_descs).
    • GPU compute sanitization (clamp_ib_pso / copy_vb_pso) and TLAS instance VA remapping (remap_pso) with WriteBufferImmediate / EmitRaytracingAccelerationStructurePostbuildInfo responses.

Minor Edge Cases Noted

  1. State leak on OOM early return in HwRtManager::execute_build (crates/victory-gpu/src/hwrt.rs): When building a TLAS, dst_inst_buf is transitioned from UNORDERED_ACCESS to NON_PIXEL_SHADER_RESOURCE after the remap dispatch, but if self.lease (for TLAS scratch) or self.alloc_or_reuse_as (for dest_as) subsequently returns None, execute_build returns early without transitioning dst_inst_buf back to UNORDERED_ACCESS before Lease::drop returns it to self.leases. Moving the scratch lease / dest_as allocation ahead of the remap barrier (or restoring the state on early return) would prevent a D3D12 state mismatch on allocation failure.
  2. len == 0 in hwrt::title_memory_freed (crates/victory-gpu/src/hwrt.rs): Returns early when len == 0, whereas watch::title_memory_freed supports len == 0 for whole-allocation MEM_RELEASE frees (unless watch.rs passes a resolved byte length).

(Note: The PR diff payload was truncated at 120 KB of 171 KB, so sanitize.rs, xboxbvh.rs, the tail of budget.rs, and the small wiring hunks in lib.rs/watch.rs/modules/mod.rs were not directly inspected.)

Next Step

Warrants a local real-GPU DXR 1.1 smoke test (both RT-off default and VICTORY_HW_RT=1) before merging.


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7351386089 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/347#issuecomment-7351386089). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T16:04:08Z. --- <!-- minivi-triage v1 head=5e532641930eaf7f11afc95cd5592d8f5369dcac verdict=needs-gpu-test ci=passing at=2026-12-02T16:04:39Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary Solid foundational DXR 1.1 infrastructure for `#339`, cleanly gated behind `VICTORY_HW_RT=1` (off by default). CI is passing, and the lock hierarchy in `HwRtManager` (`blas_table` -> `queue` -> `lru` -> `as_map` -> `shown`) is acyclic. ### Verified Changes - **`crates/victory-gpu/src/host.rs`**: Minimal addition of `Deferred::held` (`Vec<Box<dyn Any + Send>>`), `HostList::hold`, `Deferred::reset` clamping, and `HostList::untouched` check. - **`crates/victory-gpu/src/hwrt.rs` & `crates/victory-gpu/src/hwrt/budget.rs`**: - Capability gate (`can_enable` / `supported`) checks `D3D12_RAYTRACING_TIER_1_1`, SM >= 6.5, and `ID3D12Device5`. - Per-frame BLAS build throttling (`BlasQueue` / `Budget` / `Backlog`), VRAM-budgeted LRU eviction (`BlasLru` + GPU instance feedback readback via `Feedback`), scratch/work `LeasePool`, and `PERFORM_UPDATE` refit parity checks (`geom_keys_from_descs`). - GPU compute sanitization (`clamp_ib_pso` / `copy_vb_pso`) and TLAS instance VA remapping (`remap_pso`) with `WriteBufferImmediate` / `EmitRaytracingAccelerationStructurePostbuildInfo` responses. ### Minor Edge Cases Noted 1. **State leak on OOM early return in `HwRtManager::execute_build`** (`crates/victory-gpu/src/hwrt.rs`): When building a TLAS, `dst_inst_buf` is transitioned from `UNORDERED_ACCESS` to `NON_PIXEL_SHADER_RESOURCE` after the remap dispatch, but if `self.lease` (for TLAS scratch) or `self.alloc_or_reuse_as` (for `dest_as`) subsequently returns `None`, `execute_build` returns early without transitioning `dst_inst_buf` back to `UNORDERED_ACCESS` before `Lease::drop` returns it to `self.leases`. Moving the scratch lease / `dest_as` allocation ahead of the remap barrier (or restoring the state on early return) would prevent a D3D12 state mismatch on allocation failure. 2. **`len == 0` in `hwrt::title_memory_freed`** (`crates/victory-gpu/src/hwrt.rs`): Returns early when `len == 0`, whereas `watch::title_memory_freed` supports `len == 0` for whole-allocation `MEM_RELEASE` frees (unless `watch.rs` passes a resolved byte length). *(Note: The PR diff payload was truncated at 120 KB of 171 KB, so `sanitize.rs`, `xboxbvh.rs`, the tail of `budget.rs`, and the small wiring hunks in `lib.rs`/`watch.rs`/`modules/mod.rs` were not directly inspected.)* ### Next Step Warrants a local real-GPU DXR 1.1 smoke test (both RT-off default and `VICTORY_HW_RT=1`) before merging. --- _Generated with Antigravity CLI (`agy`)._
Androtim commented 2026-12-02 17:04:20 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-02T17:04:20Z.


Holding merge (triage: needs work) per Deep Static Audit Pass #2 (#282 comment 7352688269, DXR 1.1 P0/P1 findings #1–#20 routed to #339; note #354 must not merge without #357's shader_cache.rs key isolation #10).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7352860129 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/347#issuecomment-7352860129). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-02T17:04:20Z. --- Holding merge (`triage: needs work`) per Deep Static Audit Pass #2 (`#282` comment `7352688269`, DXR 1.1 P0/P1 findings #1–#20 routed to `#339`; note `#354` must not merge without `#357`'s `shader_cache.rs` key isolation #10).
Androtim commented 2026-12-03 00:03:56 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-12-03T00:03:56Z.


Merged into main (b0efcacc) via the Audit Pass #5 green-lit superset PR #357 (complete #339 DXR 1.1 RayQuery stack behind VICTORY_HW_RT=1, zero non-RT impact).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7362754110 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/347#issuecomment-7362754110). Originally posted by [Androtim](https://github.com/Androtim) on 2026-12-03T00:03:56Z. --- Merged into main (b0efcacc) via the Audit Pass #5 green-lit superset PR #357 (complete #339 DXR 1.1 RayQuery stack behind VICTORY_HW_RT=1, zero non-RT impact).

Pull request closed

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
Androtim/MiniVI!347
No description provided.