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:
chrg6
2026-11-12 22:32:33 -05:00
parent d668a62854
commit ec9dd522b1
8 changed files with 502 additions and 7 deletions

View File

@@ -328,6 +328,20 @@
# which game memory gets no copy in video memory (memory = mirror), which costs far more frame time than a texture
# uploaded again. 0: textures never give way for video memory.
# tex_vram_pressure = 80
# Texture compaction (experimental). Video memory is taken in blocks (vma_block_mb), and a block goes back to the
# driver only once everything in it is freed: after a long session the blocks hold textures scattered between holes,
# and the game holds a gigabyte or two of video memory it does not use. 1: textures no shader sampled for ten seconds
# are copied on the GPU out of the emptiest blocks into the holes of fuller ones, a few per frame and only in frames
# with time to spare, so those blocks go back. Nothing on screen moves and nothing is loaded again. The log's
# "mem: holes" line says how much there is to gain, a "texture compaction: pass" line what each pass gave back.
# 0, the default: off. Read at start.
# tex_compact = 0
# The free space inside the blocks, in MiB (64 to 65536), from which a compaction pass starts; one block's worth while
# video memory is above tex_vram_pressure. Default: 256. Read at start.
# tex_compact_min_mb = 256
# The texture memory a compaction moves per frame at most, in MiB (1 to 32); a texture larger than this never moves.
# Default: 8. Read at start.
# tex_compact_frame_mb = 8
# Low-end GPU mode (experimental; also in the settings menu's Game tab). For older graphics cards, and ones short of
# video memory: 1 turns on the settings written for them and measured on a Radeon RX 580, for every key below that
# this file does not set itself. Mesh shaders run as compute where the card has none (mesh_emulation), video memory