Add mem_budget: one place that says how much room the card and the system have.

A thread samples every two seconds the video memory budget against this process's use (vk_mem_vram) and the system's
commit headroom and free physical memory (plat_commit_info, plat_mem_info), and turns each side into a level: roomy,
normal, tight or critical, with five points of hysteresis upward and a 256 MiB floor. Changes are logged, and the
memory report's system line ends with both levels. MEM_BUDGET_TEST_VRAM_MB and MEM_BUDGET_TEST_RAM_MB pretend a side
is that small, so that what gives memory back can be tried on a large machine; the texture cache's rules are unchanged.
tests/mem_budget_check.py checks the levels and the hysteresis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 07:53:47 -05:00
parent 3573a96f46
commit 0c153c124e
8 changed files with 321 additions and 2 deletions

View File

@@ -18,6 +18,7 @@
#include "gfx.h"
#include "host.h"
#include "logq.h"
#include "mem_budget.h"
#include "mem_growth.h"
#include "nvn_api.h"
#include "nvn_pool_index.h"
@@ -5528,6 +5529,9 @@ static void system_log(uint64_t frame, const ReportFig *f, const VkPipeMem *pm,
"%.0f, %s) + other %.0f (the driver's own memory, thread stacks, the program's data; %u other heaps)",
pcache / M, pm->cache[0] / M, pm->cache[1] / M, pm->cache_asked ? "as last asked" : "as loaded at the boot",
other / M, hi.other_heaps);
char room[160];
mem_budget_text(room, sizeof room); // the levels the owners that give memory back go by (mem_budget.h)
mg_put(line, sizeof line, &k, "; room: %s", room);
rt_log("%s", line);
*out = (SysFig){priv, crt, shaders, pipes, texhost, pcache, other > 0 ? (uint64_t)other : 0};
}