mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 07:09:57 -04:00
vk_dlaa.c waited for the whole device to be idle, with the queue lock held, before it freed a size's images and feature (free_size: a third scene size, a DLSS model change; stale_sizes), the features release_kept releases before a create, a reactive-mask snapshot (free_snap), the HUD-less picture of another size (hudless_from), prebloom's images (pb_images) and what retire_idle gives back. Those run on the thread that replays the game's submissions, and with the queue lock held the present's flip, the completion thread's hold release and every upload submit waited as well, at each pause-screen size, reload, window size, dynamic resolution step or mode change; AUDIT F-4-02 measured 16.4 to 44.9 ms for release_kept's wait together with the create that followed. Now nothing there waits: - images only the replay uses go to vk_memory.c's deferred destruction, stamped with the submission being recorded; - a DLSS feature goes into a list (vk_up_defer.h) with the timeline value of the last submission that created or evaluated it (Size.feat_fence) and is released on the same thread once the GPU is past that value, which is the rule NGX gives for releasing a feature and keeps every NGX call on one thread; - a size's motion vectors and the HUD-less picture, which frame generation reads at a present, go into that list behind a present gate of 8 presents and only then to the deferred destruction; the device's idle never covered a present still to come, so this covers more than the wait did; - the list is taken at the top of every evaluation, at every pass while no evaluation runs (retire_idle), and where something is let go of (vk_upscaler_let_go). A feature creation refused while released features are still in flight waits on the timeline from the host for those features (vk_upscaler_gpu_wait, no queue touched), takes them and tries once more, with a log line; a full list waits for the device (vk_upscaler_settle). release_kept's features whose last frame the GPU still runs are now released after the create that follows, not before it: none of them is evaluated again, and its log line says how many. NX2NAVI_UPSCALER_IDLE_WAIT (upscaler_idle_wait in [display], default 0, read at start) set to 1 waits for the device at each of these places as up to 0.10.1, for comparison: rows in cfg.c's known[], metas[] and sections[], and an entry in nx2navi.ini.example. retire_idle still waits for the device before the FSR contexts it gives back while there are any; vk_ffx.cpp and vk_ffx4.cpp follow in the next commit. Not reproduced before the change: no DLSS session log here (C-6 rests on the code and on F-4-02's mark). Every runtime file compiles, vk_dlaa.c and cfg.c with -Wall -Wextra and no warning; cfg_rows_check reports 0 problems. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
5.9 KiB
C
86 lines
5.9 KiB
C
// AMD FidelityFX (vk_ffx.cpp): FSR 3.1 temporal upscaling through amd_fidelityfx_vk.dll, loaded at run time.
|
|
#pragma once
|
|
#include <vulkan/vulkan.h>
|
|
|
|
typedef struct {
|
|
VkImage image; // level 0, layer 0, in VK_IMAGE_LAYOUT_GENERAL
|
|
VkFormat format;
|
|
uint32_t width, height;
|
|
int storage; // created with VK_IMAGE_USAGE_STORAGE_BIT (FSR writes it)
|
|
} VkFfxImage;
|
|
|
|
// The scene camera FSR takes, from the frame's projection (vk_dlaa.c proj_planes): the vertical field of view in
|
|
// radians, the near and far planes' view distances (far: VK_DLAA_FAR_INFINITE, 1e8, for a projection without a far
|
|
// plane) and the metres in one unit of view space. A field of 0 is not known, and FSR then gets 1 radian, 0.1, 1e8 and
|
|
// 1.
|
|
typedef struct { float fov_y, znear, zfar, meters; } VkFfxCamera;
|
|
// vk_dlaa.c: the share (0..1) of the extra sharpening FSR 3.1 gets at a render width w of an output width ow
|
|
float vk_dlaa_fsr3_boost(uint32_t w, uint32_t ow);
|
|
// vk_dlaa.c: a wait for the device to be idle, the queue lock held, before an upscaler frees what the GPU may still
|
|
// use (NX2NAVI_TRACE=perf: "upscaler device waits")
|
|
void vk_upscaler_device_idle(void);
|
|
// vk_dlaa.c "what the upscalers let go of while the GPU may still use it", on the thread that makes the upscalers'
|
|
// calls (vk_dlaa.c's pass hooks):
|
|
int vk_upscaler_idle_wait(void); // NX2NAVI_UPSCALER_IDLE_WAIT: 1 waits for the device wherever one lets go of something
|
|
// After something was let go of: what the GPU is past goes (with NX2NAVI_UPSCALER_IDLE_WAIT=1 after a wait for the
|
|
// device, vk_upscaler_settle).
|
|
void vk_upscaler_let_go(void);
|
|
// A wait for the device, then everything let go of that a submission made so far names goes (a present gate stays).
|
|
void vk_upscaler_settle(void);
|
|
// A refused creation: waits, without the device's idle, until the GPU is past timeline value v (no further than the
|
|
// submissions made so far) and returns the value it is past; with NX2NAVI_UPSCALER_IDLE_WAIT=1, or when that wait
|
|
// fails, a wait for the device.
|
|
uint64_t vk_upscaler_gpu_wait(uint64_t v);
|
|
|
|
int vk_ffx_load(void); // 1 when the library is there with its entry points (loaded once)
|
|
// Whether FSR 3.1 upscaling can run in this build, for the settings menu: after vk_ffx_load ran, what it found; before,
|
|
// whether the library file is there, asked once without loading it. 0 where the build has no FSR 3.1 to load.
|
|
int vk_ffx_available(void);
|
|
// The same for frame generation (vk_fg.cpp), which runs through the library's own API calls (vk_ffx_create and the
|
|
// rest below), not only an upscaler.
|
|
int vk_ffx_framegen_available(void);
|
|
// Records FSR 3.1 into cb: color (the scene light, render size), depth (D32F), mv (R16G16F, render pixels, current to
|
|
// previous), out (the output size, RGBA16F, storage). jx, jy: the jitter the scene took, render pixels. cam: the
|
|
// frame's camera. 0 on failure (the caller falls back as it does when DLSS fails).
|
|
int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
|
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, const VkFfxCamera *cam);
|
|
void vk_ffx_release(void); // before the device goes away
|
|
// The upscale contexts of FSR 3.1 and FSR 4 (vk_dlaa.c retire_idle, the device idle): any held, and give them back.
|
|
int vk_ffx_holds(void);
|
|
void vk_ffx_release_idle(void);
|
|
// FSR 3.1's contexts that no upscale used in the last `recent` calls, destroyed with the device idle (the caller waited
|
|
// for it): room for an FSR 4 context whose creation failed. Their count.
|
|
int vk_ffx_trim_idle(uint64_t recent);
|
|
// The device's functions as the library is given them (ffxCreateBackendVKDesc.vkDeviceProcAddr): its pipeline creates
|
|
// go through the runtime's pipeline caches (vk_pipeline.c vk_pipeline_create_foreign; NX2NAVI_FFX_PIPE_CACHE=0: not).
|
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_ffx_proc_addr(VkDevice dev, const char *name);
|
|
|
|
// AMD FSR 4 (vk_ffx4.cpp): the ML upscaler of AMD's FSR SDK 2.4, through amd_fidelityfx_loader_vk.dll and
|
|
// amd_fidelityfx_upscaler_vk.dll beside the executable. vk_ffx_upscale runs it in FSR 3.1's place when the setting
|
|
// asks (NX2NAVI_FSR4) and it runs here, and falls back to FSR 3.1 when it fails.
|
|
int vk_ffx4_available(void); // the libraries are there and list a 4.x version for the device; asked once, with the
|
|
// device, from any thread (0 before the device exists)
|
|
const char *vk_ffx4_name(void); // "AMD FSR 4.1.2" once vk_ffx4_available found it
|
|
int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
|
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms,
|
|
const VkFfxCamera *cam); // as vk_ffx_upscale
|
|
void vk_ffx4_release(void);
|
|
int vk_ffx4_holds(void); // an FSR 4 upscale context is made
|
|
int vk_ffx4_failed(void); // it failed three times in a row: FSR 3.1 serves until vk_ffx4_retry
|
|
void vk_ffx4_retry(void); // the menu chose FSR 4 again: try it anew after such failures
|
|
void vk_ffx4_trim(uint64_t now_ns); // at each upscale: FSR 4's contexts unused for a while go
|
|
uint64_t vk_ffx4_vram(int *contexts); // FSR 4's upscale contexts and their video memory (vk_ffx_vram)
|
|
int vk_ffx_fsr4(void); // the setting asks for FSR 4 and it runs here: what vk_ffx_upscale uses, for the menu
|
|
|
|
#if defined(__cplusplus) && !defined(VK_FFX_NO_API)
|
|
// The API's calls themselves, for vk_fg.cpp (0 = FFX_API_RETURN_OK): the library loaded first (vk_ffx_load).
|
|
#include "third_party/ffx_api/ffx_api.h"
|
|
extern "C" {
|
|
ffxReturnCode_t vk_ffx_create(ffxContext *ctx, ffxCreateContextDescHeader *desc);
|
|
ffxReturnCode_t vk_ffx_destroy(ffxContext *ctx);
|
|
ffxReturnCode_t vk_ffx_configure(ffxContext *ctx, const ffxConfigureDescHeader *desc);
|
|
ffxReturnCode_t vk_ffx_query(ffxContext *ctx, ffxQueryDescHeader *desc);
|
|
ffxReturnCode_t vk_ffx_dispatch(ffxContext *ctx, const ffxDispatchDescHeader *desc);
|
|
}
|
|
#endif
|