Frame generation shows its pictures: each drawn frame goes out as a pair, the generated picture once the GPU has drawn the frame and the game's half the smoothed interval later, and the game draws at half the frame limit while it does

vk_backend.c present_pair: both blits are submitted at once (gfx_present.c vk_present_blit_pair, the flip queue of two), the generated picture is presented after a timeline wait on the frame's last submission and not before the pacer's display time, the game's frame after a wait on the value after both blits and half the smoothed interval between generated pictures (factor 0.1) after it, as AMD's frame interpolation swapchain and Savage Wind's present_wait_turn do: spaced by the CPU clock alone both pictures went on screen together under FIFO and G-SYNC. The swapchain gets one image more while frame_gen names a generator, for the two images held at once; the present slots stay at two (each blit waits on the fence of the blit two before, the previous frame's same picture, already shown). The generated picture's blit lays the menu and overlay out, the game's draws them again; colour and FSR 1 run per blit; the flight recorder keeps the game's frames; the generated present carries no present ID. frame_rate.c frame_step_cap_ns halves the limit, 30 drawn at least, while the last frame went out with a generated picture, so menus and fades keep the whole limit; the real-time step follows the game's presents and stays the drawn interval. With frame_gen = off the present path is unchanged. "fg present" log lines give shown and drawn fps and the present intervals (mean, sd, p99, each half of the pair) in the world.

Measured on the RX 9070 and the 7900X on 4 cores, field save, camera turning, 1080p output: limit 120 immediate 117 shown and 60 drawn, intervals 8.34 ms sd 0.16 from generated to game's, 8.38 sd 1.71 back; FIFO at 144 Hz the same at 120, and 141 shown and 72 drawn without a limit; immediate without a limit 169 shown and 86 drawn against 94 drawn with frame_gen = off. Replay-thread cost 0.59-0.65 ms a drawn frame.

The flip queue, the pair blit, the halving rule and the present without an ID follow PR #1089 by xellow78-lgtm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: xellow78-lgtm <336264245+xellow78-lgtm@users.noreply.github.com>
This commit is contained in:
committed 2026-11-20 10:38:58 +03:00
1 parent a7275e6644
commit 451813aa17
9 files changed
+249 -36

No files matched your search

+11 -2
View File
@@ -19,7 +19,8 @@
// 3. vk_fg_generate at the end of the submission that drew the window texture: the optical flow over the HUD-less
// picture, then the interpolation between the last frame and this one, with this frame's window texture as the
// picture with the HUD, into an RGBA8 image holding bytes as the window texture does (sRGB transfer function).
// Presenting it is not done here (TOTK_FG_TEST shows it in place of the frame, for checks only).
// The present (vk_backend.c present_pair) shows it before the frame, through vk_fg_present_gen (TOTK_FG_TEST shows it, or
// the picture before the HUD, in place of the frame instead, for checks only).
#include "vk_fg.h"
#include <malloc.h>
@@ -110,7 +111,8 @@ static struct {
float near_m, far_m, fov_y, dt_ms;
VkFormat win_fmt; // the window texture's format as last seen (UNORM twin)
int k; // the pair of hudless/out images this frame writes
VkImage show_out, show_hl; // the frame just ended (vk_fg_frame), for vk_fg_present_swap
VkImage gen_win; // the window texture this frame's picture was generated against (vk_fg_generate)
VkImage show_out, show_hl, show_win; // the frame just ended (vk_fg_frame), for vk_fg_present_swap / _gen
// images
uint32_t iw, ih;
Img hl_srgb, hl[2], out[2];
@@ -723,6 +725,7 @@ extern "C" int vk_fg_generate(VkCommandBuffer cb, uint64_t fence, uint64_t frame
return 0;
}
g.gen_ok = true;
g.gen_win = win;
g.gens++, g.resets += g.reset;
if (g.gens == 1)
rt_log("fg: first frame generated: %ux%u from a %ux%u scene (near %g m, far %g m, vertical field of view %.1f "
@@ -745,6 +748,7 @@ extern "C" void vk_fg_frame(void) {
if (!g.gen_ok) g.skipped++;
}
g.show_out = g.gen_ok ? g.out[g.k].img : VK_NULL_HANDLE;
g.show_win = g.gen_ok ? g.gen_win : VK_NULL_HANDLE;
g.show_hl = g.hl_ok ? g.hl[g.k].img : VK_NULL_HANDLE;
if (g.hl_ok) g.k ^= 1;
g.chain = g.gen_ok; // a frame without a generated picture breaks the chain: the next one starts over
@@ -779,6 +783,11 @@ extern "C" void vk_fg_exit_log(void) {
(g.prep_run + g.prep_ns) / 1e6 / g.ncpu);
}
extern "C" VkImage vk_fg_present_gen(VkImage presented) {
if (g.test || !g.show_out || presented != g.show_win) return VK_NULL_HANDLE;
return g.show_out;
}
extern "C" int vk_fg_present_swap(VkImage *img, VkFormat *fmt) {
VkImage s = g.test == 1 ? g.show_out : g.test == 2 ? g.show_hl : VK_NULL_HANDLE;
if (!s) return 0;