Proposal: opt-in host DXR path for the title's acceleration structures, with inline RayQuery for its traversal shaders #1751
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#1751
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@AlexMJHGF421 on GitHub · 2026-11-24 20:14 UTC · original
Summary
Today XCL runs the real
XboxBvhBuilder.dllnatively, replays its console command-list records as host compute, and gets console-format BLAS/TLAS (README, HANDOFF.md L429-L434).The title's traversal shaders walk those nodes themselves, and
image_bvh*_intersect_rayis emulated one node per instruction in both backends (HLSL, direct DXIL).This works, and a lot of recent work improves it (#26, #146, #631, #680, #1693, #1542, #1554, #1559).
It never uses the GPU's ray-tracing hardware, though, and the shaders that carry the traversal are among the most expensive to compile: in #505
ActivateProbes/ActivateProbesTarget/ActivateRayscame out at about 29 / 29 / 14 MB of DXIL on an RTX 3090 Ti, andActivateRayswas still in the NVIDIA driver compiler after 839 s; DXC refusals on 11–12 MB RT shadow-trace inputs are reported in #1269.This issue proposes an opt-in second path:
XboxBvhBuilder.dllbatched exports and build host DXR BLAS/TLAS from the inputs the title passes, side by side with the existing console structures.RayQuery, gated per dispatch, with the current emulated walk as the fallback.Nothing here is implemented or measured; it is a design with pointers into XCL and into other projects that reversed the same pieces.
I found no open or merged PR doing this.
Why it is feasible
The title describes its geometry through a DXR-shaped API.
five-star-recomp reversed it (
docs/raytracing.md,docs/d3d12x-shim.md):DisableDXR = 1and builds every structure throughXboxBvhBuilder.dll.BuildRaytracingAccelerationStructureBatched2X. Each 0x50-byteBATCHED_DESC2record starts with desktop-shaped fields: destination VA (0x00), inputs type/flags/count/layout (0x08–0x14), geometry-desc CPU pointer or instance-data VA (0x18), source and scratch VA (0x20, 0x28), and a per-record postbuild count and pointer (0x30, 0x38). Postbuild records are 0x10 bytes (destination VA, type).D3D12_RAYTRACING_INSTANCE_DESC-sized records.PERFORM_UPDATE, source = destination).core_bvh4.rpfand come back throughRehydrateRaytracingAccelerationStructureBatched2X, which rebuilds them from the title's vertex data (L74-L108).BvhBuilderShim.cs.Proposed stages
1. Build-only prototype (no shader changes)
XboxBvhBuilder.dllhas no HLE route today; it is mapped and its exports resolve toimage_base + rvainresolve_export_of_mapped_inner. A per-DLL override there (Batched2X build, Rehydrate, Copy, PrebuildInfo) covers static imports, delay imports andGetProcAddresswhile the constructor, destructor and other exports stay native, and lets the shim forward to the original when it does not handle a record.title_list::backing()returns the primary list; after a mid-list split the active recording list differs, so DXR builds need an accessor for the active one. On the opt-inXCL_CONSOLE_LISTSpath they would have to go into the ordered replay.real::uma_va_of,list_x::pc_va), keeping sparse residency and dirty-upload ordering. Query host prebuild sizes onID3D12Device5, allocate host result and scratch separately (the title keeps its console-sized answers), record onID3D12GraphicsCommandList4, and remap TLAS instance BLAS references to host addresses. Gate on the real host DXR tier, not on the tier reported to the title throughraytracing/XCL_RAYTRACING(real.rs L2629).gpu/bvh.rs.2. Bind a host TLAS
Today an acceleration-structure SRV writes the console BVH descriptor and never creates a host SRV (real.rs L2068-L2081).
A host AS SRV could live in a separately allocated view-heap slot (the translated compute root signature already enables direct heap indexing, pso.rs L841), with its index passed to the translated shader, alongside the console descriptor rather than instead of it.
3. RayQuery for recognised traversal regions
cs_6_6, which covers inlineRayQuery. The direct DXIL writer has the extension points but norayQuery_*ops, AS resource kind or feature bits yet.RayQueryTraversal.cpp) needs use-def information XCL builds only during emission. For a first version, a small set of traversal regions selected by shader hash may be simpler; XCL has dump hooks (XCL_DUMP_SHADERS,XCL_DXIL_DUMP) but no general compute replacement-by-hash hook yet.spirvEmitterRayQuery.cpp,gpu_bvh_mirror.comp).(t numerator, denominator, I numerator, J numerator); the swizzle byte of the selected triangle says which vertices I and J weight, so host barycentrics need that permutation and winding corrected by its parity. Map host instance/geometry/primitive indices back to guest IDs (paired leaves matter). For alpha-tested geometry, expose non-opaque candidates, run the guest acceptance logic, commit only accepted hits. Keep the emulated path for consumers that depend on denominator magnitude, exact rounding or candidate order.bvh.rs): transform at 0x00, ID and mask at 0x30, contribution and flags at 0x34, BLAS root and translation-only bit at 0x38, BLAS base >> 8 at 0x3C (five-star "Traversal header").0xD5there is the ray's inclusion mask.RayQueryis per lane, but ifProceed()feeds guest EXEC, a vote or a scalar loop exit, both halves still have to reach the same exchanges in the same order.What to measure
Prior art elsewhere
BuildRaytracingAccelerationStructureto host list4 and selects RayQuery or a compute BVH4 fallback per host and shader (command_list_x.cpp,device_x.cpp,dxr_hardware.cpp). Its export with this title'sBatched2Xsignature is a stub, its postbuild handling is per batch rather than per record, and its instance-node encoding does not match the offsets above, so it is a reference for the host side only.rayTracing.cpp). Its matcher is tied to PS5 SDK code shapes; the design transfers, the matcher does not.src/FiveStar.Shaders/Bvh/XdxrBlas.cs,XdxrTlas.cs). Note its BLAS header is 64 bytes while XCL's CPU builder reserves 256 before the nodes; both put the root at 0x30.Open questions
@marquezinii on GitHub · 2026-11-24 21:04 UTC · original
A first number for What to measure ("GPU time per trace dispatch, host path vs emulated path, same scene"), synthetic and without a title. The test is in #1815.
Same terrain, built once as a console BVH (
bvh::build, walked with a short stack and the translator's ownbvh_intersect) and once as a DXR BLAS + TLAS traced withRayQuery. 1 048 576 rays per run, best of 5 by GPU timestamps, two runs each. RTX 5070, driver 621.40:RayQueryAI use: Claude Code (Claude Opus 5.5) wrote the test, ran it and drafted this comment.
@nineforge0 on GitHub · 2026-11-24 23:06 UTC · original
A census of the traversal sites, for the open question "whether the traversal regions in the title's RT programs share a few shapes". Counts and program names only, from the title's shader database (entry 0 of
shaders.rpf).Where the intersect ops are. 716 sites in 64 compute programs (of 2,647):
image_bvh_intersect_ray638 sites in 40 programs,image_bvh64_intersect_ray78 sites in 24. No program uses both.Shapes. Every site has a
v_min3/v_med3/v_max3_u32child sort within 40 instructions after it, an LDS push within 80, and an enclosing backward-branch loop. There are four variants:image_bvh_intersect_rayds_write_b320x3fc(256 dwords)image_bvh_intersect_rayds_write2_b32image_bvh64_intersect_rayds_write_b320x7fc(512 dwords)image_bvh64_intersect_rayds_write_b320xffc(1,024 dwords)Each of the 40 programs with 32-bit sites has the first two in equal numbers; each 64-bit program uses one ring size. 16 sites, all 64-bit and in 6
indirect_light_probes/sr_tracingprograms, also carry ans_cmpk_lt_u32 sN, 0xffffiteration cap. So a matcher looks worthwhile: a few patterns, with the ring size as a parameter, rather than per-program handling. The checks are syntactic (the instructions are present near the site; data flow is not checked).How much RayQuery could replace. 45.4% of the 636,661 instructions in those 64 programs lie in the innermost loop around a site, and 57.7% to 60.5% in the three biggest,
rtdirectionalshadows:CS_RTShadowTrace32HQ_Tiled,CS_RTShadowTrace32TemporalHQ_TiledandCS_RTShadowTrace32TemporalHQ_OneOver2RPP_Tiled(44k to 47k instructions each). That loop span also holds whatever else the loop body does, so it is an upper bound on what a rewrite removes. By family:rtdirectionalshadows:CS_RTShadowTrace32*shadowmask:CS_TraceShadowRays*sr_tracing:CS_RaytraceVBuffer*indirect_diffuse_lighting:CS_ScreenProbes_TraceRays*rtdirectionalshadows:CS_RTDistant*indirect_light_probesgathers and shadow tracesCorrection on the compile bombs. The three biggest programs,
indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes,ActivateProbesTargetandActivateRays(88,862, 88,444 and 74,570 instructions; the three measured in #505), contain no intersect op, so inlineRayQuerywould not shrink them. The same holds for the 42*:CS_RaytracingResolvevariants and the twocascadeshadows_rendering:CS_ShadowRenderTiledCascades*. Of the 57 programs over 20,000 instructions (list), 9 have intersect sites, all of themrtdirectionalshadows:CS_RTShadowTrace32*. Among the big programs, inlineRayQuerywould shrink only those; the screen-probe activate passes need a different fix.Reproduce with forge9:
Method, limits and the full tables are in docs/rt_traversal_census.md.
If it would help, I could look at a traversal-region recognizer for these shapes as a follow-up. No promises on scope or timing.
AI use: drafted with Claude Code (Claude Opus 5.5) for @nineforge0.