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:
chrg6
2026-11-10 10:26:21 -05:00
committed by tangerineturtle1
parent cdaab81727
commit 07721c0058
9 changed files with 229 additions and 14 deletions

View File

@@ -308,6 +308,12 @@ static int vk_be_exec_wait(uint64_t value, uint64_t timeout_ns) {
// The front end's view (nvn_api_core.c, nvn_api_cmd.c): replay is asynchronous only on this back end.
int gfx_replay_async(void) { return gfx_backend() == &gfx_vulkan_backend && vk_replay_async(); }
// The front end's nvnEventSignal, before it writes (vk_exec_xfer.c "events the CPU signals").
void gfx_event_signalling(const void *value, uint32_t to) {
vk_exec_event_cpu(value);
vk_exec_evt('c', value, to);
}
// The newest submit number (nvn_submit_count) whose replay is done: recording copies it used may be freed.
uint64_t gfx_replayed_submits(void) {
if (!gfx_replay_async()) return nvn_submit_count();
@@ -382,6 +388,10 @@ static uint64_t submit_sync(const uint64_t *handles, int n) {
vk_present_drain();
vk_texture_new_submit();
uint64_t f = vk_sync_submit(handles, n);
// The submission stopped at a wait whose signal the CPU gave while it was being replayed (vk_exec_xfer.c "events
// the CPU signals"): it goes on now, in a submission of its own with copies taken after the signal, and that
// submission's value is the one the game's fence stands for.
if (n && vk_exec_event_at_sync() && vk_exec_held() && vk_exec_held_ready()) f = submit_sync(NULL, 0);
if (PH.on && n) {
if (!vk_exec_held()) ph_flush(&PH.after);
else if (vk_exec_submit_seq - PH.since >= PH_MAX) ph_flush(&PH.capped);
@@ -528,6 +538,7 @@ static void vk_be_present(const tex_t *t, const int crop[4], uint64_t at_ns) {
if (!gfx_replay_async()) {
uint64_t frame = __atomic_add_fetch(&gfx_counters.frames, 1, __ATOMIC_RELAXED);
vk_dlssg_submitted(frame);
vk_exec_evt_frame(frame);
perf_present(frame); // before vk_exec_frame_log, which resets the frame's exec counts the flight recorder reads
uint64_t queued = kern_now_ns();
if (present_held_on()) { // present_held