Hand the frame limit to RivaTuner Statistics Server where it runs, and take it back when RTSS does not hold to it.

Where RTSS is installed and running, the frame limit from the menu goes into RTSS's profile for the game's executable
through RTSS's hooks library, loaded at run time, and the game's own pacer stands aside while RTSS has hooked the game.
Menu changes apply live, unlimited clears the limit, and closing the game (or any exit path) puts back what the profile
held, or removes a profile the game created. Each change is read back from the saved profile: without administrator
rights RTSS's profile folder cannot be written, and the game then keeps its own limiter. While RTSS limits, RTSS's own
frame counter for the game is checked against the limit; well past it for three seconds, the game takes the limiting
back for the run. The log says which limiter is in use and why, and a note under the frame-rate row says when RTSS
limits, when its profile is read-only, and when it does not hold the game to the limit. rtss = 0 and frame generation
keep RTSS out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-08 01:08:39 -05:00
parent cfc3228cc4
commit 9bb3c6c55a
13 changed files with 401 additions and 5 deletions

View File

@@ -52,6 +52,7 @@
#include "host.h"
#include "layout.h"
#include "platform/platform.h"
#include "vk_fg.h"
#define STEP_SAMPLES 5
#define STEP_MAX_S (1.0 / 15.0) // longest step; a longer frame slows the game down
@@ -180,13 +181,25 @@ static void frame_limit_live(void) {
else rt_log("frame rate: limit at the monitor's refresh rate (60 until the window measures it)");
}
// RivaTuner Statistics Server (rtss_limit.c) gets the same limit; while it limits this process the pacer holds no
// frames, so the two never stack. NX2NAVI_RTSS=0 and frame generation (RTSS would count the generated frames) keep it out.
uint64_t frame_step_cap_ns(void) {
frame_limit_live();
if (limit_hz == -2) return 0; // unlimited: the pacer does not hold frames
static int rtss = -1;
if (rtss < 0) {
const char *e = cfg_get("NX2NAVI_RTSS");
rtss = !(e && !strcmp(e, "0")) && !vk_fg_wanted();
}
if (limit_hz == -2) { // unlimited: the pacer does not hold frames, and RTSS's limit is cleared
rtss_limit_want(rtss ? 0 : -1);
return 0;
}
double hz = limit_hz ? limit_hz : gfx_window_refresh_hz();
if (hz < LIMIT_MIN_HZ) hz = 60; // display rate unknown (no window yet)
double max = frame_free_running() ? LIMIT_FREE_MAX_HZ : LIMIT_MAX_HZ;
if (hz > max) hz = max;
rtss_limit_want(rtss ? (int64_t)(hz * 1000 + 0.5) : -1);
if (rtss_limit_active()) return 0;
return (uint64_t)(1e9 / hz + 0.5);
}