DXR ABI Capture & Wave64-to-Warp32 Translation (@opengrip Architecture Notes)

Exact engineering definition of how victory-next captures console ray-tracing ABI calls onto native NVIDIA DXR 1.1 RT cores and translates RDNA2 Wave64 shaders onto NVIDIA's 32-lane warp model.

Related pages:


Part 1: DXR ABI Capture (XboxBvhBuilder.dll HLE -> Native DXR 1.1)

1.1 DLL Interception & Forwarding (bvh_builder.rs)

  • HLE claims XboxBvhBuilder.dll and hooks all 7 MSVC x64 C++ exports:
    1. XboxBvhBuilder::XboxBvhBuilder(ID3D12Device11*, bool)
    2. XboxBvhBuilder::~XboxBvhBuilder()
    3. BuildRaytracingAccelerationStructureBatched2X(ID3D12GraphicsCommandList6*, UINT, const D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2*)
    4. CopyRaytracingAccelerationStructure(ID3D12GraphicsCommandList4*, UINT64, UINT64, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE)
    5. GetRaytracingAccelerationStructurePrebuildInfo(const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS*, const D3D12XBOX_XDXR_STREAM_DESC*, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO*)
    6. RehydrateRaytracingAccelerationStructureBatched2X(ID3D12GraphicsCommandList8*, UINT, const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC*, const UINT64*)
    7. Set64BitMortonCodes(bool)
  • The real XboxBvhBuilder.dll is loaded internally via victory-loader so any non-suppressed call forwards cleanly with console imports bound.

1.2 Captured ABI Struct Layouts (Compile-Time Size/Offset Asserted)

  • GuestBuildAsInputs (0x18 bytes): kind (0 = TLAS, 1 = BLAS), flags, num_descs, descs_layout (0 = contiguous array, 1 = ARRAY_OF_POINTERS), ptr_or_va.
  • GuestBuildAsDesc (0x30 bytes): dest_va (+0x00), inputs (+0x08), source_va (+0x20), scratch_va (+0x28).
  • GuestBatchedDesc2 (0x50 bytes): desc (+0x00), num_postbuild_info_descs (+0x30), postbuild_info_descs (+0x38), stream_desc (+0x40).
  • GuestGeometryDesc (0x38 bytes): kind (0 = Triangles 0x30 bytes, 1 = AABBs 0x18 bytes), flags, union payload (transform3x4, index_format, vertex_format, index_count, vertex_count, index_buffer, vertex_buffer_va, vertex_buffer_stride).
  • GuestPostbuildInfoDesc (0x10 bytes): dest_buffer, info_type.
  • GuestPrebuildInfo (0x18 bytes): result_data_max_size_in_bytes, scratch_data_size_in_bytes, update_scratch_data_size_in_bytes.

1.3 Suppression Modes (VICTORY_NATIVE_RT_SUPPRESS_BUILDER)

  • 0: Forward everything to the console builder.
  • 1 (active production mode): Suppress BLAS + TLAS + Copy console compute dispatches completely so zero software RDNA2 BVH builder shaders run on GPU.
  • 2 / 3: Suppress BLAS + Copy only while forwarding filtered TLAS-only batches (kind == 0) when guest TLAS buffers must remain populated by the original builder.

1.4 Native DXR 1.1 Routing (hw_rt.rs)

  • Dynamic BLAS (kind == 1):
    • Captures owned geometry descriptors into PENDING_DYN_BLASES.
    • Decodes R16_UINT, R32_UINT, and Xbox's compressed R16_TYPELESS Mode 4 index buffers (12-byte header 16-byte block table with 17-bit pool_base = (b1 & 0xFFFF) | ((b0 << 2) & 0x10000) 4-byte selector -> packed u16 pool + 0x8000 winding bit).
    • Runs UNPACK_DIRECT_BLAS on GPU to feed native D3D12 BuildRaytracingAccelerationStructure (compacted static/initial builds plus double-buffered ping-pong ALLOW_UPDATE / PERFORM_UPDATE refits for moving geometry).
    • Writes a 1-triangle-per-64B RDNA2 leaf metadata mirror ((128 + tris * 64) aligned to 256 bytes, capped at 16,384 triangles per dynamic BLAS) so lifted trace shaders reading guest leaf data stay accurate.
  • Direct TLAS (kind == 0):
    • Captures (dest_va, num_descs, descs_layout, instance_descs_va) into PENDING_DIRECT_TLASES.
    • UNPACK_TLAS translates guest D3D12_RAYTRACING_INSTANCE_DESC arrays straight into native D3D12 TLAS builds with a 16-frame ring of (tlas_slot, meta_slot) descriptors so in-flight submissions never overwrite active descriptors, paired with optional guest TLAS mirroring (VICTORY_HW_RT_TLAS_MIRROR=1).
  • Static BVH Rehydration & Compaction Copies:
    • RehydrateRaytracingAccelerationStructureBatched2X forwards to the real DLL and records (dest_va, size_bytes) in PENDING_BVH_REHYDRATES.
    • UNPACK_BLAS reads rehydrated 64-byte RDNA2 triangle leaves via a root UAV (GATHER_UAV, avoiding UNORDERED_ACCESS -> COPY_SOURCE state transitions), emits 4 triangles per leaf (prim_idx = leaf * 4 + k, quiet NaN for inactive slots) for deterministic PrimitiveIndex, and captures leaf_offset (src.Load(52)) on GPU with zero CPU stalls.
    • CopyRaytracingAccelerationStructure aliases native BLAS handles across dest_va <- src_va so compaction copies require zero rebuild.
  • Synthetic Prebuild & Postbuild Info:
    • When suppressed, HLE writes exact 256-byte aligned sizes into postbuild_info_descs (info_type 0 / 2 / 3 = mirror size, 1 = 0) and clamps GetPrebuildInfo.result_data_max_size_in_bytes upward so the game's fixed RTAS heap never under-allocates.

1.5 Trace Shader Lifting (rt_lift.rs -> SM 6.6 RayQuery)

  • Scans natural CFG loops containing RDNA2 image_bvh*_intersect_ray.
  • Classifies every loop live-out (CommittedRayT, ClosestBackfaceT, CommittedBaryU, CommittedBaryV, CommittedInstPtr, CommittedLeafPtr, CommittedFrontFace, CommittedBlasDiv256, CommittedIdMask, CommittedFlagsRaw, CommittedRootPtr, CarryPhi).
  • Extracts inline candidate-hit sub-CFGs (CandSubCfg) directly into SM 6.6 while (rq.Proceed()) loops running on hardware RT cores.

Part 2: Wave64 -> NVIDIA Warp32 Translation (lower.rs)

NVIDIA D3D12 enforces WaveLaneCountMax == 32 and rejects SM 6.6 [WaveSize(64)]. Instead of forcing heavy emulation onto every shader, lower.rs classifies each console Wave64 program into 4 lowering tiers:

Tier 1: Direct Native Wave32 (Zero Extra Overhead)

  • Used when cross-lane instructions stay strictly inside 32-lane halves:
    • DPP row ops
    • ds_swizzle
    • v_permlane16 / v_permlanex16
    • ds_bpermute (32-lane scoped on GFX10+)
  • Also requires no barrier-less intra-wave LDS sharing across >32 threads.
  • Emits native WaveSize(32) DXIL with thread relabeling so each host warp represents one half of a console wave (lanes 32k..32k+31) at zero LDS cost.

Tier 2: Host-Local Wave Idioms (wave_local / MaskData::Host)

  • Static dataflow analysis tracks Wave::First (s_ff1), Wave::Total (s_bcnt1), Wave::Prefix (v_mbcnt), and Wave::Base (first-lane atomic return value).
  • When a Wave64 compute shader only uses wave ops for the standard wave-compaction / atomic-reservation idiom (lane 0 reserves slots via atomic, each active lane adds its prefix to the returned base), it runs natively as independent 32-lane NVIDIA warps with zero cross-warp sync.
  • Pixel and vertex shaders use MaskData::Host: host-wave ballots for wave-size-agnostic ops (active counts, first lane, prefix count, equality).

Tier 3: Two-Half Wave64 Emulation via LDS Exchange (WAVE_EXCHANGE)

  • Triggered whenever compute code truly crosses the 32-lane boundary (v_mbcnt used as data, v_readlane_b32 / v_writelane_b32, ds_permute, 64-bit lane masks read as integer data, lane-constant masks, or wave-wide branches).
  • Each console Wave64 executes as two 32-lane NVIDIA warps exchanging through 2 extra LDS dwords per console wave (s.lds_dwords += 2 * group.div_ceil(64)). On meshlet shaders where title LDS already fills 32 KiB, the exchange and meet table spills to raw scratch UAV u251.
  • NVIDIA 2D 16x2 warp-packing fix (ticket / halves): Because NVIDIA packs 2D threadgroups in 16x2 tiles rather than linear 64-lane strips, the shader allocates an LDS ticket counter (wave_base + wave_rank) in the entry block so host warps map onto logical console lanes 0..63.
  • Partial final group deadlock prevention (partial_active): Threads past USER_DISPATCH_THREADS_X stay alive to reach exchange group barriers instead of returning early, while memory ops, EXEC ballots, and wave reductions mask them out using partial_active.
  • Exchange pruning: Values proven lane_uniform skip cross-half v_readfirstlane exchange. Wave ORs that only steer a per-lane bit loop (own_bits) execute locally inside each 32-lane warp.

Tier 4: Intra-Wave Barrier-Less LDS Ordering (lds_order / lds_meet)

  • On RDNA2, threads inside one Wave64 share LDS without s_barrier. Split across two 32-lane NVIDIA warps, those accesses can race.
  • lower.rs computes all_lane_blocks (blocks guaranteed reached by every lane) and inserts group barriers only where cross-half ordering matters.
  • Static lds_order analysis (VICTORY_LDS_ORDER=1) removes barriers on LDS accesses proven non-conflicting across halves.
  • When an LDS access lives inside divergent control flow, lds_meet (per-wave meet points) and lds_looped (fences for looped LDS atomics) preserve ordering without deadlocking a group barrier.

Published by @opengrip for side-by-side comparison with other RTX porting efforts.

Edit

Pub: 29 Nov 2026 23:04 UTC

Views: 249