From d1bebd34cdf238c0bbaa20e18386f7fff40e0476 Mon Sep 17 00:00:00 2001 From: epicmeme546 <178368684+epicmeme546@users.noreply.github.com> Date: Tue, 10 Nov 2026 04:39:19 -0500 Subject: [PATCH] Keep the previous picture on screen instead of showing a frame that lacks draws, and show the game's own VRAM in the overlay. A draw whose shader or pipeline is still building is left out of its frame, and the frame was shown without it: a black or unlit picture with the interface intact when it was a lighting pass, a light going out, or ground missing for a frame. In a player's session a full-screen draw was skipped after its 50 ms and the frame came out black as a boulder hit. The frame's present is now left out when draws were skipped (vk_backend.c frame_hold, NX2NAVI_FRAME_HOLD_MS, 120 by default, 0 off). The game runs on, so nothing waits. The hold comes from an allowance that fills again at an eighth of the clock's rate, so a long build or a run of them shows its frames as before and does not freeze the picture; a full-screen draw that would be skipped with the allowance spent waits on instead, 500 ms at most. Not with DLSS Frame Generation. On a first walk through a village with no pipeline recorded, 21 of the 23 frames with skipped draws were held back; in the Lost Woods, 7 of 8. The performance overlay: the VRAM line is the card's dedicated memory in use, which counts every program on it: a player read 14.5 GB as the game's while the game held 7.3 GB. The line's third cell now gives what this process holds on the device-local heaps (the driver's budget figure), in place of the GPU clock, which stays where the driver gives no budget. Co-Authored-By: Claude Fable 5.2 --- docs/building.md | 4 +++ docs/releases/v0.6.2.md | 7 +++++ runtime/cfg.c | 5 ++-- runtime/perfmon.c | 7 +++++ runtime/perfmon.h | 6 ++++ runtime/ui/perf_panel.cpp | 4 ++- runtime/vk.h | 2 ++ runtime/vk_backend.c | 59 +++++++++++++++++++++++++++++++++++++-- runtime/vk_exec.h | 4 +++ runtime/vk_exec_draw.c | 26 ++++++++++++++++- runtime/vk_memory.c | 14 ++++++++++ 11 files changed, 132 insertions(+), 6 deletions(-) diff --git a/docs/building.md b/docs/building.md index 9e280ad4..52b611ea 100644 --- a/docs/building.md +++ b/docs/building.md @@ -145,6 +145,10 @@ of them. 93 ms (vertex) and 242 ms (fragment) on average against 0.3 and 0.6 ms from the cache, and a first walk through a village skipped 11,180 draws and made 94 draws wait 5.5 s in all, against 1,605 skipped (1,473 of them in the scene's first frames) and 60 ms of waits with the cache warm. + A frame that still lacks draws when it is presented is not shown: the previous picture stays on screen + (`runtime/vk_backend.c` `frame_hold`, `NX2NAVI_FRAME_HOLD_MS`, an allowance of 120 ms that fills again at an eighth + of the clock's rate). On a first walk through a village with nothing recorded, 21 of the 23 such frames were held + back; in a player's session a hit by a boulder had shown one black frame, its lighting pass skipped after 50 ms. When the driver's shader compiler crashes on a variant (NVIDIA 615.78.08 on an RTX 5080 does, issue #30), `prepare_shaders.py` runs the driver step again with `--warm-shaders`, up to three times, without the variants the driver was building at the crash. `shader-prepare-skip.txt` next to the exe lists them with the GPU and driver diff --git a/docs/releases/v0.6.2.md b/docs/releases/v0.6.2.md index b5f201a9..db871d32 100644 --- a/docs/releases/v0.6.2.md +++ b/docs/releases/v0.6.2.md @@ -22,6 +22,13 @@ Draft notes for the release after 0.6.1. The version number is not decided yet. where it also ends the 20 second start). The game now checks the driver's cache at every start and fills it again in the background by itself, an update fills it again before you play, draws wait a moment for a pipeline that only needs linking instead of being left out, and lighting passes are no longer left out at all. +- A black or unlit frame, or a light or a piece of ground missing for a frame, when something new came on screen (a + hit, a new effect, a new enemy). A draw whose pipeline was not ready in time was left out of that frame, a lighting + pass among them once its 50 ms were spent, and the frame was shown without it. Such a frame is no longer shown: + the previous picture stays for the frame or two it takes, while the game runs on (`frame_hold_ms`, 120 by default; + 0 shows every frame as before). +- The performance overlay's VRAM line counted every program on the graphics card as if it were the game. It now + shows the game's own share beside it (*game 6.8 GB* of 10.4 GB in use, in one measurement). - Textures out of view for 11 seconds at 165 fps (30 seconds were meant) could show a blank stand-in for a few frames when they came back while memory was short. The wait is now two minutes of real time at any frame rate. - Settings menu, mouse: a setting changes only on the two framed arrows beside its value, and the arrows stay in one diff --git a/runtime/cfg.c b/runtime/cfg.c index b8d051c8..e82a85d2 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -47,7 +47,7 @@ static const char *const known[] = { "HDR_EXPOSURE", "HDR_FLARE", "HDR_GAMMA", "HDR_GAME_NITS", "HDR_GRADE", "HDR_HIGHLIGHT_SAT", "HDR_HIGHLIGHTS", "HDR_HUE", "HDR_LIVE", "HDR_PEAK_NITS", "HDR_SATURATION", "HDR_SHADOWS", "HDR_TONEMAP", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD", - "BIG_BUILD_FREE_MB", "BIG_BUILD_MAX_MB", "LIB_PREBUILD_BIG", "LIB_PREBUILD_BIG_BG", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LIB_WARM", "PIPE_LINK_MS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MEM_CENSUS", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST", + "BIG_BUILD_FREE_MB", "BIG_BUILD_MAX_MB", "LIB_PREBUILD_BIG", "LIB_PREBUILD_BIG_BG", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LIB_WARM", "PIPE_LINK_MS", "FRAME_HOLD_MS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MEM_CENSUS", "MENU_LANG", "MENU_SOUND_VOLUME", "MENU_TEST", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_CLICK", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MICROPHONE", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MONITOR", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE", "MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK", "MV_SURVEY", @@ -114,7 +114,7 @@ static const struct { const char *key, *section; } sections[] = { {"POOL_CREATE_MS", "performance"}, {"TIMER_1MS", "performance"}, {"PIPE_WAIT", "performance"}, {"PIPE_SKIP", "performance"}, {"ONESHOT_BUDGET", "performance"}, {"CACHE_DIE", "performance"}, {"ONE_PER_CORE", "performance"}, - {"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"LIB_WARM", "performance"}, {"PIPE_LINK_MS", "performance"}, {"PIPE_PREBUILD", "performance"}, + {"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"LIB_WARM", "performance"}, {"PIPE_LINK_MS", "performance"}, {"FRAME_HOLD_MS", "performance"}, {"PIPE_PREBUILD", "performance"}, {"COMPUTE_KEEP", "performance"}, {"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"}, {"TEX_ALIAS", "performance"}, {"TEX_DISUSE", "performance"}, {"TEX_GEN_UNDO", "performance"}, {"TEX_REUSE", "performance"}, {"TEX_VRAM_PRESSURE", "performance"}, {"TEX_PROC_COMMIT_MB", "performance"}, {"ASTC_BC", "performance"}, {"LOD_GUARD", "performance"}, {"FIX_C0", "performance"}, {"FIX_ZERO", "performance"}, @@ -215,6 +215,7 @@ static const CfgMeta metas[] = { // shaders and pipelines {"PIPE_WAIT", "default", "default|draw", RESTART}, {"PIPE_SKIP", "any", "strict|any|fullscreen", RESTART}, {"PIPE_LINK_MS", "6", "0..100", RESTART}, // vk_exec_draw.c link_budget + {"FRAME_HOLD_MS", "120", "0..500", RESTART}, // vk_backend.c frame_hold {"LIB_PREBUILD", "1", "0|1", RESTART}, {"LIB_PREBUILD_THREADS", "", "1..64", RESTART}, {"LIB_WARM", "1", "0|1|force", RESTART}, // vk_pipeline.c lw_start: the driver's cache of stage libraries, warmed when cold {"PIPE_PREBUILD", "1", "0|1", RESTART}, {"PREWARM_XLATE", "", "1..64", RESTART}, {"GPL", "1", "0|1", RESTART}, diff --git a/runtime/perfmon.c b/runtime/perfmon.c index 9ae8a431..0c1065ba 100644 --- a/runtime/perfmon.c +++ b/runtime/perfmon.c @@ -145,6 +145,9 @@ static uint8_t g_gpu_luid[8]; static int g_gpu_luid_ok; static int g_gpu_bus = -1; static float g_vram_total_mb = -1; +static float (*g_vram_game)(void); + +void perfmon_set_vram_game(float (*used_mb)(void)) { __atomic_store_n(&g_vram_game, used_mb, __ATOMIC_RELEASE); } void perfmon_set_gpu(const char *name, const uint8_t *luid, int pci_bus, float vram_total_mb) { plat_mutex_lock(&g_lock); @@ -308,6 +311,7 @@ static void machine_clear(PerfStats *s) { s->cpu_total_pct = s->cpu_game_pct = s->cpu_temp_c = -1; s->ram_used_mb = s->ram_total_mb = s->ram_game_mb = -1; s->gpu_pct = s->gpu_temp_c = s->gpu_power_w = s->gpu_clock_mhz = s->vram_used_mb = s->vram_total_mb = -1; + s->vram_game_mb = -1; } static void machine_copy(PerfStats *d, const PerfStats *s) { @@ -317,6 +321,7 @@ static void machine_copy(PerfStats *d, const PerfStats *s) { d->ram_used_mb = s->ram_used_mb, d->ram_total_mb = s->ram_total_mb, d->ram_game_mb = s->ram_game_mb; d->gpu_pct = s->gpu_pct, d->gpu_temp_c = s->gpu_temp_c, d->gpu_power_w = s->gpu_power_w; d->gpu_clock_mhz = s->gpu_clock_mhz, d->vram_used_mb = s->vram_used_mb, d->vram_total_mb = s->vram_total_mb; + d->vram_game_mb = s->vram_game_mb; } static void sampler(void *arg) { @@ -343,6 +348,8 @@ static void sampler(void *arg) { plat_mem_info(&s.ram_used_mb, &s.ram_total_mb, &s.ram_game_mb); plat_gpu_load(l, &s.gpu_pct, &s.vram_used_mb); s.vram_total_mb = vram_total; + float (*game)(void) = __atomic_load_n(&g_vram_game, __ATOMIC_ACQUIRE); + if (game) s.vram_game_mb = game(); nvml_sample(&s); adl_sample(&s); plat_mutex_lock(&g_lock); diff --git a/runtime/perfmon.h b/runtime/perfmon.h index 313dfef4..fd0ac1bb 100644 --- a/runtime/perfmon.h +++ b/runtime/perfmon.h @@ -28,6 +28,9 @@ typedef struct { // ADL (AMD) char gpu_name[96]; float gpu_pct, gpu_temp_c, gpu_power_w, gpu_clock_mhz, vram_used_mb, vram_total_mb; + // of vram_used_mb, which counts every program on the card, what this process holds (the driver's figure for + // the device-local heaps, perfmon_set_vram_game); -1 unknown + float vram_game_mb; // per frame, averaged over the last half second: replay (NVN to Vulkan recording), GPU busy time (timestamps; -1 // without them), the render thread's waits for pipeline builds, shader translation and texture uploads, and the // textures uploaded @@ -41,6 +44,9 @@ void perfmon_mode(int mode); // The Vulkan device the game renders on: its name, its LUID (8 bytes; NULL when the driver gives none), its PCI bus // (-1 unknown) and its device-local memory. Before the first perfmon_mode(2). void perfmon_set_gpu(const char *name, const uint8_t *luid, int pci_bus, float vram_total_mb); +// How the sampling thread asks for the device-local memory this process holds, in MB (vk_memory.c +// vk_mem_device_used_mb; negative when the driver does not report it). Called twice a second while the overlay is full. +void perfmon_set_vram_game(float (*used_mb)(void)); // A game frame was presented (perf_present, the render thread, only while the overlay is on): the time since the last // one, the render thread's waits of this frame (PERF_N entries, host.h), its replay time and the running count of // texture uploads. diff --git a/runtime/ui/perf_panel.cpp b/runtime/ui/perf_panel.cpp index 6997742c..5f959a16 100644 --- a/runtime/ui/perf_panel.cpp +++ b/runtime/ui/perf_panel.cpp @@ -93,7 +93,9 @@ void machine_and_frames(const PerfPanel *p, float scale) { label(UI_MENU_OV_VRAM); cell(UI_MENU_OV_FMT_GB, gb(s.vram_used_mb)); cell(UI_MENU_OV_FMT_GB_OF, gb(s.vram_total_mb)); - cell(UI_MENU_OV_FMT_MHZ, s.gpu_clock_mhz); + // the card's figure counts every program on it: this game's own share beside it, the clock where that is unknown + if (s.vram_game_mb >= 0) cell(UI_MENU_OV_GAME_GB, gb(s.vram_game_mb)); + else cell(UI_MENU_OV_FMT_MHZ, s.gpu_clock_mhz); label(UI_MENU_OV_CPU); cell(UI_MENU_OV_FMT_PCT, s.cpu_total_pct); cell(UI_MENU_OV_FMT_TEMP, s.cpu_temp_c); diff --git a/runtime/vk.h b/runtime/vk.h index 0c330abb..37b4d80b 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -342,6 +342,8 @@ void vk_mem_class_log(const VkPhysicalDeviceProperties *p, const VkPhysicalDevic int vk_mem_class_of(uint64_t addr); // VK_MCLS_* of the pool at addr (NONE when unbacked) void vk_mem_census(uint64_t frame); // at each present: pool census and traffic, logged at frame 1800 and, // with NX2NAVI_TRACE=perf, every 1800 frames +float vk_mem_device_used_mb(void); // device-local memory this process holds (the driver's budget + // figure), MB; -1 without VK_EXT_memory_budget. Any thread. void vk_mem_stage_log(const char *stage); // one line after a boot stage: device memory, process commit // VRAM in use and its budget, summed over the DEVICE_LOCAL heaps. exact 1: VK_EXT_memory_budget (the whole process), // 0: this allocator's own allocations against the heap sizes. 0 when unknown. diff --git a/runtime/vk_backend.c b/runtime/vk_backend.c index 4533f0c4..8bf01ce0 100644 --- a/runtime/vk_backend.c +++ b/runtime/vk_backend.c @@ -26,6 +26,7 @@ #include "gfx.h" #include "host.h" #include "nvn_api.h" +#include "perfmon.h" #include "vk.h" #include "vk_exec.h" #include "platform/platform.h" @@ -97,11 +98,64 @@ void vk_present_drain(void) { perf_end(PERF_DRAIN, p0); } +// NX2NAVI_FRAME_HOLD_MS (default 120; 0 = off): a frame whose draws were skipped because a shader or pipeline was +// still building (vk_exec_draw.c pending_draws) is not shown: the previous picture stays on screen until a frame is +// complete again. Such a frame lacks what was skipped, which showed for a frame or two as a black or unlit picture with +// the interface intact (a lighting pass), a light going out, or ground and walls missing and then back. The game runs +// on meanwhile, so nothing waits. The hold comes from an allowance of this many milliseconds, used up by the time +// held and filled again at an eighth of the clock's rate: a pipeline that takes longer, or a run of them on a first +// visit with nothing recorded, shows its incomplete frames as before and does not freeze the picture. Not with DLSS +// Frame Generation, which is told about every frame. +static struct { int64_t limit_ns, left_ns; uint64_t last_ns, held, runs, shown; int holding; } FH = {.limit_ns = -1}; + +static void frame_hold_refill(uint64_t now) { + if (FH.limit_ns < 0) { + long long ms = cfg_int("NX2NAVI_FRAME_HOLD_MS"); + FH.limit_ns = (int64_t)(ms < 0 ? 0 : ms > 500 ? 500 : ms) * 1000000; + FH.left_ns = FH.limit_ns, FH.last_ns = now; + if (FH.limit_ns) + rt_log("vk: a frame with draws skipped for a pipeline is not shown, the previous picture stays up to %lld ms " + "(NX2NAVI_FRAME_HOLD_MS)", (long long)(FH.limit_ns / 1000000)); + } + if (!FH.holding) FH.left_ns += (int64_t)(now - FH.last_ns) / 8; + else FH.left_ns -= (int64_t)(now - FH.last_ns); + if (FH.left_ns > FH.limit_ns) FH.left_ns = FH.limit_ns; + FH.last_ns = now; +} + +// Whether a frame that skipped draws now would be held (vk_exec_draw.c: a full-screen draw is skipped only then). +int vk_frame_hold_left(void) { + frame_hold_refill(kern_now_ns()); + return FH.left_ns > 0 && !vk_dlssg_active(); +} + +// 1: this frame is not shown. skipped: the draws it lacks. +static int frame_hold(uint32_t skipped, uint64_t frame) { + frame_hold_refill(kern_now_ns()); + int hold = skipped && FH.left_ns > 0 && !vk_dlssg_active(); + if (hold && !FH.holding) FH.runs++; + if (skipped && !hold) FH.shown++; + FH.holding = hold; + if (hold) FH.held++; + static uint64_t logged_at, logged_held, logged_shown; + if (!hold && FH.held + FH.shown != logged_held + logged_shown && frame - logged_at >= 600) { + rt_log("vk: frame %llu: %llu frames with skipped draws held back so far in %llu runs, %llu shown incomplete " + "(allowance used up)", (unsigned long long)frame, (unsigned long long)FH.held, + (unsigned long long)FH.runs, (unsigned long long)FH.shown); + logged_at = frame, logged_held = FH.held, logged_shown = FH.shown; + } + if (hold && (rt_trace & RT_TRACE_PRESENT)) + rt_log("present: frame %llu held back, %u draws skipped", (unsigned long long)frame, skipped); + return hold; +} + // The present after the frame count: resolves the image and hands the blit to the present thread. queued: when the game // presented; value: the timeline value queued for this present (asynchronous replay), 0 for the next one (synchronous). static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uint64_t queued, uint64_t frame, uint64_t value) { static volatile int32_t n_skipped; + static int vram_probe; + if (!vram_probe) vram_probe = 1, perfmon_set_vram_game(vk_mem_device_used_mb); // the overlay's "game" beside VRAM vk_exec_frame_log(t, frame); dynres_frame(); // before vk_dlaa_frame reads the DLSS mode it may override vk_dlaa_frame(); @@ -113,8 +167,9 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin if (vk_dump_armed) vk_dump_present(frame); __atomic_store_n(&gfx_counters.validation_errors, (uint64_t)vk_validation_errors_total(), __ATOMIC_RELAXED); const VkTexImage *img = vk_texture_get(t); - if (!img || !(img->aspect & VK_IMAGE_ASPECT_COLOR_BIT)) { - if (plat_inc32(&n_skipped) <= 8) + int held = frame_hold(vk_exec_pending_draws_take(), frame); + if (held || !img || !(img->aspect & VK_IMAGE_ASPECT_COLOR_BIT)) { + if (!held && plat_inc32(&n_skipped) <= 8) rt_log("vk: present of texture %p (format %#x) skipped: no colour image", (const void *)t, t ? t->d.format : 0); if (value) { // the queued value is still signalled, in order vk_present_drain(); diff --git a/runtime/vk_exec.h b/runtime/vk_exec.h index 4ddaba8f..2392a342 100644 --- a/runtime/vk_exec.h +++ b/runtime/vk_exec.h @@ -185,6 +185,10 @@ extern VkExecFrame vk_exec_frame; void vk_exec_frame_written(const tex_t *t); // vk_texture_gpu_written: t rendered or copied into uint64_t vk_exec_recording_fence(void); // fence of the submission this thread records, else 0 void vk_exec_frame_log(const tex_t *presented, uint64_t frame); +// The draws skipped since the last call because a shader or pipeline was still building (vk_exec_draw.c), and whether +// a frame lacking them would be held back at its present (vk_backend.c frame_hold). +uint32_t vk_exec_pending_draws_take(void); +int vk_frame_hold_left(void); // NX2NAVI_DUMP= (vk_dump.c): between presents frame-1 and frame, every pass's targets and every dispatch's storage // images are copied out and written as PNGs to NX2NAVI_DUMP_DIR (default "dump"), with passes.txt (targets, pipelines, diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index a244f328..a0342f1c 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -3254,7 +3254,9 @@ static void foliage_shadow_cull(const VkExec *ex, VkPipeState *s) { // Full-screen draws into such passes wait from their budget of 50 ms a presented frame. The default: a skipped // full-screen draw is a lighting, fog or tone mapping pass that leaves its target as it was, which shows as a black // or unlit frame with the interface intact, and with the stage libraries in the driver's cache the wait is a -// millisecond (vk_pipeline.c lw_start keeps them there). +// millisecond (vk_pipeline.c lw_start keeps them there). One that is skipped once its budget is spent leaves a frame +// that is not shown (vk_backend.c frame_hold); where that cannot hold the picture any longer, the draw waits on +// (FULLSCREEN_LAST_MS). // fullscreen (2): as any, and full-screen draws into such passes are skipped instead of waiting from their // budget. A full-screen pass whose stage libraries are cold in the driver cache took 86 ms on average (up to 194 ms) // in a fight on an RX 9070: three frames in a row each spent the 50 ms budget, and some of the draws were skipped @@ -3285,6 +3287,9 @@ static int pipe_skip_mode(void) { // this much and no more. Measured on an RX 7900 XT, first walk through a village with no pipeline recorded: 2,349 // draws skipped without the budget, with the libraries warm in both runs. #define LINK_DRAW_MS 3u +// How long a full-screen draw waits on for its pipeline once its frame budget is spent and the previous picture +// cannot be held any longer (prepare_draw_ex): the longest optimised build of such a pipeline measured was 194 ms. +#define FULLSCREEN_LAST_MS 500u static uint64_t *link_budget(void) { static uint64_t frame = ~0ull, left, per_frame = ~0ull; if (per_frame == ~0ull) { @@ -3384,8 +3389,19 @@ static void draw_stats_tick(void) { DRS.frame = f; } +// The draws skipped since the last present because their shader or pipeline was still building: the picture of that +// frame lacks them (a light, a wall, a whole lighting pass). vk_backend.c frame_hold reads it at the present and keeps +// the previous picture on screen instead. Written and read on the replay thread. +static uint32_t pending_draws; +uint32_t vk_exec_pending_draws_take(void) { + uint32_t n = pending_draws; + pending_draws = 0; + return n; +} + static int draw_skipped(const VkExec *ex, int mesh, int why) { DRS.skipped[mesh][why]++; + if (why == SK_SHADER_PENDING || why == SK_PIPE_PENDING) pending_draws++; if (!(DRS.first[mesh] >> why & 1)) { DRS.first[mesh] |= 1u << why; rt_log("vk: first %s draw skipped because: %s (program %llu)", mesh ? "mesh" : "vertex", sk_names[why], @@ -3553,6 +3569,14 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int p = vk_pipeline_graphics_async(&s, &info, &pending, ONESHOT_WAIT_MS); } } + // A full-screen draw still pending after its budget: skipped, it leaves the frame black or unlit. While the + // previous picture can stay on screen in its place (vk_frame_hold_left) that is what happens; once that time + // is used up the draw waits on, FULLSCREEN_LAST_MS at most, so that no such frame is shown. + if (pending && budget == &wait_left_ns && !vk_frame_hold_left()) { + why = "full-screen, nothing left to hold the picture"; + if (!w0) w0 = kern_now_ns(); + p = vk_pipeline_graphics_async(&s, &info, &pending, FULLSCREEN_LAST_MS); + } PM.valid = !pending && p && info; if (PM.valid) PM.s = s, PM.info = info; } diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index 0135a0df..75259b85 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -2682,6 +2682,20 @@ static void outside_watch(uint64_t frame) { last = out, seen = 1; } +// The overlay's "game" figure beside the card's memory in use (perfmon.c, its sampling thread): what the driver +// counts for this process on the device-local heaps, the same figure vram_use_log splits by use. +float vk_mem_device_used_mb(void) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_memory_budget) return -1; + 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); + uint64_t usage = 0; + 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]; + return (float)(usage / 1048576.0); +} + // 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