Merge pull request #1245: AMD FSR 4 upscales the 3D scene on Windows through AMD's signed FSR SDK 2.4 libraries (scene_upscaler = fsr4, off by default), and the setup can download them (codexx-dev) (#1409)

FSR 4 is a fourth engine of the scene upscaler beside DLSS and FSR 3.1 and takes their frame point, jitter, per-object
motion vectors, mip bias, fsr_sharpness, FXAA skip and dynamic resolution hold. The PR's dlaa_backend setting, its
FSR 3 through the DLL and its separate Upscalers row are left out: dev builds FSR 3.1 from the SDK 1.1.4 sources.
Checked on an RX 9070: FSR 4.1.2 at quality, 1280x720 -> 1920x1080, picture clean; without the DLLs the upscaler stays
off with a log line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-23 14:39:08 +03:00
commit f1ec56b592
37 files changed
+1183 -133

No files matched your search

+4 -4
View File
@@ -44,7 +44,7 @@ static const char *const known[] = {
"DESC_TEMPLATE", "DESWIZZLE", "DEVICE_PROFILE", "DIALOGUE_CLICK", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_JITTER", "DLAA_EFFECTS_AFTER", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_FIXED_EXPOSURE", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR",
"DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FG_DEBUG", "FG_OBJECTS", "FG_SHOT", "FG_SHOT_DIR", "FG_TEST", "FG_TIMES", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_GEN", "FRAME_QUEUE", "FREECAM_KEY", "FREECAM_PAD", "FREECAM_PATCH",
"FREEZE_IDLE", "FREE_CORES", "FSR3_DEBUG", "FSR3_VIEW", "FSR_SHARPNESS",
"FREEZE_IDLE", "FREE_CORES", "FSR3_DEBUG", "FSR3_VIEW", "FSR4_DEBUG", "FSR_SHARPNESS",
"FULLSCREEN", "FXAA",
"GAMEPLAY_DISTANCE_SENSITIVITY", "GAMEPLAY_ITEM_AD", "GAMEPLAY_ITEM_SENSITIVITY", "GAMEPLAY_ITEM_WHEEL",
"GAMEPLAY_MAP_ZOOM", "GAMEPLAY_MAP_ZOOM_SENSITIVITY", "GAMEPLAY_ROTATION_SENSITIVITY", "GAMEPLAY_TWEAKS_ENABLED",
@@ -142,7 +142,7 @@ static const CfgMeta metas[] = {
{"HUD_WIDTH", "full", "full|21:9|16:9", RESTART},
{"DYNAMIC_RES", "1", "0|1", LIVE}, // resolution.c res_dynres_live
{"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE},
{"SCENE_UPSCALER", "off", "off|dlss|fsr3", RESTART}, {"DLAA", "0", "0|1", RESTART},
{"SCENE_UPSCALER", "off", "off|dlss|fsr3|fsr4", RESTART}, {"DLAA", "0", "0|1", RESTART},
{"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE},
{"FSR_SHARPNESS", "80", "0..100", LIVE}, // vk_dlaa.c fsr_evaluate
{"DLSS_PRESET", "default", "default|k|j", LIVE}, {"DLSS_FIXED_EXPOSURE", "0", "0|1", LIVE}, {"DLAA_EFFECTS_AFTER", "0", "0|1", LIVE},
@@ -863,9 +863,9 @@ void cfg_init(void) {
}
// scene_upscaler, or for a totk.ini that predates it the dlaa switch it replaced: dlaa = 1 is DLSS, anything else off.
// FSR 3.1 is never the answer for a player who did not pick it. An unknown value is off.
// FSR is never the answer for a player who did not pick it. An unknown value is off.
const char *cfg_scene_upscaler(void) {
if (!cfg_is_set("TOTK_SCENE_UPSCALER")) return cfg_bool("TOTK_DLAA") ? "dlss" : "off";
const char *v = cfg_value("TOTK_SCENE_UPSCALER");
return !strcmp(v, "dlss") ? "dlss" : !strcmp(v, "fsr3") ? "fsr3" : "off";
return !strcmp(v, "dlss") ? "dlss" : !strcmp(v, "fsr3") ? "fsr3" : !strcmp(v, "fsr4") ? "fsr4" : "off";
}
+5 -3
View File
@@ -69,14 +69,16 @@ const char *cfg_value(const char *name);
int cfg_int(const char *name);
double cfg_double(const char *name);
int cfg_bool(const char *name);
// The 3D scene upscaler the settings name now: "off", "dlss" or "fsr3" (scene_upscaler; without it dlaa = 1 is "dlss").
// The 3D scene upscaler the settings name now: "off", "dlss", "fsr3" or "fsr4" (scene_upscaler; without it dlaa = 1 is
// "dlss").
// The engine in use is the one named at start (vk_dlaa.c vk_upscaler_engine).
const char *cfg_scene_upscaler(void);
// vk_dlaa.c, the 3D scene upscaler (scene_upscaler): the engine picked at start (UPSCALER_*),
// 1 while the settings still name it (the menu switches it off at once), the engine that is running (it
// ran and has not failed; 0 none), and why an engine cannot run here (UPSCALER_MISSING_*, 0 it can).
enum { UPSCALER_OFF, UPSCALER_DLSS, UPSCALER_FSR3 };
enum { UPSCALER_MISSING_GPU = 1, UPSCALER_MISSING_DLL };
// UPSCALER_FSR4 is AMD's FSR 4 from its FSR SDK libraries (vk_ffx.c), Windows only (UPSCALER_MISSING_OS elsewhere).
enum { UPSCALER_OFF, UPSCALER_DLSS, UPSCALER_FSR3, UPSCALER_FSR4 };
enum { UPSCALER_MISSING_GPU = 1, UPSCALER_MISSING_DLL, UPSCALER_MISSING_OS };
int vk_upscaler_engine(void);
int vk_upscaler_on(void);
int vk_upscaler_running(void);
+245
View File
@@ -0,0 +1,245 @@
// The part of AMD's FSR API (ffx-api) that vk_ffx.c uses: the entry points of amd_fidelityfx_loader_vk.dll, the
// Vulkan backend descriptor and the upscaler's create and dispatch descriptors. Copied from the FidelityFX SDK v2.4.0
// (GPUOpen-LibrariesAndSDKs/FidelityFX-SDK, Kits/FidelityFX/api/include/ffx_api.h, ffx_api_types.h, vk/ffx_api_vk.h
// and Kits/FidelityFX/upscalers/include/ffx_upscale.h), trimmed to those declarations; the layouts and values are
// unchanged. The SDK's headers use a C++ attribute for deprecations, so they are not included as they are.
//
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2026 Advanced Micro Devices, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <wchar.h>
#include <vulkan/vulkan.h>
// ---- ffx_api.h
enum FfxApiReturnCodes {
FFX_API_RETURN_OK = 0,
FFX_API_RETURN_ERROR = 1,
FFX_API_RETURN_ERROR_UNKNOWN_DESCTYPE = 2,
FFX_API_RETURN_ERROR_RUNTIME_ERROR = 3,
FFX_API_RETURN_NO_PROVIDER = 4,
FFX_API_RETURN_ERROR_MEMORY = 5,
FFX_API_RETURN_ERROR_PARAMETER = 6,
FFX_API_RETURN_PROVIDER_NO_SUPPORT_NEW_DESCTYPE = 7,
};
typedef void *ffxContext;
typedef uint32_t ffxReturnCode_t;
#define FFX_API_EFFECT_MASK 0x00ff0000u
#define FFX_API_BACKEND_MASK 0xff000000u
typedef uint64_t ffxStructType_t;
typedef struct ffxApiHeader {
ffxStructType_t type;
struct ffxApiHeader *pNext;
} ffxApiHeader;
typedef ffxApiHeader ffxCreateContextDescHeader;
typedef ffxApiHeader ffxConfigureDescHeader;
typedef ffxApiHeader ffxQueryDescHeader;
typedef ffxApiHeader ffxDispatchDescHeader;
enum FfxApiMsgType { FFX_API_MESSAGE_TYPE_ERROR = 0, FFX_API_MESSAGE_TYPE_WARNING = 1 };
typedef void (*ffxApiMessage)(uint32_t type, const wchar_t *message);
#define FFX_API_QUERY_DESC_TYPE_GET_VERSIONS 4u
struct ffxQueryDescGetVersions {
ffxQueryDescHeader header;
uint64_t createDescType;
void *device; // Vulkan: a VkDeviceContext *
uint64_t *outputCount;
uint64_t *versionIds;
const char **versionNames;
};
#define FFX_API_DESC_TYPE_OVERRIDE_VERSION 5u
struct ffxOverrideVersion {
ffxApiHeader header;
uint64_t versionId;
};
#define FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION 6u
struct ffxQueryGetProviderVersion {
ffxQueryDescHeader header;
uint64_t versionId;
const char *versionName;
};
typedef struct ffxAllocationCallbacks ffxAllocationCallbacks;
typedef ffxReturnCode_t (*PfnFfxCreateContext)(ffxContext *context, ffxCreateContextDescHeader *desc,
const ffxAllocationCallbacks *memCb);
typedef ffxReturnCode_t (*PfnFfxDestroyContext)(ffxContext *context, const ffxAllocationCallbacks *memCb);
typedef ffxReturnCode_t (*PfnFfxQuery)(ffxContext *context, ffxQueryDescHeader *desc);
typedef ffxReturnCode_t (*PfnFfxDispatch)(ffxContext *context, const ffxDispatchDescHeader *desc);
#define FFX_API_EFFECT_ID_UPSCALE 0x00010000u
#define FFX_API_MAKE_EFFECT_SUB_ID(effectId, subversion) ((effectId & FFX_API_EFFECT_MASK) | (subversion & ~FFX_API_EFFECT_MASK))
#define FFX_API_BACKEND_ID_VK 0x01000000u
#define FFX_API_MAKE_BACKEND_SUB_ID(backendId, subversion) ((backendId & FFX_API_BACKEND_MASK) | (subversion & ~FFX_API_BACKEND_MASK))
// ---- ffx_api_types.h
enum FfxApiSurfaceFormat {
FFX_API_SURFACE_FORMAT_UNKNOWN,
FFX_API_SURFACE_FORMAT_R32G32B32A32_TYPELESS,
FFX_API_SURFACE_FORMAT_R32G32B32A32_UINT,
FFX_API_SURFACE_FORMAT_R32G32B32A32_FLOAT,
FFX_API_SURFACE_FORMAT_R16G16B16A16_FLOAT,
FFX_API_SURFACE_FORMAT_R32G32B32_FLOAT,
FFX_API_SURFACE_FORMAT_R32G32_FLOAT,
FFX_API_SURFACE_FORMAT_R8_UINT,
FFX_API_SURFACE_FORMAT_R32_UINT,
FFX_API_SURFACE_FORMAT_R8G8B8A8_TYPELESS,
FFX_API_SURFACE_FORMAT_R8G8B8A8_UNORM,
FFX_API_SURFACE_FORMAT_R8G8B8A8_SNORM,
FFX_API_SURFACE_FORMAT_R8G8B8A8_SRGB,
FFX_API_SURFACE_FORMAT_B8G8R8A8_TYPELESS,
FFX_API_SURFACE_FORMAT_B8G8R8A8_UNORM,
FFX_API_SURFACE_FORMAT_B8G8R8A8_SRGB,
FFX_API_SURFACE_FORMAT_R11G11B10_FLOAT,
FFX_API_SURFACE_FORMAT_R10G10B10A2_UNORM,
FFX_API_SURFACE_FORMAT_R16G16_FLOAT,
FFX_API_SURFACE_FORMAT_R16G16_UINT,
FFX_API_SURFACE_FORMAT_R16G16_SINT,
FFX_API_SURFACE_FORMAT_R16_FLOAT,
FFX_API_SURFACE_FORMAT_R16_UINT,
FFX_API_SURFACE_FORMAT_R16_UNORM,
FFX_API_SURFACE_FORMAT_R16_SNORM,
FFX_API_SURFACE_FORMAT_R8_UNORM,
FFX_API_SURFACE_FORMAT_R8G8_UNORM,
FFX_API_SURFACE_FORMAT_R8G8_UINT,
FFX_API_SURFACE_FORMAT_R32_FLOAT,
};
enum FfxApiResourceUsage {
FFX_API_RESOURCE_USAGE_READ_ONLY = 0,
FFX_API_RESOURCE_USAGE_RENDERTARGET = (1 << 0),
FFX_API_RESOURCE_USAGE_UAV = (1 << 1),
FFX_API_RESOURCE_USAGE_DEPTHTARGET = (1 << 2),
};
enum FfxApiResourceState {
FFX_API_RESOURCE_STATE_COMMON = (1 << 0),
FFX_API_RESOURCE_STATE_UNORDERED_ACCESS = (1 << 1),
FFX_API_RESOURCE_STATE_COMPUTE_READ = (1 << 2),
FFX_API_RESOURCE_STATE_PIXEL_READ = (1 << 3),
FFX_API_RESOURCE_STATE_COPY_SRC = (1 << 4),
FFX_API_RESOURCE_STATE_GENERIC_READ = (FFX_API_RESOURCE_STATE_COPY_SRC | FFX_API_RESOURCE_STATE_COMPUTE_READ),
};
enum FfxApiResourceType { FFX_API_RESOURCE_TYPE_BUFFER, FFX_API_RESOURCE_TYPE_TEXTURE1D, FFX_API_RESOURCE_TYPE_TEXTURE2D };
struct FfxApiDimensions2D {
uint32_t width, height;
};
struct FfxApiFloatCoords2D {
float x, y;
};
struct FfxApiResourceDescription {
uint32_t type;
uint32_t format;
uint32_t width; // union with size (buffers)
uint32_t height; // union with stride
uint32_t depth; // union with alignment
uint32_t mipCount;
uint32_t flags;
uint32_t usage;
};
struct FfxApiResource {
void *resource; // Vulkan: the VkImage
struct FfxApiResourceDescription description;
uint32_t state;
};
// ---- vk/ffx_api_vk.h
typedef struct VkDeviceContext {
VkDevice vkDevice;
VkPhysicalDevice vkPhysicalDevice;
PFN_vkGetDeviceProcAddr vkDeviceProcAddr;
} VkDeviceContext;
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK FFX_API_MAKE_BACKEND_SUB_ID(FFX_API_BACKEND_ID_VK, 0x03)
struct ffxCreateBackendVKDesc {
ffxCreateContextDescHeader header;
VkDeviceContext deviceContext;
};
// ---- upscalers/include/ffx_upscale.h
#define FFX_UPSCALER_MAKE_VERSION(major, minor, patch) (((major) << 22) | ((minor) << 12) | (patch))
#define FFX_UPSCALER_VERSION FFX_UPSCALER_MAKE_VERSION(4, 1, 2)
enum FfxApiCreateContextUpscaleFlags {
FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE = (1 << 0),
FFX_UPSCALE_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1 << 1),
FFX_UPSCALE_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION = (1 << 2),
FFX_UPSCALE_ENABLE_DEPTH_INVERTED = (1 << 3),
FFX_UPSCALE_ENABLE_DEPTH_INFINITE = (1 << 4),
FFX_UPSCALE_ENABLE_AUTO_EXPOSURE = (1 << 5),
FFX_UPSCALE_ENABLE_DYNAMIC_RESOLUTION = (1 << 6),
FFX_UPSCALE_ENABLE_DEBUG_CHECKING = (1 << 7),
};
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_UPSCALE, 0x00)
struct ffxCreateContextDescUpscale {
ffxCreateContextDescHeader header;
uint32_t flags;
struct FfxApiDimensions2D maxRenderSize;
struct FfxApiDimensions2D maxUpscaleSize;
ffxApiMessage fpMessage;
};
#define FFX_API_DISPATCH_DESC_TYPE_UPSCALE FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_UPSCALE, 0x01)
struct ffxDispatchDescUpscale {
ffxDispatchDescHeader header;
void *commandList; // Vulkan: the VkCommandBuffer
struct FfxApiResource color;
struct FfxApiResource depth;
struct FfxApiResource motionVectors;
struct FfxApiResource exposure;
struct FfxApiResource reactive;
struct FfxApiResource transparencyAndComposition;
struct FfxApiResource output;
struct FfxApiFloatCoords2D jitterOffset;
struct FfxApiFloatCoords2D motionVectorScale;
struct FfxApiDimensions2D renderSize;
struct FfxApiDimensions2D upscaleSize;
bool enableSharpening;
float sharpness;
float frameTimeDelta; // milliseconds
float preExposure;
bool reset;
float cameraNear;
float cameraFar;
float cameraFovAngleVertical; // radians
float viewSpaceToMetersFactor;
uint32_t flags;
};
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE_VERSION FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_UPSCALE, 0x0b)
struct ffxCreateContextDescUpscaleVersion {
ffxCreateContextDescHeader header;
uint32_t version; // FFX_UPSCALER_VERSION
};
+1
View File
@@ -313,6 +313,7 @@ void res_init(void); // after rt_patches_i
float res_dlss_lod_bias(void); // TOTK_DLSS upscaling: texture LOD bias (<= 0)
int res_dlss_mode(const char *mode); // TOTK_DLSS changed while running: new scene size
int res_dlss_dll(void); // the DLSS library is next to the executable
int res_ffx_dlls(void); // AMD's two FSR 4 libraries are (Windows; 0 elsewhere)
void res_fn_hit(uint64_t addr, uint64_t x0); // main.c fnprof_hit: catches the renderer at start
void res_present(Cpu *c); // nvnQueuePresentTexture: applies a pending scene size
void res_sizes(unsigned out[2], unsigned scene[2]); // the output and scene sizes in effect (the game's own
+39 -10
View File
@@ -102,11 +102,35 @@ int res_dlss_dll(void) {
return dll;
}
// The engine picked at start can run, as far as is known before the device exists: DLSS needs its DLL (dlss_dll); FSR
// 3.1 is built in (vk_fsr3.cpp). Off: nothing to run.
// AMD's FSR 4 (vk_ffx.c) loads amd_fidelityfx_loader_vk.dll from the folder of totk.exe, which finds
// amd_fidelityfx_upscaler_vk.dll next to itself; both come from the setup's FSR step. Windows only: AMD ships no Linux
// libraries.
static int ffx_dlls(void) {
#ifdef _WIN32
char exe[1024], path[1024 + 48];
if (!plat_exe_path(exe, sizeof exe)) return 1;
char *last = plat_last_sep(exe);
if (!last) return 1;
snprintf(path, sizeof path, "%.*s/amd_fidelityfx_loader_vk.dll", (int)(last - exe), exe);
if (!plat_file_exists(path)) return 0;
snprintf(path, sizeof path, "%.*s/amd_fidelityfx_upscaler_vk.dll", (int)(last - exe), exe);
return plat_file_exists(path);
#else
return 0;
#endif
}
int res_ffx_dlls(void) {
static int dlls = -1;
if (dlls < 0) dlls = ffx_dlls();
return dlls;
}
// The engine picked at start can run, as far as is known before the device exists: DLSS needs its DLL (dlss_dll), FSR
// 4 AMD's two libraries (ffx_dlls); FSR 3.1 is built in (vk_fsr3.cpp). Off: nothing to run.
static int upscaler_ready(void) {
int e = vk_upscaler_engine();
return e == UPSCALER_DLSS ? res_dlss_dll() : e == UPSCALER_FSR3;
return e == UPSCALER_DLSS ? res_dlss_dll() : e == UPSCALER_FSR4 ? res_ffx_dlls() : e == UPSCALER_FSR3;
}
static uint64_t shadow_kib(void);
@@ -143,8 +167,12 @@ static double dlss_share(const char *m) {
int ready = upscaler_ready();
if (!ready && !told++) {
#ifdef _WIN32
rt_log("resolution: DLSS %s needs nvngx_dlss.dll next to totk.exe, which is missing: the scene follows "
"render_scale", m);
if (vk_upscaler_engine() == UPSCALER_FSR4)
rt_log("resolution: FSR 4 %s needs amd_fidelityfx_loader_vk.dll and amd_fidelityfx_upscaler_vk.dll "
"next to totk.exe, which are missing: the scene follows render_scale", m);
else
rt_log("resolution: DLSS %s needs nvngx_dlss.dll next to totk.exe, which is missing: the scene "
"follows render_scale", m);
#else
rt_log("resolution: DLSS %s needs libnvidia-ngx-dlss.so.<version> next to totk, which is missing: the "
"scene follows render_scale", m);
@@ -208,7 +236,7 @@ static void decide(void) {
else rt_log("resolution: TOTK_SHADOW_RES=%s is not game or a size 256..4096 (a multiple of 8); game", sr);
}
// A DLSS mode other than dlaa sets the scene size instead. On 1.4.3 with the scene upscaler able to run (DLSS with
// its DLL there, or FSR 3.1 in the build)
// its DLL there, FSR 4 with AMD's libraries there, or FSR 3.1 in the build)
// the mode can change while the game runs (res_dlss_mode): the scene patch is then always on and the heap is sized
// for the largest scene the modes ask for. Everyone else keeps the game's own scene size and its dynamic resolution
// unless render_scale or a DLSS mode asks for another, and a heap sized for that scene alone.
@@ -674,8 +702,8 @@ void res_fov_live(void) {
// 2867-wide scene stays at 100 %, one wider than about 2970 does not, and a 4267-wide one (5120x1440 at render_scale
// 83) fits no tier and falls back to 80 % every frame, whatever the GPU's load. 1 (the default) leaves the game's own
// stepping and the set off. Runs on a settings change (gfx_present.c window_settings_live), like res_fov_live.
// FSR 3.1 as the scene upscaler holds it at 100 % whatever dynamic_res says, as codexx-dev's pull request #1245 does
// for its FSR: each tier is a scene of another size, so every step starts FSR's history again, and below 100 % the
// FSR 3.1 or FSR 4 as the scene upscaler holds it at 100 % whatever dynamic_res says, as codexx-dev's pull request
// #1245 does for its FSR: each tier is a scene of another size, so every step starts FSR's history again, and below 100 % the
// game ends its frame another way (a frame log on 1.4.3: its copy shader scales the scene straight into the
// output-sized target instead of the scaling FXAA draw), which #1245 measured as a picture that went soft and sharp in
// turns at a 2560x1440 scene. A 1280x720 scene (1080p, quality) stayed at 100 % through a 70 s town run, so it gains
@@ -683,7 +711,8 @@ void res_fov_live(void) {
void res_dynres_live(void) {
static int set = -2, shown = -1;
if (set == -2) set = rt_patch_set("fixres");
int fsr = vk_upscaler_on() && vk_upscaler_engine() == UPSCALER_FSR3;
int e = vk_upscaler_engine();
int fsr = vk_upscaler_on() && (e == UPSCALER_FSR3 || e == UPSCALER_FSR4);
int dyn = cfg_bool("TOTK_DYNAMIC_RES") && !fsr;
int state = dyn | fsr << 1;
if (state == shown) return;
@@ -695,7 +724,7 @@ void res_dynres_live(void) {
rt_patch_switch(set, !dyn);
rt_log("resolution: dynamic resolution %s",
dyn ? "on: the game's own 100, 90 or 80 %"
: fsr ? "off while FSR 3.1 upscales the scene: the scene stays at 100 %"
: fsr ? "off while FSR upscales the scene: the scene stays at 100 %"
: "off: the scene stays at 100 %");
}
+24 -14
View File
@@ -616,22 +616,30 @@ static void row_hud_width(void) {
opt_choice_list("TOTK_HUD_WIDTH", UI_MENU_HUD_WIDTH, vals, names, n, UI_MENU_HUD_WIDTH_DESC);
}
// The 3D scene upscaler (vk_dlaa.c): off, NVIDIA DLSS or AMD FSR 3.1. An engine that cannot run here is left out of
// the steps, and the note under the value says why; a totk.ini that names it anyway shows it, with the same note.
// Returns the value the settings name ("off", "dlss", "fsr3"; without scene_upscaler, dlaa = 1 is "dlss").
// The 3D scene upscaler (vk_dlaa.c): off, NVIDIA DLSS, AMD FSR 3.1 or AMD FSR 4. An engine that cannot run here is
// left out of the steps, and the note under the value says why; a totk.ini that names it anyway shows it, with the
// same note. FSR 4 is Windows only (AMD ships no Linux libraries): elsewhere it is left out without a note.
// Returns the value the settings name ("off", "dlss", "fsr3", "fsr4"; without scene_upscaler, dlaa = 1 is "dlss").
static const char *row_scene_upscaler(void) {
static const char *const all[] = {"off", "dlss", "fsr3"};
static const int engines[] = {UPSCALER_OFF, UPSCALER_DLSS, UPSCALER_FSR3};
static const UiTextId ids[] = {UI_MENU_SCENE_UPSCALER_OFF, UI_MENU_SCENE_UPSCALER_DLSS, UI_MENU_SCENE_UPSCALER_FSR3};
enum { N = 4 };
static const char *const all[N] = {"off", "dlss", "fsr3", "fsr4"};
static const int engines[N] = {UPSCALER_OFF, UPSCALER_DLSS, UPSCALER_FSR3, UPSCALER_FSR4};
static const UiTextId ids[N] = {UI_MENU_SCENE_UPSCALER_OFF, UI_MENU_SCENE_UPSCALER_DLSS, UI_MENU_SCENE_UPSCALER_FSR3,
UI_MENU_SCENE_UPSCALER_FSR4};
const char *now = cfg_scene_upscaler();
const char *vals[3], *names[3];
const char *vals[N], *names[N];
static char note[256];
note[0] = 0;
int n = 0, cur = -1;
for (int i = 0; i < 3; i++) {
for (int i = 0; i < N; i++) {
int why = vk_upscaler_missing(engines[i]);
if (why) {
UiTextId t = why == UPSCALER_MISSING_DLL ? UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL : UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU;
if (why && (why != UPSCALER_MISSING_OS || !strcmp(now, all[i]))) {
UiTextId t = engines[i] == UPSCALER_FSR4
? (why == UPSCALER_MISSING_DLL ? UI_MENU_SCENE_UPSCALER_NO_FSR4_DLL
: why == UPSCALER_MISSING_OS ? UI_MENU_SCENE_UPSCALER_NO_FSR4_OS
: UI_MENU_SCENE_UPSCALER_NO_FSR4_GPU)
: why == UPSCALER_MISSING_DLL ? UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL
: UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU;
size_t k = strlen(note);
snprintf(note + k, sizeof note - k, "%s%s", k ? "; " : "", menu_text(t));
}
@@ -827,9 +835,9 @@ static void tab_screen(float scale) {
UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA};
opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 5, UI_MENU_DLSS_DESC);
}
if (!strcmp(engine, "fsr3")) // FSR 3.1's own sharpening (vk_dlaa.c fsr_evaluate)
opt_slider("TOTK_FSR_SHARPNESS", UI_MENU_FSR3_SHARPNESS, 0, 100, UI_MENU_FSR3_SHARPNESS_DESC, 5, "%.0f %%");
if (!strcmp(engine, "dlss")) { // DLSS's model, its characters' mask and its other switches (FSR 3.1 has none)
if (!strcmp(engine, "fsr3") || !strcmp(engine, "fsr4")) // FSR's own sharpening (vk_dlaa.c fsr_evaluate)
opt_slider("TOTK_FSR_SHARPNESS", UI_MENU_FSR_SHARPNESS, 0, 100, UI_MENU_FSR_SHARPNESS_DESC, 5, "%.0f %%");
if (!strcmp(engine, "dlss")) { // DLSS's model, its characters' mask and its other switches (FSR has none)
static const UiTextId preset[] = {UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J};
opt_choice("TOTK_DLSS_PRESET", UI_MENU_DLSS_PRESET, preset, 3, UI_MENU_DLSS_PRESET_DESC);
static const UiTextId chars[] = {UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM,
@@ -1779,7 +1787,9 @@ static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
: !strcmp(m, "ultra_performance") ? UI_MENU_DLSS_ULTRA
: UI_MENU_DLSS_DLAA;
snprintf(v[6], sizeof v[6], "%s, %s",
menu_text(up == UPSCALER_FSR3 ? UI_MENU_SCENE_UPSCALER_FSR3 : UI_MENU_SCENE_UPSCALER_DLSS),
menu_text(up == UPSCALER_FSR4 ? UI_MENU_SCENE_UPSCALER_FSR4
: up == UPSCALER_FSR3 ? UI_MENU_SCENE_UPSCALER_FSR3
: UI_MENU_SCENE_UPSCALER_DLSS),
menu_text(mt));
}
// with frame generation: the pictures shown a second, of which the FPS row above counts the ones the game drew
+34 -16
View File
@@ -34,6 +34,8 @@ typedef struct { const char *lang; const char *const *text; } Row;
#define DLSS_FILE "libnvidia-ngx-dlss.so"
#define EXE_FILE "totk"
#endif
// AMD's FSR 4 libraries (Windows only), as the setup downloads them next to the executable.
#define FFX_FILES "amd_fidelityfx_loader_vk.dll, amd_fidelityfx_upscaler_vk.dll"
static const char *const text_en[UI_TEXT_COUNT] = {
SWKBD("Text entry", "Enter a name", "Horse", "OK", "Cancel", "Controller: A = OK, B = Cancel"),
@@ -182,15 +184,19 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_SCENE_UPSCALER] = "3D scene upscaler",
[UI_MENU_SCENE_UPSCALER_DESC] = "A temporal upscaler for the 3D scene: smoother edges and less shimmer, and in a mode below Native it draws "
"the scene smaller and scales it up, which saves GPU time. NVIDIA DLSS needs an NVIDIA "
"RTX GPU and " DLSS_FILE " next to " EXE_FILE "; AMD FSR 3.1 runs on any GPU. Off keeps "
"RTX GPU and " DLSS_FILE " next to " EXE_FILE "; AMD FSR 3.1 runs on any GPU; AMD FSR 4 "
"(Windows) needs a Radeon GPU AMD offers it for and " FFX_FILES " next to " EXE_FILE ". Off keeps "
"the game's own scaling and FXAA. The HUD is not touched; the upscaler and sharpness "
"above still fit the game image to the window. Takes effect after a restart.",
[UI_MENU_SCENE_UPSCALER_OFF] = "Off", [UI_MENU_SCENE_UPSCALER_DLSS] = "NVIDIA DLSS",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_FSR4] = "AMD FSR 4",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_GPU] = "FSR 4: not offered for this GPU",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_DLL] = "FSR 4: AMD's FSR libraries are missing",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_OS] = "FSR 4: Windows only",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS: needs an NVIDIA RTX GPU",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: " DLSS_FILE " is missing",
[UI_MENU_FSR3_SHARPNESS] = "FSR 3.1 sharpness",
[UI_MENU_FSR3_SHARPNESS_DESC] = "Sharpening of the 3D scene after FSR 3.1; 0 turns it off.",
[UI_MENU_FSR_SHARPNESS] = "FSR sharpness",
[UI_MENU_FSR_SHARPNESS_DESC] = "Sharpening of the 3D scene after AMD FSR 3.1 or FSR 4; 0 turns it off.",
[UI_MENU_FPS_LIMIT] = "Frame rate limit",
[UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs Game speed "
@@ -828,15 +834,19 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_SCENE_UPSCALER_DESC] = "Временной апскейлер для 3D-сцены: ровнее края и меньше мерцания, а в режимах ниже «Родного» он "
"рисует сцену меньше и увеличивает её, что экономит время видеокарты. NVIDIA DLSS "
"нужна видеокарта NVIDIA RTX и " DLSS_FILE " рядом с " EXE_FILE "; AMD FSR 3.1 "
"работает на любой видеокарте. «Выкл» оставляет собственное масштабирование игры и "
"работает на любой видеокарте; AMD FSR 4 (Windows) нужна видеокарта Radeon, для "
"которой AMD его предлагает, и " FFX_FILES " рядом с " EXE_FILE ". «Выкл» оставляет собственное масштабирование игры и "
"FXAA. Интерфейс не затрагивается; масштабирование и резкость выше по-прежнему "
"подгоняют изображение игры под окно. Действует после перезапуска.",
[UI_MENU_SCENE_UPSCALER_OFF] = "Выкл", [UI_MENU_SCENE_UPSCALER_DLSS] = "NVIDIA DLSS",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_FSR4] = "AMD FSR 4",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_GPU] = "FSR 4: недоступен для этой видеокарты",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_DLL] = "FSR 4: нет библиотек FSR от AMD",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_OS] = "FSR 4: только Windows",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS: нужна видеокарта NVIDIA RTX",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: нет " DLSS_FILE,
[UI_MENU_FSR3_SHARPNESS] = "Резкость FSR 3.1",
[UI_MENU_FSR3_SHARPNESS_DESC] = "Повышение резкости 3D-сцены после FSR 3.1; 0 выключает его.",
[UI_MENU_FSR_SHARPNESS] = "Резкость FSR",
[UI_MENU_FSR_SHARPNESS_DESC] = "Повышение резкости 3D-сцены после AMD FSR 3.1 или FSR 4; 0 выключает его.",
[UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров",
[UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость "
@@ -1941,15 +1951,19 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_SCENE_UPSCALER_DESC] = "Um upscaler temporal para a cena 3D: bordas mais suaves e menos cintilação, e nos modos abaixo do "
"Nativo ele desenha a cena menor e a amplia, o que poupa tempo da GPU. O NVIDIA DLSS "
"precisa de uma GPU NVIDIA RTX e do " DLSS_FILE " ao lado do " EXE_FILE "; o AMD FSR "
"3.1 roda em qualquer GPU. Desligado mantém a escala e o FXAA do próprio jogo. O HUD "
"3.1 roda em qualquer GPU; o AMD FSR 4 (Windows) precisa de uma GPU Radeon para a qual a AMD o "
"oferece e de " FFX_FILES " ao lado do " EXE_FILE ". Desligado mantém a escala e o FXAA do próprio jogo. O HUD "
"não é afetado; o upscaler e a nitidez acima continuam ajustando a imagem do jogo à "
"janela. Vale após reiniciar.",
[UI_MENU_SCENE_UPSCALER_OFF] = "Desligado", [UI_MENU_SCENE_UPSCALER_DLSS] = "NVIDIA DLSS",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_FSR4] = "AMD FSR 4",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_GPU] = "FSR 4: não oferecido para esta GPU",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_DLL] = "FSR 4: faltam as bibliotecas FSR da AMD",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_OS] = "FSR 4: só no Windows",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS: precisa de uma GPU NVIDIA RTX",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: falta o " DLSS_FILE,
[UI_MENU_FSR3_SHARPNESS] = "Nitidez do FSR 3.1",
[UI_MENU_FSR3_SHARPNESS_DESC] = "Aumento de nitidez da cena 3D após o FSR 3.1; 0 desliga.",
[UI_MENU_FSR_SHARPNESS] = "Nitidez do FSR",
[UI_MENU_FSR_SHARPNESS_DESC] = "Aumento de nitidez da cena 3D após o AMD FSR 3.1 ou FSR 4; 0 desliga.",
[UI_MENU_TAB_CHEATS] = "Cheats",
[UI_MENU_CHEATS_NONE] = "Nenhum cheat para esta versão do jogo. Os cheats de um mod são um arquivo de cheats do "
"Atmosphere na pasta cheats dele, com o nome da build do jogo: mods\\<mod>\\cheats\\%s. "
@@ -2697,14 +2711,18 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_SCENE_UPSCALER] = "3D 场景超分",
[UI_MENU_SCENE_UPSCALER_DESC] = "用于 3D 场景的时间性超分:边缘更平滑,闪烁更少;低于“原生”的模式会以更小的尺寸绘制场景再放大,以节省 GPU "
"时间。NVIDIA DLSS 需要 NVIDIA RTX 显卡,并将 " DLSS_FILE " 放在 " EXE_FILE " 旁;AMD "
"FSR 3.1 可在任何显卡上运行。“关”保留游戏自己的缩放和 FXAA。HUD 不受影响;上方的缩放"
"FSR 3.1 可在任何显卡上运行;AMD FSR 4(Windows)需要 AMD 为其提供 FSR 4 的 Radeon 显卡,并将 " FFX_FILES
" 放在 " EXE_FILE " 旁。“关”保留游戏自己的缩放和 FXAA。HUD 不受影响;上方的缩放"
"方式和锐度仍负责把游戏画面适配到窗口。重启后生效。",
[UI_MENU_SCENE_UPSCALER_OFF] = "关", [UI_MENU_SCENE_UPSCALER_DLSS] = "NVIDIA DLSS",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1",
[UI_MENU_SCENE_UPSCALER_FSR3] = "AMD FSR 3.1", [UI_MENU_SCENE_UPSCALER_FSR4] = "AMD FSR 4",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_GPU] = "FSR 4:此显卡不提供",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_DLL] = "FSR 4:缺少 AMD 的 FSR 库",
[UI_MENU_SCENE_UPSCALER_NO_FSR4_OS] = "FSR 4:仅限 Windows",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU] = "DLSS:需要 NVIDIA RTX 显卡",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS:缺少 " DLSS_FILE,
[UI_MENU_FSR3_SHARPNESS] = "FSR 3.1 锐度",
[UI_MENU_FSR3_SHARPNESS_DESC] = "FSR 3.1 之后 3D 场景的锐化强度;0 为关闭。",
[UI_MENU_FSR_SHARPNESS] = "FSR 锐度",
[UI_MENU_FSR_SHARPNESS_DESC] = "AMD FSR 3.1 或 FSR 4 之后 3D 场景的锐化强度;0 为关闭。",
[UI_MENU_TAB_CHEATS] = "金手指",
[UI_MENU_CHEATS_NONE] = "此游戏版本没有金手指。模组的金手指是它的 cheats 文件夹中以游戏构建命名的 Atmosphere "
"金手指文件:mods\\<模组>\\cheats\\%s。重启游戏后才会读取。对于修改游戏代码的金手指,"
+3 -2
View File
@@ -65,8 +65,9 @@ typedef enum {
UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM, UI_MENU_DLSS_CHARS_FULL, UI_MENU_FXAA, UI_MENU_FXAA_DESC,
UI_MENU_REFLEX, UI_MENU_REFLEX_DESC, UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST,
UI_MENU_SCENE_UPSCALER, UI_MENU_SCENE_UPSCALER_DESC, UI_MENU_SCENE_UPSCALER_OFF, UI_MENU_SCENE_UPSCALER_DLSS,
UI_MENU_SCENE_UPSCALER_FSR3, UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU, UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL, UI_MENU_FSR3_SHARPNESS,
UI_MENU_FSR3_SHARPNESS_DESC,
UI_MENU_SCENE_UPSCALER_FSR3, UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU, UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL, UI_MENU_FSR_SHARPNESS,
UI_MENU_FSR_SHARPNESS_DESC, UI_MENU_SCENE_UPSCALER_FSR4, UI_MENU_SCENE_UPSCALER_NO_FSR4_GPU,
UI_MENU_SCENE_UPSCALER_NO_FSR4_DLL, UI_MENU_SCENE_UPSCALER_NO_FSR4_OS,
// Game
UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60, UI_MENU_FPS_90,
+16 -1
View File
@@ -13,6 +13,7 @@
#include "platform/platform.h"
#include "vk_dlaa.h"
#include "vk_fg.h"
#include "vk_ffx.h"
#include "vk_fsr3.h"
static VkCtx g_vk;
@@ -287,6 +288,10 @@ typedef struct {
VkPhysicalDeviceDynamicRenderingLocalReadFeaturesKHR lr;
VkPhysicalDeviceAddressBindingReportFeaturesEXT abr;
VkPhysicalDevicePresentIdFeaturesKHR pid;
VkPhysicalDeviceCooperativeMatrixFeaturesKHR coop; // FSR 4 (vk_ffx.c)
#ifdef VK_EXT_SHADER_FLOAT8_EXTENSION_NAME
VkPhysicalDeviceShaderFloat8FeaturesEXT f8; // FSR 4 (vk_ffx.c)
#endif
} FeatureChain;
static int create_device(void) {
@@ -345,7 +350,16 @@ static int create_device(void) {
CHAIN(fbl, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_FEATURES_EXT);
CHAIN(lr, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES_KHR);
}
vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's; the twelve slots after it stay for the nine below
vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's or FSR 4's; the twelve slots after it stay for the nine below
// FSR 4's shader extensions (vk_ffx_device_exts) are enabled with their features, as far as the driver reports them
for (uint32_t i = 0; i < n_ext; i++) {
if (!strcmp(ext[i], VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME))
CHAIN(coop, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR);
#ifdef VK_EXT_SHADER_FLOAT8_EXTENSION_NAME
else if (!strcmp(ext[i], VK_EXT_SHADER_FLOAT8_EXTENSION_NAME))
CHAIN(f8, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT8_FEATURES_EXT);
#endif
}
if (has_ext(ep, ne, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) { g_vk.has_memory_budget = 1; ext[n_ext++] = VK_EXT_MEMORY_BUDGET_EXTENSION_NAME; }
// GPU timestamps on the CPU clock (vk_sync.c): the perf line splits GPU idle time into waiting for a submission or not.
if (has_ext(ep, ne, VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) { g_vk.has_calibrated = 2; ext[n_ext++] = VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME; }
@@ -492,6 +506,7 @@ static void destroy_all(void) {
if (g_vk.device) vkDeviceWaitIdle(g_vk.device);
if (g_vk.device) vk_fg_release();
if (g_vk.device) fsr3_release();
if (g_vk.device) vk_ffx_release();
if (g_vk.device) vk_astc_release();
if (g_vk.device) vk_deswz_release();
if (g_vk.device) vk_crumbs_release();
+114 -49
View File
@@ -11,6 +11,10 @@
// layout with a set-then-get round trip before anything relies on it.
//
// Where DLAA runs in the frame, the jitter and the motion vectors: see the sections below.
//
// The scene upscaler (scene_upscaler) is DLSS, AMD FSR 3.1 (vk_fsr3.cpp, built from the FidelityFX SDK 1.1.4 sources)
// or AMD FSR 4 (vk_ffx.c, AMD's FSR SDK 2.4 libraries, Windows): the arming, the jitter, the motion vectors and the
// copy of the result below are shared, and only the call that upscales differs (evaluate, fsr_evaluate).
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,6 +29,7 @@
#include "input.h"
#include "nvn_api.h"
#include "vk_exec.h"
#include "vk_ffx.h"
#include "vk_fg.h"
#include "vk_fsr3.h"
#include "vk_rec.h"
@@ -105,25 +110,43 @@ static int p_getp(const NgxParam *p, const char *n, void **v) { return NGX_OK(((
#endif
// The scene upscaler picked at start (scene_upscaler; without it dlaa = 1 is DLSS): a restart applies another. AMD FSR
// 3.1 (vk_fsr3.cpp) takes the same inputs at the same point of the frame as DLSS and runs on any GPU.
// 3.1 (vk_fsr3.cpp) and FSR 4 (vk_ffx.c) take the same inputs at the same point of the frame as DLSS; FSR 3.1 runs on
// any GPU, FSR 4 on Windows where AMD's libraries offer it for the GPU (vk_ffx_init). AMD ships those libraries for
// Windows only, so elsewhere fsr4 is off.
int vk_upscaler_engine(void) {
static int e = -1;
if (e < 0) {
const char *v = cfg_scene_upscaler();
e = !strcmp(v, "dlss") ? UPSCALER_DLSS : !strcmp(v, "fsr3") ? UPSCALER_FSR3 : UPSCALER_OFF;
e = !strcmp(v, "dlss") ? UPSCALER_DLSS : !strcmp(v, "fsr3") ? UPSCALER_FSR3
: !strcmp(v, "fsr4") ? UPSCALER_FSR4 : UPSCALER_OFF;
#ifndef _WIN32
if (e == UPSCALER_FSR4) {
rt_log("dlaa: scene_upscaler = fsr4 runs on Windows only (AMD's FSR SDK has no Linux libraries): off");
e = UPSCALER_OFF;
}
#endif
}
return e;
}
// The setting's name of an engine, and the name the log gives it.
static const char *engine_value(int e) {
return e == UPSCALER_DLSS ? "dlss" : e == UPSCALER_FSR3 ? "fsr3" : e == UPSCALER_FSR4 ? "fsr4" : "off";
}
static const char *engine_name(int e) {
return e == UPSCALER_DLSS ? "DLSS" : e == UPSCALER_FSR3 ? "FSR 3.1" : e == UPSCALER_FSR4 ? "FSR 4" : "none";
}
// The engine picked at start while the settings still name it (the menu turns it off at once, as dlaa did).
int vk_upscaler_on(void) {
int e = vk_upscaler_engine();
return e && !strcmp(cfg_scene_upscaler(), e == UPSCALER_DLSS ? "dlss" : "fsr3");
return e && !strcmp(cfg_scene_upscaler(), engine_value(e));
}
// NGX is brought up only when DLSS is the scene upscaler at start: its device extensions can only be asked for at
// device creation, and loading the driver's NGX core on every NVIDIA machine would cost start time and change the device
// with DLSS off. So the choice applies after a restart; with DLSS not picked (off or FSR 3.1), nothing of NGX runs.
// with DLSS off. So the choice applies after a restart; with DLSS not picked (off or FSR), nothing of NGX runs. FSR
// 4's device extensions are chosen at device creation as well (vk_ffx_device_exts).
int vk_dlaa_wanted(void) {
static int wanted = -1;
if (wanted < 0) wanted = vk_upscaler_engine() == UPSCALER_DLSS;
@@ -182,6 +205,7 @@ void vk_dlaa_device_exts(const VkExtensionProperties *have, uint32_t nhave, cons
uint32_t max) {
unsigned ni = 0, nd = 0;
const char **ie = NULL, **de = NULL;
vk_ffx_device_exts(have, nhave, ext, n, max); // FSR 4's, when it is the engine
if (!vk_dlaa_wanted() || !core_load() || !NGX_OK(N.req_ext(&ni, &ie, &nd, &de))) return;
for (unsigned i = 0; i < nd; i++) {
int ok = 0;
@@ -210,12 +234,18 @@ static int vtable_ok(void) {
}
// The upscaler's half of the per-object motion's gate (vk_objmv_wanted, below the frame state): DLSS once NGX came up
// with it (vk_dlaa_available), FSR 3.1 whenever it is the scene upscaler picked at start. Latched in vk_dlaa_init,
// before the first frame: with no upscaler, or DLSS without NGX, it stays 0 as vk_dlaa_available does.
// with it (vk_dlaa_available), FSR 3.1 whenever it is the scene upscaler picked at start, FSR 4 once AMD's libraries
// offered it for the device (vk_ffx_available). Latched in vk_dlaa_init, before the first frame: with no upscaler, or
// one that did not come up, it stays 0.
static int objmv;
void vk_dlaa_init(void) {
objmv = vk_upscaler_engine() == UPSCALER_FSR3;
if (vk_upscaler_engine() == UPSCALER_FSR4) {
vk_ffx_init();
objmv = vk_ffx_available();
return;
}
if (!vk_dlaa_wanted() || !core_load()) return;
// The executable's folder, where NGX looks for the DLSS model library and writes its logs.
wchar_t wdir[PLAT_PATH_MAX];
@@ -338,26 +368,38 @@ static struct {
VkExecTarget hud_t, win; // the output-sized target the scene is scaled into; the window texture
float cam_dr[2]; // the viewport depth range of the draw cam_addr was noted at
int fg_mv_ok; // the frame's motion is in the motion image (fg_motion)
int fsr; // the engine is AMD FSR 3.1 (scene_upscaler = fsr3 at start), else DLSS
int fsr; // the AMD FSR engine (UPSCALER_FSR3 or UPSCALER_FSR4, picked at start), 0: DLSS
} D = {.mv_ok = -1, .cfg_seen = ~0u};
#define DLSS_SIZES (sizeof D.sizes / sizeof D.sizes[0])
const VkTexImage *vk_dlaa_swap_img;
VkImageView vk_dlaa_swap_view;
// DLSS needs NGX and its model, FSR 3.1 runs on any GPU the back end runs on: on already says the engine is there.
// DLSS needs NGX and its model, FSR 4 AMD's libraries with FSR 4 for the GPU, FSR 3.1 runs on any GPU the back end
// runs on: on already says the engine is there (vk_dlaa_frame).
static int dl_active(void) { return !D.failed && D.on; }
// The scene is followed (its G-buffer, light target, end and camera): for DLSS, or with DLSS off for frame generation.
static int track(void) { return dl_active() || D.fg; }
int vk_dlaa_fg_on; // D.fg for vk_exec_draw.c's per-draw test (vk_dlaa_hud)
int vk_upscaler_running(void) {
return dl_active() && D.evals ? (D.fsr ? UPSCALER_FSR3 : UPSCALER_DLSS) : UPSCALER_OFF;
return dl_active() && D.evals ? (D.fsr ? D.fsr : UPSCALER_DLSS) : UPSCALER_OFF;
}
// For the menu. DLSS: after a start with it picked, what NGX said; before, an NVIDIA GPU and the DLL (an NVIDIA GPU
// without RTX shows only once NGX came up). FSR 3.1 is built in.
// without RTX shows only once NGX came up). FSR 4 likewise: Windows, AMD's two libraries, then after a start with it
// picked what they offered for the device (vk_ffx_init), before one an AMD GPU (the libraries decide which Radeons get
// FSR 4, so another Radeon shows only after that start). FSR 3.1 is built in.
int vk_upscaler_missing(int engine) {
if (engine == UPSCALER_FSR4) {
#ifndef _WIN32
return UPSCALER_MISSING_OS;
#else
if (!res_ffx_dlls()) return UPSCALER_MISSING_DLL;
if (vk_ffx_tried()) return vk_ffx_available() ? 0 : UPSCALER_MISSING_GPU;
return vk_ctx()->props.vendorID == 0x1002 ? 0 : UPSCALER_MISSING_GPU;
#endif
}
if (engine != UPSCALER_DLSS) return 0;
if (!res_dlss_dll()) return UPSCALER_MISSING_DLL;
if (N.tried) return N.available ? 0 : UPSCALER_MISSING_GPU;
@@ -377,7 +419,8 @@ static int fg_objects(void) {
int vk_fg_objects_on(void) { return D.fg && fg_objects(); }
// The per-object motion's gates (vk_mvprev.c's tables, vk_usnap.c's host copy, vk_exec_draw.c's motion draws and
// lock): the upscaler that reads the motion image (objmv: DLSS once NGX came up, or FSR 3.1 picked at start), or frame
// lock): the upscaler that reads the motion image (objmv: DLSS once NGX came up, FSR 3.1 picked at start, or FSR 4
// once it came up), or frame
// generation following the scene with its objects. Frame generation is off with either upscaler, so the second term is
// 0 whenever one runs.
int vk_objmv_wanted(void) { return objmv || vk_fg_objects_on(); }
@@ -1303,18 +1346,18 @@ static int scene_shaped(const VkExecTarget *c) {
return a * 20 >= b * 19 && b * 20 >= a * 19;
}
// FSR 3.1's half of evaluate (vk_fsr3.cpp), after the motion vectors and the recorder's drain: the camera, the time step
// and the history reset, then the dispatch into e->out. 0 when it failed (DLAA is then off for the run). The camera
// comes from the scene camera block's rows 0-10 (vk_fg.cpp vk_fg_camera, which frame generation reads too: FSR 3.1
// wants the near and far planes and the vertical field of view for its depth tests); a cut there (a cutscene's camera
// jump) starts a new history. The block's bytes are the snapshot's host copy, which vk_usnap.c keeps while the
// per-object motion runs (vk_objmv_wanted, so with FSR 3.1).
// FSR's half of evaluate (FSR 3.1: vk_fsr3.cpp, FSR 4: vk_ffx.c), after the motion vectors and the recorder's drain:
// the camera, the time step and the history reset, then the dispatch into e->out. Both engines get the same inputs.
// 0 when it failed (DLAA is then off for the run). The camera comes from the scene camera block's rows 0-10 (vk_fg.cpp
// vk_fg_camera, which frame generation reads too: FSR wants the near and far planes and the vertical field of view
// for its depth tests); a cut there (a cutscene's camera jump) starts a new history. The block's bytes are the
// snapshot's host copy, which vk_usnap.c keeps while the per-object motion runs (vk_objmv_wanted, so with FSR).
static int fsr_evaluate(VkExec *ex, struct Size *e, const VkExecTarget *t, const VkExecTarget *z, uint32_t ow,
uint32_t oh, float jx, float jy, int timed) {
static VkFgScene cam = {.near_m = 0.1f, .far_m = 25000.0f, .fov_y = 0.8727f}; // until the first camera read
// the SDK takes whole images: the scene's targets are level 0, layer 0 of their own images
if (t->level || t->base_layer || z->level || z->base_layer || z->format != VK_FORMAT_D32_SFLOAT)
return dl_fail("FSR 3.1 input (not level 0, layer 0 of a colour and a D32F depth image)", 0), 0;
return dl_fail("FSR input (not level 0, layer 0 of a colour and a D32F depth image)", 0), 0;
const float *rows = D.cam_addr ? (const float *)vk_usnap_bytes(D.cam_addr, 11 * 16) : NULL;
int cut = rows && vk_fg_camera(rows, nvn_depth_minus_w(), D.cam_dr, &cam);
if (D.last_color != t->image) D.reset = 1, D.why[2]++, D.last_color = t->image;
@@ -1326,19 +1369,31 @@ static int fsr_evaluate(VkExec *ex, struct Size *e, const VkExecTarget *t, const
// without (vk_dlaa_skip_draw), so without it FSR's picture is softer than the game's own
int sharp = cfg_int("TOTK_FSR_SHARPNESS");
sharp = sharp < 0 ? 0 : sharp > 100 ? 100 : sharp;
Fsr3Frame fr = {.color = t->image, .color_format = t->format, .depth = z->image, .mv = e->mv, .out = e->out,
.w = t->width, .h = t->height, .ow = ow, .oh = oh, .jx = jx, .jy = jy, .near_m = cam.near_m,
.far_m = cam.infinite || cam.far_m <= cam.near_m ? 1e5f : cam.far_m, .fov_y = cam.fov_y,
.dt_ms = dt > 0 && dt < 100 ? (float)dt : 16.67f, .reset = D.reset, .sharpness = sharp / 100.0f,
.fence = ex->fence};
float far_m = cam.infinite || cam.far_m <= cam.near_m ? 1e5f : cam.far_m;
float dt_ms = dt > 0 && dt < 100 ? (float)dt : 16.67f;
uint64_t c0 = timed ? kern_now_ns() : 0;
int ok = fsr3_dispatch(ex->cb, &fr);
int ok;
if (D.fsr == UPSCALER_FSR4) {
VkFfxDispatch fd = {.color = {t->image, t->format, t->width, t->height},
.depth = {z->image, z->format, t->width, t->height},
.mv = {e->mv, VK_FORMAT_R16G16_SFLOAT, t->width, t->height},
.out = {e->out, VK_FORMAT_R16G16B16A16_SFLOAT, ow, oh}, .jx = jx, .jy = jy,
.dt_ms = dt_ms, .cam_near = cam.near_m, .cam_far = far_m, .fov_y = cam.fov_y,
.sharpness = sharp / 100.0f, .reset = D.reset, .fence = ex->fence};
ok = vk_ffx_dispatch(ex->cb, &fd);
} else {
Fsr3Frame fr = {.color = t->image, .color_format = t->format, .depth = z->image, .mv = e->mv, .out = e->out,
.w = t->width, .h = t->height, .ow = ow, .oh = oh, .jx = jx, .jy = jy, .near_m = cam.near_m,
.far_m = far_m, .fov_y = cam.fov_y, .dt_ms = dt_ms, .reset = D.reset,
.sharpness = sharp / 100.0f, .fence = ex->fence};
ok = fsr3_dispatch(ex->cb, &fr);
}
if (timed) T.cpu_ngx += kern_now_ns() - c0;
if (!ok) {
// the SDK may have bound a pipeline or descriptor sets of its own before it failed: the next draw binds
// everything again, and the game's own scaling and FXAA run from the next frame (DLAA off for the run)
vk_exec_draw_new_cb(ex);
return dl_fail("FSR 3.1 dispatch", 0), 0;
return dl_fail(D.fsr == UPSCALER_FSR4 ? "FSR 4 dispatch" : "FSR 3.1 dispatch", 0), 0;
}
return 1;
}
@@ -1487,7 +1542,7 @@ engine_done:
rt_log("dlaa: %llu frames anti-aliased%s (scene %ux%u, output %ux%u; %llu before the effects, %llu frames without the "
"DLAA point, %llu with camera motion, %llu with the characters' mask, %llu without a camera, %llu jitter "
"holds; resets: %llu size, %llu camera, %llu target; reactive mask %llu, without its copy %llu)",
(unsigned long long)D.evals, D.fsr ? " by FSR 3.1" : "", w, h, ow, oh, (unsigned long long)D.fx_frames, (unsigned long long)D.frames_missed,
(unsigned long long)D.evals, D.fsr == UPSCALER_FSR4 ? " by FSR 4" : D.fsr ? " by FSR 3.1" : "", w, h, ow, oh, (unsigned long long)D.fx_frames, (unsigned long long)D.frames_missed,
(unsigned long long)D.mv_frames, (unsigned long long)D.masked, (unsigned long long)D.mv_none,
(unsigned long long)D.holds, (unsigned long long)D.why[0], (unsigned long long)D.why[1],
(unsigned long long)D.why[2], (unsigned long long)R.made, (unsigned long long)R.missed);
@@ -1832,9 +1887,9 @@ void vk_dlaa_pass(VkExec *ex) {
}
// TOTK_DLSS, read at each present (the menu switches it live): the scene size of the mode (resolution.c) and the
// texture bias that goes with it while the upscaler runs. DLSS takes NVIDIA's log2(scene / output); FSR 3.1 takes AMD's
// log2(scene / output) - 1 (FidelityFX FSR 3 upscaler docs, "Mipmap biasing"), so -1 also in place. The bias follows
// the mode and the upscaler going on or off; the engine is fixed for the run.
// texture bias that goes with it while the upscaler runs. DLSS takes NVIDIA's log2(scene / output); FSR 3.1 and FSR 4
// take AMD's log2(scene / output) - 1 (FidelityFX FSR 3 upscaler docs, "Mipmap biasing"), so -1 also in place. The
// bias follows the mode and the upscaler going on or off; the engine is fixed for the run.
static void dlss_mode(void) {
static char mode[32];
static float bias; // what the material samplers have (vk_texture.c starts at 0)
@@ -1844,7 +1899,8 @@ static void dlss_mode(void) {
res_dlss_mode(m);
}
float b = 0.0f;
if (dl_active()) b = res_dlss_lod_bias() - (vk_upscaler_engine() == UPSCALER_FSR3 ? 1.0f : 0.0f);
int e = vk_upscaler_engine();
if (dl_active()) b = res_dlss_lod_bias() - (e == UPSCALER_FSR3 || e == UPSCALER_FSR4 ? 1.0f : 0.0f);
if (b != bias) bias = b, vk_sampler_dlss_bias(b);
}
@@ -1870,17 +1926,24 @@ void vk_dlaa_frame(void) {
vk_dlaa_swap_img = NULL, vk_dlaa_swap_view = VK_NULL_HANDLE;
dlss_mode();
preset_check();
int fsr = vk_upscaler_engine() == UPSCALER_FSR3; // fixed for the run: D.fsr never changes while on
int on = (fsr || N.available) && vk_upscaler_on();
// the engine is fixed for the run: D.fsr never changes while on. FSR 4 runs once AMD's libraries offered it for
// the device (vk_ffx_init said why not otherwise, and the upscaler stays off)
int e = vk_upscaler_engine();
int fsr = e == UPSCALER_FSR3 || e == UPSCALER_FSR4 ? e : 0;
int ready = e == UPSCALER_FSR3 || (e == UPSCALER_FSR4 ? vk_ffx_available() : N.available);
int on = ready && vk_upscaler_on();
vk_fg_frame();
// frame generation with an upscaler is not built yet: with FSR 3.1 picked it stays off (said once)
// frame generation with an upscaler is not built yet: with FSR picked it stays off (said once)
static int fg_said;
if (fsr && on && vk_fg_engine() != VK_FG_OFF && !fg_said++)
rt_log("fg: frame generation off while FSR 3.1 upscales the scene (scene_upscaler = fsr3)");
rt_log("fg: frame generation off while %s upscales the scene (scene_upscaler = %s)", engine_name(fsr),
engine_value(fsr));
int fg = fsr && on ? 0 : vk_fg_wanted(on && !D.failed);
D.bloom = D.hud = D.hud_wait = D.fin = D.gen = D.fg_mv_ok = 0;
if (on != D.on || fg != D.fg) {
if (on != D.on) rt_log("dlaa: %s", on ? (fsr ? "on with FSR 3.1" : "on") : "off");
if (on != D.on)
rt_log("dlaa: %s%s%s", on ? "on" : "off", on && fsr ? " with " : "",
on && fsr == UPSCALER_FSR4 ? vk_ffx_version() : on && fsr ? "FSR 3.1" : "");
if (fg != D.fg) rt_log("dlaa: the scene is %s for frame generation", fg ? "followed" : "no longer followed");
D.on = on, D.fg = vk_dlaa_fg_on = fg, D.fsr = fsr;
// either way the next DLAA frame starts a new history from an unjittered frame
@@ -1922,10 +1985,12 @@ void vk_dlaa_frame(void) {
// stretched over the whole screen.
static const uint64_t FXAA_FS[] = {0xf450003ebeb3dc52ull, 0x0a12f4bc2a9a4fbeull, 0x5c43ae18948d52cbull,
0xaad42238801d31d8ull, 0xde20aef90fea4ce6ull, 0x755964e8dce7f34dull};
// The fragment shader of the FXAA's first pass, the copy of the scene target into the scratch target (this build's
// translator, seen in 1.4.3 frame logs; another hash leaves the draw alone). See vk_dlaa_skip_draw for why FSR 3.1's
// frames skip it where it copies the scene target onto itself.
static const uint64_t FXAA_COPY_FS[] = {0xa0fd34391f2af811ull};
// The fragment shader of the FXAA's first pass, the copy of the scene target into the scratch target (another hash
// leaves the draw alone): this build's translator, seen in 1.4.3 frame logs, and the one with patch 0017, whose two
// support buffer fields change every fragment shader's hash (as with FXAA_FS above), read by codexx-dev from a 1.4.3
// run with FSR on (pull request #1245). See vk_dlaa_skip_draw for why FSR's frames skip it where it copies the scene
// target onto itself.
static const uint64_t FXAA_COPY_FS[] = {0xa0fd34391f2af811ull, 0x9d065204aac9766bull};
// Chunks of one submission look shaders up side by side: an entry's hash is stored before its shader, and entries are
// added under the lock.
@@ -1970,14 +2035,14 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) {
"FXAA_FS): the FXAA stays on", (unsigned long long)fx_off_frames);
}
}
// FSR 3.1 in place (the scene as large as the output, so no scaling draw follows) goes without the game's FXAA
// and its copy of the scene target onto itself on every frame, as codexx-dev found for FSR (pull request #1245,
// vk_dlaa.c vk_dlaa_skip_draw there). Measured there on 1.4.3 at a 2560x1440 scene and output: with the upscaler on
// the game ran its FXAA, which also sharpens, on 17 frames in every 96 and on the others drew its copy shader from
// the scene target onto itself, so the picture went soft and sharp in turns. Here the dynamic resolution stays at
// 100 % while FSR 3.1 runs (resolution.c res_dynres_live) and FSR sharpens its own output (fsr_sharpness,
// fsr_evaluate) in place of the FXAA's sharpening. Scaled frames (D.up) need nothing more: there FSR's picture
// already replaces the scaling FXAA draw below.
// FSR 3.1 or FSR 4 in place (the scene as large as the output, so no scaling draw follows) goes without the game's
// FXAA and its copy of the scene target onto itself on every frame, as codexx-dev found for FSR (pull request
// #1245, vk_dlaa.c vk_dlaa_skip_draw there). Measured there on 1.4.3 at a 2560x1440 scene and output: with the
// upscaler on the game ran its FXAA, which also sharpens, on 17 frames in every 96 and on the others drew its copy
// shader from the scene target onto itself, so the picture went soft and sharp in turns. Here the dynamic
// resolution stays at 100 % while FSR runs (resolution.c res_dynres_live) and FSR sharpens its own output
// (fsr_sharpness, fsr_evaluate) in place of the FXAA's sharpening. Scaled frames (D.up) need nothing more: there
// FSR's picture already replaces the scaling FXAA draw below.
int fsr_in_place = D.done && !D.up && D.fsr;
if (fxaa && !D.up && !fsr_in_place) return 0; // nothing to skip: no shader lookup per draw at the defaults
if (!fs) return 0;
@@ -2003,7 +2068,7 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) {
static int logged_fxaa, logged_copy;
if (known && ex->depth.image) {
if (!logged_fxaa)
logged_fxaa = 1, rt_log("dlaa: FSR 3.1 skips the game's FXAA (fragment shader %016llx) and sharpens its "
logged_fxaa = 1, rt_log("dlaa: FSR skips the game's FXAA (fragment shader %016llx) and sharpens its "
"own picture (fsr_sharpness)", (unsigned long long)h);
return 1;
}
@@ -2011,7 +2076,7 @@ int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) {
for (size_t i = 0; i < sizeof FXAA_COPY_FS / sizeof FXAA_COPY_FS[0]; i++) copy |= h == FXAA_COPY_FS[i];
if (copy && ex->color[0].image == D.color.image && vk_exec_draw_samples(ex, fs, D.color.img)) {
if (!logged_copy)
logged_copy = 1, rt_log("dlaa: FSR 3.1 skips the game's copy of the scene target onto itself (fragment "
logged_copy = 1, rt_log("dlaa: FSR skips the game's copy of the scene target onto itself (fragment "
"shader %016llx)", (unsigned long long)h);
return 1;
}
+6 -5
View File
@@ -1,5 +1,5 @@
// DLAA (vk_dlaa.c): the scene upscaler, NVIDIA DLSS or AMD FSR 3.1 (vk_fsr3.cpp), behind scene_upscaler (dlaa = 1 without
// it: DLSS).
// DLAA (vk_dlaa.c): the scene upscaler, NVIDIA DLSS, AMD FSR 3.1 (vk_fsr3.cpp) or AMD FSR 4 (vk_ffx.c, Windows), behind
// scene_upscaler (dlaa = 1 without it: DLSS).
#pragma once
#include "vk.h"
@@ -15,9 +15,10 @@ void vk_dlaa_device_exts(const VkExtensionProperties *have, uint32_t nhave, cons
void vk_dlaa_init(void);
// 1 when dlaa is on and NGX came up with DLSS (after vk_dlaa_init): a DLSS mode's smaller scene is scaled up by DLSS.
int vk_dlaa_available(void);
// 1 when the per-object motion runs (DLSS's and FSR 3.1's half after vk_dlaa_init, frame generation's live): DLSS
// with NGX up (vk_dlaa_available), FSR 3.1 picked as the scene upscaler, or frame generation following the scene with
// its objects (vk_fg_objects_on: TOTK_FG_OBJECTS, default 1).
// 1 when the per-object motion runs (the upscaler's half after vk_dlaa_init, frame generation's live): DLSS with NGX
// up (vk_dlaa_available), FSR 3.1 picked as the scene upscaler, FSR 4 picked and offered for the device
// (vk_ffx_available), or frame generation following the scene with its objects (vk_fg_objects_on: TOTK_FG_OBJECTS,
// default 1).
int vk_objmv_wanted(void);
int vk_fg_objects_on(void);
// vk_exec.c vk_exec_pass_begin, once the pass's targets are resolved and before its barrier: arms the frame on the
+296
View File
@@ -0,0 +1,296 @@
// AMD FSR 4 for the scene upscaler (vk_ffx.h). The FSR SDK 2.4 ships its Vulkan effects as signed DLLs behind a
// loader: amd_fidelityfx_loader_vk.dll exports the ffx-api entry points and finds the effect DLL
// (amd_fidelityfx_upscaler_vk.dll) next to itself. Both are loaded from the executable's folder at run time; no SDK
// code is compiled in, only the descriptor layouts of ffx_api_min.h.
//
// The upscaler DLL offers several versions (FSR 4.x, FSR 3.1.x) and decides by itself which ones a device can run:
// vk_ffx_init lists them and pins the newest 4.x. A device the DLL offers no FSR 4 for runs without the upscaler (the
// log and the menu say so): FSR 3.1 is scene_upscaler = fsr3, built from the SDK 1.1.4 sources (vk_fsr3.cpp), not a
// fallback of this DLL. Every context is created with the pinned version (ffxOverrideVersion).
//
// What FSR 4 gets is what FSR 3.1 gets (vk_dlaa.c fsr_evaluate): the R11G11B10F light target as linear HDR colour, the
// D32F scene depth (standard direction, the far plane finite), motion vectors at the render size in render pixels
// pointing from this frame's position to last frame's without the jitter (motionVectorScale 1), the jitter the scene
// was drawn with, the camera's planes and field of view. That is FSR's own convention: its guide derives the
// projection offset as (2 jx / w, -2 jy / h), which moves the picture by (jx, jy) window pixels with y down, the way
// vk_dlaa_viewport moves the viewport. The exposure is FSR's own (AUTO_EXPOSURE), as codexx-dev's pull request #1245
// ran it on an RX 9070 XT.
#include "vk_ffx.h"
#include "cfg.h"
#include "host.h"
#ifndef _WIN32
int vk_ffx_wanted(void) { return 0; }
void vk_ffx_device_exts(const VkExtensionProperties *have, uint32_t nhave, const char **ext, uint32_t *n, uint32_t max) {
(void)have, (void)nhave, (void)ext, (void)n, (void)max;
}
void vk_ffx_init(void) {}
int vk_ffx_tried(void) { return 0; }
int vk_ffx_available(void) { return 0; }
int vk_ffx_dispatch(VkCommandBuffer cb, const VkFfxDispatch *d) { return (void)cb, (void)d, 0; }
void vk_ffx_release(void) {}
const char *vk_ffx_version(void) { return ""; }
#else
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ffx_api_min.h"
#define FFX_LOADER L"amd_fidelityfx_loader_vk.dll"
#define FFX_MAX_VERSIONS 16
// The SDK's Vulkan backend writes a dispatch's descriptor sets and constants into rings this deep and frees the views
// of the dispatch that many back without knowing the GPU (FFX_MAX_QUEUED_FRAMES in the SDK's ffx_types.h, as
// vk_fsr3.cpp wait_ring reads it for SDK 1.1.4).
#define FFX_QUEUED 4
static struct {
HMODULE dll;
PfnFfxCreateContext create;
PfnFfxDestroyContext destroy;
PfnFfxQuery query;
PfnFfxDispatch dispatch;
int tried, loaded, available, failed;
VkDeviceContext dev;
uint64_t version_id;
char version[48];
ffxContext ctx; // the live context, made for ow x oh
uint32_t ow, oh;
uint64_t ring[FFX_QUEUED], n, waits; // the fences of the last dispatches (wait_ring)
} F;
int vk_ffx_wanted(void) { return vk_upscaler_engine() == UPSCALER_FSR4; }
static int loader_load(void) {
if (F.tried) return F.loaded;
F.tried = 1;
wchar_t path[MAX_PATH + 64];
DWORD len = GetModuleFileNameW(NULL, path, MAX_PATH);
while (len && path[len - 1] != L'\\') len--;
path[len] = 0;
wcscat(path, FFX_LOADER);
// LOAD_WITH_ALTERED_SEARCH_PATH: the loader's own imports and the effect DLL resolve from the executable's folder
F.dll = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (!F.dll) {
rt_log("fsr4: cannot load amd_fidelityfx_loader_vk.dll next to totk.exe (error %lu): the scene upscaler is off",
GetLastError());
return 0;
}
F.create = (PfnFfxCreateContext)(void *)GetProcAddress(F.dll, "ffxCreateContext");
F.destroy = (PfnFfxDestroyContext)(void *)GetProcAddress(F.dll, "ffxDestroyContext");
F.query = (PfnFfxQuery)(void *)GetProcAddress(F.dll, "ffxQuery");
F.dispatch = (PfnFfxDispatch)(void *)GetProcAddress(F.dll, "ffxDispatch");
if (!F.create || !F.destroy || !F.query || !F.dispatch) {
rt_log("fsr4: amd_fidelityfx_loader_vk.dll lacks the ffx-api entry points: the scene upscaler is off");
return 0;
}
return F.loaded = 1;
}
static int has(const VkExtensionProperties *have, uint32_t nhave, const char *name) {
for (uint32_t i = 0; i < nhave; i++)
if (!strcmp(have[i].extensionName, name)) return 1;
return 0;
}
static void add(const VkExtensionProperties *have, uint32_t nhave, const char **ext, uint32_t *n, uint32_t max,
const char *name) {
for (uint32_t i = 0; i < *n; i++)
if (!strcmp(ext[i], name)) return;
if (has(have, nhave, name) && *n < max) ext[(*n)++] = name;
}
// The extensions the FSR SDK's own sample enables for its effects (Cauldron2 device_vk.cpp): cooperative matrix and
// 8-bit floats for FSR 4's network where the device has them. The rest it uses (16-bit floats and storage, integer
// dot products, subgroup size control) is core Vulkan 1.3, which vk_device.c enables as far as the driver reports it.
void vk_ffx_device_exts(const VkExtensionProperties *have, uint32_t nhave, const char **ext, uint32_t *n, uint32_t max) {
if (!vk_ffx_wanted()) return;
add(have, nhave, ext, n, max, VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME);
#ifdef VK_EXT_SHADER_FLOAT8_EXTENSION_NAME
add(have, nhave, ext, n, max, VK_EXT_SHADER_FLOAT8_EXTENSION_NAME);
#endif
}
void vk_ffx_init(void) {
if (!vk_ffx_wanted() || !loader_load()) return;
const VkCtx *c = vk_ctx();
F.dev = (VkDeviceContext){c->device, c->phys, vkGetDeviceProcAddr};
uint64_t count = FFX_MAX_VERSIONS, ids[FFX_MAX_VERSIONS] = {0};
const char *names[FFX_MAX_VERSIONS] = {0};
struct ffxQueryDescGetVersions q = {.header = {FFX_API_QUERY_DESC_TYPE_GET_VERSIONS, NULL},
.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE, .device = &F.dev,
.outputCount = &count, .versionIds = ids, .versionNames = names};
ffxReturnCode_t r = F.query(NULL, &q.header);
if (r != FFX_API_RETURN_OK || !count) {
rt_log("fsr4: no upscaler for this device (query %u, %llu versions; is amd_fidelityfx_upscaler_vk.dll next to "
"totk.exe?): the scene upscaler is off", (unsigned)r, (unsigned long long)count);
return;
}
if (count > FFX_MAX_VERSIONS) count = FFX_MAX_VERSIONS;
char list[256] = "";
// The newest 4.x the DLL offers for this device; the DLL leaves FSR 4 out for GPUs it does not run on
int best = -1, best_minor = 0, best_patch = 0;
for (uint64_t i = 0; i < count; i++) {
const char *nm = names[i] ? names[i] : "?";
size_t used = strlen(list);
snprintf(list + used, sizeof list - used, "%s%s", i ? ", " : "", nm);
int ma = 0, mi = 0, pa = 0;
if (sscanf(nm, "%d.%d.%d", &ma, &mi, &pa) < 1 || ma != 4) continue;
if (best < 0 || mi > best_minor || (mi == best_minor && pa > best_patch))
best = (int)i, best_minor = mi, best_patch = pa;
}
if (best < 0) {
rt_log("fsr4: the FSR libraries offer %s for this device, no FSR 4: the scene upscaler is off", list);
return;
}
F.version_id = ids[best];
snprintf(F.version, sizeof F.version, "FSR %s", names[best]);
F.available = 1;
rt_log("fsr4: upscaler versions for this device: %s; using %s", list, F.version);
}
int vk_ffx_tried(void) { return F.tried; }
int vk_ffx_available(void) { return vk_ffx_wanted() && F.available; }
const char *vk_ffx_version(void) { return F.available ? F.version : ""; }
// Messages from the upscaler (errors and warnings), in UTF-16; into the log as UTF-8.
static void on_message(uint32_t type, const wchar_t *msg) {
char s[512];
if (!msg || !WideCharToMultiByte(CP_UTF8, 0, msg, -1, s, (int)sizeof s, NULL, NULL)) return;
rt_log("fsr4: %s: %s", type == FFX_API_MESSAGE_TYPE_ERROR ? "error" : "warning", s);
}
// The context for an ow x oh output, any scene up to that size (DYNAMIC_RESOLUTION: the modes and the game's tiers
// change the scene without a new context), as vk_fsr3.cpp create makes FSR 3.1's.
static int create(uint32_t ow, uint32_t oh) {
struct ffxOverrideVersion ov = {.header = {FFX_API_DESC_TYPE_OVERRIDE_VERSION, NULL}, .versionId = F.version_id};
struct ffxCreateContextDescUpscaleVersion ver = {
.header = {FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE_VERSION, &ov.header}, .version = FFX_UPSCALER_VERSION};
struct ffxCreateBackendVKDesc be = {.header = {FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK, &ver.header},
.deviceContext = F.dev};
// Linear HDR scene light with the upscaler's own exposure; standard depth with a finite far plane, as FSR 3.1's
uint32_t flags = FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE |
FFX_UPSCALE_ENABLE_DYNAMIC_RESOLUTION;
if (rt_knob("FSR4_DEBUG", "0")) flags |= FFX_UPSCALE_ENABLE_DEBUG_CHECKING; // TOTK_FSR4_DEBUG=1: API checks
struct ffxCreateContextDescUpscale cd = {.header = {FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE, &be.header},
.flags = flags, .maxRenderSize = {ow, oh}, .maxUpscaleSize = {ow, oh},
.fpMessage = on_message};
ffxContext ctx = NULL;
ffxReturnCode_t r = F.create(&ctx, &cd.header, NULL);
if (r != FFX_API_RETURN_OK || !ctx) {
rt_log("fsr4: context creation failed (%u) at %ux%u: FSR 4 off for this run", (unsigned)r, ow, oh);
return 0;
}
struct ffxQueryGetProviderVersion pv = {.header = {FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION, NULL}};
F.query(&ctx, &pv.header);
rt_log("fsr4: context up to %ux%u -> %ux%u with %s (flags %#x)", ow, oh, ow, oh,
pv.versionName ? pv.versionName : F.version, flags);
F.ctx = ctx, F.ow = ow, F.oh = oh, F.n = 0;
memset(F.ring, 0, sizeof F.ring);
return 1;
}
static void destroy(void) {
if (F.ctx) F.destroy(&F.ctx, NULL);
F.ctx = NULL;
}
static uint32_t surface_format(VkFormat f) {
switch (f) {
case VK_FORMAT_B10G11R11_UFLOAT_PACK32: return FFX_API_SURFACE_FORMAT_R11G11B10_FLOAT;
case VK_FORMAT_R16G16B16A16_SFLOAT: return FFX_API_SURFACE_FORMAT_R16G16B16A16_FLOAT;
case VK_FORMAT_R16G16_SFLOAT: return FFX_API_SURFACE_FORMAT_R16G16_FLOAT;
case VK_FORMAT_D32_SFLOAT: return FFX_API_SURFACE_FORMAT_R32_FLOAT;
default: return FFX_API_SURFACE_FORMAT_UNKNOWN;
}
}
// Every image of the scene upscaler stays in VK_IMAGE_LAYOUT_GENERAL: GENERIC_READ and UNORDERED_ACCESS are the
// states the Vulkan backend maps to that layout (ffx_vk.cpp getVKImageLayoutFromResourceState), and it puts each
// resource back into the state it was given at the end of the dispatch.
static struct FfxApiResource resource(const VkFfxImage *im, uint32_t usage, uint32_t state) {
struct FfxApiResource r;
memset(&r, 0, sizeof r);
if (!im->image) return r;
r.resource = (void *)im->image;
r.description = (struct FfxApiResourceDescription){.type = FFX_API_RESOURCE_TYPE_TEXTURE2D,
.format = surface_format(im->format), .width = im->width,
.height = im->height, .depth = 1, .mipCount = 1, .usage = usage};
r.state = state;
return r;
}
// With the game's two or three frames in flight the dispatch FFX_QUEUED - 1 back is long done; should it not be, its
// submission is waited for here (counted), as vk_fsr3.cpp wait_ring does for FSR 3.1.
static void wait_ring(uint64_t fence) {
if (F.n >= FFX_QUEUED - 1) {
uint64_t back = F.ring[(F.n + 1) % FFX_QUEUED];
if (back && vk_sync_fence_done() < back) {
if (!F.waits++) rt_log("fsr4: waiting for the submission of a dispatch %d back (more frames in flight than "
"the SDK's rings hold)", FFX_QUEUED - 1);
vk_sync_fence_wait(back, 2000000000ull);
}
}
F.ring[F.n % FFX_QUEUED] = fence;
}
int vk_ffx_dispatch(VkCommandBuffer cb, const VkFfxDispatch *d) {
if (!F.available || F.failed) return 0;
uint32_t ow = d->out.width, oh = d->out.height;
if (!F.ctx || ow != F.ow || oh != F.oh) {
if (F.ctx) {
vkDeviceWaitIdle(vk_ctx()->device); // what the old context recorded is queued or submitted
destroy();
}
if (!create(ow, oh)) return F.failed = 1, 0;
}
if (d->color.width > F.ow || d->color.height > F.oh) {
rt_log("fsr4: a %ux%u scene is larger than the %ux%u output: FSR 4 off for this run", d->color.width,
d->color.height, F.ow, F.oh);
return F.failed = 1, 0;
}
wait_ring(d->fence);
struct ffxDispatchDescUpscale u;
memset(&u, 0, sizeof u);
u.header.type = FFX_API_DISPATCH_DESC_TYPE_UPSCALE;
u.commandList = (void *)cb;
u.color = resource(&d->color, FFX_API_RESOURCE_USAGE_READ_ONLY, FFX_API_RESOURCE_STATE_GENERIC_READ);
u.depth = resource(&d->depth, FFX_API_RESOURCE_USAGE_DEPTHTARGET, FFX_API_RESOURCE_STATE_GENERIC_READ);
u.motionVectors = resource(&d->mv, FFX_API_RESOURCE_USAGE_READ_ONLY, FFX_API_RESOURCE_STATE_GENERIC_READ);
u.output = resource(&d->out, FFX_API_RESOURCE_USAGE_UAV, FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
// (no reactive or transparency mask: FSR 3.1 gets none either)
u.jitterOffset = (struct FfxApiFloatCoords2D){d->jx, d->jy};
u.motionVectorScale = (struct FfxApiFloatCoords2D){1.0f, 1.0f}; // render pixels already
u.renderSize = (struct FfxApiDimensions2D){d->color.width, d->color.height};
u.upscaleSize = (struct FfxApiDimensions2D){ow, oh};
u.enableSharpening = d->sharpness > 0;
u.sharpness = d->sharpness > 1.0f ? 1.0f : d->sharpness;
u.frameTimeDelta = d->dt_ms;
u.preExposure = 1.0f;
u.reset = d->reset != 0;
u.cameraNear = d->cam_near;
u.cameraFar = d->cam_far;
u.cameraFovAngleVertical = d->fov_y;
u.viewSpaceToMetersFactor = 1.0f; // TotK's world units are metres
ffxReturnCode_t r = F.dispatch(&F.ctx, &u.header);
F.n++;
if (r != FFX_API_RETURN_OK) {
rt_log("fsr4: dispatch failed (%u) at %ux%u -> %ux%u: FSR 4 off for this run", (unsigned)r, d->color.width,
d->color.height, ow, oh);
return F.failed = 1, 0;
}
return 1;
}
void vk_ffx_release(void) {
const VkCtx *c = vk_ctx();
if (!F.ctx || !c || !c->device) return;
vkDeviceWaitIdle(c->device);
if (F.waits) rt_log("fsr4: %llu dispatches waited for an earlier one's submission", (unsigned long long)F.waits);
destroy();
}
#endif
+41
View File
@@ -0,0 +1,41 @@
// AMD FSR 4 (vk_ffx.c), the fourth engine of vk_dlaa.c's scene upscaler (scene_upscaler = fsr4): the frame DLSS and
// FSR 3.1 get goes to FSR 4 through AMD's FSR SDK 2.4 signed libraries, amd_fidelityfx_loader_vk.dll and
// amd_fidelityfx_upscaler_vk.dll next to the executable. Windows only; elsewhere every call does nothing.
#pragma once
#include "vk.h"
// FSR 4 is the scene upscaler picked at start (vk_dlaa.c vk_upscaler_engine); the device may still lack it.
int vk_ffx_wanted(void);
// vk_device.c, while it builds the device: the extensions FSR 4's shaders use (cooperative matrix, 8-bit floats) join
// the list when the device has them; their feature structures are chained there.
void vk_ffx_device_exts(const VkExtensionProperties *have, uint32_t nhave, const char **ext, uint32_t *n, uint32_t max);
void vk_ffx_init(void); // vk_dlaa.c vk_dlaa_init, after the device exists: loads the loader and pins FSR 4
int vk_ffx_tried(void); // vk_ffx_init ran (FSR 4 picked at start, on Windows)
int vk_ffx_available(void); // vk_ffx_init found FSR 4 for this device
typedef struct { // one image FSR reads or writes, in VK_IMAGE_LAYOUT_GENERAL, level 0 and layer 0
VkImage image;
VkFormat format;
uint32_t width, height;
} VkFfxImage;
typedef struct {
VkFfxImage color; // the scene's light (R11G11B10F or RGBA16F, linear), the render size
VkFfxImage depth; // its D32F depth, standard direction (0 near), finite far plane
VkFfxImage mv; // RG16F motion vectors as vk_fsr3.h Fsr3Frame.mv (render pixels, without the jitter)
VkFfxImage out; // RGBA16F with storage, the output size
float jx, jy; // this frame's jitter, render pixels (window x right, y down), as the scene was drawn
float dt_ms; // time since the previous dispatch
float cam_near, cam_far; // the camera's planes (m)
float fov_y; // vertical field of view, radians
float sharpness; // FSR's own sharpening pass (RCAS) on its output, 0..1; 0: none
int reset; // a new history
uint64_t fence; // the submission's timeline value (VkExec.fence)
} VkFfxDispatch;
// Records FSR 4 into cb (every image in GENERAL, left so; no render pass open; recorder drained by the caller). The
// context is made at the first call and again when the output size changes; the scene may be any size up to the
// output. 0 when it failed (logged; FSR 4 stays off for the run). FSR binds pipelines and descriptors of its own.
int vk_ffx_dispatch(VkCommandBuffer cb, const VkFfxDispatch *d);
void vk_ffx_release(void); // vk_device.c destroy_all, before the device goes away; harmless when nothing was made
const char *vk_ffx_version(void); // "FSR 4.1.2" once vk_ffx_init pinned it, "" before or without