DXIL: swap GPURT traversal loops for native RayQuery (XCL_HW_RT_TRAVERSE) #3705
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3705"
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-02T16:00:25Z.
Add direct-DXIL GPURT inline traversal loop recognition and native
RayQuerylowering (XCL_HW_RT_TRAVERSE=1, requiringXCL_HW_RT=1andXCL_RAYTRACINGnot disabled). Off by default; compute disk translation cache entries are isolated via a compute-only_hwrt3filename suffix intranslated::file_forso enablingXCL_HW_RT_TRAVERSE=1reuses all existing graphics (VS/PS/MS) translated caches instead of busting the global cache directory.Part of #1751. Stacked on #3704 (
0e42eb3f8; only commit1f287a928belongs here).Related: #2184, #2185, #2186, #2187, #2188, #2189.
Why this PR is over 800 changed lines: The diff is +1161 / -6 lines across 5 files, consisting of ~870 production lines (
gpurt.rsCFG liveness, visibility and translucent loop recognizers, andLw::traversal_swap/Lw::translucent_swaplowering;kernel.rsloop-entry hook;pso.rscompute-scoped_hwrt3cache discriminator;shaders.rssemantic pipeline setting) and ~291 lines of synthetic RDNA2 and cache-isolation unit tests. The native top-level table,Shader::native_tlas, and shared-heap descriptor reservation were already split into #3704; splitting the loop recognizers from theLwlowering or their validation tests would either add unused code or land unverified DXIL emission.What is in it
crates/xcl/src/gpu/dxil/gpurt.rs&mod.rs:traverse_enabled()andwith_traverse_for_tests(...)delegating directly tohw_rt::traverse_enabled()andhw_rt::with_traverse_for_tests(...).image_bvh64_intersect_raysites.visibility_of: recognizes opaque first-hit visibility loops (single live-out hit VGPR read only via zero comparisons after the loop, no side-effecting memory ops and no non-nodeBUFFER_/TBUFFER_/S_LOAD/S_BUFFER_LOAD/SCRATCH_/FLAT_or non-BVHIMAGE_loads, known ray and top-level registers, single instance-mask test).translucent_of: recognizes translucent closest-hit loops with foldedFORCE_NON_OPAQUEray flags (no culling), proving front-face0xFEhit-kind polarity directly on the lane mask SGPR driving everyV_CNDMASK_B32write tofront(V_CMP_EQ_U32 0xFEwith(front, min)orV_CMP_NE_U32 0xFEwith(min, front)in the same block), plus committed-pointer, optional iteration-cap, and post-loop LDS checks.Lw::traversal_swap/Lw::translucent_swap: looks up each active lane's console TLAS VA inMEM_HW_RT_TABLE; if any active lane misses, the whole wave falls back to the software BVH walk; otherwise each active lane with an ordered valid ray interval (tmax >= tmin,Pred::FOGe) traces viaShader::trace_any_hitorShader::trace_translucentand jumps past the loop (zeroingcappedfor all active lanes).BUFFER_LOAD_DWORDandIMAGE_SAMPLE), translucent S3 polarity acceptance and rejection (inverted polarity and unrelated0xFEmask), S4fcmp oge floatguard emission, and DXC 1.9 validation.crates/xcl/src/gpu/dxil/kernel.rs: wiregpurt::swapsinto non-compact compute/kernel translation, routing each swapped loop's entry edge throughlw.swap(...).crates/xcl/src/gpu/recomp/pso.rs: scope theXCL_HW_RT_TRAVERSE=1translation disk cache discriminator strictly toStage::Computevia a_hwrt3filename suffix intranslated::file_for/file_for_with(leaving globaltranslated::identity_from_source()unchanged so graphics shadersVS/PS/MSkeep their existing cache directory and files;direct_output_identitykeepsxcl-hw-rt-traverse-3for rerouted enormous compute shaders, andhw_rt::traverse_enabled()is process-constantOnceLockso in-RAMShaderCachecannot mix entries). Addshw_rt_traverse_cache_key_is_compute_onlycoveringidentity_from_source,file_for_with/file_foracross graphics and compute stages, and disk round-trip non-collision.crates/xcl/src/shaders.rs: addXCL_HW_RT_TRAVERSEtosemantic_pipeline_setting(and assert it inwarm_settings_ignore_waits_watchdogs_and_traces_but_keep_pipeline_switches) so warm pipeline preparation tracks the compute setting without altering globaltranslation_cache_identity.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(commit1f287a928352ac71dcb238a3a5d3d4dd4741c3e0): succeeded, 39 warnings (0 new vsmain)..\scripts\test.ps1(commit1f287a928352ac71dcb238a3a5d3d4dd4741c3e0): 3006 passed, 0 failed, 52 ignored across 43 test suites; 24 GPU tests skipped on this adapter (22no wave64, 2no heap windows), includinghw_rt_traverse_cache_key_is_compute_only,warm_settings_ignore_waits_watchdogs_and_traces_but_keep_pipeline_switches, bothgpu::dxil::gpurtsynthetic tests,hw_rt_table::tests(3/3),hw_rt::tests(9/9),ray_query::tests(4/4), andhle::bvh_builder::tests(12/12) — all ran with 0 skips.XCL_HW_RT=1 XCL_HW_RT_TRAVERSE=1 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16run on previous revision112374d1907e1d234a2cea4a9edd1eb1a83ca540(same traversal lowering, before the compute-scoped cache fix and #3662/#3704 review fixes;XCL_PREPARE=0,XCL_NETWORK=0,XCL_PSO_EVICT_FRAMES=600, automated title-screen advance):exit: 0x0,1971frames shown,0device removals,0crashes:D3D12.X: XCL_HW_RT_TRAVERSE: native top-level table at descriptor 22 (8 entries)[SHADER] direct DXIL: 1 ray traversal loop(s) swapped for a native RayQuery when the top level has oneD3D12.X: XCL_HW_RT_TRAVERSE: native top-level table: 3 published, 0 taken outHW RT shadow (XCL_HW_RT): live 2620 BLAS / 5 TLAS / 134 rehydrated (240 MiB AS, 123 MiB pools); built 1331 BLAS (0 updates, 1327 skipped), 150 TLAS (80 complete, 70 hybrid, 0 skipped); insts 106502 resolved / 0 null / 2194 rehydrated-skip / 33102 missing-skip; 1764 rehydrated recorded (1618 built natively, 146 count mismatch), 159 stale invalidated, 0 copy-invalidated, 0 copied natively, 0 alloc-err, 0 budget-skipXCL_HW_RT=1 XCL_HW_RT_TRAVERSE=1run on previous revision112374d1907e1d234a2cea4a9edd1eb1a83ca540(same settings):exit: 0x0,1947frames shown,0device removals,0crashes; 4 shaders swapped,native top-level table: 2 published, 0 taken out:HW RT shadow (XCL_HW_RT): live 2 BLAS / 5 TLAS / 225 rehydrated (1 MiB AS, 10 MiB pools); built 2 BLAS (0 updates, 13247 skipped), 536 TLAS (240 complete, 296 hybrid, 0 skipped); insts 259119 resolved / 0 null / 9506 rehydrated-skip / 236718 missing-skip; 4526 rehydrated recorded (0 built natively, 388 count mismatch), 0 stale invalidated, 0 copy-invalidated, 0 copied natively, 0 alloc-err, 0 budget-skipRegression run
Base (
main):PR (
pr/hw-rt-traverse):Not tested
XCL_HW_RT_TRAVERSE=1runs were performed on previous revision112374d19and were not re-run after scoping the disk cache key and restacking on updated #3662/#3704 (1f287a928).3on 16-window,2on default), and0device removals.GLOBAL_loads in the loop are accepted as node fetches (same astranslucent_of), so an alpha test that fetches only through global loads with no image sample or buffer/scalar load would not be caught.0xFEselect is proven. That the commit (tmax, pointer) happens only on the back-face side is not proven separately; theFORCE_NON_OPAQUEfold and the0xFEmin imply it.RayQuerytraversal.XCL_HW_RT=116-window runs ended in0x887a0006; this PR's 180 s 16-windowXCL_HW_RT_TRAVERSE=1run completed cleanly with0device removals).XCL_HEAP_WINDOWS=1tests (2 skipped), and sample-gated tests (XCL_SAMPLE_*unset).AI use
Claude Opus 5.5): architecture, traversal loop safety audit (S3 front-face polarity proof, S4tmax >= tminguard, visibility non-node load rejection, B4 env gating, B5 synthetic test cleanup).Gemini 4 Neon): implementation, rebase onto updated #3662/#3704, compute-scoped_hwrt3cache key fix and cache-isolation unit tests, synthetic RDNA2 unit tests, release build, full test suite, regression smoke, live 16-window and defaultXCL_HW_RT_TRAVERSE=1verification, and PR description.Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T16:15:55Z.
@Kalmarv a heads-up for #3705 from reading the retail title's main ray program (not a run yet; we'll run your stack as soon as our rig is free):
8994bb33444988e6(compute). Its node test is a GPURT site:image_bvhat0x3a84withs19 = 0x890003ff(yourGPURT_DESC_W3).0x3818-0x479c: one external entry (0xb7c: s_branch 0x3818), one exit (the fall-through at0x47a0);0x3810is only reached from the back edge. So the loop itself should pass the single-entry/single-exit check.compact.rs'sLARGE_INSTS(10,000), so it most likely gets a compact plan, andkernel.rsonly swaps whenplan.is_none(). If that holds, #3705 leaves this program alone, and it's the one the title's ray tracing depends on.v51 == 3check at0x3a38, after the loop-guard block at0x39d4-0x39e8), so node tests stay at 0. A native RayQuery in place of this loop would bypass that.Would the swap be possible before compact planning (or inside it, per region)? Happy to test whatever you try. Your loyal testing minion, rig permitting.
AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T16:27:00Z.
Thanks for the heads-up @KDenKC — confirmed on the code:
kernel.rs:477currently gatesgpurt::swapsonplan.is_none(), so any compute shader that triggerscompact::automatic_plan(LARGE_INSTS = 10_000/LARGE_BLOCKS = 2_000) skips the swap in this PR.Yes, wiring the swap into the compact path is doable cleanly in a follow-up PR:
gpurt::swaps(&cfg, o.wave64)already runs on the pre-compactionCfg, socompact::emitcan intercept theentry -> headeredge (or dispatch a swap case in the state switch) to runlw.swap(...)and branchcurtoexit's compact index on the native path orheader's compact index on wave fallback.One caveat to check when testing
8994bb33444988e6(0x3818–0x479c):#3705only recognizes opaque first-hit visibility loops (single live-out hit VGPR, no non-nodeBUFFER_/IMAGE_/S_LOAD/etc. loads) andFORCE_NON_OPAQUEtranslucent loops (0xFEfront-face min). If0x3818–0x479creturns full closest-hit attributes (e.g.t, barycentrics, primitive/instance IDs) or loads non-node buffers/textures inside the loop, it will also need a closest-hit recognizer on top of compact-path support.Keeping
#3705scoped to the non-compact path as-is (it's already +1073 lines and CI-green), and we'll look at compact-form swap support + checking whatgpurt::swapssays about8994bb33444988e6in a follow-up stacked PR.Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T18:26:24Z.
@Kalmarv a correction to my note above, sorry: I counted the whole listing (~11,700 lines), not what
compact.rscounts. For8994bb33444988e6the reachable blocks are 878 (underLARGE_BLOCKS2,000) and the reachable non-terminator instructions 8,648 (underLARGE_INSTS10,000), and its twobuffer_atomic_addhave GLC=0, so it most likely lowers plain andplan.is_none()holds: #3705 should get to try the swap on it after all.For the matcher, from the disassembly: the loop is
0x3810-0x479c(back edge to0x3810), 83 blocks / 757 instructions, entered from0xa88 -> 0x3818besides the latch, one exit0x4788 -> 0x47a0, oneimage_bvh64(0x3a84). The values read right after the exit come from the commit block at0x4600-0x4660:v22(committed t),v27(t compared at0x47a4),v31(flags, bit 2),v33(record index),v38(a 10-bit field of the hit record),v32(tested against -1),v28-v30. We'll confirm with a run of your stack (XCL_HW_RT=1 XCL_HW_RT_TRAVERSE=1) as soon as our rig is free and report what the swap log says for this program.AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T18:36:36Z.
Thanks for the correction and the live-out breakdown @KDenKC! Good news that
plan.is_none()holds on8994bb33444988e6.From those live-outs (
v22,v27,v28–v33,v38— committedt, record index, hit-record fields, etc.),8994bb33444988e6looks like a general closest-hit loop rather than the opaque visibility (1 live-out hit VGPR) orFORCE_NON_OPAQUEtranslucent (tmax/front/committed/capped) shapes#3705recognizes, so#3705will likely leave it on the software walk and it would be a natural target for a dedicated closest-hit matcher follow-up on top of#3705. Looking forward to seeing what your run reports!Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T01:33:46Z.
merge-check
base:
078358a058head:
1f287a9283merge: clean
build: ok
tests: 3038 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 6 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1672 frames (100 % of main), peak commit 17577 → 16497 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 220 s there, 0 device removals, 0 crashes, 3.1 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: Recognizes GPURT visibility and translucent closest-hit loops in non-compact compute programs and, with XCL_HW_RT_TRAVERSE=1, replaces each with a native RayQuery when every active lane's top level is in the table, else the wave runs the software walk; disk cache entries for compute get a _hwrt3 suffix. The default path is unchanged and the CFG wiring is right. The recognizers accept loops they can't prove equivalent, no test runs a swapped program, and the test override turns the feature on for every test running at the same time; nothing is critical, and all of it is opt-in.
Medium
if let Ok(dis) = validate::disassemble(..)(~996, ~1029) also skips the string checks silently if disassembly fails. A WARP A/B on the synthetic loops, using #3704's harness, would cover it.112374d19, before the cache-key change and the restack, and no counter shows a swapped dispatch tracing natively. KDenKC's main ray program (8994bb33) looks like a closest-hit loop that neither recognizer accepts. The smoke run covers only the default path.70c8c51f3vs5bfb22746) and #3700's readable()+read_unaligned in read_archive_prims land with this PR.Nit
Checked and fine
tois head(), file_for adds no suffix and direct_output_identity is unchangedHow 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:46:35Z.
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 on1f287a928(run46994382194). Runningmain'sscripts/pr_check.py --localagainst PR #3705's current description and file list for1f287a928passes (description ok), andBuild and test (Windows, no GPU)is green (run46994386313). Oncepull_request_targetrecovers, I'll retriggerPR checksvia a no-op description edit without changing1f287a928.On the technical review points:
loop_rayusingtmin = 0: RDNA2'sIMAGE_BVH64_INTERSECT_RAYtakes 12VADDRVGPRs (node_ptr,tmax,origin,dir,inv_dir) with notminoperand — GPURT pre-offsetsoriginbytmin * dirand shrinkstmaxbefore entering the loop, sotinside the loop always starts at0. Agreed that visibility cull-flag checking, narrowingGLOBAL_loads to node-pointer bases, and proving the translucent commit side are real limits (currently listed under Not tested) and good follow-ups once checked against live swapped shaders.if let Ok(dis)): Good catch onif let Ok(dis)—validate::validateright above already requiresdxcompiler.dll, so.expect(...)avoids silently skipping the disassembly assertions. Agreed that a WARP execution test exercising the lowered swap (native hit/miss + wave fallback) is worth adding.with_traverse_for_testsglobal atomic): Good catch —pso.rsalready hasfile_for_with, and passing the traverse flag explicitly into compute translation in tests (instead of toggling the process-wideTRAVERSE_OVERRIDE) avoids any cross-test interference under--test-threads=4.XCL_HW_RT_TRAVERSE=1path and drop the carried stack commits when rebasing after#3704lands.pso.rscomment): Good catch —hw_rt::traverse_enabled()caches only the env parse inOnceLockand readsconfig().raytracing_tier_override()dynamically, so the "process-constant" comment is stale.Leaving
1f287a928untouched for now so this merge-check and green CI aren't churned during thepull_request_targetoutage; happy to fold#2(disassemble().expect(...)+ WARP test),#3(explicit test flag), and#7(comment fix) in on the next push when rebasing onto#3704(or sooner if you'd like them before merge).Drafted with Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:32:53Z.
merge-check
base:
078358a058head:
1f287a9283merge: clean
build: ok
tests: 3038 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 6 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1672 frames (100 % of main), peak commit 17577 → 16497 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 220 s there, 0 device removals, 0 crashes, 3.1 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: Recognizes GPURT visibility and translucent closest-hit loops in non-compact compute programs and, with XCL_HW_RT_TRAVERSE=1, replaces each with a native RayQuery when every active lane's top level is in the table, else the wave runs the software walk; disk cache entries for compute get a _hwrt3 suffix. The default path is unchanged and the CFG wiring is right. The recognizers accept loops they can't prove equivalent, no test runs a swapped program, and the test override turns the feature on for every test running at the same time; nothing is critical, and all of it is opt-in.
Medium
if let Ok(dis) = validate::disassemble(..)(~996, ~1029) also skips the string checks silently if disassembly fails. A WARP A/B on the synthetic loops, using #3704's harness, would cover it.112374d19, before the cache-key change and the restack, and no counter shows a swapped dispatch tracing natively. KDenKC's main ray program (8994bb33) looks like a closest-hit loop that neither recognizer accepts. The smoke run covers only the default path.70c8c51f3vs5bfb22746) and #3700's readable()+read_unaligned in read_archive_prims land with this PR.Nit
Checked and fine
tois head(), file_for adds no suffix and direct_output_identity is unchangedHow 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.