From b92f1130734729243e3ef1046da20ab581f91956 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 27 Oct 2026 01:01:54 +0300 Subject: [PATCH] Check a texture's storage pages only in the 2 MiB regions stamped since its last check: an unchanged 4 MiB texture read 1,024 page generations, at about 1,100 checks a frame Co-Authored-By: Claude Opus 5.5 --- runtime/vk_memory.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index e66ada31..b6b2e669 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -728,9 +728,15 @@ int vk_mem_changed_snap(uint64_t addr, uint64_t size, uint32_t since, uint32_t e } int untracked = 0, changed = 0; for (uint64_t r = r0; r <= r1; r++) untracked |= snap_untracked[r]; - for (uint64_t a = lo; !untracked && a < hi && !changed; a += 1ull << GEN_PAGE_SHIFT) { - uint32_t *s = gen_slot(a, 0); - if (s && *s > since) changed = 1; + // Pages only in regions stamped after since (reg_max; REG_SHIFT is SNAP_SHIFT): an unchanged texture of 4 MiB was + // 1,024 page reads, at about 1,100 texture checks a frame. + for (uint64_t r = r0; !untracked && r <= r1 && !changed; r++) { + if (reg_max[r] <= since) continue; + uint64_t a = r << REG_SHIFT > lo ? r << REG_SHIFT : lo, b = (r + 1) << REG_SHIFT < hi ? (r + 1) << REG_SHIFT : hi; + for (; a < b && !changed; a += 1ull << GEN_PAGE_SHIFT) { + uint32_t *s = gen_slot(a, 0); + if (s && *s > since) changed = 1; + } } *now = gen_now; // every observation so far is in the table __atomic_add_fetch(&n_snap_checks, 1, __ATOMIC_RELAXED);