Make the wait after a frame's first submission the fence's wait again.

For a day that wait ended on a second timeline, when the GPU had run the submission's own commands (wb_split = 1,
then the default), on the thought that it only left out write-backs nothing needed yet. It left out the completion
thread's side effects for the submissions before it as well, and the game reads some of those next: the occlusion
counts, counter reports and event values, and the stamps the texture checks read. A frame's first submission is small
and runs right behind the last frame's large one, so the game went on while that one's callbacks were still running.
Measured in Hyrule Field with the camera turning (RTX 5090, lazy write-back on): 2,267 of 2,320 such waits returned
before those side effects had run; they were through 0.45 to 0.8 ms later on average, 12.6 ms at most, and in that
time 770 to 1,015 occlusion counts, 21 to 28 counter reports and 17 event values a frame reached guest memory. The
submission the game waits for wrote nothing back in any of 14 runs, so its own write-backs were never the matter.
A player saw a patch of grass near the camera change from frame to frame there and less of it with the fence's wait.
No scripted run showed such a frame with either wait, so the link to what the player saw is not shown.
The fence's wait takes 0.65 to 0.7 ms more of a frame there, about 6 % at 85 frames a second (single runs beside
other work). wb_split = 1 still gives the other wait, and 2 forces it with shadow storage.
NX2NAVI_TRACE=perf now counts what a wait on that timeline leaves behind and the completion thread's time by callback.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 4d108b706e72c001ddbe20608f06469885df584b)
This commit is contained in:
chrg6
2026-11-11 04:48:20 -05:00
parent 84b0672ec2
commit c2591a8a46
7 changed files with 159 additions and 36 deletions

View File

@@ -82,8 +82,19 @@ static void note_gpu_write(VkExec *ex, uint64_t addr, uint64_t size) {
typedef struct { volatile uint32_t *val; uint32_t mode, value; } EventWrite;
// The side effects below that ran after a waiter on the executed timeline had gone on (vk_sync.c vk_sync_effect_late):
// the game was already past the wait after its submit when these reached its memory.
static volatile uint64_t late_events, late_counters, late_counts;
void vk_exec_late_stats(uint64_t *events, uint64_t *counters, uint64_t *counts) {
*events = __atomic_exchange_n(&late_events, 0, __ATOMIC_RELAXED);
*counters = __atomic_exchange_n(&late_counters, 0, __ATOMIC_RELAXED);
*counts = __atomic_exchange_n(&late_counts, 0, __ATOMIC_RELAXED);
}
static void event_cb(void *arg) {
EventWrite *e = arg;
if (vk_sync_effect_late()) __atomic_fetch_add(&late_events, 1, __ATOMIC_RELAXED);
if (e->mode == NVN_EVENT_SIGNAL_MODE_ADD) __atomic_fetch_add(e->val, e->value, __ATOMIC_RELEASE);
else __atomic_store_n(e->val, e->value, __ATOMIC_RELEASE);
free(e);
@@ -104,6 +115,7 @@ typedef struct { uint64_t addr, seq; } CounterWrite;
static void counter_cb(void *arg) {
CounterWrite *w = arg;
if (vk_sync_effect_late()) __atomic_fetch_add(&late_counters, 1, __ATOMIC_RELAXED);
write_counter(w->addr, 0);
pending_written(w->addr, w->seq);
free(w);
@@ -367,7 +379,10 @@ static void oq_cb(void *arg) {
else {
oq_count += sum;
if (s->lost && !oq_count) oq_count = 1;
if (s->addr) write_counter(s->addr, oq_count), pending_written(s->addr, s->seq);
if (s->addr) {
if (vk_sync_effect_late()) __atomic_fetch_add(&late_counts, 1, __ATOMIC_RELAXED);
write_counter(s->addr, oq_count), pending_written(s->addr, s->seq);
}
}
free(s);
}