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

Merged
lixonik merged 2 commits from upstream-pr/1920 into main 2026-11-27 21:42:10 +00:00
lixonik commented 2026-11-25 15:48:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-25T15:48:24Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5494580497 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1920). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-25T15:48:24Z. --- Claimed in the coordination issue as: [RT-STREAM-POOL-KEEP-VA-ALIASES](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7167255312) ### 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://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7165609001). 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.
GGandCo commented 2026-11-25 16:32:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GGandCo on 2026-11-25T16:32:14Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7168137400 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7168137400). Originally posted by [GGandCo](https://github.com/GGandCo) on 2026-11-25T16:32:14Z. --- 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.
DadaCap commented 2026-11-27 06:08:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-27T06:08:22Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7211251082 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7211251082). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-27T06:08:22Z. --- 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`.
lixonik commented 2026-11-27 08:37:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T08:37:02Z.


@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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7213729511 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7213729511). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T08:37:02Z. --- @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.
DadaCap commented 2026-11-27 08:53:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-27T08:53:12Z.


@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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7214034882 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7214034882). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-27T08:53:12Z. --- @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 commented 2026-11-27 13:04:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-27T13:04:08Z.


@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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7219017225 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7219017225). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-27T13:04:08Z. --- @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).
MoonEyes commented 2026-11-27 17:42:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T17:42:02Z.


Short A/B of this PR against main on one machine: same recipe, same pipeline cache folder, only the runtime executable changes (my recipe-diff tool reports exactly one difference). n=1 per side. One run per side, so this is not conclusive.

RUN w78 | 2026-11-27 | MoonEyes | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        main ec91d695c + PR #1920 (head d78b0e90a), merged locally | shaders: main's own translation, retranslated locally
COMPARED TO: RUN w77 = main ec91d695c alone, same short recipe, same cache folder (control)
MACHINE:     RTX 4060 8 GB, desktop, only GPU, display attached | NVIDIA 610.88 | Windows 11 Pro 26300 | Ryzen 5 3600 | 32 GB
RECIPE:      docs/running.md Windows NVIDIA recipe + Proton NVIDIA list, short form: 330 s limit, scripted button presses every 10 s from 60 s | stack dumps at fixed times (LEONIDA_STACKS)
DEVIATIONS:  Windows GPU timeout at the default (2 s); ASYNC_MIN_BYTES and COMPILE_GATE at main's defaults
CACHES:      pipeline cache warm, same folder for both | RUN 1 of 1 for this build
MEASURED (w78 | w77 main):
  in-title state (session=1)     120 s | 145 s
  world entered                  165 s | 195 s   (-30 s)
  last window >= 1 img/s         234 s | 293 s
  PresentX ok / failed           2670 / 0 | 3330 / 0
  private RAM max                17.0 GB | 16.0 GB
  free RAM min                   4307 MB | 5323 MB
END:         w78 stopped by my local stall guard (no submit-phases line for 62 s; last at 234 s) | w77 ran to its 337 s time limit | device loss: no, either run
VERDICT:     inconclusive; the display stop is still there (last window 69 s after world entry on the PR run, 98 s on the control)

Reading (marked):

  • MEASURED: the world is entered 30 s earlier with the PR (165 s against 195 s).
  • MEASURED: the display still stops on the PR build. The control reached its time limit at 337 s with its last window at 293 s; the PR run was stopped by the guard, so the two end times are not comparable.
  • NOT SHOWN: that the 30 s is caused by the PR. Four runs of main on this machine (two recipes, cold and warm cache) enter the world at 185-200 s and have their last window >= 1 img/s at 267-293 s; the only same-recipe repeat differs by 5 s and 7 s. One run per side, so this is not conclusive.

Limits: one machine, one run per side, short recipe.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7224692236 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7224692236). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T17:42:02Z. --- Short A/B of this PR against main on one machine: same recipe, same pipeline cache folder, only the runtime executable changes (my recipe-diff tool reports exactly one difference). n=1 per side. One run per side, so this is not conclusive. ``` RUN w78 | 2026-11-27 | MoonEyes | AI-assisted: Claude Code (Claude Opus 5.5) BASE: main ec91d695c + PR #1920 (head d78b0e90a), merged locally | shaders: main's own translation, retranslated locally COMPARED TO: RUN w77 = main ec91d695c alone, same short recipe, same cache folder (control) MACHINE: RTX 4060 8 GB, desktop, only GPU, display attached | NVIDIA 610.88 | Windows 11 Pro 26300 | Ryzen 5 3600 | 32 GB RECIPE: docs/running.md Windows NVIDIA recipe + Proton NVIDIA list, short form: 330 s limit, scripted button presses every 10 s from 60 s | stack dumps at fixed times (LEONIDA_STACKS) DEVIATIONS: Windows GPU timeout at the default (2 s); ASYNC_MIN_BYTES and COMPILE_GATE at main's defaults CACHES: pipeline cache warm, same folder for both | RUN 1 of 1 for this build MEASURED (w78 | w77 main): in-title state (session=1) 120 s | 145 s world entered 165 s | 195 s (-30 s) last window >= 1 img/s 234 s | 293 s PresentX ok / failed 2670 / 0 | 3330 / 0 private RAM max 17.0 GB | 16.0 GB free RAM min 4307 MB | 5323 MB END: w78 stopped by my local stall guard (no submit-phases line for 62 s; last at 234 s) | w77 ran to its 337 s time limit | device loss: no, either run VERDICT: inconclusive; the display stop is still there (last window 69 s after world entry on the PR run, 98 s on the control) ``` Reading (marked): - MEASURED: the world is entered 30 s earlier with the PR (165 s against 195 s). - MEASURED: the display still stops on the PR build. The control reached its time limit at 337 s with its last window at 293 s; the PR run was stopped by the guard, so the two end times are not comparable. - NOT SHOWN: that the 30 s is caused by the PR. Four runs of main on this machine (two recipes, cold and warm cache) enter the world at 185-200 s and have their last window >= 1 img/s at 267-293 s; the only same-recipe repeat differs by 5 s and 7 s. One run per side, so this is not conclusive. Limits: one machine, one run per side, short recipe. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-11-27 18:30:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T18:30:34Z.


Follow-up to my RUN above, with more runs on the same machine (RTX 4060 8 GB, NVIDIA 610.88, Windows 11, main ec91d695c, same short recipe and same warm cache folder):

run build world entered last window >= 1 img/s
w77 (17:31) main 195 s 293 s
w78 (17:37) main + #1920 165 s 234 s
w79 (17:48) main, same recipe as w77 200 s 286 s
rdc-court (18:33) main + 4 unrelated commits from another contributor 165 s 246 s
budget-court (18:56) main, one compile setting changed (LEONIDA_SERIAL_BIG_COMPILES unset) 165 s 243 s (*)

(*) read from that run's log at 19:05 and also recorded by my stop guard; the log was later removed by a disk cleanup on my side.

Two later runs without #1920 also entered the world at 165 s. So the 30 s earlier world entry I reported for #1920 is within what this machine shows across runs, and I do not attribute it to the PR. The display stop is the same with and without #1920. n=1 per row; I have not repeated #1920 itself.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7225560670 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1920#issuecomment-7225560670). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T18:30:34Z. --- Follow-up to my RUN above, with more runs on the same machine (RTX 4060 8 GB, NVIDIA 610.88, Windows 11, main ec91d695c, same short recipe and same warm cache folder): | run | build | world entered | last window >= 1 img/s | |---|---|---|---| | w77 (17:31) | main | 195 s | 293 s | | w78 (17:37) | main + #1920 | 165 s | 234 s | | w79 (17:48) | main, same recipe as w77 | 200 s | 286 s | | rdc-court (18:33) | main + 4 unrelated commits from another contributor | 165 s | 246 s | | budget-court (18:56) | main, one compile setting changed (`LEONIDA_SERIAL_BIG_COMPILES` unset) | 165 s | 243 s (*) | (*) read from that run's log at 19:05 and also recorded by my stop guard; the log was later removed by a disk cleanup on my side. Two later runs without #1920 also entered the world at 165 s. So the 30 s earlier world entry I reported for #1920 is within what this machine shows across runs, and I do not attribute it to the PR. The display stop is the same with and without #1920. n=1 per row; I have not repeated #1920 itself. AI-assisted (Claude Code, Claude Opus 5.5)
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!1920
No description provided.