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:
Diffstat (limited to 'runtime/test/title_memory_map_test.cpp')
-rw-r--r--runtime/test/title_memory_map_test.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/runtime/test/title_memory_map_test.cpp b/runtime/test/title_memory_map_test.cpp
index ba5a518a1..ff226d648 100644
--- a/runtime/test/title_memory_map_test.cpp
+++ b/runtime/test/title_memory_map_test.cpp
@@ -7,7 +7,8 @@
7// 3. a reader further behind than the journal holds is told so (it then looks at everything); 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; 8// 4. a change with no range overlaps every reader;
9// 5. TextureReadability keeps a positive answer, when asked to, until a retry; 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. 10// 6. a pass over 20,000 waiting textures probes only those under the one mapped block;
11// 7. between passes, sync_map retries only when a map change overlaps the texture's footprint.
11#include <windows.h> 12#include <windows.h>
12 13
13#include <cstdint> 14#include <cstdint>
@@ -142,6 +143,48 @@ int main() {
142 check(pass() == 4 && probes == 0, "a pass with no change probes nothing"); 143 check(pass() == 4 && probes == 0, "a pass with no change probes nothing");
143 } 144 }
144 145
146 // 7. Synchronous view checks between passes (sync_map): unrelated map changes cost no probe, an overlapping unmap
147 // defers without reading, and an overlapping map wakes a waiting texture before the next pass.
148 {
149 constexpr std::uintptr_t cpu = kBase + 0x20000000;
150 constexpr std::uint64_t size = 512 * 1024;
151 const std::uint64_t pass_generation = map::generation();
152 bool mapped = true;
153 unsigned probes = 0;
154 leonida::TextureReadability r;
155 const auto probe = [&] {
156 ++probes;
157 return mapped;
158 };
159 check(r.check(0, true, probe, true) && probes == 1 && !r.pending(),
160 "sync_map: initial probe caches a readable answer");
161 for (std::uintptr_t i = 0; i < 32; ++i)
162 map::changed(cpu + size + i * 0x10000, cpu + size + (i + 1) * 0x10000);
163 r.sync_map(pass_generation, cpu, size);
164 check(r.check(0, true, probe, true) && probes == 1,
165 "sync_map: map changes outside the footprint keep the cached answer");
166 r.sync_map(pass_generation, cpu, size);
167 check(r.check(0, true, probe, true) && probes == 1,
168 "sync_map: a second check at the same generation does nothing");
169
170 mapped = false;
171 map::changed(cpu + 0x10000, cpu + 0x20000);
172 r.sync_map(pass_generation, cpu, size);
173 check(!r.check(0, true, probe, true) && r.pending() && probes == 2,
174 "sync_map: an overlapping unmap between passes reprobes and defers");
175
176 map::changed(cpu - 0x10000, cpu);
177 r.sync_map(pass_generation, cpu, size);
178 check(!r.check(0, true, probe, true) && r.pending() && probes == 2,
179 "sync_map: an adjacent non-overlapping change leaves a pending texture waiting");
180
181 mapped = true;
182 map::changed(cpu, cpu + size);
183 r.sync_map(pass_generation, cpu, size);
184 check(r.check(0, true, probe, true) && !r.pending() && probes == 3,
185 "sync_map: an overlapping map between passes wakes a pending texture at once");
186 }
187
145 std::printf("%d checks, %d failures\n", g_checks, g_failures); 188 std::printf("%d checks, %d failures\n", g_checks, g_failures);
146 return g_failures ? 1 : 0; 189 return g_failures ? 1 : 0;
147} 190}