From e501ded816c918cb262ab3231470e72d53c7eb04 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Wed, 11 Nov 2026 12:01:40 -0500 Subject: [PATCH] Keep the ASTC decoder's scratch across upload batches and stage its blocks in the staging arena by default. Co-Authored-By: Claude Opus 5.5 --- nx2navi.ini.example | 8 ++++---- runtime/cfg.c | 2 +- runtime/vk_astc.c | 4 +++- runtime/vk_texture.c | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 803d4b2c..7a986be6 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -239,11 +239,11 @@ # texture (0 = the CPU untiles the blocks first). # astc_gpu_deswizzle = 1 # With astc = gpu: 1 keeps the decoder's scratch buffer from one upload batch to the next instead of making it again for -# each, to shorten the hitches when an area loads (0 = one per batch; off until a play test measures it). -# astc_scratch_keep = 0 +# each, to shorten the hitches when an area loads (0 = one per batch). +# astc_scratch_keep = 1 # With astc = gpu: 1 stages a texture's ASTC blocks in the shared staging ranges instead of a buffer of their own -# (0 = a buffer each; off until a play test measures it). -# astc_arena = 0 +# (0 = a buffer each). +# astc_arena = 1 # A render target that needs an image of its own takes the image of a released one of the same size and format # instead of making a new one (0 = always a new image). # tex_reuse = 1 diff --git a/runtime/cfg.c b/runtime/cfg.c index 1c540747..ea35611c 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -290,7 +290,7 @@ static const CfgMeta metas[] = { {"ASTC", "auto", "auto|gpu|native|cpu", RESTART}, {"MEMORY", "auto", "auto|import|mirror|verify", RESTART}, {"TEX_ALIAS", "1", "0|1", RESTART}, {"DEPTH_INIT_INLINE", "1", "0|1", RESTART}, {"DEPTH_ALIAS_LOG", "0", "0|1", RESTART}, {"TEX_DISUSE", "1", "0|1|2", RESTART}, {"TEX_DISUSE_EVICT", "0", "0|1", RESTART}, {"TEX_GEN_UNDO", "1", "0|1", RESTART}, {"TEX_REUSE", "1", "0|1", RESTART}, {"TEX_SPLIT_FILL", "1", "0|1|2", RESTART}, {"TEX_VRAM_PRESSURE", "80", "0..100", RESTART}, {"ASTC_BC", "", "0|1", RESTART}, {"ZSTD_NATIVE", "1", "0|1", RESTART}, {"ZSTD_CHECK", "0", "0|1", RESTART}, {"STG_ARENA", "1", "0|1", RESTART}, {"ASTC_GPU_DESWIZZLE", "1", "0|1", RESTART}, - {"ASTC_SCRATCH_KEEP", "0", "0|1", RESTART}, {"ASTC_ARENA", "0", "0|1", RESTART}, // vk_astc.c scratch_get, vk_texture.c astc_arena + {"ASTC_SCRATCH_KEEP", "1", "0|1", RESTART}, {"ASTC_ARENA", "1", "0|1", RESTART}, // vk_astc.c scratch_get, vk_texture.c astc_arena // render fixes {"LOD_GUARD", "1", "0|1", RESTART}, {"FIX_C0", "1", "0|1", RESTART}, {"FIX_ZERO", "1", "0|1", RESTART}, {"BIND_SKIP", "1", "0|1", RESTART}, {"SHADER_CACHE_FLUSH", "0", "0|1", RESTART}, {"SHADER_MEMO", "1", "0|1", RESTART}, {"PIPE_MEMO", "1", "0|1", RESTART}, {"TEX_MEMO", "1", "0|1", RESTART}, diff --git a/runtime/vk_astc.c b/runtime/vk_astc.c index 9fa16596..a8595c3d 100644 --- a/runtime/vk_astc.c +++ b/runtime/vk_astc.c @@ -444,7 +444,7 @@ static void mem_barrier(VkCommandBuffer cb, VkPipelineStageFlags2 src, VkAccessF static struct { VkBuffer buf; VmaAllocation alloc; VkDeviceSize size; VkCommandBuffer cb; VkDevice dev; uint64_t big_ns; } S; static uint64_t n_scratch_new, n_scratch_reuse; -// NX2NAVI_ASTC_SCRATCH_KEEP=1 (default 0 until a play test measured it): the scratch outlives its upload batch. Every +// NX2NAVI_ASTC_SCRATCH_KEEP=1 (the default): the scratch outlives its upload batch. Every // batch goes to gfx_queue, so the reuse barrier at the start of the next batch's first chunk (vk_astc_record) orders it // after the earlier batches' copies and dispatches, as it does between two textures of one batch; it then also waits // for their writes (WAW). With @@ -452,6 +452,8 @@ static uint64_t n_scratch_new, n_scratch_reuse; // old one (324 in one Kokiri Forest to Hyrule Field run), and one that found no room in a VMA block allocated a new // block on the replay thread during an area load (8-19 ms per block on NVIDIA, vk_headroom.c). A scratch grown past // SCRATCH_MIN for a large texture goes back to SCRATCH_MIN once no texture needed more for SCRATCH_SHRINK_NS. +// On a Kakariko walk at 1440p (2026-11-11) the scratch was made 3 times instead of 60, the walk allocated device memory +// 265 times instead of 342, and NX2NAVI_ASTC=check found 0 of 1920 textures differing from the CPU decode. // 0: a scratch per batch. #define SCRATCH_SHRINK_NS 5000000000ull static int scratch_keep(void) { diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index c9b21a72..f7d1e4de 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -2755,12 +2755,13 @@ static int astc_bl_regions(const Tex *e, uint32_t levels, uint32_t layers, int b return 1; } -// NX2NAVI_ASTC_ARENA=1 (default 0 until a play test measured it): the raw ASTC blocks for the GPU decoder stage in a +// NX2NAVI_ASTC_ARENA=1 (the default): the raw ASTC blocks for the GPU decoder stage in a // range of the staging arena (vk_staging_at) like the other formats, not in a VkBuffer of their own. vk_astc_record // reads its source only through a buffer copy at each region's src, so the range's offset is added to the regions. A // buffer per texture cost a vmaCreateBuffer and, after the batch, a vmaDestroyBuffer each; an area load uploads // thousands. The check mode keeps its own buffer (astc_check reads the blocks at the regions' src offsets). 0: a buffer -// per texture. +// per texture. With the kept scratch, a Kakariko walk at 1440p (2026-11-11) went from 342 device memory allocations +// and 6 frames over 50 ms to 233 and 3. static int astc_arena(void) { static int on = -1; if (on < 0) {