Shaders/GPU: opt-in AMD hardware BVH ray-node intersection (VICTORY_HW_BVH=1) #3294
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3294"
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 Marvisak/VIctory. Originally posted by MeMako on 2026-11-26T16:13:33Z.
Adds an opt-in AMD hardware BVH4 ray-node intersection path (
VICTORY_HW_BVH=1) forimage_bvh_intersect_rayandimage_bvh64_intersect_rayvia AMD's D3D12IAmdExtD3DShaderIntrinsics(IntersectBvhNode) extension.Default behavior when
VICTORY_HW_BVHis unset is unchanged (zero extra allocations, zero root-signature changes, existing software BVH path untouched).Design
victory-shader/src/emit/host.rs,victory-gpu/src/host.rs):VICTORY_HW_BVH=1(and not WARP), verifiesadapter_desc.VendorId == 0x1002, non-software adapter, andD3D12_RAYTRACING_TIER >= D3D12_RAYTRACING_TIER_1_0(D3D12_FEATURE_D3D12_OPTIONS5) before resolvingamdxc64.dllviaGetModuleHandleA/GetProcAddress. This prevents handing foreign devices toAmdExtD3DCreateInterfaceon mixed-GPU systems and prevents pre-RDNA 2 (GCN / RDNA 1) cards from taking the hardware path.IAmdExtD3DFactory→IAmdExtD3DShaderIntrinsics, checks support (0x19wired for RDNA 2/3, or DXR-gated0x0Dfor RDNA 4 where0x19returnsE_NOINTERFACEwhile opcode0x22compiles natively to hardware BVH4; verified live on RX 9070 XT / RDNA 4, untested on RDNA 2/3 silicon), and callsEnable(). Both COM interfaces are held inAmdExtGuardonHostfor the device lifetime and cleanlyRelease()d on drop. Silently falls back to software BVH on non-AMD adapters, WARP, or unsupported drivers.victory-gpu/src/memory.rs,victory-shader/src/emit/shader.rs):memory::Sharedallocates a parallelt3(MEMORY_VAS) buffer inMEMORY_SPACEholding one 64-bit host GPU VA per level-2 page entry. Only whole 64 KiB pages whose host GPU VA is 64-byte aligned receive a non-zero VA; unmapped, partial, or unaligned pages store0.Shared::rewriteruns only while no submission is in flight, overwrites every active level-2 slot (clearing removed/unowned entries to0), keepsArc<Shadow>alive inShared::layout, andbind()retains the VA buffer on eachHostListvialist.keep(&va_res)—preventing any in-flight command list from dereferencing a freedID3D12ResourceVA.victory-shader/src/emit/lower/bvh.rs):Nodes::RawBVHs when hardware BVH is active, looks up the 64-bit page VA int3using the existingmemory_pageindex, validates 64-byte alignment of bothva_loandwithin(((va_lo | within) & 63) == 0) and in-page bounds (within <= 0xFF80for 128-byte box32,within <= 0xFFC0for 64-byte nodes), computesnodePointer = ((page_va + within) >> 3) | kind, and emits theIntersectBvhNode(0x22,BoxSortEnable | ReturnBarycentrics) magic UAV atomic sequence (u0inAMD_EXT_SPACE = 2147420894).bvh_lanessoftware path, preserving exact miss-bitmap reporting and bounds-checked reads.victory-gpu/src/pipeline/host.rs,draw.rs,shader_cache.rs):HostShader::amd_bvh(bit 6 in the cache entry flags), bindst3(MEMORY_VAS) andu0(AMD_EXT_SPACE) only on stages emitting hardware BVH, and keys the shader cache on the active hardware BVH opcode. Becauseshader_cache.rshashesENCODING = include_bytes!("shader_cache.rs")into the cache key and subdirectory, existing caches from earlier builds are isolated cleanly and never fail deserialization on upgrade.Verification (rebased on
origin/main63bcca4)cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo run --locked -p xtask -- policy: 191 files ok.10.0.26200, Radeon RX 9070 XT, driver32.0.32029.2010):cargo test --workspace --locked(VICTORY_HW_BVHunset): all passed.VICTORY_HW_BVH=1 cargo test -p victory-shader --lib bvh_tests --locked -- --nocapture: 16/16 passed, includingamd_hw_bvh_lowers_and_validates(dxil.dllvalidated) andamd_hw_bvh_matches_the_reference_on_the_gpu(live hardware execution viaMEMORY_VAS+opcode=0x22matching CPU reference for both 32-bit and 64-bit pointers).VICTORY_HW_BVH=1 cargo test -p victory-gpu --lib --locked -- --test-threads=1: 232 passed, 0 failed, 1 ignored (including newmemory::tests::va_table_populates_aligned_whole_pages_onlyand updatedshader_cache::tests).bvh_tests::amd_hw_bvh_throughput_benchmark,--ignored):cargo test -p victory-shader --lib amd_hw_bvh_throughput_benchmark --locked -- --ignored --nocapture536,862,720mixed box32/box16/triangleimage_bvh64_intersect_raytests per dispatch ([65535, 32, 1] × 256, median of 5 dispatches including per-dispatch D3D12 harness overhead) on RX 9070 XT:bvh_lanes):31.16 ms(17,231.7 Mrays/s)IntersectBvhNode,opcode=0x22viaMEMORY_VAS):20.62 ms(26,031.5 Mrays/s) —1.51×wall-clock speedupavatarmanz/VIctory-7900XTX, on this RX 9070 XT, reducing GPU busy time ~1.8× (~54 ms→~29.7 ms) with visual parity and 0 crashes / 0 device removals.)Human-owned contribution: all design decisions, hardware testing, and code review were performed by me; AI coding assistance was used during implementation and drafting.
Imported from Marvisak/VIctory. Originally posted by Aniseto on 2026-11-26T16:27:35Z.
Ran the BVH tests at
8c919e6on an NVIDIA Blackwell desktop part withVICTORY_HW_BVHunset:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.The second command prints
AMD IntersectBvhNode extension unavailable on this adapter; skippedand returns early: the hardware BVH path is not exercised on this NVIDIA card.amd_hw_bvh_throughput_benchmarkisignored. What did run here are the software BVH GPU tests and the CPU reference tests; all passed. The PR has no comments yet, so this is a first datapoint: the default path still works on a Blackwell NVIDIA adapter and the guarded probe refuses this adapter instead of calling the AMD extension.Not tested: real AMD hardware BVH (
IntersectBvhNode, opcodes 0x19 and 0x22),VICTORY_HW_BVH=1on any adapter, the ignored throughput benchmark, the full workspace suite, a paired smoke run, Intel GPUs, native wave64 hosts, Wine, release profile, game data.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T17:31:04Z.
Review: APPROVED
Reviewed and verified locally on Windows 11 x64 (NVIDIA RTX 5090):
VICTORY_HW_BVH=1leaves the default software BVH path intact on non-AMD GPUs and cleanly lowers and validates the AMD hardware BVH DXIL path.cargo test -p victory-shader --lib emit::bvh_tests:: -- --test-threads=1(RTX 5090): 16 passed, 0 failed, 1 ignored (amd_hw_bvh_lowers_and_validatesvalidated cleanly;amd_hw_bvh_matches_the_reference_on_the_gpucleanly skipped on NVIDIA; all software BVH GPU tests passed on RTX 5090).cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T19:28:37Z.
Independent AMD RDNA3 verification of #3294 at
8c919e6a03e58694510668e67267684fd2af0aec(base/control:main63bcca43). Synthetic tests only.Environment: Windows 11 build 26200 x64, AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003,
amdxc64.dll8.18.10.0504, rustc 1.98.1. Physical adapter (VICTORY_D3D12_WARP/VICTORY_WARPunset). Debug test profile,--locked -j 4.Static (CPU):
cargo clippy --workspace --all-targets --locked -- -D warningsclean;cargo run -p xtask -- policyok; test binaries build.Results on the RX 7800 XT:
VICTORY_HW_BVH=1victory-shader --lib bvh_tests(--test-threads=1)VICTORY_HW_BVH=1victory-gpu --libVICTORY_HW_BVHunsetbvh_tests63bcca43bvh_tests, unset and=1amd_hw_bvh_matches_the_reference_on_the_gpuactually ran on hardware (not skipped):opcode=0x22, matched reference for both node layouts (wide=false: 146 boxes / 20 triangles hit; wide=true: 146 boxes / 16 triangles hit).eprintln!(not committed) bothCheckSupport(0x19)andCheckSupport(0x0D)returned S_OK on this RDNA3 part, so 0x19 is satisfied; the emitted opcode is 0x22 either way.amd_hw_bvh_throughput_benchmark, 536,862,720 ray-node tests/dispatch, median of 5, debug profile): software 48.90 ms (10977.9 Mrays/s) vs hardware 42.63 ms (12592.3 Mrays/s), 1.15x. Single run on one machine; treat as indicative.Not tested: no game files or real titles, so the page-VA lookup and fallback paths were only exercised by the synthetic tests; no other RDNA generation (RDNA2/RDNA4); no release-profile numbers; only a small number of benchmark runs.
AI use: Claude Code (Claude Sonnet 5.5).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-26T21:12:10Z.
Tested on AMD hardware the CI can't cover: Windows 11, AMD Radeon 780M (RDNA3 iGPU, Ryzen 7 8845HS), toolchain 1.98.1, branch as-is.
amd_hw_bvh_lowers_and_validatesandamd_hw_bvh_matches_the_reference_on_the_gpupass without the "extension unavailable ... skipped" path.amd_hw_bvh_throughput_benchmark(--release --ignored --nocapture): BVH64, 536,862,720 ray-node tests per dispatch, median of 5: software 372.97 ms (1439.4 Mrays/s), hardware (opcode 0x22) 120.92 ms (4439.9 Mrays/s), 3.08x.cargo test -p victory-shader --lib --locked --no-fail-fast -- --test-threads=1: 304 passed, 0 failed (main: 302 passed).AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-26T22:59:24Z.
RDNA 2 verification of #3294 at
8c919e6(the description lists RDNA 2 as untested). Synthetic tests only.Environment: Windows 11 Pro build 26200 x64, AMD Radeon RX 6900 XT (RDNA 2, Navi 21), driver 32.0.21045.29003,
amdxc64.dll8.18.10.0500, Ryzen 5 5600X, rustc 1.98.1 (pinned). Physical adapter (VICTORY_D3D12_WARP/VICTORY_WARPunset), release profile, a fresh target directory for this head.With
VICTORY_HW_BVH=1:victory-shader --lib bvh_tests(--test-threads=1)victory-gpu --lib(--test-threads=1)amd_hw_bvh_matches_the_reference_on_the_gpuran on the hardware path, not the "extension unavailable" skip:opcode=0x22, matched the reference for both layouts (wide=false: 146 boxes / 20 triangles hit; wide=true: 146 boxes / 16 triangles hit), the same counts as the RX 7800 XT report above.memory::tests::va_table_populates_aligned_whole_pages_onlypassed.So on this RDNA 2 part the gate takes the hardware path and its results match the reference.
Throughput (
amd_hw_bvh_throughput_benchmark,--release --ignored, 536,862,720 ray-node tests per dispatch, each run the median of 5 dispatches), 12 runs:On this card the gain is small and run-to-run spread covers part of it, closer to the RX 7800 XT's 1.15x than to the 780M's 3.08x.
Not tested: the title, the debug profile, and which
CheckSupportopcode (0x19 or 0x0D) succeeded here (not probed).Tested with Claude Code.
Imported from Marvisak/VIctory. Originally posted by zhu1025960209-web on 2026-11-26T23:23:50Z.
RDNA 2 (RX 6700 XT / Navi 22) silicon verification + live 3D world A/B results (following up on the RDNA 2 /
0x19vs0x0D/ real-workload questions above).Environment
32.0.21045.2900322631x64, Xeon E5-2696 v3 (16T)#3294'senable_amd_bvhprobe,IntersectBvhNode(opcode=0x22) lowering, andAMD_EXT_SPACEbindings onto our local AMD fork (c9c932c-based, which uses a flat 1-level 16 MiB VRAM-sideSLOT_MEMORY_VASpage table instead ofmain's 2-level page table) so we could measure a real 3D title workload end-to-end.1. RDNA 2 Extension Probe & Silicon Correctness
CheckSupporton RDNA 2:0x19(SUPPORT_INTERSECT_BVH_NODE) returnsS_OKdirectly on RX 6700 XT (32.0.21045.29003), emittingopcode=0x22without needing the0x0Dfallback.intersect_tests, physical AMD adapter): Passed all three layouts (bvh64-sorted,bvh32-sorted,bvh32-unsorted— 106 box hits & 85 triangle hits each, zero device removals).flags_val: Usingu32::from(sort) | 2instead of hardcoded3preservesBoxSortEnablefor descriptors withBOX_SORTcleared (bvh32-unsorted).enter <= extent(and0 * infgrazing semantics without clampinginvtof32::MAX), and preserves geometric[v0, v1, v2]winding on odd(i, j)barycentric permutations rather than flippingdet's sign.2. Synthetic vs Live 3D World A/B (Why Real RT Gains Much More Than the Microbench)
134Mray-node tests, median of 5):gpu=8.69 ms -> 8.19 ms(1.06x), consistent with the RX 6900 XT (1.10x) and RX 7800 XT (1.15x) microbench reports above — the 1-step synthetic kernel is bottlenecked by upload-heap reads & L2 UAV write contention rather than BVH traversal ALU.VICTORY_BVH_BUILDER=1, all 53 BVH builder pipelines + 16 RT ray-tracing dispatches/frame + ~266 BVH builds/frame, ~1.1 GB live BVH4 structures in 20–21 arenas,dropped 1, 7 consecutive steady-state 5-second windows = 35s each, 0 crashes / 0 TDR / 0 device removals):7.4 fps134.8 ms57.0 ms0 ms48.1 ms19.4 msVICTORY_HW_BVH=0)4.57 fps(4.7)219.4 ms98.8 ms+41.8 ms87.7 ms22.6 msVICTORY_HW_BVH=1)5.69 fps(5.9)176.2 ms(168.5 ms)71.7 ms+14.7 ms73.9 ms19.4 ms+24.5%(+25.5%peak)-43.2 ms/frame-27.1 ms(-27.4%)~2.84xfaster RT-13.8 ms-3.2 msIn multi-step real-world BVH4 traversal loops, AMD's RDNA 2 Ray Accelerators deliver a huge, rock-solid GPU speedup (
-27.1 msGPU, ~2.84x faster RT-only GPU time) even though the 1-step synthetic microbench only shows ~1.06x–1.10x on discrete RDNA 2 cards.(Note: not tested directly on
origin/main's 2-level page table; live 3D test ran on the flat 1-level VRAM-side VA table port.)AI-assisted (Antigravity).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:39:40Z.
Review: APPROVED
Looks solid. The opt-in AMD hardware BVH intersection path (
VICTORY_HW_BVH=1) is cleanly isolated behind feature detection, keeps default-off software lowering unchanged, handles mixed-GPU vendor/DXR checks safely, and properly falls back to softwarebvh_lanesfor unmapped, partial, unaligned, and page-straddling 128-bytebox32nodes.Verified on commit
8c919e6a03e58694510668e67267684fd2af0aec:cargo xtask policypassed (191 files ok),emit/lower.rsstays under the 512 KiB size limit (522,300bytes), andcargo clippy(--lib,--tests, and--features diagnostics --tests,-D warnings) passed for bothvictory-shaderandvictory-gpu.0x10de,VICTORY_D3D12_DEBUG=1+dxil.dll):victory-shaderbvh_testspassed 16/16 (amd_hw_bvh_lowers_and_validatesvalidated cleanly viadxil.dll), andenable_amd_bvhreturnedNoneeven withamdxc64.dllpresent in-process.VICTORY_D3D12_DEBUG=1+VICTORY_D3D12_WARP=1+VICTORY_HW_BVH=1):enable_amd_bvhreturnedNone,bvh_testspassed 16/16, andvictory-gpu --features diagnosticsmemory::tests+shader_cache::testspassed 13/13 (includingva_table_populates_aligned_whole_pages_onlyandlists_share_a_table_and_copies_keep_their_views).0x1002:0x13c0, DXR Tier 1.1):enable_amd_bvhenabled opcode0x22, live hardwareIntersectBvhNodematched the reference for both 32-bit (146boxes,20triangles) and 64-bit (146boxes,16triangles) pointers, and a targeted D3D12 Debug Layer test verified exact results on an in-page HWbox32(0x8000), a page-straddling SW-fallbackbox32(0xFFC0), and an unmapped page (0x20000) with zero debug-layer errors.Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T12:01:13Z.
Correction to my earlier 780M number. Repeated
amd_hw_bvh_throughput_benchmark(--release --ignored, BVH64, 536,862,720 ray-node tests per dispatch, median of 5 each) 12 times on head8c919e6, AMD Radeon 780M (RDNA3 iGPU), Windows 11:So the single 3.08x run I posted was high: its software time (373 ms) was an outlier, likely a power/clock state on the laptop. The repeatable figure here is about 2.2x, still roughly twice the gain the discrete RDNA 2/3 cards show in this microbench (1.06x - 1.15x above), with a narrow spread (no run near 1.0x).
AI-assisted (Claude).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.