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

Open
orazal12 wants to merge 1 commit from upstream-pr/607 into main
orazal12 commented 2026-11-25 03:09:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by orazal12 on 2026-11-25T03:09:31Z.


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
<!-- greyfinch-sync:fxceless/victory-fork:issue:6596298368 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/607). Originally posted by [orazal12](https://github.com/orazal12) on 2026-11-25T03:09:31Z. --- 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
0xmp3 commented 2026-11-25 04:11:21 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by 0xmp3 on 2026-11-25T03:35:41Z.


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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7152059801 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/607#issuecomment-7152059801). Originally posted by [0xmp3](https://github.com/0xmp3) on 2026-11-25T03:35:41Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/607:upstream-pr/607'
git switch 'upstream-pr/607'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/607'
git switch 'upstream-pr/607'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/607'
git switch 'upstream-pr/607'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/607'
git switch 'main'
git merge --squash 'upstream-pr/607'
git switch 'main'
git merge --ff-only 'upstream-pr/607'
git switch 'main'
git merge 'upstream-pr/607'
git push origin 'main'
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
fxceless/victory-fork!607
No description provided.