Native NVIDIA RTX Hardware Ray Tracing (DXR 1.1) Implementation Guide
By @opengrip | Live Roadmap: https://rentry.co/opengrip-gtavi
This write-up documents how console ray tracing from an Xbox Series X (AMD RDNA 2) title is translated onto native NVIDIA RTX hardware RT cores using D3D12 DXR 1.1 RayQuery in victory-next, achieving 100% hardware RT across all 26 active RT shaders (0.0 software BVH).
1. Why Console RT Cannot Run Directly on NVIDIA RT Cores
On Xbox Series X, the title does not call standard PC DXR (TraceRay or HLSL RayQuery). Instead:
- Manual traversal loops in compute shaders: All ray-tracing passes are standard compute shaders that manage a per-thread traversal stack in shared memory and read BVH nodes through raw 40-bit guest GPU virtual addresses.
- One console hardware instruction: Traversal relies on RDNA 2's
image_bvh_intersect_rayandimage_bvh64_intersect_rayinstructions, which test a ray against a single 64-byte or 128-byte RDNA 2 BVH4 box node or triangle leaf node. - Pre-built static BVH4 + custom builder: Static world geometry ships pre-built ("dehydrated") in RDNA 2 BVH4 format and is rehydrated on GPU. Dynamic geometry (vehicles, characters, props) is built and refitted every frame by 52 compute shaders inside
XboxBvhBuilder.dll.
Emulating image_bvh*_intersect_ray in software ALU code works as a fallback, but it burns 40+ ms per frame on general-purpose shaders while leaving NVIDIA's dedicated RT cores completely idle. To run on RTX RT cores, we have to lift both the shaders and the acceleration structures into native D3D12 DXR 1.1.
2. End-to-End Pipeline Architecture
3. Stage 1: Lifting RDNA 2 Traversal Loops to DXR 1.1 RayQuery
Implemented in crates/victory-shader/src/emit/rt_lift.rs, lower.rs, and rayquery.rs.
Structural Loop Analysis (rt_lift.rs)
Instead of pattern-matching individual shader hashes, the translator performs generic CFG and SSA dataflow analysis on any natural loop containing image_bvh_intersect_ray or image_bvh64_intersect_ray:
- Extract ray inputs: Traces the world-space ray
origin,dir,t_max, optionalt_min, and the root table(slot, dword)holding the guest TLAS descriptor (USER_HW_RT_TLAS_SLOT). - Extract inline candidate hit subgraph (
CandSubCfg): Passes that handle alpha cutout foliage, fences, grates, portals, or transparent geometry run custom shader code on every transparent triangle hit before deciding whether to accept it. The lifter isolates this inner block region and lowers it directly inside a DXRwhile (rq.Proceed())loop, preserving loop-carried side-channel accumulators (CarryPhi) andD3D12_RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCHearly breaks. - Handle dual-query face filters (
ClosestBackfaceT): Shaders that track the closest backface distance alongside primary hits lower to a secondary hardwareRayQuerywith flipped culling flags (0x11/0x21). - Reconstruct all RDNA 2 live-out values: Downstream lighting and visibility-buffer code still expects exact RDNA 2 traversal outputs. After
rq.Proceed()completes, the emitted DXIL synthesizes every live-out role from DXR committed state plus our per-instance metadata buffer (USER_HW_RT_META_SLOT):CommittedStatus(1hit /0miss)CommittedRayT,CommittedBaryU,CommittedBaryV,CommittedFrontFaceCommittedInstPtr=((inst_byte_off >> 3) | 6)CommittedLeafPtr= reconstructed directly fromCommittedPrimitiveIndex()and the instance'sleaf_offsetCommittedBlasDiv256,CommittedIdMask,CommittedFlagsRaw,CommittedRootPtr
Hardware Safety Guards (lower.rs)
Before calling TraceRayInline, emitted DXIL guards against null TLAS handles and NaN / Inf ray origins, directions, or bounds so malformed guest rays cleanly report a miss instead of triggering a GPU page fault or TDR on NVIDIA hardware.
Result
All 26 / 26 identified hardware RT shaders across Reflections/RTGI (6), Sun & Local RT Shadows (12), Distant & LOD RT Shadows (5), and Special FX/Depth Helpers (3) translate and compile cleanly into native DXR 1.1 PSOs with zero compile failures.
4. Stage 2: Hooking XboxBvhBuilder.dll (HLE)
Implemented in crates/victory-hle/src/modules/bvh_builder.rs.
The HLE module intercepts all 7 C++ exports of XboxBvhBuilder.dll while keeping the real console DLL mapped via victory-loader:
BuildRaytracingAccelerationStructureBatched2X: captures every dynamic BLAS geometry descriptor (vertex_buffer_va,vertex_format,vertex_stride,index_buffer,index_format,transform3x4, opaque flags) and every TLAS instance descriptor array.CopyRaytracingAccelerationStructure: mirrors compacted/copied BLAS aliases so native DXR BLAS entries follow guest compaction moves without rebuilding.RehydrateRaytracingAccelerationStructureBatched2X: records exact static BLAS destination addresses and byte sizes as static world chunks stream in.GetRaytracingAccelerationStructurePrebuildInfo: ensures guest allocations are large enough for our 64-byte-per-triangle RDNA 2 leaf metadata mirror whenSUPPRESS_BUILDERis active.
When VICTORY_NATIVE_RT_SUPPRESS_BUILDER=1 is enabled, dynamic BLAS builds/copies and TLAS compute dispatches inside XboxBvhBuilder.dll are suppressed completely, cutting out the console's software BVH construction overhead on the GPU.
5. Stage 3: Zero-Fault GPU BLAS Unpacking, Compaction & Refits
Implemented in crates/victory-gpu/src/hw_rt.rs.
UAV-Safe Page Gathering (GATHER_UAV)
Guest BVH arenas in memory.rs stay in D3D12_RESOURCE_STATE_UNORDERED_ACCESS. Rather than transitioning arenas to COPY_SOURCE mid-command-list (which triggers state conflicts and stalls), GATHER_UAV reads guest pages through a root RWByteAddressBuffer into a reusable per-call Workspace ring buffer.
Static World BLAS Path (UNPACK_BLAS)
Rehydrated static chunks arrive as RDNA 2 BVH4 buffers:
- A GPU compute pass unpacks each 64-byte triangle leaf into 4 flat
R32G32B32_FLOATtriangles (PrimitiveIndex() == leaf * 4 + k), writing quietNaN(0x7fc00000) for inactive slots so DXR ignores them without requiring atomics or compaction indices. - The pass records the true header
leaf_offset(src.Load(52)) on GPU soUNPACK_TLASnever stalls the CPU to read back BVH headers.
Batched Dynamic BLAS Path (UNPACK_DIRECT_BLAS)
For dynamic meshes captured via BuildBatched2X:
- Batched zero-bubble execution: All dynamic BLASes queued in a frame are packed into non-overlapping 256-byte-aligned slices of
ws.vertsandws.scratch. AllUNPACK_DIRECT_BLASdispatches run back-to-back (1 barrier), followed by all nativeBuildRaytracingAccelerationStructurecalls back-to-back (1 barrier). This cuts roughly 180 pipeline-draining barriers per frame down to 3. - Unpadded 1-tri/leaf layout: Splits triangles into 2 DXR geometries (
OPAQUEandNON-OPAQUE) with 1 triangle per leaf (4xsmaller vertex and BLAS memory footprint than 4-tri padding), signaled to liftedRayQueryshaders via bit 0 ofreal_leaf_offset(129 = 128 | 1). - Synthetic RDNA 2 leaf mirror: Writes a valid 64-byte RDNA 2 BLAS header plus 64-byte leaf records (
p0,p1,p2,geo_idx,is_opaque,tri_idx) directly into the guest BLAS buffer so downstream visibility/material shaders that dereferenceCommittedLeafPtrread valid triangle metadata. - Compaction and ping-pong refits:
- First builds and semi-static props use
ALLOW_COMPACTION(~85% VRAM reduction). - Frequently rebuilt meshes (such as skinned characters rebuilt within 32 frames) upgrade once to double-buffered
ALLOW_UPDATEand execute out-of-placePERFORM_UPDATEping-pong refits between two buffers so Frame N never mutates a BLAS still traced by Frame N-1's TLAS.
- First builds and semi-static props use
6. Stage 4: GPU TLAS Translation & Metadata Mirror (UNPACK_TLAS)
Every TLAS build translates guest D3D12_RAYTRACING_INSTANCE_DESC records on the GPU into native DXR TLAS descriptors plus a 32-byte-per-instance dst_meta table:
- 16-frame descriptor ring: Each TLAS owns a 16-frame ring of
(tlas_slot, meta_slot)descriptors so Frame N never overwrites descriptors still in flight on the GPU. Replaced acceleration structure and workspace buffers go through delayedretire_resourcecleanup. - Exact hit mapping:
dst_metastores(real_leaf_offset, blas_div256, inst_byte, flags_raw, id_mask, root_ptr)indexed by DXRInstanceIndex(). Lifted shaders perform a single structured load on hit to reconstruct every console pointer with zero CPU synchronization.
7. Verified Live Telemetry (RTX 5080, Step S28b PS5 Pro Preset)
Measured directly from live gameplay runs (VICTORY_HW_RT=1, VICTORY_NATIVE_RT_SUPPRESS_BUILDER=1):
- Hardware RT coverage:
26 / 26RT shaders lifted and compiled,100.0%HW RT,0.0SW BVH. - TLAS instance match rate:
95% - 97%steady-state match across260,000 - 458,000sampled instances per telemetry window. - Active BLAS pool & VRAM:
~684static BLASes (29 MBVRAM) +~3,458dynamic BLASes (374 MBVRAM), with1,416 MBsaved by DXR BLAS compaction across the run (40,559direct dynamic builds,26,555ping-pong refits). - Steady-state
hw_rtCPU overhead:~10.6 mstotal per logging window (~6.4 msdynamic build prep,~2.1 msTLAS prep).
8. Current Open Edge Case: R16_TYPELESS Compressed Index Pools
While auditing XboxBvhBuilder.dll's LoadTriangles compute shader, we confirmed an important console-specific detail:
- In
XboxBvhBuilder.dll,DXGI_FORMAT_R16_UINT(57) maps to mode1(flat 16-bit indices) andDXGI_FORMAT_R32_UINT(42) maps to mode2(flat 32-bit indices). DXGI_FORMAT_R16_TYPELESS(53) maps to mode4, which is not a flat 16-bit index buffer. Instead,LoadTrianglesdecodes a compressed meshlet/block layout:- 12-byte header at offset
0:num_blocks = h0 & 0x1FFFF,num_tris = h1. - 16-byte block table at offset
12: each entry stores a 17-bit base index into the index pool ((b1 & 0xFFFF) | ((b0 << 2) & 0x10000)). - 4-byte triangle selector table at
12 + num_blocks * 16: for each trianglet,block_idx = sel >> 21, plus three 7-bit local offsets(sel >> 0) & 0x7F,(sel >> 7) & 0x7F, and(sel >> 14) & 0x7F. - Packed
u16index pool at12 + num_blocks * 16 + num_tris * 4: final vertex indices are read atpool_off + (pool_base_idx + local_i) * 2(with optional winding swap when bit 15 ofElementTypeAndStrideis set).
- 12-byte header at offset
Right now, UNPACK_DIRECT_BLAS still reads R16_TYPELESS as a flat 16-bit index buffer (idx_mode = 1). Adding a dedicated idx_mode = 3 decoder matching LoadTriangles mode 4 is queued next to ensure compressed dynamic RT meshes decode with 100% geometric accuracy.