upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorstar41905453-coder <star41905453-coder@users.noreply.github.com>2026-11-25 21:59:18 +0000
committerstar41905453-coder <star41905453-coder@users.noreply.github.com>2026-11-25 21:59:18 +0000
commit04290dd2d12e027ddfbd82ea6e482999610f279f (patch)
treeb50d6c9bc5bc9e10edf931b4e5a4413ee7096868 /runtime/src
parent9f9a7c5f30f8559c52675780cf84004571b8d6e5 (diff)
d3d12: a window's GPU writes go back to the title's pages (RT-TITLE-WINDOW-WRITE-BACK)
A window of the title's memory is a read-side mirror refreshed before every submission, so a UAV or raw write into one landed in the copy and the title never saw it. At the world start that is the WRITE_INVALID device loss of #1537 (QemmHD, 160 s into the load, past the cap): the culling compute writes through addresses that name title memory, and nothing ever reads the result back into the pages. The layer now keeps every title range a submission's bindings reach (the resolve path, so root views, table V#s and created views alike) and copies those ranges from the copy to the title's pages at the start of the next refresh, before the forward copy. A page the title wrote in between takes the title's newer bytes and its GPU result is dropped; the tracker already knows those pages (guarded, hot and clean). Caps: 8,192 ranges and 64 MiB a submission, logged once; LEONIDA_TITLE_WRITEBACK=0 turns it off. Test: d3d12_title_window_write_back, a dispatch through a root UAV at the title's pages: the written words reach the pages, hold across two submissions, and a title write survives the next forward copy. No game files. Item: RT-TITLE-WINDOW-WRITE-BACK (claimed in #1608) Wine against llvmpipe.
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/title_va_alias.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/runtime/src/title_va_alias.h b/runtime/src/title_va_alias.h
index b3de5ce70..0d44050bb 100644
--- a/runtime/src/title_va_alias.h
+++ b/runtime/src/title_va_alias.h
@@ -42,6 +42,9 @@ public:
42 // memory (an arena VA, a buffer of the layer's). 42 // memory (an arena VA, a buffer of the layer's).
43 using Resolver = bool (*)(void* context, std::uint64_t va, std::uint64_t bytes, std::uint64_t& shader_va); 43 using Resolver = bool (*)(void* context, std::uint64_t va, std::uint64_t bytes, std::uint64_t& shader_va);
44 using TableScanner = void (*)(void* context, std::uint64_t table_va, std::uint32_t descriptors); 44 using TableScanner = void (*)(void* context, std::uint64_t table_va, std::uint32_t descriptors);
45 // Every binding resolved to a copy of the title's memory: [va, va + bytes) as they are reached at (the device keeps
46 // them for the copy back after the submission, see DeviceState::write_back_titles).
47 using Noter = void (*)(void* context, std::uint64_t va, std::uint64_t bytes);
45 48
46 // [title_va, title_va + bytes) is reached as [shader_va, shader_va + bytes). A range that overlaps a live one 49 // [title_va, title_va + bytes) is reached as [shader_va, shader_va + bytes). A range that overlaps a live one
47 // replaces it (the title has placed a new buffer over pages it released). False for an empty or wrapping range. 50 // replaces it (the title has placed a new buffer over pages it released). False for an empty or wrapping range.
@@ -147,6 +150,7 @@ public:
147 std::uint64_t to = shader_va(va); 150 std::uint64_t to = shader_va(va);
148 if (to != va) { 151 if (to != va) {
149 translated_[kind].fetch_add(1, std::memory_order_relaxed); 152 translated_[kind].fetch_add(1, std::memory_order_relaxed);
153 note_reached(va, bytes);
150 return to; 154 return to;
151 } 155 }
152 Resolver resolver; 156 Resolver resolver;
@@ -158,6 +162,7 @@ public:
158 } 162 }
159 if (!resolver || !resolver(context, va, bytes, to)) return va; 163 if (!resolver || !resolver(context, va, bytes, to)) return va;
160 (to != va ? translated_ : untranslated_)[kind].fetch_add(1, std::memory_order_relaxed); 164 (to != va ? translated_ : untranslated_)[kind].fetch_add(1, std::memory_order_relaxed);
165 if (to != va) note_reached(va, bytes);
161 return to; 166 return to;
162 } 167 }
163 168
@@ -167,6 +172,18 @@ public:
167 if (va && shader_va(va) != va) untranslated_[kind].fetch_add(1, std::memory_order_relaxed); 172 if (va && shader_va(va) != va) untranslated_[kind].fetch_add(1, std::memory_order_relaxed);
168 } 173 }
169 174
175 // [va, va + bytes) is reached as a copy of the title's memory: the device keeps it for the copy back.
176 void note_reached(std::uint64_t va, std::uint64_t bytes) {
177 Noter noter;
178 void* context;
179 {
180 std::lock_guard lock(hook_mutex_);
181 noter = noter_;
182 context = hook_context_;
183 }
184 if (noter) noter(context, va, bytes);
185 }
186
170 // Before a submission: the device rewrites the buffer V#s of the `descriptors` slots the root signature declares 187 // Before a submission: the device rewrites the buffer V#s of the `descriptors` slots the root signature declares
171 // for the table at `table_va` (a console VA in one of its shader-visible CBV/SRV/UAV heaps). 188 // for the table at `table_va` (a console VA in one of its shader-visible CBV/SRV/UAV heaps).
172 void scan_table(std::uint64_t table_va, std::uint32_t descriptors) { 189 void scan_table(std::uint64_t table_va, std::uint32_t descriptors) {
@@ -307,10 +324,16 @@ public:
307 hook_context_ = nullptr; 324 hook_context_ = nullptr;
308 resolver_ = nullptr; 325 resolver_ = nullptr;
309 scanner_ = nullptr; 326 scanner_ = nullptr;
327 noter_ = nullptr;
310 } 328 }
311 // The resolver alone, for a device that scans its descriptor tables itself. 329 // The resolver alone, for a device that scans its descriptor tables itself.
312 void set_resolver(void* context, Resolver resolver) { set_hooks(context, resolver, nullptr); } 330 void set_resolver(void* context, Resolver resolver) { set_hooks(context, resolver, nullptr); }
313 void clear_resolver(void* context) { clear_hooks(context); } 331 void clear_resolver(void* context) { clear_hooks(context); }
332 // Set after set_hooks, so the hook (and its context) stays the device's: what reached a copy of the title's memory.
333 void set_noter(Noter noter) {
334 std::lock_guard lock(hook_mutex_);
335 noter_ = noter;
336 }
314 337
315 std::size_t size() const { return count_.load(std::memory_order_acquire); } 338 std::size_t size() const { return count_.load(std::memory_order_acquire); }
316 std::uint64_t invalidations() const { return invalidations_.load(std::memory_order_acquire); } 339 std::uint64_t invalidations() const { return invalidations_.load(std::memory_order_acquire); }
@@ -344,6 +367,7 @@ private:
344 BufferMaker maker_ = nullptr; 367 BufferMaker maker_ = nullptr;
345 Resolver resolver_ = nullptr; 368 Resolver resolver_ = nullptr;
346 TableScanner scanner_ = nullptr; 369 TableScanner scanner_ = nullptr;
370 Noter noter_ = nullptr;
347 void* source_context_ = nullptr; 371 void* source_context_ = nullptr;
348 DescriptorSource source_ = nullptr; 372 DescriptorSource source_ = nullptr;
349 std::atomic<std::uint64_t> pulled_{0}; 373 std::atomic<std::uint64_t> pulled_{0};