Skip to content

D3D12.X: opt-in XCL_HW_RT shadow builder - #3700

Open
Kalmarv wants to merge 3 commits into
xcl-dev:mainfrom
Kalmarv:pr/hw-rt-shadow
Open

Kalmarv wants to merge 3 commits into
xcl-dev:mainfrom
Kalmarv:pr/hw-rt-shadow

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Add the opt-in XCL_HW_RT=1 native DXR 1.1 shadow builder that mirrors XboxBvhBuilder bottom-level builds, top-level builds, rehydrates, and copies into host DXR acceleration structures recorded on the title's own command list after the console build. Off by default: no extra hooks are installed for it when XCL_HW_RT is unset (on the 16-window layout #3662's hooks still run and check hw_rt::enabled() per call; XCL_RAYTRACING=0 also disables it).

Part of #1751. Stacked on #3697 (and #3662 on main 5eaadb54c; commit 3620d7652 is the new diff here). Note: title_list::active_backing (and its unit test) was moved here from #3653 because this PR is its only caller, so #3653 can drop it.

Related: #2184, #2185. Unlike those earlier PRs, this stacks on #3662's GPU-view hooks and #3697's pure registry/geometry translator, mirrors XboxBvhBuilder BuildRaytracingAccelerationStructureBatched2X, RehydrateRaytracingAccelerationStructureBatched2X, and CopyRaytracingAccelerationStructureX with explicit UAV barriers between BLAS/TLAS/copy phases, resolves console R16_TYPELESS/R32_TYPELESS index formats, retires native AS buffers via late_release GPU fences, and includes WARP DXR 1.1 tests covering builds, rehydration, and copies.

Why this PR is over 800 changed lines: The diff is +1612 / -14 lines across 5 files, consisting of ~1195 production lines (hw_rt.rs host DXR state, scratch/staging pools, Batched2X BLAS/TLAS/rehydrate/copy recording, bvh_builder.rs hook wiring, late_release.rs fence-backed retirement, title_list.rs active backing helper, host.rs periodic summary logging) and ~417 lines of WARP DXR 1.1 and command-list tests. The pure registry and geometry translation were already split out into #3697; splitting the remaining host state from its hook callers or its WARP tests would either introduce unused code or land unverified host DXR command recording.

What is in it

  • crates/xcl/src/hle/d3d12x/hw_rt.rs: HostDxr (DXR 1.1 device/tier probe), ShadowState (registry, pooled scratch/staging buffers reused after 4 presents under a configurable VRAM budget, retired list draining through late_release), on_build_batched2x (two-phase BLAS then TLAS recording with UAV barrier), on_rehydrate_batched2x (native rebuild when geometry count matches, fallback tracking otherwise), on_copy_as (native CopyRaytracingAccelerationStructure for clone/compact with surrounding UAV barriers), periodic HW RT shadow (XCL_HW_RT): summary formatting, and 3 WARP DXR 1.1 integration tests.
  • crates/xcl/src/hle/bvh_builder.rs: hook Build*Batched2X, Rehydrate*Batched2X, and Copy*X to forward to hw_rt when XCL_HW_RT=1.
  • crates/xcl/src/hle/d3d12x/late_release.rs: hold_owned_resource helper so replaced native AS buffers wait until every active queue is past a fence before release.
  • crates/xcl/src/hle/d3d12x/title_list.rs: active_backing helper (moved from Memory: cover overflow MEM_GRAPHICS reservations in trailing view windows #3653, its only caller) returning the active PC command list backing a wrapped console list across split segments, plus unit test active_backing_tracks_primary_and_split_segment.
  • crates/xcl/src/host.rs: log hw_rt::summary_line() every 10 s when active.

Tested
Hardware: Windows 11 x64, NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, DXR Tier 1.1), AMD Ryzen 9 9950X, rustc 1.99.0, DXC 1.9.2609.5 (XCL_DXC_DIR).

  • cargo build --release -p xcl (commit 3620d76522ae28985d4f0d982b3afd16732adbda): succeeded, 39 warnings (0 new vs main).
  • .\scripts\test.ps1 (commit 3620d76522ae28985d4f0d982b3afd16732adbda): 2995 passed, 0 failed, 52 ignored across 43 test binaries; 24 GPU tests skipped on this adapter (22 no wave64, 2 no heap windows). All 9 hle::d3d12x::hw_rt tests (including all 3 WARP DXR 1.1 tests) and active_backing_tracks_primary_and_split_segment passed.
  • On the default 4-window layout almost every bottom level is skipped (vertex buffer VA outside UMA: the geometry lives at GPU-view addresses that only the 16-window layout maps), so native bottom levels are built primarily with XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16.
  • Live 180 s XCL_HW_RT=1 run on 3620d76522ae28985d4f0d982b3afd16732adbda (default memory layout, XCL_PREPARE=0, XCL_NETWORK=0, XCL_PSO_EVICT_FRAMES=600, automated title-screen advance): exit: 0x0, 2149 frames shown, 0 device removals, 0 crashes:
    • HW RT shadow (XCL_HW_RT): live 2 BLAS / 5 TLAS / 90 rehydrated (1 MiB AS, 6 MiB pools); built 2 BLAS (0 updates, 2324 skipped), 75 TLAS (35 complete, 40 hybrid, 0 skipped); insts 34307 resolved / 0 null / 1487 rehydrated-skip / 29212 missing-skip; 1137 rehydrated recorded (0 built natively, 95 count mismatch), 0 stale invalidated, 0 copy-invalidated, 0 copied natively, 0 alloc-err, 0 budget-skip
  • Live 180 s XCL_HW_RT=1 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 run on 3620d76522ae28985d4f0d982b3afd16732adbda (same settings, with GPU view windows active): exit: 0x0, 2016 frames shown, 0 device removals, 0 crashes:
    • HW RT shadow (XCL_HW_RT): live 2654 BLAS / 5 TLAS / 140 rehydrated (238 MiB AS, 118 MiB pools); built 1199 BLAS (0 updates, 1371 skipped), 154 TLAS (82 complete, 72 hybrid, 0 skipped); insts 104399 resolved / 0 null / 2188 rehydrated-skip / 31495 missing-skip; 1960 rehydrated recorded (1809 built natively, 151 count mismatch), 158 stale invalidated, 0 copy-invalidated, 0 copied natively, 0 alloc-err, 0 budget-skip
    • (See Known limitations Olympus: validate launcher and texture inputs #6 below for the 1 of 2 16-window XCL_HW_RT=1 runs that hit 0x887a0006.)

Regression run

Base (main):

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1658 (PresentX 1658)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16763 MB

PR (pr/hw-rt-shadow):

xcl-smoke v1
commit: 3620d76522ae28985d4f0d982b3afd16732adbda
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1693 (PresentX 1693)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16771 MB

Not tested

  • AMD/Intel GPUs and native wave64 GPU tests (22 skipped on RTX 5070 Ti).
  • Sample-gated tests (XCL_SAMPLE_* unset).
  • Native traversal in shaders (XCL_HW_RT_TRAVERSE=1; handled in the follow-up stacked PRs).
  • Known limitations:
    1. Scratch and staging pools are reused after 4 presents without an explicit GPU fence (assumes at most 3 frames in flight; replaced AS buffers wait via late_release until every active queue is past a fence).
    2. TLAS instance descriptions are read on the CPU at command-record time (same-frame GPU writes to the instance buffer are read stale; unknown BLAS VAs are masked to AccelerationStructure = 0, InstanceMask = 0 so there is no GPU fault, though those instances are skipped until the BLAS is known).
    3. Natively built rehydrated BLASes use geometry primitive indices rather than the archive's original primitive indices.
    4. In-place BLAS rebuilds keep referencing TLASes marked complete (the title is expected to rebuild or update the TLAS, matching console behaviour).
    5. The copy hook does not request the copy destination range in GPU view windows (same gap as D3D12.X: hook XboxBvhBuilder builds and ask for every range whole in GPU views #3662).
    6. On the 16-window layout, 1 of 3 XCL_HW_RT=1 runs (including DXIL: swap GPURT traversal loops for native RayQuery (XCL_HW_RT_TRAVERSE) #3705's 180 s XCL_HW_RT_TRAVERSE=1 run) ended in 0x887a0006 (DEVICE_HUNG) at 154.2 s / frame 1969 with +3.9 GiB VRAM overcommit (last recorded: DispatchMesh in two passes); one 180 s XCL_HW_RT=0 control finished (1920 frames, 0 removals). Cause not determined; the native structures add about 360 MiB of VRAM (238 MiB AS + 118 MiB pools at 180 s).

AI use

  • Claude Code (Claude Opus 5.5): architecture, hang/TDR audit, barrier and lifetime review, and final diff/description review.
  • Antigravity (Gemini 4 Neon): split, rebase onto main, builds, test suite, smoke runs, live XCL_HW_RT=1 verification, and PR description.

Kalmarv and others added 3 commits December 2, 2026 09:23
…GPU views

Add outer XboxBvhBuilder.dll HLE hooks (BuildRaytracingAccelerationStructureBatched2X and RehydrateRaytracingAccelerationStructureBatched2X, extern "system-unwind") that ask view_want (Path::BvhBuild) for every range a build or rehydrate names whole before forwarding to the DLL.

The builder's compute programs reach vertex and index buffers through addresses inside uploaded geometry descriptions and reach destination, source, and scratch through root views, which view_want only asks for 64 KiB from their base address. On the 16-window GPU-view layout, tiles past that first 64 KiB stay unmapped until requested. Asking for each item's result, source, scratch, instance descriptions, per-geometry vertices/indices/transforms/AABBs (handling R16_TYPELESS=53 as 2 bytes), and postbuild destinations sized via GetRaytracingAccelerationStructurePrebuildInfo closes that gap:

- Resolve GetRaytracingAccelerationStructurePrebuildInfo directly from the mapped XboxBvhBuilder.dll module when wrapping any export (including ordinal imports) instead of waiting for the title to import it.
- Cache UpdateScratchDataSizeInBytes on ALLOW_UPDATE builds so a later PERFORM_UPDATE whose prebuild query returns 0 reuses the cached size (or falls back to scratch_size.max(update_scratch_size).max(SCRATCH_GUESS)) instead of dropping the scratch range.
- For ARRAY_OF_POINTERS TLAS builds, translate the GPU-VA pointer table via list_x::cpu_at, read it under shader::readable, and request coalesced 64-byte D3D12_RAYTRACING_INSTANCE_DESC target ranges alongside the pointer array.

Wrapping is gated on Uma view windows existing, so default 4-window runs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Antigravity (Gemini 4 Neon)
Add the pure acceleration-structure shadow registry and DXR 1.1 triangle geometry and TLAS instance translation helpers in hle::d3d12x::hw_rt. Nothing calls this module yet; the shadow command-list builder and XboxBvhBuilder hooks follow in a stacked PR.

Tracks native BLAS/TLAS entries keyed by console GPU VA, validates DXR 1.1 PERFORM_UPDATE refits against build flags and per-geometry signatures, marks referencing TLASes stale whenever a BLAS GPU VA relocates or is invalidated, canonicalizes console typeless index formats (R16_TYPELESS / R32_TYPELESS) to PC typed uint formats, and gates opt-in XCL_HW_RT=1 against XCL_RAYTRACING=0.

Part of xcl-dev#1751.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Antigravity (Gemini 4 Neon)
Wire the opt-in native D3D12 DXR 1.1 BLAS/TLAS shadow builder (XCL_HW_RT=1, off by default) into XboxBvhBuilder.dll's BuildBatched2X, RehydrateBatched2X, and CopyRaytracingAccelerationStructure hooks.

Builds native DXR 1.1 bottom-level and top-level acceleration structures alongside the console compute path (leaving console output untouched for software fallback):
- Translates triangle BLAS geometry (including R16_TYPELESS/R32_TYPELESS canonicalization) and rewrites TLAS instance descriptors to native BLAS GPU VAs (masking unresolved instances cleanly).
- Builds rehydrated BLASes natively when their geometry has at least as many triangles as the archive header's primitive count, and clones native structures on clone/compact copies.
- Invalidates stale entries on every skipped rebuild or fallback, marks referencing TLASes stale when a BLAS GPU VA relocates or is removed, and retires replaced AS buffers past RETIRE_FRAMES presents into late_release::hold_owned_resource so active GPU queues finish before drop.
- Respects XCL_RAYTRACING=0 dynamically on every hook and logs a periodic summary line in host.rs when active.

Part of xcl-dev#1751.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Assisted-by: Antigravity (Gemini 4 Neon)
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 2, 2026
@Jockerino

Copy link
Copy Markdown

merge-check claim
head: 3620d76522ae28985d4f0d982b3afd16732adbda

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@Jockerino

Copy link
Copy Markdown

merge-check
base: 5eaadb5
head: 3620d76
merge: clean
build: cargo build --workspace -> ok (cargo build --release -p xcl: 39 lib warnings on the base and on the merge, none new)
tests: cargo test at 1 thread instead of --test-threads=4, as one cargo process a group (the library's 2879 tests in 11 groups by module, then --bins, each of the 38 integration tests, the two test packages and the doc tests; this PC has gone down under the parallel run before) -> 2995 passed, 0 failed, 52 ignored, each test counted once; SKIPPED: 26 (22 no wave64, 2 no heap windows, 2 cannot disable the driver cache: Windows Developer Mode is off here); failing: none. All 9 hle::d3d12x::hw_rt tests ran, the 3 WARP DXR 1.1 ones without a SKIPPED notice, and the 11 hle::bvh_builder tests. cargo bench -p xcl --bench '*' -- --test: ok.
review: whole diff read, all three commits (+3707/-1, 9 files; a65c38b is #3662's and b1bd0a4 is #3697's, both still open; 3620d76 is this PR's own). (1) Not verified here: XCL_HW_RT=1 inside the world. On this machine main itself loses the device when a save in the first interior is continued (scripts/smoke.ps1 settings plus XCL_PRESS_AT): 0x887a0006 at the first world submits - base 5eaadb5 at 138 s; the merge with XCL_HW_RT unset at 142 s; the merge with XCL_HW_RT=1 at 329 s (that run was still compiling shaders before); video memory was 2.0 to 2.4 GB over budget in these three. With XCL_DEVICE_TYPE=lockhart the merge (XCL_HW_RT unset) lost the device at 137 s as well, 0.9 GB under budget, so the budget alone does not explain it. So the removal is not this PR's, and no native structure was exercised through world frames. Up to the removal the XCL_HW_RT=1 run logged "XboxBvhBuilder: builds, rehydrates and copies wrapped (GPU views: no view windows, XCL_HW_RT on)", "native DXR 1.1 shadow builder active (host RaytracingTier=12, budget=1024 MiB)" and one summary line: live 2 BLAS / 5 TLAS / 11 rehydrated (1 MiB AS, 1 MiB pools); built 2 BLAS (0 updates, 683 skipped), 5 TLAS (3 complete, 2 hybrid, 0 skipped); 160 rehydrated recorded (0 built natively, 11 count mismatch); 0 alloc-err, 0 budget-skip - in line with the description's default-layout numbers. The 16-window layout was not run here. (2) hw_rt.rs: the scratch and staging pools only grow. acquire_scratch (~918) and acquire_staging (~964) push a new buffer and add to pool_bytes (~954, ~1005); nothing removes one. pool_bytes counts against XCL_HW_RT_BUDGET_MB together with the live structures (total_bytes ~884), so after a peak - one batch sizes a single scratch buffer for all its bottom levels - that video memory stays for the life of the process, and once pools plus structures reach the budget every later allocation fails with "budget exceeded" (~941, ~987: the build is skipped and its entry invalidated) although idle pool buffers could be freed first. Opt-in path only. (3) Minor: bvh_builder.rs resolve_scratch_bytes (~440) treats a PERFORM_UPDATE with Source = 0 as an update in place (it falls back to the destination), but execute_shadow_batch passes d.build.source to Registry::can_update (~1177, ~1321), which returns None for 0 (~352): such an update is rebuilt natively, not refitted. Correct output, more GPU work, and only if a title passes 0. (4) Minor: Copy_hook (bvh_builder.rs ~683) has no forwarding test; the build and rehydrate hooks have one each, the copy only the wrap_with mapping (~776). (5) Fine: the gate (hw_rt::enabled() = XCL_HW_RT and not XCL_RAYTRACING=0) is checked in wrap, in every hook and in summary_line; with it unset and no view windows nothing is wrapped (no "XboxBvhBuilder:" line in the merge's default-layout smoke log); UAV barriers follow the bottom-level phase, the top-level phase and surround native copies; unresolved instances are masked (AccelerationStructure 0, mask 0); replaced buffers wait 4 presents and then go through late_release's fences; read_archive_prims goes through list_x::cpu_at, which leaves a CPU address as it is.
performance: off by default. With XCL_HW_RT unset the added work is one enabled() check per hook call (16-window layout only) and one summary_line() call every 10 s that returns None. Measured, 60 s smoke pair on the default layout (blocks below): 1582 -> 1574 frames shown (99.5 %), presents per 2 s 60 60 60 in both, peak commit 17482 -> 18457 MB (105.6 %), 0 device removals, 0 crashes. A repeat of the base right after the pair gave 1329 frames and 26189 MB, so on this machine two runs of main differ more than main and the merge do. With XCL_HW_RT=1: not measured in the world (review 1); by reading, up to XCL_HW_RT_BUDGET_MB (1024 MiB by default) of video memory for native structures and pools; in the default profile this card is already about 2 GB over budget at world load here.
verdict: safe to merge (after #3662 and #3697, which it carries): the default path is unchanged and measured clean, build and suite pass, and the review found nothing blocking; the opt-in XCL_HW_RT=1 path starts and builds structures here but could not be followed into the world because main itself does not survive that world load on this machine.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti (driver 621.40), AMD Ryzen 7 7800X3D, Windows 11 Pro 26300, rustc 1.101.0-nightly (clang-cl with an xwin sysroot, not the stable MSVC toolchain), DXC 1.9.2609 / Claude Code with Claude Fable 5.2 (ran the build, the tests and the runs and drafted this report)

Regression run, scripts/smoke.ps1 unchanged, one isolated data root for both, after a warm-up run of the base:

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1582)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17482 MB
xcl-smoke v1
commit: 3620d76522ae28985d4f0d982b3afd16732adbda
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1574 (PresentX 1574)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18457 MB

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants