D3D12.X: hook XboxBvhBuilder builds and ask for every range whole in GPU views #3662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3662"
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-02T05:25:08Z.
Outer
XboxBvhBuilder.dllHLE hooks that ask for every acceleration-structure build and rehydrate range whole in GPU views (d3d12x::view_want::Path::BvhBuild), laying the hook layer needed for the opt-in DXR 1.1 shadow builder follow-up.On the 16-window GPU-view layout (
XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16),XboxBvhBuilder.dll's compute passes reach vertex, index, and transform buffers through addresses inside uploaded geometry descriptions, and read/write destination, source, and scratch through root views thatview_wantonly asks for 64 KiB for. WrappingBuildRaytracingAccelerationStructureBatched2XandRehydrateRaytracingAccelerationStructureBatched2Xon import resolution andGetProcAddress(named or by ordinal) lets XCL ask for every range whole before forwarding. On the default 4-window layout nothing is wrapped.Part of #1751. Standalone on
main(5eaadb54c; no stacked PRs underneath). Note: the solid-character improvement observed earlier in this thread was bisected by @KDenKC to #3517's 16-window layout change, not this PR.(Why this is 1339 lines and not split further: ~635 lines are the
XboxBvhBuilder.dllABI definitions, safe tile-aware range calculation, andextern "system-unwind"hooks, and ~704 lines are their unit tests, kept together becauseCONTRIBUTING.mdrequires new code to ship with its tests.)Related: #2184-#2189 (specifically #2186) and #3521. Concrete differences: this PR hooks
XboxBvhBuilder.dll(BuildBatched2X+RehydrateBatched2X) on both import resolution andGetProcAddresswithout modifying the DLL or title shaders, asks for whole ranges in 16-window GPU views viaview_want::Path::BvhBuild(sized by the DLL's ownGetRaytracingAccelerationStructurePrebuildInfousing DXR-legalALLOW_UPDATEflags rather than a VA-keyed cache), and usesextern "system-unwind"on all hook trampolines.What is in it
crates/xcl/src/hle/bvh_builder.rs:XboxBvhBuilder.dllABI structs (BuildInputs,BuildDesc,BatchedBuildDesc2,GeometryDesc,PrebuildInfo,PostbuildInfoDesc,StreamDesc), safe geometry/postbuild readers, whole-range calculation (ranges_of_build), andextern "system-unwind"passthrough hooks forBuildBatched2XandRehydrateBatched2X, gated on active GPU view windows.GetRaytracingAccelerationStructurePrebuildInfodirectly from the mappedXboxBvhBuilder.dllmodule when wrapping any export (named or by ordinal), instead of waiting for the title to import it.BUILD_FLAG_PERFORM_UPDATEand setsBUILD_FLAG_ALLOW_UPDATEbefore queryingGetRaytracingAccelerationStructurePrebuildInfo(the DXR-legal form) so update builds receiveUpdateScratchDataSizeInBytesdirectly without an unbounded or VA-reuse-stale cache, falling back toscratch_size.max(SCRATCH_GUESS)if still0.read_gpu_bytes(view_want::cpu_run, splitting across 64 KiB GPU-view tile boundaries when CPU pages are discontiguous, plusdstorage::read_ownkernel copy so concurrent title decommits never fault), coalescing 64-byteD3D12_RAYTRACING_INSTANCE_DESCtarget ranges and deduplicated referenced bottom-level AS header ranges (Use::BottomLevel,HEADER_BYTES) for bothLAYOUT_ARRAYandLAYOUT_ARRAY_OF_POINTERS.R16_TYPELESS(53) index sizing, whole-range bottom-level builds, DXR-legalPERFORM_UPDATEflag stripping and VA-reuse safety (perform_update_queries_dxr_legal_flags_without_stale_cache), cross-64 KiB-tileARRAY_OF_POINTERS+ fault-saferead_own+ BLAS header asks (tlas_pointer_array_cross_tile_read_own_and_blas_headers), fallback estimation, and build/rehydrate hook forwarding.crates/xcl/src/hle/d3d12x/view_want.rs: addPath::BvhBuild("acceleration-structure builds",PATHS = 14).crates/xcl/src/hle/mod.rs,crates/xcl/src/resolver.rs: wirehle::bvh_builder::wrapinresolve_importandget_proc_addressforxboxbvhbuilder.dll, passing the mapped module andImportName.Tested
rustc 1.99.0, DXC1.9.2609.5.cargo build --release -p xcl(commit4082300ba84ea77630ac1050264b4d07fc4bb5a3): succeeded, 39 warnings (0 new vsmain)..\scripts\test.ps1directly on4082300ba84ea77630ac1050264b4d07fc4bb5a3: 2986 passed, 0 failed, 52 ignored across 43 suites; 24SKIPPEDGPU lines on this adapter (22no wave64, 2no heap windows), including all 12hle::bvh_builder::testspassing.4082300ba84ea77630ac1050264b4d07fc4bb5a3(XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_VIEW_STATS=1):exit: 0x0,1645frames shown (1645PresentX calls),0device removals,0crashes; logged 29GPU view (2 s)lines withacceleration-structure buildstotaling30036range asks (478656 KBnew), peaking at4433 acceleration-structure builds (142976 KB new)at96.6 sand2237 acceleration-structure builds (50816 KB new)at149.1 s.4082300ba(uncommitted, reverted after measurement) over 53.0 s of active 16-window BVH builds (113BuildBatched2Xcalls /1472items,83RehydrateBatched2Xcalls /1250items;2637BLAS,85TLASLAYOUT_ARRAY,0TLASLAYOUT_ARRAY_OF_POINTERS,74120TLAS instances read in1220read_gpu_bytescalls):13.92 mstotal hook CPU time (0.026 %of wall time,2.36 %of the588.6 msspent inside the realXboxBvhBuilder.dllcalls;71 µs/ call,5.1 µs/ item, max single call756 µs):read_geometries2.47 ms,sizes_of0.265 ms(0.10 µs/ item),ranges_of_build6.58 ms(77 µs/ TLAS build),ask4.16 ms.Regression run
(Clean pair; the
XboxBvhBuilderhook is not installed on the default 4-window layout.)Not tested
view_windows()is false there.LAYOUT_ARRAY_OF_POINTERSTLAS builds were not emitted by the tested retail title (onlyLAYOUT_ARRAYTLAS builds occurred);LAYOUT_ARRAY_OF_POINTERSis covered by unit tests only.CopyRaytracingAccelerationStructureis not hooked: a compacted or cloned copy whose destination is in a view window is still only asked for its first 64 KiB.XCL_SPARSE_LAZY=1).AI use
Gemini 4 Neon): rebased standalone ontomain, implemented review fixes (read_own+ tile-splittingcpu_run, DXR-legalsizes_ofwithoutUPDATE_SCRATCH, TLAS BLAS header asks) and unit tests, ran the release build, fullscripts/test.ps1, smoke runs, 180 s 16-window live run, and hook CPU timing measurement, and updated the PR description.Claude Opus 5.5): authored the original range-request logic and earlier review fixes.Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T07:03:15Z.
@Kalmarv a first in-world result with #3662 on the RTX 5090, and it's a big one for the picture, though we don't know yet which part of it does it.
What ran. Our tree (our window/alias fixes and diagnostics) + #3662 + #3656 (with #3327 under it),
XCL_NATIVE_MESH=0(so #3656's native path was off; its global shader changes were in),XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16,XCL_SKIP_CS=95cc13288a27a96e, a fully prepared shader cache plus a warm-up, one ~530 s run in the first interior scene.Picture: clearly better than anything we've had in that scene. By eye and in the saved frames:
Our own estimate: roughly 70 % of the scene correct, against far less before.
Performance: degraded. 4.6 fps in the world (stalls 7, longest 26 s) vs 6.8–7.2 fps for the #3656 A/B arms on the same save; peak commit 40,946 MB and peak local VRAM 20,376 MB (vs 39,228 / 19,217 MB for #3327 alone), no device removal or crash.
Ray tracing: our GPU counter on the node test still reads 0 node tests in this run. But with #3662 the top-level headers the walk reads moved (to
0x145db10000/0x145f8cf100/0x1460868d00in this run) and their GPU-side roots now hold what looks like real node data, where before they read empty. Why the walk still tests no node is the next thing we're checking (which backend the ray programs take, which view they read the root through).We don't know yet why the picture improved. Candidates: #3662's 16-window memory-layout commits (trailing view windows for overflow MEM_GRAPHICS reservations, 4 runtime sparse windows: e.g. character vertex/skinning data that was partly uncovered before), its null-window raw UAV fix, or #3656's global signature/optimizer changes. A run of our tree + #3662 alone is next and will split those; we'll post which one it is.
From here we'll focus on tools that find and pin down the remaining small artifacts (the tiles and flicker) automatically. The speed side we'd happily leave to you or a later step.
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 KDenKC on 2026-12-02T07:46:36Z.
@Kalmarv follow-up to the result above, as promised: the solid characters come from #3662's stack, not #3656. Our tree + #3662 alone (no #3656 or #3327), same env, same scene: the main character and the people in the yard are solid and lit, the window is lit, with the same flat missing-texture tiles on the character as the combined run. One more run will split #3662's memory-layout commits (the trailing view windows for overflow MEM_GRAPHICS reservations and the 4 runtime sparse windows) from the builder hook and the null raw-UAV fix; we'll add which one it is.
On the ray-tracing side, with #3662 the top-level headers on the GPU now hold built structures (one walk finds ~915,000 nodes in 787 bottom levels), and the title's ray programs do start (about 540 million lanes over a run), but they leave before their first node test: in the program we read, every lane exits at an early check on a per-pixel 32-bit classification word read from a 2D texture before any intersect instruction. We're tracing which pass writes that word next.
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 KDenKC on 2026-12-02T08:05:54Z.
@Kalmarv @CharlyRien the split run answers it: the solid characters come from the two memory-layout commits under #3662, not the builder hook or the null raw-UAV fix. Our tree + only #3517's 16-window layout change (4 runtime sparse windows) and #3653's trailing view windows for overflow MEM_GRAPHICS reservations, same env and scene: the main character and the people in the yard are solid and lit, exactly as with the full #3662 stack (and see-through on every build without them). So #3517 + #3653 on the 16-window layout fix the "glass" characters on our RTX 5090 by themselves. The remaining flat texture tiles on the character are the same with and without the rest of #3662. In that run too, the ray programs start but do no node test.
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 Foniass on 2026-12-02T08:36:34Z.
Review (head
a69189b8, diff read, not a merge-check):a69189b89(+866/-1, about 350 lines tests) belongs to this PR. By reading, it applies to current main without conflicts and uses nothing from the stacked commits:hle/bvh_builder.rsonly callsview_want,gpu::bvh::prebuild_size/HEADER_BYTESandgpu::shader::readable, all on main; the innerd3d12x::bvh_builderhook is only mentioned in doc comments. The stacked copies of #3517, #3349, #3521 and #3522 are rebased and do not match those PRs' heads (ce078501vs0b4283d1,e3ca17ddvs5dc64ea7,23d5cafdvs2e2d9320,f0c6ae41vs5abd576b); with merge commits, each change would land in main twice. #3349 (null raw UAVs inshared_heap) is unrelated to BVH builds. Rebasea69189b89alone onto main; if it must be smaller: (1) the ABI structs,ranges_of_buildand their tests; (2) the hooks and theresolver.rs/view_want::Path::BvhBuildwiring. The two #3653 commits it carries are identical to #3653's.hle/bvh_builder.rs~395-401 sizes aPERFORM_UPDATEbuild's scratch withUpdateScratchDataSizeInBytesfrom the prebuild query on the update's own inputs; when that is 0,push_range(~336) drops the range and only the 64 KiB root-view ask remains. The inner hook documents that this query "may give none" (d3d12x/bvh_builder.rs~53) and keeps the size from the earlierALLOW_UPDATEbuild, falling back to the larger scratch size. Reusing that logic (and itsSIZESmap) would fix this and avoid a second copy of the ABI and sizing code.REAL_PREBUILD_INFO(~236-240) is set only when the title resolvesGetRaytracingAccelerationStructurePrebuildInfoitself; otherwise scratch is asked for atSCRATCH_GUESS(64 KiB), no better than before. The inner hook looks the export up in the mapped module directly (d3d12x/bvh_builder.rs~81-82); the outer hook could do the same.ARRAY_OF_POINTERS(~403-404) only the 8-byte pointer array is asked for, not the 64-byte instance descriptions read through it, so in a GPU view they can still read zeros.view_windows()is false). The unit tests check range arithmetic only (under testview_want::wantreturns early), so nothing shows the tiles get mapped or what that costs per build (sparse::map_mirrorwalks the ranges' tiles on the recording thread).XboxBvhBuilder.dll, which keeps writing its console-format BVH for XCL's traversal. No D3D12 acceleration structure is produced, so nothing here connects to #3659's RayQuery SRVs yet (no shared files, no overlap).Fine (by reading): the ABI layouts (
BuildDesc0x30,BatchedBuildDesc20x50,GeometryDesc0x38, triangle and AABB payloads, R16 index formats 53..=59) match their D3D12 counterparts; withXCL_SPARSE_LAZY=1the calls go outer hook, inner hook, DLL; wrapping is gated on view windows, so the default 4-window layout is unchanged, and #3653's trailing reservations returnNonethere.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:56:52Z.
Diff review (head
a69189b89, read-only code review — not a test report):Clean ABI verification for
XboxBvhBuilder.dlland safe gating onview_windows()(crates/xcl/src/hle/bvh_builder.rs:203-221) so the default 4-window layout is unchanged. Reading the full diff (+2233/-93across 16 files) turned up 3 concrete issues across both the 5-PR stack and the new hook itself:5-PR stack carries rebased copies of unmerged PRs and inherits their open bugs:
Only the top commit (
a69189b89,+866/-1across 4 files) belongs to this PR, and it depends only on symbols already onmain(view_want,gpu::bvh,gpu::shader::readable). The 5 commits underneath carry copies of#3517,#3653,#3349,#3521, and#3522(4 of 5 with different commit SHAs from those PRs' open heads), inheriting:#3517'swith_switch_fallbackwindow-4 cutoff (crates/xcl/src/gpu/uma.rs:48,:59;crates/xcl/src/hle/d3d12x/real.rs:5178-5191;crates/xcl/src/gpu/recomp/pso.rs:147-161;crates/xcl/src/hle/d3d12x/bind.rs:5316-5318): moving 16-window coherent memory to window4places it pastMAX_WINDOWS = 4root UAVs (0..3) whenever a pipeline takes#156switch fallback.#3653's unrelated dead code (crates/xcl/src/hle/d3d12x/title_list.rs:292-298,:1135-1161): unusedpub fn active_backing+ unit test.#3522'sself.ownlifecycle/recycle hazards insparse.rs(un-clearedself.ownon commit/decommit and same-submityield_own->self.parked->new_mirrorreuse before in-flight GPU completion).Three range-sizing / hook gaps in
crates/xcl/src/hle/bvh_builder.rs:0(bvh_builder.rs:335-339,:395-401): forBUILD_FLAG_PERFORM_UPDATE,ranges_of_buildpassessizes.update_scratch_data_size_in_bytesdirectly topush_range, dropping the scratch range whenever queryingGetRaytracingAccelerationStructurePrebuildInfowithPERFORM_UPDATEreturns0(whereascrates/xcl/src/hle/d3d12x/bvh_builder.rs:123-129retainsUpdateScratchDataSizeInBytesfrom the originalALLOW_UPDATEbuild and falls back toScratchDataSizeInBytes.max(UpdateScratchDataSizeInBytes)).REAL_PREBUILD_INFOdepends on the title resolving that export first (bvh_builder.rs:236-241,:333,:344-366):REAL_PREBUILD_INFOis only captured if the title imports or callsGetProcAddressonSYM_PREBUILD_INFObefore building; otherwise scratch falls back toSCRATCH_GUESS = 64 KiB. Looking up the export directly from the mapped module (as ind3d12x/bvh_builder.rs:81-83) and resolving ordinal imports inresolver.rs:327-329,:444-446avoids this.ARRAY_OF_POINTERSTLAS instance descriptions omitted (bvh_builder.rs:402-404): asks only for the8 * num_descspointer table, not the pointed-to 64-byteD3D12_RAYTRACING_INSTANCE_DESCtargets.Performance regression & isolation:
RTX 5090 testing in this thread measured degraded in-world throughput (
4.6 fpsand a 26 s stall vs6.8–7.2 fps) and bisected the visual improvement solely to the#3517+#3653memory-layout commits rather than this hook. Rebasinga69189b89standalone ontomain(and unifying its prebuild/range sizing withd3d12x::bvh_builderonce#3521/#3522settle) will allow clean isolated measurement of the hook itself.AI use: Antigravity (Gemini 4 Neon) audited the full diff against
mainand drafted this review.Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-02T09:15:42Z.
A narrower answer than in my last comment: #3517 alone is enough. Our tree + only @CharlyRien's #3517 (the 16-window layout keeping 4 runtime sparse windows), without #3653 or the rest of #3662, same env and scene: the characters are solid and lit, with the same flat texture tiles. So the "glass" characters come from what #3517 changes in the 16-window layout; #3653's overflow coverage isn't needed for that (it may still matter elsewhere). Ray programs: as before, they start and do no node test.
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 Foniass on 2026-12-02T11:03:36Z.
merge-check
base:
1c8b551475head:
a69189b894merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2936 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3662#issuecomment-7339682499 and its findings stand. Most serious: only the top commit is its own (it carries rebased copies of 4 other PRs), and an update build's scratch is dropped when the size query returns 0.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (a69189b8): 1652 -> 1684 frames shown (101 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 18899 MB, 0 device removals, 0 crashes.verdict: not yet: only the top commit is its own (it carries rebased copies of 4 other PRs), and an update build's scratch is dropped when the size query returns 0 (see the review)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T15:06:12Z.
Updated in
a65c38b16(standalone onmain5eaadb54c— all 5 stacked commits from#3517/#3653/#3349/#3521/#3522dropped) and addressed every review point:PERFORM_UPDATEscratch size = 0): cachedUpdateScratchDataSizeInBytesonALLOW_UPDATEbuilds inUPDATE_SCRATCH(crates/xcl/src/hle/bvh_builder.rs,resolve_scratch_bytes) so a laterPERFORM_UPDATEwhose prebuild query returns0reuses the cached size (in-place or out-of-place), falling back toscratch_size.max(update_scratch_size).max(SCRATCH_GUESS)instead of dropping the scratch range; covered byperform_update_uses_cached_allow_update_scratch_and_falls_back_when_zero.bvh_builder::wrapnow takes the mappedXboxBvhBuilder.dllmodule andImportName(crates/xcl/src/hle/bvh_builder.rs,record_prebuild_from_module/wrap_with_module; wired incrates/xcl/src/resolver.rs), resolvingGetRaytracingAccelerationStructurePrebuildInfodirectly from the mapped DLL when any export is wrapped and matching ordinal imports as well as names; covered bywrap_resolves_prebuild_info_from_mapped_module_and_handles_ordinals.ARRAY_OF_POINTERS):ranges_of_buildnow translatesinp.descsthroughlist_x::cpu_at, reads the pointer array undershader::readable, and sorts/coalesces contiguous or overlapping 64-byteD3D12_RAYTRACING_INSTANCE_DESCtarget ranges before callingview_want::want; covered bya_top_level_build_names_its_instance_descriptions(including a non-identity GPU VA -> CPU VA mapping).#3521relation): rebased standalone ontomain(5eaadb54c) so the PR diff is only the 4 files / +1139 -1 lines of this change (~585 prod + ~554 unit tests), and documented the concrete difference vs#3521(and whyUPDATE_SCRATCHtemporarily mirrors#3521'sSIZESuntil#3521lands) in the PR body.#3517's 16-window layout — updated the PR body to note that and drop the earlier attribution.PR body updated with fresh
scripts/test.ps1counts, default smoke blocks, and 16-window live run results.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T15:37:46Z.
Follow-up runtime evidence (@Foniass): once the 16-window shader cache warmed up, a 180 s
XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_VIEW_STATS=1run on the stacked #3700 binary withXCL_HW_RTunset (where#3662's hook is the only active one) completed withexit: 0x0,1920frames,0device removals, and logged 27GPU view (2 s)lines containingacceleration-structure builds(peaking at4089 acceleration-structure builds (139392 KB new)at91.5 sand1517 acceleration-structure builds (89152 KB new)at174.9 s). Added to Tested / Not tested in the PR body.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:57Z.
Review: COMMENTED
Review of
a65c38b1: 4 finding(s) (1 critical, 1 high, 2 medium), most severe first.crates/xcl/src/hle/bvh_builder.rs:492: The CPU view of the top-level pointer array is read with rawread_unalignedafter ashader::readablecheck, a check-then-use race on title memory that can be decommitted concurrently. (inline)crates/xcl/src/hle/bvh_builder.rs:487: The ARRAY_OF_POINTERS pointer array is translated withcpu_at(inp.descs)(base address only) and then read as one contiguousn*8-byte CPU run, but when the array crosses a 64 KiB GPU-view tile the next tile's CPU page needn't follow .... (inline)crates/xcl/src/hle/bvh_builder.rs:208:UPDATE_SCRATCHgrows without bound and outlives the structures it describes: every ALLOW_UPDATE build inserts its dest VA, and an entry is removed only when a later non-update build hits the same dest. (inline)crates/xcl/src/hle/bvh_builder.rs:517: Not certain about this one, because it depends on the builder reading bottom-level headers during the top-level pass: top-level builds ask only for the instance descriptions, not for the bottom levels each instance's `AccelerationStructu.... (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:58Z.
Code review location:
crates/xcl/src/hle/bvh_builder.rs; line 492Critical: The CPU view of the top-level pointer array is read with raw
read_unalignedafter ashader::readablecheck, a check-then-use race on title memory that can be decommitted concurrently.bvh_want::read_titleusesview_want::cpu_runplusdstorage::read_own(a kernel copy that can't fault) for exactly this. If the title's streaming thread decommits or releases the page holding the instance pointer table betweenreadable()and the loop, the hook takes an access violation inside anextern "system-unwind"function on the title's render thread and the process crashes. Reading throughread_ownwould make it safe.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:58Z.
Code review location:
crates/xcl/src/hle/bvh_builder.rs; line 487High: The ARRAY_OF_POINTERS pointer array is translated with
cpu_at(inp.descs)(base address only) and then read as one contiguousn*8-byte CPU run, but when the array crosses a 64 KiB GPU-view tile the next tile's CPU page needn't follow the first, whichview_want::cpu_runexists to detect. For a top-level build with ~3000 instances whose 24 KB pointer array starts 8 KB before a tile boundary, with tiles mapped apart (queue page mappings or kernelx mirrors), the entries past the boundary are read from whatever follows the first CPU page. The wrong instance-desc ranges are asked for and the real ones are never mapped, so the builder reads zeros and those instances drop out of the top level. Translating per tile (or usingcpu_run) would fix it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:58Z.
Code review location:
crates/xcl/src/hle/bvh_builder.rs; line 208Medium:
UPDATE_SCRATCHgrows without bound and outlives the structures it describes: every ALLOW_UPDATE build inserts its dest VA, and an entry is removed only when a later non-update build hits the same dest. Besides growing for the whole session (the PR's own log shows ~4000 builds every 2 s, and streaming titles use new VAs), when a dest VA is freed and reused for a different, larger ALLOW_UPDATE structure whose PERFORM_UPDATE prebuild returns 0, the stale smaller size is used and the update scratch past it is never asked for. Querying prebuild withflags & !BUILD_FLAG_PERFORM_UPDATE(the DXR-legal form) would give the size directly and remove the cache.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:58Z.
Code review location:
crates/xcl/src/hle/bvh_builder.rs; line 517Medium: Not certain about this one, because it depends on the builder reading bottom-level headers during the top-level pass: top-level builds ask only for the instance descriptions, not for the bottom levels each instance's
AccelerationStructurefield names. If a bottom level was built frames earlier and its view tiles have since been dropped or not asked again this generation, the top-level build reads zero bounds or headers for that instance, which ends up degenerate or missing. Asking for each referenced bottom level's range (at least its header) would cover it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:56:03Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T23:24:47Z.
Thanks @bmjask — all 4 review findings are fixed in
4082300ba:bvh_builder.rs:492rawread_unalignedTOCTOU): Replaced raw pointer reads of title GPU memory withread_gpu_bytes, which reads exclusively throughdstorage::read_own(ReadProcessMemory) so concurrent decommits fail cleanly instead of faulting insideextern "system-unwind".bvh_builder.rs:487cross-64 KiB-tileARRAY_OF_POINTERS):read_gpu_bytesnow usesview_want::cpu_runon the fast path and falls back to per-64 KiB-tile translation +read_ownwhen CPU pages across a tile boundary are discontiguous.bvh_builder.rs:208unbounded/staleUPDATE_SCRATCH): RemovedUPDATE_SCRATCHcompletely.sizes_ofnow stripsBUILD_FLAG_PERFORM_UPDATEand setsBUILD_FLAG_ALLOW_UPDATE(the DXR-legal form) before callingGetRaytracingAccelerationStructurePrebuildInfo, returningUpdateScratchDataSizeInBytesdirectly (falling back toscratch.max(SCRATCH_GUESS)if still0).bvh_builder.rs:517referenced BLAS headers): BothLAYOUT_ARRAYandLAYOUT_ARRAY_OF_POINTERSTLAS builds now safely read each instance'sAccelerationStructureVA at offset+0x38viaread_gpu_bytesand ask for deduplicated bottom-level header ranges (Use::BottomLevel,HEADER_BYTES).Added regression tests
perform_update_queries_dxr_legal_flags_without_stale_cacheandtlas_pointer_array_cross_tile_read_own_and_blas_headers(hle::bvh_builder::tests: 12/12 passed; full stackscripts/test.ps1at1f287a928: 3006 passed, 0 failed, 52 ignored, 24 SKIPPED; 60 s smoke on4082300ba: 1673 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:58:17Z.
merge-check
base:
078358a058head:
4082300ba8merge: clean
build: ok
tests: 3018 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 3 medium, 2 nits (below)
performance: 60 s smoke run: 1669 → 1657 frames (99 % of main), peak commit 17577 → 17695 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 225 s there, 0 device removals, 0 crashes, 3.4 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: Hooks XboxBvhBuilder.dll's BuildBatched2X and RehydrateBatched2X (named, by ordinal and through GetProcAddress) on the 16-window layout and asks view_want for every range a build names, whole, before forwarding to the DLL. It is now one commit on main, and the earlier review's sizing, prebuild-lookup and instance findings are fixed. Nothing blocks; still open are the missing 16-window run at this head and the unmeasured CPU cost per build.
Medium
4082300band post its acceleration-structure builds line and device-removal count.Nit
1f287a92(the top of a stack). Only the 12 bvh_builder tests ran at this head.Checked and fine
5eaadb54, with no rebased copies of #3517, #3349, #3521 or #3522How 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-03T02:25:44Z.
Thanks for the thorough merge-check and title run @Foniass!
PR descriptionis red: everypull_request_targetworkflow onxcl-dev/xcl(PR checks,Auto triage,Testing feed,Discord mirror) has been failing withstartup_failurerepo-wide since ~22:47 UTC on 2026-12-02, soPR descriptionnever started on4082300ba(check suites127103282286/127103289399). Runningmain'sscripts/pr_check.py --localagainst PR #3662's updated description and 4-file list for4082300bapasses (description ok), andBuild and test (Windows, no GPU)is green (46994358570). Oncepull_request_targetrecovers, I'll retriggerPR checksvia a no-op description edit without changing4082300ba.4082300ba): ran a fresh 180 sXCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_VIEW_STATS=1session directly on4082300ba:exit: 0x0,1645frames shown (1645PresentX calls),0device removals,0crashes, with 29GPU view (2 s)lines loggingacceleration-structure builds(30,036total range asks /478,656 KBnew), peaking at:[96.640] GPU view (2 s): 11452 root views (3776 KB new), 766 mesh stage views (448 KB new), 4433 acceleration-structure builds (142976 KB new)[149.056] GPU view (2 s): 725 views by address (2560 KB new), 3 buffer views (0 KB new), 1 placed buffers (0 KB new), 4491 root views (320 KB new), 1514 mesh stage views (64 KB new), 2237 acceleration-structure builds (50816 KB new)4082300ba(reverted after measurement) across 53.0 s of active 16-window BVH builds (113BuildBatched2Xcalls /1,472items,83RehydrateBatched2Xcalls /1,250items;2,637BLAS,85TLASLAYOUT_ARRAY,0TLASLAYOUT_ARRAY_OF_POINTERS,74,120TLAS instances read across1,220read_gpu_bytescalls):13.92 ms(0.026 %of wall time;2.36 %of the588.6 msspent in the realXboxBvhBuilder.dllcalls) —71 µs/call,5.1 µs/item, worst single call756 µs.read_geometries2.47 ms,sizes_of0.265 ms(0.10 µs/item),ranges_of_build6.58 ms(77 µs/TLAS build),ask4.16 ms.~4000 acceleration-structure buildsinGPU view (2 s)counts individualview_want::wantrange calls (dest/source/scratch/vertex/index/transform/instances/headers), not batch calls (~50 hook calls / ~750 items in that 2 s window, taking~2 mstotal).4082300ba): ran full.\scripts\test.ps1directly on4082300ba:2986passed,0failed,52ignored across 43 suites;24SKIPPEDGPU lines on this adapter (22no wave64, 2no heap windows). Updated Tested and Not tested in the PR description.#3521doc comment): noted — leaving4082300bauntouched for now so this merge-check and the stacked PRs (#3697,#3700,#3704,#3705) stay aligned; happy to add(with #3521)to the doc comment if#3662needs another push or in a follow-up.(Tested, measured, and replied via Antigravity (Gemini 4 Neon).)
Imported from ivall/xcl. Originally posted by KDenKC on 2026-12-03T07:58:38Z.
@Kalmarv a freeze in the retail title that sits in #3662's BVH walk (head
4082300b, which we run on acombined tree with native mesh off). It ended the run on the title's own 30-second watchdog.
What we saw. The world ran normally until a heavy slice (13,663 draws and 27,290 dispatches in 2 s),
then nothing for 31 s, then the title's watchdog crash. XCL's crash-time thread dump, symbolized with the
build's PDB, has the title's present thread here; no other XCL thread was busy:
Why it can take that long.
bvh_want::frameruns insidepresent_x, synchronously, and walks up toA_FRAME(2) stale top levels per present, with their stale bottom levels.bvh::Limits::default()allows 2 GiB of reads and 4 M nodes per structure, 32 M per scene, 65,536 bottom levels, read 64 KiB at a
time from the title's memory (
read_title→read_own). When the title's memory is paged out (our runwas under disk load at the time), one walk can outlast the watchdog, and the present, and with it the
title's frame, waits for all of it.
The ask: keep the walk from blocking the present: a per-present budget (time or bytes, continuing the
walk on the next present), or the walk on a worker thread with the present only picking up finished
results. Either way, a log line with the walk's time when it is long would make this visible.
A question we're measuring: how much the walk costs on an ordinary frame. A top level goes stale
whenever the CPU writes a page it covers, so a title that rewrites its instance data every frame walks
every present. We're running the same build with
XCL_BVH_WALK=0against it tonight and will post thefps difference here.
Your loyal testing minion stands by for the next head.
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-03T08:12:54Z.
Thanks for the symbolized stack and diagnosis @KDenKC!
One important clarification on where this sits: that stack (
present_x→bvh_want::frame→bvh_want::walk→bvh::walk_scene→bvh::Mem::get) is entirely inmain's pre-existingbvh_want.rs/gpu/bvh.rs(commitsba6b879bband6f1f5574e), which#3662(4082300ba) does not touch —#3662only adds theXboxBvhBuilder.dllHLE hooks incrates/xcl/src/hle/bvh_builder.rs(plus wiring inresolver.rs,hle/mod.rs, andview_want.rs).What
#3662did was unmask that pre-existingmainpath: before#3662,XboxBvhBuilderproduced empty structures on the 16-window layout, sobvh_want::walkreturned in tens of microseconds at 0 nodes. Once#3662lets the builder populate real trees (and whenever the CPU side of those pages holds the built nodes),main's synchronous walk hits real node counts underLimits::default()(2 GiB/32 Mscene nodes /65,536bottom levels, read 64 KiB at a time) and can outlast the 30 s watchdog under paging/disk load.Two extra notes from checking
bvh_want.rs:view_madeis also synchronous: in addition tobvh_want::frame()inpresent_x,bvh_want::view_made(va)(called fromCreateShaderResourceViewinreal.rs) callsbvh_want::walk(va)synchronously on the recording thread whenever a new TLAS view is created or a stale TLAS is viewed on a later frame. Moving the walk onto a dedicated background worker thread (withframe()andview_made()only enqueueing stale VAs and applying finished tile sets) would keep bothpresent_xand SRV creation non-blocking, and logging any slow walk (above a millisecond threshold, not just power-of-two counts) would make long walks visible.XCL_BVH_WALK=0with#3662: for acceleration structures built or rehydrated throughXboxBvhBuilder.dll,#3662already asksview_want(Path::BvhBuild) for every result buffer whole up front (and referenced BLAS headers on TLAS builds), so running withXCL_BVH_WALK=0is a clean immediate workaround and A/B test.To keep
#3662scoped to one logical change (it is already at 1,339 lines, has@Foniass's merge-check at4082300ba, and sits under stacked#3697/#3700/#3704/#3705), I am leaving4082300bauntouched and can follow up with a small standalone PR againstmainforbvh_wantonce we see yourXCL_BVH_WALK=0fps comparison tonight (to know whether steady-state frame time is also affected or mainly paging stalls).(Checked and replied via Antigravity (Gemini 4 Neon).)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:36:33Z.
merge-check
base:
078358a058head:
4082300ba8merge: clean
build: ok
tests: 3018 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 3 medium, 2 nits (below)
performance: 60 s smoke run: 1669 → 1657 frames (99 % of main), peak commit 17577 → 17695 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 225 s there, 0 device removals, 0 crashes, 3.4 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: Hooks XboxBvhBuilder.dll's BuildBatched2X and RehydrateBatched2X (named, by ordinal and through GetProcAddress) on the 16-window layout and asks view_want for every range a build names, whole, before forwarding to the DLL. It is now one commit on main, and the earlier review's sizing, prebuild-lookup and instance findings are fixed. Nothing blocks; still open are the missing 16-window run at this head and the unmeasured CPU cost per build.
Medium
4082300band post its acceleration-structure builds line and device-removal count.Nit
1f287a92(the top of a stack). Only the 12 bvh_builder tests ran at this head.Checked and fine
5eaadb54, with no rebased copies of #3517, #3349, #3521 or #3522How 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.