Skip to content

[upstream #910] Tests: free an imported heap's memory once its held Release has gone - #174

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/910
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/910

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

hle::d3d12x::real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state fails now and then in the whole suite at its last line (VirtualFree of the 64 KiB under its imported heap returns 0) and passes alone. It shows up in the test reports of xcl-dev#682, xcl-dev#607 and xcl-dev#708, in a comment on xcl-dev#718, and in xcl-dev#866's own description, whose held Release was meant to fix it. It still happened on main a1672ef, which has xcl-dev#866.

Cause: D3D12 has one device per adapter, and other tests in the lib adopt it (bind.rs, title_textures.rs, vram.rs). The test's placed resource is then XCL's, and its last Release goes through late_release (xcl-dev#866): it is held until every queue XCL knows of is past its work. Release itself waits 300 µs for that. With other tests' work in flight the resource goes a few ms later, from late_release's thread, and until then the imported heap pins the pages: VirtualFree fails with ERROR_INVALID_PARAMETER (87). Measured with a probe: on the adopted device, with a known queue waiting on an unsignalled fence, VirtualFree right after the drops returned 0 (error 87). Once the fence was signalled it succeeded 5.3 ms later. Without the blocked queue it succeeded at once.

Test-only: the diff is inside real.rs's #[cfg(test)] mod readback_routing_tests, so I'd ask for the test-only label. The runtime is unchanged, including late_release's 300 µs wait.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs (tests only): free_imported retries VirtualFree until the held release has gone (at most 10 s), and the coherent test frees its memory with it.
  • New test imported_heap_memory_frees_after_a_held_release. It sets up the case on purpose: the device adopted, a queue registered as known (present::note_execute) and waiting on a fence. It then asserts that the release is held (VirtualFree fails), lets the queue go, and asserts that free_imported frees the memory. With free_imported cut to a single attempt (the old cleanup), it failed 5 runs out of 5; as written, it passed 5 out of 5. The blocked queue is let go as soon as the hold is seen (and on unwind), so other tests' held releases wait less than a millisecond for it.

Tested

Not tested

  • No retail title and no smoke.ps1 run: test-only change (hence the label request).
  • AMD / Intel GPUs, Wine.

AI use

  • Claude Code (Claude Opus 5.5): found the cause, wrote the probe, the fix, the test and this description, and ran the tests on this machine.

🤖 Generated with Claude Code


Mirror of xcl-dev#910 (auto-synced, do not edit).

`coherent_buffer_sanitizes_console_flags_and_state` failed now and then in the whole suite
(`VirtualFree` returned 0 at its end) and passed alone. The device it makes is the one other
tests adopted: D3D12 has one device per adapter. On that device its placed resource is XCL's,
and since e7da8a1 (xcl-dev#866) a last `Release` is held until the queues XCL knows of are past their
work; `Release` waits 300 us for that. With other tests' work in flight the resource goes a few
ms later, and until then the imported heap pins the pages: `VirtualFree` fails with
ERROR_INVALID_PARAMETER.

The test now frees the memory with `free_imported`, which retries `VirtualFree` until the held
release has gone (10 s at most). `imported_heap_memory_frees_after_a_held_release` makes the
case on purpose: an adopted device, a known queue that waits on a fence, so the release is held
and `VirtualFree` fails; then the queue goes on and the memory is freed.

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

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#910 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/910 branch November 25, 2026 00:07
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.

2 participants