Repository navigation
XboxBvhBuilder shim: rehydrate dehydrated BLASes on the GPU, byte-exact with bvh_rehydrate.py (RT-5) - #7903
XboxBvhBuilder shim: rehydrate dehydrated BLASes on the GPU, byte-exact with bvh_rehydrate.py (RT-5)#7903romainveurrier wants to merge 6 commits into
Conversation
…, boot stop 18) The package's XboxBvhBuilder.dll creates 52 console compute programs as pipelines in its constructor, on the title's thread. Translated, they take 25-60 s to compile on a cold driver cache (ItsNotRexed#7231/ItsNotRexed#7049: 31.2 s for one on an RTX 4080, 59.5 s for all 52 on an RX 9070 XT), longer than the title's ~30 s startup watchdog, so a first boot ends at the builder. runtime/shims/xbox_bvh_builder.cpp serves the seven exports the executable imports (measured statically on 1.0.2.1: constructor 1 call site, destructor 1, Set64BitMortonCodes 8, GetRaytracingAccelerationStructure- PrebuildInfo 3, BuildRaytracingAccelerationStructureBatched2X 6, CopyRaytracingAccelerationStructure 2, RehydrateRaytracingAcceleration- StructureBatched2X 4) with the layer's own XDXR builder (D3D-178). The loader binds imports to a shim before a bundled module, so the DLL is not loaded and its programs are never created. - each BATCHED_DESC2 element (docs/xdxr.md §1) is one layer build with its postbuild descriptions; the offline-statistics type (0x10), which the DLL refuses by throwing, skips the element instead (a shim must not throw); - XDXR stream records and Set64BitMortonCodes tune the console builder's heuristics and are ignored (logged once); - prebuild sizes and copies are the layer's; - the builder's state is kept in a table keyed by `this`: nothing is written into the title's object, whose size isn't known; - rehydration answers E_NOTIMPL for now (stage 2); - LEONIDA_BVH_BUILDER=console keeps the bundled DLL. xbox_bvh_builder_test (12 checks) calls the exports through the shim registry as the title binds them; xdxr_bvh.py check-build validates the BLAS, TLAS and compacted BLAS it builds (0/1000 rays differ on each). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h_rehydrate.py) The GPU side of XboxBvhBuilder.dll's RehydrateRaytracingAccelerationStructure*X (docs/bvh.md §4a), for the shim's rehydration export (RT-5, after ProjectLeonida#7516). src/xdxr_rehydrate.comp follows tools/bvh_rehydrate.py, the model that matches the DLL byte for byte, step for step and with its float32 rounding: - a one-thread plan pass reads the dehydrated header and level table from GPU memory (they may be written by earlier GPU work) and writes the indirect dispatch arguments of every later pass; - clear, kept header (dehydrated flag cleared, root parent entry), leaves (one thread each, through the leaf frame of compressionParams), then each level's BOX32 and BOX16 groups bottom-up (one workgroup each: boxes recomputed from the rehydrated children, stored overrides, BOX16 rounding, parent entries); - every node and leaf is written where its packed bytes are, so the result has exactly the dehydrated size (the size the title allocates). src/xdxr_rehydrate.h records it (XdxrRehydrator): the rotation and geometry tables go into the plan with vkCmdUpdateBuffer, then vkCmdDispatchIndirect per pass. The source and the destination must be different buffers. vk_xdxr_rehydrate_test compares the GPU's result with the model byte for byte on synthetic cases from runtime/test/xdxr_rehydrate_cases.py (several levels of both widths, >64 nodes a level, two leaf chunks, overrides, paired leaves, u16/u32/no indices, a stride, a transform, the leaf frame with rotations, updatable parents), checks the guard past the structure and a structure that isn't dehydrated. On an own 1.0.2.1 copy (local only, counts only): 400 real streams of shared_minigame000_bvh4.rpf and 400 of core_bvh4.rpf (1 to 15 levels, 1.5 M leaves, leaf frame on every one), with random geometry, are all identical to the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ngAccelerationStructureBatched2X) The shim's rehydration export (4 call sites in the executable) now records the GPU rehydration of the previous commit instead of answering E_NOTIMPL: - command_list.h: RehydrateAccelerationStructure (source, destination, scratch for the plan, the source geometry); - d3d12_com.cpp: the layer's lists answer a private ILeonidaXdxrRehydrate (shims/d3d12_xdxr_rehydrate.h), so the shim needs no link to the layer; a description it can't record is E_INVALIDARG and leaves the list usable; - vulkan_replay.h / vulkan_backend.h: the command is prepared (the scratch's buffer for the indirect dispatches, its room for the plan) and recorded by XdxrRehydrator at the arena's addresses. A rehydration the layer can't do (a geometry that isn't R32G32B32_FLOAT, a scratch too small for the plan) is skipped with a log line instead of failing the whole list; - the export passes each element to the list and returns the first failure; on a list that isn't the layer's (the Windows D3D12 backend) it is E_NOTIMPL. The per-element UINT64 argument isn't measured: its first values are logged once and it is not used. xbox_bvh_builder_test rehydrates every synthetic case of runtime/test/xdxr_rehydrate_cases.py through the shim on the layer's Vulkan device and compares the result with tools/bvh_rehydrate.py: 0 bytes differ on each. docs/bvh.md §7b and docs/xdxr.md §4a describe it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tupacfan04
left a comment
There was a problem hiding this comment.
The synthetic/GPU rehydration is clean: 24/24 xdxr_rehydrate checks, 6/6 CTests, 0/1000 rays differ, and all five cases byte-exact against bvh_rehydrate.py. There is one real integration defect.
The private rehydration interface never reaches the layer through the d3d12_xs list proxy:
runtime/shims/xbox_bvh_builder.cpp:237-241asks the title’s command list forILeonidaXdxrRehydrate.- In the boot stack the title’s lists are
ListProxyobjects created through device slot 73.ListProxy::QueryInterface(runtime/shims/d3d12_xs_device.cpp:1480-1492) answers only console-list IIDs and the public list chain; every other IID returnsE_NOINTERFACEand is not forwarded toself->real. - The shim therefore takes its “the list is not the layer’s” branch and returns
E_NOTIMPLfor any proxy-created list, even though the real layer list implements the interface.
The tests pass because they pass the real layer list directly; they never construct a ListProxy.
Fix: forward IID_ILeonidaXdxrRehydrate (or unknown private IIDs) to self->real, return the real interface with its reference, or add an unwrap helper for the shim. Add a synthetic test that gives the shim a ListProxy. The rehydration plan/header/leaf/BOX32/BOX16 path itself has no defect.
Synthetic/GPU only; no game files. AI-assisted (OpenCode).
…he proxy path From @KarolKurzyna's review of 242a5db: - builder_device() returned the builder's device without a reference, so a destructor on another thread could release it during GetRaytracingAccelerationStructurePrebuildInfo. It now takes a reference under the lock, and the caller releases it after the call. - The test only passed an unwrapped device. It now also constructs a builder on a d3d12_xs device proxy (create_device_proxy, as D3D12XboxCreateDevice hands out) and checks that its prebuild sizes are the real device's (13 checks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Synthetic ListProxy repro confirms the
This confirms the defect is the proxy QI boundary, not the GPU rehydration or the shim’s element loop. The 6/6 tests pass because they pass the real layer list directly; they never construct a |
… its interfaces From @tupacfan04's review of ItsNotRexed#7903: on a boot stack with the console list proxy (ItsNotRexed#7076), the title's lists are proxies whose QueryInterface answers only the console and public list IIDs. The shim asked the proxy itself, so a private interface was refused, and a PC interface it did answer would have been called through a console-shaped vtable. d3d12_xs_device exposes real_object_behind_proxy(), the real object behind any child proxy (proxy_real_object, which a console list proxy joins, as the file and ItsNotRexed#7076 say), and the shim asks that real list for ID3D12GraphicsCommandList4. On main lists aren't wrapped, so nothing changes there; with ItsNotRexed#7076 the shim follows its lists without a further change. docs/xdxr.md: BuildRaytracingAccelerationStructureBatched2X is 6 call [rip+disp32] sites through the import table; IDA counts 8 direct calls, two of them in another form (@FJKiXfaR on ItsNotRexed#7516). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its interfaces From @tupacfan04's review of ItsNotRexed#7903: on a boot stack with the console list proxy (ItsNotRexed#7076), the title's lists are proxies whose QueryInterface answers only the console and public list IIDs. The shim asked the proxy itself, so a private interface was refused, and a PC interface it did answer would have been called through a console-shaped vtable. d3d12_xs_device exposes real_object_behind_proxy(), the real object behind any child proxy (proxy_real_object, which a console list proxy joins, as the file and ItsNotRexed#7076 say), and the shim asks that real list for ID3D12GraphicsCommandList4. On main lists aren't wrapped, so nothing changes there; with ItsNotRexed#7076 the shim follows its lists without a further change. docs/xdxr.md: BuildRaytracingAccelerationStructureBatched2X is 6 call [rip+disp32] sites through the import table; IDA counts 8 direct calls, two of them in another form (@FJKiXfaR on ItsNotRexed#7516). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r ILeonidaXdxrRehydrate From @tupacfan04's review: a console list proxy (ItsNotRexed#7076) answers only console and public list IIDs, so the rehydration export took its "not the layer's list" branch (E_NOTIMPL) for every proxy-created list. It now asks the list real_object_behind_proxy() gives, as list4_of does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent native Windows verification of 093259a.
The second check uses a synthetic COM backend on llvm-mingw, with the adapter-LUID SDK signature adjusted in the temporary build. The Vulkan test was compiled unchanged. AI-assisted. |
|
@tupacfan04, right, and thanks for the repro. It's in both stages.
On |
|
@Racurs156, thank you, that's the test I said would have to wait for #7076. With a real
That covers @tupacfan04's finding end to end. Also thanks for the native Windows run with the validation layer on: 24/24, byte-exact, 0 diagnostics. AI-assisted. |
|
Independent native Windows check of PR head: all four selected CTests passed on each GPU, including the two fixture generators. The direct Vulkan test passed 24 checks and the builder shim test passed 20. All five rehydrated outputs matched Real Xbox list proxy: I applied the command-list proxy source changes from #2490 at The direct private-interface query on the proxy returned |
|
✅ Automated security review: CLEAN (commit
Scope: static analysis of added diff lines only; no code was executed. Please review findings manually. |
|
Tested Merged into
Not run: a live boot. AI-assisted (Claude Code). |
|
Tested
A ninth sample, an interior room that aggregates props, is left out: Game data stayed local; counts and sizes only. AI-assisted. |
|
@romainveurrier, a follow-up with data on the rehydration's speed. To spare you rewriting anything, I opened a PR against your branch
Measured on Windows 11 with an RTX 5080. I used a local-only timing hook in
The gain is biggest on small structures, where the fixed passes and their barriers are most of the time. Real trees are shallow: across 1,237 + 3,000 sampled streams the level count is p50 8, p90 12-13, max 17-18. Checked: ctest ( Two side notes:
AI-assisted. |
Item: RT-5, stage 2 of my XboxBvhBuilder claim (claim).
Depends on: #7516 (stage 1; its commit is the first one here, the two new commits are on top).
Why
The executable calls
RehydrateRaytracingAccelerationStructureBatched2Xfrom 4 sites, to turn the dehydrated BLASes shipped in the*_bvh4.rpfpacks into runtime structures. In #7516 the shim answeredE_NOTIMPL. The title sizes each destination from the dehydrated header, so a fresh build from geometry can overflow it: console trees pair leaves and use BOX16 nodes. The safe answer is real rehydration, which writes exactly the dehydrated size.What
1.
src/xdxr_rehydrate.comp+xdxr_rehydrate.h: rehydration on the GPU. It followstools/bvh_rehydrate.py, the model that matchesXboxBvhBuilder.dllbyte for byte (docs/bvh.md§4a), step for step and with its float32 rounding (precise, andfmawhere the model roundsa*b + conce):VkDispatchIndirectCommandinto the scratch.compressionParamswith the 64-rotation table; then each level's BOX32 and BOX16 groups bottom-up. Each group is one workgroup: boxes recomputed from the rehydrated children, stored overrides, BOX16 rounding, parent entries.2. Through the layer.
RehydrateAccelerationStructureincommand_list.h. The layer's lists answer a privateILeonidaXdxrRehydrate(shims/d3d12_xdxr_rehydrate.h), so the shim needs no link to the layer.R32G32B32_FLOAT, or a scratch too small for the plan of 3,712 + 32 bytes per geometry) is skipped with a log line instead of failing the whole list.3. The export. Each element goes to the list, and the first failure is returned. On a list that isn't the layer's (the Windows D3D12 backend), it answers
E_NOTIMPL.Open, posted as a
finding:: the call's last argument, oneUINT64per element. On my copy's 4 call sites, the descriptions and theUINT64array are both on the caller's stack, and batches hold at most 16 elements (static read; offsets only). The DLL's single-structureRehydrateRaytracingAccelerationStructureXworks without it. The shim logs the first values once and doesn't use them.Tests
xdxr_rehydrate_cases+xdxr_rehydrate(Vulkan, Linux or Windows): synthetic dehydrated BLASes, withtools/bvh_rehydrate.pyas the oracle.xbox_bvh_builder: the same cases through the shim's export, on the layer's Vulkan device. 0 bytes differ on each.Tested
Fedora 44, NVIDIA GeForce RTX 2050 (proprietary driver), glslc / spirv-val (the SPIR-V passes
spirv-val):vk_xdxr_rehydrate_test): all 5 synthetic cases identical to the model.xbox_bvh_builder(19 checks; the 5 cases through the shim, all identical),xbox_bvh_builder_console,xbox_bvh_builder_check,d3d12_xdxr_rt,d3d12_xdxr_rt_checkpass. No warnings in the changed files at/W4.shared_minigame000_bvh4.rpfcore_bvh4.rpf(1–15 levels, 1,524,515 leaves, a leaf frame on every one)main, see runtime: serve XboxBvhBuilder.dll with the layer's XDXR builder (RT-5, boot stop 18) #7516).No game files in the repository. AI-assisted (Claude Code).
🤖 Generated with Claude Code