diff --git a/runtime/vk.h b/runtime/vk.h index 955937ac..93445bb6 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -306,6 +306,7 @@ int vk_mem_vram(uint64_t *used, uint64_t *budget, int *exact); // Bytes the system can still give device memory beyond a reserve (TOTK_MEM_RESERVE_MIB) where device memory takes host // memory: a UMA GPU (commit and physical memory), or a discrete non-NVIDIA GPU on Windows (commit). UINT64_MAX elsewhere. uint64_t vk_mem_host_room(void); +int vk_mem_uma(void); // 1: the device class is uma (vk_mem_class_log), its memory is RAM // VRAM headroom (vk_headroom.c): the VMA callbacks that see new device memory, and the thread that allocates the next // block of each memory type in use ahead of the render thread. const VmaDeviceMemoryCallbacks *vk_headroom_callbacks(void); diff --git a/runtime/vk_astc.c b/runtime/vk_astc.c index ccfa4235..ff0b6028 100644 --- a/runtime/vk_astc.c +++ b/runtime/vk_astc.c @@ -300,17 +300,19 @@ 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. +// (normal maps), so GPUs with more memory keep RGBA8. A UMA GPU's heap is the machine's RAM however large it reads +// (10.6 GiB on an ROG Ally X, 14.9 GiB on a Radeon 880M), so there BC3 is on too: on the RX 9070, BC3 took 737 MiB off +// VMA's device-local allocations after a minute in the field, at the same GPU time. static int create_bc_pipeline(VkCtx *c) { const char *e = cfg_get("TOTK_ASTC_BC"); 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); + int on = e && *e ? *e != '0' : vram < (5ull << 30) || vk_mem_uma(); 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)); + rt_log("vk: TOTK_ASTC_BC unset: BC3 %s (largest device-local heap %llu MiB%s)", on ? "on" : "off", + (unsigned long long)(vram >> 20), vk_mem_uma() ? ", uma: system memory" : ""); if (!on) return 0; VkFormatProperties p; vkGetPhysicalDeviceFormatProperties(c->phys, VK_FORMAT_BC3_SRGB_BLOCK, &p); diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 653ac3ec..2fb547e7 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -645,6 +645,8 @@ uint64_t vk_mem_host_room(void) { return r; } +int vk_mem_uma(void) { return host_backed == HB_UMA; } + // The budget is at most the use plus what the system can still give, so the paths that react to VRAM pressure (the // mirror refusal, released textures, the headroom block) react to a system short of memory too. static void host_cap(uint64_t used, uint64_t *budget) {