Shaders: guard title-memory fault writes and skip second BVH directory lookup on non-straddling box32 nodes #607

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

@⁠orazal12 on GitHub · 2026-11-25 03:09 UTC · original
orazal12:perf/rt-bvh-memory → main · +701 −64 · 6 files · 1 commits · open

Cuts per-access overhead in ray-tracing / raw title-memory shaders:

  • Guard SLOT_FAULTS writes & URem(page, 4095) in Lower::memory(): splits Lower::memory_slot() and wraps the fault-slot modulo + rawBufferStore.i32 to SLOT_FAULTS in begin_guarded(Some(missing)) / end_guarded(...) so steady-state valid title-memory accesses execute zero modulo ops and zero PCIe UAV writes to faults[0].
  • Skip redundant 2nd directory lookup for non-straddling 128B box32 BVH nodes: guards the second-half directory lookup in bvh_node_words() with (low & 0xFFFF) >= 0xFFC0 so 1023/1024 positions reuse (slot, byte) directly, joining via i32 PHIs + bvh_heap_handle (no %dx.types.Handle PHI).

Verification:

  • cargo test -p victory-shader --offline: 216 passed, 0 failed (all 8 intersect_tests including the 311-case BVH GPU + WARP suites and 2 new end-to-end directory/faults/straddle GPU + WARP tests)
  • cargo test -p xtask --offline: 4 passed (asset policy check ok)
  • cargo clippy -p victory-shader --all-targets --offline -- -D warnings: 0 warnings
**@⁠orazal12** on GitHub · 2026-11-25 03:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/607) `orazal12:perf/rt-bvh-memory` → `main` · +701 −64 · 6 files · 1 commits · open Cuts per-access overhead in ray-tracing / raw title-memory shaders: - **Guard `SLOT_FAULTS` writes & `URem(page, 4095)` in `Lower::memory()`**: splits `Lower::memory_slot()` and wraps the fault-slot modulo + `rawBufferStore.i32` to `SLOT_FAULTS` in `begin_guarded(Some(missing))` / `end_guarded(...)` so steady-state valid title-memory accesses execute zero modulo ops and zero PCIe UAV writes to `faults[0]`. - **Skip redundant 2nd directory lookup for non-straddling 128B box32 BVH nodes**: guards the second-half directory lookup in `bvh_node_words()` with `(low & 0xFFFF) >= 0xFFC0` so 1023/1024 positions reuse `(slot, byte)` directly, joining via `i32` PHIs + `bvh_heap_handle` (no `%dx.types.Handle` PHI). **Verification:** - `cargo test -p victory-shader --offline`: 216 passed, 0 failed (all 8 `intersect_tests` including the 311-case BVH GPU + WARP suites and 2 new end-to-end directory/faults/straddle GPU + WARP tests) - `cargo test -p xtask --offline`: 4 passed (asset policy check ok) - `cargo clippy -p victory-shader --all-targets --offline -- -D warnings`: 0 warnings
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:47:19 +00:00
Author
Owner

@⁠0xmp3 on GitHub · 2026-11-25 03:35 UTC · original

Verified on a second machine, and a note on what this change can and cannot be shown to do end-to-end.

Tests: your claim reproduces exactly — cargo test -p victory-shader gives 216 passed, 0 failed, 3 ignored (23.8 s) on Windows 11 / Ryzen 5 5600 / RX 9070 XT, Rust 1.98.1 MSVC. The build is clean.

Runtime: the branch boots and reaches the world here with no crash and no device removal, using VICTORY_SHADER_OPT=59 VICTORY_RELAY=2 VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1 VICTORY_INPLACE=1 on this card (supported by my AMD notes in #543). So no correctness regression observed in the frame either — the picture is the usual coherent-but-unlit-shadowed prologue.

End-to-end timing, which unfortunately does not settle it:

build frames frame p50 GPU p50 draws/frame p50
base c96b4f2 122 2,282 ms 1,018 ms 4,969
this PR, cold 56 2,633 ms 854 ms 1,795
this PR, warm 56 2,503 ms 982 ms 3,666

GPU time is marginally lower on the PR (982 vs 1,018 ms) but it was drawing 27% fewer objects at that point, and two runs of the same build differ by 2.5× in draw count. Because the title's simulation is time-dilated by frame rate at 0.3–2 fps, no two runs sample the same workload, so scene variance is much larger than the per-access effect this change removes. I cannot attribute anything to the change from these numbers, and I don't think anyone can from frame time alone.

If you want end-to-end evidence for it, the shape that would work is a fixed workload rather than a live run: capture one frame's dispatch sequence (or replay the same command lists) and compare GPU time for that identical sequence across the two builds. Repeating a fixed scene state would also do it. Otherwise intersect_tests (already 311 GPU + WARP cases here) is the right instrument, and it already passes.

No game data; timings and counts from VIctory's own log. AI-assisted (Hermes Agent).

**@⁠0xmp3** on GitHub · 2026-11-25 03:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/607#issuecomment-7152059801) Verified on a second machine, and a note on what this change can and cannot be shown to do end-to-end. **Tests:** your claim reproduces exactly — `cargo test -p victory-shader` gives **216 passed, 0 failed, 3 ignored** (23.8 s) on Windows 11 / Ryzen 5 5600 / RX 9070 XT, Rust 1.98.1 MSVC. The build is clean. **Runtime:** the branch boots and reaches the world here with no crash and no device removal, using `VICTORY_SHADER_OPT=59 VICTORY_RELAY=2 VICTORY_BVH_BUILDER=1 VICTORY_BVH_QUARANTINE=1 VICTORY_INPLACE=1` on this card (supported by my AMD notes in #543). So no correctness regression observed in the frame either — the picture is the usual coherent-but-unlit-shadowed prologue. **End-to-end timing, which unfortunately does not settle it:** | build | frames | frame p50 | GPU p50 | draws/frame p50 | |---|---:|---:|---:|---:| | base `c96b4f2` | 122 | 2,282 ms | 1,018 ms | 4,969 | | this PR, cold | 56 | 2,633 ms | 854 ms | 1,795 | | this PR, warm | 56 | 2,503 ms | 982 ms | 3,666 | GPU time is marginally lower on the PR (982 vs 1,018 ms) but it was drawing 27% fewer objects at that point, and **two runs of the same build differ by 2.5× in draw count**. Because the title's simulation is time-dilated by frame rate at 0.3–2 fps, no two runs sample the same workload, so scene variance is much larger than the per-access effect this change removes. I cannot attribute anything to the change from these numbers, and I don't think anyone can from frame time alone. If you want end-to-end evidence for it, the shape that would work is a fixed workload rather than a live run: capture one frame's dispatch sequence (or replay the same command lists) and compare GPU time for that identical sequence across the two builds. Repeating a fixed scene state would also do it. Otherwise `intersect_tests` (already 311 GPU + WARP cases here) is the right instrument, and it already passes. No game data; timings and counts from VIctory's own log. AI-assisted (Hermes Agent).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/607/head:github-bot/gh-607'
git switch 'github-bot/gh-607'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-607'
git switch 'github-bot/gh-607'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-607'
git switch 'github-bot/gh-607'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-607'
git switch 'main'
git merge --squash 'github-bot/gh-607'
git switch 'main'
git merge --ff-only 'github-bot/gh-607'
git switch 'main'
git merge 'github-bot/gh-607'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.