D3D12.X: detach retired segments and reclaim idle aside allocators #2707

Open
github-bot wants to merge 4 commits from github-bot/gh-2707 into main AGit
Owner

@⁠Saksukella on GitHub · 2026-11-26 07:51 UTC · original
Saksukella:fix/alloc-pool-retire-reclaim → main · +644 −42 · 5 files · 4 commits · open

What is in it

  • crates/xcl/src/hle/d3d12x/alloc_pool.rs:
    • Add retire_recording(list) to detach a retired split segment or superseded primary list from its old Backing.users while preserving Backing.marks and last_submit (so GPU completion fences and in_flight(list) remain fully enforced).
    • Track Backing.already_reset and reclaim idle free() put-aside backings on title_reset so their held UMA arena blocks and scratch buffers return promptly instead of remaining pinned until a future busy swap on that exact title allocator.
    • Release STATE before calling reset_pc_allocator / CreateCommandAllocator so COM callbacks during allocator reset or resource teardown (such as dropping a pooled prelude ID3D12CommandAllocator -> real::alloc_release -> alloc_pool::forget) cannot self-deadlock on STATE, and release pending UMA blocks per free backing on forget.
    • Guard against concurrent title_reset / reset_list races while STATE is unlocked: track Backing.resetting (Backing::free() requires !self.resetting) with a Condvar (RESET_DONE), reserve the backing in reset_list before invoking native Reset (rolling back on hr < 0), and wait cleanly if a backing is mid-reset.
    • Add unit tests retired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight, clean_title_reset_reclaims_idle_aside_backings_once, stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets, reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure, and reset_list_waits_while_backing_is_resetting.
  • crates/xcl/src/hle/d3d12x/bind.rs & crates/xcl/src/hle/d3d12x/real.rs:
    • Key bind::State.allocator (and therefore console_list::PENDING UMA blocks) by the native PC allocator backing (alloc_pool::recording_backing / alloc_pool::current) rather than the logical title allocator, and move console_list::allocator_reset(raw) into real::reset_pc_allocator(raw) so swapping away from an in-flight primary backing never frees its UMA blocks while the GPU can still read them.
  • crates/xcl/src/hle/d3d12x/title_list.rs & crates/xcl/src/hle/d3d12x/list_x.rs:
    • Call alloc_pool::retire_recording when title_list::reset moves old split/stand-in segments into spares (and for primary when replaced by a stand_in, retiring its UMA blocks via bind::reset(primary, 0, 0)), in put_spare, and for KickoffX-reclaimed segments in list_x.rs after alloc_pool::executed marks them.

Tested

  • Hardware: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), 24-thread x86_64 CPU, 32 GB RAM, Windows; rustc 1.100.0 (0ef1bc386 2026-11-09); debug (tests) and release (xcl.exe).
  • cargo test -p xcl --lib hle::d3d12x::alloc_pool::tests -- --test-threads=1: 9 passed, 0 failed (0.11s, including stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets, reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure, and reset_list_waits_while_backing_is_resetting).
  • cargo test -p xcl --lib hle::d3d12x::bind::tests -- --test-threads=1: 8 passed, 0 failed (0.38s).
  • cargo test -p xcl --lib hle::d3d12x::title_list::tests -- --test-threads=1: 3 passed, 0 failed (0.01s).
  • Also live-tested in 180s 3D workload on amd-dev (b5c0275f): previously coherent UMA exhausted 4095/4095 MB (547 blocks held for 236 allocators at 63.7k draws / 34.6k dispatches), triggering unified memory is full and 0x887a0006; with this fix held blocks dropped by >72% (152 blocks / 75 allocators, 4046/4095 MB at 65.5k draws / 47.0k dispatches) with 0 unified memory is full warnings.

Regression run

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19700 MB
xcl-smoke v1
commit: dff6edc7e64c818a29fe20946911b8c0e5578387
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1669 (PresentX 1669)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19209 MB

Not tested

  • NVIDIA and Intel GPU adapters (tested on AMD Radeon RX 9070 XT only).
  • Full cargo test --workspace was run on the same base b49be183 in #2703 (1434 passed; pre-existing RDNA 4 fuzz_validate_and_gpu_1/3 failures).

AI use

  • Antigravity (Google Gemini): assisted with analyzing the coherent UMA allocator-block leak, keying pending UMA blocks by native allocator backing, adding the resetting/Condvar concurrency guard, writing unit tests, and running local tests and smoke verification. All diffs and measurements were reviewed and verified locally on hardware.
**@⁠Saksukella** on GitHub · 2026-11-26 07:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/2707) `Saksukella:fix/alloc-pool-retire-reclaim` → `main` · +644 −42 · 5 files · 4 commits · open **What is in it** - `crates/xcl/src/hle/d3d12x/alloc_pool.rs`: - Add `retire_recording(list)` to detach a retired split segment or superseded primary list from its old `Backing.users` while preserving `Backing.marks` and `last_submit` (so GPU completion fences and `in_flight(list)` remain fully enforced). - Track `Backing.already_reset` and reclaim idle `free()` put-aside backings on `title_reset` so their held UMA arena blocks and scratch buffers return promptly instead of remaining pinned until a future busy swap on that exact title allocator. - Release `STATE` before calling `reset_pc_allocator` / `CreateCommandAllocator` so COM callbacks during allocator reset or resource teardown (such as dropping a pooled prelude `ID3D12CommandAllocator` -> `real::alloc_release` -> `alloc_pool::forget`) cannot self-deadlock on `STATE`, and release pending UMA blocks per free backing on `forget`. - Guard against concurrent `title_reset` / `reset_list` races while `STATE` is unlocked: track `Backing.resetting` (`Backing::free()` requires `!self.resetting`) with a `Condvar` (`RESET_DONE`), reserve the backing in `reset_list` before invoking native `Reset` (rolling back on `hr < 0`), and wait cleanly if a backing is mid-reset. - Add unit tests `retired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight`, `clean_title_reset_reclaims_idle_aside_backings_once`, `stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets`, `reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure`, and `reset_list_waits_while_backing_is_resetting`. - `crates/xcl/src/hle/d3d12x/bind.rs` & `crates/xcl/src/hle/d3d12x/real.rs`: - Key `bind::State.allocator` (and therefore `console_list::PENDING` UMA blocks) by the native PC allocator backing (`alloc_pool::recording_backing` / `alloc_pool::current`) rather than the logical title allocator, and move `console_list::allocator_reset(raw)` into `real::reset_pc_allocator(raw)` so swapping away from an in-flight primary backing never frees its UMA blocks while the GPU can still read them. - `crates/xcl/src/hle/d3d12x/title_list.rs` & `crates/xcl/src/hle/d3d12x/list_x.rs`: - Call `alloc_pool::retire_recording` when `title_list::reset` moves old split/stand-in segments into `spares` (and for `primary` when replaced by a `stand_in`, retiring its UMA blocks via `bind::reset(primary, 0, 0)`), in `put_spare`, and for `KickoffX`-reclaimed segments in `list_x.rs` after `alloc_pool::executed` marks them. **Tested** - Hardware: AMD Radeon RX 9070 XT (driver `32.0.32029.2010`), 24-thread x86_64 CPU, 32 GB RAM, Windows; `rustc 1.100.0 (0ef1bc386 2026-11-09)`; debug (tests) and release (`xcl.exe`). - `cargo test -p xcl --lib hle::d3d12x::alloc_pool::tests -- --test-threads=1`: 9 passed, 0 failed (`0.11s`, including `stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets`, `reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure`, and `reset_list_waits_while_backing_is_resetting`). - `cargo test -p xcl --lib hle::d3d12x::bind::tests -- --test-threads=1`: 8 passed, 0 failed (`0.38s`). - `cargo test -p xcl --lib hle::d3d12x::title_list::tests -- --test-threads=1`: 3 passed, 0 failed (`0.01s`). - Also live-tested in 180s 3D workload on `amd-dev` (`b5c0275f`): previously `coherent` UMA exhausted `4095/4095 MB` (`547 blocks held for 236 allocators` at `63.7k draws / 34.6k dispatches`), triggering `unified memory is full` and `0x887a0006`; with this fix held blocks dropped by >72% (`152 blocks / 75 allocators`, `4046/4095 MB` at `65.5k draws / 47.0k dispatches`) with `0` `unified memory is full` warnings. **Regression run** ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: AMD Radeon RX 9070 XT title: b8db18c2 seconds: 60 exit: 0x0 frames shown: 1624 (PresentX 1624) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19700 MB ``` ``` xcl-smoke v1 commit: dff6edc7e64c818a29fe20946911b8c0e5578387 gpu: AMD Radeon RX 9070 XT title: b8db18c2 seconds: 60 exit: 0x0 frames shown: 1669 (PresentX 1669) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19209 MB ``` **Not tested** - NVIDIA and Intel GPU adapters (tested on AMD Radeon RX 9070 XT only). - Full `cargo test --workspace` was run on the same base `b49be183` in #2703 (`1434` passed; pre-existing RDNA 4 `fuzz_validate_and_gpu_1/3` failures). **AI use** - Antigravity (Google Gemini): assisted with analyzing the coherent UMA allocator-block leak, keying pending UMA blocks by native allocator backing, adding the `resetting`/`Condvar` concurrency guard, writing unit tests, and running local tests and smoke verification. All diffs and measurements were reviewed and verified locally on hardware.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 07:52:39 +00:00
Author
Owner

@⁠fromthemoonx on GitHub · 2026-11-26 08:14 UTC · original

NVIDIA run (listed under Not tested): passes. Both new tests are stable, list_x fails no differently than on main in parallel, and the e2e title's D3D12 debug-layer messages are the same as main's.

Tested: 7879954 merged onto main b49be18 (clean). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, Graphics Tools (D3D12 debug layer) installed.

result
cargo test --workspace --no-fail-fast -- --test-threads=4 1437 passed, 0 failed, 47 ignored; 25 SKIPPED lines
retired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight, clean_title_reset_reclaims_idle_aside_backings_once, alone, 40 runs each 40 of 40 each
hle::d3d12x::alloc_pool:: + title_list:: + real::dispatch_chain:: (11 tests), --test-threads=8, 30 runs 30 of 30
hle::d3d12x::list_x::tests::, --test-threads=4, 100 runs 7 failed runs, only in a_dispatch_with_a_pipeline_still_building_waits_at_the_submit (7×) and rotating_queue_self_deadlock_… (3×), the two that flake on main the same way (#2118, #2547)
e2e test_title_draws_with_a_root_signature_under_the_debug_layer, merged vs main the same: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit

Not tested: a title run, Intel, a release build.

AI use: Claude Code (Claude Opus 5.5) ran the suite, the repeats and the debug-layer comparison, and wrote this report.

**@⁠fromthemoonx** on GitHub · 2026-11-26 08:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2707#issuecomment-7186365972) **NVIDIA run (listed under Not tested): passes. Both new tests are stable, `list_x` fails no differently than on `main` in parallel, and the e2e title's D3D12 debug-layer messages are the same as `main`'s.** **Tested:** `7879954` merged onto `main` `b49be18` (clean). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, Graphics Tools (D3D12 debug layer) installed. | | result | |---|---| | `cargo test --workspace --no-fail-fast -- --test-threads=4` | 1437 passed, 0 failed, 47 ignored; 25 `SKIPPED` lines | | `retired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight`, `clean_title_reset_reclaims_idle_aside_backings_once`, alone, 40 runs each | 40 of 40 each | | `hle::d3d12x::alloc_pool::` + `title_list::` + `real::dispatch_chain::` (11 tests), `--test-threads=8`, 30 runs | 30 of 30 | | `hle::d3d12x::list_x::tests::`, `--test-threads=4`, 100 runs | 7 failed runs, only in `a_dispatch_with_a_pipeline_still_building_waits_at_the_submit` (7×) and `rotating_queue_self_deadlock_…` (3×), the two that flake on `main` the same way (#2118, #2547) | | `e2e` `test_title_draws_with_a_root_signature_under_the_debug_layer`, merged vs `main` | the same: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit | **Not tested:** a title run, Intel, a release build. **AI use:** Claude Code (Claude Opus 5.5) ran the suite, the repeats and the debug-layer comparison, and wrote this report.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 08:18 UTC · original · reviewed

At head 7879954925faaa048293f28857febf9eb8aa503b, the new bind::reset(primary, 0, 0) runs precisely when title_list::reset selects a stand-in because the primary PC list is still in flight (title_list.rs:157-201). bind::reset moves that primary recording's UMA blocks to console_list::PENDING under its old logical title allocator (bind.rs:75-87). A subsequent successful title-allocator Reset can swap to a different native backing while the old primary is still in flight, but real::alloc_reset unconditionally calls console_list::allocator_reset(this) on success (real.rs:7047-7057), which frees all pending blocks under that logical allocator. The GPU can therefore still read blocks freed by the new stand-in path. Before this PR, the stand-in branch did not transfer the primary's bind blocks at that point. Could those blocks stay owned by the old primary/native backing until its fence completes, with the pending-key/reset path tracking that backing rather than the logical allocator? A regression with a GPU-stalled primary, stand-in list reset, and title-allocator reset would distinguish the two lifetimes.

This is an exact-head source review; I did not run a GPU-stalled title reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) traced the interleaving; I checked the bind, pool, and allocator-reset paths before posting.

**@⁠luckyteagirl** on GitHub · 2026-11-26 08:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2707#pullrequestreview-6070577990) · **reviewed** At head `7879954925faaa048293f28857febf9eb8aa503b`, the new `bind::reset(primary, 0, 0)` runs precisely when `title_list::reset` selects a stand-in because the primary PC list is still in flight (`title_list.rs:157-201`). `bind::reset` moves that primary recording's UMA blocks to `console_list::PENDING` under its old logical title allocator (`bind.rs:75-87`). A subsequent successful title-allocator `Reset` can swap to a different native backing while the old primary is still in flight, but `real::alloc_reset` unconditionally calls `console_list::allocator_reset(this)` on success (`real.rs:7047-7057`), which frees all pending blocks under that logical allocator. The GPU can therefore still read blocks freed by the new stand-in path. Before this PR, the stand-in branch did not transfer the primary's bind blocks at that point. Could those blocks stay owned by the old primary/native backing until its fence completes, with the pending-key/reset path tracking that backing rather than the logical allocator? A regression with a GPU-stalled primary, stand-in list reset, and title-allocator reset would distinguish the two lifetimes. This is an exact-head source review; I did not run a GPU-stalled title reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) traced the interleaving; I checked the bind, pool, and allocator-reset paths before posting.
Author
Owner

@⁠sage-sage on GitHub · 2026-11-26 08:48 UTC · original

Test report: passes on NVIDIA. Exact head 78799549 (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1437 passed, 0 failed, 47 ignored; the 2 new tests pass
  • SKIPPED: 29 lines, the same as on main on this machine (wave64, debug layer, Developer Mode, heap windows)

Not tested

  • No game, so not split segments and allocator reuse on a title.

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

**@⁠sage-sage** on GitHub · 2026-11-26 08:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/2707#issuecomment-7187050769) **Test report: passes on NVIDIA.** Exact head `78799549` (its base is current `main` `b49be18`, so head = merged). **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build - `cargo test --workspace -- --test-threads=4`: 1437 passed, 0 failed, 47 ignored; the 2 new tests pass - SKIPPED: 29 lines, the same as on `main` on this machine (wave64, debug layer, Developer Mode, heap windows) **Not tested** - No game, so not split segments and allocator reuse on a title. Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Author
Owner

@⁠Saksukella on GitHub · 2026-11-26 08:55 UTC · original

Good catch @⁠luckyteagirl — fixed in f796b9e6. bind::State.allocator (and thus console_list::PENDING) is now keyed by the native PC allocator backing (alloc_pool::recording_backing / alloc_pool::current) rather than the logical title allocator, and console_list::allocator_reset now runs inside real::reset_pc_allocator (and for free backings in alloc_pool::forget) rather than unconditionally on alloc_reset(this). Added the regression test stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets covering a GPU-stalled primary, stand-in reset, title-allocator swap reset, and post-fence reclaim. Re-ran alloc_pool (7/7), bind (8/8), title_list (3/3), and a 60s RX 9070 XT smoke run (1669 frames, 0 removals, 0 crashes).

**@⁠Saksukella** on GitHub · 2026-11-26 08:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/2707#issuecomment-7187190797) Good catch @⁠luckyteagirl — fixed in `f796b9e6`. `bind::State.allocator` (and thus `console_list::PENDING`) is now keyed by the native PC allocator backing (`alloc_pool::recording_backing` / `alloc_pool::current`) rather than the logical title allocator, and `console_list::allocator_reset` now runs inside `real::reset_pc_allocator` (and for free backings in `alloc_pool::forget`) rather than unconditionally on `alloc_reset(this)`. Added the regression test `stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets` covering a GPU-stalled primary, stand-in reset, title-allocator swap reset, and post-fence reclaim. Re-ran `alloc_pool` (7/7), `bind` (8/8), `title_list` (3/3), and a 60s RX 9070 XT smoke run (1669 frames, 0 removals, 0 crashes).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2707/head:github-bot/gh-2707'
git switch 'github-bot/gh-2707'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2707'
git switch 'github-bot/gh-2707'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2707'
git switch 'github-bot/gh-2707'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2707'
git switch 'main'
git merge --squash 'github-bot/gh-2707'
git switch 'main'
git merge --ff-only 'github-bot/gh-2707'
git switch 'main'
git merge 'github-bot/gh-2707'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.