mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 02:49:57 -04:00
Add NX2NAVI_VRAM_BALLAST_MB, video memory taken for the session, to test a smaller card on a large one.
NX2NAVI_VRAM_BUDGET_MB changes only the number the decisions compare with. The ballast takes that much device-local memory right after the allocator is made, in dedicated buffers of 256 MiB, and holds it until the allocator goes, so the driver's own behaviour at its limit (slow allocations, memory moved to system RAM, refusals) shows as on an 8 GB card. Checked on an RTX 5090: 24000 of 24000 MiB taken and held; through eight reloads of Kakariko the use went past the card (32,218 MiB at the end) and Kakariko fell from 118-151 fps in the first four rounds to 10-24 fps in the last four. Texture detail was still chosen as full: the choice reads the driver's budget, which the ballast does not lower. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,7 @@ static const char *const known[] = {
|
||||
"BIND_REUSE", "DYN_DELTA", "STG_ARENA", "SUBMIT_BATCH", "ASTC_GPU_DESWIZZLE", "ASTC_SCRATCH_KEEP", "ASTC_ARENA", "ASTC_BC1",
|
||||
"TEXUP_LOG_MS", "DYN_RES", "DYN_RES_TARGET", "DYN_RES_STEP", "TEXTURE_DETAIL",
|
||||
"RECORDER_CORE", "RECORDER_PRIO", "REPLAY_TIME", "LOCK_TIME", "POOL_CREATE_BUDGET", "POOL_CREATE_MS", "POOL_FINI_IDLE", "POOL_LOAD_BACKLOG", "POOL_LOAD_MS",
|
||||
"VMA_BLOCK_MB", "SYNC_WAKE_ALL", "LOG_ASYNC", "DEVICE_LOST_AT", "STAGING_FAIL_AT",
|
||||
"VMA_BLOCK_MB", "SYNC_WAKE_ALL", "LOG_ASYNC", "DEVICE_LOST_AT", "STAGING_FAIL_AT", "VRAM_BALLAST_MB",
|
||||
"COOP", "COOP_BETA", "COOP_NAME", "COOP_SERVER", "COOP_PORT", "COOP_ROOM", "COOP_AUTO", "COOP_DROP", // co-op (coop.c); the last three have no menu row
|
||||
"COOP_PROGRESS", "COOP_ITEMS", "COOP_SONGS", "COOP_QUEST", "COOP_KEYS", "COOP_RUPEES", "COOP_AMMO", // the room's rules (coop_game.c)
|
||||
"COOP_TEST_SET", // test: sets flags by hash at given frames (coop_game.c); no menu row
|
||||
@@ -144,7 +144,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"WB_FENCE_LIMIT", "diagnostics"}, {"WB_MERGE", "diagnostics"}, {"WB_EXACT", "diagnostics"}, {"MEM_CENSUS", "diagnostics"}, {"WB_NO_REUP", "diagnostics"}, {"WB_PROBE", "diagnostics"}, {"WB_SPLIT", "performance"}, {"SHADOW_BULK_WRITE", "performance"}, {"WB_LAZY", "performance"}, {"HEAP_LAZY", "performance"}, {"BARRIER_GAME", "performance"}, {"MESH_AHEAD", "performance"}, {"MESH_FALLBACK", "performance"}, {"MESH_FALLBACK_MB", "performance"}, {"MESH_FALLBACK_WORKERS", "performance"}, {"WB_LAZY_TOUCH", "diagnostics"}, {"WB_LAZY_CHUNK", "performance"}, {"FLUSH_UPLOAD", "diagnostics"}, {"GPA_TWIN_MAX_KB", "diagnostics"}, {"MIRROR_CAPTURE_KB", "diagnostics"}, {"WB_SKIP_MB", "diagnostics"},
|
||||
{"WB_MERGE_MAX", "diagnostics"}, {"MV_SURVEY", "diagnostics"}, {"TEXUP_LOG_MS", "diagnostics"},
|
||||
{"WAIT_WATCH_S", "diagnostics"},
|
||||
{"VMA_BLOCK_MB", "diagnostics"}, {"DEVICE_LOST_AT", "diagnostics"}, {"STAGING_FAIL_AT", "diagnostics"},
|
||||
{"VMA_BLOCK_MB", "diagnostics"}, {"DEVICE_LOST_AT", "diagnostics"}, {"STAGING_FAIL_AT", "diagnostics"}, {"VRAM_BALLAST_MB", "diagnostics"},
|
||||
};
|
||||
|
||||
// The settings the menu shows: the value in effect when the key is unset, and what the key accepts. The only place a
|
||||
@@ -320,6 +320,7 @@ static const CfgMeta metas[] = {
|
||||
{"ASTC_BC1", "1", "0|1", RESTART}, // vk_astc.c bc1_on
|
||||
{"PASS_CRUMBS", "", "0|1", RESTART}, // vk_crumbs.c pass marks; unset: VK_AMD_buffer_marker only
|
||||
{"STAGING_FAIL_AT", "0", "0..1000000000", RESTART}, // vk_memory.c staging_fail_now: a test of give_back
|
||||
{"VRAM_BALLAST_MB", "0", "0..131072", RESTART}, // vk_memory.c vk_mem_ballast: a test of a smaller card
|
||||
{"DEVICE_LOST_AT", "0", "0..1000000000", RESTART}, // vk_sync.c lost_at_due: a test of the lost device's end
|
||||
{"INPUT_RECORD", "", NULL, RESTART},
|
||||
};
|
||||
|
||||
@@ -394,6 +394,8 @@ uint64_t vk_headroom_release(void); // a refused allocation: the anchors go,
|
||||
// A refused allocation: the staging and snapshot buffers kept for reuse and the headroom's spare blocks go back to the
|
||||
// driver before the caller tries once more (vk_memory.c). Returns the bytes.
|
||||
uint64_t vk_mem_give_back(void);
|
||||
void vk_mem_ballast(VmaAllocator vma); // NX2NAVI_VRAM_BALLAST_MB (test): video memory taken for the session (vk_memory.c)
|
||||
void vk_mem_ballast_release(VmaAllocator vma);
|
||||
VkDeviceSize vk_vma_block_size(void); // VMA's block size on heaps over 1 GiB (NX2NAVI_VMA_BLOCK_MB)
|
||||
int vk_mem_resolve(uint64_t addr, uint64_t size, VkMemSpan *out); // 1 when all of [addr, addr+size) is backed
|
||||
// vk_mem_resolve for a caller that reads guest memory itself or only asks what backs it: with shadow storage the pool
|
||||
|
||||
@@ -537,6 +537,7 @@ static int create_device(void) {
|
||||
.preferredLargeHeapBlockSize = vk_vma_block_size(),
|
||||
.pDeviceMemoryCallbacks = vk_headroom_callbacks()};
|
||||
if ((r = vmaCreateAllocator(&ai, &g_vk.vma)) != VK_SUCCESS) { rt_log("vk: vmaCreateAllocator failed (%d)", (int)r); return 0; }
|
||||
vk_mem_ballast(g_vk.vma);
|
||||
|
||||
VkSemaphoreTypeCreateInfo st = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO,
|
||||
.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE, .initialValue = 0};
|
||||
@@ -561,6 +562,7 @@ static void destroy_all(void) {
|
||||
if (lost_fence) vkDestroyFence(g_vk.device, lost_fence, NULL); // vk_device_lost_poll
|
||||
lost_fence = VK_NULL_HANDLE;
|
||||
vk_headroom_stop();
|
||||
if (g_vk.vma) vk_mem_ballast_release(g_vk.vma);
|
||||
if (g_vk.vma) vmaDestroyAllocator(g_vk.vma);
|
||||
if (g_vk.device) vkDestroyDevice(g_vk.device, NULL);
|
||||
if (g_vk.messenger) {
|
||||
|
||||
@@ -726,6 +726,40 @@ static uint64_t budget_cap(void) {
|
||||
return (uint64_t)mb << 20;
|
||||
}
|
||||
|
||||
// NX2NAVI_VRAM_BALLAST_MB (test; unset or 0: none): that much device-local memory is taken when the allocator is made
|
||||
// and held until it goes, in buffers of BALLAST_PIECE of their own memory. NX2NAVI_VRAM_BUDGET_MB above changes only the
|
||||
// number the decisions compare with; this fills the card for real, so the driver's own behaviour at its limit (slow
|
||||
// allocations, memory moved to system RAM, refusals) shows on a large card as it does on an 8 GB one or beside another
|
||||
// program's use.
|
||||
#define BALLAST_PIECE (256ull << 20)
|
||||
#define BALLAST_MAX 512
|
||||
static VkBuffer ballast_buf[BALLAST_MAX];
|
||||
static VmaAllocation ballast_alloc[BALLAST_MAX];
|
||||
static int nballast;
|
||||
|
||||
void vk_mem_ballast(VmaAllocator vma) { // vk_device.c, right after the allocator is made (before vk_ctx answers)
|
||||
const char *s = cfg_get("NX2NAVI_VRAM_BALLAST_MB");
|
||||
uint64_t want = s && *s && atoll(s) > 0 ? (uint64_t)atoll(s) << 20 : 0, got = 0;
|
||||
if (!want) return;
|
||||
while (got < want && nballast < BALLAST_MAX) {
|
||||
VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
.size = want - got < BALLAST_PIECE ? want - got : BALLAST_PIECE,
|
||||
.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT};
|
||||
VmaAllocationCreateInfo ai = {.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
||||
.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT,
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT};
|
||||
if (vmaCreateBuffer(vma, &bi, &ai, &ballast_buf[nballast], &ballast_alloc[nballast], NULL) != VK_SUCCESS) break;
|
||||
got += bi.size, nballast++;
|
||||
}
|
||||
rt_log("mem: %llu of %llu MiB of video memory taken and held for the session (NX2NAVI_VRAM_BALLAST_MB, a test)",
|
||||
(unsigned long long)(got >> 20), (unsigned long long)(want >> 20));
|
||||
}
|
||||
|
||||
void vk_mem_ballast_release(VmaAllocator vma) { // before the allocator goes
|
||||
for (int i = 0; i < nballast; i++) vmaDestroyBuffer(vma, ballast_buf[i], ballast_alloc[i]);
|
||||
nballast = 0;
|
||||
}
|
||||
|
||||
static int vram_query(uint64_t *used, uint64_t *budget, int *exact) {
|
||||
VkCtx *c = vk_ctx();
|
||||
*used = *budget = 0, *exact = 0;
|
||||
|
||||
Reference in New Issue
Block a user