diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 09:16:27 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 09:16:27 -0500 |
| commit | f5f67b4a9daae13d5a8a68358c1167e6866ec293 (patch) | |
| tree | e9462d71f8ceabc75ff562e9c728df8a614637cf /runtime/src | |
| parent | f5113e3da53f278873b473f1db7b1b08dbc8ceb6 (diff) | |
| parent | d088ea79b8394c04a46ec19efb2922a7cd3faae3 (diff) | |
Merge #2240 from zmasi: sync TitleTexture readability against title_memory_map between passes (RT-TITLE-TEXTURE-MAP-GEN)
Head d088ea79b.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/title_texture_memory.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/runtime/src/title_texture_memory.h b/runtime/src/title_texture_memory.h index a97e5bed6..ff9f004e0 100644 --- a/runtime/src/title_texture_memory.h +++ b/runtime/src/title_texture_memory.h | |||
| @@ -1,14 +1,17 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | #include <windows.h> | 2 | #include <windows.h> |
| 3 | #include <algorithm> | ||
| 3 | #include <cstddef> | 4 | #include <cstddef> |
| 4 | #include <cstdint> | 5 | #include <cstdint> |
| 5 | #include <limits> | 6 | #include <limits> |
| 6 | 7 | ||
| 8 | #include "title_page_watch.h" | ||
| 9 | |||
| 7 | namespace leonida { | 10 | namespace leonida { |
| 8 | 11 | ||
| 9 | // Keep negative probes until the title changes the map or a writer reports this footprint. With cache_success, | 12 | // Keep negative probes until the title changes the map or a writer reports this footprint. With cache_success, |
| 10 | // positive ones too: a caller that is told of every map change over the footprint (retry) and reads it under a guard | 13 | // positive ones too: a caller that is told of every map change over the footprint (retry or sync_map) and reads it |
| 11 | // (a page gone since faults into a defer) need not walk the pages before every read. | 14 | // under a guard (a page gone since faults into a defer) need not walk the pages before every read. |
| 12 | class TextureReadability { | 15 | class TextureReadability { |
| 13 | public: | 16 | public: |
| 14 | template<class Probe> | 17 | template<class Probe> |
| @@ -16,16 +19,37 @@ public: | |||
| 16 | if (cache_failure && pending_ && !retry_ && generation_ == generation) return false; | 19 | if (cache_failure && pending_ && !retry_ && generation_ == generation) return false; |
| 17 | if (cache_success && probed_ && !pending_ && !retry_ && generation_ == generation) return true; | 20 | if (cache_success && probed_ && !pending_ && !retry_ && generation_ == generation) return true; |
| 18 | generation_ = generation; // snapshot before the probe so a concurrent map change is noticed | 21 | generation_ = generation; // snapshot before the probe so a concurrent map change is noticed |
| 22 | map_generation_ = title_memory_map::generation(); | ||
| 19 | retry_ = false; | 23 | retry_ = false; |
| 20 | probed_ = true; | 24 | probed_ = true; |
| 21 | pending_ = !probe(); | 25 | pending_ = !probe(); |
| 22 | return !pending_; | 26 | return !pending_; |
| 23 | } | 27 | } |
| 28 | // Between refresh passes, check whether the map journal recorded a change over [cpu, cpu + size) since both | ||
| 29 | // this texture's last probe and the last pass's sweep. | ||
| 30 | void sync_map(std::uint64_t pass_generation, std::uintptr_t cpu, std::uint64_t size) { | ||
| 31 | if (!probed_ || retry_) return; | ||
| 32 | const std::uint64_t since = (std::max)(map_generation_, pass_generation); | ||
| 33 | if (title_memory_map::generation() == since) return; | ||
| 34 | const std::uintptr_t end = size > (std::numeric_limits<std::uintptr_t>::max)() - cpu | ||
| 35 | ? (std::numeric_limits<std::uintptr_t>::max)() | ||
| 36 | : cpu + static_cast<std::uintptr_t>(size); | ||
| 37 | std::uint64_t now = 0; | ||
| 38 | bool overlapped = false; | ||
| 39 | if (!title_memory_map::changes_since( | ||
| 40 | since, now, cpu, end, [&](std::uintptr_t, std::uintptr_t) { overlapped = true; }) || | ||
| 41 | overlapped) { | ||
| 42 | retry_ = true; | ||
| 43 | } else { | ||
| 44 | map_generation_ = now; | ||
| 45 | } | ||
| 46 | } | ||
| 24 | void defer() { pending_ = true; } // mapping disappeared between the probe and the read | 47 | void defer() { pending_ = true; } // mapping disappeared between the probe and the read |
| 25 | void retry() { retry_ = true; } | 48 | void retry() { retry_ = true; } |
| 26 | bool pending() const { return pending_; } | 49 | bool pending() const { return pending_; } |
| 27 | private: | 50 | private: |
| 28 | std::uint64_t generation_ = 0; | 51 | std::uint64_t generation_ = 0; |
| 52 | std::uint64_t map_generation_ = 0; | ||
| 29 | bool pending_ = false, retry_ = false, probed_ = false; | 53 | bool pending_ = false, retry_ = false, probed_ = false; |
| 30 | }; | 54 | }; |
| 31 | 55 | ||