upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/title_memory_map_test.cpp
diff options
context:
space:
mode:
authorMoriz82 <72836413+Moriz82@users.noreply.github.com>2026-11-25 03:44:31 -0600
committerMoriz82 <72836413+Moriz82@users.noreply.github.com>2026-11-25 03:44:43 -0600
commitba626820ec54776fb0faffa2413727285befe85b (patch)
tree95a99f8029785bec5f3b07b7efc4277e5bc7510b /runtime/test/title_memory_map_test.cpp
parent3de22a19047b168d28a7a11152bf05d18ed0062e (diff)
Integrate post-story-load memory, queue and Vulkan runtime changes
Preserve physical window aliases across remaps, order console list values, and replay bounded indirect graphics with captured draw state. Coordinate pipeline lifetime, texture refresh and queue teardown. Add synthetic CPU and GPU coverage for the integrated paths. Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-authored-by: ivanepsilondelta <264061546+ivanepsilondelta@users.noreply.github.com>
Diffstat (limited to 'runtime/test/title_memory_map_test.cpp')
-rw-r--r--runtime/test/title_memory_map_test.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/runtime/test/title_memory_map_test.cpp b/runtime/test/title_memory_map_test.cpp
new file mode 100644
index 000000000..ba5a518a1
--- /dev/null
+++ b/runtime/test/title_memory_map_test.cpp
@@ -0,0 +1,147 @@
1// leonida::title_memory_map (runtime/src/title_page_watch.h): the journal of changes to the title's address space, by
2// range, and what the D3D12 layer's readers build on it: the title-texture pass probes again only the textures a
3// change overlaps (TextureReadability, src/title_texture_memory.h), and a slot-133 shadow queries again only its
4// pages a change overlaps. No game data, no GPU.
5// 1. a reader is told the changes since its generation that overlap its range, clipped and in whole pages;
6// 2. a change elsewhere moves the generation but tells the reader nothing;
7// 3. a reader further behind than the journal holds is told so (it then looks at everything);
8// 4. a change with no range overlaps every reader;
9// 5. TextureReadability keeps a positive answer, when asked to, until a retry;
10// 6. a pass over 20,000 waiting textures probes only those under the one mapped block.
11#include <windows.h>
12
13#include <cstdint>
14#include <cstdio>
15#include <utility>
16#include <vector>
17
18#include "../src/title_page_watch.h"
19#include "../src/title_texture_memory.h"
20#include "../src/title_texture_refresh.h"
21
22namespace {
23
24namespace map = leonida::title_memory_map;
25
26int g_checks = 0;
27int g_failures = 0;
28
29void check(bool condition, const char* what) {
30 ++g_checks;
31 std::printf("%s %s\n", condition ? "PASS" : "FAIL", what);
32 if (!condition) ++g_failures;
33}
34
35using Ranges = std::vector<std::pair<std::uintptr_t, std::uintptr_t>>;
36
37bool since(std::uint64_t from, std::uint64_t& now, std::uintptr_t lo, std::uintptr_t hi, Ranges& out) {
38 out.clear();
39 return map::changes_since(from, now, lo, hi, [&](std::uintptr_t a, std::uintptr_t b) { out.emplace_back(a, b); });
40}
41
42} // namespace
43
44int main() {
45 constexpr std::uintptr_t kBase = 0x7000000000; // no memory is touched: the journal only records addresses
46 Ranges got;
47 std::uint64_t now = 0;
48
49 // 1. Overlapping changes only, clipped to the reader's range, rounded out to whole 4 KiB pages.
50 const std::uint64_t start = map::generation();
51 map::changed(kBase + 0x10010, kBase + 0x10020); // inside, not page-aligned
52 map::changed(kBase + 0x90000, kBase + 0xa0000); // outside
53 map::changed(kBase + 0x1f000, kBase + 0x31000); // straddles the reader's end
54 check(since(start, now, kBase + 0x10000, kBase + 0x20000, got), "the journal holds the reader's changes");
55 check(now == start + 3, "the reader is brought to the latest generation");
56 check(got.size() == 2 && got[0] == std::make_pair(kBase + 0x10000, kBase + 0x11000) &&
57 got[1] == std::make_pair(kBase + 0x1f000, kBase + 0x20000),
58 "two overlapping changes, in whole pages, clipped to the reader's range");
59
60 // 2. Caught up: a change elsewhere tells nothing, but the generation moves.
61 const std::uint64_t caught_up = now;
62 map::changed(reinterpret_cast<const void*>(kBase + 0x400000), 0x10000);
63 check(since(caught_up, now, kBase + 0x10000, kBase + 0x20000, got) && got.empty() && now == caught_up + 1,
64 "a change outside the range tells the reader nothing");
65
66 // 3. A reader more than kJournal changes behind is told it missed some.
67 const std::uint64_t behind = map::generation();
68 for (std::size_t i = 0; i <= map::kJournal; ++i) map::changed(kBase + 0x800000, kBase + 0x801000);
69 check(!since(behind, now, kBase, kBase + 0x1000, got) && got.empty(),
70 "a reader further behind than the journal is told to look at everything");
71 const std::uint64_t latest = map::generation();
72 check(since(latest - 10, now, kBase + 0x800000, kBase + 0x801000, got) && got.size() == 10,
73 "a reader within the journal is told each of its changes");
74
75 // 4. No range: everyone's.
76 const std::uint64_t before_all = map::generation();
77 map::changed();
78 check(since(before_all, now, kBase + 0x123000, kBase + 0x124000, got) && got.size() == 1 &&
79 got[0] == std::make_pair(kBase + 0x123000, kBase + 0x124000),
80 "a change with no range overlaps every reader");
81
82 // 5. TextureReadability: positive answers kept until a retry when asked to, else probed every time as before.
83 {
84 leonida::TextureReadability r;
85 unsigned probes = 0;
86 const auto readable = [&] { ++probes; return true; };
87 for (int i = 0; i < 100; ++i) r.check(0, true, readable, true);
88 check(probes == 1 && !r.pending(), "a readable texture is probed once in 100 checks with cache_success");
89 r.retry();
90 check(r.check(0, true, readable, true) && probes == 2, "a retry probes it again");
91 for (int i = 0; i < 10; ++i) r.check(0, true, readable);
92 check(probes == 12, "without cache_success every check probes (unchanged behaviour)");
93 r.defer(); // a page went between the probe and the read
94 const auto unreadable = [&] { ++probes; return false; };
95 check(!r.check(0, true, unreadable, true) && probes == 12, "a deferred texture waits for a retry");
96 r.retry();
97 check(!r.check(0, true, unreadable, true) && probes == 13 && r.pending(), "the retry finds it unreadable");
98 }
99
100 // 6. The pass: 20,000 waiting textures of 16 KiB each; one 64 KiB block is mapped and reported. Only the four
101 // textures in it are probed again; the next pass, with no change, probes none.
102 {
103 struct Texture {
104 std::uintptr_t cpu;
105 std::uint64_t size;
106 leonida::TextureReadability memory;
107 };
108 std::vector<Texture> textures(20000);
109 unsigned probes = 0;
110 std::uintptr_t mapped_from = 0, mapped_to = 0;
111 const auto probe = [&](const Texture& t) {
112 ++probes;
113 return t.cpu >= mapped_from && t.cpu + t.size <= mapped_to;
114 };
115 for (std::size_t i = 0; i < textures.size(); ++i) {
116 textures[i].cpu = kBase + 0x10000000 + i * 0x4000;
117 textures[i].size = 0x4000;
118 textures[i].memory.check(0, true, [&] { return probe(textures[i]); }, true);
119 }
120 std::uint64_t pass_generation = map::generation();
121 const auto pass = [&] {
122 leonida::TitleWriteRanges changes;
123 std::uint64_t upto = 0;
124 const bool all = !map::changes_since(pass_generation, upto, 0, UINTPTR_MAX,
125 [&](std::uintptr_t a, std::uintptr_t b) { changes.emplace_back(a, b); });
126 pass_generation = upto;
127 leonida::merge_title_writes(changes);
128 unsigned readable = 0;
129 for (Texture& t : textures) {
130 if (all || leonida::title_write_overlaps(changes, t.cpu, t.cpu + t.size)) t.memory.retry();
131 readable += t.memory.check(0, true, [&] { return probe(t); }, true);
132 }
133 return readable;
134 };
135 probes = 0;
136 mapped_from = kBase + 0x10000000 + 0x10000 * 100;
137 mapped_to = mapped_from + 0x10000;
138 map::changed(mapped_from, mapped_to);
139 const unsigned readable = pass();
140 check(probes == 4 && readable == 4, "a mapped block probes and finds only the four textures in it");
141 probes = 0;
142 check(pass() == 4 && probes == 0, "a pass with no change probes nothing");
143 }
144
145 std::printf("%d checks, %d failures\n", g_checks, g_failures);
146 return g_failures ? 1 : 0;
147}