[PR #1867] d3d12: slot-133 shadows guard aliased title pages at every address instead of copying them each submission (RT-SHADOW-ALIAS-GUARD) #1879

Open
opened 2026-11-26 21:19:16 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1867
Author: @azsekazvamdimitar
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: shadow-aliased-guard


📝 Commits (1)

  • 49a0b69 d3d12: slot-133 shadows guard aliased title pages at every address instead of copying them each submission (RT-SHADOW-ALIAS-GUARD)

📊 Changes

5 files changed (+241 additions, -44 deletions)

View changed files

📝 runtime/README.md (+1 -1)
📝 runtime/shims/d3d12_vulkan_device.cpp (+147 -34)
📝 runtime/shims/xmem.cpp (+11 -8)
📝 runtime/src/title_page_watch.h (+2 -1)
📝 runtime/test/d3d12_existing_heap_test.cpp (+80 -0)

📄 Description

Claimed in the coordination issue as: RT-SHADOW-ALIAS-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164143777)

What and why

The slot-133 shadows and title windows (ShadowPages, runtime/shims/d3d12_vulkan_device.cpp) never guarded a page xmem maps at more than one address (title_page_aliases): a guard on one view doesn't fault a write through the other, so every refresh copied those pages whole. After the story load the stream pools make that the bulk of each submission. On my retail boot (main 0d80bc5df, RTX 3090, GE-Proton, LEONIDA_TITLE_WATCHDOG=0) the by-cause line read about 987 MB aliased, 7 MB guarded and 2.4 MB pinned a submission, about 300 ms of each one, and the title presented about 0.3 frames a second. LEONIDA_SHADOW_ALIAS_MS can only make those copies older.

This guards the aliased blocks at every address instead, with the geometry watch's cells (runtime/src/title_geometry_watch.h), which the geometry views already use for the same problem:

  • ShadowPages::update_aliased, at the start of refresh() and outside the tracker's lock, acquires a cell for each aliased 64 KiB block the copies read, at its own address and at each other address geometry_aliases names, and arms them (read-only at every address). A block whose cells kept their versions since they were armed is skipped by the walk; any other is armed again before the walk copies it, so a write after the arming is copied at the next refresh. A write through any address faults into shadow_write_fault, which already notifies the geometry watch first; a remap, commit or protection change moves a cell's version too.
  • A block is still copied every time when no other address is known (no xmem), when a page is pinned for a kernel write (arm refuses it), and in the refreshes LEONIDA_SHADOW_ALIAS_MS throttles.
  • xmem: note_mapping now tells the cells of a mapping change after it updated the peers, so a watcher that sees the new mapping gets the new addresses; write_title_bytes (list value writes, through the section rather than the title's views) notifies the geometry watch, since no fault tells a guard of those writes.

The same retail boot, after the story load:

main 0d80bc5df main, LEONIDA_SHADOW_ALIAS_MS=3600000 (aliased pages copied once: stale, an upper bound) this pull request (on 98c2f7777)
aliased copies a submission ~987 MB 0 2.3-5 MB
shadow refresh a submission ~300 ms 12-130 ms 23-150 ms
frames a second ~0.3 0.6-11 1.1-9

All three runs end in the same world-start device loss, about 180-220 s after the story load starts (queue waits on memory nothing wrote, indirect draws not emitted, then VK_ERROR_DEVICE_LOST). This pull request doesn't change that; it makes the loading screen run at a usable rate up to that point. No frames were captured that show a visible difference.

Tested

  • d3d12_existing_heap_test gains check_aliased_guard: one page mapped at A and B (the test answers geometry_writes::aliases) is read-only at both addresses between submissions, a write through an unreported third view stays stale (nothing was copied), a write through B faults and arrives with it, and both addresses are writable again after the shadow is released. The existing check_aliased_write, which has no other address to arm, still copies every time and passes.
  • On this branch (rebased on main a73a57e13), cross-built with clang-cl and run under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11): d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_existing_heap_write_watch, d3d12_xmem_placed, d3d12_title_va, d3d12_title_va_shadow and xs_proxy_mock pass under both.
  • xmem fails one check, "writing to 512 of them charges about those 512 pages", under Wine; it fails the same way on main without this change.
  • The boot numbers above are from the same change on 98c2f7777. Not run on Windows.

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1867 **Author:** [@azsekazvamdimitar](https://github.com/azsekazvamdimitar) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `shadow-aliased-guard` --- ### 📝 Commits (1) - [`49a0b69`](https://github.com/ubiquitarianism/leonida/commit/49a0b69fcdb80db1f2a44ce7ca0ab8dfdec1e403) d3d12: slot-133 shadows guard aliased title pages at every address instead of copying them each submission (RT-SHADOW-ALIAS-GUARD) ### 📊 Changes **5 files changed** (+241 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `runtime/README.md` (+1 -1) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+147 -34) 📝 `runtime/shims/xmem.cpp` (+11 -8) 📝 `runtime/src/title_page_watch.h` (+2 -1) 📝 `runtime/test/d3d12_existing_heap_test.cpp` (+80 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-SHADOW-ALIAS-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164143777) ### What and why The slot-133 shadows and title windows (`ShadowPages`, `runtime/shims/d3d12_vulkan_device.cpp`) never guarded a page xmem maps at more than one address (`title_page_aliases`): a guard on one view doesn't fault a write through the other, so every refresh copied those pages whole. After the story load the stream pools make that the bulk of each submission. On my retail boot (main 0d80bc5df, RTX 3090, GE-Proton, `LEONIDA_TITLE_WATCHDOG=0`) the by-cause line read about 987 MB aliased, 7 MB guarded and 2.4 MB pinned a submission, about 300 ms of each one, and the title presented about 0.3 frames a second. `LEONIDA_SHADOW_ALIAS_MS` can only make those copies older. This guards the aliased blocks at every address instead, with the geometry watch's cells (`runtime/src/title_geometry_watch.h`), which the geometry views already use for the same problem: - `ShadowPages::update_aliased`, at the start of `refresh()` and outside the tracker's lock, acquires a cell for each aliased 64 KiB block the copies read, at its own address and at each other address `geometry_aliases` names, and arms them (read-only at every address). A block whose cells kept their versions since they were armed is skipped by the walk; any other is armed again before the walk copies it, so a write after the arming is copied at the next refresh. A write through any address faults into `shadow_write_fault`, which already notifies the geometry watch first; a remap, commit or protection change moves a cell's version too. - A block is still copied every time when no other address is known (no xmem), when a page is pinned for a kernel write (`arm` refuses it), and in the refreshes `LEONIDA_SHADOW_ALIAS_MS` throttles. - xmem: `note_mapping` now tells the cells of a mapping change after it updated the peers, so a watcher that sees the new mapping gets the new addresses; `write_title_bytes` (list value writes, through the section rather than the title's views) notifies the geometry watch, since no fault tells a guard of those writes. The same retail boot, after the story load: | | main 0d80bc5df | main, `LEONIDA_SHADOW_ALIAS_MS=3600000` (aliased pages copied once: stale, an upper bound) | this pull request (on 98c2f7777) | |---|---|---|---| | aliased copies a submission | ~987 MB | 0 | 2.3-5 MB | | shadow refresh a submission | ~300 ms | 12-130 ms | 23-150 ms | | frames a second | ~0.3 | 0.6-11 | 1.1-9 | All three runs end in the same world-start device loss, about 180-220 s after the story load starts (queue waits on memory nothing wrote, indirect draws not emitted, then `VK_ERROR_DEVICE_LOST`). This pull request doesn't change that; it makes the loading screen run at a usable rate up to that point. No frames were captured that show a visible difference. ### Tested - `d3d12_existing_heap_test` gains `check_aliased_guard`: one page mapped at A and B (the test answers `geometry_writes::aliases`) is read-only at both addresses between submissions, a write through an unreported third view stays stale (nothing was copied), a write through B faults and arrives with it, and both addresses are writable again after the shadow is released. The existing `check_aliased_write`, which has no other address to arm, still copies every time and passes. - On this branch (rebased on main a73a57e13), cross-built with clang-cl and run under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11): `d3d12_existing_heap`, `d3d12_existing_heap_no_write_watch`, `d3d12_existing_heap_write_watch`, `d3d12_xmem_placed`, `d3d12_title_va`, `d3d12_title_va_shadow` and `xs_proxy_mock` pass under both. - `xmem` fails one check, "writing to 512 of them charges about those 512 pages", under Wine; it fails the same way on main without this change. - The boot numbers above are from the same change on 98c2f7777. Not run on Windows. 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1879
No description provided.