Shaders: guard guest-memory fault writes and skip redundant Box32 directory lookups #21
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/DexNom--VIctory!21
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-21"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@davi713albano-coder on GitHub · 2026-11-25 18:57 UTC · original
davi713albano-coder:dexnom/bvh-memory-fast-path→main· +231 −120 · 3 files · 1 commits · openSummary
Reduces per-node GPU overhead on the translated guest-memory and BVH traversal hot path (
Lower::memoryandLower::bvh_boxes) while keeping bit-for-bit identical results and fault reporting:Guard guest-memory fault hashing and
SLOT_FAULTSstores (crates/victory-shader/src/emit/intersect.rs,lower.rs):Lower::memoryunconditionally computedURem(page, MEMORY_FAULTS - 1)and issued arawBufferStore.i32to the host-visibleSLOT_FAULTSUAV (writing to sink slot0) on every single guest-memory access and BVH node visit, even when the page was already mapped.self.begin_guarded(Some(missing))lets mapped waves skip both the software integer modulo and PCIe/host-memory write completely, while preserving identical fault recording on unmapped pages.let c = self.curat callers ofself.memory(...)inmemory_flatandmemory_smem, and movedLower::memoryintointersect.rs(keepinglower.rscomfortably under the 512 KiBxtaskpolicy limit).Skip redundant page-directory lookups for same-page 128-byte
Box32BVH nodes (crates/victory-shader/src/emit/intersect.rs):bvh_addressproduces 64-byte-aligned addresses ((pointer >> 3) << 6added to a 256-byte-aligned base), so a 128-byteBox32node's second 64-byte half lies in the same 64 KiB page for 1,023 of every 1,024 aligned addresses ((low & 0xFFFF) < 0xFFC0).bvh_boxesreuses the already-resolved handle and reads frombyte + 64directly (avoiding a second directoryrawBufferLoad,createHandleFromHeap, and fault check, with no%dx.types.HandlePHIs).>= 0xFFC0branch to the slow path callingaddress_plus(..., 64)andbvh_memory(...), preserving full cross-page residency tracking and fault reporting.Verification
intersect_tests::ray_nodes_through_the_guest_page_directoryto assert that mapped guest-memory accesses (both same-pagecontrolsand cross-page0xFFC0retried) leave the entireSLOT_FAULTSbuffer untouched (all == 0), while unmapped lookups (absent,split_box,beyond) continue reporting the missing page in its expected bucket.CI(windows-latest:clippy --workspace --all-targets --locked -- -D warnings,--all-features,cargo test --workspace --locked,xtaskasset-policy check, and DXIL validation across all 311 BVH ray/node cases) andScreen.No title data used. AI-assisted.
@lcg007xd-c on GitHub · 2026-11-25 21:14 UTC · original · reviewed
Reviewed against
mainat2e01ab4. The change is invictory-shader's DXIL lowering. The test it extends (reflected_rays_walk_linked_nodes_through_the_guest_directory) runs a real D3D12 device and WARP, so I could only type-check it here, not execute it.Verified on Linux
cargo test -p victory-shader --lib --locked: 182 passed, 2 ignored, the same asmain.cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings(withCC_x86_64_pc_windows_msvc=clang-cl AR_x86_64_pc_windows_msvc=llvm-lib): clean, same asmain. This also type-checks the changed Windows-only test.cargo xtask policy:asset policy: 195 files ok.lower.rsis 520,369 bytes on this branch against 524,060 onmain, and the limit inxtask/src/policy.rs:13is 524,288, somainhad only 228 bytes of headroom.git merge-tree --write-tree origin/HEAD pr21: merges cleanly intomain.What I checked by reading
Lower::memorynow re-readsself.curafter the call, since it now opens a guarded block:lower.rsglobal load (2859), atomics (2909),memory_smem(3045), andintersect.rs:172(which usesself.curafterwards). The global store path already goes throughbegin_guardedandself.cur. I found no stalecleft.shader.rs:386-432), andhost_wordreads user data in the entry block (lower.rs:2704), so using them inside the new fault-gate block does not break dominance.base<<8 + (ptr>>3)<<6(bvh_address), so the low 16 bits are 64-byte aligned and the second half crosses a 64 KiB page only when they are0xFFC0exactly.within >= 0xFFC0is therefore exact, and conservative if the alignment ever slipped.phinow has three incomings (same-page, cross-page, half), matching the three predecessors ofjoin.half_endis also taken after the 16-bit loads rather than assuminghalf_block.Findings
One, and it is about merging rather than the code. Conflict with #22:
git merge-tree --write-tree --name-only pr21 pr22reports a content conflict incrates/victory-shader/src/emit/lower.rs(both editmemory_smem: #22 changes theself.memory(...)call line that this PR follows withlet c = self.cur;). Whoever lands second will need to rebase, and the resolution must keep this PR'slet c = self.cur;after the call (otherwise the loads after it use a stale block, a silent miscompile that unit tests off-GPU would not catch).I found no defect in the lowering. I did not approve because I could not execute the test that proves the "no fault writes when mapped" claim.
Not verified
intersect_testson a GPU or WARP, and DXIL validation bydxil.dll.Reviewed with Claude Code.
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.Merge
Merge the changes and update on Forgejo.