From 78b3bc5a805b6127adfdeb68d2bcb1d65ebd6339 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Mon, 9 Nov 2026 21:34:04 -0500 Subject: [PATCH] Clear a texture pool slot's left-this-frame note when it is filled, so a skipped slot only ever holds the stand-ins. pool_refill notes a slot it could not fill (pool_defer), and once the frame's creation time is spent it skips slots noted in that frame. A fill did not clear the note. So a slot left and then filled in the same frame was skipped later in that frame with the filled texture's view still in the set, also after that texture was destroyed: a released texture dropped past the size limit, or one evicted. A shader sampling the slot would then read freed memory. A left slot holds the stand-ins (its lookup resolved to nothing), so with the note cleared on a fill, a skipped slot can only hold those. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 8d04e17a954e640a9ff06baedc3e7614dc978798) --- runtime/vk_exec_draw.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 4fd70b13..6d00dccc 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -2177,11 +2177,14 @@ static void pool_sync(VkExec *ex) { typedef struct { VkExec *ex; uint32_t used; int n, retry, spent; } PoolDirty; // A slot whose token changed: filled, or noted as left (pool_defer). With the frame's creation time spent (spent), a -// slot left earlier in the frame is not looked up again. +// slot left earlier in the frame is not looked up again. A left slot holds the stand-ins (its lookup resolved to +// nothing), and a fill clears the note: kept, a slot left and then filled in the same frame was skipped later in that +// frame with the filled texture's view still in the set, also after that texture was destroyed (a released one dropped, +// one evicted), and a shader sampling the slot read freed memory. static int pool_refill(VkExec *ex, uint32_t id, uint32_t used, uint64_t t, int spent) { uint32_t mark = (uint32_t)PL.frame + 1; if (spent && pool_defer[id] == mark) return PL.n_defer_skips++, 0; - if (pool_fill(ex, id, used, t)) return 1; + if (pool_fill(ex, id, used, t)) return pool_defer[id] = 0, 1; pool_defer[id] = mark; return 0; }