RT-STREAM-POOL-KEEP-VA-ALIASES: preserve live mappings when mirroring stream pools #1920

Open
github-bot wants to merge 2 commits from github-bot/gh-1920 into main AGit
Owner

@⁠lixonik on GitHub · 2026-11-25 15:48 UTC · original
lixonik:fix/stream-pool-keep-va-aliases → main · +202 −70 · 6 files · 2 commits · open

Claimed in the coordination issue as: RT-STREAM-POOL-KEEP-VA-ALIASES

What and why

A stream-pool extent was checked for an existing mapping at its first byte. A live mapping could start later on either side of the pair. Publishing the entire extent then evicted that mapping, even if the new request only needed the free area before it. The runtime now limits new extents to the intersection of the CPU and GPU gaps. Registration checks both sides under one lock and publishes the pair together. Reusing the other view's mapping also stops at the next live range.

If a competing mapping appears while the copy is allocated, that mapping takes precedence. The unused backing follows the device's existing allocation lifetime.

This is on the stream-pool path reported during world start. The effect on a retail boot has not been measured.

Tested

  • MSVC on Windows: title_va_alias_test, title_window_plan_test and title_window_plan_bounds_test passed. The new overlap assertion failed against the original alias table.
  • GCC with UBSan on Linux/WSL: title_va_alias_test and title_window_plan_bounds_test passed.
  • A synthetic harness compiled the actual pool resolver body with mocked allocation and memory queries. The original path allocated 1 MiB and displaced a live neighboring alias. The fixed path used the free 64 KiB and preserved it. A mapping arriving during allocation survived without a partial pair being published.
  • python -I -B scripts/run_semantic_tests.py tests/semantic: 6,261 tests across 489 files, zero failures.
  • Full Windows/Vulkan shim build and retail boot were not run.

GPUs tested: n/a (synthetic CPU tests)

AI-assisted.

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
**@⁠lixonik** on GitHub · 2026-11-25 15:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1920) `lixonik:fix/stream-pool-keep-va-aliases` → `main` · +202 −70 · 6 files · 2 commits · open Claimed in the coordination issue as: [RT-STREAM-POOL-KEEP-VA-ALIASES](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why A stream-pool extent was checked for an existing mapping at its first byte. A live mapping could start later on either side of the pair. Publishing the entire extent then evicted that mapping, even if the new request only needed the free area before it. The runtime now limits new extents to the intersection of the CPU and GPU gaps. Registration checks both sides under one lock and publishes the pair together. Reusing the other view's mapping also stops at the next live range. If a competing mapping appears while the copy is allocated, that mapping takes precedence. The unused backing follows the device's existing allocation lifetime. This is on the [stream-pool path reported during world start](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). The effect on a retail boot has not been measured. ### Tested - MSVC on Windows: `title_va_alias_test`, `title_window_plan_test` and `title_window_plan_bounds_test` passed. The new overlap assertion failed against the original alias table. - GCC with UBSan on Linux/WSL: `title_va_alias_test` and `title_window_plan_bounds_test` passed. - A synthetic harness compiled the actual pool resolver body with mocked allocation and memory queries. The original path allocated 1 MiB and displaced a live neighboring alias. The fixed path used the free 64 KiB and preserved it. A mapping arriving during allocation survived without a partial pair being published. - `python -I -B scripts/run_semantic_tests.py tests/semantic`: 6,261 tests across 489 files, zero failures. - Full Windows/Vulkan shim build and retail boot were not run. GPUs tested: n/a (synthetic CPU tests) AI-assisted. ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:11:12 +00:00
Author
Owner

@⁠GGandCo on GitHub · 2026-11-25 16:32 UTC · original

Native Windows/Intel verification of #1920 (7cb696200) together with #1926, on main b0f3d3998 plus local integration fixes:

  • Intel UHD Graphics, driver 32.0.101.6314, MSVC 14.51, Vulkan SDK 1.4.363.1.
  • title_va_alias, title_window_plan, title_window_plan_bounds and vulkan_title_image_pool: 4/4 passed.
  • xmem, d3d12_xmem_placed (production batch route, no injected mapping hook), d3d12_host_prefix and d3d12_texture_memory: 4/4 passed with LEONIDA_VK_VALIDATION=1.
  • Focused staged plane/BC-array, aliased-guard and mapped single-byte WB/WC readback cases also passed. Host image copies were disabled; on-demand pipelines enabled.

Combined integration, not an isolated A/B of this PR. No successful retail load or performance improvement claimed. The full existing_heap fixture still has a pre-existing first-render-target device-loss failure on this Intel setup, reproduced before these changes; the focused cases above were run separately. No game data included. AI-assisted with OpenAI Codex.

**@⁠GGandCo** on GitHub · 2026-11-25 16:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7168137400) Native Windows/Intel verification of #1920 (7cb696200) together with #1926, on main b0f3d3998 plus local integration fixes: - Intel UHD Graphics, driver 32.0.101.6314, MSVC 14.51, Vulkan SDK 1.4.363.1. - title_va_alias, title_window_plan, title_window_plan_bounds and vulkan_title_image_pool: 4/4 passed. - xmem, d3d12_xmem_placed (production batch route, no injected mapping hook), d3d12_host_prefix and d3d12_texture_memory: 4/4 passed with LEONIDA_VK_VALIDATION=1. - Focused staged plane/BC-array, aliased-guard and mapped single-byte WB/WC readback cases also passed. Host image copies were disabled; on-demand pipelines enabled. Combined integration, not an isolated A/B of this PR. No successful retail load or performance improvement claimed. The full existing_heap fixture still has a pre-existing first-render-target device-loss failure on this Intel setup, reproduced before these changes; the focused cases above were run separately. No game data included. AI-assisted with OpenAI Codex.
Author
Owner

@⁠DadaCap on GitHub · 2026-11-27 06:08 UTC · original

Retail data for this path, from the RT-TITLE-WINDOW-RETIRE work (RTX 5080, NVIDIA 621.24, Windows 11, main d1dff7949 plus a local diagnostic that counts windows; AI-assisted, Claude Code). It supports the bug this PR fixes, and it shows one more thing the bounding needs.

The bug, measured. 15-minute run with main's stream-pool path: 4,534 window-backed pool extents, about 2.9 GB in total but only about 1.5 GB of distinct pages; 2,887 overlapped an earlier extent and 2,501 (about 1.6 GB) were orphaned: no alias range answered from them, yet each was still refreshed every submission and charged to the window budget. Only 1 pool request in the run was served by an existing mapping.

What bounding alone does. With extents bounded by the free span in both views (the same rule as this PR), overlaps and orphans went to 0, but a request whose bytes run past the free span gets a mapping shorter than itself: resolve_pool_memory never checks that the extent covers [va, va + bytes) (bytes is only logged). A V# then becomes a zero-size view (vsharp_address refuses room < bytes), and a root view (resolved with kRootViewBytes, 64 KiB) reads and writes past its copy into whatever the arena holds next. Our first build with bounding died at about 160 s with title read faults (it also had a second bug of ours, in retirement, so the two causes were not separated).

What held. Giving such a request one mapping over the request plus every window it reaches (each taken whole, in both views, the replaced windows retired after the next submission), and having TitleVaAliases::resolve / vsharp_address go back to the resolver when the range holding a view's first byte ends before the view does: two 20-minute runs into the world, no fault; 0 overlapping, 0 orphaned windows; about 4,100 windows retired, about 3 GB returned.

That work is on DadaCap/leonida:window-orphans (not opened as a PR, to avoid overlapping this one). It also retires windows that other paths orphan (a slot-133 buffer placed over a window) and keeps a retired window's GPU writes going back to the title. @⁠lixonik, would you rather take the cover part into this PR, or have me open mine on top of yours with Depends on: #1920? I'll go with whichever you prefer. This PR currently shows a conflict with main.

**@⁠DadaCap** on GitHub · 2026-11-27 06:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7211251082) Retail data for this path, from the RT-TITLE-WINDOW-RETIRE work (RTX 5080, NVIDIA 621.24, Windows 11, `main` d1dff7949 plus a local diagnostic that counts windows; AI-assisted, Claude Code). It supports the bug this PR fixes, and it shows one more thing the bounding needs. **The bug, measured.** 15-minute run with `main`'s stream-pool path: 4,534 window-backed pool extents, about 2.9 GB in total but only about 1.5 GB of distinct pages; 2,887 overlapped an earlier extent and 2,501 (about 1.6 GB) were orphaned: no alias range answered from them, yet each was still refreshed every submission and charged to the window budget. Only 1 pool request in the run was served by an existing mapping. **What bounding alone does.** With extents bounded by the free span in both views (the same rule as this PR), overlaps and orphans went to 0, but a request whose bytes run past the free span gets a mapping shorter than itself: `resolve_pool_memory` never checks that the extent covers `[va, va + bytes)` (`bytes` is only logged). A V# then becomes a zero-size view (`vsharp_address` refuses `room < bytes`), and a root view (resolved with `kRootViewBytes`, 64 KiB) reads and writes past its copy into whatever the arena holds next. Our first build with bounding died at about 160 s with title read faults (it also had a second bug of ours, in retirement, so the two causes were not separated). **What held.** Giving such a request one mapping over the request plus every window it reaches (each taken whole, in both views, the replaced windows retired after the next submission), and having `TitleVaAliases::resolve` / `vsharp_address` go back to the resolver when the range holding a view's first byte ends before the view does: two 20-minute runs into the world, no fault; 0 overlapping, 0 orphaned windows; about 4,100 windows retired, about 3 GB returned. That work is on `DadaCap/leonida:window-orphans` (not opened as a PR, to avoid overlapping this one). It also retires windows that other paths orphan (a slot-133 buffer placed over a window) and keeps a retired window's GPU writes going back to the title. @⁠lixonik, would you rather take the cover part into this PR, or have me open mine on top of yours with `Depends on: #1920`? I'll go with whichever you prefer. This PR currently shows a conflict with `main`.
github-bot force-pushed github-bot/gh-1920 from c088fd567f to d78b0e90ab 2026-11-27 08:40:44 +00:00 Compare
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 08:37 UTC · original

@⁠DadaCap Thanks for measuring the overlaps and catching the short mapping. I rebased #1920 onto d1dff7949 and added a length check to both the pool reuse and allocation paths in d78b0e90a. A request that cannot be backed for its full length now fails through the existing unbacked-view path and leaves both live aliases intact.

Please open window-orphans as a follow-up with Depends on: #1920. Your seam-covering path needs the old windows to stay alive through their in-flight submissions and pending GPU write-back. Keeping the covering, retirement and write-back changes together in your PR also keeps your end-to-end regression with the code it exercises.

On Windows 11 / MSVC with an RTX 5070 (610.88), all eight focused CTests passed, including the new synthetic seam cases and window write-back. The two portable tests also passed with GCC/UBSan. Vulkan validation layers were unavailable on this machine.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-27 08:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7213729511) @⁠DadaCap Thanks for measuring the overlaps and catching the short mapping. I rebased #1920 onto `d1dff7949` and added a length check to both the pool reuse and allocation paths in `d78b0e90a`. A request that cannot be backed for its full length now fails through the existing unbacked-view path and leaves both live aliases intact. Please open `window-orphans` as a follow-up with `Depends on: #1920`. Your seam-covering path needs the old windows to stay alive through their in-flight submissions and pending GPU write-back. Keeping the covering, retirement and write-back changes together in your PR also keeps your end-to-end regression with the code it exercises. On Windows 11 / MSVC with an RTX 5070 (610.88), all eight focused CTests passed, including the new synthetic seam cases and window write-back. The two portable tests also passed with GCC/UBSan. Vulkan validation layers were unavailable on this machine. AI-assisted.
Author
Owner

@⁠DadaCap on GitHub · 2026-11-27 08:53 UTC · original

@⁠lixonik thanks, will do. I'm porting the covering, retirement and write-back changes onto d78b0e90a now (your bounding and length checks kept; the cover replaces the unbacked fallback only for a request that runs into existing windows, which it takes whole and retires after their in-flight submissions and write-back). It will open as a follow-up with Depends on: #1920 after the full ctest and a retail run on top of your branch. AI-assisted (Claude Code).

**@⁠DadaCap** on GitHub · 2026-11-27 08:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7214034882) @⁠lixonik thanks, will do. I'm porting the covering, retirement and write-back changes onto `d78b0e90a` now (your bounding and length checks kept; the cover replaces the unbacked fallback only for a request that runs into existing windows, which it takes whole and retires after their in-flight submissions and write-back). It will open as a follow-up with `Depends on: #1920` after the full ctest and a retail run on top of your branch. AI-assisted (Claude Code).
Author
Owner

@⁠DadaCap on GitHub · 2026-11-27 13:04 UTC · original

@⁠lixonik the follow-up is open: #2465 (Depends on: #1920, built on your d78b0e90a unchanged). Your bounding and both length checks stay; the cover replaces the unbacked fallback only where a request runs into windows, which it takes whole and retires after their in-flight submissions and write-back. All your tests pass unchanged. AI-assisted (Claude Code).

**@⁠DadaCap** on GitHub · 2026-11-27 13:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7219017225) @⁠lixonik the follow-up is open: #2465 (`Depends on: #1920`, built on your d78b0e90a unchanged). Your bounding and both length checks stay; the cover replaces the unbacked fallback only where a request runs into windows, which it takes whole and retires after their in-flight submissions and write-back. All your tests pass unchanged. AI-assisted (Claude Code).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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