d3d12-gpu: fix parallel unit test races in watch, descriptor, and pool #2854

Merged
lixonik merged 4 commits from upstream-pr/2854 into main 2026-12-02 13:34:15 +00:00
lixonik commented 2026-12-01 09:35:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T09:35:14Z.


Claim: D3D12-GPU-TEST-PARALLEL-FLAKES (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7306755357)

Fixes three process-global parallel test issues in leonida-gpu reported in #2570 (where cargo test -p leonida-gpu --lib flaked under default parallel test threads while passing under --test-threads=1).

Root causes & fixes

  1. watch::tests (d3d12/crates/leonida-gpu/src/watch.rs)

    • drop_views called title_memory_remapped instead of title_memory_unmapping, deterministically leaking clean, PUBLISHED, and VIEWS state for an unmapped view address. Switched drop_views to title_memory_unmapping.
    • nothing_is_guarded_between_our_forgetting_it_and_its_unmapping and writes_to_views_are_not_lost called UnmapViewOfFile before dropping Remapping, returning the virtual address to Windows while g.changing still marked its block as left_alone. Ended the remapping window before UnmapViewOfFile (note: this race-window tightening is not directly covered by a unit test; reverting it leaves the suite green).
  2. descriptor::tests (d3d12/crates/leonida-gpu/src/descriptor.rs)

    • records_copied_as_bytes_are_made_at_the_next_sync raced with the 4 ms background "leonida-heap-sync" thread and concurrent test submissions calling sync_heaps() over process-global SHADER_HEAPS: a competing sync round could consume the write-watch reset for slot 5 before publishing its host descriptor, causing the test's post-sync assert!(host.made(5)) to observe false. Added a #[cfg(test)] TEST_SYNC_LOCK around sync_heaps() and held it across the raw copy, pre-sync check, and sync call.
  3. pool::Reclaim / texture::alias_cast_tests (d3d12/crates/leonida-gpu/src/pool.rs)

    • Reclaim::release returned a pooled piece without removing the released ID3D12Resource raw pointer from RECENT or UNSEEN. When a subsequent committed texture reused that COM pointer within 1 second, pool::fresh falsely reported true, failing assert_eq!(pool::fresh(&copy.texture), false) in committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers. Stored raw: usize in Reclaim and called forget_released(gone.raw) before returning gone.piece to TEXTURES on final release.
    • Added unit test released_texture_pointer_is_not_kept_in_recent_or_unseen (tests forget_released directly, inserting (raw, u64::MAX) into UNSEEN without calling note_unseen's eviction sweep) and COM last-reference drop regression test dropping_last_pooled_texture_reference_forgets_recent_and_unseen (allocates a 32x32 RGBA8 placed texture via pool::texture, holds two COM references, confirms entries remain after dropping the first reference, and confirms RECENT and UNSEEN are cleared after dropping the final reference triggers Reclaim::release).

Verification

  • Before (main ad7c62edb, 8 parallel runs): watch::tests::other_memory_at_a_guarded_address_keeps_its_protection and watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view panicked on parallel run 2/8.
  • Red/green for dropping_last_pooled_texture_reference_forgets_recent_and_unseen:
    • Without forget_released(gone.raw) in Reclaim::release: 0 passed; 1 failed (panicked on post-drop RECENT assertion; independently reproduced by @Neutron-0 and @KelboLive).
    • With forget_released(gone.raw) before lock(&TEXTURES).give(...) (81a6e94a9):
      • cargo test --locked -p leonida-gpu --lib pool::: 10/10 consecutive parallel runs passed (19 passed, 0 failed each).
      • Full leonida-gpu --lib parallel runs (at bce4a898b): 17/18 passed here (601/0/55; run 18 hit the separate standing-ask flake tracked in #2896); 0/40 failures and 635/0/59 merged on main on @KelboLive's machine.
    • (depth_bounds_pipeline_loads_and_filters_draws fails deterministically on Windows 10 inbox D3D12 without Agility SDK; tracked in #2855.)

GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver 621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T)

AI-assisted: Antigravity (plus separate read-only reviewer subagent)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5582954680 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-01T09:35:14Z. --- Claim: `D3D12-GPU-TEST-PARALLEL-FLAKES` (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7306755357) Fixes three process-global parallel test issues in `leonida-gpu` reported in #2570 (where `cargo test -p leonida-gpu --lib` flaked under default parallel test threads while passing under `--test-threads=1`). ### Root causes & fixes 1. **`watch::tests` (`d3d12/crates/leonida-gpu/src/watch.rs`)** - `drop_views` called `title_memory_remapped` instead of `title_memory_unmapping`, deterministically leaking `clean`, `PUBLISHED`, and `VIEWS` state for an unmapped view address. Switched `drop_views` to `title_memory_unmapping`. - `nothing_is_guarded_between_our_forgetting_it_and_its_unmapping` and `writes_to_views_are_not_lost` called `UnmapViewOfFile` before dropping `Remapping`, returning the virtual address to Windows while `g.changing` still marked its block as `left_alone`. Ended the remapping window before `UnmapViewOfFile` (note: this race-window tightening is not directly covered by a unit test; reverting it leaves the suite green). 2. **`descriptor::tests` (`d3d12/crates/leonida-gpu/src/descriptor.rs`)** - `records_copied_as_bytes_are_made_at_the_next_sync` raced with the 4 ms background `"leonida-heap-sync"` thread and concurrent test submissions calling `sync_heaps()` over process-global `SHADER_HEAPS`: a competing sync round could consume the write-watch reset for slot 5 before publishing its host descriptor, causing the test's post-sync `assert!(host.made(5))` to observe `false`. Added a `#[cfg(test)]` `TEST_SYNC_LOCK` around `sync_heaps()` and held it across the raw copy, pre-sync check, and sync call. 3. **`pool::Reclaim` / `texture::alias_cast_tests` (`d3d12/crates/leonida-gpu/src/pool.rs`)** - `Reclaim::release` returned a pooled piece without removing the released `ID3D12Resource` raw pointer from `RECENT` or `UNSEEN`. When a subsequent committed texture reused that COM pointer within 1 second, `pool::fresh` falsely reported `true`, failing `assert_eq!(pool::fresh(&copy.texture), false)` in `committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers`. Stored `raw: usize` in `Reclaim` and called `forget_released(gone.raw)` **before** returning `gone.piece` to `TEXTURES` on final release. - Added unit test `released_texture_pointer_is_not_kept_in_recent_or_unseen` (tests `forget_released` directly, inserting `(raw, u64::MAX)` into `UNSEEN` without calling `note_unseen`'s eviction sweep) and COM last-reference drop regression test `dropping_last_pooled_texture_reference_forgets_recent_and_unseen` (allocates a 32x32 RGBA8 placed texture via `pool::texture`, holds two COM references, confirms entries remain after dropping the first reference, and confirms `RECENT` and `UNSEEN` are cleared after dropping the final reference triggers `Reclaim::release`). ### Verification - **Before (`main` `ad7c62edb`, 8 parallel runs):** `watch::tests::other_memory_at_a_guarded_address_keeps_its_protection` and `watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view` panicked on parallel run 2/8. - **Red/green for `dropping_last_pooled_texture_reference_forgets_recent_and_unseen`:** - **Without `forget_released(gone.raw)` in `Reclaim::release`:** `0 passed; 1 failed` (panicked on post-drop `RECENT` assertion; independently reproduced by `@Neutron-0` and `@KelboLive`). - **With `forget_released(gone.raw)` before `lock(&TEXTURES).give(...)` (`81a6e94a9`):** - `cargo test --locked -p leonida-gpu --lib pool::`: **10/10 consecutive parallel runs passed (19 passed, 0 failed each)**. - Full `leonida-gpu --lib` parallel runs (at `bce4a898b`): 17/18 passed here (601/0/55; run 18 hit the separate standing-ask flake tracked in #2896); 0/40 failures and 635/0/59 merged on `main` on `@KelboLive`'s machine. - (`depth_bounds_pipeline_loads_and_filters_draws` fails deterministically on Windows 10 inbox D3D12 without Agility SDK; tracked in #2855.) GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver 621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T) AI-assisted: Antigravity (plus separate read-only reviewer subagent)
MoonEyes commented 2026-12-01 10:04:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T10:04:45Z.


Your claim is there (D3D12-GPU-TEST-PARALLEL-FLAKES, https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7306755357), but the description does not name it. Could you add the ID and that link, so the merge checklist finds it?

One small thing while reading the diff: TEST_SYNC_LOCK sits between the doc comment of sync_heaps and the function, so those lines now document the static.

This one changes pool.rs outside the tests, so it is in the in-game run I have queued on an RTX 4060.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7307635602 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7307635602). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T10:04:45Z. --- Your claim is there (`D3D12-GPU-TEST-PARALLEL-FLAKES`, https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7306755357), but the description does not name it. Could you add the ID and that link, so the merge checklist finds it? One small thing while reading the diff: `TEST_SYNC_LOCK` sits between the doc comment of `sync_heaps` and the function, so those lines now document the static. This one changes `pool.rs` outside the tests, so it is in the in-game run I have queued on an RTX 4060. AI-assisted (Claude Code).
Kal0s-design commented 2026-12-01 10:45:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-01T10:45:06Z.


Independent Windows check, A/B over repeated runs: 99ed48337 merged onto current main 653f60d37 (no conflict, 1b2be1bfc) against main itself. Native Windows 11, MSVC x64, Rust 1.98.1. I built the leonida-gpu lib test binary once per side (debug, default parallel test threads) and ran each whole suite 40 times back to back, alternating nothing else.

runs with a failure tests that failed
main 653f60d37 4 / 40 watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view, watch::tests::kernel_reads_into_guarded_blocks_after_opening, watch::tests::a_write_is_reported_at_every_checked_view (one per run; one run's name wasn't captured)
main + this PR 0 / 40 none

So the watch cross-test interference reproduces on main here (about 1 run in 10), and with this PR it doesn't show in 40 runs. On another day I also saw descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync fail once in 9 runs on a branch, which is the second race this PR addresses. It didn't come up in these 40 main runs, so I can't add a count for it.

GPUs tested: n/a (unit tests). AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7308660881 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7308660881). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-01T10:45:06Z. --- **Independent Windows check, A/B over repeated runs**: `99ed48337` merged onto current `main` `653f60d37` (no conflict, `1b2be1bfc`) against `main` itself. Native Windows 11, MSVC x64, Rust 1.98.1. I built the `leonida-gpu` lib test binary once per side (debug, default parallel test threads) and ran each whole suite 40 times back to back, alternating nothing else. | | runs with a failure | tests that failed | |---|---|---| | `main` `653f60d37` | **4 / 40** | `watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view`, `watch::tests::kernel_reads_into_guarded_blocks_after_opening`, `watch::tests::a_write_is_reported_at_every_checked_view` (one per run; one run's name wasn't captured) | | `main` + this PR | **0 / 40** | none | So the `watch` cross-test interference reproduces on `main` here (about 1 run in 10), and with this PR it doesn't show in 40 runs. On another day I also saw `descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync` fail once in 9 runs on a branch, which is the second race this PR addresses. It didn't come up in these 40 `main` runs, so I can't add a count for it. GPUs tested: n/a (unit tests). AI-assisted: yes.
lixonik commented 2026-12-01 11:16:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T11:16:16Z.


@MoonEyes Thanks for catching both!

  • Added the claim ID (D3D12-GPU-TEST-PARALLEL-FLAKES) and link to the PR description.
  • Moved TEST_SYNC_LOCK above sync_heaps's doc comment so those doc lines stay attached to pub(crate) fn sync_heaps(), and re-verified records_copied_as_bytes_are_made_at_the_next_sync.

@Kal0s-design Thanks for the independent 40-run Windows 11 A/B verification (4/40 -> 0/40)!

AI-assisted: Antigravity

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7309408232 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7309408232). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-01T11:16:16Z. --- @MoonEyes Thanks for catching both! - Added the claim ID (`D3D12-GPU-TEST-PARALLEL-FLAKES`) and link to the PR description. - Moved `TEST_SYNC_LOCK` above `sync_heaps`'s doc comment so those doc lines stay attached to `pub(crate) fn sync_heaps()`, and re-verified `records_copied_as_bytes_are_made_at_the_next_sync`. @Kal0s-design Thanks for the independent 40-run Windows 11 A/B verification (4/40 -> 0/40)! AI-assisted: Antigravity
enlight3d commented 2026-12-01 11:18:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-01T11:18:10Z.


RUN (independent run on Windows, #2854 head 99ed48337, merged locally into main 3393ceec9 with git merge --no-ff, no conflicts. The head still merges cleanly into main bf30e2585. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with --locked, at low priority. cargo test -p leonida-gpu --lib --no-run of main and of the merge; then the two test binaries were run alternately, each with the default thread count (32 here, no --test-threads), as cargo test -p leonida-gpu --lib runs them:

  • Default build, 32 runs each side: main 31 clean, 1 failure (watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view, watch.rs:6010, left Some([..]), right Some([])); merge 32 clean (602 passed / 0 failed / 55 ignored, the extra test being the new one). So no new failure, and the one parallel failure seen on main is a watch test. The flake rate here is low (1 in 32 on main), so these runs alone cannot prove the fix; the two tests named in the body did not fail on main in 32 runs here.
  • --features diagnostics build, 10 runs each side: main 2 clean, merge 2 clean. timeline::record::tests::global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks fails in parallel on both sides (main 7 of 10, merge 8 of 10, record.rs:2325, no "synthetic stall span"): a parallel race this pull request does not touch. descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync, which this pull request fixes, failed once on main and never on the merge.
  • Red, by assertion: forget_released emptied (fn forget_released(_raw: usize) {}), the new test kept: released_texture_pointer_is_not_kept_in_recent_or_unseen fails on its first assertion (!RECENT...any(|r| r.0 == raw), pool.rs:1295). Green after restoring: 1 passed.
  • What that test does not cover: it calls forget_released directly. With the call taken out of release (let _ = gone.raw;), the whole suite still passes (602 / 0 / 55, one run). So no test checks that the last release of a pooled texture really forgets it; a test that makes a pooled texture, drops it and then asks fresh for its pointer would.
  • Lock order, read through pool.rs (RECENT, UNSEEN, TEXTURES): RECENT and UNSEEN are private to pool.rs. They are taken in fresh, made_now, begun_before, forget_released and the new test, and each guard covers only work on its own list of numbers (under UNSEEN, made_now also calls host::submissions(), which reads two atomics). No other lock is taken and no COM object is released while either is held, and the two are never held together (made_now drops RECENT before it takes UNSEEN; forget_released takes one, then the other). In release, the TEXTURES guard is a temporary dropped at the end of its statement, before forget_released. So both stay leaf locks: no reversed order and no re-entry is possible. A caller that holds some other lock when it drops the last reference to a pooled texture only adds an edge into these two leaf locks, which cannot close a cycle.
  • descriptor.rs: TEST_SYNC_LOCK and its use in sync_heaps are #[cfg(test)], so a normal build does not change. But the new static sits between the doc comment of sync_heaps and the function: that whole doc block (including the LEONIDA_HEAP_SYNC=0 line) now documents TEST_SYNC_LOCK, and sync_heaps has no doc comment in a normal build. Moving the static above that block would fix it. python -I tools/d3d12_switches.py --check d3d12/docs/switches.md is still clean on the merge.
  • cargo clippy -p leonida-gpu --all-targets, default and --features diagnostics, on main and on the merge: the same warnings on both sides (69 and 68 locations, counting those the command reports in leonida-shader and leonida-lua), none new.
  • Not covered here: the game. forget_released now runs at every last release of a pooled texture (a scan of RECENT, the textures made in the last second, under its lock).

Since this run the head moved to eab9e2abf, which only moves TEST_SYNC_LOCK above the doc comment of sync_heaps (5 lines in descriptor.rs): that fixes the doc point above and changes nothing else tested here.

Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40, Rust 1.98.1.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7309452232 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7309452232). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-12-01T11:18:10Z. --- RUN (independent run on Windows, #2854 head 99ed48337, merged locally into main 3393ceec9 with `git merge --no-ff`, no conflicts. The head still merges cleanly into main bf30e2585. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) Commands, in `d3d12/`, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with `--locked`, at low priority. `cargo test -p leonida-gpu --lib --no-run` of main and of the merge; then the two test binaries were run alternately, each with the default thread count (32 here, no `--test-threads`), as `cargo test -p leonida-gpu --lib` runs them: - Default build, 32 runs each side: main 31 clean, 1 failure (`watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view`, `watch.rs:6010`, left `Some([..])`, right `Some([])`); merge 32 clean (602 passed / 0 failed / 55 ignored, the extra test being the new one). So no new failure, and the one parallel failure seen on main is a watch test. The flake rate here is low (1 in 32 on main), so these runs alone cannot prove the fix; the two tests named in the body did not fail on main in 32 runs here. - `--features diagnostics` build, 10 runs each side: main 2 clean, merge 2 clean. `timeline::record::tests::global_stall_routing_retains_spans_waits_wakes_and_sent_fences_without_stacks` fails in parallel on both sides (main 7 of 10, merge 8 of 10, `record.rs:2325`, no "synthetic stall span"): a parallel race this pull request does not touch. `descriptor::tests::records_copied_as_bytes_are_made_at_the_next_sync`, which this pull request fixes, failed once on main and never on the merge. - Red, by assertion: `forget_released` emptied (`fn forget_released(_raw: usize) {}`), the new test kept: `released_texture_pointer_is_not_kept_in_recent_or_unseen` fails on its first assertion (`!RECENT...any(|r| r.0 == raw)`, `pool.rs:1295`). Green after restoring: 1 passed. - What that test does not cover: it calls `forget_released` directly. With the call taken out of `release` (`let _ = gone.raw;`), the whole suite still passes (602 / 0 / 55, one run). So no test checks that the last release of a pooled texture really forgets it; a test that makes a pooled texture, drops it and then asks `fresh` for its pointer would. - Lock order, read through `pool.rs` (`RECENT`, `UNSEEN`, `TEXTURES`): `RECENT` and `UNSEEN` are private to `pool.rs`. They are taken in `fresh`, `made_now`, `begun_before`, `forget_released` and the new test, and each guard covers only work on its own list of numbers (under `UNSEEN`, `made_now` also calls `host::submissions()`, which reads two atomics). No other lock is taken and no COM object is released while either is held, and the two are never held together (`made_now` drops `RECENT` before it takes `UNSEEN`; `forget_released` takes one, then the other). In `release`, the `TEXTURES` guard is a temporary dropped at the end of its statement, before `forget_released`. So both stay leaf locks: no reversed order and no re-entry is possible. A caller that holds some other lock when it drops the last reference to a pooled texture only adds an edge into these two leaf locks, which cannot close a cycle. - `descriptor.rs`: `TEST_SYNC_LOCK` and its use in `sync_heaps` are `#[cfg(test)]`, so a normal build does not change. But the new static sits between the doc comment of `sync_heaps` and the function: that whole doc block (including the `LEONIDA_HEAP_SYNC=0` line) now documents `TEST_SYNC_LOCK`, and `sync_heaps` has no doc comment in a normal build. Moving the static above that block would fix it. `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` is still clean on the merge. - `cargo clippy -p leonida-gpu --all-targets`, default and `--features diagnostics`, on main and on the merge: the same warnings on both sides (69 and 68 locations, counting those the command reports in `leonida-shader` and `leonida-lua`), none new. - Not covered here: the game. `forget_released` now runs at every last release of a pooled texture (a scan of `RECENT`, the textures made in the last second, under its lock). Since this run the head moved to eab9e2abf, which only moves `TEST_SYNC_LOCK` above the doc comment of `sync_heaps` (5 lines in `descriptor.rs`): that fixes the doc point above and changes nothing else tested here. Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40, Rust 1.98.1.
MoonEyes commented 2026-12-01 14:25:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T14:25:09Z.


One thing before a merge, from enlight3d's check and confirmed by reading: taking the call of forget_released out of release leaves the whole suite green, since the new test calls the function directly. Could you add a test that drops the last reference of a pooled texture (or a Reclaim) and fails without that call? The rest reads fine: the locks are leaves and the entry goes before the address can be reused.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7314218907 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7314218907). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T14:25:09Z. --- One thing before a merge, from enlight3d's check and confirmed by reading: taking the call of `forget_released` out of `release` leaves the whole suite green, since the new test calls the function directly. Could you add a test that drops the last reference of a pooled texture (or a `Reclaim`) and fails without that call? The rest reads fine: the locks are leaves and the entry goes before the address can be reused. AI-assisted (Claude Code).
merzleckeier commented 2026-12-01 14:28:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T14:28:47Z.


I tested the requested last-reference regression at eab9e2ab + #2884 on b3910e5e. The fixture makes a real 32×32 RGBA8 placed texture through pool::texture, requires that pooled allocation to succeed, and holds two COM references. It checks that both tracking entries exist initially and after the first drop. After dropping the last reference, it checks that HELD has returned to its original count and both RECENT and UNSEEN no longer contain the key.

Device under Wine 11.22 With the PR With only forget_released(gone.raw) removed from release
AMD Raphael / RADV 26.3.1 returned pool piece, both entries cleared returned pool piece, both entries remained
RTX 4070 SUPER / 620.73.04 returned pool piece, both entries cleared returned pool piece, both entries remained

That gives a red/green test through COM destruction without relying on pointer reuse. The separate full diagnostics runs with #2884 kept the same eight non-target Wine failures seen with #2884 alone. All three combined runs passed the new stock bookkeeping test and the timeline-record tests. Win64 MSVC target, Rust 1.98.1, synthetic inputs. MEASURED, AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7314317322 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7314317322). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T14:28:47Z. --- I tested the requested last-reference regression at `eab9e2ab` + #2884 on `b3910e5e`. The fixture makes a real 32×32 RGBA8 placed texture through `pool::texture`, requires that pooled allocation to succeed, and holds two COM references. It checks that both tracking entries exist initially and after the first `drop`. After dropping the last reference, it checks that `HELD` has returned to its original count and both `RECENT` and `UNSEEN` no longer contain the key. | Device under Wine 11.22 | With the PR | With only `forget_released(gone.raw)` removed from `release` | | --- | --- | --- | | AMD Raphael / RADV 26.3.1 | returned pool piece, both entries cleared | returned pool piece, both entries remained | | RTX 4070 SUPER / 620.73.04 | returned pool piece, both entries cleared | returned pool piece, both entries remained | That gives a red/green test through COM destruction without relying on pointer reuse. The separate full diagnostics runs with #2884 kept the same eight non-target Wine failures seen with #2884 alone. All three combined runs passed the new stock bookkeeping test and the timeline-record tests. Win64 MSVC target, Rust 1.98.1, synthetic inputs. MEASURED, AI-assisted (Codex).
lixonik commented 2026-12-01 15:02:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T15:02:32Z.


@MoonEyes Added pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen in bce4a898b:

  • Allocates a real 32x32 RGBA8 placed texture via pool::texture, holds two COM references, verifies RECENT and UNSEEN stay populated after dropping the first reference, and verifies both entries are cleared when dropping the final reference triggers Reclaim::release.
  • Red/green: Removing forget_released(gone.raw) from Reclaim::release fails the test (0 passed; 1 failed); restoring it passes (1 passed under both default features and --features diagnostics, and 20/20 parallel runs of pool::).

@merzleckeier Thanks for testing the last-reference drop path independently as well!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7315246236 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7315246236). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-01T15:02:32Z. --- @MoonEyes Added `pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen` in `bce4a898b`: - Allocates a real 32x32 RGBA8 placed texture via `pool::texture`, holds two COM references, verifies `RECENT` and `UNSEEN` stay populated after dropping the first reference, and verifies both entries are cleared when dropping the final reference triggers `Reclaim::release`. - **Red/green:** Removing `forget_released(gone.raw)` from `Reclaim::release` fails the test (`0 passed; 1 failed`); restoring it passes (`1 passed` under both default features and `--features diagnostics`, and `20/20` parallel runs of `pool::`). @merzleckeier Thanks for testing the last-reference drop path independently as well!
DIGITALWORLD-PL commented 2026-12-01 17:59:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DIGITALWORLD-PL on 2026-12-01T17:59:15Z.


For comparison with the test-only lock in this PR, we tested an alternative for records_copied_as_bytes_are_made_at_the_next_sync on Windows with a GeForce RTX 5090 (driver 621.01).

We paused a competing synchronization round after it had taken the dirty page for slot 5 and before it published the host descriptor. Under that forced interleaving, the original test failed 6/6 runs at assert!(host.made(5)) after its own sync_heaps() returned. With our patch, the test passed 6/6 runs under the same schedule: three with the helper thread and three with inline synchronization.

Our one-file patch checks the fresh slot before the raw copy, submits a closed command list through Host::execute_sync_internal, and checks publication after it returns. The experiment exercised CPU-side descriptor publication on the RTX-backed D3D12 device. We tested the original code and our patch; we have not run this experiment against #2854's TEST_SYNC_LOCK implementation.

AI-assisted testing and independent review with OpenAI Codex (GPT-6.2 Astra).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7320197664 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7320197664). Originally posted by [DIGITALWORLD-PL](https://github.com/DIGITALWORLD-PL) on 2026-12-01T17:59:15Z. --- For comparison with the test-only lock in this PR, we tested an alternative for `records_copied_as_bytes_are_made_at_the_next_sync` on Windows with a GeForce RTX 5090 (driver 621.01). We paused a competing synchronization round after it had taken the dirty page for slot 5 and before it published the host descriptor. Under that forced interleaving, the original test **failed 6/6 runs** at `assert!(host.made(5))` after its own `sync_heaps()` returned. With our patch, the test **passed 6/6 runs** under the same schedule: three with the helper thread and three with inline synchronization. Our [one-file patch](https://github.com/DIGITALWORLD-PL/mandy/commit/3190ee63ff99e47747ca3be6f52356d574a42b74) checks the fresh slot before the raw copy, submits a closed command list through `Host::execute_sync_internal`, and checks publication after it returns. The experiment exercised CPU-side descriptor publication on the RTX-backed D3D12 device. We tested the original code and our patch; we have not run this experiment against #2854's `TEST_SYNC_LOCK` implementation. AI-assisted testing and independent review with OpenAI Codex (GPT-6.2 Astra).
KelboLive commented 2026-12-01 18:14:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T18:14:15Z.

Review: COMMENTED


The strongest hunk is drop_views → title_memory_unmapping — open/remapped never cleared clean, PUBLISHED or VIEWS, so a freed address kept stale state; that is a deterministic leak, not a race. The descriptor lock is real too: my parent-commit A/B caught assert!(host.made(5)) failing 1/60 full-suite runs, and the head is 0/40. One correction: the body describes that race backwards — the observed failure was the post-sync assert seeing false because another sync had consumed the write-watch reset, not !made seeing an early mirror. Same root cause, opposite direction.

Two nits in pool.rs:

  1. Call forget_released(gone.raw) before lock(&TEXTURES).give(...) (:713-714). As written, a texture created at the same COM address in that gap can have its fresh RECENT/UNSEEN entry wiped by the release. The mechanism is right (wrapper reuse is independent of the 2.5 s piece REST), just the order.
  2. The new tests are not hermetic: dropping_last_... asserts on process-global RECENT/UNSEEN after freeing a COM object (a parallel pool test landing on the same wrapper address re-adds raw), and released_texture_pointer_... calls note_unseen(..., 10, 5) (:1295), whose retain evicts every other UNSEEN entry with begun <= 5. Low probability, but this is a flake PR.

The watch reorder (:5190) is not covered: reverting it leaves the whole 602-test suite green. That is acceptable for a race, but please don't count it as tested — it removes the specific window where the address is back with Windows while guards().changing still makes left_alone() skip guarding; the residual window between drop(changing) and UnmapViewOfFile is argued, not closed.

Mutation coverage otherwise holds: dropping forget_released from release fails the new test at pool.rs:1345, and dropping just UNSEEN.remove fails both. Merge is clean against current main; a local merge builds and passes 635/0/59 despite the 384-commit gap. #2896 is complementary (different hunks), but note #2908's require_host() sweep would leave the new pool.rs:1313 test on the old silent form.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6137248782 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#pullrequestreview-6137248782). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T18:14:15Z. **Review:** COMMENTED --- The strongest hunk is `drop_views` → `title_memory_unmapping` — `open`/`remapped` never cleared `clean`, `PUBLISHED` or `VIEWS`, so a freed address kept stale state; that is a deterministic leak, not a race. The descriptor lock is real too: my parent-commit A/B caught `assert!(host.made(5))` failing **1/60** full-suite runs, and the head is **0/40**. One correction: the body describes that race backwards — the observed failure was the post-sync assert seeing `false` because another sync had consumed the write-watch reset, not `!made` seeing an early mirror. Same root cause, opposite direction. Two nits in `pool.rs`: 1. **Call `forget_released(gone.raw)` before `lock(&TEXTURES).give(...)`** (`:713-714`). As written, a texture created at the same COM address in that gap can have its fresh `RECENT`/`UNSEEN` entry wiped by the release. The mechanism is right (wrapper reuse is independent of the 2.5 s piece `REST`), just the order. 2. **The new tests are not hermetic**: `dropping_last_...` asserts on process-global `RECENT`/`UNSEEN` after freeing a COM object (a parallel pool test landing on the same wrapper address re-adds `raw`), and `released_texture_pointer_...` calls `note_unseen(..., 10, 5)` (`:1295`), whose `retain` evicts every other `UNSEEN` entry with `begun <= 5`. Low probability, but this is a flake PR. The watch reorder (`:5190`) is **not covered**: reverting it leaves the whole 602-test suite green. That is acceptable for a race, but please don't count it as tested — it removes the specific window where the address is back with Windows while `guards().changing` still makes `left_alone()` skip guarding; the residual window between `drop(changing)` and `UnmapViewOfFile` is argued, not closed. Mutation coverage otherwise holds: dropping `forget_released` from `release` fails the new test at `pool.rs:1345`, and dropping just `UNSEEN.remove` fails both. Merge is clean against current main; a local merge builds and passes **635/0/59** despite the 384-commit gap. #2896 is complementary (different hunks), but note #2908's `require_host()` sweep would leave the new `pool.rs:1313` test on the old silent form.
Neutron-0 commented 2026-12-01 18:21:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T18:21:03Z.


Verified on Windows 11, Rust 1.98.1, no GPU and no game files.

The fix is shown to be needed, by reverting only the source the change touches. The pull request's own new test pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen passes on the head bce4a898b, and fails when the one line the fix adds to Reclaim::release is taken out of the head's d3d12/crates/leonida-gpu/src/pool.rs (forget_released(gone.raw);), with the rest of the head untouched:

result
the head bce4a898b test result: ok. 1 passed; 0 failed
the head with that one line removed test result: FAILED. 0 passed; 1 failed

That test builds a real 32x32 RGBA8 texture, keeps a second COM reference so the first drop does not release it, drops the last reference, and then checks that the raw pointer is gone from both RECENT and UNSEEN - so it does cover the wiring, not only the helper.

The other new test covers less than its comment says. pool::tests::released_texture_pointer_is_not_kept_in_recent_or_unseen passes on the head, and it still passes with that same line removed: it calls forget_released(raw) itself rather than releasing anything, so it tests the helper and not the path that calls it. Its doc comment ("Releasing a pooled texture clears its raw pointer from RECENT and UNSEEN") describes the other test. Not blocking - the second test covers the wiring - but the comment overstates what is checked.

What the parallel runs showed. The whole leonida-gpu test binary was run in parallel, with the shape the report uses (cargo test -p leonida-gpu --lib --features diagnostics -- --skip depth_bounds_pipeline_loads_and_filters_draws), so that the other test threads are there to contend. This was done three times, twenty runs on the head and forty on the base:

runs
the head bce4a898b 20 passed, 0 failed
the base 7fbcd456e 33 passed, 7 failed

The seven failures on the base were in four different tests, and only one of them is named in the report:

texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers
  panicked at crates\leonida-gpu\src\texture.rs:5664:17
  assertion `left == right` failed: left: true, right: false
  (the pool race this pull request fixes: assert_eq!(pool::fresh(&copy.texture), false) reading true)   [3 runs]

watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view
  panicked at crates\leonida-gpu\src\watch.rs:6010:9
  assertion `left == right` failed: left: Some([42241094]), right: Some([])
  (the second guard() query expected the block to be free, and it was still guarded)                     [1 run]

watch::tests::a_block_guarded_before_we_were_told_of_its_view_can_be_written
  panicked at crates\leonida-gpu\src\watch.rs:5343:9
  assertion failed: !writable(at) && !writable(at + ...)                                                 [1 run]

timeline::report::tests::real_waits_are_recorded_with_who_ended_them
  panicked at crates\leonida-gpu\src\timeline\report.rs:1459:9
  assertion `left == right` failed: left: None, right: Some(20124)                                      [2 runs]

The two watch failures are in the file this pull request changes, under names the report does not list. The report names watch::tests::nothing_is_guarded_between_our_forgetting_it_and_its_unmapping and watch::tests::writes_to_views_are_not_lost; the ones that actually fired here are what_the_kernel_writes_through_is_not_guarded_for_another_view and a_block_guarded_before_we_were_told_of_its_view_can_be_written. The first is the same shape the report describes - a view's address reused by another thread while this thread's guard state still listed the block, so the second guard() query found the block still guarded by somebody else - and the pull request's watch.rs change (ending the remapping window before UnmapViewOfFile returns the address to Windows, and title_memory_unmapping where title_memory_remapped was called) is aimed at exactly that window. Both of these tests should be named in the report, because they are the ones that failed here.

The timeline failure is a different race, in a file this pull request does not touch, and its cause is known. crates/leonida-gpu/src/timeline/report.rs:1459 is not covered by this pull request, and neither by #2884 (which fixes the ROLLING.dropped_contention counter in timeline/record.rs). The assertion reads left: None, so there was no wait of 10 ms or more to attribute at all: the test spawns the thread that is to wait on the mutex, sleeps a fixed 20 ms and then releases the lock, and under the load of the whole binary running in parallel the new thread sometimes has not reached the lock by then. It is filed as a separate finding: in #2570, because cargo test --workspace on main is red at random when it fires. Note the shape of the four pull requests: #2854 fixes the pool and watch races, #2884 fixes the timeline/record.rs race, and the timeline/report.rs race is a fourth one that nobody has taken.

A note on the rates. A race that fires in one run out of ten does not fire in every set of ten, so the difference between the head and the base here is seven failures in forty against none, not a clean per-test verdict for each of the races. The deterministic control above is what shows the change is needed; the parallel runs show the suite is not yet clean.

Not checked: the descriptor race in this pull request (it needs the same contention and did not fire in these sixty runs); the GPU crates under a real adapter (no GPU device here).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7320803964 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7320803964). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T18:21:03Z. --- Verified on Windows 11, Rust 1.98.1, no GPU and no game files. **The fix is shown to be needed, by reverting only the source the change touches.** The pull request's own new test `pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen` passes on the head `bce4a898b`, and **fails** when the one line the fix adds to `Reclaim::release` is taken out of the head's `d3d12/crates/leonida-gpu/src/pool.rs` (`forget_released(gone.raw);`), with the rest of the head untouched: | | result | |---|---| | the head `bce4a898b` | `test result: ok. 1 passed; 0 failed` | | the head with that one line removed | `test result: FAILED. 0 passed; 1 failed` | That test builds a real 32x32 RGBA8 texture, keeps a second COM reference so the first drop does not release it, drops the last reference, and then checks that the raw pointer is gone from both `RECENT` and `UNSEEN` - so it does cover the wiring, not only the helper. **The other new test covers less than its comment says.** `pool::tests::released_texture_pointer_is_not_kept_in_recent_or_unseen` passes on the head, and it **still passes** with that same line removed: it calls `forget_released(raw)` itself rather than releasing anything, so it tests the helper and not the path that calls it. Its doc comment ("Releasing a pooled texture clears its raw pointer from `RECENT` and `UNSEEN`") describes the other test. Not blocking - the second test covers the wiring - but the comment overstates what is checked. **What the parallel runs showed.** The whole `leonida-gpu` test binary was run in parallel, with the shape the report uses (`cargo test -p leonida-gpu --lib --features diagnostics -- --skip depth_bounds_pipeline_loads_and_filters_draws`), so that the other test threads are there to contend. This was done three times, twenty runs on the head and forty on the base: | | runs | |---|---| | the head `bce4a898b` | **20 passed, 0 failed** | | the base `7fbcd456e` | **33 passed, 7 failed** | The seven failures on the base were in **four** different tests, and only one of them is named in the report: ``` texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers panicked at crates\leonida-gpu\src\texture.rs:5664:17 assertion `left == right` failed: left: true, right: false (the pool race this pull request fixes: assert_eq!(pool::fresh(&copy.texture), false) reading true) [3 runs] watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view panicked at crates\leonida-gpu\src\watch.rs:6010:9 assertion `left == right` failed: left: Some([42241094]), right: Some([]) (the second guard() query expected the block to be free, and it was still guarded) [1 run] watch::tests::a_block_guarded_before_we_were_told_of_its_view_can_be_written panicked at crates\leonida-gpu\src\watch.rs:5343:9 assertion failed: !writable(at) && !writable(at + ...) [1 run] timeline::report::tests::real_waits_are_recorded_with_who_ended_them panicked at crates\leonida-gpu\src\timeline\report.rs:1459:9 assertion `left == right` failed: left: None, right: Some(20124) [2 runs] ``` **The two watch failures are in the file this pull request changes, under names the report does not list.** The report names `watch::tests::nothing_is_guarded_between_our_forgetting_it_and_its_unmapping` and `watch::tests::writes_to_views_are_not_lost`; the ones that actually fired here are `what_the_kernel_writes_through_is_not_guarded_for_another_view` and `a_block_guarded_before_we_were_told_of_its_view_can_be_written`. The first is the same shape the report describes - a view's address reused by another thread while this thread's guard state still listed the block, so the second `guard()` query found the block still guarded by somebody else - and the pull request's `watch.rs` change (ending the remapping window before `UnmapViewOfFile` returns the address to Windows, and `title_memory_unmapping` where `title_memory_remapped` was called) is aimed at exactly that window. Both of these tests should be named in the report, because they are the ones that failed here. **The timeline failure is a different race, in a file this pull request does not touch, and its cause is known.** `crates/leonida-gpu/src/timeline/report.rs:1459` is not covered by this pull request, and neither by #2884 (which fixes the `ROLLING.dropped_contention` counter in `timeline/record.rs`). The assertion reads `left: None`, so there was no wait of 10 ms or more to attribute at all: the test spawns the thread that is to wait on the mutex, sleeps a fixed 20 ms and then releases the lock, and under the load of the whole binary running in parallel the new thread sometimes has not reached the lock by then. It is filed as a separate `finding:` in #2570, because `cargo test --workspace` on `main` is red at random when it fires. Note the shape of the four pull requests: #2854 fixes the pool and watch races, #2884 fixes the `timeline/record.rs` race, and the `timeline/report.rs` race is a fourth one that nobody has taken. **A note on the rates.** A race that fires in one run out of ten does not fire in every set of ten, so the difference between the head and the base here is seven failures in forty against none, not a clean per-test verdict for each of the races. The deterministic control above is what shows the change is needed; the parallel runs show the suite is not yet clean. **Not checked:** the `descriptor` race in this pull request (it needs the same contention and did not fire in these sixty runs); the GPU crates under a real adapter (no GPU device here).
lixonik commented 2026-12-01 20:54:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-01T20:54:46Z.


@KelboLive @Neutron-0 Thanks for the thorough verification and mutation checks! Addressed the feedback in 81a6e94a9 and updated the PR description:

  1. Release ordering (pool.rs): moved forget_released(gone.raw) before lock(&TEXTURES).give(gone.piece, now()) so a texture reusing the COM address after give cannot have its fresh RECENT/UNSEEN entry wiped.
  2. Hermetic UNSEEN test (pool.rs): released_texture_pointer_is_not_kept_in_recent_or_unseen now inserts (raw, u64::MAX) directly into UNSEEN instead of calling note_unseen(..., 10, 5) (which ran retain across other tests' entries), and its doc comment now accurately states it tests forget_released directly while dropping_last_pooled_texture_reference_forgets_recent_and_unseen covers the COM release path.
  3. PR description: corrected the descriptor.rs race direction (assert!(host.made(5)) seeing false after a competing sync consumed the write-watch reset) and explicitly noted that the watch.rs remapping-drop reorder is not directly covered by a unit test.

Re-verified cargo test --locked -p leonida-gpu --lib pool:: (10/10 parallel runs, 19 passed, 0 failed) and scripts/check_no_game_data.py.

@DIGITALWORLD-PL Thanks for sharing the forced-interleaving confirmation on RTX 5090 -- that cleanly reproduces the exact assert!(host.made(5)) race direction!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7325460718 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7325460718). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-01T20:54:46Z. --- @KelboLive @Neutron-0 Thanks for the thorough verification and mutation checks! Addressed the feedback in `81a6e94a9` and updated the PR description: 1. **Release ordering (`pool.rs`):** moved `forget_released(gone.raw)` before `lock(&TEXTURES).give(gone.piece, now())` so a texture reusing the COM address after `give` cannot have its fresh `RECENT`/`UNSEEN` entry wiped. 2. **Hermetic `UNSEEN` test (`pool.rs`):** `released_texture_pointer_is_not_kept_in_recent_or_unseen` now inserts `(raw, u64::MAX)` directly into `UNSEEN` instead of calling `note_unseen(..., 10, 5)` (which ran `retain` across other tests' entries), and its doc comment now accurately states it tests `forget_released` directly while `dropping_last_pooled_texture_reference_forgets_recent_and_unseen` covers the COM release path. 3. **PR description:** corrected the `descriptor.rs` race direction (`assert!(host.made(5))` seeing `false` after a competing sync consumed the write-watch reset) and explicitly noted that the `watch.rs` remapping-drop reorder is not directly covered by a unit test. Re-verified `cargo test --locked -p leonida-gpu --lib pool::` (10/10 parallel runs, 19 passed, 0 failed) and `scripts/check_no_game_data.py`. @DIGITALWORLD-PL Thanks for sharing the forced-interleaving confirmation on RTX 5090 -- that cleanly reproduces the exact `assert!(host.made(5))` race direction!
merzleckeier commented 2026-12-01 21:12:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T21:12:55Z.


Real final-reference check at the pool return boundary on 81a6e94a merged into 1fff69129. The stock 32×32 real pooled texture test passed 3/3 on each of RTX 4070 SUPER (620.73.4) and Radeon RADV (26.3.1), Win64 Wine 11.22 / VKD3D-Proton 3.1.0.

I added the same observer immediately before TEXTURES.give, restricted to the test texture’s actual COM pointer. Both RECENT and UNSEEN were already empty for that pointer in all six runs with the updated order. Moving only forget_released back below give left both entries present at that point in all six comparison runs. Both arms still passed the assertions before final release and after cleanup. This distinguishes the ordering change from eventual cleanup. The probe did not force concurrent COM-pointer reuse.

Separately, the selected descriptor sync, alias cast and kernel-write watch tests passed 3/3 in all 24 starts across both trees, both GPUs, and one/eight test threads. The full serial Wine-builtin no-device suite reproduced the same three watch assertions on both trees in every repeat (holes_are_known_until_the_runtime_tells, no_mapping_is_lost_between_askers, what_is_left_alone_is_no_known_hole). Main reported 640 passes and the PR 642, both with three failures and 59 ignored.

MEASURED with synthetic inputs, OpenAI Codex and a separate read-only review.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7325916542 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7325916542). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T21:12:55Z. --- Real final-reference check at the pool return boundary on `81a6e94a` merged into `1fff69129`. The stock 32×32 real pooled texture test passed 3/3 on each of RTX 4070 SUPER (620.73.4) and Radeon RADV (26.3.1), Win64 Wine 11.22 / VKD3D-Proton 3.1.0. I added the same observer immediately before `TEXTURES.give`, restricted to the test texture’s actual COM pointer. Both `RECENT` and `UNSEEN` were already empty for that pointer in all six runs with the updated order. Moving only `forget_released` back below `give` left both entries present at that point in all six comparison runs. Both arms still passed the assertions before final release and after cleanup. This distinguishes the ordering change from eventual cleanup. The probe did not force concurrent COM-pointer reuse. Separately, the selected descriptor sync, alias cast and kernel-write watch tests passed 3/3 in all 24 starts across both trees, both GPUs, and one/eight test threads. The full serial Wine-builtin no-device suite reproduced the same three watch assertions on both trees in every repeat (`holes_are_known_until_the_runtime_tells`, `no_mapping_is_lost_between_askers`, `what_is_left_alone_is_no_known_hole`). Main reported 640 passes and the PR 642, both with three failures and 59 ignored. MEASURED with synthetic inputs, OpenAI Codex and a separate read-only review.
imShangLi commented 2026-12-01 23:45:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T23:45:16Z.


VERIFY-2854 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files

Verdict: PASS. The pooled-texture fix is a real bug fix and the ordering fix in the watch tests closes a window where an address could be handed back to Windows while a guard still held it. Nothing that passed before fails now.

Head bce4a898, base the current main, merge base 7fbcd456, 3 files, +92/−5: d3d12/crates/leonida-gpu/src/pool.rs, d3d12/crates/leonida-gpu/src/descriptor.rs, d3d12/crates/leonida-gpu/src/watch.rs.

1. What it changes

A pooled texture's address could be mistaken for a new one. pool.rs keeps two tables of raw pointers: RECENT (textures made in the last second) and UNSEEN (ones the GPU has not touched). When the last COM reference to a pooled texture went, Reclaim::release gave the piece back to the pool but left the raw pointer in both tables — and a new resource allocated at the same address would then be treated as one that was "made in the last second", which is what the commit and write-back heuristics read. The change removes it:

/// Removes a released pooled texture pointer from `RECENT` and `UNSEEN`
/// so a new resource allocated at the same address is not mistaken for it.
fn forget_released(raw: usize) {
    RECENT.lock().unwrap_or_else(|e| e.into_inner()).retain(|r| r.0 != raw);
    UNSEEN.lock().unwrap_or_else(|e| e.into_inner()).remove(&raw);
}

called from Reclaim::release, with the raw pointer carried in the Reclaim box.

An address could be handed back to Windows while a guard still held it. In watch.rs's tests the view was unmapped before the remapping guard was dropped, so another thread could take the address while g.changing still left its block alone. The change drops the guard first:

// End the remapping window before returning `at` to Windows so another
// thread cannot reuse the address while `g.changing` still leaves its block alone.
drop(changing);
assert!(!guards().left_alone(at / BLOCK));
// SAFETY: our view.
unsafe { UnmapViewOfFile(view) };

and the same order is used in many_askers_tests.

A test that raced the background sync thread. descriptor.rs gains a test-only mutex so a test that inspects a descriptor slot between two syncs cannot race the sync that writes it.

2. Red and green, run under Wine

leonida-gpu does not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it for x86_64-pc-windows-gnu and ran the tests under Wine 11.21.

The red side (the merge base with only this pull request's test changes) does not compile: the new test calls forget_released, which the change introduces (error[E0425]: cannot find function 'forget_released' in this scope). So the usual "the test fails on the base" cannot be shown, and I compared the base with the pull request's head instead:

the merge base 655 tests
the pull request's head 657 tests
the new tests, only on the head 2 — pool::tests::released_texture_pointer_is_not_kept_in_recent_or_unseen and pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen, both pass
tests that pass on the base and fail on the head 0
failing on both sides 3 (see below)

The three that fail on both sides are watch::many_askers_tests::holes_are_known_until_the_runtime_tells, watch::many_askers_tests::no_mapping_is_lost_between_askers and watch::tests::what_is_left_alone_is_no_known_hole — they are about which pages the runtime reports as known holes, and they fail identically with and without this change, so they are not this change's doing. They are the tests this pull request is about (it fixes races in them), and they need Microsoft's VirtualAlloc/VirtualQuery behaviour, which Wine does not have.

3. What I did not check

  • Whether the race the pull request fixes is the cause of the failures above. The three watch tests fail here on both sides, so I could not see them turn green; the pull request's own claim (that they are flaky under parallel runs) is not something I could confirm or refute here.
  • The pooled-texture path with a real device. pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen needs a host device (crate::host::host()) and returns early without one; under Wine a device exists, but I did not check that the texture really came back through the pool rather than through another path.
  • The commit and write-back heuristics that read RECENT and UNSEEN. I checked that the stale pointer is gone; I did not trace what the heuristics now decide differently.
  • Windows and MSVC. Everything above is Linux with Wine 11.21 (staging) and no GPU device.

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7329733130 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7329733130). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T23:45:16Z. --- ## VERIFY-2854 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files **Verdict: PASS.** The pooled-texture fix is a real bug fix and the ordering fix in the watch tests closes a window where an address could be handed back to Windows while a guard still held it. Nothing that passed before fails now. Head `bce4a898`, base the current `main`, merge base `7fbcd456`, 3 files, +92/−5: `d3d12/crates/leonida-gpu/src/pool.rs`, `d3d12/crates/leonida-gpu/src/descriptor.rs`, `d3d12/crates/leonida-gpu/src/watch.rs`. ### 1. What it changes **A pooled texture's address could be mistaken for a new one.** `pool.rs` keeps two tables of raw pointers: `RECENT` (textures made in the last second) and `UNSEEN` (ones the GPU has not touched). When the last COM reference to a pooled texture went, `Reclaim::release` gave the piece back to the pool but left the raw pointer in both tables — and a new resource allocated at the same address would then be treated as one that was "made in the last second", which is what the commit and write-back heuristics read. The change removes it: ```rust /// Removes a released pooled texture pointer from `RECENT` and `UNSEEN` /// so a new resource allocated at the same address is not mistaken for it. fn forget_released(raw: usize) { RECENT.lock().unwrap_or_else(|e| e.into_inner()).retain(|r| r.0 != raw); UNSEEN.lock().unwrap_or_else(|e| e.into_inner()).remove(&raw); } ``` called from `Reclaim::release`, with the raw pointer carried in the `Reclaim` box. **An address could be handed back to Windows while a guard still held it.** In `watch.rs`'s tests the view was unmapped *before* the remapping guard was dropped, so another thread could take the address while `g.changing` still left its block alone. The change drops the guard first: ```rust // End the remapping window before returning `at` to Windows so another // thread cannot reuse the address while `g.changing` still leaves its block alone. drop(changing); assert!(!guards().left_alone(at / BLOCK)); // SAFETY: our view. unsafe { UnmapViewOfFile(view) }; ``` and the same order is used in `many_askers_tests`. **A test that raced the background sync thread.** `descriptor.rs` gains a test-only mutex so a test that inspects a descriptor slot between two syncs cannot race the sync that writes it. ### 2. Red and green, run under Wine `leonida-gpu` does not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it for `x86_64-pc-windows-gnu` and ran the tests under Wine 11.21. The red side (the merge base with only this pull request's test changes) **does not compile**: the new test calls `forget_released`, which the change introduces (`error[E0425]: cannot find function 'forget_released' in this scope`). So the usual "the test fails on the base" cannot be shown, and I compared the base with the pull request's head instead: | | | |---|---| | the merge base | 655 tests | | the pull request's head | 657 tests | | the new tests, only on the head | 2 — `pool::tests::released_texture_pointer_is_not_kept_in_recent_or_unseen` and `pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen`, both pass | | tests that pass on the base and fail on the head | **0** | | failing on both sides | 3 (see below) | The three that fail on both sides are `watch::many_askers_tests::holes_are_known_until_the_runtime_tells`, `watch::many_askers_tests::no_mapping_is_lost_between_askers` and `watch::tests::what_is_left_alone_is_no_known_hole` — they are about which pages the runtime reports as known holes, and they fail identically with and without this change, so they are not this change's doing. They are the tests this pull request is *about* (it fixes races in them), and they need Microsoft's `VirtualAlloc`/`VirtualQuery` behaviour, which Wine does not have. ### 3. What I did not check - **Whether the race the pull request fixes is the cause of the failures above.** The three `watch` tests fail here on both sides, so I could not see them turn green; the pull request's own claim (that they are flaky under parallel runs) is not something I could confirm or refute here. - **The pooled-texture path with a real device.** `pool::tests::dropping_last_pooled_texture_reference_forgets_recent_and_unseen` needs a host device (`crate::host::host()`) and returns early without one; under Wine a device exists, but I did not check that the texture really came back through the pool rather than through another path. - **The commit and write-back heuristics that read `RECENT` and `UNSEEN`.** I checked that the stale pointer is gone; I did not trace what the heuristics now decide differently. - **Windows and MSVC.** Everything above is Linux with Wine 11.21 (staging) and no GPU device. AI-assisted: MiniMax M3.1 Flash.
andrew-ai commented 2026-12-02 00:19:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-02T00:19:12Z.


Native Windows verification with separate leonida-gpu library test executables at merge base 7fbcd456e and PR head 81a6e94a9. Each invocation started a fresh process with --test-threads 16.

Coverage Runs per revision Base, each run PR, each run
watch::tests:: 10 31 passed, 0 ignored 31 passed, 0 ignored
Full library, default features 3 600 passed, 55 ignored 602 passed, 55 ignored

No failures in either group. The full-suite runs exercised concurrent tests from other modules as well. The baseline flake did not reproduce here, so these results verify repeated passes on Windows without establishing a change in failure rate. Codex-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7330406133 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7330406133). Originally posted by [andrew-ai](https://github.com/andrew-ai) on 2026-12-02T00:19:12Z. --- Native Windows verification with separate leonida-gpu library test executables at merge base 7fbcd456e and PR head 81a6e94a9. Each invocation started a fresh process with --test-threads 16. | Coverage | Runs per revision | Base, each run | PR, each run | | --- | ---: | --- | --- | | watch::tests:: | 10 | 31 passed, 0 ignored | 31 passed, 0 ignored | | Full library, default features | 3 | 600 passed, 55 ignored | 602 passed, 55 ignored | No failures in either group. The full-suite runs exercised concurrent tests from other modules as well. The baseline flake did not reproduce here, so these results verify repeated passes on Windows without establishing a change in failure rate. Codex-assisted.
DIGITALWORLD-PL commented 2026-12-02 07:43:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DIGITALWORLD-PL on 2026-12-02T07:43:36Z.


Follow-up: I tested your TEST_SYNC_LOCK fix at 81a6e94a9 on Windows with a GeForce RTX 5090 (driver 621.01). In records_copied_as_bytes_are_made_at_the_next_sync, I paused a competing synchronization round after it took the dirty page for slot 5 and before it published the host descriptor.

Version No competing round Forced interleaving
Merge base 7fbcd456e 6/6 passed 6/6 failed
Your PR head 81a6e94a9 6/6 passed 6/6 passed
Your head with only the TEST_SYNC_LOCK acquisition inside sync_heaps() removed 6/6 passed 6/6 failed

Each group of six used three fresh processes with the helper thread and three with inline synchronization. All 12 failures hit the original positive assertion assert!(host.made(5)). The mutation kept the copy-side guard in place, isolating the contribution of the round-side lock. Three additional forced runs with the default helper and early-polling settings also passed on your head.

This confirms the descriptor fix for this controlled schedule. The selector verified the RTX 5090 D3D12 device by DXGI name and LUID. AI-assisted testing and review with OpenAI Codex (GPT-6.2 Astra).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7338533833 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7338533833). Originally posted by [DIGITALWORLD-PL](https://github.com/DIGITALWORLD-PL) on 2026-12-02T07:43:36Z. --- Follow-up: I tested your `TEST_SYNC_LOCK` fix at `81a6e94a9` on Windows with a GeForce RTX 5090 (driver 621.01). In `records_copied_as_bytes_are_made_at_the_next_sync`, I paused a competing synchronization round after it took the dirty page for slot 5 and before it published the host descriptor. | Version | No competing round | Forced interleaving | | --- | --- | --- | | Merge base `7fbcd456e` | 6/6 passed | **6/6 failed** | | Your PR head `81a6e94a9` | 6/6 passed | **6/6 passed** | | Your head with only the `TEST_SYNC_LOCK` acquisition inside `sync_heaps()` removed | 6/6 passed | **6/6 failed** | Each group of six used three fresh processes with the helper thread and three with inline synchronization. All 12 failures hit the original positive assertion `assert!(host.made(5))`. The mutation kept the copy-side guard in place, isolating the contribution of the round-side lock. Three additional forced runs with the default helper and early-polling settings also passed on your head. This confirms the descriptor fix for this controlled schedule. The selector verified the RTX 5090 D3D12 device by DXGI name and LUID. AI-assisted testing and review with OpenAI Codex (GPT-6.2 Astra).
MoonEyes commented 2026-12-02 13:15:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:15:57Z.


RUN (in game, grouped): this head 81a6e94a9 was merged with git merge --no-ff, together with nine other rendering pull requests, onto main f6dd2242e (no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11; scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2, low-memory profile, keyboard-driven entry into the world and a walking route.

  • At least 381 s in the world (time limit 330 s, then the run script stopped the game): no device loss, no unhandled exception, no hang or GPU stall in the log.
  • Rendering 14.7 frames/s median over the last 240 s (a single earlier run with the same launcher options on a different tree: 15.2).
  • Limits: one run, grouped, so a failure would not have named one pull request; the picture was not checked; free RAM was about 1.2 GB during the run.

Heads in this run: #2854 81a6e94a9, #2936 68215ad0b, #2939 561bbc19c, #2997 ef429f923, #3043 915d4d5aa, #3045 cb30a595a, #3046 0f19a0819, #3047 c33e5b48e, #3048 2ab0b4b9d, #3051 856615ce7.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7346604225 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7346604225). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T13:15:57Z. --- RUN (in game, grouped): this head `81a6e94a9` was merged with `git merge --no-ff`, together with nine other rendering pull requests, onto `main` `f6dd2242e` (no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11; `scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2`, low-memory profile, keyboard-driven entry into the world and a walking route. - At least 381 s in the world (time limit 330 s, then the run script stopped the game): no device loss, no unhandled exception, no hang or GPU stall in the log. - Rendering 14.7 frames/s median over the last 240 s (a single earlier run with the same launcher options on a different tree: 15.2). - Limits: one run, grouped, so a failure would not have named one pull request; the picture was not checked; free RAM was about 1.2 GB during the run. Heads in this run: #2854 81a6e94a9, #2936 68215ad0b, #2939 561bbc19c, #2997 ef429f923, #3043 915d4d5aa, #3045 cb30a595a, #3046 0f19a0819, #3047 c33e5b48e, #3048 2ab0b4b9d, #3051 856615ce7. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-12-02 13:19:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:19:33Z.


Merging. Head 81a6e94a9 merges cleanly with main bf7886746 and does not force a rebase of #2566. Checked on head 81a6e94a9: all 6 CI checks green; third-party red/green by DIGITALWORLD-PL (RTX 5090) on this head; an in-game run of at least 381 s with this head merged onto main f6dd2242e (grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7346697429 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2854#issuecomment-7346697429). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T13:19:33Z. --- Merging. Head `81a6e94a9` merges cleanly with `main` `bf7886746` and does not force a rebase of #2566. Checked on head 81a6e94a9: all 6 CI checks green; third-party red/green by DIGITALWORLD-PL (RTX 5090) on this head; an in-game run of at least 381 s with this head merged onto main f6dd2242e (grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes. AI-assisted (Claude Code).
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
ProjectLeonida/mandy!2854
No description provided.