D3D12.X: native top-level table for XCL_HW_RT_TRAVERSE #3704
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3704"
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?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T15:46:04Z.
Add the GPU-visible native top-level acceleration-structure table (
hle::d3d12x::hw_rt_table),Shader::native_tlaslookup helper, andhw_rt::traverse_enabled()gating forXCL_HW_RT_TRAVERSE=1. Off by default (no shaders read the table yet; Caller: #3705, direct-DXIL GPURT traversal loop swap).Part of #1751. Stacked on #3700 and #3659: its commit
70c8c51f3is #3659's5bfb22746; only0e42eb3f8belongs here.Related: #2184, #2185, #2186, #2187, #2188, #2189.
Shared descriptor heap shift: Reserves 9 fixed descriptors in the shared view heap (
MEM_HW_RT_TABLE = MEM_NULL_STORE + 1, followed by 8MEM_HW_RT_TLASslots), shiftingMEM_FIXED_END(the first dynamically allocated console descriptor heap slice) fromMEM_NULL_STORE + 1toMEM_NULL_STORE + 10(+9 descriptors). WhenXCL_HW_RT_TRAVERSEis off,init_viewsreturns early so no upload buffer is created and those 9 slots keepfill_nulls' Texture2D null views, which nothing reads because no shader is swapped.What is in it
crates/xcl/src/gpu/recomp/mod.rs: reserveMEM_HW_RT_TABLEandMEM_HW_RT_SLOTS(8)MEM_HW_RT_TLASdescriptors, advancingMEM_FIXED_END.crates/xcl/src/hle/d3d12x/console_heap.rs: callhw_rt_table::init_viewsonly for the heap that winsGLOBAL(after releasingGLOBALso descriptor hooks cannot deadlock on it;fill_nullsalready wrote valid null views into those slots before publication), and start dynamic slice allocation atMEM_FIXED_END.crates/xcl/src/hle/d3d12x/hw_rt_table.rs&mod.rs:Tablestate machine + mapped upload buffer and descriptor writer.STABLE_FRAMES(4) presents in the same native buffer, taken out immediately when relocated/invalidated/incomplete, and freed slots are quarantined forSTABLE_FRAMESpresents.init_views/init_views_inis idempotent and checks/installs underGPUso concurrent first callers can never overwriteGpu.cpuwith a losing heap or drop a live upload buffer; covered by WARP FL12_0 regression testinit_views_is_idempotent_and_safe_under_concurrent_first_init.MEM_HW_RT_TLAS + k, never 0) and(u32::MAX, u32::MAX)VA sentinels so any torn concurrent GPU read never matches a real console VA or reads descriptor 0 (_mm_sfenceorders CPU write-combining stores; word 0 is written once as a diagnostic-only count sinceShader::native_tlasscans all 8 slots directly).CreateCommittedResourceorMapfails ininit_views, writes a null raw-buffer SRV atMEM_HW_RT_TABLEand 8 null AS SRVs (tlas_view(0)) atMEM_HW_RT_TLAS + kso swapped shaders read zeros and fall back cleanly to the console BVH.crates/xcl/src/hle/d3d12x/hw_rt.rs: addtraverse_enabled()(caches onlyXCL_HW_RT_TRAVERSEenv parsing and dynamically checksenabled()soXCL_RAYTRACING=0is respected) and mutex+Drop-guardedwith_traverse_for_tests, wirehw_rt_table::syncfrom build, rehydrate, copy, and periodic summary paths, and add direct-DXILRayQuerycopy-trace verification towarp_rehydrated_and_copied_blas_are_native.crates/xcl/src/gpu/dxil/ray_query.rs: addShader::native_tlas,TLAS_TABLE_*layout constants, and WARPswap_kernellookup + trace cases covering instance masks and table misses.Tested
Hardware: Windows 11 x64 (10.0.26200), NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074 / 610.74, 15995 MiB VRAM, DXR Tier 1.1), AMD Ryzen 9 9950X,
rustc 1.99.0, DXC1.9.2609.5(XCL_DXC_DIR).cargo build --release -p xcl(commit0e42eb3f876009db0576a68c69bd043d426e4c6a): succeeded, 39 warnings (0 new vsmain).0e42eb3f876009db0576a68c69bd043d426e4c6a(all ran, 0 skipped):cargo test -p xcl --lib hw_rt_table::tests -- --nocapture: 3 passed, 0 failed, 0 skipped (includinginit_views_is_idempotent_and_safe_under_concurrent_first_initon WARP FL12_0).cargo test -p xcl --lib hw_rt::tests -- --nocapture: 9 passed, 0 failed, 0 skipped —warp_rehydrated_and_copied_blas_are_nativeran (not skipped):hw_rt: WARP rehydrated + copied bottom levels native, top level complete, RayQuery hits both copies.cargo test -p xcl --lib ray_query:: -- --nocapture: 4 passed, 0 failed, 0 skipped —warp_ray_query_matches_console_bvh_walkran (not skipped):ray_query: WARP traversal swap: table lookup and first-hit trace match the console BVH walk; [misses, hits] by case (mask 0x40, mask 0x80, moved + mask 0x80, VA not in the table): [[16, 48], [64, 0], [16, 48], [64, 0]]..\scripts\test.ps1at the top of this stack (1f287a928352ac71dcb238a3a5d3d4dd4741c3e0, containing0e42eb3f8): 3006 passed, 0 failed, 52 ignored across 43 test suites; 24 GPU tests skipped on this adapter (22no wave64, 2no heap windows).Regression run
Base (
main):PR (
pr/hw-rt-table):Not tested
XCL_HW_RT_TRAVERSE=1shader execution on this PR alone (no shaders emitShader::native_tlasuntil stacked PR #3705).XCL_HEAP_WINDOWS=1tests (2 skipped) and sample-gated tests (XCL_SAMPLE_*unset).AI use
Claude Opus 5.5): architecture, write-combining / concurrent-reader race audit (B3), dynamic env-gating review (B4), andconsole_heap.rs/init_viewsfailure-path review.Gemini 4 Neon): implementation, rebase onto updated #3662/#3700, winning-heapinit_viewsUAF fix and idempotentinit_views_in+ concurrent regression test, concurrency comment &w[0]cleanup, mutex+Dropwith_traverse_for_tests, WARP DXR 1.1 tests, release build, full test suite, regression smoke, and PR description.Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T15:52:36Z.
Review: COMMENTED
AI-assisted review (model: GPT-6). I traced the two-caller shared-heap initialization path.
Imported from ivall/xcl. Originally posted by gut0to on 2026-12-02T15:52:36Z.
Code review location:
crates/xcl/src/hle/d3d12x/hw_rt_table.rs; line 201console_heap::shared_heapexplicitly allows concurrent first callers to build outsideGLOBAL, and it callsinit_viewsbefore choosing which heap wins publication. This global assignment can therefore retain the losing caller's device, mapped table, and descriptor handles. If that caller losesGLOBAL, shaders bind the winning heap whilesyncupdates the other heap; the bound heap's native-TLAS table stays empty and lookups fall back to the console BVH. Could the table state be tied to the heap that wins publication, with a concurrent-first-initialization regression test?Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-02T20:00:03Z.
Code review (head
69ac2d73b2, diff read only — not built or tested on Windows/GPU, not a merge-check)Scope: only
69ac2d73b(the rest of the head is #3700 at3620d7652plus #3659's89bfa9a23, not re-reviewed here). TheTablestate machine,Shader::native_tlasand the default-off gating look right. I found one real bug in how the table gets set up, plus a few smaller points.1.
init_viewsruns for every racingshared_heapcaller, not just the one that winsGLOBAL(console_heap.rs~514).shared_heapdeliberately lets two threads each build a heap and keeps whichever stores toGLOBALfirst. The loser'sheapis dropped when the function returns.hw_rt_table::init_viewsis called before that decision, and every call overwrites theGPUstatic. So withXCL_HW_RT_TRAVERSE=1and a race on first use, two things can go wrong:init_viewslast,Gpu.cpupoints into the dropped heap. Every latersyncthen callsCreateShaderResourceViewon freed descriptor memory, which is a use-after-free.Gpuis dropped along with_buffer). If that was the winner, the winning heap'sMEM_HW_RT_TABLESRV still points at the released buffer.This only happens with the flag on and only under a race, but it's memory-unsafe. Fix: initialise only for the heap that actually wins. One way is to call
init_viewsafter storing toGLOBAL, and only on theg.is_none()path. Release the lock first, since the comment says descriptor hooks look upGLOBAL. No shader reads these slots until #3705, so writing them after publication is fine. The alternative is to makeinit_viewsrefuse to replace an existingGPU, but then the loser's views would still be orphaned.2. The concurrency comments promise more than the code delivers, though the code is safe.
sync's doc says the_mm_sfenceordering means GPU readers "never observe torn … entries".sfenceonly orders the CPU's stores. D3D12 gives no ordering guarantee for host writes to an upload heap that a dispatch is reading at the same time. What actually makes torn reads harmless is the layout: the descriptor index is fixed per slot (MEM_HW_RT_TLAS + k), and an empty entry is(MAX, MAX). Any mix of old and new halves therefore never matches a real VA. It's worth saying that in the comment, so nobody later "simplifies" the layout and breaks it on the strength of the fences.3. The header word is never read.
native_tlascompares all 8 entries and never readsw[0](the used count). The ordering logic for raising and loweringusedinsyncis therefore dead weight. Either drop it or note that it is debug-only.4. Unconditional heap cost. Moving
MEM_FIXED_ENDup by 9 takes 9 descriptors from dynamic allocation even with the flag off. That's fine, and the smoke run shows no change. Therunner.rstest heaps are still sizedmax(MEM_NULL_STORE + 1). That is fine for now, but it will needMEM_FIXED_ENDonce #3705's swap shaders run in recomp tests.5. Test-global override (nit).
set_traverse_for_tests(Some(true))inhw_rt'salign_uptest flips a process-wide flag while other tests run in parallel. If aconsole_heaptest happens to build the shared heap inside that window, the table goesACTIVEfor the rest of the binary. Either keep the override around a pure check, or scope it with a guard and a lock.6. Test evidence.
hw_rt_table's two tests are pure CPU and have no skip path, so the description's "24 GPU tests skipped … including all 9 hw_rt, 2 hw_rt_table, 4 ray_query" can't be literally right. Please say whether the WARPray_queryswap/trace case and the newwarp_rehydrated_and_copied_blas_are_nativeRayQuery block actually ran or printedSKIPPED. They are the only execution evidence fornative_tlas. The swap test itself is well built: there are four cases (mask 0x40, mask 0x80 at the origin, mask 0x80 shifted byFAR, and a VA that isn't in the table), and it is checked against the console walk.Still needed on Windows/GPU: a fix for (1); a real-adapter run with
XCL_HW_RT=1 XCL_HW_RT_TRAVERSE=1(with #3705 for an actual reader) showing the "native top-level table" init/publish logs and no device removal; and the regular suite with the skip counts reported.AI use: Capy, Claude Opus 5.5 (static code review only; not built or tested on Windows/GPU).
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T23:24:48Z.
Thanks @gut0to and @capy-ai — fixed the
init_viewsrace/UAF and folded in the minor items in0e42eb3f8:shared_heap/init_viewsrace & UAF (console_heap.rs,hw_rt_table.rs): Movedhw_rt_table::init_viewsto run only on the heap that winsGLOBAL(after releasingGLOBAL, withfill_nullsalready having populated valid null views in those slots before publication). Also madeinit_views/init_views_inidempotent underGPUso concurrent first callers can never overwriteGpu.cpuwith a losing heap or drop a live upload buffer. Added WARP FL12_0 two-thread barrier regression testinit_views_is_idempotent_and_safe_under_concurrent_first_init(dropping the losing heap and verifying idempotency).hw_rt_table.rs): Updatedsync's comments to state that_mm_sfenceonly orders CPU write-combining stores and that torn GPU reads are harmless because each slot keeps a fixed descriptor index (MEM_HW_RT_TLAS + k, never 0), empty slots hold(u32::MAX, u32::MAX), and freed slots are quarantined forSTABLE_FRAMESpresents.w[0]header cleanup (hw_rt_table.rs): Removed the deadgpu.usedraising/lowering ordering dance insync;w[0]is now written once as a diagnostic-only count (Shader::native_tlasscans all 8 slots directly).hw_rt.rs): Replaced rawset_traverse_for_testswith mutex+Drop-guardedwith_traverse_for_testsso parallel--test-threads=4runs cannot race.0e42eb3f8(hw_rt_table::tests3/3,hw_rt::tests9/9 withwarp_rehydrated_and_copied_blas_are_nativerunning on WARP,ray_query::tests4/4 withwarp_ray_query_matches_console_bvh_walktraversal swap running on WARP — 0 skipped on all three; full stackscripts/test.ps1at1f287a928: 3006 passed, 0 failed, 52 ignored, 24 SKIPPED; 60 s smoke on0e42eb3f8: 1628 frames, 0 removals, 0 crashes).(Fixed and replied via Antigravity (Gemini 4 Neon).)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T01:47:11Z.
merge-check
base:
078358a058head:
0e42eb3f87merge: clean
build: ok
tests: 3035 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 2 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1672 frames (100 % of main), peak commit 17577 → 16768 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 222 s there, 0 device removals, 0 crashes, 3 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet:
PR descriptionis red; otherwise no blocking finding, the suite passes and the smoke run is cleanhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Adds the GPU-visible native top-level table (hw_rt_table), Shader::native_tlas and the XCL_HW_RT_TRAVERSE gate, off by default. The only default-path changes are 9 reserved descriptors at the start of the shared heap and moving init_views after GLOBAL is published. The table's publish/quarantine logic and the init race fix read correctly. Nothing in its own commit blocks it. The stack under it carries a rebased copy of #3659 and #3700's opt-in code with a check-then-read of title memory.
Medium
70c8c51f3has the same patch as #3659's head5bfb22746but is a different commit. With merge commits, merging #3659 and then this stack lands the change twice, and #3659 still has Foniass's "not yet". Either close #3659 in favour of the stack, or stack on #3659's own commit.150a15841bvh_builder.rs ~639 read_archive_prims translates a GPU VA with cpu_at, checks readable() and then does a raw read_unaligned. That is the pattern bmjask flagged as critical in #3662 (fixed there with read_gpu_bytes / read_own). Opt-in only (XCL_HW_RT=1) and #3700's code, but it lands with this PR; it should use read_gpu_bytes.Nit
0e42eb3f8is +720/-31 (751 lines), under 800 so no reason is required, but the description gives none.Checked and fine
How this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T01:55:11Z.
Thanks for the merge-check, smoke run, and title run @Foniass!
On
`PR description` is red: everypull_request_targetworkflow onxcl-dev/xcl(PR checks,Auto triage,Testing feed,Discord mirror) has been returningstartup_failurerepo-wide since ~22:47 UTC on 2026-12-02, so thePR descriptionjob never started on0e42eb3f8(run46994373685). Runningmain'sscripts/pr_check.py --localagainst PR #3704's current description and file list for0e42eb3f8passes (description ok), andBuild and test (Windows, no GPU)is green (run46994378951). Oncepull_request_targetrecovers, I'll retriggerPR checksvia a no-op description edit without changing0e42eb3f8.On the review points:
#3659):70c8c51f3is an identical cherry-pick of#3659's5bfb22746(git range-diffmatches=).#3704depends on two independent PRs (#3659onmainand#3700on#3662→#3697) and stays linear perCONTRIBUTING.md. Note that#3659's current head5bfb22746actually has your follow-upsafe to mergeverdict (the earliernot yetwas on9c33b8cc), so I'm keeping#3659open; once#3659and#3700land onmain, I'll rebase#3704ontomainso70c8c51f3(and#3662/#3697/#3700) drop cleanly rather than landing twice.#3700'sread_archive_primscheck-then-read): Good catch on150a15841(bvh_builder.rs:639). Becausehdr_addrcan be either a CPU address (src_cpu_addrs[i]) or a GPU VA (d.source), replacingreadable()+ rawread_unalignedwithread_gpu_bytes(ford.source) anddstorage::read_own(forsrc_cpu_addrs[i]) removes that TOCTOU window cleanly. I'll fix it in#3700and pick it up when#3704rebases onto#3700(or sooner if you'd like it before merge).+720/-31):0e42eb3f8groupshw_rt_table.rs(422 lines incl. unit + WARP concurrency tests),Shader::native_tlas+ WARP traversal-swap tests inray_query.rs(+161 lines), and theconsole_heap.rs/hw_rt.rs/recomp/mod.rswiring so the table binary layout, writer, reader, and WARP tests stay validated together.Leaving
0e42eb3f8untouched for now so this merge-check, title run, and green CI aren't churned during thepull_request_targetoutage.Drafted with Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:32:31Z.
merge-check
base:
078358a058head:
0e42eb3f87merge: clean
build: ok
tests: 3035 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 2 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1672 frames (100 % of main), peak commit 17577 → 16768 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 222 s there, 0 device removals, 0 crashes, 3 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Adds the GPU-visible native top-level table (hw_rt_table), Shader::native_tlas and the XCL_HW_RT_TRAVERSE gate, off by default. The only default-path changes are 9 reserved descriptors at the start of the shared heap and moving init_views after GLOBAL is published. The table's publish/quarantine logic and the init race fix read correctly. Nothing in its own commit blocks it. The stack under it carries a rebased copy of #3659 and #3700's opt-in code with a check-then-read of title memory.
Medium
70c8c51f3has the same patch as #3659's head5bfb22746but is a different commit. With merge commits, merging #3659 and then this stack lands the change twice, and #3659 still has Foniass's "not yet". Either close #3659 in favour of the stack, or stack on #3659's own commit.150a15841bvh_builder.rs ~639 read_archive_prims translates a GPU VA with cpu_at, checks readable() and then does a raw read_unaligned. That is the pattern bmjask flagged as critical in #3662 (fixed there with read_gpu_bytes / read_own). Opt-in only (XCL_HW_RT=1) and #3700's code, but it lands with this PR; it should use read_gpu_bytes.Nit
0e42eb3f8is +720/-31 (751 lines), under 800 so no reason is required, but the description gives none.Checked and fine
How this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.