Menu navigation with the left stick and back from the bottom buttons; AMD sensors and the picture lines in the performance overlay

The left stick now moves the menu cursor as the D-pad does (ImGui only scrolled with it). The page's rows are a
direct NavFlattened child of the menu window: behind a second child level ImGui did not clip them, so up from
Continue went to the tabs and down from the tabs to Continue.

The full overlay reads temperature, board power, clock and GPU load from ADL's PM log on AMD GPUs (matched by PCI
bus), and shows the window, game image and 3D scene sizes, the scaling to the window (FSR and its sharpness), the
frame limit and the presentation mode in use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-10-27 15:21:41 +03:00
1 parent f8219ed793
commit 89cc960f09
13 files changed
+265 -51

No files matched your search

+10
View File
@@ -137,6 +137,16 @@ uint64_t frame_step_cap_ns(void) {
return (uint64_t)(1e9 / hz + 0.5);
}
// The frame rate the limit gives, for the performance overlay: the setting, the monitor's rate for "display", 60 at
// most without the real-time step; 0 before the first frame read the setting.
double frame_step_limit_hz(void) {
int hz = limit_hz;
if (hz < 0) return 0;
double r = hz ? hz : gfx_window_refresh_hz();
if (r < LIMIT_MIN_HZ) r = 60;
return !step_word && r > 60 ? 60 : r > LIMIT_MAX_HZ ? LIMIT_MAX_HZ : r;
}
// ---- TOTK_TRACE=perf speed lines
static uint64_t win_t0, win_frames, win_hist[4]; // win_hist: frames by present interval 1, 2, 3+ ([0] unused)
static double win_game;
+5 -2
View File
@@ -54,6 +54,7 @@ static CRITICAL_SECTION g_pl;
static VkSwapchainKHR g_sc;
static VkFormat g_sc_fmt;
static VkExtent2D g_sc_ext;
static int g_scaler; // the last present: 0 the game image 1:1, 1 scaled by the blit, 2 by FSR
static uint32_t g_sc_n;
static VkImage g_sc_img[MAX_IMAGES];
static VkImageView g_sc_view[MAX_IMAGES]; // colour attachment views for the menu overlay
@@ -780,7 +781,7 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w
// The menu overlay: laid out before recording (its first frame starts the ImGui back end and uploads the font)
const char *menu_shot = NULL;
MenuTarget mt = {c->instance, c->phys, c->device, c->gfx_family, c->gfx_queue, g_sc_fmt, g_sc_ext.width,
g_sc_ext.height};
g_sc_ext.height, cw, ch, g_scaler};
int overlay = g_sc_view[idx] &&
menu_overlay_frame(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), &mt, &menu_shot);
int cap = (g_capture || menu_shot) && ensure_capture_buffer();
@@ -796,7 +797,9 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w
VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT);
const int rect[4] = {cx, cy, cw, ch};
// FSR (TOTK_UPSCALER) when the swapchain is larger than the crop; else the bilinear blit
if (!general || !vk_fsr_record(cb, slot, src, fmt, w, h, rect, dst, g_sc_ext.width, g_sc_ext.height)) {
int fsr = general && vk_fsr_record(cb, slot, src, fmt, w, h, rect, dst, g_sc_ext.width, g_sc_ext.height);
g_scaler = fsr ? 2 : (uint32_t)cw != g_sc_ext.width || (uint32_t)ch != g_sc_ext.height;
if (!fsr) {
if (general) // a GENERAL source (vk_texture.c images): earlier submissions' writes become visible to the blit here
sync_barrier(cb, src, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
VK_ACCESS_2_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT);
+3
View File
@@ -232,6 +232,8 @@ int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n); //
// the grown heaps, malloc'd; 0 = cannot (logged)
void res_heapdef_served(void); // romfs.c serves the grown table
void res_init(void); // after rt_patches_init: the patch page and the sets
void res_sizes(unsigned out[2], unsigned scene[2]); // the output and scene sizes in effect (the game's own
// until res_init switched the sets on)
// ---- code patches (patches.c) and the frame step (frame_rate.c)
void rt_patches_init(void); // after ldr_load: switches from the environment, the patch
// page committed; logs the sets
@@ -244,6 +246,7 @@ void *rt_patch_page(void); // the page the patch
void frame_step_init(void); // after rt_patches_init: the real-time step's first value
int frame_step_realtime(void); // the real-time step is on: presents ignore the interval
uint64_t frame_step_cap_ns(void); // with the real-time step: the shortest frame in ns
double frame_step_limit_hz(void); // the frame rate the limit gives (overlay); 0 unknown
int64_t frame_step_world_us(void); // game time since the loaded save's first frame, -1 before
// (TOTK_FPS_LIMIT, live)
void frame_step_present(uint64_t display_ns, int interval); // nvnQueuePresentTexture: the frame's display time and
+108 -3
View File
@@ -1,15 +1,22 @@
// Performance overlay numbers (runtime/perfmon.h). Frame times come from the game's presents (perf_present, only while
// the overlay is on); the per-frame waits from the perf counters prof_win.c keeps. The machine's numbers are sampled
// twice a second on a thread of their own (some calls take milliseconds), which runs only while the overlay is full.
// The OS calls sit behind platform.h (plat_cpu_load, plat_mem_info, plat_gpu_load); NVML (NVIDIA's driver library,
// for temperature, power and clock) is loaded at run time and is missing on other machines: its numbers stay -1.
// The OS calls sit behind platform.h (plat_cpu_load, plat_mem_info, plat_gpu_load). Temperature, power and clock come
// from the GPU vendor's driver library, loaded at run time: NVML on NVIDIA, ADL's PM log on AMD; on a machine without
// either their numbers stay -1.
//
// Adapted from SavageWindRecomp's runtime/perfmon.c (https://github.com/Revivedx/SavageWindRecomp @
// 575ad88e02f9a89a9a885d90039d48af33c982f4, MIT, Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors,
// Copyright (c) 2026 Peiikai): the frame ring and its one-second summary, the NVML calls, the sampler loop. The
// Windows, Linux and macOS sampling moved behind platform.h, GPU load and video memory come from the system's counters
// for every vendor, and the sampler stops when the overlay leaves full.
//
// The ADL declarations (AdapterInfo, ADLSingleSensorData, ADLPMLogDataOutput, the ADL_PMLOG_* sensor numbers and the
// ADL2_* signatures) are copied from AMD's display-library include/adl_structures.h, adl_defines.h and adl_sdk.h
// (https://github.com/GPUOpen-LibrariesAndSDKs/display-library @ 84c881cb2136f04287eb3af12de00a9e2867aa9e, MIT,
// Copyright (c) 2016 - 2022 Advanced Micro Devices, Inc.).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "host.h"
@@ -106,13 +113,15 @@ static struct {
static char g_gpu_name[96];
static uint8_t g_gpu_luid[8];
static int g_gpu_luid_ok;
static int g_gpu_bus = -1;
static float g_vram_total_mb = -1;
void perfmon_set_gpu(const char *name, const uint8_t *luid, float vram_total_mb) {
void perfmon_set_gpu(const char *name, const uint8_t *luid, int pci_bus, float vram_total_mb) {
plat_mutex_lock(&g_lock);
snprintf(g_gpu_name, sizeof g_gpu_name, "%s", name ? name : "");
g_gpu_luid_ok = luid != NULL;
if (luid) memcpy(g_gpu_luid, luid, sizeof g_gpu_luid);
g_gpu_bus = pci_bus;
g_vram_total_mb = vram_total_mb > 0 ? vram_total_mb : -1;
plat_mutex_unlock(&g_lock);
}
@@ -166,6 +175,99 @@ static void nvml_sample(PerfStats *s) {
if (nv.clock && nv.clock(nv.dev, 0 /* NVML_CLOCK_GRAPHICS */, &v) == 0) s->gpu_clock_mhz = (float)v;
}
// ---- ADL (AMD): loaded once on the sampler thread, kept for the process. ADL2_New_QueryPMLogData_Get reads the PM log
// the driver keeps for Radeon RX 5000 and later (the numbers Adrenalin's overlay shows); older GPUs answer with an
// error and their numbers stay -1. Windows only: the Linux driver gives these through sysfs, which this does not read.
#ifdef _WIN32
#define ADL_MAX_PATH 256
#define ADL_PMLOG_MAX_SENSORS 256
enum {
ADL_PMLOG_CLK_GFXCLK = 1,
ADL_PMLOG_TEMPERATURE_EDGE = 8,
ADL_PMLOG_INFO_ACTIVITY_GFX = 19,
ADL_PMLOG_ASIC_POWER = 23,
ADL_PMLOG_TEMPERATURE_HOTSPOT = 27,
ADL_PMLOG_BOARD_POWER = 73,
};
typedef struct { // AdapterInfo, the Windows layout
int iSize, iAdapterIndex;
char strUDID[ADL_MAX_PATH];
int iBusNumber, iDeviceNumber, iFunctionNumber, iVendorID;
char strAdapterName[ADL_MAX_PATH], strDisplayName[ADL_MAX_PATH];
int iPresent, iExist;
char strDriverPath[ADL_MAX_PATH], strDriverPathExt[ADL_MAX_PATH], strPNPString[ADL_MAX_PATH];
int iOSDisplayIndex;
} AdlAdapterInfo;
typedef struct { int supported, value; } AdlSensor;
typedef struct { int size; AdlSensor sensors[ADL_PMLOG_MAX_SENSORS]; } AdlPmLog;
typedef void *(__stdcall *AdlAlloc)(int);
static struct {
int tried, ok, index;
void *ctx;
int (*pmlog)(void *, int, AdlPmLog *);
AdlPmLog log; // the sampler thread's buffer
} adl;
static void *__stdcall adl_alloc(int n) { return malloc((size_t)n); }
// The adapter Vulkan renders on: the PCI bus when the device gave one, else the name. ADL lists one index per display
// output of a GPU; the first whose PM log answers is taken.
static void adl_open(const char *hint, int bus) {
adl.tried = 1;
void *lib = plat_lib_open("atiadlxx.dll");
if (!lib) return;
int (*create)(AdlAlloc, int, void **) = (int (*)(AdlAlloc, int, void **))plat_lib_sym(lib, "ADL2_Main_Control_Create");
int (*count)(void *, int *) = (int (*)(void *, int *))plat_lib_sym(lib, "ADL2_Adapter_NumberOfAdapters_Get");
int (*info)(void *, AdlAdapterInfo *, int) =
(int (*)(void *, AdlAdapterInfo *, int))plat_lib_sym(lib, "ADL2_Adapter_AdapterInfo_Get");
adl.pmlog = (int (*)(void *, int, AdlPmLog *))plat_lib_sym(lib, "ADL2_New_QueryPMLogData_Get");
int n = 0;
if (!create || !count || !info || !adl.pmlog || create(adl_alloc, 1, &adl.ctx) != 0 || count(adl.ctx, &n) != 0 ||
n <= 0 || n > 256)
return;
AdlAdapterInfo *a = (AdlAdapterInfo *)calloc((size_t)n, sizeof *a);
if (a) {
for (int i = 0; i < n; i++) a[i].iSize = sizeof *a;
if (info(adl.ctx, a, n * (int)sizeof *a) == 0) {
for (int i = 0; i < n && !adl.ok; i++) {
if (a[i].iVendorID != 1002) continue; // ADL writes the PCI vendor id 0x1002 as decimal 1002
const char *nm = a[i].strAdapterName;
if (bus >= 0 ? a[i].iBusNumber != bus : !hint[0] || !nm[0] || !(strstr(hint, nm) || strstr(nm, hint)))
continue;
memset(&adl.log, 0, sizeof adl.log);
adl.log.size = sizeof adl.log;
if (adl.pmlog(adl.ctx, a[i].iAdapterIndex, &adl.log) != 0) continue;
adl.index = a[i].iAdapterIndex;
adl.ok = 1;
}
}
free(a);
}
rt_log("perfmon: ADL %s", adl.ok ? "found the rendering GPU" : "has no PM log for the rendering GPU");
}
static void adl_sample(PerfStats *s) {
if (!adl.ok) return;
memset(&adl.log, 0, sizeof adl.log);
adl.log.size = sizeof adl.log;
if (adl.pmlog(adl.ctx, adl.index, &adl.log) != 0) return;
const AdlSensor *v = adl.log.sensors;
if (s->gpu_pct < 0 && v[ADL_PMLOG_INFO_ACTIVITY_GFX].supported) // the system's counters first
s->gpu_pct = (float)v[ADL_PMLOG_INFO_ACTIVITY_GFX].value;
if (v[ADL_PMLOG_TEMPERATURE_EDGE].supported) s->gpu_temp_c = (float)v[ADL_PMLOG_TEMPERATURE_EDGE].value;
else if (v[ADL_PMLOG_TEMPERATURE_HOTSPOT].supported) s->gpu_temp_c = (float)v[ADL_PMLOG_TEMPERATURE_HOTSPOT].value;
// the whole card's draw where the driver reports it (RDNA 4 reports no ASIC power), else the GPU chip's
if (v[ADL_PMLOG_BOARD_POWER].supported) s->gpu_power_w = (float)v[ADL_PMLOG_BOARD_POWER].value;
else if (v[ADL_PMLOG_ASIC_POWER].supported) s->gpu_power_w = (float)v[ADL_PMLOG_ASIC_POWER].value;
if (v[ADL_PMLOG_CLK_GFXCLK].supported) s->gpu_clock_mhz = (float)v[ADL_PMLOG_CLK_GFXCLK].value;
}
#else
static struct { int tried; } adl;
static void adl_open(const char *hint, int bus) { (void)hint, (void)bus, adl.tried = 1; }
static void adl_sample(PerfStats *s) { (void)s; }
#endif
// ---- the machine sampler: runs while want is set, twice a second
static struct {
int want, alive;
@@ -196,10 +298,12 @@ static void sampler(void *arg) {
int have_luid = g_gpu_luid_ok;
memcpy(luid, g_gpu_luid, sizeof luid);
snprintf(s.gpu_name, sizeof s.gpu_name, "%s", g_gpu_name);
int bus = g_gpu_bus;
float vram_total = g_vram_total_mb;
plat_mutex_unlock(&g_lock);
sysinfo_cpu_name(s.cpu_name, sizeof s.cpu_name);
if (!nv.tried) nvml_open(s.gpu_name);
if (!nv.ok && !adl.tried) adl_open(s.gpu_name, bus);
PlatLoad *l = plat_load_open(have_luid ? luid : NULL);
plat_mutex_lock(&g_lock);
while (g_smp.want) {
@@ -210,6 +314,7 @@ static void sampler(void *arg) {
plat_gpu_load(l, &s.gpu_pct, &s.vram_used_mb);
s.vram_total_mb = vram_total;
nvml_sample(&s);
adl_sample(&s);
plat_mutex_lock(&g_lock);
machine_copy(&g_stats, &s);
if (g_smp.want) plat_cond_wait_ns(&g_smp.cv, &g_lock, 500000000ull);
+5 -4
View File
@@ -23,7 +23,8 @@ typedef struct {
float cpu_total_pct, cpu_game_pct, cpu_temp_c;
// memory, MB
float ram_used_mb, ram_total_mb, ram_game_mb;
// GPU: load and dedicated memory from the system's counters, temperature, power and clock from NVML (NVIDIA)
// GPU: load and dedicated memory from the system's counters, temperature, power and clock from NVML (NVIDIA) or
// ADL (AMD)
char gpu_name[96];
float gpu_pct, gpu_temp_c, gpu_power_w, gpu_clock_mhz, vram_used_mb, vram_total_mb;
// per frame, averaged over the last half second: replay (NVN to Vulkan recording), GPU busy time (timestamps; -1
@@ -36,9 +37,9 @@ typedef struct {
// the machine sampling thread (twice a second) and turns on the event counts and GPU timestamps; leaving full stops
// them. Off: perf_present skips perfmon_frame and nothing samples.
void perfmon_mode(int mode);
// The Vulkan device the game renders on: its name, its LUID (8 bytes; NULL when the driver gives none) and its
// device-local memory. Before the first perfmon_mode(2).
void perfmon_set_gpu(const char *name, const uint8_t *luid, float vram_total_mb);
// The Vulkan device the game renders on: its name, its LUID (8 bytes; NULL when the driver gives none), its PCI bus
// (-1 unknown) and its device-local memory. Before the first perfmon_mode(2).
void perfmon_set_gpu(const char *name, const uint8_t *luid, int pci_bus, float vram_total_mb);
// A game frame was presented (perf_present, the render thread, only while the overlay is on): the time since the last
// one, the render thread's waits of this frame (PERF_N entries, host.h), its replay time and the running count of
// texture uploads.
+8
View File
@@ -47,6 +47,7 @@ static struct {
unsigned ow, oh, sw, sh; // output and scene
int scene_set; // the scene differs from the game's 5/6 of the output
int heapdef_ok; // romfs.c serves the grown HeapDef
int on; // res_init switched the patch sets on
} R;
static void decide(void) {
@@ -216,6 +217,13 @@ void res_init(void) {
memcpy(page + 48, &out, 8);
rt_patch_switch(output, R.ow != BASE_W || R.oh != BASE_H);
rt_patch_switch(scene, scene_on);
R.on = 1;
rt_log("resolution: output %ux%u, scene %ux%u%s; texture heap +%llu KiB", R.ow, R.oh, R.sw, R.sh,
scene_on ? "" : " (the game's own 5/6 of the output)", (unsigned long long)res_heap_extra_kib());
}
void res_sizes(unsigned out[2], unsigned scene[2]) {
decide();
out[0] = R.on ? R.ow : BASE_W, out[1] = R.on ? R.oh : BASE_H;
scene[0] = R.on ? R.sw : SCENE_W, scene[1] = R.on ? R.sh : SCENE_H;
}
+91 -30
View File
@@ -30,10 +30,12 @@ extern "C" {
#include "sysinfo.h"
#include "ui/menu.h"
#include "ui_text.h"
// host.h and vk.h pull in cpu.h, which is C only: the three functions the menu needs from them, as declared there.
// host.h and vk.h pull in cpu.h, which is C only: the functions the menu needs from them, as declared there.
void rt_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
void vk_queue_lock(void);
void vk_queue_unlock(void);
void res_sizes(unsigned out[2], unsigned scene[2]);
double frame_step_limit_hz(void);
}
// Roboto Medium (Apache-2.0, ui/fonts/LICENSE-Roboto.txt) with Latin and Cyrillic glyphs.
@@ -122,8 +124,18 @@ static const struct { int bit; ImGuiKey key; } pad_keys[] = {
{B_ZL, ImGuiKey_GamepadL2}, {B_ZR, ImGuiKey_GamepadR2}, {B_LEFT, ImGuiKey_GamepadDpadLeft},
{B_UP, ImGuiKey_GamepadDpadUp}, {B_RIGHT, ImGuiKey_GamepadDpadRight}, {B_DOWN, ImGuiKey_GamepadDpadDown},
};
static uint64_t pad_prev; // buttons at the last frame; a button held when the menu opened counts once released
static float stick_prev[4]; // left stick left, right, up, down as ImGui analog values
static uint64_t pad_prev; // buttons at the last frame; a button held when the menu opened counts once released
static int stick_dir = -1; // the D-pad button the left stick holds, -1 none
// The left stick moves the cursor as the D-pad does (ImGui's own stick handling only scrolls the page): past half way
// it holds the D-pad direction of its larger axis, kept until that axis falls under 0.35; ImGui repeats a held one.
static int stick_to_dpad(int32_t lx, int32_t ly) {
float x = lx / 32767.0f, y = ly / 32767.0f; // y up
float along = stick_dir == B_LEFT ? -x : stick_dir == B_RIGHT ? x : stick_dir == B_UP ? y : stick_dir == B_DOWN ? -y : 0;
if (stick_dir >= 0 && along > 0.35f) return stick_dir;
if (fmaxf(fabsf(x), fabsf(y)) < 0.5f) return -1;
return fabsf(x) > fabsf(y) ? (x < 0 ? B_LEFT : B_RIGHT) : (y > 0 ? B_UP : B_DOWN);
}
static void pad_events(ImGuiIO &io, int reset) {
uint64_t b;
@@ -131,9 +143,10 @@ static void pad_events(ImGuiIO &io, int reset) {
int have = input_pad_read(&b, &lx, &ly);
if (have) io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
else io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
stick_dir = stick_to_dpad(lx, ly);
if (stick_dir >= 0) b |= 1ull << stick_dir;
if (reset) {
pad_prev = b;
for (float &s : stick_prev) s = 0;
return;
}
for (const auto &k : pad_keys) {
@@ -141,15 +154,6 @@ static void pad_events(ImGuiIO &io, int reset) {
if ((b ^ pad_prev) & m) io.AddKeyEvent(k.key, (b & m) != 0);
}
pad_prev = b;
const float dead = 0.3f;
float v[4] = {-lx / 32767.0f, lx / 32767.0f, ly / 32767.0f, -ly / 32767.0f};
static const ImGuiKey sk[4] = {ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp,
ImGuiKey_GamepadLStickDown};
for (int i = 0; i < 4; i++) {
float a = v[i] > dead ? (v[i] - dead) / (1 - dead) : 0;
if (a != stick_prev[i]) io.AddKeyAnalogEvent(sk[i], a > 0.1f, a);
stick_prev[i] = a;
}
}
// ---- ImGui and its Vulkan back end (present path)
@@ -485,17 +489,23 @@ static void row_fps_limit() {
opt_choice_list("TOTK_FPS_LIMIT", UI_MENU_FPS_LIMIT, vals, names, N, UI_MENU_FPS_LIMIT_DESC, cur);
}
// "in use: VSync" under the Presentation value when the swapchain got another mode than the setting (a driver without
// mailbox gets fifo); NULL when they agree or before the first swapchain.
static const char *present_note(void) {
// The menu's name of a TOTK_VK_PRESENT mode (gfx_window_present_mode); NULL for another.
static const char *present_name(const char *mode) {
static const struct { const char *mode; UiTextId name; } names[] = {
{"mailbox", UI_MENU_PRESENT_MAILBOX}, {"fifo", UI_MENU_PRESENT_VSYNC}, {"immediate", UI_MENU_PRESENT_IMMEDIATE},
};
const char *got = gfx_window_present_mode();
if (!*got || !strcmp(got, cfg_value("TOTK_VK_PRESENT"))) return nullptr;
static char note[96];
for (const auto &n : names)
if (!strcmp(n.mode, got)) snprintf(note, sizeof note, menu_text(UI_MENU_PRESENT_IN_USE), menu_text(n.name));
if (!strcmp(n.mode, mode)) return menu_text(n.name);
return nullptr;
}
// "in use: VSync" under the Presentation value when the swapchain got another mode than the setting (a driver without
// mailbox gets fifo); NULL when they agree or before the first swapchain.
static const char *present_note(void) {
const char *got = gfx_window_present_mode(), *name = present_name(got);
if (!*got || !strcmp(got, cfg_value("TOTK_VK_PRESENT")) || !name) return nullptr;
static char note[96];
snprintf(note, sizeof note, menu_text(UI_MENU_PRESENT_IN_USE), name);
return note;
}
@@ -746,7 +756,10 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
g_focus_page = -1;
}
ImGui::Spacing();
ImGui::BeginChild("##page", ImVec2(0, -bottom), ImGuiChildFlags_NavFlattened);
// the page's rows are a NavFlattened child of this window itself: ImGui clips the items of a direct child
// only, so behind a second child level the rows scrolled out above the tabs won D-pad moves from the
// buttons and the tabs (up from "Continue" went to the tabs, down from the tabs to "Continue")
opt_reserve_bottom(bottom);
switch (k) {
case TAB_SCREEN: tab_screen(scale); break;
case TAB_GAME: tab_game(scale); break;
@@ -755,7 +768,6 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
case TAB_MENU: tab_menu(scale); break;
case TAB_ADVANCED: tab_advanced(scale); break;
}
ImGui::EndChild();
ImGui::EndTabItem();
}
g_tab_request = -1;
@@ -803,12 +815,21 @@ extern "C" void menu_perf_cycle(void) {
g_perf_save.store(1);
}
// The device the game renders on, for perfmon's GPU counters (by LUID) and NVML (by name); once, before full mode.
// The device the game renders on, for perfmon's GPU counters (by LUID), NVML (by name) and ADL (by PCI bus, else
// name); once, before full mode.
static void perf_gpu_once(const MenuTarget *t) {
static bool done;
if (done) return;
done = true;
VkPhysicalDeviceIDProperties id = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES};
uint32_t ne = 0;
vkEnumerateDeviceExtensionProperties(t->phys, NULL, &ne, NULL);
VkExtensionProperties *ep = (VkExtensionProperties *)calloc(ne ? ne : 1, sizeof *ep);
bool has_bus = false;
if (ep && vkEnumerateDeviceExtensionProperties(t->phys, NULL, &ne, ep) >= 0)
for (uint32_t i = 0; i < ne && !has_bus; i++) has_bus = !strcmp(ep[i].extensionName, VK_EXT_PCI_BUS_INFO_EXTENSION_NAME);
free(ep);
VkPhysicalDevicePCIBusInfoPropertiesEXT bus = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT};
VkPhysicalDeviceIDProperties id = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, has_bus ? &bus : nullptr};
VkPhysicalDeviceProperties2 p2 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &id};
vkGetPhysicalDeviceProperties2(t->phys, &p2);
VkPhysicalDeviceMemoryProperties mp;
@@ -816,7 +837,8 @@ static void perf_gpu_once(const MenuTarget *t) {
uint64_t vram = 0;
for (uint32_t h = 0; h < mp.memoryHeapCount; h++)
if (mp.memoryHeaps[h].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) vram += mp.memoryHeaps[h].size;
perfmon_set_gpu(p2.properties.deviceName, id.deviceLUIDValid ? id.deviceLUID : NULL, (float)(vram >> 20));
perfmon_set_gpu(p2.properties.deviceName, id.deviceLUIDValid ? id.deviceLUID : NULL, has_bus ? (int)bus.pciBus : -1,
(float)(vram >> 20));
}
static void perf_tick(uint64_t now, const MenuTarget *t) {
@@ -889,7 +911,44 @@ static void perf_label(UiTextId label, const ImVec4 &c) {
static float perf_gb(float mb) { return mb < 0 ? -1 : mb / 1024; }
static void perf_full_draw(float w, float scale) {
// The picture lines: the window, the game image the present shows and the 3D scene it holds (resolution.c), how the
// present scales the image to the window (gfx_window.c, the last present), the frame limit and the presentation mode
// in use.
static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
unsigned out[2], scene[2];
res_sizes(out, scene);
char v[6][64];
snprintf(v[0], sizeof v[0], menu_text(UI_MENU_OV_FMT_SIZE), t->width, t->height);
snprintf(v[1], sizeof v[1], menu_text(UI_MENU_OV_FMT_SIZE), (unsigned)t->image_w, (unsigned)t->image_h);
snprintf(v[2], sizeof v[2], menu_text(UI_MENU_OV_FMT_SCENE), scene[0], scene[1], scene[0] * 100.0 / out[0]);
if (t->scaler == 2) {
int s = cfg_int("TOTK_SHARPNESS");
snprintf(v[3], sizeof v[3], menu_text(UI_MENU_OV_FMT_FSR), s < 0 ? 0 : s > 100 ? 100 : s);
} else {
snprintf(v[3], sizeof v[3], "%s", menu_text(t->scaler ? UI_MENU_OV_SCALE_BILINEAR : UI_MENU_OV_SCALE_NONE));
}
double hz = frame_step_limit_hz();
snprintf(v[4], sizeof v[4], "%s", menu_text(UI_MENU_OV_NONE));
if (hz > 0) snprintf(v[4], sizeof v[4], menu_text(UI_MENU_OV_FPS), hz);
const char *pm = present_name(gfx_window_present_mode());
snprintf(v[5], sizeof v[5], "%s", pm ? pm : menu_text(UI_MENU_OV_NONE));
static const UiTextId labels[6] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE,
UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT};
if (!ImGui::BeginTable("##perfp", 2, ImGuiTableFlags_SizingFixedFit)) return;
float vw = 0;
for (auto &s : v) vw = fmaxf(vw, ImGui::CalcTextSize(s).x);
ImGui::TableSetupColumn("##p0", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##p1", ImGuiTableColumnFlags_WidthFixed, vw);
for (int i = 0; i < 6; i++) {
perf_label(labels[i], c);
ImGui::TableNextColumn();
perf_right(v[i], false);
}
ImGui::EndTable();
}
static void perf_full_draw(const MenuTarget *t, float scale) {
float w = (float)t->width;
PerfStats s;
perfmon_snapshot(&s);
ImGui::SetNextWindowPos(ImVec2(w - 12 * scale, 12 * scale), ImGuiCond_Always, ImVec2(1, 0));
@@ -900,7 +959,7 @@ static void perf_full_draw(float w, float scale) {
ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); // over the menu while it is open
ImGui::SetWindowFontScale(0.72f);
const ImVec4 gpu_c(0.55f, 0.83f, 0.31f, 1), cpu_c(0.18f, 0.59f, 0.80f, 1), ram_c(0.80f, 0.45f, 0.70f, 1),
fps_c(0.95f, 0.95f, 0.95f, 1), wait_c(0.93f, 0.76f, 0.33f, 1);
fps_c(0.95f, 0.95f, 0.95f, 1), wait_c(0.93f, 0.76f, 0.33f, 1), pic_c(0.62f, 0.70f, 0.95f, 1);
if (ImGui::BeginTable("##perft", 4, ImGuiTableFlags_SizingFixedFit)) {
static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM};
static const PerfCol c0[] = {{UI_MENU_OV_FPS, 888}};
@@ -960,13 +1019,15 @@ static void perf_full_draw(float w, float scale) {
perf_cell(UI_MENU_OV_PER_FRAME, s.tex_uploads);
ImGui::EndTable();
}
perf_picture(t, pic_c);
if (s.gpu_name[0]) ImGui::TextDisabled("%s", s.gpu_name);
if (s.cpu_name[0]) ImGui::TextDisabled("%s", s.cpu_name);
ImGui::End();
}
static void perf_draw(float w, float scale) {
if (g_perf_mode == 2) return perf_full_draw(w, scale);
static void perf_draw(const MenuTarget *t, float scale) {
if (g_perf_mode == 2) return perf_full_draw(t, scale);
float w = (float)t->width;
if (!g_perf_mode || !g_perf_text[0]) return;
ImDrawList *dl = ImGui::GetForegroundDrawList();
ImVec2 sz = ImGui::CalcTextSize(g_perf_text);
@@ -1040,7 +1101,7 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
ImGui_ImplVulkan_NewFrame();
ImGui::NewFrame();
if (open) layout_menu(t->width, t->height, scale);
perf_draw((float)t->width, scale);
perf_draw(t, scale);
ImGui::Render();
if (open) g_save_pending = opt_save_tick(0);
g_cost_ns += plat_now_ns() - t0;
+2
View File
@@ -43,6 +43,8 @@ typedef struct {
VkQueue queue; // submissions take vk_queue_lock
VkFormat format; // of the swapchain image, a colour attachment
uint32_t width, height;
int image_w, image_h; // the game image this present shows (its crop)
int scaler; // how the last present scaled it to the window: 0 not, 1 bilinear blit, 2 FSR 1
} MenuTarget;
// Lays out this frame's overlay; 1 when there is something to draw. frame: the presented frame (0 unknown). *shot: a
// path when the test hook wants this frame's swapchain image saved, else NULL. The first open starts ImGui's Vulkan
+13 -11
View File
@@ -31,6 +31,7 @@ static float g_scale = 1;
static bool g_focus_req, g_take_first; // opt_focus_first: requested / this page's first row takes it
static char g_focus_key[64]; // opt_focus_key: the row that takes the cursor when it is next drawn
static bool g_held; // the last row's left / right has been held a while (steppers go faster)
static float g_bottom; // opt_reserve_bottom: kept free under the panes
static bool g_disable_next; // opt_disable_next: the next row is greyed out with g_disable_note
static UiTextId g_disable_note;
@@ -54,6 +55,8 @@ void opt_focus_first(void) { g_focus_req = true; }
void opt_focus_key(const char *key) { snprintf(g_focus_key, sizeof g_focus_key, "%s", key); }
void opt_reserve_bottom(float h) { g_bottom = h; }
void opt_disable_next(UiTextId note) {
g_disable_next = true;
g_disable_note = note;
@@ -66,6 +69,7 @@ void opt_begin(const char *id, float scale) {
if (g_take_first) ImGui::NavMoveRequestCancel(); // this frame's move goes to the first row instead
g_hover.text[0] = g_focus.text[0] = g_first.text[0] = 0;
ImVec2 avail = ImGui::GetContentRegionAvail();
avail.y -= g_bottom;
ImGui::PushID(id);
ImGui::BeginChild("##rows", ImVec2(avail.x * 0.58f, avail.y), ImGuiChildFlags_NavFlattened);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 5 * scale));
@@ -80,6 +84,7 @@ void opt_end(void) {
else if (!g_shown.text[0]) g_shown = g_first;
ImGui::SameLine(0, 0);
ImVec2 p = ImGui::GetCursorScreenPos(), avail = ImGui::GetContentRegionAvail();
avail.y -= g_bottom;
float gap = 24 * g_scale;
ImGui::GetWindowDrawList()->AddLine(ImVec2(p.x + gap * 0.5f, p.y), ImVec2(p.x + gap * 0.5f, p.y + avail.y),
IM_COL32(236, 194, 84, 110), 1.0f);
@@ -130,19 +135,16 @@ static int row(const char *key, UiTextId label, UiTextId desc, const RowView &v)
int step = clicked && !off ? 2 : 0;
g_held = false;
if (foc && !off) {
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft) || ImGui::IsKeyPressed(ImGuiKey_GamepadLStickLeft) ||
ImGui::IsKeyPressed(ImGuiKey_LeftArrow))
step = -1;
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight) || ImGui::IsKeyPressed(ImGuiKey_GamepadLStickRight) ||
ImGui::IsKeyPressed(ImGuiKey_RightArrow))
step = 1;
// the left stick arrives as the D-pad (menu.cpp pad_events)
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft) || ImGui::IsKeyPressed(ImGuiKey_LeftArrow)) step = -1;
if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight) || ImGui::IsKeyPressed(ImGuiKey_RightArrow)) step = 1;
static const ImGuiKey steps[] = {ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadRight, ImGuiKey_LeftArrow,
ImGuiKey_RightArrow, ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight};
for (ImGuiKey k : steps)
ImGuiKey_RightArrow};
for (ImGuiKey k : steps) {
if (ImGui::GetKeyData(k)->DownDuration > 1.0f) g_held = true;
// left and right belong to the row (navigation would otherwise move sideways into the description pane); the
// first four of steps, the stick stays with navigation
for (int i = 0; i < 4; i++) ImGui::SetKeyOwner(steps[i], ImGui::GetItemID());
// left and right belong to the row (navigation would otherwise move sideways into the description pane)
ImGui::SetKeyOwner(k, ImGui::GetItemID());
}
}
if (foc) desc_set(g_focus, desc, key, m, disabled);
if (hov) desc_set(g_hover, desc, key, m, disabled);
+2
View File
@@ -17,6 +17,8 @@ extern "C" {
void opt_begin(const char *id, float scale);
void opt_end(void);
// The height the next pages leave free under their panes (the menu's bottom row).
void opt_reserve_bottom(float h);
// The next page's first row takes the controller's cursor (opening the menu, switching tabs).
void opt_focus_first(void);
// The row of key (or button id) takes the cursor, scrolled into view, when it is next drawn.
+10
View File
@@ -180,6 +180,11 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_OV_FMT_PCT] = "%.0f%%", [UI_MENU_OV_FMT_TEMP] = "%.0f °C", [UI_MENU_OV_FMT_POWER] = "%.0f W",
[UI_MENU_OV_FMT_MHZ] = "%.0f MHz", [UI_MENU_OV_FMT_GB] = "%.1f GB", [UI_MENU_OV_FMT_GB_OF] = "/ %.1f GB",
[UI_MENU_OV_GAME_GB] = "game %.1f GB", [UI_MENU_OV_FMT_MS] = "%.2f ms", [UI_MENU_OV_PER_FRAME] = "%.1f per frame",
[UI_MENU_OV_WINDOW] = "Window", [UI_MENU_OV_OUTPUT] = "Game image", [UI_MENU_OV_SCENE] = "3D scene",
[UI_MENU_OV_SCALING] = "Scaling", [UI_MENU_OV_LIMIT] = "Frame limit", [UI_MENU_OV_PRESENT] = "Presentation",
[UI_MENU_OV_FMT_SIZE] = "%ux%u", [UI_MENU_OV_FMT_SCENE] = "%ux%u, %.0f%%",
[UI_MENU_OV_FMT_FSR] = "AMD FSR 1, sharpness %d%%", [UI_MENU_OV_SCALE_NONE] = "none (1:1)",
[UI_MENU_OV_SCALE_BILINEAR] = "bilinear",
};
static const char *const text_ru[UI_TEXT_COUNT] = {
@@ -342,6 +347,11 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_OV_FMT_PCT] = "%.0f%%", [UI_MENU_OV_FMT_TEMP] = "%.0f °C", [UI_MENU_OV_FMT_POWER] = "%.0f Вт",
[UI_MENU_OV_FMT_MHZ] = "%.0f МГц", [UI_MENU_OV_FMT_GB] = "%.1f ГБ", [UI_MENU_OV_FMT_GB_OF] = "/ %.1f ГБ",
[UI_MENU_OV_GAME_GB] = "игра %.1f ГБ", [UI_MENU_OV_FMT_MS] = "%.2f мс", [UI_MENU_OV_PER_FRAME] = "%.1f за кадр",
[UI_MENU_OV_WINDOW] = "Окно", [UI_MENU_OV_OUTPUT] = "Изображение игры", [UI_MENU_OV_SCENE] = "3D-сцена",
[UI_MENU_OV_SCALING] = "Масштабирование", [UI_MENU_OV_LIMIT] = "Лимит кадров", [UI_MENU_OV_PRESENT] = "Вывод кадров",
[UI_MENU_OV_FMT_SIZE] = "%ux%u", [UI_MENU_OV_FMT_SCENE] = "%ux%u, %.0f%%",
[UI_MENU_OV_FMT_FSR] = "AMD FSR 1, резкость %d%%", [UI_MENU_OV_SCALE_NONE] = "нет (1:1)",
[UI_MENU_OV_SCALE_BILINEAR] = "билинейное",
};
#define SWKBD_ONLY(name, ...) static const char *const name[UI_TEXT_COUNT] = {SWKBD(__VA_ARGS__)}
+7 -1
View File
@@ -114,7 +114,13 @@ typedef enum {
// number formats of the overlay's cells (printf, one number each)
UI_MENU_OV_FMT_PCT, UI_MENU_OV_FMT_TEMP, UI_MENU_OV_FMT_POWER, UI_MENU_OV_FMT_MHZ, UI_MENU_OV_FMT_GB,
UI_MENU_OV_FMT_GB_OF, UI_MENU_OV_GAME_GB, UI_MENU_OV_FMT_MS, UI_MENU_OV_PER_FRAME,
UI_MENU_LAST_ID = UI_MENU_OV_PER_FRAME,
// the picture lines: window, game image and 3D scene sizes, the scaling to the window, frame limit and presentation
UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT,
UI_MENU_OV_FMT_SIZE, // "%ux%u"
UI_MENU_OV_FMT_SCENE, // "%ux%u, %.0f%%": the scene and its share of the game image's width
UI_MENU_OV_FMT_FSR, // "AMD FSR 1, sharpness %d%%"
UI_MENU_OV_SCALE_NONE, UI_MENU_OV_SCALE_BILINEAR,
UI_MENU_LAST_ID = UI_MENU_OV_SCALE_BILINEAR,
UI_TEXT_COUNT
} UiTextId;