Skip to content

D3D12.X: hw_rt registry and DXR geometry translation - #3697

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

Kalmarv wants to merge 2 commits into
xcl-dev:mainfrom
Kalmarv:pr/hw-rt-registry

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Add the pure acceleration-structure shadow registry and DXR 1.1 triangle geometry / TLAS instance translation helpers in hle::d3d12x::hw_rt. Nothing calls this module yet, so default runtime behavior is unchanged; Caller: #3700 (the opt-in XCL_HW_RT=1 shadow command-list builder and XboxBvhBuilder hooks). Part of #1751.

Stacked on #3662 (includes its commit a65c38b16 on main 5eaadb54c; the new diff on top of #3662 is commit b1bd0a442).

Related: #2184/#2185 implement an earlier shadow-builder design; this PR isolates the pure registry and translation layer with DXR 1.1 PERFORM_UPDATE geometry-signature validation, referencing-TLAS staleness tracking when a BLAS GPU VA relocates or is invalidated, console typeless index format canonicalization (R16_TYPELESS/R32_TYPELESS -> R16_UINT/R32_UINT), and dynamic XCL_RAYTRACING=0 gating.

(Why this is 970 lines and not split further: ~640 lines are the pure registry and DXR 1.1 geometry/instance translation helpers, and ~330 lines are their unit tests, kept together because CONTRIBUTING.md requires new code to ship with its tests. The D3D12 command-list shadow builder, buffer pools, retirement plumbing, and XboxBvhBuilder hooks are split into the stacked follow-up PR.)

What is in it

  • crates/xcl/src/hle/d3d12x/hw_rt.rs & crates/xcl/src/hle/d3d12x/mod.rs:
    • Registry keyed by console AS GPU VA (NativeAs, NativeAsSnapshot, RewriteReport, CopySource, HwRtStats), tracking live BLAS/TLAS entries and rehydrated-only VAs.
    • mark_referencing_tlases_stale: tracks sorted, deduplicated native BLAS GPU VAs baked into each TLAS so relocating, rehydrating, or invalidating a BLAS immediately removes referencing TLASes from complete_tlases().
    • GeomSig and Registry::can_update: verifies ALLOW_UPDATE, matching sanitized non-update build flags, matching desc count, and matching per-geometry flags, vertex/index formats & counts, and transform presence before permitting a PERFORM_UPDATE refit.
    • translate_triangle_geometry / translate_blas_geometries, canonical_dxr_index_format, sanitize_build_flags, and Registry::rewrite_instance_descs_with_refs (masking unresolved/rehydrated instances cleanly with AccelerationStructure = 0, InstanceMask = 0).
    • parse_enabled / enabled_with / enabled combining opt-in XCL_HW_RT=1 with config().raytracing_tier_override() != Some(0).
    • 6 pure unit tests covering env/override gating, geometry translation and typeless index canonicalization, can_update rejection cases, BLAS relocation/invalidation staleness, hybrid TLAS rewriting, and flag sanitization.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 5070 Ti (driver 610.74), AMD Ryzen 9 9950X, Windows 11 x64, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.5 (01b62ad47).
  • cargo build --release -p xcl (commit b1bd0a4426bd3906ef38eb1ec4718ef11b1965d4): succeeded, 39 warnings (0 new vs main).
  • .\scripts\test.ps1 (debug build + benches + workspace tests --test-threads=4, commit b1bd0a4426bd3906ef38eb1ec4718ef11b1965d4): 2991 passed, 0 failed, 52 ignored across 43 test binaries (including all 6 hle::d3d12x::hw_rt tests).
  • SKIPPED GPU tests (24): 22 no wave64 (RTX 5070 Ti is wave32-only), 2 no heap windows (XCL_HEAP_WINDOWS opt-in off by default).

Regression run

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
xcl-smoke v1
commit: b1bd0a4426bd3906ef38eb1ec4718ef11b1965d4
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1681 (PresentX 1681)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16868 MB

Not tested

  • Live D3D12 command-list execution of hw_rt (nothing calls this module yet; the shadow builder, WARP DXR 1.1 tests, and live XCL_HW_RT=1 title run are in the stacked follow-up PR).
  • AMD / Intel GPUs and wave64-only GPU tests.

AI use

  • Claude Code (Claude Opus 5.5): audited the registry invariants (referencing-TLAS staleness, GeomSig refit rules, dead-code trims, and PR split) and reviewed the final diff and PR description.
  • Antigravity (Gemini 4 Neon): split and implemented the registry and translation module with its unit tests, ran the build, test suite, and regression smoke, and drafted the PR description.

Kalmarv and others added 2 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)
@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
@saintwolf

Copy link
Copy Markdown
Contributor

merge-check claim
head: b1bd0a4

@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
@saintwolf

Copy link
Copy Markdown
Contributor

merge-check
base: 5eaadb5
head: b1bd0a4
merge: clean (fast-forward of #3662's a65c38b plus this PR's b1bd0a4 onto main; git diff --check clean; +2109/-1 in 6 files - new hle/bvh_builder.rs and hle/d3d12x/hw_rt.rs, Path::BvhBuild in view_want.rs, resolver.rs import wiring, two module declarations)
build: cargo build --workspace -> ok (39 lib warnings, same count as main; none from the new code)
tests: cargo test --workspace -- --test-threads=4 -> 2991 passed, 0 failed, 52 ignored across 43 binaries (main 5eaadb5 is 2974 + the 17 new tests - 11 bvh_builder, 6 hw_rt - all confirmed run and passing here by name). SKIPPED: 27, the standard set for this card (22 no wave64, 2 no heap windows, 1 driver cache, 2 no xgameruntime.dll). XCL_SAMPLE_DLLS is not set here, so the pre-existing console_dlls_e2e XboxBvhBuilder tests early-return on main and head alike.
review: no blocking finding; every hunk of both commits read. Verified against the installed DXR 1.1 SDK (10.0.26100): the console build flags the ABI uses (ALLOW_UPDATE 0x1, PERFORM_UPDATE 0x20) are exactly the PC values in that SDK (0x2 is ALLOW_COMPACTION there), so the 0x3F mask in sanitize_build_flags / can_update is an exact console-to-PC translation and implements the DXR 1.1 refit rules (originally ALLOW_UPDATE, matching sanitized non-update flags, same desc count, matching per-geometry flags / vertex+index formats and counts / transform presence); InstanceMask is bits 24-31 of the first UINT of D3D12_RAYTRACING_INSTANCE_DESC, so the masking and its test are exact; all ten hardcoded DXGI format numbers match dxgiformat.h. The ABI structs are size/offset-pinned by tests; the PrebuildInfo mangled symbol is byte-identical to the one the existing e2e tests call on the real DLL, and the two Batched2X manglings are parameter-exact against the hook signatures. Gating: the exports are wrapped only while the UMA has view windows (the 16-window layout), so the default layout is unchanged by construction (one string compare per XboxBvhBuilder import); Path::BvhBuild is appended with stable discriminants and carries real prebuild sizes rather than the sizeless reach. Registry invariants sound: an in-place rebuild at the same native VA keeps referencing TLASes complete (instance descs point at the buffer VA), while relocating, invalidating or rehydrating a BLAS marks them stale at once, and live_as_bytes balances on every insert/remove path. Non-blocking: (1) upsert_native rebuilding the same console VA as a different AS kind with resource = None returns the old handle (the same buffer) for deferred retirement while the new entry keeps None - a caller-contract edge in a module nothing calls yet; the follow-up shadow-builder PR drives it; (2) the UPDATE_SCRATCH cache grows per distinct dest VA (bounded by the title's AS destinations, removed on a non-ALLOW_UPDATE rebuild at that VA); (3) +2109 lines over the two stacked commits (this PR's own commit is 970: ~640 code + ~330 tests kept together per CONTRIBUTING) is over the ~400 soft target.
performance: nothing by default (no view windows: one string compare per XboxBvhBuilder import, no hooks installed). In the 16-window layout: per batched build/rehydrate call one call of the DLL's own prebuild query, a readable() walk of the descs, and one is_view compare per asked range (tile mapping only for ranges in view windows). hw_rt is called by nothing in this PR, so it costs zero at runtime here.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B

1 similar comment
@saintwolf

Copy link
Copy Markdown
Contributor

merge-check
base: 5eaadb5
head: b1bd0a4
merge: clean (fast-forward of #3662's a65c38b plus this PR's b1bd0a4 onto main; git diff --check clean; +2109/-1 in 6 files - new hle/bvh_builder.rs and hle/d3d12x/hw_rt.rs, Path::BvhBuild in view_want.rs, resolver.rs import wiring, two module declarations)
build: cargo build --workspace -> ok (39 lib warnings, same count as main; none from the new code)
tests: cargo test --workspace -- --test-threads=4 -> 2991 passed, 0 failed, 52 ignored across 43 binaries (main 5eaadb5 is 2974 + the 17 new tests - 11 bvh_builder, 6 hw_rt - all confirmed run and passing here by name). SKIPPED: 27, the standard set for this card (22 no wave64, 2 no heap windows, 1 driver cache, 2 no xgameruntime.dll). XCL_SAMPLE_DLLS is not set here, so the pre-existing console_dlls_e2e XboxBvhBuilder tests early-return on main and head alike.
review: no blocking finding; every hunk of both commits read. Verified against the installed DXR 1.1 SDK (10.0.26100): the console build flags the ABI uses (ALLOW_UPDATE 0x1, PERFORM_UPDATE 0x20) are exactly the PC values in that SDK (0x2 is ALLOW_COMPACTION there), so the 0x3F mask in sanitize_build_flags / can_update is an exact console-to-PC translation and implements the DXR 1.1 refit rules (originally ALLOW_UPDATE, matching sanitized non-update flags, same desc count, matching per-geometry flags / vertex+index formats and counts / transform presence); InstanceMask is bits 24-31 of the first UINT of D3D12_RAYTRACING_INSTANCE_DESC, so the masking and its test are exact; all ten hardcoded DXGI format numbers match dxgiformat.h. The ABI structs are size/offset-pinned by tests; the PrebuildInfo mangled symbol is byte-identical to the one the existing e2e tests call on the real DLL, and the two Batched2X manglings are parameter-exact against the hook signatures. Gating: the exports are wrapped only while the UMA has view windows (the 16-window layout), so the default layout is unchanged by construction (one string compare per XboxBvhBuilder import); Path::BvhBuild is appended with stable discriminants and carries real prebuild sizes rather than the sizeless reach. Registry invariants sound: an in-place rebuild at the same native VA keeps referencing TLASes complete (instance descs point at the buffer VA), while relocating, invalidating or rehydrating a BLAS marks them stale at once, and live_as_bytes balances on every insert/remove path. Non-blocking: (1) upsert_native rebuilding the same console VA as a different AS kind with resource = None returns the old handle (the same buffer) for deferred retirement while the new entry keeps None - a caller-contract edge in a module nothing calls yet; the follow-up shadow-builder PR drives it; (2) the UPDATE_SCRATCH cache grows per distinct dest VA (bounded by the title's AS destinations, removed on a non-ALLOW_UPDATE rebuild at that VA); (3) +2109 lines over the two stacked commits (this PR's own commit is 970: ~640 code + ~330 tests kept together per CONTRIBUTING) is over the ~400 soft target.
performance: nothing by default (no view windows: one string compare per XboxBvhBuilder import, no hooks installed). In the 16-window layout: per batched build/rehydrate call one call of the DLL's own prebuild query, a readable() walk of the descs, and one is_view compare per asked range (tile mapping only for ranges in view windows). hw_rt is called by nothing in this PR, so it costs zero at runtime here.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B

@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