Skip to content

D3D12.X: a buffer released during a placement keeps the new one (#2457) - #2528

Open
xpatfussy69x wants to merge 1 commit into
xcl-dev:mainfrom
xpatfussy69x:d3d12x/sparse-place-buffer-forgotten
Open

xpatfussy69x wants to merge 1 commit into
xcl-dev:mainfrom
xpatfussy69x:d3d12x/sparse-place-buffer-forgotten

Conversation

@xpatfussy69x

Copy link
Copy Markdown

Part of #2457 (item 2 only; item 1 is claimed on the issue). place_buffer holds the sparse STATE across CreateReservedResource. A placed buffer whose last Release runs meanwhile cannot take STATE, so forget_buffer queues it in FORGOTTEN for the next lock_state. When the new reserved resource gets the released one's address, place_buffer recorded the new buffer under it, and the next lock_state let it go: its tiles were unpinned while the buffer was live on the GPU. The new buffer is now recorded by record_buffer, which lets the queued buffers go first (the issue's second fix direction).

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: record_buffer (pins the new buffer's tiles and records it, after forget_released); place_buffer uses it
  • crates/xcl/src/hle/d3d12x/sparse.rs: a_buffer_released_during_a_placement_does_not_take_the_new_one_with_it: an old buffer at an address is queued as released, a new one is recorded there, then lock_state's drain runs. Fails without the fix (the new buffer's entry is gone), passes with it. test_state() builds a State over a D3D12 device (WARP without a GPU) as a_pool_retired_a_moment_ago_is_taken_back does

Tested

  • NVIDIA GeForce RTX 3060 (driver 32.0.16.2124, 32-lane waves only), AMD Ryzen 5 7500F, Windows 11, Rust 1.100.0, debug build for the tests, release for the smoke runs
  • cargo test --workspace -- --test-threads=4: 1424 passed, 0 failed, 46 ignored
  • SKIPPED (25): 21 × no wave64; 1 × no heap windows; 3 × per-lane form refused V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 (on main too; Recompiler: the per-lane form takes f16 converts and products from #1426 #2182 removes them)
  • cargo test -p xcl --lib d3d12x::sparse: 18 passed, 0 failed, 1 ignored

Regression run

main:

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1130 (PresentX 1130)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14808 MB

PR:

xcl-smoke v1
commit: 237882e85be2919904333b6b084baee4cc4c4411
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1119 (PresentX 1119)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14807 MB

Not tested

  • The race itself in a title: the test drives the bookkeeping directly, and the smoke run does not show whether a release ever landed during a placement at the same address. A regression check only
  • AMD / native wave64

AI use

  • Claude Code, Claude Opus 5.5: wrote the fix, the test and this description, ran the tests and both smoke runs on the hardware above

…dev#2457)

place_buffer holds the sparse STATE across CreateReservedResource. A
placed buffer whose last Release runs meanwhile cannot take STATE, so
forget_buffer queues it in FORGOTTEN for the next lock_state. If the new
reserved resource gets the released one's address, place_buffer recorded
the new buffer under it and the next lock_state let it go: its tiles were
unpinned while the buffer was live on the GPU.

The new buffer is now recorded by record_buffer, which lets the queued
buffers go first. This is item 2 of xcl-dev#2457; item 1 (the fence quarantine
on unpin) is claimed on the issue and not in this change.

Test: the old buffer at an address is queued as released, a new one is
recorded there, then lock_state's drain runs. Without the fix the new
buffer's entry is gone; with it the entry and its pin stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 237882e85be2919904333b6b084baee4cc4c4411 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1422 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: hle::d3d12x::sparse::tests::a_buffer_released_during_a_placement_does_not_take_the_new_one_with_it.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 237882e85be2919904333b6b084baee4cc4c4411
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13969 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of a_buffer_released_during_a_placement_does_not_take_the_new_one_with_it: passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@xpatfussy69x

Copy link
Copy Markdown
Author

Heads-up for merge order: #2531 renames State::quarantined to retirement. This PR's test_state() builds a State with quarantined: VecDeque::new(). Git merges the two without a textual conflict, but the merged tree's tests do not build: error[E0560]: struct sparse::State has no field named quarantined (sparse.rs:1946, a local merge of 6d7f8b9 and 237882e, cargo test -p xcl --lib --no-run). Whichever lands second needs that one field renamed; I'll rebase this one if #2531 goes first.

AI use: Claude Code (Claude Opus 5.5) found this by building the merge.

@throny

throny commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2539 solves the same problem (for #2457) in a different way: #1607, group D122. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@xpatfussy69x

Copy link
Copy Markdown
Author

Thanks for the hint. #2539 and this PR fix the same item (2) of #2457 the two ways the issue suggests; this one was opened first (21:45 vs 22:12 UTC).

  • This PR (+88/−4) keeps STATE across CreateReservedResource and only lets the queued releases go (forget_released) before the new buffer is recorded – the smallest change that closes the race.
  • D3D12.X: create sparse placed buffers outside STATE and drain FORGOTTEN #2539 (+201/−16) also stops holding STATE across the driver call, which needs the window to be checked again afterwards and an abort path when it went away.

If not holding the lock across the driver call is wanted for its own sake, #2539 is the more complete fix and I'm happy to close this one in its favour; if the minimal fix is preferred, this one. I'll leave the choice to the maintainer and won't push either way.

AI use: Claude Code (Claude Opus 5.5) compared the two diffs; I checked the comparison.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

NVIDIA test report for 237882e: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4 (the hle::xaudio2 tests hang on this machine, on main too):
  • this PR, run 1: 1289 passed, 1 failed, 26 ignored; 25 SKIPPED lines (no wave64, two refused per-lane forms, the driver-cache measurement that needs Developer Mode). The failure is this PR's new test: hle::d3d12x::sparse::tests::a_buffer_released_during_a_placement_does_not_take_the_new_one_with_it panicked at sparse.rs:1838:9, "the old buffer's tile is still pinned".
  • this PR, run 2 (same command): 1290 passed, 0 failed, 26 ignored. So it is intermittent.
  • the new test alone, --test-threads=1 --nocapture, 3 runs: passes each time.
  • base 6d12f58, same command: 1289 passed, 0 failed, 26 ignored (it does not have the test).
  • Possible cause, from reading the code: the test pushes RES into the global FORGOTTEN and then drains it into its own state, but another test that calls lock_state() in parallel can take FORGOTTEN first, so the test's state never lets the old buffer go.

Lib tests only; no title run.

AI-assisted (Claude Code, Claude Opus 5.5).

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…#2528 + xcl-dev#2539)

(cherry picked from commit 95bc8198b89ff2c73a556cb370ab5055bbf821ec)
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.

6 participants