Repository navigation
d3d12: slot-133 shadows pass over the title's reserved pages until the journal names them (RT-SHADOW-RESERVATION-SKIP) - #2391
Conversation
|
I tested head There is now one merge conflict against A readback catches an incorrect resolution. I extended
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). |
…e journal names them (RT-SHADOW-RESERVATION-SKIP) 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.
a525962 to
f527961
Compare
lixonik
left a comment
There was a problem hiding this comment.
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_validationnot installed locally). ctest:xmem,d3d12_existing_heap, andd3d12_existing_heap_no_write_watchall passed (3/3). Also verifiedcheck_reserved_pagespasses underLEONIDA_SHADOW_FULL_WALK=1.scripts/check_no_game_data.pyandgit 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 intitle_memory_map, andShadowPages::write_back()still treatskZero | kCleanpages asheld, so skipping re-queries on settledMEM_RESERVE | MEM_PRIVATEpages insidetitle_reservationsis sound. - One defensive gap outside the diff hunks in
ShadowPages::absorb()(runtime/shims/d3d12_vulkan_device.cpp:769):absorb()resetsmap_generation_ = ~std::uint64_t(0)whenother.map_generation_ != map_generation_, but does not do the same forreservation_generation_. With currentadd_shadow()/refresh_shadows()orderingkeepshould not normally be ahead ofother, but mirroringif (other.reservation_generation_ != reservation_generation_) reservation_generation_ = ~std::uint64_t(0);preventskeepfrom ever silently inheriting stalekZero | kCleanpages fromotherif ordering or per-tracker refreshes change. - Two minor inline notes on
xmem.cppandtitle_page_watch.h.
AI-assisted.
| } | ||
| // 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); |
There was a problem hiding this comment.
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.
| inline void add(std::uintptr_t base, std::uintptr_t size) { | ||
| if (!size) return; | ||
| State& s = state(); | ||
| const std::uintptr_t end = base + size; |
There was a problem hiding this comment.
Minor defensive guard: if (!size || size > UINTPTR_MAX - base) return; avoids unsigned wraparound if a caller ever passes an unvalidated size.
Claimed in the coordination issue as: RT-SHADOW-RESERVATION-SKIP (#1608 (comment))
Note: #1867 changes the same lines of the walk's skip rule. This applies to
mainwithout 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 indocs/runtime_imports.mdthat nothing commits into a window with kernel32's VirtualAlloc, which a placeholder refuses. So: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.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 a73a57e 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):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_denoisingand 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:Tested
d3d12_existing_heapgains 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.d3d12_existing_heap(with and without write watch),d3d12_host_prefix,d3d12_mapped_plane_async,d3d12_xmem_placed,d3d12_title_va(+_shadow) andxs_proxy_mockpass under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11);d3d12_existing_heapalso withLEONIDA_SHADOW_FULL_WALK=1.main935a2cd.GPUs tested: NVIDIA GeForce RTX 3090, driver 590.48.01, Debian 13 (Linux 6.12), Wine/Proton as above.
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.