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

Closed
leonida/mandy
alexandersato0830 wants to merge 0 commits from codex/title-va-positive-cache into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

alexandersato0830 commented 2026-11-25 19:22:24 +00:00

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.
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 approved these changes 2026-11-25 19:53:59 +00:00
MSedgeMC left a comment

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.

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 reviewed 2026-12-01 11:15:29 +00:00
aslan2142 left a comment
No description provided.
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

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.

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.
Sign in to join this conversation.
No description provided.