Upload a texture again when its ASTC decode had no memory, instead of leaving its image unfilled.

When the decoder's scratch buffer could not be allocated, the upload logged it and still counted the texture as
uploaded. The image of a new texture then held nothing, and nothing uploaded it again until the game next wrote its
storage, which for most textures is never.

vk_astc_record now tells that failure (-1) from the ones that cannot change, and the upload leaves such a texture as
not uploaded: the lookups try it again every 30 frames until a decode succeeds. A WriteTexels whose decode has no
memory is still only logged.

The memory probe forces one failed scratch request and checks that the texture is left alone during its wait, is
uploaded by the first lookup after it and then holds its blocks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 04:48:36 -05:00
parent 147e8a02e3
commit 29eb7cf0a7
5 changed files with 90 additions and 11 deletions

View File

@@ -466,7 +466,12 @@ static int scratch_keep(void) {
// A scratch of at least need bytes for recording into cb; *reused: earlier work (in cb, or with the keep rule in an
// earlier batch) may still use it. 0 on failure.
// A test's hook (vk.h): the next n requests for the scratch buffer fail, as when the video memory is used up.
static volatile int32_t scratch_fail_n;
void vk_astc_scratch_fail(int n) { plat_xchg32(&scratch_fail_n, n); }
static VkBuffer scratch_get(VkCtx *c, VkCommandBuffer cb, VkDeviceSize need, int *reused) {
if (plat_cas32(&scratch_fail_n, 0, 0) > 0 && plat_add32(&scratch_fail_n, -1) >= 0) return VK_NULL_HANDLE;
int keep = scratch_keep();
plat_mutex_lock(&g_lock);
uint64_t now = kern_now_ns();
@@ -573,9 +578,9 @@ int vk_astc_record(VkCommandBuffer cb, VkBuffer src, VkDeviceSize src_size, cons
VkBuffer sb = scratch_get(c, cb, cap_in + cap_out + cap_bc, &reused);
if (!sb) {
if (plat_inc32(&n_fail) <= 16)
rt_log("vk: ASTC scratch buffer of %llu bytes failed: texture left undecoded",
rt_log("vk: ASTC scratch buffer of %llu bytes failed: texture left undecoded for now",
(unsigned long long)(cap_in + cap_out + cap_bc));
return 0;
return -1; // no memory at this moment: the caller tries again later (vk_texture.c upload)
}
plat_mutex_lock(&g_lock);
int need_tab = !G.tab_uploaded;