Skip to content

D3D12.X: an idle allocator's pool state goes before its last Release - #3611

Open
ArtuArtaza wants to merge 1 commit into
xcl-dev:mainfrom
ArtuArtaza:fix/alloc-release-order
Open

ArtuArtaza wants to merge 1 commit into
xcl-dev:mainfrom
ArtuArtaza:fix/alloc-release-order

Conversation

@ArtuArtaza

Copy link
Copy Markdown

alloc_release (real.rs) removed what XCL keeps by a command allocator's address after the Release that frees the object. In between, the driver can give that address to an allocator another thread creates, and the cleanup then ran on the new one: alloc_pool::forget took its type and stand-ins, and marked one that already held a recording for release by the pool. For an allocator nothing uses, the cleanup now runs before the last Release, while the hook still holds a reference.

Credit: @sage-sage proposed this order for heaps, queues and allocators in #2701 (closed). The allocator part is not on main; this is that part on today's code. A follow-up that releases idle allocators needs it, because a reused address becomes common there.

What is in it

  • crates/xcl/src/hle/d3d12x/alloc_pool.rs: release_with_probe takes before_last, called when the caller's reference was the last one and the pool does not keep the allocator; a unit test of the order.
  • crates/xcl/src/hle/d3d12x/real.rs: alloc_release passes its cleanup (dispatch chain, alloc_pool::forget, list_x::on_allocator_release) as before_last. An allocator the pool keeps for the GPU, and a Release that did not see the last reference, are cleaned up after it as before.

Tested

  • AMD Radeon RX 6700 XT 12 GB (driver 32.0.21045.29003), Ryzen 5 5600X, Windows 11 26200, rustc 1.100.0, debug
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 73a197a: 2900 passed, 6 failed, 51 ignored. The 6 are 5 tests (the two-pass cache e2e test runs itself as a child and prints two results). The same 5 fail on main 6bfb5c5 on this card (2899 passed, 6 failed, 51 ignored): gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form, f32_programs_on_the_gpu, gpu_f32_compares_with_nan, gpu_float_compares_random, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs. None is in the code this PR touches.
  • SKIPPED 4: no heap windows (2), no GPU_UPLOAD heaps (1), cannot disable the driver cache without Developer Mode (1).
  • cargo test -p xcl --lib alloc_pool -- --test-threads=4, 30 times: no run with a failure.
  • The bug itself, on main b2b1f10: a GPU test that creates allocators between the last Release and the cleanup, until one comes back at the freed address, failed 5 of 5 runs ("the title's new allocator would be released when its recording is done") and passed 5 of 5 with this order. It needs a hook inside alloc_release, so it is not in this PR; say if you want it added.

Regression run

main:

xcl-smoke v1
commit: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c
gpu: AMD Radeon RX 6700 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1505 (PresentX 1505)
presents per 2 s (last 3): 61 55 60
device removals: 0
crashes: 0
peak commit: 13154 MB

PR:

xcl-smoke v1
commit: 73a197aa1813b8b813e9bcd8a1fc786b8715ef14
gpu: AMD Radeon RX 6700 XT
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1477 (PresentX 1477)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 12339 MB

Not tested

AI use

  • Claude Code with Claude Fable 5.2 (earlier parts of the session ran as Claude Opus 5.5) found the problem while reading the pool for a memory change, and wrote the fix, the test and this description. It ran the tests and the game runs on my PC.

alloc_release dropped what XCL keeps by a command allocator's address
(the pool's namespace and type, the dispatch chain's and list_x's state)
after the Release that frees the object. In between, the driver can give
that address to an allocator another thread creates, and the cleanup then
ran on the new one: alloc_pool::forget took its type and stand-ins, and
marked one that already held a recording for release by the pool.

For an allocator nothing uses, the cleanup now runs while the hook still
holds its probe reference, before the Release that frees it. One the pool
keeps for the GPU, and a Release that did not see the last reference,
are cleaned up after it as before.

sage-sage's xcl-dev#2701 proposed this order for heaps, queues and allocators;
the allocator part is not on main.

Measured on main b2b1f10 (RX 6700 XT, driver 32.0.21045.29003) with a
GPU test that creates allocators between the Release and the cleanup
until one comes back at the freed address: it failed 5 of 5 runs there
and passed 5 of 5 with this order. That test needs a hook in
alloc_release and is not part of this commit.

Assisted-by: Claude Code (Claude Fable 5.2)
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@ArtuArtaza
ArtuArtaza marked this pull request as ready for review December 1, 2026 19:58
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 73a197a, diff read, not a merge-check):

  • The kept-for-the-GPU path can still run cleanup after the object is freed. When the pool keeps the allocator, end() runs after release_with_probe returns (real.rs ~11570). Inside end(), alloc_pool::forget can make the final Release itself: if the backing's GPU work finishes between retain_release_probe and forget, forget_in removes the backing and release_retained_allocator(owner) drops the pool's reference (alloc_pool.rs ~1291). list_x::on_allocator_release(this) then runs on a freed address (real.rs ~11560), so a list that was just Reset with a new allocator at that address loses its allocator. This window was there before the PR, but running dispatch_chain::allocator_reset and list_x::on_allocator_release before forget in end would close it too.

Fine: release_with_probe now calls before_last only when the caller held the last reference and the pool did not take the probe, so in the idle case the cleanup runs while the probe reference keeps the address alive; the existing probe tests pass closures that panic if before_last is called, and the new test checks the order of events.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 6bfb5c5
head: 73a197a
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none from this PR. The whole-suite run ended the lib binary with 0xc0000005 during eh::tests::thread_dumps_while_threads_run_and_exit (#3586, on main too). The counts are the lib binary run on its own (2757 passed, 0 failed, 31 ignored) plus the other binaries (148 passed, 0 failed, 20 ignored).
review: read the whole diff (2 files, +54 -5). No correctness problem found in what the PR changes.

  • release_with_probe now calls before_last only when the caller held the last reference and the pool did not take the probe. alloc_release passes its cleanup (dispatch_chain::allocator_reset, alloc_pool::forget, list_x::on_allocator_release) there, so for an idle allocator it runs while the probe reference keeps the address. Otherwise it still runs after the Release, as before.
  • an_idle_allocators_books_go_before_its_last_release plus the existing release_probe* tests: 3 of 3 runs passed.
  • Mutation: before_last called after the final release() (main's order) fails an_idle_allocators_books_go_before_its_last_release. Good.
  • hle::d3d12x::alloc_pool::tests:: at --test-threads=8, 30 runs: 21 of 30 ok on this merge, 22 of 30 on main 6bfb5c5. Both fail submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker (9 vs 8; listed in CI: tests that fail by timing or shared state keep unrelated PRs red (5 sightings on 28 Nov) #3180), and main once transferred_owner_is_released_once_outside_state_after_logical_forget. Not this PR.
  • Foniass's point about the kept-for-the-GPU path (end() after forget may have made the final Release) is outside this change and still open. I did not reproduce it.
  • No retail title on this machine.
    performance: none measurable: the same cleanup, run earlier on one path.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@ArtuArtaza

Copy link
Copy Markdown
Author

Thanks @fromthemoonx for the check and the mutation run.
@Foniass agreed: forget can make the final Release on the kept path, and on_allocator_release then runs on a freed address. It is on main too, so I'll fix it in a separate PR (both cleanups before forget) and keep this head unchanged.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Test report on head 73a197aa (as is, on main 6bfb5c51), Linux under Wine 11.21 Staging, x86_64-pc-windows-gnu, release, Rust 1.98.0, Ryzen 9 9950X3D. The GPU tests ran on Wine's CPU Vulkan (lavapipe), not on a card.

Tree cargo test -p xcl --lib -- alloc_pool d3d12x::real list_x
main 6bfb5c51 307 passed, 7 failed
this PR 73a197aa 308 passed, 7 failed (the new order test passes)
  • The 7 failures are the same tests on both trees (3 in list_x, 4 in real: put-off dispatches, descriptor-heap and driver-cache tests that fail under Wine without a card); none is in the code this PR touches. 5 tests SKIPPED.
  • alloc_pool alone, 10 runs: 10 of 10 passed.
  • This PR is merged into our Linux test tree, which runs the retail title on an RTX 4060 Ti (NVIDIA 615.71.09) through vkd3d-proton; nothing to report from a title run yet.

Not tested: a card (NVIDIA or other) for these tests, native Windows, the bug's own reproduction.

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

@Ignacus58

Copy link
Copy Markdown

Setup. Native Windows 11, RX 7900 XT 20 GB, Ryzen 5 7600, 32 GB RAM. XCL release builds, Series S / lockhart, DXC 1.9.2609.5. A = base 6bfb5c51, B = PR head 73a197aa. Each run used fresh XCL data and DXIL cache directories. The GPU driver cache was uncontrolled.

Startup smoke (60 s, no input). A–B–B–A passed 4/4 with clean timed exits, zero crashes and zero device removals. Each run ended at about 30 presents/s. An extra B smoke run also passed and was excluded from the ordered comparison.

Interactive New Game attempts (300 s limit, A–B–B–A).

Run Last sample with presents Outcome
1 A 154.3 s Presentation stalled until the scheduled 300 s exit (0x0).
2 B 104.3 s Crash at 108.8 s, 0xc0000005 in amdxc64.dll+0x7380f8 (read 0x0).
3 B 98.2 s Crash at 102.9 s, 0xc0000005 in amdxc64.dll+0x459aab (read 0x2f8).
4 A 100.2 s Crash at 187.3 s, 0xc0000005 in amdxc64.dll+0x7380f8 (read 0x0).
  • The tester reported a black screen during shader loading on the first A run and audible game audio during loading on the first B run. Playable control was not confirmed. No GPU device removals were logged in the interactive attempts.
  • B crashed in 2/2 attempts at two different offsets. A crashed in 1/2 attempts. The amdxc64.dll+0x7380f8 null read occurred on both builds.
  • Verdict. No startup regression observed. Interactive instability occurred on both builds. This sample leaves PR-specific causality unresolved. The allocator race and sustained gameplay were not verified.

AI use. 6.1 Sol (Codex) prepared the startup launchers and analyzed the initial smoke results. 6.2 Sol (Codex) prepared the interactive launcher, analyzed the follow-up logs, and compiled this report. The tester launched the runs and provided the input and observations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants