Files
totk-pc-recomp/runtime/vk_fg.h
T
1ea8838da9 Frame generation inputs and dispatch with DLSS off: the replay follows the scene for it, records the camera motion vectors and the SDK's prepare at the scene's end, copies the picture before the HUD sRGB-encoded as the window texture holds it, and runs the optical flow and the interpolation after the frame's window texture, nothing shown yet
vk_dlaa.c follows the scene while frame_gen is live and DLSS is off (track: the arming and end of the DLSS path, without jitter, reactive mask or per-object motion), fg_motion runs mv_pass on the camera alone and vk_fg_prepare, vk_dlaa_hud takes the picture before the HUD by PR #1089's rule once the bloom chain began, vk_dlaa_sub_end runs the interpolation at the end of the submission that drew the window texture. vk_fg.cpp reads the camera's planes and depth convention from the scene block's projection (standard depth, near 0.1 m, far 25 km in TotK 1.4.3), makes the contexts again when sizes or the convention change, resets the history on a cut (10 m or 35 degrees, as Savage Wind), a frame without camera motion and after any frame without a generated picture, and stays off with DLSS, replay workers, sync_ahead, HDR and while a menu background or a fade is open. fg_test, fg_debug, fg_shot and fg_times are the checks; GPU timestamps and the replay thread's recording time go to the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Revivedx <82332536+Revivedx@users.noreply.github.com>
Co-Authored-By: xellow78-lgtm <336264245+xellow78-lgtm@users.noreply.github.com>
2026-11-20 10:09:58 +03:00

76 lines
4.9 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
// vk_device.c, after the device exists: with TOTK_FRAME_GEN=1 (totk.ini frame_gen = 1) 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);
#ifdef __cplusplus
}
#endif