upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/test/dev_overlay_test.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-25 18:16:25 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-25 18:18:57 -0500
commit38385762bd400e8260c7b3c8a80bb0c03fcc44c4 (patch)
treee0d983ce74468edfde736ab699a695b80702ddbf /runtime/test/dev_overlay_test.cpp
parentd4fb292344088e7925ddeb3bbceb5a9ac46de8c2 (diff)
dev overlay: the title HUD's VRAM and private memory figures
LEONIDA_DEV_OVERLAY (#2137) showed the working set and free RAM, with no GPU memory and no private memory. It now shows both, from the same code as the title HUD: - src/memory_figures.h holds VramBudget, the private-bytes choice (the larger of PrivateUsage and PagefileUsage, since Wine fills only the latter), the "RAM ..." and "VRAM ..." text with "n/a" where there is no figure, and a publisher for the device's GPU memory figure. No Vulkan, and Win32 only under _WIN32, so the overlay's test still builds on every host. - A device with VK_EXT_memory_budget publishes a reader when it is created and withdraws it first thing when it is destroyed (the lock is held during a read, so a reader never outlives its device). latest_vram() calls the reader at most once per 500 ms for both views. The HUD reads it instead of its own per-device lambda. - The overlay's last line is now "RAM 2.5 GB (ws 1.0) VRAM 3.5/16.0 GB +0.5 shared"; cores and free RAM keep their own line. Tests: dev_overlay_test checks the text with and without figures, the private-bytes fallback, and the publisher (one read per refresh, only the publishing device withdraws). title_hud_test checks that a HUD without its own source shows the published figure. d3d12_vram_budget_test checks that the device publishes its figure while it lives and withdraws it on release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/dev_overlay_test.cpp')
-rw-r--r--runtime/test/dev_overlay_test.cpp72
1 files changed, 70 insertions, 2 deletions
diff --git a/runtime/test/dev_overlay_test.cpp b/runtime/test/dev_overlay_test.cpp
index b366ec2ed..55a5a31cc 100644
--- a/runtime/test/dev_overlay_test.cpp
+++ b/runtime/test/dev_overlay_test.cpp
@@ -1,7 +1,10 @@
1// src/dev_overlay.h: the text of a sample, the counter differences, the phase bookkeeping behind its "now" line 1// src/dev_overlay.h: the text of a sample, the counter differences, the phase bookkeeping behind its "now" line
2// (submit_phases.h) and the pipeline builds in flight (dev_status.h). No window, GPU or game file. 2// (submit_phases.h), the pipeline builds in flight (dev_status.h) and the memory figures it shares with the title HUD
3// (memory_figures.h). No window, GPU or game file.
3#include "dev_overlay.h" 4#include "dev_overlay.h"
4 5
6#include <chrono>
7#include <cstdint>
5#include <cstdio> 8#include <cstdio>
6#include <string> 9#include <string>
7#include <thread> 10#include <thread>
@@ -23,6 +26,68 @@ static bool has(const std::vector<std::string>& lines, const char* part) {
23 return false; 26 return false;
24} 27}
25 28
29// memory_figures.h, which the overlay and the title HUD share: the private bytes Wine reports, the text of both
30// figures with and without one, and the device's published GPU memory, read at most once per refresh.
31static int check_memory_figures() {
32 namespace mf = leonida::memory_figures;
33 constexpr std::uint64_t kGiB = 1ull << 30;
34
35 // Wine fills PagefileUsage and leaves PrivateUsage 0; Windows fills both with the same value.
36 mf::ProcessMemory ram;
37 CHECK(mf::ram_text(ram) == "RAM n/a"); // GetProcessMemoryInfo failed
38 ram.read = true;
39 ram.working_set = kGiB;
40 CHECK(mf::ram_text(ram) == "RAM n/a (ws 1.0)");
41 ram.pagefile_usage = 5 * kGiB / 2;
42 CHECK(mf::private_bytes(ram) == 5 * kGiB / 2 && mf::ram_text(ram) == "RAM 2.5 GB (ws 1.0)");
43 ram.private_usage = 5 * kGiB / 2;
44 CHECK(mf::private_bytes(ram) == 5 * kGiB / 2 && mf::ram_text(ram) == "RAM 2.5 GB (ws 1.0)");
45
46 leonida::VramBudget vram;
47 CHECK(mf::vram_text(vram) == "VRAM n/a");
48 vram.available = true;
49 vram.local_usage = 3 * kGiB + kGiB / 2;
50 vram.local_budget = 16 * kGiB;
51 vram.shared_usage = kGiB / 2;
52 CHECK(mf::vram_text(vram) == "VRAM 3.5/16.0 GB +0.5 shared");
53
54 // The overlay's line with both figures.
55 dov::Sample s;
56 s.ram = ram;
57 s.vram = vram;
58 CHECK(has(dov::lines(s, 1), "RAM 2.5 GB (ws 1.0) VRAM 3.5/16.0 GB +0.5 shared"));
59
60 // The published figure: none until a device publishes a reader; then read at most once per refresh_ms; another
61 // device's withdrawal leaves it; its own takes it away.
62 struct Fake {
63 int reads = 0;
64 leonida::VramBudget figure;
65 };
66 static Fake device;
67 static const int other = 0;
68 device.figure = vram;
69 auto& publisher = mf::vram_publisher();
70 using clock = std::chrono::steady_clock;
71 const clock::time_point t0 = clock::now();
72 CHECK(!publisher.latest(t0).available);
73 mf::publish_vram_reader(
74 [](const void* context) {
75 auto* fake = static_cast<Fake*>(const_cast<void*>(context));
76 ++fake->reads;
77 return fake->figure;
78 },
79 &device);
80 CHECK(publisher.latest(t0).local_usage == 3 * kGiB + kGiB / 2 && device.reads == 1);
81 device.figure.local_usage = 4 * kGiB;
82 CHECK(publisher.latest(t0 + mf::refresh_ms / 2).local_usage == 3 * kGiB + kGiB / 2 && device.reads == 1);
83 CHECK(publisher.latest(t0 + mf::refresh_ms).local_usage == 4 * kGiB && device.reads == 2);
84 mf::withdraw_vram_reader(&other);
85 CHECK(mf::latest_vram().available);
86 mf::withdraw_vram_reader(&device);
87 CHECK(!mf::latest_vram().available);
88 return 0;
89}
90
26int main() { 91int main() {
27 // A total that went down was reset by its log line: what it holds is the new part. 92 // A total that went down was reset by its log line: what it holds is the new part.
28 std::uint64_t before = 0; 93 std::uint64_t before = 0;
@@ -76,7 +141,9 @@ int main() {
76 141
77 dov::Sample s; 142 dov::Sample s;
78 auto text = dov::lines(s, 12); 143 auto text = dov::lines(s, 12);
79 CHECK(text.size() == 6); 144 CHECK(text.size() == 7);
145 // No counters and no device figure: "n/a", never a false 0.
146 CHECK(has(text, "RAM n/a VRAM n/a"));
80 CHECK(has(text, "12 s") && has(text, "now: the title's own code") && has(text, "pipelines: 0 built")); 147 CHECK(has(text, "12 s") && has(text, "now: the title's own code") && has(text, "pipelines: 0 built"));
81 CHECK(!has(text, "building")); 148 CHECK(!has(text, "building"));
82 s.frames = 8.44; 149 s.frames = 8.44;
@@ -93,6 +160,7 @@ int main() {
93 CHECK(has(text, "8.4 fps") && has(text, "now: refreshing textures for 3 s") && has(text, "copies 3.5")); 160 CHECK(has(text, "8.4 fps") && has(text, "now: refreshing textures for 3 s") && has(text, "copies 3.5"));
94 CHECK(has(text, "853 built, 3 building (nnn") && has(text, "3029 drawn, 38363 skipped")); 161 CHECK(has(text, "853 built, 3 building (nnn") && has(text, "3029 drawn, 38363 skipped"));
95 for (const auto& line : text) CHECK(line.size() < 160); 162 for (const auto& line : text) CHECK(line.size() < 160);
163 if (const int failed = check_memory_figures()) return failed;
96 std::puts("dev_overlay_test: ok"); 164 std::puts("dev_overlay_test: ok");
97 return 0; 165 return 0;
98} 166}