mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 13:59:56 -04:00
runtime/vk_ffx4.cpp loads amd_fidelityfx_loader_vk.dll from beside the executable and asks it which upscaler versions the device can run. Where a 4.x version is listed (Radeon RX 6000, RX 7000 and RX 9000 cards with AMD's driver 26.10.1 or newer) the menu's Upscaling row gains AMD FSR 4 Native AA, Quality, Balanced, Performance and Ultra Performance, and fsr4 = 1 runs it in FSR 3.1's place with the same inputs. Its contexts are made with that version asked for by its id and the provider is asked afterwards which version it runs, so no other upscaler can be shown under the name. When a context or a dispatch fails, FSR 3.1 makes the frame, and after three failures FSR 4 is off for the run. Each upscaler starts its history anew on the frame after a change from one to the other. The setting is off by default and the Linux build compiles stubs. On an RX 7900 XT (driver 26.10.1, 3440x1440, HDR) the library runs FSR 4.1.2: a context takes 54 ms to make and 217 MiB of video memory. Standing in Hyrule Field: Quality 47.8 fps where FSR 3.1 gives 51.5, Native AA 41.4. Screenshots of 601 consecutive frames standing, 801 during a camera sweep, 701 each in Kakariko and the graveyard, and 1,301 across changes between FSR 3.1 and FSR 4, their modes and off show no flicker that FSR 3.1 does not have, and it runs together with FSR 3.1 frame generation. The SDK's API headers are in runtime/third_party/ffx_sdk, unmodified, with the licence. tools/make_kit.py and tools/make_launcher.py take AMD's two signed libraries with --ffx4, and tools/make_game.py copies them beside the game when the kit has both. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
48 lines
3.0 KiB
C
48 lines
3.0 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;
|
|
|
|
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. fov_y in
|
|
// radians (0: unknown). 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, float fov_y);
|
|
void vk_ffx_release(void); // before the device goes away
|
|
|
|
// 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, float fov_y); // as vk_ffx_upscale
|
|
void vk_ffx4_release(void);
|
|
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
|