mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 21:05:56 +00:00
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>
85 lines
5.6 KiB
C
85 lines
5.6 KiB
C
// AMD FSR 3 frame generation (vk_fg.cpp): the FidelityFX SDK 1.1.4's frame interpolation and optical flow
|
|
// (third_party/FidelityFX, MIT) on its Vulkan backend. Plain C interface: the SDK is C++.
|
|
//
|
|
// The frame's inputs come from the replay (vk_dlaa.c follows the scene for it, with DLSS off): at the scene's end the
|
|
// camera motion vectors and the SDK's prepare step (vk_fg_prepare), before the HUD's first draw the picture without
|
|
// the HUD (vk_fg_hudless), at the end of the submission that copied the picture into the window texture the optical
|
|
// flow and the interpolation (vk_fg_generate). All of it goes into the replay's command buffer.
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// The frame generator frame_gen names (TOTK_FRAME_GEN, read at start): off, or AMD FSR 3 on the FidelityFX SDK. The
|
|
// one place that reads the string; an unknown value is off.
|
|
typedef enum { VK_FG_OFF, VK_FG_FSR3 } VkFgEngine;
|
|
VkFgEngine vk_fg_engine(void);
|
|
// vk_device.c, after the device exists: with frame_gen = fsr3 makes the shared backend, the optical flow and the
|
|
// frame interpolation contexts and logs one line; otherwise does nothing.
|
|
void vk_fg_init(void);
|
|
// 1 while the contexts exist.
|
|
int vk_fg_active(void);
|
|
// vk_device.c destroy_all, before the device goes away; harmless when nothing was made.
|
|
void vk_fg_release(void);
|
|
|
|
// vk_dlaa.c vk_dlaa_frame, once per present: 1 when frame generation follows the scene in the next frame. 0 while
|
|
// DLSS runs (dlss), with replay workers or sync_ahead = 1 (the inputs are per frame and recorded in replay order),
|
|
// with HDR output, or while the game shows a menu without its world (vk_fg_menu); each reason is logged once.
|
|
int vk_fg_wanted(int dlss);
|
|
// vk_dlaa.c, the game's thread at each present: 1 while the map or a loading or event fade is open (sampled there,
|
|
// read by vk_fg_wanted).
|
|
void vk_fg_menu(int open);
|
|
|
|
// What the scene end hands over: this frame's depth and camera motion, and the camera.
|
|
typedef struct {
|
|
VkImage depth, mv; // D32F scene depth (level 0, layer 0) and RG16F camera motion, w x h, GENERAL: last
|
|
// frame's window position minus this frame's, scene pixels (vk_dlaa.c mv_pass)
|
|
uint32_t w, h; // the scene's size
|
|
uint32_t ow, oh; // the output's (the window texture's)
|
|
float near_m, far_m, fov_y; // the camera's planes (far 0: none) and vertical field of view (radians)
|
|
int inverted, infinite; // device depth 1 is the near plane; the far plane is at infinity
|
|
float pos[3], up[3], right[3], fwd[3]; // the camera in world space
|
|
int reset; // no history: no camera motion this frame, or a cut (vk_fg_camera)
|
|
} VkFgScene;
|
|
// The camera from the scene's uniform block rows 0-10 (view 3x4, view-projection, projection, row-major, as in
|
|
// vk_dlaa.c note_camera's block), the NVN depth mode (minus_w: clip z -w..w) and the viewport depth range dr: fills s's
|
|
// camera fields. Returns 1 at a cut against the last call (over 10 m or 35 degrees, as Savage Wind's frame
|
|
// generation tests it), else 0.
|
|
int vk_fg_camera(const float *rows, int minus_w, const float dr[2], VkFgScene *s);
|
|
// Records the SDK's prepare (dilated depth and motion) into cb, recorder drained here. Makes the contexts again when
|
|
// the sizes, the depth convention or the window texture's format changed. 1: done; 0: frame generation off this
|
|
// frame (logged).
|
|
int vk_fg_prepare(VkCommandBuffer cb, const VkFgScene *s);
|
|
// The picture before the HUD: src (level, layer) copied, sRGB-encoded as the game's last draw encodes it into the
|
|
// window texture, into an RGBA8 image of the SDK's. No pass open, earlier writes visible (vk_exec_barrier).
|
|
int vk_fg_hudless(VkCommandBuffer cb, VkImage src, VkFormat fmt, uint32_t level, uint32_t layer, uint32_t w, uint32_t h);
|
|
// The optical flow and the interpolation into cb, after the frame's last draw into the window texture win (fmt, w x h,
|
|
// GENERAL, level 0); fence: the submission's timeline value, frame: the present this frame will be (TOTK_FG_SHOT).
|
|
// 1: a frame between the last one and this was made.
|
|
int vk_fg_generate(VkCommandBuffer cb, uint64_t fence, uint64_t frame, VkImage win, VkFormat fmt, uint32_t w,
|
|
uint32_t h);
|
|
// GPU timestamps of the frame's steps (TOTK_FG_TIMES, default on with frame generation): FG_T_MV0 resets the frame's
|
|
// slot, so it comes first in the frame.
|
|
enum { FG_T_MV0, FG_T_MV1, FG_T_PREP0, FG_T_PREP1, FG_T_HL0, FG_T_HL1, FG_T_FI0, FG_T_FI1, FG_T_N };
|
|
void vk_fg_mark(VkCommandBuffer cb, int which);
|
|
void vk_fg_cpu(uint64_t ns); // replay-thread time the frame generation recording took, added to the frame's
|
|
// vk_dlaa.c vk_dlaa_frame, each present before the frame state is cleared: the frame's counts and times.
|
|
void vk_fg_frame(void);
|
|
void vk_fg_exit_log(void); // vk_backend.c gfx_exit_log: the run's counts and times, once
|
|
// vk_backend.c present_image (testing, TOTK_FG_TEST): 1 = the frame's generated picture, 2 = its picture before the
|
|
// HUD in place of the window texture (*img, *fmt). 0: the present is left as it is.
|
|
int vk_fg_present_swap(VkImage *img, VkFormat *fmt);
|
|
// vk_backend.c present_image, after vk_dlaa_frame: the picture generated between the last frame and the one just
|
|
// ended, when presented is the window texture it was generated against (RGBA8 holding the window texture's bytes,
|
|
// GENERAL, its size), else VK_NULL_HANDLE (none made, a test swap, or another texture presented). It stays unwritten
|
|
// until the replay of the frame after next: its blit is on the queue before the next frame's submissions.
|
|
VkImage vk_fg_present_gen(VkImage presented);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|