[WIP / Draft] Parallel DXR 1.1 acceleration structures (Stage 1) behind VICTORY_DXR_RAYQUERY=1 #469
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!469
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-469"
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?
@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 · draftSummary & 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 viaRayQuery.This draft implements Stage 1 only behind
VICTORY_DXR_RAYQUERY=1(opt-in, off by default):XboxBvhBuilder.dll(dual/shadow mode — the console BVH4 remains in place).dxc.exewith BLAKE3 disk caching (no.dxilbinaries in the repository;cargo xtask policypasses).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.8c98bab) portingVICTORY_BVH_SIZES_BOUND(on by default whenVICTORY_BVH_BUILDER=1,=0to disable; see Attribution and Separate Finding below).RayQuery) is NOT included here.Behavior when
VICTORY_DXR_RAYQUERYis unsetOnceLock<bool>(dxr::enabled() == false);title_memory_freed()performs oneOnceLockcheck and returns immediately.8c98bab(VICTORY_BVH_SIZES_BOUND) is enabled by default wheneverVICTORY_BVH_BUILDER=1(matchingnotquiteog/victory-nvidia@57dd221), so running withVICTORY_BVH_BUILDER=1does change compacted-size slot writes unlessVICTORY_BVH_SIZES_BOUND=0is set.Test Environment & Wine Dependencies
d16accesses / faces),VICTORY_KEYS),VICTORY_HOLE_SKIP) and a patchedwineserver(viewtree),VICTORY_RT_TIMING) used to capture the livegpu_ms/ffigures below (omitted from this branch so the diff stays focused on DXR).VICTORY_DXR_RAYQUERY=1compiles the 5 embedded SM 6.6.hlslfiles viadxc.exe(resolved fromVICTORY_PC_DXC, next tovictory.exe, the Windows SDK default path, orPATH).Design
XboxBvhBuilder.dllpass-through HLE hook (crates/victory-hle/src/modules/bvh.rs)GetRaytracingAccelerationStructurePrebuildInfo,BuildRaytracingAccelerationStructureBatched2X,RehydrateRaytracingAccelerationStructureBatched2X, andCopyRaytracingAccelerationStructure.XboxBvhBuilder.dllfirst, pre-opening destination ranges inmemory.rs(dxr_prepare_dests) before builds run.crates/victory-gpu/src/dxr/)extract_triangles.hlslreads already-decodedTriangleNodeleaves directly out ofmemory.rsarenas/shadows into a temporaryR32G32B32_FLOATbuffer (pre-filled with quiet NaNs byclear_nan.hlslso unused slots are skipped by DXR).OPAQUEandNON_OPAQUE, slottid * 2 + k), validatesleaf_off/num_nodes, maps BLASes up to 64 MiB inmemory.rs(dxr_bind), and invertsheader[15](objectToLocal: scale,sceneBoundsmidpoint offset, and 6-bit quantized Euler rotationR^T) back to object space.bad_hdrrefit fallbackremap_instances.hlslremaps 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.hlslwrites1(valid) or0(bad_hdr) to a sharedblas_validbuffer,remap_instances.hlslfalls back to the previous valid host BLAS on the GPU with no CPU stall if0, andsettle_pending_updates()revertsblas_mapand frees the empty buffer once the submission finishes.VICTORY_DXR_VERIFY=1&verify_test.rs)verify_rayquery.hlsl(host DXR 1.1 TLAS) andverify_console_bvh.hlsl(console BVH4 inmemory.rs).verify_console_bvh.hlslwalks 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 dumpingInstanceNode.Transform,w2o, BLAS header, and first/hit leaf vertices on mismatches.How to Reproduce
Policy & static checks
Synthetic GPU & unit tests (no title required)
Requires DXR Tier 1.1 and
dxc.exe(setVICTORY_PC_DXCif not in Windows SDK /PATH; tests skip cleanly if either is absent):Live run with parallel DXR + differential verifier
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-trivialheader[15]rotation/offset/scale):con_hits = 18,101,rq_hits = 18,101100.0000%|tmatch:100.0000%(max_t_err = 0.000051) |InstanceIDmatch:100.0000%build = 0.513 ms,RayQuery = 0.165 msvsconsole_bvh = 0.331 ms(2.01x)67.2 KBbad_hdr_refit_preserves_valid_host_blas:valid_slots=(1,0),bad_hdr=1,fallback_used=1,64/64hits preserved.radv_all_nan_blas_in_tlas_probe:64/64hits.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:
SIZES_BOUND=0(28 runs)SIZES_BOUND=1(26 runs)tmatch (median / mean / range)inst_idmatch (median / range)tmatchinst_idmatchtris/oob/bad_hdrmapped/missing/fb_gpu/refit_revertedSIZES_BOUND=0session, 21 of 28 runs reached 99.971–100.000% filtered hit agreement (median 99.993% hit / 99.964%t, 5 runs at 100.000%), with0extraction OOBs over 27.7M triangles and0missing BLAS remaps over 2.29M instances.h0 = 0x80020006rehydrated BLASes (session 2, runs 14–26): A rehydrated BLAS withh0 = 0x80020006,h15 = 0x808e8f8f(scale = (65536, 65536, 32768)), and validTriangleNodemetadata (meta = (0x181, 0xa9, 0xaa, 0x904)) had vertex dwords0xf8a3de7band0x5c60fabf. Decoded as signedi16(-8581, -1885, -1345, +23648) and divided byh15scale, those coordinates fall insidebmin..bmax([-0.85..0.86, -0.83..0.91, -0.16..1.50]). Becauseextract_triangles.hlslread them asfloat32, it emitted huge triangles at±4e29that generated 1,700–3,024 false DXR hits per run.scratch/temp_inst/ TLAS buffer hazard under heavy multi-queue load (session 2, runs 2, 4, 9): Three verification runs recordedrq_hits = 0..15against 4,266–7,312 console hits whiletlasbuilds reached 24–48/frame across concurrent command lists sharing a singlescratchandtemp_instbuffer.InstanceIDwas reportedNOT FOUNDwhen walking the console TLAS.3. Cost (GPU ms/frame & VRAM)
(GPU ms/f measured via the local
VICTORY_RT_TIMINGprofiler on the same Wine/RADV/RX 9070 XT setup; not included on this branch.)SIZES_BOUND=0): median 15.20 ms/frame (13.62 msBLAS +1.37 msTLAS; range4.12–32.38 ms/f).SIZES_BOUND=1, heavier streaming): median 20.84 ms/frame (19.18 msBLAS +1.55 msTLAS; range9.94–38.57 ms/f).VICTORY_DXR_VERIFY=1only):0.64–0.87 ms/famortized.~1.9–2.0 GiBacross~2,180–2,240live host BLASes,~1.1 MiBTLASes, plus 64 MiB upload ring + scratch/temp buffers). No DXR BLAS compaction is implemented yet, and BLASes use worst-casemax_nodes * 4NaN-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
TriangleNodefloats/metadata).CopyRaytracingAccelerationStructure) reading staleGetBVHCompactedSizeslots under async/thin-list submission, rather than from the parallel DXR backend.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.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,bvhsizematched 553 / 2,434 (22.7%) ofGetBVHCompactedSizequeries (asked_without = 1,881,put_back = 97), leaving ~77% of size queries without a bound.Next Steps (for anyone continuing this work)
VICTORY_DXR_RAYQUERY=0to verify whether corrupted BLAS headers occur at the same rate without DXR active, and investigate why ~77% ofGetBVHCompactedSizequeries missbvhsize's bound table.h0 = 0x8002000616-bit quantized leaves (or skip/guard non-float32 leaf payloads inextract_triangles.hlsluntil decoded).scratch/temp_inst/temp_vertsand in-flight TLAS reuse across concurrent command lists (per-list or ring-buffered allocations).max_nodes * 4NaN-padded buffers, and avoid re-extracting unchanged BLASes.RayQueryshader 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 insideProceed(), instance masks, ray flags, and hit payload layout.🤖 Generated with Claude Code
@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-gpu406 passed, 0 failed, 34 ignored;victory-hle163 passed, 0 failed, 2 ignored.VICTORY_DXR_RAYQUERYwas not set, so this only shows the default path is unaffected.AI-assisted (Claude Code); no game data.
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.