Retire textures evicted by disuse before freeing them, take them back on any use, and add tex_disuse = 2 to tell the freeing from the marks.

0.6.1.14 faulted the GPU (a read of an invalid address in a pass) about 30 seconds after its last disuse evictions, and
no path by which an evicted image is still read was found in the code. An evicted texture is now first retired: the
pool refresh gives its slots the stand-in while the image stays whole. It is destroyed only once the texture pool has
taken every set of its ring since and the GPU has finished the submissions recorded until then, so no pool set can
still be bound with its view. A mark on one of its slots or any lookup outside the pool refresh takes it back as it is,
and the perf line counts those, which shows whether the marks miss a real use. tex_disuse = 2 retires and never frees,
so the next fault can be put on the freeing or on the marks and stand-ins.

The registration shortcut also read a slot's cached entry without checking that the resolution was current, so it could
read the record of a destroyed texture; it now checks the slot's generation first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4c5b2ae2e030ab00a910d8f071c030e610fd78e1)
This commit is contained in:
chrg6
2026-11-09 21:09:09 -05:00
committed by tangerineturtle1
parent 57cdfa1520
commit f1127f8be9
6 changed files with 125 additions and 25 deletions

View File

@@ -1709,7 +1709,7 @@ static void tex_info_full(VkExec *ex, const GfxShaderRes *r, uint64_t h, int sto
// last current; the whole set when the log has wrapped). Writes within a submission go to its own set at once, as
// before.
volatile uint32_t vk_pool_kinds_used;
#define POOL_SETS 4
#define POOL_SETS VK_POOL_SETS
#define POOL_LOG (1u << 20) // entries of the change log: binding * VK_POOL_TEX + id, one per write
static struct {
VkDescriptorSetLayout layout, empty;
@@ -1991,6 +1991,8 @@ static void pool_entry_to(VkDescriptorSet set, uint32_t e) {
// A submission's first pool use: the next set of the ring, once the GPU is done with it. 1 when it switched; *from is
// the log position the set holds writes up to (pool_catch_up brings it level once pool_sync has refreshed the entries:
// a view written into a set must be alive, and the refresh is what replaces the views of destroyed textures).
static volatile uint64_t pool_takes; // sets taken (vk_pool_takes): counted once the take's pool_sync is done
static int pool_take_set(VkExec *ex, uint64_t *from) {
if (PL.cur_fence == ex->fence) return 0;
int i = (PL.cur + 1) % PL.nsets;
@@ -2003,6 +2005,8 @@ static int pool_take_set(VkExec *ex, uint64_t *from) {
return PL.nsets > 1;
}
uint64_t vk_pool_takes(void) { return __atomic_load_n(&pool_takes, __ATOMIC_ACQUIRE); }
// The current set gets the entries written into other sets in [from, to) of the log, as PL.view / PL.samp hold them now.
static uint64_t pool_memo_hits; // pool_fill: slots that shared another slot's lookup (defined with pool_memo below)
@@ -2129,6 +2133,7 @@ static void pool_sync_entries(VkExec *ex);
static void pool_sync(VkExec *ex) {
if (!PL.layout) vk_pool_set_layout();
uint64_t from = 0, pre = PL.logn;
int took = PL.cur_fence != ex->fence;
int switched = pool_take_set(ex, &from); // every submission its own set, before the shortcut
uint64_t t0 = kern_now_ns(), f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
if (f != PL.frame) PL.frame = f, PL.frame_ns = 0;
@@ -2143,6 +2148,8 @@ 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);
}
typedef struct { VkExec *ex; uint32_t used; int n, retry, spent; } PoolDirty;