D3D12.X: the sparse state is replaced outside its lock #443
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!443
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/443/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Kalmarv on GitHub · 2026-11-24 00:22 UTC · original
Kalmarv:fix/sparse-state-replace-outside-lock→main· +45 −1 · 2 files · 1 commits · merged 2026-11-24 03:38 UTCd3d12x::sparse::initinstalled its state with*STATE.lock().unwrap() = Some(s), so the state it replaced was dropped while the guard was held. A state that has been used holds the last references to buffers of its own: readback, staging and zeros, made lazily through the adopted device (sparse.rs830–896). Their release goes throughreal::res_release, which callssparse::forget_buffer, which locksSTATEagain. The thread waits for itself, and every later user of the sparse windows waits behind it. The old state is now taken out under the lock and dropped after it, as planned in the issue.Fixes #344
The windows get set up again when two first
real::init()calls overlap.real::initreturns early only onceDEVICEis set, andDEVICEis set afteropen_uma→sparse::init, so GPU tests that start together can both get there. That is how the hang in the issue came about: the issue's suite run stopped in four GPU tests until it was killed. One correction to the issue: what matters is not placed buffers in general but the state's own last-referenced buffers, which is why the test reads back a block before setting the windows up again.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs,sparse::init:STATE.lock().unwrap().replace(s), and the old state is dropped after the guard.crates/xcl/tests/sparse_reinit.rs,the_sparse_state_is_replaced_outside_its_lock, in its own process:real::init(), then a 64 KiB sparse block, written and read back (readback_now), which gives the state its readback buffer;sparse::initagain with the same device, on a second thread. The test waits 60 s for it, so on main it fails instead of hanging the suite;real::init()(real::uma_gpu_va() == 0, as on WARP and the no-GPU CI runner), it skips (no GPU UMA), aspredication_e2e.rsdoes.Tested
cargo test --workspace -- --test-threads=4ond96812a(this PR, on maina6f5f7a): 677 passed, 0 failed, 41 ignored (thexcllibrary: 636 passed, 21 ignored). SKIPPED GPU tests: 2, bothno wave64(gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware).d96812a, 3 runs each:sparse.rsas on maina6f5f7a: 3 of 3 failed withsparse::init did not return within 60 s;XCL_ADAPTER=warp: the first set-up opens no sparse window (CreateReservedResource:E_OUTOFMEMORY), and the test printsSKIPPED the_sparse_state_is_replaced_outside_its_lock: no GPU UMAand passes, with this change and with main'ssparse.rs. At16fc79dit failed there atsparse_reinit.rs:33in 0.13 s, as on the CI runner.16fc79d.scripts/test.ps1: 677 passed, 0 failed, 41 ignored, no SKIPPED GPU tests. Withsparse.rsfrommainand the new test kept, the test fails after 60.33 s (1 run).16fc79dmerged ontomain2997c9a.cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored; SKIPPED only the 2no wave64tests.16fc79dmerged ontomain2997c9a.cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored;sparse_reinit3 of 3 pass, and fails after 60 s withinitas onmain. Without this PR their suite stopped in the #344 hang in 8 runs; their thread stacks show the chain above.16fc79d.cargo test --workspace --no-fail-fast -- --test-threads=4: 677 passed, 0 failed, 41 ignored; SKIPPED the 2no wave64tests and 2no D3D12 debug layertests;sparse_reinitpasses 3 of 3.scripts/smoke.ps1 -Seconds 90,main508a0c7againstd96812a, each run twice and the second run kept: 2361 and 2342 frames, peak commit 15674 and 15698 MB, no device removal or crash in any run.d96812amerged ontomain508a0c7, on a machine that hits #344 often.cargo test -p xcl --lib -- --test-threads=4, 180 s limit a run:mainhung in 1 of 5 runs,mainwith #541 in 4 of 7, and this PR finished all 10 (640 passed, 0 failed, 21 ignored each). Every hang stopped at the same four tests as the stacks above.Regression run
Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes.
main:
PR:
Not tested
sparse::inittwice: not throughreal::init, which outside tests onlybackend()'s one-time initializer calls (checked on2997c9a); other routes are not checked. The smoke runs above are a regression check only.real::init()calls that really overlap. The test callssparse::inita second time directly, with the device it already has.sparse::initand keeps the drop under the guard (*state = Some(s)whilestateis the guard), so whichever merges second needs a rebase.AI use
🤖 Generated with Claude Code
@MesshM on GitHub · 2026-11-24 00:39 UTC · original
Test run of
16fc79d51385e52aaa9e14749bb23e8914ce7fb4on AMD (RDNA4); the PR was tested on NVIDIA only.Tested
backend 'real' – AMD Radeon RX 9060 XT (16191 MiB VRAM))stable-x86_64-pc-windows-msvc, debug.\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 677 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 636 passed, 0 failed, 21 ignoredSKIPPEDon this adapter, so the two wave64 tests skipped on the RTX 5070 Ti ran and passed herethe_sparse_state_is_replaced_outside_its_lockpasses in the suite (sparse_reinit: 2 passed, 0.17 s)sparse.rsfrommaina6f5f7aand the new test kept,cargo test -p xcl --test sparse_reinit: 0 passed, 1 failed after 60.33 s (sparse::init did not return within 60 s: it waits for the lock it holds: Timeout), as the description says (1 run)Review of the change: in
let old = STATE.lock().unwrap().replace(s);the guard is a temporary of theletstatement, so it is dropped at the end of that statement anddrop(old)runs without the lock;forget_buffercan then take it. The caller (real.rs:348, inopen_uma) holds no other lock aroundsparse::init. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the failing run onmainwas done once, not three times.Run and report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@PHeitor1 on GitHub · 2026-11-24 00:44 UTC · original
Tested
16fc79dmerged ontomain2997c9a.RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed, so the debug-layer tests run), rustc 1.100.0 MSVC, debug,
cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*.Pass: 677 passed, 0 failed, 41 ignored. SKIPPED: only the 2
no wave64tests (gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware). Build clean.Run and written with Claude Code (Claude Opus 5.5).
@throny on GitHub · 2026-11-24 01:16 UTC · original
Test report for
16fc79dmerged ontomain2997c9a(clean merge, merge commit3216209): pass, the new test fails without the fix, and this machine hits the #344 hang in the plain suite often enough to add an independent stack capture.Tested
stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); noXCL_SAMPLE_*cargo build --workspace && cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored (lib: 636 / 0 / 21;sparse_reinit: 1 / 0 / 0)SKIPPEDon this adapter:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)cargo test -p xcl --test sparse_reinit: 3 of 3 runs pass (0.4 s each).initback to*STATE.lock().unwrap() = Some(s);, the same command fails after 60 s (sparse::init did not return within 60 s: it waits for the lock it holds).The hang without this PR, on this machine
cargo test --workspace -- --test-threads=4on trees without the fix stopped in the lib tests in 8 of the suite runs I made tonight (bases2b4bb43,a6f5f7a,2997c9a,7ebf1b8, each with one unrelated open PR merged), always after ~194 tests, withgpu_uma_import_check_at_initand three other GPU tests reported as running for over 60 seconds until I killed the process. Other runs of the same trees passed, so it depends on test order and timing.a6f5f7a+ #350, taken with cdb):gpu_uma_import_check_at_init:real::init→real::open_uma→sparse::init→real::res_release→sparse::forget_buffer(waiting on the lock) – the chain the description gives;gpu_wave32_and_wave64_src_vccz_execz:runner::run_with_statics→real::res_release→sparse::forget_buffer(waiting);gpu_typed_buffer_loads_and_stores,gpu_valu_16_and_64_bit: waiting inrunner::run_with_statics.main+ #349) ran through: 679 passed, 0 failed, 41 ignored (one run).Reviewed (read the whole diff)
replacereturns the old state out of the guard's statement, so it is dropped after the lock is released; nothing else ininitchanges. #461 makes the same change with a unit test of a stand-in type; this PR's test goes throughreal::initand the real release path.Not tested
scripts/smoke.ps1) on a title, AMD and wave64 hardware, release build.AI use
@QemmHD on GitHub · 2026-11-24 01:18 UTC · original
Two points not covered above:
tests/sparse_reinit.rs:15/33– on the WARP CI runnerCreateReservedResourcefails (E_OUTOFMEMORY) in both inits, so the second init opens 0 windows and line 33 panics instead of reaching the deadlock.crates/xcl/tests/predication_e2e.rs:177already skips this case (if real::uma_gpu_va() == 0 { runner::skip_test("no GPU UMA"); return; }); the same guard after the first init here should turn the required check green.real::inithaving no once-guard (real.rs:456-538), so overlapping first calls runsparse::inittwice. The secondStatestarts with an emptymappedtable andEARLYis already drained, so blocks committed before it get no tiles in the new windows. Worth a separate issue to serialisereal::init?On an RTX 4070 SUPER (621.24) this tree passed 4 of 4 plain suite runs (677 / 0 / 41), while trees without it hung in the #344 chain in 6 of 11 runs, matching throny's stacks.
AI-assisted review (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.
@Kalmarv on GitHub · 2026-11-24 02:02 UTC · original
Thanks, @QemmHD. Point 1 was right, and it's fixed in
d96812a(squashed into the PR's commit).real::init()with the guardpredication_e2e.rsuses (if real::uma_gpu_va() == 0 { skip_test("no GPU UMA") }). The 60 s check on the second set-up is unchanged.XCL_ADAPTER=warphere, the test before this change panicked at line 33 in 0.13 s, as on CI. It now printsSKIPPED … no GPU UMAand passes, also withmain'ssparse.rs.main'ssparse.rsit still fails 3 of 3 after 60 s.real::init()is only reached throughd3d12x::backend(), which is aOnceLock. Onlygpu_uma_import_check_at_init,gpu_sparse_vram_descriptors_buffers_and_xmemand this test call it directly, so the double set-up is a test-only race (PHeitor1 found the same on #343).🤖 Claude Opus 5.5
@13hourstilliland on GitHub · 2026-11-24 01:52 UTC · original · edited 2026-11-24 02:06 UTC
Ampere 8 GB (RTX 3070, driver 610.88) targeted and full workspace run on exact PR head
d96812a(updated from earlier16fc79drun, which also passed with the same counts).Tested
d96812a91dc968bb9db8707d41339b09931087d6(PR #443 head), clean worktreestable-x86_64-pc-windows-gnu, not MSVC); DXC 1.9.2609.5 (01b62ad4) viaXCL_DXC_DIR; debug build; noXCL_SAMPLE_*setcargo test -p xcl --test sparse_reinit -- --show-outputthe_sparse_state_is_replaced_outside_its_lock, 0.46 s / 0.45 s / 0.42 s, no skip)cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output(interactive desktop session)xcllib: 636 passed, 0 failed, 21 ignored;sparse_reinit: 1/0;e2e: 3/0)SKIPPED(4, not coverage):no wave64(2):gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardwareno D3D12 debug layer(2):test_title_draws_with_a_root_signature_under_the_debug_layer,uploads_start_from_each_subresources_stateNot tested
scripts/smoke.ps1regression run, negative control without thesparse.rsfix, AMD / wave64 hardware, MSVC toolchain, release build, D3D12 debug-layer testsAI use
gemini-4-neon: ran the commands and wrote this report from the logs; the human reviewed it.@srcamarda on GitHub · 2026-11-24 02:16 UTC · original
Regression run on a retail title, as asked under Regression run.
Tested
scripts/smoke.ps1 -Seconds 90, no input (the title stays on its account screen at 30 fps). Each binary was built from a clean checkout of its commit and run twice; the first run of each has a cold translation cache. Blocks below are from the second run.main508a0c7: 2343 / 2361 frames, peak 15764 / 15674 MB. This PR (d96812a): 2318 / 2342 frames, peak 15787 / 15698 MB. No crash or device removal in any run.mainbeyond run-to-run spread.Regression run
main:this PR's head:
Not tested
sparse::initran once; the replace-while-locked case is not reached here (as your Not tested says).AI use
@futurepro62 on GitHub · 2026-11-24 02:25 UTC · original
Repeated runs on a machine that hits the #344 hang often, since the check above that the fix removes it was one suite run.
Tested
d96812amerged ontomain508a0c7(clean merge). NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.XCL_REQUIRE_GPU=mesh cargo test -p xcl --lib -- --test-threads=4, 180 s limit per run:main508a0c7main+ #541 (does not touchsparse.rs)main+ this PREvery hang without the fix stopped at the same four tests reported as running for over 60 seconds, with the process idle:
gpu_uma_import_check_at_init,gpu_typed_buffer_loads_and_stores,gpu_valu_16_and_64_bit,gpu_valu_float_and_int. Those are the tests in the stacks above. With this PR, all 10 runs finished: 640 passed, 0 failed, 21 ignored.cargo test -p xcl --test sparse_reinit: 1 passed.Not tested
sparse_reinit); no stack dump of my own hangs;scripts/smoke.ps1(no title on this machine); AMD, wave64 hardware.AI use
@shdann on GitHub · 2026-11-24 00:47 UTC · original · reviewed
crates/xcl/tests/sparse_reinit.rs:33assumes that the second initialization creates at least one window. On16fc79d, the Windows CI worker completed the call within the timeout and returned zero windows. The test then failed at this assertion. Please check that the adapter can create the second set of windows before using this integration test as the deadlock check. A separate test with a destructor that takes the same lock can cover the lock order on every worker. Failed CI job. Reviewed the diff and CI log with OpenAI Codex (GPT-6).