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

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

@⁠azsekazvamdimitar on GitHub · 2026-11-26 17:05 UTC · original
azsekazvamdimitar:shadow-reservation-skip → main · +194 −16 · 5 files · 1 commits · draft

Claimed in the coordination issue as: RT-SHADOW-RESERVATION-SKIP (#1608)

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.
**@⁠azsekazvamdimitar** on GitHub · 2026-11-26 17:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2391) `azsekazvamdimitar:shadow-reservation-skip` → `main` · +194 −16 · 5 files · 1 commits · draft Claimed in the coordination issue as: RT-SHADOW-RESERVATION-SKIP (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) 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.
Under Wine most of the shadow walk after the story load is VirtualQuery of
reserved pages: the stream pools' unmapped 64 KiB slots inside xmem's
physical-page windows, 450-7,500 queries a refresh, 1.5 us each when quiet
and 15-70 us under Wine's virtual-memory lock while the title maps memory.

xmem now records the title's placeholders and windows in
leonida::title_reservations and forgets them on every release. The walk marks
a page there that VirtualQuery found reserved and private as settled and
passes over it until the title memory journal names it, a release moves the
registry's generation, or a full walk runs. Aliased, pinned and write-watched
pages never settle.

First world minute on an RTX 3090 (GE-Proton): VirtualQuery calls a refresh
443-1,616 -> 70-136, walk 16.5-40.4 -> 10.2-21.4 ms.

AI-assisted. Tested: shadow tests under WineHQ 11.22 and GE-Proton11-14,
also with LEONIDA_SHADOW_FULL_WALK=1; RTX 3090, NVIDIA 590.48.01.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 17:11:37 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 18:21 UTC · original

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

**@⁠ecox982745** on GitHub · 2026-11-26 18:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2391#issuecomment-7200360724) 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).
This pull request has changes conflicting with the target branch.
  • runtime/shims/d3d12_vulkan_device.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/2391/head:github-bot/gh-2391'
git switch 'github-bot/gh-2391'

Merge

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