Shaders/GPU: opt-in AMD hardware BVH ray-node intersection (VICTORY_HW_BVH=1) #3294
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3294
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@MeMako on GitHub · 2026-11-26 16:13 UTC · original
MeMako:pr/amd-hw-bvh→main· +1069 −43 · 19 files · 1 commits · openAdds 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.
@Aniseto on GitHub · 2026-11-26 16:27 UTC · original
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.
@Dukestar69 on GitHub · 2026-11-26 17:31 UTC · original · approved these changes
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).
@oni-swr on GitHub · 2026-11-26 19:28 UTC · original
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).
@kilolimaVI on GitHub · 2026-11-26 21:12 UTC · original
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).
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.