nvnCommandBufferFenceSync is implemented: the sync waits for the fence of the submit that carries the record (#1388)

Zonai Fieldworks' native-font renderer (Cryonis in its BotW Abilities member) records it, and the weak stub ended the
game with "NVN nvnCommandBufferFenceSync is not implemented". The record is a new op, OP_FENCE_SYNC, that every replay
skips; at QueueSubmitCommands the syncs named in the submitted handles get that submit's fence value, which completes
no earlier than the console's point. The game itself never records the op, so its submits pay one flag load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-25 21:23:19 +03:00
1 parent 4fccaa5bef
commit fc2863a15c
7 files changed
+71 -9

No files matched your search

+10 -1
View File
@@ -463,7 +463,8 @@ NVN_API(nvnBufferFlushMappedRange) {
}
// ---------- Sync and events
// A sync is a fence value: fenced = 1 after QueueFenceSync (the newest submit), 3 after WindowAcquireTexture (fence 0).
// A sync is a fence value: fenced = 1 after QueueFenceSync (the newest submit) or the submit of a CommandBufferFenceSync
// record (that submit), 3 after WindowAcquireTexture (fence 0).
// NVNboolean nvnSyncInitialize(NVNsync *s, NVNdevice *d)
NVN_API(nvnSyncInitialize) {
*(sync_t *)arg_p(c, 0) = (sync_t){SYNC_MAGIC, 0, 0};
@@ -478,6 +479,13 @@ NVN_API(nvnQueueFenceSync) {
s->fenced = 1;
s->fence = nvn_fence_last();
}
// CommandBufferFenceSync at its submit (nvn_api_cmd.c nvn_submit_fence_syncs): the value first, then fenced, so a
// thread that sees fenced waits for this value or a newer one. A sync finalized since the record is left alone.
void nvn_sync_fence(sync_t *s, uint64_t fence) {
if (!s || s->magic != SYNC_MAGIC) return;
__atomic_store_n(&s->fence, fence, __ATOMIC_RELAXED);
__atomic_store_n(&s->fenced, 1, __ATOMIC_RELEASE);
}
// TOTK_SYNC_AHEAD=1: one more frame in flight. Each frame the game waits (one nvnSyncWait, frame_wait_lr) for
// the frame it presented last; on the Switch that work is long done by then, here it is still in the replay and on the
// GPU (about 11 ms from the submit), and the wait sets the frame time. With the switch on, that wait, and only that
@@ -720,6 +728,7 @@ NVN_API(nvnQueueSubmitCommands) {
nvn_submit_prepare(h, n);
f = gfx_backend()->submit(h, n);
}
nvn_submit_fence_syncs(h, n, f); // the syncs this submit's CommandBufferFenceSync records name wait for f
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)) {}
__atomic_store_n(&lod_fence[no % LOD_RING], f, __ATOMIC_RELAXED);