d3d12: evict geometry views on range release and retry refused ranges #2094

Merged
qhukz13 merged 9 commits from upstream-pr/2094 into main 2026-11-26 02:43:17 +00:00
qhukz13 commented 2026-11-25 20:04:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-25T20:04:41Z.


Item: RT-GEOMETRY-VIEW-EVICTION

Problem

runtime/shims/d3d12_geometry_views.h: once LEONIDA_GEOMETRY_MB is used up, resolve() marks a range refused for good, and no view is freed before teardown, even after the title releases the memory it copies.

Change

  • Release events. xmem reports title ranges that go away: XMemFree/XMemFreeDefault, VirtualFree MEM_RELEASE/MEM_DECOMMIT, the XMemMapPhysicalPages unmap and the CopyPageMappingsBatchX unmap range. They go to a small queue in title_geometry_watch.h (note_released/take_released). Ranges outside every watched tile are not queued; a GPU-only range counts through its CPU view, where the views are keyed. When the queue is full it collapses into one covering range: retiring a few views too many is harmless (they are made again on the next resolve), dropping a release is not.
  • Retire, then reap. On the submit thread (before_execute_, before the geometry refresh) a released range retires every view over it at once: it leaves keys_, the address map, the fast lookup, the tile watches and the title VA aliases. Its storage is freed only once completed_retire_ticket() passes the submitted_retire_ticket() taken at retirement, so in-flight work keeps reading valid memory. The recording threads never drain, so they do not wait on GeometryViews::mutex_ while a refresh holds it (speed-26).
  • Retry. A refused key remembers the free generation it was refused in. resolve() answers it from the fast map without a lock while nothing was freed, and tries again once a reap has returned budget.
  • Storage. TitleBufferWindows keeps coalesced free ranges per block, destroys a block when its last range comes back, and keeps one empty 4 MiB block as a spare (dropped when a larger request needs the cap), so a title that frees and reallocates each frame does not allocate Vulkan memory each frame. The 2 s backoff after a driver refusal is kept.
  • refresh() walks the tiles by key (lower_bound) instead of holding a std::map iterator and raw Tile* across its periodic unlock, because a retirement can now erase a tile in that window.

Nothing changes while under the cap, and with LEONIDA_GEOMETRY_MB=0 (default) note_released returns on one atomic load.

Testing

Windows 10 Pro 19045, GeForce GTX 1050 Ti (Pascal, 4 GB, no Resizable BAR), NVIDIA 582.66, MSVC (VS 18 Build Tools), RelWithDebInfo, base 9f9a7c5f3.

  • geometry_views_test (extended: small cap, refusal and retry, deferred reap before/at the ticket, block reclamation, watched-bounds filter, GPU-only twin, queue overflow, spare block): 51 checks, 3/3 passes.
  • Full ctest (with #2059 applied): 449 tests, 13 failed. All 13 also fail on plain 9f9a7c5f3 (16 failures there); the other three are d3d12_compute and d3d12_geometry_views, which #2059 fixes, and xmem, which is flaky on this host (5/5 on rerun, also without this branch). No test that passes on main fails here.
  • 3x, plain and with LEONIDA_VK_VALIDATION=1: geometry_views, xmem*, d3d12_title_va*, d3d12_geometry_views, d3d12_title_window_cap, d3d12_api_descriptor_copy*, d3d12_rebound*, d3d12_compute, d3d12_xmem_placed: 17/17 pass, no validation messages.
  • On Windows 10, d3d12_geometry_views only reaches the geometry code with #2059 (root signature serialization); the integration numbers above were taken with #2059 applied locally.

AI-assisted (Claude Code, Opus 5.5, with Antigravity / Gemini 4 Neon for the first draft of the code; every change reviewed and the GPU-only filter case fixed by hand).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5498300898 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2094). Originally posted by [qhukz13](https://github.com/qhukz13) on 2026-11-25T20:04:41Z. --- Item: `RT-GEOMETRY-VIEW-EVICTION` ### Problem `runtime/shims/d3d12_geometry_views.h`: once `LEONIDA_GEOMETRY_MB` is used up, `resolve()` marks a range refused for good, and no view is freed before teardown, even after the title releases the memory it copies. ### Change - **Release events.** `xmem` reports title ranges that go away: `XMemFree`/`XMemFreeDefault`, `VirtualFree` `MEM_RELEASE`/`MEM_DECOMMIT`, the `XMemMapPhysicalPages` unmap and the `CopyPageMappingsBatchX` unmap range. They go to a small queue in `title_geometry_watch.h` (`note_released`/`take_released`). Ranges outside every watched tile are not queued; a GPU-only range counts through its CPU view, where the views are keyed. When the queue is full it collapses into one covering range: retiring a few views too many is harmless (they are made again on the next resolve), dropping a release is not. - **Retire, then reap.** On the submit thread (`before_execute_`, before the geometry refresh) a released range retires every view over it at once: it leaves `keys_`, the address map, the fast lookup, the tile watches and the title VA aliases. Its storage is freed only once `completed_retire_ticket()` passes the `submitted_retire_ticket()` taken at retirement, so in-flight work keeps reading valid memory. The recording threads never drain, so they do not wait on `GeometryViews::mutex_` while a refresh holds it (speed-26). - **Retry.** A refused key remembers the free generation it was refused in. `resolve()` answers it from the fast map without a lock while nothing was freed, and tries again once a reap has returned budget. - **Storage.** `TitleBufferWindows` keeps coalesced free ranges per block, destroys a block when its last range comes back, and keeps one empty 4 MiB block as a spare (dropped when a larger request needs the cap), so a title that frees and reallocates each frame does not allocate Vulkan memory each frame. The 2 s backoff after a driver refusal is kept. - `refresh()` walks the tiles by key (`lower_bound`) instead of holding a `std::map` iterator and raw `Tile*` across its periodic unlock, because a retirement can now erase a tile in that window. Nothing changes while under the cap, and with `LEONIDA_GEOMETRY_MB=0` (default) `note_released` returns on one atomic load. ### Testing Windows 10 Pro 19045, GeForce GTX 1050 Ti (Pascal, 4 GB, no Resizable BAR), NVIDIA 582.66, MSVC (VS 18 Build Tools), RelWithDebInfo, base `9f9a7c5f3`. - `geometry_views_test` (extended: small cap, refusal and retry, deferred reap before/at the ticket, block reclamation, watched-bounds filter, GPU-only twin, queue overflow, spare block): 51 checks, 3/3 passes. - Full ctest (with #2059 applied): 449 tests, 13 failed. All 13 also fail on plain `9f9a7c5f3` (16 failures there); the other three are `d3d12_compute` and `d3d12_geometry_views`, which #2059 fixes, and `xmem`, which is flaky on this host (5/5 on rerun, also without this branch). No test that passes on main fails here. - 3x, plain and with `LEONIDA_VK_VALIDATION=1`: `geometry_views`, `xmem*`, `d3d12_title_va*`, `d3d12_geometry_views`, `d3d12_title_window_cap`, `d3d12_api_descriptor_copy*`, `d3d12_rebound*`, `d3d12_compute`, `d3d12_xmem_placed`: 17/17 pass, no validation messages. - On Windows 10, `d3d12_geometry_views` only reaches the geometry code with #2059 (root signature serialization); the integration numbers above were taken with #2059 applied locally. AI-assisted (Claude Code, Opus 5.5, with Antigravity / Gemini 4 Neon for the first draft of the code; every change reviewed and the GPU-only filter case fixed by hand). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lixonik commented 2026-11-25 20:46:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T20:46:43Z.

Review: COMMENTED


Native Windows review of this head. geometry_views passed its existing 51 checks and xmem passed on retry. The additional two-device case below failed. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6064759576 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2094#pullrequestreview-6064759576). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T20:46:43Z. **Review:** COMMENTED --- Native Windows review of this head. `geometry_views` passed its existing 51 checks and `xmem` passed on retry. The additional two-device case below failed. AI-assisted.
lixonik commented 2026-11-25 20:46:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T20:46:43Z.

Code review location: runtime/shims/d3d12_geometry_views.h; line 438

@@ -209,19 +327,131 @@ class GeometryViews {
             tile.views.push_back(id);
             ready &= !tile.retry;
         }
-        if (ready) fill(views_.back(), copy);
+        if (ready) fill(views_[id], copy);
         else {
             std::memset(mapped, 0, bytes);
             cleared_ += bytes;
-            views_.back().zeroed = true;
+            views_[id].zeroed = true;
         }
-        publish(key, va);
+        publish(key, va, 0);
         return va;
     }
 
+    // Retires every live view overlapping [begin, end), unlinking it from lookup/refresh/watch immediately and
+    // deferring its backing storage reclamation until GPU submissions through `retire_ticket` have completed.
+    template<class OnRetire = NoopRetire>
+    std::size_t retire_range(Address begin, Address end, std::uint64_t retire_ticket = 0,
+                             OnRetire&& on_retire = {}) {
+        if (end <= begin) return 0;
+        struct CallbackItem {
+            Address source;
+            std::size_t size;
+            VkDeviceSize va;
+        };
+        std::vector<CallbackItem> callbacks;
+        {
+            std::lock_guard lock(mutex_);
+            std::vector<std::size_t> ids;
+            const Key key_start{begin > max_view_bytes_ ? begin - max_view_bytes_ : Address(0), 0};
+            for (auto it = keys_.lower_bound(key_start); it != keys_.end(); ++it) {
+                const auto& [key, id] = *it;
+                if (key.first >= end) break;
+                if (begin < key.first + key.second) ids.push_back(id);
+            }
+            std::vector<Key> stale_refused;
+            const Key refused_start{begin > max_refused_bytes_ ? begin - max_refused_bytes_ : Address(0), 0};
+            for (auto it = refused_.lower_bound(refused_start); it != refused_.end(); ++it) {
+                const auto& key = it->first;
+                if (key.first >= end) break;
+                if (begin < key.first + key.second) stale_refused.push_back(key);
+            }
+            if (ids.empty() && stale_refused.empty()) return 0;
+            callbacks.reserve(ids.size());
+            for (const auto id : ids) {
+                View& v = views_[id];
+                detach_tiles_locked(id, v.source, v.size);
+                if (v.ready) {
+                    --ready_;
+                    v.ready = false;
+                }
+                callbacks.push_back({v.source, v.size, v.va});
+                retired_.push_back({v.va, v.size, retire_ticket});
+            }
+            if (!ids.empty()) {
+                std::unique_lock structure(structure_mutex_);
+                for (const auto id : ids) {
+                    View& v = views_[id];
+                    keys_.erase({v.source, v.size});
+                    by_address_.erase(v.bda);
+                    v.alive = false;
+                }
+            }
+            {
+                std::unique_lock fast(fast_mutex_);
+                for (const auto id : ids) fast_.erase({views_[id].source, views_[id].size});
+                for (const auto& k : stale_refused) fast_.erase(k);
+            }
+            for (const auto& k : stale_refused) refused_.erase(k);
+            for (const auto id : ids) {
+                free_ids_.push_back(id);
+                --live_views_;
+                ++evicted_;
+            }
+            retired_count_.store(retired_.size(), std::memory_order_release);
+        }
+        for (const auto& item : callbacks) on_retire(item.source, item.size, item.va);
+        return callbacks.size();
+    }
+
+    // Frees backing storage for retired views whose GPU retire_ticket <= completed_ticket, returning their budget
+    // and bumping free_generation_ so previously refused ranges retry on the next resolve().
+    template<class Device>
+    std::size_t reap(Device& device, std::uint64_t completed_ticket = UINT64_MAX) {
+        if (!has_retired()) return 0;
+        std::lock_guard lock(mutex_);
+        std::size_t freed = 0;
+        std::size_t keep = 0;
+        for (std::size_t i = 0; i < retired_.size(); ++i) {
+            const Retired& r = retired_[i];
+            if (r.ticket <= completed_ticket) {
+                pool_.free(device, r.va, r.size);
+                bytes_ -= r.size;
+                ++reaped_;
+                ++freed;
+            } else {
+                if (keep != i) retired_[keep] = r;
+                ++keep;
+            }
+        }
+        retired_.resize(keep);
+        retired_count_.store(retired_.size(), std::memory_order_release);
+        if (freed) free_generation_.fetch_add(1, std::memory_order_release);
+        return freed;
+    }
+
+    // Drains released title ranges recorded by xmem (retiring matching views at `retire_ticket`) and reaps retired
+    // views whose GPU work completed by `completed_ticket`.
+    template<class Device, class OnRetire = NoopRetire>
+    void drain_released(Device& device, std::uint64_t retire_ticket, std::uint64_t completed_ticket,
+                        OnRetire&& on_retire = {}) {
+        std::vector<std::pair<Address, Address>> ranges;
+        leonida::geometry_writes::take_released(ranges);

[P2] Deliver a release to every device that owns a view of the range. take_released() removes the notification from a process-wide queue, but this call only retires views in the current DeviceState. I reproduced this with two GeometryViews instances over the same synthetic title extent: resolve it in both, queue one note_released, then drain both with completed tickets. The first drops the view and frees its charged bytes. The second retains the old view and its charged bytes indefinitely because its drain sees an empty queue. Could the queue route releases to the affected owners, with each owner retiring against its own submission tickets?

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4700678287 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2094#discussion_r4700678287). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T20:46:43Z. **Code review location:** `runtime/shims/d3d12_geometry_views.h`; line 438 ~~~~diff @@ -209,19 +327,131 @@ class GeometryViews { tile.views.push_back(id); ready &= !tile.retry; } - if (ready) fill(views_.back(), copy); + if (ready) fill(views_[id], copy); else { std::memset(mapped, 0, bytes); cleared_ += bytes; - views_.back().zeroed = true; + views_[id].zeroed = true; } - publish(key, va); + publish(key, va, 0); return va; } + // Retires every live view overlapping [begin, end), unlinking it from lookup/refresh/watch immediately and + // deferring its backing storage reclamation until GPU submissions through `retire_ticket` have completed. + template<class OnRetire = NoopRetire> + std::size_t retire_range(Address begin, Address end, std::uint64_t retire_ticket = 0, + OnRetire&& on_retire = {}) { + if (end <= begin) return 0; + struct CallbackItem { + Address source; + std::size_t size; + VkDeviceSize va; + }; + std::vector<CallbackItem> callbacks; + { + std::lock_guard lock(mutex_); + std::vector<std::size_t> ids; + const Key key_start{begin > max_view_bytes_ ? begin - max_view_bytes_ : Address(0), 0}; + for (auto it = keys_.lower_bound(key_start); it != keys_.end(); ++it) { + const auto& [key, id] = *it; + if (key.first >= end) break; + if (begin < key.first + key.second) ids.push_back(id); + } + std::vector<Key> stale_refused; + const Key refused_start{begin > max_refused_bytes_ ? begin - max_refused_bytes_ : Address(0), 0}; + for (auto it = refused_.lower_bound(refused_start); it != refused_.end(); ++it) { + const auto& key = it->first; + if (key.first >= end) break; + if (begin < key.first + key.second) stale_refused.push_back(key); + } + if (ids.empty() && stale_refused.empty()) return 0; + callbacks.reserve(ids.size()); + for (const auto id : ids) { + View& v = views_[id]; + detach_tiles_locked(id, v.source, v.size); + if (v.ready) { + --ready_; + v.ready = false; + } + callbacks.push_back({v.source, v.size, v.va}); + retired_.push_back({v.va, v.size, retire_ticket}); + } + if (!ids.empty()) { + std::unique_lock structure(structure_mutex_); + for (const auto id : ids) { + View& v = views_[id]; + keys_.erase({v.source, v.size}); + by_address_.erase(v.bda); + v.alive = false; + } + } + { + std::unique_lock fast(fast_mutex_); + for (const auto id : ids) fast_.erase({views_[id].source, views_[id].size}); + for (const auto& k : stale_refused) fast_.erase(k); + } + for (const auto& k : stale_refused) refused_.erase(k); + for (const auto id : ids) { + free_ids_.push_back(id); + --live_views_; + ++evicted_; + } + retired_count_.store(retired_.size(), std::memory_order_release); + } + for (const auto& item : callbacks) on_retire(item.source, item.size, item.va); + return callbacks.size(); + } + + // Frees backing storage for retired views whose GPU retire_ticket <= completed_ticket, returning their budget + // and bumping free_generation_ so previously refused ranges retry on the next resolve(). + template<class Device> + std::size_t reap(Device& device, std::uint64_t completed_ticket = UINT64_MAX) { + if (!has_retired()) return 0; + std::lock_guard lock(mutex_); + std::size_t freed = 0; + std::size_t keep = 0; + for (std::size_t i = 0; i < retired_.size(); ++i) { + const Retired& r = retired_[i]; + if (r.ticket <= completed_ticket) { + pool_.free(device, r.va, r.size); + bytes_ -= r.size; + ++reaped_; + ++freed; + } else { + if (keep != i) retired_[keep] = r; + ++keep; + } + } + retired_.resize(keep); + retired_count_.store(retired_.size(), std::memory_order_release); + if (freed) free_generation_.fetch_add(1, std::memory_order_release); + return freed; + } + + // Drains released title ranges recorded by xmem (retiring matching views at `retire_ticket`) and reaps retired + // views whose GPU work completed by `completed_ticket`. + template<class Device, class OnRetire = NoopRetire> + void drain_released(Device& device, std::uint64_t retire_ticket, std::uint64_t completed_ticket, + OnRetire&& on_retire = {}) { + std::vector<std::pair<Address, Address>> ranges; + leonida::geometry_writes::take_released(ranges); ~~~~ --- [P2] Deliver a release to every device that owns a view of the range. `take_released()` removes the notification from a process-wide queue, but this call only retires views in the current `DeviceState`. I reproduced this with two `GeometryViews` instances over the same synthetic title extent: resolve it in both, queue one `note_released`, then drain both with completed tickets. The first drops the view and frees its charged bytes. The second retains the old view and its charged bytes indefinitely because its drain sees an empty queue. Could the queue route releases to the affected owners, with each owner retiring against its own submission tickets?
qhukz13 commented 2026-11-25 22:23:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-25T22:23:47Z.


Thanks, confirmed and fixed in 6fd430ebc. The release queue was process-wide while every DeviceState owns its own GeometryViews, so the first device to drain took every release.

  • title_geometry_watch.h: each GeometryViews now owns a ReleaseQueue and subscribes it on construction (unsubscribes in its destructor). note_released keeps the same filters (watched bounds, GPU-only twin) and then appends the range to every subscribed queue, each with the 65536-entry collapse on its own. Lock order is subscribers -> queue; take_released takes only its own queue.
  • Each owner drains its own queue in its before_execute_ and retires against its own submitted_retire_ticket() / completed_retire_ticket(), as you suggested.
  • geometry_views_test case 12 is your scenario: two instances over the same synthetic extent, one note_released, both drained -> both retire and reap the view and return to bytes() == 0. It also checks that an instance destroyed in a scope stops receiving releases while the survivor still does.

GTX 1050 Ti, Windows 10 19045, NVIDIA 582.66, MSVC RelWithDebInfo: geometry_views_test 60 checks, 3/3 passes. Full ctest with #2059 applied (for d3d12_geometry_views on Windows 10): 449 tests, the same 13 failures as before this commit, all of which fail on plain 9f9a7c5f3 too; geometry_views, xmem*, d3d12_title_va*, d3d12_geometry_views, d3d12_compute and the other title-VA cases pass 3x plain and 3x with LEONIDA_VK_VALIDATION=1, no validation messages.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7176309362 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2094#issuecomment-7176309362). Originally posted by [qhukz13](https://github.com/qhukz13) on 2026-11-25T22:23:47Z. --- Thanks, confirmed and fixed in 6fd430ebc. The release queue was process-wide while every `DeviceState` owns its own `GeometryViews`, so the first device to drain took every release. - `title_geometry_watch.h`: each `GeometryViews` now owns a `ReleaseQueue` and subscribes it on construction (unsubscribes in its destructor). `note_released` keeps the same filters (watched bounds, GPU-only twin) and then appends the range to every subscribed queue, each with the 65536-entry collapse on its own. Lock order is subscribers -> queue; `take_released` takes only its own queue. - Each owner drains its own queue in its `before_execute_` and retires against its own `submitted_retire_ticket()` / `completed_retire_ticket()`, as you suggested. - `geometry_views_test` case 12 is your scenario: two instances over the same synthetic extent, one `note_released`, both drained -> both retire and reap the view and return to `bytes() == 0`. It also checks that an instance destroyed in a scope stops receiving releases while the survivor still does. GTX 1050 Ti, Windows 10 19045, NVIDIA 582.66, MSVC RelWithDebInfo: `geometry_views_test` 60 checks, 3/3 passes. Full ctest with #2059 applied (for `d3d12_geometry_views` on Windows 10): 449 tests, the same 13 failures as before this commit, all of which fail on plain `9f9a7c5f3` too; `geometry_views`, `xmem*`, `d3d12_title_va*`, `d3d12_geometry_views`, `d3d12_compute` and the other title-VA cases pass 3x plain and 3x with `LEONIDA_VK_VALIDATION=1`, no validation messages. AI-assisted (Claude Code).
moffington commented 2026-11-26 01:31:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by moffington on 2026-11-26T01:31:01Z.


Checked 6fd430ebc on Linux/Wine (clang++ --target=x86_64-w64-windows-gnu): geometry_views_test passes all 60 checks (0 failures), confirming the per-GeometryViews ReleaseQueue subscription fix for multi-device release delivery.

Three findings still remain on 6fd430ebc:

  1. Confirmed in local probe (RetireTickets/GeometryViews) + code inspection — Cross-queue retirement ticket race (DeviceState::drain_geometry_releases): retire_ticket = context->submitted_retire_ticket() is sampled before unlinking outside the replay/submit critical section. Another queue that already captured a geometry VA during replay and publishes its submission afterward can get a higher ticket than the retirement cutoff; if the prior ticket is already complete, reap reclaims the backing while the newer submission is still pending (FAIL backing still holds queue A's data while ticket 6 is incomplete).
  2. Code inspection — before_execute_ ordering (refresh_shadows before drain_geometry_releases): fix_console_slot can resolve a title V# into a live geometry view, and drain_geometry_releases in the same before_execute_ can immediately unlink and reap it before the batch executes (and without an alias entry, TitleVaAliases::remove will not bump the generation).
  3. Code inspection — 65,537-entry overflow collapse in raw address space: When a subscriber's ReleaseQueue overflows, note_released collapses [min_begin, max_end) in the original address space, and drain_released only translates the collapsed range if its start is a GPU address. An unrelated CPU release below a GPU twin can mask the GPU-only event's CPU twin if the CPU twin lies outside [min_begin, max_end).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7179849008 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2094#issuecomment-7179849008). Originally posted by [moffington](https://github.com/moffington) on 2026-11-26T01:31:01Z. --- Checked `6fd430ebc` on Linux/Wine (`clang++ --target=x86_64-w64-windows-gnu`): `geometry_views_test` passes all 60 checks (0 failures), confirming the per-`GeometryViews` `ReleaseQueue` subscription fix for multi-device release delivery. Three findings still remain on `6fd430ebc`: 1. **Confirmed in local probe (`RetireTickets`/`GeometryViews`) + code inspection — Cross-queue retirement ticket race (`DeviceState::drain_geometry_releases`)**: `retire_ticket = context->submitted_retire_ticket()` is sampled before unlinking outside the replay/submit critical section. Another queue that already captured a geometry VA during replay and publishes its submission afterward can get a higher ticket than the retirement cutoff; if the prior ticket is already complete, `reap` reclaims the backing while the newer submission is still pending (`FAIL backing still holds queue A's data while ticket 6 is incomplete`). 2. **Code inspection — `before_execute_` ordering (`refresh_shadows` before `drain_geometry_releases`)**: `fix_console_slot` can resolve a title V# into a live geometry view, and `drain_geometry_releases` in the same `before_execute_` can immediately unlink and reap it before the batch executes (and without an alias entry, `TitleVaAliases::remove` will not bump the generation). 3. **Code inspection — 65,537-entry overflow collapse in raw address space**: When a subscriber's `ReleaseQueue` overflows, `note_released` collapses `[min_begin, max_end)` in the original address space, and `drain_released` only translates the collapsed range if its start is a GPU address. An unrelated CPU release below a GPU twin can mask the GPU-only event's CPU twin if the CPU twin lies outside `[min_begin, max_end)`. AI-assisted.
aslan2142 commented 2026-11-26 02:43:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-26T02:43:20Z.


Merged, thanks @qhukz13! Freeing geometry views when the title releases their range is a real gain under a cap. We merged main in and fixed what the review found:

  • Reap race: a retired view is freed only after every replay that may name it has recorded and completed its submissions (a new after-execute hook), and the drain runs before the console heaps are translated.
  • Answers without an alias: retirement now invalidates them too (TitleVaAliases::forget_copy), so heap slots and the GPU key table drop a reaped view.
  • Destroyed blocks: a destroyed block leaves #2098's published_ and the backed table (layout_generation, title_block_gone).
  • Tests: geometry_views_test keeps its views off the stack; its new case 13 covers the race, the invalidation and the block removal, and fails without these fixes.
  • Tested: the full Windows suite under Wine on the gfx1036 iGPU (RADV), merged onto main 3abb99cad: area tests 28/28, and nothing failing that doesn't fail on main too.
  • Left for later: a DeviceState-level test, and command lists executed again keep the root VAs resolved when they were recorded.
  • Checked on main 86dc3d86e + bbc8ef17c: it merges cleanly; the semantic suite passes (496 files, 6,336 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 8 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7181059687 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2094#issuecomment-7181059687). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-26T02:43:20Z. --- Merged, thanks @qhukz13! Freeing geometry views when the title releases their range is a real gain under a cap. We merged `main` in and fixed what the review found: - **Reap race:** a retired view is freed only after every replay that may name it has recorded and completed its submissions (a new after-execute hook), and the drain runs before the console heaps are translated. - **Answers without an alias:** retirement now invalidates them too (`TitleVaAliases::forget_copy`), so heap slots and the GPU key table drop a reaped view. - **Destroyed blocks:** a destroyed block leaves #2098's `published_` and the backed table (`layout_generation`, `title_block_gone`). - **Tests:** `geometry_views_test` keeps its views off the stack; its new case 13 covers the race, the invalidation and the block removal, and fails without these fixes. - **Tested:** the full Windows suite under Wine on the gfx1036 iGPU (RADV), merged onto `main` `3abb99cad`: area tests 28/28, and nothing failing that doesn't fail on `main` too. - **Left for later:** a DeviceState-level test, and command lists executed again keep the root VAs resolved when they were recorded. - **Checked on `main` `86dc3d86e` + `bbc8ef17c`:** it merges cleanly; the semantic suite passes (496 files, 6,336 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 8 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
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!2094
No description provided.