[PR #2094] [MERGED] d3d12: evict geometry views on range release and retry refused ranges #2100

Closed
opened 2026-11-26 21:20:02 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2094
Author: @qhukz13
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: cont/geometry-view-eviction


📝 Commits (9)

  • e54c691 d3d12: evict geometry views on range release and retry refused ranges
  • c09ee75 d3d12: geometry views drain on the submit thread, bound the release queue, keep one empty block
  • 6fd430e d3d12: deliver a released title range to every device's geometry views
  • 7d38eee Merge main into RT-GEOMETRY-VIEW-EVICTION
  • 861bb05 d3d12: reap a retired geometry view only after the replays that may name it
  • 266f335 d3d12: a retired geometry view invalidates the answers it made without an alias
  • b21b47b d3d12: no table keeps naming a destroyed title-window block
  • 702fbaa test: keep geometry_views_test's GeometryViews off the stack
  • bbc8ef1 test: geometry views across a submission's replays, invalidation and block removal

📊 Changes

8 files changed (+1083 additions, -107 deletions)

View changed files

📝 runtime/shims/d3d12_geometry_views.h (+397 -66)
📝 runtime/shims/d3d12_title_buffer_windows.h (+147 -31)
📝 runtime/shims/d3d12_vulkan_device.cpp (+58 -4)
📝 runtime/shims/xmem.cpp (+26 -3)
📝 runtime/src/title_geometry_watch.h (+80 -0)
📝 runtime/src/title_va_alias.h (+13 -0)
📝 runtime/src/vulkan_backend.h (+10 -0)
📝 runtime/test/geometry_views_test.cpp (+352 -3)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2094 **Author:** [@qhukz13](https://github.com/qhukz13) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `cont/geometry-view-eviction` --- ### 📝 Commits (9) - [`e54c691`](https://github.com/ubiquitarianism/leonida/commit/e54c69175a86e347cfc544bddf6e66570c9726d7) d3d12: evict geometry views on range release and retry refused ranges - [`c09ee75`](https://github.com/ubiquitarianism/leonida/commit/c09ee75c0e194554a8746ddbd558092f52e929c3) d3d12: geometry views drain on the submit thread, bound the release queue, keep one empty block - [`6fd430e`](https://github.com/ubiquitarianism/leonida/commit/6fd430ebc751e17bf2e29a560bc87c9b8d57e491) d3d12: deliver a released title range to every device's geometry views - [`7d38eee`](https://github.com/ubiquitarianism/leonida/commit/7d38eee1163a8a825cc2506b2e931c5313f45014) Merge main into RT-GEOMETRY-VIEW-EVICTION - [`861bb05`](https://github.com/ubiquitarianism/leonida/commit/861bb0546e0fa11f22b6550e576fa21ed9b445b5) d3d12: reap a retired geometry view only after the replays that may name it - [`266f335`](https://github.com/ubiquitarianism/leonida/commit/266f335dda39d8807f6ee5f44e89d5514d85ee8a) d3d12: a retired geometry view invalidates the answers it made without an alias - [`b21b47b`](https://github.com/ubiquitarianism/leonida/commit/b21b47b052f4c5f190d319a1519b1accf9a2e418) d3d12: no table keeps naming a destroyed title-window block - [`702fbaa`](https://github.com/ubiquitarianism/leonida/commit/702fbaa96963eb809ecbbfcf3e1472f69fbbd5fc) test: keep geometry_views_test's GeometryViews off the stack - [`bbc8ef1`](https://github.com/ubiquitarianism/leonida/commit/bbc8ef17c639b2838a3b290559ca3d5623d70752) test: geometry views across a submission's replays, invalidation and block removal ### 📊 Changes **8 files changed** (+1083 additions, -107 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/d3d12_geometry_views.h` (+397 -66) 📝 `runtime/shims/d3d12_title_buffer_windows.h` (+147 -31) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+58 -4) 📝 `runtime/shims/xmem.cpp` (+26 -3) 📝 `runtime/src/title_geometry_watch.h` (+80 -0) 📝 `runtime/src/title_va_alias.h` (+13 -0) 📝 `runtime/src/vulkan_backend.h` (+10 -0) 📝 `runtime/test/geometry_views_test.cpp` (+352 -3) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:20:02 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2100
No description provided.