Repository navigation
D3D12.X: an allocator Reset keeps the recordings the title still submits - #897
Conversation
A retail title's device was removed (0x887a0001) a few seconds into its world. The debug layer: "The command allocator was reset after the command list was recorded" (id 541). A trace of every list reset, allocator reset and submit showed the title's own order: one recording made at 61.4 s, submitted at 61.6 s, at 63.2 s on a second queue, the allocator it was given reset at 67.2 s, and the same recording submitted a third time at 67.8 s. Its console lets it; on the PC the recording lives in the allocator and is gone. The title's allocator now stands for a PC allocator that changes. At the title's Reset, when lists still hold recordings on the PC allocator in use or the GPU has not finished them, that one is put aside as it is and another takes its place: one put aside earlier that nothing uses any more, or a new one. A list reset on the title's allocator records on the one in use. A list holds one recording, so no more are put aside than there are lists. Measured on the retail title (RTX 5090) with this change on a build that also carried the trace: no device removal and no stale submit in the trace in five runs (before: removed 5-9 s into the world in every run). Four of them reached their limit of 100-120 s; the first ran 134 s and was ended on an NVIDIA driver error (nvlddmkm 153) whose cause is not known. In 60 s of world: 240 resets swapped, 163 allocators made, 77 reuses. XCL_ALLOC_SWAP=0 turns it off. Assisted-by: Claude Code (Claude Fable 5.2)
81d3253 to
11920b5
Compare
#897 kept, by address, which PC allocator a title's allocator stands for. The entry stayed when the allocator was released, so a later allocator at the same address went on with the old one's PC allocator - of another type or device. On CI (WARP) that failed mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares: its list Reset got E_INVALIDARG after alloc_pool's own test had left an entry for an address the test's allocator then received. The allocator's last Release now drops its entries; the PC allocators made for it go with it when nothing records on them any more. Assisted-by: Claude Code (Claude Fable 5.2)
…eset On the newer console command-list layout (real::QUEUE_SHIFTED), titles reset pooled lists through slot ivall#139 Reset(allocator, initial_pso, flags), which real.rs routes to list_x::reset_x. title_list's wrapper vtable only overrode slots 0, 1, 2, 9, and 10, leaving slot ivall#139 as a raw forwarder to F_BACKING. Once a mid-list Wait64 split switched F_BACKING to a continuation segment, ivall#139 reset only that continuation segment and never ran title_list::reset: F_PRIMARY stayed bound to the previous recording/allocator, F_BACKING was never restored to F_PRIMARY, and extra_active kept accumulating split segments across frames. On pre-ivall#897 main that caused D3D12 device removal (0x887a0001 / debug-layer id 541) as soon as the old allocator was reused; even with ivall#897/ivall#907 allocator pooling, stale primary/prior segments continue to be resubmitted and extra_active grows until MAX_EXTRA_SEGMENTS. The wrapper's ivall#139 is now a guard::make_layout_split of its own: a title on the newer layout goes to a four-argument adapter that runs wrapper reset, while a title on the older layout and the runtime take the generated forwarder. The forwarder's tail jump keeps the caller's return address and arguments, which the backing list's own layout guard at ivall#139 needs to tell a title from the runtime; calling the backing slot from Rust would hide it and send an older-layout title to the PC method. Tests: one covers the forwarder and the newer-layout reset on fake lists; one calls the slot from a caller in a registered mapped image, with the backing slot behind a layout guard as real.rs installs it and a test-local layout flag (flag clear: the older handler with the title's arguments; flag set: the primary is reset and the split segment reclaimed). Co-Authored-By: Antigravity <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A result for the allocator swap on an AMD RX 6800 (16 GB) with a newer retail game. Builds are local: main at 384f7f7 plus later With the swap on (default), 14 runs in a row ended with a device removal What grows: this title uses about 246 command allocators and resets each one before the lists recorded on it, while those lists still hold recordings that have already executed. The swap counts them as live, so nearly every title allocator gets a second PC allocator (389 made by about 210 s in one run: 246 because none was put aside yet, 143 because a recording held the spare). Each keeps the memory of its largest recording. Non-local video memory outside our own resources rises from 4.6 GB at world start to about 6.1 GB, and the removal comes at that level every time. With Two things I tried that did not bound it: releasing a segment's hold when it is set aside at Reset, and capping idle spares per title allocator. Measured in runs on my machine; the diagnostics and this report were written with Claude Code (Claude Opus 5.5, reviewed with Claude Fable 5.2). |
…:reset On the newer console command-list layout (real::QUEUE_SHIFTED), titles reset pooled lists through slot xcl-dev#139 Reset(allocator, initial_pso, flags), which real.rs routes to list_x::reset_x. title_list's wrapper vtable only overrode slots 0, 1, 2, 9, and 10, leaving slot xcl-dev#139 as a raw forwarder to F_BACKING. Once a mid-list Wait64 split switched F_BACKING to a continuation segment, xcl-dev#139 reset only that continuation segment and never ran title_list::reset: F_PRIMARY stayed bound to the previous recording/allocator, F_BACKING was never restored to F_PRIMARY, and extra_active kept accumulating split segments across frames. On pre-xcl-dev#897 main that caused D3D12 device removal (0x887a0001 / debug-layer id 541) as soon as the old allocator was reused; even with xcl-dev#897/xcl-dev#907 allocator pooling, stale primary/prior segments continue to be resubmitted and extra_active grows until MAX_EXTRA_SEGMENTS. The wrapper's xcl-dev#139 is now a guard::make_layout_split of its own: a title on the newer layout goes to a four-argument adapter that runs wrapper reset, while a title on the older layout and the runtime take the generated forwarder. The forwarder's tail jump keeps the caller's return address and arguments, which the backing list's own layout guard at xcl-dev#139 needs to tell a title from the runtime; calling the backing slot from Rust would hide it and send an older-layout title to the PC method. Tests: one covers the forwarder and the newer-layout reset on fake lists; one calls the slot from a caller in a registered mapped image, with the backing slot behind a layout guard as real.rs installs it and a test-local layout flag (flag clear: the older handler with the title's arguments; flag set: the primary is reset and the split segment reclaimed). Co-Authored-By: Antigravity <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit b3a969b)
…#1358) A title's allocator Reset while the GPU still runs what was recorded on it puts that PC allocator aside (alloc_pool, xcl-dev#897) and returns S_OK. real::alloc_reset took the S_OK as "the GPU is done" and freed every unified-memory block that ended recordings on the title's allocator had used: root argument tables, io and AllocateUploadMemory blocks. Coherent blocks go back on the pool's LIFO stack, so the next translated draw can take one and write its arguments over those a submitted draw has not read yet; sparse ones are decommitted. xcl-dev#897 counted 240 such swaps in 60 s of a retail title's world. The blocks were also held under the title's allocator, which since xcl-dev#897 stands for PC allocators that change, so no one Reset could tell whether the GPU was done with all of them. A recording's blocks are now held for the PC allocator it is on (the one alloc_pool's reset_list hands to the PC Reset), and alloc_pool gives a PC allocator's blocks back at the title's Reset once the GPU has passed every submit on it, whether it is in use, was reset or was put aside. A PC allocator made here that is released gives its blocks back with it. The device test through the Reset hook finds the blocks freed at the swap on the old code (run on Wine's D3D12 over MoltenVK; no Windows machine here). Fixes xcl-dev#1358. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 7901856)
A retail title's device was removed (
0x887a0001) a few seconds after its world started, in every run. The debug layer names it: "The command allocator was reset after the command list was recorded" (id 541). A trace of every list reset, allocator reset and submit showed the title's own order: one recording made at 61.4 s, submitted at 61.6 s, again at 63.2 s on a second queue, the allocator it was given reset at 67.2 s, and the same recording submitted a third time at 67.8 s. Its console lets it; on the PC the recording lives in the allocator and is gone at the Reset.The title's allocator now stands for a PC allocator that changes: at the title's Reset, if lists still hold recordings on the one in use (or the GPU has not finished them), it is put aside as it is and another takes its place.
What is in it
crates/xcl/src/hle/d3d12x/alloc_pool.rs(new): which PC allocator each list's recording is on, a fence value a queue after each submit, and the swap at the title's Reset – to an allocator put aside earlier that no list uses any more and whose submits are done, or a new one. A list holds one recording, so no more are put aside than there are lists. GPU testa_recording_outlives_the_reset_of_the_titles_allocator(withXCL_ALLOC_SWAP=0it fails at its first assertion).real.rs:alloc_resetasksalloc_poolfirst;reset_pc_allocator; a note of each submit inq_execute_command_lists.list_x.rs: every PC list Reset (the title's, the mid-list split's, KickoffX's) takes the PC allocator in use; CreateCommandList notes the list's allocator; KickoffX's submits are noted.XCL_ALLOC_SWAP=0turns it off.Tested
cargo build --workspace, thencargo test --workspace -- --test-threads=4: 716 passed, 0 failed, 41 ignored; no SKIPPED tests on this adaptertiling::detile_levelreading title memory – not this code.)Regression run
main (dbe9324 is the commit of #873, merged as 1ec4c98):
PR:
Not tested
alloc_poollogic on a build that also carried the trace and other local changes. The 60 s regression run is of the head commit and does not reach the world.AI use
🤖 Generated with Claude Code