Cache repeated title VA alias lookups (RT-TITLE-VA-POSITIVE-LOOKUP-CACHE) #2065

Closed
alexandersato0830 wants to merge 1 commit from upstream-pr/2065 into main
alexandersato0830 commented 2026-11-25 19:22:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by alexandersato0830 on 2026-11-25T19:22:24Z.


Claimed in the coordination issue as: RT-TITLE-VA-POSITIVE-LOOKUP-CACHE

Depends on: #1699 (overlapping test include hunk; the runtime change applies independently).

What and why

Repeated lookups in one title VA range acquire a shared lock and search the map each time. Cache one positive mapping per thread after two uncached lookups in the same range. A cache hit checks range bounds, the table's invalidation counter and its instance identity. Other requests still query the live map. Original finding

The draft records the lookup tradeoff so it can be evaluated with runtime traces. The retail lookup mix and frame-time impact remain unmeasured.

Tested

  • Native Windows 11, MSVC 19.51, on public main 490f5b9 plus this patch. All ten targeted CTests passed, including title_va_alias, d3d12_title_va, shadow and geometry views, the window cap, and descriptor copy and table rebound on/off paths. The new regression checks range bounds, deletion, replacement across threads, and reuse of the same storage for a new table. Removing either guard made the test fail.
  • Ryzen 9 7950X3D, single pinned thread, MSVC /O2. One executable compared the original and patched header, interleaving five timed samples per case. Each sample made five passes over 524,288 precomputed inputs. The tests used 32, 1,024 and 4,096 64 KiB ranges. Hot queries moved to a new range every 1,000 lookups, and mixed queries replaced every fifth lookup with a uniformly random one. The random controls included all mapped addresses and 50% addresses in gaps.
  • Across shader_va and range_of, the median hot lookups took 66–77% less time and the mixed lookups 34–39% less time. Random cases took 1.6–10.5% more time, an increase of 1.2–2.3 ns per query in this run. Most of the relative penalty occurred at 32 ranges. The benchmark compared returned addresses on the same input stream.
  • Verified git diff --check and the source-only check.

GPUs tested: NVIDIA RTX 4080, driver 621.01, Windows 11.

AI-assisted: yes.

  • Based on current main.
  • One topic.
  • Uses source and synthetic fixtures.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497680580 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2065). Originally posted by [alexandersato0830](https://github.com/alexandersato0830) on 2026-11-25T19:22:24Z. --- Claimed in the coordination issue as: [RT-TITLE-VA-POSITIVE-LOOKUP-CACHE](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171881642) Depends on: #1699 (overlapping test include hunk; the runtime change applies independently). ### What and why Repeated lookups in one title VA range acquire a shared lock and search the map each time. Cache one positive mapping per thread after two uncached lookups in the same range. A cache hit checks range bounds, the table's invalidation counter and its instance identity. Other requests still query the live map. [Original finding](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164354183) The draft records the lookup tradeoff so it can be evaluated with runtime traces. The retail lookup mix and frame-time impact remain unmeasured. ### Tested - Native Windows 11, MSVC 19.51, on public main `490f5b9` plus this patch. All ten targeted CTests passed, including `title_va_alias`, `d3d12_title_va`, shadow and geometry views, the window cap, and descriptor copy and table rebound on/off paths. The new regression checks range bounds, deletion, replacement across threads, and reuse of the same storage for a new table. Removing either guard made the test fail. - Ryzen 9 7950X3D, single pinned thread, MSVC `/O2`. One executable compared the original and patched header, interleaving five timed samples per case. Each sample made five passes over 524,288 precomputed inputs. The tests used 32, 1,024 and 4,096 64 KiB ranges. Hot queries moved to a new range every 1,000 lookups, and mixed queries replaced every fifth lookup with a uniformly random one. The random controls included all mapped addresses and 50% addresses in gaps. - Across `shader_va` and `range_of`, the median hot lookups took **66–77% less time** and the mixed lookups **34–39% less time**. Random cases took **1.6–10.5% more time**, an increase of **1.2–2.3 ns per query** in this run. Most of the relative penalty occurred at 32 ranges. The benchmark compared returned addresses on the same input stream. - Verified `git diff --check` and the source-only check. GPUs tested: NVIDIA RTX 4080, driver 621.01, Windows 11. AI-assisted: yes. - [x] Based on current `main`. - [x] One topic. - [x] Uses source and synthetic fixtures.
MSedgeMC commented 2026-11-25 19:53:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MSedgeMC on 2026-11-25T19:53:59Z.

Review: APPROVED


Verified on the PR branch: the standalone C++ test compiles (g++ -std=c++20 -pthread) and passes — output 'title_va_alias: translation inside a title-placed range, identity outside it and after release', exit 0. The PR consolidates shader_va/range_of through find_mapping and adds a thread-local one-entry cache guarded by instance + invalidation counters; the test file covers the exact risk cases (shader_va/range_of agreement, bounds, remove-invalidates-cache, and replacement on another thread invalidating a reader's cached range). No GPU or game data. Advisory: branch carries ~45 older commits not on main; rebase before merge.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6064049495 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2065#pullrequestreview-6064049495). Originally posted by [MSedgeMC](https://github.com/MSedgeMC) on 2026-11-25T19:53:59Z. **Review:** APPROVED --- Verified on the PR branch: the standalone C++ test compiles (g++ -std=c++20 -pthread) and passes — output 'title_va_alias: translation inside a title-placed range, identity outside it and after release', exit 0. The PR consolidates shader_va/range_of through find_mapping and adds a thread-local one-entry cache guarded by instance + invalidation counters; the test file covers the exact risk cases (shader_va/range_of agreement, bounds, remove-invalidates-cache, and replacement on another thread invalidating a reader's cached range). No GPU or game data. Advisory: branch carries ~45 older commits not on main; rebase before merge.
aslan2142 commented 2026-12-01 11:15:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:15:29Z.

Review: COMMENTED


The thread-local positive-lookup cache in runtime/src/title_va_alias.h looks clean (2-hit admission via last_uncached, ABA protection via monotonic instance_, and good unit/concurrency tests in runtime/test/title_va_alias_test.cpp).

Holding off on merge/approval because this PR is still a draft, currently conflicts with main, and is stacked on open PR #1699 (which also needs a rebase). Once #1699 lands, please rebase onto main, mark ready, and run CI to green.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130129134 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2065#pullrequestreview-6130129134). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:15:29Z. **Review:** COMMENTED --- The thread-local positive-lookup cache in `runtime/src/title_va_alias.h` looks clean (2-hit admission via `last_uncached`, ABA protection via monotonic `instance_`, and good unit/concurrency tests in `runtime/test/title_va_alias_test.cpp`). Holding off on merge/approval because this PR is still a draft, currently conflicts with `main`, and is stacked on open PR `#1699` (which also needs a rebase). Once `#1699` lands, please rebase onto `main`, mark ready, and run CI to green. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:41:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:41:51Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318055401 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2065#issuecomment-7318055401). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:41:51Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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!2065
No description provided.