mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 19:39:57 -04:00
Time the hand-off to the present thread, the present call and other threads' acquire waits, and count the acquire's GPU wait once.
The perf lines could not see pacing. In the 0.10.0 fresh session (nx2navi.1.log, 7,974,927 bytes) all 666 windows read "pacing 0%" and "bound: cpu" and all 70 slow-frame lines "pacing 0.0 drain 0.0", while 610 windows had a 16.x ms interval at fps_limit 60 under the game's own limiter. The pacer's wait happened where perf does not count it: vk_backend.c present_image's wait for the present thread to take the previous picture was untimed, perf_end drops waits on any thread but the presenting and replay ones (a game may acquire its window image on another), and the acquire's GPU wait was counted twice, as pacing around b->fence_wait and as a fence wait inside vk_sync_fence_wait (F-7-04). - host.h: PERF_HANDOFF, the presenting thread's wait to hand the present thread the next picture, timed in present_image from under pl (where pending is read) and kept in PresentJob.handoff_ns. perf_end_any counts a wait on any other guest thread into a sum that perf_present adds to the frame before ft_frame reads its parts. - nvn_api_obj.c nvnWindowAcquireTexture: the pacer's sleep is timed with perf_end_any; the GPU wait counts only as the fence wait it is; one line names the threads that acquire and present once the first present is known. - vk_backend.c present_main: the TRACE=present line adds the present call's time (vkQueuePresentKHR, under the queue lock, where an overlay's frame limiter sleeps) and the job's hand-off wait; with trace=perf, a line per 60 presents gives the present thread's blit and submit, paced wait, present call (avg, max), time past target and the hand-off. - perf.c: "handoff" in the window line's shares and the slow-frame line, "hand-off" in the worst-frame lines and as a cause of its own for frames over 25 ms and the stutter map. The "bound:" rule stays as it is until play-test numbers exist. - The cause list changes together: perf.c FT_C_* and ft_cause_name, stutter_map.c SM_CAUSES and cause_short, tests/stutter_hitch_check.c names[] (now sized from SM_CAUSES), and tools/stutter_map.py, whose cause and hitch patterns now take a hyphen. flight.c's frames.tsv gets a handoff_ms column (blocked_names checked against PERF_N), and tools/flight_view.py lists it. - tools/perf_summary.py reads the hand-off share, the present-thread lines and the TRACE=present lines, and prints percentiles of the present interval, paced wait, time past target, present call and hand-off. New tests/perf_summary_check.py makes lines with the runtime's format strings (checked against the C sources) and checks the percentiles, the window averages and the hand-off share, and that older lines without these fields still parse; tests/stutter_map_check.py gets a hand-off hitch and area cause, which the old patterns dropped. Diagnostics only: no wait, pacing or presentation change. Not reproduced before the change (it needs a game run with trace=perf). perf_summary_check, stutter_map_check, stutter_hitch_check, flight_flash_check and frame_step_check pass; every runtime file compiles with the dev flags after the host.h change, and the changed files add no -Wall -Wextra warnings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -32,7 +32,9 @@
|
||||
|
||||
// Record columns after frame, time and interval: blocked time per PERF_* kind (us), then the counts.
|
||||
enum { C_SUBMITS, C_PASSES, C_DRAWS, C_DRAWS_SEEN, C_CLEARS, C_COPIES, C_DISPATCHES, C_XLATED, C_PERF0, C_N = C_PERF0 + PERF_CNT_N };
|
||||
static const char *const blocked_names[PERF_N] = {"pace_ms", "fence_ms", "drain_ms", "pipe_ms", "xlate_ms", "tex_ms", "astc_ms"};
|
||||
static const char *const blocked_names[] = {"pace_ms", "fence_ms", "drain_ms", "pipe_ms", "xlate_ms", "tex_ms", "astc_ms",
|
||||
"handoff_ms"};
|
||||
_Static_assert(sizeof blocked_names / sizeof *blocked_names == PERF_N, "blocked_names follows the PERF_* list (host.h)");
|
||||
static const char *const count_names[C_N] = {
|
||||
"submits", "passes", "draws", "draws_seen", "clears", "copies", "dispatches", "shaders_xlated",
|
||||
// PERF_CNT_* order (host.h)
|
||||
|
||||
@@ -28,12 +28,17 @@ enum { RT_TRACE_SVC = 1, RT_TRACE_HOSTCALL = 2, RT_TRACE_IPC = 4, RT_TRACE_FS =
|
||||
RT_TRACE_SCHED = 64, RT_TRACE_AUDIO = 128, RT_TRACE_PRESENT = 256 };
|
||||
extern unsigned rt_trace; // from NX2NAVI_TRACE=svc,host,ipc,fs,gfx,perf,sched,audio,present (or all)
|
||||
// prof_win.c: NX2NAVI_PROFILE=<path> sampling profiler; NX2NAVI_TRACE=perf frame timing (waits of the render thread)
|
||||
// PERF_TEX: texture uploads on the render thread (deswizzle, decode, staging), PERF_ASTC included
|
||||
enum { PERF_PACE, PERF_FENCE, PERF_DRAIN, PERF_PIPE, PERF_XLATE, PERF_TEX, PERF_ASTC, PERF_N };
|
||||
// PERF_TEX: texture uploads on the render thread (deswizzle, decode, staging), PERF_ASTC included. PERF_HANDOFF: the
|
||||
// presenting thread's wait for the present thread to take the previous picture (vk_backend.c present_image), which is
|
||||
// where the present thread's own pacing and a slow present call (an overlay's frame limiter inside it) hold the game.
|
||||
enum { PERF_PACE, PERF_FENCE, PERF_DRAIN, PERF_PIPE, PERF_XLATE, PERF_TEX, PERF_ASTC, PERF_HANDOFF, PERF_N };
|
||||
void prof_start(void);
|
||||
void prof_write(void); // idempotent; boot.c calls it before _exit
|
||||
uint64_t perf_begin(void); // start time of a wait; pair with perf_end
|
||||
void perf_end(int kind, uint64_t t0); // counts render-thread time only
|
||||
// The same for a wait that may run on any guest thread (the game's image acquire): the render and replay threads' as
|
||||
// perf_end, any other thread's added to the next present's frame (perf_present).
|
||||
void perf_end_any(int kind, uint64_t t0);
|
||||
void perf_replay(uint64_t t0); // replay (NVN -> Vulkan recording) time on any thread, waits inside it included
|
||||
void perf_replay_thread(void); // the calling thread replays for the render thread: perf_end counts its waits
|
||||
void perf_main_thread(void); // the calling thread is the guest main thread (NX2NAVI_PROFILE_MAIN)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "nvn_api.h"
|
||||
#include "nvn_hmap.h"
|
||||
#include "nvn_tex.h"
|
||||
#include "prof.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
// ---------- Descriptor pools
|
||||
@@ -827,11 +828,19 @@ NVN_API(nvnWindowAcquireTexture) {
|
||||
NVN_BLOCKING();
|
||||
int idx = o->active ? o->next++ % o->active : 0;
|
||||
*out = idx;
|
||||
// The frame timing's waits count on the presenting thread (perf.c perf_end); a game may acquire on another, whose
|
||||
// wait here perf_end_any adds to the next present. One line names both threads once the first present is known.
|
||||
static volatile int32_t named;
|
||||
if (prof_render_tid && !named && !plat_xchg32(&named, 1)) {
|
||||
uint32_t tid = plat_thread_id();
|
||||
rt_log("nvn: the game acquires its window images on thread %u and presents on thread %u%s", tid,
|
||||
prof_render_tid, tid == prof_render_tid ? "" : ": the acquire's waits count for the next present");
|
||||
}
|
||||
uint64_t at = idx < 4 ? o->avail[idx] : 0;
|
||||
if (at) {
|
||||
uint64_t p0 = perf_begin();
|
||||
sleep_until(at);
|
||||
perf_end(PERF_PACE, p0);
|
||||
perf_end_any(PERF_PACE, p0);
|
||||
}
|
||||
// On the Switch the image comes back only after the display has shown it, which needs the GPU to have finished the
|
||||
// frame drawn into it, so the CPU never runs more than the swapchain's depth ahead of the GPU. Here the pacer frees
|
||||
@@ -846,13 +855,9 @@ NVN_API(nvnWindowAcquireTexture) {
|
||||
}
|
||||
uint64_t *fe = img_fence_of(o, idx), want = fe ? *fe : 0;
|
||||
if (acq_wait == 2) want = last_present_fence;
|
||||
if (acq_wait && want) {
|
||||
if (acq_wait && want) { // the back end's wait counts it as a fence wait (vk_sync.c vk_sync_fence_wait), not pacing
|
||||
const GfxBackend *b = gfx_backend();
|
||||
if (b->fence_done() < want) {
|
||||
uint64_t p0 = perf_begin();
|
||||
b->fence_wait(want, UINT64_MAX);
|
||||
perf_end(PERF_PACE, p0);
|
||||
}
|
||||
if (b->fence_done() < want) b->fence_wait(want, UINT64_MAX);
|
||||
}
|
||||
if (gfx_backend()->frame_start) gfx_backend()->frame_start(); // the frame's work starts here
|
||||
// The sync means "the display no longer reads this image". Presents are copies queued in submit order, so it is
|
||||
|
||||
@@ -98,6 +98,22 @@ void perf_end(int kind, uint64_t t0) {
|
||||
__atomic_fetch_add(&frame_ns[kind], d, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
// The waits of other threads that hold the frame all the same: a game may acquire its window image on a thread other
|
||||
// than the one that presents (vk_lowlat.c's comments note it), and perf_end leaves those waits out, so the pacer's
|
||||
// wait in the acquire showed nowhere. Added to frame_ns and wait_ns by the present (perf_present) before the frame's
|
||||
// parts are read.
|
||||
static volatile int64_t any_ns[PERF_N];
|
||||
|
||||
void perf_end_any(int kind, uint64_t t0) {
|
||||
if (!t0 || (unsigned)kind >= PERF_N) return;
|
||||
uint32_t tid = plat_thread_id();
|
||||
if (tid == prof_render_tid || tid == prof_replay_tid) {
|
||||
perf_end(kind, t0);
|
||||
return;
|
||||
}
|
||||
plat_add64(&any_ns[kind], (int64_t)(kern_now_ns() - t0));
|
||||
}
|
||||
|
||||
static volatile int64_t other_wait_ns; // perf_gpu_wait on threads other than the render thread, over the window
|
||||
static volatile int64_t render_wait_ns; // the same on the render thread
|
||||
void (*perf_gpu_stats)(PerfGpu *out);
|
||||
@@ -454,10 +470,12 @@ typedef struct {
|
||||
// them in, every frame that waited 900 ms for a pipeline was charged to "replay", the larger number, and a log
|
||||
// could not tell a pipeline stall from a slow replay.
|
||||
// "census" is the address-space walk of NX2NAVI_MEM_CENSUS (census_check), which runs on the presenting thread after a
|
||||
// present: its time is charged to the next frame, which it delays.
|
||||
enum { FT_C_PIPE, FT_C_XLATE, FT_C_TEX, FT_C_FENCE, FT_C_PACE, FT_C_REPLAY, FT_C_CENSUS, FT_C_OTHER, FT_C_N };
|
||||
static const char *const ft_cause_name[FT_C_N] = { "pipeline", "translation", "texture", "fence", "pacing", "replay",
|
||||
"census", "unattributed" };
|
||||
// present: its time is charged to the next frame, which it delays. "hand-off" is the wait for the present thread to
|
||||
// take the previous picture (PERF_HANDOFF): its own pacing and its present call, an overlay's frame limiter included.
|
||||
// stutter_map.c cause_short and tools/stutter_map.py read these names, in this order.
|
||||
enum { FT_C_PIPE, FT_C_XLATE, FT_C_TEX, FT_C_FENCE, FT_C_PACE, FT_C_HANDOFF, FT_C_REPLAY, FT_C_CENSUS, FT_C_OTHER, FT_C_N };
|
||||
static const char *const ft_cause_name[FT_C_N] = { "pipeline", "translation", "texture", "fence", "pacing", "hand-off",
|
||||
"replay", "census", "unattributed" };
|
||||
static uint64_t census_part_ns; // present thread: the census walks since the last present (census_check)
|
||||
static struct {
|
||||
uint64_t t0, frames, sum, over25, over50, over100;
|
||||
@@ -647,10 +665,11 @@ static void ft_report(uint64_t now, const char *tag) {
|
||||
(unsigned long long)w->op_n[PERF_RP_DRAW], w->op_ns[PERF_RP_BIND] / 1e6,
|
||||
(unsigned long long)w->op_n[PERF_RP_BIND], w->op_ns[PERF_RP_XFER] / 1e6,
|
||||
(unsigned long long)w->op_n[PERF_RP_XFER], nvn_op_name(w->max_op), w->max_ns / 1e6, w->hold_ns / 1e6);
|
||||
rt_log("frametime: worst frame %llu: %.1f ms; shader translation %.1f, pipeline build %.1f, texture upload %.1f (astc %.1f), replay %.1f (on the CPU %.1f), fence/present wait %.1f, pacing %.1f%s",
|
||||
rt_log("frametime: worst frame %llu: %.1f ms; shader translation %.1f, pipeline build %.1f, texture upload %.1f (astc %.1f), replay %.1f (on the CPU %.1f), fence/present wait %.1f, pacing %.1f, hand-off %.1f%s",
|
||||
(unsigned long long)w->frame, w->ns / 1e6, w->wait[PERF_XLATE] / 1e6, w->wait[PERF_PIPE] / 1e6,
|
||||
w->wait[PERF_TEX] / 1e6, w->wait[PERF_ASTC] / 1e6, w->replay / 1e6, w->replay_cpu / 1e6,
|
||||
(w->wait[PERF_FENCE] + w->wait[PERF_DRAIN]) / 1e6, w->wait[PERF_PACE] / 1e6, ops);
|
||||
(w->wait[PERF_FENCE] + w->wait[PERF_DRAIN]) / 1e6, w->wait[PERF_PACE] / 1e6,
|
||||
w->wait[PERF_HANDOFF] / 1e6, ops);
|
||||
}
|
||||
}
|
||||
memset(&ft, 0, sizeof ft);
|
||||
@@ -741,6 +760,7 @@ static uint64_t ft_frame(uint64_t frame, uint64_t now, uint64_t d) {
|
||||
part[FT_C_TEX] = frame_ns[PERF_TEX];
|
||||
part[FT_C_FENCE] = frame_ns[PERF_FENCE] + frame_ns[PERF_DRAIN];
|
||||
part[FT_C_PACE] = frame_ns[PERF_PACE];
|
||||
part[FT_C_HANDOFF] = frame_ns[PERF_HANDOFF];
|
||||
part[FT_C_REPLAY] = rep > 0 ? (uint64_t)rep : 0;
|
||||
uint64_t inside = part[FT_C_PIPE] + part[FT_C_XLATE] + part[FT_C_TEX]; // waits on the replay thread
|
||||
part[FT_C_REPLAY] = part[FT_C_REPLAY] > inside ? part[FT_C_REPLAY] - inside : 0;
|
||||
@@ -997,6 +1017,10 @@ void perf_present(uint64_t frame) {
|
||||
if (rt_trace & RT_TRACE_SCHED) kern_sched_report(frame);
|
||||
uint64_t now = kern_now_ns(), d = last ? now - last : 0;
|
||||
prof_sampler_frame(frame, now, last ? d : 0);
|
||||
for (int k = 0; k < PERF_N; k++) { // other threads' waits for this frame (perf_end_any), before its parts are read
|
||||
int64_t a = __atomic_load_n(&any_ns[k], __ATOMIC_RELAXED) ? plat_xchg64(&any_ns[k], 0) : 0;
|
||||
if (a > 0) __atomic_fetch_add(&frame_ns[k], (uint64_t)a, __ATOMIC_RELAXED), __atomic_fetch_add(&wait_ns[k], (uint64_t)a, __ATOMIC_RELAXED);
|
||||
}
|
||||
uint64_t rep = ft_frame(frame, now, d); // d is 0 on the first present: it only starts the period
|
||||
if (__atomic_load_n(&session_due, __ATOMIC_RELAXED) && plat_xchg32(&session_due, 0)) session_report(now);
|
||||
ab_b += rt_ab();
|
||||
@@ -1035,13 +1059,14 @@ void perf_present(uint64_t frame) {
|
||||
char marks[700];
|
||||
marks[0] = 0;
|
||||
mark_text(&fm, marks, 0, sizeof marks);
|
||||
// drain: the wait for the present thread's previous job; replay: the replays since the last present, the
|
||||
// pipeline, translation and texture waits above included (the rest of a slow frame is the game's own work)
|
||||
// drain: the wait for the present thread's previous job; handoff: the wait to hand it the next one;
|
||||
// replay: the replays since the last present, the pipeline, translation and texture waits above included
|
||||
// (the rest of a slow frame is the game's own work)
|
||||
rt_log("perf: slow frame %llu: %.1f ms; blocked pipeline %.1f xlate %.1f texture %.1f astc %.1f fence %.1f pacing %.1f "
|
||||
"drain %.1f; replay %.1f%s",
|
||||
"drain %.1f handoff %.1f; replay %.1f%s",
|
||||
(unsigned long long)frame, d / 1e6, frame_ns[PERF_PIPE] / 1e6, frame_ns[PERF_XLATE] / 1e6,
|
||||
frame_ns[PERF_TEX] / 1e6, frame_ns[PERF_ASTC] / 1e6, frame_ns[PERF_FENCE] / 1e6,
|
||||
frame_ns[PERF_PACE] / 1e6, frame_ns[PERF_DRAIN] / 1e6, rep / 1e6, marks);
|
||||
frame_ns[PERF_PACE] / 1e6, frame_ns[PERF_DRAIN] / 1e6, frame_ns[PERF_HANDOFF] / 1e6, rep / 1e6, marks);
|
||||
}
|
||||
}
|
||||
memset(frame_ns, 0, sizeof frame_ns);
|
||||
@@ -1065,9 +1090,9 @@ void perf_present(uint64_t frame) {
|
||||
uint64_t dwin[3];
|
||||
for (int i = 0; i < 3; i++) dwin[i] = disk[i] - disk_prev[i], disk_prev[i] = disk[i];
|
||||
if (n && span)
|
||||
rt_log("perf: frame %llu: interval avg %.2f ms max %.2f ms (%.1f fps); render thread blocked: pacing %.0f%% fence %.0f%% drain %.0f%% pipeline build %.0f%% shader xlate %.0f%% texture %.0f%% (astc %.0f%%); pipelines built in background %lld, draws skipped pending %lld, waited %lld, waiting for a shader %lld, one-shot waited %lld; textures uploaded %lld re-uploaded %lld; slowest frame: xlate %.1f ms texture %.1f ms (astc %.1f) pipeline %.1f ms fence %.1f ms; shaders: %llu keys, %llu translated; render busy avg %.2f ms; replay avg %.2f ms; ab %llu/%llu; world %.1f s; shader disk reads: %llu on the render thread (%.1f ms), %llu by the loaders",
|
||||
rt_log("perf: frame %llu: interval avg %.2f ms max %.2f ms (%.1f fps); render thread blocked: pacing %.0f%% fence %.0f%% drain %.0f%% handoff %.0f%% pipeline build %.0f%% shader xlate %.0f%% texture %.0f%% (astc %.0f%%); pipelines built in background %lld, draws skipped pending %lld, waited %lld, waiting for a shader %lld, one-shot waited %lld; textures uploaded %lld re-uploaded %lld; slowest frame: xlate %.1f ms texture %.1f ms (astc %.1f) pipeline %.1f ms fence %.1f ms; shaders: %llu keys, %llu translated; render busy avg %.2f ms; replay avg %.2f ms; ab %llu/%llu; world %.1f s; shader disk reads: %llu on the render thread (%.1f ms), %llu by the loaders",
|
||||
(unsigned long long)frame, sum / 1e6 / n, max / 1e6, n * 1e9 / sum, 100.0 * wait_ns[PERF_PACE] / span,
|
||||
100.0 * wait_ns[PERF_FENCE] / span, 100.0 * wait_ns[PERF_DRAIN] / span,
|
||||
100.0 * wait_ns[PERF_FENCE] / span, 100.0 * wait_ns[PERF_DRAIN] / span, 100.0 * wait_ns[PERF_HANDOFF] / span,
|
||||
100.0 * wait_ns[PERF_PIPE] / span, 100.0 * wait_ns[PERF_XLATE] / span,
|
||||
100.0 * wait_ns[PERF_TEX] / span, 100.0 * wait_ns[PERF_ASTC] / span, (long long)async, (long long)skips, (long long)waited, (long long)sskip, (long long)oneshot,
|
||||
(long long)up, (long long)reup, worst_ns[PERF_XLATE] / 1e6, worst_ns[PERF_TEX] / 1e6,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
// 96 ms after an area load (2026-11-13) each counted as a change of pace before, as each was followed by one as long.
|
||||
//
|
||||
// What a hitch went to comes from the frame-time summary's split (perf.c ft_frame: pipeline, translation, texture,
|
||||
// fence, pacing, replay, unattributed), with the draws that met a pipeline or a shader missing between the previous
|
||||
// fence, pacing, hand-off, replay, census, unattributed), with the draws that met a pipeline or a shader missing between the previous
|
||||
// present and this one (stutter_miss, from the replay thread). Each hitch gets a "stutter:" line, at most
|
||||
// SM_LINES_PER_S a second and SM_LINES_MAX in all; the counts go on past that. Every SM_REPORT_NS of play, when the
|
||||
// window loses the focus in play (perf.c session_report) and at exit,
|
||||
@@ -42,7 +42,7 @@
|
||||
int stutter_map_on;
|
||||
|
||||
#define SM_AREAS 128 // areas kept by name; later ones share the last slot
|
||||
#define SM_CAUSES 8
|
||||
#define SM_CAUSES 9 // perf.c's FT_C_N
|
||||
#define SM_LOAD_NS 3000000000ull // after an area load, frames count as the load's for this long
|
||||
#define SM_HITCH_MIN_NS 12000000.0 // a hitch is at least this long...
|
||||
#define SM_HITCH_ANY_NS 25000000ull // ...and any frame over this is one
|
||||
@@ -364,9 +364,10 @@ void stutter_frame(uint64_t frame, uint64_t now, uint64_t d, const uint64_t *par
|
||||
}
|
||||
}
|
||||
|
||||
// In the order of perf.c's causes (FT_C_*); "census" is NX2NAVI_MEM_CENSUS's walk of the address space.
|
||||
static const char *const cause_short[SM_CAUSES] = {"pipeline", "translation", "texture", "fence", "pacing", "replay",
|
||||
"census", "unattributed"};
|
||||
// In the order of perf.c's causes (FT_C_*); "hand-off" is the wait for the present thread to take the previous picture,
|
||||
// "census" NX2NAVI_MEM_CENSUS's walk of the address space.
|
||||
static const char *const cause_short[SM_CAUSES] = {"pipeline", "translation", "texture", "fence", "pacing", "hand-off",
|
||||
"replay", "census", "unattributed"};
|
||||
|
||||
static int area_cmp(const void *x, const void *y) {
|
||||
const Area *a = &areas[*(const int *)x], *b = &areas[*(const int *)y];
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
|
||||
#define WEAK __attribute__((weak))
|
||||
|
||||
typedef struct { VkImage image; VkFormat format; int w, h, has_crop, crop[4]; uint64_t frame, at, queued, value; } PresentJob;
|
||||
// handoff_ns: how long the presenting thread waited to hand this job over (present_image), for the present lines
|
||||
typedef struct { VkImage image; VkFormat format; int w, h, has_crop, crop[4]; uint64_t frame, at, queued, value, handoff_ns; } PresentJob;
|
||||
|
||||
static PlatMutex pl = PLAT_MUTEX_INIT;
|
||||
static PlatCond pcv = PLAT_COND_INIT; // job queued, job taken, job submitted
|
||||
@@ -76,9 +77,31 @@ static void pace_shown(uint64_t interval_ns) {
|
||||
pace_avg_ns = pace_avg_ns ? pace_avg_ns + (uint64_t)(((int64_t)interval_ns - (int64_t)pace_avg_ns) / 4) : interval_ns;
|
||||
}
|
||||
|
||||
// NX2NAVI_TRACE=perf: the present thread's own window of PW_PRESENTS presents. The render thread's perf lines time the
|
||||
// game's side and the hand-off; these say where the present thread's time went: the blit and its submission, the
|
||||
// wait for the picture's time (pace_smooth), and the present call, which takes the queue lock and in which an overlay
|
||||
// with a frame limiter sleeps. With the presenting thread's wait to hand each picture over, which that time causes.
|
||||
#define PW_PRESENTS 60
|
||||
typedef struct { uint64_t n, blit, wait, call, call_max, past, hand, hand_max; } PresentWin;
|
||||
|
||||
static void present_window(PresentWin *w, uint64_t frame, uint64_t blit, uint64_t wait, uint64_t call, uint64_t past,
|
||||
uint64_t hand) {
|
||||
w->n++, w->blit += blit, w->wait += wait, w->call += call, w->past += past, w->hand += hand;
|
||||
if (call > w->call_max) w->call_max = call;
|
||||
if (hand > w->hand_max) w->hand_max = hand;
|
||||
if (w->n < PW_PRESENTS) return;
|
||||
double n = (double)w->n;
|
||||
rt_log("perf: present thread frame %llu: %llu presents; blit and submit avg %.2f ms, paced wait avg %.2f ms, present "
|
||||
"call avg %.2f ms max %.2f ms, past target avg %.2f ms; the presenting thread waited to hand over avg %.2f ms "
|
||||
"max %.2f ms", (unsigned long long)frame, (unsigned long long)w->n, w->blit / 1e6 / n, w->wait / 1e6 / n,
|
||||
w->call / 1e6 / n, w->call_max / 1e6, w->past / 1e6 / n, w->hand / 1e6 / n, w->hand_max / 1e6);
|
||||
memset(w, 0, sizeof *w);
|
||||
}
|
||||
|
||||
static void present_main(void *arg) {
|
||||
(void)arg;
|
||||
uint64_t last = 0, last_queued = 0;
|
||||
PresentWin win = {0};
|
||||
plat_mutex_lock(&pl);
|
||||
for (;;) {
|
||||
while (!pending) plat_cond_wait(&pcv, &pl);
|
||||
@@ -87,6 +110,8 @@ static void present_main(void *arg) {
|
||||
busy = 1;
|
||||
plat_cond_broadcast(&pcv);
|
||||
plat_mutex_unlock(&pl);
|
||||
int timed = (rt_trace & (RT_TRACE_PRESENT | RT_TRACE_PERF)) != 0;
|
||||
uint64_t b0 = timed ? kern_now_ns() : 0;
|
||||
if (flight_on || vk_dump_white) vk_thumbs_frame(j.frame); // NX2NAVI_DUMP_WHITE reads them too
|
||||
vk_dlssg_present_frame(j.frame);
|
||||
vk_lowlat_present_frame(j.frame); // the frame's number for the blit's submit and the present's markers
|
||||
@@ -104,14 +129,18 @@ static void present_main(void *arg) {
|
||||
uint64_t t1 = kern_now_ns();
|
||||
if (last) pace_shown(t1 - last);
|
||||
vk_present_flip();
|
||||
uint64_t t2 = timed ? kern_now_ns() : 0;
|
||||
perfmon_shown(t1); // the overlay's frame times: the pictures as shown
|
||||
// NX2NAVI_TRACE=present: one line per present: the host present's interval, the interval of the game's present
|
||||
// calls (when the host present went out before back-edge pacing), the wait and how far past its target it went
|
||||
// calls (when the host present went out before back-edge pacing), the wait and how far past its target it went;
|
||||
// then how long the present call took and how long the presenting thread waited to hand this picture over
|
||||
if (rt_trace & RT_TRACE_PRESENT)
|
||||
rt_log("present: frame %llu interval %.3f ms, game %.3f ms, waited %.3f ms, %.3f ms past target",
|
||||
(unsigned long long)j.frame, last ? (t1 - last) / 1e6 : 0.0,
|
||||
rt_log("present: frame %llu interval %.3f ms, game %.3f ms, waited %.3f ms, %.3f ms past target; present call "
|
||||
"%.3f ms, hand-off %.3f ms", (unsigned long long)j.frame, last ? (t1 - last) / 1e6 : 0.0,
|
||||
last_queued ? (j.queued - last_queued) / 1e6 : 0.0, (t1 - t0) / 1e6,
|
||||
j.at && t1 > j.at ? (t1 - j.at) / 1e6 : 0.0);
|
||||
j.at && t1 > j.at ? (t1 - j.at) / 1e6 : 0.0, (t2 - t1) / 1e6, j.handoff_ns / 1e6);
|
||||
if (rt_trace & RT_TRACE_PERF)
|
||||
present_window(&win, j.frame, t0 - b0, t1 - t0, t2 - t1, j.at && t1 > j.at ? t1 - j.at : 0, j.handoff_ns);
|
||||
last = t1;
|
||||
last_queued = j.queued;
|
||||
vk_pipeline_autosave(); // starts the autosave thread once
|
||||
@@ -258,11 +287,16 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin
|
||||
if (!plat_thread_spawn(present_main, NULL, "vk present", 0)) rt_fatal("vk: cannot start the present thread");
|
||||
present_thread = 1;
|
||||
}
|
||||
while (pending) plat_cond_wait(&pcv, &pl); // one present in waiting at most
|
||||
// One present in waiting at most: the wait for the present thread to take the previous one is the hand-off
|
||||
// (PERF_HANDOFF), timed from under pl, where pending is read.
|
||||
uint64_t h0 = pending ? perf_begin() : 0;
|
||||
while (pending) plat_cond_wait(&pcv, &pl);
|
||||
j.handoff_ns = h0 ? kern_now_ns() - h0 : 0;
|
||||
job = j;
|
||||
pending = 1;
|
||||
plat_cond_broadcast(&pcv);
|
||||
plat_mutex_unlock(&pl);
|
||||
perf_end(PERF_HANDOFF, h0);
|
||||
if (rdoc_active()) { vk_present_drain(); rdoc_after_present(frame); }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user