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_ray and image_bvh64_intersect_ray instructions, 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

⎗
✓
[Console Compute Shader (RDNA 2 ISA)]
        |
        v  (1) victory-shader: CFG loop analysis + DXIL SM 6.6 RayQuery lifting
[Native D3D12 PSO using DXR 1.1 TraceRayInline / Proceed / Committed*]
        ^                                      ^
        | (4) Root SRV: Native DXR TLAS        | (4) Root SRV: Instance Metadata Table
        |                                      |
[UNPACK_TLAS (GPU Compute)]  <---  16-frame ring of (tlas_slot, meta_slot)
        ^
        |  Native DXR BLAS GPU VAs + RDNA 2 leaf_offset table
        +-------------------------------+
        |                               |
[Static World BLAS Path]        [Dynamic BLAS Path (SUPPRESS_BUILDER=1)]
XboxBvhBuilder Rehydrate        HLE intercepts BuildBatched2X raw VB/IB/XF
  -> GATHER_UAV (RWByteAddr)      -> UNPACK_DIRECT_BLAS (batched GPU unpack)
  -> UNPACK_BLAS (4 tris/leaf)    -> Synthetic 64B header + 64B leaf mirror
  -> DXR BuildBLAS + Compact      -> DXR BuildBLAS + Compact / Ping-Pong Refit

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:

  1. Extract ray inputs: Traces the world-space ray origin, dir, t_max, optional t_min, and the root table (slot, dword) holding the guest TLAS descriptor (USER_HW_RT_TLAS_SLOT).
  2. 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 DXR while (rq.Proceed()) loop, preserving loop-carried side-channel accumulators (CarryPhi) and D3D12_RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH early breaks.
  3. Handle dual-query face filters (ClosestBackfaceT): Shaders that track the closest backface distance alongside primary hits lower to a secondary hardware RayQuery with flipped culling flags (0x11 / 0x21).
  4. 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 (1 hit / 0 miss)
    • CommittedRayT, CommittedBaryU, CommittedBaryV, CommittedFrontFace
    • CommittedInstPtr = ((inst_byte_off >> 3) | 6)
    • CommittedLeafPtr = reconstructed directly from CommittedPrimitiveIndex() and the instance's leaf_offset
    • CommittedBlasDiv256, 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 when SUPPRESS_BUILDER is 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_FLOAT triangles (PrimitiveIndex() == leaf * 4 + k), writing quiet NaN (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 so UNPACK_TLAS never 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.verts and ws.scratch. All UNPACK_DIRECT_BLAS dispatches run back-to-back (1 barrier), followed by all native BuildRaytracingAccelerationStructure calls 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 (OPAQUE and NON-OPAQUE) with 1 triangle per leaf (4x smaller vertex and BLAS memory footprint than 4-tri padding), signaled to lifted RayQuery shaders via bit 0 of real_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 dereference CommittedLeafPtr read 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_UPDATE and execute out-of-place PERFORM_UPDATE ping-pong refits between two buffers so Frame N never mutates a BLAS still traced by Frame N-1's TLAS.

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 delayed retire_resource cleanup.
  • Exact hit mapping: dst_meta stores (real_leaf_offset, blas_div256, inst_byte, flags_raw, id_mask, root_ptr) indexed by DXR InstanceIndex(). 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 / 26 RT shaders lifted and compiled, 100.0% HW RT, 0.0 SW BVH.
  • TLAS instance match rate: 95% - 97% steady-state match across 260,000 - 458,000 sampled instances per telemetry window.
  • Active BLAS pool & VRAM: ~684 static BLASes (29 MB VRAM) + ~3,458 dynamic BLASes (374 MB VRAM), with 1,416 MB saved by DXR BLAS compaction across the run (40,559 direct dynamic builds, 26,555 ping-pong refits).
  • Steady-state hw_rt CPU overhead: ~10.6 ms total per logging window (~6.4 ms dynamic build prep, ~2.1 ms TLAS 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 mode 1 (flat 16-bit indices) and DXGI_FORMAT_R32_UINT (42) maps to mode 2 (flat 32-bit indices).
  • DXGI_FORMAT_R16_TYPELESS (53) maps to mode 4, which is not a flat 16-bit index buffer. Instead, LoadTriangles decodes a compressed meshlet/block layout:
    1. 12-byte header at offset 0: num_blocks = h0 & 0x1FFFF, num_tris = h1.
    2. 16-byte block table at offset 12: each entry stores a 17-bit base index into the index pool ((b1 & 0xFFFF) | ((b0 << 2) & 0x10000)).
    3. 4-byte triangle selector table at 12 + num_blocks * 16: for each triangle t, block_idx = sel >> 21, plus three 7-bit local offsets (sel >> 0) & 0x7F, (sel >> 7) & 0x7F, and (sel >> 14) & 0x7F.
    4. Packed u16 index pool at 12 + num_blocks * 16 + num_tris * 4: final vertex indices are read at pool_off + (pool_base_idx + local_i) * 2 (with optional winding swap when bit 15 of ElementTypeAndStride is set).

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.

Edit

Pub: 29 Nov 2026 13:24 UTC

Views: 514