diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 5b875bbd73..9e3ff3b857 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -4051,6 +4051,10 @@ if(TARGET Vulkan::Headers) # The same fault with a later run of the write-back in the tile it reopened: that run's GPU words go back too. add_test(NAME d3d12_title_window_write_back_fault_tile COMMAND d3d12_title_va_test --window-writeback-fault-tile) set_tests_properties(d3d12_title_window_write_back_fault_tile PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120) + # Disjoint write-back ranges on one guarded page: every one of them reaches the page, not only the first + # (RT-TITLE-WRITEBACK-SAME-PAGE-RANGES). + add_test(NAME d3d12_title_window_write_back_ranges COMMAND d3d12_title_va_test --window-writeback-ranges) + set_tests_properties(d3d12_title_window_write_back_ranges PROPERTIES SKIP_RETURN_CODE 77) # The same return copy for a slot-133 buffer's shadow (the write-back of a compute result the title reads again). add_test(NAME d3d12_placed_write_back COMMAND d3d12_title_va_test --placed-writeback) set_tests_properties(d3d12_placed_write_back PROPERTIES SKIP_RETURN_CODE 77) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index de623b6040..053d4fb19d 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -407,9 +407,10 @@ class ShadowPages { ShadowPages(const ShadowPages&) = delete; ShadowPages& operator=(const ShadowPages&) = delete; - // What the GPU writes into the copies of [from, to) goes back to the title's pages. Returns the bytes written. - // Called before the next refresh, so a page the title writes again is copied forward over the result, as on a GPU - // that shares the memory. + // What the GPU writes into the copies of the ranges [first, second) goes back to the title's pages: `count` of + // them, sorted by start. Returns the bytes written, and in `reached` (when given) how many of the ranges wrote + // any. Called before the next refresh, so a page the title writes again is copied forward over the result, as on + // a GPU that shares the memory. // // Only the bytes a copy holds differently from the title's page go back, and only on a page known unchanged since // it was copied: guarded (read-only since that copy), or write-watched and found unwritten by an asking made here. @@ -419,11 +420,29 @@ class ShadowPages { // where opening them for a whole copy lost a write made between the opening and the copy; and of two copies of // the same bytes only the one that differs is written, where the last one won. // + // All the finished ranges over this tracker come in one call, and which pages are held is decided once for all of + // them, before the first copy. One call per range made the first range that differed reopen its page (kProtected + // gone), and every later range on that page then read as written by the title and was dropped, though only this + // write-back had written there (73N1X, #1608: of 130 four-byte ranges 256 bytes apart, 9 went back). A page + // opened here is open to the title until the next refresh guards it again, as it was for the pieces of one range + // after the first. + // // `only` (a retired window's copy, when it is freed): that copy alone goes back, where no live copy changed the // bytes; the live copies' own results wait for their submissions' batches. - std::size_t write_back(std::uintptr_t from, std::uintptr_t to, const std::uint8_t* only = nullptr) { - from = std::max(from, first_), to = std::min(to, last_); - if (from >= to) return 0; + std::size_t write_back(const std::pair* ranges, std::size_t count, + std::size_t* reached = nullptr, const std::uint8_t* only = nullptr) { + if (reached) *reached = 0; + std::uintptr_t lo = last_, hi = first_; // the pages the ranges cover + for (std::size_t r = 0; r < count; ++r) { + const std::uintptr_t from = std::max(ranges[r].first, first_), to = std::min(ranges[r].second, last_); + if (from >= to) continue; + lo = std::min(lo, from & ~(kPage - 1)); + hi = std::max(hi, (to + kPage - 1) & ~(kPage - 1)); + } + if (lo >= hi) return 0; + // Sized before lock_ is taken: a thread that faults on a guarded page waits on lock_ in reopen(), and may hold + // the heap's lock while it does. Only write_back uses it, and one write_back runs at a time (shadow_mutex). + held_pages_.resize((hi - lo) / kPage); AcquireSRWLockExclusive(&lock_); // The copies below can fault on a page another guard (the geometry watch, another view's shadow) keeps // read-only. The fault handler asks this tracker too (reopen), and must not take lock_ again on this thread: @@ -445,101 +464,122 @@ class ShadowPages { ReleaseSRWLockExclusive(&lock_); return 0; } - leonida::kernel_writes::for_each_pin(from, to, [&](std::uintptr_t a, std::uintptr_t b) { - for (std::uintptr_t p = std::max(a, from) & ~(kPage - 1); p < std::min(b, to); p += kPage) - state_[(p - first_) / kPage] |= kPinned; - pinned_ = true; - }); + for (std::size_t r = 0; r < count; ++r) { + const std::uintptr_t from = std::max(ranges[r].first, first_), to = std::min(ranges[r].second, last_); + if (from >= to) continue; + leonida::kernel_writes::for_each_pin(from, to, [&](std::uintptr_t a, std::uintptr_t b) { + for (std::uintptr_t p = std::max(a, from) & ~(kPage - 1); p < std::min(b, to); p += kPage) + state_[(p - first_) / kPage] |= kPinned; + pinned_ = true; + }); + } ask_written_locked(); // A page the title wrote since it was last copied holds the newer bytes already: its GPU result is dropped and // the refresh's own copy carries the title's. So is a page whose mapping changed, one a kernel write may be // filling, and one xmem maps at another address too (a write there is seen by no guard and no watch here). - // Decided for every page before the first copy: a copy below can fault on another guard, and the handler then - // reopens the whole 64 KiB tile here on this thread (reopen_range), which clears kClean and kProtected there. - // Read live, that made the later runs in the tile count as written by the title, and their GPU results were - // dropped from a batch already taken off the queue. A page the title wrote before this point is held still. - const std::size_t p0 = (from - first_) / kPage, p1 = (to - first_ + kPage - 1) / kPage; - held_pages_.resize(p1 - p0); - for (std::size_t i = p0; i < p1; ++i) { - const std::uint8_t s = state_[i]; - held_pages_[i - p0] = (s & (kZero | kRequery | kPinned | kAliased)) || (!(s & kProtected) && !(s & kClean)); + // Decided for every page of every range before the first copy (#2468, RT-WRITEBACK-TILE-REOPEN, and this + // call's other ranges): a copy below can fault on another guard, and the handler then reopens the whole 64 KiB + // tile here on this thread (reopen_range), which clears kClean and kProtected there; and a range that differs + // reopens its pages itself. Read live, either made the later runs on those pages count as written by the + // title, and their GPU results were dropped from a batch already taken off the queue. A page the title wrote + // before this point is held still. + const std::size_t p0 = (lo - first_) / kPage; + for (std::size_t r = 0; r < count; ++r) { + const std::uintptr_t from = std::max(ranges[r].first, first_), to = std::min(ranges[r].second, last_); + if (from >= to) continue; + for (std::size_t i = (from - first_) / kPage, i1 = (to - first_ + kPage - 1) / kPage; i < i1; ++i) { + const std::uint8_t s = state_[i]; + held_pages_[i - p0] = + (s & (kZero | kRequery | kPinned | kAliased)) || (!(s & kProtected) && !(s & kClean)); + } } const auto held = [&](std::size_t i) { return held_pages_[i - p0] != 0; }; constexpr std::uintptr_t kPiece = 256; // compared and copied in pieces this size std::size_t written = 0; - for (std::uintptr_t at = from & ~(kPage - 1); at < ((to + kPage - 1) & ~(kPage - 1));) { - std::size_t pages = 0; - while (at + (pages + 1) * kPage <= ((to + kPage - 1) & ~(kPage - 1)) && - held((at - first_) / kPage + pages) == held((at - first_) / kPage)) - ++pages; - if (!held((at - first_) / kPage)) { - const std::uintptr_t a = std::max(at, from), b = std::min(at + pages * kPage, to); - bool opened = false; - Vector over; // the targets with bytes in [a, b) - for (const Target& t : targets_) - if (t.shadow && std::max(a, t.begin) < std::min(b, t.end)) over.push_back(&t); - // Piece by piece, against the title's bytes as they were before any copy went back here: a copy goes - // back on the bytes it holds differently from those, so one that still holds them is not written over - // another's result. A retired window's copy (retire_target) goes back only on bytes no live copy - // changed: what a submission wrote in it is older than what a live copy holds (the range that - // replaced it serves every submission recorded since). Byte by byte, as two copies can share a piece - // with disjoint bytes each. - for (std::uintptr_t c = a; c < b && !over.empty();) { - const std::uintptr_t e = std::min(b, (c + kPiece) & ~(kPiece - 1)); - std::uint8_t before[kPiece]; - bool live[kPiece]; // the bytes a live copy changed, once `saved` - bool saved = false; - for (int pass = 0; pass < 2; ++pass) - for (const Target* t : over) { - if (t->retired != (pass == 1) || (only && pass == 1 && t->shadow != only)) continue; - const std::uintptr_t x = std::max(c, t->begin), y = std::min(e, t->end); - if (x >= y) continue; - const std::uint8_t* copy = t->shadow + (x - t->begin); - const void* now = saved ? static_cast(before + (x - c)) - : reinterpret_cast(x); - if (std::memcmp(now, copy, y - x) == 0) continue; - if (!saved) { - std::memcpy(before, reinterpret_cast(c), e - c); - std::fill_n(live, e - c, false); - saved = true; - } - const auto goes = [&](std::uintptr_t v) { - return copy[v - x] != before[v - c] && !(pass == 1 && live[v - c]); - }; - for (std::uintptr_t i = x; i < y;) { - if (!goes(i)) { - ++i; - continue; + for (std::size_t r = 0; r < count; ++r) { + const std::uintptr_t from = std::max(ranges[r].first, first_), to = std::min(ranges[r].second, last_); + if (from >= to) continue; + const std::size_t range_written = written; + const std::uintptr_t end = (to + kPage - 1) & ~(kPage - 1); + for (std::uintptr_t at = from & ~(kPage - 1); at < end;) { + std::size_t pages = 0; + while (at + (pages + 1) * kPage <= end && + held((at - first_) / kPage + pages) == held((at - first_) / kPage)) + ++pages; + if (!held((at - first_) / kPage)) { + const std::uintptr_t a = std::max(at, from), b = std::min(at + pages * kPage, to); + bool opened = false; + Vector over; // the targets with bytes in [a, b) + for (const Target& t : targets_) + if (t.shadow && std::max(a, t.begin) < std::min(b, t.end)) over.push_back(&t); + // Piece by piece, against the title's bytes as they were before any copy went back here: a copy goes + // back on the bytes it holds differently from those, so one that still holds them is not written over + // another's result. A retired window's copy (retire_target) goes back only on bytes no live copy + // changed: what a submission wrote in it is older than what a live copy holds (the range that + // replaced it serves every submission recorded since). Byte by byte, as two copies can share a piece + // with disjoint bytes each. + for (std::uintptr_t c = a; c < b && !over.empty();) { + const std::uintptr_t e = std::min(b, (c + kPiece) & ~(kPiece - 1)); + std::uint8_t before[kPiece]; + bool live[kPiece]; // the bytes a live copy changed, once `saved` + bool saved = false; + for (int pass = 0; pass < 2; ++pass) + for (const Target* t : over) { + if (t->retired != (pass == 1) || (only && pass == 1 && t->shadow != only)) continue; + const std::uintptr_t x = std::max(c, t->begin), y = std::min(e, t->end); + if (x >= y) continue; + const std::uint8_t* copy = t->shadow + (x - t->begin); + const void* now = saved ? static_cast(before + (x - c)) + : reinterpret_cast(x); + if (std::memcmp(now, copy, y - x) == 0) continue; + if (!saved) { + std::memcpy(before, reinterpret_cast(c), e - c); + std::fill_n(live, e - c, false); + saved = true; } - std::uintptr_t j = i + 1; - while (j < y && goes(j)) ++j; - if (pass == 0) std::fill(live + (i - c), live + (j - c), true); - if (pass == 1 || !only) { // `only`: the live copies' results wait for their batches - if (!opened) { - reopen_locked(at, at + pages * kPage); - opened = true; + const auto goes = [&](std::uintptr_t v) { + return copy[v - x] != before[v - c] && !(pass == 1 && live[v - c]); + }; + for (std::uintptr_t i = x; i < y;) { + if (!goes(i)) { + ++i; + continue; } - std::memcpy(reinterpret_cast(i), copy + (i - x), j - i); - written += j - i; - } - // A retired copy's bytes are the title's now: the copies that held the older ones - // take them too, as the next refresh would, so one read before it (the range that - // replaced the window, when the window is freed after this submission's refresh) - // is not behind the title. A copy that changed a byte keeps its own. - if (pass == 1) - for (const Target* o : over) { - if (o == t) continue; - for (std::uintptr_t v = std::max(i, o->begin); v < std::min(j, o->end); ++v) - if (o->shadow[v - o->begin] == before[v - c]) - o->shadow[v - o->begin] = copy[v - x]; + std::uintptr_t j = i + 1; + while (j < y && goes(j)) ++j; + if (pass == 0) std::fill(live + (i - c), live + (j - c), true); + if (pass == 1 || !only) { // `only`: the live copies' results wait for their batches + if (!opened) { + // An earlier range on these pages may have reopened them already. + const std::size_t i0 = (at - first_) / kPage; + if (std::any_of(state_.begin() + i0, state_.begin() + i0 + pages, + [](std::uint8_t page) { return page & kProtected; })) + reopen_locked(at, at + pages * kPage); + opened = true; + } + std::memcpy(reinterpret_cast(i), copy + (i - x), j - i); + written += j - i; } - i = j; + // A retired copy's bytes are the title's now: the copies that held the older ones + // take them too, as the next refresh would, so one read before it (the range that + // replaced the window, when the window is freed after this submission's refresh) + // is not behind the title. A copy that changed a byte keeps its own. + if (pass == 1) + for (const Target* o : over) { + if (o == t) continue; + for (std::uintptr_t v = std::max(i, o->begin); v < std::min(j, o->end); ++v) + if (o->shadow[v - o->begin] == before[v - c]) + o->shadow[v - o->begin] = copy[v - x]; + } + i = j; + } } - } - c = e; + c = e; + } } + at += pages * kPage; } - at += pages * kPage; + if (reached && written != range_written) ++*reached; } writer_.store(0, std::memory_order_relaxed); ReleaseSRWLockExclusive(&lock_); @@ -1493,7 +1533,7 @@ class ShadowPages { std::uintptr_t first_ = 0, last_ = 0; // the pages covered SRWLOCK lock_ = SRWLOCK_INIT; // state_, cover_, the targets, and the protection of the pages std::atomic writer_{0}; // the thread in write_back, which holds lock_ while it copies into the title - Vector held_pages_; // write_back's per-page decision, taken before its copies (under lock_) + Vector held_pages_; // write_back's per-page decision, taken before its copies Vector state_; // per 4 KiB page Vector cover_; // per 4 KiB page: the targets that read it Vector targets_; // by start @@ -3168,8 +3208,9 @@ struct DeviceState { for (auto it = shadows.begin(); it != shadows.end(); ++it) { ShadowPages& s = **it; if (!s.has_target(mapped)) continue; - title_write_back_total += s.write_back(static_cast(start), - static_cast(start + size), mapped); + const std::pair range{static_cast(start), + static_cast(start + size)}; + title_write_back_total += s.write_back(&range, 1, nullptr, mapped); s.remove_target(mapped); if (!s.targets()) shadows.erase(it); return; @@ -3801,14 +3842,21 @@ struct DeviceState { 1); } if (finished.empty()) return; + // Each shadow takes all the ranges over it in one call, in address order (batches can overlap), and decides + // which of its pages are held once for all of them (ShadowPages::write_back). + std::sort(finished.begin(), finished.end()); std::uint64_t written = 0, ranges = 0; - for (const auto& [begin, end] : finished) - for (const ShadowPagesPtr& s : shadows) - if (end > s->first() && begin < s->last()) { - const std::uint64_t bytes = s->write_back(begin, end); - written += bytes; - ranges += bytes != 0; - } + std::vector> over; + for (const ShadowPagesPtr& s : shadows) { + over.clear(); + for (const auto& [begin, end] : finished) + if (end > s->first() && begin < s->last()) + over.push_back({static_cast(begin), static_cast(end)}); + if (over.empty()) continue; + std::size_t reached = 0; + written += s->write_back(over.data(), over.size(), &reached); + ranges += reached; + } title_write_back_total += written; if (!written) return; if (++title_write_back_calls <= 4 || !(title_write_back_calls & (title_write_back_calls - 1))) diff --git a/runtime/test/d3d12_title_va_test.cpp b/runtime/test/d3d12_title_va_test.cpp index b968b4edeb..e493533e6c 100644 --- a/runtime/test/d3d12_title_va_test.cpp +++ b/runtime/test/d3d12_title_va_test.cpp @@ -525,15 +525,16 @@ struct WriteBack { ID3D12CommandQueue* queue = nullptr; // the context's when null }; -// One submission that dispatches through a root UAV at `va` (and at `va2` too, when given) and waits for it. With -// `wait` false it is only executed (no signal: the caller knows when it is done). False on a failed call. -int submit_write(WriteBack& s, std::uint64_t va, std::uint64_t va2 = 0, bool wait = true) { +// One submission that dispatches through a root UAV at `va` (and at `va2` too, when given) and waits for it. The +// shader writes `base` + its step at each word. With `wait` false it is only executed (no signal: the caller knows +// when it is done). False on a failed call. +int submit_write(WriteBack& s, std::uint64_t va, std::uint64_t va2 = 0, std::uint32_t base = 0, bool wait = true) { EXPECT(s.allocator->Reset() == S_OK); EXPECT(s.list->Reset(s.allocator, s.c->pso) == S_OK); ID3D12DescriptorHeap* heaps[] = {s.heap}; s.list->SetDescriptorHeaps(1, heaps); s.list->SetComputeRootSignature(s.c->root); - s.list->SetComputeRoot32BitConstant(0, 0, 0); + s.list->SetComputeRoot32BitConstant(0, base, 0); s.list->SetComputeRoot32BitConstant(0, 1, 1); // the step: a word the shader writes s.list->SetComputeRootUnorderedAccessView(1, va); s.list->SetComputeRootDescriptorTable(2, D3D12_GPU_DESCRIPTOR_HANDLE{s.gpu}); @@ -708,6 +709,94 @@ int check_window_write_back(Context& c, bool geometry) { return 0; } +// Several disjoint write-back ranges on one guarded page (RT-TITLE-WRITEBACK-SAME-PAGE-RANGES, found by 73N1X in +// #1608). The ranges of a submission go back one by one; the first that differs used to reopen the page, and every +// later range on it then found the page neither guarded nor clean and was dropped as written by the title, though +// nothing but the write-back itself had written there. +// 1. a submission makes the ring's window, and a second one copies its words back and guards the pages; +// 2. a submission writes new words into the window through its arena address (nothing noted for it), while 16 +// four-byte ranges 16 bytes apart on the first page are noted as reached; +// 3. the next submission's refresh copies those ranges back: every one of them must reach the page, and the words +// between them must keep the title's. +int check_window_write_back_ranges(Context& c, bool geometry) { + if (geometry) { + std::fprintf(stderr, "SKIP: the geometry copy backs the ring, not a window\n"); + return 77; + } + constexpr UINT64 ring_bytes = 64 * 1024; + constexpr UINT kRanges = 16, kSpacing = 4; // in words: ranges at words 0, 4, 8, ..., 60 + auto* ring = static_cast( + VirtualAlloc(nullptr, ring_bytes, MEM_TOP_DOWN | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + EXPECT(ring); + const auto ring_va = reinterpret_cast(ring); + for (UINT i = 0; i < ring_bytes / 4; ++i) ring[i] = 0; + auto& aliases = leonida::title_va_aliases(); + aliases.add_title_memory(ring_va, ring_bytes); + + const D3D12_HEAP_PROPERTIES default_heap{D3D12_HEAP_TYPE_DEFAULT}; + const auto uav = buffer_desc(kBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + Ref out, scratch; + EXPECT(SUCCEEDED(c.device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &uav, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, + IID_PPV_ARGS(&out.p)))); + EXPECT(SUCCEEDED(c.device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &uav, + D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, + IID_PPV_ARGS(&scratch.p)))); + D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 8, + D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 0}; + Ref heap; + EXPECT(SUCCEEDED(c.device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap.p)))); + Ref allocator; + Ref list; + EXPECT(SUCCEEDED(c.device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator.p)))); + EXPECT(SUCCEEDED(c.device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator.p, c.pso, + IID_PPV_ARGS(&list.p)))); + EXPECT(list->Close() == S_OK); + WriteBack s{&c, allocator.p, list.p, out.p, heap.p, + reinterpret_cast(slot(heap.p, 10))(heap.p)}; + + // 1. The window, and its words back in the pages; then a submission that does not reach the ring guards them. + EXPECT(submit_write(s, ring_va) == 0); + const std::uint64_t window = aliases.shader_va(ring_va); + EXPECT(window != ring_va && window != 0); + EXPECT(submit_write(s, scratch->GetGPUVirtualAddress()) == 0); + EXPECT(submit_write(s, scratch->GetGPUVirtualAddress()) == 0); + const std::vector before(ring, ring + kElements); + UINT nonzero = 0; + for (std::uint32_t w : before) nonzero += w != 0; + EXPECT(nonzero > 0); // the first submission's words came back + MEMORY_BASIC_INFORMATION region{}; + EXPECT(VirtualQuery(ring, ®ion, sizeof(region)) && (region.Protect & 0xff) == PAGE_READONLY); + + // 2. New words in the window, written through its arena address (not a title address: nothing is noted), and the + // ranges the copy back should cover, noted for the same submission. + constexpr std::uint32_t kBase = 0x5A000000u; + for (UINT k = 0; k < kRanges; ++k) aliases.note_reached(ring_va + k * kSpacing * 4, 4); + EXPECT(submit_write(s, window, 0, kBase) == 0); + for (UINT i = 0; i < kElements; ++i) EXPECT(ring[i] == before[i]); // not back before the next submission + + // 3. The next refresh copies the ranges back. + EXPECT(submit_write(s, scratch->GetGPUVirtualAddress()) == 0); + UINT reached = 0, kept = 0, wrong = 0; + for (UINT i = 0; i < kElements; ++i) { + if (i % kSpacing == 0) + reached += ring[i] != before[i]; + else + kept += ring[i] == before[i]; + wrong += ring[i] != before[i] && ring[i] != before[i] + kBase; + } + std::printf("write back ranges: %u/%u four-byte ranges on one guarded page reached it, %u/%u words between them " + "kept the title's, %u words neither\n", + reached, kRanges, kept, kElements - kRanges, wrong); + EXPECT(reached == kRanges); + EXPECT(kept == kElements - kRanges); + EXPECT(wrong == 0); + + aliases.remove_title_memory(ring_va); + VirtualFree(ring, 0, MEM_RELEASE); + return 0; +} + // A write-back whose copy faults (#2418). The copy runs under its tracker's lock and can land on a page another guard // keeps read-only: here a hot page (write-watched, so this tracker does not guard it) that a geometry watch cell has // made read-only, as a geometry view over the same pages does in the title. The copy faults, the handler reopens the @@ -1297,7 +1386,7 @@ int check_retired_window_write_back(Context& c) { // Held on the GPU: it writes the ring's window once the gate opens. const auto empty = rt::d3d12::title_windows(c.inner); EXPECT(SUCCEEDED(gated->Wait(gate.p, 1))); - EXPECT(submit_write(held, ring_va + held_at, 0, false) == 0); + EXPECT(submit_write(held, ring_va + held_at, 0, 0, false) == 0); EXPECT(SUCCEEDED(gated->Signal(held_done.p, 1))); const std::uint64_t window = aliases.shader_va(ring_va); const auto before = rt::d3d12::title_windows(c.inner); @@ -1306,7 +1395,7 @@ int check_retired_window_write_back(Context& c) { EXPECT(SUCCEEDED(rt::d3d12::create_buffer_at_host_address(c.inner, ring, buffer_desc(ring_bytes), 0xFFFFFFFFu, IID_PPV_ARGS(&placed.p)))); EXPECT(!aliases.answers_into(window, 1)); - EXPECT(submit_write(next, arena_va, 0, false) == 0); // its refresh retires the window, its write still queued + EXPECT(submit_write(next, arena_va, 0, 0, false) == 0); // its refresh retires the window, its write still queued const auto retired = rt::d3d12::title_windows(c.inner); EXPECT(retired.retired == before.retired + 1 && retired.waiting >= 1); EXPECT(held_done->GetCompletedValue() == 0); // the write has not run yet @@ -1744,6 +1833,7 @@ int main(int argc, char** argv) { const bool window_write_back_fault = window_write_back_tile || (argc == 2 && std::strcmp(argv[1], "--window-writeback-fault") == 0); const bool placed_write_back = argc == 2 && std::strcmp(argv[1], "--placed-writeback") == 0; + const bool window_write_back_ranges = argc == 2 && std::strcmp(argv[1], "--window-writeback-ranges") == 0; const bool keep_refill = argc == 2 && std::strcmp(argv[1], "--shadow-keep-refill") == 0; if (window_cap) { const char* cap = std::getenv("LEONIDA_TITLE_WINDOWS_MB"); @@ -1886,6 +1976,15 @@ int main(int argc, char** argv) { "read-only returned, and the GPU's words reached the title's pages\n"); return 0; } + if (window_write_back_ranges) { + if (const int result = check_window_write_back_ranges(c, geometry)) return result; + if (d.validation_errors()) { + std::fprintf(stderr, "%u validation errors\n", d.validation_errors()); + return 1; + } + std::printf("title window write back ranges: every range on one guarded page reached it\n"); + return 0; + } if (window_write_back) { if (check_window_write_back(c, geometry)) return 1; if (d.validation_errors()) {