mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 14:39:58 -04:00
Close a frame's replay state under the submission lock: at the present when the lock is free, else first thing in the next submission, so another thread's replay never sees it reset halfway.
present_image ran the frame's bookkeeping on the presenting thread without a lock: vk_exec_frame_log (the trace counts and vk_exec_cond_frame_end's frame count, which the conditional draws go by), dynres_frame, vk_exec_barrier_log, vk_dlaa_frame (the DLSS mode and its LOD bias, the frame's points, the swap image, the idle releases), vk_mvsurvey_frame, vk_mvprev_frame (which swaps the two motion tables the draws insert into) and vk_gpu_passes_frame. All of it is state the replay reads and writes as it records, under sub_lock. With the replay on the submitting threads the game presents on one thread while another may be replaying (the overlap lines of the 0.10.0 fresh session, at area changes), so the present reset it in the middle of that replay: a DLSS frame reset halfway, the motion tables swapped halfway (with MVPREV_CHECK=1 an index out of bounds), the conditional draws counted against the next frame. Now the bookkeeping is frame_end, and runtime/vk_frame_owed.h decides where it runs. present_image marks its frame owed and runs it itself only when it gets sub_lock at once (vk_sync.c vk_sync_try_locked); otherwise vk_sync.c submit runs every owed frame's, in frame order, right after it takes the lock and before its replay (vk_present_frames_owed), on whichever thread submits next, the present thread's blit submission included. The presenting thread never waits for another thread's replay for it: no new wait on a drawing thread; the thread that takes the lock next does the work it would have done at the present, tens of microseconds normally. The hand-off, vk_texture_get with its upload flush and vk_present_drain stay outside the lock, as frame_end must not wait for the present thread or submit; its callees were checked for that. vk_sampler_aniso_live and vk_mem_census keep their place in present_image (their own locks). In the asynchronous replay the other holder of sub_lock is the present thread's blit, and the same applies. NX2NAVI_PRESENT_ORDER (present_order in [diagnostics], default 1, read at start) puts it back at the present with 0, as in 0.10.1: metas, known and sections rows and an nx2navi.ini.example entry. Not reproduced before the change. Checks that passed: the new tests/frame_owed_check (one presenting and three replaying threads, some replays holding the lock 40 ms, over 20,000 frames: every frame's bookkeeping once, in order, never during a replay and before any replay that took the lock after its present; the longest present under 1 ms with 19,000 presents made during a long hold), cfg_rows_check with 0 problems, pass_cc_check on every runtime file (headers changed), no new -Wall -Wextra warnings in vk_backend.c, vk_sync.c, vk_exec.c and cfg.c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -895,6 +895,12 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n); // records with vk_ex
|
||||
// The probes (--probe-vkmem's table parts, the lost-device probe): one submission whose commands the caller records
|
||||
// itself where the replay would, with the submission lock, the memory prologue and the fence of any other.
|
||||
uint64_t vk_sync_submit_own(void (*record)(VkCommandBuffer, void *), void *arg);
|
||||
// Runs fn() under the submission lock when it is free now and returns 1; returns 0 at once, without running it, when
|
||||
// another thread holds the lock (vk_backend.c present_image: a frame's bookkeeping never waits for another replay).
|
||||
int vk_sync_try_locked(void (*fn)(void));
|
||||
// vk_backend.c (vk_frame_owed.h): the bookkeeping of the frames presented while another thread held the submission
|
||||
// lock. vk_sync.c submit calls it right after taking the lock, before its replay; a no-op without the back end.
|
||||
void vk_present_frames_owed(void);
|
||||
uint64_t vk_sync_reserve(void); // asynchronous replay: the value the next queued submission signals
|
||||
int vk_sync_fence_wait(uint64_t value, uint64_t timeout_ns); // 1 when done; 0 on timeout or a value never submitted
|
||||
// The executed timeline (vk_sync.c): a submission's own commands are through the GPU, its write-backs maybe not yet.
|
||||
|
||||
Reference in New Issue
Block a user