Tie RivaTuner Statistics Server's hold to the want it was decided for, so a stale store no longer keeps the pacer aside.

The worker checked that the want was still the one it had read and then stored active = 1, two steps on two atomics.
A rtss_limit_want between them (frame generation or low latency switched on, a movie, a new limit) stored the new want
and active = 0, and the worker's store then set active back to 1: frame_step_cap_ns returned 0 for the kept-out want
until the next poll, up to 500 ms in which nothing limited the game.

The worker now stores the want RTSS holds the game to (active_for, or RTSS_UNSET for none), and rtss_limit_active is
true only while it equals the newest want, so a change of the want stops matching at once and rtss_limit_want no
longer clears anything. The frame count check against the limit keeps its test that the want has not changed.

tests/rtss_worker_check.c gains active_race: the worker polls without pause while the want switches 400000 times
between 60 fps and frame generation, and after each switch to frame generation rtss_limit_active must read 0 until
the worker has seen it. Before the change 128440 switches read 1; after it none do. The other scenarios and a compile
of rtss_limit.c with -Wall pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:15:35 -05:00
parent b0488796a1
commit 07aca0170c
2 changed files with 58 additions and 18 deletions

View File

@@ -190,7 +190,9 @@ DWORD stub_GetCurrentProcessId(void) { return PID; }
// ---- host.h and platform.h, as far as rtss_limit.c uses them
static char logged_lines[1 << 16];
static size_t logged_at;
static int quiet; // the stress scenario: no lines kept or printed
void rt_log(const char *fmt, ...) {
if (quiet) return;
char line[512];
va_list ap;
va_start(ap, fmt);
@@ -221,6 +223,8 @@ int plat_mutex_trylock(PlatMutex *m) { return TryAcquireSRWLockExclusive((PSRWLO
static PlatThreadFn worker_fn;
static volatile LONG spawned;
static volatile LONG free_run; // the worker polls without waiting
static volatile LONG64 polls;
static DWORD WINAPI worker_main(void *arg) {
worker_tid = GetCurrentThreadId();
worker_fn(arg);
@@ -237,6 +241,8 @@ void plat_sleep_ms(uint32_t ms) {
Sleep(ms);
return;
}
InterlockedIncrement64(&polls);
if (free_run) return;
SetEvent(done); // a poll ended
WaitForSingleObject(tick, INFINITE); // the next one starts when the scenario says
}
@@ -389,6 +395,35 @@ static void kept_framegen(void) {
CHECK(!loads && !saves, "kept out, the hooks library is never loaded");
}
// Frame generation switched on while the worker polls without pause: from the switch until the worker sees it, the
// game's limiter paces, never RTSS's hold of the limit before (the worker's store for a want that changed after it
// read it must not count for the new one).
static void active_race(void) {
app_set(1, 0xA, 1000, 2000, 60);
ask(60000);
poll();
CHECK(rtss_limit_active(), "RTSS limits at 60");
quiet = 1, free_run = 1;
SetEvent(tick);
long hits = 0, n = 400000, stuck = 0;
srand(7);
for (long i = 0; i < n && !stuck; i++) {
for (volatile int k = rand() % 200; k > 0; k--) {}
rtss_limit_want(RTSS_OUT_FRAMEGEN);
LONG64 p0 = polls;
int seen = 0;
while (polls < p0 + 2) seen |= rtss_limit_active();
hits += seen;
rtss_limit_want(60000);
ULONGLONG t0 = GetTickCount64();
while (!rtss_limit_active() && !stuck) stuck = GetTickCount64() - t0 > 5000;
}
quiet = 0;
printf(" %ld of %ld switches read RTSS's hold afterwards (worker polls %lld)\n", hits, n, (long long)polls);
CHECK(!stuck, "RTSS did not take the limit back");
CHECK(!hits, "the game's limiter stood aside for a kept-out want %ld times", hits);
}
static const struct { const char *name; void (*run)(void); } scenarios[] = {
{"restore_race", restore_race},
{"restore_player", restore_player},
@@ -398,6 +433,7 @@ static const struct { const char *name; void (*run)(void); } scenarios[] = {
{"kept_two", kept_two},
{"kept_lowlat_then_limit", kept_lowlat_then_limit},
{"kept_framegen", kept_framegen},
{"active_race", active_race},
};
int main(int argc, char **argv) {