[WIP / Draft] Parallel DXR 1.1 acceleration structures (Stage 1) behind VICTORY_DXR_RAYQUERY=1 #469

Open
github-bot wants to merge 4 commits from github-bot/gh-469 into a-publier AGit
Owner

@⁠Fran-co-F on GitHub · 2026-11-27 04:02 UTC · original
Fran-co-F:wip/dxr-rayquery-stage1 → a-publier · +5850 −2 · 17 files · 4 commits · draft

Status: WIP / Draft — Stage 1 only (acceleration structures + differential verification).
This PR is intentionally left as a draft and is open for anyone to pick up, fork, or continue into Stage 2 (replacing shader traversal loops with RayQuery).

AI disclosure: The design exploration, Rust code, HLSL shaders, synthetic tests, and this PR write-up were authored by AI. The submitter executed the builds and live sessions locally and collected the measurements, without manually reviewing the code.

Attribution:

  • Commit 8c98bab (VICTORY_BVH_SIZES_BOUND, crates/victory-gpu/src/bvhsize.rs and its wiring into memory.rs, queue.rs, modules/bvh.rs, and docs/fork-ray-tracing.md) is ported from notquiteog/victory-nvidia@57dd221 (avatarmanz PR #395, originally e8258c1), adapted to hook through victory-hle::modules::bvh.
  • Console BVH4 node layouts and traversal math in extract_triangles.hlsl and verify_console_bvh.hlsl follow existing crates/victory-shader/src/bvh.rs and observations of XboxBvhBuilder.dll exports.
  • Nothing was taken from XCL.

Summary & Scope

Software-emulated console BVH4 traversal takes a large share of GPU frame time when ray tracing is enabled (VICTORY_BVH_BUILDER=1). Host GPUs exposing DXR 1.1 (D3D12_RAYTRACING_TIER_1_1) can execute ray traversal natively via RayQuery.
This draft implements Stage 1 only behind VICTORY_DXR_RAYQUERY=1 (opt-in, off by default):

  • Builds parallel host DXR 1.1 BLASes and TLASes alongside the title's XboxBvhBuilder.dll (dual/shadow mode — the console BVH4 remains in place).
  • Compiles the 5 SM 6.6 HLSL shaders at runtime via dxc.exe with BLAKE3 disk caching (no .dxil binaries in the repository; cargo xtask policy passes).
  • Adds a GPU differential verifier (VICTORY_DXR_VERIFY=1) and synthetic DXR 1.1 GPU tests comparing identical rays against both the console BVH4 and the parallel host DXR 1.1 TLAS.
  • Includes a separate commit (8c98bab) porting VICTORY_BVH_SIZES_BOUND (on by default when VICTORY_BVH_BUILDER=1, =0 to disable; see Attribution and Separate Finding below).
  • Stage 2 (rewriting trace shaders to RayQuery) is NOT included here.

Behavior when VICTORY_DXR_RAYQUERY is unset

  • All DXR hooks and GPU passes short-circuit via a cached OnceLock<bool> (dxr::enabled() == false); title_memory_freed() performs one OnceLock check and returns immediately.
  • Note that commit 8c98bab (VICTORY_BVH_SIZES_BOUND) is enabled by default whenever VICTORY_BVH_BUILDER=1 (matching notquiteog/victory-nvidia@57dd221), so running with VICTORY_BVH_BUILDER=1 does change compacted-size slot writes unless VICTORY_BVH_SIZES_BOUND=0 is set.

Test Environment & Wine Dependencies

  • Environment tested: Linux, Wine, vkd3d-proton, RADV (Mesa), AMD Radeon RX 9070 XT (DXR Tier 1.1).
  • Untested on Windows and untested on NVIDIA.
  • Local patches required during our Wine live runs (NOT included on this clean branch):
    • avatarmanz PR #114 (d16 accesses / faces),
    • avatarmanz PR #166 (Wine/Proton compute wait, null-blob pipeline library, VICTORY_KEYS),
    • local Wine placeholder hole-skipping (VICTORY_HOLE_SKIP) and a patched wineserver (viewtree),
    • local GPU timestamp profiler (VICTORY_RT_TIMING) used to capture the live gpu_ms/f figures below (omitted from this branch so the diff stays focused on DXR).
  • Runtime shader compiler requirement: VICTORY_DXR_RAYQUERY=1 compiles the 5 embedded SM 6.6 .hlsl files via dxc.exe (resolved from VICTORY_PC_DXC, next to victory.exe, the Windows SDK default path, or PATH).

Design

  1. XboxBvhBuilder.dll pass-through HLE hook (crates/victory-hle/src/modules/bvh.rs)
    • Intercepts GetRaytracingAccelerationStructurePrebuildInfo, BuildRaytracingAccelerationStructureBatched2X, RehydrateRaytracingAccelerationStructureBatched2X, and CopyRaytracingAccelerationStructure.
    • Always calls the title's mapped XboxBvhBuilder.dll first, pre-opening destination ranges in memory.rs (dxr_prepare_dests) before builds run.
  2. GPU triangle extraction from console BVH4 (crates/victory-gpu/src/dxr/)
    • extract_triangles.hlsl reads already-decoded TriangleNode leaves directly out of memory.rs arenas/shadows into a temporary R32G32B32_FLOAT buffer (pre-filled with quiet NaNs by clear_nan.hlsl so unused slots are skipped by DXR).
    • Uses a flat 2-geometry split (OPAQUE and NON_OPAQUE, slot tid * 2 + k), validates leaf_off/num_nodes, maps BLASes up to 64 MiB in memory.rs (dxr_bind), and inverts header[15] (objectToLocal: scale, sceneBounds midpoint offset, and 6-bit quantized Euler rotation R^T) back to object space.
  3. TLAS instance remapping & bad_hdr refit fallback
    • remap_instances.hlsl remaps title BLAS VAs to host DXR BLAS VAs through a cached stride-2 open-addressed GPU hash table (UploadRing, 64 MiB).
    • PERFORM_UPDATE (BUILD_FLAG_PERFORM_UPDATE = 1 << 5 = 0x20) allocates a new host BLAS buffer instead of overwriting the valid BLAS in-place: extract_triangles.hlsl writes 1 (valid) or 0 (bad_hdr) to a shared blas_valid buffer, remap_instances.hlsl falls back to the previous valid host BLAS on the GPU with no CPU stall if 0, and settle_pending_updates() reverts blas_map and frees the empty buffer once the submission finishes.
  4. Differential verification (VICTORY_DXR_VERIFY=1 & verify_test.rs)
    • Dispatches 16,384 rays every 30 frames against both verify_rayquery.hlsl (host DXR 1.1 TLAS) and verify_console_bvh.hlsl (console BVH4 in memory.rs).
    • Thread 0 of verify_console_bvh.hlsl walks the full console TLAS to count corrupted console BLAS headers, and every log line prints both unfiltered totals and filtered accuracy (excluding only rays hitting an instance whose console BLAS header is corrupted), plus a 2-slot probe dumping InstanceNode.Transform, w2o, BLAS header, and first/hit leaf vertices on mismatches.

How to Reproduce

Policy & static checks

cargo xtask policy
cargo clippy --workspace -- -D warnings
cargo clippy --workspace --all-features -- -D warnings

Synthetic GPU & unit tests (no title required)

Requires DXR Tier 1.1 and dxc.exe (set VICTORY_PC_DXC if not in Windows SDK / PATH; tests skip cleanly if either is absent):

cargo test -p victory-gpu --lib dxr:: -- --nocapture
cargo test -p victory-gpu --lib bvhsize::
cargo test -p victory-hle --lib modules::bvh::

Live run with parallel DXR + differential verifier

VICTORY_BVH_BUILDER=1
VICTORY_DXR_RAYQUERY=1
VICTORY_DXR_VERIFY=1
VICTORY_PC_DXC=<path-to-dxc.exe>
# Optional A/B toggle for commit 8c98bab:
VICTORY_BVH_SIZES_BOUND=0   # or 1 (default)

Results (including failures & open issues)

1. Synthetic GPU differential tests (Linux / Wine / vkd3d-proton / RADV / RX 9070 XT)

  • synthetic_console_vs_dxr_matches_over_99_9_percent (65,536 rays, Box16 + Box32, single + paired triangles, all 6 barycentric swizzles, opaque + non-opaque, masks, backface culling, and non-trivial header[15] rotation/offset/scale):
    • con_hits = 18,101, rq_hits = 18,101
    • Hit match: 100.0000% | t match: 100.0000% (max_t_err = 0.000051) | InstanceID match: 100.0000%
    • GPU timing: build = 0.513 ms, RayQuery = 0.165 ms vs console_bvh = 0.331 ms (2.01x)
    • AS VRAM: 67.2 KB
  • bad_hdr_refit_preserves_valid_host_blas: valid_slots=(1,0), bad_hdr=1, fallback_used=1, 64/64 hits preserved.
  • radv_all_nan_blas_in_tlas_probe: 64/64 hits.

2. Live scene differential verification (2,800+ instances, 16,384 rays/run, two 90 s sessions)

Both unfiltered totals and filtered rates are reported side by side:

Metric SIZES_BOUND=0 (28 runs) SIZES_BOUND=1 (26 runs)
Unfiltered hit match (median / mean / range) 92.371% / 93.879% (89.392–100.000%) 90.936% / 88.208% (55.402–100.000%)
Unfiltered t match (median / mean / range) 89.517% / 91.447% (83.942–100.000%) 79.666% / 80.461% (55.341–100.000%)
Unfiltered inst_id match (median / range) 94.230% (90.658–99.918%) 84.475% (0.000–100.000%)
Filtered hit match (excl. corrupt-header instances) 99.993% / 99.072% (91.177–100.000%) 92.695% / 90.551% (59.647–100.000%)
Filtered t match 99.964% / 98.702% (89.027–100.000%) 79.992% / 83.496% (59.647–100.000%)
Filtered inst_id match 99.941% (93.144–100.000%) 84.821% (0.000–100.000%)
Corrupted instances in console TLAS (med / mean / max) 300.0 / 253.4 / 367 205.5 / 186.9 / 334
Unique corrupted BLASes in console TLAS (med / mean / max) 67.5 / 63.3 / 109 55.0 / 45.8 / 63
Extraction tris / oob / bad_hdr 27.70M / 0 / 1,749 28.42M / 0 / 2,660
Instance remap mapped / missing / fb_gpu / refit_reverted 2.29M / 0 / 2,012 / 2,416 2.28M / 0 / 2,928 / 3,020
  • In the SIZES_BOUND=0 session, 21 of 28 runs reached 99.971–100.000% filtered hit agreement (median 99.993% hit / 99.964% t, 5 runs at 100.000%), with 0 extraction OOBs over 27.7M triangles and 0 missing BLAS remaps over 2.29M instances.
  • Known bugs & observed anomalies (NOT yet fixed):
    1. 16-bit quantized vertices in h0 = 0x80020006 rehydrated BLASes (session 2, runs 14–26): A rehydrated BLAS with h0 = 0x80020006, h15 = 0x808e8f8f (scale = (65536, 65536, 32768)), and valid TriangleNode metadata (meta = (0x181, 0xa9, 0xaa, 0x904)) had vertex dwords 0xf8a3de7b and 0x5c60fabf. Decoded as signed i16 (-8581, -1885, -1345, +23648) and divided by h15 scale, those coordinates fall inside bmin..bmax ([-0.85..0.86, -0.83..0.91, -0.16..1.50]). Because extract_triangles.hlsl read them as float32, it emitted huge triangles at ±4e29 that generated 1,700–3,024 false DXR hits per run.
    2. Shared scratch / temp_inst / TLAS buffer hazard under heavy multi-queue load (session 2, runs 2, 4, 9): Three verification runs recorded rq_hits = 0..15 against 4,266–7,312 console hits while tlas builds reached 24–48/frame across concurrent command lists sharing a single scratch and temp_inst buffer.
    3. 3 runs (session 1, runs 4–6) dropped to 91.2–91.6% filtered due to instances hit by DXR whose InstanceID was reported NOT FOUND when walking the console TLAS.
    4. Visual/boot anomalies observed (root cause undetermined): During earlier development runs, a black screen at boot (with the title still running and responding to input) was observed once, and stretched-mesh artifacts were also observed; neither has an established root cause yet.

3. Cost (GPU ms/frame & VRAM)

(GPU ms/f measured via the local VICTORY_RT_TIMING profiler on the same Wine/RADV/RX 9070 XT setup; not included on this branch.)

  • Extra GPU time (Stage 1 parallel builds, excluding verifier):
    • Session 1 (SIZES_BOUND=0): median 15.20 ms/frame (13.62 ms BLAS + 1.37 ms TLAS; range 4.12–32.38 ms/f).
    • Session 2 (SIZES_BOUND=1, heavier streaming): median 20.84 ms/frame (19.18 ms BLAS + 1.55 ms TLAS; range 9.94–38.57 ms/f).
    • Verifier overhead (VICTORY_DXR_VERIFY=1 only): 0.64–0.87 ms/f amortized.
  • Extra VRAM:
    • 2.17–2.25 GiB peak (~1.9–2.0 GiB across ~2,180–2,240 live host BLASes, ~1.1 MiB TLASes, plus 64 MiB upload ring + scratch/temp buffers). No DXR BLAS compaction is implemented yet, and BLASes use worst-case max_nodes * 4 NaN-padded vertex capacity.

Separate Finding (Hypothesis): Console Compaction-Size Neighbor Overwrites

In both live sessions, scanning the console TLAS found ~200–367 instances (~55–109 unique BLASes) per frame whose 64-byte console BLAS header contained non-header data (such as neighbor TriangleNode floats/metadata).

  • Hypothesis: These overwrites come from the console builder's compacting copies (CopyRaytracingAccelerationStructure) reading stale GetBVHCompactedSize slots under async/thin-list submission, rather than from the parallel DXR backend.
  • Not yet proven: We have not yet run the same TLAS header scan with VICTORY_DXR_RAYQUERY=0 (DXR structures disabled) as a clean control. Running that control measurement is needed to confirm whether corrupted console header counts are identical without DXR active.
  • Partial effect of VICTORY_BVH_SIZES_BOUND=1 (8c98bab): Enabling the ported compacted-size bound reduced median corrupted headers from 300.0 → 205.5 instances (-31.5%) and 67.5 → 55.0 unique BLASes (-18.5%, peak 109 → 63). Across the 90 s run, bvhsize matched 553 / 2,434 (22.7%) of GetBVHCompactedSize queries (asked_without = 1,881, put_back = 97), leaving ~77% of size queries without a bound.

Next Steps (for anyone continuing this work)

  1. Control measurement for console header corruption: Run the TLAS header scan with VICTORY_DXR_RAYQUERY=0 to verify whether corrupted BLAS headers occur at the same rate without DXR active, and investigate why ~77% of GetBVHCompactedSize queries miss bvhsize's bound table.
  2. Decode h0 = 0x80020006 16-bit quantized leaves (or skip/guard non-float32 leaf payloads in extract_triangles.hlsl until decoded).
  3. Fix shared scratch / temp_inst / temp_verts and in-flight TLAS reuse across concurrent command lists (per-list or ring-buffered allocations).
  4. Investigate the observed black screen / stretched-mesh artifacts and test on native Windows and NVIDIA hardware.
  5. Reduce Stage 1 VRAM & GPU ms/f: Compact static/rehydrated DXR BLASes, allocate exact triangle counts instead of max_nodes * 4 NaN-padded buffers, and avoid re-extracting unchanged BLASes.
  6. Stage 2 (RayQuery shader replacement): Validate end-to-end rendering on a single simple opaque-only trace shader first, then migrate the main trace families while preserving non-opaque/alpha-test handling inside Proceed(), instance masks, ray flags, and hit payload layout.

🤖 Generated with Claude Code

**@⁠Fran-co-F** on GitHub · 2026-11-27 04:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/469) `Fran-co-F:wip/dxr-rayquery-stage1` → `a-publier` · +5850 −2 · 17 files · 4 commits · draft > **Status: WIP / Draft — Stage 1 only (acceleration structures + differential verification).** > This PR is intentionally left as a draft and is **open for anyone to pick up, fork, or continue** into Stage 2 (replacing shader traversal loops with `RayQuery`). > > **AI disclosure:** The design exploration, Rust code, HLSL shaders, synthetic tests, and this PR write-up were authored by AI. The submitter executed the builds and live sessions locally and collected the measurements, **without manually reviewing the code**. > > **Attribution:** > - Commit `8c98bab` (`VICTORY_BVH_SIZES_BOUND`, `crates/victory-gpu/src/bvhsize.rs` and its wiring into `memory.rs`, `queue.rs`, `modules/bvh.rs`, and `docs/fork-ray-tracing.md`) is ported from `notquiteog/victory-nvidia@57dd221` (avatarmanz PR #395, originally `e8258c1`), adapted to hook through `victory-hle::modules::bvh`. > - Console BVH4 node layouts and traversal math in `extract_triangles.hlsl` and `verify_console_bvh.hlsl` follow existing `crates/victory-shader/src/bvh.rs` and observations of `XboxBvhBuilder.dll` exports. > - Nothing was taken from XCL. --- ## Summary & Scope Software-emulated console BVH4 traversal takes a large share of GPU frame time when ray tracing is enabled (`VICTORY_BVH_BUILDER=1`). Host GPUs exposing DXR 1.1 (`D3D12_RAYTRACING_TIER_1_1`) can execute ray traversal natively via `RayQuery`. This draft implements **Stage 1 only** behind **`VICTORY_DXR_RAYQUERY=1`** (opt-in, off by default): - Builds parallel host DXR 1.1 BLASes and TLASes alongside the title's `XboxBvhBuilder.dll` (dual/shadow mode — the console BVH4 remains in place). - Compiles the 5 SM 6.6 HLSL shaders at runtime via `dxc.exe` with BLAKE3 disk caching (no `.dxil` binaries in the repository; `cargo xtask policy` passes). - Adds a GPU differential verifier (**`VICTORY_DXR_VERIFY=1`**) and synthetic DXR 1.1 GPU tests comparing identical rays against both the console BVH4 and the parallel host DXR 1.1 TLAS. - Includes a separate commit (`8c98bab`) porting `VICTORY_BVH_SIZES_BOUND` (on by default when `VICTORY_BVH_BUILDER=1`, `=0` to disable; see Attribution and Separate Finding below). - **Stage 2 (rewriting trace shaders to `RayQuery`) is NOT included here.** ### Behavior when `VICTORY_DXR_RAYQUERY` is unset - All DXR hooks and GPU passes short-circuit via a cached `OnceLock<bool>` (`dxr::enabled() == false`); `title_memory_freed()` performs one `OnceLock` check and returns immediately. - Note that commit `8c98bab` (`VICTORY_BVH_SIZES_BOUND`) is **enabled by default whenever `VICTORY_BVH_BUILDER=1`** (matching `notquiteog/victory-nvidia@57dd221`), so running with `VICTORY_BVH_BUILDER=1` *does* change compacted-size slot writes unless `VICTORY_BVH_SIZES_BOUND=0` is set. --- ## Test Environment & Wine Dependencies - **Environment tested:** Linux, Wine, vkd3d-proton, RADV (Mesa), AMD Radeon RX 9070 XT (DXR Tier 1.1). - **Untested on Windows and untested on NVIDIA.** - **Local patches required during our Wine live runs (NOT included on this clean branch):** - avatarmanz PR #114 (`d16` accesses / faces), - avatarmanz PR #166 (Wine/Proton compute wait, null-blob pipeline library, `VICTORY_KEYS`), - local Wine placeholder hole-skipping (`VICTORY_HOLE_SKIP`) and a patched `wineserver` (`viewtree`), - local GPU timestamp profiler (`VICTORY_RT_TIMING`) used to capture the live `gpu_ms/f` figures below (omitted from this branch so the diff stays focused on DXR). - **Runtime shader compiler requirement:** `VICTORY_DXR_RAYQUERY=1` compiles the 5 embedded SM 6.6 `.hlsl` files via `dxc.exe` (resolved from `VICTORY_PC_DXC`, next to `victory.exe`, the Windows SDK default path, or `PATH`). --- ## Design 1. **`XboxBvhBuilder.dll` pass-through HLE hook (`crates/victory-hle/src/modules/bvh.rs`)** - Intercepts `GetRaytracingAccelerationStructurePrebuildInfo`, `BuildRaytracingAccelerationStructureBatched2X`, `RehydrateRaytracingAccelerationStructureBatched2X`, and `CopyRaytracingAccelerationStructure`. - Always calls the title's mapped `XboxBvhBuilder.dll` first, pre-opening destination ranges in `memory.rs` (`dxr_prepare_dests`) before builds run. 2. **GPU triangle extraction from console BVH4 (`crates/victory-gpu/src/dxr/`)** - `extract_triangles.hlsl` reads already-decoded `TriangleNode` leaves directly out of `memory.rs` arenas/shadows into a temporary `R32G32B32_FLOAT` buffer (pre-filled with quiet NaNs by `clear_nan.hlsl` so unused slots are skipped by DXR). - Uses a flat 2-geometry split (`OPAQUE` and `NON_OPAQUE`, slot `tid * 2 + k`), validates `leaf_off`/`num_nodes`, maps BLASes up to 64 MiB in `memory.rs` (`dxr_bind`), and inverts `header[15]` (`objectToLocal`: scale, `sceneBounds` midpoint offset, and 6-bit quantized Euler rotation `R^T`) back to object space. 3. **TLAS instance remapping & `bad_hdr` refit fallback** - `remap_instances.hlsl` remaps title BLAS VAs to host DXR BLAS VAs through a cached stride-2 open-addressed GPU hash table (`UploadRing`, 64 MiB). - `PERFORM_UPDATE` (`BUILD_FLAG_PERFORM_UPDATE = 1 << 5 = 0x20`) allocates a new host BLAS buffer instead of overwriting the valid BLAS in-place: `extract_triangles.hlsl` writes `1` (valid) or `0` (`bad_hdr`) to a shared `blas_valid` buffer, `remap_instances.hlsl` falls back to the previous valid host BLAS on the GPU with no CPU stall if `0`, and `settle_pending_updates()` reverts `blas_map` and frees the empty buffer once the submission finishes. 4. **Differential verification (`VICTORY_DXR_VERIFY=1` & `verify_test.rs`)** - Dispatches 16,384 rays every 30 frames against both `verify_rayquery.hlsl` (host DXR 1.1 TLAS) and `verify_console_bvh.hlsl` (console BVH4 in `memory.rs`). - Thread 0 of `verify_console_bvh.hlsl` walks the full console TLAS to count corrupted console BLAS headers, and every log line prints **both unfiltered totals and filtered accuracy** (excluding only rays hitting an instance whose console BLAS header is corrupted), plus a 2-slot probe dumping `InstanceNode.Transform`, `w2o`, BLAS header, and first/hit leaf vertices on mismatches. --- ## How to Reproduce ### Policy & static checks ```bash cargo xtask policy cargo clippy --workspace -- -D warnings cargo clippy --workspace --all-features -- -D warnings ``` ### Synthetic GPU & unit tests (no title required) Requires DXR Tier 1.1 and `dxc.exe` (set `VICTORY_PC_DXC` if not in Windows SDK / `PATH`; tests skip cleanly if either is absent): ```bash cargo test -p victory-gpu --lib dxr:: -- --nocapture cargo test -p victory-gpu --lib bvhsize:: cargo test -p victory-hle --lib modules::bvh:: ``` ### Live run with parallel DXR + differential verifier ```text VICTORY_BVH_BUILDER=1 VICTORY_DXR_RAYQUERY=1 VICTORY_DXR_VERIFY=1 VICTORY_PC_DXC=<path-to-dxc.exe> # Optional A/B toggle for commit 8c98bab: VICTORY_BVH_SIZES_BOUND=0 # or 1 (default) ``` --- ## Results (including failures & open issues) ### 1. Synthetic GPU differential tests (Linux / Wine / vkd3d-proton / RADV / RX 9070 XT) - **`synthetic_console_vs_dxr_matches_over_99_9_percent`** (65,536 rays, Box16 + Box32, single + paired triangles, all 6 barycentric swizzles, opaque + non-opaque, masks, backface culling, and non-trivial `header[15]` rotation/offset/scale): - `con_hits = 18,101`, `rq_hits = 18,101` - **Hit match:** `100.0000%` | **`t` match:** `100.0000%` (`max_t_err = 0.000051`) | **`InstanceID` match:** `100.0000%` - **GPU timing:** `build = 0.513 ms`, `RayQuery = 0.165 ms` vs `console_bvh = 0.331 ms` (**2.01x**) - **AS VRAM:** `67.2 KB` - **`bad_hdr_refit_preserves_valid_host_blas`:** `valid_slots=(1,0)`, `bad_hdr=1`, `fallback_used=1`, `64/64` hits preserved. - **`radv_all_nan_blas_in_tlas_probe`:** `64/64` hits. ### 2. Live scene differential verification (2,800+ instances, 16,384 rays/run, two 90 s sessions) **Both unfiltered totals and filtered rates are reported side by side:** | Metric | `SIZES_BOUND=0` (28 runs) | `SIZES_BOUND=1` (26 runs) | |---|---:|---:| | **Unfiltered hit match** (median / mean / range) | **92.371%** / 93.879% (89.392–100.000%) | **90.936%** / 88.208% (55.402–100.000%) | | **Unfiltered `t` match** (median / mean / range) | **89.517%** / 91.447% (83.942–100.000%) | **79.666%** / 80.461% (55.341–100.000%) | | **Unfiltered `inst_id` match** (median / range) | **94.230%** (90.658–99.918%) | **84.475%** (0.000–100.000%) | | **Filtered hit match** *(excl. corrupt-header instances)* | **99.993%** / 99.072% (91.177–100.000%) | **92.695%** / 90.551% (59.647–100.000%) | | **Filtered `t` match** | **99.964%** / 98.702% (89.027–100.000%) | **79.992%** / 83.496% (59.647–100.000%) | | **Filtered `inst_id` match** | **99.941%** (93.144–100.000%) | **84.821%** (0.000–100.000%) | | Corrupted instances in console TLAS (med / mean / max) | **300.0** / 253.4 / 367 | **205.5** / 186.9 / 334 | | Unique corrupted BLASes in console TLAS (med / mean / max) | **67.5** / 63.3 / 109 | **55.0** / 45.8 / 63 | | Extraction `tris` / `oob` / `bad_hdr` | 27.70M / **0** / 1,749 | 28.42M / **0** / 2,660 | | Instance remap `mapped` / `missing` / `fb_gpu` / `refit_reverted` | 2.29M / **0** / 2,012 / 2,416 | 2.28M / **0** / 2,928 / 3,020 | - In the `SIZES_BOUND=0` session, **21 of 28 runs reached 99.971–100.000% filtered hit agreement** (median **99.993%** hit / **99.964%** `t`, 5 runs at **100.000%**), with `0` extraction OOBs over 27.7M triangles and `0` missing BLAS remaps over 2.29M instances. - **Known bugs & observed anomalies (NOT yet fixed):** 1. **16-bit quantized vertices in `h0 = 0x80020006` rehydrated BLASes (session 2, runs 14–26):** A rehydrated BLAS with `h0 = 0x80020006`, `h15 = 0x808e8f8f` (`scale = (65536, 65536, 32768)`), and valid `TriangleNode` metadata (`meta = (0x181, 0xa9, 0xaa, 0x904)`) had vertex dwords `0xf8a3de7b` and `0x5c60fabf`. Decoded as signed `i16` (`-8581, -1885, -1345, +23648`) and divided by `h15` scale, those coordinates fall inside `bmin..bmax` (`[-0.85..0.86, -0.83..0.91, -0.16..1.50]`). Because `extract_triangles.hlsl` read them as `float32`, it emitted huge triangles at `±4e29` that generated 1,700–3,024 false DXR hits per run. 2. **Shared `scratch` / `temp_inst` / TLAS buffer hazard under heavy multi-queue load (session 2, runs 2, 4, 9):** Three verification runs recorded `rq_hits = 0..15` against 4,266–7,312 console hits while `tlas` builds reached 24–48/frame across concurrent command lists sharing a single `scratch` and `temp_inst` buffer. 3. **3 runs (session 1, runs 4–6) dropped to 91.2–91.6% filtered** due to instances hit by DXR whose `InstanceID` was reported `NOT FOUND` when walking the console TLAS. 4. **Visual/boot anomalies observed (root cause undetermined):** During earlier development runs, a black screen at boot (with the title still running and responding to input) was observed once, and stretched-mesh artifacts were also observed; neither has an established root cause yet. ### 3. Cost (GPU ms/frame & VRAM) *(GPU ms/f measured via the local `VICTORY_RT_TIMING` profiler on the same Wine/RADV/RX 9070 XT setup; not included on this branch.)* - **Extra GPU time (Stage 1 parallel builds, excluding verifier):** - Session 1 (`SIZES_BOUND=0`): median **15.20 ms/frame** (`13.62 ms` BLAS + `1.37 ms` TLAS; range `4.12–32.38 ms/f`). - Session 2 (`SIZES_BOUND=1`, heavier streaming): median **20.84 ms/frame** (`19.18 ms` BLAS + `1.55 ms` TLAS; range `9.94–38.57 ms/f`). - Verifier overhead (`VICTORY_DXR_VERIFY=1` only): `0.64–0.87 ms/f` amortized. - **Extra VRAM:** - **2.17–2.25 GiB** peak (`~1.9–2.0 GiB` across `~2,180–2,240` live host BLASes, `~1.1 MiB` TLASes, plus 64 MiB upload ring + scratch/temp buffers). No DXR BLAS compaction is implemented yet, and BLASes use worst-case `max_nodes * 4` NaN-padded vertex capacity. --- ## Separate Finding (Hypothesis): Console Compaction-Size Neighbor Overwrites In both live sessions, scanning the console TLAS found **~200–367 instances (~55–109 unique BLASes)** per frame whose 64-byte console BLAS header contained non-header data (such as neighbor `TriangleNode` floats/metadata). - **Hypothesis:** These overwrites come from the console builder's compacting copies (`CopyRaytracingAccelerationStructure`) reading stale `GetBVHCompactedSize` slots under async/thin-list submission, rather than from the parallel DXR backend. - **Not yet proven:** We have **not** yet run the same TLAS header scan with `VICTORY_DXR_RAYQUERY=0` (DXR structures disabled) as a clean control. Running that control measurement is needed to confirm whether corrupted console header counts are identical without DXR active. - **Partial effect of `VICTORY_BVH_SIZES_BOUND=1` (`8c98bab`):** Enabling the ported compacted-size bound reduced median corrupted headers from **300.0 → 205.5 instances** (-31.5%) and **67.5 → 55.0 unique BLASes** (-18.5%, peak 109 → 63). Across the 90 s run, `bvhsize` matched **553 / 2,434 (22.7%)** of `GetBVHCompactedSize` queries (`asked_without = 1,881`, `put_back = 97`), leaving ~77% of size queries without a bound. --- ## Next Steps (for anyone continuing this work) 1. **Control measurement for console header corruption:** Run the TLAS header scan with `VICTORY_DXR_RAYQUERY=0` to verify whether corrupted BLAS headers occur at the same rate without DXR active, and investigate why ~77% of `GetBVHCompactedSize` queries miss `bvhsize`'s bound table. 2. **Decode `h0 = 0x80020006` 16-bit quantized leaves** (or skip/guard non-float32 leaf payloads in `extract_triangles.hlsl` until decoded). 3. **Fix shared `scratch` / `temp_inst` / `temp_verts` and in-flight TLAS reuse** across concurrent command lists (per-list or ring-buffered allocations). 4. **Investigate the observed black screen / stretched-mesh artifacts** and test on native Windows and NVIDIA hardware. 5. **Reduce Stage 1 VRAM & GPU ms/f:** Compact static/rehydrated DXR BLASes, allocate exact triangle counts instead of `max_nodes * 4` NaN-padded buffers, and avoid re-extracting unchanged BLASes. 6. **Stage 2 (`RayQuery` shader replacement):** Validate end-to-end rendering on a single simple opaque-only trace shader first, then migrate the main trace families while preserving non-opaque/alpha-test handling inside `Proceed()`, instance masks, ray flags, and hit payload layout. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Implements Stage 1 of parallel DXR 1.1 acceleration structures behind
VICTORY_DXR_RAYQUERY=1 (opt-in, off by default):
- Compiles the 5 SM 6.6 compute shaders from embedded HLSL at runtime via
  dxc.exe (VICTORY_PC_DXC, beside victory.exe, Windows SDK, or PATH) with
  BLAKE3 disk caching, keeping the repo free of precompiled DXIL binaries.
- Extracts already-decoded TriangleNode leaves from console BVH4 buffers in
  memory.rs arenas/shadows into flat 2-geometry (OPAQUE / NON_OPAQUE) DXR
  vertex buffers, inverting header[15] objectToLocal transforms back to
  object space and validating leaf_off/num_nodes.
- Remaps title InstanceDescs to host DXR BLAS VAs via an open-addressed GPU
  hash table with GPU-driven fallback (blas_valid) so a PERFORM_UPDATE
  (0x20) refit hitting bad_hdr never overwrites a valid host BLAS.
- Adds live differential verification (VICTORY_DXR_VERIFY=1) comparing
  host RayQuery against console BVH4 traversal, reporting both unfiltered
  and filtered agreement, console TLAS corrupt-header counts, and a 2-slot
  InstanceNode.Transform + vertex mismatch probe.
Captures the real exports from the title's mapped XboxBvhBuilder.dll
(PrebuildInfo, BuildBatched2X, RehydrateBatched2X, Copy) when
VICTORY_DXR_RAYQUERY=1, always forwarding to the real DLL first so console
BVH4 stays intact, then forwarding descriptors to victory_gpu::dxr.
Adds GPU differential tests compiled from embedded HLSL at runtime via
dxc.exe (skipping cleanly when host DXR 1.1 or dxc.exe is unavailable):
- synthetic_console_vs_dxr_matches_over_99_9_percent: 65,536 rays against
  Box16 + Box32 console BVH4 vs parallel DXR 1.1 TLAS (including full
  header[15] objectToLocal transforms, all 6 swizzles, opaque/non-opaque,
  masks, and backface culling).
- bad_hdr_refit_preserves_valid_host_blas: verifies GPU blas_valid fallback
  preserves 64/64 hits when a refit hits bad_hdr.
- radv_all_nan_blas_in_tlas_probe: sanity probe for all-NaN BLAS handling.
Ports the compacted-size upper-bound fix (VICTORY_BVH_SIZES_BOUND, on by
default with VICTORY_BVH_BUILDER=1, 0 to disable) from avatarmanz PR #395 /
notquiteog/victory-nvidia commit 57dd221acf37 (originally e8258c1bbdb6).

Integrates bvhsize::prebuilt() and bvhsize::batch() into the existing
victory-hle XboxBvhBuilder.dll pass-through hook (active whenever either
VICTORY_DXR_RAYQUERY=1 or VICTORY_BVH_SIZES_BOUND is wanted) so prebuild
ResultDataMaxSizeInBytes bounds are written to GetBVHCompactedSize slots on
list translation and restored on late landings via Written::SizeLanded.

Credit: notquiteog / avatarmanz PR #395 (notquiteog/victory-nvidia@57dd221).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:06:45 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 05:38 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At 8e5a3df: victory-gpu 406 passed, 0 failed, 34 ignored; victory-hle 163 passed, 0 failed, 2 ignored. VICTORY_DXR_RAYQUERY was not set, so this only shows the default path is unaffected.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 05:38 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/469#issuecomment-7210807219) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `8e5a3df`: `victory-gpu` 406 passed, 0 failed, 34 ignored; `victory-hle` 163 passed, 0 failed, 2 ignored. `VICTORY_DXR_RAYQUERY` was not set, so this only shows the default path is unaffected. AI-assisted (Claude Code); no game data.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/469/head:github-bot/gh-469'
git switch 'github-bot/gh-469'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-469'
git switch 'github-bot/gh-469'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-469'
git switch 'github-bot/gh-469'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-469'
git switch 'a-publier'
git merge --squash 'github-bot/gh-469'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-469'
git switch 'a-publier'
git merge 'github-bot/gh-469'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.