AMD FSR 3.1 upscales the 3D scene on the FidelityFX SDK 1.1.4 sources behind scene_upscaler = fsr3, off by default

scene_upscaler (off | dlss | fsr3, read at start) replaces the dlaa toggle on the Screen tab; without the key dlaa = 1
still means DLSS, so nobody gets FSR 3.1 without picking it. The DLSS mode row is the upscaling mode of both engines,
the DLSS model, characters' mask, fixed exposure and effects-after rows show only with DLSS, and the performance
overlay names the upscaler that ran and its mode. resolution.c sizes the scene for the engine picked at start.

runtime/vk_fsr3.cpp drives the SDK's upscaler context on its Vulkan backend directly, as Savage Wind's fsr3.cpp does:
one context per output size with the output as its largest render size (the modes and the dynamic resolution need
no new context), HDR input (the light target before the bloom, where DLSS reads it), render-size motion vectors with
the per-object pass, the camera jitter, the camera's planes and field of view from the scene block (vk_fg_camera; a
cut starts a new history), FSR's sharpening off. vk_dlaa.c calls it at the DLSS point after the recorder's drain;
the NGX path is left as it was. The backend's per-frame rings hold four dispatches: a dispatch waits for the one three
back should it still be in flight. Frame generation stays off while FSR 3.1 runs (logged once).

The SDK subset gains the upscaler component, its shader headers, FSR 1's (its RCAS) and its GLSL, from Savage Wind's
copy unchanged; tools/ffx_shaders.py --effects fu builds its blobs (HDR, 32- and 16-bit floats) into
spirv/ffx_fsr3upscaler_vk.h, and vk_fg.cpp's blob lookup hands those out through vk_fsr3_blob. The luma history's
storage image is declared rgba16f, its images' format (rgba8 in the SDK; the validation layer reported it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Revivedx <82332536+Revivedx@users.noreply.github.com>
This commit is contained in:
committed 2026-11-20 14:39:57 +03:00
1 parent efee9bcf16
commit 14ccef9a80
56 files changed
+18464 -125

No files matched your search

+2 -2
View File
@@ -30,8 +30,8 @@ Code copied or adapted from another project is listed here with its source, the
| SDL 3.4.20, dynamic link, `SDL3.dll` copied next to `totk.exe`. Developer builds use the MSYS2 build (`mingw-w64-ucrt-x86_64-sdl3`, which imports `libiconv-2.dll`, LGPL-2.1, unmodified, copied beside it); the installer release ships the upstream release `SDL3-3.4.20-win32-x64.zip`, which imports no libiconv | https://libsdl.org, Copyright (c) 1997-2026 Sam Lantinga | zlib | `runtime/input_win.c` (gamepad input, rumble, gyro and accelerometer) |
| libopus (MSYS2 `mingw-w64-ucrt-x86_64-opus`), dynamic link, `libopus-0.dll` copied next to `totk.exe` | https://opus-codec.org, Copyright (c) 2001-2023 Xiph.Org, Skype Limited, Octasic, Jean-Marc Valin, Timothy B. Terriberry, CSIRO, Gregory Maxwell, Mark Borgerding, Erik de Castro Lopo, Mozilla, Amazon | BSD-3-Clause | `runtime/ov_media.c` (nn::codec hardware Opus decoder) |
| Dear ImGui 1.91.9 (core and Vulkan back end, unmodified), as vendored by LAS Recomp | https://github.com/ocornut/imgui, via https://github.com/peiikai/LASRecomp @ `da35b83a9611d046a9a681aae668d7085954d37f` (`third_party/imgui/`), Copyright (c) 2014-2025 Omar Cornut | MIT | `runtime/third_party/imgui/` (compiled into `totk.exe` for the in-game menu, `runtime/ui/`) |
| AMD FidelityFX SDK 1.1.4 subset (public host and shader headers, frame interpolation and optical flow components, the Vulkan backend `ffx_vk.cpp` and its GLSL shaders, shared helpers), with three marked Savage Wind patches (64-byte aligned backend scratch arrays, doubled context size where `wchar_t` is 4 bytes, all six descriptor pool sizes) | https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/tree/v1.1.4, Copyright (C) 2024 Advanced Micro Devices, Inc., via https://github.com/Revivedx/SavageWindRecomp @ `bf6146c14c37fee8781a601e5a544b93dff6d75e` (`third_party/FidelityFX/`) | MIT | `runtime/third_party/FidelityFX/` (compiled into `totk.exe`; licence text in `runtime/third_party/FidelityFX/LICENSE.txt`, shipped as `licenses/FidelityFX-SDK-LICENSE.txt`) |
| SavageWindRecomp FidelityFX build support and frame generation set-up: the SDK-to-clang compat header, the glslang SPIR-V shader generator with its resource reflection, the blob lookup and the backend and context creation of `runtime/nvn/vulkan/framegen.cpp`, the pair's present spacing of `runtime/nvn/vulkan/device.c` `present_wait_turn` | https://github.com/Revivedx/SavageWindRecomp @ `bf6146c14c37fee8781a601e5a544b93dff6d75e` (`third_party/FidelityFX/ffx_compat.h`, `tools/ffx_shaders.py`, `runtime/nvn/vulkan/framegen.cpp`, `runtime/nvn/vulkan/device.c`) | MIT | `runtime/third_party/FidelityFX/ffx_compat.h`, `runtime/third_party/FidelityFX/spirv/ffx_shaders_vk.h` (output of `tools/ffx_shaders.py`), `tools/ffx_shaders.py`, `runtime/vk_fg.cpp`, `runtime/vk_backend.c` (`present_pair`) |
| AMD FidelityFX SDK 1.1.4 subset (public host and shader headers, frame interpolation, optical flow and FSR 3 upscaler components, the Vulkan backend `ffx_vk.cpp` and its GLSL shaders, shared helpers), with four marked Savage Wind patches (64-byte aligned backend scratch arrays, doubled context size where `wchar_t` is 4 bytes, all six descriptor pool sizes, the upscaler's Catmull-Rom history reprojection) and one of ours (the upscaler's luma history declared `rgba16f`) | https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/tree/v1.1.4, Copyright (C) 2024 Advanced Micro Devices, Inc., via https://github.com/Revivedx/SavageWindRecomp @ `bf6146c14c37fee8781a601e5a544b93dff6d75e` (`third_party/FidelityFX/`) | MIT | `runtime/third_party/FidelityFX/` (compiled into `totk.exe`; licence text in `runtime/third_party/FidelityFX/LICENSE.txt`, shipped as `licenses/FidelityFX-SDK-LICENSE.txt`) |
| SavageWindRecomp FidelityFX build support, frame generation and FSR 3 upscaler set-up: the SDK-to-clang compat header, the glslang SPIR-V shader generator with its resource reflection and its FSR 3 upscaler permutations, the blob lookup and the backend and context creation of `runtime/nvn/vulkan/framegen.cpp`, the upscaler context with its shared images and the dispatch parameters of `runtime/nvn/vulkan/fsr3.cpp`, the pair's present spacing of `runtime/nvn/vulkan/device.c` `present_wait_turn` | https://github.com/Revivedx/SavageWindRecomp @ `bf6146c14c37fee8781a601e5a544b93dff6d75e` (`third_party/FidelityFX/ffx_compat.h`, `tools/ffx_shaders.py`, `runtime/nvn/vulkan/framegen.cpp`, `runtime/nvn/vulkan/fsr3.cpp`, `runtime/nvn/vulkan/device.c`) | MIT | `runtime/third_party/FidelityFX/ffx_compat.h`, `runtime/third_party/FidelityFX/spirv/ffx_shaders_vk.h` and `ffx_fsr3upscaler_vk.h` (output of `tools/ffx_shaders.py`), `tools/ffx_shaders.py`, `runtime/vk_fg.cpp`, `runtime/vk_fsr3.cpp`, `runtime/vk_backend.c` (`present_pair`) |
| SavageWindRecomp settings menu: two-pane option rows (row look, left / right stepping, hold speed-up, description pane), the menu style and tab bar | https://github.com/Revivedx/SavageWindRecomp @ `575ad88e02f9a89a9a885d90039d48af33c982f4` (`runtime/ui/option_rows.mm`, `runtime/ui/menu.mm`), Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors, Copyright (c) 2026 Peiikai | MIT | `runtime/ui/option_rows.cpp`, `runtime/ui/option_rows.h`, `runtime/ui/menu.cpp` |
| SavageWindRecomp descriptor sets allocated in growing batches per layout | https://github.com/Revivedx/SavageWindRecomp @ `740b18025fe11ba03c117dbb56668db304b5043e` (`runtime/nvn/vulkan/exec.c` vk_alloc_set), Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors, Copyright (c) 2026 Peiikai | MIT | `runtime/vk_exec_draw.c` (alloc_set_batched) |
| SavageWindRecomp performance overlay: the frame ring and its one-second summary, the NVML calls, the sampling loop, the full panel's layout | https://github.com/Revivedx/SavageWindRecomp @ `575ad88e02f9a89a9a885d90039d48af33c982f4` (`runtime/perfmon.c`, `runtime/perfmon.h`, `perf_overlay_draw` in `runtime/ui/menu.mm`), Copyright (c) 2026 Revivedx and the Savage Wind Recomp contributors, Copyright (c) 2026 Peiikai | MIT | `runtime/perfmon.c`, `runtime/perfmon.h`, `runtime/ui/menu.cpp` |
+3 -1
View File
@@ -143,7 +143,7 @@ Many rows below are developer tools that only act together with another setting
| `dyn_delta` (default `1`) | Records only the pipeline dynamic states (cull mode, depth and stencil tests, vertex input, blend enables, equations and write masks, ...) whose values changed since the last draw in the command buffer, also across pipeline changes; `0` records the full set at every change of pipeline state, as before; `ab` alternates with the `ab` blocks. | Fewer commands per pipeline change on the render and recorder threads; a driver that loses dynamic state across pipeline binds would draw with stale state. `TOTK_TRACE=perf` prints the calls and commands per submission. | Caution |
| `feedback` | `0` samples a target that an earlier draw of the same pass wrote with no barrier; `restart` ends and restarts the pass behind a full barrier; otherwise the feedback-loop layout is used when the GPU supports it. | `0` brings back the old behaviour that the barrier fixed, so the picture can break in passes that read a target they draw into; `restart` costs extra passes. | Risky |
| `flush_span` (default `0`) | `1` copies one span from the lowest to the highest flushed address of a pool, as an older version did. | Copies far more data to the GPU in crowded towns: an estimated 30-50 ms of GPU time per large copy over PCIe 3.0 x8. | Caution |
| `frame_gen` (default `off`) | The frame generator: `off`, or `fsr3`, which brings up AMD FSR 3 frame interpolation and optical flow (FidelityFX SDK 1.1.4) at start; with DLSS off the replay follows the scene and records the camera motion vectors, the picture before the HUD and the interpolation of a frame between each two the game draws (`runtime/vk_fg.cpp`). Each frame then goes out as two presents: the generated picture once the GPU has drawn the frame (a timeline wait, not before the pacer's time), the game's half the smoothed interval later (`runtime/vk_backend.c` `present_pair`); `fps_limit` counts the pictures shown and the game draws half, 30 at least (`runtime/frame_rate.c` `frame_step_cap_ns`). Off with DLSS, `replay_workers` above 0, `sync_ahead = 1` or HDR output, and while a menu background or a loading or event fade is open; the game then draws at the whole limit. The swapchain gets one image more. Applies at once: turned on in the menu, the contexts are made at the next frame (a hitch of about 0.1 s once); turned off, they stay until exit. | The controls answer at the drawn rate, about half a frame later. Costs about 1.5 ms of GPU and 0.6 ms of the replay thread per drawn frame at 1080p (RX 9070, 7900X on 4 cores: 94 drawn without it, 86 drawn and 169 shown with it, no limit). For displays of 120 Hz and more. | Caution |
| `frame_gen` (default `off`) | The frame generator: `off`, or `fsr3`, which brings up AMD FSR 3 frame interpolation and optical flow (FidelityFX SDK 1.1.4) at start; with DLSS off the replay follows the scene and records the camera motion vectors, the picture before the HUD and the interpolation of a frame between each two the game draws (`runtime/vk_fg.cpp`). Each frame then goes out as two presents: the generated picture once the GPU has drawn the frame (a timeline wait, not before the pacer's time), the game's half the smoothed interval later (`runtime/vk_backend.c` `present_pair`); `fps_limit` counts the pictures shown and the game draws half, 30 at least (`runtime/frame_rate.c` `frame_step_cap_ns`). Off with DLSS or FSR 3.1 (`scene_upscaler`), `replay_workers` above 0, `sync_ahead = 1` or HDR output, and while a menu background or a loading or event fade is open; the game then draws at the whole limit. The swapchain gets one image more. Applies at once: turned on in the menu, the contexts are made at the next frame (a hitch of about 0.1 s once); turned off, they stay until exit. | The controls answer at the drawn rate, about half a frame later. Costs about 1.5 ms of GPU and 0.6 ms of the replay thread per drawn frame at 1080p (RX 9070, 7900X on 4 cores: 94 drawn without it, 86 drawn and 169 shown with it, no limit). For displays of 120 Hz and more. | Caution |
| `fg_test` | Frame generation checks: `1` presents the generated frame in place of the game's, `2` the picture before the HUD. Read at start. | Shows the frames out of their order: for checks only. | Caution |
| `fg_debug` | `1`: the generated frames hold the SDK's debug view (motion fields, optical flow, disocclusion). Read at start. | For checks only. | Caution |
| `fg_shot` | Frame generation shots: a present number, or `w<seconds>` of world time; the window texture, the generated frame and the picture before the HUD of three frames from there go to `fg_shot_dir` as `fg_<present>_<real\|gen\|hudless>.png`. | Writes PNGs. | Safe |
@@ -190,6 +190,8 @@ Many rows below are developer tools that only act together with another setting
| `dlaa_survey` (default `0`) | `1` logs what is drawn into the light target that DLSS reads. | Adds log output and per-draw work. | Caution |
| `dlaa_times` (default `0`) | `1` times the DLSS passes on the GPU. | Adds GPU timestamps and log lines. | Caution |
| `dlss_reactive` (default `0`) | `1` builds a reactive mask for DLSS where it ran. | Changes how DLSS blends moving areas; a test setting. | Caution |
| `fsr3_debug` (default `0`) | With `scene_upscaler = fsr3`: `1` creates the FSR 3.1 context with the SDK's input checks, whose warnings go to the log (the first 32). | Adds checks to every FSR 3.1 dispatch and log lines. | Caution |
| `fsr3_view` (default `0`) | With `scene_upscaler = fsr3`: `1` shows FSR 3.1's own debug view of its inputs and state in place of the picture. | The frame shows a debug image while it is set. | Caution |
| `mv_check` | Frame interval; every that many DLSS frames copies the light target and motion images to host memory and logs how well the vectors explain the picture. | Costs a GPU-to-host copy and a comparison on the completion thread at each interval. | Caution |
| `mv_survey` (default `0`) | `1` notes the uniform blocks of each scene draw and compares them with those of earlier frames. | Adds per-draw work and log output. | Caution |
| `mvobj_all` (default `0`) | `1` also lists draws for object motion that read no object blocks (terrain and grass). | More draws are checked and listed, which costs time. | Caution |
+13 -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_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",
"FREEZE_IDLE", "FREE_CORES", "FSR3_DEBUG", "FSR3_VIEW",
"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",
@@ -62,7 +62,7 @@ static const char *const known[] = {
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "QUICKLOAD_KEY", "QUICKSAVE", "QUICKSAVE_KEY", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX",
"RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS",
"REPLAY_CHECK", "REPORT_GUARD", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
"ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE",
"ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SCENE_UPSCALER", "SHADER_CACHE",
"SHADER_MEMO", "SHADOW", "SHADOW_DEFER", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHADOW_SNAP", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHUTTER_FIX",
"SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "STICK_DEADZONE", "STICK_SENS",
"SWKBD_ANSWER", "SYNC_AHEAD",
@@ -85,7 +85,7 @@ static const struct { const char *key, *section; } sections[] = {
{"COLOR_BRIGHTNESS", "display"}, {"COLOR_CONTRAST", "display"}, {"COLOR_SATURATION", "display"},
{"COLOR_GAMMA", "display"}, {"HDR", "display"}, {"HDR_PEAK_NITS", "display"}, {"HDR_GAME_NITS", "display"},
{"HDR_UI_NITS", "display"}, {"HDR_HUE", "display"}, {"SHADOW_RES", "display"},
{"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"DLSS_FIXED_EXPOSURE", "display"}, {"DLAA_EFFECTS_AFTER", "display"}, {"REFLEX", "display"}, {"FXAA", "display"},
{"SCENE_UPSCALER", "display"}, {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"DLSS_FIXED_EXPOSURE", "display"}, {"DLAA_EFFECTS_AFTER", "display"}, {"REFLEX", "display"}, {"FXAA", "display"},
{"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"},
{"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"},
{"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"GRASS_RANGE", "display"}, {"CONTACT_SHADOWS", "display"},
@@ -141,7 +141,8 @@ 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},
{"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE},
{"SCENE_UPSCALER", "off", "off|dlss|fsr3", RESTART}, {"DLAA", "0", "0|1", RESTART},
{"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE},
{"DLSS_PRESET", "default", "default|k|j", LIVE}, {"DLSS_FIXED_EXPOSURE", "0", "0|1", LIVE}, {"DLAA_EFFECTS_AFTER", "0", "0|1", LIVE},
{"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"REFLEX", "off", "off|on|boost", RESTART}, {"FXAA", "1", "0|1", LIVE},
{"LOD_STEADY", "0", "0|1", RESTART}, // sets steady
@@ -858,3 +859,11 @@ void cfg_init(void) {
rt_log("cfg: device profile Steam Deck: defaults for the keys totk.ini does not set (TOTK_DEVICE_PROFILE=desktop "
"turns it off)");
}
// 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.
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";
}
+12
View File
@@ -69,3 +69,15 @@ 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 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 };
int vk_upscaler_engine(void);
int vk_upscaler_on(void);
int vk_upscaler_running(void);
int vk_upscaler_missing(int engine);
+1
View File
@@ -312,6 +312,7 @@ void res_heapdef_served(void); // romfs.c serves the
void res_init(void); // after rt_patches_init: the patch page and the sets
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
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
+23 -7
View File
@@ -96,6 +96,19 @@ static int dlss_dll(void) {
#endif
}
int res_dlss_dll(void) {
static int dll = -1;
if (dll < 0) dll = dlss_dll();
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.
static int upscaler_ready(void) {
int e = vk_upscaler_engine();
return e == UPSCALER_DLSS ? res_dlss_dll() : e == UPSCALER_FSR3;
}
static uint64_t shadow_kib(void);
// The scene size for a share k of the output, within SCENE_MAX a side and within what a texture heap of DTA_MAX_KIB
@@ -118,15 +131,17 @@ static int scene_for(double k, unsigned *w, unsigned *h) {
}
// The scene's share of the output for a TOTK_DLSS mode; 0 for dlaa (the scene keeps base_k), while DLSS/DLAA is off
// (the mode the menu still holds would shrink the scene for the plain upscaler) and where DLSS cannot run (dlss_dll).
// (the mode the menu still holds would shrink the scene for the plain upscaler) and where the engine picked at start
// cannot run (upscaler_ready).
static double dlss_share(const char *m) {
static const struct { const char *name; double k; } dlss[] = {
{"quality", 2.0 / 3.0}, {"balanced", 0.58}, {"performance", 0.5}, {"ultra_performance", 1.0 / 3.0}};
static int dll = -1;
if (!cfg_bool("TOTK_DLAA")) return 0;
static int told;
if (!vk_upscaler_on()) return 0;
for (int i = 0; i < (int)(sizeof dlss / sizeof dlss[0]); i++)
if (!strcmp(m, dlss[i].name)) {
if (dll < 0 && !(dll = dlss_dll())) {
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);
@@ -135,7 +150,7 @@ static double dlss_share(const char *m) {
"scene follows render_scale", m);
#endif
}
return dll ? dlss[i].k : 0;
return ready ? dlss[i].k : 0;
}
return 0;
}
@@ -192,12 +207,13 @@ static void decide(void) {
if (n >= 256 && n <= 4096 && !(n & 7)) R.shadow = n;
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 DLSS able to run (DLAA on, the DLL there)
// 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)
// 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.
R.base_k = k;
R.live = RT_V143 && cfg_bool("TOTK_DLAA") && dlss_dll();
R.live = RT_V143 && vk_upscaler_on() && upscaler_ready();
const char *m = cfg_value("TOTK_DLSS");
R.dlss_k = dlss_share(m);
if (R.dlss_k) rt_log("resolution: DLSS %s: the scene at %.0f %% of the output (render_scale ignored)", m, R.dlss_k * 100);
+20 -7
View File
@@ -3,22 +3,27 @@
From <https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/tree/v1.1.4>, MIT (`LICENSE.txt`), via Savage Wind
(<https://github.com/Revivedx/SavageWindRecomp>, MIT, `third_party/FidelityFX`). `runtime/vk_fg.cpp` drives the frame
interpolation and optical flow of FSR 3 on the SDK's Vulkan backend directly, without the SDK's frame interpolation
swapchain or its ffx-api DLL layer.
swapchain or its ffx-api DLL layer; `runtime/vk_fsr3.cpp` drives the FSR 3.1 upscaler the same way.
What is here:
- `sdk/include/FidelityFX/host`: the SDK's public headers; `gpu`: the shader headers of frame interpolation, optical
flow and SPD (which optical flow includes). Left out against Savage Wind's copy: the FSR 3 upscaler's and FSR 1's
shader headers (`gpu/fsr3upscaler`, `gpu/fsr1`), its component and its GLSL. The host headers of the upscaler and
the other effects stay, unchanged, because the SDK's own headers include each other.
- `sdk/src/components/frameinterpolation`, `opticalflow`: the two effects.
- `sdk/src/backends/vk/ffx_vk.cpp` and its `shaders/frameinterpolation`, `shaders/opticalflow` (GLSL).
flow, the FSR 3 upscaler, SPD (which optical flow and the upscaler include) and FSR 1 (the upscaler's RCAS). The host
headers of the other effects stay, unchanged, because the SDK's own headers include each other.
- `sdk/src/components/frameinterpolation`, `opticalflow`, `fsr3upscaler`: the three effects.
- `sdk/src/backends/vk/ffx_vk.cpp` and its `shaders/frameinterpolation`, `shaders/opticalflow`, `shaders/fsr3upscaler`
(GLSL).
- `sdk/src/shared`: the SDK's assert, message and object-management helpers.
- `sdk/src/backends/shared/ffx_shader_blobs.h`: the declaration of the blob lookup, which `runtime/vk_fg.cpp` implements.
- `sdk/src/backends/shared/ffx_shader_blobs.h`: the declaration of the blob lookup, which `runtime/vk_fg.cpp` implements
(the upscaler's blobs through `runtime/vk_fsr3.cpp` `vk_fsr3_blob`).
- `spirv/ffx_shaders_vk.h`: the shaders compiled to SPIR-V with their bindings, by `tools/ffx_shaders.py`
(glslangValidator from MSYS2 UCRT64 or the Vulkan SDK) in place of the SDK's Windows-only FidelityFX_SC.exe. Only the
permutations used. Committed like `runtime/*_spv.h`: AMD's shaders, no game data. Regenerate after changing the GLSL:
`python tools/ffx_shaders.py`.
- `spirv/ffx_fsr3upscaler_vk.h`: the same for the FSR 3 upscaler (`python tools/ffx_shaders.py --effects fu`), one
permutation per pass: HDR input (the scene's linear light before the bloom), render-size motion vectors without
jitter, depth not inverted, the reference Lanczos and Savage Wind's Catmull-Rom history reprojection, in 32-bit and
16-bit floats (the 16-bit ones where the SDK asks for them and the device has shaderFloat16 and shaderInt16).
- `ffx_compat.h`: force-included into the SDK's sources (`tools/build_game.py`, rule `cc_ffx`) so they build with clang.
Changes to the SDK's files (marked "Savage Wind" in them):
@@ -30,3 +35,11 @@ Changes to the SDK's files (marked "Savage Wind" in them):
(their resources' debug names) is 4 bytes instead of 2.
- `sdk/src/backends/vk/ffx_vk.cpp`: the global descriptor pool is created with all six of the sizes it lists. It passed
five, leaving out the storage buffers (the validation layer reports it).
- `sdk/include/FidelityFX/gpu/fsr3upscaler/ffx_fsr3upscaler_reproject.h`: the history reprojected with a Catmull-Rom
filter from 5 bilinear samples (`FFX_FSR3UPSCALER_OPTION_REPROJECT_CATMULL_ROM_5`), a Savage Wind addition.
Changes of our own (marked "TotK Recomp"):
- `sdk/include/FidelityFX/gpu/fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h`: the luma history's storage image is
declared `rgba16f`, the format of its images (R16G16B16A16_FLOAT in `ffx_fsr3upscaler.cpp`). It was `rgba8`, which
the Vulkan validation layer reports as a format mismatch with undefined loads and stores.
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,219 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#include "ffx_fsr1_resources.h"
#if defined(FFX_GPU)
#include "ffx_core.h"
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // #ifndef FFX_PREFER_WAVE64
#if defined(FSR1_BIND_CB_FSR1)
layout (set = 0, binding = FSR1_BIND_CB_FSR1, std140) uniform cbFSR1_t
{
FfxUInt32x4 const0;
FfxUInt32x4 const1;
FfxUInt32x4 const2;
FfxUInt32x4 const3;
FfxUInt32x4 sample0;
} cbFSR1;
#endif
FfxUInt32x4 Const0()
{
return cbFSR1.const0;
}
FfxUInt32x4 Const1()
{
return cbFSR1.const1;
}
FfxUInt32x4 Const2()
{
return cbFSR1.const2;
}
FfxUInt32x4 Const3()
{
return cbFSR1.const3;
}
FfxUInt32x4 EASUSample()
{
return cbFSR1.sample0;
}
FfxUInt32x4 RCasSample()
{
return cbFSR1.sample0;
}
FfxUInt32x4 RCasConfig()
{
return cbFSR1.const0;
}
layout (set = 0, binding = 1000) uniform sampler s_LinearClamp;
// SRVs
#if defined FSR1_BIND_SRV_INPUT_COLOR
layout (set = 0, binding = FSR1_BIND_SRV_INPUT_COLOR) uniform texture2D r_input_color;
#endif
#if defined FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR
layout (set = 0, binding = FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR) uniform texture2D r_internal_upscaled_color;
#endif
#if defined FSR1_BIND_SRV_UPSCALED_OUTPUT
layout (set = 0, binding = FSR1_BIND_SRV_UPSCALED_OUTPUT) uniform texture2D r_upscaled_output;
#endif
// UAV declarations
#if defined FSR1_BIND_UAV_INPUT_COLOR
layout (set = 0, binding = FSR1_BIND_UAV_INPUT_COLOR, rgba32f) uniform image2D rw_input_color;
#endif
#if defined FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR
layout (set = 0, binding = FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR, rgba32f) uniform image2D rw_internal_upscaled_color;
#endif
#if defined FSR1_BIND_UAV_UPSCALED_OUTPUT
layout (set = 0, binding = FSR1_BIND_UAV_UPSCALED_OUTPUT, rgba32f) uniform image2D rw_upscaled_output;
#endif
#if FFX_HALF
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat16x4 GatherEasuRed(FfxFloat32x2 fPxPos)
{
return FfxFloat16x4(textureGather(sampler2D(r_input_color, s_LinearClamp), fPxPos, 0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat16x4 GatherEasuGreen(FfxFloat32x2 fPxPos)
{
return FfxFloat16x4(textureGather(sampler2D(r_input_color, s_LinearClamp), fPxPos, 1));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat16x4 GatherEasuBlue(FfxFloat32x2 fPxPos)
{
return FfxFloat16x4(textureGather(sampler2D(r_input_color, s_LinearClamp), fPxPos, 2));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat16x3 fColor)
{
imageStore(rw_internal_upscaled_color, FfxInt32x2(iPxPos), FfxFloat32x4(fColor, 1.f));
}
#endif // #if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#else
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat16x3 fColor)
{
imageStore(rw_upscaled_output, FfxInt32x2(iPxPos), FfxFloat32x4(fColor, 1.f));
}
#endif // #if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#endif // #if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR)
FfxFloat16x4 LoadRCas_Input(FfxInt16x2 iPxPos)
{
return FfxFloat16x4(texelFetch(r_internal_upscaled_color, FfxInt32x2(iPxPos), 0));
}
#endif // defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreRCasOutputHx2(FfxInt16x2 iPxPos, FfxFloat16x2 fColorR, FfxFloat16x2 fColorG, FfxFloat16x2 fColorB, FfxFloat16x2 fColorA)
{
imageStore(rw_upscaled_output, FfxInt32x2(iPxPos), FfxFloat32x4(fColorR.x, fColorG.x, fColorB.x, fColorA.x));
iPxPos.x += FfxInt16(8);
imageStore(rw_upscaled_output, FfxInt32x2(iPxPos), FfxFloat32x4(fColorR.y, fColorG.y, fColorB.y, fColorA.y));
}
#endif // defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#else // FFX_HALF
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat32x4 GatherEasuRed(FfxFloat32x2 fPxPos)
{
return textureGather(sampler2D(r_input_color, s_LinearClamp), fPxPos, 0);
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat32x4 GatherEasuGreen(FfxFloat32x2 fPxPos)
{
return textureGather(sampler2D(r_input_color, s_LinearClamp), fPxPos, 1);
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat32x4 GatherEasuBlue(FfxFloat32x2 fPxPos)
{
return textureGather(sampler2D(r_input_color, s_LinearClamp), fPxPos, 2);
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
imageStore(rw_internal_upscaled_color, FfxInt32x2(iPxPos), FfxFloat32x4(fColor, 1.f));
}
#endif // #if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#else
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
imageStore(rw_upscaled_output, FfxInt32x2(iPxPos), FfxFloat32x4(fColor, 1.f));
}
#endif // #if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#endif // #if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR)
FfxFloat32x4 LoadRCas_Input(FfxInt32x2 iPxPos)
{
return texelFetch(r_internal_upscaled_color, iPxPos, 0);
}
#endif // defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreRCasOutput(FfxInt32x2 iPxPos, FfxFloat32x4 fColor)
{
imageStore(rw_upscaled_output, iPxPos, fColor);
}
void StoreRCasOutput(FfxInt32x2 iPxPos, FfxFloat32x3 fColor)
{
StoreRCasOutput(iPxPos, FfxFloat32x4(fColor, 1.f));
}
#endif // defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#endif // FFX_HALF
#endif // #if defined(FFX_GPU)
@@ -0,0 +1,257 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#include "ffx_fsr1_resources.h"
#if defined(FFX_GPU)
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic push
#pragma dxc diagnostic ignored "-Wambig-lit-shift"
#endif //__hlsl_dx_compiler
#include "ffx_core.h"
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic pop
#endif //__hlsl_dx_compiler
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // #ifndef FFX_PREFER_WAVE64
#pragma warning(disable: 3205) // conversion from larger type to smaller
#define DECLARE_SRV_REGISTER(regIndex) t##regIndex
#define DECLARE_UAV_REGISTER(regIndex) u##regIndex
#define DECLARE_CB_REGISTER(regIndex) b##regIndex
#define FFX_FSR1_DECLARE_SRV(regIndex) register(DECLARE_SRV_REGISTER(regIndex))
#define FFX_FSR1_DECLARE_UAV(regIndex) register(DECLARE_UAV_REGISTER(regIndex))
#define FFX_FSR1_DECLARE_CB(regIndex) register(DECLARE_CB_REGISTER(regIndex))
#if defined(FSR1_BIND_CB_FSR1)
cbuffer cbFSR1 : FFX_FSR1_DECLARE_CB(FSR1_BIND_CB_FSR1)
{
FfxUInt32x4 const0;
FfxUInt32x4 const1;
FfxUInt32x4 const2;
FfxUInt32x4 const3;
FfxUInt32x4 sample;
#define FFX_FSR1_CONSTANT_BUFFER_1_SIZE 20 // Number of 32-bit values. This must be kept in sync with the cbFSR1 size.
};
#else
#define const0 0
#define const1 0
#define const2 0
#define const3 0
#define sample 0
#endif
#if defined(FFX_GPU)
#define FFX_FSR1_ROOTSIG_STRINGIFY(p) FFX_FSR1_ROOTSIG_STR(p)
#define FFX_FSR1_ROOTSIG_STR(p) #p
#define FFX_FSR1_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_FSR1_ROOTSIG_STRINGIFY(FFX_FSR1_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_FSR1_ROOTSIG_STRINGIFY(FFX_FSR1_RESOURCE_IDENTIFIER_COUNT) ")), " \
"CBV(b0), " \
"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_LINEAR, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_CLAMP, " \
"comparisonFunc = COMPARISON_NEVER, " \
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK)" )]
#if defined(FFX_FSR1_EMBED_ROOTSIG)
#define FFX_FSR1_EMBED_ROOTSIG_CONTENT FFX_FSR1_ROOTSIG
#else
#define FFX_FSR1_EMBED_ROOTSIG_CONTENT
#endif // #if FFX_FSR1_EMBED_ROOTSIG
#endif // #if defined(FFX_GPU)
FfxUInt32x4 Const0()
{
return const0;
}
FfxUInt32x4 Const1()
{
return const1;
}
FfxUInt32x4 Const2()
{
return const2;
}
FfxUInt32x4 Const3()
{
return const3;
}
FfxUInt32x4 EASUSample()
{
return sample;
}
FfxUInt32x4 RCasSample()
{
return sample;
}
FfxUInt32x4 RCasConfig()
{
return const0;
}
SamplerState s_LinearClamp : register(s0);
// SRVs
#if defined FSR1_BIND_SRV_INPUT_COLOR
Texture2D<FfxFloat32x4> r_input_color : FFX_FSR1_DECLARE_SRV(FSR1_BIND_SRV_INPUT_COLOR);
#endif
#if defined FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR
Texture2D<FfxFloat32x4> r_internal_upscaled_color : FFX_FSR1_DECLARE_SRV(FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR);
#endif
#if defined FSR1_BIND_SRV_UPSCALED_OUTPUT
Texture2D<FfxFloat32x4> r_upscaled_output : FFX_FSR1_DECLARE_SRV(FSR1_BIND_SRV_UPSCALED_OUTPUT);
#endif
// UAV declarations
#if defined FSR1_BIND_UAV_INPUT_COLOR
RWTexture2D<FfxFloat32x4> rw_input_color : FFX_FSR1_DECLARE_UAV(FSR1_BIND_UAV_INPUT_COLOR);
#endif
#if defined FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR
RWTexture2D<FfxFloat32x4> rw_internal_upscaled_color : FFX_FSR1_DECLARE_UAV(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR);
#endif
#if defined FSR1_BIND_UAV_UPSCALED_OUTPUT
RWTexture2D<FfxFloat32x4> rw_upscaled_output : FFX_FSR1_DECLARE_UAV(FSR1_BIND_UAV_UPSCALED_OUTPUT);
#endif
#if FFX_HALF
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat16x4 GatherEasuRed(FfxFloat32x2 fPxPos)
{
return (FfxFloat16x4)r_input_color.GatherRed(s_LinearClamp, fPxPos, FfxInt32x2(0,0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat16x4 GatherEasuGreen(FfxFloat32x2 fPxPos)
{
return (FfxFloat16x4)r_input_color.GatherGreen(s_LinearClamp, fPxPos, FfxInt32x2(0, 0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat16x4 GatherEasuBlue(FfxFloat32x2 fPxPos)
{
return (FfxFloat16x4)r_input_color.GatherBlue(s_LinearClamp, fPxPos, FfxInt32x2(0, 0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat16x3 fColor)
{
rw_internal_upscaled_color[iPxPos] = FfxFloat32x4(fColor, 1.f);
}
#endif // #if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#else
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat16x3 fColor)
{
rw_upscaled_output[iPxPos] = FfxFloat32x4(fColor, 1.f);
}
#endif // #if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#endif // #if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR)
FfxFloat16x4 LoadRCas_Input(FfxInt16x2 iPxPos)
{
return (FfxFloat16x4)r_internal_upscaled_color[iPxPos];
}
#endif // defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreRCasOutputHx2(FfxInt16x2 iPxPos, FfxFloat16x2 fColorR, FfxFloat16x2 fColorG, FfxFloat16x2 fColorB, FfxFloat16x2 fColorA)
{
rw_upscaled_output[iPxPos] = FfxFloat32x4(fColorR.x, fColorG.x, fColorB.x, fColorA.x);
iPxPos.x += 8;
rw_upscaled_output[iPxPos] = FfxFloat32x4(fColorR.y, fColorG.y, fColorB.y, fColorA.y);
}
#endif // defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#else // FFX_HALF
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat32x4 GatherEasuRed(FfxFloat32x2 fPxPos)
{
return r_input_color.GatherRed(s_LinearClamp, fPxPos, FfxInt32x2(0, 0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat32x4 GatherEasuGreen(FfxFloat32x2 fPxPos)
{
return r_input_color.GatherGreen(s_LinearClamp, fPxPos, FfxInt32x2(0, 0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if defined(FSR1_BIND_SRV_INPUT_COLOR)
FfxFloat32x4 GatherEasuBlue(FfxFloat32x2 fPxPos)
{
return r_input_color.GatherBlue(s_LinearClamp, fPxPos, FfxInt32x2(0, 0));
}
#endif // defined(FSR1_BIND_SRV_INPUT_COLOR)
#if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
rw_internal_upscaled_color[iPxPos] = FfxFloat32x4(fColor, 1.f);
}
#endif // #if defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#else
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreEASUOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
rw_upscaled_output[iPxPos] = FfxFloat32x4(fColor, 1.f);
}
#endif // #if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#endif // #if FFX_FSR1_OPTION_APPLY_RCAS
#if defined(FSR1_BIND_SRV_INTERNAL_UPSCALED_COLOR)
FfxFloat32x4 LoadRCas_Input(FfxInt32x2 iPxPos)
{
return r_internal_upscaled_color[iPxPos];
}
#endif // defined(FSR1_BIND_UAV_INTERNAL_UPSCALED_COLOR)
#if defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
void StoreRCasOutput(FfxInt32x2 iPxPos, FfxFloat32x4 fColor)
{
rw_upscaled_output[iPxPos] = fColor;
}
#endif // defined(FSR1_BIND_UAV_UPSCALED_OUTPUT)
#endif // FFX_HALF
#endif // #if defined(FFX_GPU)
@@ -0,0 +1,98 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#define GROUP_SIZE 8
#define FSR_RCAS_DENOISE 1
#include "ffx_core.h"
#if FFX_HALF
#define FFX_FSR_EASU_HALF 1
FfxFloat16x4 FsrEasuRH(FfxFloat32x2 p) { return GatherEasuRed(p); }
FfxFloat16x4 FsrEasuGH(FfxFloat32x2 p) { return GatherEasuGreen(p); }
FfxFloat16x4 FsrEasuBH(FfxFloat32x2 p) { return GatherEasuBlue(p); }
#else
#define FFX_FSR_EASU_FLOAT 1
FfxFloat32x4 FsrEasuRF(FfxFloat32x2 p) { return GatherEasuRed(p); }
FfxFloat32x4 FsrEasuGF(FfxFloat32x2 p) { return GatherEasuGreen(p); }
FfxFloat32x4 FsrEasuBF(FfxFloat32x2 p) { return GatherEasuBlue(p); }
#endif // FFX_HALF
#if FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
#define FSR_RCAS_PASSTHROUGH_ALPHA
#endif // FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
#include "fsr1/ffx_fsr1.h"
void CurrFilter(FfxUInt32x2 pos)
{
#if FFX_HALF
FfxFloat16x3 c;
FsrEasuH(c, pos, Const0(), Const1(), Const2(), Const3());
if (EASUSample().x == 1)
{
c *= c;
}
#if FFX_FSR1_OPTION_SRGB_CONVERSIONS
// Apply gamma if this is an sRGB format (auto-degamma'd on sampler read)
c = pow(c, FfxFloat16x3(1.0 / 2.2, 1.0 / 2.2, 1.0 / 2.2));
#endif // FFX_FSR1_OPTION_SRGB_CONVERSIONS
StoreEASUOutput(pos, c);
#else
FfxFloat32x3 c;
ffxFsrEasuFloat(c, pos, Const0(), Const1(), Const2(), Const3());
if (EASUSample().x == 1)
{
c *= c;
}
#if FFX_FSR1_OPTION_SRGB_CONVERSIONS
// Apply gamma if this is an sRGB format (auto-degamma'd on sampler read)
c = pow(c, FfxFloat32x3(1.f / 2.2f, 1.f / 2.2f, 1.f / 2.2f));
#endif // FFX_FSR1_OPTION_SRGB_CONVERSIONS
StoreEASUOutput(pos, c);
#endif // FFX_HALF
}
void EASU(FfxUInt32x3 LocalThreadId, FfxUInt32x3 WorkGroupId, FfxUInt32x3 Dtid)
{
// Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
FfxUInt32x2 gxy = ffxRemapForQuad(LocalThreadId.x) + FfxUInt32x2(WorkGroupId.x << 4u, WorkGroupId.y << 4u);
CurrFilter(gxy);
gxy.x += 8u;
CurrFilter(gxy);
gxy.y += 8u;
CurrFilter(gxy);
gxy.x -= 8u;
CurrFilter(gxy);
}
@@ -0,0 +1,116 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#define GROUP_SIZE 8
#define FSR_RCAS_DENOISE 1
#include "ffx_core.h"
#if FFX_HALF
#define FSR_RCAS_HX2 1
FfxFloat16x4 FsrRcasLoadHx2(FfxInt16x2 p)
{
return LoadRCas_Input(p);
}
void FsrRcasInputHx2(inout FfxFloat16x2 r,inout FfxFloat16x2 g,inout FfxFloat16x2 b) {}
#else
#define FSR_RCAS_F 1
FfxFloat32x4 FsrRcasLoadF(FfxInt32x2 p)
{
return LoadRCas_Input(p);
}
void FsrRcasInputF(inout FfxFloat32 r, inout FfxFloat32 g, inout FfxFloat32 b) {}
#endif // FFX_HALF
#if FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
#define FSR_RCAS_PASSTHROUGH_ALPHA
#endif // FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
#include "fsr1/ffx_fsr1.h"
void CurrFilter(FFX_MIN16_U2 pos)
{
#if FFX_HALF
#if FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
FfxFloat16x2 cr, cg, cb, ca;
FsrRcasHx2(cr, cg, cb, ca, pos, RCasConfig());
#else
FfxFloat16x2 cr, cg, cb;
FsrRcasHx2(cr, cg, cb, pos, RCasConfig());
#endif // FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
if (RCasSample().x == 1)
{
cr *= cr;
cg *= cg;
cb *= cb;
}
#if FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
StoreRCasOutputHx2(FfxInt16x2(pos), cr, cg, cb, ca);
#else
StoreRCasOutputHx2(FfxInt16x2(pos), cr, cg, cb, FfxFloat16x2(1.0, 1.0));
#endif
#else
#if FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
FfxFloat32x4 c;
FsrRcasF(c.r, c.g, c.b, c.a, pos, RCasConfig());
#else
FfxFloat32x3 c;
FsrRcasF(c.r, c.g, c.b, pos, RCasConfig());
#endif // FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
if (RCasSample().x == 1)
{
c *= c;
}
#if FFX_FSR1_OPTION_RCAS_PASSTHROUGH_ALPHA
StoreRCasOutput(FfxInt32x2(pos), c);
#else
StoreRCasOutput(FfxInt32x2(pos), FfxFloat32x4(c, 1.0));
#endif
#endif
}
void RCAS(FfxUInt32x3 LocalThreadId, FfxUInt32x3 WorkGroupId, FfxUInt32x3 Dtid)
{
// Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
FfxUInt32x2 gxy = ffxRemapForQuad(LocalThreadId.x) + FfxUInt32x2(WorkGroupId.x << 4u, WorkGroupId.y << 4u);
#if FFX_HALF
// packed version process left and right 8x8 tile, in total 16x8 region
CurrFilter(FFX_MIN16_U2(gxy));
gxy.y += 8u;
CurrFilter(FFX_MIN16_U2(gxy));
#else
CurrFilter(FFX_MIN16_U2(gxy));
gxy.x += 8u;
CurrFilter(FFX_MIN16_U2(gxy));
gxy.y += 8u;
CurrFilter(FFX_MIN16_U2(gxy));
gxy.x -= 8u;
CurrFilter(FFX_MIN16_U2(gxy));
#endif
}
@@ -0,0 +1,38 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#ifndef FFX_FSR1_RESOURCES_H
#define FFX_FSR1_RESOURCES_H
#if defined(FFX_CPU) || defined(FFX_GPU)
#define FFX_FSR1_RESOURCE_IDENTIFIER_NULL 0
#define FFX_FSR1_RESOURCE_IDENTIFIER_INPUT_COLOR 1
#define FFX_FSR1_RESOURCE_IDENTIFIER_INTERNAL_UPSCALED_COLOR 2
#define FFX_FSR1_RESOURCE_IDENTIFIER_UPSCALED_OUTPUT 3
#define FFX_FSR1_RESOURCE_IDENTIFIER_COUNT 4
#define FFX_FSR1_CONSTANTBUFFER_IDENTIFIER_FSR1 0
#endif // #if defined(FFX_CPU) || defined(FFX_GPU)
#endif //!defined( FFX_FSR1_RESOURCES_H )
@@ -0,0 +1,172 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
void Accumulate(const AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data)
{
// Avoid invalid values when accumulation and upsampled weight is 0
data.fHistoryWeight *= FfxFloat32(data.fHistoryWeight > FSR3UPSCALER_FP16_MIN);
data.fHistoryWeight = ffxMax(FSR3UPSCALER_EPSILON, data.fHistoryWeight + data.fUpsampledWeight);
#if FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT
//YCoCg -> RGB -> Tonemap -> YCoCg (Use RGB tonemapper to avoid color desaturation)
data.fUpsampledColor = RGBToYCoCg(Tonemap(YCoCgToRGB(data.fUpsampledColor)));
data.fHistoryColor = RGBToYCoCg(Tonemap(YCoCgToRGB(data.fHistoryColor)));
#endif
const FfxFloat32 fAlpha = ffxSaturate(data.fUpsampledWeight / data.fHistoryWeight);
data.fHistoryColor = ffxLerp(data.fHistoryColor, data.fUpsampledColor, fAlpha);
data.fHistoryColor = YCoCgToRGB(data.fHistoryColor);
#if FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT
data.fHistoryColor = InverseTonemap(data.fHistoryColor);
#endif
}
void RectifyHistory(
const AccumulationPassCommonParams params,
FFX_PARAMETER_INOUT AccumulationPassData data
)
{
const FfxFloat32 f4kVelocityFactor = ffxSaturate(params.f4KVelocity / 20.0f);
const FfxFloat32 fDistanceFactor = ffxSaturate(0.75f - params.fFarthestDepthInMeters / 20.0f);
const FfxFloat32 fAccumulationFactor = 1.0f - params.fAccumulation;
const FfxFloat32 fReactiveFactor = ffxPow(params.fReactiveMask, 1.0f / 2.0f);
const FfxFloat32 fShadingChangeFactor = params.fShadingChange;
const FfxFloat32 fBoxScaleT = ffxMax(f4kVelocityFactor, ffxMax(fDistanceFactor, ffxMax(fAccumulationFactor, ffxMax(fReactiveFactor, fShadingChangeFactor))));
const FfxFloat32 fBoxScale = ffxLerp(3.0f, 1.0f, fBoxScaleT);
const FfxFloat32x3 fScaledBoxVec = data.clippingBox.boxVec * FfxFloat32x3(1.7f, 1.0f, 1.0f) * fBoxScale;
const FfxFloat32x3 fClampedScaledBoxVec = ffxMax(fScaledBoxVec, FfxFloat32x3(1.193e-7f, 1.193e-7f, 1.193e-7f));
const FfxFloat32x3 fTransformedHistoryColor = (data.fHistoryColor - data.clippingBox.boxCenter) / fClampedScaledBoxVec;
if (length(fTransformedHistoryColor)>1.f) {
const FfxFloat32x3 fClampedHistoryColor = normalize(fTransformedHistoryColor);
const FfxFloat32x3 fFinalClampedHistoryColor = (fClampedHistoryColor * fScaledBoxVec) + data.clippingBox.boxCenter;
// Scale history color using rectification info, also using accumulation mask to avoid potential invalid color protection
const FfxFloat32 fHistoryContribution = ffxMax(params.fLumaInstabilityFactor, data.fLockContributionThisFrame) * params.fAccumulation * (1 - params.fDisocclusion);
data.fHistoryColor = ffxLerp(fFinalClampedHistoryColor, data.fHistoryColor, ffxSaturate(fHistoryContribution));
}
}
void UpdateLockStatus(AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data)
{
data.fLock *= FfxFloat32(params.bIsNewSample == false);
const FfxFloat32 fLifetimeDecreaseFactor = ffxMax(ffxSaturate(params.fShadingChange), ffxMax(params.fReactiveMask, params.fDisocclusion));
data.fLock = ffxMax(0.0f, data.fLock - fLifetimeDecreaseFactor * fLockMax);
// Compute this frame lock contribution
data.fLockContributionThisFrame = ffxSaturate(ffxSaturate(data.fLock - fLockThreshold) * (fLockMax - fLockThreshold));
const FfxFloat32 fNewLockIntensity = LoadRwNewLocks(params.iPxHrPos) * (1.0f - ffxMax(params.fShadingChange * 0, params.fReactiveMask));
data.fLock = ffxMax(0.0f, ffxMin(data.fLock + fNewLockIntensity, fLockMax));
// Preparing for next frame
const FfxFloat32 fLifetimeDecrease = (0.1f / JitterSequenceLength()) * (1.0f - fLifetimeDecreaseFactor);
data.fLock = ffxMax(0.0f, data.fLock - fLifetimeDecrease);
// we expect similar motion for next frame
// kill lock if that location is outside screen, avoid locks to be clamped to screen borders
const FfxFloat32x2 fEstimatedUvNextFrame = params.fHrUv - params.fMotionVector;
data.fLock *= FfxFloat32(IsUvInside(fEstimatedUvNextFrame) == true);
}
void ComputeBaseAccumulationWeight(const AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data)
{
FfxFloat32 fBaseAccumulation = params.fAccumulation;
fBaseAccumulation = ffxMin(fBaseAccumulation, ffxLerp(fBaseAccumulation, 0.15f, ffxSaturate(ffxMax(0.0f, (params.f4KVelocity * VelocityFactor()) / 0.5f))));
data.fHistoryWeight = fBaseAccumulation;
}
void InitPassData(FfxInt32x2 iPxHrPos, FFX_PARAMETER_INOUT AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data)
{
// Init constant params
params.iPxHrPos = iPxHrPos;
const FfxFloat32x2 fHrUv = (iPxHrPos + 0.5f) / UpscaleSize();
params.fHrUv = fHrUv;
params.fLrUvJittered = fHrUv + Jitter() / RenderSize();
params.fLrUv_HwSampler = ClampUv(params.fLrUvJittered, RenderSize(), MaxRenderSize());
params.fMotionVector = GetMotionVector(iPxHrPos, fHrUv);
params.f4KVelocity = Get4KVelocity(params.fMotionVector);
ComputeReprojectedUVs(params);
const FfxFloat32x2 fLumaInstabilityUv_HW = ClampUv(fHrUv, RenderSize(), MaxRenderSize());
params.fLumaInstabilityFactor = SampleLumaInstability(fLumaInstabilityUv_HW);
const FfxFloat32x2 fFarthestDepthUv = ClampUv(params.fLrUvJittered, RenderSize() / 2, GetFarthestDepthMip1ResourceDimensions());
params.fFarthestDepthInMeters = SampleFarthestDepthMip1(fFarthestDepthUv);
params.bIsNewSample = (params.bIsExistingSample == false || 0 == FrameIndex());
const FfxFloat32x4 fDilatedReactiveMasks = SampleDilatedReactiveMasks(params.fLrUv_HwSampler);
params.fReactiveMask = ffxSaturate(fDilatedReactiveMasks[REACTIVE]);
params.fDisocclusion = ffxSaturate(fDilatedReactiveMasks[DISOCCLUSION]);
params.fShadingChange = ffxSaturate(fDilatedReactiveMasks[SHADING_CHANGE]);
params.fAccumulation = ffxSaturate(fDilatedReactiveMasks[ACCUMULAION]);
params.fAccumulation *= FfxFloat32(round(params.fAccumulation * 100.0f) > 1.0f);
// Init variable data
data.fUpsampledColor = FfxFloat32x3(0.0f, 0.0f, 0.0f);
data.fHistoryColor = FfxFloat32x3(0.0f, 0.0f, 0.0f);
data.fHistoryWeight = 1.0f;
data.fUpsampledWeight = 0.0f;
data.fLock = 0.0f;
data.fLockContributionThisFrame = 0.0f;
}
void Accumulate(FfxInt32x2 iPxHrPos)
{
AccumulationPassCommonParams params;
AccumulationPassData data;
InitPassData(iPxHrPos, params, data);
if (params.bIsExistingSample && !params.bIsNewSample) {
ReprojectHistoryColor(params, data);
}
UpdateLockStatus(params, data);
ComputeBaseAccumulationWeight(params, data);
ComputeUpsampledColorAndWeight(params, data);
RectifyHistory(params, data);
Accumulate(params, data);
data.fHistoryColor /= Exposure();
data.fHistoryColor = ffxMax(data.fHistoryColor, FfxFloat32x3(0.0f, 0.0f, 0.0f));
StoreInternalColorAndWeight(iPxHrPos, FfxFloat32x4(data.fHistoryColor, data.fLock));
// Output final color when RCAS is disabled
#if FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING == 0
StoreUpscaledOutput(iPxHrPos, data.fHistoryColor);
#endif
StoreNewLocks(iPxHrPos, 0);
}
@@ -0,0 +1,905 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#include "ffx_fsr3upscaler_resources.h"
#if defined(FFX_GPU)
#include "ffx_core.h"
#endif // #if defined(FFX_GPU)
#if defined(FFX_GPU)
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // FFX_PREFER_WAVE64
#if defined(FSR3UPSCALER_BIND_CB_FSR3UPSCALER)
layout (set = 0, binding = FSR3UPSCALER_BIND_CB_FSR3UPSCALER, std140) uniform cbFSR3UPSCALER_t
{
FfxInt32x2 iRenderSize;
FfxInt32x2 iPreviousFrameRenderSize;
FfxInt32x2 iUpscaleSize;
FfxInt32x2 iPreviousFrameUpscaleSize;
FfxInt32x2 iMaxRenderSize;
FfxInt32x2 iMaxUpscaleSize;
FfxFloat32x4 fDeviceToViewDepth;
FfxFloat32x2 fJitter;
FfxFloat32x2 fPreviousFrameJitter;
FfxFloat32x2 fMotionVectorScale;
FfxFloat32x2 fDownscaleFactor;
FfxFloat32x2 fMotionVectorJitterCancellation;
FfxFloat32 fTanHalfFOV;
FfxFloat32 fJitterSequenceLength;
FfxFloat32 fDeltaTime;
FfxFloat32 fDeltaPreExposure;
FfxFloat32 fViewSpaceToMetersFactor;
FfxFloat32 fFrameIndex;
FfxFloat32 fVelocityFactor;
FfxFloat32 fReactivenessScale;
FfxFloat32 fShadingChangeScale;
FfxFloat32 fAccumulationAddedPerFrame;
FfxFloat32 fMinDisocclusionAccumulation;
} cbFSR3Upscaler;
FfxInt32x2 RenderSize()
{
return cbFSR3Upscaler.iRenderSize;
}
FfxInt32x2 PreviousFrameRenderSize()
{
return cbFSR3Upscaler.iPreviousFrameRenderSize;
}
FfxInt32x2 MaxRenderSize()
{
return cbFSR3Upscaler.iMaxRenderSize;
}
FfxInt32x2 UpscaleSize()
{
return cbFSR3Upscaler.iUpscaleSize;
}
FfxInt32x2 PreviousFrameUpscaleSize()
{
return cbFSR3Upscaler.iPreviousFrameUpscaleSize;
}
FfxInt32x2 MaxUpscaleSize()
{
return cbFSR3Upscaler.iMaxUpscaleSize;
}
FfxFloat32x2 Jitter()
{
return cbFSR3Upscaler.fJitter;
}
FfxFloat32x2 PreviousFrameJitter()
{
return cbFSR3Upscaler.fPreviousFrameJitter;
}
FfxFloat32x4 DeviceToViewSpaceTransformFactors()
{
return cbFSR3Upscaler.fDeviceToViewDepth;
}
FfxFloat32x2 MotionVectorScale()
{
return cbFSR3Upscaler.fMotionVectorScale;
}
FfxFloat32x2 DownscaleFactor()
{
return cbFSR3Upscaler.fDownscaleFactor;
}
FfxFloat32x2 MotionVectorJitterCancellation()
{
return cbFSR3Upscaler.fMotionVectorJitterCancellation;
}
FfxFloat32 TanHalfFoV()
{
return cbFSR3Upscaler.fTanHalfFOV;
}
FfxFloat32 JitterSequenceLength()
{
return cbFSR3Upscaler.fJitterSequenceLength;
}
FfxFloat32 DeltaTime()
{
return cbFSR3Upscaler.fDeltaTime;
}
FfxFloat32 DeltaPreExposure()
{
return cbFSR3Upscaler.fDeltaPreExposure;
}
FfxFloat32 ViewSpaceToMetersFactor()
{
return cbFSR3Upscaler.fViewSpaceToMetersFactor;
}
FfxFloat32 FrameIndex()
{
return cbFSR3Upscaler.fFrameIndex;
}
FfxFloat32 VelocityFactor()
{
return cbFSR3Upscaler.fVelocityFactor;
}
FfxFloat32 AccumulationAddedPerFrame()
{
return cbFSR3Upscaler.fAccumulationAddedPerFrame;
}
FfxFloat32 MinDisocclusionAccumulation()
{
return cbFSR3Upscaler.fMinDisocclusionAccumulation;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_FSR3UPSCALER)
#if defined(FSR3UPSCALER_BIND_CB_AUTOREACTIVE)
layout(set = 0, binding = FSR3UPSCALER_BIND_CB_AUTOREACTIVE, std140) uniform cbGenerateReactive_t
{
FfxFloat32 fTcThreshold; // 0.1 is a good starting value, lower will result in more TC pixels
FfxFloat32 fTcScale;
FfxFloat32 fReactiveScale;
FfxFloat32 fReactiveMax;
} cbGenerateReactive;
FfxFloat32 TcThreshold()
{
return cbGenerateReactive.fTcThreshold;
}
FfxFloat32 TcScale()
{
return cbGenerateReactive.fTcScale;
}
FfxFloat32 ReactiveScale()
{
return cbGenerateReactive.fReactiveScale;
}
FfxFloat32 ReactiveMax()
{
return cbGenerateReactive.fReactiveMax;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_AUTOREACTIVE)
#if defined(FSR3UPSCALER_BIND_CB_RCAS)
layout(set = 0, binding = FSR3UPSCALER_BIND_CB_RCAS, std140) uniform cbRCAS_t
{
FfxUInt32x4 rcasConfig;
} cbRCAS;
FfxUInt32x4 RCASConfig()
{
return cbRCAS.rcasConfig;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_RCAS)
#if defined(FSR3UPSCALER_BIND_CB_REACTIVE)
layout(set = 0, binding = FSR3UPSCALER_BIND_CB_REACTIVE, std140) uniform cbGenerateReactive_t
{
FfxFloat32 gen_reactive_scale;
FfxFloat32 gen_reactive_threshold;
FfxFloat32 gen_reactive_binaryValue;
FfxUInt32 gen_reactive_flags;
} cbGenerateReactive;
FfxFloat32 GenReactiveScale()
{
return cbGenerateReactive.gen_reactive_scale;
}
FfxFloat32 GenReactiveThreshold()
{
return cbGenerateReactive.gen_reactive_threshold;
}
FfxFloat32 GenReactiveBinaryValue()
{
return cbGenerateReactive.gen_reactive_binaryValue;
}
FfxUInt32 GenReactiveFlags()
{
return cbGenerateReactive.gen_reactive_flags;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_REACTIVE)
#if defined(FSR3UPSCALER_BIND_CB_SPD)
layout(set = 0, binding = FSR3UPSCALER_BIND_CB_SPD, std140) uniform cbSPD_t
{
FfxUInt32 mips;
FfxUInt32 numWorkGroups;
FfxUInt32x2 workGroupOffset;
FfxUInt32x2 renderSize;
} cbSPD;
FfxUInt32 MipCount()
{
return cbSPD.mips;
}
FfxUInt32 NumWorkGroups()
{
return cbSPD.numWorkGroups;
}
FfxUInt32x2 WorkGroupOffset()
{
return cbSPD.workGroupOffset;
}
FfxUInt32x2 SPD_RenderSize()
{
return cbSPD.renderSize;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_SPD)
layout (set = 0, binding = 1000) uniform sampler s_PointClamp;
layout (set = 0, binding = 1001) uniform sampler s_LinearClamp;
#if defined(FSR3UPSCALER_BIND_SRV_SPD_MIPS)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_SPD_MIPS) uniform texture2D r_spd_mips;
FfxInt32x2 GetSPDMipDimensions(FfxUInt32 uMipLevel)
{
return textureSize(r_spd_mips, int(uMipLevel)).xy;
}
FfxFloat32x2 SampleSPDMipLevel(FfxFloat32x2 fUV, FfxUInt32 mipLevel)
{
return textureLod(sampler2D(r_spd_mips, s_LinearClamp), fUV, float(mipLevel)).rg;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_DEPTH)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_INPUT_DEPTH) uniform texture2D r_input_depth;
FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos)
{
return texelFetch(r_input_depth, iPxPos, 0).r;
}
FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_input_depth, s_LinearClamp), fUV, 0.0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_REACTIVE_MASK)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_REACTIVE_MASK) uniform texture2D r_reactive_mask;
FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos)
{
return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r * cbFSR3Upscaler.fReactivenessScale;
}
FfxInt32x2 GetReactiveMaskResourceDimensions()
{
return textureSize(r_reactive_mask, 0).xy;
}
FfxFloat32 SampleReactiveMask(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_reactive_mask, s_LinearClamp), fUV, 0.0).x * cbFSR3Upscaler.fReactivenessScale;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK) uniform texture2D r_transparency_and_composition_mask;
FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)
{
return texelFetch(r_transparency_and_composition_mask, FfxInt32x2(iPxPos), 0).r;
}
FfxInt32x2 GetTransparencyAndCompositionMaskResourceDimensions()
{
return textureSize(r_transparency_and_composition_mask, 0).xy;
}
FfxFloat32 SampleTransparencyAndCompositionMask(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_transparency_and_composition_mask, s_LinearClamp), fUV, 0.0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_COLOR)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_INPUT_COLOR) uniform texture2D r_input_color_jittered;
FfxFloat32x3 LoadInputColor(FfxInt32x2 iPxPos)
{
return texelFetch(r_input_color_jittered, iPxPos, 0).rgb;
}
FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_input_color_jittered, s_LinearClamp), fUV, 0.0).rgb;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS) uniform texture2D r_input_motion_vectors;
FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos)
{
FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy;
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
#if FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS
fUvMotionVector -= MotionVectorJitterCancellation();
#endif
return fUvMotionVector;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INTERNAL_UPSCALED)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_INTERNAL_UPSCALED) uniform texture2D r_internal_upscaled_color;
FfxFloat32x4 LoadHistory(FfxInt32x2 iPxHistory)
{
return texelFetch(r_internal_upscaled_color, iPxHistory, 0);
}
FfxFloat32x4 SampleHistory(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_internal_upscaled_color, s_LinearClamp), fUV, 0.0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_LUMA_HISTORY)
// TotK Recomp: rgba16f, the format of the luma history images (ffx_fsr3upscaler.cpp, R16G16B16A16_FLOAT). With rgba8
// the stores and loads do not match the image (the Vulkan validation layer reports it; undefined values).
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_LUMA_HISTORY, rgba16f) uniform image2D rw_luma_history;
void StoreLumaHistory(FfxInt32x2 iPxPos, FfxFloat32x4 fLumaHistory)
{
imageStore(rw_luma_history, iPxPos, fLumaHistory);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_LUMA_HISTORY)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_LUMA_HISTORY) uniform texture2D r_luma_history;
FfxFloat32x4 LoadLumaHistory(FfxInt32x2 iPxPos)
{
return texelFetch(r_luma_history, iPxPos, 0);
}
FfxFloat32x4 SampleLumaHistory(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_luma_history, s_LinearClamp), fUV, 0.0);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_RCAS_INPUT)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_RCAS_INPUT) uniform texture2D r_rcas_input;
FfxFloat32x4 LoadRCAS_Input(FfxInt32x2 iPxPos)
{
return texelFetch(r_rcas_input, iPxPos, 0);
}
FfxFloat32x3 SampleRCAS_Input(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_rcas_input, s_LinearClamp), fUV, 0.0).rgb;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_INTERNAL_UPSCALED)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_INTERNAL_UPSCALED, rgba16f) writeonly uniform image2D rw_internal_upscaled_color;
void StoreReprojectedHistory(FfxInt32x2 iPxHistory, FfxFloat32x4 fHistory)
{
imageStore(rw_internal_upscaled_color, iPxHistory, fHistory);
}
void StoreInternalColorAndWeight(FfxInt32x2 iPxPos, FfxFloat32x4 fColorAndWeight)
{
imageStore(rw_internal_upscaled_color, iPxPos, fColorAndWeight);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT /* app controlled format */) writeonly uniform image2D rw_upscaled_output;
void StoreUpscaledOutput(FfxInt32x2 iPxPos, FfxFloat32x3 fColor)
{
imageStore(rw_upscaled_output, iPxPos, FfxFloat32x4(fColor, 1.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_ACCUMULATION)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_ACCUMULATION) uniform texture2D r_accumulation;
FfxFloat32 SampleAccumulation(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_accumulation, s_LinearClamp), fUV, 0.0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_ACCUMULATION)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_ACCUMULATION, r8) uniform image2D rw_accumulation;
void StoreAccumulation(FfxInt32x2 iPxPos, FfxFloat32 fAccumulation)
{
imageStore(rw_accumulation, iPxPos, vec4(fAccumulation, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_SHADING_CHANGE)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_SHADING_CHANGE) uniform texture2D r_shading_change;
FfxFloat32 LoadShadingChange(FfxInt32x2 iPxPos)
{
return texelFetch(r_shading_change, iPxPos, 0).x * cbFSR3Upscaler.fShadingChangeScale;
}
FfxFloat32 SampleShadingChange(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_shading_change, s_LinearClamp), fUV, 0.0).x * cbFSR3Upscaler.fShadingChangeScale;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_SHADING_CHANGE)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SHADING_CHANGE, r8) uniform image2D rw_shading_change;
void StoreShadingChange(FfxInt32x2 iPxPos, FfxFloat32 fShadingChange)
{
imageStore(rw_shading_change, iPxPos, vec4(fShadingChange, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH) uniform texture2D r_farthest_depth;
FfxInt32x2 GetFarthestDepthResourceDimensions()
{
return textureSize(r_farthest_depth, 0).xy;
}
FfxFloat32 LoadFarthestDepth(FfxInt32x2 iPxPos)
{
return texelFetch(r_farthest_depth, iPxPos, 0).x;
}
FfxFloat32 SampleFarthestDepth(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_farthest_depth, s_LinearClamp), fUV, 0.0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH, r16f) uniform image2D rw_farthest_depth;
void StoreFarthestDepth(FfxInt32x2 iPxPos, FfxFloat32 fDepth)
{
imageStore(rw_farthest_depth, iPxPos, vec4(fDepth, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH_MIP1)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH_MIP1) uniform texture2D r_farthest_depth_mip1;
FfxInt32x2 GetFarthestDepthMip1ResourceDimensions()
{
return textureSize(r_farthest_depth_mip1, 0).xy;
}
FfxFloat32 LoadFarthestDepthMip1(FfxInt32x2 iPxPos)
{
return texelFetch(r_farthest_depth_mip1, iPxPos, 0).x;
}
FfxFloat32 SampleFarthestDepthMip1(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_farthest_depth_mip1, s_LinearClamp), fUV, 0.0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH_MIP1)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH_MIP1, r16f) uniform image2D rw_farthest_depth_mip1;
void StoreFarthestDepthMip1(FfxInt32x2 iPxPos, FfxFloat32 fDepth)
{
imageStore(rw_farthest_depth_mip1, iPxPos, vec4(fDepth, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_CURRENT_LUMA)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_CURRENT_LUMA) uniform texture2D r_current_luma;
FfxFloat32 LoadCurrentLuma(FfxInt32x2 iPxPos)
{
return texelFetch(r_current_luma, iPxPos, 0).r;
}
FfxFloat32 SampleCurrentLuma(FfxFloat32x2 uv)
{
return textureLod(sampler2D(r_current_luma, s_LinearClamp), uv, 0.0).r;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_CURRENT_LUMA)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_CURRENT_LUMA, r16f) uniform image2D rw_current_luma;
void StoreCurrentLuma(FfxInt32x2 iPxPos, FfxFloat32 fLuma)
{
imageStore(rw_current_luma, iPxPos, vec4(fLuma, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_LUMA_INSTABILITY)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_LUMA_INSTABILITY) uniform texture2D r_luma_instability;
FfxFloat32 SampleLumaInstability(FfxFloat32x2 uv)
{
return textureLod(sampler2D(r_luma_instability, s_LinearClamp), uv, 0.0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_LUMA_INSTABILITY)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_LUMA_INSTABILITY, r16f) uniform image2D rw_luma_instability;
void StoreLumaInstability(FfxInt32x2 iPxPos, FfxFloat32 fLumaInstability)
{
imageStore(rw_luma_instability, iPxPos, vec4(fLumaInstability, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_PREVIOUS_LUMA)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_PREVIOUS_LUMA) uniform texture2D r_previous_luma;
FfxFloat32 LoadPreviousLuma(FfxInt32x2 iPxPos)
{
return texelFetch(r_previous_luma, iPxPos, 0).r;
}
FfxFloat32 SamplePreviousLuma(FfxFloat32x2 uv)
{
return textureLod(sampler2D(r_previous_luma, s_LinearClamp), uv, 0.0).r;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_NEW_LOCKS)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_NEW_LOCKS) uniform texture2D r_new_locks;
FfxFloat32 LoadNewLocks(FfxInt32x2 iPxPos)
{
return texelFetch(r_new_locks, iPxPos, 0).r;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_NEW_LOCKS)
layout(set = 0, binding = FSR3UPSCALER_BIND_UAV_NEW_LOCKS, r8) uniform image2D rw_new_locks;
FfxFloat32 LoadRwNewLocks(FfxInt32x2 iPxPos)
{
return imageLoad(rw_new_locks, iPxPos).r;
}
void StoreNewLocks(FfxInt32x2 iPxPos, FfxFloat32 newLock)
{
imageStore(rw_new_locks, iPxPos, vec4(newLock, 0, 0, 0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH) uniform utexture2D r_reconstructed_previous_nearest_depth;
FfxFloat32 LoadReconstructedPrevDepth(FfxInt32x2 iPxPos)
{
return uintBitsToFloat(texelFetch(r_reconstructed_previous_nearest_depth, iPxPos, 0).r);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH, r32ui) uniform uimage2D rw_reconstructed_previous_nearest_depth;
void StoreReconstructedDepth(FfxInt32x2 iPxSample, FfxFloat32 fDepth)
{
FfxUInt32 uDepth = floatBitsToUint(fDepth);
#if FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH
imageAtomicMax(rw_reconstructed_previous_nearest_depth, iPxSample, uDepth);
#else
imageAtomicMin(rw_reconstructed_previous_nearest_depth, iPxSample, uDepth); // min for standard, max for inverted depth
#endif
}
void SetReconstructedDepth(FfxInt32x2 iPxSample, FfxUInt32 uValue)
{
imageStore(rw_reconstructed_previous_nearest_depth, iPxSample, uvec4(uValue, 0, 0, 0));
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_DILATED_DEPTH)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_DILATED_DEPTH, r32f) writeonly uniform image2D rw_dilated_depth;
void StoreDilatedDepth(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32 fDepth)
{
imageStore(rw_dilated_depth, iPxPos, vec4(fDepth, 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_DILATED_MOTION_VECTORS)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_DILATED_MOTION_VECTORS, rg16f) writeonly uniform image2D rw_dilated_motion_vectors;
void StoreDilatedMotionVector(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fMotionVector)
{
imageStore(rw_dilated_motion_vectors, iPxPos, vec4(fMotionVector, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS) uniform texture2D r_dilated_motion_vectors;
FfxFloat32x2 LoadDilatedMotionVector(FfxInt32x2 iPxInput)
{
return texelFetch(r_dilated_motion_vectors, iPxInput, 0).xy;
}
FfxFloat32x2 SampleDilatedMotionVector(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_dilated_motion_vectors, s_LinearClamp), fUV, 0.0).xy;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_DILATED_DEPTH)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_DILATED_DEPTH) uniform texture2D r_dilated_depth;
FfxFloat32 LoadDilatedDepth(FfxInt32x2 iPxInput)
{
return texelFetch(r_dilated_depth, iPxInput, 0).r;
}
FfxFloat32 SampleDilatedDepth(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_dilated_depth, s_LinearClamp), fUV, 0.0).r;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE) uniform texture2D r_input_exposure;
FfxFloat32 Exposure()
{
FfxFloat32 exposure = texelFetch(r_input_exposure, FfxInt32x2(0, 0), 0).x;
if (exposure == 0.0) {
exposure = 1.0;
}
return exposure;
}
#endif
// BEGIN: FSR3UPSCALER_BIND_SRV_LANCZOS_LUT
#if defined(FSR3UPSCALER_BIND_SRV_LANCZOS_LUT)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_LANCZOS_LUT) uniform texture2D r_lanczos_lut;
#endif
FfxFloat32 SampleLanczos2Weight(FfxFloat32 x)
{
#if defined(FSR3UPSCALER_BIND_SRV_LANCZOS_LUT)
return textureLod(sampler2D(r_lanczos_lut, s_LinearClamp), FfxFloat32x2(x / 2.0, 0.5), 0.0).x;
#else
return 0.f;
#endif
}
// END: FSR3UPSCALER_BIND_SRV_LANCZOS_LUT
#if defined(FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS) uniform texture2D r_dilated_reactive_masks;
FfxFloat32x4 SampleDilatedReactiveMasks(FfxFloat32x2 fUV)
{
return textureLod(sampler2D(r_dilated_reactive_masks, s_LinearClamp), fUV, 0.0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_DILATED_REACTIVE_MASKS)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_DILATED_REACTIVE_MASKS, rgba8) writeonly uniform image2D rw_dilated_reactive_masks;
void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x4 fDilatedReactiveMasks)
{
imageStore(rw_dilated_reactive_masks, iPxPos, fDilatedReactiveMasks);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY)
layout (set = 0, binding = FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY) uniform texture2D r_input_opaque_only;
FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return texelFetch(r_input_opaque_only, iPxPos, 0).xyz;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_PREV_PRE_ALPHA_COLOR)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_PREV_PRE_ALPHA_COLOR) uniform texture2D r_input_prev_color_pre_alpha;
FfxFloat32x3 LoadPrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return texelFetch(r_input_prev_color_pre_alpha, iPxPos, 0).xyz;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_PREV_POST_ALPHA_COLOR)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_PREV_POST_ALPHA_COLOR) uniform texture2D r_input_prev_color_post_alpha;
FfxFloat32x3 LoadPrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return texelFetch(r_input_prev_color_post_alpha, iPxPos, 0).xyz;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_AUTOREACTIVE) && \
defined(FSR3UPSCALER_BIND_UAV_AUTOCOMPOSITION)
layout(set = 0, binding = FSR3UPSCALER_BIND_UAV_AUTOREACTIVE, r32f) uniform image2D rw_output_autoreactive;
layout(set = 0, binding = FSR3UPSCALER_BIND_UAV_AUTOCOMPOSITION, r32f) uniform image2D rw_output_autocomposition;
void StoreAutoReactive(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F2 fReactive)
{
imageStore(rw_output_autoreactive, iPxPos, FfxFloat32x4(FfxFloat32(fReactive.x), 0.0, 0.0, 0.0));
imageStore(rw_output_autocomposition, iPxPos, FfxFloat32x4(FfxFloat32(fReactive.y), 0.0, 0.0, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_PREV_PRE_ALPHA_COLOR)
layout(set = 0, binding = FSR3UPSCALER_BIND_UAV_PREV_PRE_ALPHA_COLOR, r11f_g11f_b10f) uniform image2D rw_output_prev_color_pre_alpha;
void StorePrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)
{
imageStore(rw_output_prev_color_pre_alpha, iPxPos, FfxFloat32x4(color, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_PREV_POST_ALPHA_COLOR)
layout(set = 0, binding = FSR3UPSCALER_BIND_UAV_PREV_POST_ALPHA_COLOR, r11f_g11f_b10f) uniform image2D rw_output_prev_color_post_alpha;
void StorePrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)
{
imageStore(rw_output_prev_color_post_alpha, iPxPos, FfxFloat32x4(color, 0.0));
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_FRAME_INFO)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_FRAME_INFO, rgba32f) uniform image2D rw_frame_info;
FfxFloat32x4 LoadFrameInfo()
{
return imageLoad(rw_frame_info, ivec2(0, 0));
}
void StoreFrameInfo(FfxFloat32x4 fInfo)
{
imageStore(rw_frame_info, ivec2(0, 0), fInfo);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_FRAME_INFO)
layout(set = 0, binding = FSR3UPSCALER_BIND_SRV_FRAME_INFO) uniform texture2D r_frame_info;
FfxFloat32x4 FrameInfo()
{
return texelFetch(r_frame_info, ivec2(0, 0), 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_0) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_1) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_2) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_3) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_4) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_5)
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_0, rg16f) uniform image2D rw_spd_mip0;
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_1, rg16f) uniform image2D rw_spd_mip1;
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_2, rg16f) uniform image2D rw_spd_mip2;
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_3, rg16f) uniform image2D rw_spd_mip3;
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_4, rg16f) uniform image2D rw_spd_mip4;
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_5, rg16f) coherent uniform image2D rw_spd_mip5;
FfxFloat32x2 RWLoadPyramid(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxUInt32 index)
{
#define LOAD(idx) \
if (index == idx) \
{ \
return imageLoad(rw_spd_mip##idx, iPxPos).xy; \
}
LOAD(0);
LOAD(1);
LOAD(2);
LOAD(3);
LOAD(4);
LOAD(5);
return FfxFloat32x2(0.0, 0.0);
#undef LOAD
}
void StorePyramid(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 outValue, FFX_PARAMETER_IN FfxUInt32 index)
{
#define STORE(idx) \
if (index == idx) \
{ \
imageStore(rw_spd_mip##idx, iPxPos, vec4(outValue, 0.0, 0.0)); \
}
STORE(0);
STORE(1);
STORE(2);
STORE(3);
STORE(4);
STORE(5);
#undef STORE
}
#endif
#if defined FSR3UPSCALER_BIND_UAV_SPD_GLOBAL_ATOMIC
layout (set = 0, binding = FSR3UPSCALER_BIND_UAV_SPD_GLOBAL_ATOMIC, r32ui) coherent uniform uimage2D rw_spd_global_atomic;
void SPD_IncreaseAtomicCounter(inout FfxUInt32 spdCounter)
{
spdCounter = imageAtomicAdd(rw_spd_global_atomic, ivec2(0, 0), 1);
}
void SPD_ResetAtomicCounter()
{
imageStore(rw_spd_global_atomic, ivec2(0, 0), uvec4(0));
}
#endif
#endif // #if defined(FFX_GPU)
@@ -0,0 +1,990 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#include "ffx_fsr3upscaler_resources.h"
#if defined(FFX_GPU)
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic push
#pragma dxc diagnostic ignored "-Wambig-lit-shift"
#endif //__hlsl_dx_compiler
#include "ffx_core.h"
#ifdef __hlsl_dx_compiler
#pragma dxc diagnostic pop
#endif //__hlsl_dx_compiler
#endif // #if defined(FFX_GPU)
#if defined(FFX_GPU)
#ifndef FFX_PREFER_WAVE64
#define FFX_PREFER_WAVE64
#endif // FFX_PREFER_WAVE64
#pragma warning(disable: 3205) // conversion from larger type to smaller
#define DECLARE_SRV_REGISTER(regIndex) t##regIndex
#define DECLARE_UAV_REGISTER(regIndex) u##regIndex
#define DECLARE_CB_REGISTER(regIndex) b##regIndex
#define FFX_FSR3UPSCALER_DECLARE_SRV(regIndex) register(DECLARE_SRV_REGISTER(regIndex))
#define FFX_FSR3UPSCALER_DECLARE_UAV(regIndex) register(DECLARE_UAV_REGISTER(regIndex))
#define FFX_FSR3UPSCALER_DECLARE_CB(regIndex) register(DECLARE_CB_REGISTER(regIndex))
#if defined(FSR3UPSCALER_BIND_CB_FSR3UPSCALER)
cbuffer cbFSR3Upscaler : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_FSR3UPSCALER)
{
FfxInt32x2 iRenderSize;
FfxInt32x2 iPreviousFrameRenderSize;
FfxInt32x2 iUpscaleSize;
FfxInt32x2 iPreviousFrameUpscaleSize;
FfxInt32x2 iMaxRenderSize;
FfxInt32x2 iMaxUpscaleSize;
FfxFloat32x4 fDeviceToViewDepth;
FfxFloat32x2 fJitter;
FfxFloat32x2 fPreviousFrameJitter;
FfxFloat32x2 fMotionVectorScale;
FfxFloat32x2 fDownscaleFactor;
FfxFloat32x2 fMotionVectorJitterCancellation;
FfxFloat32 fTanHalfFOV;
FfxFloat32 fJitterSequenceLength;
FfxFloat32 fDeltaTime;
FfxFloat32 fDeltaPreExposure;
FfxFloat32 fViewSpaceToMetersFactor;
FfxFloat32 fFrameIndex;
FfxFloat32 fVelocityFactor;
FfxFloat32 fReactivenessScale;
FfxFloat32 fShadingChangeScale;
FfxFloat32 fAccumulationAddedPerFrame;
FfxFloat32 fMinDisocclusionAccumulation;
};
#define FFX_FSR3UPSCALER_CONSTANT_BUFFER_1_SIZE (sizeof(cbFSR3Upscaler) / 4) // Number of 32-bit values. This must be kept in sync with the cbFSR3Upscaler size.
/* Define getter functions in the order they are defined in the CB! */
FfxInt32x2 RenderSize()
{
return iRenderSize;
}
FfxInt32x2 PreviousFrameRenderSize()
{
return iPreviousFrameRenderSize;
}
FfxInt32x2 MaxRenderSize()
{
return iMaxRenderSize;
}
FfxInt32x2 UpscaleSize()
{
return iUpscaleSize;
}
FfxInt32x2 PreviousFrameUpscaleSize()
{
return iPreviousFrameUpscaleSize;
}
FfxInt32x2 MaxUpscaleSize()
{
return iMaxUpscaleSize;
}
FfxFloat32x2 Jitter()
{
return fJitter;
}
FfxFloat32x2 PreviousFrameJitter()
{
return fPreviousFrameJitter;
}
FfxFloat32x4 DeviceToViewSpaceTransformFactors()
{
return fDeviceToViewDepth;
}
FfxFloat32x2 MotionVectorScale()
{
return fMotionVectorScale;
}
FfxFloat32x2 DownscaleFactor()
{
return fDownscaleFactor;
}
FfxFloat32x2 MotionVectorJitterCancellation()
{
return fMotionVectorJitterCancellation;
}
FfxFloat32 TanHalfFoV()
{
return fTanHalfFOV;
}
FfxFloat32 JitterSequenceLength()
{
return fJitterSequenceLength;
}
FfxFloat32 DeltaTime()
{
return fDeltaTime;
}
FfxFloat32 DeltaPreExposure()
{
return fDeltaPreExposure;
}
FfxFloat32 ViewSpaceToMetersFactor()
{
return fViewSpaceToMetersFactor;
}
FfxFloat32 FrameIndex()
{
return fFrameIndex;
}
FfxFloat32 VelocityFactor()
{
return fVelocityFactor;
}
FfxFloat32 AccumulationAddedPerFrame()
{
return fAccumulationAddedPerFrame;
}
FfxFloat32 MinDisocclusionAccumulation()
{
return fMinDisocclusionAccumulation;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_FSR3UPSCALER)
#define FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(p) FFX_FSR3UPSCALER_ROOTSIG_STR(p)
#define FFX_FSR3UPSCALER_ROOTSIG_STR(p) #p
#define FFX_FSR3UPSCALER_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT) ")), " \
"CBV(b0), " \
"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_POINT, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_CLAMP, " \
"comparisonFunc = COMPARISON_NEVER, " \
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \
"StaticSampler(s1, filter = FILTER_MIN_MAG_MIP_LINEAR, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_CLAMP, " \
"comparisonFunc = COMPARISON_NEVER, " \
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK)" )]
#define FFX_FSR3UPSCALER_CONSTANT_BUFFER_2_SIZE 6 // Number of 32-bit values. This must be kept in sync with max( cbRCAS , cbSPD) size.
#define FFX_FSR3UPSCALER_CB2_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT) ")), " \
"DescriptorTable(SRV(t0, numDescriptors = " FFX_FSR3UPSCALER_ROOTSIG_STRINGIFY(FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT) ")), " \
"CBV(b0), " \
"CBV(b1), " \
"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_POINT, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_CLAMP, " \
"comparisonFunc = COMPARISON_NEVER, " \
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \
"StaticSampler(s1, filter = FILTER_MIN_MAG_MIP_LINEAR, " \
"addressU = TEXTURE_ADDRESS_CLAMP, " \
"addressV = TEXTURE_ADDRESS_CLAMP, " \
"addressW = TEXTURE_ADDRESS_CLAMP, " \
"comparisonFunc = COMPARISON_NEVER, " \
"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK)" )]
#if defined(FFX_FSR3UPSCALER_EMBED_ROOTSIG)
#define FFX_FSR3UPSCALER_EMBED_ROOTSIG_CONTENT FFX_FSR3UPSCALER_ROOTSIG
#define FFX_FSR3UPSCALER_EMBED_CB2_ROOTSIG_CONTENT FFX_FSR3UPSCALER_CB2_ROOTSIG
#else
#define FFX_FSR3UPSCALER_EMBED_ROOTSIG_CONTENT
#define FFX_FSR3UPSCALER_EMBED_CB2_ROOTSIG_CONTENT
#endif // #if FFX_FSR3UPSCALER_EMBED_ROOTSIG
#if defined(FSR3UPSCALER_BIND_CB_AUTOREACTIVE)
cbuffer cbGenerateReactive : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_AUTOREACTIVE)
{
FfxFloat32 fTcThreshold; // 0.1 is a good starting value, lower will result in more TC pixels
FfxFloat32 fTcScale;
FfxFloat32 fReactiveScale;
FfxFloat32 fReactiveMax;
};
FfxFloat32 TcThreshold()
{
return fTcThreshold;
}
FfxFloat32 TcScale()
{
return fTcScale;
}
FfxFloat32 ReactiveScale()
{
return fReactiveScale;
}
FfxFloat32 ReactiveMax()
{
return fReactiveMax;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_AUTOREACTIVE)
#if defined(FSR3UPSCALER_BIND_CB_RCAS)
cbuffer cbRCAS : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_RCAS)
{
FfxUInt32x4 rcasConfig;
};
FfxUInt32x4 RCASConfig()
{
return rcasConfig;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_RCAS)
#if defined(FSR3UPSCALER_BIND_CB_REACTIVE)
cbuffer cbGenerateReactive : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_REACTIVE)
{
FfxFloat32 gen_reactive_scale;
FfxFloat32 gen_reactive_threshold;
FfxFloat32 gen_reactive_binaryValue;
FfxUInt32 gen_reactive_flags;
};
FfxFloat32 GenReactiveScale()
{
return gen_reactive_scale;
}
FfxFloat32 GenReactiveThreshold()
{
return gen_reactive_threshold;
}
FfxFloat32 GenReactiveBinaryValue()
{
return gen_reactive_binaryValue;
}
FfxUInt32 GenReactiveFlags()
{
return gen_reactive_flags;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_REACTIVE)
#if defined(FSR3UPSCALER_BIND_CB_SPD)
cbuffer cbSPD : FFX_FSR3UPSCALER_DECLARE_CB(FSR3UPSCALER_BIND_CB_SPD) {
FfxUInt32 mips;
FfxUInt32 numWorkGroups;
FfxUInt32x2 workGroupOffset;
FfxUInt32x2 renderSize;
};
FfxUInt32 MipCount()
{
return mips;
}
FfxUInt32 NumWorkGroups()
{
return numWorkGroups;
}
FfxUInt32x2 WorkGroupOffset()
{
return workGroupOffset;
}
FfxUInt32x2 SPD_RenderSize()
{
return renderSize;
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_SPD)
SamplerState s_PointClamp : register(s0);
SamplerState s_LinearClamp : register(s1);
#if defined(FSR3UPSCALER_BIND_SRV_SPD_MIPS)
Texture2D<FfxFloat32x2> r_spd_mips : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_SPD_MIPS);
FfxInt32x2 GetSPDMipDimensions(FfxUInt32 uMipLevel)
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
FfxUInt32 uLevels;
r_spd_mips.GetDimensions(uMipLevel, uWidth, uHeight, uLevels);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32x2 SampleSPDMipLevel(FfxFloat32x2 fUV, FfxUInt32 mipLevel)
{
return r_spd_mips.SampleLevel(s_LinearClamp, fUV, mipLevel);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_DEPTH)
Texture2D<FfxFloat32> r_input_depth : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_DEPTH);
FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos)
{
return r_input_depth[iPxPos];
}
FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV)
{
return r_input_depth.SampleLevel(s_LinearClamp, fUV, 0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_REACTIVE_MASK)
Texture2D<FfxFloat32> r_reactive_mask : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_REACTIVE_MASK);
FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos)
{
return r_reactive_mask[iPxPos] * fReactivenessScale;
}
FfxInt32x2 GetReactiveMaskResourceDimensions()
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
r_reactive_mask.GetDimensions(uWidth, uHeight);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32 SampleReactiveMask(FfxFloat32x2 fUV)
{
return r_reactive_mask.SampleLevel(s_LinearClamp, fUV, 0).x * fReactivenessScale;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
Texture2D<FfxFloat32> r_transparency_and_composition_mask : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)
{
return r_transparency_and_composition_mask[iPxPos];
}
FfxInt32x2 GetTransparencyAndCompositionMaskResourceDimensions()
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
r_transparency_and_composition_mask.GetDimensions(uWidth, uHeight);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32 SampleTransparencyAndCompositionMask(FfxFloat32x2 fUV)
{
return r_transparency_and_composition_mask.SampleLevel(s_LinearClamp, fUV, 0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_COLOR)
Texture2D<FfxFloat32x4> r_input_color_jittered : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_COLOR);
FfxFloat32x3 LoadInputColor(FfxUInt32x2 iPxPos)
{
return r_input_color_jittered[iPxPos].rgb;
}
FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)
{
return r_input_color_jittered.SampleLevel(s_LinearClamp, fUV, 0).rgb;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS)
Texture2D<FfxFloat32x4> r_input_motion_vectors : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS);
FfxFloat32x2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos)
{
FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[iPxDilatedMotionVectorPos].xy;
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
#if FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS
fUvMotionVector -= MotionVectorJitterCancellation();
#endif
return fUvMotionVector;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INTERNAL_UPSCALED)
Texture2D<FfxFloat32x4> r_internal_upscaled_color : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INTERNAL_UPSCALED);
FfxFloat32x4 LoadHistory(FfxUInt32x2 iPxHistory)
{
return r_internal_upscaled_color[iPxHistory];
}
FfxFloat32x4 SampleHistory(FfxFloat32x2 fUV)
{
return r_internal_upscaled_color.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_LUMA_HISTORY)
RWTexture2D<FfxFloat32x4> rw_luma_history : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_LUMA_HISTORY);
void StoreLumaHistory(FfxUInt32x2 iPxPos, FfxFloat32x4 fLumaHistory)
{
rw_luma_history[iPxPos] = fLumaHistory;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_LUMA_HISTORY)
Texture2D<FfxFloat32x4> r_luma_history : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_LUMA_HISTORY);
FfxFloat32x4 LoadLumaHistory(FfxInt32x2 iPxPos)
{
return r_luma_history[iPxPos];
}
FfxFloat32x4 SampleLumaHistory(FfxFloat32x2 fUV)
{
return r_luma_history.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_RCAS_INPUT)
Texture2D<FfxFloat32x4> r_rcas_input : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_RCAS_INPUT);
FfxFloat32x4 LoadRCAS_Input(FfxInt32x2 iPxPos)
{
return r_rcas_input[iPxPos];
}
FfxFloat32x3 SampleRCAS_Input(FfxFloat32x2 fUV)
{
return r_rcas_input.SampleLevel(s_LinearClamp, fUV, 0).rgb;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_INTERNAL_UPSCALED)
RWTexture2D<FfxFloat32x4> rw_internal_upscaled_color : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_INTERNAL_UPSCALED);
void StoreReprojectedHistory(FfxUInt32x2 iPxHistory, FfxFloat32x4 fHistory)
{
rw_internal_upscaled_color[iPxHistory] = fHistory;
}
void StoreInternalColorAndWeight(FfxUInt32x2 iPxPos, FfxFloat32x4 fColorAndWeight)
{
rw_internal_upscaled_color[iPxPos] = fColorAndWeight;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT)
RWTexture2D<FfxFloat32x4> rw_upscaled_output : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT);
void StoreUpscaledOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
rw_upscaled_output[iPxPos] = FfxFloat32x4(fColor, 1.f);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_ACCUMULATION)
Texture2D<FfxFloat32> r_accumulation : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_ACCUMULATION);
FfxFloat32 SampleAccumulation(FfxFloat32x2 fUV)
{
return r_accumulation.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_ACCUMULATION)
RWTexture2D<FfxFloat32> rw_accumulation : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_ACCUMULATION);
void StoreAccumulation(FfxUInt32x2 iPxPos, FfxFloat32 fAccumulation)
{
rw_accumulation[iPxPos] = fAccumulation;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_SHADING_CHANGE)
Texture2D<FfxFloat32> r_shading_change : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_SHADING_CHANGE);
FfxFloat32 LoadShadingChange(FfxUInt32x2 iPxPos)
{
return r_shading_change[iPxPos] * fShadingChangeScale;
}
FfxFloat32 SampleShadingChange(FfxFloat32x2 fUV)
{
return r_shading_change.SampleLevel(s_LinearClamp, fUV, 0) * fShadingChangeScale;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_SHADING_CHANGE)
RWTexture2D<FfxFloat32> rw_shading_change : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SHADING_CHANGE);
void StoreShadingChange(FfxUInt32x2 iPxPos, FfxFloat32 fShadingChange)
{
rw_shading_change[iPxPos] = fShadingChange;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH)
Texture2D<FfxFloat32> r_farthest_depth : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH);
FfxInt32x2 GetFarthestDepthResourceDimensions()
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
r_farthest_depth.GetDimensions(uWidth, uHeight);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32 LoadFarthestDepth(FfxUInt32x2 iPxPos)
{
return r_farthest_depth[iPxPos];
}
FfxFloat32 SampleFarthestDepth(FfxFloat32x2 fUV)
{
return r_farthest_depth.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH)
RWTexture2D<FfxFloat32> rw_farthest_depth : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH);
void StoreFarthestDepth(FfxUInt32x2 iPxPos, FfxFloat32 fDepth)
{
rw_farthest_depth[iPxPos] = fDepth;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH_MIP1)
Texture2D<FfxFloat32> r_farthest_depth_mip1 : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH_MIP1);
FfxInt32x2 GetFarthestDepthMip1ResourceDimensions()
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
r_farthest_depth_mip1.GetDimensions(uWidth, uHeight);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32 LoadFarthestDepthMip1(FfxUInt32x2 iPxPos)
{
return r_farthest_depth_mip1[iPxPos];
}
FfxFloat32 SampleFarthestDepthMip1(FfxFloat32x2 fUV)
{
return r_farthest_depth_mip1.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH_MIP1)
RWTexture2D<FfxFloat32> rw_farthest_depth_mip1 : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH_MIP1);
void StoreFarthestDepthMip1(FfxUInt32x2 iPxPos, FfxFloat32 fDepth)
{
rw_farthest_depth_mip1[iPxPos] = fDepth;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_CURRENT_LUMA)
Texture2D<FfxFloat32> r_current_luma : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_CURRENT_LUMA);
FfxFloat32 LoadCurrentLuma(FfxUInt32x2 iPxPos)
{
return r_current_luma[iPxPos];
}
FfxFloat32 SampleCurrentLuma(FfxFloat32x2 uv)
{
return r_current_luma.SampleLevel(s_LinearClamp, uv, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_CURRENT_LUMA)
RWTexture2D<FfxFloat32> rw_current_luma : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_CURRENT_LUMA);
void StoreCurrentLuma(FfxUInt32x2 iPxPos, FfxFloat32 fLuma)
{
rw_current_luma[iPxPos] = fLuma;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_LUMA_INSTABILITY)
Texture2D<FfxFloat32> r_luma_instability : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_LUMA_INSTABILITY);
FfxFloat32 SampleLumaInstability(FfxFloat32x2 uv)
{
return r_luma_instability.SampleLevel(s_LinearClamp, uv, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_LUMA_INSTABILITY)
RWTexture2D<FfxFloat32> rw_luma_instability : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_LUMA_INSTABILITY);
void StoreLumaInstability(FfxUInt32x2 iPxPos, FfxFloat32 fLumaInstability)
{
rw_luma_instability[iPxPos] = fLumaInstability;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_PREVIOUS_LUMA)
Texture2D<FfxFloat32> r_previous_luma : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_PREVIOUS_LUMA);
FfxFloat32 LoadPreviousLuma(FfxUInt32x2 iPxPos)
{
return r_previous_luma[iPxPos];
}
FfxFloat32 SamplePreviousLuma(FfxFloat32x2 uv)
{
return r_previous_luma.SampleLevel(s_LinearClamp, uv, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_NEW_LOCKS)
Texture2D<unorm FfxFloat32> r_new_locks : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_NEW_LOCKS);
FfxFloat32 LoadNewLocks(FfxUInt32x2 iPxPos)
{
return r_new_locks[iPxPos];
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_NEW_LOCKS)
RWTexture2D<unorm FfxFloat32> rw_new_locks : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_NEW_LOCKS);
FfxFloat32 LoadRwNewLocks(FfxUInt32x2 iPxPos)
{
return rw_new_locks[iPxPos];
}
void StoreNewLocks(FfxUInt32x2 iPxPos, FfxFloat32 newLock)
{
rw_new_locks[iPxPos] = newLock;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
Texture2D<FfxUInt32> r_reconstructed_previous_nearest_depth : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH);
FfxFloat32 LoadReconstructedPrevDepth(FfxUInt32x2 iPxPos)
{
return asfloat(r_reconstructed_previous_nearest_depth[iPxPos]);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
RWTexture2D<FfxUInt32> rw_reconstructed_previous_nearest_depth : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH);
void StoreReconstructedDepth(FfxUInt32x2 iPxSample, FfxFloat32 fDepth)
{
FfxUInt32 uDepth = asuint(fDepth);
#if FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH
InterlockedMax(rw_reconstructed_previous_nearest_depth[iPxSample], uDepth);
#else
InterlockedMin(rw_reconstructed_previous_nearest_depth[iPxSample], uDepth); // min for standard, max for inverted depth
#endif
}
void SetReconstructedDepth(FfxUInt32x2 iPxSample, const FfxUInt32 uValue)
{
rw_reconstructed_previous_nearest_depth[iPxSample] = uValue;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_DILATED_DEPTH)
RWTexture2D<FfxFloat32> rw_dilated_depth : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_DILATED_DEPTH);
void StoreDilatedDepth(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32 fDepth)
{
rw_dilated_depth[iPxPos] = fDepth;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_DILATED_MOTION_VECTORS)
RWTexture2D<FfxFloat32x2> rw_dilated_motion_vectors : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_DILATED_MOTION_VECTORS);
void StoreDilatedMotionVector(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fMotionVector)
{
rw_dilated_motion_vectors[iPxPos] = fMotionVector;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS)
Texture2D<FfxFloat32x2> r_dilated_motion_vectors : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS);
FfxFloat32x2 LoadDilatedMotionVector(FfxUInt32x2 iPxInput)
{
return r_dilated_motion_vectors[iPxInput];
}
FfxFloat32x2 SampleDilatedMotionVector(FfxFloat32x2 fUV)
{
return r_dilated_motion_vectors.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_DILATED_DEPTH)
Texture2D<FfxFloat32> r_dilated_depth : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_DILATED_DEPTH);
FfxFloat32 LoadDilatedDepth(FfxUInt32x2 iPxInput)
{
return r_dilated_depth[iPxInput];
}
FfxFloat32 SampleDilatedDepth(FfxFloat32x2 fUV)
{
return r_dilated_depth.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE)
Texture2D<FfxFloat32x2> r_input_exposure : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE);
FfxFloat32 Exposure()
{
FfxFloat32 exposure = r_input_exposure[FfxUInt32x2(0, 0)].x;
#if defined(__XBOX_SCARLETT)
if (exposure < 0.000030517578/** 2^-15 */) {
exposure = 1.0f;
}
#else
if (exposure == 0.0f) {
exposure = 1.0f;
}
#endif // #if defined(__XBOX_SCARLETT)
return exposure;
}
#endif
// BEGIN: FSR3UPSCALER_BIND_SRV_LANCZOS_LUT
#if defined(FSR3UPSCALER_BIND_SRV_LANCZOS_LUT)
Texture2D<FfxFloat32> r_lanczos_lut : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_LANCZOS_LUT);
#endif
FfxFloat32 SampleLanczos2Weight(FfxFloat32 x)
{
#if defined(FSR3UPSCALER_BIND_SRV_LANCZOS_LUT)
return r_lanczos_lut.SampleLevel(s_LinearClamp, FfxFloat32x2(x / 2, 0.5f), 0);
#else
return 0.f;
#endif
}
// END: FSR3UPSCALER_BIND_SRV_LANCZOS_LUT
#if defined(FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS)
Texture2D<unorm FfxFloat32x4> r_dilated_reactive_masks : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS);
FfxFloat32x4 SampleDilatedReactiveMasks(FfxFloat32x2 fUV)
{
return r_dilated_reactive_masks.SampleLevel(s_LinearClamp, fUV, 0);
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_DILATED_REACTIVE_MASKS)
RWTexture2D<unorm FfxFloat32x4> rw_dilated_reactive_masks : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_DILATED_REACTIVE_MASKS);
void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x4 fDilatedReactiveMasks)
{
rw_dilated_reactive_masks[iPxPos] = fDilatedReactiveMasks;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY)
Texture2D<FfxFloat32x4> r_input_opaque_only : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY);
FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return r_input_opaque_only[iPxPos].xyz;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_PREV_PRE_ALPHA_COLOR)
Texture2D<float3> r_input_prev_color_pre_alpha : FFX_FSR3UPSCALER_DECLARE_SRV(FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_PREV_PRE_ALPHA_COLOR);
FfxFloat32x3 LoadPrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return r_input_prev_color_pre_alpha[iPxPos];
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_PREV_POST_ALPHA_COLOR)
Texture2D<float3> r_input_prev_color_post_alpha : FFX_FSR3UPSCALER_DECLARE_SRV(FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_PREV_POST_ALPHA_COLOR);
FfxFloat32x3 LoadPrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return r_input_prev_color_post_alpha[iPxPos];
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_AUTOREACTIVE) && \
defined(FSR3UPSCALER_BIND_UAV_AUTOCOMPOSITION)
RWTexture2D<float> rw_output_autoreactive : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_AUTOREACTIVE);
RWTexture2D<float> rw_output_autocomposition : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_AUTOCOMPOSITION);
void StoreAutoReactive(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F2 fReactive)
{
rw_output_autoreactive[iPxPos] = fReactive.x;
rw_output_autocomposition[iPxPos] = fReactive.y;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_PREV_PRE_ALPHA_COLOR)
RWTexture2D<float3> rw_output_prev_color_pre_alpha : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_PREV_PRE_ALPHA_COLOR);
void StorePrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)
{
rw_output_prev_color_pre_alpha[iPxPos] = color;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_PREV_POST_ALPHA_COLOR)
RWTexture2D<float3> rw_output_prev_color_post_alpha : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_PREV_POST_ALPHA_COLOR);
void StorePrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)
{
rw_output_prev_color_post_alpha[iPxPos] = color;
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_FRAME_INFO)
RWTexture2D<FfxFloat32x4> rw_frame_info : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_FRAME_INFO);
FfxFloat32x4 LoadFrameInfo()
{
return rw_frame_info[FfxInt32x2(0, 0)];
}
void StoreFrameInfo(FfxFloat32x4 fInfo)
{
rw_frame_info[FfxInt32x2(0, 0)] = fInfo;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_FRAME_INFO)
Texture2D<FfxFloat32x4> r_frame_info : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_FRAME_INFO);
FfxFloat32x4 FrameInfo()
{
return r_frame_info[FfxInt32x2(0, 0)];
}
#endif
#if defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_0) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_1) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_2) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_3) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_4) && \
defined(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_5)
RWTexture2D<FfxFloat32x2> rw_spd_mip0 : FFX_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_0);
RWTexture2D<FfxFloat32x2> rw_spd_mip1 : FFX_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_1);
RWTexture2D<FfxFloat32x2> rw_spd_mip2 : FFX_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_2);
RWTexture2D<FfxFloat32x2> rw_spd_mip3 : FFX_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_3);
RWTexture2D<FfxFloat32x2> rw_spd_mip4 : FFX_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_4);
globallycoherent RWTexture2D<FfxFloat32x2> rw_spd_mip5 : FFX_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_5);
FfxFloat32x2 RWLoadPyramid(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxUInt32 index)
{
#define LOAD(idx) \
if (index == idx) \
{ \
return rw_spd_mip##idx[iPxPos]; \
}
LOAD(0);
LOAD(1);
LOAD(2);
LOAD(3);
LOAD(4);
LOAD(5);
return 0;
#undef LOAD
}
void StorePyramid(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 outValue, FFX_PARAMETER_IN FfxUInt32 index)
{
#define STORE(idx) \
if (index == idx) \
{ \
rw_spd_mip##idx[iPxPos] = outValue; \
}
STORE(0);
STORE(1);
STORE(2);
STORE(3);
STORE(4);
STORE(5);
#undef STORE
}
#endif
#if defined FSR3UPSCALER_BIND_UAV_SPD_GLOBAL_ATOMIC
globallycoherent RWTexture2D<FfxUInt32> rw_spd_global_atomic : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_SPD_GLOBAL_ATOMIC);
void SPD_IncreaseAtomicCounter(inout FfxUInt32 spdCounter)
{
InterlockedAdd(rw_spd_global_atomic[FfxInt32x2(0, 0)], 1, spdCounter);
}
void SPD_ResetAtomicCounter()
{
rw_spd_global_atomic[FfxInt32x2(0, 0)] = 0;
}
#endif
#endif // #if defined(FFX_GPU)
@@ -0,0 +1,403 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#if !defined(FFX_FSR3UPSCALER_COMMON_H)
#define FFX_FSR3UPSCALER_COMMON_H
#if defined(FFX_GPU)
#pragma warning(error : 3206) // treat vector truncation warnings as errors
#pragma warning(disable : 3205) // conversion from larger type to smaller
#pragma warning(disable : 3571) // in ffxPow(f, e), f could be negative
FFX_STATIC const FfxFloat32 FSR3UPSCALER_FP16_MIN = 6.10e-05f;
FFX_STATIC const FfxFloat32 FSR3UPSCALER_FP16_MAX = 65504.0f;
FFX_STATIC const FfxFloat32 FSR3UPSCALER_EPSILON = FSR3UPSCALER_FP16_MIN;
FFX_STATIC const FfxFloat32 FSR3UPSCALER_TONEMAP_EPSILON = FSR3UPSCALER_FP16_MIN;
FFX_STATIC const FfxFloat32 FSR3UPSCALER_FP32_MAX = 3.402823466e+38f;
FFX_STATIC const FfxFloat32 FSR3UPSCALER_FP32_MIN = 1.175494351e-38f;
// Reconstructed depth usage
FFX_STATIC const FfxFloat32 fReconstructedDepthBilinearWeightThreshold = FSR3UPSCALER_EPSILON * 10;
FfxFloat32 ReconstructedDepthMvPxThreshold(FfxFloat32 fNearestDepthInMeters)
{
return ffxLerp(0.25f, 0.75f, ffxSaturate(fNearestDepthInMeters / 100.0f));
}
// Accumulation
FFX_STATIC const FfxFloat32 fUpsampleLanczosWeightScale = 1.0f / 16.0f;
FFX_STATIC const FfxFloat32 fAverageLanczosWeightPerFrame = 0.74f * fUpsampleLanczosWeightScale; // Average lanczos weight for jitter accumulated samples
FFX_STATIC const FfxFloat32 fAccumulationMaxOnMotion = 3.0f * fUpsampleLanczosWeightScale;
#define SHADING_CHANGE_SET_SIZE 5
FFX_STATIC const FfxInt32 iShadingChangeMipStart = 0;
FFX_STATIC const FfxFloat32 fShadingChangeSamplePow = 1.0f / 1.0f;
FFX_STATIC const FfxFloat32 fLockThreshold = 1.0f;
FFX_STATIC const FfxFloat32 fLockMax = 2.0f;
FFX_STATIC const FfxInt32 REACTIVE = 0;
FFX_STATIC const FfxInt32 DISOCCLUSION = 1;
FFX_STATIC const FfxInt32 SHADING_CHANGE = 2;
FFX_STATIC const FfxInt32 ACCUMULAION = 3;
FFX_STATIC const FfxInt32 FRAME_INFO_EXPOSURE = 0;
FFX_STATIC const FfxInt32 FRAME_INFO_LOG_LUMA = 1;
FFX_STATIC const FfxInt32 FRAME_INFO_SCENE_AVERAGE_LUMA = 2;
FfxBoolean TonemapFirstFrame()
{
const FfxBoolean bEnabled = true;
return FrameIndex() == 0 && bEnabled;
}
FfxFloat32 AverageLanczosWeightPerFrame()
{
return 0.74f;
}
FfxInt32x2 ShadingChangeRenderSize()
{
return FfxInt32x2(RenderSize() * 0.5f);
}
FfxInt32x2 ShadingChangeMaxRenderSize()
{
return FfxInt32x2(MaxRenderSize() * 0.5f);
}
FfxInt32x2 PreviousFrameShadingChangeRenderSize()
{
return FfxInt32x2(PreviousFrameRenderSize() * 0.5f);
}
#if defined(FSR3UPSCALER_BIND_SRV_FRAME_INFO)
FfxFloat32 SceneAverageLuma()
{
return FrameInfo()[FRAME_INFO_SCENE_AVERAGE_LUMA];
}
#endif
// Auto exposure
FFX_STATIC const FfxFloat32 resetAutoExposureAverageSmoothing = 1e4f;
struct AccumulationPassCommonParams
{
FfxInt32x2 iPxHrPos;
FfxFloat32x2 fHrUv;
FfxFloat32x2 fLrUvJittered;
FfxFloat32x2 fLrUv_HwSampler;
FfxFloat32x2 fMotionVector;
FfxFloat32x2 fReprojectedHrUv;
FfxFloat32 f4KVelocity;
FfxFloat32 fDisocclusion;
FfxFloat32 fReactiveMask;
FfxFloat32 fShadingChange;
FfxFloat32 fAccumulation;
FfxFloat32 fLumaInstabilityFactor;
FfxFloat32 fFarthestDepthInMeters;
FfxBoolean bIsExistingSample;
FfxBoolean bIsNewSample;
};
FfxFloat32 Get4KVelocity(FfxFloat32x2 fMotionVector)
{
return length(fMotionVector * FfxFloat32x2(3840.0f, 2160.0f));
}
struct RectificationBox
{
FfxFloat32x3 boxCenter;
FfxFloat32x3 boxVec;
FfxFloat32x3 aabbMin;
FfxFloat32x3 aabbMax;
FfxFloat32 fBoxCenterWeight;
};
struct AccumulationPassData
{
RectificationBox clippingBox;
FfxFloat32x3 fUpsampledColor;
FfxFloat32 fUpsampledWeight;
FfxFloat32x3 fHistoryColor;
FfxFloat32 fHistoryWeight;
FfxFloat32 fLock;
FfxFloat32 fLockContributionThisFrame;
};
void RectificationBoxAddInitialSample(FFX_PARAMETER_INOUT RectificationBox rectificationBox, const FfxFloat32x3 colorSample, const FfxFloat32 fSampleWeight)
{
rectificationBox.aabbMin = colorSample;
rectificationBox.aabbMax = colorSample;
FfxFloat32x3 weightedSample = colorSample * fSampleWeight;
rectificationBox.boxCenter = weightedSample;
rectificationBox.boxVec = colorSample * weightedSample;
rectificationBox.fBoxCenterWeight = fSampleWeight;
}
void RectificationBoxAddSample(FfxBoolean bInitialSample, FFX_PARAMETER_INOUT RectificationBox rectificationBox, const FfxFloat32x3 colorSample, const FfxFloat32 fSampleWeight)
{
if (bInitialSample) {
RectificationBoxAddInitialSample(rectificationBox, colorSample, fSampleWeight);
} else {
rectificationBox.aabbMin = ffxMin(rectificationBox.aabbMin, colorSample);
rectificationBox.aabbMax = ffxMax(rectificationBox.aabbMax, colorSample);
FfxFloat32x3 weightedSample = colorSample * fSampleWeight;
rectificationBox.boxCenter += weightedSample;
rectificationBox.boxVec += colorSample * weightedSample;
rectificationBox.fBoxCenterWeight += fSampleWeight;
}
}
void RectificationBoxComputeVarianceBoxData(FFX_PARAMETER_INOUT RectificationBox rectificationBox)
{
rectificationBox.fBoxCenterWeight = (abs(rectificationBox.fBoxCenterWeight) > FfxFloat32(FSR3UPSCALER_FP32_MIN) ? rectificationBox.fBoxCenterWeight : FfxFloat32(1.f));
rectificationBox.boxCenter /= rectificationBox.fBoxCenterWeight;
rectificationBox.boxVec /= rectificationBox.fBoxCenterWeight;
FfxFloat32x3 stdDev = sqrt(abs(rectificationBox.boxVec - rectificationBox.boxCenter * rectificationBox.boxCenter));
rectificationBox.boxVec = stdDev;
}
FfxFloat32x3 SafeRcp3(FfxFloat32x3 v)
{
return (all(FFX_NOT_EQUAL(v, FfxFloat32x3(0, 0, 0)))) ? (FfxFloat32x3(1, 1, 1) / v) : FfxFloat32x3(0, 0, 0);
}
FfxFloat32 MinDividedByMax(const FfxFloat32 v0, const FfxFloat32 v1, const FfxFloat32 fOnZeroReturnValue)
{
const FfxFloat32 m = ffxMax(v0, v1);
return m != 0 ? ffxMin(v0, v1) / m : fOnZeroReturnValue;
}
FfxFloat32 MinDividedByMax(const FfxFloat32 v0, const FfxFloat32 v1)
{
const FfxFloat32 m = ffxMax(v0, v1);
return m != 0 ? ffxMin(v0, v1) / m : 0;
}
FfxFloat32x3 YCoCgToRGB(FfxFloat32x3 fYCoCg)
{
FfxFloat32x3 fRgb;
fRgb = FfxFloat32x3(
fYCoCg.x + fYCoCg.y - fYCoCg.z,
fYCoCg.x + fYCoCg.z,
fYCoCg.x - fYCoCg.y - fYCoCg.z);
return fRgb;
}
FfxFloat32x3 RGBToYCoCg(FfxFloat32x3 fRgb)
{
FfxFloat32x3 fYCoCg;
fYCoCg = FfxFloat32x3(
0.25f * fRgb.r + 0.5f * fRgb.g + 0.25f * fRgb.b,
0.5f * fRgb.r - 0.5f * fRgb.b,
-0.25f * fRgb.r + 0.5f * fRgb.g - 0.25f * fRgb.b);
return fYCoCg;
}
FfxFloat32 RGBToLuma(FfxFloat32x3 fLinearRgb)
{
return dot(fLinearRgb, FfxFloat32x3(0.2126f, 0.7152f, 0.0722f));
}
FfxFloat32 RGBToPerceivedLuma(FfxFloat32x3 fLinearRgb)
{
FfxFloat32 fLuminance = RGBToLuma(fLinearRgb);
FfxFloat32 fPercievedLuminance = 0;
if (fLuminance <= 216.0f / 24389.0f) {
fPercievedLuminance = fLuminance * (24389.0f / 27.0f);
}
else {
fPercievedLuminance = ffxPow(fLuminance, 1.0f / 3.0f) * 116.0f - 16.0f;
}
return fPercievedLuminance * 0.01f;
}
FfxFloat32x3 Tonemap(FfxFloat32x3 fRgb)
{
return fRgb / (ffxMax(ffxMax(0.f, fRgb.r), ffxMax(fRgb.g, fRgb.b)) + 1.f).xxx;
}
FfxFloat32x3 InverseTonemap(FfxFloat32x3 fRgb)
{
return fRgb / ffxMax(FSR3UPSCALER_TONEMAP_EPSILON, 1.f - ffxMax(fRgb.r, ffxMax(fRgb.g, fRgb.b))).xxx;
}
FfxBoolean IsUvInside(FfxFloat32x2 fUv)
{
return (fUv.x >= 0.0f && fUv.x <= 1.0f) && (fUv.y >= 0.0f && fUv.y <= 1.0f);
}
FfxInt32x2 ClampLoad(FfxInt32x2 iPxSample, FfxInt32x2 iPxOffset, FfxInt32x2 iTextureSize)
{
FfxInt32x2 result = iPxSample + iPxOffset;
result.x = ffxMax(0, ffxMin(result.x, iTextureSize.x - 1));
result.y = ffxMax(0, ffxMin(result.y, iTextureSize.y - 1));
return result;
}
FfxFloat32x2 ClampUv(FfxFloat32x2 fUv, FfxInt32x2 iTextureSize, FfxInt32x2 iResourceSize)
{
const FfxFloat32x2 fSampleLocation = fUv * iTextureSize;
const FfxFloat32x2 fClampedLocation = ffxMax(FfxFloat32x2(0.5f, 0.5f), ffxMin(fSampleLocation, FfxFloat32x2(iTextureSize) - FfxFloat32x2(0.5f, 0.5f)));
const FfxFloat32x2 fClampedUv = fClampedLocation / FfxFloat32x2(iResourceSize);
return fClampedUv;
}
FfxBoolean IsOnScreen(FfxInt32x2 pos, FfxInt32x2 size)
{
return all(FFX_LESS_THAN(FfxUInt32x2(pos), FfxUInt32x2(size)));
}
FfxFloat32 ComputeAutoExposureFromLavg(FfxFloat32 Lavg)
{
Lavg = exp(Lavg);
const FfxFloat32 S = 100.0f; //ISO arithmetic speed
const FfxFloat32 K = 12.5f;
FfxFloat32 ExposureISO100 = log2((Lavg * S) / K);
const FfxFloat32 q = 0.65f;
FfxFloat32 Lmax = (78.0f / (q * S)) * ffxPow(2.0f, ExposureISO100);
return 1.0f / Lmax;
}
FfxInt32x2 ComputeHrPosFromLrPos(FfxInt32x2 iPxLrPos)
{
FfxFloat32x2 fSrcJitteredPos = FfxFloat32x2(iPxLrPos) + 0.5f - Jitter();
FfxFloat32x2 fLrPosInHr = (fSrcJitteredPos / RenderSize()) * UpscaleSize();
FfxInt32x2 iPxHrPos = FfxInt32x2(floor(fLrPosInHr));
return iPxHrPos;
}
FfxFloat32x2 ComputeNdc(FfxFloat32x2 fPxPos, FfxInt32x2 iSize)
{
return fPxPos / FfxFloat32x2(iSize) * FfxFloat32x2(2.0f, -2.0f) + FfxFloat32x2(-1.0f, 1.0f);
}
FfxFloat32 GetViewSpaceDepth(FfxFloat32 fDeviceDepth)
{
const FfxFloat32x4 fDeviceToViewDepth = DeviceToViewSpaceTransformFactors();
// fDeviceToViewDepth details found in ffx_fsr3upscaler.cpp
return (fDeviceToViewDepth[1] / (fDeviceDepth - fDeviceToViewDepth[0]));
}
FfxFloat32 GetViewSpaceDepthInMeters(FfxFloat32 fDeviceDepth)
{
return GetViewSpaceDepth(fDeviceDepth) * ViewSpaceToMetersFactor();
}
FfxFloat32x3 GetViewSpacePosition(FfxInt32x2 iViewportPos, FfxInt32x2 iViewportSize, FfxFloat32 fDeviceDepth)
{
const FfxFloat32x4 fDeviceToViewDepth = DeviceToViewSpaceTransformFactors();
const FfxFloat32 Z = GetViewSpaceDepth(fDeviceDepth);
const FfxFloat32x2 fNdcPos = ComputeNdc(iViewportPos, iViewportSize);
const FfxFloat32 X = fDeviceToViewDepth[2] * fNdcPos.x * Z;
const FfxFloat32 Y = fDeviceToViewDepth[3] * fNdcPos.y * Z;
return FfxFloat32x3(X, Y, Z);
}
FfxFloat32x3 GetViewSpacePositionInMeters(FfxInt32x2 iViewportPos, FfxInt32x2 iViewportSize, FfxFloat32 fDeviceDepth)
{
return GetViewSpacePosition(iViewportPos, iViewportSize, fDeviceDepth) * ViewSpaceToMetersFactor();
}
FfxFloat32 GetMaxDistanceInMeters()
{
#if FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH
return GetViewSpaceDepth(0.0f) * ViewSpaceToMetersFactor();
#else
return GetViewSpaceDepth(1.0f) * ViewSpaceToMetersFactor();
#endif
}
struct BilinearSamplingData
{
FfxInt32x2 iOffsets[4];
FfxFloat32 fWeights[4];
FfxInt32x2 iBasePos;
};
BilinearSamplingData GetBilinearSamplingData(FfxFloat32x2 fUv, FfxInt32x2 iSize)
{
BilinearSamplingData data;
FfxFloat32x2 fPxSample = (fUv * iSize) - FfxFloat32x2(0.5f, 0.5f);
data.iBasePos = FfxInt32x2(floor(fPxSample));
FfxFloat32x2 fPxFrac = ffxFract(fPxSample);
data.iOffsets[0] = FfxInt32x2(0, 0);
data.iOffsets[1] = FfxInt32x2(1, 0);
data.iOffsets[2] = FfxInt32x2(0, 1);
data.iOffsets[3] = FfxInt32x2(1, 1);
data.fWeights[0] = (1 - fPxFrac.x) * (1 - fPxFrac.y);
data.fWeights[1] = (fPxFrac.x) * (1 - fPxFrac.y);
data.fWeights[2] = (1 - fPxFrac.x) * (fPxFrac.y);
data.fWeights[3] = (fPxFrac.x) * (fPxFrac.y);
return data;
}
struct PlaneData
{
FfxFloat32x3 fNormal;
FfxFloat32 fDistanceFromOrigin;
};
PlaneData GetPlaneFromPoints(FfxFloat32x3 fP0, FfxFloat32x3 fP1, FfxFloat32x3 fP2)
{
PlaneData plane;
FfxFloat32x3 v0 = fP0 - fP1;
FfxFloat32x3 v1 = fP0 - fP2;
plane.fNormal = normalize(cross(v0, v1));
plane.fDistanceFromOrigin = -dot(fP0, plane.fNormal);
return plane;
}
FfxFloat32 PointToPlaneDistance(PlaneData plane, FfxFloat32x3 fPoint)
{
return abs(dot(plane.fNormal, fPoint) + plane.fDistanceFromOrigin);
}
#endif // #if defined(FFX_GPU)
#endif //!defined(FFX_FSR3UPSCALER_COMMON_H)
@@ -0,0 +1,159 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
struct FfxDebugViewport
{
FfxInt32x2 offset;
FfxInt32x2 size;
};
// Macro to cull and draw debug viewport
#define DRAW_VIEWPORT(function, pos, vp) \
{ \
if (pointIsInsideViewport(pos, vp)) \
{ \
function(pos, vp); \
} \
}
FfxFloat32x2 getTransformedUv(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = (FfxFloat32x2(iPxPos - vp.offset) + 0.5f) / vp.size;
return fUv;
}
FfxFloat32x3 getMotionVectorColor(FfxFloat32x2 fMotionVector)
{
return FfxFloat32x3(0.5f + fMotionVector * RenderSize() * 0.5f, 0.5f);
}
FfxFloat32x4 getUnusedIndicationColor(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxInt32x2 basePos = iPxPos - vp.offset;
FfxFloat32 ar = FfxFloat32(vp.size.x) / FfxFloat32(vp.size.y);
return FfxFloat32x4(basePos.x == FfxInt32(basePos.y * ar), 0, 0, 1);
}
void drawDilatedMotionVectors(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = getTransformedUv(iPxPos, vp);
FfxFloat32x2 fUv_HW = ClampUv(fUv, RenderSize(), MaxRenderSize());
FfxFloat32x2 fMotionVector = SampleDilatedMotionVector(fUv_HW);
StoreUpscaledOutput(iPxPos, getMotionVectorColor(fMotionVector));
}
void drawDisocclusionMask(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = getTransformedUv(iPxPos, vp);
FfxFloat32x2 fUv_HW = ClampUv(fUv, RenderSize(), MaxRenderSize());
FfxFloat32 fDisocclusionFactor = ffxSaturate(SampleDilatedReactiveMasks(fUv_HW)[DISOCCLUSION]);
StoreUpscaledOutput(iPxPos, FfxFloat32x3(0, fDisocclusionFactor, 0));
}
void drawDetailProtectionTakedown(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = getTransformedUv(iPxPos, vp);
FfxFloat32x2 fUv_HW = ClampUv(fUv, RenderSize(), MaxRenderSize());
FfxFloat32 fProtectionTakedown = ffxSaturate(SampleDilatedReactiveMasks(fUv_HW)[REACTIVE]);
StoreUpscaledOutput(iPxPos, FfxFloat32x3(0, fProtectionTakedown, 0));
}
void drawReactiveness(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = getTransformedUv(iPxPos, vp);
FfxFloat32x2 fUv_HW = ClampUv(fUv, RenderSize(), MaxRenderSize());
FfxFloat32 fShadingChange = ffxSaturate(SampleDilatedReactiveMasks(fUv_HW)[SHADING_CHANGE]);
StoreUpscaledOutput(iPxPos, FfxFloat32x3(0, fShadingChange, 0));
}
void drawProtectedAreas(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = getTransformedUv(iPxPos, vp);
FfxFloat32 fProtection = ffxSaturate(SampleHistory(fUv).w - fLockThreshold);
StoreUpscaledOutput(iPxPos, FfxFloat32x3(fProtection, 0, 0));
}
void drawDilatedDepthInMeters(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxFloat32x2 fUv = getTransformedUv(iPxPos, vp);
FfxFloat32x2 fUv_HW = ClampUv(fUv, RenderSize(), MaxRenderSize());
const FfxFloat32 fDilatedDepth = SampleDilatedDepth(fUv_HW);
const FfxFloat32 fDepthInMeters = GetViewSpaceDepthInMeters(fDilatedDepth);
StoreUpscaledOutput(iPxPos, FfxFloat32x3(ffxSaturate(fDepthInMeters / 25.0f), 0, 0));
}
FfxBoolean pointIsInsideViewport(FfxInt32x2 iPxPos, FfxDebugViewport vp)
{
FfxInt32x2 extent = vp.offset + vp.size;
return (iPxPos.x >= vp.offset.x && iPxPos.x < extent.x) && (iPxPos.y >= vp.offset.y && iPxPos.y < extent.y);
}
void DebugView(FfxInt32x2 iPxPos)
{
#define VIEWPORT_GRID_SIZE_X 3
#define VIEWPORT_GRID_SIZE_Y 3
FfxFloat32x2 fViewportScale = FfxFloat32x2(1.0f / VIEWPORT_GRID_SIZE_X, 1.0f / VIEWPORT_GRID_SIZE_Y);
FfxInt32x2 iViewportSize = FfxInt32x2(UpscaleSize() * fViewportScale);
// compute grid [y][x] for easier placement of viewports
FfxDebugViewport vp[VIEWPORT_GRID_SIZE_Y][VIEWPORT_GRID_SIZE_X];
for (FfxInt32 y = 0; y < VIEWPORT_GRID_SIZE_Y; y++)
{
for (FfxInt32 x = 0; x < VIEWPORT_GRID_SIZE_X; x++)
{
vp[y][x].offset = iViewportSize * FfxInt32x2(x, y);
vp[y][x].size = iViewportSize;
}
}
// top row
DRAW_VIEWPORT(drawDilatedMotionVectors, iPxPos, vp[0][0]);
DRAW_VIEWPORT(drawProtectedAreas, iPxPos, vp[0][1]);
DRAW_VIEWPORT(drawDilatedDepthInMeters, iPxPos, vp[0][2]);
// bottom row
DRAW_VIEWPORT(drawDisocclusionMask, iPxPos, vp[2][0]);
DRAW_VIEWPORT(drawReactiveness, iPxPos, vp[2][1]);
DRAW_VIEWPORT(drawDetailProtectionTakedown, iPxPos, vp[2][2]);
}
@@ -0,0 +1,115 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
struct LumaInstabilityFactorData
{
FfxFloat32x4 fLumaHistory;
FfxFloat32 fLumaInstabilityFactor;
};
LumaInstabilityFactorData ComputeLumaInstabilityFactor(LumaInstabilityFactorData data, FfxFloat32 fCurrentFrameLuma, FfxFloat32 fFarthestDepthInMeters)
{
const FfxInt32 N_MINUS_1 = 0;
const FfxInt32 N_MINUS_2 = 1;
const FfxInt32 N_MINUS_3 = 2;
const FfxInt32 N_MINUS_4 = 3;
FfxFloat32 fLumaInstability = 0.0f;
const FfxFloat32 fDiffs0 = (fCurrentFrameLuma - data.fLumaHistory[N_MINUS_1]);
const FfxFloat32 fSimilarity0 = MinDividedByMax(fCurrentFrameLuma, data.fLumaHistory[N_MINUS_1], 1.0f);
FfxFloat32 fMaxSimilarity = fSimilarity0;
if (fSimilarity0 < 1.0f) {
for (int i = N_MINUS_2; i <= N_MINUS_4; i++) {
const FfxFloat32 fDiffs1 = (fCurrentFrameLuma - data.fLumaHistory[i]);
const FfxFloat32 fSimilarity1 = MinDividedByMax(fCurrentFrameLuma, data.fLumaHistory[i]);
if (sign(fDiffs0) == sign(fDiffs1)) {
fMaxSimilarity = ffxMax(fMaxSimilarity, fSimilarity1);
}
}
fLumaInstability = FfxFloat32(fMaxSimilarity > fSimilarity0);
}
// Shift history
data.fLumaHistory[N_MINUS_4] = data.fLumaHistory[N_MINUS_3];
data.fLumaHistory[N_MINUS_3] = data.fLumaHistory[N_MINUS_2];
data.fLumaHistory[N_MINUS_2] = data.fLumaHistory[N_MINUS_1];
data.fLumaHistory[N_MINUS_1] = fCurrentFrameLuma;
data.fLumaHistory /= Exposure();
data.fLumaInstabilityFactor = fLumaInstability * FfxFloat32(data.fLumaHistory[N_MINUS_4] != 0);
return data;
}
void LumaInstability(FfxInt32x2 iPxPos)
{
LumaInstabilityFactorData data;
data.fLumaInstabilityFactor = 0.0f;
data.fLumaHistory = FfxFloat32x4(0.0f, 0.0f, 0.0f, 0.0f);
const FfxFloat32x2 fDilatedMotionVector = LoadDilatedMotionVector(iPxPos);
const FfxFloat32x2 fUv = (iPxPos + 0.5f) / RenderSize();
const FfxFloat32x2 fUvCurrFrameJittered = fUv + Jitter() / RenderSize();
const FfxFloat32x2 fUvPrevFrameJittered = fUv + PreviousFrameJitter() / PreviousFrameRenderSize();
const FfxFloat32x2 fReprojectedUv = fUvPrevFrameJittered + fDilatedMotionVector;
if (IsUvInside(fReprojectedUv))
{
const FfxFloat32x2 fUvReactive_HW = ClampUv(fUvCurrFrameJittered, RenderSize(), MaxRenderSize());
const FfxFloat32x4 fDilatedReactiveMasks = SampleDilatedReactiveMasks(fUvReactive_HW);
const FfxFloat32 fReactiveMask = ffxSaturate(fDilatedReactiveMasks[REACTIVE]);
const FfxFloat32 fDisocclusion = ffxSaturate(fDilatedReactiveMasks[DISOCCLUSION]);
const FfxFloat32 fShadingChange = ffxSaturate(fDilatedReactiveMasks[SHADING_CHANGE]);
const FfxFloat32 fAccumulation = ffxSaturate(fDilatedReactiveMasks[ACCUMULAION]);
const FfxBoolean bAccumulationFactor = fAccumulation > 0.9f;
const FfxBoolean bComputeInstability = bAccumulationFactor;
if (bComputeInstability) {
const FfxFloat32x2 fUv_HW = ClampUv(fUvCurrFrameJittered, RenderSize(), MaxRenderSize());
const FfxFloat32 fCurrentFrameLuma = SampleCurrentLuma(fUv_HW) * Exposure();
const FfxFloat32x2 fReprojectedUv_HW = ClampUv(fReprojectedUv, PreviousFrameRenderSize(), MaxRenderSize());
data.fLumaHistory = SampleLumaHistory(fReprojectedUv_HW) * DeltaPreExposure() * Exposure();
const FfxFloat32x2 fFarthestDepthUv_HW = ClampUv(fUvCurrFrameJittered, RenderSize() / 2, GetFarthestDepthMip1ResourceDimensions());
const FfxFloat32 fFarthestDepthInMeters = SampleFarthestDepthMip1(fFarthestDepthUv_HW);
data = ComputeLumaInstabilityFactor(data, fCurrentFrameLuma, fFarthestDepthInMeters);
const FfxFloat32 fVelocityWeight = 1.0f - ffxSaturate(Get4KVelocity(fDilatedMotionVector) / 20.0f);
data.fLumaInstabilityFactor *= fVelocityWeight * (1.0f - fDisocclusion) * (1.0f - fReactiveMask) * (1.0f - fShadingChange);
}
}
StoreLumaHistory(iPxPos, data.fLumaHistory);
StoreLumaInstability(iPxPos, data.fLumaInstabilityFactor);
}
@@ -0,0 +1,192 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
FFX_GROUPSHARED FfxUInt32 spdCounter;
void SpdIncreaseAtomicCounter(FfxUInt32 slice)
{
SPD_IncreaseAtomicCounter(spdCounter);
}
FfxUInt32 SpdGetAtomicCounter()
{
return spdCounter;
}
void SpdResetAtomicCounter(FfxUInt32 slice)
{
SPD_ResetAtomicCounter();
}
#ifndef SPD_PACKED_ONLY
FFX_GROUPSHARED FfxFloat32 spdIntermediateR[16][16];
FFX_GROUPSHARED FfxFloat32 spdIntermediateG[16][16];
FFX_GROUPSHARED FfxFloat32 spdIntermediateB[16][16];
FFX_GROUPSHARED FfxFloat32 spdIntermediateA[16][16];
FFX_STATIC const FfxInt32 LOG_LUMA = 0;
FFX_STATIC const FfxInt32 LUMA = 1;
FFX_STATIC const FfxInt32 DEPTH_IN_METERS = 2;
FfxFloat32x4 SpdLoadSourceImage(FfxFloat32x2 iPxPos, FfxUInt32 slice)
{
//We assume linear data. if non-linear input (sRGB, ...),
//then we should convert to linear first and back to sRGB on output.
const FfxInt32x2 iPxSamplePos = ClampLoad(FfxInt32x2(iPxPos), FfxInt32x2(0, 0), FfxInt32x2(RenderSize()));
const FfxFloat32 fLuma = LoadCurrentLuma(iPxSamplePos);
const FfxFloat32 fLogLuma = ffxMax(FSR3UPSCALER_EPSILON, log(fLuma));
const FfxFloat32 fFarthestDepthInMeters = LoadFarthestDepth(iPxSamplePos);
FfxFloat32x4 fOutput = FfxFloat32x4(0.0f, 0.0f, 0.0f, 0.0f);
fOutput[LOG_LUMA] = fLogLuma;
fOutput[LUMA] = fLuma;
fOutput[DEPTH_IN_METERS] = fFarthestDepthInMeters;
return fOutput;
}
FfxFloat32x4 SpdLoad(FfxInt32x2 tex, FfxUInt32 slice)
{
return FfxFloat32x4(RWLoadPyramid(tex, 5), 0, 0);
}
FfxFloat32x4 SpdReduce4(FfxFloat32x4 v0, FfxFloat32x4 v1, FfxFloat32x4 v2, FfxFloat32x4 v3)
{
return (v0 + v1 + v2 + v3) * 0.25f;
}
void SpdStore(FfxInt32x2 pix, FfxFloat32x4 outValue, FfxUInt32 index, FfxUInt32 slice)
{
if (index == 5)
{
StorePyramid(pix, outValue.xy, index);
}
else if (index == 0) {
StoreFarthestDepthMip1(pix, outValue[DEPTH_IN_METERS]);
}
if (index == MipCount() - 1) { //accumulate on 1x1 level
if (all(FFX_EQUAL(pix, FfxInt32x2(0, 0))))
{
FfxFloat32x4 frameInfo = LoadFrameInfo();
const FfxFloat32 fSceneAvgLuma = outValue[LUMA];
const FfxFloat32 fPrevLogLuma = frameInfo[FRAME_INFO_LOG_LUMA];
FfxFloat32 fLogLuma = outValue[LOG_LUMA];
if (fPrevLogLuma < resetAutoExposureAverageSmoothing) // Compare Lavg, so small or negative values
{
fLogLuma = fPrevLogLuma + (fLogLuma - fPrevLogLuma) * (1.0f - exp(-DeltaTime()));
fLogLuma = ffxMax(0.0f, fLogLuma);
}
frameInfo[FRAME_INFO_EXPOSURE] = ComputeAutoExposureFromLavg(fLogLuma);
frameInfo[FRAME_INFO_LOG_LUMA] = fLogLuma;
frameInfo[FRAME_INFO_SCENE_AVERAGE_LUMA] = fSceneAvgLuma;
StoreFrameInfo(frameInfo);
}
}
}
FfxFloat32x4 SpdLoadIntermediate(FfxUInt32 x, FfxUInt32 y)
{
return FfxFloat32x4(
spdIntermediateR[x][y],
spdIntermediateG[x][y],
spdIntermediateB[x][y],
spdIntermediateA[x][y]);
}
void SpdStoreIntermediate(FfxUInt32 x, FfxUInt32 y, FfxFloat32x4 value)
{
spdIntermediateR[x][y] = value.x;
spdIntermediateG[x][y] = value.y;
spdIntermediateB[x][y] = value.z;
spdIntermediateA[x][y] = value.w;
}
#endif
// define fetch and store functions Packed
#if FFX_HALF
FFX_GROUPSHARED FfxFloat16x2 spdIntermediateRG[16][16];
FFX_GROUPSHARED FfxFloat16x2 spdIntermediateBA[16][16];
FfxFloat16x4 SpdLoadSourceImageH(FfxFloat32x2 tex, FfxUInt32 slice)
{
return FfxFloat16x4(0, 0, 0, 0);
}
FfxFloat16x4 SpdLoadH(FfxInt32x2 p, FfxUInt32 slice)
{
return FfxFloat16x4(0, 0, 0, 0);
}
void SpdStoreH(FfxInt32x2 p, FfxFloat16x4 value, FfxUInt32 mip, FfxUInt32 slice)
{
}
FfxFloat16x4 SpdLoadIntermediateH(FfxUInt32 x, FfxUInt32 y)
{
return FfxFloat16x4(
spdIntermediateRG[x][y].x,
spdIntermediateRG[x][y].y,
spdIntermediateBA[x][y].x,
spdIntermediateBA[x][y].y);
}
void SpdStoreIntermediateH(FfxUInt32 x, FfxUInt32 y, FfxFloat16x4 value)
{
spdIntermediateRG[x][y] = value.xy;
spdIntermediateBA[x][y] = value.zw;
}
FfxFloat16x4 SpdReduce4H(FfxFloat16x4 v0, FfxFloat16x4 v1, FfxFloat16x4 v2, FfxFloat16x4 v3)
{
return (v0 + v1 + v2 + v3) * FfxFloat16(0.25);
}
#endif
#include "spd/ffx_spd.h"
void ComputeAutoExposure(FfxUInt32x3 WorkGroupId, FfxUInt32 LocalThreadIndex)
{
#if FFX_HALF
SpdDownsampleH(
FfxUInt32x2(WorkGroupId.xy),
FfxUInt32(LocalThreadIndex),
FfxUInt32(MipCount()),
FfxUInt32(NumWorkGroups()),
FfxUInt32(WorkGroupId.z),
FfxUInt32x2(WorkGroupOffset()));
#else
SpdDownsample(
FfxUInt32x2(WorkGroupId.xy),
FfxUInt32(LocalThreadIndex),
FfxUInt32(MipCount()),
FfxUInt32(NumWorkGroups()),
FfxUInt32(WorkGroupId.z),
FfxUInt32x2(WorkGroupOffset()));
#endif
}
@@ -0,0 +1,152 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
void ReconstructPrevDepth(FfxInt32x2 iPxPos, FfxFloat32 fDepth, FfxFloat32x2 fMotionVector)
{
const FfxFloat32 fNearestDepthInMeters = ffxMin(GetViewSpaceDepthInMeters(fDepth), FSR3UPSCALER_FP16_MAX);
const FfxFloat32 fReconstructedDeptMvThreshold = ReconstructedDepthMvPxThreshold(fNearestDepthInMeters);
// Discard small mvs
fMotionVector *= FfxFloat32(Get4KVelocity(fMotionVector) > fReconstructedDeptMvThreshold);
const FfxFloat32x2 fUv = (iPxPos + FfxFloat32(0.5)) / RenderSize();
const FfxFloat32x2 fReprojectedUv = fUv + fMotionVector;
const BilinearSamplingData bilinearInfo = GetBilinearSamplingData(fReprojectedUv, RenderSize());
// Project current depth into previous frame locations.
// Push to all pixels having some contribution if reprojection is using bilinear logic.
for (FfxInt32 iSampleIndex = 0; iSampleIndex < 4; iSampleIndex++) {
const FfxInt32x2 iOffset = bilinearInfo.iOffsets[iSampleIndex];
const FfxFloat32 fWeight = bilinearInfo.fWeights[iSampleIndex];
if (fWeight > fReconstructedDepthBilinearWeightThreshold) {
const FfxInt32x2 iStorePos = bilinearInfo.iBasePos + iOffset;
if (IsOnScreen(iStorePos, RenderSize())) {
StoreReconstructedDepth(iStorePos, fDepth);
}
}
}
}
struct DepthExtents
{
FfxFloat32 fNearest;
FfxInt32x2 fNearestCoord;
FfxFloat32 fFarthest;
};
DepthExtents FindDepthExtents(FFX_PARAMETER_IN FfxInt32x2 iPxPos)
{
DepthExtents extents;
const FfxInt32 iSampleCount = 9;
const FfxInt32x2 iSampleOffsets[iSampleCount] = {
FfxInt32x2(+0, +0),
FfxInt32x2(+1, +0),
FfxInt32x2(+0, +1),
FfxInt32x2(+0, -1),
FfxInt32x2(-1, +0),
FfxInt32x2(-1, +1),
FfxInt32x2(+1, +1),
FfxInt32x2(-1, -1),
FfxInt32x2(+1, -1),
};
// pull out the depth loads to allow SC to batch them
FfxFloat32 depth[9];
FfxInt32 iSampleIndex = 0;
FFX_UNROLL
for (iSampleIndex = 0; iSampleIndex < iSampleCount; ++iSampleIndex) {
FfxInt32x2 iPos = iPxPos + iSampleOffsets[iSampleIndex];
depth[iSampleIndex] = LoadInputDepth(iPos);
}
// find closest depth
extents.fNearestCoord = iPxPos;
extents.fNearest = depth[0];
extents.fFarthest = depth[0];
FFX_UNROLL
for (iSampleIndex = 1; iSampleIndex < iSampleCount; ++iSampleIndex) {
const FfxInt32x2 iPos = iPxPos + iSampleOffsets[iSampleIndex];
if (IsOnScreen(iPos, RenderSize())) {
FfxFloat32 fNdDepth = depth[iSampleIndex];
#if FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH
if (fNdDepth > extents.fNearest) {
extents.fFarthest = ffxMin(extents.fFarthest, fNdDepth);
#else
if (fNdDepth < extents.fNearest) {
extents.fFarthest = ffxMax(extents.fFarthest, fNdDepth);
#endif
extents.fNearestCoord = iPos;
extents.fNearest = fNdDepth;
}
}
}
return extents;
}
FfxFloat32x2 DilateMotionVector(FfxInt32x2 iPxPos, const DepthExtents depthExtents)
{
#if FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS
const FfxInt32x2 iSamplePos = iPxPos;
const FfxInt32x2 iMotionVectorPos = depthExtents.fNearestCoord;
#else
const FfxInt32x2 iSamplePos = ComputeHrPosFromLrPos(iPxPos);
const FfxInt32x2 iMotionVectorPos = ComputeHrPosFromLrPos(depthExtents.fNearestCoord);
#endif
const FfxFloat32x2 fDilatedMotionVector = LoadInputMotionVector(iMotionVectorPos);
return fDilatedMotionVector;
}
FfxFloat32 GetCurrentFrameLuma(FfxInt32x2 iPxPos)
{
//We assume linear data. if non-linear input (sRGB, ...),
//then we should convert to linear first and back to sRGB on output.
const FfxFloat32x3 fRgb = ffxMax(FfxFloat32x3(0, 0, 0), LoadInputColor(iPxPos));
const FfxFloat32 fLuma = RGBToLuma(fRgb);
return fLuma;
}
void PrepareInputs(FfxInt32x2 iPxPos)
{
const DepthExtents depthExtents = FindDepthExtents(iPxPos);
const FfxFloat32x2 fDilatedMotionVector = DilateMotionVector(iPxPos, depthExtents);
ReconstructPrevDepth(iPxPos, depthExtents.fNearest, fDilatedMotionVector);
StoreDilatedMotionVector(iPxPos, fDilatedMotionVector);
StoreDilatedDepth(iPxPos, depthExtents.fNearest);
const FfxFloat32 fFarthestDepthInMeters = ffxMin(GetViewSpaceDepthInMeters(depthExtents.fFarthest), FSR3UPSCALER_FP16_MAX);
StoreFarthestDepth(iPxPos, fFarthestDepthInMeters);
const FfxFloat32 fLuma = GetCurrentFrameLuma(iPxPos);
StoreCurrentLuma(iPxPos, fLuma);
}
@@ -0,0 +1,283 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
FfxFloat32 ComputeDisocclusions(FfxFloat32x2 fUv, FfxFloat32x2 fMotionVector, FfxFloat32 fCurrentDepthViewSpace)
{
const FfxFloat32 fNearestDepthInMeters = ffxMin(fCurrentDepthViewSpace * ViewSpaceToMetersFactor(), FSR3UPSCALER_FP16_MAX);
const FfxFloat32 fReconstructedDeptMvThreshold = ReconstructedDepthMvPxThreshold(fNearestDepthInMeters);
fMotionVector *= FfxFloat32(Get4KVelocity(fMotionVector) > fReconstructedDeptMvThreshold);
const FfxFloat32x2 fReprojectedUv = fUv + fMotionVector;
const BilinearSamplingData bilinearInfo = GetBilinearSamplingData(fReprojectedUv, RenderSize());
FfxFloat32 fDisocclusion = 0.0f;
FfxFloat32 fWeightSum = 0.0f;
FfxBoolean bPotentialDisocclusion = true;
for (FfxInt32 iSampleIndex = 0; iSampleIndex < 4 && bPotentialDisocclusion; iSampleIndex++)
{
const FfxInt32x2 iOffset = bilinearInfo.iOffsets[iSampleIndex];
const FfxInt32x2 iSamplePos = ClampLoad(bilinearInfo.iBasePos, iOffset, FfxInt32x2(RenderSize()));
if (IsOnScreen(iSamplePos, RenderSize())) {
const FfxFloat32 fWeight = bilinearInfo.fWeights[iSampleIndex];
if (fWeight > fReconstructedDepthBilinearWeightThreshold) {
const FfxFloat32 fPrevNearestDepthViewSpace = GetViewSpaceDepth(LoadReconstructedPrevDepth(iSamplePos));
const FfxFloat32 fDepthDifference = fCurrentDepthViewSpace - fPrevNearestDepthViewSpace;
bPotentialDisocclusion = bPotentialDisocclusion && (fDepthDifference > FSR3UPSCALER_FP32_MIN);
if (bPotentialDisocclusion) {
const FfxFloat32 fHalfViewportWidth = length(FfxFloat32x2(RenderSize()) * 0.5f);
const FfxFloat32 fDepthThreshold = ffxMax(fCurrentDepthViewSpace, fPrevNearestDepthViewSpace);
const FfxFloat32 Ksep = 1.37e-05f;
const FfxFloat32 fRequiredDepthSeparation = Ksep * fHalfViewportWidth * fDepthThreshold;
fDisocclusion += ffxSaturate(FfxFloat32(fRequiredDepthSeparation / fDepthDifference)) * fWeight;
fWeightSum += fWeight;
}
}
}
}
fDisocclusion = (bPotentialDisocclusion && fWeightSum > 0) ? ffxSaturate(1.0f - fDisocclusion / fWeightSum) : 0.0f;
return fDisocclusion;
}
FfxFloat32 ComputeMotionDivergence(FfxFloat32x2 fUv, FfxFloat32x2 fMotionVector, FfxFloat32 fCurrentDepthSample)
{
const FfxInt32x2 iPxReprojectedPos = FfxInt32x2((fUv + fMotionVector) * RenderSize());
const FfxFloat32 fReprojectedDepth = LoadDilatedDepth(iPxReprojectedPos);
const FfxFloat32x2 fReprojectedMotionVector = LoadDilatedMotionVector(iPxReprojectedPos);
const FfxFloat32 fReprojectedVelocity = Get4KVelocity(fReprojectedMotionVector);
const FfxFloat32 f4KVelocity = Get4KVelocity(fMotionVector);
const FfxFloat32 fMaxLen = max(length(fMotionVector), length(fReprojectedMotionVector));
const FfxFloat32 fNucleusDepthInMeters = GetViewSpaceDepthInMeters(fReprojectedDepth);
const FfxFloat32 fCurrentDepthInMeters = GetViewSpaceDepthInMeters(fCurrentDepthSample);
const FfxFloat32 fDistanceFactor = MinDividedByMax(fNucleusDepthInMeters, fCurrentDepthInMeters);
const FfxFloat32 fVelocityFactor = ffxSaturate(f4KVelocity / 10.0f);
const FfxFloat32 fMotionVectorFieldConfidence = (1.0f - ffxSaturate(fReprojectedVelocity / f4KVelocity)) * fDistanceFactor * fVelocityFactor;
return fMotionVectorFieldConfidence;
}
FfxFloat32 DilateReactiveMasks(FfxInt32x2 iPxPos, FfxFloat32x2 fUv)
{
FfxFloat32 fDilatedReactiveMasks = 0.0f;
FFX_UNROLL
for (FfxInt32 y = -1; y <=1; y++)
{
FFX_UNROLL
for (FfxInt32 x = -1; x <= 1; x++)
{
const FfxInt32x2 sampleCoord = ClampLoad(iPxPos, FfxInt32x2(x, y), FfxInt32x2(RenderSize()));
fDilatedReactiveMasks = ffxMax(fDilatedReactiveMasks, LoadReactiveMask(sampleCoord));
}
}
return fDilatedReactiveMasks;
}
FfxFloat32 DilateTransparencyAndCompositionMasks(FfxInt32x2 iPxPos, FfxFloat32x2 fUv)
{
const FfxFloat32x2 fUvTransparencyAndCompositionMask = ClampUv(fUv, RenderSize(), GetTransparencyAndCompositionMaskResourceDimensions());
return SampleTransparencyAndCompositionMask(fUvTransparencyAndCompositionMask);
}
FfxFloat32 ComputeThinFeatureConfidence(FfxInt32x2 iPxPos)
{
/*
1 2 3
4 0 5
6 7 8
*/
const FfxInt32 iNucleusIndex = 0;
const FfxInt32 iSampleCount = 9;
const FfxInt32x2 iSampleOffsets[iSampleCount] = {
FfxInt32x2(+0, +0),
FfxInt32x2(-1, -1),
FfxInt32x2(+0, -1),
FfxInt32x2(+1, -1),
FfxInt32x2(-1, +0),
FfxInt32x2(+1, +0),
FfxInt32x2(-1, +1),
FfxInt32x2(+0, +1),
FfxInt32x2(+1, +1),
};
FfxFloat32 fSamples[iSampleCount];
FfxFloat32 fLumaMin = FSR3UPSCALER_FP32_MAX;
FfxFloat32 fLumaMax = FSR3UPSCALER_FP32_MIN;
FFX_UNROLL
for (FfxInt32 iSampleIndex = 0; iSampleIndex < iSampleCount; ++iSampleIndex) {
const FfxInt32x2 iPxSamplePos = ClampLoad(iPxPos, iSampleOffsets[iSampleIndex], FfxInt32x2(RenderSize()));
fSamples[iSampleIndex] = LoadCurrentLuma(iPxSamplePos) * Exposure();
fLumaMin = ffxMin(fLumaMin, fSamples[iSampleIndex]);
fLumaMax = ffxMax(fLumaMax, fSamples[iSampleIndex]);
}
const FfxFloat32 fThreshold = 0.9f;
FfxFloat32 fDissimilarLumaMin = FSR3UPSCALER_FP32_MAX;
FfxFloat32 fDissimilarLumaMax = 0;
#define SETBIT(x) (1U << x)
FfxUInt32 uPatternMask = SETBIT(iNucleusIndex); // Flag nucleus as similar
const FfxUInt32 uNumRejectionMasks = 4;
const FfxUInt32 uRejectionMasks[uNumRejectionMasks] = {
SETBIT(1) | SETBIT(2) | SETBIT(4) | SETBIT(iNucleusIndex), // Upper left
SETBIT(2) | SETBIT(3) | SETBIT(5) | SETBIT(iNucleusIndex), // Upper right
SETBIT(4) | SETBIT(6) | SETBIT(7) | SETBIT(iNucleusIndex), // Lower left
SETBIT(5) | SETBIT(7) | SETBIT(8) | SETBIT(iNucleusIndex) // Lower right
};
FfxInt32 iBitIndex = 1;
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iSampleCount; ++iSampleIndex, ++iBitIndex) {
const FfxFloat32 fDifference = abs(fSamples[iSampleIndex] - fSamples[iNucleusIndex]) / (fLumaMax - fLumaMin);
if (fDifference < fThreshold)
{
uPatternMask |= SETBIT(iBitIndex);
}
else
{
fDissimilarLumaMin = ffxMin(fDissimilarLumaMin, fSamples[iSampleIndex]);
fDissimilarLumaMax = ffxMax(fDissimilarLumaMax, fSamples[iSampleIndex]);
}
}
const FfxBoolean bIsRidge = fSamples[iNucleusIndex] > fDissimilarLumaMax || fSamples[iNucleusIndex] < fDissimilarLumaMin;
if (FFX_FALSE == bIsRidge)
{
return 0.0f;
}
FFX_UNROLL
for (FfxInt32 i = 0; i < uNumRejectionMasks; i++)
{
if ((uPatternMask & uRejectionMasks[i]) == uRejectionMasks[i])
{
return 0.0f;
}
}
return 1.0f - fLumaMin / fLumaMax;
}
FfxFloat32 UpdateAccumulation(FfxInt32x2 iPxPos, FfxFloat32x2 fUv, FfxFloat32x2 fMotionVector, FfxFloat32 fDisocclusion, FfxFloat32 fShadingChange)
{
const FfxFloat32x2 fReprojectedUv = fUv + fMotionVector;
FfxFloat32 fAccumulation = 0.0f;
if (IsUvInside(fReprojectedUv)) {
const FfxFloat32x2 fReprojectedUv_HW = ClampUv(fReprojectedUv, PreviousFrameRenderSize(), MaxRenderSize());
fAccumulation = ffxSaturate(SampleAccumulation(fReprojectedUv_HW));
}
const FfxFloat32 fAccumulationAddedPerFrame= AccumulationAddedPerFrame(); //default is 0.333
// Assume at frame N+0 fShadingChange is 1.0, and all subsequent frames fShadingChange is 0.0 and fDisocclusion is 0.0. Then,
// frame N+0 fAccumulation will be 0.000
// frame N+2 fAccumulation will be 0.000 + 0.333 * 1 == 0.333
// frame N+3 fAccumulation will be 0.000 + 0.333 * 2 == 0.666
// frame N+4 fAccumulation will be 0.000 + 0.333 * 3 == 0.999
fAccumulation = ffxLerp(fAccumulation, 0.0f, fShadingChange);
const FfxFloat32 fMinDisocclusionAccumulation = MinDisocclusionAccumulation(); //default is -0.333
// Assume at frame N+0 fDisocclusion is 1.0, and all subsequent frames fShadingChange is 0.0 and fDisocclusion is 0.0. Then,
// frame N+0 fAccumulation will be -0.333f (but normalized to store in unorm)
// frame N+1 fAccumulation will be -0.333f + 0.333 * 1 == 0.000
// frame N+2 fAccumulation will be -0.333f + 0.333 * 2 == 0.333
// frame N+3 fAccumulation will be -0.333f + 0.333 * 3 == 0.666
// frame N+4 fAccumulation will be -0.333f + 0.333 * 4 == 0.999
fAccumulation = ffxLerp(fAccumulation, ffxMin(fMinDisocclusionAccumulation, fAccumulation), fDisocclusion);
fAccumulation *= FfxFloat32(round(fAccumulation * 100.0f) > 1.0f);
// Update for next frame, normalize to store in unorm
const FfxFloat32 fAccumulatedFramesToStore = ffxSaturate(fAccumulation + fAccumulationAddedPerFrame);
StoreAccumulation(iPxPos, fAccumulatedFramesToStore);
return fAccumulation;
}
FfxFloat32 ComputeShadingChange(FfxFloat32x2 fUv)
{
// NOTE: Here we re-apply jitter, will be reverted again when sampled in accumulation pass
const FfxFloat32x2 fShadingChangeUv = ClampUv(fUv - Jitter() / RenderSize(), ShadingChangeRenderSize(), ShadingChangeMaxRenderSize());
const FfxFloat32 fShadingChange = ffxSaturate(SampleShadingChange(fShadingChangeUv));
return fShadingChange;
}
void PrepareReactivity(FfxInt32x2 iPxPos)
{
const FfxFloat32x2 fUv = (iPxPos + 0.5f) / RenderSize();
const FfxFloat32x2 fMotionVector = LoadDilatedMotionVector(iPxPos);
// Discard small mvs
const FfxFloat32 f4KVelocity = Get4KVelocity(fMotionVector);
const FfxFloat32x2 fDilatedUv = fUv + fMotionVector;
const FfxFloat32 fDilatedDepth = LoadDilatedDepth(iPxPos);
const FfxFloat32 fDepthInMeters = GetViewSpaceDepthInMeters(fDilatedDepth);
const FfxFloat32 fDisocclusion = ComputeDisocclusions(fUv, fMotionVector, GetViewSpaceDepth(fDilatedDepth));
const FfxFloat32 fShadingChange = ffxMax(DilateReactiveMasks(iPxPos, fUv), ComputeShadingChange(fUv));
const FfxFloat32 fMotionDivergence = ComputeMotionDivergence(fUv, fMotionVector, fDilatedDepth);
const FfxFloat32 fDilatedTransparencyAndComposition = DilateTransparencyAndCompositionMasks(iPxPos, fUv);
const FfxFloat32 fFinalReactiveness = ffxMax(fMotionDivergence, fDilatedTransparencyAndComposition);
const FfxFloat32 fAccumulation = UpdateAccumulation(iPxPos, fUv, fMotionVector, fDisocclusion, fShadingChange);
FfxFloat32x4 fOutput;
fOutput[REACTIVE] = fFinalReactiveness;
fOutput[DISOCCLUSION] = fDisocclusion;
fOutput[SHADING_CHANGE] = fShadingChange;
fOutput[ACCUMULAION] = fAccumulation;
StoreDilatedReactiveMasks(iPxPos, fOutput);
const FfxFloat32 fLockStrength = ComputeThinFeatureConfidence(iPxPos);
if (fLockStrength > (1.0f / 100.0f))
{
StoreNewLocks(ComputeHrPosFromLrPos(FfxInt32x2(iPxPos)), fLockStrength);
}
}
@@ -0,0 +1,112 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#define GROUP_SIZE 8
#define FSR_RCAS_DENOISE 1
#include "ffx_core.h"
#if FFX_HALF && defined(__XBOX_SCARLETT) && defined(__XBATG_EXTRA_16_BIT_OPTIMISATION) && (__XBATG_EXTRA_16_BIT_OPTIMISATION == 1)
#define FSR_RCAS_PREFER_PAIRED_VERSION 1
#else
#define FSR_RCAS_PREFER_PAIRED_VERSION 0
#endif
void WriteUpscaledOutput(FFX_MIN16_U2 iPxHrPos, FfxFloat32x3 fUpscaledColor)
{
StoreUpscaledOutput(FFX_MIN16_I2(iPxHrPos), fUpscaledColor);
}
#if FSR_RCAS_PREFER_PAIRED_VERSION
#define FSR_RCAS_HX2 1
FfxFloat16x4 FsrRcasLoadHx2(FfxInt16x2 p)
{
return FfxFloat16x4(LoadRCAS_Input(p));
}
void FsrRcasInputHx2(inout FfxFloat16x2 r, inout FfxFloat16x2 g, inout FfxFloat16x2 b)
{
FfxFloat32 e = Exposure();
r = FfxFloat16x2(r * e);
g = FfxFloat16x2(g * e);
b = FfxFloat16x2(b * e);
}
#include "fsr1/ffx_fsr1.h"
void CurrFilterPaired(FFX_MIN16_U2 pos)
{
FfxFloat16x2 cr;
FfxFloat16x2 cg;
FfxFloat16x2 cb;
FsrRcasHx2(cr, cg, cb, pos, RCASConfig());
FfxFloat32 InvExposure = 1.0f / Exposure();
cr = FfxFloat16x2(cr * InvExposure);
cg = FfxFloat16x2(cg * InvExposure);
cb = FfxFloat16x2(cb * InvExposure);
WriteUpscaledOutput(pos, FfxFloat16x3(cr.x, cg.x, cb.x)); //TODO: fix type
pos.x += 8;
WriteUpscaledOutput(pos, FfxFloat16x3(cr.y, cg.y, cb.y)); //TODO: fix type
}
#else
#define FSR_RCAS_F 1
FfxFloat32x4 FsrRcasLoadF(FfxInt32x2 p)
{
FfxFloat32x4 fColor = LoadRCAS_Input(p);
fColor.rgb *= Exposure();
return fColor;
}
void FsrRcasInputF(inout FfxFloat32 r, inout FfxFloat32 g, inout FfxFloat32 b) {}
#include "fsr1/ffx_fsr1.h"
void CurrFilter(FFX_MIN16_U2 pos)
{
FfxFloat32x3 c;
FsrRcasF(c.r, c.g, c.b, pos, RCASConfig());
c /= Exposure();
WriteUpscaledOutput(pos, c);
}
#endif // #if FSR_RCAS_PREFER_PAIRED_VERSION
void RCAS(FfxUInt32x3 LocalThreadId, FfxUInt32x3 WorkGroupId, FfxUInt32x3 Dtid)
{
// Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
FfxUInt32x2 gxy = ffxRemapForQuad(LocalThreadId.x) + FfxUInt32x2(WorkGroupId.x << 4u, WorkGroupId.y << 4u);
#if FSR_RCAS_PREFER_PAIRED_VERSION
CurrFilterPaired(FFX_MIN16_U2(gxy));
gxy.y += 8u;
CurrFilterPaired(FFX_MIN16_U2(gxy));
#else
CurrFilter(FFX_MIN16_U2(gxy));
gxy.x += 8u;
CurrFilter(FFX_MIN16_U2(gxy));
gxy.y += 8u;
CurrFilter(FFX_MIN16_U2(gxy));
gxy.x -= 8u;
CurrFilter(FFX_MIN16_U2(gxy));
#endif
}
@@ -0,0 +1,108 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#ifndef FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE
#define FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE 0 // Reference
#endif
FfxFloat32x4 WrapHistory(FfxInt32x2 iPxSample)
{
return LoadHistory(iPxSample);
}
DeclareCustomFetchBicubicSamples(FetchHistorySamples, WrapHistory)
DeclareCustomTextureSample(HistorySample, FFX_FSR3UPSCALER_GET_LANCZOS_SAMPLER1D(FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchHistorySamples)
#if FFX_HALF
FFX_MIN16_F4 WrapHistory16(FfxInt32x2 iPxSample)
{
return FFX_MIN16_F4(LoadHistory(iPxSample));
}
DeclareCustomFetchBicubicSamplesMin16(FetchHistorySamples16, WrapHistory16)
DeclareCustomTextureSampleMin16(HistorySample16, FFX_FSR3UPSCALER_GET_LANCZOS_SAMPLER1D(FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE), FetchHistorySamples16)
#endif
FfxFloat32x2 GetMotionVector(FfxInt32x2 iPxHrPos, FfxFloat32x2 fHrUv)
{
#if FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS
const FfxFloat32x2 fDilatedMotionVector = LoadDilatedMotionVector(FFX_MIN16_I2(fHrUv * RenderSize()));
#else
const FfxFloat32x2 fDilatedMotionVector = LoadInputMotionVector(iPxHrPos);
#endif
return fDilatedMotionVector;
}
void ComputeReprojectedUVs(FFX_PARAMETER_INOUT AccumulationPassCommonParams params)
{
params.fReprojectedHrUv = params.fHrUv + params.fMotionVector;
params.bIsExistingSample = IsUvInside(params.fReprojectedHrUv);
}
#if FFX_FSR3UPSCALER_OPTION_REPROJECT_CATMULL_ROM_5
// Savage Wind: the history reprojected with a Catmull-Rom filter from 5 bilinear samples (its 4x4 footprint's corners
// left out) instead of Lanczos on 16 loads: the accumulation's largest cost, ~0.3 ms less at 3840x2160 on an RTX 3060.
// The history texture is the upscale size (the upscaler's output, fixed).
FfxFloat32x4 HistorySampleCatmullRom5(FfxFloat32x2 fUv, FfxFloat32x2 fSize)
{
const FfxFloat32x2 fPx = fUv * fSize;
const FfxFloat32x2 fPx1 = floor(fPx - 0.5f) + 0.5f;
const FfxFloat32x2 f = fPx - fPx1;
const FfxFloat32x2 w0 = f * (-0.5f + f * (1.0f - 0.5f * f));
const FfxFloat32x2 w1 = 1.0f + f * f * (-2.5f + 1.5f * f);
const FfxFloat32x2 w2 = f * (0.5f + f * (2.0f - 1.5f * f));
const FfxFloat32x2 w3 = f * f * (-0.5f + 0.5f * f);
const FfxFloat32x2 w12 = w1 + w2;
const FfxFloat32x2 fUv0 = (fPx1 - 1.0f) / fSize;
const FfxFloat32x2 fUv3 = (fPx1 + 2.0f) / fSize;
const FfxFloat32x2 fUv12 = (fPx1 + w2 / w12) / fSize;
const FfxFloat32 k0 = w12.x * w0.y, k1 = w0.x * w12.y, k2 = w12.x * w12.y, k3 = w3.x * w12.y, k4 = w12.x * w3.y;
FfxFloat32x4 c = SampleHistory(FfxFloat32x2(fUv12.x, fUv0.y)) * k0
+ SampleHistory(FfxFloat32x2(fUv0.x, fUv12.y)) * k1
+ SampleHistory(fUv12) * k2
+ SampleHistory(FfxFloat32x2(fUv3.x, fUv12.y)) * k3
+ SampleHistory(FfxFloat32x2(fUv12.x, fUv3.y)) * k4;
return ffxMax(c / (k0 + k1 + k2 + k3 + k4), FfxFloat32x4(0.0f, 0.0f, 0.0f, 0.0f));
}
#endif
void ReprojectHistoryColor(const AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data)
{
#if FFX_FSR3UPSCALER_OPTION_REPROJECT_CATMULL_ROM_5
const FfxFloat32x4 fReprojectedHistory = HistorySampleCatmullRom5(params.fReprojectedHrUv, FfxFloat32x2(UpscaleSize()));
#elif FFX_HALF && FFX_FSR3UPSCALER_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF
const FfxFloat32x4 fReprojectedHistory = FfxFloat32x4(HistorySample16(params.fReprojectedHrUv, UpscaleSize()));
#else
const FfxFloat32x4 fReprojectedHistory = HistorySample(params.fReprojectedHrUv, PreviousFrameUpscaleSize());
#endif
data.fHistoryColor = fReprojectedHistory.rgb;
data.fHistoryColor *= DeltaPreExposure();
data.fHistoryColor *= Exposure();
data.fHistoryColor = RGBToYCoCg(data.fHistoryColor);
data.fLock = fReprojectedHistory.w;
}
@@ -0,0 +1,100 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#ifndef FFX_FSR3UPSCALER_RESOURCES_H
#define FFX_FSR3UPSCALER_RESOURCES_H
#if defined(FFX_CPU) || defined(FFX_GPU)
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_NULL 0
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_OPAQUE_ONLY 1
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_COLOR 2
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_MOTION_VECTORS 3
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_DEPTH 4
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_EXPOSURE 5
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_REACTIVE_MASK 6
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INPUT_TRANSPARENCY_AND_COMPOSITION_MASK 7
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_RECONSTRUCTED_PREVIOUS_NEAREST_DEPTH 8
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_DILATED_MOTION_VECTORS 9
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_DILATED_DEPTH 10
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERNAL_UPSCALED_COLOR 11
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_ACCUMULATION 12
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_NEW_LOCKS 13
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LUMA_HISTORY 14
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_DEBUG_OUTPUT 15
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LANCZOS_LUT 16
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_ATOMIC_COUNT 17
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_UPSCALED_OUTPUT 18
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_RCAS_INPUT 19
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_ACCUMULATION_1 20
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_ACCUMULATION_2 21
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERNAL_UPSCALED_COLOR_1 22
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERNAL_UPSCALED_COLOR_2 23
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERNAL_DEFAULT_REACTIVITY 24
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERNAL_DEFAULT_TRANSPARENCY_AND_COMPOSITION 25
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_DILATED_REACTIVE_MASKS 26
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS 27 // same as FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_0
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_0 27
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_1 28
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_2 29
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_3 30
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_4 31
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SPD_MIPS_LEVEL_5 32
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERNAL_DEFAULT_EXPOSURE 33
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_FRAME_INFO 34
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_AUTOREACTIVE 35
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_AUTOCOMPOSITION_DEPRECATED 36
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LUMA_HISTORY_1 37
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LUMA_HISTORY_2 38
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LUMA_1 40
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LUMA_2 41
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SHADING_CHANGE 42
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_FARTHEST_DEPTH 43
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_FARTHEST_DEPTH_MIP1 44
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_CURRENT_LUMA 45
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_PREVIOUS_LUMA 46
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LUMA_INSTABILITY 48
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_INTERMEDIATE_FP16x1 49
// Shading change detection mip level setting, value must be in the range [FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_0, FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_12]
//#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_SHADING_CHANGE FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_4
//#define FFX_FSR3UPSCALER_SHADING_CHANGE_MIP_LEVEL (FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_SHADING_CHANGE - FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_SCENE_LUMINANCE)
#define FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT 60
#define FFX_FSR3UPSCALER_CONSTANTBUFFER_IDENTIFIER_FSR3UPSCALER 0
#define FFX_FSR3UPSCALER_CONSTANTBUFFER_IDENTIFIER_SPD 1
#define FFX_FSR3UPSCALER_CONSTANTBUFFER_IDENTIFIER_RCAS 2
#define FFX_FSR3UPSCALER_CONSTANTBUFFER_IDENTIFIER_GENREACTIVE 3
#define FFX_FSR3UPSCALER_CONSTANTBUFFER_COUNT 4
#define FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_APPLY_TONEMAP 1
#define FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_APPLY_INVERSETONEMAP 2
#define FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_APPLY_THRESHOLD 4
#define FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_USE_COMPONENTS_MAX 8
#endif // #if defined(FFX_CPU) || defined(FFX_GPU)
#endif //!defined( FFX_FSR3UPSCALER_RESOURCES_H )
@@ -0,0 +1,628 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#ifndef FFX_FSR3UPSCALER_SAMPLE_H
#define FFX_FSR3UPSCALER_SAMPLE_H
// suppress warnings
#ifdef FFX_HLSL
#pragma warning(disable: 4008) // potentially divide by zero
#endif //FFX_HLSL
struct FetchedBilinearSamples {
FfxFloat32x4 fColor00;
FfxFloat32x4 fColor10;
FfxFloat32x4 fColor01;
FfxFloat32x4 fColor11;
};
struct FetchedBicubicSamples {
FfxFloat32x4 fColor00;
FfxFloat32x4 fColor10;
FfxFloat32x4 fColor20;
FfxFloat32x4 fColor30;
FfxFloat32x4 fColor01;
FfxFloat32x4 fColor11;
FfxFloat32x4 fColor21;
FfxFloat32x4 fColor31;
FfxFloat32x4 fColor02;
FfxFloat32x4 fColor12;
FfxFloat32x4 fColor22;
FfxFloat32x4 fColor32;
FfxFloat32x4 fColor03;
FfxFloat32x4 fColor13;
FfxFloat32x4 fColor23;
FfxFloat32x4 fColor33;
};
#if FFX_HALF
struct FetchedBilinearSamplesMin16 {
FFX_MIN16_F4 fColor00;
FFX_MIN16_F4 fColor10;
FFX_MIN16_F4 fColor01;
FFX_MIN16_F4 fColor11;
};
struct FetchedBicubicSamplesMin16 {
FFX_MIN16_F4 fColor00;
FFX_MIN16_F4 fColor10;
FFX_MIN16_F4 fColor20;
FFX_MIN16_F4 fColor30;
FFX_MIN16_F4 fColor01;
FFX_MIN16_F4 fColor11;
FFX_MIN16_F4 fColor21;
FFX_MIN16_F4 fColor31;
FFX_MIN16_F4 fColor02;
FFX_MIN16_F4 fColor12;
FFX_MIN16_F4 fColor22;
FFX_MIN16_F4 fColor32;
FFX_MIN16_F4 fColor03;
FFX_MIN16_F4 fColor13;
FFX_MIN16_F4 fColor23;
FFX_MIN16_F4 fColor33;
};
#else //FFX_HALF
#define FetchedBicubicSamplesMin16 FetchedBicubicSamples
#define FetchedBilinearSamplesMin16 FetchedBilinearSamples
#endif //FFX_HALF
FfxFloat32x4 Linear(FfxFloat32x4 A, FfxFloat32x4 B, FfxFloat32 t)
{
return A + (B - A) * t;
}
FfxFloat32x4 Bilinear(FetchedBilinearSamples BilinearSamples, FfxFloat32x2 fPxFrac)
{
FfxFloat32x4 fColorX0 = Linear(BilinearSamples.fColor00, BilinearSamples.fColor10, fPxFrac.x);
FfxFloat32x4 fColorX1 = Linear(BilinearSamples.fColor01, BilinearSamples.fColor11, fPxFrac.x);
FfxFloat32x4 fColorXY = Linear(fColorX0, fColorX1, fPxFrac.y);
return fColorXY;
}
#if FFX_HALF
FFX_MIN16_F4 Linear(FFX_MIN16_F4 A, FFX_MIN16_F4 B, FFX_MIN16_F t)
{
return A + (B - A) * t;
}
FFX_MIN16_F4 Bilinear(FetchedBilinearSamplesMin16 BilinearSamples, FFX_MIN16_F2 fPxFrac)
{
FFX_MIN16_F4 fColorX0 = Linear(BilinearSamples.fColor00, BilinearSamples.fColor10, fPxFrac.x);
FFX_MIN16_F4 fColorX1 = Linear(BilinearSamples.fColor01, BilinearSamples.fColor11, fPxFrac.x);
FFX_MIN16_F4 fColorXY = Linear(fColorX0, fColorX1, fPxFrac.y);
return fColorXY;
}
#endif
FfxFloat32 Lanczos2NoClamp(FfxFloat32 x)
{
const FfxFloat32 PI = 3.141592653589793f; // TODO: share SDK constants
return abs(x) < FSR3UPSCALER_EPSILON ? 1.f : (sin(PI * x) / (PI * x)) * (sin(0.5f * PI * x) / (0.5f * PI * x));
}
FfxFloat32 Lanczos2(FfxFloat32 x)
{
x = ffxMin(abs(x), 2.0f);
return Lanczos2NoClamp(x);
}
#if FFX_HALF
#if 0
FFX_MIN16_F Lanczos2NoClamp(FFX_MIN16_F x)
{
const FFX_MIN16_F PI = FFX_MIN16_F(3.141592653589793f); // TODO: share SDK constants
return abs(x) < FFX_MIN16_F(FSR3UPSCALER_EPSILON) ? FFX_MIN16_F(1.f) : (sin(PI * x) / (PI * x)) * (sin(FFX_MIN16_F(0.5f) * PI * x) / (FFX_MIN16_F(0.5f) * PI * x));
}
#endif
FFX_MIN16_F Lanczos2(FFX_MIN16_F x)
{
x = ffxMin(abs(x), FFX_MIN16_F(2.0f));
return FFX_MIN16_F(Lanczos2NoClamp(x));
}
#endif //FFX_HALF
// FSR1 lanczos approximation. Input is x*x and must be <= 4.
FfxFloat32 Lanczos2ApproxSqNoClamp(FfxFloat32 x2)
{
FfxFloat32 a = (2.0f / 5.0f) * x2 - 1;
FfxFloat32 b = (1.0f / 4.0f) * x2 - 1;
return ((25.0f / 16.0f) * a * a - (25.0f / 16.0f - 1)) * (b * b);
}
#if FFX_HALF
FFX_MIN16_F Lanczos2ApproxSqNoClamp(FFX_MIN16_F x2)
{
FFX_MIN16_F a = FFX_MIN16_F(2.0f / 5.0f) * x2 - FFX_MIN16_F(1);
FFX_MIN16_F b = FFX_MIN16_F(1.0f / 4.0f) * x2 - FFX_MIN16_F(1);
return (FFX_MIN16_F(25.0f / 16.0f) * a * a - FFX_MIN16_F(25.0f / 16.0f - 1)) * (b * b);
}
#if defined(__XBOX_SCARLETT) && defined(__XBATG_EXTRA_16_BIT_OPTIMISATION) && (__XBATG_EXTRA_16_BIT_OPTIMISATION == 1)
FFX_MIN16_F2 PairedLanczos2ApproxSqNoClamp(FFX_MIN16_F2 x2)
{
// Xbox ATG (Pavel):
//
// 2.0 * x2 - 5.0 25.0 25.0 - 16.0 (2.0 * x2 - 5.0)^2 - (3.0)^2 (2.0 * x2 - 8.0) * (2.0 * x2 - 2.0) (x2 - 4.0) * (x2 - 1.0)
// a = -------------- ==> ---- * a^2 - -------------- = ----------------------------- = ---------------------------------- = ----------------------- = b * (x2 - 1.0)
// 5.0 16.0 16.0 16.0 16.0 4.0
//
// so we need to compute just (b * b) * (b * x2 - b), so we should get four packed instructions: 2 fma + 2 mul
//
FFX_MIN16_F2 b = (0.25 * x2 - 1.0);
return (b * b) * (b * x2 - b);
}
#endif
#endif //FFX_HALF
FfxFloat32 Lanczos2ApproxSq(FfxFloat32 x2)
{
x2 = ffxMin(x2, 4.0f);
return Lanczos2ApproxSqNoClamp(x2);
}
#if FFX_HALF
FFX_MIN16_F Lanczos2ApproxSq(FFX_MIN16_F x2)
{
x2 = ffxMin(x2, FFX_MIN16_F(4.0f));
return Lanczos2ApproxSqNoClamp(x2);
}
#if defined(__XBOX_SCARLETT) && defined(__XBATG_EXTRA_16_BIT_OPTIMISATION) && (__XBATG_EXTRA_16_BIT_OPTIMISATION == 1)
FFX_MIN16_F2 PairedLanczos2ApproxSq(FFX_MIN16_F2 x2)
{
x2 = ffxMin(x2, FFX_MIN16_F2(4.0, 4.0));
return PairedLanczos2ApproxSqNoClamp(x2);
}
#endif
#endif //FFX_HALF
FfxFloat32 Lanczos2ApproxNoClamp(FfxFloat32 x)
{
return Lanczos2ApproxSqNoClamp(x * x);
}
#if FFX_HALF
FFX_MIN16_F Lanczos2ApproxNoClamp(FFX_MIN16_F x)
{
return Lanczos2ApproxSqNoClamp(x * x);
}
#endif //FFX_HALF
FfxFloat32 Lanczos2Approx(FfxFloat32 x)
{
return Lanczos2ApproxSq(x * x);
}
#if FFX_HALF
FFX_MIN16_F Lanczos2Approx(FFX_MIN16_F x)
{
return Lanczos2ApproxSq(x * x);
}
#endif //FFX_HALF
FfxFloat32 Lanczos2_UseLUT(FfxFloat32 x)
{
return SampleLanczos2Weight(abs(x));
}
#if FFX_HALF
FFX_MIN16_F Lanczos2_UseLUT(FFX_MIN16_F x)
{
return FFX_MIN16_F(SampleLanczos2Weight(abs(x)));
}
#endif //FFX_HALF
FfxFloat32x4 Lanczos2_UseLUT(FfxFloat32x4 fColor0, FfxFloat32x4 fColor1, FfxFloat32x4 fColor2, FfxFloat32x4 fColor3, FfxFloat32 t)
{
FfxFloat32 fWeight0 = Lanczos2_UseLUT(-1.f - t);
FfxFloat32 fWeight1 = Lanczos2_UseLUT(-0.f - t);
FfxFloat32 fWeight2 = Lanczos2_UseLUT(+1.f - t);
FfxFloat32 fWeight3 = Lanczos2_UseLUT(+2.f - t);
return (fWeight0 * fColor0 + fWeight1 * fColor1 + fWeight2 * fColor2 + fWeight3 * fColor3) / (fWeight0 + fWeight1 + fWeight2 + fWeight3);
}
#if FFX_HALF
FFX_MIN16_F4 Lanczos2_UseLUT(FFX_MIN16_F4 fColor0, FFX_MIN16_F4 fColor1, FFX_MIN16_F4 fColor2, FFX_MIN16_F4 fColor3, FFX_MIN16_F t)
{
FFX_MIN16_F fWeight0 = Lanczos2_UseLUT(FFX_MIN16_F(-1.f) - t);
FFX_MIN16_F fWeight1 = Lanczos2_UseLUT(FFX_MIN16_F(-0.f) - t);
FFX_MIN16_F fWeight2 = Lanczos2_UseLUT(FFX_MIN16_F(+1.f) - t);
FFX_MIN16_F fWeight3 = Lanczos2_UseLUT(FFX_MIN16_F(+2.f) - t);
return (fWeight0 * fColor0 + fWeight1 * fColor1 + fWeight2 * fColor2 + fWeight3 * fColor3) / (fWeight0 + fWeight1 + fWeight2 + fWeight3);
}
#endif
FfxFloat32x4 Lanczos2(FfxFloat32x4 fColor0, FfxFloat32x4 fColor1, FfxFloat32x4 fColor2, FfxFloat32x4 fColor3, FfxFloat32 t)
{
FfxFloat32 fWeight0 = Lanczos2(-1.f - t);
FfxFloat32 fWeight1 = Lanczos2(-0.f - t);
FfxFloat32 fWeight2 = Lanczos2(+1.f - t);
FfxFloat32 fWeight3 = Lanczos2(+2.f - t);
return (fWeight0 * fColor0 + fWeight1 * fColor1 + fWeight2 * fColor2 + fWeight3 * fColor3) / (fWeight0 + fWeight1 + fWeight2 + fWeight3);
}
FfxFloat32x4 Lanczos2(FetchedBicubicSamples Samples, FfxFloat32x2 fPxFrac)
{
FfxFloat32x4 fColorX0 = Lanczos2(Samples.fColor00, Samples.fColor10, Samples.fColor20, Samples.fColor30, fPxFrac.x);
FfxFloat32x4 fColorX1 = Lanczos2(Samples.fColor01, Samples.fColor11, Samples.fColor21, Samples.fColor31, fPxFrac.x);
FfxFloat32x4 fColorX2 = Lanczos2(Samples.fColor02, Samples.fColor12, Samples.fColor22, Samples.fColor32, fPxFrac.x);
FfxFloat32x4 fColorX3 = Lanczos2(Samples.fColor03, Samples.fColor13, Samples.fColor23, Samples.fColor33, fPxFrac.x);
FfxFloat32x4 fColorXY = Lanczos2(fColorX0, fColorX1, fColorX2, fColorX3, fPxFrac.y);
// Deringing
// TODO: only use 4 by checking jitter
const FfxInt32 iDeringingSampleCount = 4;
const FfxFloat32x4 fDeringingSamples[4] = {
Samples.fColor11,
Samples.fColor21,
Samples.fColor12,
Samples.fColor22,
};
FfxFloat32x4 fDeringingMin = fDeringingSamples[0];
FfxFloat32x4 fDeringingMax = fDeringingSamples[0];
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iDeringingSampleCount; ++iSampleIndex) {
fDeringingMin = ffxMin(fDeringingMin, fDeringingSamples[iSampleIndex]);
fDeringingMax = ffxMax(fDeringingMax, fDeringingSamples[iSampleIndex]);
}
fColorXY = clamp(fColorXY, fDeringingMin, fDeringingMax);
return fColorXY;
}
#if FFX_HALF
FFX_MIN16_F4 Lanczos2(FFX_MIN16_F4 fColor0, FFX_MIN16_F4 fColor1, FFX_MIN16_F4 fColor2, FFX_MIN16_F4 fColor3, FFX_MIN16_F t)
{
FFX_MIN16_F fWeight0 = Lanczos2(FFX_MIN16_F(-1.f) - t);
FFX_MIN16_F fWeight1 = Lanczos2(FFX_MIN16_F(-0.f) - t);
FFX_MIN16_F fWeight2 = Lanczos2(FFX_MIN16_F(+1.f) - t);
FFX_MIN16_F fWeight3 = Lanczos2(FFX_MIN16_F(+2.f) - t);
return (fWeight0 * fColor0 + fWeight1 * fColor1 + fWeight2 * fColor2 + fWeight3 * fColor3) / (fWeight0 + fWeight1 + fWeight2 + fWeight3);
}
FFX_MIN16_F4 Lanczos2(FetchedBicubicSamplesMin16 Samples, FFX_MIN16_F2 fPxFrac)
{
FFX_MIN16_F4 fColorX0 = Lanczos2(Samples.fColor00, Samples.fColor10, Samples.fColor20, Samples.fColor30, fPxFrac.x);
FFX_MIN16_F4 fColorX1 = Lanczos2(Samples.fColor01, Samples.fColor11, Samples.fColor21, Samples.fColor31, fPxFrac.x);
FFX_MIN16_F4 fColorX2 = Lanczos2(Samples.fColor02, Samples.fColor12, Samples.fColor22, Samples.fColor32, fPxFrac.x);
FFX_MIN16_F4 fColorX3 = Lanczos2(Samples.fColor03, Samples.fColor13, Samples.fColor23, Samples.fColor33, fPxFrac.x);
FFX_MIN16_F4 fColorXY = Lanczos2(fColorX0, fColorX1, fColorX2, fColorX3, fPxFrac.y);
// Deringing
// TODO: only use 4 by checking jitter
const FfxInt32 iDeringingSampleCount = 4;
const FFX_MIN16_F4 fDeringingSamples[4] = {
Samples.fColor11,
Samples.fColor21,
Samples.fColor12,
Samples.fColor22,
};
FFX_MIN16_F4 fDeringingMin = fDeringingSamples[0];
FFX_MIN16_F4 fDeringingMax = fDeringingSamples[0];
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iDeringingSampleCount; ++iSampleIndex)
{
fDeringingMin = ffxMin(fDeringingMin, fDeringingSamples[iSampleIndex]);
fDeringingMax = ffxMax(fDeringingMax, fDeringingSamples[iSampleIndex]);
}
fColorXY = clamp(fColorXY, fDeringingMin, fDeringingMax);
return fColorXY;
}
#endif //FFX_HALF
FfxFloat32x4 Lanczos2LUT(FetchedBicubicSamples Samples, FfxFloat32x2 fPxFrac)
{
FfxFloat32x4 fColorX0 = Lanczos2_UseLUT(Samples.fColor00, Samples.fColor10, Samples.fColor20, Samples.fColor30, fPxFrac.x);
FfxFloat32x4 fColorX1 = Lanczos2_UseLUT(Samples.fColor01, Samples.fColor11, Samples.fColor21, Samples.fColor31, fPxFrac.x);
FfxFloat32x4 fColorX2 = Lanczos2_UseLUT(Samples.fColor02, Samples.fColor12, Samples.fColor22, Samples.fColor32, fPxFrac.x);
FfxFloat32x4 fColorX3 = Lanczos2_UseLUT(Samples.fColor03, Samples.fColor13, Samples.fColor23, Samples.fColor33, fPxFrac.x);
FfxFloat32x4 fColorXY = Lanczos2_UseLUT(fColorX0, fColorX1, fColorX2, fColorX3, fPxFrac.y);
// Deringing
// TODO: only use 4 by checking jitter
const FfxInt32 iDeringingSampleCount = 4;
const FfxFloat32x4 fDeringingSamples[4] = {
Samples.fColor11,
Samples.fColor21,
Samples.fColor12,
Samples.fColor22,
};
FfxFloat32x4 fDeringingMin = fDeringingSamples[0];
FfxFloat32x4 fDeringingMax = fDeringingSamples[0];
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iDeringingSampleCount; ++iSampleIndex) {
fDeringingMin = ffxMin(fDeringingMin, fDeringingSamples[iSampleIndex]);
fDeringingMax = ffxMax(fDeringingMax, fDeringingSamples[iSampleIndex]);
}
fColorXY = clamp(fColorXY, fDeringingMin, fDeringingMax);
return fColorXY;
}
#if FFX_HALF
FFX_MIN16_F4 Lanczos2LUT(FetchedBicubicSamplesMin16 Samples, FFX_MIN16_F2 fPxFrac)
{
FFX_MIN16_F4 fColorX0 = Lanczos2_UseLUT(Samples.fColor00, Samples.fColor10, Samples.fColor20, Samples.fColor30, fPxFrac.x);
FFX_MIN16_F4 fColorX1 = Lanczos2_UseLUT(Samples.fColor01, Samples.fColor11, Samples.fColor21, Samples.fColor31, fPxFrac.x);
FFX_MIN16_F4 fColorX2 = Lanczos2_UseLUT(Samples.fColor02, Samples.fColor12, Samples.fColor22, Samples.fColor32, fPxFrac.x);
FFX_MIN16_F4 fColorX3 = Lanczos2_UseLUT(Samples.fColor03, Samples.fColor13, Samples.fColor23, Samples.fColor33, fPxFrac.x);
FFX_MIN16_F4 fColorXY = Lanczos2_UseLUT(fColorX0, fColorX1, fColorX2, fColorX3, fPxFrac.y);
// Deringing
// TODO: only use 4 by checking jitter
const FfxInt32 iDeringingSampleCount = 4;
const FFX_MIN16_F4 fDeringingSamples[4] = {
Samples.fColor11,
Samples.fColor21,
Samples.fColor12,
Samples.fColor22,
};
FFX_MIN16_F4 fDeringingMin = fDeringingSamples[0];
FFX_MIN16_F4 fDeringingMax = fDeringingSamples[0];
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iDeringingSampleCount; ++iSampleIndex)
{
fDeringingMin = ffxMin(fDeringingMin, fDeringingSamples[iSampleIndex]);
fDeringingMax = ffxMax(fDeringingMax, fDeringingSamples[iSampleIndex]);
}
fColorXY = clamp(fColorXY, fDeringingMin, fDeringingMax);
return fColorXY;
}
#endif //FFX_HALF
FfxFloat32x4 Lanczos2Approx(FfxFloat32x4 fColor0, FfxFloat32x4 fColor1, FfxFloat32x4 fColor2, FfxFloat32x4 fColor3, FfxFloat32 t)
{
FfxFloat32 fWeight0 = Lanczos2ApproxNoClamp(-1.f - t);
FfxFloat32 fWeight1 = Lanczos2ApproxNoClamp(-0.f - t);
FfxFloat32 fWeight2 = Lanczos2ApproxNoClamp(+1.f - t);
FfxFloat32 fWeight3 = Lanczos2ApproxNoClamp(+2.f - t);
return (fWeight0 * fColor0 + fWeight1 * fColor1 + fWeight2 * fColor2 + fWeight3 * fColor3) / (fWeight0 + fWeight1 + fWeight2 + fWeight3);
}
#if FFX_HALF
FFX_MIN16_F4 Lanczos2Approx(FFX_MIN16_F4 fColor0, FFX_MIN16_F4 fColor1, FFX_MIN16_F4 fColor2, FFX_MIN16_F4 fColor3, FFX_MIN16_F t)
{
FFX_MIN16_F fWeight0 = Lanczos2ApproxNoClamp(FFX_MIN16_F(-1.f) - t);
FFX_MIN16_F fWeight1 = Lanczos2ApproxNoClamp(FFX_MIN16_F(-0.f) - t);
FFX_MIN16_F fWeight2 = Lanczos2ApproxNoClamp(FFX_MIN16_F(+1.f) - t);
FFX_MIN16_F fWeight3 = Lanczos2ApproxNoClamp(FFX_MIN16_F(+2.f) - t);
return (fWeight0 * fColor0 + fWeight1 * fColor1 + fWeight2 * fColor2 + fWeight3 * fColor3) / (fWeight0 + fWeight1 + fWeight2 + fWeight3);
}
#endif //FFX_HALF
FfxFloat32x4 Lanczos2Approx(FetchedBicubicSamples Samples, FfxFloat32x2 fPxFrac)
{
FfxFloat32x4 fColorX0 = Lanczos2Approx(Samples.fColor00, Samples.fColor10, Samples.fColor20, Samples.fColor30, fPxFrac.x);
FfxFloat32x4 fColorX1 = Lanczos2Approx(Samples.fColor01, Samples.fColor11, Samples.fColor21, Samples.fColor31, fPxFrac.x);
FfxFloat32x4 fColorX2 = Lanczos2Approx(Samples.fColor02, Samples.fColor12, Samples.fColor22, Samples.fColor32, fPxFrac.x);
FfxFloat32x4 fColorX3 = Lanczos2Approx(Samples.fColor03, Samples.fColor13, Samples.fColor23, Samples.fColor33, fPxFrac.x);
FfxFloat32x4 fColorXY = Lanczos2Approx(fColorX0, fColorX1, fColorX2, fColorX3, fPxFrac.y);
// Deringing
// TODO: only use 4 by checking jitter
const FfxInt32 iDeringingSampleCount = 4;
const FfxFloat32x4 fDeringingSamples[4] = {
Samples.fColor11,
Samples.fColor21,
Samples.fColor12,
Samples.fColor22,
};
FfxFloat32x4 fDeringingMin = fDeringingSamples[0];
FfxFloat32x4 fDeringingMax = fDeringingSamples[0];
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iDeringingSampleCount; ++iSampleIndex)
{
fDeringingMin = ffxMin(fDeringingMin, fDeringingSamples[iSampleIndex]);
fDeringingMax = ffxMax(fDeringingMax, fDeringingSamples[iSampleIndex]);
}
fColorXY = clamp(fColorXY, fDeringingMin, fDeringingMax);
return fColorXY;
}
#if FFX_HALF
FFX_MIN16_F4 Lanczos2Approx(FetchedBicubicSamplesMin16 Samples, FFX_MIN16_F2 fPxFrac)
{
FFX_MIN16_F4 fColorX0 = Lanczos2Approx(Samples.fColor00, Samples.fColor10, Samples.fColor20, Samples.fColor30, fPxFrac.x);
FFX_MIN16_F4 fColorX1 = Lanczos2Approx(Samples.fColor01, Samples.fColor11, Samples.fColor21, Samples.fColor31, fPxFrac.x);
FFX_MIN16_F4 fColorX2 = Lanczos2Approx(Samples.fColor02, Samples.fColor12, Samples.fColor22, Samples.fColor32, fPxFrac.x);
FFX_MIN16_F4 fColorX3 = Lanczos2Approx(Samples.fColor03, Samples.fColor13, Samples.fColor23, Samples.fColor33, fPxFrac.x);
FFX_MIN16_F4 fColorXY = Lanczos2Approx(fColorX0, fColorX1, fColorX2, fColorX3, fPxFrac.y);
// Deringing
// TODO: only use 4 by checking jitter
const FfxInt32 iDeringingSampleCount = 4;
const FFX_MIN16_F4 fDeringingSamples[4] = {
Samples.fColor11,
Samples.fColor21,
Samples.fColor12,
Samples.fColor22,
};
FFX_MIN16_F4 fDeringingMin = fDeringingSamples[0];
FFX_MIN16_F4 fDeringingMax = fDeringingSamples[0];
FFX_UNROLL
for (FfxInt32 iSampleIndex = 1; iSampleIndex < iDeringingSampleCount; ++iSampleIndex)
{
fDeringingMin = ffxMin(fDeringingMin, fDeringingSamples[iSampleIndex]);
fDeringingMax = ffxMax(fDeringingMax, fDeringingSamples[iSampleIndex]);
}
fColorXY = clamp(fColorXY, fDeringingMin, fDeringingMax);
return fColorXY;
}
#endif
// Clamp by offset direction. Assuming iPxSample is already in range and iPxOffset is compile time constant.
FfxInt32x2 ClampCoord(FfxInt32x2 iPxSample, FfxInt32x2 iPxOffset, FfxInt32x2 iTextureSize)
{
FfxInt32x2 result = iPxSample + iPxOffset;
result.x = ffxMax(1, ffxMin(result.x, iTextureSize.x - 2));
result.y = ffxMax(1, ffxMin(result.y, iTextureSize.y - 2));
return result;
}
#if FFX_HALF
FFX_MIN16_I2 ClampCoord(FFX_MIN16_I2 iPxSample, FFX_MIN16_I2 iPxOffset, FFX_MIN16_I2 iTextureSize)
{
FFX_MIN16_I2 result = iPxSample + iPxOffset;
result.x = ffxMax(FFX_MIN16_I(1), ffxMin(result.x, iTextureSize.x - FFX_MIN16_I(2)));
result.y = ffxMax(FFX_MIN16_I(1), ffxMin(result.y, iTextureSize.y - FFX_MIN16_I(2)));
return result;
}
#endif //FFX_HALF
#define DeclareCustomFetchBicubicSamplesWithType(SampleType, TextureType, AddrType, Name, LoadTexture) \
SampleType Name(AddrType iPxSample, AddrType iTextureSize) \
{ \
SampleType Samples; \
\
Samples.fColor00 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(-1, -1), iTextureSize))); \
Samples.fColor10 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+0, -1), iTextureSize))); \
Samples.fColor20 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+1, -1), iTextureSize))); \
Samples.fColor30 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+2, -1), iTextureSize))); \
\
Samples.fColor01 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(-1, +0), iTextureSize))); \
Samples.fColor11 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+0, +0), iTextureSize))); \
Samples.fColor21 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+1, +0), iTextureSize))); \
Samples.fColor31 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+2, +0), iTextureSize))); \
\
Samples.fColor02 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(-1, +1), iTextureSize))); \
Samples.fColor12 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+0, +1), iTextureSize))); \
Samples.fColor22 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+1, +1), iTextureSize))); \
Samples.fColor32 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+2, +1), iTextureSize))); \
\
Samples.fColor03 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(-1, +2), iTextureSize))); \
Samples.fColor13 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+0, +2), iTextureSize))); \
Samples.fColor23 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+1, +2), iTextureSize))); \
Samples.fColor33 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+2, +2), iTextureSize))); \
\
return Samples; \
}
#define DeclareCustomFetchBicubicSamples(Name, LoadTexture) \
DeclareCustomFetchBicubicSamplesWithType(FetchedBicubicSamples, FfxFloat32x4, FfxInt32x2, Name, LoadTexture)
#define DeclareCustomFetchBicubicSamplesMin16(Name, LoadTexture) \
DeclareCustomFetchBicubicSamplesWithType(FetchedBicubicSamplesMin16, FFX_MIN16_F4, FfxInt32x2, Name, LoadTexture)
#define DeclareCustomFetchBilinearSamplesWithType(SampleType, TextureType,AddrType, Name, LoadTexture) \
SampleType Name(AddrType iPxSample, AddrType iTextureSize) \
{ \
SampleType Samples; \
Samples.fColor00 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+0, +0), iTextureSize))); \
Samples.fColor10 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+1, +0), iTextureSize))); \
Samples.fColor01 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+0, +1), iTextureSize))); \
Samples.fColor11 = TextureType(LoadTexture(ClampCoord(iPxSample, AddrType(+1, +1), iTextureSize))); \
return Samples; \
}
#define DeclareCustomFetchBilinearSamples(Name, LoadTexture) \
DeclareCustomFetchBilinearSamplesWithType(FetchedBilinearSamples, FfxFloat32x4, FfxInt32x2, Name, LoadTexture)
#define DeclareCustomFetchBilinearSamplesMin16(Name, LoadTexture) \
DeclareCustomFetchBilinearSamplesWithType(FetchedBilinearSamplesMin16, FFX_MIN16_F4, FfxInt32x2, Name, LoadTexture)
// BE CAREFUL: there is some precision issues and (3253, 125) leading to (3252.9989778, 125.001102)
// is common, so iPxSample can "jitter"
#define DeclareCustomTextureSample(Name, InterpolateSamples, FetchSamples) \
FfxFloat32x4 Name(FfxFloat32x2 fUvSample, FfxInt32x2 iTextureSize) \
{ \
FfxFloat32x2 fPxSample = (fUvSample * FfxFloat32x2(iTextureSize)) - FfxFloat32x2(0.5f, 0.5f); \
FfxFloat32x2 fPxFrac = ffxFract(fPxSample); \
/* Clamp base coords */ \
fPxSample.x = ffxMax(0.0f, ffxMin(FfxFloat32(iTextureSize.x-1), fPxSample.x)); \
fPxSample.y = ffxMax(0.0f, ffxMin(FfxFloat32(iTextureSize.y-1), fPxSample.y)); \
/* */ \
FfxInt32x2 iPxSample = FfxInt32x2(floor(fPxSample)); \
FfxFloat32x4 fColorXY = FfxFloat32x4(InterpolateSamples(FetchSamples(iPxSample, iTextureSize), fPxFrac)); \
return fColorXY; \
}
#define DeclareCustomTextureSampleMin16(Name, InterpolateSamples, FetchSamples) \
FFX_MIN16_F4 Name(FfxFloat32x2 fUvSample, FfxInt32x2 iTextureSize) \
{ \
FfxFloat32x2 fPxSample = (fUvSample * FfxFloat32x2(iTextureSize)) - FfxFloat32x2(0.5f, 0.5f); \
FFX_MIN16_F2 fPxFrac = FFX_MIN16_F2(ffxFract(fPxSample)); \
/* Clamp base coords */ \
fPxSample.x = ffxMax(0.0f, ffxMin(FfxFloat32(iTextureSize.x), fPxSample.x)); \
fPxSample.y = ffxMax(0.0f, ffxMin(FfxFloat32(iTextureSize.y), fPxSample.y)); \
/* */ \
FfxInt32x2 iPxSample = FfxInt32x2(floor(fPxSample)); \
FFX_MIN16_F4 fColorXY = FFX_MIN16_F4(InterpolateSamples(FetchSamples(iPxSample, iTextureSize), fPxFrac)); \
return fColorXY; \
}
#define FFX_FSR3UPSCALER_CONCAT_ID(x, y) x ## y
#define FFX_FSR3UPSCALER_CONCAT(x, y) FFX_FSR3UPSCALER_CONCAT_ID(x, y)
#define FFX_FSR3UPSCALER_SAMPLER_1D_0 Lanczos2
#define FFX_FSR3UPSCALER_SAMPLER_1D_1 Lanczos2LUT
#define FFX_FSR3UPSCALER_SAMPLER_1D_2 Lanczos2Approx
#define FFX_FSR3UPSCALER_GET_LANCZOS_SAMPLER1D(x) FFX_FSR3UPSCALER_CONCAT(FFX_FSR3UPSCALER_SAMPLER_1D_, x)
#endif //!defined( FFX_FSR3UPSCALER_SAMPLE_H )
@@ -0,0 +1,68 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
FFX_STATIC const FfxInt32 s_MipLevelsToUse = 3;
struct ShadingChangeLumaInfo
{
FfxFloat32 fSamples[s_MipLevelsToUse];
};
ShadingChangeLumaInfo ComputeShadingChangeLuma(FfxInt32x2 iPxPos, FfxFloat32x2 fUv, const FfxInt32x2 iCurrentSize)
{
ShadingChangeLumaInfo info;
const FfxFloat32x2 fMipUv = ClampUv(fUv, ShadingChangeRenderSize(), GetSPDMipDimensions(0));
FFX_UNROLL
for (FfxInt32 iMipLevel = iShadingChangeMipStart; iMipLevel < s_MipLevelsToUse; iMipLevel++) {
const FfxFloat32x2 fSample = SampleSPDMipLevel(fMipUv, iMipLevel);
info.fSamples[iMipLevel] = abs(fSample.x * fSample.y);
}
return info;
}
void ShadingChange(FfxInt32x2 iPxPos)
{
if (IsOnScreen(FfxInt32x2(iPxPos), ShadingChangeRenderSize())) {
const FfxFloat32x2 fUv = (iPxPos + 0.5f) / ShadingChangeRenderSize();
const FfxFloat32x2 fUvJittered = fUv + Jitter() / RenderSize();
const ShadingChangeLumaInfo info = ComputeShadingChangeLuma(iPxPos, fUvJittered, ShadingChangeRenderSize());
const FfxFloat32 fScale = 1.0f + iShadingChangeMipStart / s_MipLevelsToUse;
FfxFloat32 fShadingChange = 0.0f;
FFX_UNROLL
for (int iMipLevel = iShadingChangeMipStart; iMipLevel < s_MipLevelsToUse; iMipLevel++)
{
if (info.fSamples[iMipLevel] > 0) {
fShadingChange = ffxMax(fShadingChange, info.fSamples[iMipLevel]) * fScale;
}
}
StoreShadingChange(iPxPos, ffxSaturate(fShadingChange));
}
}
@@ -0,0 +1,297 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
FFX_GROUPSHARED FfxUInt32 spdCounter;
void SpdIncreaseAtomicCounter(FfxUInt32 slice)
{
SPD_IncreaseAtomicCounter(spdCounter);
}
FfxUInt32 SpdGetAtomicCounter()
{
return spdCounter;
}
void SpdResetAtomicCounter(FfxUInt32 slice)
{
SPD_ResetAtomicCounter();
}
#ifndef SPD_PACKED_ONLY
FFX_GROUPSHARED FfxFloat32 spdIntermediateR[16][16];
FFX_GROUPSHARED FfxFloat32 spdIntermediateG[16][16];
FFX_GROUPSHARED FfxFloat32 spdIntermediateB[16][16];
FFX_GROUPSHARED FfxFloat32 spdIntermediateA[16][16];
FFX_STATIC const FfxInt32 DIFFERENCE = 0;
FFX_STATIC const FfxInt32 SIGN_SUM = 1;
FFX_STATIC const FfxInt32 MIP0_INDICATOR = 2;
FfxFloat32x2 Sort2(FfxFloat32x2 v)
{
return FfxFloat32x2(ffxMin(v.x, v.y), ffxMax(v.x, v.y));
}
struct SampleSet
{
FfxFloat32 fSamples[SHADING_CHANGE_SET_SIZE];
};
#define CompareSwap(i, j) \
{ \
FfxFloat32 fTmp = ffxMin(fSet.fSamples[i], fSet.fSamples[j]);\
fSet.fSamples[j] = ffxMax(fSet.fSamples[i], fSet.fSamples[j]);\
fSet.fSamples[i] = fTmp;\
}
#if SHADING_CHANGE_SET_SIZE == 5
FFX_STATIC const FfxInt32x2 iSampleOffsets[5] = {FfxInt32x2(+0, +0), FfxInt32x2(-1, +0), FfxInt32x2(+1, +0), FfxInt32x2(+0, -1), FfxInt32x2(+0, +1)};
void SortSet(FFX_PARAMETER_INOUT SampleSet fSet)
{
CompareSwap(0, 3);
CompareSwap(1, 4);
CompareSwap(0, 2);
CompareSwap(1, 3);
CompareSwap(0, 1);
CompareSwap(2, 4);
CompareSwap(1, 2);
CompareSwap(3, 4);
CompareSwap(2, 3);
}
#endif
FfxFloat32 ComputeMinimumDifference(FfxInt32x2 iPxPos, SampleSet fSet0, SampleSet fSet1)
{
FfxFloat32 fMinDiff = FSR3UPSCALER_FP16_MAX - 1;
FfxInt32 a = 0;
FfxInt32 b = 0;
SortSet(fSet0);
SortSet(fSet1);
const FfxFloat32 fMax = ffxMin(fSet0.fSamples[SHADING_CHANGE_SET_SIZE-1], fSet1.fSamples[SHADING_CHANGE_SET_SIZE-1]);
if (fMax > FSR3UPSCALER_FP32_MIN) {
FFX_UNROLL
for (FfxInt32 i = 0; i < SHADING_CHANGE_SET_SIZE && (fMinDiff < FSR3UPSCALER_FP16_MAX); i++) {
FfxFloat32 fDiff = fSet0.fSamples[a] - fSet1.fSamples[b];
if (abs(fDiff) > FSR3UPSCALER_FP16_MIN) {
fDiff = sign(fDiff) * (1.0f - MinDividedByMax(fSet0.fSamples[a], fSet1.fSamples[b]));
fMinDiff = (abs(fDiff) < abs(fMinDiff)) ? fDiff : fMinDiff;
a += FfxInt32(fSet0.fSamples[a] < fSet1.fSamples[b]);
b += FfxInt32(fSet0.fSamples[a] >= fSet1.fSamples[b]);
}
else
{
fMinDiff = FSR3UPSCALER_FP16_MAX;
}
}
}
return fMinDiff * FfxFloat32(fMinDiff < (FSR3UPSCALER_FP16_MAX - 1));
}
SampleSet GetCurrentLumaBilinearSamples(FfxFloat32x2 fUv)
{
const FfxFloat32x2 fUvJittered = fUv + Jitter() / RenderSize();
const FfxInt32x2 iBasePos = FfxInt32x2(floor(fUvJittered * RenderSize()));
SampleSet fSet;
for (FfxInt32 iSampleIndex = 0; iSampleIndex < SHADING_CHANGE_SET_SIZE; iSampleIndex++) {
const FfxInt32x2 iSamplePos = ClampLoad(iBasePos, iSampleOffsets[iSampleIndex], RenderSize());
fSet.fSamples[iSampleIndex] = LoadCurrentLuma(iSamplePos) * Exposure();
fSet.fSamples[iSampleIndex] = ffxPow(fSet.fSamples[iSampleIndex], fShadingChangeSamplePow);
fSet.fSamples[iSampleIndex] = ffxMax(fSet.fSamples[iSampleIndex], FSR3UPSCALER_EPSILON);
}
return fSet;
}
struct PreviousLumaBilinearSamplesData
{
SampleSet fSet;
FfxBoolean bIsExistingSample;
};
PreviousLumaBilinearSamplesData GetPreviousLumaBilinearSamples(FfxFloat32x2 fUv, FfxFloat32x2 fMotionVector)
{
PreviousLumaBilinearSamplesData data;
const FfxFloat32x2 fUvJittered = fUv + PreviousFrameJitter() / PreviousFrameRenderSize();
const FfxFloat32x2 fReprojectedUv = fUvJittered + fMotionVector;
data.bIsExistingSample = IsUvInside(fReprojectedUv);
if (data.bIsExistingSample) {
const FfxInt32x2 iBasePos = FfxInt32x2(floor(fReprojectedUv * PreviousFrameRenderSize()));
for (FfxInt32 iSampleIndex = 0; iSampleIndex < SHADING_CHANGE_SET_SIZE; iSampleIndex++) {
const FfxInt32x2 iSamplePos = ClampLoad(iBasePos, iSampleOffsets[iSampleIndex], PreviousFrameRenderSize());
data.fSet.fSamples[iSampleIndex] = LoadPreviousLuma(iSamplePos) * DeltaPreExposure() * Exposure();
data.fSet.fSamples[iSampleIndex] = ffxPow(data.fSet.fSamples[iSampleIndex], fShadingChangeSamplePow);
data.fSet.fSamples[iSampleIndex] = ffxMax(data.fSet.fSamples[iSampleIndex], FSR3UPSCALER_EPSILON);
}
}
return data;
}
FfxFloat32 ComputeDiff(FfxInt32x2 iPxPos, FfxFloat32x2 fUv, FfxFloat32x2 fMotionVector)
{
FfxFloat32 fMinDiff = 0.0f;
const SampleSet fCurrentSamples = GetCurrentLumaBilinearSamples(fUv);
const PreviousLumaBilinearSamplesData previousData = GetPreviousLumaBilinearSamples(fUv, fMotionVector);
if (previousData.bIsExistingSample) {
fMinDiff = ComputeMinimumDifference(iPxPos, fCurrentSamples, previousData.fSet);
}
return fMinDiff;
}
FfxFloat32x4 SpdLoadSourceImage(FfxFloat32x2 iPxPos, FfxUInt32 slice)
{
const FfxInt32x2 iPxSamplePos = ClampLoad(FfxInt32x2(iPxPos), FfxInt32x2(0, 0), FfxInt32x2(RenderSize()));
const FfxFloat32x2 fDilatedMotionVector = LoadDilatedMotionVector(iPxSamplePos);
const FfxFloat32x2 fUv = (iPxSamplePos + 0.5f) / RenderSize();
const FfxFloat32 fScaledAndSignedLumaDiff = ComputeDiff(iPxSamplePos, fUv, fDilatedMotionVector);
FfxFloat32x4 fOutput = FfxFloat32x4(0.0f, 0.0f, 0.0f, 0.0f);
fOutput[DIFFERENCE] = fScaledAndSignedLumaDiff;
fOutput[SIGN_SUM] = (fScaledAndSignedLumaDiff != 0.0f) ? sign(fScaledAndSignedLumaDiff) : 0.0f;
fOutput[MIP0_INDICATOR] = 1.0f;
return fOutput;
}
FfxFloat32x4 SpdLoad(FfxInt32x2 tex, FfxUInt32 slice)
{
return FfxFloat32x4(RWLoadPyramid(tex, 5), 0, 0);
}
FfxFloat32x4 SpdReduce4(FfxFloat32x4 v0, FfxFloat32x4 v1, FfxFloat32x4 v2, FfxFloat32x4 v3)
{
return (v0 + v1 + v2 + v3) * 0.25f;
}
void SpdStore(FfxInt32x2 pix, FfxFloat32x4 outValue, FfxUInt32 index, FfxUInt32 slice)
{
if (index >= iShadingChangeMipStart)
{
StorePyramid(pix, outValue.xy, index);
}
}
FfxFloat32x4 SpdLoadIntermediate(FfxUInt32 x, FfxUInt32 y)
{
return FfxFloat32x4(
spdIntermediateR[x][y],
spdIntermediateG[x][y],
spdIntermediateB[x][y],
spdIntermediateA[x][y]);
}
void SpdStoreIntermediate(FfxUInt32 x, FfxUInt32 y, FfxFloat32x4 value)
{
spdIntermediateR[x][y] = value.x;
spdIntermediateG[x][y] = value.y;
spdIntermediateB[x][y] = value.z;
spdIntermediateA[x][y] = value.w;
}
#endif
// define fetch and store functions Packed
#if FFX_HALF
FFX_GROUPSHARED FfxFloat16x2 spdIntermediateRG[16][16];
FFX_GROUPSHARED FfxFloat16x2 spdIntermediateBA[16][16];
FfxFloat16x4 SpdLoadSourceImageH(FfxFloat32x2 tex, FfxUInt32 slice)
{
return FfxFloat16x4(0, 0, 0, 0);
}
FfxFloat16x4 SpdLoadH(FfxInt32x2 p, FfxUInt32 slice)
{
return FfxFloat16x4(0, 0, 0, 0);
}
void SpdStoreH(FfxInt32x2 p, FfxFloat16x4 value, FfxUInt32 mip, FfxUInt32 slice)
{
}
FfxFloat16x4 SpdLoadIntermediateH(FfxUInt32 x, FfxUInt32 y)
{
return FfxFloat16x4(
spdIntermediateRG[x][y].x,
spdIntermediateRG[x][y].y,
spdIntermediateBA[x][y].x,
spdIntermediateBA[x][y].y);
}
void SpdStoreIntermediateH(FfxUInt32 x, FfxUInt32 y, FfxFloat16x4 value)
{
spdIntermediateRG[x][y] = value.xy;
spdIntermediateBA[x][y] = value.zw;
}
FfxFloat16x4 SpdReduce4H(FfxFloat16x4 v0, FfxFloat16x4 v1, FfxFloat16x4 v2, FfxFloat16x4 v3)
{
return (v0 + v1 + v2 + v3) * FfxFloat16(0.25);
}
#endif
#include "spd/ffx_spd.h"
void ComputeShadingChangePyramid(FfxUInt32x3 WorkGroupId, FfxUInt32 LocalThreadIndex)
{
#if FFX_HALF
SpdDownsampleH(
FfxUInt32x2(WorkGroupId.xy),
FfxUInt32(LocalThreadIndex),
FfxUInt32(MipCount()),
FfxUInt32(NumWorkGroups()),
FfxUInt32(WorkGroupId.z),
FfxUInt32x2(WorkGroupOffset()));
#else
SpdDownsample(
FfxUInt32x2(WorkGroupId.xy),
FfxUInt32(LocalThreadIndex),
FfxUInt32(MipCount()),
FfxUInt32(NumWorkGroups()),
FfxUInt32(WorkGroupId.z),
FfxUInt32x2(WorkGroupOffset()));
#endif
}
@@ -0,0 +1,644 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
void Deringing(RectificationBox clippingBox, FFX_PARAMETER_INOUT FfxFloat32x3 fColor)
{
fColor = clamp(fColor, clippingBox.aabbMin, clippingBox.aabbMax);
}
#ifndef FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE
#define FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE 2 // Approximate
#endif
FfxFloat32 GetUpsampleLanczosWeight(FfxFloat32x2 fSrcSampleOffset, FfxFloat32 fKernelWeight)
{
FfxFloat32x2 fSrcSampleOffsetBiased = fSrcSampleOffset * fKernelWeight.xx;
#if FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 0 // LANCZOS_TYPE_REFERENCE
FfxFloat32 fSampleWeight = Lanczos2(length(fSrcSampleOffsetBiased));
#elif FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 1 // LANCZOS_TYPE_LUT
FfxFloat32 fSampleWeight = Lanczos2_UseLUT(length(fSrcSampleOffsetBiased));
#elif FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 2 // LANCZOS_TYPE_APPROXIMATE
FfxFloat32 fSampleWeight = Lanczos2ApproxSq(dot(fSrcSampleOffsetBiased, fSrcSampleOffsetBiased));
#else
#error "Invalid Lanczos type"
#endif
return fSampleWeight;
}
#if FFX_HALF
FFX_MIN16_F GetUpsampleLanczosWeight(FFX_MIN16_F2 fSrcSampleOffset, FFX_MIN16_F fKernelWeight)
{
FFX_MIN16_F2 fSrcSampleOffsetBiased = fSrcSampleOffset * fKernelWeight.xx;
#if FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 0 // LANCZOS_TYPE_REFERENCE
FFX_MIN16_F fSampleWeight = Lanczos2(length(fSrcSampleOffsetBiased));
#elif FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 1 // LANCZOS_TYPE_LUT
FFX_MIN16_F fSampleWeight = Lanczos2_UseLUT(length(fSrcSampleOffsetBiased));
#elif FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 2 // LANCZOS_TYPE_APPROXIMATE
FFX_MIN16_F fSampleWeight = Lanczos2ApproxSq(dot(fSrcSampleOffsetBiased, fSrcSampleOffsetBiased));
// To Test: Save reciproqual sqrt compute
// FfxFloat32 fSampleWeight = Lanczos2Sq_UseLUT(dot(fSrcSampleOffsetBiased, fSrcSampleOffsetBiased));
#else
#error "Invalid Lanczos type"
#endif
return fSampleWeight;
}
#endif
FfxFloat32 ComputeMaxKernelWeight(const AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data) {
const FfxFloat32 fKernelSizeBias = 1.0f + (1.0f / FfxFloat32x2(DownscaleFactor()) - 1.0f).x;
return ffxMin(FfxFloat32(1.99f), fKernelSizeBias);
}
FfxFloat32x3 LoadPreparedColor(FfxInt32x2 iSamplePos)
{
const FfxFloat32x3 fRgb = ffxMax(FfxFloat32x3(0, 0, 0), LoadInputColor(iSamplePos)) * Exposure();
const FfxFloat32x3 fPreparedYCoCg = RGBToYCoCg(fRgb);
return fPreparedYCoCg;
}
#if FFX_HALF && (FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 2) && defined(__XBOX_SCARLETT) && defined(__XBATG_EXTRA_16_BIT_OPTIMISATION) && (__XBATG_EXTRA_16_BIT_OPTIMISATION == 1)
#define FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS 1
#else
#define FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS 0
#endif
#if FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS
void LoadPreparedColorPairedRgb(FFX_PARAMETER_OUT FFX_MIN16_F2 r,
FFX_PARAMETER_OUT FFX_MIN16_F2 g,
FFX_PARAMETER_OUT FFX_MIN16_F2 b,
FfxInt32x2 iSamplePos0,
FfxInt32x2 iSamplePos1)
{
const FFX_MIN16_F3 sample0 = FFX_MIN16_F3(LoadInputColor(iSamplePos0));
const FFX_MIN16_F3 sample1 = FFX_MIN16_F3(LoadInputColor(iSamplePos1));
r = ffxMax(FFX_MIN16_F2(0, 0), FFX_MIN16_F2(sample0.r, sample1.r));
g = ffxMax(FFX_MIN16_F2(0, 0), FFX_MIN16_F2(sample0.g, sample1.g));
b = ffxMax(FFX_MIN16_F2(0, 0), FFX_MIN16_F2(sample0.b, sample1.b));
r = FFX_MIN16_F2(r * Exposure());
g = FFX_MIN16_F2(g * Exposure());
b = FFX_MIN16_F2(b * Exposure());
}
void TonemapPaired(FFX_PARAMETER_INOUT FFX_MIN16_F2 r, FFX_PARAMETER_INOUT FFX_MIN16_F2 g, FFX_PARAMETER_INOUT FFX_MIN16_F2 b)
{
FFX_MIN16_F2 denomF16 = ffxMax(ffxMax(ffxMax(0.0, r), g), b) + FFX_MIN16_F2(1.0, 1.0);
// NOTE: expect 2 x v_cvt_f32_f16
FfxFloat32x2 denomF32 = FfxFloat32x2(denomF16);
// NOTE: expect 2 x v_rcp_f32
FfxFloat32x2 normF32 = FfxFloat32x2(1.0, 1.0) / denomF32;
// NOTE: expect 2 x v_cvt_f16_f32
FFX_MIN16_F2 normF16 = FFX_MIN16_F2(normF32);
r *= normF16;
g *= normF16;
b *= normF16;
}
void RGBToYCoCgPaired(FFX_PARAMETER_INOUT FFX_MIN16_F2 r, FFX_PARAMETER_INOUT FFX_MIN16_F2 g, FFX_PARAMETER_INOUT FFX_MIN16_F2 b)
{
/**
* NOTE: given the following conversion
*
* fYCoCg = FfxFloat32x3(
* 0.25f * fRgb.r + 0.5f * fRgb.g + 0.25f * fRgb.b,
* 0.5f * fRgb.r - 0.5f * fRgb.b,
* -0.25f * fRgb.r + 0.5f * fRgb.g - 0.25f * fRgb.b);
*
* it's possible to notice that we can compute:
* RplusBdiv4 = 0.25 * (R + B)
*
* so everything else is computed in 3 instructions
* Y = G * 0.5 + RplusBdiv4
* Co = 2 * RplusBdiv4 - G
* Cg = G * 0.5 - RplusBdiv4
*/
// NOTE: expect v_pk_add_f32 + v_pk_mul_f32
FFX_MIN16_F2 RplusBdiv4 = (r + b) * 0.25;
FFX_MIN16_F2 G = g;
FFX_MIN16_F2 B = b;
// NOTE: expect 3x v_pk_fma_f32
r = G * 0.5 + RplusBdiv4;
g = RplusBdiv4 * 2.0 - B;
b = G * 0.5 - RplusBdiv4;
}
FFX_MIN16_F2 Compute3x3SamplesMinMaxPaired(FFX_PARAMETER_IN FFX_MIN16_F2 sampleCenter,
FFX_PARAMETER_IN FFX_MIN16_F2 sample0,
FFX_PARAMETER_IN FFX_MIN16_F2 sample1,
FFX_PARAMETER_IN FFX_MIN16_F2 sample2,
FFX_PARAMETER_IN FFX_MIN16_F2 sample3)
{
FFX_MIN16_F2 twoMinValues = ffxMin(ffxMin(sample0, sample1), ffxMin(sample2, sample3));
FFX_MIN16_F2 twoMaxValues = ffxMax(ffxMax(sample0, sample1), ffxMax(sample2, sample3));
return FFX_MIN16_F2(
ffxMin3Half(twoMinValues.x, twoMinValues.y, sampleCenter.x),
ffxMax3Half(twoMaxValues.x, twoMaxValues.y, sampleCenter.x)
);
}
FFX_MIN16_F2 Bool2ToFloat16x2(bool x, bool y)
{
uint lo = x ? 0x00003c00 : 0x00000000;
uint hi = y ? 0x3c000000 : 0x00000000;
return FFX_MIN16_F2(__XB_AsHalf(lo).x, __XB_AsHalf(hi).y);
}
struct PairedRectificationBoxAndAccumulatedColorAndWeight
{
FFX_MIN16_F2 boxCenterR;
FFX_MIN16_F2 boxCenterG;
FFX_MIN16_F2 boxCenterB;
FFX_MIN16_F2 boxVecR;
FFX_MIN16_F2 boxVecG;
FFX_MIN16_F2 boxVecB;
FFX_MIN16_F2 fBoxCenterWeight;
FFX_MIN16_F2 fColorR;
FFX_MIN16_F2 fColorG;
FFX_MIN16_F2 fColorB;
FFX_MIN16_F2 fWeight;
FFX_MIN16_F fKernelBiasSq;
FFX_MIN16_F fRectificationCurveBias;
void setKernelBiasAndRectificationCurveBias(FfxFloat32 kernelBias, FfxFloat32 rectificationCurveBias)
{
fKernelBiasSq = FFX_MIN16_F(kernelBias * kernelBias);
fRectificationCurveBias = FFX_MIN16_F(rectificationCurveBias);
}
void initUpscaledColor(FFX_MIN16_F fSrcSampleOffsetSq, FFX_MIN16_F fOnScreenWeight, FFX_MIN16_F2 sampleR, FFX_MIN16_F2 sampleG, FFX_MIN16_F2 sampleB)
{
#if FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 2 // LANCZOS_TYPE_APPROXIMATE
const FFX_MIN16_F2 LanczosUpsampleWeight = FFX_MIN16_F2(
PairedLanczos2ApproxSq(fSrcSampleOffsetSq * fKernelBiasSq).x,
0.0
);
#else
#error "Only LANCZOS_TYPE_APPROXIMATE is supported in paired version so far"
#endif
const FFX_MIN16_F2 fSampleWeight = fOnScreenWeight * LanczosUpsampleWeight;
fColorR = sampleR * fSampleWeight;
fColorG = sampleG * fSampleWeight;
fColorB = sampleB * fSampleWeight;
fWeight = fSampleWeight;
}
void initBox(FFX_MIN16_F fSrcSampleOffsetSq, FFX_MIN16_F fOnScreenWeight, FFX_MIN16_F2 sampleR, FFX_MIN16_F2 sampleG, FFX_MIN16_F2 sampleB)
{
const FFX_MIN16_F2 fBoxSampleWeight = FFX_MIN16_F2(
exp(fRectificationCurveBias * fSrcSampleOffsetSq) * fOnScreenWeight,
0.0
);
FFX_MIN16_F2 weightedSampleR = sampleR * fBoxSampleWeight;
FFX_MIN16_F2 weightedSampleG = sampleG * fBoxSampleWeight;
FFX_MIN16_F2 weightedSampleB = sampleB * fBoxSampleWeight;
boxCenterR = weightedSampleR;
boxCenterG = weightedSampleG;
boxCenterB = weightedSampleB;
boxVecR = sampleR * weightedSampleR;
boxVecG = sampleG * weightedSampleG;
boxVecB = sampleB * weightedSampleB;
fBoxCenterWeight = fBoxSampleWeight;
}
void addUpscaledColorSample(FFX_MIN16_F2 fSrcSampleOffsetSq, FFX_MIN16_F2 fOnScreenWeight, FFX_MIN16_F2 sampleR, FFX_MIN16_F2 sampleG, FFX_MIN16_F2 sampleB)
{
#if FFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE == 2 // LANCZOS_TYPE_APPROXIMATE
const FFX_MIN16_F2 LanczosUpsampleWeight = PairedLanczos2ApproxSq(fSrcSampleOffsetSq * fKernelBiasSq);
#else
#error "Only LANCZOS_TYPE_APPROXIMATE is supported in paired version so far"
#endif
const FFX_MIN16_F2 fSampleWeight = fOnScreenWeight * LanczosUpsampleWeight;
fColorR += sampleR * fSampleWeight;
fColorG += sampleG * fSampleWeight;
fColorB += sampleB * fSampleWeight;
fWeight += fSampleWeight;
}
void addBoxSample(FFX_MIN16_F2 fSrcSampleOffsetSq, FFX_MIN16_F2 fOnScreenWeight, FFX_MIN16_F2 sampleR, FFX_MIN16_F2 sampleG, FFX_MIN16_F2 sampleB)
{
// NOTE: ideally expect here 2x v_fma_mix + 2x v_exp_f32 + 2x v_fma_mix
const FFX_MIN16_F2 fBoxSampleWeight = exp(fRectificationCurveBias * fSrcSampleOffsetSq) * fOnScreenWeight;
FFX_MIN16_F2 weightedSampleR = sampleR * fBoxSampleWeight;
FFX_MIN16_F2 weightedSampleG = sampleG * fBoxSampleWeight;
FFX_MIN16_F2 weightedSampleB = sampleB * fBoxSampleWeight;
boxCenterR += weightedSampleR;
boxCenterG += weightedSampleG;
boxCenterB += weightedSampleB;
boxVecR += sampleR * weightedSampleR;
boxVecG += sampleG * weightedSampleG;
boxVecB += sampleB * weightedSampleB;
fBoxCenterWeight += fBoxSampleWeight;
}
void finalizeUpscaledColor(FFX_PARAMETER_OUT FfxFloat32x4 upscaledColorAndWeight)
{
upscaledColorAndWeight.r = fColorR.x + fColorR.y;
upscaledColorAndWeight.g = fColorG.x + fColorG.y;
upscaledColorAndWeight.b = fColorB.x + fColorB.y;
upscaledColorAndWeight.a = fWeight.x + fWeight.y;
}
void finalizeBox(FFX_PARAMETER_OUT FfxFloat32x2 boxCenterAndVecR,
FFX_PARAMETER_OUT FfxFloat32x2 boxCenterAndVecG,
FFX_PARAMETER_OUT FfxFloat32x2 boxCenterAndVecB,
FFX_PARAMETER_OUT FfxFloat32 boxCenterWeight)
{
boxCenterAndVecR = FfxFloat32x2(boxCenterR.x + boxCenterR.y, boxVecR.x + boxVecR.y);
boxCenterAndVecG = FfxFloat32x2(boxCenterG.x + boxCenterG.y, boxVecG.x + boxVecG.y);
boxCenterAndVecB = FfxFloat32x2(boxCenterB.x + boxCenterB.y, boxVecB.x + boxVecB.y);
boxCenterWeight = fBoxCenterWeight.x + fBoxCenterWeight.y;
}
};
#endif // #if FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS
void ComputeUpsampledColorAndWeight(const AccumulationPassCommonParams params, FFX_PARAMETER_INOUT AccumulationPassData data)
{
// We compute a sliced lanczos filter with 2 lobes (other slices are accumulated temporaly)
const FfxFloat32x2 fDstOutputPos = FfxFloat32x2(params.iPxHrPos) + FFX_BROADCAST_FLOAT32X2(0.5f);
const FfxFloat32x2 fSrcOutputPos = fDstOutputPos * DownscaleFactor();
const FfxInt32x2 iSrcInputPos = FfxInt32x2(floor(fSrcOutputPos));
const FfxFloat32x2 fSrcUnjitteredPos = (FfxFloat32x2(iSrcInputPos) + FfxFloat32x2(0.5f, 0.5f)) - Jitter(); // This is the un-jittered position of the sample at offset 0,0
const FfxFloat32x2 fBaseSampleOffset = FfxFloat32x2(fSrcUnjitteredPos - fSrcOutputPos);
FfxInt32x2 offsetTL;
offsetTL.x = (fSrcUnjitteredPos.x > fSrcOutputPos.x) ? FfxInt32(-2) : FfxInt32(-1);
offsetTL.y = (fSrcUnjitteredPos.y > fSrcOutputPos.y) ? FfxInt32(-2) : FfxInt32(-1);
//Load samples
// If fSrcUnjitteredPos.y > fSrcOutputPos.y, indicates offsetTL.y = -2, sample offset Y will be [-2, 1], clipbox will be rows [1, 3].
// Flip row# for sampling offset in this case, so first 0~2 rows in the sampled array can always be used for computing the clipbox.
// This reduces branch or cmove on sampled colors, but moving this overhead to sample position / weight calculation time which apply to less values.
const FfxBoolean bFlipRow = fSrcUnjitteredPos.y > fSrcOutputPos.y;
const FfxBoolean bFlipCol = fSrcUnjitteredPos.x > fSrcOutputPos.x;
const FfxFloat32x2 fOffsetTL = FfxFloat32x2(offsetTL);
const FfxBoolean bIsInitialSample = (params.fAccumulation == 0.0f);
#if FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS
// Unroll the loop to load samples on Scarlett to help the shader compiler
const FFX_MIN16_F2 fSampleOffsetX02 = __XB_AsHalf(bFlipCol ? __XB_AsUInt(FFX_MIN16_F2( 1, -1)) : __XB_AsUInt(FFX_MIN16_F2(-1, 1)));
const FFX_MIN16_F2 fSampleOffsetY02 = __XB_AsHalf(bFlipRow ? __XB_AsUInt(FFX_MIN16_F2( 1, -1)) : __XB_AsUInt(FFX_MIN16_F2(-1, 1)));
typedef FfxInt32 FfxTexCoordI;
typedef FfxInt32x2 FfxTexCoordI2;
const FfxTexCoordI2 iSrcSamplePosX01 = FfxTexCoordI2(iSrcInputPos.xx) + (bFlipCol ? FfxTexCoordI2( 1, 0) : FfxTexCoordI2(-1, 0));
const FfxTexCoordI2 iSrcSamplePosX23 = FfxTexCoordI2(iSrcInputPos.xx) + (bFlipCol ? FfxTexCoordI2(-1, -2) : FfxTexCoordI2( 1, 2));
const FfxTexCoordI2 iSrcSamplePosY01 = FfxTexCoordI2(iSrcInputPos.yy) + (bFlipRow ? FfxTexCoordI2( 1, 0) : FfxTexCoordI2(-1, 0));
const FfxTexCoordI2 iSrcSamplePosY23 = FfxTexCoordI2(iSrcInputPos.yy) + (bFlipRow ? FfxTexCoordI2(-1, -2) : FfxTexCoordI2( 1, 2));
const FfxTexCoordI2 renderSizeLastTexelCoord = FfxTexCoordI2(RenderSize()) - FfxTexCoordI2(1, 1);
const FfxTexCoordI2 iSrcSamplePosX01Clamped = FfxTexCoordI2(
__XB_Med3_I32(iSrcSamplePosX01.x, 0, renderSizeLastTexelCoord.x),
__XB_Med3_I32(iSrcSamplePosX01.y, 0, renderSizeLastTexelCoord.x)
);
const FfxTexCoordI2 iSrcSamplePosX23Clamped = FfxTexCoordI2(
__XB_Med3_I32(iSrcSamplePosX23.x, 0, renderSizeLastTexelCoord.x),
__XB_Med3_I32(iSrcSamplePosX23.y, 0, renderSizeLastTexelCoord.x)
);
const FfxTexCoordI2 iSrcSamplePosY01Clamped = FfxTexCoordI2(
__XB_Med3_I32(iSrcSamplePosY01.x, 0, renderSizeLastTexelCoord.y),
__XB_Med3_I32(iSrcSamplePosY01.y, 0, renderSizeLastTexelCoord.y)
);
const FfxTexCoordI2 iSrcSamplePosY23Clamped = FfxTexCoordI2(
__XB_Med3_I32(iSrcSamplePosY23.x, 0, renderSizeLastTexelCoord.y),
__XB_Med3_I32(iSrcSamplePosY23.y, 0, renderSizeLastTexelCoord.y)
);
FFX_MIN16_F2 TopCornerR, BotCornerR, HorzR, VertR, CenterR;
FFX_MIN16_F2 TopCornerG, BotCornerG, HorzG, VertG, CenterG;
FFX_MIN16_F2 TopCornerB, BotCornerB, HorzB, VertB, CenterB;
LoadPreparedColorPairedRgb(TopCornerR, TopCornerG, TopCornerB,
FfxTexCoordI2(iSrcSamplePosX01Clamped.x, iSrcSamplePosY01Clamped.x),
FfxTexCoordI2(iSrcSamplePosX23Clamped.x, iSrcSamplePosY01Clamped.x)
);
LoadPreparedColorPairedRgb(BotCornerR, BotCornerG, BotCornerB,
FfxTexCoordI2(iSrcSamplePosX01Clamped.x, iSrcSamplePosY23Clamped.x),
FfxTexCoordI2(iSrcSamplePosX23Clamped.x, iSrcSamplePosY23Clamped.x)
);
LoadPreparedColorPairedRgb(HorzR, HorzG, HorzB,
FfxTexCoordI2(iSrcSamplePosX01Clamped.x, iSrcSamplePosY01Clamped.y),
FfxTexCoordI2(iSrcSamplePosX23Clamped.x, iSrcSamplePosY01Clamped.y)
);
LoadPreparedColorPairedRgb(VertR, VertG, VertB,
FfxTexCoordI2(iSrcSamplePosX01Clamped.y, iSrcSamplePosY01Clamped.x),
FfxTexCoordI2(iSrcSamplePosX01Clamped.y, iSrcSamplePosY23Clamped.x)
);
// NOTE: duplicated data
LoadPreparedColorPairedRgb(CenterR, CenterG, CenterB,
FfxTexCoordI2(iSrcSamplePosX01Clamped.y, iSrcSamplePosY01Clamped.y),
FfxTexCoordI2(iSrcSamplePosX01Clamped.y, iSrcSamplePosY01Clamped.y)
);
#if FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT
if (bIsInitialSample)
{
TonemapPaired(TopCornerR, TopCornerG, TopCornerB);
TonemapPaired(BotCornerR, BotCornerG, BotCornerB);
TonemapPaired(HorzR, HorzG, HorzB);
TonemapPaired(VertR, VertG, VertB);
TonemapPaired(CenterR, CenterG, CenterB);
}
#endif
RGBToYCoCgPaired(TopCornerR, TopCornerG, TopCornerB);
RGBToYCoCgPaired(BotCornerR, BotCornerG, BotCornerB);
RGBToYCoCgPaired(HorzR, HorzG, HorzB);
RGBToYCoCgPaired(VertR, VertG, VertB);
RGBToYCoCgPaired(CenterR, CenterG, CenterB);
#else
FfxFloat32x3 fSamples[9];
FfxInt32 iSampleIndex = 0;
FFX_UNROLL
for (FfxInt32 row = 0; row < 3; row++) {
FFX_UNROLL
for (FfxInt32 col = 0; col < 3; col++) {
const FfxInt32x2 iSampleColRow = FfxInt32x2(bFlipCol ? (3 - col) : col, bFlipRow ? (3 - row) : row);
const FfxInt32x2 iSrcSamplePos = FfxInt32x2(iSrcInputPos) + offsetTL + iSampleColRow;
const FfxInt32x2 iSampleCoord = ClampLoad(iSrcSamplePos, FfxInt32x2(0, 0), FfxInt32x2(RenderSize()));
fSamples[iSampleIndex] = LoadPreparedColor(iSampleCoord);
++iSampleIndex;
}
}
#if FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT
if (bIsInitialSample)
{
for (iSampleIndex = 0; iSampleIndex < 9; ++iSampleIndex)
{
//YCoCg -> RGB -> Tonemap -> YCoCg (Use RGB tonemapper to avoid color desaturation)
fSamples[iSampleIndex] = RGBToYCoCg(Tonemap(YCoCgToRGB(fSamples[iSampleIndex])));
}
}
#endif
#endif // #if FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS
// Identify how much of each upsampled color to be used for this frame
const FfxFloat32 fKernelBiasMax = ComputeMaxKernelWeight(params, data);
const FfxFloat32 fKernelBiasMin = ffxMax(1.0f, ((1.0f + fKernelBiasMax) * 0.3f));
const FfxFloat32 fKernelBiasWeight =
ffxMin(1.0f - params.fDisocclusion * 0.5f,
ffxMin(1.0f - params.fShadingChange,
ffxSaturate(data.fHistoryWeight * 5.0f)
));
const FfxFloat32 fKernelBias = ffxLerp(fKernelBiasMin, fKernelBiasMax, fKernelBiasWeight);
#if FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS
// Unroll the loop to load samples on Scarlett to help the shader compiler
const bool coordX0OnScreen = iSrcSamplePosX01.x == iSrcSamplePosX01Clamped.x;
const bool coordX1OnScreen = iSrcSamplePosX01.y == iSrcSamplePosX01Clamped.y;
const bool coordX2OnScreen = iSrcSamplePosX23.x == iSrcSamplePosX23Clamped.x;
const bool coordY0OnScreen = iSrcSamplePosY01.x == iSrcSamplePosY01Clamped.x;
const bool coordY1OnScreen = iSrcSamplePosY01.y == iSrcSamplePosY01Clamped.y;
const bool coordY2OnScreen = iSrcSamplePosY23.x == iSrcSamplePosY23Clamped.x;
const FFX_MIN16_F2 fBaseSampleOffsetHalf = FFX_MIN16_F2(fBaseSampleOffset);
const FFX_MIN16_F2 fSrcSampleOffsetX_02 = fBaseSampleOffsetHalf.xx + fSampleOffsetX02;
const FFX_MIN16_F2 fSrcSampleOffsetY_02 = fBaseSampleOffsetHalf.yy + fSampleOffsetY02;
const FFX_MIN16_F2 fSrcSampleOffsetXSq_02 = fSrcSampleOffsetX_02 * fSrcSampleOffsetX_02;
const FFX_MIN16_F2 fSrcSampleOffsetYSq_02 = fSrcSampleOffsetY_02 * fSrcSampleOffsetY_02;
const FFX_MIN16_F2 fSrcSampleOffsetXYSq_11 = fBaseSampleOffsetHalf * fBaseSampleOffsetHalf;
const FfxFloat32 fRectificationCurveBias = -2.3f;
PairedRectificationBoxAndAccumulatedColorAndWeight pairedBox;
pairedBox.setKernelBiasAndRectificationCurveBias(fKernelBias, fRectificationCurveBias);
// init by o o o
// o x o
// o o o
pairedBox.initBox(
fSrcSampleOffsetXYSq_11.x + fSrcSampleOffsetXYSq_11.y,
Bool2ToFloat16x2(coordX1OnScreen && coordY1OnScreen, false).x,
CenterR, CenterG, CenterB
);
// add remaining two samples from 1st row x o x
// o * o
// o o o
pairedBox.addBoxSample(
fSrcSampleOffsetXSq_02 + fSrcSampleOffsetYSq_02.xx,
Bool2ToFloat16x2(coordX0OnScreen && coordY0OnScreen, coordX2OnScreen && coordY0OnScreen),
TopCornerR, TopCornerG, TopCornerB
);
// add two samples from 2nd row * o *
// o * o
// x o x
pairedBox.addBoxSample(
fSrcSampleOffsetXSq_02 + fSrcSampleOffsetYSq_02.yy,
Bool2ToFloat16x2(coordX0OnScreen && coordY2OnScreen, coordX2OnScreen && coordY2OnScreen),
BotCornerR, BotCornerG, BotCornerB
);
// add two samples from 3rd row * o *
// x * x
// * o *
pairedBox.addBoxSample(
fSrcSampleOffsetXSq_02 + fSrcSampleOffsetXYSq_11.yy,
Bool2ToFloat16x2(coordX0OnScreen && coordY1OnScreen, coordX2OnScreen && coordY1OnScreen),
HorzR, HorzG, HorzB
);
// add remaining samples * x *
// * * *
// * x *
pairedBox.addBoxSample(
fSrcSampleOffsetXYSq_11.xx + fSrcSampleOffsetYSq_02,
Bool2ToFloat16x2(coordX1OnScreen && coordY0OnScreen, coordX1OnScreen && coordY2OnScreen),
VertR, VertG, VertB
);
FfxFloat32x2 boxCenterAndVecR, boxCenterAndVecG, boxCenterAndVecB;
FfxFloat32 boxCenterWeight;
pairedBox.finalizeBox(boxCenterAndVecR, boxCenterAndVecG, boxCenterAndVecB, boxCenterWeight);
if (!bIsInitialSample)
{
pairedBox.initUpscaledColor(
fSrcSampleOffsetXYSq_11.x + fSrcSampleOffsetXYSq_11.y,
Bool2ToFloat16x2(coordX1OnScreen && coordY1OnScreen, false).x,
CenterR, CenterG, CenterB
);
// add remaining two samples from 1st row x o x
// o * o
// o o o
pairedBox.addUpscaledColorSample(
fSrcSampleOffsetXSq_02 + fSrcSampleOffsetYSq_02.xx,
Bool2ToFloat16x2(coordX0OnScreen && coordY0OnScreen, coordX2OnScreen && coordY0OnScreen),
TopCornerR, TopCornerG, TopCornerB
);
// add two samples from 2nd row * o *
// o * o
// x o x
pairedBox.addUpscaledColorSample(
fSrcSampleOffsetXSq_02 + fSrcSampleOffsetYSq_02.yy,
Bool2ToFloat16x2(coordX0OnScreen && coordY2OnScreen, coordX2OnScreen && coordY2OnScreen),
BotCornerR, BotCornerG, BotCornerB
);
// add two samples from 3rd row * o *
// x * x
// * o *
pairedBox.addUpscaledColorSample(
fSrcSampleOffsetXSq_02 + fSrcSampleOffsetXYSq_11.yy,
Bool2ToFloat16x2(coordX0OnScreen && coordY1OnScreen, coordX2OnScreen && coordY1OnScreen),
HorzR, HorzG, HorzB
);
// add remaining samples * x *
// * * *
// * x *
pairedBox.addUpscaledColorSample(
fSrcSampleOffsetXYSq_11.xx + fSrcSampleOffsetYSq_02,
Bool2ToFloat16x2(coordX1OnScreen && coordY0OnScreen, coordX1OnScreen && coordY2OnScreen),
VertR, VertG, VertB
);
FfxFloat32x4 upscaledColorAndWeight = 0.0;
pairedBox.finalizeUpscaledColor(upscaledColorAndWeight);
data.fUpsampledColor = FfxFloat32x3(upscaledColorAndWeight.rgb);
data.fUpsampledWeight = FfxFloat32(upscaledColorAndWeight.w);
}
FFX_MIN16_F2 aabbMinMaxR = Compute3x3SamplesMinMaxPaired(CenterR, TopCornerR, BotCornerR, HorzR, VertR);
FFX_MIN16_F2 aabbMinMaxG = Compute3x3SamplesMinMaxPaired(CenterG, TopCornerG, BotCornerG, HorzG, VertG);
FFX_MIN16_F2 aabbMinMaxB = Compute3x3SamplesMinMaxPaired(CenterB, TopCornerB, BotCornerB, HorzB, VertB);
data.clippingBox.boxCenter = FfxFloat32x3(boxCenterAndVecR.x, boxCenterAndVecG.x, boxCenterAndVecB.x);
data.clippingBox.boxVec = FfxFloat32x3(boxCenterAndVecR.y, boxCenterAndVecG.y, boxCenterAndVecB.y);
data.clippingBox.aabbMin = FfxFloat32x3(aabbMinMaxR.x, aabbMinMaxG.x, aabbMinMaxB.x);
data.clippingBox.aabbMax = FfxFloat32x3(aabbMinMaxR.y, aabbMinMaxG.y, aabbMinMaxB.y);
data.clippingBox.fBoxCenterWeight = FfxFloat32(boxCenterWeight);
#else
iSampleIndex = 0;
FFX_UNROLL
for (FfxInt32 row = 0; row < 3; row++)
{
FFX_UNROLL
for (FfxInt32 col = 0; col < 3; col++)
{
const FfxInt32x2 sampleColRow = FfxInt32x2(bFlipCol ? (3 - col) : col, bFlipRow ? (3 - row) : row);
const FfxFloat32x2 fOffset = fOffsetTL + FfxFloat32x2(sampleColRow);
const FfxFloat32x2 fSrcSampleOffset = fBaseSampleOffset + fOffset;
const FfxInt32x2 iSrcSamplePos = FfxInt32x2(iSrcInputPos) + FfxInt32x2(offsetTL) + sampleColRow;
const FfxFloat32 fOnScreenFactor = FfxFloat32(IsOnScreen(FfxInt32x2(iSrcSamplePos), FfxInt32x2(RenderSize())));
if (!bIsInitialSample)
{
const FfxFloat32 fSampleWeight = fOnScreenFactor * FfxFloat32(GetUpsampleLanczosWeight(fSrcSampleOffset, fKernelBias));
data.fUpsampledColor += fSamples[iSampleIndex] * fSampleWeight;
data.fUpsampledWeight += fSampleWeight;
}
// Update rectification box
{
const FfxFloat32 fRectificationCurveBias = -2.3f;
const FfxFloat32 fSrcSampleOffsetSq = dot(fSrcSampleOffset, fSrcSampleOffset);
const FfxFloat32 fBoxSampleWeight = exp(fRectificationCurveBias * fSrcSampleOffsetSq) * fOnScreenFactor;
const FfxBoolean bInitialSample = (row == 0) && (col == 0);
RectificationBoxAddSample(bInitialSample, data.clippingBox, fSamples[iSampleIndex], fBoxSampleWeight);
}
++iSampleIndex;
}
}
#endif // #if FFX_FSR3UPSCALER_USE_XBOX_PAIRED_16BIT_MATH_OPTIMIZATIONS
RectificationBoxComputeVarianceBoxData(data.clippingBox);
data.fUpsampledWeight *= FfxFloat32(data.fUpsampledWeight > FSR3UPSCALER_EPSILON);
if (data.fUpsampledWeight > FSR3UPSCALER_EPSILON) {
// Normalize for deringing (we need to compare colors)
data.fUpsampledColor = data.fUpsampledColor / data.fUpsampledWeight;
data.fUpsampledWeight *= fAverageLanczosWeightPerFrame;
Deringing(data.clippingBox, data.fUpsampledColor);
}
// Initial samples using tonemapped upsampling
if (bIsInitialSample) {
#if FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT
data.fUpsampledColor = RGBToYCoCg(InverseTonemap(YCoCgToRGB(data.clippingBox.boxCenter)));
#else
data.fUpsampledColor = data.clippingBox.boxCenter;
#endif
data.fUpsampledWeight = 1.0f;
data.fHistoryWeight = 0.0f;
}
}
@@ -0,0 +1,75 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
// Needed for rw_upscaled_output declaration
#extension GL_EXT_shader_image_load_formatted : require
#define FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE 0
#define FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS 1
#if FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#define FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS 2
#else
#define FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS 2
#endif
#define FSR3UPSCALER_BIND_SRV_INTERNAL_UPSCALED 3
#define FSR3UPSCALER_BIND_SRV_LANCZOS_LUT 4
#define FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH_MIP1 5
#define FSR3UPSCALER_BIND_SRV_CURRENT_LUMA 6
#define FSR3UPSCALER_BIND_SRV_LUMA_INSTABILITY 7
#define FSR3UPSCALER_BIND_SRV_INPUT_COLOR 8
#define FSR3UPSCALER_BIND_UAV_INTERNAL_UPSCALED 9
#define FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT 10
#define FSR3UPSCALER_BIND_UAV_NEW_LOCKS 11
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 12
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_sample.h"
#include "fsr3upscaler/ffx_fsr3upscaler_upsample.h"
#include "fsr3upscaler/ffx_fsr3upscaler_reproject.h"
#include "fsr3upscaler/ffx_fsr3upscaler_accumulate.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
Accumulate(FfxInt32x2(gl_GlobalInvocationID.xy));
}
@@ -0,0 +1,84 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY 0
#define FSR3UPSCALER_BIND_SRV_INPUT_COLOR 1
#define FSR3UPSCALER_BIND_UAV_AUTOREACTIVE 2
#define FSR3UPSCALER_BIND_UAV_AUTOCOMPOSITION 3
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 4
#define FSR3UPSCALER_BIND_CB_REACTIVE 5
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
FfxUInt32x2 uGroupId = gl_WorkGroupID.xy;
FfxUInt32x2 uGroupThreadId = gl_LocalInvocationID.xy;
FfxUInt32x2 uDispatchThreadId = uGroupId * FfxUInt32x2(FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT) + uGroupThreadId;
FfxFloat32x3 ColorPreAlpha = LoadOpaqueOnly(FFX_MIN16_I2(uDispatchThreadId)).rgb;
FfxFloat32x3 ColorPostAlpha = LoadInputColor(FfxInt32x2(uDispatchThreadId)).rgb;
if ((GenReactiveFlags() & FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_APPLY_TONEMAP) != 0)
{
ColorPreAlpha = Tonemap(ColorPreAlpha);
ColorPostAlpha = Tonemap(ColorPostAlpha);
}
if ((GenReactiveFlags() & FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_APPLY_INVERSETONEMAP) != 0)
{
ColorPreAlpha = InverseTonemap(ColorPreAlpha);
ColorPostAlpha = InverseTonemap(ColorPostAlpha);
}
FfxFloat32 out_reactive_value = 0.f;
FfxFloat32x3 delta = abs(ColorPostAlpha - ColorPreAlpha);
out_reactive_value = ((GenReactiveFlags() & FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_USE_COMPONENTS_MAX)!=0) ? max(delta.x, max(delta.y, delta.z)) : length(delta);
out_reactive_value *= GenReactiveScale();
out_reactive_value = ((GenReactiveFlags() & FFX_FSR3UPSCALER_AUTOREACTIVEFLAGS_APPLY_THRESHOLD)!=0) ? ((out_reactive_value < GenReactiveThreshold()) ? 0 : GenReactiveBinaryValue()) : out_reactive_value;
imageStore(rw_output_autoreactive, FfxInt32x2(uDispatchThreadId), FfxFloat32x4(out_reactive_value, 0.0, 0.0, 0.0));
}
@@ -0,0 +1,59 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS 0
#define FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS 1
#define FSR3UPSCALER_BIND_SRV_DILATED_DEPTH 2
#define FSR3UPSCALER_BIND_SRV_INTERNAL_UPSCALED 3
#define FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE 4
#define FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT 5
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 6
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_debug_view.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
DebugView(FfxInt32x2(gl_GlobalInvocationID.xy));
}
@@ -0,0 +1,62 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE 0
#define FSR3UPSCALER_BIND_SRV_DILATED_REACTIVE_MASKS 1
#define FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS 2
#define FSR3UPSCALER_BIND_SRV_FRAME_INFO 3
#define FSR3UPSCALER_BIND_SRV_LUMA_HISTORY 4
#define FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH_MIP1 5
#define FSR3UPSCALER_BIND_SRV_CURRENT_LUMA 6
#define FSR3UPSCALER_BIND_UAV_LUMA_HISTORY 7
#define FSR3UPSCALER_BIND_UAV_LUMA_INSTABILITY 8
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 9
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_luma_instability.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
LumaInstability(FfxInt32x2(gl_GlobalInvocationID.xy));
}
@@ -0,0 +1,65 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_CURRENT_LUMA 0
#define FSR3UPSCALER_BIND_SRV_FARTHEST_DEPTH 1
#define FSR3UPSCALER_BIND_UAV_SPD_GLOBAL_ATOMIC 2
#define FSR3UPSCALER_BIND_UAV_FRAME_INFO 3
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_0 4
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_1 5
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_2 6
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_3 7
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_4 8
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_5 9
#define FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH_MIP1 10
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 11
#define FSR3UPSCALER_BIND_CB_SPD 12
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_luma_pyramid.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 256
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
ComputeAutoExposure(gl_WorkGroupID, gl_LocalInvocationIndex);
}
@@ -0,0 +1,61 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS 0
#define FSR3UPSCALER_BIND_SRV_INPUT_DEPTH 1
#define FSR3UPSCALER_BIND_SRV_INPUT_COLOR 2
#define FSR3UPSCALER_BIND_UAV_DILATED_MOTION_VECTORS 3
#define FSR3UPSCALER_BIND_UAV_DILATED_DEPTH 4
#define FSR3UPSCALER_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH 5
#define FSR3UPSCALER_BIND_UAV_FARTHEST_DEPTH 6
#define FSR3UPSCALER_BIND_UAV_CURRENT_LUMA 7
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 8
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_prepare_inputs.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
PrepareInputs(FfxInt32x2(gl_GlobalInvocationID.xy));
}
@@ -0,0 +1,65 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH 0
#define FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS 1
#define FSR3UPSCALER_BIND_SRV_DILATED_DEPTH 2
#define FSR3UPSCALER_BIND_SRV_REACTIVE_MASK 3
#define FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK 4
#define FSR3UPSCALER_BIND_SRV_ACCUMULATION 5
#define FSR3UPSCALER_BIND_SRV_SHADING_CHANGE 6
#define FSR3UPSCALER_BIND_SRV_CURRENT_LUMA 7
#define FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE 8
#define FSR3UPSCALER_BIND_UAV_DILATED_REACTIVE_MASKS 9
#define FSR3UPSCALER_BIND_UAV_NEW_LOCKS 10
#define FSR3UPSCALER_BIND_UAV_ACCUMULATION 11
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 12
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_prepare_reactivity.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
PrepareReactivity(FfxInt32x2(gl_GlobalInvocationID.xy));
}
@@ -0,0 +1,59 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
// Needed for rw_upscaled_output declaration
#extension GL_EXT_shader_image_load_formatted : require
#define FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE 0
#define FSR3UPSCALER_BIND_SRV_RCAS_INPUT 1
#define FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT 2
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 3
#define FSR3UPSCALER_BIND_CB_RCAS 4
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_rcas.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 64
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
RCAS(gl_LocalInvocationID.xyz, gl_WorkGroupID.xyz, gl_GlobalInvocationID.xyz);
}
@@ -0,0 +1,55 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_SPD_MIPS 0
#define FSR3UPSCALER_BIND_UAV_SHADING_CHANGE 1
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 2
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_shading_change.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 8
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
ShadingChange(FfxInt32x2(gl_GlobalInvocationID.xy));
}
@@ -0,0 +1,67 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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.
#version 450
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#define FSR3UPSCALER_BIND_SRV_CURRENT_LUMA 0
#define FSR3UPSCALER_BIND_SRV_PREVIOUS_LUMA 1
#define FSR3UPSCALER_BIND_SRV_DILATED_MOTION_VECTORS 2
#define FSR3UPSCALER_BIND_SRV_INPUT_EXPOSURE 3
#define FSR3UPSCALER_BIND_UAV_SPD_GLOBAL_ATOMIC 4
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_0 5
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_1 6
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_2 7
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_3 8
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_4 9
#define FSR3UPSCALER_BIND_UAV_SPD_MIPS_LEVEL_5 10
#define FSR3UPSCALER_BIND_CB_FSR3UPSCALER 11
#define FSR3UPSCALER_BIND_CB_SPD 12
#include "fsr3upscaler/ffx_fsr3upscaler_callbacks_glsl.h"
#include "fsr3upscaler/ffx_fsr3upscaler_common.h"
#include "fsr3upscaler/ffx_fsr3upscaler_shading_change_pyramid.h"
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH 256
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#define FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT
#ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#define FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH 1
#endif // #ifndef FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH
#ifndef FFX_FSR3UPSCALER_NUM_THREADS
#define FFX_FSR3UPSCALER_NUM_THREADS layout (local_size_x = FFX_FSR3UPSCALER_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR3UPSCALER_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR3UPSCALER_THREAD_GROUP_DEPTH) in;
#endif // #ifndef FFX_FSR3UPSCALER_NUM_THREADS
FFX_FSR3UPSCALER_NUM_THREADS
void main()
{
ComputeShadingChangePyramid(gl_WorkGroupID, gl_LocalInvocationIndex);
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,122 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (C) 2024 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 <FidelityFX/gpu/fsr3upscaler/ffx_fsr3upscaler_resources.h>
/// An enumeration of all the permutations that can be passed to the FSR3 Upscaler algorithm.
///
/// FSR3 Upscaler features are organized through a set of pre-defined compile
/// permutation options that need to be specified. Which shader blob
/// is returned for pipeline creation will be determined by what combination
/// of shader permutations are enabled.
///
/// @ingroup FSR3Upscaler
typedef enum Fs3UpscalerShaderPermutationOptions
{
FSR3UPSCALER_SHADER_PERMUTATION_USE_LANCZOS_TYPE = (1 << 0), ///< Off means reference, On means LUT
FSR3UPSCALER_SHADER_PERMUTATION_HDR_COLOR_INPUT = (1 << 1), ///< Enables the HDR code path
FSR3UPSCALER_SHADER_PERMUTATION_LOW_RES_MOTION_VECTORS = (1 << 2), ///< Indicates low resolution motion vectors provided
FSR3UPSCALER_SHADER_PERMUTATION_JITTER_MOTION_VECTORS = (1 << 3), ///< Indicates motion vectors were generated with jitter
FSR3UPSCALER_SHADER_PERMUTATION_DEPTH_INVERTED = (1 << 4), ///< Indicates input resources were generated with inverted depth
FSR3UPSCALER_SHADER_PERMUTATION_ENABLE_SHARPENING = (1 << 5), ///< Enables a supplementary sharpening pass
FSR3UPSCALER_SHADER_PERMUTATION_FORCE_WAVE64 = (1 << 6), ///< doesn't map to a define, selects different table
FSR3UPSCALER_SHADER_PERMUTATION_ALLOW_FP16 = (1 << 7), ///< Enables fast math computations where possible
} Fs3UpscalerShaderPermutationOptions;
// Constants for FSR3 Upscaler dispatches. Must be kept in sync with cbFSR3Upscaler in ffx_fsr2_callbacks_hlsl.h
typedef struct Fsr3UpscalerConstants {
int32_t renderSize[2];
int32_t previousFrameRenderSize[2];
int32_t upscaleSize[2];
int32_t previousFrameUpscaleSize[2];
int32_t maxRenderSize[2];
int32_t maxUpscaleSize[2];
float deviceToViewDepth[4];
float jitterOffset[2];
float previousFrameJitterOffset[2];
float motionVectorScale[2];
float downscaleFactor[2];
float motionVectorJitterCancellation[2];
float tanHalfFOV;
float jitterPhaseCount;
float deltaTime;
float deltaPreExposure;
float viewSpaceToMetersFactor;
float frameIndex;
float velocityFactor;
float reactivenessScale;
float shadingChangeScale;
float accumulationAddedPerFrame;
float minDisocclusionAccumulation;
} Fsr3UpscalerConstants;
struct FfxFsr3UpscalerContextDescription;
struct FfxDeviceCapabilities;
struct FfxPipelineState;
// FfxFsr3UpscalerContext_Private
// The private implementation of the FSR3 Upscaler context.
typedef struct FfxFsr3UpscalerContext_Private {
FfxFsr3UpscalerContextDescription contextDescription;
FfxUInt32 effectContextId;
Fsr3UpscalerConstants constants;
FfxDevice device;
FfxDeviceCapabilities deviceCapabilities;
FfxPipelineState pipelinePrepareInputs;
FfxPipelineState pipelinePrepareReactivity;
FfxPipelineState pipelineShadingChange;
FfxPipelineState pipelineAccumulate;
FfxPipelineState pipelineAccumulateSharpen;
FfxPipelineState pipelineRCAS;
FfxPipelineState pipelineLumaPyramid;
FfxPipelineState pipelineGenerateReactive;
FfxPipelineState pipelineTcrAutogenerate;
FfxPipelineState pipelineShadingChangePyramid;
FfxPipelineState pipelineLumaInstability;
FfxPipelineState pipelineDebugView;
FfxConstantBuffer constantBuffers[FFX_FSR3UPSCALER_CONSTANTBUFFER_COUNT];
// 2 arrays of resources, as e.g. FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_LOCK_STATUS will use different resources when bound as SRV vs when bound as UAV
FfxResourceInternal srvResources[FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT];
FfxResourceInternal uavResources[FFX_FSR3UPSCALER_RESOURCE_IDENTIFIER_COUNT];
bool firstExecution;
uint32_t resourceFrameIndex;
float previousJitterOffset[2];
float preExposure;
float previousFramePreExposure;
} FfxFsr3UpscalerContext_Private;
// declare fsr3UpscalerCreate so it can be used from fsr3
FFX_API FfxErrorCode fsr3UpscalerCreate(FfxFsr3UpscalerContext_Private* context, const FfxFsr3UpscalerContextDescription* contextDescription);
File diff suppressed because it is too large. Load diff
+73 -22
View File
@@ -616,6 +616,34 @@ 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").
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};
const char *now = cfg_scene_upscaler();
const char *vals[3], *names[3];
static char note[256];
note[0] = 0;
int n = 0, cur = -1;
for (int i = 0; i < 3; 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;
size_t k = strlen(note);
snprintf(note + k, sizeof note - k, "%s%s", k ? "; " : "", menu_text(t));
}
if (why && strcmp(now, all[i])) continue;
if (!strcmp(now, all[i])) cur = n;
vals[n] = all[i], names[n] = menu_text(ids[i]), n++;
}
opt_choice_list("TOTK_SCENE_UPSCALER", UI_MENU_SCENE_UPSCALER, vals, names, n, UI_MENU_SCENE_UPSCALER_DESC, cur,
note[0] ? note : nullptr);
return cfg_scene_upscaler();
}
static void row_render_scale(void) {
static const char *const vals[] = {"game", "50", "67", "75", "100", "125", "150", "200"};
enum { N = sizeof vals / sizeof *vals };
@@ -793,17 +821,21 @@ static void tab_screen(float scale) {
opt_toggle("TOTK_LOD_STEADY", UI_MENU_LOD_STEADY, UI_MENU_LOD_STEADY_DESC);
opt_slider("TOTK_PCSS", UI_MENU_PCSS, 0, 200, UI_MENU_PCSS_DESC, 10, "%.0f %%");
opt_slider("TOTK_CONTACT_SHADOWS", UI_MENU_CONTACT_SHADOWS, 0, 100, UI_MENU_CONTACT_SHADOWS_DESC, 10, "%.0f %%");
opt_toggle("TOTK_DLAA", UI_MENU_DLAA, UI_MENU_DLAA_DESC);
static const UiTextId dlss[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED,
UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA};
opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 5, UI_MENU_DLSS_DESC);
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,
UI_MENU_DLSS_CHARS_FULL};
opt_choice("TOTK_DLSS_CHAR_MASK", UI_MENU_DLSS_CHARS, chars, 4, UI_MENU_DLSS_CHARS_DESC);
opt_toggle("TOTK_DLSS_FIXED_EXPOSURE", UI_MENU_DLSS_FIXED_EXPOSURE, UI_MENU_DLSS_FIXED_EXPOSURE_DESC);
opt_toggle("TOTK_DLAA_EFFECTS_AFTER", UI_MENU_DLAA_EFFECTS_AFTER, UI_MENU_DLAA_EFFECTS_AFTER_DESC);
const char *engine = row_scene_upscaler();
if (strcmp(engine, "off")) { // the mode serves both engines
static const UiTextId dlss[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED,
UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA};
opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 5, UI_MENU_DLSS_DESC);
}
if (!strcmp(engine, "dlss")) { // DLSS's model, its characters' mask and its other switches (FSR 3.1 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,
UI_MENU_DLSS_CHARS_FULL};
opt_choice("TOTK_DLSS_CHAR_MASK", UI_MENU_DLSS_CHARS, chars, 4, UI_MENU_DLSS_CHARS_DESC);
opt_toggle("TOTK_DLSS_FIXED_EXPOSURE", UI_MENU_DLSS_FIXED_EXPOSURE, UI_MENU_DLSS_FIXED_EXPOSURE_DESC);
opt_toggle("TOTK_DLAA_EFFECTS_AFTER", UI_MENU_DLAA_EFFECTS_AFTER, UI_MENU_DLAA_EFFECTS_AFTER_DESC);
}
static const UiTextId reflex[] = {UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST};
opt_choice("TOTK_REFLEX", UI_MENU_REFLEX, reflex, 3, UI_MENU_REFLEX_DESC);
opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC);
@@ -1708,13 +1740,14 @@ static void perf_label(UiTextId label, const ImVec4 &c) {
static float perf_gb(float mb) { return mb < 0 ? -1 : mb / 1024; }
// The picture lines: the window, the game image the present shows and the 3D scene it holds (resolution.c), how the
// present scales the image to the window (gfx_present.c, the last present), the frame limit and the presentation mode
// in use.
// The picture lines: the window, the game image the present shows and the 3D scene it holds (resolution.c), the
// temporal upscaler that scales the scene (vk_dlaa.c) with its mode, how the present scales the image to the window
// (gfx_present.c, the last present), the frame limit, the presentation mode in use and, with frame generation, the
// pictures shown a second.
static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
unsigned out[2], scene[2];
res_sizes(out, scene);
char v[7][64];
char v[8][64];
snprintf(v[0], sizeof v[0], menu_text(UI_MENU_OV_FMT_SIZE), t->width, t->height);
snprintf(v[1], sizeof v[1], menu_text(UI_MENU_OV_FMT_SIZE), (unsigned)t->image_w, (unsigned)t->image_h);
snprintf(v[2], sizeof v[2], menu_text(UI_MENU_OV_FMT_SCENE), scene[0], scene[1], scene[0] * 100.0 / out[0]);
@@ -1733,20 +1766,38 @@ static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
if (hz > 0) snprintf(v[4], sizeof v[4], menu_text(UI_MENU_OV_FPS), hz);
const char *pm = present_name(gfx_window_present_mode());
snprintf(v[5], sizeof v[5], "%s", pm ? pm : menu_text(UI_MENU_OV_NONE));
// the temporal upscaler that ran (vk_dlaa.c: it ran and has not failed) and its mode, after the scene it scales; the
// line is left out while none runs, so the overlay without one has the same lines as before the setting existed
int up = vk_upscaler_running();
if (up) {
const char *m = cfg_value("TOTK_DLSS");
UiTextId mt = !strcmp(m, "quality") ? UI_MENU_DLSS_QUALITY
: !strcmp(m, "balanced") ? UI_MENU_DLSS_BALANCED
: !strcmp(m, "performance") ? UI_MENU_DLSS_PERFORMANCE
: !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(mt));
}
// with frame generation: the pictures shown a second, of which the FPS row above counts the ones the game drew
int n = 6;
if (g_shown_fps > 0) snprintf(v[n++], sizeof v[6], menu_text(UI_MENU_OV_FPS), g_shown_fps);
static const UiTextId labels[7] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, UI_MENU_OV_SCALING,
UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT, UI_MENU_OV_SHOWN};
if (g_shown_fps > 0) snprintf(v[7], sizeof v[7], menu_text(UI_MENU_OV_FPS), g_shown_fps);
static const UiTextId labels[8] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, UI_MENU_OV_SCALING,
UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT, UI_MENU_OV_UPSCALER, UI_MENU_OV_SHOWN};
int order[8], n = 0;
order[n++] = 0, order[n++] = 1, order[n++] = 2;
if (up) order[n++] = 6;
order[n++] = 3, order[n++] = 4, order[n++] = 5;
if (g_shown_fps > 0) order[n++] = 7;
if (!ImGui::BeginTable("##perfp", 2, ImGuiTableFlags_SizingFixedFit)) return;
float vw = 0;
for (int i = 0; i < n; i++) vw = fmaxf(vw, ImGui::CalcTextSize(v[i]).x);
for (int i = 0; i < n; i++) vw = fmaxf(vw, ImGui::CalcTextSize(v[order[i]]).x);
ImGui::TableSetupColumn("##p0", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("##p1", ImGuiTableColumnFlags_WidthFixed, vw);
for (int i = 0; i < n; i++) {
perf_label(labels[i], c);
perf_label(labels[order[i]], c);
ImGui::TableNextColumn();
perf_right(v[i], false);
perf_right(v[order[i]], false);
}
ImGui::EndTable();
}
+65 -33
View File
@@ -153,10 +153,6 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_GRASS_RANGE_DESC] = "How far around the camera grass grows (the game's: 62.5 m). Higher keeps the "
"grass in meadows further out instead of growing it in just in front of you; lower "
"draws less of it. Takes effect at the next start.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS for the 3D scene (NVIDIA RTX GPUs; " DLSS_FILE " next to " EXE_FILE "): smoother "
"edges and less shimmer. The HUD is not touched. The mode below sets the resolution it works "
"from. Takes effect after a restart.",
[UI_MENU_DLSS_PRESET] = "DLSS model",
[UI_MENU_DLSS_PRESET_DESC] = "Which DLSS model runs. Automatic follows NVIDIA's advice per mode: K for DLAA, Quality "
"and Balanced, M for Performance, L for Ultra Performance. J: slightly less ghosting "
@@ -170,11 +166,11 @@ static const char *const text_en[UI_TEXT_COUNT] = {
"edges a little less smooth. Applies at once.",
[UI_MENU_DLSS_CHARS_OFF] = "Off", [UI_MENU_DLSS_CHARS_LIGHT] = "Light", [UI_MENU_DLSS_CHARS_MEDIUM] = "Medium",
[UI_MENU_DLSS_CHARS_FULL] = "Full",
[UI_MENU_DLSS] = "DLSS mode",
[UI_MENU_DLSS_DESC] = "DLAA draws the 3D scene at full resolution. Quality, Balanced, Performance and Ultra "
"Performance draw it at 67, 58, 50 and 33 % and let DLSS scale it up, which saves GPU time; "
"they replace the 3D render scale. Takes effect at once.",
[UI_MENU_DLSS_DLAA] = "DLAA (native)", [UI_MENU_DLSS_QUALITY] = "Quality", [UI_MENU_DLSS_BALANCED] = "Balanced",
[UI_MENU_DLSS] = "Upscaling mode",
[UI_MENU_DLSS_DESC] = "Native anti-aliases the 3D scene at full resolution. Quality, Balanced, Performance and Ultra "
"Performance draw it at 67, 58, 50 and 33 % and let the upscaler (DLSS or FSR 3.1) scale it "
"up, which saves GPU time; they replace the 3D render scale. Takes effect at once.",
[UI_MENU_DLSS_DLAA] = "Native", [UI_MENU_DLSS_QUALITY] = "Quality", [UI_MENU_DLSS_BALANCED] = "Balanced",
[UI_MENU_DLSS_PERFORMANCE] = "Performance", [UI_MENU_DLSS_ULTRA] = "Ultra Performance",
[UI_MENU_FXAA] = "Game anti-aliasing (FXAA)",
[UI_MENU_FXAA_DESC] = "The game's own FXAA edge smoothing. It blurs fine detail a little; with DLAA on it is not needed.",
@@ -183,6 +179,16 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_REFLEX_OFF] = "Off",
[UI_MENU_REFLEX_ON] = "On",
[UI_MENU_REFLEX_BOOST] = "On + Boost",
[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 "
"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_NO_DLSS_GPU] = "DLSS: needs an NVIDIA RTX GPU",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: " DLSS_FILE " is missing",
[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 "
@@ -605,6 +611,7 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_OV_FMT_MHZ] = "%.0f MHz", [UI_MENU_OV_FMT_GB] = "%.1f GB", [UI_MENU_OV_FMT_GB_OF] = "/ %.1f GB",
[UI_MENU_OV_GAME_GB] = "game %.1f GB", [UI_MENU_OV_FMT_MS] = "%.2f ms", [UI_MENU_OV_PER_FRAME] = "%.1f per frame",
[UI_MENU_OV_WINDOW] = "Window", [UI_MENU_OV_OUTPUT] = "Game image", [UI_MENU_OV_SCENE] = "3D scene",
[UI_MENU_OV_UPSCALER] = "3D upscaler",
[UI_MENU_OV_SCALING] = "Scaling", [UI_MENU_OV_LIMIT] = "Frame limit", [UI_MENU_OV_PRESENT] = "Presentation", [UI_MENU_OV_SHOWN] = "Shown",
[UI_MENU_OV_FMT_SIZE] = "%ux%u", [UI_MENU_OV_FMT_SCENE] = "%ux%u, %.0f%%",
[UI_MENU_OV_FMT_FSR] = "AMD FSR 1, sharpness %d%%", [UI_MENU_OV_SCALE_NONE] = "none (1:1)",
@@ -788,10 +795,6 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_GRASS_RANGE_DESC] = "Как далеко вокруг камеры растёт трава (в игре 62,5 м). Выше: трава на лугах видна "
"дальше и не вырастает прямо перед вами; ниже: травы меньше. Действует после "
"перезапуска.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS для 3D-сцены (видеокарты NVIDIA RTX; " DLSS_FILE " рядом с " EXE_FILE "): ровнее "
"края и меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он "
"работает. Действует после перезапуска.",
[UI_MENU_DLSS_PRESET] = "Модель DLSS",
[UI_MENU_DLSS_PRESET_DESC] = "Какая модель DLSS работает. «Автоматически» следует совету NVIDIA для каждого режима: K "
"для DLAA, «Качества» и «Баланса», M для «Производительности», L для «Макс. "
@@ -805,11 +808,12 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
"гладкие края. Действует сразу.",
[UI_MENU_DLSS_CHARS_OFF] = "Выкл.", [UI_MENU_DLSS_CHARS_LIGHT] = "Слабо", [UI_MENU_DLSS_CHARS_MEDIUM] = "Средне",
[UI_MENU_DLSS_CHARS_FULL] = "Полностью",
[UI_MENU_DLSS] = "Режим DLSS",
[UI_MENU_DLSS_DESC] = "DLAA рисует 3D-сцену в полном разрешении. «Качество», «Баланс», «Производительность» и "
"«Макс. производительность» рисуют её в 67, 58, 50 и 33 % и масштабируют через DLSS, что "
"экономит время видеокарты; они заменяют масштаб 3D-отрисовки. Действует сразу.",
[UI_MENU_DLSS_DLAA] = "DLAA (родное)", [UI_MENU_DLSS_QUALITY] = "Качество", [UI_MENU_DLSS_BALANCED] = "Баланс",
[UI_MENU_DLSS] = "Режим апскейлера",
[UI_MENU_DLSS_DESC] = "«Родное» сглаживает 3D-сцену в полном разрешении. «Качество», «Баланс», «Производительность» и "
"«Макс. производительность» рисуют её в 67, 58, 50 и 33 % и масштабируют апскейлером (DLSS "
"или FSR 3.1), что экономит время видеокарты; они заменяют масштаб 3D-отрисовки. Действует "
"сразу.",
[UI_MENU_DLSS_DLAA] = "Родное", [UI_MENU_DLSS_QUALITY] = "Качество", [UI_MENU_DLSS_BALANCED] = "Баланс",
[UI_MENU_DLSS_PERFORMANCE] = "Производительность", [UI_MENU_DLSS_ULTRA] = "Макс. производительность",
[UI_MENU_FXAA] = "Сглаживание игры (FXAA)",
[UI_MENU_FXAA_DESC] = "Собственное сглаживание FXAA. Слегка размывает мелкие детали; с DLAA оно не нужно.",
@@ -818,6 +822,17 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_REFLEX_OFF] = "Выкл",
[UI_MENU_REFLEX_ON] = "Вкл",
[UI_MENU_REFLEX_BOOST] = "Вкл + Ускорение",
[UI_MENU_SCENE_UPSCALER] = "Апскейлер 3D-сцены",
[UI_MENU_SCENE_UPSCALER_DESC] = "Временной апскейлер для 3D-сцены: ровнее края и меньше мерцания, а в режимах ниже «Родного» он "
"рисует сцену меньше и увеличивает её, что экономит время видеокарты. NVIDIA DLSS "
"нужна видеокарта NVIDIA RTX и " DLSS_FILE " рядом с " EXE_FILE "; AMD FSR 3.1 "
"работает на любой видеокарте. «Выкл» оставляет собственное масштабирование игры и "
"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_NO_DLSS_GPU] = "DLSS: нужна видеокарта NVIDIA RTX",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: нет " DLSS_FILE,
[UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров",
[UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость "
@@ -1244,6 +1259,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_OV_FMT_MHZ] = "%.0f МГц", [UI_MENU_OV_FMT_GB] = "%.1f ГБ", [UI_MENU_OV_FMT_GB_OF] = "/ %.1f ГБ",
[UI_MENU_OV_GAME_GB] = "игра %.1f ГБ", [UI_MENU_OV_FMT_MS] = "%.2f мс", [UI_MENU_OV_PER_FRAME] = "%.1f за кадр",
[UI_MENU_OV_WINDOW] = "Окно", [UI_MENU_OV_OUTPUT] = "Изображение игры", [UI_MENU_OV_SCENE] = "3D-сцена",
[UI_MENU_OV_UPSCALER] = "3D-апскейлер",
[UI_MENU_OV_SCALING] = "Масштабирование", [UI_MENU_OV_LIMIT] = "Лимит кадров", [UI_MENU_OV_PRESENT] = "Вывод кадров", [UI_MENU_OV_SHOWN] = "Показано",
[UI_MENU_OV_FMT_SIZE] = "%ux%u", [UI_MENU_OV_FMT_SCENE] = "%ux%u, %.0f%%",
[UI_MENU_OV_FMT_FSR] = "AMD FSR 1, резкость %d%%", [UI_MENU_OV_SCALE_NONE] = "нет (1:1)",
@@ -1699,6 +1715,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_OV_FMT_MHZ] = "%.0f MHz", [UI_MENU_OV_FMT_GB] = "%.1f GB", [UI_MENU_OV_FMT_GB_OF] = "/ %.1f GB",
[UI_MENU_OV_GAME_GB] = "jogo %.1f GB", [UI_MENU_OV_FMT_MS] = "%.2f ms", [UI_MENU_OV_PER_FRAME] = "%.1f por quadro",
[UI_MENU_OV_WINDOW] = "Janela", [UI_MENU_OV_OUTPUT] = "Imagem do jogo", [UI_MENU_OV_SCENE] = "Cena 3D",
[UI_MENU_OV_UPSCALER] = "Upscaler 3D",
[UI_MENU_OV_SCALING] = "Escala", [UI_MENU_OV_LIMIT] = "Limite de quadros", [UI_MENU_OV_PRESENT] = "Apresentação", [UI_MENU_OV_SHOWN] = "Exibidos",
[UI_MENU_OV_FMT_SIZE] = "%ux%u", [UI_MENU_OV_FMT_SCENE] = "%ux%u, %.0f%%",
[UI_MENU_OV_FMT_FSR] = "AMD FSR 1, nitidez %d%%", [UI_MENU_OV_SCALE_NONE] = "nenhuma (1:1)",
@@ -1887,15 +1904,11 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_PCSS] = "Sombras suaves",
[UI_MENU_PCSS_DESC] = "Sombras do sol nítidas onde um objeto toca o chão e mais suaves quanto mais longe a sombra "
"cai (PCSS). 0 mantém o filtro do jogo. Vale no próximo início.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS para a cena 3D (placas NVIDIA RTX; nvngx_dlss.dll ao lado do totk.exe): bordas "
"mais suaves e menos cintilação. O HUD não é afetado. O modo abaixo define a resolução de "
"onde ele parte. Vale após reiniciar.",
[UI_MENU_DLSS] = "Modo do DLSS",
[UI_MENU_DLSS_DESC] = "DLAA desenha a cena 3D na resolução cheia. Qualidade, Equilibrado, Desempenho e Ultra "
"Desempenho a desenham em 67, 58, 50 e 33 % e deixam o DLSS ampliá-la, o que poupa tempo da "
"GPU; eles substituem a escala 3D. Vale na hora.",
[UI_MENU_DLSS_DLAA] = "DLAA (nativo)",
[UI_MENU_DLSS] = "Modo de upscaling",
[UI_MENU_DLSS_DESC] = "Nativo suaviza a cena 3D na resolução cheia. Qualidade, Equilibrado, Desempenho e Ultra "
"Desempenho a desenham em 67, 58, 50 e 33 % e deixam o upscaler (DLSS ou FSR 3.1) ampliá-la, "
"o que poupa tempo da GPU; eles substituem a escala 3D. Vale na hora.",
[UI_MENU_DLSS_DLAA] = "Nativo",
[UI_MENU_DLSS_QUALITY] = "Qualidade",
[UI_MENU_DLSS_BALANCED] = "Equilibrado",
[UI_MENU_DLSS_PERFORMANCE] = "Desempenho", [UI_MENU_DLSS_ULTRA] = "Ultra Desempenho",
@@ -1920,6 +1933,17 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_REFLEX_OFF] = "Desligado",
[UI_MENU_REFLEX_ON] = "Ligado",
[UI_MENU_REFLEX_BOOST] = "Ligado + Boost",
[UI_MENU_SCENE_UPSCALER] = "Upscaler da cena 3D",
[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 "
"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_NO_DLSS_GPU] = "DLSS: precisa de uma GPU NVIDIA RTX",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS: falta o " DLSS_FILE,
[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. "
@@ -2504,6 +2528,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_OV_WINDOW] = "窗口",
[UI_MENU_OV_OUTPUT] = "游戏画面",
[UI_MENU_OV_SCENE] = "3D 场景",
[UI_MENU_OV_UPSCALER] = "3D 超分",
[UI_MENU_OV_SCALING] = "缩放",
[UI_MENU_OV_LIMIT] = "帧率上限",
[UI_MENU_OV_PRESENT] = "呈现模式",
@@ -2638,12 +2663,10 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_CONTACT_SHADOWS_DESC] = "阴影贴图遗漏的细小太阳阴影:脚下、石头下、草丛和褶皱中。在光照之后于屏幕空间追踪。下次启动时生效。",
[UI_MENU_PCSS] = "柔和阴影",
[UI_MENU_PCSS_DESC] = "物体接触地面处的太阳阴影锐利,阴影投得越远越柔和(PCSS)。0 保留游戏自身的过滤。下次启动时生效。",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "用于 3D 场景的 NVIDIA DLSS(NVIDIA RTX 显卡;nvngx_dlss.dll 放在 totk.exe 旁):边缘更平滑,闪烁更少。HUD "
"不受影响。下方的模式决定它的工作分辨率。重启后生效。",
[UI_MENU_DLSS] = "DLSS 模式",
[UI_MENU_DLSS_DESC] = "DLAA 以全分辨率绘制 3D 场景。质量、平衡、性能和超级性能分别以 67%、58%、50% 和 33% 绘制,再由 DLSS 放大,以节省 GPU 时间;它们会取代 3D 渲染比例。立即生效。",
[UI_MENU_DLSS_DLAA] = "DLAA(原生)",
[UI_MENU_DLSS] = "超分模式",
[UI_MENU_DLSS_DESC] = "原生以全分辨率对 3D 场景做抗锯齿。质量、平衡、性能和超级性能分别以 67%、58%、50% 和 33% 绘制,再由超分"
"(DLSS 或 FSR 3.1)放大,以节省 GPU 时间;它们会取代 3D 渲染比例。立即生效。",
[UI_MENU_DLSS_DLAA] = "原生",
[UI_MENU_DLSS_QUALITY] = "质量",
[UI_MENU_DLSS_BALANCED] = "平衡",
[UI_MENU_DLSS_PERFORMANCE] = "性能",
@@ -2665,6 +2688,15 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_REFLEX_OFF] = "关",
[UI_MENU_REFLEX_ON] = "开",
[UI_MENU_REFLEX_BOOST] = "开 + 增强",
[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 不受影响;上方的缩放"
"方式和锐度仍负责把游戏画面适配到窗口。重启后生效。",
[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_NO_DLSS_GPU] = "DLSS:需要 NVIDIA RTX 显卡",
[UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL] = "DLSS:缺少 " DLSS_FILE,
[UI_MENU_TAB_CHEATS] = "金手指",
[UI_MENU_CHEATS_NONE] = "此游戏版本没有金手指。模组的金手指是它的 cheats 文件夹中以游戏构建命名的 Atmosphere "
"金手指文件:mods\\<模组>\\cheats\\%s。重启游戏后才会读取。对于修改游戏代码的金手指,"
+4 -2
View File
@@ -59,11 +59,13 @@ typedef enum {
UI_MENU_GRASS_RANGE, UI_MENU_GRASS_RANGE_DESC,
UI_MENU_CONTACT_SHADOWS, UI_MENU_CONTACT_SHADOWS_DESC,
UI_MENU_PCSS, UI_MENU_PCSS_DESC,
UI_MENU_DLAA, UI_MENU_DLAA_DESC, UI_MENU_DLSS, UI_MENU_DLSS_DESC, UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY,
UI_MENU_DLSS, UI_MENU_DLSS_DESC, UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY,
UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA, UI_MENU_DLSS_PRESET, UI_MENU_DLSS_PRESET_DESC,
UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J, UI_MENU_DLSS_CHARS, UI_MENU_DLSS_CHARS_DESC,
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,
// 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,
@@ -285,7 +287,7 @@ typedef enum {
UI_MENU_OV_FMT_PCT, UI_MENU_OV_FMT_TEMP, UI_MENU_OV_FMT_POWER, UI_MENU_OV_FMT_MHZ, UI_MENU_OV_FMT_GB,
UI_MENU_OV_FMT_GB_OF, UI_MENU_OV_GAME_GB, UI_MENU_OV_FMT_MS, UI_MENU_OV_PER_FRAME,
// the picture lines: window, game image and 3D scene sizes, the scaling to the window, frame limit and presentation
UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT,
UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE, UI_MENU_OV_UPSCALER, UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT,
UI_MENU_OV_SHOWN, // frame generation: the pictures shown a second
UI_MENU_OV_FMT_SIZE, // "%ux%u"
UI_MENU_OV_FMT_SCENE, // "%ux%u, %.0f%%": the scene and its share of the game image's width
+2
View File
@@ -13,6 +13,7 @@
#include "platform/platform.h"
#include "vk_dlaa.h"
#include "vk_fg.h"
#include "vk_fsr3.h"
static VkCtx g_vk;
static int g_ready;
@@ -484,6 +485,7 @@ static void destroy_all(void) {
gfx_window_release_vk();
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_astc_release();
if (g_vk.device) vk_deswz_release();
if (g_vk.device) vk_crumbs_release();
+104 -16
View File
@@ -26,6 +26,7 @@
#include "nvn_api.h"
#include "vk_exec.h"
#include "vk_fg.h"
#include "vk_fsr3.h"
#include "vk_rec.h"
#include "dlaa_mv_spv.h"
@@ -103,12 +104,29 @@ static int p_getp(const NgxParam *p, const char *n, void **v) { return NGX_OK(((
#define DLSS_MODEL "libnvidia-ngx-dlss.so.<version>"
#endif
// NGX is brought up only when dlaa is on 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 DLAA off. So
// dlaa applies after a restart; switched off, nothing else of DLAA runs.
// 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.
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;
}
return e;
}
// 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");
}
// 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.
int vk_dlaa_wanted(void) {
static int wanted = -1;
if (wanted < 0) wanted = cfg_bool("TOTK_DLAA");
if (wanted < 0) wanted = vk_upscaler_engine() == UPSCALER_DLSS;
return wanted;
}
@@ -191,7 +209,16 @@ static int vtable_ok(void) {
return ok;
}
// Per-object motion (vk_mvprev.c, vk_usnap.c's host copy, vk_exec_draw.c's motion draws) runs for the engine that
// reads the motion image: 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.
static int objmv;
int vk_objmv_wanted(void) { return objmv; }
void vk_dlaa_init(void) {
objmv = vk_upscaler_engine() == UPSCALER_FSR3;
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];
@@ -215,6 +242,7 @@ void vk_dlaa_init(void) {
p_geti(caps, "SuperSampling.NeedsUpdatedDriver", &driver);
}
N.available = avail != 0;
objmv = N.available; // vk_dlaa_available: wanted, and DLSS came up
rt_log("dlaa: NGX up; DLSS %s%s", avail ? "available" : "NOT available (is " DLSS_MODEL " next to the executable?)",
driver ? "; the driver needs an update" : "");
}
@@ -313,17 +341,32 @@ 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 camera motion is in the motion image (fg_motion)
int fsr; // the engine is AMD FSR 3.1 (scene_upscaler = fsr3 at start), else 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;
static int dl_active(void) { return N.available && !D.failed && D.on; }
// 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.
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;
}
// 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.
int vk_upscaler_missing(int engine) {
if (engine != UPSCALER_DLSS) return 0;
if (!res_dlss_dll()) return UPSCALER_MISSING_DLL;
if (N.tried) return N.available ? 0 : UPSCALER_MISSING_GPU;
return vk_ctx()->props.vendorID == 0x10de ? 0 : UPSCALER_MISSING_GPU;
}
static void dl_fail(const char *what, NgxResult r) {
rt_log("dlaa: %s failed (%08x): DLAA off for this run", what, (unsigned)r);
D.failed = 1;
@@ -1229,6 +1272,41 @@ 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).
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;
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;
if (cut) D.reset = 1, D.why[1]++;
uint64_t now = plat_now_ns();
double dt = D.last_eval_ns ? (now - D.last_eval_ns) / 1e6 : 0;
D.last_eval_ns = now;
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, .fence = ex->fence};
uint64_t c0 = timed ? kern_now_ns() : 0;
int 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 1;
}
// dst: the target DLSS's picture goes to, NULL for the light target itself (DLAA in place).
static void evaluate(VkExec *ex, const VkExecTarget *dst) {
const VkExecTarget *t = &D.color, *z = &D.depth;
@@ -1244,7 +1322,7 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) {
struct Size *e = size_for(cb, w, h, ow, oh, 1);
if (!e) return dl_fail("work image creation", 0);
if (e != D.last) D.reset = 1, D.why[0]++, e->chars_ok = 0; // another size's history is from another moment
if (!D.params && !NGX_OK(N.alloc_params(&D.params))) return dl_fail("parameter allocation", 0);
if (!D.fsr && !D.params && !NGX_OK(N.alloc_params(&D.params))) return dl_fail("parameter allocation", 0);
NgxParam *p = D.params;
VkImageView zv = vk_exec_target_view(z->img, z->format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT, z->level,
z->base_layer, 1, 0);
@@ -1252,7 +1330,7 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) {
static int no_mv = -1;
if (no_mv < 0) no_mv = !rt_knob("DLAA_MV", "1"); // TOTK_DLAA_MV=0: zero motion (test)
int masked = 0;
if (no_mv || !mv_pass(ex, e, zv, jx, jy, char_bias(), &masked, 1)) {
if (no_mv || !mv_pass(ex, e, zv, jx, jy, D.fsr ? 0.0f : char_bias(), &masked, 1)) {
VkClearColorValue zero = {{0, 0, 0, 0}};
VkImageSubresourceRange all = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
vkCmdClearColorImage(cb, e->mv, VK_IMAGE_LAYOUT_GENERAL, &zero, 1, &all);
@@ -1261,12 +1339,16 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) {
}
VkImageView cv = vk_exec_target_view(t->img, t->format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, t->level,
t->base_layer, 1, 0);
struct Snap *mk = D.mv_samp ? mask_pass(cb, cv, w, h) : NULL;
struct Snap *mk = !D.fsr && D.mv_samp ? mask_pass(cb, cv, w, h) : NULL; // a bias mask is DLSS's only
int timed = T.on > 0 && T.used[T.slot]; // mv_pass began this frame's slot
if (timed) times_mark(cb, T_DL0);
uint64_t c0 = timed ? kern_now_ns() : 0;
rec_drain(); // NGX records into the command buffer itself: the recorder thread must have made every call so far
rec_drain(); // NGX and FSR record into the command buffer themselves: the recorder thread must have made every call
if (timed) T.cpu_drain += kern_now_ns() - c0;
if (D.fsr) {
if (!fsr_evaluate(ex, e, t, z, ow, oh, jx, jy, timed)) return;
goto engine_done;
}
if (!e->feat) {
p_setu(p, "CreationNodeMask", 1);
p_setu(p, "VisibilityNodeMask", 1);
@@ -1337,7 +1419,8 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) {
NgxResult r = N.evaluate(cb, e->feat, p, NULL);
if (timed) T.cpu_ngx += kern_now_ns() - c0;
if (!NGX_OK(r)) return dl_fail("DLSS evaluation", r);
if (timed) times_mark(cb, T_DL1); // through the recorder, after NGX's own commands
engine_done:
if (timed) times_mark(cb, T_DL1); // through the recorder, after NGX's or FSR's own commands
D.reset = 0;
D.last = e, e->used = D.evals + 1;
full_barrier(cb);
@@ -1365,10 +1448,10 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) {
next_jitter(w, ow);
cam_unjitter(ex);
if (++D.evals == 1 || D.evals == 300 || D.evals % 3600 == 0) // 300: one early line with the frames counted
rt_log("dlaa: %llu frames anti-aliased (scene %ux%u, output %ux%u; %llu before the effects, %llu frames without the "
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, w, h, ow, oh, (unsigned long long)D.fx_frames, (unsigned long long)D.frames_missed,
(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.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);
@@ -1750,14 +1833,19 @@ void vk_dlaa_frame(void) {
vk_dlaa_swap_img = NULL, vk_dlaa_swap_view = VK_NULL_HANDLE;
dlss_mode();
preset_check();
int on = N.available && cfg_bool("TOTK_DLAA");
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();
vk_fg_frame();
int fg = vk_fg_wanted(on && !D.failed);
// frame generation with an upscaler is not built yet: with FSR 3.1 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)");
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 ? "on" : "off");
if (on != D.on) rt_log("dlaa: %s", on ? (fsr ? "on with FSR 3.1" : "on") : "off");
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.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
D.reset = 1, D.cam_prev_ok = 0, D.jit_ok = D.jit_used = D.armed = D.done = D.gbuf = D.ended = D.up = 0;
D.fx_seen = D.fx_open = D.fx_bad = 0, D.fx_steady = 0;
+5 -2
View File
@@ -1,4 +1,5 @@
// DLAA (vk_dlaa.c): NVIDIA DLSS at the scene's own size, behind TOTK_DLAA (totk.ini dlaa = 1).
// 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).
#pragma once
#include "vk.h"
@@ -6,7 +7,7 @@
// output renders 640 wide, smaller windows less.
#define DLAA_SCENE_MIN_W 320u
int vk_dlaa_wanted(void); // the setting is on (the device may still lack DLSS)
int vk_dlaa_wanted(void); // DLSS is the scene upscaler picked at start (the device may still lack it)
// vk_device.c: NGX's instance and device extensions join the lists (room for max names); vk_dlaa_init after the
// device exists brings NGX up and checks that DLSS is available.
void vk_dlaa_instance_exts(const char **ext, uint32_t *n, uint32_t max);
@@ -14,6 +15,8 @@ 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 (after vk_dlaa_init): vk_dlaa_available, or FSR 3.1 picked as the scene upscaler.
int vk_objmv_wanted(void);
// vk_exec.c vk_exec_pass_begin, once the pass's targets are resolved and before its barrier: arms the frame on the
// scene's light target or, at the first quarter-width pass after it, runs DLAA on that target. Each present ends the
// frame (vk_dlaa_frame).
+1 -1
View File
@@ -3527,7 +3527,7 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
}
D->B.st_pm = D->PM.valid; // st is this draw's state, which PM holds while valid
vk_dlaa_draw(ex);
int mo = ex->chunked && vk_dlaa_available();
int mo = ex->chunked && vk_objmv_wanted();
if (mo) plat_mutex_lock(&mo_lock);
vk_mvsurvey_draw(ex);
vk_mvprev_draw(ex);
+2
View File
@@ -22,6 +22,7 @@
// The present (vk_backend.c present_pair) shows it before the frame, through vk_fg_present_gen (TOTK_FG_TEST shows it, or
// the picture before the HUD, in place of the frame instead, for checks only).
#include "vk_fg.h"
#include "vk_fsr3.h"
#include <malloc.h>
#include <math.h>
@@ -56,6 +57,7 @@ extern "C" FfxErrorCode ffxGetPermutationBlobByIndex(FfxEffect effect, FfxPass p
memcpy(out, &ffx_of_blobs[pass], sizeof *out);
return FFX_OK;
}
if (effect == FFX_EFFECT_FSR3UPSCALER && vk_fsr3_blob(pass, options, out)) return FFX_OK; // the upscaler's (vk_fsr3.cpp)
rt_log("fg: no shader for effect %d pass %d", (int)effect, (int)pass);
return FFX_ERROR_INVALID_ARGUMENT;
}
+265
View File
@@ -0,0 +1,265 @@
// AMD FSR 3.1 temporal upscaler (scene_upscaler = fsr3): the FidelityFX SDK 1.1.4's upscaler context
// (third_party/FidelityFX, MIT) on the SDK's Vulkan backend, driven directly, without the ffx-api DLL layer.
//
// Ported from Savage Wind (https://github.com/Revivedx/SavageWindRecomp @ bf6146c14c37fee8781a601e5a544b93dff6d75e,
// MIT), runtime/nvn/vulkan/fsr3.cpp: the context with the three images FSR 3.1 has the application own (dilated depth
// and motion vectors, the previous frame's nearest depth, made by the backend for a context of their own as the SDK's
// ffx_fsr3.cpp does), the resource wrapping and the dispatch parameters; framegen.cpp for the 16-bit blob choice.
//
// What differs from Savage Wind: the input is the scene's linear light before the bloom (vk_dlaa.c's DLSS point), so
// the context and the shaders are HDR; one context per output size with the output as its largest render size, so the
// upscaling modes (which change while the game runs) and the dynamic resolution tiers need no new context; the backend's
// per-frame rings are guarded against more frames in flight than they hold (wait_ring).
//
// Everything is recorded into the replay's command buffer by vk_dlaa.c evaluate, on the replay thread, after it drained
// the recorder thread; the SDK binds pipelines and descriptor sets of its own, so vk_dlaa.c makes the next draw bind
// everything again.
#include "vk_fsr3.h"
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <FidelityFX/host/backends/vk/ffx_vk.h>
#include <FidelityFX/host/ffx_fsr3upscaler.h>
#include <ffx_shader_blobs.h>
extern "C" {
#include "cfg.h"
#include "host.h"
#include "vk.h"
}
// The shaders: tools/ffx_shaders.py --effects fu (wave32; HDR input, render-size motion vectors without jitter, depth
// not inverted; 32-bit and 16-bit floats) in place of the SDK's FidelityFX_SC permutation tables
#include "ffx_fsr3upscaler_vk.h"
enum { FU_PERM_FP16 = 1 << 7 }; // ffx_fsr3upscaler_private.h FSR3UPSCALER_SHADER_PERMUTATION_ALLOW_FP16
static struct {
bool live, failed, fp16;
FfxFsr3UpscalerContext ctx;
FfxInterface iface;
void *scratch;
FfxUInt32 shared_id;
FfxResourceInternal shared[3];
uint32_t ow, oh;
// the timeline values of the last dispatches: the backend reuses its descriptor sets, constant buffers and image
// views after FFX_MAX_QUEUED_FRAMES dispatches (wait_ring)
uint64_t ring[FFX_MAX_QUEUED_FRAMES];
uint32_t n;
uint64_t waits;
} F;
extern "C" int vk_fsr3_blob(uint32_t pass, uint32_t options, void *out) {
if (pass >= sizeof ffx_fu_blobs[0] / sizeof ffx_fu_blobs[0][0] || !ffx_fu_blobs[0][pass].data) return 0;
// the 16-bit version where the SDK asks for it (the backend found shaderFloat16) and the device has what its
// SPIR-V declares (Float16, Int16), which the runtime's device enables wherever the driver reports it
int half = (options & FU_PERM_FP16) && F.fp16;
memcpy(out, &ffx_fu_blobs[half][pass], sizeof(FfxShaderBlob));
return 1;
}
// The backend calls a few extension functions unchecked: the debug labels (VK_EXT_debug_utils, an instance extension
// the runtime enables only with validation) and vkGetBufferMemoryRequirements2KHR (core since 1.1 without the suffix)
static VKAPI_ATTR void VKAPI_CALL no_label(VkCommandBuffer, const VkDebugUtilsLabelEXT *) {}
static VKAPI_ATTR void VKAPI_CALL no_label_end(VkCommandBuffer) {}
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL device_proc(VkDevice d, const char *name) {
PFN_vkVoidFunction f = vkGetDeviceProcAddr(d, name);
if (f) return f;
if (!strcmp(name, "vkGetBufferMemoryRequirements2KHR")) return vkGetDeviceProcAddr(d, "vkGetBufferMemoryRequirements2");
if (!strcmp(name, "vkCmdBeginDebugUtilsLabelEXT")) return (PFN_vkVoidFunction)no_label;
if (!strcmp(name, "vkCmdEndDebugUtilsLabelEXT")) return (PFN_vkVoidFunction)no_label_end;
return nullptr;
}
// The backend's scratch memory holds its context, whose members the compiler aligns past malloc's 16 bytes
static void *scratch_alloc(size_t n) {
#ifdef _WIN32
void *p = _aligned_malloc(n, 256);
#else
void *p = aligned_alloc(256, n);
#endif
if (p) memset(p, 0, n);
return p;
}
static void scratch_free(void *p) {
#ifdef _WIN32
_aligned_free(p);
#else
free(p);
#endif
}
static void message(FfxMsgType type, const wchar_t *msg) {
static int n;
if (n++ >= 32) return; // (the debug checks repeat every frame)
char buf[512];
snprintf(buf, sizeof buf, "%ls", msg);
rt_log("fsr3: SDK %s: %s", type == FFX_MESSAGE_TYPE_ERROR ? "error" : "warning", buf);
}
// The SDK's objects: the device is idle or the context never recorded anything.
static void destroy(void) {
if (F.live) {
for (int i = 0; i < 3; i++) F.iface.fpDestroyResource(&F.iface, F.shared[i], F.shared_id);
F.iface.fpDestroyBackendContext(&F.iface, F.shared_id);
ffxFsr3UpscalerContextDestroy(&F.ctx);
}
scratch_free(F.scratch);
F.scratch = nullptr;
F.live = false;
}
static int fp16_usable(VkPhysicalDevice phys) {
VkPhysicalDeviceVulkan12Features f12 = {};
f12.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES;
VkPhysicalDeviceFeatures2 f2 = {};
f2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
f2.pNext = &f12;
vkGetPhysicalDeviceFeatures2(phys, &f2);
return f12.shaderFloat16 && f2.features.shaderInt16;
}
#define TRY(x, what) \
do { \
FfxErrorCode e_ = (x); \
if (e_ != FFX_OK) { \
rt_log("fsr3: %s failed (%#x) at %ux%u: FSR 3.1 off for this run", what, (unsigned)e_, ow, oh); \
return false; \
} \
} while (0)
static bool create(VkCtx *c, uint32_t ow, uint32_t oh) {
enum { CONTEXTS = FFX_FSR3UPSCALER_CONTEXT_COUNT + 1 }; // (+ the shared images')
size_t n = (ffxGetScratchMemorySizeVK(c->phys, CONTEXTS) + 255) & ~(size_t)255;
if (!(F.scratch = scratch_alloc(n))) {
rt_log("fsr3: no memory for the backend (%zu bytes): FSR 3.1 off for this run", n);
return false;
}
VkDeviceContext dc = {c->device, c->phys, device_proc}; // (ffxGetDeviceVK keeps a copy)
FfxFsr3UpscalerContextDescription cd = {};
TRY(ffxGetInterfaceVK(&cd.backendInterface, ffxGetDeviceVK(&dc), F.scratch, n, CONTEXTS), "the backend");
// HDR: the scene's linear light. Render-size motion vectors without the jitter (the defaults), standard depth with a
// finite far plane. TOTK_FSR3_DEBUG=1: the SDK's checks of the inputs, in the log.
cd.flags = FFX_FSR3UPSCALER_ENABLE_HIGH_DYNAMIC_RANGE | FFX_FSR3UPSCALER_ENABLE_DYNAMIC_RESOLUTION |
(rt_knob("FSR3_DEBUG", "0") ? FFX_FSR3UPSCALER_ENABLE_DEBUG_CHECKING : 0);
cd.maxRenderSize = {ow, oh};
cd.maxUpscaleSize = {ow, oh};
cd.fpMessage = message;
TRY(ffxFsr3UpscalerContextCreate(&F.ctx, &cd), "context creation");
F.iface = cd.backendInterface;
F.live = true; // (from here destroy() takes the context down)
FfxFsr3UpscalerSharedResourceDescriptions sd = {};
TRY(ffxFsr3UpscalerGetSharedResourceDescriptions(&F.ctx, &sd), "the shared images' descriptions");
TRY(F.iface.fpCreateBackendContext(&F.iface, FFX_EFFECT_SHAREDRESOURCES, nullptr, &F.shared_id), "the shared context");
const FfxCreateResourceDescription *rd[3] = {&sd.dilatedDepth, &sd.dilatedMotionVectors, &sd.reconstructedPrevNearestDepth};
for (int i = 0; i < 3; i++) TRY(F.iface.fpCreateResource(&F.iface, rd[i], F.shared_id, &F.shared[i]), "a shared image");
F.ow = ow, F.oh = oh, F.n = 0;
memset(F.ring, 0, sizeof F.ring);
FfxEffectMemoryUsage mu = {};
ffxFsr3UpscalerContextGetGpuMemoryUsage(&F.ctx, &mu);
rt_log("fsr3: FSR 3.1 context up to %ux%u -> %ux%u (HDR, %s floats), %.1f MiB", ow, oh, ow, oh,
F.fp16 ? "16-bit" : "32-bit", (double)mu.totalUsageInBytes / 1048576.0);
return true;
}
// An image of the runtime as the SDK sees it: every one is in GENERAL, which the backend takes both states as and
// returns it to after the dispatch (UnregisterResourcesVK). A D32F image is a depth target to it (its view's aspect).
static FfxResource res(VkImage img, VkFormat f, uint32_t w, uint32_t h, bool write, const wchar_t *name) {
VkImageCreateInfo ci = {};
ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
ci.imageType = VK_IMAGE_TYPE_2D;
ci.format = f;
ci.extent = {w, h, 1};
ci.mipLevels = 1;
ci.arrayLayers = 1;
ci.samples = VK_SAMPLE_COUNT_1_BIT;
ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT | (write ? VK_IMAGE_USAGE_STORAGE_BIT : 0);
return ffxGetResourceVK((void *)img, ffxGetImageResourceDescriptionVK(img, ci, write ? FFX_RESOURCE_USAGE_UAV
: FFX_RESOURCE_USAGE_READ_ONLY), name, write ? FFX_RESOURCE_STATE_UNORDERED_ACCESS
: FFX_RESOURCE_STATE_GENERIC_READ);
}
// The backend writes a dispatch's descriptor sets and constants into rings FFX_MAX_QUEUED_FRAMES deep and destroys the
// image views of the dispatch that many back at the end of each one, without knowing the GPU. With the game's two or
// three frames in flight that dispatch is long done; should it not be, its submission is waited for here (counted).
static void wait_ring(uint64_t fence) {
if (F.n >= FFX_MAX_QUEUED_FRAMES - 1) {
uint64_t back = F.ring[(F.n + 1) % FFX_MAX_QUEUED_FRAMES]; // the dispatch FFX_MAX_QUEUED_FRAMES - 1 back
if (back && vk_sync_fence_done() < back) {
if (!F.waits++) rt_log("fsr3: waiting for the submission of a dispatch %d back (more frames in flight than "
"the SDK's rings hold)", FFX_MAX_QUEUED_FRAMES - 1);
vk_sync_fence_wait(back, 2000000000ull);
}
}
F.ring[F.n % FFX_MAX_QUEUED_FRAMES] = fence;
}
extern "C" int fsr3_dispatch(VkCommandBuffer cb, const Fsr3Frame *f) {
if (F.failed) return 0;
VkCtx *c = vk_ctx();
if (!F.live || f->ow != F.ow || f->oh != F.oh) {
if (F.live) {
vkDeviceWaitIdle(c->device); // what the old context recorded is queued or submitted
destroy();
}
F.fp16 = fp16_usable(c->phys);
if (!create(c, f->ow, f->oh)) {
destroy();
F.failed = true;
return 0;
}
}
if (f->w > F.ow || f->h > F.oh) {
rt_log("fsr3: a %ux%u scene is larger than the %ux%u output: FSR 3.1 off for this run", f->w, f->h, F.ow, F.oh);
F.failed = true;
return 0;
}
wait_ring(f->fence);
FfxFsr3UpscalerDispatchDescription dd = {};
dd.commandList = ffxGetCommandListVK(cb);
dd.color = res(f->color, f->color_format, f->w, f->h, false, L"FSR3_Color");
dd.depth = res(f->depth, VK_FORMAT_D32_SFLOAT, f->w, f->h, false, L"FSR3_Depth");
dd.motionVectors = res(f->mv, VK_FORMAT_R16G16_SFLOAT, f->w, f->h, false, L"FSR3_MotionVectors");
dd.output = res(f->out, VK_FORMAT_R16G16B16A16_SFLOAT, f->ow, f->oh, true, L"FSR3_Output");
dd.dilatedDepth = F.iface.fpGetResource(&F.iface, F.shared[0]);
dd.dilatedMotionVectors = F.iface.fpGetResource(&F.iface, F.shared[1]);
dd.reconstructedPrevNearestDepth = F.iface.fpGetResource(&F.iface, F.shared[2]);
// (no reactive or transparency mask, no exposure: the SDK's defaults, zero and exposure 1)
dd.jitterOffset = {f->jx, f->jy};
dd.motionVectorScale = {1.0f, 1.0f}; // render pixels already
dd.renderSize = {f->w, f->h};
dd.upscaleSize = {f->ow, f->oh};
dd.enableSharpening = false; // the present's RCAS (upscaler = fsr, sharpness) is the one sharpening pass
dd.sharpness = 0.0f;
dd.frameTimeDelta = f->dt_ms;
dd.preExposure = 1.0f;
dd.reset = f->reset != 0;
dd.cameraNear = f->near_m;
dd.cameraFar = f->far_m;
dd.cameraFovAngleVertical = f->fov_y;
dd.viewSpaceToMetersFactor = 1.0f; // (TotK's units are meters)
static int view = -1; // TOTK_FSR3_VIEW=1: FSR's own debug view of its inputs and state
if (view < 0) view = rt_knob("FSR3_VIEW", "0");
if (view) dd.flags |= FFX_FSR3UPSCALER_DISPATCH_DRAW_DEBUG_VIEW;
FfxErrorCode e = ffxFsr3UpscalerContextDispatch(&F.ctx, &dd);
F.n++;
if (e != FFX_OK) {
rt_log("fsr3: dispatch failed (%#x) at %ux%u -> %ux%u: FSR 3.1 off for this run", (unsigned)e, f->w, f->h, f->ow,
f->oh);
F.failed = true;
return 0;
}
return 1;
}
extern "C" void fsr3_release(void) {
VkCtx *c = vk_ctx();
if (!c || !c->device || (!F.live && !F.scratch)) return;
vkDeviceWaitIdle(c->device);
if (F.waits) rt_log("fsr3: %llu dispatches waited for an earlier one's submission", (unsigned long long)F.waits);
destroy();
}
+40
View File
@@ -0,0 +1,40 @@
// AMD FSR 3.1 temporal upscaler (vk_fsr3.cpp): the FidelityFX SDK 1.1.4's upscaler (third_party/FidelityFX, MIT) on
// its Vulkan backend, the other engine of vk_dlaa.c's DLSS point. The same scene light, depth, motion vectors and
// jitter go to FSR 3.1 instead of NGX, on any GPU the back end runs on. Plain C interface: the SDK is C++.
#pragma once
#include <stdint.h>
#include <vulkan/vulkan.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
VkImage color; // the scene's light (level 0, layer 0; R11G11B10F or RGBA16F, linear), w x h
VkFormat color_format;
VkImage depth; // its D32F depth (level 0, layer 0), w x h, standard direction (0 near)
VkImage mv; // RG16F motion vectors, w x h: last frame's window position minus this frame's, render
// pixels, without the jitter (vk_dlaa.c mv_pass, with the per-object pass)
VkImage out; // RGBA16F with storage, ow x oh: the upscaled scene
uint32_t w, h, ow, oh;
float jx, jy; // the jitter the scene was drawn with, render pixels (x right, y down)
float near_m, far_m, fov_y; // the camera's planes (m) and vertical field of view (radians)
float dt_ms; // time since the last upscaled frame
int reset; // no usable history (a cut, a new size, the first frame)
uint64_t fence; // the submission's timeline value (VkExec.fence)
} Fsr3Frame;
// Records FSR 3.1 into cb (every image in VK_IMAGE_LAYOUT_GENERAL, left so; no render pass open; recorder drained by the
// caller). The context is made at the first call and made again when the output size changes; the scene may be any
// size up to the output (the modes, the dynamic resolution). 0 when it failed (logged; FSR 3.1 stays off for the run).
int fsr3_dispatch(VkCommandBuffer cb, const Fsr3Frame *f);
// vk_device.c destroy_all, before the device goes away; harmless when nothing was made.
void fsr3_release(void);
// vk_fg.cpp ffxGetPermutationBlobByIndex for FFX_EFFECT_FSR3UPSCALER: the blob of pass (FfxFsr3UpscalerPass) for the
// SDK's permutation options into out (an FfxShaderBlob). 0: no shader for that pass.
int vk_fsr3_blob(uint32_t pass, uint32_t options, void *out);
#ifdef __cplusplus
}
#endif
+7 -6
View File
@@ -1,6 +1,6 @@
// Last frame's object and bone blocks, for per-object motion vectors (TOTK_DLAA_OBJMV, on with DLAA). The banks kept
// start as c5, c7 and c14 and grow with what the vertex shader variants read (vk_mvprev_want); c7 and c5 are described
// here, the others follow the same two-copy rule.
// Last frame's object and bone blocks, for per-object motion vectors (TOTK_DLAA_OBJMV, on with DLSS or FSR 3.1). The
// banks kept start as c5, c7 and c14 and grow with what the vertex shader variants read (vk_mvprev_want); c7 and c5 are
// described here, the others follow the same two-copy rule.
//
// The scene's vertex shaders read an object's place from bank c7 (gsys_shape: one 3x4 matrix at the start of a
// 0x100 block) and a skinned object's bones from c5 (gsys_skeleton: a run of 3x4 matrices), of this frame only. The
@@ -172,8 +172,9 @@ static void mvprev_draw_(VkExec *ex) {
}
void vk_mvprev_frame(void) {
// without DLSS (no NGX, no RTX GPU, dlaa = 0) nothing reads last frame's blocks: P.on stays 0, no tables
if (!vk_dlaa_available()) return;
// without an upscaler that reads the motion (DLSS with NGX up, or FSR 3.1) nothing reads last frame's blocks: P.on
// stays 0, no tables
if (!vk_objmv_wanted()) return;
if (P.knob < 0) {
P.knob = rt_knob("DLAA_OBJMV", "1");
if (P.knob) {
@@ -186,7 +187,7 @@ void vk_mvprev_frame(void) {
P.timed = rt_knob("MVOBJ_TIMES", "0");
}
}
int on = P.knob && cfg_bool("TOTK_DLAA");
int on = P.knob && vk_upscaler_on();
if (on != (P.on > 0)) {
P.on = on ? 1 : -1;
if (P.t[0]) memset(P.t[0], 0, TABLE * sizeof(Seen)), memset(P.t[1], 0, TABLE * sizeof(Seen));
+5 -4
View File
@@ -37,9 +37,10 @@ typedef struct Arena {
VkBuffer buf;
VmaAllocation alloc;
uint8_t *map;
uint8_t *cpu; // with DLSS (vk_dlaa_available), the same bytes in host memory for the CPU's reads (vk_usnap_bytes):
// map is often device memory through the BAR, written fast but read back at about a microsecond a
// cache line. Without DLSS nothing reads them back, and the bytes go into map in one copy.
uint8_t *cpu; // with the per-object motion (vk_objmv_wanted: DLSS or FSR 3.1), the same bytes in host memory for
// the CPU's reads (vk_usnap_bytes): map is often device memory through the BAR, written fast but
// read back at about a microsecond a cache line. Without it nothing reads them back, and the bytes
// go into map in one copy.
uint64_t size;
} Arena;
@@ -289,7 +290,7 @@ void vk_usnap_begin(const uint64_t *handles, int n, uint64_t fence) {
if (!U.nreg) return;
if (!(U.arena = arena_get(total))) return;
uint8_t *dst = U.arena->map;
if (vk_dlaa_available()) {
if (vk_objmv_wanted()) {
if (!U.arena->cpu && !(U.arena->cpu = malloc(U.arena->size))) rt_fatal("vk_usnap: out of memory");
dst = U.arena->cpu;
}
+51 -8
View File
@@ -1,20 +1,24 @@
#!/usr/bin/env python3
"""FidelityFX frame interpolation and optical flow shaders -> one C header (runtime/vk_fg.cpp).
"""FidelityFX frame interpolation, optical flow and FSR 3 upscaler shaders -> C headers (runtime/vk_fg.cpp,
runtime/vk_fsr3.cpp).
Ported from Savage Wind (https://github.com/Revivedx/SavageWindRecomp, MIT), tools/ffx_shaders.py, without its FSR 3
upscaler effect.
Ported from Savage Wind (https://github.com/Revivedx/SavageWindRecomp, MIT), tools/ffx_shaders.py.
The SDK builds its shader "permutation" headers with FidelityFX_SC.exe (a Windows-only wrapper around glslang that
also writes each shader's resource bindings). This does the same with glslangValidator and a small SPIR-V reader,
for the permutations used here only: wave32, 32-bit floats, low-resolution motion vectors without jitter, and both
depth directions (frame interpolation); SDR luma (optical flow). The backend (ffx_vk.cpp) takes each blob with its
depth directions (frame interpolation); SDR luma (optical flow); HDR input (the scene's linear light before the
bloom), low-resolution motion vectors without jitter, depth not inverted, the reference (not LUT) Lanczos and Savage
Wind's Catmull-Rom history reprojection, in 32-bit and 16-bit floats (FSR 3 upscaler; its accumulate pass twice,
without and with sharpening, FFX_FSR3UPSCALER_PASS_ACCUMULATE / _SHARPEN). The backend (ffx_vk.cpp) takes each blob with its
bindings by name, as FidelityFX_SC writes them. The header is committed (AMD shader builds, no game data), so building
totk.exe needs no shader compiler; run this after changing the GLSL or this script:
python tools/ffx_shaders.py [<output header>] [<glslangValidator>]
python tools/ffx_shaders.py [--effects fi,of | fu] [<output header>] [<glslangValidator>]
The defaults are runtime/third_party/FidelityFX/spirv/ffx_shaders_vk.h and glslangValidator from MSYS2 UCRT64
(C:/msys64/ucrt64/bin) or PATH; the Vulkan SDK's works too.
--effects picks the header: fi,of (the default: frame interpolation and optical flow, spirv/ffx_shaders_vk.h) or fu
(the FSR 3 upscaler, spirv/ffx_fsr3upscaler_vk.h), so that regenerating one does not rewrite the other's blobs. The
other defaults are glslangValidator from MSYS2 UCRT64 (C:/msys64/ucrt64/bin) or PATH; the Vulkan SDK's works too.
"""
import os
import struct
@@ -41,6 +45,21 @@ FI_DEFS = ['-DFFX_FRAMEINTERPOLATION_OPTION_UPSAMPLE_SAMPLERS_USE_DATA_HALF=0',
'-DFFX_FRAMEINTERPOLATION_OPTION_LOW_RES_MOTION_VECTORS=1',
'-DFFX_FRAMEINTERPOLATION_OPTION_JITTER_MOTION_VECTORS=0']
OF_DEFS = ['-DFFX_OPTICALFLOW_OPTION_HDR_COLOR_INPUT=0']
FU_PASSES = [ # FfxFsr3UpscalerPass order: (shader, sharpening); None: no shader (the deprecated TCR pass)
('prepare_inputs_pass', 0), ('luma_pyramid_pass', 0), ('shading_change_pyramid_pass', 0), ('shading_change_pass', 0),
('prepare_reactivity_pass', 0), ('luma_instability_pass', 0), ('accumulate_pass', 0), ('accumulate_pass', 1),
('rcas_pass', 0), ('debug_view_pass', 0), ('autogen_reactive_pass', 0), None]
FU_DEFS = ['-DFFX_FSR3UPSCALER_OPTION_UPSAMPLE_SAMPLERS_USE_DATA_HALF=0',
'-DFFX_FSR3UPSCALER_OPTION_ACCUMULATE_SAMPLERS_USE_DATA_HALF=0',
'-DFFX_FSR3UPSCALER_OPTION_REPROJECT_SAMPLERS_USE_DATA_HALF=1',
'-DFFX_FSR3UPSCALER_OPTION_POSTPROCESSLOCKSTATUS_SAMPLERS_USE_DATA_HALF=0',
'-DFFX_FSR3UPSCALER_OPTION_UPSAMPLE_USE_LANCZOS_TYPE=2',
'-DFFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE=2',
'-DFFX_FSR3UPSCALER_OPTION_REPROJECT_CATMULL_ROM_5=1',
'-DFFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT=1',
'-DFFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS=1',
'-DFFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS=0',
'-DFFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH=0']
# SPIR-V opcodes / enums used below
OP_NAME, OP_ENTRY, OP_CONSTANT, OP_DECORATE, OP_MEMBER_DECORATE = 5, 15, 43, 71, 72
@@ -134,8 +153,13 @@ def default_glslang():
def main():
args = sys.argv[1:]
effects = {'fi', 'of'}
if '--effects' in args:
k = args.index('--effects')
effects = set(args[k + 1].split(','))
del args[k:k + 2]
sdk = str(ROOT / 'runtime' / 'third_party' / 'FidelityFX' / 'sdk')
out = args[0] if args else str(ROOT / 'runtime' / 'third_party' / 'FidelityFX' / 'spirv' / 'ffx_shaders_vk.h')
spirv = ROOT / 'runtime' / 'third_party' / 'FidelityFX' / 'spirv'
out = args[0] if args else str(spirv / ('ffx_fsr3upscaler_vk.h' if effects == {'fu'} else 'ffx_shaders_vk.h'))
glslang = args[1] if len(args) > 1 else default_glslang()
gpu = os.path.join(sdk, 'include', 'FidelityFX', 'gpu')
shaders = os.path.join(sdk, 'src', 'backends', 'vk', 'shaders')
@@ -150,6 +174,15 @@ def main():
src = os.path.join(shaders, 'opticalflow', 'ffx_opticalflow_%s.glsl' % p)
spv = compile_glsl(glslang, src, [gpu, os.path.join(gpu, 'opticalflow')], OF_DEFS)
blobs.append(('of_%s' % p, spv, reflect(spv)))
for half in (0, 1) if 'fu' in effects else (): # (16-bit floats where the SDK asks and the device has them)
for e in FU_PASSES:
if e is None:
continue
p, sharpen = e
src = os.path.join(shaders, 'fsr3upscaler', 'ffx_fsr3upscaler_%s.glsl' % p)
spv = compile_glsl(glslang, src, [gpu, os.path.join(gpu, 'fsr3upscaler')],
FU_DEFS + ['-DFFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING=%d' % sharpen], half)
blobs.append(('fu%d_%s_%d' % (half, p, sharpen), spv, reflect(spv)))
L = ['// Generated by tools/ffx_shaders.py from the AMD FidelityFX SDK (MIT, see runtime/third_party/FidelityFX/LICENSE.txt).',
'// Do not edit.', '#pragma once', '#include <stdint.h>', '']
for cname, spv, refl in blobs:
@@ -191,6 +224,16 @@ def main():
L.append('static const FfxShaderBlob ffx_of_blobs[%d] = {' % len(OF_PASSES))
L += [blob(c, r) for c, _, r in blobs if c.startswith('of_')]
L.append('};')
if 'fu' in effects:
L.append('// [16-bit floats][FfxFsr3UpscalerPass] (an empty blob: no shader)')
L.append('static const FfxShaderBlob ffx_fu_blobs[2][%d] = {' % len(FU_PASSES))
refl = {c: r for c, _, r in blobs}
for half in (0, 1):
L.append(' {')
L += [' {},' if e is None else blob('fu%d_%s_%d' % ((half,) + e), refl['fu%d_%s_%d' % ((half,) + e)])
for e in FU_PASSES]
L.append(' },')
L.append('};')
with open(out, 'w', newline='\n') as f:
f.write('\n'.join(L) + '\n')
total = sum(len(s) for _, s, _ in blobs)
+17 -10
View File
@@ -22,8 +22,8 @@
# frame_queue = 0
# Frame generation: off, or fsr3 (AMD FSR 3 frame interpolation). A generated picture goes on screen between each two
# the game draws: twice the pictures, the game at half of fps_limit (the limit counts the pictures shown), the controls
# about half a frame later. For displays of 120 Hz and more; off with DLSS or HDR, and in menus and fades. Applies at
# once.
# about half a frame later. For displays of 120 Hz and more; off with DLSS, FSR 3.1 (scene_upscaler) or HDR, and in
# menus and fades. Applies at once.
# frame_gen = off
# Real-time frame step: game speed follows the clock instead of the frame count.
# realtime = 1
@@ -291,15 +291,22 @@
# shaders (translator patches 0010 and 0017), so the shader cache is rebuilt once after an update. Read at start.
# pcss = 0
# NVIDIA DLSS / DLAA for the 3D scene, on NVIDIA RTX GPUs with the DLSS model from NVIDIA's DLSS SDK next to the
# executable (Windows: nvngx_dlss.dll next to totk.exe; Linux: libnvidia-ngx-dlss.so.<version> next to totk, with the
# NVIDIA driver's libnvidia-ngx.so.1 installed); elsewhere the setting does nothing. The HUD is drawn after it and is not touched.
# Read at start.
# The temporal upscaler for the 3D scene: off (the game's own scaling and FXAA), dlss (NVIDIA DLSS, on NVIDIA RTX GPUs
# with the DLSS model from NVIDIA's DLSS SDK next to the executable: Windows nvngx_dlss.dll next to totk.exe; Linux
# libnvidia-ngx-dlss.so.<version> next to totk, with the NVIDIA driver's libnvidia-ngx.so.1 installed) or fsr3 (AMD FSR
# 3.1 from AMD's FidelityFX SDK, on any GPU). FSR 3.1 below native (dlss = quality and down) pays where the GPU limits
# the frame rate: integrated GPUs, weak cards, 4K output; where the CPU limits it, its own GPU and CPU time make the game
# slower. An engine that cannot run here leaves the game's own scaling in place. The HUD is drawn after it, at the
# output size, and is not touched. The present's upscaler and sharpness below still scale the game image to the window.
# Frame generation stays off with fsr3. Read at start. Without this line, dlaa = 1 (the older switch) means dlss.
# scene_upscaler = off
# The older DLSS switch, read only when scene_upscaler is not set: 1 is scene_upscaler = dlss.
# dlaa = 0
# What DLSS works from: dlaa (the 3D scene at full size), quality, balanced, performance or ultra_performance (the
# scene at 67, 58, 50 or 33 % of the output, scaled up by DLSS; these replace render_scale and sharpen texture filtering
# to match). They apply only with dlaa = 1 and the DLSS model next to the executable; otherwise the scene follows
# render_scale. Changes while the game runs take effect at once (1.4.3; 1.2.1 at the next start).
# The upscaling mode of the scene upscaler, DLSS or FSR 3.1: dlaa (native: the 3D scene at full size, anti-aliased
# only), quality, balanced, performance or ultra_performance (the scene at 67, 58, 50 or 33 % of the output, scaled up by
# the upscaler; these replace render_scale and sharpen texture filtering to match). They apply only while a scene
# upscaler runs; otherwise the scene follows render_scale. Changes while the game runs take effect at once (1.4.3; 1.2.1
# at the next start).
# dlss = dlaa
# The DLSS model: default (NVIDIA's advice per mode: K for dlaa, quality and balanced, M for performance, L for
# ultra_performance), k (K in every mode) or j (the other transformer model: slightly less ghosting behind moving