diff options
| author | Dimitar Pavlov <360593571+azsekazvamdimitar@users.noreply.github.com> | 2026-11-25 15:39:43 +0200 |
|---|---|---|
| committer | Dimitar Pavlov <360593571+azsekazvamdimitar@users.noreply.github.com> | 2026-11-26 11:18:19 +0200 |
| commit | 49a0b69fcdb80db1f2a44ce7ca0ab8dfdec1e403 (patch) | |
| tree | dd53c9909834cbfeec85e7cbd188595c8a2d9931 /runtime/shims/xmem.cpp | |
| parent | a73a57e1339be072baf5522351c8ec7f1482b56b (diff) | |
d3d12: slot-133 shadows guard aliased title pages at every address instead of copying them each submission (RT-SHADOW-ALIAS-GUARD)
A page xmem maps at two addresses was copied whole at every refresh, since
a guard on one view doesn't fault a write through the other: about 1 GB a
submission after the story load on a retail boot. ShadowPages now arms the
geometry watch's cells of each aliased 64 KiB block at every address it is
mapped and copies a block only when a cell's version moved. xmem tells the
cells of a mapping change after updating the peers, and of list value
writes made through the section.
AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index 384f7bd27..44c6f140b 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -543,8 +543,8 @@ using AddressList = std::vector<uintptr_t, leonida::host_heap::Allocator<uintptr | |||
| 543 | HostUnorderedMap<uintptr_t, AddressList> g_alias_peers; | 543 | HostUnorderedMap<uintptr_t, AddressList> g_alias_peers; |
| 544 | 544 | ||
| 545 | // With g_phys_mutex held. Keeps leonida::title_page_aliases in step: a page mapped at two or more addresses is | 545 | // With g_phys_mutex held. Keeps leonida::title_page_aliases in step: a page mapped at two or more addresses is |
| 546 | // aliased at each of them (the D3D12 layer's slot-133 shadows copy those pages at every submission instead of | 546 | // aliased at each of them (the D3D12 layer's slot-133 shadows guard those pages at every address, since a write |
| 547 | // waiting for a write fault, which a write through another address doesn't raise). | 547 | // through one address doesn't fault a guard on another). |
| 548 | void note_mapping(uint64_t page, uintptr_t address, bool mapped) { | 548 | void note_mapping(uint64_t page, uintptr_t address, bool mapped) { |
| 549 | auto& addresses = g_page_addresses[page]; | 549 | auto& addresses = g_page_addresses[page]; |
| 550 | if (mapped) { | 550 | if (mapped) { |
| @@ -553,12 +553,6 @@ void note_mapping(uint64_t page, uintptr_t address, bool mapped) { | |||
| 553 | addresses.erase(address); | 553 | addresses.erase(address); |
| 554 | leonida::title_page_aliases::set(address, false); | 554 | leonida::title_page_aliases::set(address, false); |
| 555 | } | 555 | } |
| 556 | using namespace leonida::geometry_writes; | ||
| 557 | if (state().count.load(std::memory_order_acquire)) { | ||
| 558 | notify(address, address + kPhysicalPageSize, Event::mapping); | ||
| 559 | for (auto other : addresses) | ||
| 560 | if (other != address) notify(other, other + kPhysicalPageSize, Event::mapping); | ||
| 561 | } | ||
| 562 | const bool aliased = addresses.size() > 1; | 556 | const bool aliased = addresses.size() > 1; |
| 563 | for (const uintptr_t at : addresses) leonida::title_page_aliases::set(at, aliased); | 557 | for (const uintptr_t at : addresses) leonida::title_page_aliases::set(at, aliased); |
| 564 | const std::unique_lock aliases(g_alias_lock); | 558 | const std::unique_lock aliases(g_alias_lock); |
| @@ -573,6 +567,13 @@ void note_mapping(uint64_t page, uintptr_t address, bool mapped) { | |||
| 573 | for (const uintptr_t other : addresses) | 567 | for (const uintptr_t other : addresses) |
| 574 | if (other != at) peers.push_back(other); | 568 | if (other != at) peers.push_back(other); |
| 575 | } | 569 | } |
| 570 | // After the peers: a cell's watcher that sees the new mapping asks geometry_aliases for the addresses again. | ||
| 571 | using namespace leonida::geometry_writes; | ||
| 572 | if (state().count.load(std::memory_order_acquire)) { | ||
| 573 | notify(address, address + kPhysicalPageSize, Event::mapping); | ||
| 574 | for (auto other : addresses) | ||
| 575 | if (other != address) notify(other, other + kPhysicalPageSize, Event::mapping); | ||
| 576 | } | ||
| 576 | if (addresses.empty()) g_page_addresses.erase(page); | 577 | if (addresses.empty()) g_page_addresses.erase(page); |
| 577 | } | 578 | } |
| 578 | 579 | ||
| @@ -2726,6 +2727,8 @@ bool write_title_bytes(const void* address, const void* bytes, std::size_t size) | |||
| 2726 | std::memcpy(host + offset, static_cast<const std::uint8_t*>(bytes) + done, chunk); | 2727 | std::memcpy(host + offset, static_cast<const std::uint8_t*>(bytes) + done, chunk); |
| 2727 | done += chunk; | 2728 | done += chunk; |
| 2728 | } | 2729 | } |
| 2730 | // Through the section, not the title's views: no fault tells a guard of them (a shadow's cells) of the write. | ||
| 2731 | leonida::geometry_writes::notify(start, start + size, leonida::geometry_writes::Event::write); | ||
| 2729 | return true; | 2732 | return true; |
| 2730 | } | 2733 | } |
| 2731 | 2734 | ||