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

Open
github-bot wants to merge 1 commit from github-bot/gh-2065 into main AGit
Owner

@⁠alexandersato0830 on GitHub · 2026-11-25 19:22 UTC · original
alexandersato0830:codex/title-va-positive-cache → main · +87 −15 · 2 files · 1 commits · draft

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.
**@⁠alexandersato0830** on GitHub · 2026-11-25 19:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2065) `alexandersato0830:codex/title-va-positive-cache` → `main` · +87 −15 · 2 files · 1 commits · draft Claimed in the coordination issue as: [RT-TITLE-VA-POSITIVE-LOOKUP-CACHE](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) 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://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:16:39 +00:00
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 19:53 UTC · original · approved these changes

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.

**@⁠MSedgeMC** on GitHub · 2026-11-25 19:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2065#pullrequestreview-6064049495) · **approved these changes** 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.
This pull request has changes conflicting with the target branch.
  • runtime/src/title_va_alias.h
  • runtime/test/title_va_alias_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2065/head:github-bot/gh-2065'
git switch 'github-bot/gh-2065'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2065'
git switch 'github-bot/gh-2065'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2065'
git switch 'github-bot/gh-2065'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2065'
git switch 'main'
git merge --squash 'github-bot/gh-2065'
git switch 'main'
git merge --ff-only 'github-bot/gh-2065'
git switch 'main'
git merge 'github-bot/gh-2065'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.