mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 08:19:56 -04:00
Compare commits
4 Commits
4d5454d380
...
5a69bdc91f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a69bdc91f | ||
|
|
45d0c87423 | ||
|
|
5bdf583331 | ||
|
|
5833ad8e18 |
@@ -106,7 +106,7 @@ folder's `licenses/` and in each component's own folder.
|
||||
| MacNativeGames shader variant list | as in the installer release row above | MIT | `data/shader_list.tsv` |
|
||||
| Weeping of the Empire menu cursor: eui's focus box read through ScreenMgr, BoxCursorMgr and the screens' node lists, AnimButton's hit test, the stale-hit-pane fallback to the parts panes, the three writes of moveBoxCursor, the structure offsets (1.0.0; the ScreenMgr instance placed in 1.4.3 by us) | https://github.com/daniel-madrid-07/weeping-of-the-empire @ `df0586cdc5702ca19bbebfa59697e0b6980f6237` (`engine/runtime/nx2navi_menu_cursor.cpp`), Copyright (c) 2026 daniel-madrid-07 | MIT | `runtime/menu_cursor.c` |
|
||||
| AMD FidelityFX API headers (FSR 3.1 upscaling and frame generation) and its signed Vulkan library | https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK @ `v1.1.4` (`ffx-api/include/ffx_api/`, `PrebuiltSignedDLL/amd_fidelityfx_vk.dll`), Copyright (C) 2024 Advanced Micro Devices, Inc. | MIT | `runtime/third_party/ffx_api/` (unmodified, with `LICENSE.txt`), used by `runtime/vk_ffx.cpp`; the library ships in the build kit's `bin/` and beside the built game (never in this repository) |
|
||||
| AMD FSR SDK API headers (FSR 4 upscaling) and its signed Vulkan libraries | https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK @ `v2.4.0` (`Kits/FidelityFX/api/include/`, `Kits/FidelityFX/upscalers/include/ffx_upscale.h`, `Kits/FidelityFX/signedbin/amd_fidelityfx_loader_vk.dll`, `Kits/FidelityFX/signedbin/amd_fidelityfx_upscaler_vk.dll`), Copyright (C) Advanced Micro Devices, Inc. | MIT | `runtime/third_party/ffx_sdk/` (unmodified, with `LICENSE.txt`), used by `runtime/vk_ffx4.cpp`; the libraries ship in the build kit's `bin/` and beside the built game (never in this repository) |
|
||||
| AMD FSR SDK API headers (FSR 4 upscaling, frame generation) and its signed Vulkan libraries | https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK @ `v2.4.0` (`Kits/FidelityFX/api/include/`, `Kits/FidelityFX/upscalers/include/ffx_upscale.h`, `Kits/FidelityFX/framegeneration/include/`, `Kits/FidelityFX/signedbin/amd_fidelityfx_loader_vk.dll`, `amd_fidelityfx_upscaler_vk.dll`, `amd_fidelityfx_framegeneration_vk.dll`), Copyright (C) Advanced Micro Devices, Inc. | MIT | `runtime/third_party/ffx_sdk/` (unmodified, with `LICENSE.txt`), used by `runtime/vk_ffx4.cpp` and `runtime/vk_fg4.cpp`; the libraries ship in the build kit's `bin/` and beside the built game (never in this repository) |
|
||||
|
||||
## Distributed in the launcher release
|
||||
|
||||
|
||||
@@ -165,7 +165,8 @@ beside the game.
|
||||
`py -I tools\make_game.py --rebuild --out "C:\Games\Ocarina"` to draw them again (it skips everything else).
|
||||
- The build copies NVIDIA's DLSS library `nvngx_dlss.dll` (with `nvngx_dlss-NOTICE.txt`, which names its licence)
|
||||
and FSR 3.1's `amd_fidelityfx_vk.dll` beside `ocarina.exe` from the kit's `bin\`, and FSR 4's
|
||||
`amd_fidelityfx_loader_vk.dll` and `amd_fidelityfx_upscaler_vk.dll` when the kit has both. To use another DLSS version, put
|
||||
`amd_fidelityfx_loader_vk.dll` and `amd_fidelityfx_upscaler_vk.dll` when the kit has both (and
|
||||
`amd_fidelityfx_framegeneration_vk.dll` for `fsr4_fg`). To use another DLSS version, put
|
||||
your own `nvngx_dlss.dll` there: later builds keep it. On Linux the library is `libnvidia-ngx-dlss.so.<version>`
|
||||
(see "Linux").
|
||||
- A kit with `bin\dlssg\` (made with `tools/make_kit.py --dlssg`) also brings DLSS Frame Generation on GeForce RTX 40
|
||||
|
||||
@@ -359,6 +359,7 @@ game folder is the default `<launcher>\game`. The dump is never touched.
|
||||
`--ffx` puts AMD's signed `amd_fidelityfx_vk.dll` (FidelityFX SDK 1.1.4) in the release for FSR 3.1.
|
||||
`--ffx4 <folder>` puts AMD's signed `amd_fidelityfx_loader_vk.dll` and `amd_fidelityfx_upscaler_vk.dll` (FSR SDK
|
||||
2.4.0, the files of its `Kits/FidelityFX/signedbin/`) in the release for FSR 4; without it the menu offers no FSR 4.
|
||||
`amd_fidelityfx_framegeneration_vk.dll` goes along when it is in that folder (`fsr4_fg`).
|
||||
NVIDIA's `nvngx_dlss.dll` goes in by itself: the script downloads the version `tools/dlss_pin.py` pins from
|
||||
NVIDIA's DLSS SDK repository (cached in `toolchain/launcher-dl/`), checks its size and sha256, and puts it in
|
||||
`bin/` with `nvngx_dlss-NOTICE.txt`; `make_game.py` copies both beside the game. `--dlss FILE` takes a copy on disk
|
||||
|
||||
@@ -28,6 +28,23 @@ Draft notes for the release after 0.7.1. The version number is not decided yet.
|
||||
`amd_fidelityfx_upscaler_vk.dll`), which ask the driver whether the card can run FSR 4: the rows appear only
|
||||
where it can, and the log names the version (`ffx4:`). It works together with FSR 3.1 frame generation, and you
|
||||
can switch between FSR 3.1 and FSR 4 while playing.
|
||||
- **Frame generation from AMD's newer library, to try**: in the menu under Screen, Frame generation, as *AMD FSR 4
|
||||
library* with its version, a choice of its own after *AMD FSR 3.1* (`fsr4_fg = 1` in `nx2navi.ini`). Choosing it
|
||||
sets Upscaling to FSR 4 as well, which it needs. The frames are then generated by the library FSR 4 comes with (FSR
|
||||
SDK 2.4, `amd_fidelityfx_framegeneration_vk.dll`) instead of the FSR 3.1 library. It picks the version for your
|
||||
card: on a Radeon RX 9000 with Windows 11 that is AMD's machine-learned FSR Frame Generation 4, **which nobody has
|
||||
tested in this game yet**; on every other card it is version 3.1.6, which on an RX 7900 XT runs at the same frame
|
||||
rate as before and showed clean frames in a fast camera turn. It is off unless you set it, and when it fails the FSR
|
||||
3.1 library takes over. Please report how it looks on an RX 9000.
|
||||
- **A debug menu for testing** (off by default: Game tab, *Debug menu (F9)*, or `debug_menu = 1` in `nx2navi.ini`). F9
|
||||
opens a panel on the left edge, in the performance overlay's look, with the game in view beside it. It has three
|
||||
tabs. *Flags*: the game's 11,292 on/off flags with a search box, about 2,250 of them by name (the names are found in
|
||||
your own game's event files; the rest show their hash), each switched with a click through the game's own function,
|
||||
with the last changes listed to put back. *World*: Link's position and the game's speed, from 0.05x to 8x. *Memory*:
|
||||
a search of the game's memory for a number (1, 2 or 4 bytes, or a float), narrowed down by equals, changed,
|
||||
unchanged, went up or went down, with a value to set at a place or to hold there. Teleporting, a free camera and
|
||||
starting cutscenes are not in it yet: they need the game's own scene-change, warp and event functions. Changing
|
||||
flags or memory can break a save, so keep a copy first.
|
||||
- **Add to Steam** in Customize Launcher (Windows): adds the game to your Steam library as *The Legend of Zelda
|
||||
Ocarina of Time*, with Navi as its icon and the title screen's artwork and logo. Starting it from Steam starts the
|
||||
game. Steam restarts once while it is added.
|
||||
@@ -36,6 +53,12 @@ Draft notes for the release after 0.7.1. The version number is not decided yet.
|
||||
|
||||
## Fixed
|
||||
|
||||
- A crash with frame generation (AMD FSR 3.1) set: switching Upscaling to a choice without FSR or DLSS and back, which
|
||||
the Upscaling row does on its way through its choices, ended the game in AMD's driver. Frame generation was handed
|
||||
the depth picture of the last frame before the switch, which the game had replaced by then.
|
||||
- Frame generation never generates a frame from a picture with the HUD in it any more: a frame for which the picture
|
||||
without the HUD is missing is shown as it is, so the HUD cannot be warped along with the scene behind it. On screen
|
||||
the item button stayed pixel for pixel in place through a fast camera turn, with both frame generation libraries.
|
||||
- Your own background picture in the launcher is no longer partly hidden under the top bar: it now starts right
|
||||
below it, and keeps its shape.
|
||||
|
||||
|
||||
@@ -404,6 +404,18 @@
|
||||
# cards with AMD's driver 26.10.1 or newer. Elsewhere, or when it fails, FSR 3.1 runs and the log says why. Changes
|
||||
# while the game runs take effect at once.
|
||||
# fsr4 = 0
|
||||
# The menu's Frame generation row lists it as "AMD FSR 4 library". With fsr4 = 1 and framegen = fsr3: 1 takes the
|
||||
# frame generation of the same AMD library
|
||||
# (amd_fidelityfx_framegeneration_vk.dll next to the executable) instead of the FSR 3.1 library's. The library picks
|
||||
# the version for the GPU: the machine-learned FSR Frame Generation 4 on Radeon RX 9000 cards with Windows 11, which
|
||||
# has not been tested, and 3.1.6 on every other, where it runs at the same frame rate as the FSR 3.1 library's. When
|
||||
# it fails, the FSR 3.1 library takes over and the log says why (fg4:). Changes while the game runs take effect at once.
|
||||
# fsr4_fg = 0
|
||||
# The debug menu, a tool for testing (Ocarina of Time 1.1.1): with 1, F9 opens a window with the game's on/off flags
|
||||
# by name (the names found in your own game's event files), the game's speed, Link's position, and a search of the
|
||||
# game's memory with values to set and to hold. Changing flags or memory can break a save: keep a copy of the save
|
||||
# first. Do not bind F9 to a game button while it is on. The menu's Game tab has the switch. Takes effect at once.
|
||||
# debug_menu = 0
|
||||
# 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
|
||||
# characters, a little more flicker). Any other model by its letter, a to m: on slower RTX cards the older model e is
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// nx2navi.ini: file-backed defaults for the NX2NAVI_* environment variables (docs/controls.md, nx2navi.ini.example).
|
||||
// nx2navi.ini: file-backed defaults for the NX2NAVI_* environment variables (docs/controls.md, nx2navi.ini.example).
|
||||
// Format: "key = value" lines, '#' or ';' at the start of a line begins a comment, [sections] only group. A key is a
|
||||
// variable name without "NX2NAVI_" (an optional NX2NAVI_ prefix is accepted), case-insensitive. A value is the rest of the
|
||||
// line, trimmed, optionally in double quotes; an empty value counts as unset. The environment wins over the file.
|
||||
@@ -62,7 +62,7 @@ static const char *const known[] = {
|
||||
"SVC_SLOW_MS",
|
||||
"SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_IDLE", "SPLIT_IN_PASS", "SPLIT_US", "SPV_MARK_TEST", "SPV_OVERRIDE", "STICK_DEADZONE", "STICK_SENS",
|
||||
"SWKBD_ANSWER",
|
||||
"SET_AT", "SWKBD_TEST", "TAA", "FSR4", "TEST_PAD", "TEST_PAD_AT", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_DISUSE", "TEX_GEN_UNDO", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TEX_RELEASED_MB", "TEX_REUSE", "TEX_COMMIT_FREE_MB", "TEX_PROC_COMMIT_MB", "TEX_EVICT", "TEX_COMMIT_EVICT", "MIRROR_EVICT", "VRAM_BUDGET_MB", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "EVO_TRACE", "EVENT_AT_SYNC", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NAN_PRESERVE", "VK_NOOPT", "VK_NO_FLOAT64",
|
||||
"SET_AT", "SWKBD_TEST", "TAA", "DBG_TEST", "DEBUG_MENU", "MENU_TEST_DEBUG", "FSR4", "FSR4_FG", "FG4_VERSION", "FG4_SWAPCHAIN", "TEST_PAD", "TEST_PAD_AT", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_DISUSE", "TEX_GEN_UNDO", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TEX_RELEASED_MB", "TEX_REUSE", "TEX_COMMIT_FREE_MB", "TEX_PROC_COMMIT_MB", "TEX_EVICT", "TEX_COMMIT_EVICT", "MIRROR_EVICT", "VRAM_BUDGET_MB", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "EVO_TRACE", "EVENT_AT_SYNC", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NAN_PRESERVE", "VK_NOOPT", "VK_NO_FLOAT64",
|
||||
"VK_PRESENT", "VK_RECONVERGE", "VK_NAN_BITS", "VK_RECORDER", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VRAM_HEADROOM", "VS_OUTS",
|
||||
"WALK_KEY", "WALK_SCALE", "WB_EXACT", "WB_FENCE_LIMIT", "WB_MERGE", "WB_NO_REUP", "WB_MERGE_MAX", "WB_PROBE", "WB_SPLIT", "WB_LAZY", "WB_LAZY_TOUCH", "WINDOW_SIZE", "XLATE", "XLATE_ID", "XLATE_KEEP", "XLATE_PROCS",
|
||||
"ZSTD_CHECK", "ZSTD_NATIVE",
|
||||
@@ -88,7 +88,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"HDR_HIGHLIGHTS", "display"}, {"HDR_SHADOWS", "display"}, {"HDR_CONTRAST", "display"}, {"HDR_SATURATION", "display"},
|
||||
{"HDR_HIGHLIGHT_SAT", "display"}, {"HDR_BLOWOUT", "display"}, {"HDR_FLARE", "display"}, {"HDR_HUE", "display"},
|
||||
{"HDR_GRADE", "display"}, {"SHADOW_RES", "display"},
|
||||
{"DLAA", "display"}, {"FSR4", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_IDLE_FREE", "display"}, {"DLSS_CHAR_MASK", "display"}, {"FXAA", "display"},
|
||||
{"DLAA", "display"}, {"FSR4", "display"}, {"FSR4_FG", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_IDLE_FREE", "display"}, {"DLSS_CHAR_MASK", "display"}, {"FXAA", "display"},
|
||||
{"FRAMEGEN", "display"}, {"FRAMEGEN_MULTIPLIER", "display"}, {"FG_MULT", "display"},
|
||||
{"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"},
|
||||
{"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"},
|
||||
@@ -99,7 +99,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"VOLUME", "audio"}, {"AUDIO_CHANNELS", "audio"}, {"AUDIO_DEVICE", "audio"}, {"MICROPHONE", "audio"}, {"MENU_SOUND_VOLUME", "audio"},
|
||||
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, {"DS3", "input"},
|
||||
{"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"},
|
||||
{"STICK_SENS", "input"},
|
||||
{"STICK_SENS", "input"}, {"DEBUG_MENU", "input"},
|
||||
{"MENU_CURSOR", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"},
|
||||
{"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"},
|
||||
{"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"},
|
||||
@@ -153,6 +153,7 @@ static const CfgMeta metas[] = {
|
||||
{"DLAA", "0", "0|1", LIVE}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE},
|
||||
{"DLSS_PRESET", "default", "default|k|j", LIVE}, {"DLSS_IDLE_FREE", "1", "0|1|2", RESTART}, {"TAA", "dlss", "dlss|fsr3", LIVE}, // vk_dlaa.c fsr3
|
||||
{"FSR4", "0", "0|1", LIVE}, // vk_ffx.cpp vk_ffx_fsr4
|
||||
{"FSR4_FG", "0", "0|1", LIVE}, // vk_fg.cpp use4
|
||||
{"FRAMEGEN", "off", "off|fsr3|dlss", LIVE}, // vk_fg.cpp, vk_dlssg.c
|
||||
{"FRAMEGEN_MULTIPLIER", "2", "2|3|4", LIVE}, // vk_dlssg.c: frames on screen per rendered frame with DLSS
|
||||
// the same where DLSS's frame generation runs through NGX itself (gfx_present.c ng_multiplier): 2x to 6x or dynamic
|
||||
@@ -204,6 +205,7 @@ static const CfgMeta metas[] = {
|
||||
{"DS3", "0", "0|1", LIVE}, // input_ds3_win.c ds3_read: read a DualShock 3 directly; off: no HID scan
|
||||
{"PROMPTS", "nintendo", "nintendo|xbox|playstation|steamdeck|pc", RESTART},
|
||||
{"STICK_DEADZONE", "8", "0..50", LIVE}, {"STICK_SENS", "1", "0.1..3", LIVE}, // camera_speed.c cam_speed_tick
|
||||
{"DEBUG_MENU", "0", "0|1", LIVE}, // ui/menu.cpp menu_debug_toggle
|
||||
{"LSTICK_DEADZONE", "", "0..50", LIVE}, {"RSTICK_DEADZONE", "", "0..50", LIVE},
|
||||
{"MOUSE_MODE", "direct", "stick|direct", LIVE},
|
||||
{"MOUSE_SENS", "1", "0..10", LIVE}, {"MENU_CURSOR", "1", "0|1", LIVE},
|
||||
|
||||
480
runtime/debug_tools.c
Normal file
480
runtime/debug_tools.c
Normal file
@@ -0,0 +1,480 @@
|
||||
// The debug menu's hands in the game (ui/debug_menu.cpp is its window, F9 with debug_menu = 1). Ocarina of Time 1.1.1.
|
||||
//
|
||||
// Reads go straight to the game's memory from the menu's thread, through plat_mem_read, which answers 0 instead of
|
||||
// faulting. Changes are queued and made on the game's own thread at its pad read (dbg_tick, from ov_input.c), between
|
||||
// two of the game's frames: a flag through the game's own function, so everything that follows a flag in the game
|
||||
// follows this change too; a memory value by a plain write into memory the game may read and write.
|
||||
//
|
||||
// The game's on/off flags ("game data"): the manager is **[main+0x4c7e180]; +0x10 the number of flags, +0x18 their
|
||||
// entries (0x18 bytes each, the value's byte at +0x16), +0x20 a table of {hash, index} pairs probed from hash % size
|
||||
// (+0x2c the size). main+0x20d9c0 (manager, u8 *out, hash) reads a flag and main+0x682b20 (manager, value, hash)
|
||||
// queues a change, which the manager applies at its next update. A flag is known to the game by the MurmurHash3 of
|
||||
// its name only; the names shown are those found in the player's own game files (the event flows), hashed here and
|
||||
// matched (dbg_names), so nothing of them is kept in this code.
|
||||
//
|
||||
// The game's speed: the runtime gives the game its step every frame (frame_rate.c ocarina_step_write, the display
|
||||
// interval); the menu's factor multiplies that step, so 0.5 is half speed for the whole game and its interface.
|
||||
//
|
||||
// Link's position is shown but not written: it is the actor's copy ([[main+0x4e371d0]+0x480]+0x31c), which the physics
|
||||
// writes every frame. Writing it, or every copy of it in the heap, moved Link back within three frames.
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <zstd.h>
|
||||
|
||||
#include "cfg.h"
|
||||
#include "cpu.h"
|
||||
#include "debug_tools.h"
|
||||
#include "fs.h"
|
||||
#include "host.h"
|
||||
#include "layout.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
int dbg_supported(void) { return RT_V111; }
|
||||
|
||||
static int rd(uint64_t a, void *out, size_t n) { return a && plat_mem_read(a, out, n); }
|
||||
static uint64_t rd_ptr(uint64_t a) {
|
||||
uint64_t p = 0;
|
||||
return rd(a, &p, 8) ? p : 0;
|
||||
}
|
||||
// A write into memory the game may read and write: 0 when the place is not such memory.
|
||||
static int wr(uint64_t a, const void *from, size_t n) {
|
||||
RtMemoryInfo mi;
|
||||
if (!a || mem_query(a, &mi) || !mi.state || (mi.perm & 3) != 3 || a + n > mi.base + mi.size) return 0;
|
||||
mem_thaw(a, n);
|
||||
memcpy((void *)(uintptr_t)a, from, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---- the player and the game's speed
|
||||
static uint64_t player(void) {
|
||||
uint64_t manager = rd_ptr(MOD_MAIN_BASE + 0x4e371d0), actor = manager ? rd_ptr(manager + 0x480) : 0;
|
||||
char name[7];
|
||||
uint64_t np = actor ? rd_ptr(actor + 0x20) : 0;
|
||||
return np && rd(np, name, 7) && !memcmp(name, "Player", 7) ? actor : 0;
|
||||
}
|
||||
|
||||
int dbg_player_pos(float xyz[3]) {
|
||||
uint64_t a = dbg_supported() ? player() : 0;
|
||||
return a && rd(a + 0x31c, xyz, 12) && isfinite(xyz[0]) && isfinite(xyz[1]) && isfinite(xyz[2]);
|
||||
}
|
||||
|
||||
static float speed_factor = 1.0f;
|
||||
float dbg_speed_factor(void) { return speed_factor; }
|
||||
void dbg_speed_set(float factor) { speed_factor = factor >= 0.05f && factor <= 8.0f ? factor : 1.0f; }
|
||||
|
||||
// ---- what the menu asks for, done by dbg_tick
|
||||
enum { Q_FLAG, Q_WRITE, Q_MAX = 256, FREEZE_MAX = 64 };
|
||||
typedef struct { int kind; uint32_t hash; uint64_t addr, value; int size; } Req;
|
||||
static PlatMutex q_lock = PLAT_MUTEX_INIT;
|
||||
static Req q[Q_MAX];
|
||||
static int q_n;
|
||||
static struct { uint64_t addr, value; int size; } frozen[FREEZE_MAX];
|
||||
static int frozen_n;
|
||||
static uint64_t stat_flags, stat_writes, stat_refused;
|
||||
|
||||
static void ask(Req r) {
|
||||
plat_mutex_lock(&q_lock);
|
||||
if (q_n < Q_MAX) q[q_n++] = r;
|
||||
plat_mutex_unlock(&q_lock);
|
||||
}
|
||||
|
||||
void dbg_flag_set(uint32_t hash, int on) { ask((Req){Q_FLAG, hash, 0, (uint64_t)(on != 0), 0}); }
|
||||
void dbg_mem_write(uint64_t addr, uint64_t value, int size) {
|
||||
if (addr) ask((Req){Q_WRITE, 0, addr, value, size});
|
||||
}
|
||||
|
||||
int dbg_freeze(uint64_t addr, uint64_t value, int size, int on) {
|
||||
if (!addr) return 0;
|
||||
int ok = 1;
|
||||
plat_mutex_lock(&q_lock);
|
||||
int at = -1;
|
||||
for (int i = 0; i < frozen_n; i++)
|
||||
if (frozen[i].addr == addr) at = i;
|
||||
if (on && at < 0 && frozen_n < FREEZE_MAX) at = frozen_n++;
|
||||
if (on && at >= 0) frozen[at].addr = addr, frozen[at].value = value, frozen[at].size = size;
|
||||
else if (on) ok = 0;
|
||||
else if (at >= 0) frozen[at] = frozen[--frozen_n];
|
||||
plat_mutex_unlock(&q_lock);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int dbg_frozen(uint64_t addr) {
|
||||
int is = 0;
|
||||
plat_mutex_lock(&q_lock);
|
||||
for (int i = 0; i < frozen_n; i++) is |= frozen[i].addr == addr;
|
||||
plat_mutex_unlock(&q_lock);
|
||||
return is;
|
||||
}
|
||||
|
||||
int dbg_frozen_count(void) { return frozen_n; }
|
||||
|
||||
void dbg_unfreeze_all(void) {
|
||||
plat_mutex_lock(&q_lock);
|
||||
frozen_n = 0;
|
||||
plat_mutex_unlock(&q_lock);
|
||||
}
|
||||
|
||||
// ---- the flags
|
||||
static uint64_t gmd(void) {
|
||||
uint64_t slot = rd_ptr(MOD_MAIN_BASE + 0x4c7e180);
|
||||
return slot ? rd_ptr(slot) : 0;
|
||||
}
|
||||
|
||||
typedef struct { uint32_t hash, index; } Pair;
|
||||
static Pair *flag_pairs; // the flags by hash, sorted; made once the game's table is there
|
||||
static const char **flag_name; // parallel: the name found for the hash, or NULL
|
||||
static uint8_t *flag_value; // parallel: the value at the last dbg_flags_refresh
|
||||
static int flag_n;
|
||||
static volatile int32_t names_state; // 0 not asked, 1 being read, 2 read
|
||||
static int names_found;
|
||||
|
||||
static int by_hash(const void *a, const void *b) {
|
||||
uint32_t x = ((const Pair *)a)->hash, y = ((const Pair *)b)->hash;
|
||||
return x < y ? -1 : x > y;
|
||||
}
|
||||
|
||||
// The list of the game's flags from its hash table. 0 until the manager exists (a save is loaded).
|
||||
static int flags_list(void) {
|
||||
if (flag_pairs) return 1;
|
||||
uint64_t m = gmd(), table = m ? rd_ptr(m + 0x20) : 0;
|
||||
uint32_t count = 0, size = 0;
|
||||
if (!table || !rd(m + 0x10, &count, 4) || !rd(m + 0x2c, &size, 4) || !count || count > 200000 || size < count ||
|
||||
size > 1000000)
|
||||
return 0;
|
||||
Pair *slots = malloc(sizeof(Pair) * size), *list = malloc(sizeof(Pair) * count);
|
||||
int n = 0;
|
||||
if (slots && list && rd(table, slots, sizeof(Pair) * size))
|
||||
for (uint32_t i = 0; i < size && n < (int)count; i++)
|
||||
if (slots[i].hash && slots[i].index < count) list[n++] = slots[i];
|
||||
free(slots);
|
||||
if (!list || !n) {
|
||||
free(list);
|
||||
return 0;
|
||||
}
|
||||
qsort(list, (size_t)n, sizeof(Pair), by_hash);
|
||||
flag_name = calloc((size_t)n, sizeof *flag_name);
|
||||
flag_value = calloc((size_t)n, 1);
|
||||
if (!flag_name || !flag_value) {
|
||||
free(list);
|
||||
return 0;
|
||||
}
|
||||
flag_n = n;
|
||||
flag_pairs = list;
|
||||
rt_log("debug: %d of the game's %u on/off flags listed", n, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dbg_flags_refresh(void) {
|
||||
if (!dbg_supported() || !flags_list()) return 0;
|
||||
uint64_t m = gmd(), entries = m ? rd_ptr(m + 0x18) : 0;
|
||||
uint32_t count = 0;
|
||||
if (!entries || !rd(m + 0x10, &count, 4) || !count || count > 200000) return flag_n;
|
||||
uint8_t *raw = malloc((size_t)count * 0x18);
|
||||
if (raw && rd(entries, raw, (size_t)count * 0x18))
|
||||
for (int i = 0; i < flag_n; i++)
|
||||
if (flag_pairs[i].index < count) flag_value[i] = raw[(size_t)flag_pairs[i].index * 0x18 + 0x16] & 1;
|
||||
free(raw);
|
||||
return flag_n;
|
||||
}
|
||||
|
||||
uint32_t dbg_flag_hash(int i) { return i >= 0 && i < flag_n ? flag_pairs[i].hash : 0; }
|
||||
int dbg_flag_value(int i) { return i >= 0 && i < flag_n ? flag_value[i] : 0; }
|
||||
const char *dbg_flag_name(int i) {
|
||||
return i >= 0 && i < flag_n && __atomic_load_n(&names_state, __ATOMIC_ACQUIRE) == 2 ? flag_name[i] : NULL;
|
||||
}
|
||||
|
||||
// ---- the flags' names, from the player's game files
|
||||
static uint32_t murmur3(const uint8_t *p, size_t len) {
|
||||
uint32_t h = 0;
|
||||
size_t n = len & ~(size_t)3;
|
||||
for (size_t i = 0; i < n; i += 4) {
|
||||
uint32_t k;
|
||||
memcpy(&k, p + i, 4);
|
||||
k *= 0xcc9e2d51u, k = (k << 15) | (k >> 17), k *= 0x1b873593u;
|
||||
h ^= k, h = (h << 13) | (h >> 19), h = h * 5 + 0xe6546b64u;
|
||||
}
|
||||
uint32_t k = 0;
|
||||
switch (len & 3) {
|
||||
case 3: k ^= (uint32_t)p[n + 2] << 16; // fall through
|
||||
case 2: k ^= (uint32_t)p[n + 1] << 8; // fall through
|
||||
case 1:
|
||||
k ^= p[n];
|
||||
k *= 0xcc9e2d51u, k = (k << 15) | (k >> 17), k *= 0x1b873593u;
|
||||
h ^= k;
|
||||
}
|
||||
h ^= (uint32_t)len;
|
||||
h ^= h >> 16, h *= 0x85ebca6bu, h ^= h >> 13, h *= 0xc2b2ae35u, h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
|
||||
static int name_char(uint8_t c) {
|
||||
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '.';
|
||||
}
|
||||
|
||||
// Every run of name characters in a file is hashed and looked up among the flags.
|
||||
static void names_in(const uint8_t *p, size_t n) {
|
||||
for (size_t i = 0; i < n;) {
|
||||
if (!name_char(p[i])) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
size_t e = i;
|
||||
while (e < n && name_char(p[e])) e++;
|
||||
if (e - i >= 4 && e - i <= 96) {
|
||||
Pair key = {murmur3(p + i, e - i), 0};
|
||||
Pair *hit = bsearch(&key, flag_pairs, (size_t)flag_n, sizeof(Pair), by_hash);
|
||||
if (hit && !flag_name[hit - flag_pairs]) {
|
||||
char *s = malloc(e - i + 1);
|
||||
if (s) {
|
||||
memcpy(s, p + i, e - i);
|
||||
s[e - i] = 0;
|
||||
flag_name[hit - flag_pairs] = s;
|
||||
names_found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
i = e;
|
||||
}
|
||||
}
|
||||
|
||||
// A member of a SARC archive: its place and size, 0 when it is not there.
|
||||
static int sarc_member(const uint8_t *p, size_t n, const char *name, size_t *at, size_t *size) {
|
||||
if (n < 0x20 || memcmp(p, "SARC", 4)) return 0;
|
||||
uint16_t head, count;
|
||||
uint32_t data;
|
||||
memcpy(&head, p + 4, 2);
|
||||
memcpy(&data, p + 12, 4);
|
||||
if ((size_t)head + 12 > n || memcmp(p + head, "SFAT", 4)) return 0;
|
||||
memcpy(&count, p + head + 6, 2);
|
||||
size_t names = (size_t)head + 12 + (size_t)count * 16 + 8, len = strlen(name);
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
uint32_t attr, lo, hi;
|
||||
size_t e = (size_t)head + 12 + (size_t)i * 16;
|
||||
if (e + 16 > n) return 0;
|
||||
memcpy(&attr, p + e + 4, 4), memcpy(&lo, p + e + 8, 4), memcpy(&hi, p + e + 12, 4);
|
||||
size_t s = names + (size_t)(attr & 0xffffff) * 4;
|
||||
if (s + len + 1 > n || memcmp(p + s, name, len + 1)) continue;
|
||||
if (lo > hi || (size_t)data + hi > n) return 0;
|
||||
*at = data + lo, *size = hi - lo;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void names_thread(void *arg) {
|
||||
(void)arg;
|
||||
uint64_t t0 = plat_now_ns(), dn = 0;
|
||||
uint8_t *dz = romfs_load("Pack/ZsDic.pack.zs", &dn), *dics = NULL;
|
||||
ZSTD_DDict *dd = NULL;
|
||||
ZSTD_DCtx *dctx = ZSTD_createDCtx();
|
||||
unsigned long long dsize = dz ? ZSTD_getFrameContentSize(dz, (size_t)dn) : 0;
|
||||
size_t at = 0, size = 0;
|
||||
int files = 0;
|
||||
if (dz && dsize && dsize < (64u << 20) && (dics = malloc((size_t)dsize)) &&
|
||||
ZSTD_decompress(dics, (size_t)dsize, dz, (size_t)dn) == dsize && sarc_member(dics, (size_t)dsize, "zs.zsdic", &at, &size))
|
||||
dd = ZSTD_createDDict(dics + at, size);
|
||||
if (dd && dctx) {
|
||||
uint64_t count = romfs_file_count();
|
||||
for (uint64_t i = 0; i < count; i++) {
|
||||
uint64_t off, fsize;
|
||||
const char *path = romfs_entry(i, &off, &fsize);
|
||||
size_t len = path ? strlen(path) : 0;
|
||||
if (!path || strncmp(path, "Event/EventFlow/", 16) || len < 4 || strcmp(path + len - 3, ".zs")) continue;
|
||||
uint8_t *z = romfs_load(path, &fsize);
|
||||
unsigned long long rn = z ? ZSTD_getFrameContentSize(z, (size_t)fsize) : 0;
|
||||
uint8_t *raw = z && rn && rn < (64u << 20) ? malloc((size_t)rn) : NULL;
|
||||
if (raw && ZSTD_decompress_usingDDict(dctx, raw, (size_t)rn, z, (size_t)fsize, dd) == rn) {
|
||||
names_in(raw, (size_t)rn);
|
||||
files++;
|
||||
}
|
||||
free(raw);
|
||||
free(z);
|
||||
}
|
||||
}
|
||||
ZSTD_freeDCtx(dctx);
|
||||
ZSTD_freeDDict(dd);
|
||||
free(dics);
|
||||
free(dz);
|
||||
rt_log("debug: names for %d of %d flags, from %d of the game's event files, in %.0f ms", names_found, flag_n, files,
|
||||
(double)(plat_now_ns() - t0) / 1e6);
|
||||
__atomic_store_n(&names_state, 2, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
// 0 not started (no flags yet), 1 being read, 2 there. Starts the reading once the flags are listed.
|
||||
int dbg_names(int *found) {
|
||||
int s = __atomic_load_n(&names_state, __ATOMIC_ACQUIRE);
|
||||
if (!s && flag_pairs) {
|
||||
int32_t zero = 0;
|
||||
if (__atomic_compare_exchange_n(&names_state, &zero, 1, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) {
|
||||
if (!plat_thread_spawn(names_thread, NULL, "debug names", 0)) __atomic_store_n(&names_state, 2, __ATOMIC_RELEASE);
|
||||
s = 1;
|
||||
}
|
||||
}
|
||||
if (found) *found = s == 2 ? names_found : 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
// ---- the memory search: values of 1, 2 or 4 bytes in the game's heap
|
||||
enum { RESULT_MAX = 2000000 };
|
||||
static uint64_t *res_addr;
|
||||
static uint32_t *res_last;
|
||||
static int res_n, res_size, res_over;
|
||||
|
||||
int dbg_mem_read(uint64_t addr, int size, uint32_t *v) {
|
||||
*v = 0;
|
||||
return (size == 1 || size == 2 || size == 4) && rd(addr, v, (size_t)size);
|
||||
}
|
||||
|
||||
int dbg_search_count(int *over) {
|
||||
if (over) *over = res_over;
|
||||
return res_n;
|
||||
}
|
||||
uint64_t dbg_search_addr(int i) { return i >= 0 && i < res_n ? res_addr[i] : 0; }
|
||||
int dbg_search_size(void) { return res_size; }
|
||||
void dbg_search_clear(void) { res_n = res_over = 0; }
|
||||
|
||||
// A new search: every place in the heap, aligned to the size, that holds the value. Returns how many (at most
|
||||
// RESULT_MAX are kept; dbg_search_count's over says there were more).
|
||||
int dbg_search_new(uint32_t value, int size) {
|
||||
enum { PIECE = 16 << 20 };
|
||||
if (!res_addr) res_addr = malloc(sizeof(uint64_t) * RESULT_MAX), res_last = malloc(sizeof(uint32_t) * RESULT_MAX);
|
||||
res_n = res_over = 0;
|
||||
res_size = size;
|
||||
if (!res_addr || !res_last || !dbg_supported()) return 0;
|
||||
const RtGuestLayout *l = mem_layout();
|
||||
const RtRange ranges[2] = {l->heap, l->alias};
|
||||
for (int r = 0; r < 2; r++) {
|
||||
uint64_t a = ranges[r].base, end = ranges[r].base + ranges[r].size;
|
||||
while (a < end) {
|
||||
RtMemoryInfo mi;
|
||||
if (mem_query(a, &mi) || !mi.size) break;
|
||||
uint64_t stop = mi.base + mi.size < end ? mi.base + mi.size : end;
|
||||
if (!mi.state || (mi.perm & 3) != 3) { // free, or not the game's to read and write
|
||||
a = stop;
|
||||
continue;
|
||||
}
|
||||
while (a < stop) {
|
||||
uint64_t n = stop - a < PIECE ? stop - a : PIECE;
|
||||
if (mem_read_hold(a, n)) {
|
||||
const uint8_t *p = (const uint8_t *)(uintptr_t)a;
|
||||
#define FIND(T) \
|
||||
for (uint64_t i = 0; i + sizeof(T) <= n; i += sizeof(T)) { \
|
||||
T x; \
|
||||
memcpy(&x, p + i, sizeof(T)); \
|
||||
if (x == (T)value) { \
|
||||
if (res_n < RESULT_MAX) res_addr[res_n] = a + i, res_last[res_n++] = value; \
|
||||
else res_over = 1; \
|
||||
} \
|
||||
}
|
||||
if (size == 4) { FIND(uint32_t) } else if (size == 2) { FIND(uint16_t) } else { FIND(uint8_t) }
|
||||
#undef FIND
|
||||
mem_read_release();
|
||||
}
|
||||
a += n;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res_n;
|
||||
}
|
||||
|
||||
// Keeps the results whose value now passes: mode 0 equals value, 1 changed, 2 unchanged, 3 greater, 4 less than at the
|
||||
// search before (unsigned; a float is searched by its bits with mode 0).
|
||||
int dbg_search_next(int mode, uint32_t value) {
|
||||
int kept = 0;
|
||||
for (int i = 0; i < res_n; i++) {
|
||||
uint32_t v, was = res_last[i];
|
||||
if (!dbg_mem_read(res_addr[i], res_size, &v)) continue;
|
||||
int pass = mode == 0 ? v == value : mode == 1 ? v != was : mode == 2 ? v == was : mode == 3 ? v > was : v < was;
|
||||
if (pass) res_addr[kept] = res_addr[i], res_last[kept++] = v;
|
||||
}
|
||||
res_n = kept;
|
||||
res_over = 0;
|
||||
return kept;
|
||||
}
|
||||
|
||||
// ---- NX2NAVI_DBG_TEST="<tick>:flag <hash hex> <0|1>;<tick>:speed <factor>;<tick>:find <value> <size>;
|
||||
// <tick>:next <mode> <value>;<tick>:setfirst <value>;<tick>:holdfirst <value>;<tick>:show [<hash hex>]": the menu's
|
||||
// requests without the menu, for test runs. Ticks count the game's pad reads from the player's first appearance.
|
||||
static void test_script(uint64_t tick) {
|
||||
static char buf[512];
|
||||
static const char *next;
|
||||
static int state;
|
||||
if (!state) {
|
||||
const char *e = cfg_get("NX2NAVI_DBG_TEST");
|
||||
state = e && *e ? 1 : -1;
|
||||
if (state > 0) snprintf(buf, sizeof buf, "%s", e), next = buf;
|
||||
}
|
||||
while (state > 0 && next && *next && strtoull(next, NULL, 10) <= tick) {
|
||||
const char *colon = strchr(next, ':'), *end = strchr(next, ';');
|
||||
if (!colon) break;
|
||||
unsigned hash = 0, on = 0, size = 4;
|
||||
unsigned long long value = 0;
|
||||
float f = 0;
|
||||
if (sscanf(colon + 1, "flag %x %u", &hash, &on) == 2) {
|
||||
dbg_flag_set(hash, (int)on);
|
||||
} else if (sscanf(colon + 1, "speed %f", &f) == 1) {
|
||||
dbg_speed_set(f);
|
||||
} else if (sscanf(colon + 1, "setfirst %llu", &value) == 1) {
|
||||
dbg_mem_write(dbg_search_addr(0), value, dbg_search_size());
|
||||
} else if (sscanf(colon + 1, "holdfirst %llu", &value) == 1) {
|
||||
dbg_freeze(dbg_search_addr(0), value, dbg_search_size(), value != 0);
|
||||
} else if (sscanf(colon + 1, "next %u %llu", &on, &value) == 2) {
|
||||
int n = dbg_search_next((int)on, (uint32_t)value);
|
||||
uint32_t now = 0;
|
||||
dbg_mem_read(dbg_search_addr(0), dbg_search_size(), &now);
|
||||
rt_log("debug: tick %llu: %d places left (mode %u, value %llu); the first holds %u; %d held", (unsigned long long)tick, n,
|
||||
on, value, now, dbg_frozen_count());
|
||||
} else if (sscanf(colon + 1, "find %llu %u", &value, &size) >= 1) {
|
||||
uint64_t t0 = plat_now_ns();
|
||||
int n = dbg_search_new((uint32_t)value, (int)size), over = 0;
|
||||
dbg_search_count(&over);
|
||||
rt_log("debug: tick %llu: %d places hold %llu as %u bytes%s, searched in %.0f ms; first %#llx", (unsigned long long)tick,
|
||||
n, value, size, over ? " (and more)" : "", (double)(plat_now_ns() - t0) / 1e6,
|
||||
(unsigned long long)dbg_search_addr(0));
|
||||
} else if (!strncmp(colon + 1, "show", 4)) {
|
||||
float p[3] = {0, 0, 0}, sp = dbg_speed_factor();
|
||||
int n = dbg_flags_refresh(), set = 0, found = 0;
|
||||
for (int i = 0; i < n; i++) set += flag_value[i];
|
||||
int names = dbg_names(&found);
|
||||
dbg_player_pos(p);
|
||||
rt_log("debug: tick %llu: %d flags, %d on; names state %d, %d found; player %.2f %.2f %.2f; speed %.3f; done: %llu flag "
|
||||
"changes, %llu writes, %llu refused", (unsigned long long)tick, n, set, names, found, p[0], p[1], p[2], sp,
|
||||
(unsigned long long)stat_flags, (unsigned long long)stat_writes, (unsigned long long)stat_refused);
|
||||
if (sscanf(colon + 1, "show %x", &hash) == 1)
|
||||
for (int i = 0; i < n; i++)
|
||||
if (flag_pairs[i].hash == hash)
|
||||
rt_log("debug: flag %08x (%s) is %d", hash, names == 2 && flag_name[i] ? flag_name[i] : "no name", flag_value[i]);
|
||||
}
|
||||
next = end ? end + 1 : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// The game's thread, at its pad read.
|
||||
void dbg_tick(Cpu *c) {
|
||||
static uint64_t tick;
|
||||
if (!dbg_supported() || (!tick && !player())) return;
|
||||
tick++;
|
||||
test_script(tick);
|
||||
static Req todo[Q_MAX];
|
||||
int n;
|
||||
plat_mutex_lock(&q_lock);
|
||||
n = q_n, q_n = 0;
|
||||
memcpy(todo, q, sizeof(Req) * (size_t)n);
|
||||
for (int i = 0; i < frozen_n && n < Q_MAX; i++) todo[n++] = (Req){Q_WRITE, 0, frozen[i].addr, frozen[i].value, frozen[i].size};
|
||||
plat_mutex_unlock(&q_lock);
|
||||
uint64_t m = gmd();
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (todo[i].kind == Q_FLAG) {
|
||||
if (!m) continue;
|
||||
rt_call(c, MOD_MAIN_BASE + 0x682b20, 3, m, todo[i].value, (uint64_t)todo[i].hash);
|
||||
stat_flags++;
|
||||
rt_log("debug: flag %08x set to %s", todo[i].hash, todo[i].value ? "on" : "off"); // what a tester changed, for the log
|
||||
} else if (todo[i].size == 1 || todo[i].size == 2 || todo[i].size == 4) {
|
||||
if (wr(todo[i].addr, &todo[i].value, (size_t)todo[i].size)) stat_writes++;
|
||||
else stat_refused++;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
runtime/debug_tools.h
Normal file
43
runtime/debug_tools.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// The debug menu's access to the game (debug_tools.c). Everything but dbg_tick is for the menu's thread.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include "cpu.h"
|
||||
void dbg_tick(Cpu *c); // the game's thread, at its pad read (ov_input.c): does what the menu asked for
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int dbg_supported(void); // this game build's structures are known (Ocarina of Time 1.1.1)
|
||||
|
||||
int dbg_player_pos(float xyz[3]); // Link's position in metres; 0 while there is no player
|
||||
float dbg_speed_factor(void); // the game's speed: 1 normal, 0.05 to 8 (frame_rate.c multiplies the game's step)
|
||||
void dbg_speed_set(float factor);
|
||||
|
||||
// The game's on/off flags, sorted by hash. dbg_flags_refresh reads their values and returns their number (0 until a
|
||||
// save is loaded). A change is made by the game's own function at the next frame.
|
||||
int dbg_flags_refresh(void);
|
||||
uint32_t dbg_flag_hash(int i);
|
||||
int dbg_flag_value(int i);
|
||||
const char *dbg_flag_name(int i); // NULL: no name found for it
|
||||
void dbg_flag_set(uint32_t hash, int on);
|
||||
int dbg_names(int *found); // 0 not started, 1 being read from the game's files, 2 read (*found of them)
|
||||
|
||||
// Memory: values of 1, 2 or 4 bytes in the game's heap.
|
||||
int dbg_search_new(uint32_t value, int size); // returns the number of places
|
||||
int dbg_search_next(int mode, uint32_t value); // 0 equals value, 1 changed, 2 unchanged, 3 greater, 4 less
|
||||
int dbg_search_count(int *over); // *over: the first search found more than are kept
|
||||
uint64_t dbg_search_addr(int i);
|
||||
int dbg_search_size(void);
|
||||
void dbg_search_clear(void);
|
||||
int dbg_mem_read(uint64_t addr, int size, uint32_t *v);
|
||||
void dbg_mem_write(uint64_t addr, uint64_t value, int size);
|
||||
int dbg_freeze(uint64_t addr, uint64_t value, int size, int on); // written every frame while on; 0: the list is full
|
||||
int dbg_frozen(uint64_t addr);
|
||||
int dbg_frozen_count(void);
|
||||
void dbg_unfreeze_all(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "debug_tools.h"
|
||||
#include "cfg.h"
|
||||
#include "gfx.h"
|
||||
#include "host.h"
|
||||
@@ -582,7 +583,8 @@ void frame_step_present(uint64_t display_ns, int interval) {
|
||||
}
|
||||
}
|
||||
if (frame_free_running() && last_ns) {
|
||||
if (dt > 0 && dt < STEP_RESET_S) ocarina_step_write(ocarina_step(dt));
|
||||
// the debug menu's speed factor (debug_tools.c) multiplies the step the game is given
|
||||
if (dt > 0 && dt < STEP_RESET_S) ocarina_step_write(ocarina_step(dt) * (double)dbg_speed_factor());
|
||||
else ocarina_step_reset(); // a load or a debugger stop: the intervals before it say nothing about the next
|
||||
}
|
||||
last_ns = display_ns;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "debug_tools.h"
|
||||
#include "cfg.h"
|
||||
#include "host.h"
|
||||
#include "input.h"
|
||||
@@ -93,6 +94,7 @@ static void npad_states(Cpu *c, uint32_t want) {
|
||||
s.attributes = ATTR_CONNECTED;
|
||||
input_poll(&s.buttons, &s.lx, &s.ly, &s.rx, &s.ry);
|
||||
}
|
||||
dbg_tick(c); // the debug menu's changes to the game, between two of its frames (debug_tools.c)
|
||||
*out = s;
|
||||
ret_x(c, 1);
|
||||
}
|
||||
|
||||
3
runtime/third_party/ffx_sdk/LICENSE.txt
vendored
3
runtime/third_party/ffx_sdk/LICENSE.txt
vendored
@@ -1,5 +1,6 @@
|
||||
AMD FSR SDK 2.4.0 (https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK, tag v2.4.0), the files of
|
||||
Kits/FidelityFX/api/include and Kits/FidelityFX/upscalers/include kept here at the same relative paths, unmodified.
|
||||
Kits/FidelityFX/api/include, Kits/FidelityFX/upscalers/include and Kits/FidelityFX/framegeneration/include kept here at
|
||||
the same relative paths, unmodified.
|
||||
docs/license.md of that tag lists them among the files under this licence:
|
||||
|
||||
Copyright (C) Advanced Micro Devices, Inc.
|
||||
|
||||
299
runtime/third_party/ffx_sdk/framegeneration/include/ffx_framegeneration.h
vendored
Normal file
299
runtime/third_party/ffx_sdk/framegeneration/include/ffx_framegeneration.h
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2026 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../api/include/ffx_api.h"
|
||||
#include "ffx_framegeneration_api_types.h"
|
||||
|
||||
#define FFX_FRAMEGENERATION_VERSION_MAJOR 4
|
||||
#define FFX_FRAMEGENERATION_VERSION_MINOR 0
|
||||
#define FFX_FRAMEGENERATION_VERSION_PATCH 2
|
||||
|
||||
#define FFX_FRAMEGENERATION_MAKE_VERSION(major, minor, patch) (((major) << 22) | ((minor) << 12) | (patch))
|
||||
#define FFX_FRAMEGENERATION_VERSION FFX_FRAMEGENERATION_MAKE_VERSION(FFX_FRAMEGENERATION_VERSION_MAJOR, FFX_FRAMEGENERATION_VERSION_MINOR, FFX_FRAMEGENERATION_VERSION_PATCH)
|
||||
|
||||
#define FFX_FRAMEGENERATION_PREPARE_REPLACEMENT_SUFFIX "PrepareV2"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
enum FfxApiCreateContextFramegenerationFlags
|
||||
{
|
||||
FFX_FRAMEGENERATION_ENABLE_ASYNC_WORKLOAD_SUPPORT = (1 << 0), ///< A bit indicating that async compute workloads should be supported. Enables generation work on async compute queues.
|
||||
FFX_FRAMEGENERATION_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1 << 1), ///< A bit indicating if the motion vectors are rendered at display resolution.
|
||||
FFX_FRAMEGENERATION_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION = (1 << 2), ///< A bit indicating that the motion vectors have the jittering pattern applied to them.
|
||||
FFX_FRAMEGENERATION_ENABLE_DEPTH_INVERTED = (1 << 3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
|
||||
FFX_FRAMEGENERATION_ENABLE_DEPTH_INFINITE = (1 << 4), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane.
|
||||
FFX_FRAMEGENERATION_ENABLE_HIGH_DYNAMIC_RANGE = (1 << 5), ///< A bit indicating if the input color data provided to all inputs is using a high-dynamic range.
|
||||
FFX_FRAMEGENERATION_ENABLE_DEBUG_CHECKING = (1 << 6), ///< A bit indicating that the runtime should check some API values and report issues.
|
||||
};
|
||||
|
||||
enum FfxApiDispatchFramegenerationFlags
|
||||
{
|
||||
FFX_FRAMEGENERATION_FLAG_DRAW_DEBUG_TEAR_LINES = (1 << 0), ///< A bit indicating that the debug tear lines will be drawn to the generated output.
|
||||
FFX_FRAMEGENERATION_FLAG_DRAW_DEBUG_RESET_INDICATORS = (1 << 1), ///< A bit indicating that the debug reset indicators will be drawn to the generated output.
|
||||
FFX_FRAMEGENERATION_FLAG_DRAW_DEBUG_VIEW = (1 << 2), ///< A bit indicating that the generated output resource will contain debug views with relevant information.
|
||||
FFX_FRAMEGENERATION_FLAG_NO_SWAPCHAIN_CONTEXT_NOTIFY = (1 << 3), ///< A bit indicating that the context should only run frame interpolation and not modify the swapchain.
|
||||
FFX_FRAMEGENERATION_FLAG_DRAW_DEBUG_PACING_LINES = (1 << 4), ///< A bit indicating that the debug pacing lines will be drawn to the generated output.
|
||||
FFX_FRAMEGENERATION_FLAG_RESERVED_1 = (1 << 5), ///< Reserved for future use.
|
||||
FFX_FRAMEGENERATION_FLAG_RESERVED_2 = (1 << 6), ///< Reserved for future use.
|
||||
};
|
||||
|
||||
enum FfxApiUiCompositionFlags
|
||||
{
|
||||
FFX_FRAMEGENERATION_UI_COMPOSITION_FLAG_USE_PREMUL_ALPHA = (1 << 0), ///< A bit indicating that we use premultiplied alpha for UI composition.
|
||||
FFX_FRAMEGENERATION_UI_COMPOSITION_FLAG_ENABLE_INTERNAL_UI_DOUBLE_BUFFERING = (1 << 1), ///< A bit indicating that the swapchain should doublebuffer the UI resource.
|
||||
};
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x01)
|
||||
struct ffxCreateContextDescFrameGeneration
|
||||
{
|
||||
ffxCreateContextDescHeader header; ///< Description header for frame generation context creation.
|
||||
uint32_t flags; ///< A combination of zero or more values from FfxApiCreateContextFramegenerationFlags.
|
||||
struct FfxApiDimensions2D displaySize; ///< The resolution at which both rendered and generated frames will be displayed.
|
||||
struct FfxApiDimensions2D maxRenderSize; ///< The maximum rendering resolution.
|
||||
uint32_t backBufferFormat; ///< The surface format for the backbuffer. One of the values from FfxApiSurfaceFormat.
|
||||
};
|
||||
|
||||
#define FFX_API_CALLBACK_DESC_TYPE_FRAMEGENERATION_PRESENT FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x05)
|
||||
typedef struct ffxCallbackDescFrameGenerationPresent
|
||||
{
|
||||
ffxDispatchDescHeader header; ///< Description header for present callback dispatch.
|
||||
void* device; ///< The GPU device (ID3D12Device for DX12, VkDevice for Vulkan) passed during context creation.
|
||||
void* commandList; ///< A command list (ID3D12GraphicsCommandList for DX12, VkCommandBuffer for Vulkan) that will be executed before presentation.
|
||||
struct FfxApiResource currentBackBuffer; ///< Backbuffer image either rendered or generated.
|
||||
struct FfxApiResource currentUI; ///< UI image for composition if passed. Otherwise empty.
|
||||
struct FfxApiResource outputSwapChainBuffer; ///< Output image that will be presented.
|
||||
bool isGeneratedFrame; ///< true if this frame is generated, false if rendered.
|
||||
uint64_t frameID; ///< Identifier used to select internal resources when async support is enabled. Must increment by exactly one (1) for each frame. Any non-exactly-one difference will reset the frame generation logic.
|
||||
} ffxCallbackDescFrameGenerationPresent;
|
||||
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_FRAMEGENERATION FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x03)
|
||||
typedef struct ffxDispatchDescFrameGeneration
|
||||
{
|
||||
ffxDispatchDescHeader header; ///< Description header for frame generation dispatch.
|
||||
void* commandList; ///< The command list (ID3D12GraphicsCommandList for DX12, VkCommandBuffer for Vulkan) to record frame generation commands.
|
||||
struct FfxApiResource presentColor; ///< The current presentation color buffer to be used as source for frame generation.
|
||||
struct FfxApiResource outputs[4]; ///< Output destination targets for generated frames (1 for each frame in numGeneratedFrames).
|
||||
uint32_t numGeneratedFrames; ///< The number of frames to generate from the input color target.
|
||||
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously and frame generation should reset.
|
||||
uint32_t backbufferTransferFunction; ///< The transfer function used to convert frame generation source color data to linear RGB. One of the values from FfxApiBackbufferTransferFunction.
|
||||
float minMaxLuminance[2]; ///< Min and max luminance values (in nits), used when converting HDR colors to linear RGB.
|
||||
struct FfxApiRect2D generationRect; ///< The area of the backbuffer that should be used for frame generation in case only a part of the screen is active (e.g. due to movie bars).
|
||||
uint64_t frameID; ///< Identifier used to select internal resources when async support is enabled. Must increment by exactly one (1) for each frame. Any non-exactly-one difference will reset the frame generation logic.
|
||||
} ffxDispatchDescFrameGeneration;
|
||||
|
||||
typedef ffxReturnCode_t (*FfxApiPresentCallbackFunc)(ffxCallbackDescFrameGenerationPresent* params, void* pUserCtx);
|
||||
typedef ffxReturnCode_t (*FfxApiFrameGenerationDispatchFunc)(ffxDispatchDescFrameGeneration* params, void* pUserCtx);
|
||||
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATION FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x02)
|
||||
struct ffxConfigureDescFrameGeneration
|
||||
{
|
||||
ffxConfigureDescHeader header; ///< Description header for frame generation configuration.
|
||||
void* swapChain; ///< The swapchain to use with frame generation (IDXGISwapChain for DX12, VkSwapchainKHR for Vulkan).
|
||||
FfxApiPresentCallbackFunc presentCallback; ///< Callback function called when finalizing the frame image for presentation and UI composition.
|
||||
void* presentCallbackUserContext; ///< User context pointer to be passed to the present callback function.
|
||||
FfxApiFrameGenerationDispatchFunc frameGenerationCallback; ///< Callback function called to dispatch frame generation work and generate interpolated frames.
|
||||
void* frameGenerationCallbackUserContext; ///< User context pointer to be passed to the frame generation callback function.
|
||||
bool frameGenerationEnabled; ///< Sets the state of frame generation. Set to false to disable frame generation.
|
||||
bool allowAsyncWorkloads; ///< Sets the state of async workloads. Set to true to enable generation work on async compute.
|
||||
struct FfxApiResource HUDLessColor; ///< The hudless back buffer image to use for UI extraction from backbuffer resource. May be empty.
|
||||
uint32_t flags; ///< Zero or combination of flags from FfxApiDispatchFrameGenerationFlags.
|
||||
bool onlyPresentGenerated; ///< Set to true to only present generated frames.
|
||||
struct FfxApiRect2D generationRect; ///< The area of the backbuffer that should be used for generation in case only a part of the screen is used e.g. due to movie bars
|
||||
uint64_t frameID; ///< Identifier used to select internal resources when async support is enabled. Must increment by exactly one (1) for each frame. Any non-exactly-one difference will reset the frame generation logic.
|
||||
};
|
||||
|
||||
#pragma FFX_PRAGMA_WARNING_PUSH
|
||||
#pragma FFX_PRAGMA_WARNING_DISABLE_DEPRECATIONS
|
||||
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_FRAMEGENERATION_PREPARE FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x04)
|
||||
struct FFX_DEPRECATION("ffxDispatchDescFrameGenerationPrepare is deprecated, use ffxDispatchDescFrameGeneration" FFX_FRAMEGENERATION_PREPARE_REPLACEMENT_SUFFIX) ffxDispatchDescFrameGenerationPrepare
|
||||
{
|
||||
ffxDispatchDescHeader header; ///< Description header for frame generation prepare dispatch.
|
||||
uint64_t frameID; ///< Frame identifier used to select internal resources when async support is enabled. Must increment by exactly one (1) for each frame. Any non-exactly-one difference will reset the frame generation logic.
|
||||
uint32_t flags; ///< Zero or combination of values from FfxApiDispatchFrameGenerationFlags.
|
||||
void* commandList; ///< The command list (ID3D12GraphicsCommandList for DX12, VkCommandBuffer for Vulkan) to record frame generation prepare commands.
|
||||
struct FfxApiDimensions2D renderSize; ///< The dimensions used to render game content, dilatedDepth, dilatedMotionVectors are expected to be of ths size.
|
||||
struct FfxApiFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
|
||||
struct FfxApiFloatCoords2D motionVectorScale; ///< The scale factor to convert motion vectors to pixel space. Internally: pixelSpaceMV = motionVector * motionVectorScale. Set to renderSize if motion vectors are in UV space [0,1], or to (1.0, 1.0) if motion vectors are already in pixel space. When using display-resolution motion vectors, set to displaySize.
|
||||
|
||||
float frameTimeDelta; ///< Time elapsed in milliseconds since the last frame.
|
||||
bool unused_reset; ///< A (currently unused) boolean value which when set to true, indicates FrameGeneration will be called in reset mode
|
||||
float cameraNear; ///< The distance to the near plane of the camera.
|
||||
float cameraFar; ///< The distance to the far plane of the camera. This is used only used in case of non infinite depth.
|
||||
float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
|
||||
float viewSpaceToMetersFactor; ///< The scale factor to convert view space units to meters
|
||||
struct FfxApiResource depth; ///< The depth buffer data for the current frame.
|
||||
struct FfxApiResource motionVectors; ///< The motion vector data for the current frame.
|
||||
};
|
||||
|
||||
#pragma FFX_PRAGMA_WARNING_POP
|
||||
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATION_KEYVALUE FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x06)
|
||||
struct ffxConfigureDescFrameGenerationKeyValue
|
||||
{
|
||||
ffxConfigureDescHeader header; ///< Description header for frame generation key-value configuration.
|
||||
uint64_t key; ///< Configuration key, member of the FfxApiConfigureFrameGenerationKey enumeration.
|
||||
uint64_t u64; ///< Integer value or enum value to set.
|
||||
void* ptr; ///< Pointer value to set or pointer to value to set.
|
||||
};
|
||||
|
||||
enum FfxApiConfigureFrameGenerationKey
|
||||
{
|
||||
FFX_API_CONFIGURE_FRAMEGENERATION_KEY_DEBUG_VIEW_MODE = 0, ///< A key to set a debug view mode of display.
|
||||
FFX_API_CONFIGURE_FRAMEGENERATION_KEY_DEBUG_VIEW_FLOW_SCALE = 1, ///< A key to set a debug view scale for flow resources.
|
||||
};
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_FRAMEGENERATION_GPU_MEMORY_USAGE FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x07)
|
||||
struct ffxQueryDescFrameGenerationGetGPUMemoryUsage
|
||||
{
|
||||
ffxQueryDescHeader header; ///< Description header for GPU memory usage query.
|
||||
struct FfxApiEffectMemoryUsage* gpuMemoryUsageFrameGeneration; ///< Output pointer to receive GPU memory usage information for frame generation.
|
||||
};
|
||||
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATION_REGISTERDISTORTIONRESOURCE FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x08)
|
||||
//Pass this optional linked struct after ffxConfigureDescFrameGeneration
|
||||
struct ffxConfigureDescFrameGenerationRegisterDistortionFieldResource
|
||||
{
|
||||
ffxConfigureDescHeader header; ///< Description header for distortion field resource configuration.
|
||||
struct FfxApiResource distortionField; ///< A resource containing distortion offset data. Needs to be 2-component (ie. RG). Read by FG shaders via Sample. Pixel value encodes [UV coordinate of pixel after lens distortion effect - UV coordinate of pixel before lens distortion].
|
||||
};
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION_HUDLESS FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x09)
|
||||
//Pass this optional linked struct at FG context creation to enable app to use different hudlessBackBufferformat (IE.RGBA8_UNORM) from backBufferFormat (IE. BGRA8_UNORM)
|
||||
struct ffxCreateContextDescFrameGenerationHudless
|
||||
{
|
||||
ffxCreateContextDescHeader header; ///< Description header for hudless context creation.
|
||||
uint32_t hudlessBackBufferFormat; ///< The surface format for the hudless back buffer. One of the values from FfxApiSurfaceFormat.
|
||||
};
|
||||
|
||||
#pragma FFX_PRAGMA_WARNING_PUSH
|
||||
#pragma FFX_PRAGMA_WARNING_DISABLE_DEPRECATIONS
|
||||
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_FRAMEGENERATION_PREPARE_CAMERAINFO FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x0a)
|
||||
// Link this struct after ffxDispatchDescFrameGenerationPrepare. This is a required input to FSR3.1.4 and FSR3.1.5.
|
||||
// These fields are now embedded in ffxDispatchDescFrameGenerationPrepareV2.
|
||||
struct FFX_DEPRECATION("ffxDispatchDescFrameGenerationPrepareCameraInfo is deprecated, use ffxDispatchDescFrameGeneration" FFX_FRAMEGENERATION_PREPARE_REPLACEMENT_SUFFIX " instead") ffxDispatchDescFrameGenerationPrepareCameraInfo
|
||||
{
|
||||
ffxConfigureDescHeader header; ///< Description header for camera info configuration.
|
||||
float cameraPosition[3]; ///< The camera position in world space.
|
||||
float cameraUp[3]; ///< The camera up normalized vector in world space.
|
||||
float cameraRight[3]; ///< The camera right normalized vector in world space.
|
||||
float cameraForward[3]; ///< The camera forward normalized vector in world space.
|
||||
};
|
||||
|
||||
#pragma FFX_PRAGMA_WARNING_POP
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_FRAMEGENERATION_GPU_MEMORY_USAGE_V2 FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x0b)
|
||||
struct ffxQueryDescFrameGenerationGetGPUMemoryUsageV2
|
||||
{
|
||||
ffxQueryDescHeader header; ///< Description header for GPU memory usage query.
|
||||
void* device; ///< The GPU device. For DX12: pointer to ID3D12Device. For VK: pointer to VkDeviceContext. App needs to fill out before Query() call.
|
||||
struct FfxApiDimensions2D maxRenderSize; ///< The maximum rendering resolution. App needs to fill out before Query() call.
|
||||
struct FfxApiDimensions2D displaySize; ///< The resolution at which both rendered and generated frames will be displayed. App needs to fill out before Query() call.
|
||||
uint32_t createFlags; ///< Context creation flags. A combination of zero or more values from FfxApiCreateContextFramegenerationFlags. App needs to fill out before Query() call.
|
||||
uint32_t dispatchFlags; ///< Dispatch flags. A combination of zero or more values from FfxApiDispatchFrameGenerationFlags. App needs to fill out before Query() call.
|
||||
uint32_t backBufferFormat; ///< The surface format for the backbuffer. One of the values from FfxApiSurfaceFormat. App needs to fill out before Query() call.
|
||||
uint32_t hudlessBackBufferFormat; ///< The surface format for HUDLessColor resource if used. One of the values from FfxApiSurfaceFormat. Otherwise set value to FFX_API_SURFACE_FORMAT_UNKNOWN(0). App needs to fill out before Query() call.
|
||||
struct FfxApiEffectMemoryUsage* gpuMemoryUsageFrameGeneration; ///< Output pointer to receive GPU memory usage information for frame generation. Populated by Query() call.
|
||||
};
|
||||
|
||||
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_FRAMEGENERATION_PREPARE_V2 FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x0c)
|
||||
|
||||
struct ffxDispatchDescFrameGenerationPrepareV2
|
||||
|
||||
{
|
||||
ffxDispatchDescHeader header; ///< Description header for frame generation prepare dispatch.
|
||||
uint64_t frameID; ///< Frame identifier used to select internal resources when async support is enabled. Must increment by exactly one (1) for each frame. Any non-exactly-one difference will reset the frame generation logic.
|
||||
uint32_t flags; ///< Zero or combination of values from FfxApiDispatchFrameGenerationFlags.
|
||||
void* commandList; ///< The command list (ID3D12GraphicsCommandList for DX12, VkCommandBuffer for Vulkan) to record frame generation prepare commands.
|
||||
struct FfxApiDimensions2D renderSize; ///< The dimensions used to render game content. dilatedDepth and dilatedMotionVectors are expected to be of this size.
|
||||
struct FfxApiFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
|
||||
struct FfxApiFloatCoords2D motionVectorScale; ///< The scale factor to convert motion vectors to pixel space. Internally: pixelSpaceMV = motionVector * motionVectorScale. Set to renderSize if motion vectors are in UV space [0,1], or to (1.0, 1.0) if motion vectors are already in pixel space. When using display-resolution motion vectors, set to displaySize.
|
||||
|
||||
float frameTimeDelta; ///< Time elapsed in milliseconds since the last frame.
|
||||
bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously and frame generation should reset its internal state.
|
||||
float cameraNear; ///< The distance to the near plane of the camera.
|
||||
float cameraFar; ///< The distance to the far plane of the camera. This is used only in case of non-infinite depth.
|
||||
float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
|
||||
float viewSpaceToMetersFactor; ///< The scale factor to convert view space units to meters.
|
||||
struct FfxApiResource depth; ///< The depth buffer data for the current frame.
|
||||
struct FfxApiResource motionVectors; ///< The motion vector data for the current frame.
|
||||
|
||||
float cameraPosition[3]; ///< The camera position in world space.
|
||||
float cameraUp[3]; ///< The camera up normalized vector in world space.
|
||||
float cameraRight[3]; ///< The camera right normalized vector in world space.
|
||||
float cameraForward[3]; ///< The camera forward normalized vector in world space.
|
||||
};
|
||||
|
||||
#define FFX_API_CALLBACK_DESC_TYPE_FRAMEGENERATION_PRESENT_PREMUL_ALPHA FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x0d)
|
||||
// This is a structure that is attached to header.pNext of ffxCallbackDescFrameGenerationPresent
|
||||
// Provides whether to use premultiplied alpha blending or not for the UI
|
||||
typedef struct ffxCallbackDescFrameGenerationPresentPremulAlpha
|
||||
{
|
||||
ffxApiHeader header; ///< Header for versioning & ABI stability.
|
||||
bool usePremulAlpha; ///< Toggles whether UI gets premultiplied alpha blending or not.
|
||||
} ffxCallbackDescFrameGenerationPresentPremulAlpha;
|
||||
|
||||
/// Callback function for waiting on a named fence to reach a specific value.
|
||||
/// @param fenceName The name of the fence to wait on.
|
||||
/// @param fenceValueToWaitFor The fence value to wait for.
|
||||
/// @return 0 on success, non-zero error code on failure.
|
||||
typedef int32_t (*FfxWaitCallbackFunc)(wchar_t* fenceName, uint64_t fenceValueToWaitFor);
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION_VERSION FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x0e)
|
||||
// Pass this linked struct at FG context creation to enable new API features - omitting this will prevent new APIs from functioning.
|
||||
struct ffxCreateContextDescFrameGenerationVersion
|
||||
{
|
||||
ffxCreateContextDescHeader header; ///< Description header for frame generation version context creation.
|
||||
uint32_t version; ///< The version of the API the application was built against. This must be set to FFX_FRAMEGENERATION_VERSION.
|
||||
};
|
||||
|
||||
#define FFX_API_FRAME_GENERATION_CONFIG FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATION, 0x0f)
|
||||
/// A structure representing the configuration options to pass to FrameInterpolationSwapChain
|
||||
///
|
||||
/// @ingroup FfxInterface
|
||||
typedef struct FfxFrameGenerationConfig
|
||||
{
|
||||
ffxApiHeader header; ///< Header for versioning & ABI stability.
|
||||
void* swapChain; ///< The <c><i>FfxSwapchain</i></c> to use with frame interpolation.
|
||||
FfxApiPresentCallbackFunc presentCallback; ///< A UI composition callback to call when finalizing the frame image.
|
||||
void* presentCallbackContext; ///< A pointer to be passed to the UI composition callback.
|
||||
FfxApiFrameGenerationDispatchFunc frameGenerationCallback; ///< The frame generation callback to use to generate the interpolated frame.
|
||||
void* frameGenerationCallbackContext; ///< A pointer to be passed to the frame generation callback.
|
||||
bool frameGenerationEnabled; ///< Sets the state of frame generation. Set to false to disable frame generation.
|
||||
bool allowAsyncWorkloads; ///< Sets the state of async workloads. Set to true to enable interpolation work on async compute.
|
||||
bool allowAsyncPresent; ///< Sets the state of async presentation (console only). Set to true to enable present from async command queue.
|
||||
struct FfxApiResource HUDLessColor; ///< The hudless back buffer image to use for UI extraction from backbuffer resource.
|
||||
uint32_t flags; ///< Zero or combination of flags from FfxApiDispatchFrameGenerationFlags.
|
||||
bool onlyPresentInterpolated; ///< Set to true to only present interpolated frame.
|
||||
struct FfxApiRect2D interpolationRect; ///< Set the area in the backbuffer that will be interpolated.
|
||||
uint64_t frameID; ///< A frame identifier used to synchronize resource usage in workloads.
|
||||
bool drawDebugPacingLines; ///< Sets the state of pacing debug lines. Set to true to display debug lines.
|
||||
} FfxFrameGenerationConfig;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
72
runtime/third_party/ffx_sdk/framegeneration/include/ffx_framegeneration_api_types.h
vendored
Normal file
72
runtime/third_party/ffx_sdk/framegeneration/include/ffx_framegeneration_api_types.h
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2026 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../../api/include/ffx_api_types.h"
|
||||
|
||||
/*
|
||||
Tuning varianceFactor and safetyMarginInMs Tips:
|
||||
Calculation of frame pacing algorithm's next target timestamp:
|
||||
target frametime delta = average Frametime - (variance * varianceFactor) - safetyMarginInMs
|
||||
|
||||
Default Tuning uses safetyMarginInMs==0.1ms and varianceFactor==0.1.
|
||||
Say Tuning set A uses safetyMarginInMs==0.75ms, and varianceFactor==0.1.
|
||||
Say Tuning Set B uses safetyMarginInMs==0.01ms and varianceFactor==0.3.
|
||||
|
||||
Example #1 - Actual Game Cutscene. Game's framerate after FG ON during camera pan from normal (19ms avg frametime) to complex (37ms avg frametime over 1 sec) and back to normal scene complexity (19ms avg frametime).
|
||||
After the panning is done,
|
||||
- Default Tuning now gets stuck at targeting ~33ms after panning to a complex scene. GPU utilization significantly lower in this case.
|
||||
- Tuning Set B and Tuning Set A are able to recover close to ~19ms because of these 2 tuning result in lower "target frametime delta" than Default Tuning.
|
||||
|
||||
However, larger varianceFactor or safetyMarginInMs results in higher variance. As seen in Example #2 below.
|
||||
|
||||
Example #2 - FFX_API_FSR sample. Set app fps cap to 33.33ms. Use OCAT to capture 10s at default camera position.
|
||||
FSR 3.1.0 FG msbetweenpresents ping-pong between 16.552 (5th-percentile) and 16.832 (95th-percentile). Variance is 0.01116.
|
||||
Tuning set A FG msbetweenpresents ping-pong between 15.901 (5th-percentile) and 17.500 (95th-percentile). Variance is 0.057674.
|
||||
Tuning Set B FG msbetweenpresents ping-pong between 16.589 (5th-percentile) and 16.971 (95th-percentile). Variance is 0.014452.
|
||||
|
||||
| FG output Frames timestamp | n | n+1 | n+2 | n+3 | frame delta n+1 to n+2 | frame delta n+2 to n+3 |
|
||||
| -------------------------- | - | ------ | ----- | ------ | ---------------------- | ---------------------- |
|
||||
| App real frame presents | 0 | | 33.33 | | | |
|
||||
| Default Tuning | 0 | 16.552 | 33.33 | 49.882 | 16.778 | 16.552 |
|
||||
| Tuning Set A | 0 | 15.901 | 33.33 | 49.231 | 17.429 | 15.901 |
|
||||
| Tuning Set B | 0 | 16.589 | 33.33 | 49.919 | 16.741 | 16.589 |
|
||||
|
||||
Analysis of table data in words:
|
||||
Ignoring the cost of FI,
|
||||
"Tuning set A"'s "target frametime delta" of 15.901 results in larger frame to frame delta (or in other words larger variance) vs Default tuning.
|
||||
"Tuning set B"'s "target frametime delta" of 16.589 results in a bit larger frame to frame delta (or in other words a bit larger variance) vs Default tuning.
|
||||
|
||||
TLDR:
|
||||
If your game when using FG, frame rate is running at an unexpectedly low frame rate, after gradual transition from rendering complex to easy scene complexity, you could try setting "Tuning Set B" to recover lost FPS at cost of a bit higher variance.
|
||||
|
||||
*/
|
||||
|
||||
//struct definition matches FfxSwapchainFramePacingTuning
|
||||
typedef struct FfxApiSwapchainFramePacingTuning
|
||||
{
|
||||
float safetyMarginInMs; ///< Frame pacing sleep time's safety margin in milliseconds. Default is 0.1ms.
|
||||
float varianceFactor; ///< Variance factor for consecutive frame times. Valid range [0.0,1.0], default is 0.1.
|
||||
bool allowHybridSpin; ///< Allows pacing spinlock to sleep. Less precise, but power saving. Default is false.
|
||||
uint32_t hybridSpinTime; ///< How long to spin if allowHybridSpin is true, in timer resolution units. Not recommended to go below 2, as it will result in frequent overshoots. Default is 2.
|
||||
bool allowWaitForSingleObjectOnFence; ///< Allows WaitForSingleObject instead of spinning for fence value. Default is false.
|
||||
} FfxApiSwapchainFramePacingTuning;
|
||||
150
runtime/third_party/ffx_sdk/framegeneration/include/vk/ffx_api_framegeneration_vk.h
vendored
Normal file
150
runtime/third_party/ffx_sdk/framegeneration/include/vk/ffx_api_framegeneration_vk.h
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
// This file is part of the FidelityFX SDK.
|
||||
//
|
||||
// Copyright (C) 2026 Advanced Micro Devices, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../../../api/include/vk/ffx_api_vk.h"
|
||||
|
||||
#define FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION_MAJOR 4
|
||||
#define FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION_MINOR 0
|
||||
#define FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION_PATCH 0
|
||||
|
||||
#define FFX_FRAMEGENERATION_SWAPCHAIN_VK_MAKE_VERSION(major, minor, patch) (((major) << 22) | ((minor) << 12) | (patch))
|
||||
#define FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION FFX_FRAMEGENERATION_SWAPCHAIN_VK_MAKE_VERSION(FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION_MAJOR, FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION_MINOR, FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION_PATCH)
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_FGSWAPCHAIN_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x01)
|
||||
struct ffxCreateContextDescFrameGenerationSwapChainVK
|
||||
{
|
||||
ffxCreateContextDescHeader header;
|
||||
VkPhysicalDevice physicalDevice; ///< the physicak device used by the program.
|
||||
VkDevice device; ///< the logical device used by the program.
|
||||
VkSwapchainKHR* swapchain; ///< the current swapchain to be replaced. Will be destroyed when the context is created. This can be VK_NULL_HANDLE. Will contain the new swapchain on return.
|
||||
VkAllocationCallbacks* allocator; ///< optional allocation callbacks.
|
||||
VkSwapchainCreateInfoKHR createInfo; ///< the description of the desired swapchain. If its VkSwapchainCreateInfoKHR::oldSwapchain field isn't VK_NULL_HANDLE, it should be the same as the ffxCreateContextDescFrameGenerationSwapChainVK::swapchain field above.
|
||||
VkQueueInfoFFXAPI gameQueue; ///< the main graphics queue, where Present is called.
|
||||
VkQueueInfoFFXAPI asyncComputeQueue; ///< A queue with Compute capability.
|
||||
VkQueueInfoFFXAPI presentQueue; ///< A queue with Transfer and Present capabilities.
|
||||
VkQueueInfoFFXAPI imageAcquireQueue; ///< A queue with no capability required.
|
||||
};
|
||||
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_FGSWAPCHAIN_REGISTERUIRESOURCE_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x02)
|
||||
struct ffxConfigureDescFrameGenerationSwapChainRegisterUiResourceVK
|
||||
{
|
||||
ffxConfigureDescHeader header;
|
||||
struct FfxApiResource uiResource; ///< Resource containing user interface for composition. May be empty.
|
||||
uint32_t flags; ///< Zero or combination of values from FfxApiUiCompositionFlags.
|
||||
};
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_FGSWAPCHAIN_INTERPOLATIONCOMMANDLIST_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x03)
|
||||
struct ffxQueryDescFrameGenerationSwapChainInterpolationCommandListVK
|
||||
{
|
||||
ffxQueryDescHeader header;
|
||||
void** pOutCommandList; ///< Output command nuffer (VkCommandBuffer) to be used for frame generation dispatch.
|
||||
};
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_FGSWAPCHAIN_INTERPOLATIONTEXTURE_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x04)
|
||||
struct ffxQueryDescFrameGenerationSwapChainInterpolationTextureVK
|
||||
{
|
||||
ffxQueryDescHeader header;
|
||||
struct FfxApiResource* pOutTexture; ///< Output resource in which the frame interpolation result should be placed.
|
||||
};
|
||||
|
||||
#define FFX_API_DISPATCH_DESC_TYPE_FGSWAPCHAIN_WAIT_FOR_PRESENTS_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x07)
|
||||
struct ffxDispatchDescFrameGenerationSwapChainWaitForPresentsVK
|
||||
{
|
||||
ffxDispatchDescHeader header;
|
||||
};
|
||||
|
||||
#define FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_KEYVALUE_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x08)
|
||||
struct ffxConfigureDescFrameGenerationSwapChainKeyValueVK
|
||||
{
|
||||
ffxConfigureDescHeader header;
|
||||
uint64_t key; ///< Configuration key, member of the FfxApiConfigureFrameGenerationSwapChainKeyVK enumeration.
|
||||
uint64_t u64; ///< Integer value or enum value to set.
|
||||
void* ptr; ///< Pointer to set or pointer to value to set.
|
||||
};
|
||||
|
||||
//enum value matches enum FfxFrameInterpolationSwapchainConfigureKey
|
||||
enum FfxApiConfigureFrameGenerationSwapChainKeyVK
|
||||
{
|
||||
FFX_API_CONFIGURE_FG_SWAPCHAIN_KEY_WAITCALLBACK = 0, ///< Sets FfxWaitCallbackFunc
|
||||
FFX_API_CONFIGURE_FG_SWAPCHAIN_KEY_FRAMEPACINGTUNING = 2, ///< Sets FfxApiSwapchainFramePacingTuning casted from ptr
|
||||
};
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_GPU_MEMORY_USAGE_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x09)
|
||||
struct ffxQueryFrameGenerationSwapChainGetGPUMemoryUsageVK
|
||||
{
|
||||
ffxQueryDescHeader header;
|
||||
struct FfxApiEffectMemoryUsage* gpuMemoryUsageFrameGenerationSwapchain; ///< Output pointer. Requires an existing swapchain context.
|
||||
};
|
||||
|
||||
/// Pre-context GPU memory estimate for a Vulkan frame-generation swapchain.
|
||||
/// Does not require an ffxContext. Pass the device and the swapchain configuration the application intends to create.
|
||||
#define FFX_API_QUERY_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_GPU_MEMORY_USAGE_VK_V2 FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x0b)
|
||||
struct ffxQueryFrameGenerationSwapChainGetGPUMemoryUsageVKV2
|
||||
{
|
||||
ffxQueryDescHeader header; ///< Description header for the pre-context GPU memory query.
|
||||
VkDevice device; ///< Logical device used to size images. Required.
|
||||
VkPhysicalDevice physicalDevice; ///< Physical device that owns the logical device. Required. Used to select an external provider.
|
||||
struct FfxApiDimensions2D displaySize; ///< Resolution of rendered and generated frames. Required.
|
||||
uint32_t backBufferFormat; ///< Backbuffer format. One of the values from FfxApiSurfaceFormat. Required.
|
||||
uint32_t backBufferCount; ///< Number of application backbuffers, from 1 through 6. Required.
|
||||
struct FfxApiDimensions2D uiResourceSize; ///< UI resource resolution. Required when flags requests internal UI double buffering, otherwise ignored.
|
||||
uint32_t uiResourceFormat; ///< UI resource format. One of the values from FfxApiSurfaceFormat. Required when flags requests internal UI double buffering.
|
||||
uint32_t flags; ///< UI composition flags. Zero or a combination of values from FfxApiUiCompositionFlags.
|
||||
uint32_t composeOnGameQueue; ///< Nonzero when UI composition runs on the game queue. Adds the composition output image.
|
||||
uint32_t reserved; ///< Must be zero.
|
||||
struct FfxApiEffectMemoryUsage* gpuMemoryUsageFrameGenerationSwapchain; ///< Output. totalUsageInBytes is the sum of the swapchain images. aliasableUsageInBytes is zero because those images stay live together.
|
||||
};
|
||||
|
||||
/// Function to get the number of presents. This is useful when using frame interpolation
|
||||
typedef uint64_t(*PFN_getLastPresentCountFFXAPI)(VkSwapchainKHR);
|
||||
|
||||
/// FFX API specific functions to create and destroy a swapchain
|
||||
typedef VkResult(*PFN_vkCreateSwapchainFFXAPI)(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain, void* pContext);
|
||||
typedef void(*PFN_vkDestroySwapchainFFXAPI)(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator, void* pContext);
|
||||
|
||||
#define FFX_API_QUERY_DESC_TYPE_FGSWAPCHAIN_FUNCTIONS_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x05)
|
||||
struct ffxQueryDescSwapchainReplacementFunctionsVK
|
||||
{
|
||||
ffxQueryDescHeader header;
|
||||
PFN_vkCreateSwapchainFFXAPI pOutCreateSwapchainFFXAPI; ///< Replacement of vkCreateSwapchainKHR. Recreates the swapchain in place (for example on resize or vsync toggle); pContext and the returned handle are the existing frame generation swapchain.
|
||||
PFN_vkDestroySwapchainFFXAPI pOutDestroySwapchainFFXAPI; ///< Replacement of vkDestroySwapchainKHR. Must be called after the swapchain context is destroyed; pContext is the frame generation swapchain. The handle is invalid afterwards.
|
||||
PFN_vkGetSwapchainImagesKHR pOutGetSwapchainImagesKHR; ///< Replacement of vkGetSwapchainImagesKHR.
|
||||
PFN_vkAcquireNextImageKHR pOutAcquireNextImageKHR; ///< Replacement of vkAcquireNextImageKHR.
|
||||
PFN_vkQueuePresentKHR pOutQueuePresentKHR; ///< Replacement of vkQueuePresentKHR.
|
||||
PFN_vkSetHdrMetadataEXT pOutSetHdrMetadataEXT; ///< Replacement of vkSetHdrMetadataEXT.
|
||||
PFN_getLastPresentCountFFXAPI pOutGetLastPresentCountFFXAPI; ///< Additional function to get the number of times present has been called since the swapchain creation.
|
||||
};
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_FGSWAPCHAIN_MODE_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x10)
|
||||
struct ffxCreateContextDescFrameGenerationSwapChainModeVK
|
||||
{
|
||||
ffxCreateContextDescHeader header;
|
||||
bool composeOnPresentQueue; ///< flags indicating that composition will happen on the present queue
|
||||
};
|
||||
|
||||
#define FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_VERSION_VK FFX_API_MAKE_EFFECT_SUB_ID(FFX_API_EFFECT_ID_FRAMEGENERATIONSWAPCHAIN_VK, 0x0a)
|
||||
struct ffxCreateContextDescFrameGenerationSwapChainVersionVK
|
||||
{
|
||||
ffxCreateContextDescHeader header; ///< Description header for frame generation swapchain version context creation.
|
||||
uint32_t version; ///< The API version the application was built against. This must be set to FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION.
|
||||
};
|
||||
310
runtime/ui/debug_menu.cpp
Normal file
310
runtime/ui/debug_menu.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
// The debug menu's panel (F9 with debug_menu = 1; ui/menu.cpp lays it out in the settings menu's place while it is
|
||||
// open, so its input, its sounds and the game's blocked pad are the menu's own): on the left edge, in the performance
|
||||
// overlay's look, with the game in view beside it. What it does to the game is in
|
||||
// debug_tools.c: the game's on/off flags by name, the game's speed, Link's position, and a search of the game's memory
|
||||
// with values to set and to hold. Plain Dear ImGui with English text: a tool for testing, not part of the game's
|
||||
// interface. Present thread only.
|
||||
#include <algorithm>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
#include "debug_tools.h"
|
||||
extern "C" void rt_log(const char *fmt, ...);
|
||||
#include "ui/debug_menu.h"
|
||||
#include "ui/menu_skin.h"
|
||||
|
||||
namespace {
|
||||
|
||||
int g_tab = -1; // a tab asked for by the test hook (debug_menu_tab), -1 none
|
||||
|
||||
// ---- flags
|
||||
char f_filter[64];
|
||||
bool f_only_on, f_only_named;
|
||||
int *f_rows; // the flags that pass the filter
|
||||
int f_rows_n, f_count;
|
||||
int f_age = 1000; // frames since the values were read
|
||||
bool f_dirty = true;
|
||||
struct Change { uint32_t hash; int on; char name[72]; } f_log[6];
|
||||
int f_log_n;
|
||||
|
||||
bool contains(const char *hay, const char *needle) {
|
||||
size_t n = strlen(needle);
|
||||
for (; *hay; hay++) {
|
||||
size_t i = 0;
|
||||
while (i < n && hay[i] && tolower((unsigned char)hay[i]) == tolower((unsigned char)needle[i])) i++;
|
||||
if (i == n) return true;
|
||||
}
|
||||
return !n;
|
||||
}
|
||||
|
||||
void flags_filter(void) {
|
||||
if (!f_rows) f_rows = (int *)malloc(sizeof(int) * 200000);
|
||||
f_rows_n = 0;
|
||||
if (!f_rows) return;
|
||||
char hex[12];
|
||||
for (int i = 0; i < f_count && i < 200000; i++) {
|
||||
const char *name = dbg_flag_name(i);
|
||||
if (f_only_on && !dbg_flag_value(i)) continue;
|
||||
if (f_only_named && !name) continue;
|
||||
if (f_filter[0]) {
|
||||
snprintf(hex, sizeof hex, "%08x", dbg_flag_hash(i));
|
||||
if (!(name && contains(name, f_filter)) && !contains(hex, f_filter)) continue;
|
||||
}
|
||||
f_rows[f_rows_n++] = i;
|
||||
}
|
||||
// the named ones first, by name; the rest by hash, as the back end lists them
|
||||
std::stable_sort(f_rows, f_rows + f_rows_n, [](int a, int b) {
|
||||
const char *x = dbg_flag_name(a), *y = dbg_flag_name(b);
|
||||
if (!x || !y) return x && !y;
|
||||
return strcmp(x, y) < 0;
|
||||
});
|
||||
f_dirty = false;
|
||||
if (getenv("NX2NAVI_DBG_TEST")) rt_log("debug: filter \"%s\": %d flags shown", f_filter, f_rows_n); // test runs
|
||||
}
|
||||
|
||||
void tab_flags(void) {
|
||||
if (++f_age > 20) {
|
||||
int n = dbg_flags_refresh();
|
||||
if (n != f_count) f_count = n, f_dirty = true;
|
||||
f_age = 0;
|
||||
if (f_only_on) f_dirty = true; // values moved
|
||||
}
|
||||
if (!f_count) {
|
||||
ImGui::TextWrapped("The game's flags appear once a save is loaded.");
|
||||
return;
|
||||
}
|
||||
static int names_was;
|
||||
int found = 0, names = dbg_names(&found);
|
||||
if (names != names_was) names_was = names, f_dirty = true;
|
||||
if (names == 2) ImGui::TextWrapped("%d on/off flags of the game, %d with a name found in its event files.", f_count, found);
|
||||
else ImGui::TextWrapped("%d on/off flags of the game. Reading their names from the game's event files...", f_count);
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (ImGui::InputTextWithHint("##filter", "part of a name, or of the hash", f_filter, sizeof f_filter)) f_dirty = true;
|
||||
if (ImGui::Checkbox("only on", &f_only_on)) f_dirty = true;
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Checkbox("only named", &f_only_named)) f_dirty = true;
|
||||
if (f_dirty) flags_filter();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("%d shown", f_rows_n);
|
||||
float log_h = f_log_n ? ImGui::GetTextLineHeightWithSpacing() * (float)(f_log_n + 1) + 8 : 0;
|
||||
if (ImGui::BeginChild("##flags", ImVec2(0, -log_h), ImGuiChildFlags_Borders)) {
|
||||
ImGuiListClipper clip;
|
||||
clip.Begin(f_rows_n);
|
||||
while (clip.Step())
|
||||
for (int r = clip.DisplayStart; r < clip.DisplayEnd; r++) {
|
||||
int i = f_rows[r];
|
||||
const char *name = dbg_flag_name(i);
|
||||
uint32_t hash = dbg_flag_hash(i);
|
||||
bool on = dbg_flag_value(i) != 0;
|
||||
char label[128];
|
||||
if (name) snprintf(label, sizeof label, "%s##%08x", name, hash);
|
||||
else snprintf(label, sizeof label, "(no name) %08x##%08x", hash, hash);
|
||||
if (ImGui::Checkbox(label, &on)) {
|
||||
dbg_flag_set(hash, on);
|
||||
f_age = 15; // read again in a few frames: the game applies the change at its next update
|
||||
for (int k = f_log_n < 6 ? f_log_n : 5; k > 0; k--) f_log[k] = f_log[k - 1];
|
||||
f_log[0].hash = hash, f_log[0].on = on;
|
||||
snprintf(f_log[0].name, sizeof f_log[0].name, "%s", name ? name : "(no name)");
|
||||
if (f_log_n < 6) f_log_n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
if (f_log_n) {
|
||||
ImGui::TextDisabled("Changed in this session (click to put back):");
|
||||
for (int k = 0; k < f_log_n; k++) {
|
||||
char label[128];
|
||||
snprintf(label, sizeof label, "%s %08x -> %s##log%d", f_log[k].name, f_log[k].hash, f_log[k].on ? "on" : "off", k);
|
||||
if (ImGui::SmallButton(label)) {
|
||||
dbg_flag_set(f_log[k].hash, !f_log[k].on);
|
||||
f_log[k].on = !f_log[k].on;
|
||||
f_age = 15;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- world
|
||||
void tab_world(void) {
|
||||
float p[3];
|
||||
if (dbg_player_pos(p)) ImGui::Text("Link is at x %.2f y %.2f z %.2f (metres; y is up)", p[0], p[1], p[2]);
|
||||
else ImGui::TextDisabled("Link's position appears once a save is loaded.");
|
||||
ImGui::Separator();
|
||||
float speed = dbg_speed_factor();
|
||||
ImGui::Text("Game speed");
|
||||
static const float steps[] = {0.1f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f};
|
||||
for (float s : steps) {
|
||||
char label[16];
|
||||
snprintf(label, sizeof label, s < 1 ? "%.2gx" : "%.0fx", s);
|
||||
if (s != steps[0]) ImGui::SameLine();
|
||||
bool is = speed == s;
|
||||
if (is) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
|
||||
if (ImGui::Button(label)) dbg_speed_set(s);
|
||||
if (is) ImGui::PopStyleColor();
|
||||
}
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (ImGui::SliderFloat("##speed", &speed, 0.05f, 8.0f, "%.2fx", ImGuiSliderFlags_Logarithmic)) dbg_speed_set(speed);
|
||||
ImGui::TextWrapped("The whole game runs at this speed, its interface and its music's timing included. It goes back to 1x when "
|
||||
"the game is closed.");
|
||||
ImGui::Separator();
|
||||
ImGui::TextWrapped("Not in this menu yet: teleporting, the free camera and starting cutscenes. They need the game's own "
|
||||
"scene-change, warp and event functions, which are not connected yet; writing Link's position into "
|
||||
"memory does not move him (the physics puts him back).");
|
||||
}
|
||||
|
||||
// ---- memory
|
||||
int m_type; // 0: 4 bytes, 1: 2 bytes, 2: 1 byte, 3: float
|
||||
char m_value[32] = "0";
|
||||
char m_set[32];
|
||||
char m_note[160];
|
||||
const int m_sizes[] = {4, 2, 1, 4};
|
||||
|
||||
bool parse_value(const char *s, uint32_t *out) {
|
||||
char *end = NULL;
|
||||
if (m_type == 3) {
|
||||
float f = strtof(s, &end);
|
||||
memcpy(out, &f, 4);
|
||||
} else {
|
||||
unsigned long long v = strtoull(s, &end, 0);
|
||||
if (v >> (8 * m_sizes[m_type])) return false;
|
||||
*out = (uint32_t)v;
|
||||
}
|
||||
return end && end != s;
|
||||
}
|
||||
|
||||
void show_value(char *out, size_t n, uint32_t v) {
|
||||
if (m_type == 3) {
|
||||
float f;
|
||||
memcpy(&f, &v, 4);
|
||||
snprintf(out, n, "%g", (double)f);
|
||||
} else {
|
||||
snprintf(out, n, "%u", v);
|
||||
}
|
||||
}
|
||||
|
||||
void tab_memory(void) {
|
||||
ImGui::TextWrapped("Finds a value in the game's memory: search for what a number is now, change it in the game, then narrow "
|
||||
"the places down until few are left. Setting or holding a wrong place can break the running game; a save "
|
||||
"made before is the way back.");
|
||||
const float field = ImGui::GetFontSize() * 12;
|
||||
ImGui::SetNextItemWidth(field);
|
||||
int over = 0, count = dbg_search_count(&over);
|
||||
if (count) ImGui::BeginDisabled();
|
||||
ImGui::Combo("##type", &m_type, "4 bytes (whole number)\0002 bytes\0001 byte\000float (4 bytes)\000");
|
||||
if (count) ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(field * 0.6f);
|
||||
ImGui::InputText("value", m_value, sizeof m_value, ImGuiInputTextFlags_CharsScientific);
|
||||
uint32_t v = 0;
|
||||
bool ok = parse_value(m_value, &v);
|
||||
if (!count) {
|
||||
if (!ok) ImGui::BeginDisabled();
|
||||
if (ImGui::Button("Search all memory")) {
|
||||
int n = dbg_search_new(v, m_sizes[m_type]);
|
||||
dbg_search_count(&over);
|
||||
snprintf(m_note, sizeof m_note, over ? "More than %d places hold it: only these are kept. Search for a rarer value, or narrow down."
|
||||
: "%d places hold it.", n);
|
||||
}
|
||||
if (!ok) ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(takes a few seconds; the game waits)");
|
||||
} else {
|
||||
static const char *const modes[] = {"equals the value", "changed", "unchanged", "went up", "went down"};
|
||||
for (int m = 0; m < 5; m++) {
|
||||
if (m && m != 3) ImGui::SameLine(); // two rows: the panel is narrow
|
||||
if (m == 0 && !ok) ImGui::BeginDisabled();
|
||||
if (ImGui::Button(modes[m])) snprintf(m_note, sizeof m_note, "%d places left.", dbg_search_next(m, v));
|
||||
if (m == 0 && !ok) ImGui::EndDisabled();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("New search")) dbg_search_clear(), m_note[0] = 0;
|
||||
}
|
||||
if (m_note[0]) ImGui::TextUnformatted(m_note);
|
||||
int frozen = dbg_frozen_count();
|
||||
if (frozen) {
|
||||
char label[48];
|
||||
snprintf(label, sizeof label, "Stop holding %d value%s", frozen, frozen == 1 ? "" : "s");
|
||||
if (ImGui::Button(label)) dbg_unfreeze_all();
|
||||
}
|
||||
count = dbg_search_count(&over);
|
||||
if (!count) return;
|
||||
ImGui::SetNextItemWidth(field * 0.6f);
|
||||
ImGui::InputText("value to set", m_set, sizeof m_set, ImGuiInputTextFlags_CharsScientific);
|
||||
uint32_t setv = 0;
|
||||
bool set_ok = parse_value(m_set, &setv);
|
||||
int size = dbg_search_size();
|
||||
if (ImGui::BeginChild("##results", ImVec2(0, 0), ImGuiChildFlags_Borders)) {
|
||||
int shown = count < 300 ? count : 300;
|
||||
if (count > shown) ImGui::TextDisabled("The first %d of %d places:", shown, count);
|
||||
for (int i = 0; i < shown; i++) {
|
||||
uint64_t a = dbg_search_addr(i);
|
||||
uint32_t now = 0;
|
||||
char text[32] = "?";
|
||||
if (dbg_mem_read(a, size, &now)) show_value(text, sizeof text, now);
|
||||
ImGui::PushID(i);
|
||||
ImGui::Text("%012llx %-14s", (unsigned long long)a, text);
|
||||
ImGui::SameLine();
|
||||
if (!set_ok) ImGui::BeginDisabled();
|
||||
if (ImGui::SmallButton("Set")) dbg_mem_write(a, setv, size);
|
||||
if (!set_ok) ImGui::EndDisabled();
|
||||
ImGui::SameLine();
|
||||
bool hold = dbg_frozen(a) != 0;
|
||||
if (ImGui::Checkbox("hold", &hold)) {
|
||||
if (!dbg_freeze(a, set_ok ? setv : now, size, hold)) snprintf(m_note, sizeof m_note, "No more than 64 values can be held.");
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" void debug_menu_tab(int tab) { g_tab = tab; }
|
||||
|
||||
// A panel on the left edge in the performance overlay's dress (the game's panel art, gold labels, the smaller text),
|
||||
// as tall as the window: the game stays in view beside it while a flag or a value is changed.
|
||||
extern "C" void debug_menu_layout(uint32_t w, uint32_t h, float scale) {
|
||||
const float m = 12 * scale;
|
||||
const ImVec4 gold(236 / 255.0f, 196 / 255.0f, 104 / 255.0f, 1), dim(0.72f, 0.69f, 0.62f, 1);
|
||||
float width = (float)w * 0.27f, min_width = 560 * scale;
|
||||
if (width < min_width) width = min_width < (float)w - 2 * m ? min_width : (float)w - 2 * m;
|
||||
ImGui::SetNextWindowPos(ImVec2(m, m), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(width, (float)h - 2 * m), ImGuiCond_Always);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); // the panel below is the background
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(24 * scale, 20 * scale));
|
||||
bool shown = ImGui::Begin("##debug", NULL, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor();
|
||||
if (shown) {
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
ImVec2 a = ImGui::GetWindowPos(), sz = ImGui::GetWindowSize();
|
||||
skin_panel(dl, a, ImVec2(a.x + sz.x, a.y + sz.y), scale * 0.8f, 0.92f);
|
||||
ImGui::SetWindowFontScale(0.72f);
|
||||
ImGui::TextColored(gold, "Debug menu");
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(dim, " F9 or Esc closes");
|
||||
ImGui::Dummy(ImVec2(0, 2 * scale));
|
||||
if (!dbg_supported()) {
|
||||
ImGui::TextWrapped("The debug menu knows the structures of Ocarina of Time 1.1.1 only.");
|
||||
} else if (ImGui::BeginTabBar("##tabs")) {
|
||||
static const char *const names[] = {"Flags", "World", "Memory"};
|
||||
for (int t = 0; t < 3; t++) {
|
||||
if (ImGui::BeginTabItem(names[t], NULL, g_tab == t ? ImGuiTabItemFlags_SetSelected : 0)) {
|
||||
if (t == 0) tab_flags();
|
||||
else if (t == 1) tab_world();
|
||||
else tab_memory();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
g_tab = -1;
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
13
runtime/ui/debug_menu.h
Normal file
13
runtime/ui/debug_menu.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// The debug menu's window (ui/debug_menu.cpp), laid out by ui/menu.cpp in the settings menu's place.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void debug_menu_layout(uint32_t w, uint32_t h, float scale); // between ImGui::NewFrame and Render, present thread
|
||||
void debug_menu_tab(int tab); // the tab to show at the next layout (test hook): 0 to 2
|
||||
#define DEBUG_MENU_TABS 3
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -36,12 +36,14 @@ static int g_font_bad;
|
||||
#pragma clang diagnostic pop
|
||||
#include "ui/amiibo_page.h"
|
||||
#include "ui/binds_page.h"
|
||||
#include "ui/debug_menu.h"
|
||||
#include "ui/option_rows.h"
|
||||
#include "ui/perf_panel.h"
|
||||
|
||||
extern "C" {
|
||||
#include "amiibo.h"
|
||||
#include "cheats.h"
|
||||
#include "debug_tools.h"
|
||||
#include "cfg.h"
|
||||
#include "folder_pick.h"
|
||||
#include "fs.h"
|
||||
@@ -73,6 +75,10 @@ int vk_ffx_available(void); // vk_ffx.cpp: FSR 3.1 upscaling can run
|
||||
int vk_ffx_framegen_available(void); // ... and FSR 3.1 frame generation
|
||||
int vk_ffx4_available(void); // vk_ffx4.cpp: AMD's FSR 4 runs on this device (its libraries, card and driver)
|
||||
int vk_ffx_fsr4(void); // vk_ffx.cpp: ... and the setting asks for it (NX2NAVI_FSR4)
|
||||
int vk_fg4_available(void); // vk_fg4.cpp: the frame generation of AMD's FSR 4 library runs on this device
|
||||
int vk_fg4_failed(void); // ... it failed in this run, FSR 3.1's generates the frames
|
||||
int vk_fg4_active(void); // ... its swapchain is in place
|
||||
const char *vk_fg4_name(void); // ... the version the library runs here ("3.1.6", "4.0.2")
|
||||
int vk_texture_detail_auto(void); // vk_texture.c: the texture detail auto picks on this card, 0 full to 2 low
|
||||
double frame_step_limit_hz(void);
|
||||
int frame_limit_follows_display(void);
|
||||
@@ -125,17 +131,34 @@ static int change_open(int want) {
|
||||
|
||||
static void set_open(int open) { change_open(open); }
|
||||
|
||||
// The debug menu (ui/debug_menu.cpp; F9 with NX2NAVI_DEBUG_MENU = 1) is laid out in this menu's place: open is the one
|
||||
// state for both, with its input, its sounds and the game's blocked pad, and g_debug says which window it shows.
|
||||
static std::atomic<int> g_debug{0};
|
||||
extern "C" int menu_debug_enabled(void) { return cfg_bool("NX2NAVI_DEBUG_MENU"); }
|
||||
|
||||
static int g_failed_flag();
|
||||
// Until the game's first frame (menu_overlay_frame), boot screen included: the menu does not open, as it would not be
|
||||
// drawn while its keys queued up and changed settings once the game ran.
|
||||
static std::atomic<int> g_booting{1};
|
||||
extern "C" int menu_is_open(void) { return g_open.load(std::memory_order_relaxed); }
|
||||
extern "C" void menu_toggle(void) {
|
||||
if (!g_failed_flag() && !g_booting.load(std::memory_order_acquire)) change_open(-1);
|
||||
if (g_failed_flag() || g_booting.load(std::memory_order_acquire)) return;
|
||||
if (!menu_is_open()) g_debug.store(0); // F1 opens the settings; with either window open it closes that one
|
||||
change_open(-1);
|
||||
}
|
||||
// F9: opens the debug menu, and closes it again; with the settings menu open it does nothing.
|
||||
extern "C" void menu_debug_toggle(void) {
|
||||
if (!menu_debug_enabled() || g_failed_flag() || g_booting.load(std::memory_order_acquire)) return;
|
||||
if (menu_is_open()) {
|
||||
if (g_debug.load()) change_open(0);
|
||||
return;
|
||||
}
|
||||
g_debug.store(1);
|
||||
change_open(1);
|
||||
}
|
||||
|
||||
// ---- events from the window adapter, queued while the menu is open; the present path hands them to ImGui
|
||||
enum { EV_KEY, EV_POS, EV_BUTTON, EV_WHEEL, EV_FOCUS, EV_MAX = 256 };
|
||||
enum { EV_KEY, EV_POS, EV_BUTTON, EV_WHEEL, EV_FOCUS, EV_CHAR, EV_MAX = 256 };
|
||||
struct Ev { int type, a, b; float x, y; };
|
||||
static Ev ev_q[EV_MAX];
|
||||
|
||||
@@ -154,6 +177,8 @@ static void push(Ev e) {
|
||||
}
|
||||
|
||||
extern "C" void menu_event_key(int key, int down) { push({EV_KEY, key, down, 0, 0}); }
|
||||
// a typed character, for the debug menu's text fields (the settings menu has none)
|
||||
extern "C" void menu_event_char(unsigned c) { push({EV_CHAR, (int)c, 0, 0, 0}); }
|
||||
extern "C" void menu_event_mouse_pos(float x, float y) { push({EV_POS, 0, 0, x, y}); }
|
||||
extern "C" void menu_event_mouse_button(int button, int down) { push({EV_BUTTON, button, down, 0, 0}); }
|
||||
extern "C" void menu_event_wheel(float dx, float dy) { push({EV_WHEEL, 0, 0, dx, dy}); }
|
||||
@@ -179,6 +204,7 @@ static void drain_events(ImGuiIO &io) {
|
||||
case EV_BUTTON: io.AddMouseButtonEvent(e.a, e.b != 0); break;
|
||||
case EV_WHEEL: io.AddMouseWheelEvent(e.x, e.y); break;
|
||||
case EV_FOCUS: io.AddFocusEvent(e.a != 0); break;
|
||||
case EV_CHAR: io.AddInputCharacter((unsigned)e.a); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1007,6 +1033,19 @@ static bool framegen_restart(void) {
|
||||
return framegen_ngx() ? set && !vk_ngxfg_wanted() : set != (vk_dlssg_wanted() != 0);
|
||||
}
|
||||
|
||||
// The frame generation of the library FSR 4 comes with (vk_fg4.cpp), as the row names it: with the version the library
|
||||
// runs on this card, the machine-learned 4.x on a Radeon RX 9000 and 3.1.x on any other.
|
||||
static const char *fg4_label(void) {
|
||||
static char s[48];
|
||||
const char *v = vk_fg4_name();
|
||||
snprintf(s, sizeof s, *v ? "AMD FSR 4 library (%s)" : "AMD FSR 4 library", v);
|
||||
return s;
|
||||
}
|
||||
// It is the one in use: set (NX2NAVI_FSR4_FG) with FSR 4 as the upscaler, where it runs (vk_fg.cpp use4).
|
||||
static bool fg4_chosen(void) {
|
||||
return cfg_bool("NX2NAVI_FSR4_FG") && vk_ffx_fsr4() && vk_fg4_available() && !vk_fg4_failed();
|
||||
}
|
||||
|
||||
// Frame generation (vk_fg.cpp, at once; NVIDIA's after a restart); it needs a temporal upscaler's motion vectors
|
||||
static void row_framegen(void) {
|
||||
// the generated frames are made from DLSS's or FSR 3.1's motion vectors: without one of them it would do nothing,
|
||||
@@ -1026,14 +1065,21 @@ static void row_framegen(void) {
|
||||
// Off, AMD's where FSR 3.1 loads and NVIDIA DLSS (vk_dlssg.c, through Streamline and nx2navi_dlssg.dll) on NVIDIA GPUs,
|
||||
// now that Reflex paces it from the frame's start and generated frames are presented; elsewhere one stays listed
|
||||
// while it is set
|
||||
static const char *const all_values[] = {"off", "fsr3", "dlss"};
|
||||
const char *all_names[] = {menu_text(UI_MENU_FRAMEGEN_OFF), "AMD FSR 3.1", "NVIDIA DLSS"};
|
||||
const char *values[3], *names[3];
|
||||
// AMD's has two libraries where FSR 4 runs: the FSR 3.1 library's, and the one of the library FSR 4 comes with,
|
||||
// listed after it as a choice of its own. That one generates only beside FSR 4 upscaling, so choosing it sets the
|
||||
// upscaler to FSR 4 as well; both are NX2NAVI_FRAMEGEN = fsr3, told apart by NX2NAVI_FSR4_FG.
|
||||
enum { OFF, FSR3, FSR4LIB, DLSS };
|
||||
const bool four = cur == 1 && fg4_chosen();
|
||||
const bool four_offered = fsr && vk_ffx4_available() && vk_fg4_available() && !vk_fg4_failed();
|
||||
const int now = cur == 2 ? DLSS : cur == 1 ? (four ? FSR4LIB : FSR3) : OFF;
|
||||
const char *all_names[] = {menu_text(UI_MENU_FRAMEGEN_OFF), "AMD FSR 3.1", fg4_label(), "NVIDIA DLSS"};
|
||||
int kinds[4];
|
||||
const char *names[4];
|
||||
int n = 0, at = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if ((i == 1 && !fsr && cur != 1) || (i == 2 && !dlss && cur != 2)) continue;
|
||||
if (i == cur) at = n;
|
||||
values[n] = all_values[i], names[n++] = all_names[i];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if ((i == FSR3 && !fsr && cur != 1) || (i == FSR4LIB && !four_offered && !four) || (i == DLSS && !dlss && cur != 2)) continue;
|
||||
if (i == now) at = n;
|
||||
kinds[n] = i, names[n++] = all_names[i];
|
||||
}
|
||||
// AMD's follows the setting; NVIDIA's is set up with the device, so only a change to or from it waits for a restart.
|
||||
// Through NGX it follows the setting too, once NGX is up, which needs DLSS upscaling on when the game starts.
|
||||
@@ -1046,8 +1092,18 @@ static void row_framegen(void) {
|
||||
const int st = cur != 2 || restart ? DLSSG_RUNS : ngx ? (vk_ngxfg_max() ? DLSSG_RUNS : DLSSG_NO_FILES) : vk_dlssg_status();
|
||||
if (st == DLSSG_NO_GPU) note = UI_MENU_FRAMEGEN_OFF_GPU;
|
||||
else if (st == DLSSG_NO_FILES) note = UI_MENU_FRAMEGEN_OFF_FILES;
|
||||
int nv = opt_choice_index("NX2NAVI_FRAMEGEN", UI_MENU_FRAMEGEN, names, n, at, 0, desc, menu_text(note));
|
||||
if (nv >= 0 && nv < n) opt_apply("NX2NAVI_FRAMEGEN", values[nv]);
|
||||
// the note under AMD's names FSR 3.1 as what it needs; the FSR 4 library's runs beside FSR 4, so it has none
|
||||
int nv = opt_choice_index("NX2NAVI_FRAMEGEN", UI_MENU_FRAMEGEN, names, n, at, 0, desc, four && !restart ? NULL : menu_text(note));
|
||||
if (nv >= 0 && nv < n) {
|
||||
const int k = kinds[nv];
|
||||
opt_apply("NX2NAVI_FRAMEGEN", k == OFF ? "off" : k == DLSS ? "dlss" : "fsr3");
|
||||
if (k == FSR4LIB) {
|
||||
opt_apply("NX2NAVI_FSR4_FG", "1");
|
||||
if (!vk_ffx_fsr4()) opt_apply("NX2NAVI_TAA", "fsr3"), opt_apply("NX2NAVI_FSR4", "1");
|
||||
} else if (k == FSR3 && cfg_bool("NX2NAVI_FSR4_FG")) {
|
||||
opt_apply("NX2NAVI_FSR4_FG", "0");
|
||||
}
|
||||
}
|
||||
else if (cur == 2 && upscaled && dlss && ngx) row_framegen_mult_ngx();
|
||||
else if (cur == 2 && upscaled && dlss) row_framegen_mult(restart);
|
||||
}
|
||||
@@ -1203,6 +1259,16 @@ static void tab_game(float scale) {
|
||||
// discord_rpc.c reads the setting on its own thread and connects or clears the status within half a second
|
||||
opt_toggle("NX2NAVI_DISCORD_RPC", UI_MENU_DISCORD_RPC, UI_MENU_DISCORD_RPC_DESC);
|
||||
rows_saves();
|
||||
// The debug menu, a tool for testing with English text of its own: off unless switched on here
|
||||
if (dbg_supported()) {
|
||||
opt_group_text("Testing");
|
||||
const bool on = cfg_bool("NX2NAVI_DEBUG_MENU");
|
||||
if (opt_toggle_text("debug_menu", "Debug menu (F9)",
|
||||
"F9 opens a window for testing: the game's flags by name, the game's speed, and a search of "
|
||||
"its memory with values to set and hold. Changing flags or memory can break a save: keep a "
|
||||
"copy of the save first.", on))
|
||||
opt_apply("NX2NAVI_DEBUG_MENU", on ? "0" : "1");
|
||||
}
|
||||
opt_end();
|
||||
}
|
||||
|
||||
@@ -1654,7 +1720,8 @@ static void perf_picture(const MenuTarget *t, PerfPanel *p) {
|
||||
snprintf(v[8], sizeof v[8], "%s", menu_text(!strcmp(hdr, "native") ? UI_MENU_HDR_NATIVE : cfg_bool("NX2NAVI_HDR") ? UI_MENU_HDR_TONEMAPPED : UI_MENU_FRAMEGEN_OFF));
|
||||
const char *fg = cfg_value("NX2NAVI_FRAMEGEN");
|
||||
const bool fsr_fg = !strcmp(fg, "fsr3") && vk_ffx_framegen_available(); // set but not loadable: off
|
||||
snprintf(v[9], sizeof v[9], "%s", fsr_fg ? "AMD FSR 3.1" : !strcmp(fg, "dlss") ? "NVIDIA DLSS" : menu_text(UI_MENU_FRAMEGEN_OFF));
|
||||
snprintf(v[9], sizeof v[9], "%s", fsr_fg ? (vk_fg4_active() ? fg4_label() : "AMD FSR 3.1")
|
||||
: !strcmp(fg, "dlss") ? "NVIDIA DLSS" : menu_text(UI_MENU_FRAMEGEN_OFF));
|
||||
if (!strcmp(fg, "dlss") && vk_dlssg_active()) // its multiplier as set, clamped to what this GPU allows
|
||||
snprintf(v[9], sizeof v[9], "NVIDIA DLSS %dx",
|
||||
vk_dlssg_multiplier_of(cfg_value("NX2NAVI_FRAMEGEN_MULTIPLIER"), vk_dlssg_multiplier_max(nullptr), nullptr));
|
||||
@@ -1725,6 +1792,8 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
g_test.opened = frame;
|
||||
g_test.page = 0;
|
||||
g_tab_request = 0;
|
||||
g_debug.store(cfg_get("NX2NAVI_MENU_TEST_DEBUG") != NULL); // the test shoots the debug menu's tabs instead
|
||||
if (g_debug.load()) debug_menu_tab(0);
|
||||
set_open(1);
|
||||
open = true;
|
||||
} else if (!g_perf_mode) {
|
||||
@@ -1783,7 +1852,14 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
// no ImGui_ImplVulkan_NewFrame: all it does is upload Dear ImGui's own font atlas when the back end holds none,
|
||||
// which it never does here (fonts_up uploads it, ui/menu_art.cpp menu_font_upload)
|
||||
ImGui::NewFrame();
|
||||
if (open) layout_menu(t->width, t->height, scale);
|
||||
if (open && g_debug.load(std::memory_order_relaxed)) {
|
||||
debug_menu_layout(t->width, t->height, scale);
|
||||
// Esc, or B on the pad when no field is being typed in, closes it
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || (!io.WantTextInput && ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false)))
|
||||
set_open(0);
|
||||
} else if (open) {
|
||||
layout_menu(t->width, t->height, scale);
|
||||
}
|
||||
perf_draw(t, scale);
|
||||
ImGui::Render();
|
||||
if (open) g_save_pending = opt_save_tick(0);
|
||||
@@ -1793,11 +1869,12 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
const char *dir = cfg_get("NX2NAVI_MENU_TEST_DIR");
|
||||
snprintf(path, sizeof path, "%s/menu-test-%llu-%d.png", dir ? dir : ".", (unsigned long long)frame, g_test.page);
|
||||
*shot = path;
|
||||
if (++g_test.page == TAB_COUNT) {
|
||||
if (++g_test.page == (g_debug.load() ? DEBUG_MENU_TABS : TAB_COUNT)) {
|
||||
g_test.page = -1;
|
||||
set_open(0); // the next frame lays out nothing
|
||||
} else {
|
||||
g_tab_request = g_test.page;
|
||||
if (g_debug.load()) debug_menu_tab(g_test.page);
|
||||
}
|
||||
}
|
||||
return ImGui::GetDrawData()->TotalVtxCount > 0;
|
||||
|
||||
@@ -30,6 +30,9 @@ void menu_perf_cycle(void); // F10: the performance overlay off, f
|
||||
// ---- events from the window adapter, used only while the menu is open. key: an ImGuiKey; coordinates in pixels of the
|
||||
// window's client area, which is the swapchain image.
|
||||
void menu_event_key(int key, int down);
|
||||
void menu_event_char(unsigned c); // a typed character (the debug menu's text fields)
|
||||
int menu_debug_enabled(void); // NX2NAVI_DEBUG_MENU: F9 belongs to the debug menu (ui/debug_menu.cpp)
|
||||
void menu_debug_toggle(void); // F9
|
||||
void menu_event_mouse_pos(float x, float y);
|
||||
void menu_event_mouse_button(int button, int down); // 0 left, 1 right, 2 middle
|
||||
void menu_event_wheel(float dx, float dy);
|
||||
|
||||
@@ -49,6 +49,10 @@ extern "C" void menu_sdl_event(const SDL_Event *e) {
|
||||
menu_toggle();
|
||||
return;
|
||||
}
|
||||
if (e->key.scancode == SDL_SCANCODE_F9 && menu_debug_enabled()) { // the debug menu, while its setting is on
|
||||
if (!e->key.repeat) menu_debug_toggle();
|
||||
return;
|
||||
}
|
||||
if (e->key.scancode == SDL_SCANCODE_F10) {
|
||||
if (!e->key.repeat) menu_perf_cycle();
|
||||
return;
|
||||
|
||||
@@ -56,6 +56,11 @@ extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res)
|
||||
*res = 0;
|
||||
return 1;
|
||||
}
|
||||
if (w == VK_F9 && menu_debug_enabled()) { // the debug menu, while its setting is on
|
||||
if (!(l & (1 << 30))) menu_debug_toggle();
|
||||
*res = 0;
|
||||
return 1;
|
||||
}
|
||||
if (w == VK_F10) { // also keeps F10 from opening the window menu
|
||||
if (!(l & (1 << 30))) menu_perf_cycle();
|
||||
*res = 0;
|
||||
@@ -69,6 +74,9 @@ extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res)
|
||||
if (!menu_is_open()) return 0;
|
||||
if (ImGuiKey k = key_of(w)) menu_event_key(k, m == WM_KEYDOWN || m == WM_SYSKEYDOWN);
|
||||
return 0; // F11 and the system keys keep working
|
||||
case WM_CHAR: // typed text, for the debug menu's fields
|
||||
if (menu_is_open() && w >= 0x20 && w < 0xd800) menu_event_char((unsigned)w);
|
||||
return 0;
|
||||
case WM_MOUSEMOVE:
|
||||
if (menu_is_open()) menu_event_mouse_pos((float)GET_X_LPARAM(l), (float)GET_Y_LPARAM(l));
|
||||
return 0;
|
||||
|
||||
@@ -539,6 +539,8 @@ static struct {
|
||||
int fg_cam_ok;
|
||||
float fg_jx, fg_jy;
|
||||
int fg_fresh, fg_reset; // fresh: not handed out yet (vk_dlaa_fg_inputs)
|
||||
uint64_t presents; // vk_dlaa_frame calls so far
|
||||
uint64_t fg_at, hl_at; // presents when the inputs and the HUD-less picture were made (fg_current)
|
||||
// the picture without the HUD for frame generation (vk_dlaa_fg_hudless): DLSS's output encoded to sRGB as the game's
|
||||
// last pass encodes its picture, then copied bit for bit into an RGBA8 UNORM image, the format the present reads; with
|
||||
// HDR on, DLSS's output as RGBA16F, as the game's float picture the present encodes (hl_srgb unused)
|
||||
@@ -565,9 +567,20 @@ static struct {
|
||||
VkImage second_img;
|
||||
} F;
|
||||
|
||||
// What an evaluation left for frame generation is for the present of its own frame. Frame generation takes it only
|
||||
// while its swapchain is in place, so with frame generation off the last evaluation's images stayed marked fresh for
|
||||
// as long as it was off. Among them is the game's own depth target, which the game replaces when the scene's size
|
||||
// changes: switching the upscaler off and on again with frame generation set (the menu's Upscaling row passes through
|
||||
// its choices without one) handed that destroyed image to frame generation's preparation, and AMD's driver ended the
|
||||
// process. Images made more than FG_INPUT_PRESENTS presents ago are therefore never handed out, and vk_dlaa_frame
|
||||
// drops them when the upscaler goes off or on.
|
||||
#define FG_INPUT_PRESENTS 4 // an evaluation is taken at its own present, or the one after when the present thread is behind
|
||||
static int fg_current(uint64_t made) { return D.presents - made <= FG_INPUT_PRESENTS; }
|
||||
|
||||
int vk_dlaa_fg_hudless(VkImage *img, VkImageView *view, uint32_t *w, uint32_t *h, VkFormat *fmt) {
|
||||
if (!D.hl_fresh) return 0;
|
||||
D.hl_fresh = 0;
|
||||
if (!fg_current(D.hl_at)) return 0;
|
||||
*img = D.hl, *view = D.hl_view, *w = D.hl_w, *h = D.hl_h, *fmt = D.hl_fmt;
|
||||
return 1;
|
||||
}
|
||||
@@ -586,6 +599,7 @@ int vk_dlaa_fg_camera(VkDlaaCamera *c) {
|
||||
int vk_dlaa_fg_inputs(VkFfxImage *depth, VkFfxImage *mv, float *jx, float *jy, int *reset) {
|
||||
if (!D.fg_fresh || D.failed) return 0;
|
||||
D.fg_fresh = 0;
|
||||
if (!fg_current(D.fg_at)) return 0;
|
||||
*depth = D.fg_depth, *mv = D.fg_mv, *jx = D.fg_jx, *jy = D.fg_jy, *reset = 0;
|
||||
return 1;
|
||||
}
|
||||
@@ -1743,7 +1757,7 @@ evaluated:
|
||||
D.fg_depth = (VkFfxImage){z->image, z->format, w, h, 0};
|
||||
D.fg_mv = (VkFfxImage){e->mv, VK_FORMAT_R16G16_SFLOAT, w, h, 1};
|
||||
D.fg_depth_view = zv, D.fg_mv_view = e->mv_view;
|
||||
D.fg_jx = jx, D.fg_jy = jy, D.fg_fresh = 1;
|
||||
D.fg_jx = jx, D.fg_jy = jy, D.fg_at = D.presents, D.fg_fresh = 1;
|
||||
next_jitter(w, ow);
|
||||
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 frames without the DLAA point, %llu with camera "
|
||||
@@ -1810,14 +1824,14 @@ static void hudless(VkCommandBuffer cb, struct Size *e, uint32_t w, uint32_t h)
|
||||
VK_FILTER_NEAREST);
|
||||
full_barrier(cb);
|
||||
if (hdr) {
|
||||
D.hl_fresh = 1;
|
||||
D.hl_at = D.presents, D.hl_fresh = 1;
|
||||
return;
|
||||
}
|
||||
VkImageCopy cp = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}, .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.extent = {w, h, 1}};
|
||||
vkCmdCopyImage(cb, D.hl_srgb, VK_IMAGE_LAYOUT_GENERAL, D.hl, VK_IMAGE_LAYOUT_GENERAL, 1, &cp);
|
||||
full_barrier(cb);
|
||||
D.hl_fresh = 1;
|
||||
D.hl_at = D.presents, D.hl_fresh = 1;
|
||||
}
|
||||
|
||||
static int scene_color(VkFormat f) {
|
||||
@@ -1998,6 +2012,7 @@ void vk_dlaa_frame(void) {
|
||||
static unsigned cfg_seen;
|
||||
static int cfg_known;
|
||||
unsigned v = cfg_version();
|
||||
D.presents++;
|
||||
if (cfg_known && v != cfg_seen) setting_presents = SETTING_PRESENTS;
|
||||
else if (setting_presents) setting_presents--;
|
||||
cfg_seen = v, cfg_known = 1;
|
||||
@@ -2015,6 +2030,7 @@ void vk_dlaa_frame(void) {
|
||||
// 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.hold = 0;
|
||||
D.fg_fresh = D.hl_fresh = 0; // frame generation gets nothing made before the switch (fg_current)
|
||||
memset(&F, 0, sizeof F);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@ extern "C" void vk_ffx4_release(void) {}
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "third_party/ffx_sdk/api/include/ffx_api.h"
|
||||
#include "third_party/ffx_sdk/api/include/vk/ffx_api_vk.h"
|
||||
#include "third_party/ffx_sdk/upscalers/include/ffx_upscale.h"
|
||||
#include "vk_ffx4_api.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
@@ -88,19 +87,20 @@ int file_there(const char *path) {
|
||||
return attr != INVALID_FILE_ATTRIBUTES && !(attr & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
// Loads the loader and asks it for the device's upscaler versions. Under g_lock, once the device exists.
|
||||
int probe(void) {
|
||||
int g_loader = -1; // under g_lock: -1 not tried, 0 the loader is not there or does not load, 1 its entry points are in A
|
||||
|
||||
// Loads the SDK's loader from beside the executable. Under g_lock, once the device exists (-1 before).
|
||||
int load(void) {
|
||||
if (g_loader >= 0) return g_loader;
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (!c || !c->device) return -1; // asked before the device: again later
|
||||
char loader[MAX_PATH], upscaler[MAX_PATH];
|
||||
if (!beside_exe("amd_fidelityfx_loader_vk.dll", loader, sizeof loader) ||
|
||||
!beside_exe("amd_fidelityfx_upscaler_vk.dll", upscaler, sizeof upscaler) || !file_there(loader) ||
|
||||
!file_there(upscaler))
|
||||
return 0; // not shipped beside this build: nothing is said, FSR 3.1 is what the menu offers
|
||||
char loader[MAX_PATH];
|
||||
if (!beside_exe("amd_fidelityfx_loader_vk.dll", loader, sizeof loader) || !file_there(loader))
|
||||
return g_loader = 0; // not shipped beside this build: nothing is said, FSR 3.1 is what the menu offers
|
||||
HMODULE m = LoadLibraryA(loader);
|
||||
if (!m) {
|
||||
rt_log("ffx4: %s does not load (error %lu): FSR 4 off", loader, (unsigned long)GetLastError());
|
||||
return 0;
|
||||
return g_loader = 0;
|
||||
}
|
||||
A.create = (PfnFfxCreateContext)(void *)GetProcAddress(m, "ffxCreateContext");
|
||||
A.destroy = (PfnFfxDestroyContext)(void *)GetProcAddress(m, "ffxDestroyContext");
|
||||
@@ -109,36 +109,52 @@ int probe(void) {
|
||||
A.dispatch = (PfnFfxDispatch)(void *)GetProcAddress(m, "ffxDispatch");
|
||||
if (!A.create || !A.destroy || !A.configure || !A.query || !A.dispatch) {
|
||||
rt_log("ffx4: amd_fidelityfx_loader_vk.dll lacks the API entry points: FSR 4 off");
|
||||
return 0;
|
||||
return g_loader = 0;
|
||||
}
|
||||
return g_loader = 1;
|
||||
}
|
||||
|
||||
// The versions the loader lists for one kind of context on this device, in its order: their count, at most cap.
|
||||
// Under g_lock, the loader loaded.
|
||||
int versions(uint64_t type, uint64_t *ids, const char **names, int cap) {
|
||||
const VkCtx *c = vk_ctx();
|
||||
VkDeviceContext dc = {c->device, c->phys, vkGetDeviceProcAddr};
|
||||
uint64_t ids[16] = {}, n = 0;
|
||||
const char *names[16] = {};
|
||||
uint64_t n = 0;
|
||||
ffxQueryDescGetVersions q = {};
|
||||
q.header.type = FFX_API_QUERY_DESC_TYPE_GET_VERSIONS;
|
||||
q.createDescType = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE;
|
||||
q.createDescType = type;
|
||||
q.device = &dc;
|
||||
q.outputCount = &n;
|
||||
ffxReturnCode_t r = A.query(nullptr, &q.header); // the count
|
||||
if (r == FFX_API_RETURN_OK && n) {
|
||||
if (n > 16) n = 16;
|
||||
q.versionIds = ids;
|
||||
q.versionNames = names;
|
||||
r = A.query(nullptr, &q.header);
|
||||
}
|
||||
if (r != FFX_API_RETURN_OK || !n) {
|
||||
rt_log("ffx4: the FSR SDK's loader lists no upscaler for this device (%u): FSR 4 off", (unsigned)r);
|
||||
if (A.query(nullptr, &q.header) != FFX_API_RETURN_OK || !n) return 0; // the count
|
||||
if (n > (uint64_t)cap) n = (uint64_t)cap;
|
||||
q.versionIds = ids;
|
||||
q.versionNames = names;
|
||||
if (A.query(nullptr, &q.header) != FFX_API_RETURN_OK) return 0;
|
||||
return (int)n;
|
||||
}
|
||||
|
||||
// Asks the loader for the device's upscaler versions. Under g_lock; -1 before the device exists.
|
||||
int probe(void) {
|
||||
int loaded = load();
|
||||
if (loaded <= 0) return loaded;
|
||||
char upscaler[MAX_PATH];
|
||||
if (!beside_exe("amd_fidelityfx_upscaler_vk.dll", upscaler, sizeof upscaler) || !file_there(upscaler)) return 0;
|
||||
uint64_t ids[16] = {};
|
||||
const char *names[16] = {};
|
||||
int n = versions(FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE, ids, names, 16);
|
||||
if (!n) {
|
||||
rt_log("ffx4: the FSR SDK's loader lists no upscaler for this device: FSR 4 off");
|
||||
return 0;
|
||||
}
|
||||
char list[200] = "";
|
||||
size_t len = 0;
|
||||
int best = -1, best_major = 0;
|
||||
for (uint64_t i = 0; i < n; i++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
const char *nm = names[i] ? names[i] : "?";
|
||||
len += (size_t)snprintf(list + len, sizeof list - len, "%s%s", i ? ", " : "", nm);
|
||||
if (len >= sizeof list) len = sizeof list - 1;
|
||||
int major = atoi(nm); // "4.1.2", and "4.1.2 *" for a version the driver brings
|
||||
if (major >= 4 && major > best_major) best = (int)i, best_major = major;
|
||||
if (major >= 4 && major > best_major) best = i, best_major = major;
|
||||
}
|
||||
if (best < 0) {
|
||||
rt_log("ffx4: upscaler versions for this device: %s; none is FSR 4 (it needs a Radeon RX 6000, 7000 or 9000 card "
|
||||
@@ -310,6 +326,31 @@ extern "C" int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, cons
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The loader's calls for vk_fg4.cpp (vk_ffx4_api.h).
|
||||
extern "C" int vk_ffx4_api_file(const char *name) {
|
||||
char path[MAX_PATH];
|
||||
return beside_exe(name, path, sizeof path) && file_there(path);
|
||||
}
|
||||
extern "C" int vk_ffx4_api_versions(uint64_t create_type, uint64_t *ids, const char **names, int cap) {
|
||||
std::lock_guard<std::mutex> hold(g_lock);
|
||||
return load() > 0 ? versions(create_type, ids, names, cap) : 0;
|
||||
}
|
||||
extern "C" ffxReturnCode_t vk_ffx4_api_create(ffxContext *ctx, ffxCreateContextDescHeader *desc) {
|
||||
return A.create ? A.create(ctx, desc, nullptr) : FFX_API_RETURN_ERROR;
|
||||
}
|
||||
extern "C" ffxReturnCode_t vk_ffx4_api_destroy(ffxContext *ctx) {
|
||||
return A.destroy ? A.destroy(ctx, nullptr) : FFX_API_RETURN_ERROR;
|
||||
}
|
||||
extern "C" ffxReturnCode_t vk_ffx4_api_configure(ffxContext *ctx, const ffxConfigureDescHeader *desc) {
|
||||
return A.configure ? A.configure(ctx, desc) : FFX_API_RETURN_ERROR;
|
||||
}
|
||||
extern "C" ffxReturnCode_t vk_ffx4_api_query(ffxContext *ctx, ffxQueryDescHeader *desc) {
|
||||
return A.query ? A.query(ctx, desc) : FFX_API_RETURN_ERROR;
|
||||
}
|
||||
extern "C" ffxReturnCode_t vk_ffx4_api_dispatch(ffxContext *ctx, const ffxDispatchDescHeader *desc) {
|
||||
return A.dispatch ? A.dispatch(ctx, desc) : FFX_API_RETURN_ERROR;
|
||||
}
|
||||
|
||||
extern "C" void vk_ffx4_release(void) {
|
||||
if (!A.destroy) return;
|
||||
for (Up &u : U)
|
||||
|
||||
22
runtime/vk_ffx4_api.h
Normal file
22
runtime/vk_ffx4_api.h
Normal file
@@ -0,0 +1,22 @@
|
||||
// The entry points of AMD's FSR SDK 2.4 loader (amd_fidelityfx_loader_vk.dll, which vk_ffx4.cpp loads), for
|
||||
// vk_fg4.cpp. C++ and Windows only, and never in one file with vk_ffx.h's API section: the two sets of headers name
|
||||
// the same types with other layouts.
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "third_party/ffx_sdk/api/include/ffx_api.h"
|
||||
#include "third_party/ffx_sdk/api/include/vk/ffx_api_vk.h"
|
||||
|
||||
extern "C" {
|
||||
// The versions the loader lists for one kind of context (a FFX_API_CREATE_CONTEXT_DESC_TYPE_*) on this device, in
|
||||
// its order, newest first: their count, at most cap. The names are the library's memory. 0 without the loader, before
|
||||
// the device exists, or when it lists none (an effect whose library is not beside the executable).
|
||||
int vk_ffx4_api_versions(uint64_t create_type, uint64_t *ids, const char **names, int cap);
|
||||
int vk_ffx4_api_file(const char *name); // a file of that name is next to the executable (one of the SDK's libraries)
|
||||
// The API's calls (0 = FFX_API_RETURN_OK), valid once vk_ffx4_api_versions returned a count.
|
||||
ffxReturnCode_t vk_ffx4_api_create(ffxContext *ctx, ffxCreateContextDescHeader *desc);
|
||||
ffxReturnCode_t vk_ffx4_api_destroy(ffxContext *ctx);
|
||||
ffxReturnCode_t vk_ffx4_api_configure(ffxContext *ctx, const ffxConfigureDescHeader *desc);
|
||||
ffxReturnCode_t vk_ffx4_api_query(ffxContext *ctx, ffxQueryDescHeader *desc);
|
||||
ffxReturnCode_t vk_ffx4_api_dispatch(ffxContext *ctx, const ffxDispatchDescHeader *desc);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ struct {
|
||||
ffxQueryDescSwapchainReplacementFunctionsVK fn = {};
|
||||
uint64_t frame = 0;
|
||||
int failed = 0;
|
||||
uint64_t generated = 0, paused = 0, no_inputs = 0, hudless = 0;
|
||||
uint64_t generated = 0, paused = 0, no_inputs = 0, hudless = 0, no_hudless = 0;
|
||||
int on = 0; // the last configured frame had generation on (vk_fg_generating)
|
||||
} F;
|
||||
|
||||
@@ -85,10 +85,23 @@ void fail(const char *what, unsigned r) {
|
||||
// NVIDIA's driver when the menu switched from NVIDIA's frame generation to AMD's. That switch waits for a restart,
|
||||
// as the menu says (menu.cpp row_framegen). Not after a failure (fail): the present code then takes AMD's swapchain
|
||||
// down as it does for a switch in the menu, and a plain one follows.
|
||||
//
|
||||
// Two libraries can make the swapchain: the FSR 3.1 library, here, or AMD's FSR SDK 2.4 (vk_fg4.cpp) where the
|
||||
// setting asks for it while FSR 4 is the upscaler (use4). The swapchain in place is wanted only while its library is
|
||||
// still the one to use: a change of that setting or of the upscaler between FSR 3.1 and FSR 4, or a failure of the SDK
|
||||
// 2.4 path, takes it down as switching frame generation off does, and the next present makes it with the other library.
|
||||
static int use4(void) { // NX2NAVI_FSR4_FG (default 0, live): 1 takes the SDK 2.4's frame generation with FSR 4
|
||||
return cfg_bool("NX2NAVI_FSR4_FG") && vk_ffx_fsr4() && !vk_fg4_failed() && vk_fg4_available();
|
||||
}
|
||||
|
||||
extern "C" int vk_fg_wanted(void) {
|
||||
if (F.failed || strcmp(cfg_value("NX2NAVI_FRAMEGEN"), "fsr3") || !cfg_bool("NX2NAVI_DLAA") || !vk_dlaa_wanted() ||
|
||||
vk_dlssg_dpa())
|
||||
if (strcmp(cfg_value("NX2NAVI_FRAMEGEN"), "fsr3") || !cfg_bool("NX2NAVI_DLAA") || !vk_dlaa_wanted() || vk_dlssg_dpa())
|
||||
return 0;
|
||||
int four = use4();
|
||||
if (vk_fg4_active()) return four;
|
||||
if (F.sc) return !F.failed && !four;
|
||||
if (four) return 1;
|
||||
if (F.failed) return 0;
|
||||
if (vk_ffx_framegen_available()) return 1;
|
||||
static int told;
|
||||
if (!__atomic_exchange_n(&told, 1, __ATOMIC_RELAXED))
|
||||
@@ -99,16 +112,28 @@ extern "C" int vk_fg_wanted(void) {
|
||||
// Always the three queues: the setting can be switched on during a run, and idle queues cost nothing.
|
||||
extern "C" uint32_t vk_fg_queue_count(void) { return 3; }
|
||||
|
||||
extern "C" void vk_fg_queues(VkQueue present, VkQueue acquire) { F.present = present, F.acquire = acquire; }
|
||||
extern "C" void vk_fg_queues(VkQueue present, VkQueue acquire) {
|
||||
F.present = present, F.acquire = acquire;
|
||||
vk_fg4_queues(present, acquire);
|
||||
}
|
||||
|
||||
// AMD's swapchain is in place: the window's swapchain handle is AMD's object, and every swapchain call has to go
|
||||
// through AMD's functions. That holds after a failure too, until the present code has replaced the swapchain
|
||||
// (vk_fg_wanted): the plain Vulkan calls must never get that handle.
|
||||
extern "C" int vk_fg_active(void) { return F.sc != nullptr; }
|
||||
extern "C" int vk_fg_active(void) { return F.sc != nullptr || vk_fg4_active(); }
|
||||
|
||||
extern "C" int vk_fg_generating(void) { return vk_fg_active() && !F.failed && __atomic_load_n(&F.on, __ATOMIC_RELAXED); }
|
||||
extern "C" int vk_fg_generating(void) {
|
||||
if (vk_fg4_active()) return vk_fg4_generating();
|
||||
return F.sc && !F.failed && __atomic_load_n(&F.on, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
extern "C" VkResult vk_fg_create_swapchain(const VkSwapchainCreateInfoKHR *ci, VkSwapchainKHR *sc) {
|
||||
if (vk_fg4_active()) return vk_fg4_create_swapchain(ci, sc);
|
||||
if (!F.sc && use4()) {
|
||||
VkResult r = vk_fg4_create_swapchain(ci, sc);
|
||||
if (r == VK_SUCCESS || vk_fg4_active()) return r;
|
||||
// it failed before its swapchain existed and said so (use4 is 0 from here on): the FSR 3.1 library's below
|
||||
}
|
||||
if (F.sc) return F.fn.pOutCreateSwapchainFFXAPI(vk_ctx()->device, ci, nullptr, sc, F.sc);
|
||||
if (!vk_fg_wanted() || F.failed || !F.present || !vk_ffx_load()) return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
const VkCtx *c = vk_ctx();
|
||||
@@ -142,28 +167,34 @@ extern "C" VkResult vk_fg_create_swapchain(const VkSwapchainCreateInfoKHR *ci, V
|
||||
}
|
||||
|
||||
extern "C" void vk_fg_destroy_swapchain(VkSwapchainKHR sc) {
|
||||
if (vk_fg4_active()) return vk_fg4_destroy_swapchain(sc);
|
||||
if (F.sc && sc) F.fn.pOutDestroySwapchainFFXAPI(vk_ctx()->device, sc, nullptr, F.sc);
|
||||
}
|
||||
|
||||
extern "C" VkResult vk_fg_get_images(VkSwapchainKHR sc, uint32_t *n, VkImage *img) {
|
||||
if (vk_fg4_active()) return vk_fg4_get_images(sc, n, img);
|
||||
return F.fn.pOutGetSwapchainImagesKHR(vk_ctx()->device, sc, n, img);
|
||||
}
|
||||
|
||||
extern "C" VkResult vk_fg_acquire(VkSwapchainKHR sc, uint64_t timeout, VkSemaphore sem, uint32_t *idx) {
|
||||
if (vk_fg4_active()) return vk_fg4_acquire(sc, timeout, sem, idx);
|
||||
return F.fn.pOutAcquireNextImageKHR(vk_ctx()->device, sc, timeout, sem, VK_NULL_HANDLE, idx);
|
||||
}
|
||||
|
||||
extern "C" VkResult vk_fg_present(const VkPresentInfoKHR *pi) {
|
||||
if (vk_fg4_active()) return vk_fg4_present(pi);
|
||||
return F.fn.pOutQueuePresentKHR(vk_ctx()->gfx_queue, pi);
|
||||
}
|
||||
|
||||
extern "C" uint64_t vk_fg_presents(VkSwapchainKHR sc) {
|
||||
return vk_fg_active() && F.fn.pOutGetLastPresentCountFFXAPI && sc ? F.fn.pOutGetLastPresentCountFFXAPI(sc) : 0;
|
||||
if (vk_fg4_active()) return vk_fg4_presents(sc);
|
||||
return F.sc && F.fn.pOutGetLastPresentCountFFXAPI && sc ? F.fn.pOutGetLastPresentCountFFXAPI(sc) : 0;
|
||||
}
|
||||
|
||||
// The HDR10 metadata goes to AMD's swapchain through its own call (vk_hdr.c vk_hdr_metadata).
|
||||
extern "C" PFN_vkSetHdrMetadataEXT vk_fg_hdr_metadata_fn(void) {
|
||||
return vk_fg_active() ? F.fn.pOutSetHdrMetadataEXT : nullptr;
|
||||
if (vk_fg4_active()) return vk_fg4_hdr_metadata_fn();
|
||||
return F.sc ? F.fn.pOutSetHdrMetadataEXT : nullptr;
|
||||
}
|
||||
|
||||
// An HDR10 swapchain (10-bit PQ or 16-bit float): frame generation is told its inputs are HDR.
|
||||
@@ -175,7 +206,8 @@ static bool hdr_format(VkFormat f) {
|
||||
extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, VkExtent2D ext, VkImage hudless,
|
||||
VkImageView hudless_view, const int pic[4]) {
|
||||
(void)hudless_view;
|
||||
if (!vk_fg_active() || F.failed) return;
|
||||
if (vk_fg4_active()) return vk_fg4_frame(cb, sc, fmt, ext, hudless, pic);
|
||||
if (!F.sc || F.failed) return;
|
||||
vk_dlaa_hudless_wanted = 1; // the upscaling pass keeps a copy of the picture before the HUD (vk_dlaa.c hudless)
|
||||
const VkCtx *c = vk_ctx();
|
||||
VkFfxImage depth, mv;
|
||||
@@ -226,9 +258,12 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt,
|
||||
depth.height, F.fg_max.width, F.fg_max.height);
|
||||
have = 0;
|
||||
}
|
||||
int on = have && !menu_is_open();
|
||||
// Only with the picture without the HUD: generated from the presented picture alone, the HUD would be warped along
|
||||
// with the scene behind it and trail when the camera turns. A frame without that picture is shown as it is.
|
||||
int on = have && hudless && !menu_is_open();
|
||||
__atomic_store_n(&F.on, on, __ATOMIC_RELAXED);
|
||||
if (!have) F.no_inputs++;
|
||||
else if (!hudless) F.no_hudless++;
|
||||
else if (!on) F.paused++;
|
||||
F.frame++;
|
||||
ffxConfigureDescFrameGeneration cfg = {};
|
||||
@@ -242,7 +277,7 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt,
|
||||
// whole swapchain warped the picture's edges into the bars
|
||||
cfg.generationRect = pic && pic[2] > 0 && pic[3] > 0 ? FfxApiRect2D{pic[0], pic[1], pic[2], pic[3]}
|
||||
: FfxApiRect2D{0, 0, (int32_t)ext.width, (int32_t)ext.height};
|
||||
if (on && hudless) {
|
||||
if (on) {
|
||||
VkFfxImage h = {hudless, fmt, ext.width, ext.height, 1};
|
||||
cfg.HUDLessColor = image(&h);
|
||||
F.hudless++;
|
||||
@@ -273,11 +308,13 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt,
|
||||
if (r != FFX_API_RETURN_OK) return fail("frame generation preparation", r);
|
||||
if (F.frame == 2 || F.frame % 3600 == 0)
|
||||
rt_log("fg: %llu frames presented, %llu generated (%llu with the HUD kept out); paused %llu (menu), %llu without depth "
|
||||
"and motion", (unsigned long long)F.frame, (unsigned long long)F.generated, (unsigned long long)F.hudless,
|
||||
(unsigned long long)F.paused, (unsigned long long)F.no_inputs);
|
||||
"and motion, %llu without the HUD-less picture", (unsigned long long)F.frame, (unsigned long long)F.generated,
|
||||
(unsigned long long)F.hudless, (unsigned long long)F.paused, (unsigned long long)F.no_inputs,
|
||||
(unsigned long long)F.no_hudless);
|
||||
}
|
||||
|
||||
extern "C" void vk_fg_release(void) {
|
||||
vk_fg4_release();
|
||||
if (F.fg) vk_ffx_destroy(&F.fg), F.fg = nullptr;
|
||||
if (F.sc) vk_ffx_destroy(&F.sc), F.sc = nullptr;
|
||||
__atomic_store_n(&F.on, 0, __ATOMIC_RELAXED);
|
||||
|
||||
@@ -26,3 +26,21 @@ void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, VkExtent2D
|
||||
uint64_t vk_fg_presents(VkSwapchainKHR sc); // frames the swapchain presented, generated ones included (0: off)
|
||||
PFN_vkSetHdrMetadataEXT vk_fg_hdr_metadata_fn(void); // AMD's replacement for vkSetHdrMetadataEXT while active, else NULL
|
||||
void vk_fg_release(void);
|
||||
|
||||
// The same through AMD's FSR SDK 2.4 (vk_fg4.cpp), for vk_fg.cpp alone: it takes this path while FSR 4 is the upscaler,
|
||||
// and every call above goes to these while this path holds the swapchain.
|
||||
int vk_fg4_available(void); // its libraries are beside the executable and list a frame generation for the device
|
||||
int vk_fg4_failed(void); // it failed in this run: FSR 3.1's library generates the frames
|
||||
const char *vk_fg4_name(void); // the frame generation version the loader lists first for the device ("3.1.6"), "" unknown
|
||||
int vk_fg4_active(void);
|
||||
int vk_fg4_generating(void);
|
||||
void vk_fg4_queues(VkQueue present, VkQueue acquire);
|
||||
VkResult vk_fg4_create_swapchain(const VkSwapchainCreateInfoKHR *ci, VkSwapchainKHR *sc);
|
||||
void vk_fg4_destroy_swapchain(VkSwapchainKHR sc);
|
||||
VkResult vk_fg4_get_images(VkSwapchainKHR sc, uint32_t *n, VkImage *img);
|
||||
VkResult vk_fg4_acquire(VkSwapchainKHR sc, uint64_t timeout, VkSemaphore sem, uint32_t *idx);
|
||||
VkResult vk_fg4_present(const VkPresentInfoKHR *pi);
|
||||
void vk_fg4_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, VkExtent2D ext, VkImage hudless, const int pic[4]);
|
||||
uint64_t vk_fg4_presents(VkSwapchainKHR sc);
|
||||
PFN_vkSetHdrMetadataEXT vk_fg4_hdr_metadata_fn(void);
|
||||
void vk_fg4_release(void);
|
||||
|
||||
435
runtime/vk_fg4.cpp
Normal file
435
runtime/vk_fg4.cpp
Normal file
@@ -0,0 +1,435 @@
|
||||
// Frame generation through AMD's FSR SDK 2.4: amd_fidelityfx_loader_vk.dll (vk_ffx4.cpp loads it) with
|
||||
// amd_fidelityfx_framegeneration_vk.dll next to the executable. vk_fg.cpp takes this path instead of the FSR 3.1
|
||||
// library's where the setting asks for it while FSR 4 is the upscaler (vk_fg.cpp use4, NX2NAVI_FSR4_FG), and its
|
||||
// functions here are called by vk_fg.cpp alone. The
|
||||
// loader picks the frame generation and the swapchain for the card: the machine-learned FSR Frame Generation 4.x on
|
||||
// Radeon RX 9000 cards with Windows 11, FSR Frame Generation 3.1.x on every other. The log names both versions.
|
||||
//
|
||||
// What happens each frame is what vk_fg.cpp does (the configuration, then the preparation from the frame's depth and
|
||||
// motion vectors, then the generation from the swapchain's callback at present, the order FSR Frame Generation 4
|
||||
// requires), in this SDK's layouts and with what it adds: the camera's position and axes in the preparation, which
|
||||
// FSR Frame Generation 4 needs, and the version each context is made for.
|
||||
//
|
||||
// The swapchain's life differs from the FSR 3.1 library's:
|
||||
// - A new size remakes the swapchain in place: its create function takes the swapchain's own handle, and the handle
|
||||
// stays. vk_fg4_destroy_swapchain therefore does nothing while the swapchain context lives.
|
||||
// - Taking it down (vk_fg4_release) waits for its presents, destroys the frame generation context, then the swapchain
|
||||
// context, and calls its destroy function last, as the SDK asks.
|
||||
#define VK_FFX_NO_API // vk_ffx.h: without the API declarations of the other set of headers
|
||||
#ifndef _WIN32
|
||||
// AMD publishes the SDK's libraries for Windows only: in any other build this path is never available.
|
||||
extern "C" {
|
||||
#include "vk.h"
|
||||
#include "vk_ffx.h"
|
||||
#include "vk_fg.h"
|
||||
}
|
||||
extern "C" int vk_fg4_available(void) { return 0; }
|
||||
extern "C" int vk_fg4_failed(void) { return 0; }
|
||||
extern "C" const char *vk_fg4_name(void) { return ""; }
|
||||
extern "C" int vk_fg4_active(void) { return 0; }
|
||||
extern "C" int vk_fg4_generating(void) { return 0; }
|
||||
extern "C" void vk_fg4_queues(VkQueue, VkQueue) {}
|
||||
extern "C" VkResult vk_fg4_create_swapchain(const VkSwapchainCreateInfoKHR *, VkSwapchainKHR *) {
|
||||
return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
}
|
||||
extern "C" void vk_fg4_destroy_swapchain(VkSwapchainKHR) {}
|
||||
extern "C" VkResult vk_fg4_get_images(VkSwapchainKHR, uint32_t *, VkImage *) { return VK_ERROR_FEATURE_NOT_PRESENT; }
|
||||
extern "C" VkResult vk_fg4_acquire(VkSwapchainKHR, uint64_t, VkSemaphore, uint32_t *) { return VK_ERROR_FEATURE_NOT_PRESENT; }
|
||||
extern "C" VkResult vk_fg4_present(const VkPresentInfoKHR *) { return VK_ERROR_FEATURE_NOT_PRESENT; }
|
||||
extern "C" uint64_t vk_fg4_presents(VkSwapchainKHR) { return 0; }
|
||||
extern "C" PFN_vkSetHdrMetadataEXT vk_fg4_hdr_metadata_fn(void) { return nullptr; }
|
||||
extern "C" void vk_fg4_frame(VkCommandBuffer, VkSwapchainKHR, VkFormat, VkExtent2D, VkImage, const int *) {}
|
||||
extern "C" void vk_fg4_release(void) {}
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <mutex>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "third_party/ffx_sdk/framegeneration/include/ffx_framegeneration.h"
|
||||
#include "third_party/ffx_sdk/framegeneration/include/vk/ffx_api_framegeneration_vk.h"
|
||||
#include "vk_ffx4_api.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
#include "host.h"
|
||||
#include "platform/platform.h"
|
||||
#include "vk.h"
|
||||
#include "vk_dlaa.h"
|
||||
#include "vk_ffx.h"
|
||||
#include "vk_fg.h"
|
||||
#include "ui/menu.h"
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
struct {
|
||||
VkQueue present = VK_NULL_HANDLE, acquire = VK_NULL_HANDLE;
|
||||
ffxContext sc = nullptr; // the swapchain context
|
||||
ffxContext fg = nullptr; // the frame generation context
|
||||
VkSwapchainKHR handle = VK_NULL_HANDLE; // the swapchain the context made: remade in place, destroyed after the context
|
||||
VkExtent2D fg_ext = {0, 0};
|
||||
VkExtent2D fg_max = {0, 0}; // the context's largest render size
|
||||
VkFormat fg_fmt = VK_FORMAT_UNDEFINED;
|
||||
ffxQueryDescSwapchainReplacementFunctionsVK fn = {};
|
||||
// what the contexts were made from: the API asks that it stays until the context is destroyed
|
||||
ffxCreateContextDescFrameGenerationSwapChainVK sc_desc = {};
|
||||
ffxCreateContextDescFrameGenerationSwapChainVersionVK sc_ver = {};
|
||||
ffxOverrideVersion sc_pin = {};
|
||||
ffxCreateContextDescFrameGeneration fg_desc = {};
|
||||
ffxCreateBackendVKDesc fg_be = {};
|
||||
ffxCreateContextDescFrameGenerationHudless fg_hl = {};
|
||||
ffxCreateContextDescFrameGenerationVersion fg_ver = {};
|
||||
ffxOverrideVersion fg_pin = {};
|
||||
uint64_t frame = 0;
|
||||
int failed = 0;
|
||||
uint64_t generated = 0, paused = 0, no_inputs = 0, hudless = 0, no_hudless = 0;
|
||||
int on = 0; // the last configured frame had generation on (vk_fg4_generating)
|
||||
} F;
|
||||
|
||||
std::mutex g_lock; // the probe: the menu asks from its thread, the present from its own
|
||||
int g_avail = -1; // -1 not asked yet; 0 this path does not run here; 1 it does
|
||||
char g_sc_list[96]; // the swapchain versions the loader listed, for the log
|
||||
char g_fg_name[24]; // the frame generation version a context gets: the one asked for, else the first listed
|
||||
uint64_t g_fg_pin, g_sc_pin; // NX2NAVI_FG4_VERSION, NX2NAVI_FG4_SWAPCHAIN (tests): the version asked for by its id; 0 the loader's choice
|
||||
|
||||
VkResult submit_game(uint32_t n, const VkSubmitInfo *si, VkFence fence) {
|
||||
vk_queue_lock(); // the game's queue is shared with the recorder and the present path
|
||||
VkResult r = vkQueueSubmit(vk_ctx()->gfx_queue, n, si, fence);
|
||||
vk_queue_unlock();
|
||||
return r;
|
||||
}
|
||||
|
||||
ffxReturnCode_t generate(ffxDispatchDescFrameGeneration *d, void *user) {
|
||||
F.generated++;
|
||||
return vk_ffx4_api_dispatch((ffxContext *)user, &d->header);
|
||||
}
|
||||
|
||||
FfxApiResource image(const VkFfxImage *i) {
|
||||
VkImageCreateInfo ci = {};
|
||||
ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
ci.imageType = VK_IMAGE_TYPE_2D;
|
||||
ci.format = i->format;
|
||||
ci.extent = {i->width, i->height, 1};
|
||||
ci.mipLevels = 1;
|
||||
ci.arrayLayers = 1;
|
||||
return ffxApiGetResourceVK((void *)i->image, ffxApiGetImageResourceDescriptionVK(i->image, ci, 0),
|
||||
FFX_API_RESOURCE_STATE_UNORDERED_ACCESS);
|
||||
}
|
||||
|
||||
// After this the FSR 3.1 library generates the frames: vk_fg.cpp's vk_fg_wanted stops wanting this swapchain, the
|
||||
// present code takes it down as it does for a switch in the menu, and the next one is made by the other path.
|
||||
void fail(const char *what, unsigned r) {
|
||||
rt_log("fg4: %s failed (%u): the FSR SDK's frame generation is off for this run, FSR 3.1's takes its place", what, r);
|
||||
F.failed = 1;
|
||||
}
|
||||
|
||||
// The list the loader gives for one kind of context, as text, and the id of the version a test asks for by the start
|
||||
// of its name (0: none asked, or not listed).
|
||||
int list_versions(uint64_t type, const char *want, char *out, size_t size, uint64_t *pin) {
|
||||
uint64_t ids[8] = {};
|
||||
const char *names[8] = {};
|
||||
int n = vk_ffx4_api_versions(type, ids, names, 8);
|
||||
size_t len = 0;
|
||||
out[0] = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
const char *nm = names[i] ? names[i] : "?";
|
||||
len += (size_t)snprintf(out + len, size - len, "%s%s", i ? ", " : "", nm);
|
||||
if (len >= size) len = size - 1;
|
||||
if (want && *want && !*pin && !strncmp(nm, want, strlen(want))) *pin = ids[i];
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// The version a context runs, as its provider names it ("3.1.6"); "?" when it does not say.
|
||||
const char *provider(ffxContext *ctx) {
|
||||
ffxQueryGetProviderVersion v = {};
|
||||
v.header.type = FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION;
|
||||
vk_ffx4_api_query(ctx, &v.header);
|
||||
return v.versionName ? v.versionName : "?";
|
||||
}
|
||||
|
||||
// An HDR10 swapchain (10-bit PQ or 16-bit float): frame generation is told its inputs are HDR.
|
||||
bool hdr_format(VkFormat f) {
|
||||
return f == VK_FORMAT_A2B10G10R10_UNORM_PACK32 || f == VK_FORMAT_A2R10G10B10_UNORM_PACK32 ||
|
||||
f == VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||
}
|
||||
|
||||
// The swapchain's own presents are done before it is remade or taken down.
|
||||
void wait_presents(void) {
|
||||
ffxDispatchDescFrameGenerationSwapChainWaitForPresentsVK w = {};
|
||||
w.header.type = FFX_API_DISPATCH_DESC_TYPE_FGSWAPCHAIN_WAIT_FOR_PRESENTS_VK;
|
||||
vk_ffx4_api_dispatch(&F.sc, &w.header);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// The loader and its frame generation library are beside the executable and list a frame generation and a swapchain
|
||||
// for the device. Asked once, with the device; 0 before it exists.
|
||||
extern "C" int vk_fg4_available(void) {
|
||||
int a = __atomic_load_n(&g_avail, __ATOMIC_ACQUIRE); // asked several times a frame
|
||||
if (a >= 0) return a;
|
||||
std::lock_guard<std::mutex> hold(g_lock);
|
||||
if (g_avail >= 0) return g_avail;
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (!c || !c->device) return 0;
|
||||
if (!vk_ffx4_api_file("amd_fidelityfx_framegeneration_vk.dll")) { // not shipped beside this build
|
||||
__atomic_store_n(&g_avail, 0, __ATOMIC_RELEASE);
|
||||
return 0;
|
||||
}
|
||||
char fg[96];
|
||||
char *sc = g_sc_list;
|
||||
int nf = list_versions(FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION, cfg_get("NX2NAVI_FG4_VERSION"), fg, sizeof fg, &g_fg_pin);
|
||||
int ns = list_versions(FFX_API_CREATE_CONTEXT_DESC_TYPE_FGSWAPCHAIN_VK, cfg_get("NX2NAVI_FG4_SWAPCHAIN"), sc, sizeof g_sc_list,
|
||||
&g_sc_pin);
|
||||
a = nf > 0 && ns > 0;
|
||||
// the menu's name for it: the first of the list, which the loader takes when none is asked for (a test's version
|
||||
// changes the context, not this name); a version the driver brings carries a star
|
||||
snprintf(g_fg_name, sizeof g_fg_name, "%.*s", (int)strcspn(fg, ",*"), fg);
|
||||
for (size_t k = strlen(g_fg_name); k && g_fg_name[k - 1] == ' '; k--) g_fg_name[k - 1] = 0;
|
||||
__atomic_store_n(&g_avail, a, __ATOMIC_RELEASE);
|
||||
if (a) rt_log("fg4: the FSR SDK lists for this device: frame generation %s; its swapchain %s", fg, sc);
|
||||
else rt_log("fg4: the FSR SDK lists no frame generation for this device: FSR 3.1's library generates the frames");
|
||||
return a;
|
||||
}
|
||||
|
||||
extern "C" int vk_fg4_failed(void) { return F.failed; }
|
||||
|
||||
extern "C" const char *vk_fg4_name(void) { return g_fg_name; }
|
||||
|
||||
extern "C" void vk_fg4_queues(VkQueue present, VkQueue acquire) { F.present = present, F.acquire = acquire; }
|
||||
|
||||
// The SDK's swapchain is in place: the window's swapchain handle is its object, and every swapchain call has to go
|
||||
// through its functions, after a failure too, until the present code has taken it down.
|
||||
extern "C" int vk_fg4_active(void) { return F.sc != nullptr; }
|
||||
|
||||
extern "C" int vk_fg4_generating(void) { return vk_fg4_active() && !F.failed && __atomic_load_n(&F.on, __ATOMIC_RELAXED); }
|
||||
|
||||
extern "C" VkResult vk_fg4_create_swapchain(const VkSwapchainCreateInfoKHR *ci, VkSwapchainKHR *sc) {
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (F.sc) { // a new size: the swapchain is remade in place and keeps its handle
|
||||
wait_presents();
|
||||
VkSwapchainCreateInfoKHR in = *ci;
|
||||
in.oldSwapchain = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR h = F.handle;
|
||||
VkResult r = F.fn.pOutCreateSwapchainFFXAPI(c->device, &in, nullptr, &h, (void *)F.handle);
|
||||
if (r == VK_SUCCESS) *sc = F.handle = h;
|
||||
return r;
|
||||
}
|
||||
if (F.failed || !F.present || !vk_fg4_available()) return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
F.handle = VK_NULL_HANDLE;
|
||||
F.sc_desc = {};
|
||||
F.sc_desc.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FGSWAPCHAIN_VK;
|
||||
F.sc_desc.physicalDevice = c->phys;
|
||||
F.sc_desc.device = c->device;
|
||||
F.sc_desc.swapchain = &F.handle;
|
||||
F.sc_desc.createInfo = *ci;
|
||||
F.sc_desc.createInfo.oldSwapchain = VK_NULL_HANDLE;
|
||||
F.sc_desc.gameQueue = {c->gfx_queue, c->gfx_family, submit_game};
|
||||
F.sc_desc.asyncComputeQueue = {VK_NULL_HANDLE, c->gfx_family, nullptr};
|
||||
F.sc_desc.presentQueue = {F.present, c->gfx_family, nullptr};
|
||||
F.sc_desc.imageAcquireQueue = {F.acquire, c->gfx_family, nullptr};
|
||||
// the version this code was built against, which the SDK asks for with every context, and a test's version
|
||||
F.sc_ver = {};
|
||||
F.sc_ver.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATIONSWAPCHAIN_VERSION_VK;
|
||||
F.sc_ver.version = FFX_FRAMEGENERATION_SWAPCHAIN_VK_VERSION;
|
||||
F.sc_desc.header.pNext = &F.sc_ver.header;
|
||||
if (g_sc_pin) {
|
||||
F.sc_pin = {};
|
||||
F.sc_pin.header.type = FFX_API_DESC_TYPE_OVERRIDE_VERSION;
|
||||
F.sc_pin.versionId = g_sc_pin;
|
||||
F.sc_ver.header.pNext = &F.sc_pin.header;
|
||||
}
|
||||
ffxReturnCode_t r = vk_ffx4_api_create(&F.sc, &F.sc_desc.header);
|
||||
if (r != FFX_API_RETURN_OK || !F.sc) {
|
||||
F.sc = nullptr, F.handle = VK_NULL_HANDLE;
|
||||
fail("the frame generation swapchain", r);
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
F.fn = {};
|
||||
F.fn.header.type = FFX_API_QUERY_DESC_TYPE_FGSWAPCHAIN_FUNCTIONS_VK;
|
||||
// The swapchain the driver brings (listed with a star, the loader's choice where it is listed) hands out no destroy
|
||||
// function: its context's destruction is the swapchain's too (vk_fg4_release).
|
||||
if (vk_ffx4_api_query(&F.sc, &F.fn.header) != FFX_API_RETURN_OK || !F.fn.pOutQueuePresentKHR || !F.fn.pOutCreateSwapchainFFXAPI ||
|
||||
!F.fn.pOutGetSwapchainImagesKHR || !F.fn.pOutAcquireNextImageKHR || !F.handle) {
|
||||
VkSwapchainKHR h = F.handle;
|
||||
PFN_vkDestroySwapchainFFXAPI destroy = F.fn.pOutDestroySwapchainFFXAPI;
|
||||
vk_ffx4_api_destroy(&F.sc), F.sc = nullptr, F.handle = VK_NULL_HANDLE;
|
||||
if (h && destroy) destroy(c->device, h, nullptr, nullptr); // nothing was handed out yet
|
||||
fail("the swapchain functions", 0);
|
||||
return VK_ERROR_INITIALIZATION_FAILED;
|
||||
}
|
||||
*sc = F.handle;
|
||||
rt_log("fg4: AMD FSR frame generation swapchain, %ux%u (%s%s)", ci->imageExtent.width, ci->imageExtent.height,
|
||||
g_sc_pin ? "the version a test asked for, of " : "the loader's choice of ", g_sc_list);
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
// Nothing while the swapchain context lives: a new size remakes the swapchain in place (vk_fg4_create_swapchain), and
|
||||
// vk_fg4_release destroys it after its context.
|
||||
extern "C" void vk_fg4_destroy_swapchain(VkSwapchainKHR sc) { (void)sc; }
|
||||
|
||||
extern "C" VkResult vk_fg4_get_images(VkSwapchainKHR sc, uint32_t *n, VkImage *img) {
|
||||
return F.fn.pOutGetSwapchainImagesKHR(vk_ctx()->device, sc, n, img);
|
||||
}
|
||||
|
||||
extern "C" VkResult vk_fg4_acquire(VkSwapchainKHR sc, uint64_t timeout, VkSemaphore sem, uint32_t *idx) {
|
||||
return F.fn.pOutAcquireNextImageKHR(vk_ctx()->device, sc, timeout, sem, VK_NULL_HANDLE, idx);
|
||||
}
|
||||
|
||||
extern "C" VkResult vk_fg4_present(const VkPresentInfoKHR *pi) { return F.fn.pOutQueuePresentKHR(vk_ctx()->gfx_queue, pi); }
|
||||
|
||||
extern "C" uint64_t vk_fg4_presents(VkSwapchainKHR sc) {
|
||||
return vk_fg4_active() && F.fn.pOutGetLastPresentCountFFXAPI && sc ? F.fn.pOutGetLastPresentCountFFXAPI(sc) : 0;
|
||||
}
|
||||
|
||||
extern "C" PFN_vkSetHdrMetadataEXT vk_fg4_hdr_metadata_fn(void) { return vk_fg4_active() ? F.fn.pOutSetHdrMetadataEXT : nullptr; }
|
||||
|
||||
extern "C" void vk_fg4_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, VkExtent2D ext, VkImage hudless, const int pic[4]) {
|
||||
if (!vk_fg4_active() || F.failed) return;
|
||||
vk_dlaa_hudless_wanted = 1; // the upscaling pass keeps a copy of the picture before the HUD (vk_dlaa.c hudless)
|
||||
const VkCtx *c = vk_ctx();
|
||||
VkFfxImage depth, mv;
|
||||
float jx = 0, jy = 0;
|
||||
int reset = 0;
|
||||
int have = vk_dlaa_fg_inputs(&depth, &mv, &jx, &jy, &reset);
|
||||
// The context's largest render size covers the depth and motion vectors it is given: the picture's size, which
|
||||
// the scene never exceeds (vk_fg.cpp vk_fg_frame has the history of this rule).
|
||||
unsigned pw, ph;
|
||||
wide_picture(&pw, &ph);
|
||||
VkExtent2D max_render = {ext.width > pw ? ext.width : pw, ext.height > ph ? ext.height : ph};
|
||||
if (F.fg && (F.fg_ext.width != ext.width || F.fg_ext.height != ext.height || F.fg_fmt != fmt)) {
|
||||
vk_queue_lock(), vkDeviceWaitIdle(c->device), vk_queue_unlock(); // a new window size: the context is made for its display size
|
||||
vk_ffx4_api_destroy(&F.fg);
|
||||
F.fg = nullptr;
|
||||
}
|
||||
if (!F.fg) {
|
||||
F.fg_be = {};
|
||||
F.fg_be.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK;
|
||||
F.fg_be.deviceContext = {c->device, c->phys, vkGetDeviceProcAddr};
|
||||
// the HUD-less picture has the swapchain's format (gfx_present.c hudless_record)
|
||||
F.fg_hl = {};
|
||||
F.fg_hl.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION_HUDLESS;
|
||||
F.fg_hl.header.pNext = &F.fg_be.header;
|
||||
F.fg_hl.hudlessBackBufferFormat = ffxApiGetSurfaceFormatVK(fmt);
|
||||
F.fg_ver = {};
|
||||
F.fg_ver.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION_VERSION;
|
||||
F.fg_ver.header.pNext = &F.fg_hl.header;
|
||||
F.fg_ver.version = FFX_FRAMEGENERATION_VERSION;
|
||||
if (g_fg_pin) {
|
||||
F.fg_pin = {};
|
||||
F.fg_pin.header.type = FFX_API_DESC_TYPE_OVERRIDE_VERSION;
|
||||
F.fg_pin.versionId = g_fg_pin;
|
||||
F.fg_be.header.pNext = &F.fg_pin.header;
|
||||
}
|
||||
F.fg_desc = {};
|
||||
F.fg_desc.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION;
|
||||
F.fg_desc.header.pNext = &F.fg_ver.header;
|
||||
F.fg_desc.flags = FFX_FRAMEGENERATION_ENABLE_DEPTH_INFINITE | (hdr_format(fmt) ? FFX_FRAMEGENERATION_ENABLE_HIGH_DYNAMIC_RANGE : 0);
|
||||
F.fg_desc.displaySize = {ext.width, ext.height};
|
||||
F.fg_desc.maxRenderSize = {max_render.width, max_render.height};
|
||||
F.fg_desc.backBufferFormat = ffxApiGetSurfaceFormatVK(fmt);
|
||||
uint64_t t0 = plat_now_ns();
|
||||
ffxReturnCode_t r = vk_ffx4_api_create(&F.fg, &F.fg_desc.header);
|
||||
if (r != FFX_API_RETURN_OK || !F.fg) return F.fg = nullptr, fail("the frame generation context", r);
|
||||
F.fg_ext = ext, F.fg_fmt = fmt, F.fg_max = max_render;
|
||||
FfxApiEffectMemoryUsage mem = {};
|
||||
ffxQueryDescFrameGenerationGetGPUMemoryUsage mq = {};
|
||||
mq.header.type = FFX_API_QUERY_DESC_TYPE_FRAMEGENERATION_GPU_MEMORY_USAGE;
|
||||
mq.gpuMemoryUsageFrameGeneration = &mem;
|
||||
vk_ffx4_api_query(&F.fg, &mq.header);
|
||||
rt_log("fg4: AMD FSR frame generation %s for %ux%u%s, render size up to %ux%u, made in %.0f ms, %.0f MiB of video memory",
|
||||
provider(&F.fg), ext.width, ext.height, hdr_format(fmt) ? " (HDR)" : "", max_render.width, max_render.height,
|
||||
(double)(plat_now_ns() - t0) / 1e6, (double)mem.totalUsageInBytes / 1048576.0);
|
||||
}
|
||||
if (have && (depth.width > F.fg_max.width || depth.height > F.fg_max.height)) {
|
||||
static int told;
|
||||
if (!told++)
|
||||
rt_log("fg4: a %ux%u scene is larger than the context's %ux%u: those frames are not generated", depth.width,
|
||||
depth.height, F.fg_max.width, F.fg_max.height);
|
||||
have = 0;
|
||||
}
|
||||
// Only with the picture without the HUD: generated from the presented picture alone, the HUD would be warped along
|
||||
// with the scene behind it and trail when the camera turns. A frame without that picture is shown as it is.
|
||||
int on = have && hudless && !menu_is_open();
|
||||
__atomic_store_n(&F.on, on, __ATOMIC_RELAXED);
|
||||
if (!have) F.no_inputs++;
|
||||
else if (!hudless) F.no_hudless++;
|
||||
else if (!on) F.paused++;
|
||||
F.frame++;
|
||||
ffxConfigureDescFrameGeneration cfg = {};
|
||||
cfg.header.type = FFX_API_CONFIGURE_DESC_TYPE_FRAMEGENERATION;
|
||||
cfg.swapChain = (void *)sc;
|
||||
cfg.frameGenerationCallback = generate;
|
||||
cfg.frameGenerationCallbackUserContext = &F.fg;
|
||||
cfg.frameGenerationEnabled = on != 0;
|
||||
cfg.allowAsyncWorkloads = false;
|
||||
// the picture's rectangle: with black bars beside or below it (a window of another shape) a generation over the
|
||||
// whole swapchain warped the picture's edges into the bars
|
||||
cfg.generationRect = pic && pic[2] > 0 && pic[3] > 0 ? FfxApiRect2D{pic[0], pic[1], pic[2], pic[3]}
|
||||
: FfxApiRect2D{0, 0, (int32_t)ext.width, (int32_t)ext.height};
|
||||
if (on) {
|
||||
VkFfxImage h = {hudless, fmt, ext.width, ext.height, 1};
|
||||
cfg.HUDLessColor = image(&h);
|
||||
F.hudless++;
|
||||
}
|
||||
cfg.frameID = F.frame;
|
||||
ffxReturnCode_t r = vk_ffx4_api_configure(&F.fg, &cfg.header);
|
||||
if (r != FFX_API_RETURN_OK) return fail("frame generation configuration", r);
|
||||
if (!on) return;
|
||||
ffxDispatchDescFrameGenerationPrepareV2 p = {};
|
||||
p.header.type = FFX_API_DISPATCH_DESC_TYPE_FRAMEGENERATION_PREPARE_V2;
|
||||
p.frameID = F.frame;
|
||||
p.commandList = cb;
|
||||
p.renderSize = {depth.width, depth.height};
|
||||
p.jitterOffset = {jx, jy};
|
||||
p.motionVectorScale = {1.0f, 1.0f}; // render pixels, current to previous (vk_dlaa.c mv_pass), as FSR takes them
|
||||
static uint64_t last_ns;
|
||||
uint64_t now = plat_now_ns();
|
||||
double dt = last_ns ? (now - last_ns) / 1e6 : 16.67;
|
||||
last_ns = now;
|
||||
p.frameTimeDelta = dt > 0 && dt < 100 ? (float)dt : 16.67f;
|
||||
p.reset = reset != 0;
|
||||
p.cameraNear = 0.1f; // Ocarina's projection: near 0.1, far at infinity (vk_ffx.cpp)
|
||||
p.cameraFar = 1e8f;
|
||||
p.cameraFovAngleVertical = 1.0f;
|
||||
// The game's world is taken to be in metres (its near plane is at 0.1). With 0.01 here, the value vk_fg.cpp gives
|
||||
// the FSR 3.1 library, frame generation 3.1.6 drew grey translucent shapes into the sky of its frames while the
|
||||
// camera turned, and with 0 it smeared them; with 1 its frames were clean in the same camera sweep.
|
||||
p.viewSpaceToMetersFactor = 1.0f;
|
||||
p.depth = image(&depth);
|
||||
p.motionVectors = image(&mv);
|
||||
// the camera in the world: the game's own, or one at the origin looking down -z on a frame without it
|
||||
VkDlaaCamera cam;
|
||||
if (vk_dlaa_fg_camera(&cam)) {
|
||||
memcpy(p.cameraPosition, cam.pos, sizeof p.cameraPosition), memcpy(p.cameraUp, cam.up, sizeof p.cameraUp);
|
||||
memcpy(p.cameraRight, cam.right, sizeof p.cameraRight), memcpy(p.cameraForward, cam.fwd, sizeof p.cameraForward);
|
||||
if (cam.fov_y > 0) p.cameraFovAngleVertical = cam.fov_y;
|
||||
} else {
|
||||
p.cameraUp[1] = 1.0f, p.cameraRight[0] = 1.0f, p.cameraForward[2] = -1.0f;
|
||||
}
|
||||
r = vk_ffx4_api_dispatch(&F.fg, &p.header);
|
||||
if (r != FFX_API_RETURN_OK) return fail("frame generation preparation", r);
|
||||
if (F.frame == 2 || F.frame % 3600 == 0)
|
||||
rt_log("fg4: %llu frames presented, %llu generated (%llu with the HUD kept out); paused %llu (menu), %llu without depth "
|
||||
"and motion, %llu without the HUD-less picture", (unsigned long long)F.frame, (unsigned long long)F.generated,
|
||||
(unsigned long long)F.hudless, (unsigned long long)F.paused, (unsigned long long)F.no_inputs,
|
||||
(unsigned long long)F.no_hudless);
|
||||
}
|
||||
|
||||
extern "C" void vk_fg4_release(void) {
|
||||
__atomic_store_n(&F.on, 0, __ATOMIC_RELAXED);
|
||||
if (!F.sc && !F.fg) return;
|
||||
if (F.sc) wait_presents();
|
||||
if (F.fg) vk_ffx4_api_destroy(&F.fg), F.fg = nullptr;
|
||||
if (F.sc) {
|
||||
VkSwapchainKHR h = F.handle;
|
||||
vk_ffx4_api_destroy(&F.sc), F.sc = nullptr, F.handle = VK_NULL_HANDLE;
|
||||
if (h && F.fn.pOutDestroySwapchainFFXAPI) F.fn.pOutDestroySwapchainFFXAPI(vk_ctx()->device, h, nullptr, nullptr);
|
||||
}
|
||||
F.fn = {};
|
||||
}
|
||||
#endif // _WIN32
|
||||
@@ -127,6 +127,7 @@ XLATE_NAME = 'nx2navi_xlate.exe' if WIN else 'nx2navi_xlate'
|
||||
GENERATED_HEADERS = ('layout.h', 'patches.h', 'romfs_config.h')
|
||||
RUNTIME_LIB = 'libnx2navirt.a'
|
||||
FFX4_DLLS = ('amd_fidelityfx_loader_vk.dll', 'amd_fidelityfx_upscaler_vk.dll') # AMD's FSR SDK 2.4, for FSR 4
|
||||
FFX4_FG_DLL = 'amd_fidelityfx_framegeneration_vk.dll' # ... and its frame generation, with the two above
|
||||
RUNTIME_PATTERNS = ('*.c', '*.cpp', 'platform/*.c', 'ui/*.cpp', 'third_party/imgui/*.cpp',
|
||||
'third_party/imgui/backends/*.cpp')
|
||||
INCLUDE = re.compile(r'^[ \t]*#[ \t]*include[ \t]+"([^"]+)"', re.M)
|
||||
@@ -1359,9 +1360,11 @@ def step_compile(out, cache_dir, msys, jobs, romfs_job=None, update=False):
|
||||
copy_if_changed(xlate / name, out / name)
|
||||
if (KIT / 'bin' / 'amd_fidelityfx_vk.dll').is_file(): # FSR 3.1 (runtime/vk_ffx.cpp)
|
||||
copy_if_changed(KIT / 'bin' / 'amd_fidelityfx_vk.dll', out / 'amd_fidelityfx_vk.dll')
|
||||
for name in FFX4_DLLS: # FSR 4 (runtime/vk_ffx4.cpp): both or neither
|
||||
if all((KIT / 'bin' / n).is_file() for n in FFX4_DLLS):
|
||||
if all((KIT / 'bin' / n).is_file() for n in FFX4_DLLS): # FSR 4 (runtime/vk_ffx4.cpp): both or neither
|
||||
for name in FFX4_DLLS:
|
||||
copy_if_changed(KIT / 'bin' / name, out / name)
|
||||
if (KIT / 'bin' / FFX4_FG_DLL).is_file(): # its frame generation (runtime/vk_fg4.cpp)
|
||||
copy_if_changed(KIT / 'bin' / FFX4_FG_DLL, out / FFX4_FG_DLL)
|
||||
kept = place_dlss(out, linux=not WIN) # NVIDIA DLSS (runtime/vk_dlaa.c): this platform's library from the kit
|
||||
if kept:
|
||||
say(f' {kept}')
|
||||
|
||||
@@ -52,7 +52,8 @@ def main():
|
||||
ap.add_argument('--xlate', type=Path, required=True, help='folder with nx2navi_xlate.exe and nx2navi_xlate.id')
|
||||
ap.add_argument('--ffx', type=Path, help="AMD's signed amd_fidelityfx_vk.dll (FidelityFX SDK 1.1.4, MIT) for FSR 3.1")
|
||||
ap.add_argument('--ffx4', type=Path, help="the folder with AMD's signed amd_fidelityfx_loader_vk.dll and "
|
||||
'amd_fidelityfx_upscaler_vk.dll (FSR SDK 2.4.0, MIT) for FSR 4')
|
||||
'amd_fidelityfx_upscaler_vk.dll (FSR SDK 2.4.0, MIT) for FSR 4, and its '
|
||||
'amd_fidelityfx_framegeneration_vk.dll when it is there')
|
||||
ap.add_argument('--dlss', type=Path, help="NVIDIA's nvngx_dlss.dll from disk instead of downloading it from "
|
||||
"NVIDIA's DLSS SDK repository")
|
||||
ap.add_argument('--no-dlss', action='store_true', help='leave NVIDIA DLSS out of the kit')
|
||||
@@ -98,6 +99,8 @@ def main():
|
||||
if a.ffx4: # FSR 4 loads them from beside the game (runtime/vk_ffx4.cpp); their licence is runtime/third_party/ffx_sdk
|
||||
for n in ('amd_fidelityfx_loader_vk.dll', 'amd_fidelityfx_upscaler_vk.dll'):
|
||||
shutil.copy2(a.ffx4 / n, kit / 'bin' / n)
|
||||
if (a.ffx4 / 'amd_fidelityfx_framegeneration_vk.dll').is_file(): # its frame generation (runtime/vk_fg4.cpp)
|
||||
shutil.copy2(a.ffx4 / 'amd_fidelityfx_framegeneration_vk.dll', kit / 'bin' / 'amd_fidelityfx_framegeneration_vk.dll')
|
||||
if dlss: # DLSS: NGX loads it from beside the game (runtime/vk_dlaa.c); make_game.py copies it there
|
||||
dlss_pin.place(dlss, kit / 'bin')
|
||||
if sdk: # DLSS Frame Generation (runtime/vk_dlssg.c): make_game.py place_dlssg copies it beside the game
|
||||
|
||||
@@ -203,6 +203,8 @@ def build_app(app, ver, xlate, feed_repo, lock, ffx=None, dlss=None, art=None, d
|
||||
if ffx4: # FSR 4 loads them from beside the game (runtime/vk_ffx4.cpp); make_game.py copies them there
|
||||
for n in ('amd_fidelityfx_loader_vk.dll', 'amd_fidelityfx_upscaler_vk.dll'):
|
||||
shutil.copy2(ffx4 / n, app / 'bin' / n)
|
||||
if (ffx4 / 'amd_fidelityfx_framegeneration_vk.dll').is_file(): # its frame generation (runtime/vk_fg4.cpp)
|
||||
shutil.copy2(ffx4 / 'amd_fidelityfx_framegeneration_vk.dll', app / 'bin' / 'amd_fidelityfx_framegeneration_vk.dll')
|
||||
if dlss: # DLSS: NGX loads it from beside the game (runtime/vk_dlaa.c); make_game.py copies it there
|
||||
dlss_pin.place(dlss, app / 'bin')
|
||||
if dlssg: # DLSS Frame Generation (runtime/vk_dlssg.c): make_game.py place_dlssg copies it beside the game
|
||||
@@ -320,7 +322,8 @@ def main():
|
||||
ap.add_argument('--xlate', type=Path, required=True, help='folder with nx2navi_xlate.exe and nx2navi_xlate.id')
|
||||
ap.add_argument('--ffx', type=Path, help="AMD's signed amd_fidelityfx_vk.dll (FidelityFX SDK 1.1.4, MIT) for FSR 3.1")
|
||||
ap.add_argument('--ffx4', type=Path, help="the folder with AMD's signed amd_fidelityfx_loader_vk.dll and "
|
||||
'amd_fidelityfx_upscaler_vk.dll (FSR SDK 2.4.0, MIT) for FSR 4')
|
||||
'amd_fidelityfx_upscaler_vk.dll (FSR SDK 2.4.0, MIT) for FSR 4, and its '
|
||||
'amd_fidelityfx_framegeneration_vk.dll when it is there')
|
||||
ap.add_argument('--dlss', type=Path, help=f"NVIDIA's nvngx_dlss.dll (DLSS {dlss_pin.VERSION}) from disk instead of "
|
||||
"downloading it from NVIDIA's DLSS SDK repository")
|
||||
ap.add_argument('--no-dlss', action='store_true', help='leave NVIDIA DLSS out of the release')
|
||||
|
||||
Reference in New Issue
Block a user