Replay the game's queues in the order their events allow, so Link and the other characters are no longer drawn too dark.

Ocarina runs compute work on a second queue that trades results with the main one through events: the worker's command buffers wait (WaitEvent) for signals the main queue gives in its submission a few submits later, and the main queue waits for the worker's signals in turn. Replayed one submission after the other, the worker's steps ran before the work they wait for and read the previous frame's results, and the characters came out much too dark at any time of day (Kokiri Forest: about 13 waits a frame, 7 of them reached before their signal).

A top-level wait whose condition does not hold in replay order now stops its submission: the rest is held, with private copies of its recordings and the queue's state, and the queue's later submissions line up behind it. After each replayed signal the held work whose wait now holds goes on inside the command buffer being recorded, between full barriers, with its own state swapped in. Work still held after 36 submissions goes on regardless, as before (counted in the NX2NAVI_TRACE=perf line). The queue reaches the back end as gfx_submit_queue. Only with the replay on the submitting thread; NX2NAVI_EVENT_ORDER=0 turns it off.

Tested by play in adult Hyrule Field with the tree fix of the previous commit: Link lit normally at dusk and at noon, trees steady, lighting otherwise unchanged. The white specks in the grass remain (they predate both changes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-08 09:43:15 -05:00
parent 82257eec3d
commit 3aa8ff56a2
5 changed files with 257 additions and 11 deletions

View File

@@ -612,6 +612,7 @@ NVN_API(nvnQueueFinish) {
// lod_entered / lod_issued count submits that entered QueueSubmitCommands / reached the back end; lod_fence holds
// the fence of the last LOD_RING. NX2NAVI_LOD_GUARD=0 turns the wait off.
#define LOD_RING 64
_Thread_local uintptr_t gfx_submit_queue;
int nvn_submits_in_frame; // nvnQueueSubmitCommands calls since the last nvnQueuePresentTexture (NX2NAVI_SUBMIT_FINISH)
static uint64_t lod_entered, lod_issued, lod_fence[LOD_RING];
@@ -635,12 +636,16 @@ NVN_API(nvnQueueSubmitCommands) {
if (!hs) rt_fatal("nvn: out of memory (submit of %d handles)", n);
plat_mutex_lock(&submit_lock);
nvn_submit_prepare_async(h, hs, n);
gfx_submit_queue = (uintptr_t)q;
f = gfx_backend()->submit(hs, n);
gfx_submit_queue = 0;
plat_mutex_unlock(&submit_lock);
if (hs != local) free(hs);
} else {
nvn_submit_prepare(h, n);
gfx_submit_queue = (uintptr_t)q;
f = gfx_backend()->submit(h, n);
gfx_submit_queue = 0;
}
uint64_t prev = __atomic_load_n(&last_fence, __ATOMIC_RELAXED);
while (f > prev && !__atomic_compare_exchange_n(&last_fence, &prev, f, 1, __ATOMIC_RELEASE, __ATOMIC_RELAXED)) {}