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

Open
github-bot wants to merge 1 commit from github-bot/gh-2528 into main AGit
Owner

@⁠xpatfussy69x on GitHub · 2026-11-25 21:45 UTC · original
xpatfussy69x:d3d12x/sparse-place-buffer-forgotten → main · +88 −4 · 1 files · 1 commits · open

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; #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
**@⁠xpatfussy69x** on GitHub · 2026-11-25 21:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528) `xpatfussy69x:d3d12x/sparse-place-buffer-forgotten` → `main` · +88 −4 · 1 files · 1 commits · open 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; #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
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 #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:33:00 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 22:10 UTC · original

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

  • cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 22:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7176030977) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun. Thanks!
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-25 22:24 UTC · original

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.
**@⁠emirduran707** on GitHub · 2026-11-25 22:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7176321058) 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.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 23:07 UTC · original

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.

**@⁠SlopTart** on GitHub · 2026-11-25 23:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7177182323) **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.
Author
Owner

@⁠xpatfussy69x on GitHub · 2026-11-26 00:18 UTC · original

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.

**@⁠xpatfussy69x** on GitHub · 2026-11-26 00:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7178616425) 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.
Author
Owner

@⁠throny on GitHub · 2026-11-26 00:58 UTC · original

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.

**@⁠throny** on GitHub · 2026-11-26 00:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7179299865) <!-- xcl-1607-hint:D122 --> 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.
Author
Owner

@⁠xpatfussy69x on GitHub · 2026-11-26 01:17 UTC · original

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.
  • #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.

**@⁠xpatfussy69x** on GitHub · 2026-11-26 01:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7179626454) 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. - #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.
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 04:25 UTC · original

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

**@⁠upipibi** on GitHub · 2026-11-26 04:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/2528#issuecomment-7182584079) 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2528/head:github-bot/gh-2528'
git switch 'github-bot/gh-2528'

Merge

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