diff options
| author | Aslan2142 <jan.trencansky@protonmail.com> | 2026-11-26 17:15:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-26 17:15:32 +0100 |
| commit | 56bdd7e889f6e05ca498eb79e35fa22578fe4696 (patch) | |
| tree | 3118b532fc54beab0216743f9d11c53931865943 /runtime/src | |
| parent | 246791612080cae89dc40cd20c5cdb8d92f90066 (diff) | |
| parent | b0767fd6574e5ec7af617e27c87a3401176154b8 (diff) | |
Merge pull request #2370 from aslan2142/remove-remap-release-and-heap-mirror
d3d12, xmem: remove remap release and the console heap mirror (RT-REMOVE-REMAP-RELEASE-AND-HEAP-MIRROR)
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/console_heap_copy.h | 98 | ||||
| -rw-r--r-- | runtime/src/title_geometry_watch.h | 2 |
2 files changed, 1 insertions, 99 deletions
diff --git a/runtime/src/console_heap_copy.h b/runtime/src/console_heap_copy.h deleted file mode 100644 index 7eae03aa5..000000000 --- a/runtime/src/console_heap_copy.h +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | #pragma once | ||
| 2 | // A console resource heap's translated copy (DeviceState::ConsoleHeap::copy): the bytes shaders read, and a host-RAM | ||
| 3 | // mirror of them that the CPU reads instead. | ||
| 4 | // | ||
| 5 | // The copy lies in the GPU address arena when the import of host memory is not used (arena.mapped + offset), and the | ||
| 6 | // arena prefers DEVICE_LOCAL | HOST_VISIBLE memory (ReBAR): a CPU read of it is an uncached read across PCIe. The | ||
| 7 | // release sweep of refresh_console_heap with LEONIDA_CONSOLE_RELEASE_FILTER=1 reads words 0-2 of both V# halves of | ||
| 8 | // every live V# slot (about 470k in a game run) to decide whether the slot needs fixing, and that read cost | ||
| 9 | // 0.9-1.0 s a sweep. Every CPU write goes through write() and zero(), which write both the copy and the mirror, so | ||
| 10 | // view() (the mirror, or the copy when there is none) holds what the GPU reads. | ||
| 11 | // | ||
| 12 | // The mirror is made only with LEONIDA_HEAP_MIRROR=1 (off by default: a world run with it hung the GPU). Even then, | ||
| 13 | // no mirror when the copy is already host RAM (the import of the heap's own scratch), or | ||
| 14 | // once the copy is written by the GPU pass (LEONIDA_CONSOLE_HEAP_GPU: drop_mirror(); the CPU neither writes nor reads | ||
| 15 | // the copy then). The mirror covers the heap's bytes only, not the null guard after them (written once, at creation). | ||
| 16 | // | ||
| 17 | // LEONIDA_HEAP_MIRROR_CHECK=1: refresh_console_heap compares the mirror with the copy at every release sweep | ||
| 18 | // (mismatches()) and logs the first slots that differ. | ||
| 19 | |||
| 20 | #include <algorithm> | ||
| 21 | #include <cstddef> | ||
| 22 | #include <cstdint> | ||
| 23 | #include <cstring> | ||
| 24 | #include <vector> | ||
| 25 | |||
| 26 | namespace leonida { | ||
| 27 | |||
| 28 | class ConsoleHeapCopy { | ||
| 29 | public: | ||
| 30 | // `gpu`: the copy shaders read; `bytes`: the heap's bytes (the mirror's size, when `mirrored`). | ||
| 31 | void attach(std::uint8_t* gpu, std::size_t bytes, bool mirrored) { | ||
| 32 | gpu_ = gpu; | ||
| 33 | bytes_ = bytes; | ||
| 34 | mirror_.clear(); | ||
| 35 | mirror_.shrink_to_fit(); | ||
| 36 | if (gpu && mirrored) mirror_.assign(bytes, 0); | ||
| 37 | } | ||
| 38 | // The mirror goes; view() is the copy from now on. | ||
| 39 | void drop_mirror() { | ||
| 40 | mirror_.clear(); | ||
| 41 | mirror_.shrink_to_fit(); | ||
| 42 | } | ||
| 43 | |||
| 44 | explicit operator bool() const noexcept { return gpu_ != nullptr; } | ||
| 45 | std::uint8_t* gpu() const noexcept { return gpu_; } | ||
| 46 | bool mirrored() const noexcept { return !mirror_.empty(); } | ||
| 47 | std::size_t bytes() const noexcept { return bytes_; } | ||
| 48 | |||
| 49 | // What the CPU reads: the mirror, or the copy itself. | ||
| 50 | const std::uint8_t* view() const noexcept { return mirror_.empty() ? gpu_ : mirror_.data(); } | ||
| 51 | |||
| 52 | // [at, at + n) of the copy, and of the mirror where it reaches. | ||
| 53 | void write(std::size_t at, const void* bytes, std::size_t n) { | ||
| 54 | std::memcpy(gpu_ + at, bytes, n); | ||
| 55 | if (const std::size_t m = mirror_span(at, n)) std::memcpy(mirror_.data() + at, bytes, m); | ||
| 56 | } | ||
| 57 | void zero(std::size_t at, std::size_t n) { | ||
| 58 | std::memset(gpu_ + at, 0, n); | ||
| 59 | if (const std::size_t m = mirror_span(at, n)) std::memset(mirror_.data() + at, 0, m); | ||
| 60 | } | ||
| 61 | |||
| 62 | // LEONIDA_HEAP_MIRROR_CHECK: the slots of `slot_bytes` whose mirror bytes differ from the copy's, at most `limit` | ||
| 63 | // of them in `out` (in ascending order); returns how many slots differ in all. 0 without a mirror. | ||
| 64 | std::size_t mismatches(std::size_t slot_bytes, std::size_t limit, std::vector<std::size_t>& out) const { | ||
| 65 | out.clear(); | ||
| 66 | if (mirror_.empty() || !slot_bytes) return 0; | ||
| 67 | // Read the copy in large blocks: one pass over device memory, compared in host RAM. | ||
| 68 | constexpr std::size_t kBlock = std::size_t(1) << 16; | ||
| 69 | std::vector<std::uint8_t> block; | ||
| 70 | std::size_t count = 0; | ||
| 71 | const std::size_t step = std::max(slot_bytes, kBlock / slot_bytes * slot_bytes); | ||
| 72 | for (std::size_t at = 0; at < bytes_; at += step) { | ||
| 73 | const std::size_t n = std::min(step, bytes_ - at); | ||
| 74 | block.resize(n); | ||
| 75 | std::memcpy(block.data(), gpu_ + at, n); | ||
| 76 | if (!std::memcmp(block.data(), mirror_.data() + at, n)) continue; | ||
| 77 | for (std::size_t s = 0; s < n; s += slot_bytes) { | ||
| 78 | const std::size_t k = std::min(slot_bytes, n - s); | ||
| 79 | if (!std::memcmp(block.data() + s, mirror_.data() + at + s, k)) continue; | ||
| 80 | if (out.size() < limit) out.push_back((at + s) / slot_bytes); | ||
| 81 | ++count; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | return count; | ||
| 85 | } | ||
| 86 | |||
| 87 | private: | ||
| 88 | std::size_t mirror_span(std::size_t at, std::size_t n) const noexcept { | ||
| 89 | if (mirror_.empty() || at >= mirror_.size()) return 0; | ||
| 90 | return std::min(n, mirror_.size() - at); | ||
| 91 | } | ||
| 92 | |||
| 93 | std::uint8_t* gpu_ = nullptr; | ||
| 94 | std::size_t bytes_ = 0; | ||
| 95 | std::vector<std::uint8_t> mirror_; | ||
| 96 | }; | ||
| 97 | |||
| 98 | } // namespace leonida | ||
diff --git a/runtime/src/title_geometry_watch.h b/runtime/src/title_geometry_watch.h index dfb0ae5b5..7283eccd8 100644 --- a/runtime/src/title_geometry_watch.h +++ b/runtime/src/title_geometry_watch.h | |||
| @@ -75,7 +75,7 @@ inline void note_released(std::uintptr_t begin, std::uintptr_t end) { | |||
| 75 | std::lock_guard lock(q->mutex); | 75 | std::lock_guard lock(q->mutex); |
| 76 | bool room = q->ranges.size() < 65536; | 76 | bool room = q->ranges.size() < 65536; |
| 77 | if (!room) { | 77 | if (!room) { |
| 78 | // Full: first the ranges that overlap or touch become one (remaps report page runs, often neighbours), and | 78 | // Full: first the ranges that overlap or touch become one (unmaps report page runs, often neighbours), and |
| 79 | // only when that leaves it more than half full does it all become one covering range. | 79 | // only when that leaves it more than half full does it all become one covering range. |
| 80 | std::sort(q->ranges.begin(), q->ranges.end()); | 80 | std::sort(q->ranges.begin(), q->ranges.end()); |
| 81 | std::size_t kept = 0; | 81 | std::size_t kept = 0; |