Set vk_sub_in_frame under the submission lock from the place the submitting thread noted, so a thread about to submit no longer changes it under another thread's replay.

vk_sub_in_frame says which of its frame's submissions the one being recorded is; vk_memory.c sub_place files the mirror
pre-snapshot's statistics by it during the replay, on the replaying thread and its workers. vk_be_submit wrote it on
every submitting thread before submit_sync, outside sub_lock, so with the replay on the submitting threads another
thread entering a submit changed it under a replay in progress, and the replay filed its work at the other
submission's place. Each thread now notes the place in a thread-local (vk_be_submit, and replay_main for the
asynchronous replay), and vk_sync.c submit publishes it right after taking the lock for a submission with commands
(vk_sub_in_frame_publish, a weak no-op without the back end). Submissions without commands of their own (held work, the
present thread's blit) leave it as it was, as before. Performance heuristics only; no timing change.

Not reproduced before the change. Checks that passed: pass_cc_check on every runtime file (a header changed), no new
-Wall -Wextra warnings in vk_backend.c and vk_sync.c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 19:12:51 -05:00
parent 0e918d4846
commit 518185b808
3 changed files with 16 additions and 3 deletions

View File

@@ -1483,6 +1483,7 @@ static uint64_t submit(const uint64_t *handles, int n, const OwnCommands *own) {
VkCtx *c = vk_ctx();
plat_mutex_lock(&sub_lock);
vk_present_frames_owed(); // frames presented while another thread replayed close before this replay begins
if (n > 0 && !own) vk_sub_in_frame_publish(); // this submission's place in its frame, for the replay
vk_mem_dirty_submit(); // NX2NAVI_TRACE=perf: what a mirror would upload before this submit
uint64_t fence = __atomic_load_n(&issued, __ATOMIC_ACQUIRE) + 1;
cur_fence = fence;
@@ -1581,8 +1582,10 @@ int vk_sync_try_locked(void (*fn)(void)) {
return 1;
}
// vk_backend.c's, which runs the frames' bookkeeping (vk_frame_owed.h); builds without the back end have none.
// vk_backend.c's, which run the frames' bookkeeping (vk_frame_owed.h) and set the place in the frame of the submission
// being recorded; builds without the back end have neither.
WEAK void vk_present_frames_owed(void) {}
WEAK void vk_sub_in_frame_publish(void) {}
// st_lock held: p at the end of the queue *q.
static void pending_push(Pending **q, int *head, int *n, int *cap, Pending p) {