mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 16:49:58 -04:00
Add texture compaction behind NX2NAVI_TEX_COMPACT, off by default.
With the setting on, textures no shader sampled for ten seconds are copied on the GPU out of the emptiest allocator blocks into the holes of fuller ones, so the emptied blocks go back to the driver. A pass starts when the free space inside the device-local blocks reaches NX2NAVI_TEX_COMPACT_MIN_MB (one block under VRAM pressure) and the block table has blocks that hold nothing but such textures, with room elsewhere for what moves. It takes at most four textures and NX2NAVI_TEX_COMPACT_FRAME_MB a frame, and none in a frame that loads an area, already made or uploaded textures, or follows a long one. A released texture the size cap would drop is dropped instead of moved. Only a texture whose image holds what the game's memory holds moves: uploaded, never written by the GPU, single sampled, not depth. The entry takes the new image under the texture lock and its address generation moves, so every slot, pool descriptor and memo resolves again. The old image and its views stay until the texture pool has taken every set of its ring and the GPU is past the submissions recorded until then, as a retired texture's do. Each pass logs what it moved and dropped, the blocks and bytes given back, and the time it took. A block emptied of textures that the allocator keeps is left alone for ten minutes, and a pass that gave nothing back doubles the wait. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -98,10 +98,19 @@ static void VKAPI_PTR on_allocate(VmaAllocator a, uint32_t type, VkDeviceMemory
|
||||
plat_event_set(&H.ev);
|
||||
}
|
||||
|
||||
// NX2NAVI_TEX_COMPACT: every device memory VMA gives back to the driver is reported to the texture compaction, which
|
||||
// counts the blocks its pass emptied (vk_texture.c vk_texture_block_freed). Any thread; the callback takes no lock.
|
||||
static void VKAPI_PTR on_free(VmaAllocator a, uint32_t type, VkDeviceMemory m, VkDeviceSize size, void *user) {
|
||||
(void)a, (void)type, (void)size, (void)user;
|
||||
vk_texture_block_freed((uint64_t)(uintptr_t)m);
|
||||
}
|
||||
|
||||
const VmaDeviceMemoryCallbacks *vk_headroom_callbacks(void) {
|
||||
static const VmaDeviceMemoryCallbacks cb = {.pfnAllocate = on_allocate};
|
||||
static const VmaDeviceMemoryCallbacks cb_free = {.pfnAllocate = on_allocate, .pfnFree = on_free};
|
||||
const char *v = cfg_get("NX2NAVI_VRAM_HEADROOM"); // empty is unset: the key has no settings row for cfg_bool
|
||||
H.on = !v || !*v || cfg_bool("NX2NAVI_VRAM_HEADROOM");
|
||||
if (vk_texture_compact_on()) return &cb_free; // on_allocate does nothing for the headroom while H.on is 0
|
||||
return H.on ? &cb : NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user