Skip to content

D3D12.X: unpin retired split segments from alloc_pool and guard title_list::release ABA - #1453

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:d3d12x/title-list-segment-leak-and-aba
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:d3d12x/title-list-segment-leak-and-aba

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes two lifecycle bugs in title_list split segments and wrapper release:

  • When a title_list split onto an extra PC segment and later returned that segment to spares via Reset or KickoffX, alloc_pool::forget_list was never called on the retired segment. The segment stayed pinned in its backing allocator's users set indefinitely, preventing reuse of that backing allocator and leaking new PC ID3D12CommandAllocators on subsequent Resets.
  • In title_list::release, after f(pc) freed the primary PC command list, WRAPPER_OF.remove(&pc) and bind::forget(pc) ran unconditionally. If another thread created a new command list that reused the freed pc heap address in the window after f(pc), the old wrapper's cleanup detached the new wrapper and wiped the new list's bind state.

This calls alloc_pool::forget_list(list) inside list_x::clear_segment_state (covering both title_list::reset and KickoffX) and before releasing spare segments; in title_list::release, it only removes WRAPPER_OF entries still mapped to this and skips the redundant bind::forget(pc) when pc was adopted (already cleaned up inside real::cl_release).

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: call alloc_pool::forget_list(list) in clear_segment_state.
  • crates/xcl/src/hle/d3d12x/title_list.rs: guard WRAPPER_OF removal against address reuse, skip redundant bind::forget(pc) for adopted lists, forget spare segments from alloc_pool before release, and add unit tests reset_releases_retired_split_segment_from_alloc_pool and release_does_not_remove_reused_pc_from_wrapper_map (both verified failing before the fix).

Since the last push: rebased onto main 06c9f55. The conflicts were in the test module (main's newer_layout_slot_139_resets_primary_and_reclaims_split_segments and slot_139_keeps_the_title_caller_for_the_backing_layout_guard, both kept) and in release's loop, where main iterates extra_active, spares and first: the PR's ABA guard now applies to all three.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 1267 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib title_list: 3 passed, 0 failed (both new tests failed before the fix)

Regression run

main (426a5a7, clean tree, no local changes):

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15158 MB

PR (0bfea00, clean tree, no local changes):

xcl-smoke v1
commit: 0bfea00ee34df738436dbf2d2f098b6c36f2ed1e
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1638 (PresentX 1639)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16322 MB

(The main block is 426a5a7, an ancestor of the current main, from the same machine and data folder.)

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto main 06c9f55, resolved the conflicts, ran the suite and the scripts/smoke.ps1 pair at the head above.

@crosettiremi

Copy link
Copy Markdown

Tested the change at d827520 on Windows with an RX 7900 XT, on a downstream XCL stack that includes #1422 and a local direct texture upload change. Both split-segment tests and the existing in-flight allocator lifetime test passed individually. The release build passed.

I ran one game comparison per build with the same saved Series X profile, separate copies of the same populated DXIL/PSO caches, two DXC workers, a 28 GiB whole-job limit, and the same scripted Player1 selection at 33 s.

Last 2 s sample containing a present Terminal event
Without #1453 96.3 s Guest write to address zero at +0x23cf683
With #1453 238.2 s Guest breakpoint at +0x2474606 after 248 s; sampled process commit reached 28,052 MB

With the patch, at 256 allocator replacements the runtime logged 197 created and 197 put aside. The warm control ended before that counter appeared. An earlier run with the control executable and different cache history reached 256 replacements with 184 put aside. These counts include in-flight work and do not isolate a leak. The later run still had a dark captured frame. I could not verify a visible world or player control. One run per variant does not establish a timing improvement.

@LocranKing

Copy link
Copy Markdown

Independent Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB) test report for d827520e3d4741137e4b569fde77e415024cb186.

Tested

  • Commit: d827520e3d4741137e4b569fde77e415024cb186 (clean tree, merge-base b7aa9f3)
  • Hardware / software: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release
  • cargo build --release --workspace: ok (exit 0)
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4: 772 passed, 0 failed, 41 ignored, exit 0
    • New tests passed: hle::d3d12x::title_list::tests::reset_releases_retired_split_segment_from_alloc_pool, hle::d3d12x::title_list::tests::release_does_not_remove_reused_pc_from_wrapper_map
    • SKIPPED (no wave64): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware

Regression run
main baseline (b7aa9f3bd212088e0d927439284dc5ed325ce3c7):

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1508 (PresentX 1508)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14730 MB

PR head (d827520e3d4741137e4b569fde77e415024cb186):

xcl-smoke v1
commit: d827520e3d4741137e4b569fde77e415024cb186
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1597 (PresentX 1597)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14706 MB

Not tested: debug build, XCL_SAMPLE_* tests on this branch, AMD / native wave64 hardware, extended gameplay sessions past 60 s.

AI use: Antigravity (Gemini 4 Hydrogen) ran the build, tests, and smoke runs and drafted this report from the command outputs.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/d3d12x/title_list.rs
…_list::release ABA

Two bugs in title_list segment and wrapper lifecycle:
- When a title_list split onto an extra PC segment and later returned
  that segment to `spares` via Reset or KickoffX, `alloc_pool::forget_list`
  was never called on the retired segment. The segment stayed in its
  backing allocator's `users` set indefinitely, preventing that backing
  allocator from being reused and leaking new PC allocators on every Reset.
- In `title_list::release`, after `f(pc)` freed the primary PC list,
  `WRAPPER_OF.remove(&pc)` and `bind::forget(pc)` ran unconditionally.
  If another thread created a new command list that reused the freed `pc`
  address in the window after `f(pc)`, the old wrapper's cleanup detached
  the new wrapper and wiped the new list's bind state.

Call `alloc_pool::forget_list(list)` inside `list_x::clear_segment_state`
(covering both `title_list::reset` and `KickoffX`) and before releasing
spare segments; in `title_list::release`, only remove `WRAPPER_OF` entries
still mapped to `this` and skip redundant `bind::forget(pc)` when `pc` was
adopted (already cleaned up inside `real::cl_release`).

Assisted-by: OpenCode (Gemini 4 Neon)
@b3IKK
b3IKK force-pushed the d3d12x/title-list-segment-leak-and-aba branch from d827520 to 0bfea00 Compare November 25, 2026 16:11
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
Integrates split-segment alloc_pool unpin + title_list ABA guard (xcl-dev#1453),
allocator-put-aside memory retention (xcl-dev#1422), and forget-PSO-before-free
(xcl-dev#2422). Preserves UnadoptGuard in list_x reset paths and xcl-dev#2320 kickoff
target switching.

Assisted-by: Antigravity (Gemini 4 Neon)
@SergeAx

SergeAx commented Nov 26, 2026

Copy link
Copy Markdown

Test report: #1453's diff (head 0bfea00) applied onto main b49be183, measured on the parallel-only failure of list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit reported in #42.

That failure is the second bug this PR fixes. In a failing run on main, an instrumented bind::forget removed the dispatch test's stand-in state (pso == 0x7E57_D001) on the thread of a_reset_while_the_last_submit_runs_records_on_another_pc_list, from title_list::release's bind::forget(pc). A split segment the dispatch test had just made had the address of the reset test's freed primary list. bind::dispatch then saw no pending pipeline and stopped splitting (273, 289, 301 or 5 segments instead of 421).

Tested

  • NVIDIA GeForce RTX 5080 (driver 621.14), AMD Ryzen 5 3500X, Windows 10 Pro 22H2 (19045.6466), D3D12 Agility SDK 1.620.2, Rust 1.100.0, debug
  • The xcl lib test binary run as --test-threads=4 hle::d3d12x::list_x, the builds alternating run by run: the dispatch test failed in 13 of 200 runs on main and in 0 of 400 with this PR.
  • Other failures: in 8 of the 400 runs with this PR, another list_x test could not create a queue or allocator (E_OUTOFMEMORY, 0x8007000E). The same error came on a build without this PR too (main plus another change); main itself had 1 other failure in 200 runs, output not kept.

Not tested

  • The full suite and a title with this PR; AMD and Intel GPUs; Windows 11

real::cl_release still forgets a list after the runtime frees it (the same order, with a shorter window); that is not this PR's to fix.

AI use: Claude Code (Claude Opus 5.5) found the cause, ran the measurements and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

sage-sage added a commit to sage-sage/xcl that referenced this pull request Nov 26, 2026
…ease

`heap_release`, `mem_heap_release`, `q_release` and `alloc_release`
called the driver's Release first and, when it returned 0, removed what
XCL keeps by the object's address. Once the driver has freed the object,
another thread can create a new one at the same address and record its
own entries; the cleanup then removes those. For an ID3D12Heap that is
worse than lost bookkeeping: `mem_heap_release` takes the new heap's
`HEAP_UMA` entry and frees its block of unified memory while the new
heap's buffers live in it. A descriptor heap loses its console slots, a
queue or an allocator its list_x / alloc_pool entries.

`release_taking_first` takes a reference first; when AddRef returns 2
the caller holds the last one, so the entries are removed while the
address is still this object's, and what must outlive the object (the
heap's memory block, a descriptor heap's slots and shadow) is freed
after the last Release, as before. `console_heap::unregister` is split
into `take` and `free` for that.

The command list and pipeline releases have the same order; xcl-dev#2691,
xcl-dev#1453 and xcl-dev#2422 change those (xcl-dev#2690).

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sage-sage

Copy link
Copy Markdown

Test report: passes on NVIDIA merged onto current main, and with #2691 the dispatch flake from #2690 did not show in 300 parallel runs. Head 0bfea00e merged locally onto main b49be18 (clean, merge 289952d).

Tested

Not tested

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@KDenKC

KDenKC commented Nov 26, 2026

Copy link
Copy Markdown

Source review of 0bfea00e, no run yet. Two things:

1. The spare pool's in-flight check may lose its data. This PR adds alloc_pool::forget_list(list) to list_x::clear_segment_state (list_x.rs:857). title_list::reset calls that for every segment it has just moved to b.spares (title_list.rs:~185-196). forget_list removes the segment's last_submit (alloc_pool.rs:92), and with it its recordings and its entry in the backing's users. But a title may reset a list while its last submission still runs, and pop_spare decides reuse with alloc_pool::in_flight(p) (title_list.rs:285), which reads that same last_submit. So a retired segment still on the GPU now looks idle and can be taken and reset at once. That is the case the check is there for. Keeping last_submit (and the recordings) until the segment is really released or done, and clearing only the list's own state here, would keep the guard working.

2. Our flake looks like yours. On an AMD iGPU (RDNA2, Ryzen 7 9800X3D), with the list_x fixtures pointed at it, a_dispatch_with_a_pipeline_still_building_waits_at_the_submit failed once in 6 parallel runs. The skipped dispatches showed pipeline 0x0 instead of the stand-in, and it gave 317 segments instead of 421. The standalone and serial runs passed. That matches what you describe (273/289/301 instead of 421). We'll run main, #2691, this PR, and both together, 50 times each on that iGPU, and post the counts here.

AI use: Gemini (Antigravity) found point 1 in a review; Claude Code (Claude Opus 5.5) checked it against 0bfea00e and main and wrote this.

sage-sage added a commit to sage-sage/xcl that referenced this pull request Nov 26, 2026
…ease

`heap_release`, `mem_heap_release`, `q_release` and `alloc_release`
called the driver's Release first and, when it returned 0, removed what
XCL keeps by the object's address. Once the driver has freed the object,
another thread can create a new one at the same address and record its
own entries; the cleanup then removes those. For an ID3D12Heap that is
worse than lost bookkeeping: `mem_heap_release` takes the new heap's
`HEAP_UMA` entry and frees its block of unified memory while the new
heap's buffers live in it. A descriptor heap loses its console slots, a
queue or an allocator its list_x / alloc_pool entries.

`release_taking_first` takes a reference first; when AddRef returns 2
the caller holds the last one, so the entries are removed while the
address is still this object's, and what must outlive the object (the
heap's memory block, a descriptor heap's slots and shadow) is freed
after the last Release, as before. Two last-but-one releases at once
both miss `AddRef == 2`; the one whose Release ends at 0 then takes the
entries after the object is gone, as before this change, so nothing is
left behind. `console_heap::unregister` is split into `take` and `free`.

The command list and pipeline releases have the same order; xcl-dev#2691,
xcl-dev#1453 and xcl-dev#2422 change those (xcl-dev#2690).

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KDenKC

KDenKC commented Nov 26, 2026

Copy link
Copy Markdown

The repetition counts promised in 7186429674: this PR removes the flake on our AMD iGPU.

AMD Radeon integrated graphics (RDNA2) of a Ryzen 7 9800X3D, Windows 11, debug, XCL_ADAPTER=amd with a test-only fixture change so the list_x devices honour it (the fixture printed the AMD adapter on every run), cargo test -p xcl --lib list_x -- --test-threads=4. Up to 50 runs per arm; an arm stopped at its third failure.

arm runs failed segments in the failures (421 expected)
main b49be18 5 3 337, 75, 55
+ #2691 (008fc961) 11 3 51, 77, 81
+ this PR (0bfea00e) 50 0
+ both 50 0

Every failure was a_dispatch_with_a_pipeline_still_building_waits_at_the_submit, with Dispatch with a pipeline that has no translated console shader (0x0) skipped: the stand-in's state was gone, as you describe. The two PRs merge cleanly together.

Point 1 of my earlier comment (the spare pool's last_submit) still stands. These tests don't reach it.

Not tested: NVIDIA (never seen to fail there, 0 of 11 earlier runs); a title.

AI use: Claude Code (Claude Opus 5.5) ran the arms and wrote this.

KDenKC added a commit to KDenKC/xcl that referenced this pull request Nov 26, 2026
Apply thehollowedone's patch and reference-count regression from xcl-dev#2622 comment 7187891221. A list whose Close failed cannot be reset, so release it rather than losing its owner on later spare reuse, and clear its dispatch-chain predecessor.

Adjust the suggested initial-refusal Release call to use the adopted vtable too: cl_release must clean address-keyed state instead of bypassing it through orig_fn. This is the same lifecycle class discussed in xcl-dev#1453 and xcl-dev#2691.

Assisted-by: Codex (GPT-6.1-Sol)
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.

7 participants