Proposal: opt-in host DXR path for the title's acceleration structures, with inline RayQuery for its traversal shaders #1751

Open
opened 2026-11-26 05:03:46 +00:00 by github-bot · 2 comments
Owner

@⁠AlexMJHGF421 on GitHub · 2026-11-24 20:14 UTC · original

Summary

Today XCL runs the real XboxBvhBuilder.dll natively, 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_ray is 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 / ActivateRays came out at about 29 / 29 / 14 MB of DXIL on an RTX 3090 Ti, and ActivateRays was 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:

  1. Intercept the four XboxBvhBuilder.dll batched exports and build host DXR BLAS/TLAS from the inputs the title passes, side by side with the existing console structures.
  2. Replace recognised traversal regions in the title's compute shaders with DXR 1.1 inline 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):

  • The title sets DisableDXR = 1 and builds every structure through XboxBvhBuilder.dll.
  • BLAS and TLAS go through BuildRaytracingAccelerationStructureBatched2X. Each 0x50-byte BATCHED_DESC2 record 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).
  • BLAS geometry is 0x38-byte triangle geometry descs from the title's mesh records; instance descs are 64-byte D3D12_RAYTRACING_INSTANCE_DESC-sized records.
  • Updates are in place (PERFORM_UPDATE, source = destination).
  • Static BLASes ship serialized in core_bvh4.rpf and come back through RehydrateRaytracingAccelerationStructureBatched2X, which rebuilds them from the title's vertex data (L74-L108).
  • Decorated export names and signatures: BvhBuilderShim.cs.

Proposed stages

1. Build-only prototype (no shader changes)

  • Override four exports, keep the rest native. XboxBvhBuilder.dll has no HLE route today; it is mapped and its exports resolve to image_base + rva in resolve_export_of_mapped_inner. A per-DLL override there (Batched2X build, Rehydrate, Copy, PrebuildInfo) covers static imports, delay imports and GetProcAddress while the constructor, destructor and other exports stay native, and lets the shim forward to the original when it does not handle a record.
  • Record on the right host list. 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-in XCL_CONSOLE_LISTS path they would have to go into the ordered replay.
  • Translate the records. Resolve vertex, index, transform and instance VAs through the UMA helpers (real::uma_va_of, list_x::pc_va), keeping sparse residency and dirty-upload ordering. Query host prebuild sizes on ID3D12Device5, allocate host result and scratch separately (the title keeps its console-sized answers), record on ID3D12GraphicsCommandList4, and remap TLAS instance BLAS references to host addresses. Gate on the real host DXR tier, not on the tier reported to the title through raytracing / XCL_RAYTRACING (real.rs L2629).
  • Track ownership. Map title AS address + generation to the host AS; invalidate on rebuild, rehydrate, copy/compaction and allocation reuse.
  • Rehydrate. Rebuild host BLASes from the rehydrate inputs and archive data; which archive entries carry everything needed is still open.
  • Validate host structures against the console ones with the CPU reference traversal in 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

  • HLSL first. The HLSL path already targets cs_6_6, which covers inline RayQuery. The direct DXIL writer has the extension points but no rayQuery_* ops, AS resource kind or feature bits yet.
  • Recognition. A guest-level loop matcher in the style of KytyPS5 (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.
  • Per-dispatch gate. As in KytyPS5, pass a validity word with the TLAS index; it is set only when the TLAS, its BLAS dependencies and the hit metadata are current, otherwise the original walk runs (spirvEmitterRayQuery.cpp, gpu_bvh_mirror.comp).
  • Hit equivalence. The guest result is (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.
  • Instance fields the shadow shader reads (agreed between five-star and XCL's 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"). 0xD5 there is the ray's inclusion mask.
  • Split wave64 (HANDOFF.md L1669): a RayQuery is per lane, but if Proceed() 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

  • Compile time of the traversal shaders after the rewrite (the rest of each shader still compiles), and whether the largest RT/GI programs leave the critical path.
  • GPU time per trace dispatch, host path vs emulated path, same scene.
  • Visual difference in shadowed and indirect-lit areas.

Prior art elsewhere

  • OpenScarlett forwards console BuildRaytracingAccelerationStructure to 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's Batched2X signature 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.
  • KytyPS5 (PS5): traversal matcher, host mirror from guest triangle and instance records, per-dispatch validity (rayTracing.cpp). Its matcher is tied to PS5 SDK code shapes; the design transfers, the matcher does not.
  • five-star-recomp: reversed batch, rehydrate and instance layouts above, and a CPU builder for console-format structures (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

  • Whether the traversal regions in the title's RT programs share a few shapes (matcher worthwhile) or need per-program handling.
  • Whether rehydrate inputs are available at record time for every archive entry.
  • Host rebuild/refit cost per frame for the dynamic structures.
**@⁠AlexMJHGF421** on GitHub · 2026-11-24 20:14 UTC · [original](https://github.com/xcl-dev/xcl/issues/1751) ## Summary Today XCL runs the real `XboxBvhBuilder.dll` natively, replays its console command-list records as host compute, and gets console-format BLAS/TLAS ([README](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/README.md#L63), [HANDOFF.md L429-L434](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/HANDOFF.md#L429-L434)). The title's traversal shaders walk those nodes themselves, and `image_bvh*_intersect_ray` is emulated one node per instruction in both backends ([HLSL](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/gpu/recomp/emit.rs#L2084-L2119), [direct DXIL](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/gpu/dxil/lower_image.rs#L265-L325)). 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](https://git.gtahub.st/github/xcl-dev--xcl/issues/505) `ActivateProbes` / `ActivateProbesTarget` / `ActivateRays` came out at about 29 / 29 / 14 MB of DXIL on an RTX 3090 Ti, and `ActivateRays` was still in the NVIDIA driver compiler after 839 s; DXC refusals on 11–12 MB RT shadow-trace inputs are reported in [#1269](https://git.gtahub.st/github/xcl-dev--xcl/issues/1269). This issue proposes an opt-in second path: 1. Intercept the four `XboxBvhBuilder.dll` batched exports and build **host DXR** BLAS/TLAS from the inputs the title passes, side by side with the existing console structures. 2. Replace recognised traversal regions in the title's compute shaders with **DXR 1.1 inline `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`](https://github.com/ThatRecompDev/five-star-recomp/blob/2646905de4b4c80d8e297c77c27fa20aee161187/docs/raytracing.md#L12-L48), [`docs/d3d12x-shim.md`](https://github.com/ThatRecompDev/five-star-recomp/blob/2646905de4b4c80d8e297c77c27fa20aee161187/docs/d3d12x-shim.md#L43-L50)): - The title sets `DisableDXR = 1` and builds every structure through `XboxBvhBuilder.dll`. - BLAS **and** TLAS go through `BuildRaytracingAccelerationStructureBatched2X`. Each 0x50-byte `BATCHED_DESC2` record 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). - BLAS geometry is 0x38-byte triangle geometry descs from the title's mesh records; instance descs are 64-byte `D3D12_RAYTRACING_INSTANCE_DESC`-sized records. - Updates are in place (`PERFORM_UPDATE`, source = destination). - Static BLASes ship serialized in `core_bvh4.rpf` and come back through `RehydrateRaytracingAccelerationStructureBatched2X`, which rebuilds them from the title's vertex data ([L74-L108](https://github.com/ThatRecompDev/five-star-recomp/blob/2646905de4b4c80d8e297c77c27fa20aee161187/docs/raytracing.md#L74-L108)). - Decorated export names and signatures: [`BvhBuilderShim.cs`](https://github.com/ThatRecompDev/five-star-recomp/blob/2646905de4b4c80d8e297c77c27fa20aee161187/src/FiveStar.Loader/Shims/Bvh/BvhBuilderShim.cs#L34-L59). ## Proposed stages ### 1. Build-only prototype (no shader changes) - **Override four exports, keep the rest native.** `XboxBvhBuilder.dll` has no HLE route today; it is mapped and its exports resolve to `image_base + rva` in [`resolve_export_of_mapped_inner`](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/resolver.rs#L167). A per-DLL override there (Batched2X build, Rehydrate, Copy, PrebuildInfo) covers static imports, delay imports and `GetProcAddress` while the constructor, destructor and other exports stay native, and lets the shim forward to the original when it does not handle a record. - **Record on the right host list.** [`title_list::backing()`](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/hle/d3d12x/title_list.rs#L209) 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-in `XCL_CONSOLE_LISTS` path they would have to go into the ordered replay. - **Translate the records.** Resolve vertex, index, transform and instance VAs through the UMA helpers (`real::uma_va_of`, `list_x::pc_va`), keeping sparse residency and dirty-upload ordering. Query host prebuild sizes on `ID3D12Device5`, allocate host result and scratch separately (the title keeps its console-sized answers), record on `ID3D12GraphicsCommandList4`, and remap TLAS instance BLAS references to host addresses. Gate on the real host DXR tier, not on the tier reported to the title through `raytracing` / `XCL_RAYTRACING` ([real.rs L2629](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/hle/d3d12x/real.rs#L2629-L2643)). - **Track ownership.** Map title AS address + generation to the host AS; invalidate on rebuild, rehydrate, copy/compaction and allocation reuse. - **Rehydrate.** Rebuild host BLASes from the rehydrate inputs and archive data; which archive entries carry everything needed is still open. - **Validate** host structures against the console ones with the CPU reference traversal in [`gpu/bvh.rs`](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/gpu/bvh.rs#L384). ### 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](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/hle/d3d12x/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](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/crates/xcl/src/gpu/recomp/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 - **HLSL first.** The HLSL path already targets `cs_6_6`, which covers inline `RayQuery`. The direct DXIL writer has the extension points but no `rayQuery_*` ops, AS resource kind or feature bits yet. - **Recognition.** A guest-level loop matcher in the style of KytyPS5 ([`RayQueryTraversal.cpp`](https://github.com/KytyPS5/KytyPS5/blob/30781dcda029cbd669aa81337ac2902c9c3015d8/src/graphics/shader/recompiler/ir/passes/RayQueryTraversal.cpp#L1150-L1178)) 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. - **Per-dispatch gate.** As in KytyPS5, pass a validity word with the TLAS index; it is set only when the TLAS, its BLAS dependencies and the hit metadata are current, otherwise the original walk runs ([`spirvEmitterRayQuery.cpp`](https://github.com/KytyPS5/KytyPS5/blob/30781dcda029cbd669aa81337ac2902c9c3015d8/src/graphics/shader/recompiler/backend/spirv/spirvEmitterRayQuery.cpp#L38-L46), [`gpu_bvh_mirror.comp`](https://github.com/KytyPS5/KytyPS5/blob/30781dcda029cbd669aa81337ac2902c9c3015d8/src/graphics/host_gpu/shaders/gpu_bvh_mirror.comp#L408-L412)). - **Hit equivalence.** The guest result is `(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. - **Instance fields** the shadow shader reads (agreed between five-star and XCL's `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"](https://github.com/ThatRecompDev/five-star-recomp/blob/2646905de4b4c80d8e297c77c27fa20aee161187/docs/raytracing.md#L52-L72)). `0xD5` there is the ray's inclusion mask. - **Split wave64** ([HANDOFF.md L1669](https://github.com/xcl-dev/xcl/blob/b9b6ea62080cc62fc19e212033372d01c6214e5c/HANDOFF.md#L1669-L1678)): a `RayQuery` is per lane, but if `Proceed()` 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 - Compile time of the traversal shaders after the rewrite (the rest of each shader still compiles), and whether the largest RT/GI programs leave the critical path. - GPU time per trace dispatch, host path vs emulated path, same scene. - Visual difference in shadowed and indirect-lit areas. ## Prior art elsewhere - **OpenScarlett** forwards console `BuildRaytracingAccelerationStructure` to host list4 and selects RayQuery or a compute BVH4 fallback per host and shader ([`command_list_x.cpp`](https://github.com/californiaAlmonds/OpenScarlett/blob/46d8e2c2f47ce48f84e54d11eeaf7effdbd8ad57/src/gpu/d3d12_xs/command_list_x.cpp#L4018-L4030), [`device_x.cpp`](https://github.com/californiaAlmonds/OpenScarlett/blob/46d8e2c2f47ce48f84e54d11eeaf7effdbd8ad57/src/gpu/d3d12_xs/device_x.cpp#L3155-L3210), [`dxr_hardware.cpp`](https://github.com/californiaAlmonds/OpenScarlett/blob/46d8e2c2f47ce48f84e54d11eeaf7effdbd8ad57/src/gpu/dxr_hardware.cpp#L748)). Its export with this title's `Batched2X` signature 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. - **KytyPS5** (PS5): traversal matcher, host mirror from guest triangle and instance records, per-dispatch validity ([`rayTracing.cpp`](https://github.com/KytyPS5/KytyPS5/blob/30781dcda029cbd669aa81337ac2902c9c3015d8/src/graphics/host_gpu/renderer/rayTracing.cpp#L394-L431)). Its matcher is tied to PS5 SDK code shapes; the design transfers, the matcher does not. - **five-star-recomp**: reversed batch, rehydrate and instance layouts above, and a CPU builder for console-format structures (`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 - Whether the traversal regions in the title's RT programs share a few shapes (matcher worthwhile) or need per-program handling. - Whether rehydrate inputs are available at record time for every archive entry. - Host rebuild/refit cost per frame for the dynamic structures.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:46 +00:00
Author
Owner

@⁠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 own bvh_intersect) and once as a DXR BLAS + TLAS traced with RayQuery. 1 048 576 rays per run, best of 5 by GPU timestamps, two runs each. RTX 5070, driver 621.40:

scene rays emulated walk RayQuery ratio
131 072 triangles coherent (camera) 0.81 ms 0.094–0.106 ms 7.6–8.7×
131 072 triangles incoherent (random) 2.73 ms 0.150 ms 18.3–18.4×
524 288 triangles coherent 1.02 ms 0.100–0.112 ms 9.1–10.2×
524 288 triangles incoherent 3.15 ms 0.19–0.24 ms 13.1–16.4×
  • Both walks find the same closest t on all but 0–18 of the 1 048 576 rays (edges shared by two triangles).
  • The host BLAS is 41–42 % of the console BVH's size (7.9 vs 19.1 MB at 131 072 triangles), and BLAS + TLAS build in 0.5–1.5 ms.
  • The emulated side is an idealised HLSL walk. A title's translated traversal also runs its guest loop, stack and EXEC bookkeeping (and the split wave64 form on 32-lane GPUs), so this is the node test against the hardware, not a title's numbers.
  • No instances, transforms or non-opaque geometry yet, and no AMD / Intel run: their ray accelerators may give a very different ratio.

AI use: Claude Code (Claude Opus 5.5) wrote the test, ran it and drafted this comment.

**@⁠marquezinii** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/xcl-dev/xcl/issues/1751#issuecomment-7144442394) 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 own `bvh_intersect`) and once as a DXR BLAS + TLAS traced with `RayQuery`. 1 048 576 rays per run, best of 5 by GPU timestamps, two runs each. RTX 5070, driver 621.40: | scene | rays | emulated walk | `RayQuery` | ratio | |---|---|---|---|---| | 131 072 triangles | coherent (camera) | 0.81 ms | 0.094–0.106 ms | 7.6–8.7× | | 131 072 triangles | incoherent (random) | 2.73 ms | 0.150 ms | 18.3–18.4× | | 524 288 triangles | coherent | 1.02 ms | 0.100–0.112 ms | 9.1–10.2× | | 524 288 triangles | incoherent | 3.15 ms | 0.19–0.24 ms | 13.1–16.4× | - Both walks find the same closest t on all but 0–18 of the 1 048 576 rays (edges shared by two triangles). - The host BLAS is 41–42 % of the console BVH's size (7.9 vs 19.1 MB at 131 072 triangles), and BLAS + TLAS build in 0.5–1.5 ms. - The emulated side is an idealised HLSL walk. A title's translated traversal also runs its guest loop, stack and EXEC bookkeeping (and the split wave64 form on 32-lane GPUs), so this is the node test against the hardware, not a title's numbers. - No instances, transforms or non-opaque geometry yet, and no AMD / Intel run: their ray accelerators may give a very different ratio. **AI use:** Claude Code (Claude Opus 5.5) wrote the test, ran it and drafted this comment.
Author
Owner

@⁠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_ray 638 sites in 40 programs, image_bvh64_intersect_ray 78 sites in 24. No program uses both.

Shapes. Every site has a v_min3/v_med3/v_max3_u32 child sort within 40 instructions after it, an LDS push within 80, and an enclosing backward-branch loop. There are four variants:

op sites programs push ring mask
image_bvh_intersect_ray 319 40 ds_write_b32 0x3fc (256 dwords)
image_bvh_intersect_ray 319 40 ds_write2_b32 none within 80 instructions
image_bvh64_intersect_ray 56 15 ds_write_b32 0x7fc (512 dwords)
image_bvh64_intersect_ray 22 9 ds_write_b32 0xffc (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_tracing programs, also carry an s_cmpk_lt_u32 sN, 0xffff iteration 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_Tiled and CS_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:

family programs instructions in loop
rtdirectionalshadows:CS_RTShadowTrace32* 20 438,557 43.0%
shadowmask:CS_TraceShadowRays* 7 54,038 49.8%
sr_tracing:CS_RaytraceVBuffer* 6 48,077 53.8%
indirect_diffuse_lighting:CS_ScreenProbes_TraceRays* 8 28,047 53.6%
rtdirectionalshadows:CS_RTDistant* 5 21,059 52.3%
indirect_light_probes gathers and shadow traces 8 30,255 48.9%
10 smaller programs in 4 shader files 10 16,628 42.5%

Correction on the compile bombs. The three biggest programs, indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes, ActivateProbesTarget and ActivateRays (88,862, 88,444 and 74,570 instructions; the three measured in #505), contain no intersect op, so inline RayQuery would not shrink them. The same holds for the 42 *:CS_RaytracingResolve variants and the two cascadeshadows_rendering:CS_ShadowRenderTiledCascades*. Of the 57 programs over 20,000 instructions (list), 9 have intersect sites, all of them rtdirectionalshadows:CS_RTShadowTrace32*. Among the big programs, inline RayQuery would shrink only those; the screen-probe activate passes need a different fix.

Reproduce with forge9:

forge9 isa shaders.rpf 0 --rt-census          # totals, shapes, per-program table, 10 heaviest
forge9 isa shaders.rpf 0 --rt-census --json

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.

**@⁠nineforge0** on GitHub · 2026-11-24 23:06 UTC · [original](https://github.com/xcl-dev/xcl/issues/1751#issuecomment-7147015716) 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_ray` 638 sites in 40 programs, `image_bvh64_intersect_ray` 78 sites in 24. No program uses both. **Shapes.** Every site has a `v_min3/v_med3/v_max3_u32` child sort within 40 instructions after it, an LDS push within 80, and an enclosing backward-branch loop. There are four variants: | op | sites | programs | push | ring mask | |---|---:|---:|---|---| | `image_bvh_intersect_ray` | 319 | 40 | `ds_write_b32` | `0x3fc` (256 dwords) | | `image_bvh_intersect_ray` | 319 | 40 | `ds_write2_b32` | none within 80 instructions | | `image_bvh64_intersect_ray` | 56 | 15 | `ds_write_b32` | `0x7fc` (512 dwords) | | `image_bvh64_intersect_ray` | 22 | 9 | `ds_write_b32` | `0xffc` (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_tracing` programs, also carry an `s_cmpk_lt_u32 sN, 0xffff` iteration 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_Tiled` and `CS_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: | family | programs | instructions | in loop | |---|---:|---:|---:| | `rtdirectionalshadows:CS_RTShadowTrace32*` | 20 | 438,557 | 43.0% | | `shadowmask:CS_TraceShadowRays*` | 7 | 54,038 | 49.8% | | `sr_tracing:CS_RaytraceVBuffer*` | 6 | 48,077 | 53.8% | | `indirect_diffuse_lighting:CS_ScreenProbes_TraceRays*` | 8 | 28,047 | 53.6% | | `rtdirectionalshadows:CS_RTDistant*` | 5 | 21,059 | 52.3% | | `indirect_light_probes` gathers and shadow traces | 8 | 30,255 | 48.9% | | 10 smaller programs in 4 shader files | 10 | 16,628 | 42.5% | **Correction on the compile bombs.** The three biggest programs, `indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes`, `ActivateProbesTarget` and `ActivateRays` (88,862, 88,444 and 74,570 instructions; the three measured in #505), contain no intersect op, so inline `RayQuery` would not shrink them. The same holds for the 42 `*:CS_RaytracingResolve` variants and the two `cascadeshadows_rendering:CS_ShadowRenderTiledCascades*`. Of the 57 programs over 20,000 instructions ([list](https://github.com/nineforge0/forge9/blob/main/docs/exec_uniformity.md)), 9 have intersect sites, all of them `rtdirectionalshadows:CS_RTShadowTrace32*`. Among the big programs, inline `RayQuery` would shrink only those; the screen-probe activate passes need a different fix. **Reproduce** with [forge9](https://github.com/nineforge0/forge9): ``` forge9 isa shaders.rpf 0 --rt-census # totals, shapes, per-program table, 10 heaviest forge9 isa shaders.rpf 0 --rt-census --json ``` Method, limits and the full tables are in [docs/rt_traversal_census.md](https://github.com/nineforge0/forge9/blob/main/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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.