d3d12: slot-133 shadows pass over the title's reserved pages until the journal names them (RT-SHADOW-RESERVATION-SKIP) #2391

Closed
azsekazvamdimitar wants to merge 1 commit from upstream-pr/2391 into main
azsekazvamdimitar commented 2026-11-26 17:05:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by azsekazvamdimitar on 2026-11-26T17:05:44Z.


Claimed in the coordination issue as: RT-SHADOW-RESERVATION-SKIP (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198477484)

Note: #1867 changes the same lines of the walk's skip rule. This applies to main without it; whichever lands second takes both clauses.

What and why

Under Wine the slot-133 shadow walk spends most of its time in VirtualQuery of pages that are only reserved. A local census on my retail boot put them in the stream pools' 16 GiB physical-page windows: each unmapped 64 KiB slot is its own placeholder after xmem unmaps a view, and the walk asked about 450-7,500 of them a refresh. Each query takes 1.5 us while nothing else maps memory and 15-70 us (single ones 200-400 us) while the title's mapping threads hold Wine's virtual-memory lock, so after the story load the walk took 100-330 ms a submission.

Nothing but xmem's own calls and the title's memory calls (VirtualAlloc, VirtualFree, VirtualProtect, the XMem functions, all shimmed; the title imports no other memory API) changes a page inside those reservations, and every one of them is recorded in title_memory_map. This leans on the assumption in docs/runtime_imports.md that nothing commits into a window with kernel32's VirtualAlloc, which a placeholder refuses. So:

  • xmem records the title's placeholders and physical-page windows in leonida::title_reservations (title_page_watch.h). Every successful release forgets its range, also one xmem's own tables missed; a new reservation drops any stale range it overlaps; a window replaced by ordinary memory is forgotten.
  • A shadow's walk that finds a page there reserved (MEM_RESERVE, MEM_PRIVATE) marks it settled and passes over it like an unchanged page until the journal names it, a release moves the registry's generation, or the walk is forced (LEONIDA_SHADOW_FULL_WALK=1, or a journal that overflowed). Aliased, pinned and write-watched pages never settle.

#417 (commits into windows) stays compatible: such a commit goes through the journalled VirtualAlloc shim, and its releases through the free shim that forgets the range.

Two shapes I tried first and dropped: passing over every page last seen uncommitted, trusting the journal everywhere, misses commits made inside ntdll (heap growth), and that boot hung; a per-refresh cache of uncommitted runs shared across trackers never answered a query in the game.

The same retail boot, RTX 3090, GE-Proton, main a73a57e13 with #1851, #1957, #1918, #2097, #1867 and #2117, shaders translated with llvm-mc 23.1.6, synchronous pipelines, LEONIDA_RT_AS=off, the ray-hit shading programs skipped (LEONIDA_SKIP_COMPUTE), LEONIDA_DEVICE_FAULT=2, title watchdog kicked. First world minute (120-270 s; the world starts at about 190 s):

without (2 runs) with this pull request (3 runs)
VirtualQuery calls a refresh 443-1,616 70-136
walk a refresh 16.5-40.4 ms 10.2-21.4 ms
slot-133 shadows a submission 17.9-41.9 ms 11.7-23.1 ms

Later in the world the walk without this reached 125-330 ms a submission; none of the runs with it got that far, because on this setting most runs end in a GPU hang (checkpoints in sr_denoising and the particle light-atlas pass). Without the change 2 of 7 runs went the full 25 minutes; with it none of 5 did (a title access violation at the world start, which contributes only pre-world refreshes to the table above, and hangs). To tell whether the change is behind that:

  • Two runs asked about every passed-over page again at every refresh. In the second, 77 of 9.5 million had changed, all by a mapping the journal recorded after that refresh had read it (the next refresh asks anyway), none without a record. Both hung at the same checkpoints as runs without the change.
  • The same build with the pass-over switched off hung at about 183 s; with it on, at 845 s after a 530 s run of cold compute compiles. Same hang family in both.

Tested

  • d3d12_existing_heap gains a check: the reserved pages of a registered reservation are asked about once and then not again; a page committed there (and journalled, as the title's VirtualAlloc shim does) arrives at the next submission, a decommit reads zeros, and after the reservation is forgotten the pages are asked about again. With the pass-over clause removed from the walk it fails at the query count.
  • Cross-built with clang-cl: d3d12_existing_heap (with and without write watch), d3d12_host_prefix, d3d12_mapped_plane_async, d3d12_xmem_placed, d3d12_title_va (+ _shadow) and xs_proxy_mock pass under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11); d3d12_existing_heap also with LEONIDA_SHADOW_FULL_WALK=1.
  • On main 935a2cd5b.
  • Not run on Windows, and the VirtualQuery cost there wasn't measured.

GPUs tested: NVIDIA GeForce RTX 3090, driver 590.48.01, Debian 13 (Linux 6.12), Wine/Proton as above.

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5514209660 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2391). Originally posted by [azsekazvamdimitar](https://github.com/azsekazvamdimitar) on 2026-11-26T17:05:44Z. --- Claimed in the coordination issue as: RT-SHADOW-RESERVATION-SKIP (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198477484) Note: #1867 changes the same lines of the walk's skip rule. This applies to `main` without it; whichever lands second takes both clauses. ### What and why Under Wine the slot-133 shadow walk spends most of its time in VirtualQuery of pages that are only reserved. A local census on my retail boot put them in the stream pools' 16 GiB physical-page windows: each unmapped 64 KiB slot is its own placeholder after xmem unmaps a view, and the walk asked about 450-7,500 of them a refresh. Each query takes 1.5 us while nothing else maps memory and 15-70 us (single ones 200-400 us) while the title's mapping threads hold Wine's virtual-memory lock, so after the story load the walk took 100-330 ms a submission. Nothing but xmem's own calls and the title's memory calls (VirtualAlloc, VirtualFree, VirtualProtect, the XMem functions, all shimmed; the title imports no other memory API) changes a page inside those reservations, and every one of them is recorded in `title_memory_map`. This leans on the assumption in `docs/runtime_imports.md` that nothing commits into a window with kernel32's VirtualAlloc, which a placeholder refuses. So: - xmem records the title's placeholders and physical-page windows in `leonida::title_reservations` (`title_page_watch.h`). Every successful release forgets its range, also one xmem's own tables missed; a new reservation drops any stale range it overlaps; a window replaced by ordinary memory is forgotten. - A shadow's walk that finds a page there reserved (`MEM_RESERVE`, `MEM_PRIVATE`) marks it settled and passes over it like an unchanged page until the journal names it, a release moves the registry's generation, or the walk is forced (`LEONIDA_SHADOW_FULL_WALK=1`, or a journal that overflowed). Aliased, pinned and write-watched pages never settle. #417 (commits into windows) stays compatible: such a commit goes through the journalled VirtualAlloc shim, and its releases through the free shim that forgets the range. Two shapes I tried first and dropped: passing over every page last seen uncommitted, trusting the journal everywhere, misses commits made inside ntdll (heap growth), and that boot hung; a per-refresh cache of uncommitted runs shared across trackers never answered a query in the game. The same retail boot, RTX 3090, GE-Proton, main a73a57e13 with #1851, #1957, #1918, #2097, #1867 and #2117, shaders translated with llvm-mc 23.1.6, synchronous pipelines, `LEONIDA_RT_AS=off`, the ray-hit shading programs skipped (`LEONIDA_SKIP_COMPUTE`), `LEONIDA_DEVICE_FAULT=2`, title watchdog kicked. First world minute (120-270 s; the world starts at about 190 s): | | without (2 runs) | with this pull request (3 runs) | |---|---|---| | VirtualQuery calls a refresh | 443-1,616 | 70-136 | | walk a refresh | 16.5-40.4 ms | 10.2-21.4 ms | | slot-133 shadows a submission | 17.9-41.9 ms | 11.7-23.1 ms | Later in the world the walk without this reached 125-330 ms a submission; none of the runs with it got that far, because on this setting most runs end in a GPU hang (checkpoints in `sr_denoising` and the particle light-atlas pass). Without the change 2 of 7 runs went the full 25 minutes; with it none of 5 did (a title access violation at the world start, which contributes only pre-world refreshes to the table above, and hangs). To tell whether the change is behind that: - Two runs asked about every passed-over page again at every refresh. In the second, 77 of 9.5 million had changed, all by a mapping the journal recorded after that refresh had read it (the next refresh asks anyway), none without a record. Both hung at the same checkpoints as runs without the change. - The same build with the pass-over switched off hung at about 183 s; with it on, at 845 s after a 530 s run of cold compute compiles. Same hang family in both. ### Tested - `d3d12_existing_heap` gains a check: the reserved pages of a registered reservation are asked about once and then not again; a page committed there (and journalled, as the title's VirtualAlloc shim does) arrives at the next submission, a decommit reads zeros, and after the reservation is forgotten the pages are asked about again. With the pass-over clause removed from the walk it fails at the query count. - Cross-built with clang-cl: `d3d12_existing_heap` (with and without write watch), `d3d12_host_prefix`, `d3d12_mapped_plane_async`, `d3d12_xmem_placed`, `d3d12_title_va` (+ `_shadow`) and `xs_proxy_mock` pass under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11); `d3d12_existing_heap` also with `LEONIDA_SHADOW_FULL_WALK=1`. - On `main` 935a2cd5b. - Not run on Windows, and the VirtualQuery cost there wasn't measured. GPUs tested: NVIDIA GeForce RTX 3090, driver 590.48.01, Debian 13 (Linux 6.12), Wine/Proton as above. AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
ecox982745 commented 2026-11-26 18:21:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T18:21:16Z.


I tested head a525962d73 on native Windows 11, RTX 4090, NVIDIA 616.64. All five focused CTests passed with Vulkan validation enabled: the three d3d12_existing_heap variants, d3d12_title_va, and d3d12_title_va_shadow.

There is now one merge conflict against main bdbc7e9236, in the zero-page handling in runtime/shims/d3d12_vulkan_device.cpp after #2163. I tested this resolution locally: keep this PR's if (!(state_[i] & kZero)) block, put main's leonida::shadow_keep::forget(...) immediately after zero_targets(offset, bytes) inside that block, and leave the settled && alone update outside it. All seven focused CTests passed on that tree, including main's two shadow-refill tests.

A readback catches an incorrect resolution. I extended check_reserved_pages in scratch. After it committed and wrote a 4 KiB page, decommitted it and verified the zero readback, I recommitted the same page, wrote the identical bytes, and notified title_memory_map as the fixture already does. I compared the entire 256 KiB buffer after the GPU copy.

Resolution Shadow keep on Shadow keep off
Keep checksum invalidation after zeroing All bytes matched All bytes matched
Omit only that invalidation First byte of the recommitted page was 0, expected 43 All bytes matched

Both the normal and forced-full walks gave the same readback result in each cell. With the tested resolution, the second refresh of the untouched reservation made zero queries normally and one on a forced full walk. Adding the identical-byte recommit to the test would protect both sides of this merge.

AI-assisted hardware verification with OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7200360724 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2391#issuecomment-7200360724). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-26T18:21:16Z. --- I tested head `a525962d73` on native Windows 11, RTX 4090, NVIDIA 616.64. All five focused CTests passed with Vulkan validation enabled: the three `d3d12_existing_heap` variants, `d3d12_title_va`, and `d3d12_title_va_shadow`. There is now one merge conflict against `main` `bdbc7e9236`, in the zero-page handling in `runtime/shims/d3d12_vulkan_device.cpp` after #2163. I tested this resolution locally: keep this PR's `if (!(state_[i] & kZero))` block, put main's `leonida::shadow_keep::forget(...)` immediately after `zero_targets(offset, bytes)` inside that block, and leave the `settled && alone` update outside it. All seven focused CTests passed on that tree, including main's two shadow-refill tests. **A readback catches an incorrect resolution.** I extended `check_reserved_pages` in scratch. After it committed and wrote a 4 KiB page, decommitted it and verified the zero readback, I recommitted the same page, wrote the **identical bytes**, and notified `title_memory_map` as the fixture already does. I compared the entire 256 KiB buffer after the GPU copy. | Resolution | Shadow keep on | Shadow keep off | | --- | --- | --- | | Keep checksum invalidation after zeroing | All bytes matched | All bytes matched | | Omit only that invalidation | First byte of the recommitted page was 0, expected 43 | All bytes matched | Both the normal and forced-full walks gave the same readback result in each cell. With the tested resolution, the second refresh of the untouched reservation made zero queries normally and one on a forced full walk. Adding the identical-byte recommit to the test would protect both sides of this merge. AI-assisted hardware verification with OpenAI Codex (GPT-6).
lixonik commented 2026-11-27 15:49:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:49:19Z.

Review: COMMENTED


Reviewed and locally tested at f52796172 (merged cleanly onto main ec91d695c).

Verification

  • Environment: Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
  • ctest: xmem, d3d12_existing_heap, and d3d12_existing_heap_no_write_watch all passed (3/3). Also verified check_reserved_pages passes under LEONIDA_SHADOW_FULL_WALK=1.
  • scripts/check_no_game_data.py and git diff --check: clean.

Review notes

  • Checked all commit/map/remap/protect/fault paths in xmem.cpp (XMemVirtualAlloc, isolate_placeholder, map_view3, physical_page_fault, TitleVirtualAlloc, TitleVirtualFree, TitleVirtualProtect): all record changes in title_memory_map, and ShadowPages::write_back() still treats kZero | kClean pages as held, so skipping re-queries on settled MEM_RESERVE | MEM_PRIVATE pages inside title_reservations is sound.
  • One defensive gap outside the diff hunks in ShadowPages::absorb() (runtime/shims/d3d12_vulkan_device.cpp:769): absorb() resets map_generation_ = ~std::uint64_t(0) when other.map_generation_ != map_generation_, but does not do the same for reservation_generation_. With current add_shadow() / refresh_shadows() ordering keep should not normally be ahead of other, but mirroring if (other.reservation_generation_ != reservation_generation_) reservation_generation_ = ~std::uint64_t(0); prevents keep from ever silently inheriting stale kZero | kClean pages from other if ordering or per-tracker refreshes change.
  • Two minor inline notes on xmem.cpp and title_page_watch.h.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6090584510 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2391#pullrequestreview-6090584510). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:49:19Z. **Review:** COMMENTED --- Reviewed and locally tested at `f52796172` (merged cleanly onto `main` `ec91d695c`). ### Verification - Environment: Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341; `VK_LAYER_KHRONOS_validation` not installed locally). - `ctest`: `xmem`, `d3d12_existing_heap`, and `d3d12_existing_heap_no_write_watch` all passed (3/3). Also verified `check_reserved_pages` passes under `LEONIDA_SHADOW_FULL_WALK=1`. - `scripts/check_no_game_data.py` and `git diff --check`: clean. ### Review notes - Checked all commit/map/remap/protect/fault paths in `xmem.cpp` (`XMemVirtualAlloc`, `isolate_placeholder`, `map_view3`, `physical_page_fault`, `TitleVirtualAlloc`, `TitleVirtualFree`, `TitleVirtualProtect`): all record changes in `title_memory_map`, and `ShadowPages::write_back()` still treats `kZero | kClean` pages as `held`, so skipping re-queries on settled `MEM_RESERVE | MEM_PRIVATE` pages inside `title_reservations` is sound. - One defensive gap outside the diff hunks in `ShadowPages::absorb()` (`runtime/shims/d3d12_vulkan_device.cpp:769`): `absorb()` resets `map_generation_ = ~std::uint64_t(0)` when `other.map_generation_ != map_generation_`, but does not do the same for `reservation_generation_`. With current `add_shadow()` / `refresh_shadows()` ordering `keep` should not normally be ahead of `other`, but mirroring `if (other.reservation_generation_ != reservation_generation_) reservation_generation_ = ~std::uint64_t(0);` prevents `keep` from ever silently inheriting stale `kZero | kClean` pages from `other` if ordering or per-tracker refreshes change. - Two minor inline notes on `xmem.cpp` and `title_page_watch.h`. AI-assisted.
lixonik commented 2026-11-27 15:49:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:49:20Z.

Code review location: runtime/shims/xmem.cpp; line 2289

@@ -2276,6 +2284,9 @@ BOOL title_free_impl(LPVOID address, SIZE_T size, DWORD free_type) {
     } else {
         result = VirtualFree(address, size, free_type);
     }
+    // Every release, also of a reservation xmem's tables missed, before the journal names its pages: the host can
+    // reserve the space again for memory the shadows would otherwise take as settled.
+    if (result && releases && release_end > start) leonida::title_reservations::forget(start, release_end);

Minor race note: for tracked windows/placeholders, title_release() frees the pages and drops g_fault_windows / g_title_placeholders under g_phys_mutex + FaultLockExclusive, then unlocks before returning here. If another thread immediately reserves the freed range via XMemVirtualAlloc and calls title_reservations::add() before this line runs, forget(start, release_end) will drop the new reservation (safe -- shadows just fall back to querying it -- only loses the skip optimization for that range). Calling title_reservations::forget(start, end) inside title_release() under FaultLockExclusive (while keeping this fallback for untracked releases) would close that window.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4721353553 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2391#discussion_r4721353553). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:49:20Z. **Code review location:** `runtime/shims/xmem.cpp`; line 2289 ~~~~diff @@ -2276,6 +2284,9 @@ BOOL title_free_impl(LPVOID address, SIZE_T size, DWORD free_type) { } else { result = VirtualFree(address, size, free_type); } + // Every release, also of a reservation xmem's tables missed, before the journal names its pages: the host can + // reserve the space again for memory the shadows would otherwise take as settled. + if (result && releases && release_end > start) leonida::title_reservations::forget(start, release_end); ~~~~ --- Minor race note: for tracked windows/placeholders, `title_release()` frees the pages and drops `g_fault_windows` / `g_title_placeholders` under `g_phys_mutex` + `FaultLockExclusive`, then unlocks before returning here. If another thread immediately reserves the freed range via `XMemVirtualAlloc` and calls `title_reservations::add()` before this line runs, `forget(start, release_end)` will drop the new reservation (safe -- shadows just fall back to querying it -- only loses the skip optimization for that range). Calling `title_reservations::forget(start, end)` inside `title_release()` under `FaultLockExclusive` (while keeping this fallback for untracked releases) would close that window.
lixonik commented 2026-11-27 15:49:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:49:20Z.

Code review location: runtime/src/title_page_watch.h; line 754

@@ -720,6 +722,85 @@ std::uint64_t ask(std::uint64_t reader, const Runs& runs, Dirty&& dirty, Refused
 
 }  // namespace leonida::title_write_watch
 
+// 7. The title's xmem reservations (title_reservations): its placeholders and physical-page windows, from the
+//    reservation to its release. Nothing but xmem and the title's own memory calls changes their pages, and those
+//    record every change in title_memory_map (a placeholder refuses a plain commit, and the title doesn't commit
+//    inside a window with VirtualAlloc: see the windows in xmem.cpp). A shadow takes a page there that is reserved
+//    and not mapped as zero until the journal names it, instead of asking VirtualQuery at every submission: under
+//    Wine a query waits for the virtual-memory lock, and the world's thousands of 64 KiB placeholders made the
+//    queries most of a refresh.
+namespace leonida::title_reservations {
+
+// Allocates from host_heap, as title_write_watch does: the D3D12 layer asks under a tracker's lock.
+struct State {
+    std::shared_mutex mutex;                                // ranges
+    host_heap::map<std::uintptr_t, std::uintptr_t> ranges;  // base -> end; apart, never touching
+    std::atomic<std::size_t> count{0};                      // ranges.size(), read without the lock
+    std::atomic<std::uint64_t> generation{1};               // moved whenever a range was released or dropped
+};
+
+inline State& state() {
+    static State s;
+    return s;
+}
+
+// xmem: [base, base + size) was reserved as a placeholder or a physical-page window of the title's. Inside one range
+// already, it is part of that reservation (a window replacing part of a placeholder). A range it only overlaps was
+// released without xmem seeing it, and goes whole, as xmem's tables drop it: nothing outside the new reservation is
+// known to be one of the title's any more.
+inline void add(std::uintptr_t base, std::uintptr_t size) {
+    if (!size) return;
+    State& s = state();
+    const std::uintptr_t end = base + size;

Minor defensive guard: if (!size || size > UINTPTR_MAX - base) return; avoids unsigned wraparound if a caller ever passes an unvalidated size.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4721353559 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2391#discussion_r4721353559). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:49:20Z. **Code review location:** `runtime/src/title_page_watch.h`; line 754 ~~~~diff @@ -720,6 +722,85 @@ std::uint64_t ask(std::uint64_t reader, const Runs& runs, Dirty&& dirty, Refused } // namespace leonida::title_write_watch +// 7. The title's xmem reservations (title_reservations): its placeholders and physical-page windows, from the +// reservation to its release. Nothing but xmem and the title's own memory calls changes their pages, and those +// record every change in title_memory_map (a placeholder refuses a plain commit, and the title doesn't commit +// inside a window with VirtualAlloc: see the windows in xmem.cpp). A shadow takes a page there that is reserved +// and not mapped as zero until the journal names it, instead of asking VirtualQuery at every submission: under +// Wine a query waits for the virtual-memory lock, and the world's thousands of 64 KiB placeholders made the +// queries most of a refresh. +namespace leonida::title_reservations { + +// Allocates from host_heap, as title_write_watch does: the D3D12 layer asks under a tracker's lock. +struct State { + std::shared_mutex mutex; // ranges + host_heap::map<std::uintptr_t, std::uintptr_t> ranges; // base -> end; apart, never touching + std::atomic<std::size_t> count{0}; // ranges.size(), read without the lock + std::atomic<std::uint64_t> generation{1}; // moved whenever a range was released or dropped +}; + +inline State& state() { + static State s; + return s; +} + +// xmem: [base, base + size) was reserved as a placeholder or a physical-page window of the title's. Inside one range +// already, it is part of that reservation (a window replacing part of a placeholder). A range it only overlaps was +// released without xmem seeing it, and goes whole, as xmem's tables drop it: nothing outside the new reservation is +// known to be one of the title's any more. +inline void add(std::uintptr_t base, std::uintptr_t size) { + if (!size) return; + State& s = state(); + const std::uintptr_t end = base + size; ~~~~ --- Minor defensive guard: `if (!size || size > UINTPTR_MAX - base) return;` avoids unsigned wraparound if a caller ever passes an unvalidated size.
zmasi commented 2026-11-29 00:31:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:31:06Z.


#2391 | head f52796172d (merged cleanly with main 829530dbd0 — no conflicts on current main) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_host_prefix|d3d12_mapped_plane_async|d3d12_existing_heap_no_write_watch|d3d12_existing_heap_write_watch|d3d12_title_va|d3d12_title_va_shadow)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red proof: omitting s == (kZero | kClean) || in runtime/shims/d3d12_vulkan_device.cpp fails d3d12_existing_heap_no_write_watch at rt::d3d12::title_shadow_refresh_queries(device) == (full_walk ? 1u : 0u) in check_reserved_pages | green on PR+main: 6/6 CTests (d3d12_host_prefix, d3d12_mapped_plane_async, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch, d3d12_title_va, d3d12_title_va_shadow) pass in 18.54 s on RTX 3090 (vulkan slot-133 reserved pages: the reserved pages of a registered reservation are not asked about again; a committed one arrives, 0 runtime validation errors; check_reserved_pages also passes under LEONIDA_SHADOW_FULL_WALK=1, though note main's newer check_shared_pages at d3d12_existing_heap_test.cpp:1280 currently hardcodes EXPECT(clean_queries == 0) without checking LEONIDA_SHADOW_FULL_WALK); test_docs_encoding.py, test_docs_repo_paths.py, test_docs_env_vars.py (11/11 tests OK) and check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248167509 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2391#issuecomment-7248167509). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T00:31:06Z. --- #2391 | head f52796172d221875aa5758ea45a7623122885d93 (merged cleanly with main 829530dbd0196aa817dbec74aaafc79407b94b57 — no conflicts on current `main`) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_host_prefix|d3d12_mapped_plane_async|d3d12_existing_heap_no_write_watch|d3d12_existing_heap_write_watch|d3d12_title_va|d3d12_title_va_shadow)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red proof: omitting `s == (kZero | kClean) ||` in `runtime/shims/d3d12_vulkan_device.cpp` fails `d3d12_existing_heap_no_write_watch` at `rt::d3d12::title_shadow_refresh_queries(device) == (full_walk ? 1u : 0u)` in `check_reserved_pages` | green on PR+main: `6/6` CTests (`d3d12_host_prefix`, `d3d12_mapped_plane_async`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch`, `d3d12_title_va`, `d3d12_title_va_shadow`) pass in `18.54 s` on RTX 3090 (`vulkan slot-133 reserved pages: the reserved pages of a registered reservation are not asked about again; a committed one arrives`, `0` runtime validation errors; `check_reserved_pages` also passes under `LEONIDA_SHADOW_FULL_WALK=1`, though note `main`'s newer `check_shared_pages` at `d3d12_existing_heap_test.cpp:1280` currently hardcodes `EXPECT(clean_queries == 0)` without checking `LEONIDA_SHADOW_FULL_WALK`); `test_docs_encoding.py`, `test_docs_repo_paths.py`, `test_docs_env_vars.py` (`11/11` tests OK) and `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
timbot103 commented 2026-11-29 04:28:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:28:34Z.

Review: COMMENTED


Static audit of f52796172 against the supplied base. No builds, tests, or GPU runs were performed. The skip in runtime/shims/d3d12_vulkan_device.cpp:629 settles only private reserved pages. Committed PAGE_NOACCESS pages stay on the existing zero-page path, and a ranged journal entry makes a settled page eligible for requery.

  • runtime/shims/xmem.cpp:2289 — If another thread reserves the same address after title_release drops its fault lock but before forget, the first thread can remove the new reservation's registry coverage. The new placeholder then keeps paying for queries. Move the successful-release update into the scope that serializes it with reservation registration.
  • runtime/shims/xmem.cpp:916 — When VirtualAlloc2 rejects an ordinary replacement after isolate_placeholder succeeds, the placeholder survives but loses registry coverage. Call forget only after a successful replacement.
  • runtime/test/d3d12_existing_heap_test.cpp:902 — The commit and decommit checks use global journal notifications and thus miss a shim notification that drops a changed page. Please use ranged notifications for a multi-page partial change and add an xmem-backed case that goes through reserve, map, unmap, and release.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6101399872 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2391#pullrequestreview-6101399872). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T04:28:34Z. **Review:** COMMENTED --- Static audit of `f52796172` against the supplied base. No builds, tests, or GPU runs were performed. The skip in `runtime/shims/d3d12_vulkan_device.cpp:629` settles only private reserved pages. Committed `PAGE_NOACCESS` pages stay on the existing zero-page path, and a ranged journal entry makes a settled page eligible for requery. - `runtime/shims/xmem.cpp:2289` — If another thread reserves the same address after `title_release` drops its fault lock but before `forget`, the first thread can remove the new reservation's registry coverage. The new placeholder then keeps paying for queries. Move the successful-release update into the scope that serializes it with reservation registration. - `runtime/shims/xmem.cpp:916` — When `VirtualAlloc2` rejects an ordinary replacement after `isolate_placeholder` succeeds, the placeholder survives but loses registry coverage. Call `forget` only after a successful replacement. - `runtime/test/d3d12_existing_heap_test.cpp:902` — The commit and decommit checks use global journal notifications and thus miss a shim notification that drops a changed page. Please use ranged notifications for a multi-page partial change and add an xmem-backed case that goes through reserve, map, unmap, and release. AI-assisted.
aslan2142 commented 2026-12-01 16:44:43 +00:00 (Migrated from github.com)

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


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:7318146970 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2391#issuecomment-7318146970). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:44:43Z. --- 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!2391
No description provided.