From 1b48c8dc2c8d0cdd42c7397b47b5f7b071093577 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 3 Nov 2026 12:00:28 +0300 Subject: [PATCH] Encode decoded ASTC to BC3 by default on GPUs with less than 5 GiB of video memory A GPU without ASTC gets the textures decoded to RGBA8, four times the memory of BC3, and on a 4 GiB card that fills video memory: a GTX 1650 went from 10-23 to 3-12 ms of GPU time a frame with astc_bc = 1 (#87). BC3 loses some precision (normal maps), so it stays off where memory is not short. astc_bc unset now turns it on when the largest device-local heap is under 5 GiB and logs the choice; 0 and 1 still decide. The menu row becomes Auto / Off / On, and the description says what Auto does in all four languages. On an RX 9070 nothing changes. The Radeon iGPU on Windows reports its shared 10.5 GiB as device-local, so it keeps RGBA8 as well. All probes pass, probe-astc and probe-cfg included. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 2 +- runtime/ui/menu.cpp | 3 ++- runtime/ui_text.c | 10 +++++----- runtime/vk_astc.c | 13 ++++++++++++- totk.ini.example | 3 +++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index c53dfa49..94e0c883 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -154,7 +154,7 @@ static const CfgMeta metas[] = { {"PIPE_PREBUILD", "1", "0|1", RESTART}, {"PREWARM_XLATE", "", "1..64", RESTART}, {"GPL", "1", "0|1", RESTART}, // textures and memory {"ASTC", "auto", "auto|gpu|native|cpu", RESTART}, {"MEMORY", "auto", "auto|import|mirror|verify", RESTART}, - {"TEX_ALIAS", "1", "0|1", RESTART}, {"TEX_VRAM_PRESSURE", "90", "0..100", RESTART}, {"ASTC_BC", "0", "0|1", RESTART}, {"ZSTD_NATIVE", "1", "0|1", RESTART}, {"ZSTD_CHECK", "0", "0|1", RESTART}, + {"TEX_ALIAS", "1", "0|1", RESTART}, {"TEX_VRAM_PRESSURE", "90", "0..100", RESTART}, {"ASTC_BC", "", "0|1", RESTART}, {"ZSTD_NATIVE", "1", "0|1", RESTART}, {"ZSTD_CHECK", "0", "0|1", RESTART}, // 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_MEMO", "1", "0|1", RESTART}, {"PIPE_MEMO", "1", "0|1", RESTART}, {"TEX_MEMO", "1", "0|1", RESTART}, diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index c27ed223..1d4ad1d7 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -944,7 +944,8 @@ static void tab_advanced(float scale) { opt_choice("TOTK_MEMORY", UI_MENU_MEMORY, mem, 4, UI_MENU_MEMORY_DESC); opt_toggle("TOTK_TEX_ALIAS", UI_MENU_TEX_ALIAS, UI_MENU_TEX_ALIAS_DESC); opt_slider("TOTK_TEX_VRAM_PRESSURE", UI_MENU_TEX_VRAM_PRESSURE, 0, 100, UI_MENU_TEX_VRAM_PRESSURE_DESC, 1, "%.0f%%"); - opt_toggle("TOTK_ASTC_BC", UI_MENU_ASTC_BC, UI_MENU_ASTC_BC_DESC); + static const UiTextId astc_bc[] = {UI_MENU_AUTO, UI_MENU_OFF, UI_MENU_ON}; // unset, 0, 1 + opt_choice("TOTK_ASTC_BC", UI_MENU_ASTC_BC, astc_bc, 3, UI_MENU_ASTC_BC_DESC); opt_group(UI_MENU_GROUP_FIXES); opt_toggle("TOTK_LOD_GUARD", UI_MENU_LOD_GUARD, UI_MENU_LOD_GUARD_DESC); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index cc39efa1..28fff483 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -359,7 +359,7 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_MEMORY_VERIFY] = "Verify", [UI_MENU_TEX_ALIAS] = "Texture aliasing", [UI_MENU_TEX_ALIAS_DESC] = "A new texture created over a live texture's memory starts with that content instead of empty.", [UI_MENU_TEX_VRAM_PRESSURE] = "Texture memory limit", [UI_MENU_TEX_VRAM_PRESSURE_DESC] = "Percent of video memory above which textures the game released are dropped (they come back from storage when used again). 0 keeps them.", - [UI_MENU_ASTC_BC] = "Compress ASTC to BC3", [UI_MENU_ASTC_BC_DESC] = "With the GPU decoder: re-encodes decoded ASTC textures to BC3, a quarter of the video memory. For GPUs with 4 GB or less; textures look slightly blockier.", + [UI_MENU_ASTC_BC] = "Compress ASTC to BC3", [UI_MENU_ASTC_BC_DESC] = "With the GPU decoder: re-encodes decoded ASTC textures to BC3, a quarter of the video memory. Textures look slightly blockier. Auto: on for GPUs with 4 GB of video memory or less.", [UI_MENU_LOD_GUARD] = "LOD guard", [UI_MENU_LOD_GUARD_DESC] = "Prevents objects flashing in the wrong place or a flat far field for a frame, by waiting for the game to finish rewriting level-of-detail data before the GPU reads it.", [UI_MENU_FIX_C0] = "Constant buffer fix", [UI_MENU_FIX_C0_DESC] = "Fills the driver-reserved constant bank c0 (storage sizes, dispatch size, point size, base instance) instead of reading zeros.", @@ -789,7 +789,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_MEMORY_VERIFY] = "Проверка", [UI_MENU_TEX_ALIAS] = "Наследование содержимого текстур", [UI_MENU_TEX_ALIAS_DESC] = "Новая текстура поверх памяти живой текстуры получает её содержимое, а не пустую.", [UI_MENU_TEX_VRAM_PRESSURE] = "Предел памяти текстур", [UI_MENU_TEX_VRAM_PRESSURE_DESC] = "Процент видеопамяти, выше которого освобождённые игрой текстуры удаляются (при повторном использовании загружаются снова). 0 — не удалять.", - [UI_MENU_ASTC_BC] = "Сжатие ASTC в BC3", [UI_MENU_ASTC_BC_DESC] = "С декодером на GPU: декодированные текстуры ASTC пересжимаются в BC3 и занимают вчетверо меньше видеопамяти. Для видеокарт с 4 ГБ и меньше; текстуры чуть более блочные.", + [UI_MENU_ASTC_BC] = "Сжатие ASTC в BC3", [UI_MENU_ASTC_BC_DESC] = "С декодером на GPU: декодированные текстуры ASTC пересжимаются в BC3 и занимают вчетверо меньше видеопамяти. Текстуры чуть более блочные. Авто: включено на видеокартах с 4 ГБ видеопамяти и меньше.", [UI_MENU_LOD_GUARD] = "Защита LOD", [UI_MENU_LOD_GUARD_DESC] = "Не даёт объектам мелькать не на своём месте, а дальнему плану — на кадр становиться плоским: ждёт, пока игра допишет данные уровней детализации, и только потом их читает GPU.", [UI_MENU_FIX_C0] = "Исправление константного буфера", [UI_MENU_FIX_C0_DESC] = "Заполняет зарезервированный драйвером банк констант c0 (размеры хранилищ, размер запуска, размер точки, базовый экземпляр) вместо чтения нулей.", @@ -1140,7 +1140,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_MEMORY_VERIFY] = "Verificar", [UI_MENU_TEX_ALIAS] = "Aliasing de texturas", [UI_MENU_TEX_ALIAS_DESC] = "Uma textura nova criada sobre a memória de uma textura viva começa com esse conteúdo em vez de vazia.", [UI_MENU_TEX_VRAM_PRESSURE] = "Limite de memória de texturas", [UI_MENU_TEX_VRAM_PRESSURE_DESC] = "Porcentagem da memória de vídeo acima da qual as texturas liberadas pelo jogo são descartadas (voltam do armazenamento quando usadas de novo). 0 mantém todas.", - [UI_MENU_ASTC_BC] = "Comprimir ASTC em BC3", [UI_MENU_ASTC_BC_DESC] = "Com o decodificador da GPU: recodifica as texturas ASTC decodificadas em BC3, que ocupa um quarto da memória de vídeo. Para GPUs com 4 GB ou menos; as texturas ficam um pouco mais quadriculadas.", + [UI_MENU_ASTC_BC] = "Comprimir ASTC em BC3", [UI_MENU_ASTC_BC_DESC] = "Com o decodificador da GPU: recodifica as texturas ASTC decodificadas em BC3, que ocupa um quarto da memória de vídeo. As texturas ficam um pouco mais quadriculadas. Automático: ligado em GPUs com 4 GB de memória de vídeo ou menos.", [UI_MENU_LOD_GUARD] = "Proteção de LOD", [UI_MENU_LOD_GUARD_DESC] = "Evita que objetos pisquem no lugar errado ou que o plano distante fique achatado por um quadro, esperando o jogo terminar de reescrever os dados de nível de detalhe antes que a GPU os leia.", [UI_MENU_FIX_C0] = "Correção do buffer de constantes", [UI_MENU_FIX_C0_DESC] = "Preenche o banco de constantes c0 reservado ao driver (tamanhos de armazenamento, tamanho do dispatch, tamanho do ponto, instância base) em vez de ler zeros.", @@ -1715,8 +1715,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { "再次用到时从存储重新加载。0 表示不丢弃。", [UI_MENU_ASTC_BC] = "ASTC 压缩为 BC3", [UI_MENU_ASTC_BC_DESC] = "配合 GPU 解码器使用:把解码后的 ASTC 纹理重新编码为 BC3," - "显存占用只有四分之一。适用于 4 GB 及以下的显卡;" - "纹理会出现轻微色块。", + "显存占用只有四分之一。纹理会出现轻微色块。" + "自动:显存 4 GB 及以下的显卡上开启。", [UI_MENU_LOD_GUARD] = "LOD 保护", [UI_MENU_LOD_GUARD_DESC] = "等待游戏改写完细节层次数据后再让 GPU 读取," "避免物体错位闪现,或远景有一帧变平。", diff --git a/runtime/vk_astc.c b/runtime/vk_astc.c index f4acaa69..0b91e70f 100644 --- a/runtime/vk_astc.c +++ b/runtime/vk_astc.c @@ -298,9 +298,20 @@ static int create_pipeline(VkCtx *c) { } // TOTK_ASTC_BC=1: the BC3 encoder, when the device samples BC3 (every desktop GPU does); 0 leaves ASTC as RGBA8. +// Unset: on when the largest device-local heap is under 5 GiB. There RGBA8 ASTC, four times the size of BC3, fills +// video memory (a GTX 1650 4 GiB went from 10-23 to 3-12 ms of GPU time a frame, issue #87); BC3 loses some precision +// (normal maps), so GPUs with more memory keep RGBA8. static int create_bc_pipeline(VkCtx *c) { const char *e = cfg_get("TOTK_ASTC_BC"); - if (!e || !*e || *e == '0') return 0; + VkDeviceSize vram = 0; + for (uint32_t h = 0; h < c->mem_props.memoryHeapCount && h < VK_MAX_MEMORY_HEAPS; h++) + if (c->mem_props.memoryHeaps[h].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT && c->mem_props.memoryHeaps[h].size > vram) + vram = c->mem_props.memoryHeaps[h].size; + int on = e && *e ? *e != '0' : vram < (5ull << 30); + if (!(e && *e)) + rt_log("vk: TOTK_ASTC_BC unset: BC3 %s (largest device-local heap %llu MiB)", on ? "on" : "off", + (unsigned long long)(vram >> 20)); + if (!on) return 0; VkFormatProperties p; vkGetPhysicalDeviceFormatProperties(c->phys, VK_FORMAT_BC3_SRGB_BLOCK, &p); VkFormatFeatureFlags need = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT; diff --git a/totk.ini.example b/totk.ini.example index e2eb6146..805eff08 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -62,6 +62,9 @@ # ASTC texture decoding: native (the GPU's own ASTC support), gpu (a compute shader), cpu, or auto (native when the GPU # has it, gpu otherwise). # astc = auto +# With astc = gpu: re-encode the decoded ASTC textures to BC3, a quarter of the video memory, textures slightly blockier, +# 0 or 1. Default: on when the GPU has less than 5 GB of video memory, off otherwise. +# astc_bc = 1 # Game memory shared with the GPU: auto (mirror on a discrete GPU, import on an integrated one), import (host memory # imported into Vulkan), mirror (pools used as buffers get a copy in video memory) or verify (mirror plus a check of # every copy; slow). On a discrete GPU import can be far slower than mirror, not slightly slower: the GPU reads the