d3d12: build acceleration structures that titles place in their own memory #320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/320"
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 brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-27T17:51:26Z.
Draft: the change does what it says in Lanes and in ProjectScarlett, but with it ProjectScarlett now hits a GPU fault at world entry on my RX 9060 XT, which I haven't solved yet. I'm opening it so others can try it, especially on NVIDIA, and because the remaining fault may be something someone else recognises. Details under "Known issue".
Addresses the open item "the title's ray tracing scenes aren't built yet" in
docs/PROJECTSCARLETT.mdanddocs/SHADERS.md, and the dropped builds I asked about on #258.Problem
On the console a GPU address is the CPU address, so a title can build an acceleration structure anywhere in memory it allocated itself, with no resource naming the range. ProjectScarlett does this for its BLASes: from world entry, all destinations lie in one ~2.2 GiB
MEM_PRIVATEallocation of its own (not XMem-backed), and no D3D12 resource covers them.blas::resolveonly knows structure pools registered throughdepth::wrap, where the guest address is the native one. So the guest address went to vkd3d-proton unchanged, and vkd3d dropped every build:That was 147 to 1,275 drops per run on my card. The same builds also passed their scratch, geometry, instance and size-report addresses through unchanged.
Change
device/blas/guest_memory.rs(new): a committed private or mapped allocation that no registered resource covers gets a structure pool without native storage (Buffers::structure_pool). Every structure built or copied into it gets private device-local storage, published under its guest address through the existing relocation path, so TLAS instance fixups, copies, size queries and ray-query scenes see the native address.findprefers a registered pool over a guest-memory pool, so a native address inside a guest CPU range keeps its old meaning.commands/build_raytracing/guest_addresses.rs(new): scratch, geometry, TLAS instance records and size reports go throughcommand_buffer_address_flags, the import views and CBVs already use. Instance records in title memory are patched by the existing GPU instance fixup through that import. A remainingDirectrefusal (which fails the wholeExecuteCommandListsbatch once anything is relocated) is logged once.scene_view.rs: a ray-query scene in title memory resolves to its private storage.XboxBvhBuilderrehydration still returnsE_NOTIMPL, but now says so in a bounded log. ProjectScarlett doesn't call it.Test
New Lanes scenario
ray-tracing-guest-memory: oneVirtualAllocblock holds vertices, an instance record, scratch, a BLAS and a TLAS using it. It builds the BLAS with a compacted-size report, clones it, builds the TLAS and reads all current sizes.FAIL ... the build in title memory reported no compacted size (compacted 0, current 0, copy 0, scene 0), with vkd3d'sFailed to place destAccelerationStructure.PASS(compacted 512, current 584, copy 584, scene 704 on RADV). RADV reports the TLAS's current size above its prebuild maximum (704 > 640), so the scenario only requires a non-zero scene size.Unit tests for the overlap rule are in
src/tests/device/blas/guest_memory.rs.Not covered by Lanes yet: a scene submitted before the list that builds its BLAS, while that list waits for a title fence (the record-time publication above). I want to add that scenario before this leaves draft.
BLAS control (second commit)
Every build mode of
tools/check_frosty_blas.pyfailed onmainwithunaligned batch accepted, before any ray query: sincee8af9fda refused build is skipped and the list kept, but the guest still expectedClose()to fail. The second commit updates the six build-related negative checks; copy and size-query checks still expect an error.With that, the modes that need no retail data give identical results with this branch's and
main'sd3d12_xs.dll: default,--single-build,--gpu-instances,--promote-blasand--ambiguous-aspass and match the desktop ray query (70010,70120,80010,80120,dead),--copy-onlypasses,--reuse-blasfails on both (oversized BLAS copy accepted, not touched here).ProjectScarlett
Title 1.0.2.1, offline, 3840x2160. RX 9060 XT, Mesa 26.2.6 RADV, kernel 6.18, GE-Proton11-14, no preload. Build:
07db52fwith #258 and #308 merged plus this change; all my runs that reached world entry had #258.Failed to place destAccelerationStructureany more. At world entry the title's AS allocation gets one pool; private storage grows to 128-259 MiB over ~900 structures.Known issue: GPU fault at world entry
In every run with this change, shortly after world entry, the compute ring faults on reads of a few consecutive pages, then the gfx ring times out and the kernel resets the GPU (twice a full MODE1 reset; once the whole desktop froze):
The address differs per run but always lies in
0xd10000000-0xd1e000000. Without this change, the same build ran past world entry for 39 minutes without it (but with every BLAS dropped, and a dark, very grainy picture).What I could rule out with temporary diagnostics:
0xffff8002...-0xffff8004...) and storage released while still referenced (nothing was released before the fault)buffer_atcould not backWhat I see: in one run the first scene referenced 11 structures at
0xd0a10b100-0xd1b080100, the same range as the faults, which the provider never built or copied. In another run the scenes had no such references and the fault came anyway.Open questions
0xd0-0xd1...guest addresses or native VAs? On RADV some native buffer VAs may be that low; I'm checking it next.Checks
RX 9060 XT (RDNA4), Mesa 26.2.6 RADV, kernel 6.18, Proton Experimental (Lanes) and GE-Proton11-14 (game).
python tuxbox.py check --no-gpu: all six groups pass.python tuxbox.py verify --only lanes-selftest: all 18 scenarios pass, including the new one andray-tracing-builder(before the record-time publication and rehydration log commits; not rerun since).check: not run yet.AI use
This branch was made with an AI coding agent (Claude Opus 5.5 via Claude Code, following
AGENTS.md). The agent analysed the run logs and the provider source, wrote the provider changes, the Lanes scenario, the unit tests, the control update, the temporary diagnostics behind the findings above (not part of the branch) and this description. I reviewed the first two commits before committing them. The game runs, the Lanes runs, the BLAS controls and the checks above ran on my machine.No title files, shader bytes or logs included.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T18:21:07Z.
We had a branch for the same problem and won't open it; yours covers more. Three things from it that may help, measured on an RTX 5090 (driver 620.70.10, GE-Proton11-14) unless noted.
1. The fault range is guest memory, and the 11 unbuilt structures look like cooked ones.
In a ProjectScarlett 1.0.2.1 run we read the 64-byte instance records bound beside each scene on the CPU and mapped where their structure addresses fall:
0x14b070000pool, where the builds go;0x300200000to0x108a720000. Each is0x100past the start of its view, for example0x90a500100,0x910700100,0xd27180100,0xeb9980100. 89 instances pointed into a single 640 KiB view.Your
0xd0a10b100-0xd1b080100have the same…100form and lie in that span, as does the fault range0xd10000000-0xd1e000000. That run had the package's own builder staged, so I can't say from it that no build call ever targets those addresses; your log says the provider never built or copied them.instance_fixup.hlsl(and the CPU patch) leaves an address it doesn't find in the table unchanged, so such a record reaches the host scene as a raw guest address. A top-level build reads each instance's bottom level, which would fault on the compute ring without any ray-query dispatch. That part is inference; I haven't run it.Suggested test: count the instance addresses with no mapping at fixup, and write 0 for them (an instance with a null structure is inactive). If the fault goes, the remaining work is giving those streamed structures host builds, not the placement in this PR.
2. RADV's current size is the build size plus serialisation padding.
radv_acceleration_structure.csets the header'ssizeto the compacted size, plus the serialisation header and the bottom-level address list rounded up to 128 bytes, minus both. That is +72 for a bottom level and +64 for a scene with one instance: your 512 → 584 and 640 → 704, and our 384 → 456 for a single triangle (Raphael iGPU). It doesn't depend on the buffer. A title that sizes a copy from the current size sees more than its prebuild maximum on RADV.3. A ray-hit test for scenes in title memory.
We gave
tools/check_scarlett_rays.pya second pass in which the guest keeps vertices, instance records, scratch and both structures in memory it allocated, and binds each scene by the top level's address. On our branch:main(65e3e48)failed=0failed=5,12,10,6failed=0failed=0I haven't run it against this PR. It is two small commits (the guest mode, and a check that
--xshaderand--providerexist) that I can send as a PR on top of yours, or you can take them.Our full checks of our own branch passed on NVIDIA (149/149); I'll run this PR's head on the 5090 and report.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T19:19:47Z.
NVIDIA results for
561b8059:python tuxbox.py check --adapter 10de:2b85passed, 148 pass and 0 fail (RTX 5090, driver 620.70.10, GE-Proton11-14).mainat8ef909bb. There was no Xid, no device loss, no forced label release, and noFailed to place destAccelerationStructure.mainunder the same conditions didn't either. After the intro, both sat at about 1 fps while pipelines compiled for the rest of the 30 minutes, so I'll rerun once that's sorted out.The ray-hit replay against this PR's provider is next.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T19:50:32Z.
Ray-hit replay against this PR's provider (
561b8059plus our twotools/commits, RTX 5090, 620.70.10, GE-Proton11-14): all 4 programs showfailed=0, both with the scenes in buffers and with the scenes in title memory.maingavefailed=5,12,10and6in the title-memory pass. So the placement in this PR gives the same ray hits as our branch did.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-27T20:00:59Z.
Update the PR when you're ready to merge and I'll have a look
Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-27T23:51:44Z.
I think I hit the same world-entry fault on the same card (RX 9060 XT, RADV 26.1.8), with a local branch that builds the title-memory BLASes much like this one. In my case it came from geometry formats the console uses and the host doesn't, not from the structure placement.
What an audit of the title's BLAS build inputs showed (ProjectScarlett 1.0.2.1):
_ => 0in the index match, the index range has 0 bytes, and in my branchnative(addr, 0)returned the title pointer unchanged, so it reached the GPU as a raw address. The faults stopped when I decoded it. YourIndexBuffer = native(..., bytes, ...)withbytes == 0may do the same; worth checking whatnativereturns for an empty range.R32G32_FLOATwith stride 8 (175 geometries). The real data needs a 32-byte header just beforeStartAddress(origin, order, scale), and read as R32G32 the positions come out as garbage.VertexCountranges run past committed memory (checking only the first page doesn't catch it);VertexCount(e.g. 3747 against 16).The format 53 layout, as far as I decoded it:
0x80000000 | meshlet count, dword 1 = triangle count;2 * (((M0 << 2) & 0x10000) | (M1 & 0xffff)), where M0 and M1 are its record's first two dwords.Rebuilt that way, triangles matched the retail builder's leaves on 61,973 of 61,973 paired leaves.
What fixed it for me:
After that, a run decoded 256+ builds and had no GPU page fault through to "Game Running". I can open the decoder as a follow-up PR on top of this one if that helps.
Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T05:09:34Z.
@gtb-sbe, following up on the geometry decoder above (index format 53 and the 8-byte quantized positions): would you like me to open it as a separate PR stacked on this branch, or would you rather fold those formats into this PR yourself? Either works for me. I'll wait for your preference so we don't both change the same build path.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T06:12:19Z.
@Jerkin42, your format-53 decoder would help us too; I'd welcome it as a PR stacked on this one. Here's what we measured with this PR merged into
mainplus our mesh-loop fix (#372), on an RTX 5090 (620.70.10):0x90032e100–0xef8238500), 16-byte aligned, and inside no registered buffer.guest_addresses::geometry, any index format other than R16_UINT or R32_UINT is sized as 0 bytes, so it is never resolved and its raw address is passed through.acceleration_structure.c:90-98atcae8353e) treats any index format other than UNKNOWN or R16_UINT as R32_UINT at that address.Locally we're testing a stopgap that builds such a geometry empty, so no raw address reaches the host. It doesn't decode anything, so your decoder is the real fix. We'll post the run result here.
Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-28T06:26:04Z.
@NickStallman thanks for the measurements. I opened #375, stacked on this branch. It decodes format 53 on the CPU into R32_UINT indices, in an upload buffer the list keeps, and sizes the vertex range by the largest decoded index. Any other index format the host can't read now refuses the build instead of passing the address through.
I left out the packed 8-byte positions (R32G32_FLOAT, stride 8) for now: that layout is also valid D3D12, so decoding it needs a reliable way to tell the two apart. It hasn't been run in game on this branch yet.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T06:43:36Z.
A correction to what this PR and our earlier comment assumed, with what we're doing about it. Measured on an RTX 5090 (620.70.10) with this PR merged locally.
ProjectScarlett does call rehydration.
game_scarlett_master.exeimportsXboxBvhBuilder::RehydrateRaytracingAccelerationStructureBatched2X(hint 7). The package DLL exports only the Batched and Batched2X rehydrate entry points.tuxbox_bvh_rehydrate2(runtime/bvh/src/lib.rs:146) answersE_NOTIMPLto all of them.0x14,NumDescs1–12, an array of geometry descs. Dests are in the title's reserved streaming span, ending in…100or at 256-byte steps after it. The extraaddressesarray is always dest −0x600000000.…100form.What that does on the 5090.
ReadInvalidat0x926c95000, in the same span and about 212 KiB past refused rehydration destinations, with no allocation there.What we're doing. The cooked data holds no vertices: its leaves carry geometry and primitive indices only, and rehydration reads the title's own geometry. So each rehydrate entry can be handled as an ordinary bottom-level build of the geometry descs it carries, through this PR's title-memory path. That needs format-53 indices (#375) and the 8-byte quantized positions decoded. We're writing that now, on top of this PR and #375, and will open it as a PR stacked on #375 with a Lanes scenario and game results.
@Jerkin42, if you already decode the quantized positions, say so and we'll use yours rather than write a second decoder.
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T11:20:15Z.
Following up on our note above: the rehydration fix is now #394, stacked on #376.
RehydrateRaytracingAccelerationStructureBatched2Xbecomes host builds of each entry's geometry, read through XMem's backing. In ProjectScarlett on an RTX 5090, with #376's 14-bit stride mask, a run logged 84 rehydrations and none skipped. Lanesray-tracing-rehydratepasses on NVIDIA and AMD.Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-28T11:49:57Z.
A data point from RDNA2 without this change. It may help separate what this PR causes from what happens at world entry anyway on RADV.
Setup
RX 6600 (
1002:73ff, RDNA2, 8 GB), Ryzen 5 5600, 32 GB RAM + 34 GB swap, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14. ProjectScarlett 1.0.2.1, offline, 3840x2160, no preload.mainatb426c1a, D3D12 provider sha2567ae6d1db…de720cb2, Microsoft DXC 1.9.2609, shaders prepared. Host profile:adapter=1002:73ff wave=32-64 section-import=substituted descriptor-bytes=64/16 mesh=yes rays=yes.What happened
This is the first run on this card that got past the #215 watchdog. All five earlier runs, on
7953f0aand before, ended on it in the intro Prestream. This time the intro presented 1–14 frames per second instead of 0.5. The title set mission0x98c85f2aat frame 15,258, after 39 minutes. Then, within about 11 s:Failed to place destAccelerationStructure. Dropping call.There were none earlier in the run; all 379 fall in those last 11 s, around the frames where the mission was set.VK_ERROR_DEVICE_LOST, the provider loggeddirect queue rejected a guest command-list batch, and the title stopped on a breakpoint (exit code 3) at frame 15,262.Unlike your known issue, there was no gfxhub page fault and no MODE1 reset, only the ring timeout and a ring reset. In the last 25 lines before the hang the log also shows a skipped compute dispatch (
pipeline has no paged descriptor layout: its root indexes the resource heap directly, guest caller0x248cbc1, 11 in the whole run) andplaced texture alias handled without failing the queuemessages.How this relates to the PR
mainwithout this change ran past world entry for 39 minutes. On this card it hangs within seconds of world entry without the change. So the gfx timeout after world entry is not caused by this PR alone on RDNA2. It could be the dropped builds themselves, or whatever the frame does with the scenes they should have produced. I can't tell which from this run.Not established
I can run this branch on the same setup and report whether the drops go away and how it ends. I'd add per-process VRAM and GTT samples to that run.
Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-28T12:07:49Z.
Follow-up to my comment above: a second run on the same build (
mainb426c1a, still without this change) reproduced the ending, this time with per-process memory numbers.Same ending, after 5 minutes instead of 39
With the Mesa cache and the link translations from the first run warm, the title reached world entry after 5 minutes. It set mission
0x98c85f2aat frame 1,748. Then came 315Failed to place destAccelerationStructure. Dropping call.and the samering gfx_0.0.0 timeoutwith a ring reset (no page fault). The title stopped with exit code 3 at frame 1,752. The first run ended the same way, 4 frames after the same mission was set.So on this card the hang follows the start of the mission at world entry, not run time. In both runs the dropped builds start at that point, and the ring times out about 10 s later.
Memory at the hang
The game process's amdgpu counters (
/proc/<pid>/fdinfo), sampled every 10 s. The last sample was 2 s before the ring timeout:amd-requested-vramamd-requested-gttdrm-memory-vram(resident)drm-memory-gtt(resident)amd-evicted-vramNot enough memory for command submission.So this hang doesn't look like an allocation failure. Your 128–259 MiB of private storage would come on top of a VRAM that is already full.
Not established
Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-11-28T12:29:17Z.
I ran this PR on the RX 6600 from my comments above. It was merged locally into
mainatb426c1a: one conflict, in the Lanes list inproject_tuxbox/verify.py, where I kept both sides.tuxbox.py check --no-gpupasses. D3D12 provider sha256e1e11ef5…56348877. Same setup otherwise: RDNA2, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, warm shader caches.The dropped builds are gone
Failed to place destAccelerationStructure: 0. The two runs onmainwithout this change had 379 and 315.It ends in your known issue, on RDNA2 too
The title set mission
0x98c85f2aat frame 4,973, after about 7 minutes. It ended at frame 4,979 with exit code 3. The kernel log:There were 10 fault reports, all on ring 24, at these pages:
0x969fbf0000x969fc00000xd2115c0000xe9cf49000These are the same client, status and permission fault as on your RX 9060 XT, so it isn't specific to RDNA4. Two things differ:
0xd10000000–0xd1e000000; one of mine is just above that range, the others far outside it.Without this change, the same build on this card ended with a plain gfx ring timeout and no page fault.
The title calls rehydration here
Your PR description says ProjectScarlett doesn't call
XboxBvhBuilderrehydration. In this run it did, 16 times with 16 structures each, all refused by the new log:The refusals came about 2 minutes before the first page fault, by vkd3d's timestamps. Your note says one run's first scene referenced 11 structures that the provider never built or copied. 256 refused rehydrations would be one source of such structures. That is a guess, not tested. #394 (on #376) implements rehydration, so a run with it should show whether the faults follow the refused structures.
Memory
The game process's own amdgpu counters (
/proc/<pid>/fdinfo), in the last sample before the fault (13:23:45):amd-requested-vramamd-requested-gttdrm-memory-vram(resident)drm-memory-gtt(resident)Host memory: 29.0 of 32 GB RAM, 11.9 of 34 GB swap. That is about 0.7 GB more requested VRAM than on
main(14,646 MiB), most of it not this PR's private storage (64 MiB). The growth in GTT after 13:23:55 is after the fault.Not established
I can run #394 on top of this next if that's useful.
Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-28T17:41:11Z.
Thanks everyone for taking this further while I was away: the rehydration (#394) and the console geometry formats (#375, #376) were exactly the missing pieces.
A correction to my description: ProjectScarlett does call rehydration, as @NickStallman showed. My "doesn't call it" came from runs that faulted at world entry before the title got there. The structures my last runs found in small title-memory views outside the AS pool, with addresses ending in
…100, match the rehydrated ones.Follow-up in #406, for two ways a title-memory structure could still stay unbuilt while a scene points at it:
ERROR_INVALID_ADDRESSon my card, or memory the title only reserved) now gets private scratch instead of refusing the build or reaching the host raw.Both come with Lanes scenarios that fail on current
main.