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:
- Live Roadmap & Milestones: https://rentry.co/opengrip-gtavi
- NVIDIA RTX Hardware RT Guide: https://rentry.co/opengrip-nvidia-rt
- RT & BVH Engineering Audit: https://rentry.co/opengrip-rt-audit
Part 1: DXR ABI Capture (XboxBvhBuilder.dll HLE -> Native DXR 1.1)
1.1 DLL Interception & Forwarding (bvh_builder.rs)
- HLE claims
XboxBvhBuilder.dlland hooks all 7 MSVC x64 C++ exports:XboxBvhBuilder::XboxBvhBuilder(ID3D12Device11*, bool)XboxBvhBuilder::~XboxBvhBuilder()BuildRaytracingAccelerationStructureBatched2X(ID3D12GraphicsCommandList6*, UINT, const D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2*)CopyRaytracingAccelerationStructure(ID3D12GraphicsCommandList4*, UINT64, UINT64, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE)GetRaytracingAccelerationStructurePrebuildInfo(const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS*, const D3D12XBOX_XDXR_STREAM_DESC*, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_PREBUILD_INFO*)RehydrateRaytracingAccelerationStructureBatched2X(ID3D12GraphicsCommandList8*, UINT, const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC*, const UINT64*)Set64BitMortonCodes(bool)
- The real
XboxBvhBuilder.dllis loaded internally viavictory-loaderso any non-suppressed call forwards cleanly with console imports bound.
1.2 Captured ABI Struct Layouts (Compile-Time Size/Offset Asserted)
GuestBuildAsInputs(0x18bytes):kind(0= TLAS,1= BLAS),flags,num_descs,descs_layout(0= contiguous array,1=ARRAY_OF_POINTERS),ptr_or_va.GuestBuildAsDesc(0x30bytes):dest_va(+0x00),inputs(+0x08),source_va(+0x20),scratch_va(+0x28).GuestBatchedDesc2(0x50bytes):desc(+0x00),num_postbuild_info_descs(+0x30),postbuild_info_descs(+0x38),stream_desc(+0x40).GuestGeometryDesc(0x38bytes):kind(0= Triangles0x30bytes,1= AABBs0x18bytes),flags, union payload (transform3x4,index_format,vertex_format,index_count,vertex_count,index_buffer,vertex_buffer_va,vertex_buffer_stride).GuestPostbuildInfoDesc(0x10bytes):dest_buffer,info_type.GuestPrebuildInfo(0x18bytes):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 compressedR16_TYPELESSMode 4 index buffers (12-byte header 16-byte block table with 17-bitpool_base = (b1 & 0xFFFF) | ((b0 << 2) & 0x10000)4-byte selector -> packedu16pool +0x8000winding bit). - Runs
UNPACK_DIRECT_BLASon GPU to feed native D3D12BuildRaytracingAccelerationStructure(compacted static/initial builds plus double-buffered ping-pongALLOW_UPDATE/PERFORM_UPDATErefits for moving geometry). - Writes a 1-triangle-per-64B RDNA2 leaf metadata mirror (
(128 + tris * 64)aligned to256bytes, capped at16,384triangles per dynamic BLAS) so lifted trace shaders reading guest leaf data stay accurate.
- Captures owned geometry descriptors into
- Direct TLAS (
kind == 0):- Captures
(dest_va, num_descs, descs_layout, instance_descs_va)intoPENDING_DIRECT_TLASES. UNPACK_TLAStranslates guestD3D12_RAYTRACING_INSTANCE_DESCarrays 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).
- Captures
- Static BVH Rehydration & Compaction Copies:
RehydrateRaytracingAccelerationStructureBatched2Xforwards to the real DLL and records(dest_va, size_bytes)inPENDING_BVH_REHYDRATES.UNPACK_BLASreads rehydrated 64-byte RDNA2 triangle leaves via a root UAV (GATHER_UAV, avoidingUNORDERED_ACCESS -> COPY_SOURCEstate transitions), emits 4 triangles per leaf (prim_idx = leaf * 4 + k, quietNaNfor inactive slots) for deterministicPrimitiveIndex, and capturesleaf_offset(src.Load(52)) on GPU with zero CPU stalls.CopyRaytracingAccelerationStructurealiases native BLAS handles acrossdest_va <- src_vaso compaction copies require zero rebuild.
- Synthetic Prebuild & Postbuild Info:
- When suppressed, HLE writes exact
256-byte aligned sizes intopostbuild_info_descs(info_type0/2/3= mirror size,1=0) and clampsGetPrebuildInfo.result_data_max_size_in_bytesupward so the game's fixed RTAS heap never under-allocates.
- When suppressed, HLE writes exact
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.6while (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:
DPProw opsds_swizzlev_permlane16/v_permlanex16ds_bpermute(32-lane scoped on GFX10+)
- Also requires no barrier-less intra-wave LDS sharing across
>32threads. - 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), andWave::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_mbcntused 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 UAVu251. - NVIDIA 2D
16x2warp-packing fix (ticket/halves): Because NVIDIA packs 2D threadgroups in16x2tiles 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 lanes0..63. - Partial final group deadlock prevention (
partial_active): Threads pastUSER_DISPATCH_THREADS_Xstay alive to reach exchange group barriers instead of returning early, while memory ops,EXECballots, and wave reductions mask them out usingpartial_active. - Exchange pruning: Values proven
lane_uniformskip cross-halfv_readfirstlaneexchange. 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.rscomputesall_lane_blocks(blocks guaranteed reached by every lane) and inserts group barriers only where cross-half ordering matters.- Static
lds_orderanalysis (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) andlds_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.