Tests: stop leaking imported heap resource references #1510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1520"
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?
Imported from ivall/xcl. Originally posted by wileyGray on 2026-11-24T17:12:01Z.
Part of #1487. Four transition barriers in the imported-heap GPU test cloned a resource into
ManuallyDropand never released it. The test then freed the backing allocation with four resource references outstanding. This fixes that specific lifetime bug, also identified in the #175 investigation; it does not establish the cause of every intermittent access violation in #1487.What is in it
crates/xcl/src/hle/d3d12x/list_x.rs: borrow the resource in the four test barriers while its owner remains alive through the existing fence waits, checkVirtualFree, and add a CPU-only reference-count regression. All 75 changed lines are inside#[cfg(test)] mod tests.Tested
6159773d93e826b4c328ad7174334c7a12c75541, based on mainb7aa9f3; Windows 11 Home build 26300, i9-14900K, RTX 4080 SUPER, driver 32.0.16.2114, Rust 1.93.0, DXC 1.9.2609.5, debug,XCL_ADAPTER=NVIDIA. AllXCL_SAMPLE_*unset.scripts/test.ps1(workspace build and tests with four threads): 771 passed, 0 failed, 41 ignored. Includes four GPU/debug skips (two native-wave64 tests, two missing-debug-layer tests) and 33 sample-gated early returns; these are not executed coverage. Synthetic console-title e2e passed.(5, 4)after four barriers / dropping the owner, versus expected(1, 0). With the fix: 1 passed, 0 failed. Reproduce:cargo test -p xcl --lib imported_heap_test_barriers_do_not_retain_the_resource -- --nocapture.real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_statewith two threads: 20 passed, 0 failed, 0 skipped, no access violations or stalls (0.27-0.36 seconds per pair).git diff --checkpassed.Paired-test reproduction and exact GPU/debug skips
Build with
cargo test -p xcl --lib --no-run. Run the emitted library test executable ten times, one process at a time, with these arguments (each run must report exactly two passes and no skips):Full-suite GPU/debug skips:
gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no native wave64);uploads_start_from_each_subresources_stateandtest_title_draws_with_a_root_signature_under_the_debug_layer(debug layer unavailable).Regression run
test-onlylabel under CONTRIBUTING.md. The path-based description check otherwise requests retail smoke blocks. No runtime behavior changes.Not tested
AI use
Imported from ivall/xcl. Originally posted by GonZiin on 2026-11-24T17:52:33Z.
Review: COMMENTED
Independent full-suite run on AMD RDNA4. Both the reference-count regression and the imported-heap GPU test passed. I checked the diff and all changed Rust lines are inside the test module.
Tested
6159773d93e826b4c328ad7174334c7a12c75541, clean checkout. Windows 11 Pro build 26300, Ryzen 7 7800X3D, Radeon RX 9070 XT (driver 32.0.32029.2010), Rust 1.100.0 MSVC, DXC 1.8.2502.11, debug..\scripts\test.ps1exited 0. Workspace totals were 771 passed, 0 failed, 41 ignored and 0 reported GPU skips. The bundled title end-to-end test passed.list_x.rs. A maintainer can apply the documentedtest-onlylabel after checking this revision.Not tested
Retail smoke and the opt-in sample data tests.
AI use
Codex (
gpt-6.2-sol) inspected the diff, ran the Windows tests, and wrote this review.Imported from ivall/xcl. Originally posted by Bullet18x on 2026-11-24T18:25:13Z.
Test report for head
6159773, with one finding about the newVirtualFreeassert.Tested
XCL_SAMPLE_*unset.imported_heap_test_barriers_do_not_retain_the_resourcepasses. The barriers no longer keep the resource alive.cargo test -p xcl --lib -- --test-threads=32, 10 runs on6159773:write_buffer_immediate_on_open_existing_heap_visible_to_cpufailed or was among the failures in 4 runs. In 1 of those 4 it was the only failure, on the newassert_ne!(VirtualFree(mem, 0, MEM_RELEASE), 0)(left: 0, right: 0). The other 3 also had an access violation (#1523's cause).9e3831e+ #1520 + #1523 + #1590, 25 runs at 32/16 threads: this assert failed 4 times, and nothing else in this test failed.Cause (same as #1590)
D3D12CreateDevicereturns the process's one device. Once another test has adopted it,bufis adopted too, and its lastReleasegoes tolate_release::hold. While another test's queue still has work, the resource is held and the imported heap keepsmempinned. So the firstVirtualFreefails with 87, even with the leak fixed.Check
On the combined branch, I let this test retry
VirtualFreefor up to 10 s, the same as #1590 does forcoherent_buffer_sanitizes_console_flags_and_state, and ran it 20 more times at 32 threads. The test failed 0 times. The firstVirtualFreefailed in 4 runs, and the retry freed the memory each time, after 5 to 27 ms.Suggestion
Keep the assert, but wait for the held release first:
Not tested
AI use: Claude Code with Claude Opus 5.5 ran the tests, found the cause and wrote this report. I checked each point.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:54:00Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by crastinator on 2026-11-24T19:20:15Z.
Review: COMMENTED
Tested on RDNA2 under Wine (RADV). This also fixes the parallel device removal I traced in #1246: the
VirtualFreeof this test's imported memory while another test's GPU work ran on the shared device.Tested (head
6159773, merged ontomainc160d86: no conflicts)-Db_ndebug=true, dxil-spirv53aac418), DXVK v3.1.1-209dxgi, DXC 1.9.2609.5. Cross-built forx86_64-pc-windows-msvc, Rust 1.99.1, debug.--test-threads=2 --exact gpu::recomp::tests::jumps_to_outer_loop_heads_are_structured hle::d3d12x::list_x::tests::write_buffer_immediate_on_open_existing_heap_visible_to_cpu:mainfails 3/3 (kernel dispatch: D3D12 device removedafter ~0.15 s). With this PR it passes 3/3.cargo test -p xcl --lib -- --test-threads=4, 2 runs: 801 / 9 / 22 and 804 / 6 / 22 (passed / failed / ignored), no device removal. The 6 are the Wine-lane set: #530 ×2, #676, #890 ×2,gpu_depth_buffer_created_for_unordered_access_is_placed(#1475). Run 1 also had the #718 trio.mainin the same setup: 795 / 14 / 22, with 5 device-removed lines (the #1246 cascade throughsparse,title_texturesandvram).VirtualFreedidn't help there, because the fourManuallyDropbarrier clones still held the resource, so the imported heap never went away.Not tested
XCL_SAMPLE_*set.AI use
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:32:45Z.
Regression run of
6159773don the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 101 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T05:26:17Z.
Empirical test report (
6159773d)Verified PR #1520 at
6159773d93e826b4c328ad7174334c7a12c75541.Hardware / environment
XCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1. The imported-heap fixture creates a device on the Windows default D3D12 adapter, with WARP as a fallback. It does not readXCL_ADAPTERor log the resulting device, so the adapter and driver used by that fixture were unverified.Commands and results
cargo test --workspace --no-runexited 0 outside the GPU lock.SKIPPEDlog lines.Observed behavior
VirtualFree(..., MEM_RELEASE)assertion also passed after the resource and heap were dropped.Not tested
The full GPU workspace suite and game smoke runs were omitted.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against
pr1520-focused.logand published.Imported from ivall/xcl. Originally posted by ivall on 2026-11-25T19:32:34Z.
The leak fix is right and worth having (it also explains the device removal of #1246). What holds it is the new
VirtualFreeassert: it fails at times because another test's work still holds the lastRelease(Bullet18x: 4 of 25 runs at 16 and 32 threads, 0 of 20 with a bounded retry). #1590 is merged and retries up to 10 s incoherent_buffer_sanitizes_console_flags_and_state; please do the same here. The diff is inside the test module, so thetest-onlylabel can be set after that push.AI use: Claude Code (Claude Opus 5.5) wrote this on the maintainer's behalf.
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-28T12:41:50Z.
Test report on Wine + AMD (the "Not tested" of the reports above): this test's leak is what makes RADV reject a command submission in the lib suite (#3067).
Tested
experimental-11.0-20261112, stock vkd3d-protonmaster71cae091; debug,x86_64-pc-windows-gnu.linux/stack8b7faec7(maine429936cplus the stack in #3067), once as is and once with this PR's diff tolist_x.rs(head6159773d) applied on top.cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- --test-threads=1 --exact hle::d3d12x::list_x::tests::write_buffer_immediate_on_open_existing_heap_visible_to_cpu hle::d3d12x::present::frame_dump_tests::compositor_blends_ui_plane_over_scene_plane:radv/amdgpu: The CS has been rejected … (-14);0x887a0005).I found it by bisecting the suite, and any later GPU test can be the one rejected (a
sparsetest when the compositor test is skipped). Without theVirtualFreethe rejection is gone, so freeing the imported memory while the resource is still held is what triggers it.imported_heap_test_barriers_do_not_retain_the_resourcepasses. The lib suite with--skip gpu::and the two OOM tests skipped (failed_restore_stops_before_importing_an_unbacked_window,grooming_leaves_a_window_under_1_gib_only_its_hole): no CS rejection at--test-threads=1or2(646 passed / 2 failed and 729 / 4). Both runs still end early at an access violation in vkd3d-proton'sExecuteCommandListsin atitle_texturestest. That is another issue (#3067), and that test crashes alone too (run without this PR, which does not touch it).Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and the bisection on my machine and wrote this; I checked each point.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-28T16:23:33Z.
Second hardware confirmation, on RDNA3 this time. rig1: RX 7900 XT 20 GB (Navi 31), Ryzen 9 9900X, 96 GB, Arch, Mesa 26.2.5 RADV, wine 11.0 (proton build),
--test-threads=2 --skip gpu::.Without #1520, both current heads crash the suite on rig1:
mainbb9a6b4b: exit 5, 577 ok,radv/amdgpu: The CS has been rejected (-14)thenD3D12 device removed: 0x887a0005, last ok areal::queue_tests::newer_layout...neighbor.linux/stack0e1e766c: exit 5, 305 ok, same-14rejection, drop site elsewhere (the site moves, matching ClosetPie107's poisoning explanation).With #1520 merged locally (
6159773d, merges applied clean at both heads:51f9d74aand159bc2b1), both complete:bb9a6b4b+ #1520: 1213 passed / 6 failed / 5 ignored in 15.6 s0e1e766c+ #1520: 1256 passed / 6 failed / 5 ignored in 15.8 sThe 6 reds, identical on both heads:
gpu_promoted_uav_clear_values_pass_create_committed_resource,a_dispatch_with_a_pipeline_still_building_waits_at_the_submit,a_put_off_call_whose_close_fails_is_not_submitted,an_older_process_cannot_remove_a_replacement_blob,grooming_leaves_a_window_under_1_gib_only_its_hole,xma2_source_voice_decodes_and_manages_lifetime. That is rig2's (GTX 1070) veteran set minuswrite_buffer_immediate_on_open_existing_heap_visible_to_cpu(fixed here by exactly this PR) and minusfailed_restore_stops_before_importing_an_unbacked_window(passed in this completed run; note it is still flaky solo on Wine - see my retraction row on #3067, child re-reserve race, not this PR's business).So #1520 kills the suite poison on RDNA3 and RDNA4 under Wine, and it is the only thing standing between rig1 lanes and a completed suite count. Please merge it; every AMD/Wine tester is eating a fake crash without it.
Tested: both suites above, at the merged shas named, rig1.
Not tested: native Windows, NVIDIA with this merge (rig2's crash history is different), the flaky solo.
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-29T02:15:26Z.
Patch suggestion for the
VirtualFreeassert, verified on Wine + RDNA3.Ivall's blocker ("fails at times because another test's work still holds the last
Release") is the exact mechanism documented in the #1590 line: one device per adapter, other tests adopt it, the lastReleaseof a placed resource waits for known queues, and until then the imported heap pins the pages,VirtualFreefailing withERROR_INVALID_PARAMETER. So the same bounded retryfree_importeduses. Applied on top of this PR merged intomainfa204595(merge4ca5da3b), replacing the assert:rig1 (RX 7900 XT, Mesa 26.2.5 RADV, wine 11.0 proton build),
--test-threads=2 --skip gpu:::imported_heap_test_barriers_do_not_retain_the_resource(this PR's new unit test): solo 3/3 green.write_buffer_immediate_on_open_existing_heap_visible_to_cpuwith the retry: solo 3/3 green, 0.09-0.10 s each.This also matches my flake data on Wine fixed-address (re)allocation over the same heap (#3067): when a release is racing, it is racing for a bounded time or never, and a retry with a timeout is the right shape on both sides.
Tested: the patch above on merge
4ca5da3bofmainfa204595+6159773d, rig1 only.Not tested: Windows, NVIDIA, Bullet18x's 25-run flake repro (0 failures seen in my 3 solo + 1 suite run either way).
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-11-30T02:51:23Z.
@wileyGray the
PR descriptioncheck is what keeps this out of the merge queue (#3041): because the diff touchescrates/xcl/src, it wants twoxcl-smokeblocks under Regression run (this head6159773d, and a commit ofmain). The change is inside a test module, so the other way CONTRIBUTING.md gives is a maintainer applying thetest-onlylabel. Could you add the blocks or ask for the label? It merges cleanly intomain(1c5acde4). The Linux branch in #3067 carries it: without it these four tests leave references that break later tests on RADV.AI use: Claude Code (Claude Fable 5.2) read the check's log and wrote this.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:59:42Z.
Triage (#1607) – head
6159773No open or merged PR makes the same change; main's write_buffer_immediate_on_open_existing_heap_visible_to_cpu still clones buf into ManuallyDrop in its four barriers. #1600, #1628 and #1671 are also part of #1487 but fix other flaky tests.
The new imported_heap_test_barriers_do_not_retain_the_resource test checks the test helper heap_test_barrier, not runtime code. The diff is test-only in a runtime file, so the smoke check needs the test-only label.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.