Files
NX2navi/runtime/vk_gpa.h
chrg6 817737adae Evict idle VRAM mirrors to make room, and ask again for mirrors the budget refused.
A pool whose mirror did not fit the VRAM budget stayed imported for good, however hot, while mirrors nothing had used for minutes kept their memory. Now a new mirror that does not fit takes the room of mirrors no submission synced for 120 submissions, least recently synced first; a pool refused for the budget asks again after 600 submissions; and above the texture pressure threshold (90% of the budget) mirrors idle for 600 submissions go every 8 submissions so the textures get the room. A victim has nothing in the submission being recorded and its GPU writes are already back in guest memory; its device address table pages move back to the imported buffer (vk_gpa_remap_plain) and the mirror is destroyed once the submission is done. It is mirrored again from a whole copy at its next buffer use. NX2NAVI_MIRROR_EVICT=0 turns it off.

Measured with the budget taken as 16 GiB, same route: off, 691 mirrors (910 MiB) and 133 pools refused for the budget; on, 405 mirrors (799 MiB): 240 idle ones (98 MiB, title-screen and loading pools) evicted, 114 pools refused. That exe still evicted idle mirrors under pressure for the textures, which a later commit removes, and asked refused pools again every 16 submissions (1,795 times), which another commit spaces out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 03:34:46 -05:00

29 lines
1.9 KiB
C

// The device address table (vk_gpa.c): GPU address pages to buffer device addresses for shaders' global memory accesses.
#pragma once
#include <stdint.h>
#include "vk.h"
#define VK_GPA_CB_SLOT 0x40 // res.json cb_slot of the table (translator ResourceManager.DeviceAddressTableCbSlot)
int vk_gpa_wanted(void); // the device has buffer device addresses and NX2NAVI_GPA is not 0
int vk_gpa_wanted_ctx(const VkCtx *c); // the same during device creation, before vk_ctx() returns it
int vk_gpa_on(void); // the table exists (created on first use)
uint64_t vk_gpa_device_address(VkBuffer b);
VkDescriptorBufferInfo vk_gpa_info(void); // the whole table, for a storage descriptor
// Maps the pages [lo, hi) holds whole to buf, whose byte 0 is GPU address buf_lo. Returns the record (0: not mapped).
uint32_t vk_gpa_map(uint64_t lo, uint64_t hi, VkBuffer buf, uint64_t buf_lo);
// Unmaps the pages of [lo, hi) that name rec; cover (may be NULL) gives the record of another live buffer that holds a
// page whole, or 0. rec is reused once the GPU finished the submissions issued until now.
void vk_gpa_unmap(uint64_t lo, uint64_t hi, uint32_t rec, uint32_t (*cover)(uint64_t page_addr));
// Unmaps every page of [lo, hi), whatever record it names (pages of a virtual pool whose physical memory goes away).
void vk_gpa_clear(uint64_t lo, uint64_t hi);
// Moves the pages of [lo, hi) that name old_rec (or none) to buf (a pool's VRAM mirror), with old_rec's buffer as their
// twin, which shaders write too; returns the new record.
uint32_t vk_gpa_remap(uint64_t lo, uint64_t hi, uint32_t old_rec, VkBuffer buf, uint64_t buf_lo);
// The same without the twin: the pages name buf alone (a pool whose VRAM mirror is evicted goes back to its imported
// buffer).
uint32_t vk_gpa_remap_plain(uint64_t lo, uint64_t hi, uint32_t old_rec, VkBuffer buf, uint64_t buf_lo);
void vk_gpa_report(void);
void vk_gpa_shutdown(void);