Merge the fix for sunken terrain chunks from pull request #535: a finalize marks stale only the slots its own texture object registered, so a streamed heightmap registered at the storage of the one before it keeps its slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epicmeme546
2026-11-11 11:28:41 -05:00
3 changed files with 18 additions and 2 deletions

View File

@@ -100,7 +100,9 @@ keeps per-core data without locks and relies on that, so the host models it (`ru
(`vk_exec_draw.c pool_sync`); slots that resolve alike share one lookup.
Finalization is retained on registered slots independently of image-cache eviction: a stale CPU-backed descriptor
cannot recreate an image from freed storage or follow newly reused CPU bytes. Registration makes it current again;
finalized descriptors may still follow live GPU-owned content.
finalized descriptors may still follow live GPU-owned content. A finalize marks only the slots its own texture
object registered (by initialization serial): the game initializes and registers the next terrain heightmap at the
storage of the previous one before it finalizes that one (`vk_texture.c vk_texture_release`).
- Shaders: Ampere (SM86) code is lowered to Maxwell (`tools/xlate/AmpereLowering.cs`) and translated to SPIR-V by the
pinned shader translator (`tools/vendor/ryujinx`, 1.3.2) with our patches (`tools/xlate/patches/`), built with .NET 10 NativeAOT as
`nx2navi_xlate.exe` and run as separate processes. Translations are cached on disk; shaders and pipelines seen in

View File

@@ -961,7 +961,16 @@ static int test_textures(pool_t *tpool, pool_t *phys) {
const VkTexImage *renewed = vk_texture_by_id(5, NULL, NULL);
GCHECK(renewed && renewed->format == VK_FORMAT_BC1_RGBA_UNORM_BLOCK && renewed->width == 64 && renewed->height == 48,
"re-registered CPU slot 5 did not resolve its own descriptor");
// A release finalizes only the slots of its own texture object: another texture initialized at the same storage
// with the same parameters before the finalize keeps its slot (vk_texture_release, terrain heightmaps).
tex_t bn = b;
bn.serial = 6;
vk_texture_register(6, &bn, NULL);
vk_texture_release(&b);
const VkTexImage *kept = vk_texture_by_id(6, NULL, NULL);
GCHECK(kept && kept->width == 64 && kept->height == 48 && !vk_texture_by_id(5, NULL, NULL),
"a release finalized slot 6 of another live texture, or left its own slot 5 current");
vk_texture_release(&bn);
// Once the live texture at its storage holds GPU content the storage bytes lack, the finalized CPU slot follows it.
// The live texture is cleared on the GPU and noted as rendered into, as a draw into it would be; the slot's image
// must then show the clear, which neither the storage bytes nor a recreated image of the slot's own descriptor hold.

View File

@@ -3545,11 +3545,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 this texture object registered (its initialization serial): a slot registered with another
// texture initialized at the same storage with the same parameters names that one, which is still live. Ocarina
// streams terrain heightmaps (R32F 260x260) through a fixed set of storage and initializes and registers the next
// chunk's texture there before it finalizes the previous one; finalizing the new registration left the slot stale,
// the draws sampled the zero stand-in, and the chunk was drawn at height zero, tens of metres below the ground.
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 (s->finalized || (uintptr_t)s->t.mem != k.addr || s->t.serial != t->serial) continue;
TexKey sk;
make_key(&s->t, &sk);
if (!memcmp(&sk, &k, sizeof k)) s->finalized = 1, s->ce = NULL, changed = 1;