Repository navigation
Shaders: guard guest-memory fault writes and skip redundant Box32 directory lookups - #21
davi713albano-coder wants to merge 1 commit into
Conversation
lcg007xd-c
left a comment
There was a problem hiding this comment.
Reviewed against main at 2e01ab4. The change is in victory-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.- Could not run: the revert-and-see-it-fail check on the new assertions, because they need a D3D12 device.
What I checked by reading
- Every caller of
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. - The root UAV/SRV handles are created in the entry block (
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. - Same-page fast path: the node address is built as
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. - The residency
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 pr22 reports a content conflict in crates/victory-shader/src/emit/lower.rs (both edit memory_smem: #22 changes the self.memory(...) call line that this PR follows with let c = self.cur;). Whoever lands second will need to rebase, and the resolution must keep this PR's let 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
- Running
intersect_testson a GPU or WARP, and DXIL validation bydxil.dll. - The performance claim (skipping the modulo, the fault store and the second directory lookup).
Reviewed with Claude Code.
…up again only when it crosses a 64 KiB page (by davi713albano-coder) From the pull request's commit as the previous port took it (d1785aa8f on integration-next), only the box test's part. The other part, the note of a missing page stored only when a page is missing, is on main already: Lower::memory notes it under its own guard. The 32-bit box node reads its second 64 bytes. In title memory they lie in the same 64 KiB page, and so in the same host copy at 64 bytes on, for 1,023 of 1,024 aligned nodes; only a node that starts at 0xFFC0 or later in its page asks the directory again, on a branch of its own, as every wide node did before. Whether the second half's page is there is the first half's on the fast path. The structures are walked only with VICTORY_BVH_BUILDER=1, so a run without it translates the same programs but traces nothing. The ray programs' translations change, so cached translations of them are made again. Not measured; the gain is the author's reasoning. (cherry picked in part from commit d1785aa8f6a143fbd1474a8f192d3bc7a68f36e8) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent native Windows release check at The existing assertions verified the entire untouched fault buffer for mapped same-page and split Box32 reads (offset Verification was AI-assisted with GPT-6.2 Astra. |
Summary
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.