Fix a deadlock between the replay workers in vk_exec_pass_end.

vk_exec_pass_end took tfr_lock and then, in vk_texture_gpu_written, the texture lock. A chunk recorded by another
thread can hold the texture lock in the pool sync and end its pass there (a lookup's alias copy through
vk_exec_inline_begin), and then wait for tfr_lock. The two chunks waited for each other and the other chunks spun in
their turns, so loading after Continue never finished with replay_workers = 3. The targets are now marked written
before tfr_lock is taken, which guards only the target history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Leonardo Chappuis
2026-11-12 12:23:32 -03:00
committed by chrg6
parent a654d079e1
commit d991c04284

View File

@@ -899,16 +899,24 @@ void vk_exec_pass_end(VkExec *ex) {
bc_copy_back(ex, &ex->color[i]);
if (vk_dump_armed) vk_dump_pass_end(ex);
uint64_t stamp = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED) + 1;
// The targets are marked written outside tfr_lock: vk_texture_gpu_written takes the texture lock, and a chunk that
// holds the texture lock can end its pass here (a lookup's alias copy, vk_exec_inline_begin) and then wait for
// tfr_lock. Taken the other way round, a chunk holding tfr_lock and waiting for the texture lock deadlocked with it,
// the other chunks spinning in their turns (the loading screen after Continue, 3 replay workers). tfr_lock guards
// only the target history and takes no other lock inside.
for (int i = 0; i < 8; i++)
if (ex->color[i].image) vk_texture_gpu_written(ex->color[i].tex);
if (ex->depth.image) vk_texture_gpu_written(ex->depth.tex);
int lk = vk_exec_shared();
if (lk) plat_mutex_lock(&tfr_lock);
for (int i = 0; i < 8; i++)
if (ex->color[i].image) {
TfrTarget ft = tfr_of(&ex->color[i]);
vk_texture_gpu_written(ex->color[i].tex), tfr_note(&ft, stamp);
tfr_note(&ft, stamp);
}
if (ex->depth.image) {
TfrTarget ft = tfr_of(&ex->depth);
vk_texture_gpu_written(ex->depth.tex), tfr_note(&ft, stamp);
tfr_note(&ft, stamp);
}
if (lk) plat_mutex_unlock(&tfr_lock);
vk_dlaa_pass_end(ex); // a jittered pass left its targets' outer rows or columns undrawn