mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-21 10:09:59 -04:00
Compare commits
15 Commits
d55f7e763d
...
4768762213
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4768762213 | ||
|
|
c490bfec68 | ||
|
|
9fee9c781f | ||
|
|
8c239ee4b5 | ||
|
|
4e3280c2a7 | ||
|
|
7b201d868e | ||
|
|
b5789c6bec | ||
|
|
8683d14e30 | ||
|
|
ae0c8140a2 | ||
|
|
bdcf07bbf6 | ||
|
|
8afca0922a | ||
|
|
a8fa1a9370 | ||
|
|
2765a752b0 | ||
|
|
1096efef12 | ||
|
|
ef0b2b49a3 |
24
.github/workflows/linux-appimage.yml
vendored
24
.github/workflows/linux-appimage.yml
vendored
@@ -35,7 +35,29 @@ jobs:
|
||||
- uses: astral-sh/setup-uv@v6
|
||||
- name: Shader compilers
|
||||
# make_appimage.py compiles the runtime's own shaders (tools/build_shaders.py: glslc, spirv-as, spirv-val)
|
||||
run: sudo apt-get update && sudo apt-get install -y glslc spirv-tools
|
||||
# On 2026-11-11 the runners could not resolve Ubuntu's archive hosts (azure.archive.ubuntu.com, then
|
||||
# archive.ubuntu.com) and apt failed every fetch for hours. When they do not resolve, the three tools come from
|
||||
# LunarG's Vulkan SDK for Linux instead, which holds all of them.
|
||||
run: |
|
||||
if getent hosts azure.archive.ubuntu.com >/dev/null || getent hosts archive.ubuntu.com >/dev/null; then
|
||||
sudo apt-get update && sudo apt-get install -y glslc spirv-tools && exit 0
|
||||
echo "::warning::apt failed: the shader compilers come from the Vulkan SDK"
|
||||
else
|
||||
echo "::warning::Ubuntu's archive does not resolve: the shader compilers come from the Vulkan SDK"
|
||||
fi
|
||||
sdk="$RUNNER_TEMP/vulkan-sdk"
|
||||
mkdir -p "$sdk"
|
||||
for f in vulkan-sdk.tar.xz vulkan-sdk.tar.gz; do
|
||||
curl -fsSL --retry 3 -o "$RUNNER_TEMP/$f" "https://sdk.lunarg.com/sdk/download/latest/linux/$f" &&
|
||||
tar -xf "$RUNNER_TEMP/$f" -C "$sdk" && break
|
||||
done
|
||||
bin=$(dirname "$(find "$sdk" -type f -name glslc -path '*/bin/*' | head -1)")
|
||||
test -x "$bin/glslc" && test -x "$bin/spirv-as" && test -x "$bin/spirv-val"
|
||||
echo "$bin" >> "$GITHUB_PATH"
|
||||
if ! "$bin/spirv-as" --version >/dev/null 2>&1; then # the SDK's tools may link its own shared libraries
|
||||
echo "LD_LIBRARY_PATH=$(cd "$bin/../lib" && pwd)${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
|
||||
fi
|
||||
"$bin/glslc" --version | head -1
|
||||
- name: Shader translator and VMA
|
||||
run: |
|
||||
uv venv -q --python 3.12 .venv
|
||||
|
||||
@@ -100,7 +100,9 @@ keeps per-core data without locks and relies on that, so the host models it (`ru
|
||||
(`vk_exec_draw.c pool_sync`); slots that resolve alike share one lookup.
|
||||
Finalization is retained on registered slots independently of image-cache eviction: a stale CPU-backed descriptor
|
||||
cannot recreate an image from freed storage or follow newly reused CPU bytes. Registration makes it current again;
|
||||
finalized descriptors may still follow live GPU-owned content.
|
||||
finalized descriptors may still follow live GPU-owned content. A finalize marks only the slots its own texture
|
||||
object registered (by initialization serial): the game initializes and registers the next terrain heightmap at the
|
||||
storage of the previous one before it finalizes that one (`vk_texture.c vk_texture_release`).
|
||||
- Shaders: Ampere (SM86) code is lowered to Maxwell (`tools/xlate/AmpereLowering.cs`) and translated to SPIR-V by the
|
||||
pinned shader translator (`tools/vendor/ryujinx`, 1.3.2) with our patches (`tools/xlate/patches/`), built with .NET 10 NativeAOT as
|
||||
`nx2navi_xlate.exe` and run as separate processes. Translations are cached on disk; shaders and pipelines seen in
|
||||
|
||||
37
docs/releases/v0.8.1.md
Normal file
37
docs/releases/v0.8.1.md
Normal file
@@ -0,0 +1,37 @@
|
||||
## Fixed
|
||||
|
||||
- **Ground that vanished in open areas, leaving a view into the void below.** The game streams the terrain's height
|
||||
maps through a fixed set of memory and sets up the next piece of ground there before it lets go of the one before; the
|
||||
runtime took that letting go for the new piece too, and the piece was drawn at height zero, far below the ground. Seen
|
||||
after some minutes of running in Hyrule Field, and in Kokiri Forest, Kakariko Village and the Graveyard. It is no
|
||||
rare case: a Hyrule Field save does it 173 times while it loads, and running through the field 40 to 365 times a
|
||||
second. Found and fixed by MartinIsla (pull request #535).
|
||||
- **Ground flickering white on PCs with 16 GB of memory.** Past a bound on the game's own memory, textures gave way one
|
||||
after the other, although dropping them could never bring the game back under that bound: the bound leaves the video
|
||||
memory out, and a dropped texture lowers both sides alike. Textures now give way only when the system's memory is
|
||||
really running low (`tex_proc_commit_mb` only writes a line into the log now).
|
||||
- **Stutter and textures missing for a moment on cards with 8 to 12 GB.** The game lets go of textures and takes them
|
||||
back within frames, hundreds a frame in towns. Above 80 % of the card's memory those were dropped, only to be made and
|
||||
uploaded again a moment later, and the card never got under its budget: with an 8 GB card's budget, seven minutes of
|
||||
teleports between Hyrule Field, Kakariko Village, the Graveyard, Death Mountain Trail and Kokiri Forest dropped
|
||||
82,288 of them, and with a 12 GB card's budget a texture was drawn while it was gone 178 times (9 times with the
|
||||
card's full 20 GB). Only textures that stayed let go of for two seconds, and that nothing looked up since, are
|
||||
dropped now: on the same tour with the 8 GB budget, 34,699 drops, a fifth fewer textures made again, a third less
|
||||
time the game waited on textures, 4 draws of a missing texture instead of 11, and in Hyrule Field afterwards the
|
||||
slowest 1 % of frames at 32 fps instead of 22; with the 12 GB budget 60 % less waiting on textures, 10 draws of a
|
||||
missing texture instead of 178, and 43 fps instead of 39 in the field afterwards.
|
||||
- **AMD FSR 4 turning into FSR 3.1 by itself.** Each upscaling mode made an FSR 4 context of its own (about 220 MB of
|
||||
video memory each, up to six of them beside FSR 3.1's), and three creations that failed in a row, as they can while
|
||||
a save loads and the area's textures fill the card, turned FSR 4 off until the game was restarted; the menu then
|
||||
showed FSR 3.1 and no longer listed FSR 4. Now one context per output size serves every mode, contexts nothing used
|
||||
for 90 seconds go, a creation that fails frees the others and tries again two seconds later, and should FSR 4 still
|
||||
give up, choosing it in the menu again tries it anew.
|
||||
- **Debug menu: a teleport that left Link falling for good.** A teleport to a start position the area does not have put
|
||||
Link where nothing held him, and the game refuses every teleport while he falls. A teleport now always goes to one of
|
||||
the area's own start positions, and when Link falls through the ground after arriving it takes him to the area's next
|
||||
one.
|
||||
- **Debug menu: the free camera no longer goes under the map.** Flown while looking down it sank into the ground, and
|
||||
flown level it went through hills, and below the ground the picture showed the void under the map, which looks like
|
||||
missing ground. The left stick now moves it level, only ZR and ZL change its height, and with DLSS, DLAA or FSR 3.1
|
||||
or 4 on it rises where the ground ahead or below comes within a few metres (it reads the distances the upscaler's
|
||||
motion pass works out for the scene).
|
||||
@@ -266,10 +266,11 @@
|
||||
# which game memory gets no copy in video memory (memory = mirror), which costs far more frame time than a texture
|
||||
# uploaded again. 0: textures never give way for video memory.
|
||||
# tex_vram_pressure = 80
|
||||
# Megabytes this process may commit before textures give way as they do while the system's commit runs low. Windows
|
||||
# counts video memory against the commit; with a discrete GPU the video memory in use is left out of the comparison,
|
||||
# since it is not in RAM. Default: the installed memory, at least 24576, so that it does not depend on the size of the
|
||||
# page file. 0: no bound of its own; only the system's commit counts. On Linux it counts the
|
||||
# Megabytes of this process's commit above which the log says so. Windows counts video memory against the commit;
|
||||
# with a discrete GPU the video memory in use is left out of the comparison, since it is not in RAM. Textures no longer
|
||||
# give way at this bound: dropping one lowers both sides of the comparison alike, so nothing they could do brought the
|
||||
# process under it, and the ground flickered white while the system had commit to spare. They give way only while the
|
||||
# system's commit runs low. Default: the installed memory, at least 24576. 0: no bound. On Linux it counts the
|
||||
# process's resident anonymous memory, which stays under the installed memory, so there only a smaller value holds.
|
||||
# tex_proc_commit_mb = 32768
|
||||
# 1: a texture the game releases or takes back, with nothing else changed at its address, puts the texture table's
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
//
|
||||
// The free camera stands in for the game's camera inside the game's own camera update (dbg_freecam_host), so the game
|
||||
// itself draws from it.
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -279,8 +280,13 @@ static int sarc_member(const uint8_t *p, size_t n, const char *name, size_t *at,
|
||||
}
|
||||
|
||||
// ---- the places to teleport to and the events, from the player's game files (names_thread)
|
||||
typedef struct { const char *area, *pos; } Place;
|
||||
typedef struct {
|
||||
const char *area, *pos;
|
||||
float xyz[3]; // where it is in the area, metres, when the file gives it (has_xyz)
|
||||
int has_xyz;
|
||||
} Place;
|
||||
static Place *places; // by area, as the game's file lists them; the texts stay in the file's buffer
|
||||
static const char *place_xyz_key; // the key the positions' coordinates were found under, for the log
|
||||
static int place_n;
|
||||
static char **event_names; // the event files that hold a script, by name
|
||||
static int event_n;
|
||||
@@ -296,6 +302,38 @@ static const char *byml_key(const uint8_t *p, size_t n, uint32_t keys, uint32_t
|
||||
return (const char *)p + keys + off;
|
||||
}
|
||||
|
||||
// Three floats at node off of the given kind: an array of three floats (node 0xc0: its count, the kinds of its items
|
||||
// padded to four bytes, then the items; a float is kind 0xd2, its bits in place), or found in a dictionary under the
|
||||
// first key that holds one, a key whose name says where (Translate, Trans, Pos) taken before the others. depth bounds
|
||||
// the search. *key: the key it was found under.
|
||||
static int byml_vec3(const uint8_t *p, size_t n, uint32_t keys, uint32_t off, uint8_t kind, float out[3], int depth,
|
||||
const char **key) {
|
||||
if ((size_t)off + 4 > n) return 0;
|
||||
uint32_t count = u24(p + off + 1);
|
||||
if (kind == 0xc0 && p[off] == 0xc0 && count == 3) {
|
||||
uint32_t vals = off + 4 + ((count + 3) & ~3u);
|
||||
if ((size_t)vals + 12 > n || p[off + 4] != 0xd2 || p[off + 5] != 0xd2 || p[off + 6] != 0xd2) return 0;
|
||||
memcpy(out, p + vals, 12);
|
||||
return isfinite(out[0]) && isfinite(out[1]) && isfinite(out[2]);
|
||||
}
|
||||
if (kind != 0xc1 || p[off] != 0xc1 || depth <= 0) return 0;
|
||||
int found = 0;
|
||||
for (int pass = 0; pass < 2 && !found; pass++)
|
||||
for (uint32_t i = 0; i < count && !found && (size_t)off + 12 + 8 * (size_t)i <= n; i++) {
|
||||
const uint8_t *e = p + off + 4 + 8 * (size_t)i;
|
||||
const char *name = byml_key(p, n, keys, u24(e));
|
||||
int named = name && (strstr(name, "Trans") || strstr(name, "Pos"));
|
||||
if (pass == 0 && !named) continue;
|
||||
uint32_t at;
|
||||
memcpy(&at, e + 4, 4);
|
||||
if (byml_vec3(p, n, keys, at, e[3], out, depth - 1, key)) {
|
||||
if (key && name && depth == 2) *key = name;
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// The start positions file: a dictionary (node 0xc1: its count, then entries of a key's number in 24 bits, the
|
||||
// value's kind and the value's offset) of areas, each a dictionary of its start positions.
|
||||
static void places_in(const uint8_t *p, size_t n) {
|
||||
@@ -314,8 +352,14 @@ static void places_in(const uint8_t *p, size_t n) {
|
||||
if (!area || e[3] != 0xc1 || (size_t)at + 4 > n || p[at] != 0xc1 || strlen(area) > 63) continue;
|
||||
uint32_t spots = u24(p + at + 1);
|
||||
for (uint32_t k = 0; k < spots && count < 4096 && (size_t)at + 12 + 8 * (size_t)k <= n; k++) {
|
||||
const char *pos = byml_key(p, n, keys, u24(p + at + 4 + 8 * (size_t)k));
|
||||
if (pos && strlen(pos) <= 63) list[count++] = (Place){area, pos};
|
||||
const uint8_t *pe = p + at + 4 + 8 * (size_t)k;
|
||||
const char *pos = byml_key(p, n, keys, u24(pe));
|
||||
if (!pos || !pos[0] || strlen(pos) > 63) continue;
|
||||
Place pl = {area, pos, {0, 0, 0}, 0};
|
||||
uint32_t val;
|
||||
memcpy(&val, pe + 4, 4);
|
||||
pl.has_xyz = byml_vec3(p, n, keys, val, pe[3], pl.xyz, 2, &place_xyz_key);
|
||||
list[count++] = pl;
|
||||
}
|
||||
}
|
||||
places = list, place_n = count;
|
||||
@@ -369,8 +413,15 @@ static void names_thread(void *arg) {
|
||||
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; %d events, %d places to teleport to",
|
||||
names_found, flag_n, files, (double)(plat_now_ns() - t0) / 1e6, event_n, place_n);
|
||||
int with_xyz = 0;
|
||||
for (int i = 0; i < place_n; i++) with_xyz += places[i].has_xyz;
|
||||
rt_log("debug: names for %d of %d flags, from %d of the game's event files, in %.0f ms; %d events, %d places to teleport to "
|
||||
"(%d with their coordinates, under \"%s\")", names_found, flag_n, files, (double)(plat_now_ns() - t0) / 1e6,
|
||||
event_n, place_n, with_xyz, place_xyz_key ? place_xyz_key : "");
|
||||
if (cfg_get("NX2NAVI_DBG_TEST")) // test runs: every place with its coordinates, to plan routes (dbg_route)
|
||||
for (int i = 0; i < place_n; i++)
|
||||
rt_log("debug: place %s > %s at %.1f %.1f %.1f%s", places[i].area, places[i].pos, places[i].xyz[0],
|
||||
places[i].xyz[1], places[i].xyz[2], places[i].has_xyz ? "" : " (no coordinates)");
|
||||
__atomic_store_n(&names_state, 2, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
@@ -391,6 +442,28 @@ int dbg_names(int *found) {
|
||||
int dbg_places(void) { return __atomic_load_n(&names_state, __ATOMIC_ACQUIRE) == 2 ? place_n : 0; }
|
||||
const char *dbg_place_area(int i) { return i >= 0 && i < dbg_places() ? places[i].area : ""; }
|
||||
const char *dbg_place_pos(int i) { return i >= 0 && i < dbg_places() ? places[i].pos : ""; }
|
||||
|
||||
// The start position of area that comes after pos in the game's list, the first one for a pos the area does not list
|
||||
// (or none given), NULL for an area without any. A change of area to a start position the area does not have puts
|
||||
// Link where nothing holds him: he falls below the map for good, and the game refuses events while he falls.
|
||||
static const char *place_after(const char *area, const char *pos) {
|
||||
const char *first = NULL;
|
||||
int seen = 0, n = dbg_places();
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (strcmp(places[i].area, area)) continue;
|
||||
if (seen) return places[i].pos;
|
||||
if (!first) first = places[i].pos;
|
||||
if (pos && pos[0] && !strcmp(places[i].pos, pos)) seen = 1;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
static int place_listed(const char *area, const char *pos) {
|
||||
int n = dbg_places();
|
||||
for (int i = 0; i < n; i++)
|
||||
if (!strcmp(places[i].area, area) && !strcmp(places[i].pos, pos)) return 1;
|
||||
return 0;
|
||||
}
|
||||
int dbg_events(void) { return __atomic_load_n(&names_state, __ATOMIC_ACQUIRE) == 2 ? event_n : 0; }
|
||||
const char *dbg_event_name(int i) { return i >= 0 && i < dbg_events() ? event_names[i] : ""; }
|
||||
|
||||
@@ -462,12 +535,21 @@ static int event_request(Cpu *c, const char *name) {
|
||||
}
|
||||
|
||||
// ---- the teleport and the event start: asked for by the menu, done by warp_tick on the game's thread
|
||||
enum { W_IDLE, W_ASKED, W_EVENT, W_FLIGHT };
|
||||
// W_SETTLE: Link arrived and is watched for a while; one who falls FALL_M below where he arrived has no ground under
|
||||
// him, and the change of area is asked again for the area's next start position (place_after), up to FALL_TRIES times.
|
||||
// The game refuses events while Link is in the air, so such a request is tried again every RETRY_EVERY ticks until
|
||||
// RETRY_FOR ticks have passed.
|
||||
enum { W_IDLE, W_ASKED, W_EVENT, W_FLIGHT, W_SETTLE };
|
||||
enum { SETTLE_TICKS = 180, FALL_TRIES = 3, RETRY_EVERY = 30, RETRY_FOR = 1200, LIST_WAIT = 600 };
|
||||
static const float FALL_M = 25.0f; // metres: an arrival's own drop is a step or two
|
||||
static struct {
|
||||
char area[64], pos[64], event[80]; // q_lock: what the menu asked for
|
||||
int state; // W_*
|
||||
uint64_t at; // the tick of the next step, or the one at which the wait for the arrival ends
|
||||
uint64_t retry_until, waited; // W_ASKED: refused requests are tried again until then; ticks spent on the list
|
||||
float from[3]; // where Link stood
|
||||
float land; // the height he arrived at
|
||||
int tries; // start positions tried after falls
|
||||
} warp;
|
||||
static char status[160]; // q_lock: the last thing that happened, for the menu
|
||||
|
||||
@@ -491,6 +573,7 @@ void dbg_warp(const char *area, const char *pos) {
|
||||
if (warp.state == W_IDLE && !warp.event[0] && area[0]) {
|
||||
snprintf(warp.area, sizeof warp.area, "%s", area);
|
||||
snprintf(warp.pos, sizeof warp.pos, "%s", pos);
|
||||
warp.tries = 0, warp.retry_until = 0, warp.waited = 0, warp.at = 0;
|
||||
warp.state = W_ASKED;
|
||||
}
|
||||
plat_mutex_unlock(&q_lock);
|
||||
@@ -514,12 +597,35 @@ static void warp_tick(Cpu *c, uint64_t tick) {
|
||||
warp.event[0] = 0;
|
||||
plat_mutex_unlock(&q_lock);
|
||||
}
|
||||
if (warp.state == W_ASKED) {
|
||||
if (warp.state == W_ASKED && tick >= warp.at) {
|
||||
// The area's own list of start positions decides the position: read with the flag names, which a test run that
|
||||
// never opened the menu has not started yet
|
||||
if (dbg_names(NULL) != 2 && warp.waited++ < LIST_WAIT) {
|
||||
dbg_flags_refresh(), dbg_names(NULL);
|
||||
return;
|
||||
}
|
||||
if (dbg_places() && !place_listed(warp.area, warp.pos)) {
|
||||
const char *first = place_after(warp.area, NULL);
|
||||
if (!first) {
|
||||
status_set("%s is not an area of the game's list of start positions: no teleport.", warp.area, "");
|
||||
warp.state = W_IDLE;
|
||||
return;
|
||||
}
|
||||
rt_log("debug: %s lists no start position \"%s\": %s, the first it lists, instead", warp.area, warp.pos, first);
|
||||
plat_mutex_lock(&q_lock);
|
||||
snprintf(warp.pos, sizeof warp.pos, "%s", first);
|
||||
plat_mutex_unlock(&q_lock);
|
||||
}
|
||||
// the game's event that only waits: the change of area is asked for while it runs
|
||||
if (player() && gmd() && dbg_player_pos(warp.from) && event_request(c, "DefaultParentEvent")) {
|
||||
warp.at = tick + 4, warp.state = W_EVENT;
|
||||
} else if (tick < warp.retry_until) {
|
||||
warp.at = tick + RETRY_EVERY; // Link still falls: the game takes it once he lands, or the time runs out
|
||||
} else {
|
||||
status_set(REFUSED, "the teleport", "");
|
||||
status_set(warp.tries ? "The game refuses a teleport while Link falls below %s: load the save, or try again "
|
||||
"should he land."
|
||||
: REFUSED,
|
||||
warp.tries ? warp.area : "the teleport", "");
|
||||
warp.state = W_IDLE;
|
||||
}
|
||||
} else if (warp.state == W_EVENT && tick >= warp.at) {
|
||||
@@ -540,15 +646,34 @@ static void warp_tick(Cpu *c, uint64_t tick) {
|
||||
}
|
||||
} else if (warp.state == W_FLIGHT) {
|
||||
char now[64];
|
||||
float p[3];
|
||||
float p[3] = {0, 0, 0};
|
||||
int there = text_get("Sequence_CurrentBanc", now) && !strcmp(now, warp.area) && dbg_player_pos(p) &&
|
||||
fabsf(p[0] - warp.from[0]) + fabsf(p[1] - warp.from[1]) + fabsf(p[2] - warp.from[2]) > 0.5f;
|
||||
if (there || tick >= warp.at) {
|
||||
status_set(there ? "Arrived in %s, %s." : "The teleport to %s, %s was asked for; no arrival was seen.", warp.area,
|
||||
warp.pos[0] ? warp.pos : "its default start");
|
||||
warp.state = W_IDLE;
|
||||
warp.state = there ? W_SETTLE : W_IDLE;
|
||||
warp.land = p[1], warp.at = tick + SETTLE_TICKS;
|
||||
dbg_freecam_reset(); // a free camera left behind in the old area's place starts again from the game's view
|
||||
}
|
||||
} else if (warp.state == W_SETTLE) {
|
||||
float p[3];
|
||||
if (dbg_player_pos(p) && p[1] < warp.land - FALL_M) {
|
||||
const char *next = place_after(warp.area, warp.pos);
|
||||
if (warp.tries < FALL_TRIES && next && strcmp(next, warp.pos)) {
|
||||
status_set("Link fell through the ground at %s: the next start position, %s...", warp.area, next);
|
||||
plat_mutex_lock(&q_lock);
|
||||
snprintf(warp.pos, sizeof warp.pos, "%s", next);
|
||||
plat_mutex_unlock(&q_lock);
|
||||
warp.tries++, warp.retry_until = tick + RETRY_FOR, warp.at = tick, warp.state = W_ASKED;
|
||||
} else {
|
||||
status_set("Link fell through the ground at %s, %s, and the area has no other start position left to try: "
|
||||
"load the save.", warp.area, warp.pos);
|
||||
warp.state = W_IDLE;
|
||||
}
|
||||
} else if (tick >= warp.at) {
|
||||
warp.state = W_IDLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,8 +769,24 @@ static struct {
|
||||
double pos[3], reach; // the game thread's: where it is, and the game's distance to its target
|
||||
float yaw, pitch;
|
||||
uint64_t last_ns, updates;
|
||||
volatile uint32_t ground_bits; // dbg_freecam_ground: the closest distance seen in the lower view (a float's bits)
|
||||
volatile uint64_t ground_ns; // and when; 0 none
|
||||
} fc = {.sticks = 1, .speed = 8.0f, .reach = 5.0};
|
||||
|
||||
int dbg_freecam_flying(void) { return fc.on && fc.sticks && !fc.capture; }
|
||||
|
||||
// The replay's thread (vk_dlaa.c fcam_probe): view distances read back from the lower part of the view a few frames
|
||||
// ago, 0 where it saw the sky. The closest is kept for dbg_pad.
|
||||
void dbg_freecam_ground(const float *dist, int n) {
|
||||
float best = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (dist[i] > 0 && isfinite(dist[i]) && (best == 0 || dist[i] < best)) best = dist[i];
|
||||
uint32_t bits;
|
||||
memcpy(&bits, &best, 4);
|
||||
__atomic_store_n(&fc.ground_bits, bits, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&fc.ground_ns, plat_now_ns(), __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
static double reg_d(Cpu *c, int r) {
|
||||
uint64_t b = (uint64_t)c->v[r];
|
||||
double v;
|
||||
@@ -718,10 +859,99 @@ int dbg_freecam(int *sticks, float *speed, double pos[3]) {
|
||||
return fc.on;
|
||||
}
|
||||
|
||||
// Whether s holds the len characters at part, in any case.
|
||||
static int contains_nocase(const char *s, const char *part, size_t len) {
|
||||
for (; *s; s++) {
|
||||
size_t i = 0;
|
||||
while (i < len && s[i] && tolower((unsigned char)s[i]) == tolower((unsigned char)part[i])) i++;
|
||||
if (i == len) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- the route (test runs: NX2NAVI_DBG_TEST "route" and "routeto"): Link runs through points of the area on his
|
||||
// own, so a walking test crosses the field instead of pressing into its walls. The left stick is turned from the way
|
||||
// he moves towards the next point (the game's camera follows behind him, so a stick to the side turns him), with an
|
||||
// integral that takes out the camera's own angle; a point counts as reached within ROUTE_NEAR metres. When he gains
|
||||
// less than a metre on it in 2.5 seconds he is stuck (a wall, a fence, a steep slope): he sidesteps for two seconds,
|
||||
// three times to one side and then to the other, and after ROUTE_STUCK such tries the route ends.
|
||||
#define ROUTE_MAX 16
|
||||
#define ROUTE_NEAR 4.0
|
||||
#define ROUTE_STUCK 10
|
||||
static struct {
|
||||
volatile int on;
|
||||
int n, at, have_last, have_heading, side, stuck;
|
||||
float pt[ROUTE_MAX][2]; // x, z in metres
|
||||
char name[ROUTE_MAX][48];
|
||||
float last[3], best;
|
||||
double heading, integ; // radians: the way he moved last; the integral of the turn
|
||||
uint64_t prev_ns, prog_ns, side_until;
|
||||
} route;
|
||||
|
||||
static void route_start(void) {
|
||||
route.at = 0, route.have_last = route.have_heading = 0, route.stuck = 0, route.side = 1, route.integ = 0;
|
||||
route.best = 1e9f, route.prog_ns = plat_now_ns(), route.side_until = 0, route.prev_ns = 0;
|
||||
route.on = route.n > 0;
|
||||
if (route.on) rt_log("debug: route of %d points, first %s at %.1f %.1f", route.n, route.name[0], route.pt[0][0], route.pt[0][1]);
|
||||
}
|
||||
|
||||
// The game's thread: the left stick while a route runs. Stick right turns Link right, which lowers atan2(x, z) (the
|
||||
// free camera's own frame: ahead (sin yaw, cos yaw), right (-cos yaw, sin yaw)).
|
||||
static void route_pad(int32_t *lx, int32_t *ly) {
|
||||
float p[3];
|
||||
if (!route.on || !dbg_player_pos(p)) return;
|
||||
uint64_t now = plat_now_ns();
|
||||
double dt = route.prev_ns ? (double)(now - route.prev_ns) / 1e9 : 0;
|
||||
route.prev_ns = now;
|
||||
if (dt > 0.1) dt = 0.1;
|
||||
double dx = route.pt[route.at][0] - p[0], dz = route.pt[route.at][1] - p[2], d = sqrt(dx * dx + dz * dz);
|
||||
if (d < ROUTE_NEAR) {
|
||||
rt_log("debug: route: reached %s (%d of %d) at %.1f %.1f %.1f", route.name[route.at], route.at + 1, route.n, p[0], p[1], p[2]);
|
||||
if (++route.at == route.n) {
|
||||
route.on = 0;
|
||||
rt_log("debug: route done");
|
||||
return;
|
||||
}
|
||||
route.best = 1e9f, route.prog_ns = now, route.integ = 0;
|
||||
dx = route.pt[route.at][0] - p[0], dz = route.pt[route.at][1] - p[2], d = sqrt(dx * dx + dz * dz);
|
||||
}
|
||||
if (route.have_last) {
|
||||
double mx = p[0] - route.last[0], mz = p[2] - route.last[2];
|
||||
if (mx * mx + mz * mz > 0.0025) route.heading = atan2(mx, mz), route.have_heading = 1;
|
||||
}
|
||||
memcpy(route.last, p, sizeof route.last), route.have_last = 1;
|
||||
double err = route.have_heading ? atan2(dx, dz) - route.heading : 0;
|
||||
while (err > M_PI) err -= 2 * M_PI;
|
||||
while (err < -M_PI) err += 2 * M_PI;
|
||||
route.integ += err * dt * 0.4;
|
||||
route.integ = route.integ > 1.0 ? 1.0 : route.integ < -1.0 ? -1.0 : route.integ;
|
||||
double a = -(1.2 * err + route.integ); // the stick's angle from straight ahead, right positive
|
||||
a = a > 1.4 ? 1.4 : a < -1.4 ? -1.4 : a;
|
||||
if (d < route.best - 1.0f) route.best = (float)d, route.prog_ns = now;
|
||||
else if (now - route.prog_ns > 2500000000ull && now >= route.side_until) {
|
||||
if (++route.stuck > ROUTE_STUCK) {
|
||||
route.on = 0;
|
||||
rt_log("debug: route given up before %s: stuck %d times at %.1f %.1f %.1f", route.name[route.at], ROUTE_STUCK, p[0], p[1], p[2]);
|
||||
return;
|
||||
}
|
||||
// the same side three times before the other: a wall is gone round, where turns to alternate sides kept him
|
||||
// pressed against a cliff face south of the Kakariko Village gate
|
||||
if (route.stuck % 3 == 1) route.side = -route.side;
|
||||
route.side_until = now + 2000000000ull, route.prog_ns = now + 2000000000ull, route.best = (float)d;
|
||||
rt_log("debug: route: stuck at %.1f %.1f %.1f, %.1f m before %s: a sidestep to the %s", p[0], p[1], p[2], d,
|
||||
route.name[route.at], route.side > 0 ? "right" : "left");
|
||||
}
|
||||
if (now < route.side_until) a = route.side * 1.5;
|
||||
*lx = (int32_t)(sin(a) * 30000), *ly = (int32_t)(cos(a) * 30000);
|
||||
}
|
||||
|
||||
// The game's thread, with the pad's state before the game gets it: while the free camera has the sticks, the left one
|
||||
// moves it along its view and sideways, the right one turns it, ZR and ZL raise and lower it, R makes it four times
|
||||
// as fast and L four times as slow, and the game is told that none of those is touched, so Link stays where he is.
|
||||
// moves it level, ahead where it faces and sideways, the right one turns it, ZR and ZL raise and lower it, R makes it
|
||||
// four times as fast and L four times as slow, and the game is told that none of those is touched, so Link stays where
|
||||
// he is. Its height changes only with ZR and ZL: moved along its view, a camera looking down at the ground flew into
|
||||
// it and showed the void below the map, which looks like ground the game failed to draw.
|
||||
void dbg_pad(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *ry) {
|
||||
route_pad(lx, ly);
|
||||
if (!fc.on || !fc.sticks || fc.capture) {
|
||||
fc.last_ns = 0;
|
||||
return;
|
||||
@@ -738,9 +968,23 @@ void dbg_pad(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *
|
||||
fc.yaw -= (float)(in[2] * 2.4 * dt);
|
||||
fc.pitch += (float)(in[3] * 1.8 * dt);
|
||||
fc.pitch = fc.pitch > 1.5f ? 1.5f : fc.pitch < -1.5f ? -1.5f : fc.pitch;
|
||||
double cp = cos(fc.pitch), dir[3] = {cp * sin(fc.yaw), sin(fc.pitch), cp * cos(fc.yaw)};
|
||||
double ahead[3] = {sin(fc.yaw), 0, cos(fc.yaw)}; // where it faces, level
|
||||
double right[3] = {-cos(fc.yaw), 0, sin(fc.yaw)}; // the view's direction crossed with up
|
||||
for (int i = 0; i < 3; i++) fc.pos[i] += (dir[i] * in[1] + right[i] * in[0]) * step;
|
||||
for (int i = 0; i < 3; i++) fc.pos[i] += (ahead[i] * in[1] + right[i] * in[0]) * step;
|
||||
// Clear of the ground: where the closest surface in the lower part of the view (vk_dlaa.c fcam_probe, with DLSS,
|
||||
// DLAA or FSR 3.1/4 on) is nearer than the clearance, the camera rises instead of going on into a hill and under
|
||||
// the map, and ZL does not take it lower. The clearance grows with the speed: the distances are a few frames old.
|
||||
uint64_t seen = __atomic_load_n(&fc.ground_ns, __ATOMIC_ACQUIRE);
|
||||
if (seen && now - seen < 300000000ull && dt > 0) {
|
||||
uint32_t bits = __atomic_load_n(&fc.ground_bits, __ATOMIC_RELAXED);
|
||||
float near_m;
|
||||
memcpy(&near_m, &bits, 4);
|
||||
double clear = 2.5 + 0.15 * step / dt;
|
||||
if (near_m > 0 && near_m < clear) {
|
||||
if (rise < 0) rise = 0;
|
||||
fc.pos[1] += (clear - near_m) * (dt * 8 < 1 ? dt * 8 : 1);
|
||||
}
|
||||
}
|
||||
fc.pos[1] += rise * step;
|
||||
*lx = *ly = *rx = *ry = 0;
|
||||
*buttons &= ~(zl | zr | l | r);
|
||||
@@ -759,6 +1003,8 @@ static void test_script(uint64_t tick) {
|
||||
const char *e = cfg_get("NX2NAVI_DBG_TEST");
|
||||
state = e && *e ? 1 : -1;
|
||||
if (state > 0) snprintf(buf, sizeof buf, "%s", e), next = buf;
|
||||
// the places and events, read with the flag names as the menu starts them, for warp, event and routeto
|
||||
if (state > 0) dbg_flags_refresh(), dbg_names(NULL);
|
||||
}
|
||||
while (state > 0 && next && *next && strtoull(next, NULL, 10) <= tick) {
|
||||
const char *colon = strchr(next, ':'), *end = strchr(next, ';');
|
||||
@@ -787,6 +1033,45 @@ static void test_script(uint64_t tick) {
|
||||
for (int i = 0; i < 3; i++) fc.pos[i] += d[i];
|
||||
fc.yaw += yaw, fc.pitch += pitch;
|
||||
}
|
||||
} else if (!strncmp(colon + 1, "route ", 6)) { // route <x> <z> [<x> <z> ...]: points in metres
|
||||
const char *q = colon + 7;
|
||||
double x, z;
|
||||
int used = 0;
|
||||
route.n = 0;
|
||||
while (route.n < ROUTE_MAX && sscanf(q, "%lf %lf%n", &x, &z, &used) == 2 && (!end || q + used <= end)) {
|
||||
route.pt[route.n][0] = (float)x, route.pt[route.n][1] = (float)z;
|
||||
snprintf(route.name[route.n], sizeof route.name[0], "point %d", route.n + 1);
|
||||
route.n++, q += used;
|
||||
}
|
||||
route_start();
|
||||
} else if (!strncmp(colon + 1, "routeto ", 8)) {
|
||||
// routeto <part of a start position's name>[/<another part>] ...: the area's own start positions, in order
|
||||
char area[64] = "", item[128];
|
||||
text_get("Sequence_CurrentBanc", area);
|
||||
const char *q = colon + 9;
|
||||
int used = 0;
|
||||
route.n = 0;
|
||||
while (route.n < ROUTE_MAX && sscanf(q, "%127[^ ;]%n", item, &used) == 1 && (!end || q + used <= end)) {
|
||||
q += used;
|
||||
while (*q == ' ') q++;
|
||||
int found = -1;
|
||||
for (int i = 0; found < 0 && i < dbg_places(); i++) {
|
||||
if (strcmp(places[i].area, area) || !places[i].has_xyz) continue;
|
||||
for (const char *tok = item; *tok && found < 0;) { // the parts between the slashes
|
||||
size_t len = strcspn(tok, "/");
|
||||
if (len && contains_nocase(places[i].pos, tok, len)) found = i;
|
||||
tok += len + (tok[len] == '/');
|
||||
}
|
||||
}
|
||||
if (found < 0) {
|
||||
rt_log("debug: routeto: no start position of %s with coordinates matches \"%s\"", area, item);
|
||||
continue;
|
||||
}
|
||||
route.pt[route.n][0] = places[found].xyz[0], route.pt[route.n][1] = places[found].xyz[2];
|
||||
snprintf(route.name[route.n], sizeof route.name[0], "%s", places[found].pos);
|
||||
route.n++;
|
||||
}
|
||||
route_start();
|
||||
} else if (!strncmp(colon + 1, "warp ", 5)) {
|
||||
char area[64] = "", pos[64] = "";
|
||||
if (sscanf(colon + 6, "%63[^ ;] %63[^ ;]", area, pos) >= 1) dbg_warp(area, pos);
|
||||
|
||||
@@ -34,7 +34,7 @@ int dbg_names(int *found); // 0 not started, 1 being read from the g
|
||||
// time: nothing is taken while dbg_busy. dbg_status is the last thing that happened, in words.
|
||||
int dbg_places(void);
|
||||
const char *dbg_place_area(int i);
|
||||
const char *dbg_place_pos(int i); // "": the area's default start
|
||||
const char *dbg_place_pos(int i); // never "": a teleport without a listed position takes the area's first
|
||||
void dbg_warp(const char *area, const char *pos);
|
||||
int dbg_events(void);
|
||||
const char *dbg_event_name(int i);
|
||||
@@ -48,6 +48,8 @@ int dbg_freecam_available(void); // the build has the camera's patch set
|
||||
void dbg_freecam_set(int on, int sticks, float speed);
|
||||
void dbg_freecam_reset(void); // back to the game's view, free again from there
|
||||
int dbg_freecam(int *sticks, float *speed, double pos[3]); // on or off
|
||||
int dbg_freecam_flying(void); // on, with the sticks: vk_dlaa.c reads the ground's distance back for it
|
||||
void dbg_freecam_ground(const float *dist, int n); // the replay's thread: view distances in the lower view, 0 sky
|
||||
|
||||
// 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
|
||||
|
||||
@@ -961,7 +961,16 @@ static int test_textures(pool_t *tpool, pool_t *phys) {
|
||||
const VkTexImage *renewed = vk_texture_by_id(5, NULL, NULL);
|
||||
GCHECK(renewed && renewed->format == VK_FORMAT_BC1_RGBA_UNORM_BLOCK && renewed->width == 64 && renewed->height == 48,
|
||||
"re-registered CPU slot 5 did not resolve its own descriptor");
|
||||
// A release finalizes only the slots of its own texture object: another texture initialized at the same storage
|
||||
// with the same parameters before the finalize keeps its slot (vk_texture_release, terrain heightmaps).
|
||||
tex_t bn = b;
|
||||
bn.serial = 6;
|
||||
vk_texture_register(6, &bn, NULL);
|
||||
vk_texture_release(&b);
|
||||
const VkTexImage *kept = vk_texture_by_id(6, NULL, NULL);
|
||||
GCHECK(kept && kept->width == 64 && kept->height == 48 && !vk_texture_by_id(5, NULL, NULL),
|
||||
"a release finalized slot 6 of another live texture, or left its own slot 5 current");
|
||||
vk_texture_release(&bn);
|
||||
// Once the live texture at its storage holds GPU content the storage bytes lack, the finalized CPU slot follows it.
|
||||
// The live texture is cleared on the GPU and noted as rendered into, as a draw into it would be; the slot's image
|
||||
// must then show the clear, which neither the storage bytes nor a recreated image of the slot's own descriptor hold.
|
||||
|
||||
@@ -309,9 +309,12 @@ void tab_world(void) {
|
||||
ImGui::TextDisabled("x %.1f y %.1f z %.1f", at[0], at[1], at[2]);
|
||||
}
|
||||
if (changed) dbg_freecam_set(on, sticks, cam_speed);
|
||||
ImGui::TextWrapped("Close this menu to fly: the left stick moves along the view and sideways, the right stick turns, ZR and ZL "
|
||||
"go up and down, R is four times as fast and L four times as slow. The game goes on meanwhile and "
|
||||
"draws what the camera sees; the game speed above slows it down. The camera does not stop at walls.");
|
||||
ImGui::TextWrapped("Close this menu to fly: the left stick moves level, ahead and sideways, the right stick turns, ZR and ZL "
|
||||
"go up and down, R is four times as fast and L four times as slow. The height changes only with ZR "
|
||||
"and ZL, and with DLSS, DLAA or FSR 3.1 or 4 on the camera rises where the ground ahead or below comes "
|
||||
"within a few metres. The game goes on meanwhile and draws what the camera sees; the game speed above "
|
||||
"slows it down. Without those upscalers it does not stop at hills: below the ground the picture shows "
|
||||
"the void under the map, not a missing floor.");
|
||||
}
|
||||
|
||||
// ---- memory
|
||||
|
||||
@@ -76,6 +76,7 @@ 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)
|
||||
void vk_ffx4_retry(void); // vk_ffx4.cpp: FSR 4 chosen again after failures that turned it off
|
||||
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
|
||||
@@ -974,6 +975,9 @@ static void row_upscaling(void) {
|
||||
if (e.kind >= DLSS) opt_apply("NX2NAVI_DLSS", modes[e.mode]);
|
||||
if (e.kind >= DLSS) opt_apply("NX2NAVI_TAA", e.kind >= FSR3 ? "fsr3" : "dlss");
|
||||
if (e.kind >= FSR3) opt_apply("NX2NAVI_FSR4", e.kind == FSR4 ? "1" : "0");
|
||||
// FSR 4 that failed in a row stays listed (it runs on this device) while FSR 3.1 serves: the row shows FSR 3.1, and
|
||||
// choosing FSR 4 again tries it anew
|
||||
if (e.kind == FSR4) vk_ffx4_retry();
|
||||
}
|
||||
|
||||
// Under the HDR value: "after restart" when what is set waits for one (the game's own HDR, to or from it:
|
||||
@@ -1157,7 +1161,7 @@ static void row_framegen(void) {
|
||||
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");
|
||||
if (!vk_ffx_fsr4()) opt_apply("NX2NAVI_TAA", "fsr3"), opt_apply("NX2NAVI_FSR4", "1"), vk_ffx4_retry();
|
||||
} else if (k == FSR3 && cfg_bool("NX2NAVI_FSR4_FG")) {
|
||||
opt_apply("NX2NAVI_FSR4_FG", "0");
|
||||
}
|
||||
|
||||
@@ -1345,6 +1345,55 @@ static void hl_destroy(void) {
|
||||
// The device is idle here. Release NGX features and parameters before their Vulkan resources, then shut down NGX even
|
||||
// if initialization succeeded but the layout check failed. The Linux core's Shutdown1 takes an extra output pointer
|
||||
// compared with the SDK's public wrapper; it reports the number of devices still using NGX.
|
||||
// ---- the free camera's view of the ground (debug_tools.c dbg_pad). While it flies, nine of the view distances
|
||||
// mv_pass wrote (a grid over the lower part of the view, where the ground is) go back to the host, and the camera rises
|
||||
// where the closest is nearer than its clearance: flown through a hill, it showed the void below the map. A slot is
|
||||
// read FC_SLOTS evaluations after its copy, when the GPU has long been past it.
|
||||
int dbg_freecam_flying(void); // debug_tools.c
|
||||
void dbg_freecam_ground(const float *dist, int n);
|
||||
#define FC_N 9
|
||||
#define FC_SLOTS 4
|
||||
static VkBuffer fc_buf;
|
||||
static VmaAllocation fc_mem;
|
||||
static float *fc_map;
|
||||
static uint32_t fc_next;
|
||||
static uint8_t fc_have[FC_SLOTS];
|
||||
|
||||
static void fcam_probe(VkCommandBuffer cb, const struct Size *e, uint32_t w, uint32_t h) {
|
||||
if (!dbg_freecam_flying() || !e->dist_ok) { // dist_ok: mv_pass wrote this frame's distances (Ocarina's frame)
|
||||
memset(fc_have, 0, sizeof fc_have);
|
||||
return;
|
||||
}
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (!fc_buf) {
|
||||
VkBufferCreateInfo bi = {.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .size = FC_SLOTS * FC_N * sizeof(float),
|
||||
.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT};
|
||||
VmaAllocationCreateInfo ai = {.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT};
|
||||
VmaAllocationInfo info;
|
||||
if (vmaCreateBuffer(c->vma, &bi, &ai, &fc_buf, &fc_mem, &info) != VK_SUCCESS) {
|
||||
fc_buf = VK_NULL_HANDLE;
|
||||
return;
|
||||
}
|
||||
fc_map = info.pMappedData;
|
||||
}
|
||||
uint32_t s = fc_next++ % FC_SLOTS;
|
||||
if (fc_have[s]) {
|
||||
vmaInvalidateAllocation(c->vma, fc_mem, s * FC_N * sizeof(float), FC_N * sizeof(float));
|
||||
dbg_freecam_ground(fc_map + s * FC_N, FC_N);
|
||||
}
|
||||
// the replay's viewports have negative heights: row 0 is the top of the view
|
||||
static const float fx[3] = {0.2f, 0.5f, 0.8f}, fy[3] = {0.6f, 0.78f, 0.96f};
|
||||
VkBufferImageCopy r[FC_N];
|
||||
for (int i = 0; i < FC_N; i++)
|
||||
r[i] = (VkBufferImageCopy){.bufferOffset = (s * FC_N + i) * sizeof(float),
|
||||
.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
|
||||
.imageOffset = {(int32_t)(fx[i % 3] * (w - 1)), (int32_t)(fy[i / 3] * (h - 1)), 0},
|
||||
.imageExtent = {1, 1, 1}};
|
||||
vkCmdCopyImageToBuffer(cb, e->dist[e->dist_cur ^ 1], VK_IMAGE_LAYOUT_GENERAL, fc_buf, FC_N, r);
|
||||
fc_have[s] = 1;
|
||||
}
|
||||
|
||||
void vk_dlaa_release(void) {
|
||||
#ifndef _WIN32
|
||||
const VkCtx *c = vk_ctx();
|
||||
@@ -1365,6 +1414,7 @@ void vk_dlaa_release(void) {
|
||||
if (D.mv_samp) vkDestroySampler(c->device, D.mv_samp, NULL);
|
||||
if (D.camb) vmaDestroyBuffer(c->vma, D.camb, D.camb_mem);
|
||||
if (D.mvm) vmaDestroyBuffer(c->vma, D.mvm, D.mvm_mem); // mapped for good: the destroy unmaps it
|
||||
if (fc_buf) vmaDestroyBuffer(c->vma, fc_buf, fc_mem), fc_buf = VK_NULL_HANDLE, fc_map = NULL;
|
||||
if (R.pipe) vkDestroyPipeline(c->device, R.pipe, NULL);
|
||||
if (R.layout) vkDestroyPipelineLayout(c->device, R.layout, NULL);
|
||||
if (R.dsl) vkDestroyDescriptorSetLayout(c->device, R.dsl, NULL);
|
||||
@@ -1666,6 +1716,7 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) {
|
||||
uint64_t c0 = timed ? kern_now_ns() : 0;
|
||||
rec_drain(); // NGX records into the command buffer itself: the recorder thread must have made every call so far
|
||||
if (timed) T.cpu_drain += kern_now_ns() - c0;
|
||||
if (mv == 1) fcam_probe(cb, e, w, h); // mv_pass's distances, behind its barrier
|
||||
if (fsr) { // FSR 3.1 (vk_ffx.cpp) in DLSS's place: the same images, then the same blit below
|
||||
if (t->level || t->base_layer || z->level || z->base_layer) return dl_fail("FSR 3.1 on a target that is not level 0, layer 0", 0);
|
||||
if (D.last_color != t->image) target_changed(t, mv == 1);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
#include "host.h"
|
||||
#include "platform/platform.h"
|
||||
#include "vk.h"
|
||||
#include "vk_ffx.h"
|
||||
}
|
||||
@@ -110,20 +111,35 @@ ffxReturnCode_t create_counted(ffxContext *ctx, ffxCreateContextDescHeader *desc
|
||||
return r;
|
||||
}
|
||||
|
||||
// One upscaling context per render and output size: each render scale the menu sets brings its own, and so do the
|
||||
// game's second scenes. When all are taken, the least recently used one is destroyed for the new size once the GPU is
|
||||
// idle, as vk_dlaa.c free_size does for DLSS. Without that, a seventh size found no context, and vk_dlaa.c turned
|
||||
// FSR 3.1 off for the rest of the run: stepping through the render scales in the menu was enough.
|
||||
// One upscaling context per output size, made for render sizes up to the output's: every render scale the menu sets
|
||||
// runs on it with its own render size at each dispatch (the API's dynamic resolution, up to maxRenderSize), and the
|
||||
// game's second scenes, of another output size, get their own. When all are taken, the least recently used one is
|
||||
// destroyed for the new size once the GPU is idle, as vk_dlaa.c free_size does for DLSS. One per render size, as
|
||||
// before, kept a context for each mode tried, each with its own video memory, and the seventh size found none.
|
||||
struct Up {
|
||||
ffxContext ctx = nullptr;
|
||||
uint32_t w = 0, h = 0, ow = 0, oh = 0;
|
||||
uint64_t used = 0; // up_tick when context_for last returned it
|
||||
} U[6];
|
||||
uint32_t mw = 0, mh = 0, ow = 0, oh = 0; // the largest render size it takes; the output size
|
||||
uint64_t used = 0, used_ns = 0; // up_tick and the time when context_for last returned it
|
||||
} U[4];
|
||||
uint64_t up_tick;
|
||||
// A context used in the last few calls may sit in a command buffer that is not submitted yet, where waiting for the
|
||||
// GPU does not cover it: a frame makes one or two calls (the scene, and a second scene after it), so this is a few
|
||||
// frames back.
|
||||
const uint64_t UP_RECENT = 8;
|
||||
// A context no upscale used for this long goes (trim): FSR 3.1's after a switch to FSR 4, and a second scene's (the
|
||||
// pause screen's) a while after it closed. Unused that long, no command buffer names it.
|
||||
const uint64_t UP_IDLE_NS = 90ull * 1000000000ull;
|
||||
|
||||
void destroy_up(Up *u, const char *why) {
|
||||
rt_log("ffx: the FSR 3.1 context for %ux%u (render sizes up to %ux%u) destroyed: %s", u->ow, u->oh, u->mw, u->mh, why);
|
||||
A.destroy(&u->ctx, nullptr);
|
||||
*u = Up();
|
||||
}
|
||||
|
||||
void trim(uint64_t now_ns) {
|
||||
for (Up &u : U)
|
||||
if (u.ctx && now_ns - u.used_ns > UP_IDLE_NS) destroy_up(&u, "no upscale used it for 90 s");
|
||||
}
|
||||
|
||||
FfxApiResource image(const VkFfxImage *i, uint32_t state, uint32_t usage) {
|
||||
VkImageCreateInfo ci = {};
|
||||
@@ -139,31 +155,34 @@ FfxApiResource image(const VkFfxImage *i, uint32_t state, uint32_t usage) {
|
||||
|
||||
Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
up_tick++;
|
||||
uint64_t now = plat_now_ns();
|
||||
Up *small = nullptr; // a context of this output size made for smaller render sizes
|
||||
for (Up &u : U)
|
||||
if (u.ctx && u.w == w && u.h == h && u.ow == ow && u.oh == oh) {
|
||||
u.used = up_tick;
|
||||
return &u;
|
||||
if (u.ctx && u.ow == ow && u.oh == oh) {
|
||||
if (w <= u.mw && h <= u.mh) {
|
||||
u.used = up_tick, u.used_ns = now;
|
||||
return &u;
|
||||
}
|
||||
small = &u;
|
||||
}
|
||||
Up *slot = nullptr, *lru = nullptr;
|
||||
for (Up &u : U) {
|
||||
if (!u.ctx) {
|
||||
slot = &u;
|
||||
break;
|
||||
if (!slot) slot = &u;
|
||||
continue;
|
||||
}
|
||||
if (up_tick - u.used >= UP_RECENT && (!lru || u.used < lru->used)) lru = &u;
|
||||
}
|
||||
if (small && up_tick - small->used >= UP_RECENT) slot = nullptr, lru = small; // a larger one takes its place
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (!slot && lru) {
|
||||
static int told;
|
||||
if (told++ < 20)
|
||||
rt_log("ffx: FSR 3.1 context %ux%u -> %ux%u destroyed for %ux%u -> %ux%u (all %d in use)", lru->w, lru->h, lru->ow,
|
||||
lru->oh, w, h, ow, oh, (int)(sizeof U / sizeof U[0]));
|
||||
vk_queue_lock(), vkDeviceWaitIdle(c->device), vk_queue_unlock(); // its work may still be in flight
|
||||
A.destroy(&lru->ctx, nullptr);
|
||||
*lru = Up();
|
||||
destroy_up(lru, lru == small ? "a larger render size came" : "its slot went to another output size");
|
||||
slot = lru;
|
||||
}
|
||||
if (!slot) return nullptr;
|
||||
// the render size up to the output size: every mode of the menu, and a scene drawn at the output size itself
|
||||
uint32_t mw = w > ow ? w : ow, mh = h > oh ? h : oh;
|
||||
ffxCreateBackendVKDesc be = {};
|
||||
be.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_BACKEND_VK;
|
||||
be.vkDevice = c->device;
|
||||
@@ -173,20 +192,21 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
d.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE;
|
||||
d.header.pNext = &be.header;
|
||||
d.flags = FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_DEPTH_INFINITE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE;
|
||||
d.maxRenderSize = {w, h};
|
||||
d.maxRenderSize = {mw, mh};
|
||||
d.maxUpscaleSize = {ow, oh};
|
||||
d.fpMessage = message;
|
||||
ffxReturnCode_t r = create_counted(&slot->ctx, &d.header);
|
||||
if (r != FFX_API_RETURN_OK) {
|
||||
rt_log("ffx: FSR 3.1 context creation at %ux%u -> %ux%u failed (%u)", w, h, ow, oh, (unsigned)r);
|
||||
rt_log("ffx: FSR 3.1 context creation for %ux%u (render sizes up to %ux%u) failed (%u)", ow, oh, mw, mh, (unsigned)r);
|
||||
slot->ctx = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
slot->w = w, slot->h = h, slot->ow = ow, slot->oh = oh, slot->used = up_tick;
|
||||
slot->mw = mw, slot->mh = mh, slot->ow = ow, slot->oh = oh, slot->used = up_tick, slot->used_ns = now;
|
||||
ffxQueryGetProviderVersion v = {};
|
||||
v.header.type = FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION;
|
||||
A.query(&slot->ctx, &v.header);
|
||||
rt_log("ffx: FSR 3.1 upscaling at %ux%u -> %ux%u (%s)", w, h, ow, oh, v.versionName ? v.versionName : "provider unknown");
|
||||
rt_log("ffx: FSR 3.1 upscaling to %ux%u from render sizes up to %ux%u (%s)", ow, oh, mw, mh,
|
||||
v.versionName ? v.versionName : "provider unknown");
|
||||
return slot;
|
||||
}
|
||||
|
||||
@@ -240,12 +260,22 @@ extern "C" int vk_ffx_available(void) {
|
||||
|
||||
extern "C" int vk_ffx_framegen_available(void) { return vk_ffx_available(); } // the same library, its API calls
|
||||
|
||||
// NX2NAVI_FSR4 (default 0, live): FSR 4 where it runs (vk_ffx4.cpp), else FSR 3.1.
|
||||
extern "C" int vk_ffx_fsr4(void) { return cfg_bool("NX2NAVI_FSR4") && vk_ffx4_available(); }
|
||||
// NX2NAVI_FSR4 (default 0, live): FSR 4 where it runs (vk_ffx4.cpp) and has not failed in a row, else FSR 3.1.
|
||||
extern "C" int vk_ffx_fsr4(void) { return cfg_bool("NX2NAVI_FSR4") && vk_ffx4_available() && !vk_ffx4_failed(); }
|
||||
|
||||
extern "C" int vk_ffx_trim_idle(uint64_t recent) {
|
||||
int n = 0;
|
||||
for (Up &u : U)
|
||||
if (u.ctx && up_tick - u.used >= recent) destroy_up(&u, "room for an FSR 4 context"), n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
extern "C" int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
||||
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y) {
|
||||
if (!vk_ffx_load()) return 0;
|
||||
uint64_t now = plat_now_ns();
|
||||
trim(now);
|
||||
vk_ffx4_trim(now);
|
||||
// Each upscaler keeps a history of its own: the frame after a change from one to the other starts it anew, or it
|
||||
// would blend this picture with whatever that upscaler last saw.
|
||||
static int last; // 3 or 4: which one made the frame before
|
||||
|
||||
@@ -22,6 +22,9 @@ int vk_ffx_framegen_available(void);
|
||||
int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
||||
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y);
|
||||
void vk_ffx_release(void); // before the device goes away
|
||||
// FSR 3.1's contexts that no upscale used in the last `recent` calls, destroyed with the device idle (the caller waited
|
||||
// for it): room for an FSR 4 context whose creation failed. Their count.
|
||||
int vk_ffx_trim_idle(uint64_t recent);
|
||||
// The device's functions as the library is given them (ffxCreateBackendVKDesc.vkDeviceProcAddr): its pipeline creates
|
||||
// go through the runtime's pipeline caches (vk_pipeline.c vk_pipeline_create_foreign; NX2NAVI_FFX_PIPE_CACHE=0: not).
|
||||
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_ffx_proc_addr(VkDevice dev, const char *name);
|
||||
@@ -35,6 +38,9 @@ const char *vk_ffx4_name(void); // "AMD FSR 4.1.2" once vk_ffx4_available foun
|
||||
int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
||||
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y); // as vk_ffx_upscale
|
||||
void vk_ffx4_release(void);
|
||||
int vk_ffx4_failed(void); // it failed three times in a row: FSR 3.1 serves until vk_ffx4_retry
|
||||
void vk_ffx4_retry(void); // the menu chose FSR 4 again: try it anew after such failures
|
||||
void vk_ffx4_trim(uint64_t now_ns); // at each upscale: FSR 4's contexts unused for a while go
|
||||
int vk_ffx_fsr4(void); // the setting asks for FSR 4 and it runs here: what vk_ffx_upscale uses, for the menu
|
||||
|
||||
#if defined(__cplusplus) && !defined(VK_FFX_NO_API)
|
||||
|
||||
@@ -28,6 +28,9 @@ extern "C" int vk_ffx4_upscale(VkCommandBuffer, const VkFfxImage *, const VkFfxI
|
||||
return 0;
|
||||
}
|
||||
extern "C" void vk_ffx4_release(void) {}
|
||||
extern "C" int vk_ffx4_failed(void) { return 0; }
|
||||
extern "C" void vk_ffx4_retry(void) {}
|
||||
extern "C" void vk_ffx4_trim(uint64_t) {}
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <atomic>
|
||||
@@ -61,10 +64,15 @@ struct Api {
|
||||
|
||||
std::mutex g_lock; // the probe: the menu asks from its thread, the replay from its own
|
||||
std::atomic<int> g_state{-1}; // -1 not probed; 0 FSR 4 does not run here; 1 it does
|
||||
std::atomic<int> g_off{0}; // FAIL_MAX failures in a row: FSR 3.1 serves until the menu asks again (vk_ffx4_retry)
|
||||
uint64_t g_version; // the id of the 4.x version the loader listed for the device
|
||||
char g_name[48] = "AMD FSR 4"; // "AMD FSR 4.1.2", for the menu and the log
|
||||
int g_failures; // contexts or dispatches that failed; past FAIL_MAX FSR 4 is off for the run
|
||||
const int FAIL_MAX = 3;
|
||||
int g_failures; // contexts or dispatches that failed in a row
|
||||
const int FAIL_MAX = 4;
|
||||
// After a context creation failed, FSR 3.1 serves the frames until the next try this much later: a save loading fills
|
||||
// the video memory with the area's textures for a few frames, and three tries in three frames there turned FSR 4 off.
|
||||
uint64_t g_retry_ns;
|
||||
const uint64_t RETRY_NS = 2ull * 1000000000ull;
|
||||
|
||||
void message(uint32_t type, const wchar_t *msg) {
|
||||
char s[512];
|
||||
@@ -170,19 +178,32 @@ int probe(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// One context per render and output size, as vk_ffx.cpp keeps them for FSR 3.1; the descriptors a context was made
|
||||
// from stay with it, as the API asks ("must remain live until ffxDestroyContext").
|
||||
// One context per output size, made for render sizes up to the output's, as vk_ffx.cpp keeps them for FSR 3.1: every
|
||||
// render scale of the menu runs on it with its own render size at each dispatch, which the API allows up to the
|
||||
// context's maxRenderSize. With one context per render and output size, each mode tried made a context of its own,
|
||||
// about 217 MiB of video memory and 50 to 70 ms each, up to six were kept beside FSR 3.1's, and three creations that
|
||||
// failed (the card out of memory) turned FSR 4 off for the run. The descriptors a context was made from stay with it,
|
||||
// as the API asks ("must remain live until ffxDestroyContext").
|
||||
struct Up {
|
||||
ffxContext ctx = nullptr;
|
||||
uint32_t w = 0, h = 0, ow = 0, oh = 0;
|
||||
uint64_t used = 0;
|
||||
uint32_t mw = 0, mh = 0, ow = 0, oh = 0; // the largest render size it takes; the output size
|
||||
uint64_t used = 0, used_ns = 0; // up_tick and the time when context_for last returned it
|
||||
ffxCreateContextDescUpscale desc = {};
|
||||
ffxCreateBackendVKDesc backend = {};
|
||||
ffxOverrideVersion version = {};
|
||||
ffxCreateContextDescUpscaleVersion built = {};
|
||||
} U[6];
|
||||
} U[4];
|
||||
uint64_t up_tick;
|
||||
const uint64_t UP_RECENT = 8; // contexts used this recently may sit in a command buffer not submitted yet
|
||||
// A context no upscale used for this long goes (vk_ffx4_trim): FSR 4's after a switch to FSR 3.1, and a second scene's
|
||||
// (the pause screen's) a while after it closed. Unused that long, no command buffer names it.
|
||||
const uint64_t UP_IDLE_NS = 90ull * 1000000000ull;
|
||||
|
||||
void destroy_up(Up *u, const char *why) {
|
||||
rt_log("ffx4: the %ux%u context (render sizes up to %ux%u) destroyed: %s", u->ow, u->oh, u->mw, u->mh, why);
|
||||
A.destroy(&u->ctx, nullptr);
|
||||
*u = Up();
|
||||
}
|
||||
|
||||
FfxApiResource image(const VkFfxImage *i, uint32_t state, uint32_t usage) {
|
||||
VkImageCreateInfo ci = {};
|
||||
@@ -196,29 +217,9 @@ FfxApiResource image(const VkFfxImage *i, uint32_t state, uint32_t usage) {
|
||||
return ffxApiGetResourceVK((void *)i->image, ffxApiGetImageResourceDescriptionVK(i->image, ci, usage), state);
|
||||
}
|
||||
|
||||
Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
up_tick++;
|
||||
for (Up &u : U)
|
||||
if (u.ctx && u.w == w && u.h == h && u.ow == ow && u.oh == oh) {
|
||||
u.used = up_tick;
|
||||
return &u;
|
||||
}
|
||||
Up *slot = nullptr, *lru = nullptr;
|
||||
for (Up &u : U) {
|
||||
if (!u.ctx) {
|
||||
slot = &u;
|
||||
break;
|
||||
}
|
||||
if (up_tick - u.used >= UP_RECENT && (!lru || u.used < lru->used)) lru = &u;
|
||||
}
|
||||
// A context in slot for render sizes up to mw x mh and the output size ow x oh; NULL when it is not made.
|
||||
Up *create(Up *slot, uint32_t mw, uint32_t mh, uint32_t ow, uint32_t oh) {
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (!slot && lru) {
|
||||
vk_queue_lock(), vkDeviceWaitIdle(c->device), vk_queue_unlock(); // its work may still be in flight
|
||||
A.destroy(&lru->ctx, nullptr);
|
||||
*lru = Up();
|
||||
slot = lru;
|
||||
}
|
||||
if (!slot) return nullptr;
|
||||
*slot = Up();
|
||||
slot->built.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE_VERSION;
|
||||
slot->built.version = FFX_UPSCALER_VERSION;
|
||||
@@ -232,17 +233,18 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
slot->desc.header.pNext = &slot->backend.header;
|
||||
slot->desc.flags =
|
||||
FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_DEPTH_INFINITE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE;
|
||||
slot->desc.maxRenderSize = {w, h};
|
||||
slot->desc.maxRenderSize = {mw, mh};
|
||||
slot->desc.maxUpscaleSize = {ow, oh};
|
||||
slot->desc.fpMessage = message;
|
||||
uint64_t t0 = plat_now_ns();
|
||||
ffxReturnCode_t r = A.create(&slot->ctx, &slot->desc.header, nullptr);
|
||||
if (r != FFX_API_RETURN_OK || !slot->ctx) {
|
||||
rt_log("ffx4: %s context creation at %ux%u -> %ux%u failed (%u)", g_name, w, h, ow, oh, (unsigned)r);
|
||||
rt_log("ffx4: %s context creation for %ux%u (render sizes up to %ux%u) failed (%u)", g_name, ow, oh, mw, mh,
|
||||
(unsigned)r);
|
||||
*slot = Up();
|
||||
return nullptr;
|
||||
}
|
||||
slot->w = w, slot->h = h, slot->ow = ow, slot->oh = oh, slot->used = up_tick;
|
||||
slot->mw = mw, slot->mh = mh, slot->ow = ow, slot->oh = oh;
|
||||
ffxQueryGetProviderVersion v = {};
|
||||
v.header.type = FFX_API_QUERY_DESC_TYPE_GET_PROVIDER_VERSION;
|
||||
A.query(&slot->ctx, &v.header);
|
||||
@@ -251,8 +253,8 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
mq.header.type = FFX_API_QUERY_DESC_TYPE_UPSCALE_GPU_MEMORY_USAGE;
|
||||
mq.gpuMemoryUsageUpscaler = &mem;
|
||||
A.query(&slot->ctx, &mq.header);
|
||||
rt_log("ffx4: FSR %s upscaling at %ux%u -> %ux%u, made in %.0f ms, %.0f MiB of video memory",
|
||||
v.versionName ? v.versionName : "4", w, h, ow, oh, (double)(plat_now_ns() - t0) / 1e6,
|
||||
rt_log("ffx4: FSR %s upscaling to %ux%u from render sizes up to %ux%u, made in %.0f ms, %.0f MiB of video memory",
|
||||
v.versionName ? v.versionName : "4", ow, oh, mw, mh, (double)(plat_now_ns() - t0) / 1e6,
|
||||
(double)mem.totalUsageInBytes / 1048576.0);
|
||||
// The provider is asked for the version it runs: anything but a 4.x here means the loader gave another upscaler
|
||||
if (v.versionName && atoi(v.versionName) < 4) {
|
||||
@@ -264,10 +266,60 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
return slot;
|
||||
}
|
||||
|
||||
// The context for a render size and an output size: the one of that output size that takes the render size, else a
|
||||
// new one, in a free slot or in place of the least recently used one, with the device idle first. A creation that
|
||||
// fails is tried once more after every context not in use has gone, FSR 3.1's idle ones too (vk_ffx_trim_idle): what
|
||||
// it lacked was most often video memory.
|
||||
Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
up_tick++;
|
||||
uint64_t now = plat_now_ns();
|
||||
Up *small = nullptr; // a context of this output size made for smaller render sizes
|
||||
for (Up &u : U)
|
||||
if (u.ctx && u.ow == ow && u.oh == oh) {
|
||||
if (w <= u.mw && h <= u.mh) {
|
||||
u.used = up_tick, u.used_ns = now;
|
||||
return &u;
|
||||
}
|
||||
small = &u;
|
||||
}
|
||||
Up *slot = nullptr, *lru = nullptr;
|
||||
for (Up &u : U) {
|
||||
if (!u.ctx) {
|
||||
if (!slot) slot = &u;
|
||||
continue;
|
||||
}
|
||||
if (up_tick - u.used >= UP_RECENT && (!lru || u.used < lru->used)) lru = &u;
|
||||
}
|
||||
if (small && up_tick - small->used >= UP_RECENT) slot = nullptr, lru = small; // a larger one takes its place
|
||||
const VkCtx *c = vk_ctx();
|
||||
if (!slot && lru) {
|
||||
vk_queue_lock(), vkDeviceWaitIdle(c->device), vk_queue_unlock(); // its work may still be in flight
|
||||
destroy_up(lru, lru == small ? "a larger render size came" : "its slot went to another output size");
|
||||
slot = lru;
|
||||
}
|
||||
if (!slot) return nullptr;
|
||||
// the render size up to the output size: every mode of the menu, and a scene drawn at the output size itself
|
||||
uint32_t mw = w > ow ? w : ow, mh = h > oh ? h : oh;
|
||||
Up *u = create(slot, mw, mh, ow, oh);
|
||||
if (!u) {
|
||||
int freed = 0;
|
||||
vk_queue_lock(), vkDeviceWaitIdle(c->device), vk_queue_unlock();
|
||||
for (Up &o : U)
|
||||
if (o.ctx && up_tick - o.used >= UP_RECENT) destroy_up(&o, "room for a context whose creation failed"), freed++;
|
||||
freed += vk_ffx_trim_idle(UP_RECENT);
|
||||
if (freed) u = create(slot, mw, mh, ow, oh);
|
||||
}
|
||||
if (u) u->used = up_tick, u->used_ns = now;
|
||||
return u;
|
||||
}
|
||||
|
||||
// Failures in a row: FAIL_MAX of them turn FSR 4 off until the menu asks for it again (vk_ffx4_retry); a success
|
||||
// starts the count again, so a creation that failed once in a while does not add up over a session.
|
||||
void failed(const char *what, unsigned code) {
|
||||
if (++g_failures == FAIL_MAX) {
|
||||
rt_log("ffx4: %s failed %d times (last %u): FSR 4 is off for this run, FSR 3.1 takes its place", what, FAIL_MAX, code);
|
||||
g_state.store(0, std::memory_order_release);
|
||||
rt_log("ffx4: %s failed %d times in a row (last %u): FSR 4 is off, FSR 3.1 takes its place until FSR 4 is "
|
||||
"chosen again in the menu", what, FAIL_MAX, code);
|
||||
g_off.store(1, std::memory_order_release);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,11 +338,29 @@ extern "C" int vk_ffx4_available(void) {
|
||||
|
||||
extern "C" const char *vk_ffx4_name(void) { return g_name; }
|
||||
|
||||
extern "C" int vk_ffx4_failed(void) { return g_off.load(std::memory_order_acquire); }
|
||||
|
||||
// The menu chose FSR 4 again: after failures that turned it off, it is tried anew.
|
||||
extern "C" void vk_ffx4_retry(void) {
|
||||
if (!g_off.exchange(0, std::memory_order_acq_rel)) return;
|
||||
g_failures = 0, g_retry_ns = 0;
|
||||
rt_log("ffx4: FSR 4 chosen again in the menu: tried anew");
|
||||
}
|
||||
|
||||
// Called at every upscale, with FSR 4 or FSR 3.1 (vk_ffx.cpp vk_ffx_upscale), on the thread that records them.
|
||||
extern "C" void vk_ffx4_trim(uint64_t now_ns) {
|
||||
for (Up &u : U)
|
||||
if (u.ctx && now_ns - u.used_ns > UP_IDLE_NS) destroy_up(&u, "no upscale used it for 90 s");
|
||||
}
|
||||
|
||||
extern "C" int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv,
|
||||
const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y) {
|
||||
if (!vk_ffx4_available()) return 0;
|
||||
if (!vk_ffx4_available() || g_off.load(std::memory_order_acquire)) return 0;
|
||||
uint64_t now = plat_now_ns();
|
||||
if (g_failures && now < g_retry_ns) return 0; // FSR 3.1 serves until the next try
|
||||
Up *u = context_for(color->width, color->height, out->width, out->height);
|
||||
if (!u) {
|
||||
g_retry_ns = now + RETRY_NS;
|
||||
failed("making a context", 0);
|
||||
return 0;
|
||||
}
|
||||
@@ -323,6 +393,7 @@ extern "C" int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, cons
|
||||
failed("a dispatch", (unsigned)r);
|
||||
return 0;
|
||||
}
|
||||
g_failures = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1537,6 +1537,15 @@ int vk_texture_pool_fresh_locked(void) {
|
||||
// slot_resolve's last answer was none because of its stale rule (vk_texture_slot_retry_locked)
|
||||
static int resolve_stale;
|
||||
|
||||
// NX2NAVI_TRACE=perf, since the last perf line: slots a finalize marked (its own texture object's), slots at the storage
|
||||
// with the same parameters registered with another texture object, which a finalize leaves current
|
||||
// (vk_texture_release), and lookups the stale rule answered with the stand-in (slot_resolve). _hm: of them, the
|
||||
// terrain's streamed heightmaps (R32F 260x260), whose stand-in draws a chunk of ground at height zero.
|
||||
static uint64_t n_fin_own, n_fin_other, n_fin_other_hm, n_stale, n_stale_hm;
|
||||
static int terrain_heightmap(const tex_t *t) {
|
||||
return t->d.format == NVN_FORMAT_R32F && t->d.width == 260 && t->d.height == 260;
|
||||
}
|
||||
|
||||
int vk_texture_slot_retry_locked(int id) {
|
||||
if (id < 0 || id >= ntslots || !tslots[id].used || !tslots[id].t.mem) return -1;
|
||||
resolve_stale = 0;
|
||||
@@ -1820,8 +1829,9 @@ static int idle(const Tex *e, uint64_t now);
|
||||
// machine runs out of memory, and plat_commit_info reports the tighter of the two. Both drop only stale entries
|
||||
// (drop_stale), a few per check like the VRAM pressure.
|
||||
//
|
||||
// NX2NAVI_TEX_PROC_COMMIT_MB (default the installed memory, at least PROC_COMMIT_MIN_MB; 0 = off) counts the commit as
|
||||
// low too while this process's own commit is above it. The system's figure depends on the page file and on what else
|
||||
// NX2NAVI_TEX_PROC_COMMIT_MB (default the installed memory, at least PROC_COMMIT_MIN_MB; 0 = off) is a bound on this
|
||||
// process's own commit that is logged when passed; it counted the commit as low too until it was found that no texture
|
||||
// dropped could bring the process back under it (commit_is_low, at its end). The system's figure depends on the page file and on what else
|
||||
// runs: with a 64 GB limit it turned low at 59 GB in use, when this process alone held 42 GB on a PC with 32 GB of
|
||||
// memory, about half of it device memory, with the textures of five areas left behind. A process is not meant to need
|
||||
// more commit than the PC has memory: beyond that it lives on the page file, whatever its size. The bound holds until
|
||||
@@ -1899,8 +1909,8 @@ static int commit_is_low(void) {
|
||||
char note[2048]; // the platform layer's own lines go to stderr only, so the log file gets this through here
|
||||
if (plat_commit_note(note, sizeof note)) rt_log("platform: %s", note);
|
||||
if (proc_commit_mb)
|
||||
rt_log("vk: textures give way as under low commit while this process's commit%s is above %lld MB "
|
||||
"(NX2NAVI_TEX_PROC_COMMIT_MB; 0 = off)",
|
||||
rt_log("vk: this process's commit%s is logged when it passes %lld MB (NX2NAVI_TEX_PROC_COMMIT_MB; 0 = off); "
|
||||
"textures give way only when the system's commit is low",
|
||||
plat_commit_counts_vram() ? ", less the video memory in use on a discrete card," : "", proc_commit_mb);
|
||||
}
|
||||
if (!commit_free_mb && !proc_commit_mb) return 0;
|
||||
@@ -1925,7 +1935,8 @@ static int commit_is_low(void) {
|
||||
rt_log("vk: this process's commit %s: %.0f MB less %.0f MB of video memory, the bound is %lld MB (system: %.0f "
|
||||
"of %.0f MB in use); released textures kept %d, %.0f MiB of own memory%s", high ? "high" : "no longer high",
|
||||
proc, dev, proc_commit_mb, used, limit, nreleased, rel_bytes / 1048576.0,
|
||||
high ? ": dropping the stale ones" : "");
|
||||
high ? ": the host's own memory, which dropping textures does not lower; textures give way only when the "
|
||||
"system's commit is low" : "");
|
||||
}
|
||||
proc_high = high;
|
||||
if (low != sys_low && commit_logs < 40) { // a few lines, however often it flips
|
||||
@@ -1946,7 +1957,12 @@ static int commit_is_low(void) {
|
||||
}
|
||||
}
|
||||
sys_low = low;
|
||||
return commit_low = low || high;
|
||||
// Only the system's figure makes textures give way. The process's bound compares its commit less the video memory
|
||||
// in use, and a texture dropped lowers both by the same amount: past the bound nothing a drop does could bring it
|
||||
// back under, and textures went one after the other for as long as the rest of the process stayed large, the ground
|
||||
// flickering white with the system's commit to spare (#434). What is above it is the host's own memory (the
|
||||
// game's heap, pipelines, caches); the bound is logged, and the system's figure still acts when the commit runs low.
|
||||
return commit_low = low;
|
||||
}
|
||||
|
||||
int vk_texture_commit_low(void) { return __atomic_load_n(&commit_low, __ATOMIC_RELAXED); }
|
||||
@@ -2502,10 +2518,17 @@ static void sweep_pressure(void) { // tex_lock held
|
||||
}
|
||||
}
|
||||
if (over) {
|
||||
uint64_t freed = 0;
|
||||
for (Tex *e = rel_head, *next; e && dropped < PRESSURE_STEP; e = next) {
|
||||
// Released entries that come back intact, by the rule drop_stale keeps: released STALE_FRAMES ago and reached by
|
||||
// no lookup since (idle). The game releases and takes back hundreds of textures a frame in towns, and the
|
||||
// release list is mostly those: dropped, each was made and uploaded again within frames and freed nothing.
|
||||
// With the budget taken as 7.5 GiB (NX2NAVI_VRAM_BUDGET_MB), teleports from Hyrule Field through Kakariko
|
||||
// Village, the Graveyard, Death Mountain Trail and Kokiri Forest dropped 82,288 under the pressure and the card
|
||||
// stayed over its budget throughout; with this rule 34,699 went, a fifth fewer textures were made again, the
|
||||
// render thread waited a third less on textures, and 4 draws met a texture gone where 11 had.
|
||||
uint64_t freed = 0, now = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
|
||||
for (Tex *e = rel_head, *next; e && dropped < PRESSURE_STEP && now - e->rel_frame >= STALE_FRAMES; e = next) {
|
||||
next = e->rel_next;
|
||||
if (!comes_back_intact(e)) continue;
|
||||
if (!comes_back_intact(e) || !idle(e, now)) continue;
|
||||
freed += e->bytes;
|
||||
drop_tex(e, DROP_VRAM);
|
||||
dropped++, n_pressure_drops++;
|
||||
@@ -3545,6 +3568,11 @@ void vk_texture_release(const tex_t *t) {
|
||||
// Staleness belongs to the registered descriptor, not the cached image: a released Tex can be destroyed before the
|
||||
// slot looks again (eviction, the released cap, start_at for a mirrored one). A registered texture may also be
|
||||
// finalized before its image is created.
|
||||
// Only the slots this texture object registered (its initialization serial): a slot registered with another
|
||||
// texture initialized at the same storage with the same parameters names that one, which is still live. Ocarina
|
||||
// streams terrain heightmaps (R32F 260x260) through a fixed set of storage and initializes and registers the next
|
||||
// chunk's texture there before it finalizes the previous one; finalizing the new registration left the slot stale,
|
||||
// the draws sampled the zero stand-in, and the chunk was drawn at height zero, tens of metres below the ground.
|
||||
int changed = 0;
|
||||
if (sinfo)
|
||||
for (int id = bucket_head[agen_idx(k.addr)]; id >= 0; id = slot_next[id]) {
|
||||
@@ -3552,7 +3580,13 @@ void vk_texture_release(const tex_t *t) {
|
||||
if (s->finalized || (uintptr_t)s->t.mem != k.addr) continue;
|
||||
TexKey sk;
|
||||
make_key(&s->t, &sk);
|
||||
if (!memcmp(&sk, &k, sizeof k)) s->finalized = 1, s->ce = NULL, changed = 1;
|
||||
if (memcmp(&sk, &k, sizeof k)) continue;
|
||||
if (s->t.serial != t->serial) { // another texture object's registration: it stays current
|
||||
n_fin_other++, n_fin_other_hm += terrain_heightmap(&s->t);
|
||||
continue;
|
||||
}
|
||||
s->finalized = 1, s->ce = NULL, changed = 1;
|
||||
n_fin_own++;
|
||||
}
|
||||
if (e && !e->released) {
|
||||
mark_released(e);
|
||||
@@ -3701,7 +3735,7 @@ static Tex *slot_resolve(TexSlot *s, view_t *view, int *has_view) {
|
||||
// after its released image was evicted; registering the descriptor again makes it current.
|
||||
if (!e && any) e = any;
|
||||
else if (!e && !cpu_slot) e = own && own->superseded ? NULL : own; // a superseded one: entry_of takes it back
|
||||
else if (!e && cpu_slot && s->finalized) stale = 1;
|
||||
else if (!e && cpu_slot && s->finalized) stale = 1, n_stale++, n_stale_hm += terrain_heightmap(&s->t);
|
||||
}
|
||||
resolve_stale = stale;
|
||||
if (!e && s->t.mem && !stale) {
|
||||
@@ -3957,6 +3991,12 @@ void vk_texture_new_submit(void) {
|
||||
(unsigned long long)n_mark_empty, (unsigned long long)n_mark_none);
|
||||
memset(n_drop_by, 0, sizeof n_drop_by), memset(n_cpu_empty, 0, sizeof n_cpu_empty);
|
||||
n_mark_empty = n_mark_none = 0;
|
||||
rt_log("perf: frame %llu: texture finalizes: slots marked %llu; slots of another live texture with the same "
|
||||
"parameters at the storage, left current %llu (terrain heightmaps %llu); lookups the stale rule gave the "
|
||||
"stand-in %llu (terrain heightmaps %llu)", (unsigned long long)f * 60, (unsigned long long)n_fin_own,
|
||||
(unsigned long long)n_fin_other, (unsigned long long)n_fin_other_hm, (unsigned long long)n_stale,
|
||||
(unsigned long long)n_stale_hm);
|
||||
n_fin_own = n_fin_other = n_fin_other_hm = n_stale = n_stale_hm = 0;
|
||||
if (split_mode > 0)
|
||||
rt_log("perf: frame %llu: split fill: entries the CPU does not write started with their storage's bytes: "
|
||||
"copied from the released entry they replaced %llu, filled from storage %llu (%.1f MiB, %.2f ms), "
|
||||
|
||||
Reference in New Issue
Block a user