Measure the overlay's frame times where the pictures go out, and keep an early picture back to seven eighths of the recent interval.

The overlay's rate, lows and graph were fed from the game's present calls. With the replay on the submitting thread, work held for an event is replayed with the next frame, so the calls come in uneven steps although each frame costs about the same: 36 and 9 ms apart in turn in a village, a sawtooth in the graph and a 1% low of 14 fps, while the pictures went out 19.7 ms apart on average and changed by 3.9 ms from one to the next. The present thread now reports each picture (perfmon_shown) and the overlay takes its intervals from that; the game's calls are used only where no present thread reports.

A picture that arrives early now waits until seven eighths of the recent interval have passed since the one before (vk_backend.c pace_smooth, NX2NAVI_PACE_SMOOTH, on by default; not with frame generation). In that village the change from one picture to the next went from 3.9 to 3.0 ms at 51 fps both ways, in a graveyard from 3.1 to 2.6 ms at 54.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
epicmeme546
2026-11-10 06:35:28 -05:00
parent 7e23e7309b
commit a710c6193d
5 changed files with 70 additions and 3 deletions

View File

@@ -43,9 +43,42 @@ static struct {
int64_t up0, up;
} g_win;
// The frame times the overlay shows (the rate, the lows, the graph) are those of the pictures as they go out: the
// present thread reports each one (perfmon_shown). The game's present calls come at other times: with the replay on
// the submitting thread, work held for an event is replayed in the next frame's first submission, so the calls came
// 36 and 9 ms apart in turn in a village while the pictures went out every 17 to 27 ms, and the graph drew a sawtooth
// the screen did not show. A frame held back (vk_backend.c frame_hold) is not shown and lengthens its interval.
// Without a present thread reporting (another back end) the game's present calls are taken, as before.
static uint64_t g_shown_last; // when the last picture went out; 0: none yet
static uint64_t g_shown_report; // when perfmon_shown last ran: perfmon_frame leaves the intervals to it for a second
static void interval_add(uint64_t now, uint64_t interval_ns) { // (lock held)
g_ring[g_ring_pos] = (float)(interval_ns / 1e6);
g_ring_at[g_ring_pos] = now;
g_ring_pos = (g_ring_pos + 1) % PERF_HISTORY;
if (g_ring_n < PERF_HISTORY) g_ring_n++;
if (now - g_low_t0 >= 1000000000ull) { // the next second: its slice starts empty
g_low_cur = (g_low_cur + 1) % LOW_SLICES;
memset(g_low_hist[g_low_cur], 0, sizeof g_low_hist[0]);
g_low_t0 = now;
}
uint64_t bin = interval_ns / 250000ull;
uint16_t *h = &g_low_hist[g_low_cur][bin < LOW_BINS ? bin : LOW_BINS - 1];
if (*h < 65535) (*h)++;
}
void perfmon_shown(uint64_t now) {
plat_mutex_lock(&g_lock);
// a gap of a second or more is a load or a pause, not a frame time
if (g_shown_last && now > g_shown_last && now - g_shown_last < 1000000000ull) interval_add(now, now - g_shown_last);
g_shown_last = g_shown_report = now;
plat_mutex_unlock(&g_lock);
}
void perfmon_frame(uint64_t now, uint64_t interval_ns, const uint64_t *wait_ns, uint64_t replay_ns,
int64_t tex_uploads) {
plat_mutex_lock(&g_lock);
if (g_shown_report && now - g_shown_report < 1000000000ull) interval_ns = 0; // perfmon_shown has them
if (interval_ns) {
g_ring[g_ring_pos] = (float)(interval_ns / 1e6);
g_ring_at[g_ring_pos] = now;