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

@@ -300,6 +300,13 @@ keeps per-core data without locks and relies on that, so the host models it (`ru
misses and draws (the module's hash and its Binding decorations) is kept apart and needs no decode; a compute
pipeline created at a dispatch and a mesh shader's first pipeline key decode on that thread, which the memory report
counts. `shader_compress = 0` keeps it plain.
- Room levels: a thread samples every two seconds how much room the card and the system have and turns each into a
level, roomy (over 40% free), normal (over 20%), tight (over 8%) or critical, with five points of hysteresis upward
(`runtime/mem_budget.h`, `mem_budget.c`): the card's from the driver's budget against this process's use, the
system's from the lower of the commit's headroom and the physical memory free. A change is logged, and the memory
report's `mem: system` line ends with both levels. The SPIR-V at rest is compressed after 5 s unused while the system
is tight and after 1 s while it is critical. `mem_budget_test_vram_mb` and `mem_budget_test_ram_mb` pretend a side is
that small, to test what gives memory back on a large machine; they leave the texture cache's own rules alone.
- Allocation: Vulkan Memory Allocator. Debugging: Vulkan validation layers, per-pass frame dumps (`NX2NAVI_DUMP`,
`vk_dump.c`), a sampling profiler (`NX2NAVI_PROFILE`, `tools/prof_report.py`) and a flight recorder
(`NX2NAVI_FLIGHT`). RenderDoc cannot capture, because it hides `VK_EXT_external_memory_host` from the application.