feat(rt): AMD hardware BVH ray-node intersection via IntersectBvhNode (VICTORY_HW_BVH=1) #317
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!317
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-317"
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?
@MeMako on GitHub · 2026-11-26 16:14 UTC · original
MeMako:pr/amd-hw-bvh-110→main· +868 −32 · 11 files · 1 commits · openImplements opt-in AMD hardware BVH4 ray-node intersection (
VICTORY_HW_BVH=1) forimage_bvh_intersect_rayandimage_bvh64_intersect_ray, closing #110.Summary of Changes
victory-shader/src/emit/host.rs,victory-gpu/src/host.rs):adapter_desc.VendorId == 0x1002, non-software adapter, andD3D12_RAYTRACING_TIER >= D3D12_RAYTRACING_TIER_1_0(D3D12_FEATURE_D3D12_OPTIONS5) before touchingamdxc64.dll—preventing foreign-device calls on mixed AMD iGPU + NVIDIA dGPU systems and preventing pre-RDNA 2 (GCN / RDNA 1) GPUs from taking the hardware path.AmdExtD3DCreateInterfacefrom the already-loadedamdxc64.dllviaGetModuleHandleA/GetProcAddress, acquiresIAmdExtD3DFactory→IAmdExtD3DShaderIntrinsics, checks support, and callsEnable(). Held onHostviaAmdExtGuardfor the device lifetime and released cleanly via COMRelease()on drop. Falls back silently to software BVH on unsupported adapters/drivers.gfx1201) vs RDNA 2/3 note: Verified live on Radeon RX 9070 XT (RDNA 4, driver32.0.32029.2010), whereCheckSupport(0x19)(IntersectBvhNode) returnsE_NOINTERFACEwhileCheckSupport(0x0D)returnsS_OKand opcode0x22compiles natively to hardware BVH4 intersection.CheckSupport(0x19)is wired for RDNA 2/3 alongside the DXR-gated0x0Dfallback, though RDNA 2/3 silicon has not been tested locally yet—an RX 7900 XTX verification pass would be great!victory-gpu/src/memory.rs,victory-shader/src/emit/shader.rs): Doubles the directory buffer (16 MiB→32 MiB,+16 MiB) to store a parallel 64-bit host GPU VA per mapped 64 KiB page atMEMORY_VA_OFFSET.Memory::copiesis append-only for process lifetime (never drops a backingID3D12Resource), andgone()clears bothva_entryandentryto0before returning slots toself.free, ensuring no in-flight command list can traverse a freedID3D12ResourceVA.victory-shader/src/emit/intersect.rs): WhenVICTORY_HW_BVH=1is active, looks up the host 64-bit page VA, notes unmapped pages inSLOT_FAULTS, validates 64-byte alignment of bothva_loandwithin(((va_lo | within) & 63) == 0) plus in-page bounds (within <= 0xFF80for 128-byte box32,within <= 0xFFC0for 64-byte nodes), computesnodePointer = ((page_va + within) >> 3) | kind, and emits theIntersectBvhNode(0x22) magic UAV atomic sequence (u0, space2147420894,BoxSortEnable | ReturnBarycentrics). Unaligned or page-straddling nodes fall back cleanly to the software path.victory-gpu/src/pipeline/host.rs,draw.rs,shader_cache.rs): Adds theSLOT_AMD_EXTroot UAV binding (u0, space2147420894) and keys the shader cache dynamically onVICTORY_HW_BVH=1+ opcode so default software caches are untouched (the firstVICTORY_HW_BVH=1launch warms a fresh cache).Verification (based on
origin/mainc9c932c)cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.cargo clippy -p victory-gpu --all-targets --locked: 0 warnings in all modified files (1 pre-existing warning in untouchedwatch.rs:3626onorigin/main).VICTORY_HW_BVHunset ANDVICTORY_HW_BVH=1):cargo test -p victory-shader --lib intersect_tests --locked: 10/10 passed on RX 9070 XT (includingamd_hw_bvh_directory_form_lowers_and_validateswithdxil.dllandamd_hw_bvh_matches_the_reference_on_the_cardacross all 352 box32/box16/triangle/sorted/unsorted/32-bit/64-bit/masked cases).cargo test -p victory-gpu --lib memory:: --locked: 2/2 passed.cargo test -p victory-gpu --lib pipeline:: --locked: 25/25 passed.cargo test -p victory-gpu --lib shader_cache:: --locked: 3/3 passed.10.0.26200, Ryzen 9 7950X, Radeon RX 9070 XT, driver32.0.32029.2010,-PortCbv, two ~5-minute sessions):~54 msGPU busy →~29.7 msGPU busy), moving steady-state FPS from15.4–17.4 FPS→20.4–21.6 FPS(and heavier scenes from13.7–15.4 FPS→16.9–19.7 FPS, now CPU-bound with GPU at 60–82% busy).Human-owned contribution: all design decisions, hardware testing, and code review were performed by me; AI coding assistance was used during implementation and drafting.
@Calvix2k on GitHub · 2026-11-26 18:50 UTC · original
Useful direction for the picture, not just for ray-traced effects: in the prologue's heavy view our log reports ~340 draws a frame dropped with "a stage of the ray-tracing structure builder, which is off" - that is the missing geometry, not a shader gap. Enabling the builder today trades that geometry for frame time.
On an RX 7800 XT (RDNA3, Windows 10 22H2) the heavy frame is 167 ms at ~6,800 draws with GPU ~95 ms. So the number that decides this PR for us is the cost of the builder when it runs: if
VICTORY_HW_BVH=1brings the build within a few ms, the ~340 draws come back for almost nothing. A before/after measurement of the builder with the switch on would be very welcome.@MeMako on GitHub · 2026-11-26 22:22 UTC · original
Great question—happy to break down what
VICTORY_HW_BVH=1does and doesn't speed up, plus share a 3-way measurement from my RX 9070 XT:BVH building vs. ray traversal: When
VICTORY_BVH_BUILDERis unset (off), VIctory's log rolls the title's skipped RT compute dispatches into the same"draws dropped"counter ("a stage of the ray-tracing structure builder, which is off"—those are the title's RT compute passes for building/refitting acceleration structures and tracing bounce light/shadows, rather than rasterized scene meshes).VICTORY_HW_BVH=1specifically accelerates the traversal / ray-node intersection shaders (image_bvh_intersect_ray/image_bvh64_intersect_ray) via AMD's hardwareIntersectBvhNodeintrinsic. The BVH builder compute passes themselves are standard compute shaders without ray-intersect ops, so they keep their own GPU cost (along with the existing ~3.4 ms/frame CPUmemory.rspage tracking that runs wheneverVICTORY_BVH_BUILDER=1is enabled, independent ofVICTORY_HW_BVH).3-way GPU busy time on RX 9070 XT (1080p,
-Console series-x -PortCbv, fresh back-to-back A/B/C runs across the same lighter and heavier indoor scenes at matching draw counts; the PR description's~54 ms -> ~29.7 msfigure was from an earlier single-scene pair):VICTORY_BVH_BUILDERunset):~20–22 msGPU busy (lighter scene, ~4.5k–5.4k draws) /~22–28 ms(heavier scene, ~6.2k–7.0k draws)VICTORY_HW_BVHunset):~35–37 msGPU busy (lighter scene, ~4.4k–5.9k draws;18.0–19.5 fps) /~57–65 ms(heavier scene, ~8.7k–10.7k draws;13.6–15.4 fps)VICTORY_HW_BVH=1):~29–31 msGPU busy (lighter scene, ~4.6k–5.3k draws;19.5–20.7 fps) /~45–48 ms(heavier scene, ~7.4k–10.2k draws;16.3–18.7 fps)So
VICTORY_HW_BVH=1shaves~6 msin the lighter scene and~12–17 msin the heavier scene—cutting the net RT-on GPU overhead by ~35–45%—though it won't reduce the builder passes down to a few ms on its own.RDNA 3 (RX 7800 XT) note: On the clean-room upstream PR (
Marvisak/VIctory#3294), an independent RX 7800 XT tester (@oni-swr) already confirmedCheckSupport(0x19)returnsS_OKandopcode=0x22passes all 16/16 synthetic BVH GPU tests, and a Radeon 780M (RDNA 3 iGPU,@kilolimaVI) measured372.97 ms -> 120.92 mson the--releasesynthetic BVH64 microbenchmark (536.8M ray-node intersections/dispatch, median of 5; isolated intersection throughput, not whole-frame FPS). Since nobody has tested#317on a live scene on RDNA 3 yet, if you have a chance to throw this branch at your RX 7800 XT heavy frame withVICTORY_BVH_BUILDER=1+VICTORY_HW_BVH=1, a live before/after datapoint there would be awesome!Comment drafted with Antigravity.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.