diff --git a/runtime/vk_backend.c b/runtime/vk_backend.c index 8bf01ce0..27a0e29b 100644 --- a/runtime/vk_backend.c +++ b/runtime/vk_backend.c @@ -106,7 +106,14 @@ void vk_present_drain(void) { // 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}; +// The same hold covers a change of the scene's size (a DLSS or FSR 3.1 mode picked in the menu, vk_dlaa.c +// vk_dlaa_resized_take): the first frames drawn into the game's new, empty scene targets come out dark or black, so the +// previous picture stays for RESIZE_HOLD presents from the first frame of the new size. That is once per change of a +// setting and does not use the allowance. It holds with DLSS Frame Generation too: a present left out is a longer gap +// between two rendered frames to it (its constants and tags are set at the host present, gfx_present.c), and a dark +// frame it is given comes out as several generated ones. +#define RESIZE_HOLD 6 +static struct { int64_t limit_ns, left_ns; uint64_t last_ns, held, runs, shown; int holding, resize_left; } FH = {.limit_ns = -1}; static void frame_hold_refill(uint64_t now) { if (FH.limit_ns < 0) { @@ -129,9 +136,18 @@ int vk_frame_hold_left(void) { 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) { +// 1: this frame is not shown. skipped: the draws it lacks; resized: its scene is the first of a new size. +static int frame_hold(uint32_t skipped, int resized, uint64_t frame) { frame_hold_refill(kern_now_ns()); + if (resized && FH.limit_ns > 0) { + FH.resize_left = RESIZE_HOLD; + rt_log("vk: frame %llu: the scene has a new size after a setting changed; the previous picture stays for %d " + "frames", (unsigned long long)frame, RESIZE_HOLD); + } + if (FH.resize_left) { // beside the allowance: nothing below counts these frames + FH.resize_left--; + return 1; + } int hold = skipped && FH.left_ns > 0 && !vk_dlssg_active(); if (hold && !FH.holding) FH.runs++; if (skipped && !hold) FH.shown++; @@ -167,7 +183,7 @@ 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); - int held = frame_hold(vk_exec_pending_draws_take(), frame); + int held = frame_hold(vk_exec_pending_draws_take(), vk_dlaa_resized_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); diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index b120d055..572f703b 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -1496,6 +1496,9 @@ static void release_kept(const struct Size *making, int all) { making->w, making->h, all ? "after a release" : "larger inputs"); } +// Set when the scene the upscaler runs on has another size than the last one; vk_dlaa_resized_take reads it. +static volatile int32_t size_changed; + static void evaluate(VkExec *ex, const VkExecTarget *dst) { const VkExecTarget *t = &D.color, *z = &D.depth; if (!dst) dst = t; @@ -1510,7 +1513,10 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { } struct Size *e = size_for(cb, w, h, ow, oh); if (!e) return dl_fail("work image creation", 0); - if (e != D.last) D.reset = 1, D.why[0]++, e->chars_ok = 0; // another size's history is from another moment + if (e != D.last) { // another size's history is from another moment + D.reset = 1, D.why[0]++, e->chars_ok = 0; + __atomic_store_n(&size_changed, 1, __ATOMIC_RELEASE); + } // Read once: vk_dlaa_frame runs on the present's thread and can clear fsr_frame while this replay is between the // checks below, which would send the rest of this function to DLSS's path without NGX after all. const int fsr = use_fsr(); @@ -1870,7 +1876,30 @@ static void preset_check(void) { D.preset = p, D.preset_dirty = 1, D.reset = 1; } +// The scene's size after a setting changed (a DLSS or FSR 3.1 mode picked in the menu). The game makes its scene targets +// again at the new size and they start empty, so the first frames drawn into them are wrong: the first one is lit +// without what the frame before it left (a dark scene), and two frames later the scene can be black with the interface +// intact (Ultra Performance and DLAA). Measured by capturing every present over six mode changes, 2026-11-10: bad +// frames 3 and 5 presents after the change, with every other setting the same. evaluate notes a scene of another size; +// vk_dlaa_frame counts the presents since a setting last changed, so a game that draws two sizes in turn holds nothing. +static int setting_presents; // vk_dlaa_frame: presents left in which that counts as a mode change +#define SETTING_PRESENTS 60 + +// vk_backend.c frame_hold, each present after vk_dlaa_frame: 1 once when the scene took a new size after a setting +// changed. The previous picture then stays on screen over the frames described above. +int vk_dlaa_resized_take(void) { + if (!__atomic_exchange_n(&size_changed, 0, __ATOMIC_ACQ_REL) || !setting_presents) return 0; + setting_presents = 0; + return 1; +} + void vk_dlaa_frame(void) { + static unsigned cfg_seen; + static int cfg_known; + unsigned v = cfg_version(); + if (cfg_known && v != cfg_seen) setting_presents = SETTING_PRESENTS; + else if (setting_presents) setting_presents--; + cfg_seen = v, cfg_known = 1; vk_dlaa_swap_img = NULL, vk_dlaa_swap_view = VK_NULL_HANDLE; dlss_mode(); preset_check(); diff --git a/runtime/vk_dlaa.h b/runtime/vk_dlaa.h index f381ac0b..076fb1fc 100644 --- a/runtime/vk_dlaa.h +++ b/runtime/vk_dlaa.h @@ -48,6 +48,8 @@ int64_t vk_dlaa_vram(void); typedef struct VkExec VkExec; void vk_dlaa_pass(VkExec *ex); void vk_dlaa_frame(void); +// 1 once, at the present of the first frame whose scene has a new size after a setting changed (vk_dlaa.c). +int vk_dlaa_resized_take(void); // vk_exec_draw.c, each draw before its fixed state is recorded: notes the scene camera block (vk_dlaa_draw), and moves // the viewport of the scene's draws by the frame's jitter (vk_dlaa_viewport, when the viewport is recorded). void vk_dlaa_draw(VkExec *ex);