mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 12:59:58 -04:00
Keep only the compute pipelines of recently dispatched shaders from the boot, and build the others into the pipeline cache without keeping them.
The boot prebuild built the pipeline of every compute shader play ever recorded and kept all of them for the process. A pipeline that exists holds driver memory whether or not anything dispatches it: with a history of 4,066 compute shaders they held 2.3 GiB of device memory, and its share of the process's commit, from the title screen on (RTX 5090, NVIDIA 621.01), while a boot into the first village dispatched 95 of them.
The boot now keeps the pipelines of the 512 compute shaders dispatched most recently (compute-used.bin next to pipeline-keys.bin records which run last dispatched each; the setting is compute_keep, with "all" for the earlier behaviour). Every other one is still built at boot, so that the pipeline cache holds it after an update or a driver update, but destroyed at once, and created from the cache at its first dispatch. A dispatch that comes while such a build runs gets that build's pipeline.
Each boot stage now logs the device memory and the process commit it leaves ("mem: boot stage"), and the log says what the first dispatches cost. nx2navi.exe --probe-prewarm runs these stages without the game from the caches next to the executable and times first dispatches of pipelines the boot did not keep: 256 of them took 0.19 ms on average and 3 ms at most, all read from the pipeline cache file, and 372 pipelines built and destroyed at boot left the device memory where it was.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 16a796d623686bca5304eaf1b29981247453a413)
This commit is contained in:
@@ -2682,6 +2682,39 @@ static void outside_watch(uint64_t frame) {
|
||||
last = out, seen = 1;
|
||||
}
|
||||
|
||||
// One line per boot stage (vk_pipeline.c calls it after the pipeline cache load, the shader prewarm, the recorded
|
||||
// pipelines and the compute pipeline prebuild): the device-local memory in use, the part of it VMA did not allocate
|
||||
// (outside_watch's "outside VMA": pipelines and the driver's own, before the swapchain and the upscaler exist), and the
|
||||
// process's commit and working set. Subtracting two lines gives what a stage left behind: with a long play history the
|
||||
// boot's compute pipelines alone held 2.3 GiB of device memory on an RTX 5090 (4,066 pipelines kept, 95 of them
|
||||
// dispatched before the first village), which is what this line was added to place.
|
||||
void vk_mem_stage_log(const char *stage) {
|
||||
VkCtx *c = vk_ctx();
|
||||
double proc, used, limit;
|
||||
float ram_used, ram_total, ws;
|
||||
plat_commit_info(&proc, &used, &limit);
|
||||
plat_mem_info(&ram_used, &ram_total, &ws);
|
||||
const double M = 1048576.0;
|
||||
uint64_t usage = 0, blocks = 0;
|
||||
int budget = c && c->has_memory_budget;
|
||||
if (budget) {
|
||||
VkPhysicalDeviceMemoryBudgetPropertiesEXT bp = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT};
|
||||
VkPhysicalDeviceMemoryProperties2 p2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, .pNext = &bp};
|
||||
vkGetPhysicalDeviceMemoryProperties2(c->phys, &p2);
|
||||
VmaBudget vb[VK_MAX_MEMORY_HEAPS] = {0};
|
||||
if (c->vma) vmaGetHeapBudgets(c->vma, vb);
|
||||
for (uint32_t h = 0; h < c->mem_props.memoryHeapCount && h < VK_MAX_MEMORY_HEAPS; h++)
|
||||
if (c->mem_props.memoryHeaps[h].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
|
||||
usage += bp.heapUsage[h], blocks += vb[h].statistics.blockBytes;
|
||||
}
|
||||
char dev[96] = "device memory unknown (no VK_EXT_memory_budget)";
|
||||
if (budget)
|
||||
snprintf(dev, sizeof dev, "device memory in use %.0f MiB, outside VMA %.0f MiB", usage / M,
|
||||
usage > blocks ? (usage - blocks) / M : 0.0);
|
||||
rt_log("mem: boot stage, after %s: %s; process commit %.0f MB, working set %.0f MB; system commit %.0f of %.0f MB",
|
||||
stage, dev, proc, (double)ws, used, limit);
|
||||
}
|
||||
|
||||
// With NX2NAVI_TRACE=perf every 600 frames: what holds device-local memory, to see what grows over a long session.
|
||||
// VMA's blocks and allocations on the device-local heaps, texture entries with their own memory, the VRAM mirrors and
|
||||
// the objects waiting for their last submission to retire.
|
||||
|
||||
Reference in New Issue
Block a user