mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 04:19:57 -04:00
Test an event wait against the value the event had when the submission took its copies, so a frame is no longer drawn from data the game had not finished writing.
Each frame the game sets one of two events to 0 from the CPU, submits its worker queues and the main queue, whose first command waits for that event to be 1, and signals 1 with nvnEventSignal once it has written what the frame's commands read. The recording of a submission takes the VRAM mirror sync and the uniform snapshot at its start and tested the wait a moment later, so a signal that arrived in between passed the wait and the frame was drawn from copies taken before the signal: single frames with the whole scene's shadowing missing (6 to 7 of 255 brighter, the sky and the interface unchanged) or a black scene, more of them the busier the CPU. Every nvnEventSignal is now numbered and keeps the value it replaced, the recording notes the number before it takes its copies, and a signal with a later number does not count for that submission. The submission stops at the wait like any wait reached before its signal and goes on at once in a submission of its own, whose copies are taken after the signal. NX2NAVI_EVENT_AT_SYNC=0 gives the earlier test. NX2NAVI_EVO_TRACE=1 logs the order in which every frame's submissions, waits and signals were replayed, which is how the frames were found. Measured with the flight recorder's thumbnails, 1,800 presented frames a run, standing in Hyrule Field by day with the lazy write-back on, DLSS Performance, frame generation 4x and HDR: the build before this change showed 34 single-frame spikes with eight busy threads beside the game, 20 with four and 8 with six, most of them in frames whose signal came during the replay; with this change two runs with eight busy threads showed 0 and 0, with 667 and 724 such frames. A session of the user's with the lazy write-back off ran 25,200 frames without a spike in its three automatic dumps while the change stopped 4,744 wait tests. Not measured: runs of this same build with the switch off (the two tried failed for other reasons, a device loss during the boot beside another game and a load with cold caches), any run with the lazy write-back off under load, the frame rate and GPU time against the switch off, and the differential tests, which this change does not touch. The flicker with the lazy write-back off that was reported has not been reproduced in a capture; its mechanism is the same signal and occurs there too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -976,6 +976,82 @@ int vk_exec_held(void) { return evo_pending; }
|
||||
|
||||
static const op_hdr *walk(VkExec *ex, const op_hdr *h, int depth);
|
||||
|
||||
// ---- event order trace (NX2NAVI_EVO_TRACE=1, diagnostics)
|
||||
// The order in which a frame's submissions, waits, signals and held parts were replayed, as a string of tokens:
|
||||
// |<queue>.<n> a submission of n command buffers on that queue; p it lines up behind held work of its queue; m<e> a
|
||||
// wait on event e that holds; u<e> one that does not; h the submission stops there; s<e>=<v> a replayed signal; r<queue>
|
||||
// held work of that queue goes on; w it stops at a wait again; d it is through; F it went on without its signal;
|
||||
// c<e>=<v> the CPU signals an event (nvnEventSignal, on whatever thread, where the call came between the others); L<e>
|
||||
// a wait that holds only by a CPU signal that came after the submission took its copies (vk_exec_xfer.c "events the
|
||||
// CPU signals"). Events and queues are numbered in the order they first appear; a value of 16 or more is written n,
|
||||
// as a counter would make every frame's string its own. Every distinct string is logged once with its number, and the
|
||||
// numbers of the frames are logged sixty to a line, so the frames that were replayed in another order than usual can
|
||||
// be set against the pictures of the flight recorder.
|
||||
#define EVT_KINDS 512
|
||||
static struct {
|
||||
int on;
|
||||
PlatMutex lock;
|
||||
char buf[2048];
|
||||
int n, over;
|
||||
const void *ev[64];
|
||||
int nev;
|
||||
char *kind[EVT_KINDS];
|
||||
int nkind;
|
||||
uint64_t line_first;
|
||||
int line_n;
|
||||
char line[512];
|
||||
int line_len;
|
||||
} ET = {.on = -1, .lock = PLAT_MUTEX_INIT};
|
||||
|
||||
static int evt_on(void) {
|
||||
if (ET.on < 0) ET.on = rt_knob("EVO_TRACE", "0");
|
||||
return ET.on;
|
||||
}
|
||||
|
||||
void vk_exec_evt(char what, const void *event, uint32_t value) {
|
||||
if (!evt_on()) return;
|
||||
char t[40];
|
||||
int e = -1;
|
||||
plat_mutex_lock(&ET.lock);
|
||||
if (event) {
|
||||
for (e = 0; e < ET.nev && ET.ev[e] != event; e++) {}
|
||||
if (e == ET.nev && ET.nev < 64) ET.ev[ET.nev++] = event;
|
||||
}
|
||||
if (what == 's' || what == 'c') snprintf(t, sizeof t, value < 16 ? "%c%d=%u " : "%c%d=n ", what, e, value);
|
||||
else if (what == '|') snprintf(t, sizeof t, "|%d.%u ", e, value);
|
||||
else if (event) snprintf(t, sizeof t, "%c%d ", what, e);
|
||||
else snprintf(t, sizeof t, "%c ", what);
|
||||
for (const char *s = t; *s; s++) {
|
||||
if (ET.n >= (int)sizeof ET.buf - 1) { ET.over = 1; break; }
|
||||
ET.buf[ET.n++] = *s;
|
||||
}
|
||||
plat_mutex_unlock(&ET.lock);
|
||||
}
|
||||
|
||||
void vk_exec_evt_frame(uint64_t frame) {
|
||||
if (!evt_on()) return;
|
||||
plat_mutex_lock(&ET.lock);
|
||||
ET.buf[ET.n] = 0;
|
||||
int k = 0;
|
||||
while (k < ET.nkind && strcmp(ET.kind[k], ET.buf)) k++;
|
||||
if (k == ET.nkind && ET.nkind < EVT_KINDS) {
|
||||
size_t len = strlen(ET.buf) + 1;
|
||||
if ((ET.kind[k] = malloc(len))) {
|
||||
memcpy(ET.kind[k], ET.buf, len);
|
||||
ET.nkind++;
|
||||
rt_log("evo: order %d first at frame %llu%s: %s", k, (unsigned long long)frame, ET.over ? " (cut)" : "", ET.buf);
|
||||
}
|
||||
}
|
||||
if (!ET.line_n) ET.line_first = frame, ET.line_len = 0;
|
||||
ET.line_len += snprintf(ET.line + ET.line_len, sizeof ET.line - (size_t)ET.line_len, " %d", k);
|
||||
if (++ET.line_n == 60 || ET.line_len > (int)sizeof ET.line - 16) {
|
||||
rt_log("evo: frames %llu-%llu:%s", (unsigned long long)ET.line_first, (unsigned long long)frame, ET.line);
|
||||
ET.line_n = 0;
|
||||
}
|
||||
ET.n = 0, ET.over = 0;
|
||||
plat_mutex_unlock(&ET.lock);
|
||||
}
|
||||
|
||||
static int evo_enabled(void) {
|
||||
if (evo_on < 0) {
|
||||
const char *e = cfg_get("NX2NAVI_EVENT_ORDER");
|
||||
@@ -1069,6 +1145,7 @@ static int held_sync(void) {
|
||||
static int cont_walk(VkExec *ex, Cont *c) {
|
||||
if (c->at && !vk_exec_event_met(nvn_op_payload(c->at))) {
|
||||
evo_forced++;
|
||||
vk_exec_evt('F', NULL, 0);
|
||||
static int logged;
|
||||
if (logged++ < 8)
|
||||
rt_log("vk: event order: a held submission goes on after %llu submissions without its signal",
|
||||
@@ -1108,7 +1185,9 @@ static void evo_resume(VkExec *ex) {
|
||||
evo_in = 1, evo_queue = evq[s].q;
|
||||
for (;;) {
|
||||
evo_resumed++;
|
||||
vk_exec_evt('r', (const void *)evq[s].q, 0);
|
||||
if (cont_walk(ex, c)) { // waits again: the queue's state stays with it
|
||||
vk_exec_evt('w', NULL, 0);
|
||||
vk_exec_pass_end(ex);
|
||||
if (!c->st && !(c->st = malloc(ST_HI - ST_LO))) rt_fatal("vk: out of memory (queue state)");
|
||||
memcpy(c->st, (uint8_t *)ex + ST_LO, ST_HI - ST_LO);
|
||||
@@ -1118,6 +1197,7 @@ static void evo_resume(VkExec *ex) {
|
||||
evq[s].head = c->next; // done: the queue's next submission starts with the state this one left
|
||||
if (!evq[s].head) evq[s].tail = NULL;
|
||||
evo_pending--;
|
||||
vk_exec_evt('d', NULL, 0);
|
||||
cont_free(c);
|
||||
c = evq[s].head;
|
||||
if (!c) break;
|
||||
@@ -1213,12 +1293,15 @@ static const op_hdr *walk(VkExec *ex, const op_hdr *h, int depth) {
|
||||
case OP_CLEAR_BUF:
|
||||
vk_exec_op_xfer(ex, h->op, a);
|
||||
break;
|
||||
case OP_WAIT_EVENT:
|
||||
if (!vk_exec_wait_event(a) && depth == 0 && evo_queue) {
|
||||
case OP_WAIT_EVENT: {
|
||||
int met = vk_exec_wait_event(a);
|
||||
vk_exec_evt(met ? 'm' : 'u', (const void *)((const p_wait_event *)a)->val, 0);
|
||||
if (!met && depth == 0 && evo_queue) {
|
||||
vk_exec_pass_end(ex);
|
||||
return h;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: rt_fatal("vk: op %s has no replay handler", nvn_op_name(h->op));
|
||||
}
|
||||
if (vk_exec_signalled && depth == 0 && !evo_in) evo_resume(ex);
|
||||
@@ -1296,6 +1379,8 @@ int vk_exec_record(VkCommandBuffer cb, const uint64_t *handles, int n, uint64_t
|
||||
int evo = evo_enabled() && gfx_submit_queue;
|
||||
int slot = evo ? evq_slot(gfx_submit_queue) : -1;
|
||||
if (evo && slot < 0) evo = 0;
|
||||
vk_exec_evt('|', (const void *)gfx_submit_queue, (uint32_t)n);
|
||||
vk_exec_event_sync(1); // before the mirror sync and the uniform copy: a CPU signal after this point came after them
|
||||
int synced = n || (evo_pending && held_sync() && vk_exec_held_ready()); // held_sync
|
||||
if (synced) {
|
||||
vk_mem_mirror_begin();
|
||||
@@ -1317,7 +1402,7 @@ int vk_exec_record(VkCommandBuffer cb, const uint64_t *handles, int n, uint64_t
|
||||
if (!handles[i]) rt_fatal("vk: command handle %d of a submission is null", i);
|
||||
if (evo_pending) evo_resume(ex); // signals the CPU gave since, and holds past CONT_MAX
|
||||
if (evo && evq[slot].head) { // the queue waits: this submission lines up behind it
|
||||
if (n) cont_push(slot, cont_new(handles, n, 0, NULL)), evo_held++;
|
||||
if (n) cont_push(slot, cont_new(handles, n, 0, NULL)), evo_held++, vk_exec_evt('p', NULL, 0);
|
||||
} else {
|
||||
evo_queue = evo ? gfx_submit_queue : 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
@@ -1325,12 +1410,14 @@ int vk_exec_record(VkCommandBuffer cb, const uint64_t *handles, int n, uint64_t
|
||||
if (!stop) continue;
|
||||
cont_push(slot, cont_new(handles, n, i, stop)); // the rest of this submission waits for its signal
|
||||
evo_held++;
|
||||
vk_exec_evt('h', NULL, 0);
|
||||
break;
|
||||
}
|
||||
evo_queue = 0;
|
||||
}
|
||||
vk_exec_pass_end(ex);
|
||||
x_here = 0;
|
||||
vk_exec_event_sync(0);
|
||||
if (ex->recorded) vk_exec_barrier(ex), vk_exec_pool_marks(ex); // later submissions see this one's writes
|
||||
// The write-backs in a part of their own, after one that signals the executed timeline (vk_sync.c exec_tl): the
|
||||
// wait after a frame's first submission then ends when the submission's passes are through, not its write-backs.
|
||||
@@ -1353,9 +1440,11 @@ int vk_exec_record(VkCommandBuffer cb, const uint64_t *handles, int n, uint64_t
|
||||
if ((rt_trace & RT_TRACE_PERF) && n_subs >= 240) {
|
||||
rt_log("perf: replay command buffer parts per submission %.2f (%.2f first parts sent while the GPU was idle, %.2f "
|
||||
"splits inside a pass); event order: held %llu, resumed %llu (%llu without their signal), switches %llu, "
|
||||
"held now %d", (double)(n_subs + n_parts) / (double)n_subs, (double)n_idle_parts / (double)n_subs,
|
||||
"held now %d; waits a CPU signal met only after the submission's copies were taken: %llu",
|
||||
(double)(n_subs + n_parts) / (double)n_subs, (double)n_idle_parts / (double)n_subs,
|
||||
(double)n_pass_splits / (double)n_subs, (unsigned long long)evo_held, (unsigned long long)evo_resumed,
|
||||
(unsigned long long)evo_forced, (unsigned long long)evo_switches, evo_pending);
|
||||
(unsigned long long)evo_forced, (unsigned long long)evo_switches, evo_pending,
|
||||
(unsigned long long)vk_exec_event_late_take());
|
||||
evo_held = evo_resumed = evo_forced = evo_switches = 0;
|
||||
n_subs = n_parts = n_idle_parts = n_pass_splits = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user