fix(victory-shader): guard BVH memory lookups and optimize box32 second-half reads #476
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/476"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T01:31:53Z.
Change
Fixes two real-directory correctness bugs in
victory-shader's DXIL lowering ofimage_bvh_intersect_ray/image_bvh64_intersect_ray(third_party/victory/crates/victory-shader/src/emit/intersect.rs) and reduces redundant node/directory work on 128-bytebox32nodes, verified bit-for-bit againstcrate::bvh::intersecton an NVIDIA GeForce RTX 5070 Ti (Wave32 hardware, SM 6.6) and WARP using synthetic scenes only:bvh_addressandbvh_memory(SLOT_MEMORY/SLOT_FAULTS) insidebegin_guarded(memory_guard)andkind < 6:bvh_addressandbvh_memoryran beforebegin_guarded(guard)and before checkingkind, andLower::bvhusedself.guard(b, i)instead ofself.memory_guard(b, i).guard == false) still computed addresses, loaded from the 16 MiBSLOT_MEMORYdirectory, and createdNonUniformResourceIndexheap handles.kind == 6(instance),kind == 7(procedural), orbvh::NONE(0xffff_ffff,kind == 7) readSLOT_MEMORYfor unread addresses and wrote spurious page faults to host-RAMSLOT_FAULTSover PCIe.USER_DISPATCH_THREADS_Xin split wave64-on-wave32 partial final groups (partial_active) were not masked out and could readSLOT_MEMORYand record spurious faults.box32second-half reads, box load hoisting, and 32-bitbvh_address:bvh_addressin 32-bit halves instead of 64-bit integers, removingflags::INT64requirement on shaders that do not otherwise use 64-bit ints.children+ bytes16..64) inbvh_boxesbefore thebox32(kind == 5) vsbox16(kind == 4) branch so mixed warps never load bytes16..64twice.box32nodes when(children[2] & children[3]) == bvh::NONE(2-child nodes).box32nodes that do have child 2 or 3, reuse the first half's heap handle atbyte + 64unless(low & 0xFFFF) == 0xFFC0(straddling a 64 KiB page boundary), eliminating the redundant 2nd directory load and 2ndNonUniformResourceIndexhandle in 99.9%+ of nodes.intersect_tests.rs, test-onlyhost.rs):intersect_tests.rstests bypassedLower::memoryviaTEST_MEMORY. Addedreal_directory_memory_path_handles_cross_page_unmapped_and_no_spurious_faults(testing multi-arenaSLOT_MEMORY+SLOT_FAULTS+USER_MEMORY_BASE, cross-pagebox32across arenas, partially-unmapped cross-pagebox32, cross-page 2-childbox32, and zero spurious faults on masked andkind 6/7/NONElanes),wave64_bvh64_intersect_runs_on_wave32_hardware_and_respects_partial_groups, and an#[ignore]GPU timestamp benchmark (bench_bvh64_intersect_on_gpu).Verification
Tested on Windows 11 x64 with NVIDIA GeForce RTX 5070 Ti (driver
32.0.16.2140/621.40, Wave32 SM 6.6) and WARP against base commit4340aac1a494b9649c00e0e1ad2c6fbe6ea00e80(main):RTX 5070 Ti GPU Timestamp Comparison (same synthetic scenes, 32,768 threads x 64 iterations = 2,097,152
image_bvh64_intersect_raycalls/dispatch, 10 warmups + 40 timed dispatches, bit-exact CPU oracle verified):4340aac)f482803)mixed_pc_faults(host-RAM L0SLOT_FAULTS, matchingmemory.rs)1.062 ms(126 spurious faults)0.157 ms(0 faults)box32_2child(2-child 128B BVH4 nodes)0.279 ms0.162 msbox32_8arenas(8 divergent arenas/warp)0.390 ms0.381 msbox32_only(4-child 128B scattered)0.279 ms0.279 msbox16_only(64B scattered)0.162 ms0.162 msbox16_l1_coherent0.030 ms0.030 msmixed_box16_box320.221 ms0.223 mstriangle_only0.055 ms0.054 mstri_l1_coherent0.027 ms0.027 msmixed_traversal(VRAMSLOT_FAULTS)0.157 ms(126 spurious faults)0.157 ms(0 faults)box32_l1_coherent(coherent 4-child L1-hot)0.032 ms0.037 ms(Python
pytestwas not run because no files outsidethird_party/victory/crates/victory-shader/were modified.)Oracle and test data
third_party/victory/crates/victory-shader/src/bvh.rs(bvh::intersect), compared dword-for-dword on both RTX 5070 Ti hardware and WARP, plusdxil.dllvalidation.intersect_tests.rs(no game, console, or SDK files).4340aac):real_directory_memory_path_handles_cross_page_unmapped_and_no_spurious_faultsfails on4340aacwith spurious faults[0x41, 0x42, 0x7ffff]fromkind == 6,kind == 7, andbvh::NONE(0xffff_ffff).wave64_bvh64_intersect_runs_on_wave32_hardware_and_respects_partial_groupsfails on4340aacwith spurious fault[0x60]from trailing lanes45..63of a split wave64 partial group.Checklist
E_NOTIMPL), never a fake success.AI assistance disclosure: This change, its synthetic tests, and GPU measurements were prepared with AI coding assistance (Gemini).
Review follow-up on current
mainThe GPU boundary test covers both
image_bvh_intersect_rayencodings through the realSLOT_MEMORYdirectory. With descriptor word 0 set to0x00ffffff, pointer0x25resolves to0x100000000, and the wide pointer with high word1resolves to0x900000000. The test maps four synthetic pages, compares ordered child pointers and triangle hit/miss words withbvh::intersect, and checks that mapped rays produce zero faults. The triangle hit returns[80, 16, 4, 4], representing a distance of 5 and barycentric weights of 0.25 and 0.25. The boundary and directory tests passed on the RTX 5070 Ti and WARP. The wave64 partial-group test passed on the RTX.With the same test harness on
mainatb62053fe70078deac140ec43039d7ce0af3c6b17, the directory test reproduced false faults for pages0x27,0x41,0x42, and0x7ffff. Lanes 45–63 of the partial wave64 group also incorrectly faulted page0x60. Both tests passed one4ed303d9a527764d54653bb0ad93f59ed6879bd.On the RTX 5070 Ti with driver 621.40, I ran the same 11 workloads in base/head/head/base order. Each workload ran 2,097,152 node tests per dispatch, with 10 warmups and 40 timed dispatches. CPU oracle samples passed and the BLAKE3 hash of every lane's four-word output matched between builds on all 11 workloads. The table shows the first pair in milliseconds.
mainp50 / p95mixed_pc_faultsbox32_2childbox32_8arenasbox32_l1_coherentmixed_pc_faultsrecorded 126 false faults onmainand zero on the PR. The coherent four-child case took roughly 4.4 µs longer in both pairs.A separate control used the same shader, virtual pointers, ray records and output on the RTX. Eight distinct arena buffers took 0.3810 ms at the median. Eight descriptors pointing at a single backing buffer took 0.2862 ms. A single descriptor pointing at that buffer took 0.2793 ms. This isolates most of the eight-arena surcharge to the physical working set in this fixture. The local RT registry contains the reproducible control for the BVH and memory front.
The published head passed 11 filtered intersection tests, 16 CPU BVH tests, the timestamp benchmark, the asset policy check, and Ruff.
AI assistance (Codex) helped write the boundary test, run the measurements, and prepare this report.
Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-27T01:39:51Z.
PortBridge's merge check found
f4828034clean against current receivingb62053fe. I also extracted the arithmetic frombvh_addressinto a CPU model and compared the two-word result against the original u64 expression. Two boundary inputs and 100,000 deterministic 32/64-bit inputs matched. This checks the address formula only.A small additional control for the actual shader would keep the existing 64 KiB-page fixture and add the 4 GiB carry case: descriptor low word
0x00ffffff, descriptor high byte 0, pointer low word0x25. The old u64 expression and the split calculation both give0x100000000; with pointer high word 1 they both give0x900000000. A CPU/address-output fixture can cover that without allocating 4 GiB. This is separate from the existing mixed-arena and partial-group oracle, which would be the first two GPU checks for someone with another adapter. AI-assisted source review and isolated CPU model.Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T01:40:01Z.
Independent check on release RTX 5070 Ti, driver 621.40, at
f482803499f4f10f356922686643cf2f042e6fec. I ran the candidate’s test harness againsta40ed684341fbd2cc6d27c171af9ae27bbc56018, whosevictory-shadersources match parent4340aac1a494b9649c00e0e1ad2c6fbe6ea00e80.0x27,0x41,0x42, and0x7ffff. The partial wave64 group failed with page0x60. Both tests passed on the head on the RTX.VICTORY_WARP=1and the printed adapterMicrosoft Basic Render Driver. The wave64 partial-group result above is from the RTX.I ran the same synthetic directory workload twice per build in base/head/head/base order, 2,097,152 node tests per dispatch, 10 warmups and 40 measured dispatches per case. The CPU oracle passed in all runs. I added nearest-rank p95 reporting to the copied test harness.
mixed_pc_faultsbox32_2childbox32_l1_coherentbox32_onlymixed_pc_faultsdropped from 126 recorded faults to zero. The coherent four-child case was 0.005 ms slower at the median in both pairs; the scattered four-child case was stable. Keep the coherent case in regression coverage.The local registry contains the two
pr476-*-fixture.rsfiles with the matching test harness and thepr476-trace-{base,head}-{a,b}logs with all eleven workload summaries.