Count a texture pool take only when its sync left no slot behind, so a retired texture is not freed while a set still holds its view.

Once the frame's creation time is spent, pool_refill skips a slot it left earlier in the frame, and pool_sync_entries
may return before the walk. Such a slot keeps its old view in the current set with nothing in the change log, so the
takes after it do not carry the change into the other sets. vk_pool_takes counted those takes all the same, and at
about six submissions a frame, more than VK_POOL_SETS of them could pass within one frame while a retired texture's slot
was skipped every time. retire_sweep would then free the image while every set still named it. A take now counts only
when its sync left no slot behind (PL.retry clear): after it, every slot change made before it is in that set and in
the log, and the takes after it bring it into the others. A sealed second take inside one submission still goes
uncounted, which only delays the free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5cd431f792e00ca3b9a03657cd4aab64fc38dae7)
This commit is contained in:
chrg6
2026-11-09 21:32:45 -05:00
committed by tangerineturtle1
parent a87f6e1bd6
commit 49dd6639f1
3 changed files with 12 additions and 5 deletions

View File

@@ -2165,8 +2165,13 @@ static void pool_sync(VkExec *ex) {
PL.catch_ns += kern_now_ns() - t1;
}
PL.set_synced[PL.cur] = PL.logn;
// a set taken and up to date (with one set, the refresh above wrote into it directly)
if (took) __atomic_fetch_add(&pool_takes, 1, __ATOMIC_RELEASE);
// A set taken and up to date (with one set, the refresh above wrote into it directly), counted only when this sync
// left no slot behind: once the frame's creation time is spent, pool_refill skips a slot it left earlier in the frame
// and pool_sync_entries may return before the walk, and such a slot keeps its old view in this set with nothing in
// the log, so the takes after it would not carry the change into the other sets. After a counted take, every slot
// change made before it is in this set and in the log; vk_texture.c retire_sweep frees a retired image only after
// more than VK_POOL_SETS of them, so no set of the ring still holds its view.
if (took && !PL.retry) __atomic_fetch_add(&pool_takes, 1, __ATOMIC_RELEASE);
}
typedef struct { VkExec *ex; uint32_t used; int n, retry, spent; } PoolDirty;