Let the game's pacer hold a movie while RivaTuner Statistics Server holds the limit, and keep the play limit in RTSS's profile through it.

During a movie frame_step_cap_ns wanted the movie's rate and returned 0 once RTSS held it, so pace() kept none of the
movie's slots while ocarina_step still gave one movie frame per update: each late frame put the picture behind the
sound for good, the fall-behind d3e50328 fixed for the game's pacer. Each movie start and end also rewrote RTSS's
profile (two saves and two UpdateProfiles per movie in lane A's probe). Now frame_step_cap_ns wants the play limit
through the movie and tells RTSS of the movie (rtss_limit_movie); rtss_pace_period keeps the movie's period from its
first frame, and the worker leaves the movie to the pacer (RTSS_WHY_MOVIE) with the profile as it is. Under a limit
below the movie's rate (30, 40, 45) the profile has no limit for the movie's length (rtss_decide.h rtss_target), since
RTSS at the movie's rate would space out the frames the pacer sends at once to catch up; that is still two writes per
movie there, and none at 60 or more.

Not reproduced before the change. rtss_limit_check (the movie case at 144 and 40, rtss_target, rtss_pace_period),
rtss_worker_check (movie_run, new movie_low_run) and frame_step_check (the want and period through a movie under RTSS)
pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 18:58:47 -05:00
parent 27a034e946
commit 208a10718d
7 changed files with 136 additions and 41 deletions

View File

@@ -17,7 +17,7 @@ uint64_t rt_guest_start_ns;
const char *cfg_get(const char *key) {
if (!strcmp(key, "NX2NAVI_FPS_LIMIT")) return limit;
if (!strcmp(key, "NX2NAVI_STEP_STEADY")) return steady;
if (!strcmp(key, "NX2NAVI_RTSS")) return "0";
if (!strcmp(key, "NX2NAVI_RTSS")) return "1";
return NULL;
}
unsigned cfg_version(void) { return version; }
@@ -38,7 +38,10 @@ static int fg_mult = 1; // frames on screen per game frame
int vk_dlssg_multiplier(void) { return fg_mult; }
int vk_dlssg_active(void) { return fg_mult > 1; }
int vk_lowlat_on(void) { return 0; }
void rtss_limit_want(int64_t millihz) { (void)millihz; }
static int64_t rtss_want; // the newest want (rtss_limit.c)
static int rtss_movie; // the newest movie rate RTSS was told of
void rtss_limit_want(int64_t millihz) { rtss_want = millihz; }
void rtss_limit_movie(int hz) { rtss_movie = hz; }
static int rtss_holds; // RivaTuner Statistics Server holds the game to the want (rtss_limit.c)
static uint64_t kern_ns, hosted; // kern_now_ns, and its time at the newest host present (0: none yet)
int rtss_limit_active(void) { return rtss_holds; }
@@ -303,6 +306,24 @@ int main(int argc, char **argv) {
double hz = 1e9 / (double)frame_step_cap_ns();
CHECK(fabs(hz - cases[i].hz) < 0.01, "%s: paces at %.3f fps, not %.0f", cases[i].what, hz, cases[i].hz);
}
// A movie while RTSS holds 144: RTSS keeps the play limit (no rewrite of its profile at the movie's start and
// end) and the pacer holds the movie's 60 with its slots; at 40 the want stays 40 too (rtss_decide.h rtss_target
// decides what the profile gets).
hosted = kern_ns - 10000000;
static const struct { const char *l; int64_t want; } movies[] = {{"144", 144000}, {"40", 40000}};
for (unsigned i = 0; i < 2; i++) {
set_limit(movies[i].l);
movie = 1;
double hz = 1e9 / (double)frame_step_cap_ns();
CHECK(fabs(hz - 60) < 0.01 && rtss_want == movies[i].want && rtss_movie == 60,
"a movie at a limit of %s under RTSS: paces at %.3f fps, wants %lld, movie %d", movies[i].l, hz,
(long long)rtss_want, rtss_movie);
movie = 0;
hz = 1e9 / (double)frame_step_cap_ns();
CHECK(fabs(hz - 240) < 0.01 && rtss_want == movies[i].want && !rtss_movie,
"after the movie at %s: paces at %.3f fps, wants %lld, movie %d", movies[i].l, hz,
(long long)rtss_want, rtss_movie);
}
rtss_holds = 0, hosted = kern_ns = 0;
}

View File

@@ -151,6 +151,7 @@ typedef struct {
RtssOps ops;
int running, listed;
uint32_t t0, t1, frames;
int64_t movie_mhz; // a movie plays at this rate (rtss_limit_movie)
} Run;
static void run_init(Run *r) {
memset(r, 0, sizeof *r);
@@ -161,7 +162,7 @@ static void run_init(Run *r) {
}
// One poll for want, as rtss_limit.c worker makes it: the hooks library loads on the first poll that wants it and stays.
static RtssOut step_ex(Run *r, int64_t want, int current) {
RtssIn in = {.want = want, .current = current};
RtssIn in = {.want = want, .current = current, .movie_mhz = r->movie_mhz};
in.app = (RtssApp){r->running, r->running && r->listed, r->t0, r->t1, r->frames};
if (r->st.loaded) in.hooks = 1;
else if (rtss_wants_hooks(&r->s, &in)) in.hooks = r->st.no_library ? 0 : (r->st.loaded = 1);
@@ -326,15 +327,39 @@ static void churn(void) {
CHECK(r.st.applies == 11 && r.st.put_backs == 10, "%d writes, %d put backs", r.st.applies, r.st.put_backs);
}
// A movie under RTSS: the want follows the movie's rate, and each start and end is a write.
// A movie under RTSS: the want stays the play limit and the game's pacer holds the movie. At a limit of 144 the profile
// keeps 144 through it, with no write; under the movie's rate (40) the profile has no limit for the movie's length, so
// RTSS cannot space out the frames that catch up after a late one, and gets 40 back at its end.
static void movie(void) {
Run r;
run_init(&r);
step(&r, 144000);
RtssOut o = step(&r, 60000);
CHECK(o.act == RTSS_DO_APPLY && o.holds, "the movie's 60 written");
r.movie_mhz = 60000;
RtssOut o = step(&r, 144000);
CHECK(o.act == RTSS_DO_NOTHING && !o.holds && o.why == RTSS_WHY_MOVIE, "a movie at 144: no write, the pacer's");
for (int i = 0; i < 10; i++) o = step(&r, 144000);
CHECK(!o.holds && o.why == RTSS_WHY_MOVIE && r.st.applies == 1, "through the movie");
char t[128];
rtss_why_text(t, sizeof t, &o, r.s.fail);
CHECK(!strcmp(t, "a movie plays: the game keeps its pictures on time"), "%s", t);
r.movie_mhz = 0;
o = step(&r, 144000);
CHECK(o.act == RTSS_DO_APPLY && o.holds && r.st.applies == 3, "144 written again at its end");
CHECK(o.act == RTSS_DO_NOTHING && o.holds && o.why == RTSS_WHY_HOLDS && r.st.applies == 1, "held again after it");
run_init(&r);
step(&r, 40000);
r.movie_mhz = 60000;
o = step(&r, 40000);
CHECK(o.act == RTSS_DO_APPLY && o.mhz == 0 && !o.holds && o.why == RTSS_WHY_MOVIE && r.st.holds == 0,
"a movie at 40: no limit in the profile");
o = step(&r, 40000);
CHECK(o.act == RTSS_DO_NOTHING && r.st.applies == 2, "once");
r.movie_mhz = 0;
o = step(&r, 40000);
CHECK(o.act == RTSS_DO_APPLY && o.mhz == 40000 && o.holds && r.st.holds == 40000 && r.st.applies == 3,
"40 back at its end");
CHECK(rtss_target(60000, 60000) == 60000 && rtss_target(59940, 60000) == 0 && rtss_target(0, 60000) == 0 &&
rtss_target(144000, 0) == 144000 && rtss_target(RTSS_OUT_LOWLAT, 60000) == RTSS_OUT_LOWLAT,
"rtss_target");
}
// No want yet: nothing at all. The hooks library that does not load fails the run. (A run whose exit put the profile
@@ -384,13 +409,14 @@ static void two(void) {
// otherwise; never 0.
static void pace_period(void) {
const uint64_t p60 = 16666667, ceiling = 4166667, now = 50000000000ull;
CHECK(rtss_pace_period(1, now, now - 10000000, p60, ceiling) == ceiling, "holds, a host present 10 ms ago");
CHECK(rtss_pace_period(1, now, now - RTSS_HOLD_IDLE_NS + 1, p60, ceiling) == ceiling, "just under 200 ms");
CHECK(rtss_pace_period(1, now, now - RTSS_HOLD_IDLE_NS, p60, ceiling) == p60, "200 ms with no host present");
CHECK(rtss_pace_period(1, now, 0, p60, ceiling) == p60, "no host present yet");
CHECK(rtss_pace_period(0, now, now - 10000000, p60, ceiling) == p60, "RTSS does not hold");
CHECK(rtss_pace_period(1, now, now + 1000, p60, ceiling) == ceiling, "a host present stored after now was read");
CHECK(rtss_pace_period(1, now, now - 10000000, ceiling, ceiling) == ceiling, "a limit at the ceiling");
CHECK(rtss_pace_period(1, 0, now, now - 10000000, p60, ceiling) == ceiling, "holds, a host present 10 ms ago");
CHECK(rtss_pace_period(1, 0, now, now - RTSS_HOLD_IDLE_NS + 1, p60, ceiling) == ceiling, "just under 200 ms");
CHECK(rtss_pace_period(1, 0, now, now - RTSS_HOLD_IDLE_NS, p60, ceiling) == p60, "200 ms with no host present");
CHECK(rtss_pace_period(1, 0, now, 0, p60, ceiling) == p60, "no host present yet");
CHECK(rtss_pace_period(0, 0, now, now - 10000000, p60, ceiling) == p60, "RTSS does not hold");
CHECK(rtss_pace_period(1, 0, now, now + 1000, p60, ceiling) == ceiling, "a host present stored after now was read");
CHECK(rtss_pace_period(1, 0, now, now - 10000000, ceiling, ceiling) == ceiling, "a limit at the ceiling");
CHECK(rtss_pace_period(1, 60, now, now - 10000000, p60, ceiling) == p60, "a movie: its period and slots");
}
int main(void) {

View File

@@ -726,19 +726,40 @@ static void churn_run(void) {
CHECK(rtss_limit_active(), "RTSS limits after the last want of a limit");
}
// A movie at 60 under a limit of 144: the want follows the movie, and each start and end is a write.
// A movie at 60 under a limit of 144: the want stays 144 (frame_rate.c frame_step_cap_ns) and RTSS's profile keeps it
// with no write, while the game's pacer holds the movie at its rate; RTSS holds the game again at its end.
static void movie_run(void) {
app_set(1, 0xA, 1000, 2000, 144);
ask(144000);
poll();
long s0 = saves;
ask(60000);
poll();
CHECK(own.limit == 60 && rtss_limit_active(), "RTSS holds the movie's 60");
rtss_limit_movie(60);
ask(144000);
poll();
show("after one movie");
CHECK(own.limit == 144 && saves - s0 == 2, "two writes for one movie");
show("a movie at 60");
CHECK(own.limit == 144 && !rtss_limit_active() && saves == s0, "the profile keeps 144; the game's pacer holds it");
CHECK(logged("the game's own limiter (a movie plays: the game keeps its pictures on time)"), "logged");
rtss_limit_movie(0);
poll();
show("after the movie");
CHECK(own.limit == 144 && rtss_limit_active() && saves == s0, "RTSS holds again, no write for the movie");
}
// The same under a limit of 40: the profile has no limit while the movie plays, so RTSS cannot space out the frames the
// pacer sends at once after a late one, and gets 40 back at its end.
static void movie_low_run(void) {
app_set(1, 0xA, 1000, 2000, 40);
ask(40000);
poll();
long s0 = saves;
rtss_limit_movie(60);
poll();
show("a movie at 60 with the limit at 40");
CHECK(own.exists && own.limit == 0 && !rtss_limit_active(), "no limit in the profile during the movie");
rtss_limit_movie(0);
poll();
show("after the movie");
CHECK(own.limit == 40 && rtss_limit_active() && saves - s0 == 2, "40 back: two writes for the movie");
}
static const struct { const char *name; void (*run)(void); } scenarios[] = {
@@ -768,6 +789,7 @@ static const struct { const char *name; void (*run)(void); } scenarios[] = {
{"library_run", library_run},
{"churn_run", churn_run},
{"movie_run", movie_run},
{"movie_low_run", movie_low_run},
};
int main(int argc, char **argv) {