Skip to content

D3D12.X: an allocator Reset keeps the recordings the title still submits - #897

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
theaustinayers:alloc-swap
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
theaustinayers:alloc-swap

Conversation

@theaustinayers

@theaustinayers theaustinayers commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 test a_recording_outlives_the_reset_of_the_titles_allocator (with XCL_ALLOC_SWAP=0 it fails at its first assertion).
  • real.rs: alloc_reset asks alloc_pool first; reset_pc_allocator; a note of each submit in q_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=0 turns it off.

Tested

  • NVIDIA GeForce RTX 5090 (driver 621.14), Ryzen 9 9950X3D, Windows 11 build 26300, rustc 1.100.0, debug build for tests, release for the runs
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4: 716 passed, 0 failed, 41 ignored; no SKIPPED tests on this adapter
  • A retail title, on a build of main at beaa245 with this change and the trace: before, the device was removed 5–9 s into the world in every run (4 runs). With it, no device removal and no stale submit in the trace in 5 world runs: 4 reached their limit of 100–120 s; the first ran 134 s and was ended on an NVIDIA driver error (nvlddmkm 153) whose cause I do not know. In 60 s of world: 240 Resets swapped, 163 allocators made, 77 reuses. (A sixth run crashed at 22 s in the menus in tiling::detile_level reading title memory – not this code.)

Regression run

main (dbe9324 is the commit of #873, merged as 1ec4c98):

xcl-smoke v1
commit: dbe932400410828fd0490f86714a1f397d4a1504
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1627 (PresentX 1627)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16291 MB

PR:

xcl-smoke v1
commit: 11920b5e0d127f04d45363ac8475e82d174d9e40
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1639 (PresentX 1639)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16186 MB

Not tested

  • The head commit itself in the title's world: the world runs above were made with the same alloc_pool logic 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.
  • AMD and Intel GPUs, Wine / vkd3d-proton.
  • Memory over a long session: an allocator put aside stays until the list that recorded on it is reset again; 116 were held that way after 60 s of world. A list that is released while it holds a recording keeps its allocator put aside for good (not handled here).
  • The world is still at about one frame every 2–6 s with this (the GPU is at 97–100 % from the world's start): this PR only keeps the device.

AI use

  • Claude Code, Claude Fable 5.2: wrote the trace that found the order, the code, the test and this description. The runs above were made on the hardware named.

🤖 Generated with Claude Code

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)
@theaustinayers
theaustinayers merged commit 1c87b1d into xcl-dev:main Nov 24, 2026
2 of 3 checks passed
theaustinayers added a commit that referenced this pull request Nov 24, 2026
#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)
shelbykb2 added a commit to shelbykb2/xcl that referenced this pull request Nov 24, 2026
…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>
@shelbykb2

Copy link
Copy Markdown
Contributor

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 alloc_pool commits up to 01d4c77, with other open PRs and local changes on top, so take it as a pointer, not a clean A/B of main.

With the swap on (default), 14 runs in a row ended with a device removal 0x887a0007 at 213-347 s into the run, always at about 2,640-2,770 presented frames. With XCL_D3D12_DEBUG=1 the debug layer logs Kernel memory failure. There might be a memory leak. (id 834) at the removal. DRED page-fault reporting shows no fault, and no operation is stuck on any queue.

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 XCL_ALLOC_SWAP=0: 4 runs to their timers (310, 400, 450, 560 s; up to 3,177 frames), no removal, and the same memory levels off near 5.7 GB. No 0x887a0001 either; these builds have the slot #139 list Reset change of #929. I did not run the debug layer in those four, so I cannot say whether id 541 still appears.

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).

theaustinayers pushed a commit to theaustinayers/xcl that referenced this pull request Nov 25, 2026
…: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)
theaustinayers pushed a commit to theaustinayers/xcl that referenced this pull request Nov 25, 2026
…#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants