Hold less device memory that only costs the system's commit: a smaller released-texture cache, no spare blocks while commit is low, large images in memory of their own.

The driver charges device memory to the system's commit. A 32 GB PC lost the device at an area load with the
system at 61 of 65.5 GB committed, the game at 28 GB: 12.35 GB of VRAM in use, of it up to 1.3 GB in released
textures kept for reuse, 0.5 to 1.8 GB free inside VMA's blocks, and a spare 256 MiB block per memory type.
- Released textures keep a thirty-second of the installed memory (512 MiB to 2 GiB) instead of a sixteenth (1 to 4
  GiB); only those released STALE_FRAMES presents ago go, so the transient ones the game takes back stay.
- The headroom thread keeps no spare block while the system's commit is low (vk_texture_commit_low), as it already
  keeps none under VRAM pressure.
- A texture image of 32 MiB or more gets memory of its own (DEDICATED_MIN), so freeing it gives the memory back at
  once instead of leaving a hole in a shared block that the driver counts in full until the block empties.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-09 14:00:12 -05:00
parent 7a15c063ca
commit fbb6783664
3 changed files with 20 additions and 7 deletions

View File

@@ -12,7 +12,8 @@
// a block per memory type is held back.
// Under VRAM pressure no headroom is kept: the spare block counts against the budget that decides whether a pool gets
// its VRAM mirror (vk_memory.c), so while use plus two blocks passes 85% of the budget the anchor goes and nothing new
// is allocated.
// is allocated. Nor while the system's commit is low (vk_texture_commit_low): the driver charges device memory to it,
// and a spare block of each type held up to 256 MiB of it empty when an allocation that failed there ended the game.
// NX2NAVI_VRAM_HEADROOM=0 turns it off.
#include "cfg.h"
@@ -63,6 +64,7 @@ static VkDeviceSize block_size(const VkCtx *c, uint32_t type) {
}
static int room(const VkCtx *c, uint32_t type, VkDeviceSize block) {
if (vk_texture_commit_low()) return 0;
VmaBudget b[VK_MAX_MEMORY_HEAPS];
vmaGetHeapBudgets(c->vma, b);
const VmaBudget *h = &b[c->mem_props.memoryTypes[type].heapIndex];