Finalize only the slots a texture object registered itself, so the next streamed piece of ground keeps its heightmap.

Ocarina streams its terrain heightmaps (R32F, 260x260) through a fixed set of storage. It initializes the next piece's texture at the storage of the one before, registers it in the texture pool, and only then finalizes the old texture object, which has the same parameters. vk_texture.c vk_texture_release marked every slot at the storage with the same parameters as finalized, the new registration too. A finalized CPU-written slot takes no image made from its storage again (slot_resolve's stale rule), so the new piece drew the zero stand-in and was drawn at height zero, far below the ground around it: the holes and stretched ground of issues #453 and #569, through which the sky shows. A finalize now marks only the slots registered with its own texture object (the initialization serial); a slot registered with another texture object at the same storage names that one, which is still live.

From pull request #535 by MartinIsla, in its final form, which no longer skips the whole release while another texture with the same parameters is live (that kept textures the game had released and drew dark lines in Kakariko's fog). --probe-vkmem gets the pull request's check: a release leaves another live texture's slot current and marks its own; it fails on the old rule and passes with this one, with and without shadow storage.

Added here: under the perf trace a line every 60 frames counts the slots a finalize marked, the slots of another live texture it left current and the lookups the stale rule answered with the stand-in, the terrain's heightmaps counted apart, so a run shows whether the case comes up and whether stand-ins are still drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 12:18:52 -05:00
parent bdcf07bbf6
commit ae0c8140a2
3 changed files with 40 additions and 3 deletions

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.