Let the game's limiter stand aside only once RivaTuner Statistics Server is seen holding the game, and give up on RTSS at 1.05 times the limit over three fresh periods.

The worker stood aside as soon as RTSS listed the process and the profile read back, before RTSS had seen a Vulkan
present (with InjectionDelay=15000 it lists the game some seconds after start) or read the new profile. Its frame
count check took the newest period whatever its age: a period frozen at 144 fps after the limit went to 60 and the
window was minimised failed RTSS for the run, and 1.15 times the limit was never caught (lane A's probe: listed_no_api,
stale_fps, over115). rtss_decide now parses the entry's flags and stands aside only when the profile held the target
at the poll before, RTSS lists the game with the Vulkan API value (flags & 0xFFFF == 0xA), RTSS_UPDATE_ASKED is clear,
a new period was seen within max(2.5 s, 2.5 times its length), no movie plays and a host present went out within
200 ms. Only a new period after a poll that stood aside is checked: three in a row over 1.05 times the limit put the
profile back for the run, and a stale period counts neither way. The worker reads the poll time and the newest host
present (gfx_window_hosted_ns), and logs each change of why the game's limiter paces, up to 100 lines.

Not reproduced before the change. rtss_limit_check (the flags at +264; T2 injection delay through not listed, no API,
the update flag, no period and holding; T3 quit; T6 the frame count at 144, 69, 63 fps, a frozen period and a newer
want; the idle case) and rtss_worker_check (over_run, over_slack_run, new api_run and idle_run, and every scenario that
now holds from the poll after the write) pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:13:36 -05:00
parent 04f4d44747
commit f7899e5443
4 changed files with 298 additions and 109 deletions

View File

@@ -13,11 +13,13 @@
// then fails silently. So every change is read back
// from the saved profile, and a limit that did not stick leaves the game's own limiter in charge for the session.
//
// RTSS runs when its shared memory "RTSSSharedMemoryV2" carries the signature 'RTSS'; it limits this process once the
// memory's application list holds this process id (RTSS hooks a process some seconds after it starts, its injection
// delay). Until then, and again if RTSS quits, the game's own limiter paces the frames. While RTSS limits, the frame
// rate RTSS itself measures for the game is checked against the limit: well above it for three seconds, and the game
// takes the limiting back for the rest of the run.
// RTSS runs when its shared memory "RTSSSharedMemoryV2" carries the signature 'RTSS'. The game's own limiter stands
// aside only once RTSS is seen to hold the game (rtss_decide.h rtss_decide): the memory's application list holds this
// process id with its Vulkan presents (RTSS hooks a process some seconds after it starts, its injection delay), RTSS
// has read the profile the game wrote, it measured a period of the game's frames lately, no movie plays and pictures
// go out. Until then, and again whenever one of these ends (RTSS quits, the window is minimised), the game's own limiter
// paces the frames. While RTSS limits, each new period RTSS measures for the game is checked against the limit: above
// 1.05 times it for three periods in a row, and the game takes the limiting back for the rest of the run.
//
// The calls run on a thread of their own, every half second, which also looks RTSS up (find_rtss), so a present never
// waits on the registry or profile files. On every orderly exit (rtss_limit_restore) the profile gets back what it held
@@ -40,6 +42,7 @@
#include <stdlib.h>
#include <string.h>
#include "gfx.h"
#include "host.h"
#include "platform/platform.h"
#include "rtss_decide.h"
@@ -328,17 +331,23 @@ static void put_back_op(void *ctx, const RtssOut *o) { // rtss_poll's RtssOps.
}
// Whether RTSS holds the game to the want w this poll read, and the log of which limiter is in use: the first decision,
// then each change. The want may have changed since the poll read it: rtss_limit_active compares the two, so a stale
// store never lets the game's limiter stand aside for a newer want. The store is made either way (a want that went
// w, w2, w again must not find an older hold), but a hold is logged only while its want is still the current one: the
// game's limiter paces a newer want, and the next poll logs what holds it.
// then each change of the limiter or of why the game's own one paces (RTSS not hooked yet, not read the profile, a
// minimised window), up to LIMITER_LINES lines. The want may have changed since the poll read it: rtss_limit_active
// compares the two, so a stale store never lets the game's limiter stand aside for a newer want. The store is made
// either way (a want that went w, w2, w again must not find an older hold), but a hold is logged only while its want
// is still the current one: the game's limiter paces a newer want, and the next poll logs what holds it.
#define LIMITER_LINES 100
static void set_active(int64_t w, int on, const char *why) {
static int logged = -1;
static int logged = -1, lines;
static char said[128];
atomic_store(&active_for, on ? w : RTSS_UNSET);
if (logged == on || (on && atomic_load(&want) != w)) return;
if ((on && atomic_load(&want) != w) || (logged == on && (on || !strcmp(why, said)))) return;
logged = on;
snprintf(said, sizeof said, "%s", on ? "" : why);
if (++lines > LIMITER_LINES) return;
if (on) rt_log("frame rate: RivaTuner Statistics Server does the limiting; the game's own limiter stands aside");
else rt_log("frame rate: the game's own limiter (%s)", why);
if (lines == LIMITER_LINES) rt_log("frame rate: later changes of the limiter in charge are not logged");
}
// RTSS's own settings for the game, read from its profile file as RTSS keeps it: Profiles\<exe>.cfg, else
@@ -473,7 +482,8 @@ static void worker(void *arg) {
plat_mutex_unlock(&lock);
continue;
}
RtssIn in = {.want = w, .movie_mhz = atomic_load(&movie_mhz)};
RtssIn in = {.want = w, .movie_mhz = atomic_load(&movie_mhz), .now_ns = kern_now_ns(),
.hosted_ns = gfx_window_hosted_ns()};
rtss_map(&in.app);
if (in.app.running != was_running || in.app.listed != was_listed) {
if (!in.app.running) rt_log("frame rate: RivaTuner Statistics Server is installed but not running");