D3D12.X: a native host's last Release only queues the resource #2435

Open
Ahmet-Dedeler wants to merge 3 commits from upstream-pr/2445 into main
Ahmet-Dedeler commented 2026-11-25 19:08:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ahmet-Dedeler on 2026-11-25T19:08:55Z.


Stacked on #1789; only the top two commits belong here (D3D12.X: a resource's last Release forgets its address in one function and D3D12.X: a native host's last Release only queues the resource). The bottom one is #1789's commit, @vakaobr's, rebased onto current main (#1789's base predates a change to res_release that the second commit builds on). Part of #258.

Apple's D3DMetal calls Release on threads of its own (its queue thread at submit) and from inside calls XCL makes while XCL holds a lock of its own. When that is the title's last Release and late release keeps the object, res_release took the maps' locks, the sparse state's and the texture table's, and late_release::hold signalled the queues and waited. Whatever the host's thread waits for there, its queue waits for too. On a native host, such a Release now only writes the resource into a ring of atomics and returns. The late-release thread forgets what XCL keeps by the address and then lets the object go. This is the ring from mac7's fd1e593, which @vakaobr asked to see opened on main in #258 so his host-thread part can go on top. That part (no host Release at all on a host thread) is not in this PR.

The gate needs no other open PR. class_for already calls module_of on the table's first method. When that is 0 (the host's D3D12 is in no PE module), it sets NATIVE_HOST once and starts the late-release thread there, on the adopting thread. D3D12 on Windows and vkd3d-proton are PE modules. There the flag is never set, the ring stays empty (drain_known reads two atomics) and a Release does what it did.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: the body of res_release that forgets a released resource moves into forget_released, unchanged (first commit, no behaviour change).
  • crates/xcl/src/hle/d3d12x/real.rs: NATIVE_HOST, set in class_for from module_of(...) == 0. With it set, a kept last Release calls late_release::hand_over and returns 0. Tests only_a_table_in_no_pe_module_makes_a_native_host and a_kept_last_release_on_a_native_host_waits_for_no_lock.
  • crates/xcl/src/hle/d3d12x/late_release.rs:
    • Ring (16,384 slots; the indices only grow; a writer claims an index with one compare-exchange, only while it is less than N past the tail, so a claimed slot is always one the reader has emptied; one reader at a time, which empties a slot before it moves the tail).
    • hand_over (atomics only; with the ring full the reference is kept for good and counted, never the locking path).
    • drain_known takes the ring first: it forgets each resource, then holds it like any other.
    • start_thread is split out of hold.
    • Ring tests: in order, a full ring, 4 writers × 50,000 against 2 readers, and 300 writers let go by one barrier against a ring with 257 free slots (exactly 257 claimed, nothing in the ring overwritten).

Tested

  • MacBook Pro, Apple M5 Max (40-core GPU), 64 GB, macOS 27.3, CrossOver 26.3 (bottle with D3DMetal). Rust 1.100.0, x86_64-pc-windows-gnu (mingw-w64 GCC 16.2.0), debug, DXC 1.9.2609.
  • The repository's CI workflow (Windows runner, no GPU) on this head 6df8f64, run on my fork because it waits for approval here: Build and test passed.
  • cargo build --workspace --target x86_64-pc-windows-gnu at each of the two commits: builds, no new warnings (the same 3 as main).
  • Each test in its own process under Wine (<xcl lib test exe> --exact <test> --test-threads=1): passed:
    • the 6 late_release tests: the 4 new ring tests (on 6df8f64), plus a_held_resource_goes_when_the_queue_is_past_its_batch and without_queues_a_batch_goes_at_once;
    • the 2 new real::native_host_tests;
    • title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes;
    • sparse::tests::a_buffer_released_while_the_state_is_held_does_not_wait_for_it.
  • a_kept_last_release_on_a_native_host_waits_for_no_lock with the hand_over branch taken out of res_release fails: "the last Release waited for a lock another thread held: Timeout".
  • In this bottle the test device's tables are in d3d12.dll, so the gate test checked the PE-host side. The native path ran through the test's own switch (native_host_tests::FORCED, a thread-local read only after the flag).

Regression run

From this Mac, scripts/smoke.ps1 unchanged under PowerShell, with a wrapper as -Xcl that starts xcl.exe under Wine, both from the same copy of the caches. On this host main shows no frame (the title stops about 3 s in, before it creates its device), so neither run reaches a title's Release: this pair shows that the build starts and ends as main does.

main:

xcl-smoke v1
commit: 3ceb5507a05355719ff1d7b5c29bc52aff142000
gpu: AMD Compatibility Mode
title: 21222967
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 6df8f647253b3e2cb071543afce1248be3a4f08f
gpu: AMD Compatibility Mode
title: 21222967
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

(peak commit is 0 because Wine reports no commit charge.)

Not tested

  • Windows and the whole suite. On a PE host this only adds a flag that stays false and an empty ring.
  • A retail title with this branch on main, and the gate on a real D3DMetal table in a test. (In this bottle XCL's own device goes through d3d12.dll, a PE module, so the gate test saw that side. In earlier retail runs on this Mac the tables of resources, queues, lists and fences were at addresses in no module, PC vtable 0x21a6… in the log, which is what the gate keys on.) Without #1904, main does not get far on D3DMetal. On mac7, the loading runs I have predate this change.
  • Linux Wine.

AI use

  • Claude Code with Claude Opus 5.5 (port and tests), from code Claude Mythos 5.2 wrote for the Mac port.
<!-- greyfinch-sync:ivall/xcl:issue:5497483585 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445). Originally posted by [Ahmet-Dedeler](https://github.com/Ahmet-Dedeler) on 2026-11-25T19:08:55Z. --- Stacked on #1789; only the top two commits belong here (`D3D12.X: a resource's last Release forgets its address in one function` and `D3D12.X: a native host's last Release only queues the resource`). The bottom one is #1789's commit, @vakaobr's, rebased onto current `main` (#1789's base predates a change to `res_release` that the second commit builds on). Part of #258. Apple's D3DMetal calls `Release` on threads of its own (its queue thread at submit) and from inside calls XCL makes while XCL holds a lock of its own. When that is the title's last `Release` and late release keeps the object, `res_release` took the maps' locks, the sparse state's and the texture table's, and `late_release::hold` signalled the queues and waited. Whatever the host's thread waits for there, its queue waits for too. On a native host, such a `Release` now only writes the resource into a ring of atomics and returns. The late-release thread forgets what XCL keeps by the address and then lets the object go. This is the ring from `mac7`'s `fd1e593`, which @vakaobr asked to see opened on `main` in #258 so his host-thread part can go on top. That part (no host `Release` at all on a host thread) is not in this PR. The gate needs no other open PR. `class_for` already calls `module_of` on the table's first method. When that is 0 (the host's D3D12 is in no PE module), it sets `NATIVE_HOST` once and starts the late-release thread there, on the adopting thread. D3D12 on Windows and vkd3d-proton are PE modules. There the flag is never set, the ring stays empty (`drain_known` reads two atomics) and a `Release` does what it did. **What is in it** - `crates/xcl/src/hle/d3d12x/real.rs`: the body of `res_release` that forgets a released resource moves into `forget_released`, unchanged (first commit, no behaviour change). - `crates/xcl/src/hle/d3d12x/real.rs`: `NATIVE_HOST`, set in `class_for` from `module_of(...) == 0`. With it set, a kept last `Release` calls `late_release::hand_over` and returns 0. Tests `only_a_table_in_no_pe_module_makes_a_native_host` and `a_kept_last_release_on_a_native_host_waits_for_no_lock`. - `crates/xcl/src/hle/d3d12x/late_release.rs`: - `Ring` (16,384 slots; the indices only grow; a writer claims an index with one compare-exchange, only while it is less than N past the tail, so a claimed slot is always one the reader has emptied; one reader at a time, which empties a slot before it moves the tail). - `hand_over` (atomics only; with the ring full the reference is kept for good and counted, never the locking path). - `drain_known` takes the ring first: it forgets each resource, then holds it like any other. - `start_thread` is split out of `hold`. - Ring tests: in order, a full ring, 4 writers × 50,000 against 2 readers, and 300 writers let go by one barrier against a ring with 257 free slots (exactly 257 claimed, nothing in the ring overwritten). **Tested** - MacBook Pro, Apple M5 Max (40-core GPU), 64 GB, macOS 27.3, CrossOver 26.3 (bottle with D3DMetal). Rust 1.100.0, `x86_64-pc-windows-gnu` (mingw-w64 GCC 16.2.0), debug, DXC 1.9.2609. - The repository's `CI` workflow (Windows runner, no GPU) on this head `6df8f64`, run on my fork because it waits for approval here: [Build and test passed](https://github.com/Ahmet-Dedeler/xcl/actions/runs/45702967645). - `cargo build --workspace --target x86_64-pc-windows-gnu` at each of the two commits: builds, no new warnings (the same 3 as `main`). - Each test in its own process under Wine (`<xcl lib test exe> --exact <test> --test-threads=1`): passed: - the 6 `late_release` tests: the 4 new ring tests (on `6df8f64`), plus `a_held_resource_goes_when_the_queue_is_past_its_batch` and `without_queues_a_batch_goes_at_once`; - the 2 new `real::native_host_tests`; - `title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes`; - `sparse::tests::a_buffer_released_while_the_state_is_held_does_not_wait_for_it`. - `a_kept_last_release_on_a_native_host_waits_for_no_lock` with the `hand_over` branch taken out of `res_release` fails: "the last Release waited for a lock another thread held: Timeout". - In this bottle the test device's tables are in `d3d12.dll`, so the gate test checked the PE-host side. The native path ran through the test's own switch (`native_host_tests::FORCED`, a thread-local read only after the flag). **Regression run** From this Mac, `scripts/smoke.ps1` unchanged under PowerShell, with a wrapper as `-Xcl` that starts `xcl.exe` under Wine, both from the same copy of the caches. On this host `main` shows no frame (the title stops about 3 s in, before it creates its device), so neither run reaches a title's `Release`: this pair shows that the build starts and ends as `main` does. main: ``` xcl-smoke v1 commit: 3ceb5507a05355719ff1d7b5c29bc52aff142000 gpu: AMD Compatibility Mode title: 21222967 seconds: 60 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 0 MB ``` PR: ``` xcl-smoke v1 commit: 6df8f647253b3e2cb071543afce1248be3a4f08f gpu: AMD Compatibility Mode title: 21222967 seconds: 60 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 0 MB ``` (`peak commit` is 0 because Wine reports no commit charge.) **Not tested** - Windows and the whole suite. On a PE host this only adds a flag that stays false and an empty ring. - A retail title with this branch on `main`, and the gate on a real D3DMetal table in a test. (In this bottle XCL's own device goes through `d3d12.dll`, a PE module, so the gate test saw that side. In earlier retail runs on this Mac the tables of resources, queues, lists and fences were at addresses in no module, `PC vtable 0x21a6…` in the log, which is what the gate keys on.) Without #1904, `main` does not get far on D3DMetal. On `mac7`, the loading runs I have predate this change. - Linux Wine. **AI use** - Claude Code with Claude Opus 5.5 (port and tests), from code Claude Mythos 5.2 wrote for the Mac port.
SlopTart commented 2026-11-25 20:08:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T20:02:43Z.


gpu_ suite (cold cache): 160 passed / 4 failed, no crashes. The four are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, depth-buffer state refusal, and gpu_promoted_uav_clear_values_pass_create_committed_resource (report); none caused by this PR.

<!-- greyfinch-sync:ivall/xcl:comment:7173110038 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7173110038). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-25T20:02:43Z. --- `gpu_` suite (cold cache): 160 passed / 4 failed, no crashes. The four are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, depth-buffer state refusal, and `gpu_promoted_uav_clear_values_pass_create_committed_resource` ([report](https://github.com/xcl-dev/xcl/pull/2280#issuecomment-7172066690)); none caused by this PR.
bmjask commented 2026-11-25 20:18:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:18:40Z.

Review: COMMENTED


P1: Ring::push has a concurrent reservation race. late_release.rs:172-179 checks head-tail and then separately fetch_adds tail; RING_WRITERS=256 reserves space only under a bounded simultaneous-writer assumption, but no such bound is enforced. For example with N=512 and used=255, 258 writers can all observe occupancy below N-256 before incrementing; the last claim reaches tail+N and writes slots[tail % N] before the reader consumes it, overwriting a pending resource. That loses its pointer/reference and leaves its XCL address state unforgotten. The new 4-writer stress test cannot cover this. Please use CAS reservation/a bounded MPMC queue or enforce the writer bound, with a barrier test exceeding the reserve.

<!-- greyfinch-sync:ivall/xcl:review:6064361958 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#pullrequestreview-6064361958). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T20:18:40Z. **Review:** COMMENTED --- P1: Ring::push has a concurrent reservation race. late_release.rs:172-179 checks head-tail and then separately fetch_adds tail; RING_WRITERS=256 reserves space only under a bounded simultaneous-writer assumption, but no such bound is enforced. For example with N=512 and used=255, 258 writers can all observe occupancy below N-256 before incrementing; the last claim reaches tail+N and writes slots[tail % N] before the reader consumes it, overwriting a pending resource. That loses its pointer/reference and leaves its XCL address state unforgotten. The new 4-writer stress test cannot cover this. Please use CAS reservation/a bounded MPMC queue or enforce the writer bound, with a barrier test exceeding the reserve.
DavidM1911 commented 2026-11-25 21:05:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T20:16:01Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7173417197 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7173417197). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T20:16:01Z. --- 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!
fromthemoonx commented 2026-11-25 21:05:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-25T20:19:59Z.


Rerun on the new head 6df8f64: passes on NVIDIA, and the ring tests are stable. The new writers_at_once_past_the_free_room_overwrite_nothing catches the old check-then-fetch_add push, but only rarely here: 1 of 340 runs.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, 6df8f64 merged onto main e1d84b7 (clean) 1429 passed, 0 failed, 46 ignored; 25 SKIPPED lines
same at the head 6df8f64 1352 passed, 1 failed, 46 ignored: a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, from the base 3ceb550 (fixed on main by c828d8c), not this PR
writers_at_once_past_the_free_room_overwrite_nothing, writers_and_readers_at_once_…, a_full_ring_…, alone, 40 runs each 40 of 40 each
late_release:: + real::native_host_tests:: (8 tests), --test-threads=8, 40 runs 40 of 40
the new test with push put back as a check followed by fetch_add (scratch) failed 1 of 340 runs: exactly the free slots are claimed, left 258, right 257

So the new test can catch the race, but on an 8-core Ryzen it almost never does: the 300 writers rarely reach the check in the same window. A test that holds writers between the check and the claim (or loops the barrier round many times in one run) would fail reliably. The compare-exchange itself looks right to me by reading.


First run, on 6979e9f: Windows run: passed on NVIDIA with the whole suite, the ring and native-host tests were stable under repeats, and on Windows the gate stays off (the e2e title's log has no native-host line, and its debug-layer messages are the same as main's). This covers the "Windows and the whole suite" item under Not tested.

Tested: 6979e9f, and the same commit merged onto main e0d93c8 (clean; real.rs auto-merged). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC (x86_64-pc-windows-msvc), debug, Graphics Tools (D3D12 debug layer) installed.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, merged 1426 passed, 0 failed, 46 ignored; 25 SKIPPED lines (no wave64, refused per-lane forms)
same at the head 6979e9f 1351 passed, 1 failed, 46 ignored: a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, because the base 3ceb550 predates its fix on main (c828d8c); not this PR
each of the 3 new late_release ring tests and the 2 native_host_tests, alone, 40 runs each 40 of 40 each
hle::d3d12x::late_release:: + hle::d3d12x::real:: (66 tests), --test-threads=8, 30 runs 30 of 30
e2e test_title_draws_with_a_root_signature_under_the_debug_layer, merged vs main e0d93c8 the same messages on both: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit; the host's D3D12 is in no PE module appears in neither log

Not tested: a title on Windows with this branch, a release build, AMD / Intel, Wine / D3DMetal (nothing here).

AI use: Claude Code (Claude Opus 5.5) ran the tests and the debug-layer comparison, and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7173512274 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7173512274). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-25T20:19:59Z. --- **Rerun on the new head `6df8f64`: passes on NVIDIA, and the ring tests are stable. The new `writers_at_once_past_the_free_room_overwrite_nothing` catches the old check-then-`fetch_add` push, but only rarely here: 1 of 340 runs.** | | result | |---|---| | `cargo test --workspace --no-fail-fast -- --test-threads=4`, `6df8f64` merged onto `main` `e1d84b7` (clean) | 1429 passed, 0 failed, 46 ignored; 25 `SKIPPED` lines | | same at the head `6df8f64` | 1352 passed, 1 failed, 46 ignored: `a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`, from the base `3ceb550` (fixed on `main` by c828d8c), not this PR | | `writers_at_once_past_the_free_room_overwrite_nothing`, `writers_and_readers_at_once_…`, `a_full_ring_…`, alone, 40 runs each | 40 of 40 each | | `late_release::` + `real::native_host_tests::` (8 tests), `--test-threads=8`, 40 runs | 40 of 40 | | the new test with `push` put back as a check followed by `fetch_add` (scratch) | failed 1 of 340 runs: `exactly the free slots are claimed`, left `258`, right `257` | So the new test can catch the race, but on an 8-core Ryzen it almost never does: the 300 writers rarely reach the check in the same window. A test that holds writers between the check and the claim (or loops the barrier round many times in one run) would fail reliably. The compare-exchange itself looks right to me by reading. --- *First run, on `6979e9f`:* Windows run: passed on NVIDIA with the whole suite, the ring and native-host tests were stable under repeats, and on Windows the gate stays off (the e2e title's log has no native-host line, and its debug-layer messages are the same as `main`'s). This covers the "Windows and the whole suite" item under Not tested. **Tested:** `6979e9f`, and the same commit merged onto `main` `e0d93c8` (clean; `real.rs` auto-merged). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC (`x86_64-pc-windows-msvc`), debug, Graphics Tools (D3D12 debug layer) installed. | | result | |---|---| | `cargo test --workspace --no-fail-fast -- --test-threads=4`, merged | 1426 passed, 0 failed, 46 ignored; 25 `SKIPPED` lines (`no wave64`, refused per-lane forms) | | same at the head `6979e9f` | 1351 passed, 1 failed, 46 ignored: `a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`, because the base `3ceb550` predates its fix on `main` (c828d8c); not this PR | | each of the 3 new `late_release` ring tests and the 2 `native_host_tests`, alone, 40 runs each | 40 of 40 each | | `hle::d3d12x::late_release::` + `hle::d3d12x::real::` (66 tests), `--test-threads=8`, 30 runs | 30 of 30 | | `e2e` `test_title_draws_with_a_root_signature_under_the_debug_layer`, merged vs `main` `e0d93c8` | the same messages on both: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit; `the host's D3D12 is in no PE module` appears in neither log | **Not tested:** a title on Windows with this branch, a release build, AMD / Intel, Wine / D3DMetal (nothing here). **AI use:** Claude Code (Claude Opus 5.5) ran the tests and the debug-layer comparison, and wrote this report.
Ahmet-Dedeler commented 2026-11-25 22:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Ahmet-Dedeler on 2026-11-25T21:17:28Z.


@bmjask you're right, thanks. The check and the fetch_add were two steps, and nothing bounded how many writers could pass the check at once.

Fixed in 6df8f64 (squashed into the ring commit): Ring::push now claims an index with one compare_exchange_weak on head, and only while head - tail < N, so writers arriving at once can't claim past the tail together. The tail is still stored only after the reader has emptied the slot, so a claimed slot is always an empty one. RING_WRITERS and its margin are gone, and the full ring is exactly N slots now.

New test writers_at_once_past_the_free_room_overwrite_nothing: a 512-slot ring with 255 entries, then 300 writers released by one barrier. It checks that exactly 257 are accepted, that the 255 already in the ring come out unchanged and in order, and that every accepted resource comes out once. With the old push that's more writers than the 256 reserve. The other three ring tests pass on the new head too (under Wine, --exact, one process each), and the description has the smoke block for 6df8f64.

<!-- greyfinch-sync:ivall/xcl:comment:7174876309 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7174876309). Originally posted by [Ahmet-Dedeler](https://github.com/Ahmet-Dedeler) on 2026-11-25T21:17:28Z. --- @bmjask you're right, thanks. The check and the `fetch_add` were two steps, and nothing bounded how many writers could pass the check at once. Fixed in `6df8f64` (squashed into the ring commit): `Ring::push` now claims an index with one `compare_exchange_weak` on `head`, and only while `head - tail < N`, so writers arriving at once can't claim past the tail together. The tail is still stored only after the reader has emptied the slot, so a claimed slot is always an empty one. `RING_WRITERS` and its margin are gone, and the full ring is exactly N slots now. New test `writers_at_once_past_the_free_room_overwrite_nothing`: a 512-slot ring with 255 entries, then 300 writers released by one barrier. It checks that exactly 257 are accepted, that the 255 already in the ring come out unchanged and in order, and that every accepted resource comes out once. With the old `push` that's more writers than the 256 reserve. The other three ring tests pass on the new head too (under Wine, `--exact`, one process each), and the description has the smoke block for `6df8f64`.
DavidM1911 commented 2026-11-26 02:08:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T01:50:07Z.


Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7180184602 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7180184602). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T01:50:07Z. --- Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
luckyteagirl commented 2026-11-26 07:28:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T07:28:14Z.

Review: COMMENTED


late_release.rs:171–176: the capacity check can treat an empty ring as full because it samples head before tail. Start with head = tail = 0: producer A reads i = 0 and pauses; B claims slot 0; the reader drains it and publishes tail = 1 (take, line 204). A then reads that tail, so 0usize.wrapping_sub(1) == usize::MAX and returns false even though head = tail = 1. hand_over_to counts the rejected resource as kept for good (lines 224–229), so an ordinary two-producer/one-reader interleaving leaks a resource and retains its address bookkeeping without the ring ever being full. The newer CAS reservation fixes the writer-overflow race, but not this stale-head/fresh-tail snapshot.

Could the check read tail before the head sample, or refresh head before treating an apparent wrap as full, with a deterministic barrier test after A's head load? This is source-derived at exact head 6df8f647253b3e2cb071543afce1248be3a4f08f; a CPU arithmetic probe confirmed the usize::MAX result, but I have not run the XCL ring test or a native-host title. The behavior is inherited by stacked #2498. AI-assisted review with Codex.

<!-- greyfinch-sync:ivall/xcl:review:6070040545 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#pullrequestreview-6070040545). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T07:28:14Z. **Review:** COMMENTED --- `late_release.rs:171–176`: the capacity check can treat an empty ring as full because it samples `head` before `tail`. Start with `head = tail = 0`: producer A reads `i = 0` and pauses; B claims slot 0; the reader drains it and publishes `tail = 1` (`take`, line 204). A then reads that tail, so `0usize.wrapping_sub(1) == usize::MAX` and returns `false` even though `head = tail = 1`. `hand_over_to` counts the rejected resource as kept for good (lines 224–229), so an ordinary two-producer/one-reader interleaving leaks a resource and retains its address bookkeeping without the ring ever being full. The newer CAS reservation fixes the writer-overflow race, but not this stale-head/fresh-tail snapshot. Could the check read `tail` before the head sample, or refresh `head` before treating an apparent wrap as full, with a deterministic barrier test after A's head load? This is source-derived at exact head `6df8f647253b3e2cb071543afce1248be3a4f08f`; a CPU arithmetic probe confirmed the `usize::MAX` result, but I have not run the XCL ring test or a native-host title. The behavior is inherited by stacked #2498. AI-assisted review with Codex.
ClosetPie107 commented 2026-11-27 18:00:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-27T18:00:42Z.


Tested on AMD / Linux: 6df8f647 (RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimental experimental-11.0-20261112 with vkd3d-proton master ec207194 plus a local patch dropping the lpVtbl checks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0, x86_64-pc-windows-gnu debug build, tests run under Wine)

The head as it is (not merged onto current main), with its base 3ceb5507 the same session as the baseline.

Tests (XCL_REQUIRE_GPU=wave64)

  • cargo test -p xcl --lib -- hle::d3d12x::late_release:: --test-threads=1: 6 passed, 0 failed, 0 ignored.
  • cargo test -p xcl --lib -- only_a_table_in_no_pe_module_makes_a_native_host a_kept_last_release_on_a_native_host_waits_for_no_lock --test-threads=1: 2 passed, 0 failed, 0 ignored.
  • Lib with --test-threads=1 and --skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (the first loses the RADV device here, the other two run out of memory under Wine): 1264 passed, 10 failed, 26 ignored; base 3ceb5507 the same way: 1255 passed, 13 failed, 26 ignored. All of this head's failures are among the base's.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 with --skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (the first loses the RADV device here, the other two run out of memory under Wine): lib 1252 passed, 22 failed, 26 ignored. Each of the extra failures also fails on the base single-threaded, on 2898511a (another older tree) with 4 threads, or on main. The base's own 4-thread lib run ended with a device removal (0x887a0005). The other binaries fail the same 3 tests as on main here (e2e, pls_quota, predication_e2e). d3d12_resource_and_sync ended the process, as it does on the other trees here.

Not tested

  • A retail title
  • Native Windows, NVIDIA / Intel

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the builds and tests on my machine and wrote this report.
<!-- greyfinch-sync:ivall/xcl:comment:7225022850 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7225022850). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-11-27T18:00:42Z. --- **Tested on AMD / Linux: `6df8f647`** (RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimental `experimental-11.0-20261112` with vkd3d-proton master `ec207194` plus a local patch dropping the `lpVtbl` checks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0, `x86_64-pc-windows-gnu` debug build, tests run under Wine) The head as it is (not merged onto current `main`), with its base `3ceb5507` the same session as the baseline. **Tests** (`XCL_REQUIRE_GPU=wave64`) - `cargo test -p xcl --lib -- hle::d3d12x::late_release:: --test-threads=1`: **6 passed, 0 failed**, 0 ignored. - `cargo test -p xcl --lib -- only_a_table_in_no_pe_module_makes_a_native_host a_kept_last_release_on_a_native_host_waits_for_no_lock --test-threads=1`: **2 passed, 0 failed**, 0 ignored. - Lib with `--test-threads=1` and `--skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole` (the first loses the RADV device here, the other two run out of memory under Wine): 1264 passed, 10 failed, 26 ignored; base `3ceb5507` the same way: 1255 passed, 13 failed, 26 ignored. All of this head's failures are among the base's. - `cargo test --workspace --no-fail-fast -- --test-threads=4` with `--skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole` (the first loses the RADV device here, the other two run out of memory under Wine): lib 1252 passed, 22 failed, 26 ignored. Each of the extra failures also fails on the base single-threaded, on `2898511a` (another older tree) with 4 threads, or on `main`. The base's own 4-thread lib run ended with a device removal (`0x887a0005`). The other binaries fail the same 3 tests as on `main` here (`e2e`, `pls_quota`, `predication_e2e`). `d3d12_resource_and_sync` ended the process, as it does on the other trees here. **Not tested** - A retail title - Native Windows, NVIDIA / Intel **AI use** - Claude Code (Claude Opus 5.5) wrote the test scripts, ran the builds and tests on my machine and wrote this report.
Foniass commented 2026-12-01 08:06:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:06:47Z.


Triage (#1607) – head 6df8f64

Stacked on #1789: the bottom commit (9ac7d63, late_release::init called from real::adopt) is #1789's change rebased onto main; the two top commits (forget_released split out of res_release, and the native-host ring in late_release.rs) are this PR's own. #2498 (draft) is stacked on an earlier version of this PR: it carries these commits (with a fetch_add ring instead of this compare-exchange one) and adds a deferred Release for foreign threads on top.
No open or merged PR makes the same ring change. In the diff, Ring::push claims an index only while it is less than N past the tail, so a claimed slot is always one the reader has emptied, and take stops at a claimed but unwritten slot; with the ring full the reference is kept for good (a deliberate leak, logged by the late-release thread). No problems found.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7304889683 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2445#issuecomment-7304889683). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:06:47Z. --- **Triage (#1607)** – head 6df8f64 Stacked on #1789: the bottom commit (9ac7d63, `late_release::init` called from `real::adopt`) is #1789's change rebased onto main; the two top commits (`forget_released` split out of `res_release`, and the native-host ring in `late_release.rs`) are this PR's own. #2498 (draft) is stacked on an earlier version of this PR: it carries these commits (with a fetch_add ring instead of this compare-exchange one) and adds a deferred Release for foreign threads on top. No open or merged PR makes the same ring change. In the diff, `Ring::push` claims an index only while it is less than N past the tail, so a claimed slot is always one the reader has emptied, and `take` stops at a claimed but unwritten slot; with the ring full the reference is kept for good (a deliberate leak, logged by the late-release thread). No problems found. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2445:upstream-pr/2445'
git switch 'upstream-pr/2445'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2445'
git switch 'upstream-pr/2445'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2445'
git switch 'upstream-pr/2445'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2445'
git switch 'main'
git merge --squash 'upstream-pr/2445'
git switch 'main'
git merge --ff-only 'upstream-pr/2445'
git switch 'main'
git merge 'upstream-pr/2445'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2435
No description provided.