mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 01:49:59 -04:00
Keep a texture's slots current when the game finalizes another texture with the same parameters at its storage, which left streamed terrain heightmaps stale and drew those chunks at height zero, far below the ground (issue #453).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2523,7 +2523,17 @@ void vk_texture_gpu_written(const tex_t *t) {
|
||||
unlock();
|
||||
}
|
||||
|
||||
void vk_texture_release(const tex_t *t) {
|
||||
uint32_t vk_texture_reg_mark(void) { return __atomic_load_n(®_serial, __ATOMIC_ACQUIRE); }
|
||||
|
||||
int vk_texture_same_key(const tex_t *a, const tex_t *b) {
|
||||
TexKey ka, kb;
|
||||
make_key(a, &ka), make_key(b, &kb);
|
||||
return !memcmp(&ka, &kb, sizeof ka);
|
||||
}
|
||||
|
||||
void vk_texture_release(const tex_t *t) { vk_texture_release_at(t, vk_texture_reg_mark()); }
|
||||
|
||||
void vk_texture_release_at(const tex_t *t, uint32_t mark) {
|
||||
if (!t || !t->mem) return;
|
||||
TexKey k;
|
||||
make_key(t, &k);
|
||||
@@ -2532,11 +2542,16 @@ void vk_texture_release(const tex_t *t) {
|
||||
// Staleness belongs to the registered descriptor, not the cached image: a released Tex can be destroyed before the
|
||||
// slot looks again (eviction, the released cap, start_at for a mirrored one). A registered texture may also be
|
||||
// finalized before its image is created.
|
||||
// Only the slots registered before the game finalized the texture (mark): the asynchronous replay applies a
|
||||
// release behind the submissions queued before it (vk_backend.c vk_be_texture_release), while a registration takes
|
||||
// effect at once. A texture the game initializes at the same storage with the same parameters after the finalize,
|
||||
// and registers before the replay reaches the release, keeps its slot.
|
||||
int changed = 0;
|
||||
if (sinfo)
|
||||
for (int id = bucket_head[agen_idx(k.addr)]; id >= 0; id = slot_next[id]) {
|
||||
TexSlot *s = &tslots[id];
|
||||
if (s->finalized || (uintptr_t)s->t.mem != k.addr) continue;
|
||||
if ((int32_t)((uint32_t)(sinfo[id] >> 16) - mark) > 0) continue; // registered after the finalize
|
||||
TexKey sk;
|
||||
make_key(&s->t, &sk);
|
||||
if (!memcmp(&sk, &k, sizeof k)) s->finalized = 1, s->ce = NULL, changed = 1;
|
||||
@@ -2605,7 +2620,7 @@ void vk_texture_register(int id, const tex_t *t, const view_t *v) {
|
||||
s->ce = NULL;
|
||||
s->cheld = 0;
|
||||
slots_gen++;
|
||||
if (!++reg_serial) reg_serial = 1;
|
||||
__atomic_store_n(®_serial, reg_serial + 1 ? reg_serial + 1 : 1, __ATOMIC_RELEASE); // read by vk_texture_reg_mark
|
||||
__atomic_store_n(&sinfo[id], (uint64_t)reg_serial << 16 | agen_idx((uintptr_t)t->mem), __ATOMIC_RELEASE);
|
||||
slot_rebucket(id, agen_idx((uintptr_t)t->mem));
|
||||
dirty_push((uint32_t)id);
|
||||
|
||||
Reference in New Issue
Block a user