Frame generation gets a row on the Game tab under the frame limit (Off or AMD FSR 3) that applies at once, and the fps overlay reads "N fps drawn, M shown" while it runs

The row and its description (for displays of 120 Hz and more, the game at half the limit, about half a frame more input delay, not with DLSS or HDR) are in the menu's catalog for English, Russian, Portuguese (Brazil) and Simplified Chinese. frame_gen is live: vk_fg.cpp vk_fg_engine reads it again after a settings change, the contexts are made at the first frame after it is turned on (a hitch of about 0.1 s once), turned off they stay unused until exit, and gfx_present.c builds the swapchain again when the extra image for the pair comes or goes. The full overlay gets a Shown row. totk.ini.example describes frame_gen.

The shown-frames counter and the overlay lines follow PR #1089 by xellow78-lgtm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: xellow78-lgtm <336264245+xellow78-lgtm@users.noreply.github.com>
This commit is contained in:
committed 2026-11-20 13:48:10 +03:00
1 parent 451813aa17
commit efee9bcf16
9 files changed
+101 -24

No files matched your search

+34 -6
View File
@@ -54,6 +54,8 @@ void vk_queue_unlock(void);
int vk_exec_replay_workers(void);
void res_sizes(unsigned out[2], unsigned scene[2]);
double frame_step_limit_hz(void);
uint64_t gfx_presents_shown(void); // gfx_present.c
int gfx_frame_gen_live(void); // vk_backend.c
extern const int rt_game_version;
extern const char rt_port_version[];
void cheats_frame(uint64_t frame); // cheats.c
@@ -831,6 +833,8 @@ static void row_play_time(void) {
static void tab_game(float scale) {
opt_begin("##game", scale);
row_fps_limit();
static const UiTextId frame_gen[] = {UI_MENU_FRAME_GEN_OFF, UI_MENU_FRAME_GEN_FSR3};
opt_choice("TOTK_FRAME_GEN", UI_MENU_FRAME_GEN, frame_gen, 2, UI_MENU_FRAME_GEN_DESC);
opt_toggle("TOTK_FRAME_QUEUE", UI_MENU_FRAME_QUEUE, UI_MENU_FRAME_QUEUE_DESC);
row_game_lang();
static const UiTextId mode[] = {UI_MENU_MODE_DOCKED, UI_MENU_MODE_HANDHELD};
@@ -1579,6 +1583,24 @@ static uint64_t g_perf_last_ns, g_perf_win_ns, g_perf_max_ns;
static int g_perf_frames;
static char g_perf_text[96];
// Frame generation shows more pictures than the game draws (vk_backend.c present_pair): the presents a second over the
// last half second while it runs, else 0. The overlay's frame counts stay the frames the game drew. (PR #1089's
// shown_tick, by xellow78-lgtm.)
static double g_shown_fps;
static void shown_tick(uint64_t now) {
static uint64_t t0, n0;
uint64_t n = gfx_presents_shown();
int live = gfx_frame_gen_live();
if (!live || !t0 || now - t0 > 2000000000ull) {
t0 = now, n0 = n;
if (!live) g_shown_fps = 0;
} else if (now - t0 >= 500000000ull) {
g_shown_fps = (double)(n - n0) * 1e9 / (double)(now - t0);
t0 = now, n0 = n;
}
}
static int perf_mode_of(const char *s) { return !strcmp(s, "full") ? 2 : !strcmp(s, "fps") ? 1 : 0; }
extern "C" void menu_perf_cycle(void) {
@@ -1624,6 +1646,7 @@ static void perf_tick(uint64_t now, const MenuTarget *t) {
}
g_perf_mode = m;
}
if (g_perf_mode) shown_tick(now);
if (g_perf_mode != 1) return;
uint64_t d = now - g_perf_last_ns;
if (!g_perf_last_ns || d > 2000000000ull) { // first frame, or a stall the window should not average in
@@ -1634,7 +1657,9 @@ static void perf_tick(uint64_t now, const MenuTarget *t) {
g_perf_frames++;
if (d > g_perf_max_ns) g_perf_max_ns = d;
if (g_perf_win_ns >= 500000000ull) {
snprintf(g_perf_text, sizeof g_perf_text, menu_text(UI_PERF_LINE_FPS), g_perf_frames * 1e9 / g_perf_win_ns);
double drawn = g_perf_frames * 1e9 / g_perf_win_ns;
if (g_shown_fps > 0) snprintf(g_perf_text, sizeof g_perf_text, menu_text(UI_PERF_LINE_FPS_GEN), drawn, g_shown_fps);
else snprintf(g_perf_text, sizeof g_perf_text, menu_text(UI_PERF_LINE_FPS), drawn);
g_perf_win_ns = g_perf_max_ns = 0;
g_perf_frames = 0;
}
@@ -1689,7 +1714,7 @@ static float perf_gb(float mb) { return mb < 0 ? -1 : mb / 1024; }
static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
unsigned out[2], scene[2];
res_sizes(out, scene);
char v[6][64];
char v[7][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]);
@@ -1708,14 +1733,17 @@ static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
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};
// with frame generation: the pictures shown a second, of which the FPS row above counts the ones the game drew
int n = 6;
if (g_shown_fps > 0) snprintf(v[n++], sizeof v[6], menu_text(UI_MENU_OV_FPS), g_shown_fps);
static const UiTextId labels[7] = {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_SHOWN};
if (!ImGui::BeginTable("##perfp", 2, ImGuiTableFlags_SizingFixedFit)) return;
float vw = 0;
for (auto &s : v) vw = fmaxf(vw, ImGui::CalcTextSize(s).x);
for (int i = 0; i < n; i++) vw = fmaxf(vw, ImGui::CalcTextSize(v[i]).x);
ImGui::TableSetupColumn("##p0", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##p1", ImGuiTableColumnFlags_WidthFixed, vw);
for (int i = 0; i < 6; i++) {
for (int i = 0; i < n; i++) {
perf_label(labels[i], c);
ImGui::TableNextColumn();
perf_right(v[i], false);