Shaders/GPU: opt-in AMD hardware BVH ray-node intersection (VICTORY_HW_BVH=1) #3294

Open
MeMako wants to merge 1 commit from upstream-pr/3294 into main
MeMako commented 2026-11-26 16:13:33 +00:00 (Migrated from github.com)

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) for image_bvh_intersect_ray and image_bvh64_intersect_ray via AMD's D3D12 IAmdExtD3DShaderIntrinsics (IntersectBvhNode) extension.

Default behavior when VICTORY_HW_BVH is unset is unchanged (zero extra allocations, zero root-signature changes, existing software BVH path untouched).

Design

  • Guarded extension probe & COM lifetime (victory-shader/src/emit/host.rs, victory-gpu/src/host.rs):
    • When VICTORY_HW_BVH=1 (and not WARP), verifies adapter_desc.VendorId == 0x1002, non-software adapter, and D3D12_RAYTRACING_TIER >= D3D12_RAYTRACING_TIER_1_0 (D3D12_FEATURE_D3D12_OPTIONS5) before resolving amdxc64.dll via GetModuleHandleA/GetProcAddress. This prevents handing foreign devices to AmdExtD3DCreateInterface on mixed-GPU systems and prevents pre-RDNA 2 (GCN / RDNA 1) cards from taking the hardware path.
    • Acquires IAmdExtD3DFactory → IAmdExtD3DShaderIntrinsics, checks support (0x19 wired for RDNA 2/3, or DXR-gated 0x0D for RDNA 4 where 0x19 returns E_NOINTERFACE while opcode 0x22 compiles natively to hardware BVH4; verified live on RX 9070 XT / RDNA 4, untested on RDNA 2/3 silicon), and calls Enable(). Both COM interfaces are held in AmdExtGuard on Host for the device lifetime and cleanly Release()d on drop. Silently falls back to software BVH on non-AMD adapters, WARP, or unsupported drivers.
  • Parallel page GPU VA table & lifetime safety (victory-gpu/src/memory.rs, victory-shader/src/emit/shader.rs):
    • Only when hardware BVH is active, memory::Shared allocates a parallel t3 (MEMORY_VAS) buffer in MEMORY_SPACE holding 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 store 0.
    • Shared::rewrite runs only while no submission is in flight, overwrites every active level-2 slot (clearing removed/unowned entries to 0), keeps Arc<Shadow> alive in Shared::layout, and bind() retains the VA buffer on each HostList via list.keep(&va_res)—preventing any in-flight command list from dereferencing a freed ID3D12Resource VA.
  • Hardware lowering with safe software fallback (victory-shader/src/emit/lower/bvh.rs):
    • For Nodes::Raw BVHs when hardware BVH is active, looks up the 64-bit page VA in t3 using the existing memory_page index, validates 64-byte alignment of both va_lo and within (((va_lo | within) & 63) == 0) and in-page bounds (within <= 0xFF80 for 128-byte box32, within <= 0xFFC0 for 64-byte nodes), computes nodePointer = ((page_va + within) >> 3) | kind, and emits the IntersectBvhNode (0x22, BoxSortEnable | ReturnBarycentrics) magic UAV atomic sequence (u0 in AMD_EXT_SPACE = 2147420894).
    • Unmapped pages, partial/unaligned copies, and page-straddling nodes branch directly to the existing bvh_lanes software path, preserving exact miss-bitmap reporting and bounds-checked reads.
  • Pipeline bindings & shader-cache compatibility (victory-gpu/src/pipeline/host.rs, draw.rs, shader_cache.rs):
    • Adds HostShader::amd_bvh (bit 6 in the cache entry flags), binds t3 (MEMORY_VAS) and u0 (AMD_EXT_SPACE) only on stages emitting hardware BVH, and keys the shader cache on the active hardware BVH opcode. Because shader_cache.rs hashes ENCODING = 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/main 63bcca4)

  • Static & policy checks:
    • 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.
  • Test suites (Windows 11 10.0.26200, Radeon RX 9070 XT, driver 32.0.32029.2010):
    • Full cargo test --workspace --locked (VICTORY_HW_BVH unset): all passed.
    • VICTORY_HW_BVH=1 cargo test -p victory-shader --lib bvh_tests --locked -- --nocapture: 16/16 passed, including amd_hw_bvh_lowers_and_validates (dxil.dll validated) and amd_hw_bvh_matches_the_reference_on_the_gpu (live hardware execution via MEMORY_VAS + opcode=0x22 matching 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 new memory::tests::va_table_populates_aligned_whole_pages_only and updated shader_cache::tests).
  • Standalone GPU throughput microbenchmark (bvh_tests::amd_hw_bvh_throughput_benchmark, --ignored):
    • Command (debug build): cargo test -p victory-shader --lib amd_hw_bvh_throughput_benchmark --locked -- --ignored --nocapture
    • Workload: 536,862,720 mixed box32/box16/triangle image_bvh64_intersect_ray tests per dispatch ([65535, 32, 1] × 256, median of 5 dispatches including per-dispatch D3D12 harness overhead) on RX 9070 XT:
      • Software (bvh_lanes): 31.16 ms (17,231.7 Mrays/s)
      • Hardware (IntersectBvhNode, opcode=0x22 via MEMORY_VAS): 20.62 ms (26,031.5 Mrays/s) — 1.51× wall-clock speedup
    • (Cross-check note: live world RT frame-time parity was also cross-checked with the equivalent lowering in a live RT-capable fork, avatarmanz/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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5513460304 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294). Originally posted by [MeMako](https://github.com/MeMako) on 2026-11-26T16:13:33Z. --- Adds an opt-in AMD hardware BVH4 ray-node intersection path (`VICTORY_HW_BVH=1`) for `image_bvh_intersect_ray` and `image_bvh64_intersect_ray` via AMD's D3D12 `IAmdExtD3DShaderIntrinsics` (`IntersectBvhNode`) extension. Default behavior when `VICTORY_HW_BVH` is unset is unchanged (zero extra allocations, zero root-signature changes, existing software BVH path untouched). ### Design - **Guarded extension probe & COM lifetime (`victory-shader/src/emit/host.rs`, `victory-gpu/src/host.rs`):** - When `VICTORY_HW_BVH=1` (and not WARP), verifies `adapter_desc.VendorId == 0x1002`, non-software adapter, and `D3D12_RAYTRACING_TIER >= D3D12_RAYTRACING_TIER_1_0` (`D3D12_FEATURE_D3D12_OPTIONS5`) before resolving `amdxc64.dll` via `GetModuleHandleA`/`GetProcAddress`. This prevents handing foreign devices to `AmdExtD3DCreateInterface` on mixed-GPU systems and prevents pre-RDNA 2 (GCN / RDNA 1) cards from taking the hardware path. - Acquires `IAmdExtD3DFactory` → `IAmdExtD3DShaderIntrinsics`, checks support (`0x19` wired for RDNA 2/3, or DXR-gated `0x0D` for RDNA 4 where `0x19` returns `E_NOINTERFACE` while opcode `0x22` compiles natively to hardware BVH4; verified live on RX 9070 XT / RDNA 4, untested on RDNA 2/3 silicon), and calls `Enable()`. Both COM interfaces are held in `AmdExtGuard` on `Host` for the device lifetime and cleanly `Release()`d on drop. Silently falls back to software BVH on non-AMD adapters, WARP, or unsupported drivers. - **Parallel page GPU VA table & lifetime safety (`victory-gpu/src/memory.rs`, `victory-shader/src/emit/shader.rs`):** - Only when hardware BVH is active, `memory::Shared` allocates a parallel `t3` (`MEMORY_VAS`) buffer in `MEMORY_SPACE` holding 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 store `0`. - `Shared::rewrite` runs only while no submission is in flight, overwrites every active level-2 slot (clearing removed/unowned entries to `0`), keeps `Arc<Shadow>` alive in `Shared::layout`, and `bind()` retains the VA buffer on each `HostList` via `list.keep(&va_res)`—preventing any in-flight command list from dereferencing a freed `ID3D12Resource` VA. - **Hardware lowering with safe software fallback (`victory-shader/src/emit/lower/bvh.rs`):** - For `Nodes::Raw` BVHs when hardware BVH is active, looks up the 64-bit page VA in `t3` using the existing `memory_page` index, validates 64-byte alignment of both `va_lo` and `within` (`((va_lo | within) & 63) == 0`) and in-page bounds (`within <= 0xFF80` for 128-byte box32, `within <= 0xFFC0` for 64-byte nodes), computes `nodePointer = ((page_va + within) >> 3) | kind`, and emits the `IntersectBvhNode` (`0x22`, `BoxSortEnable | ReturnBarycentrics`) magic UAV atomic sequence (`u0` in `AMD_EXT_SPACE = 2147420894`). - Unmapped pages, partial/unaligned copies, and page-straddling nodes branch directly to the existing `bvh_lanes` software path, preserving exact miss-bitmap reporting and bounds-checked reads. - **Pipeline bindings & shader-cache compatibility (`victory-gpu/src/pipeline/host.rs`, `draw.rs`, `shader_cache.rs`):** - Adds `HostShader::amd_bvh` (bit 6 in the cache entry flags), binds `t3` (`MEMORY_VAS`) and `u0` (`AMD_EXT_SPACE`) only on stages emitting hardware BVH, and keys the shader cache on the active hardware BVH opcode. Because `shader_cache.rs` hashes `ENCODING = 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/main` `63bcca4`) - **Static & policy checks:** - `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**. - **Test suites (Windows 11 `10.0.26200`, Radeon RX 9070 XT, driver `32.0.32029.2010`):** - Full `cargo test --workspace --locked` (`VICTORY_HW_BVH` unset): **all passed**. - `VICTORY_HW_BVH=1 cargo test -p victory-shader --lib bvh_tests --locked -- --nocapture`: **16/16 passed**, including `amd_hw_bvh_lowers_and_validates` (`dxil.dll` validated) and `amd_hw_bvh_matches_the_reference_on_the_gpu` (live hardware execution via `MEMORY_VAS` + `opcode=0x22` matching 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 new `memory::tests::va_table_populates_aligned_whole_pages_only` and updated `shader_cache::tests`). - **Standalone GPU throughput microbenchmark (`bvh_tests::amd_hw_bvh_throughput_benchmark`, `--ignored`):** - Command (debug build): `cargo test -p victory-shader --lib amd_hw_bvh_throughput_benchmark --locked -- --ignored --nocapture` - Workload: `536,862,720` mixed box32/box16/triangle `image_bvh64_intersect_ray` tests per dispatch (`[65535, 32, 1] × 256`, median of 5 dispatches including per-dispatch D3D12 harness overhead) on RX 9070 XT: - Software (`bvh_lanes`): **`31.16 ms`** (`17,231.7 Mrays/s`) - Hardware (`IntersectBvhNode`, `opcode=0x22` via `MEMORY_VAS`): **`20.62 ms`** (`26,031.5 Mrays/s`) — **`1.51×`** wall-clock speedup - *(Cross-check note: live world RT frame-time parity was also cross-checked with the equivalent lowering in a live RT-capable fork, `avatarmanz/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 commented 2026-11-26 16:27:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Aniseto on 2026-11-26T16:27:35Z.


Ran the BVH tests at 8c919e6 on an NVIDIA Blackwell desktop part with VICTORY_HW_BVH unset:

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.

cargo test -p victory-shader --lib emit::bvh_tests -- --test-threads=1
16 passed; 0 failed; 1 ignored; 0 measured; 291 filtered out      (exit 0)

cargo test -p victory-shader --lib emit::bvh_tests::amd_hw_bvh_matches_the_reference_on_the_gpu -- --exact --nocapture --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 307 filtered out      (exit 0)

The second command prints AMD IntersectBvhNode extension unavailable on this adapter; skipped and returns early: the hardware BVH path is not exercised on this NVIDIA card. amd_hw_bvh_throughput_benchmark is ignored. 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=1 on 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197673009 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#issuecomment-7197673009). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-26T16:27:35Z. --- Ran the BVH tests at `8c919e6` on an NVIDIA Blackwell desktop part with `VICTORY_HW_BVH` unset: 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. ``` cargo test -p victory-shader --lib emit::bvh_tests -- --test-threads=1 16 passed; 0 failed; 1 ignored; 0 measured; 291 filtered out (exit 0) cargo test -p victory-shader --lib emit::bvh_tests::amd_hw_bvh_matches_the_reference_on_the_gpu -- --exact --nocapture --test-threads=1 1 passed; 0 failed; 0 ignored; 0 measured; 307 filtered out (exit 0) ``` The second command prints `AMD IntersectBvhNode extension unavailable on this adapter; skipped` and returns early: the hardware BVH path is **not** exercised on this NVIDIA card. `amd_hw_bvh_throughput_benchmark` is `ignored`. 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=1` on 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 commented 2026-11-26 17:31:04 +00:00 (Migrated from github.com)

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):

  • Opt-in VICTORY_HW_BVH=1 leaves 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_validates validated cleanly; amd_hw_bvh_matches_the_reference_on_the_gpu cleanly 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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6078404208 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#pullrequestreview-6078404208). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T17:31:04Z. **Review:** APPROVED --- Reviewed and verified locally on Windows 11 x64 (NVIDIA RTX 5090): - Opt-in `VICTORY_HW_BVH=1` leaves 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_validates` validated cleanly; `amd_hw_bvh_matches_the_reference_on_the_gpu` cleanly 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 commented 2026-11-26 19:28:37 +00:00 (Migrated from github.com)

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: main 63bcca43). Synthetic tests only.

Environment: Windows 11 build 26200 x64, AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003, amdxc64.dll 8.18.10.0504, rustc 1.98.1. Physical adapter (VICTORY_D3D12_WARP / VICTORY_WARP unset). Debug test profile, --locked -j 4.

Static (CPU): cargo clippy --workspace --all-targets --locked -- -D warnings clean; cargo run -p xtask -- policy ok; test binaries build.

Results on the RX 7800 XT:

Run Result
VICTORY_HW_BVH=1 victory-shader --lib bvh_tests (--test-threads=1) 16 passed, 0 failed, 1 ignored (benchmark)
VICTORY_HW_BVH=1 victory-gpu --lib 232 passed, 0 failed, 1 ignored
VICTORY_HW_BVH unset bvh_tests 16 passed, 0 failed, 1 ignored
control 63bcca43 bvh_tests, unset and =1 14 passed each (no HW code there)
  • amd_hw_bvh_matches_the_reference_on_the_gpu actually 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).
  • Extension probe: with a temporary local eprintln! (not committed) both CheckSupport(0x19) and CheckSupport(0x0D) returned S_OK on this RDNA3 part, so 0x19 is satisfied; the emitted opcode is 0x22 either way.
  • Throughput (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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7201631023 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#issuecomment-7201631023). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T19:28:37Z. --- Independent AMD RDNA3 verification of #3294 at `8c919e6a03e58694510668e67267684fd2af0aec` (base/control: `main` `63bcca43`). Synthetic tests only. **Environment:** Windows 11 build 26200 x64, AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003, `amdxc64.dll` 8.18.10.0504, rustc 1.98.1. Physical adapter (`VICTORY_D3D12_WARP` / `VICTORY_WARP` unset). Debug test profile, `--locked -j 4`. **Static (CPU):** `cargo clippy --workspace --all-targets --locked -- -D warnings` clean; `cargo run -p xtask -- policy` ok; test binaries build. **Results on the RX 7800 XT:** | Run | Result | |---|---| | `VICTORY_HW_BVH=1` `victory-shader --lib bvh_tests` (`--test-threads=1`) | 16 passed, 0 failed, 1 ignored (benchmark) | | `VICTORY_HW_BVH=1` `victory-gpu --lib` | 232 passed, 0 failed, 1 ignored | | `VICTORY_HW_BVH` unset `bvh_tests` | 16 passed, 0 failed, 1 ignored | | control `63bcca43` `bvh_tests`, unset and `=1` | 14 passed each (no HW code there) | - `amd_hw_bvh_matches_the_reference_on_the_gpu` actually 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). - Extension probe: with a temporary local `eprintln!` (not committed) both `CheckSupport(0x19)` and `CheckSupport(0x0D)` returned S_OK on this RDNA3 part, so 0x19 is satisfied; the emitted opcode is 0x22 either way. - Throughput (`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 commented 2026-11-26 21:12:10 +00:00 (Migrated from github.com)

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.

  • The extension is there on this adapter: amd_hw_bvh_lowers_and_validates and amd_hw_bvh_matches_the_reference_on_the_gpu pass 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203491157 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#issuecomment-7203491157). Originally posted by [kilolimaVI](https://github.com/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. - The extension is there on this adapter: `amd_hw_bvh_lowers_and_validates` and `amd_hw_bvh_matches_the_reference_on_the_gpu` pass 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).
shortselow-byte commented 2026-11-26 22:59:24 +00:00 (Migrated from github.com)

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.dll 8.18.10.0500, Ryzen 5 5600X, rustc 1.98.1 (pinned). Physical adapter (VICTORY_D3D12_WARP / VICTORY_WARP unset), release profile, a fresh target directory for this head.

With VICTORY_HW_BVH=1:

Run Result
victory-shader --lib bvh_tests (--test-threads=1) 16 passed, 0 failed, 1 ignored (benchmark)
victory-gpu --lib (--test-threads=1) 232 passed, 0 failed, 1 ignored
  • amd_hw_bvh_matches_the_reference_on_the_gpu ran 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_only passed.

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:

speedup, median of 12 1.10x
speedup, range 0.85x - 1.21x (3 of 12 runs at or below 1.00x)
last 8 runs, median software 37.7 ms, hardware 34.9 ms

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 CheckSupport opcode (0x19 or 0x0D) succeeded here (not probed).

Tested with Claude Code.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205157907 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#issuecomment-7205157907). Originally posted by [shortselow-byte](https://github.com/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.dll` 8.18.10.0500, Ryzen 5 5600X, rustc 1.98.1 (pinned). Physical adapter (`VICTORY_D3D12_WARP` / `VICTORY_WARP` unset), release profile, a fresh target directory for this head. **With `VICTORY_HW_BVH=1`:** | Run | Result | |---|---| | `victory-shader --lib bvh_tests` (`--test-threads=1`) | 16 passed, 0 failed, 1 ignored (benchmark) | | `victory-gpu --lib` (`--test-threads=1`) | 232 passed, 0 failed, 1 ignored | - `amd_hw_bvh_matches_the_reference_on_the_gpu` ran 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_only` passed. 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: | | | |---|---| | speedup, median of 12 | 1.10x | | speedup, range | 0.85x - 1.21x (3 of 12 runs at or below 1.00x) | | last 8 runs, median | software 37.7 ms, hardware 34.9 ms | 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 `CheckSupport` opcode (0x19 or 0x0D) succeeded here (not probed). Tested with Claude Code.
zhu1025960209-web commented 2026-11-26 23:23:50 +00:00 (Migrated from github.com)

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 / 0x19 vs 0x0D / real-workload questions above).

Environment

  • GPU: AMD Radeon RX 6700 XT (RDNA 2, Navi 22, DXR 1.1), driver 32.0.21045.29003
  • OS / CPU: Windows 11 build 22631 x64, Xeon E5-2696 v3 (16T)
  • Codebase note: Ported #3294's enable_amd_bvh probe, IntersectBvhNode (opcode=0x22) lowering, and AMD_EXT_SPACE bindings onto our local AMD fork (c9c932c-based, which uses a flat 1-level 16 MiB VRAM-side SLOT_MEMORY_VAS page table instead of main's 2-level page table) so we could measure a real 3D title workload end-to-end.

1. RDNA 2 Extension Probe & Silicon Correctness

  • CheckSupport on RDNA 2: 0x19 (SUPPORT_INTERSECT_BVH_NODE) returns S_OK directly on RX 6700 XT (32.0.21045.29003), emitting opcode=0x22 without needing the 0x0D fallback.
  • GPU correctness (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).
    • Small observation on flags_val: Using u32::from(sort) | 2 instead of hardcoded 3 preserves BoxSortEnable for descriptors with BOX_SORT cleared (bvh32-unsorted).
    • RDNA 2 silicon vs software reference boundary notes: Hardware uses inclusive enter <= extent (and 0 * inf grazing semantics without clamping inv to f32::MAX), and preserves geometric [v0, v1, v2] winding on odd (i, j) barycentric permutations rather than flipping det's sign.

2. Synthetic vs Live 3D World A/B (Why Real RT Gains Much More Than the Microbench)

  • Synthetic 1-step microbenchmark (134M ray-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.
  • Live 3D world A/B (1080p Series S mode, 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):
Run (RX 6700 XT, 1080p, ~4.5k–4.6k draws/frame) Avg FPS (Peak) Frame Time GPU Time Est. RT-Only GPU Cost (vs RT-off 57.0 ms) Preparing Copy-Back
RT OFF baseline (same scene) 7.4 fps 134.8 ms 57.0 ms 0 ms 48.1 ms 19.4 ms
Software BVH4 RT (VICTORY_HW_BVH=0) 4.57 fps (4.7) 219.4 ms 98.8 ms +41.8 ms 87.7 ms 22.6 ms
Hardware RDNA 2 BVH4 RT (VICTORY_HW_BVH=1) 5.69 fps (5.9) 176.2 ms (168.5 ms) 71.7 ms +14.7 ms 73.9 ms 19.4 ms
Hardware BVH4 Delta +24.5% (+25.5% peak) -43.2 ms/frame -27.1 ms (-27.4%) ~2.84x faster RT -13.8 ms -3.2 ms

In multi-step real-world BVH4 traversal loops, AMD's RDNA 2 Ray Accelerators deliver a huge, rock-solid GPU speedup (-27.1 ms GPU, ~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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205506307 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#issuecomment-7205506307). Originally posted by [zhu1025960209-web](https://github.com/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 / `0x19` vs `0x0D` / real-workload questions above). ### Environment - **GPU:** AMD Radeon RX 6700 XT (RDNA 2, Navi 22, DXR 1.1), driver `32.0.21045.29003` - **OS / CPU:** Windows 11 build `22631` x64, Xeon E5-2696 v3 (16T) - **Codebase note:** Ported `#3294`'s `enable_amd_bvh` probe, `IntersectBvhNode` (`opcode=0x22`) lowering, and `AMD_EXT_SPACE` bindings onto our local AMD fork (`c9c932c`-based, which uses a flat 1-level 16 MiB VRAM-side `SLOT_MEMORY_VAS` page table instead of `main`'s 2-level page table) so we could measure a real 3D title workload end-to-end. --- ### 1. RDNA 2 Extension Probe & Silicon Correctness - **`CheckSupport` on RDNA 2:** **`0x19` (`SUPPORT_INTERSECT_BVH_NODE`) returns `S_OK` directly** on RX 6700 XT (`32.0.21045.29003`), emitting `opcode=0x22` without needing the `0x0D` fallback. - **GPU correctness (`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). - *Small observation on `flags_val`*: Using `u32::from(sort) | 2` instead of hardcoded `3` preserves `BoxSortEnable` for descriptors with `BOX_SORT` cleared (`bvh32-unsorted`). - *RDNA 2 silicon vs software reference boundary notes*: Hardware uses inclusive `enter <= extent` (and `0 * inf` grazing semantics without clamping `inv` to `f32::MAX`), and preserves geometric `[v0, v1, v2]` winding on odd `(i, j)` barycentric permutations rather than flipping `det`'s sign. --- ### 2. Synthetic vs Live 3D World A/B (Why Real RT Gains Much More Than the Microbench) - **Synthetic 1-step microbenchmark** (`134M` ray-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. - **Live 3D world A/B** (1080p Series S mode, `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**): | Run (RX 6700 XT, 1080p, ~4.5k–4.6k draws/frame) | Avg FPS (Peak) | Frame Time | **GPU Time** | Est. RT-Only GPU Cost (vs RT-off 57.0 ms) | Preparing | Copy-Back | |---|---:|---:|---:|---:|---:|---:| | RT OFF baseline (same scene) | `7.4 fps` | `134.8 ms` | `57.0 ms` | `0 ms` | `48.1 ms` | `19.4 ms` | | **Software BVH4 RT (`VICTORY_HW_BVH=0`)** | `4.57 fps` (`4.7`) | `219.4 ms` | **`98.8 ms`** | **`+41.8 ms`** | `87.7 ms` | `22.6 ms` | | **Hardware RDNA 2 BVH4 RT (`VICTORY_HW_BVH=1`)** | **`5.69 fps` (`5.9`)** | **`176.2 ms` (`168.5 ms`)** | **`71.7 ms`** | **`+14.7 ms`** | `73.9 ms` | `19.4 ms` | | **Hardware BVH4 Delta** | **`+24.5%` (`+25.5%` peak)** | **`-43.2 ms/frame`** | **`-27.1 ms` (`-27.4%`)** | **`~2.84x` faster RT** | `-13.8 ms` | `-3.2 ms` | In multi-step real-world BVH4 traversal loops, AMD's RDNA 2 Ray Accelerators deliver a huge, rock-solid GPU speedup (`-27.1 ms` GPU, **~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).
fuzeofficlal commented 2026-11-27 01:39:40 +00:00 (Migrated from github.com)

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 software bvh_lanes for unmapped, partial, unaligned, and page-straddling 128-byte box32 nodes.

Verified on commit 8c919e6a03e58694510668e67267684fd2af0aec:

  • cargo xtask policy passed (191 files ok), emit/lower.rs stays under the 512 KiB size limit (522,300 bytes), and cargo clippy (--lib, --tests, and --features diagnostics --tests, -D warnings) passed for both victory-shader and victory-gpu.
  • NVIDIA RTX 5090 (0x10de, VICTORY_D3D12_DEBUG=1 + dxil.dll): victory-shader bvh_tests passed 16/16 (amd_hw_bvh_lowers_and_validates validated cleanly via dxil.dll), and enable_amd_bvh returned None even with amdxc64.dll present in-process.
  • WARP (VICTORY_D3D12_DEBUG=1 + VICTORY_D3D12_WARP=1 + VICTORY_HW_BVH=1): enable_amd_bvh returned None, bvh_tests passed 16/16, and victory-gpu --features diagnostics memory::tests + shader_cache::tests passed 13/13 (including va_table_populates_aligned_whole_pages_only and lists_share_a_table_and_copies_keep_their_views).
  • AMD Radeon RDNA2 iGPU (0x1002:0x13c0, DXR Tier 1.1): enable_amd_bvh enabled opcode 0x22, live hardware IntersectBvhNode matched the reference for both 32-bit (146 boxes, 20 triangles) and 64-bit (146 boxes, 16 triangles) pointers, and a targeted D3D12 Debug Layer test verified exact results on an in-page HW box32 (0x8000), a page-straddling SW-fallback box32 (0xFFC0), and an unmapped page (0x20000) with zero debug-layer errors.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082347187 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#pullrequestreview-6082347187). Originally posted by [fuzeofficlal](https://github.com/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 software `bvh_lanes` for unmapped, partial, unaligned, and page-straddling 128-byte `box32` nodes. Verified on commit `8c919e6a03e58694510668e67267684fd2af0aec`: - `cargo xtask policy` passed (`191 files ok`), `emit/lower.rs` stays under the 512 KiB size limit (`522,300` bytes), and `cargo clippy` (`--lib`, `--tests`, and `--features diagnostics --tests`, `-D warnings`) passed for both `victory-shader` and `victory-gpu`. - **NVIDIA RTX 5090** (`0x10de`, `VICTORY_D3D12_DEBUG=1` + `dxil.dll`): `victory-shader` `bvh_tests` passed 16/16 (`amd_hw_bvh_lowers_and_validates` validated cleanly via `dxil.dll`), and `enable_amd_bvh` returned `None` even with `amdxc64.dll` present in-process. - **WARP** (`VICTORY_D3D12_DEBUG=1` + `VICTORY_D3D12_WARP=1` + `VICTORY_HW_BVH=1`): `enable_amd_bvh` returned `None`, `bvh_tests` passed 16/16, and `victory-gpu --features diagnostics` `memory::tests` + `shader_cache::tests` passed 13/13 (including `va_table_populates_aligned_whole_pages_only` and `lists_share_a_table_and_copies_keep_their_views`). - **AMD Radeon RDNA2 iGPU** (`0x1002:0x13c0`, DXR Tier 1.1): `enable_amd_bvh` enabled opcode `0x22`, live hardware `IntersectBvhNode` matched the reference for both 32-bit (`146` boxes, `20` triangles) and 64-bit (`146` boxes, `16` triangles) pointers, and a targeted D3D12 Debug Layer test verified exact results on an in-page HW `box32` (`0x8000`), a page-straddling SW-fallback `box32` (`0xFFC0`), and an unmapped page (`0x20000`) with zero debug-layer errors.
kilolimaVI commented 2026-11-27 12:01:13 +00:00 (Migrated from github.com)

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 head 8c919e6, AMD Radeon 780M (RDNA3 iGPU), Windows 11:

median of 12 range
speedup 2.20x 2.01x - 2.30x
software 233.6 ms 226.6 - 240.0 ms
hardware (opcode 0x22) 107.8 ms 102.3 - 117.6 ms

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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217741917 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3294#issuecomment-7217741917). Originally posted by [kilolimaVI](https://github.com/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 head 8c919e6, AMD Radeon 780M (RDNA3 iGPU), Windows 11: | | median of 12 | range | |---|---|---| | speedup | **2.20x** | 2.01x - 2.30x | | software | 233.6 ms | 226.6 - 240.0 ms | | hardware (opcode 0x22) | 107.8 ms | 102.3 - 117.6 ms | 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).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3294:upstream-pr/3294'
git switch 'upstream-pr/3294'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3294'
git switch 'upstream-pr/3294'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3294'
git switch 'upstream-pr/3294'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3294'
git switch 'main'
git merge --squash 'upstream-pr/3294'
git switch 'main'
git merge --ff-only 'upstream-pr/3294'
git switch 'main'
git merge 'upstream-pr/3294'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3294
No description provided.