diff options
| author | kawaii-shakal <deusex1998@gmail.com> | 2026-11-25 20:51:50 +0500 |
|---|---|---|
| committer | kawaii-shakal <deusex1998@gmail.com> | 2026-11-25 20:51:50 +0500 |
| commit | e86b3ceaa8d9359df5baaee7e5246d219fb88dbb (patch) | |
| tree | 766912e2d62b5fa5a24b677421ec60484d8f0f52 /runtime/test | |
| parent | 71a769d7d85208f86c6e2e50263aca7df1becce9 (diff) | |
d3d12_xs: LEONIDA_TITLE_HUD shows frame rate, memory and pipeline compiles in the window's title bar (RT-TITLE-HUD)
A tester has no way to see, during a boot, whether the game is slow because of frame time, memory pressure or
pipelines compiled in the frame. With LEONIDA_TITLE_HUD=1 the window the title presents in gets, twice a
second:
- fps and the average and worst frame time from PresentX;
- private memory and working set;
- local GPU memory against the DXGI budget, and shared GPU memory;
- pipelines created and the seconds spent in vkCreate*Pipelines in the last interval (with
LEONIDA_MEM_PROBE);
- time since the first present.
A thread of its own sets the text with SendMessageTimeout, so a busy or hung window thread never holds a
present. title_hud_test drives a real window from another thread and checks the text and the shutdown.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test')
| -rw-r--r-- | runtime/test/title_hud_test.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/runtime/test/title_hud_test.cpp b/runtime/test/title_hud_test.cpp new file mode 100644 index 000000000..8d4d17675 --- /dev/null +++ b/runtime/test/title_hud_test.cpp | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // shims/title_hud.h: LEONIDA_TITLE_HUD's counters reach the title bar of a window owned by another thread, and a | ||
| 2 | // window that stops pumping messages does not hold the HUD thread. A real Win32 window; no GPU needed. | ||
| 3 | #include "title_hud.h" | ||
| 4 | |||
| 5 | #include <windows.h> | ||
| 6 | |||
| 7 | #include <cstdio> | ||
| 8 | #include <string> | ||
| 9 | |||
| 10 | #define CHECK(condition) do { \ | ||
| 11 | if (!(condition)) { \ | ||
| 12 | std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); \ | ||
| 13 | return 1; \ | ||
| 14 | } \ | ||
| 15 | } while (0) | ||
| 16 | |||
| 17 | static std::wstring title_of(HWND window) { | ||
| 18 | wchar_t text[512] = {}; | ||
| 19 | InternalGetWindowText(window, text, 512); // no message: the window's own thread may be busy | ||
| 20 | return text; | ||
| 21 | } | ||
| 22 | |||
| 23 | // Pumps this thread's messages for `ms`, presenting every 16 ms when `present` is set. | ||
| 24 | static void pump(DWORD ms, rt::d3d12_xs::TitleHud* present) { | ||
| 25 | const ULONGLONG end = GetTickCount64() + ms; | ||
| 26 | while (GetTickCount64() < end) { | ||
| 27 | MSG msg; | ||
| 28 | while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { | ||
| 29 | TranslateMessage(&msg); | ||
| 30 | DispatchMessageW(&msg); | ||
| 31 | } | ||
| 32 | if (present) present->note_present(); | ||
| 33 | Sleep(16); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | int main() { | ||
| 38 | WNDCLASSW cls{}; | ||
| 39 | cls.lpfnWndProc = DefWindowProcW; | ||
| 40 | cls.hInstance = GetModuleHandleW(nullptr); | ||
| 41 | cls.lpszClassName = L"LeonidaTitleHudTest"; | ||
| 42 | CHECK(RegisterClassW(&cls)); | ||
| 43 | HWND window = CreateWindowExW(WS_EX_NOACTIVATE, cls.lpszClassName, L"before", WS_OVERLAPPEDWINDOW, 0, 0, 64, 64, | ||
| 44 | nullptr, nullptr, cls.hInstance, nullptr); | ||
| 45 | CHECK(window); | ||
| 46 | { | ||
| 47 | rt::d3d12_xs::TitleHud hud(window); | ||
| 48 | // Presents at ~60 Hz for 1.5 s: the title shows a frame rate and the counters. | ||
| 49 | pump(1500, &hud); | ||
| 50 | const std::wstring text = title_of(window); | ||
| 51 | std::fwprintf(stderr, L"title: %ls\n", text.c_str()); | ||
| 52 | CHECK(text.rfind(L"Leonida | ", 0) == 0); | ||
| 53 | CHECK(text.find(L" fps ") != std::wstring::npos && text.find(L" ms (worst ") != std::wstring::npos); | ||
| 54 | CHECK(text.find(L"RAM ") != std::wstring::npos && text.find(L"VRAM ") != std::wstring::npos); | ||
| 55 | CHECK(text.find(L"PSO -") != std::wstring::npos); // no LEONIDA_MEM_PROBE: no pipeline counters | ||
| 56 | const int fps = _wtoi(text.c_str() + 10); | ||
| 57 | CHECK(fps >= 10 && fps <= 120); // a loose band: Sleep(16) on a loaded machine is not 60 Hz | ||
| 58 | |||
| 59 | // The window's thread stops pumping: the HUD's SendMessageTimeout gives up and the HUD thread is not stuck, | ||
| 60 | // so the destructor below returns. | ||
| 61 | Sleep(1200); | ||
| 62 | } | ||
| 63 | const ULONGLONG before = GetTickCount64(); | ||
| 64 | { | ||
| 65 | rt::d3d12_xs::TitleHud quick(window); | ||
| 66 | } // stops at once, without waiting a whole interval | ||
| 67 | CHECK(GetTickCount64() - before < 1000); | ||
| 68 | DestroyWindow(window); | ||
| 69 | std::printf("title_hud: counters in the title bar of another thread's window; a busy window does not hold it\n"); | ||
| 70 | return 0; | ||
| 71 | } | ||