mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-21 00:59:59 -04:00
Triforce v0.6.0 "Sage Of Power"
Faster frames (the replay's memory work, held submits, helper threads, collection and capture cuts), the game letting old areas go (QueryMemoryInfo), the 0.5.2 stutter fixed, AMD RX 5000/6000 and integrated-GPU fixes, the GPU device chosen by name, the in-game menus and launcher reworked, controller, Linux and benchmark fixes.
This commit is contained in:
176
host/crash_threads.c
Normal file
176
host/crash_threads.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/* (Triforce) A crash report's other threads: host/crash_threads.h has what and why. */
|
||||
#include "crash_threads.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void hos_log(const char *fmt, ...);
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
typedef struct {
|
||||
DWORD id;
|
||||
int frames;
|
||||
DWORD64 pc[CRASH_THREADS_FRAMES];
|
||||
} CrashStack;
|
||||
static CrashStack crash_stacks[CRASH_THREADS_MAX]; /* (static: nothing is allocated while a thread is stopped) */
|
||||
static volatile LONG crash_begun, crash_count = -1; /* (-1 until the snapshot is whole) */
|
||||
static HANDLE crash_helper;
|
||||
static DWORD crash_self;
|
||||
|
||||
/* (the thread's stack, from its TEB: NtQueryInformationThread, a system call that takes no lock of the process's; found by
|
||||
crash_take before it stops any thread, as GetProcAddress takes the loader's lock) */
|
||||
typedef LONG(NTAPI *CrashQueryThread)(HANDLE, int, PVOID, ULONG, PULONG);
|
||||
typedef struct {
|
||||
LONG ExitStatus;
|
||||
PVOID TebBaseAddress;
|
||||
PVOID UniqueProcess, UniqueThread;
|
||||
ULONG_PTR AffinityMask;
|
||||
LONG Priority, BasePriority;
|
||||
} CrashThreadBasic; /* (THREAD_BASIC_INFORMATION, class 0) */
|
||||
static CrashQueryThread crash_query;
|
||||
static int crash_stack_bounds(HANDLE h, DWORD64 *lo, DWORD64 *hi) {
|
||||
CrashThreadBasic bi;
|
||||
memset(&bi, 0, sizeof bi);
|
||||
if (!crash_query || crash_query(h, 0, &bi, sizeof bi, NULL) < 0 || !bi.TebBaseAddress) return 0;
|
||||
const NT_TIB *tib = (const NT_TIB *)bi.TebBaseAddress; /* (the TEB is the thread's, always there) */
|
||||
*lo = (DWORD64)(uintptr_t)tib->StackLimit, *hi = (DWORD64)(uintptr_t)tib->StackBase;
|
||||
return *lo < *hi;
|
||||
}
|
||||
|
||||
static int crash_unwind(HANDLE h, DWORD64 *out) {
|
||||
CONTEXT ctx;
|
||||
memset(&ctx, 0, sizeof ctx);
|
||||
ctx.ContextFlags = CONTEXT_FULL;
|
||||
if (!GetThreadContext(h, &ctx)) return 0;
|
||||
DWORD64 lo = 0, hi = 0;
|
||||
if (!crash_stack_bounds(h, &lo, &hi)) { /* (no stack known: the top frame alone, nothing read) */
|
||||
out[0] = ctx.Rip;
|
||||
return ctx.Rip != 0;
|
||||
}
|
||||
int n = 0;
|
||||
for (; n < CRASH_THREADS_FRAMES && ctx.Rip; n++) {
|
||||
out[n] = ctx.Rip;
|
||||
DWORD64 image = 0;
|
||||
PRUNTIME_FUNCTION f = RtlLookupFunctionEntry(ctx.Rip, &image, NULL);
|
||||
if (!crash_threads_in_stack(ctx.Rsp, 8, lo, hi)) break; /* (crash_threads.h: nothing read outside the stack) */
|
||||
if (!f) { /* (a leaf: the return address on the top of the stack) */
|
||||
ctx.Rip = *(DWORD64 *)ctx.Rsp;
|
||||
ctx.Rsp += 8;
|
||||
} else {
|
||||
void *handler_data = NULL;
|
||||
DWORD64 frame = 0;
|
||||
RtlVirtualUnwind(UNW_FLAG_NHANDLER, image, ctx.Rip, f, &ctx, &handler_data, &frame, NULL);
|
||||
}
|
||||
if (!ctx.Rsp) break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Every thread but the faulting one and this one, each stopped for its own unwind only. Between a SuspendThread and its
|
||||
ResumeThread nothing is allocated, locked or logged: the stopped thread may hold the heap's or the log's lock */
|
||||
static DWORD WINAPI crash_take(void *unused) {
|
||||
(void)unused;
|
||||
const DWORD me = GetCurrentThreadId(), pid = GetCurrentProcessId();
|
||||
int count = 0;
|
||||
crash_query = (CrashQueryThread)(void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryInformationThread");
|
||||
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
||||
if (snap != INVALID_HANDLE_VALUE) {
|
||||
THREADENTRY32 te;
|
||||
te.dwSize = sizeof te;
|
||||
for (BOOL ok = Thread32First(snap, &te); ok && count < CRASH_THREADS_MAX; ok = Thread32Next(snap, &te)) {
|
||||
if (te.th32OwnerProcessID != pid || te.th32ThreadID == me || te.th32ThreadID == crash_self) continue;
|
||||
HANDLE h = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, FALSE, te.th32ThreadID);
|
||||
if (!h) continue;
|
||||
CrashStack *s = &crash_stacks[count];
|
||||
s->id = te.th32ThreadID, s->frames = 0;
|
||||
if (SuspendThread(h) != (DWORD)-1) {
|
||||
s->frames = crash_unwind(h, s->pc);
|
||||
ResumeThread(h);
|
||||
}
|
||||
CloseHandle(h);
|
||||
count++;
|
||||
}
|
||||
CloseHandle(snap);
|
||||
}
|
||||
InterlockedExchange(&crash_count, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hos_crash_threads_begin(void) {
|
||||
if (!crash_threads_on(getenv("HOS_CRASH_THREADS")) || InterlockedExchange(&crash_begun, 1)) return;
|
||||
crash_self = GetCurrentThreadId();
|
||||
crash_helper = CreateThread(NULL, 0, crash_take, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
/* An address as its module's file name and the offset in it ("?" and the address where no module holds it) */
|
||||
static DWORD64 crash_in_module(DWORD64 pc, char *mod, size_t size) {
|
||||
HMODULE m = NULL;
|
||||
snprintf(mod, size, "?");
|
||||
if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)pc, &m) && m) {
|
||||
char full[MAX_PATH];
|
||||
if (GetModuleFileNameA(m, full, sizeof full)) {
|
||||
const char *b = full;
|
||||
for (const char *q = full; *q; q++)
|
||||
if (*q == '\\' || *q == '/') b = q + 1;
|
||||
snprintf(mod, size, "%s", b);
|
||||
}
|
||||
}
|
||||
return m ? pc - (DWORD64)(uintptr_t)m : pc;
|
||||
}
|
||||
|
||||
void hos_crash_threads_end(void) {
|
||||
if (!crash_helper) return;
|
||||
HANDLE helper = crash_helper;
|
||||
crash_helper = NULL; /* (one report) */
|
||||
const DWORD waited = WaitForSingleObject(helper, CRASH_THREADS_WAIT_MS);
|
||||
const LONG count = InterlockedCompareExchange(&crash_count, -1, -1);
|
||||
if (waited != WAIT_OBJECT_0 || count < 0) {
|
||||
hos_log("CRASH: the other threads' stacks were not taken within %d ms", (int)CRASH_THREADS_WAIT_MS);
|
||||
return;
|
||||
}
|
||||
CloseHandle(helper);
|
||||
typedef HRESULT(WINAPI * GetDesc)(HANDLE, PWSTR *);
|
||||
const GetDesc get_desc = (GetDesc)(void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetThreadDescription");
|
||||
int running = 0;
|
||||
for (int pass = 0; pass < 2; pass++) /* (the threads running code first, then the ones waiting in the system) */
|
||||
for (int i = 0; i < count; i++) {
|
||||
const CrashStack *s = &crash_stacks[i];
|
||||
if (!s->frames) continue;
|
||||
char mod[96];
|
||||
crash_in_module(s->pc[0], mod, sizeof mod);
|
||||
const int waiting = crash_threads_waiting(mod);
|
||||
if (waiting != pass) continue;
|
||||
running += !waiting;
|
||||
char name[96] = "";
|
||||
HANDLE h = get_desc ? OpenThread(THREAD_QUERY_LIMITED_INFORMATION, FALSE, s->id) : NULL;
|
||||
if (h) {
|
||||
PWSTR w = NULL;
|
||||
if (SUCCEEDED(get_desc(h, &w)) && w) {
|
||||
WideCharToMultiByte(CP_UTF8, 0, w, -1, name, sizeof name, NULL, NULL);
|
||||
name[sizeof name - 1] = 0;
|
||||
LocalFree(w);
|
||||
}
|
||||
CloseHandle(h);
|
||||
}
|
||||
char line[900];
|
||||
int n = snprintf(line, sizeof line, "CRASH: beside it, thread \"%s\" (%lu) %s:", name, (unsigned long)s->id,
|
||||
waiting ? "waiting" : "running");
|
||||
const int shown = crash_threads_shown(s->frames, waiting);
|
||||
for (int k = 0; k < shown && n < (int)sizeof line - 112; k++) {
|
||||
const DWORD64 off = crash_in_module(s->pc[k], mod, sizeof mod);
|
||||
n += snprintf(line + n, sizeof line - (size_t)n, " %s+%#llx", mod, (unsigned long long)off);
|
||||
}
|
||||
hos_log("%s", line);
|
||||
}
|
||||
hos_log("CRASH: beside it: %ld other threads, %d of them running code (HOS_CRASH_THREADS=0: not taken)", (long)count, running);
|
||||
}
|
||||
|
||||
#else
|
||||
/* (Linux: no stacks of other threads here; the report is as before) */
|
||||
void hos_crash_threads_begin(void) {}
|
||||
void hos_crash_threads_end(void) {}
|
||||
#endif
|
||||
57
host/crash_threads.h
Normal file
57
host/crash_threads.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* (Triforce) What the other threads were doing when one crashed (host/crash_threads.c; HOS_CRASH_THREADS=0: not taken).
|
||||
A crash report had the faulting thread alone: its registers, its guest frames, the memory three of its registers point to.
|
||||
The crash while a save loads (BaseProcCreateAndDeleteThread, the game's f_80119570 walking objects whose memory holds
|
||||
something else: -1, text, zeros; three in 105 lab runs, lab round 78) looks like an object freed and used again under
|
||||
that walk, and nothing in its reports says which thread freed it. So a report now starts by taking every other
|
||||
thread's host stack, each thread stopped only for its own unwind, on a helper thread while the faulting thread writes
|
||||
its own lines, and ends with one line a thread: the ones running game or host code first, with more frames, then the
|
||||
ones waiting in the system. Triforce.map turns the offsets into the game's functions (scripts/prof.py).
|
||||
Plain functions here: tests/test_crash_threads.py checks them. */
|
||||
#ifndef HOS_CRASH_THREADS_H
|
||||
#define HOS_CRASH_THREADS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
CRASH_THREADS_MAX = 384, /* (threads in a snapshot at most: the game has about 120) */
|
||||
CRASH_THREADS_FRAMES = 16, /* (frames kept of each stack) */
|
||||
CRASH_THREADS_WAIT_MS = 1500, /* (the report waits this long for the snapshot, then goes on without it) */
|
||||
};
|
||||
|
||||
/* HOS_CRASH_THREADS: on unless it is 0 */
|
||||
static inline int crash_threads_on(const char *env) { return !(env && env[0] == '0' && !env[1]); }
|
||||
|
||||
static inline int crash_threads_lower(int ch) { return ch >= 'A' && ch <= 'Z' ? ch + 32 : ch; }
|
||||
static inline int crash_threads_prefix(const char *s, const char *lower_prefix) {
|
||||
for (; *lower_prefix; s++, lower_prefix++)
|
||||
if (crash_threads_lower((unsigned char)*s) != *lower_prefix) return 0;
|
||||
return 1;
|
||||
}
|
||||
/* A thread whose top frame is in this module is waiting in the system (a sleep, a wait, a system call), not running the
|
||||
game's or the host's code: the report lists it after the others, with fewer frames. No module known ("?"): running */
|
||||
static inline int crash_threads_waiting(const char *top_module) {
|
||||
return crash_threads_prefix(top_module, "ntdll") || crash_threads_prefix(top_module, "kernelbase") ||
|
||||
crash_threads_prefix(top_module, "kernel32") || crash_threads_prefix(top_module, "win32u") ||
|
||||
crash_threads_prefix(top_module, "user32");
|
||||
}
|
||||
/* The frames of a stack that go into its line: all kept for a running thread, 12 for a waiting one (the system's and the
|
||||
host's wait take the first four or five; the game's functions come after them), never more than it has */
|
||||
static inline int crash_threads_shown(int frames, int waiting) {
|
||||
const int most = waiting ? 12 : CRASH_THREADS_FRAMES;
|
||||
return frames < 0 ? 0 : frames < most ? frames : most;
|
||||
}
|
||||
|
||||
/* Whether `need` bytes at sp lie in a thread's stack [lo, hi). The walk of a stopped thread reads nothing outside it: a read
|
||||
there can fault, a fault goes through the host's handlers first (host/mkw_glue.c commit_on_touch commits a reserved guest
|
||||
page and logs it: the log's lock and the heap's, which the stopped thread may hold), and the report would hang where it
|
||||
should end the process. A frame the walk cannot follow inside the stack ends the walk */
|
||||
static inline int crash_threads_in_stack(uint64_t sp, uint64_t need, uint64_t lo, uint64_t hi) {
|
||||
return sp >= lo && sp <= hi && need <= hi - sp;
|
||||
}
|
||||
|
||||
/* Starts the snapshot (once a process; the calling thread is left out). Then the caller writes its own report */
|
||||
void hos_crash_threads_begin(void);
|
||||
/* Waits for the snapshot, CRASH_THREADS_WAIT_MS at most, and writes its lines */
|
||||
void hos_crash_threads_end(void);
|
||||
|
||||
#endif
|
||||
@@ -60,6 +60,14 @@ int hos_commit(uint64_t addr, uint64_t size);
|
||||
zeroed in place (an import holds them); DISCARDED: let go, out of RAM but still committed */
|
||||
enum { HOS_MEM_COMMITTED, HOS_MEM_TOUCHED, HOS_MEM_PAGES, HOS_MEM_MAPPED, HOS_MEM_DECOMMITTED, HOS_MEM_ZEROED, HOS_MEM_DISCARDED };
|
||||
void hos_mem_note(int what, uint64_t addr, uint64_t size);
|
||||
/* ((Triforce) HOS_MEM_LIMIT, hos_mem.c) the limit in bytes (0: none), what the game holds, and whether it may take a range */
|
||||
int64_t hos_mem_limit(void);
|
||||
uint64_t hos_mem_used(void);
|
||||
int hos_mem_fits(uint64_t used, uint64_t fresh, uint64_t limit);
|
||||
int hos_mem_room(uint64_t addr, uint64_t size);
|
||||
/* ((Triforce) hos_mem.c) whether a freed address region's pages are discarded: not a region of the game's own with none of its pages
|
||||
(game_region: the game's own, and the limit on) */
|
||||
int hos_region_discard_needed(int game_region, int census_on, uint64_t game_pages);
|
||||
int hos_mem_census_on(void); /* (the notes are kept: HOS_MEM_CENSUS or HOS_MEM_GIVE_BACK) */
|
||||
int64_t hos_mem_give_back(uint64_t max_bytes);
|
||||
void hos_mem_census_start(void); /* (mkw_glue.c: the census's thread) */
|
||||
|
||||
@@ -57,6 +57,7 @@ typedef struct {
|
||||
double seconds, avg, low1, low01, max_ms;
|
||||
float points[GRAPH_POINTS];
|
||||
int npoints;
|
||||
int scene; /* ((Triforce, 11-19) the scene it measured: a scene skipped before it shifts no name */
|
||||
} Result;
|
||||
typedef struct { uint64_t screen, vt; int stage, presses, focus_asks; int64_t press_ns, ask_ns; } Screen;
|
||||
|
||||
@@ -85,6 +86,7 @@ static struct {
|
||||
uint32_t ring_n;
|
||||
Result results[MAX_SCENES];
|
||||
int nresults;
|
||||
int skipped[MAX_SCENES], nskipped; /* ((Triforce, 11-19) the scenes left out: skip_scene */
|
||||
char error[160];
|
||||
int written, closing;
|
||||
int64_t end_ns;
|
||||
@@ -256,6 +258,7 @@ static void scene_done(void) { /* (under the lock) */
|
||||
if (B.nresults >= MAX_SCENES) return;
|
||||
Result *r = &B.results[B.nresults++];
|
||||
memset(r, 0, sizeof *r);
|
||||
r->scene = B.scene;
|
||||
r->frames = B.n;
|
||||
int64_t sum = 0;
|
||||
for (int i = 0; i < B.n; i++) sum += B.iv[i];
|
||||
@@ -281,7 +284,7 @@ static void scene_done(void) { /* (under the lock) */
|
||||
}
|
||||
}
|
||||
hos_log("benchmark: scene %d of %d, %s: %.1f fps average, 1%% low %.1f, 0.1%% low %.1f, %d frames in %.2f s", B.nresults,
|
||||
B.nscenes, B.scenes[B.nresults - 1].name, r->avg, r->low1, r->low01, r->frames, r->seconds);
|
||||
B.nscenes, B.scenes[r->scene].name, r->avg, r->low1, r->low01, r->frames, r->seconds);
|
||||
}
|
||||
static void json_text(FILE *f, const char *s) {
|
||||
fputc('"', f);
|
||||
@@ -354,12 +357,14 @@ static void write_results(int stopped) { /* (under the lock; once) */
|
||||
for (int i = 0; i < B.nresults; i++) {
|
||||
const Result *r = &B.results[i];
|
||||
fprintf(f, "%s{\"name\":", i ? "," : "");
|
||||
json_text(f, B.scenes[i].name);
|
||||
json_text(f, B.scenes[r->scene].name);
|
||||
fprintf(f, ",\"avg\":%.2f,\"low1\":%.2f,\"low01\":%.2f,\"frames\":%d,\"seconds\":%.3f,\"max_ms\":%.2f,\"frametimes_ms\":[",
|
||||
bench_finite(r->avg), bench_finite(r->low1), bench_finite(r->low01), r->frames, bench_finite(r->seconds), bench_finite(r->max_ms));
|
||||
for (int p = 0; p < r->npoints; p++) fprintf(f, "%s%.2f", p ? "," : "", bench_finite(r->points[p]));
|
||||
fprintf(f, "]}");
|
||||
}
|
||||
fprintf(f, "],\"skipped\":[");
|
||||
for (int i = 0; i < B.nskipped; i++) fprintf(f, "%s", i ? "," : ""), json_text(f, B.scenes[B.skipped[i]].name);
|
||||
fprintf(f, "],\"settings\":");
|
||||
json_settings(f);
|
||||
fprintf(f, "}\n");
|
||||
@@ -379,6 +384,28 @@ static void fail(int64_t now, const char *why) { /* (under the lock) */
|
||||
B.phase = MKWVK_BENCH_FAILED, B.end_ns = now;
|
||||
write_results(1);
|
||||
}
|
||||
/* ((Triforce, 11-19) #bug-tracker "Game kept refusing to teleport to Lake Hylia while running the benchmark" (RTX 5090): one place
|
||||
the game would not take Link to failed the whole run. A place it refuses (an event or a fight keeps the event manager busy)
|
||||
or never arrives at is left out now, said in the log and the results' "skipped", and the tour goes on; it fails only
|
||||
when nothing at all was measured (under the lock) */
|
||||
static void go_scene(int64_t now);
|
||||
static void skip_scene(int64_t now, const char *why) {
|
||||
if (B.phase >= MKWVK_BENCH_DONE) return;
|
||||
hos_log("benchmark: %s %s: left out, the tour goes on", why, B.scenes[B.scene].name);
|
||||
if (B.nskipped < MAX_SCENES) B.skipped[B.nskipped++] = B.scene;
|
||||
if (++B.scene < B.nscenes) {
|
||||
go_scene(now);
|
||||
return;
|
||||
}
|
||||
if (B.nresults) {
|
||||
B.phase = MKWVK_BENCH_DONE, B.end_ns = now;
|
||||
write_results(0);
|
||||
} else {
|
||||
char msg[160];
|
||||
snprintf(msg, sizeof msg, "%s %s", why, B.scenes[B.scene - 1].name);
|
||||
fail(now, msg);
|
||||
}
|
||||
}
|
||||
static void stop(int64_t now, const char *why) { /* (under the lock) */
|
||||
if (B.phase >= MKWVK_BENCH_DONE) return;
|
||||
hos_log("benchmark: stopped (%s)", why);
|
||||
@@ -484,9 +511,7 @@ int hos_bench_link(int64_t now, uint64_t actor, const char *map, int loading, in
|
||||
B.phase = MKWVK_BENCH_SETTLE, B.t_phase = now;
|
||||
} else if (!B.saw_load && now - B.sent_ns > 12000000000LL) {
|
||||
if (++B.resends > 3) {
|
||||
char why[160];
|
||||
snprintf(why, sizeof why, "The benchmark could not reach %s", B.scenes[B.scene].name);
|
||||
fail(now, why);
|
||||
skip_scene(now, "The benchmark could not reach");
|
||||
} else {
|
||||
hos_log("benchmark: no map change 12 s after the teleport to %s: asked again", B.scenes[B.scene].name);
|
||||
B.want = 1, B.retry_ns = 0;
|
||||
@@ -504,10 +529,8 @@ void hos_bench_teleport_sent(int index, int ok) {
|
||||
if (B.phase == MKWVK_BENCH_TRAVEL && B.want) {
|
||||
if (ok) {
|
||||
B.want = 0, B.sent_ns = now, B.saw_load = 0;
|
||||
} else if (++B.tries > 60) { /* (an event playing refuses it: asked again every half second, 30 s at most) */
|
||||
char why[160];
|
||||
snprintf(why, sizeof why, "The game kept refusing the teleport to %s", B.scenes[B.scene].name);
|
||||
fail(now, why);
|
||||
} else if (++B.tries > 20) { /* (an event playing refuses it: asked again every half second, 10 s at most, then left out) */
|
||||
skip_scene(now, "The game kept refusing the teleport to");
|
||||
} else {
|
||||
B.retry_ns = now + 500000000LL;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,10 @@ static void call_guest(Ctx *c, uint64_t addr, uint64_t sp, const char *what) {
|
||||
|
||||
void hos_update_check(void); /* (host/hos_update.c) */
|
||||
#ifndef _WIN32
|
||||
/* (linux) Saves live in $XDG_DATA_HOME/hookshot (~/.local/share/hookshot), so a rebuilt game folder still finds them.
|
||||
/* (linux) Saves live in $XDG_DATA_HOME/triforce/user (~/.local/share/triforce/user), so a rebuilt game folder still finds
|
||||
them. ((Triforce) 11-19: the folder builds before v0.5.3 used, $XDG_DATA_HOME/hookshot, is renamed to it the first time,
|
||||
in one step (triforce/ itself may hold the builder already, so the saves get a folder of their own there); if that cannot
|
||||
be done the saves stay in the old folder. The launcher looks in both, the new one first.)
|
||||
A user/ folder beside the executable from before is moved there the first time, entry by entry. Anything that
|
||||
cannot be moved keeps the old place. --user still wins. */
|
||||
static int is_dir(const char *p) {
|
||||
@@ -334,7 +337,20 @@ static const char *saves_dir(const char *beside) {
|
||||
snprintf(dir, sizeof dir, "%s/.local/share", home);
|
||||
} else return beside;
|
||||
CreateDirectoryA(dir, NULL);
|
||||
snprintf(dir + strlen(dir), sizeof dir - strlen(dir), "/hookshot");
|
||||
{
|
||||
char old[MAX_PATH];
|
||||
snprintf(old, sizeof old, "%s/hookshot", dir);
|
||||
snprintf(dir + strlen(dir), sizeof dir - strlen(dir), "/triforce");
|
||||
CreateDirectoryA(dir, NULL);
|
||||
snprintf(dir + strlen(dir), sizeof dir - strlen(dir), "/user");
|
||||
if (is_dir(old) && GetFileAttributesA(dir) == INVALID_FILE_ATTRIBUTES) { /* (the old folder, and no new one yet) */
|
||||
if (MoveFileExA(old, dir, 0)) hos_log("saves: the save folder %s is now %s", old, dir);
|
||||
else {
|
||||
hos_log("saves: %s could not be renamed to %s (error %lu): the saves stay there", old, dir, (unsigned long)GetLastError());
|
||||
snprintf(dir, sizeof dir, "%s", old);
|
||||
}
|
||||
}
|
||||
}
|
||||
CreateDirectoryA(dir, NULL);
|
||||
if (GetFileAttributesA(dir) == INVALID_FILE_ATTRIBUTES) return beside;
|
||||
char pattern[MAX_PATH];
|
||||
|
||||
218
host/hos_mem.c
218
host/hos_mem.c
@@ -45,8 +45,9 @@ static void census_free(void *p, size_t n) {
|
||||
static GcMap census;
|
||||
|
||||
/* Address regions are handed out top-down from HOS_SPACE_END; the heap grows up from HOS_HEAP_BASE. (Triforce) freeing: a
|
||||
region being freed, listed until its pages are discarded (hos_region_free) */
|
||||
typedef struct { uint64_t addr, size; int freeing; } Range;
|
||||
region being freed, listed until its pages are discarded (hos_region_free); game: one the game asked for itself
|
||||
(nn::os::AllocateAddressRegion), which holds nothing of the game's until it takes pages or a physical map in it */
|
||||
typedef struct { uint64_t addr, size; int freeing, game; } Range;
|
||||
static Range *regions;
|
||||
static int nregions, capregions;
|
||||
static uint64_t region_floor = ~0ULL; /* the lowest region (none yet: the window's end) */
|
||||
@@ -93,7 +94,7 @@ uint64_t hos_sys_alloc(uint64_t size, uint64_t align) {
|
||||
return a;
|
||||
}
|
||||
|
||||
uint64_t hos_region_alloc(uint64_t size, uint64_t align) {
|
||||
static uint64_t region_alloc(uint64_t size, uint64_t align, int game) {
|
||||
if (align < 0x1000) align = 0x1000;
|
||||
size = (size + 0xFFF) & ~0xFFFULL;
|
||||
LOCK();
|
||||
@@ -133,6 +134,7 @@ uint64_t hos_region_alloc(uint64_t size, uint64_t align) {
|
||||
regions[at].addr = found;
|
||||
regions[at].size = size;
|
||||
regions[at].freeing = 0;
|
||||
regions[at].game = game;
|
||||
nregions++;
|
||||
if (found < region_floor && found >= HOS_HEAP_BASE) region_floor = found; /* (not the holes below) */
|
||||
}
|
||||
@@ -142,6 +144,21 @@ uint64_t hos_region_alloc(uint64_t size, uint64_t align) {
|
||||
(unsigned long long)hos_heap_size);
|
||||
return found;
|
||||
}
|
||||
uint64_t hos_region_alloc(uint64_t size, uint64_t align) { return region_alloc(size, align, 0); }
|
||||
|
||||
/* (Triforce) Whether a freed region's pages are discarded (hos_region_free). A region the game asked for itself holds
|
||||
nothing of the game's until it takes pages or a physical map in it, and the census knows which of its pages are the
|
||||
game's now (GC_GAME: what it was given, less what it gave back, each give-back discarded or decommitted where it was
|
||||
made). With none, there is nothing to discard: the pages were committed with the region and never handed over.
|
||||
Held to what it is told it has (HOS_MEM_LIMIT), the game's Resource Memory thread asks for a region, is refused its
|
||||
pages, frees the region and asks again: 16,640 times in a lab run of three areas (round 79), each free a
|
||||
DiscardVirtualMemory over 0.2 to 37 MB of pages nobody had touched, 61% of that thread's time while an area loaded,
|
||||
and the game's main thread waited for it: its own part of the frame 8 to 23 ms for seconds at a time, where 2 ms is
|
||||
usual (the stutter the limit was set aside for). Without the census (HOS_MEM_CENSUS=0) every region is discarded, as
|
||||
before, and so is one the host asked for itself (the renderer's and the pools' storage: written without pages) */
|
||||
int hos_region_discard_needed(int game_region, int census_on, uint64_t game_pages) {
|
||||
return !(game_region && census_on && !game_pages);
|
||||
}
|
||||
|
||||
static uint64_t pages_used[(1ULL << 32) / 0x1000 / 64];
|
||||
|
||||
@@ -158,6 +175,19 @@ static void discard_pages(uint64_t addr, uint64_t size) {
|
||||
#if defined(_WIN32) && !defined(__EMSCRIPTEN__)
|
||||
extern uint64_t hos_large_lo, hos_large_hi; /* (hos_main.c: large pages cannot be discarded) */
|
||||
if (hos_large_hi && lo < hos_large_hi && hi > hos_large_lo) return;
|
||||
/* ((Triforce, 11-19) pages a Vulkan import holds (a pool's chunk) are zeroed where they are, as FreeMemoryPages and Linux below
|
||||
do: the import keeps them locked in RAM, so a discard gave nothing back, and it was slow there: 3.7 ms a region on average,
|
||||
23 ms at most, 42 s on the game's "Resource Memory" thread over a lab tour once the game let areas go
|
||||
(QueryMemoryInfo above), with the game's frames waiting on it (Hyrule Field 34 fps, Castle Town 15). Zeroed: the pages
|
||||
read as zero, as freed pages; the census keeps them for the give-back once no import holds them) */
|
||||
extern int rx_guest_imported(uint64_t lo, uint64_t hi);
|
||||
{
|
||||
const int io = hos_guest_io_begin(GP(lo), hi - lo);
|
||||
const int held = rx_guest_imported(lo, hi);
|
||||
if (held) memset(GP(lo), 0, (size_t)(hi - lo)), hos_mem_note(HOS_MEM_ZEROED, lo, hi - lo);
|
||||
hos_guest_io_end(io);
|
||||
if (held) return; /* (lab tour: 5.2 GB zeroed in 0.47 s in all) */
|
||||
}
|
||||
/* (Triforce, the census: let go and still committed. Not the large pages above, left as they were, nor Linux's below,
|
||||
noted zeroed or decommitted there) */
|
||||
hos_mem_note(HOS_MEM_DISCARDED, lo, hi - lo);
|
||||
@@ -169,8 +199,14 @@ static void discard_pages(uint64_t addr, uint64_t size) {
|
||||
discard = (DiscardFn)(void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "DiscardVirtualMemory");
|
||||
}
|
||||
const int io = hos_guest_io_begin(GP(lo), hi - lo); /* (Triforce: the pages' state changes under the lazy write-back's: rx_backend.c) */
|
||||
/* ((Triforce) the thread's virtual core given up for the discard itself: milliseconds in the kernel for a region of some MB,
|
||||
in which the thread runs no guest code and cannot see a better thread's ask for its core (hos_thread.c vc_kick). Held to
|
||||
its memory (HOS_MEM_LIMIT) the game frees regions by the hundred while an area loads, on its Resource Memory thread.
|
||||
Only with the limit on, where it was measured: without it the game frees few regions and the path is upstream's) */
|
||||
const int away = hos_mem_limit() ? hos_vcore_away() : 0;
|
||||
if (!discard || discard(GP(lo), (SIZE_T)(hi - lo)) != ERROR_SUCCESS)
|
||||
VirtualAlloc(GP(lo), (SIZE_T)(hi - lo), MEM_RESET, PAGE_READWRITE);
|
||||
if (away) hos_vcore_back();
|
||||
hos_guest_io_end(io);
|
||||
#elif !defined(__EMSCRIPTEN__)
|
||||
extern int hos_posix_guest_discard(void *p, size_t n); /* (hos_main.c: MADV_REMOVE on the memfd window) */
|
||||
@@ -182,13 +218,16 @@ static void discard_pages(uint64_t addr, uint64_t size) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static int64_t region_frees_bare; /* ((Triforce) regions freed without a discard: hos_region_discard_needed; the refusal line's) */
|
||||
void hos_region_free(uint64_t addr) {
|
||||
uint64_t freed_size = 0;
|
||||
int game = 0;
|
||||
LOCK();
|
||||
for (int i = 0; i < nregions; i++) {
|
||||
if (regions[i].addr == addr && !regions[i].freeing) {
|
||||
pages_mark_used_locked(regions[i].addr, regions[i].size);
|
||||
freed_size = regions[i].size;
|
||||
game = regions[i].game;
|
||||
regions[i].freeing = 1;
|
||||
break;
|
||||
}
|
||||
@@ -199,7 +238,17 @@ void hos_region_free(uint64_t addr) {
|
||||
given these pages, which a discard after it would take from it, and a commit of them marked kept by the late note. Not
|
||||
under the lock: the discard may wait for the GPU (the lazy write-back) with the thread's virtual core given up, and a
|
||||
thread taking its core back with the lock held could wait on one that holds a core and waits for the lock */
|
||||
discard_pages(addr, freed_size);
|
||||
/* ((Triforce) hos_region_discard_needed: a region of the game's own with none of its pages has nothing to discard. Its
|
||||
pages are noted let go all the same, as a discard notes them: committed, and nobody's. Only with the limit on
|
||||
(HOS_MEM_LIMIT), where the refused asks make such regions by the thousand and it was measured; without it every
|
||||
region is discarded, as upstream does) */
|
||||
const uint64_t game_pages = addr + freed_size <= GC_SPACE ? gc_count(&census, GC_GAME, addr, addr + freed_size) : ~0ULL;
|
||||
if (hos_region_discard_needed(game && hos_mem_limit(), hos_mem_census_on(), game_pages)) {
|
||||
discard_pages(addr, freed_size);
|
||||
} else {
|
||||
hos_mem_note(HOS_MEM_DISCARDED, addr, freed_size);
|
||||
__atomic_add_fetch(®ion_frees_bare, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
LOCK();
|
||||
for (int i = 0; i < nregions; i++) {
|
||||
if (regions[i].addr == addr && regions[i].freeing) {
|
||||
@@ -274,16 +323,45 @@ HLE(_ZN2nn2os19AllocateMemoryBlockEPmm) {
|
||||
RET(0);
|
||||
}
|
||||
|
||||
/* ((Triforce, 11-19, lab) HOS_MEM_TRACE=1: every address region and page call of the game, with its size and caller, for the
|
||||
memory that grows all session and is never let go (the census's "let go 0" through whole tours) */
|
||||
int hos_mem_trace(void) {
|
||||
static int on = -1;
|
||||
if (on < 0) on = getenv("HOS_MEM_TRACE") && atoi(getenv("HOS_MEM_TRACE")) != 0;
|
||||
return on;
|
||||
}
|
||||
#define MEM_TRACE(...) do { if (hos_mem_trace()) hos_log(__VA_ARGS__); } while (0)
|
||||
/* (the callers above it: the guest's frame records, x29 up) */
|
||||
static const char *mem_trace_stack(const Ctx *c, char *out, size_t n) {
|
||||
uint64_t fp = c->x[29];
|
||||
size_t at = 0;
|
||||
out[0] = 0;
|
||||
for (int i = 0; i < 10 && at + 20 < n; i++) {
|
||||
if (!fp || (fp & 7) || !hos_guest_range(fp, 16)) break;
|
||||
const uint64_t ret = G64(fp + 8), up = G64(fp);
|
||||
at += (size_t)snprintf(out + at, n - at, " %#llx", (unsigned long long)ret);
|
||||
if (up <= fp) break;
|
||||
fp = up;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* nn::os::AllocateAddressRegion(unsigned long*, unsigned long) -> Result */
|
||||
HLE(_ZN2nn2os21AllocateAddressRegionEPmm) {
|
||||
HOS_TRACE_CALL("AllocateAddressRegion");
|
||||
G64(ARG(0)) = hos_region_alloc(ARG(1), 0x10000);
|
||||
G64(ARG(0)) = region_alloc(ARG(1), 0x10000, 1); /* ((Triforce) the game's own: hos_region_discard_needed) */
|
||||
if (hos_mem_trace()) {
|
||||
char st[256];
|
||||
hos_log("memtrace: region %#llx size %#llx lr %#llx st%s", (unsigned long long)G64(ARG(0)), (unsigned long long)ARG(1),
|
||||
(unsigned long long)c->x[30], mem_trace_stack(c, st, sizeof st));
|
||||
}
|
||||
RET(0);
|
||||
}
|
||||
|
||||
/* nn::os::FreeAddressRegion(unsigned long) -> Result */
|
||||
HLE(_ZN2nn2os17FreeAddressRegionEm) {
|
||||
HOS_TRACE_CALL("FreeAddressRegion");
|
||||
MEM_TRACE("memtrace: region free %#llx lr %#llx", (unsigned long long)ARG(0), (unsigned long long)c->x[30]);
|
||||
hos_region_free(ARG(0));
|
||||
RET(0);
|
||||
}
|
||||
@@ -292,11 +370,16 @@ HLE(_ZN2nn2os17FreeAddressRegionEm) {
|
||||
HLE(_ZN2nn2os19AllocateMemoryPagesEmm) {
|
||||
HOS_TRACE_CALL("AllocateMemoryPages");
|
||||
const uint64_t a = ARG(0), n = ARG(1), end = a + n;
|
||||
MEM_TRACE("memtrace: pages %#llx size %#llx lr %#llx", (unsigned long long)a, (unsigned long long)n, (unsigned long long)c->x[30]);
|
||||
if (!hos_guest_range(a, n)) { /* (hookshot: a range that wrapped around was zeroed whole, past the guest window) */
|
||||
hos_log("AllocateMemoryPages(%#llx, %#llx): outside the guest window", (unsigned long long)a, (unsigned long long)n);
|
||||
RET(0xCA01); /* svc::ResultOutOfMemory */
|
||||
return;
|
||||
}
|
||||
if (!hos_mem_room(a, n)) { /* ((Triforce) HOS_MEM_LIMIT: past what the game is told it has, as the console refuses) */
|
||||
RET(0x1A01); /* os::ResultOutOfMemory */
|
||||
return;
|
||||
}
|
||||
static int zero_all = -1;
|
||||
if (zero_all < 0) zero_all = getenv("HOS_ZERO_ALL_PAGES") != NULL;
|
||||
if (end > (1ULL << 32) && !zero_all) {
|
||||
@@ -338,6 +421,7 @@ HLE(_ZN2nn2os19AllocateMemoryPagesEmm) {
|
||||
/* nn::os::FreeMemoryPages(unsigned long, unsigned long) -> Result */
|
||||
HLE(_ZN2nn2os15FreeMemoryPagesEmm) {
|
||||
HOS_TRACE_CALL("FreeMemoryPages");
|
||||
MEM_TRACE("memtrace: pages free %#llx size %#llx lr %#llx", (unsigned long long)ARG(0), (unsigned long long)ARG(1), (unsigned long long)c->x[30]);
|
||||
if (!hos_guest_range(ARG(0), ARG(1))) { /* (hookshot: decommitted or discarded: guest pages only) */
|
||||
hos_log("FreeMemoryPages(%#llx, %#llx): outside the guest window", (unsigned long long)ARG(0), (unsigned long long)ARG(1));
|
||||
RET(0xCA01);
|
||||
@@ -369,13 +453,48 @@ HLE(_ZN2nn2os15FreeMemoryPagesEmm) {
|
||||
RET(0);
|
||||
}
|
||||
|
||||
/* ((Triforce, 11-19) the game's pages beyond its heap (game_pages_now below) */
|
||||
static uint64_t game_pages_now(void);
|
||||
/* ((Triforce, 11-19) What Horizon answers as the memory in use: the program, the system's part, the heap and every page the game
|
||||
has mapped beyond it (AllocateMemoryPages, MapPhysicalMemory), at most the total. The game's "Resource Memory" allocator
|
||||
(main 0x8080f010 / 0x8080f090, beside its region and page calls) sizes what it may still take as total - used from
|
||||
QueryMemoryInfo. It was told program + system only, so it always saw about 9.6 GB free, kept every area's resources it had
|
||||
ever loaded, and the game's own memory climbed to 12.5 GB of 9809 MB after four areas (16 GB PCs ran out: #bug-tracker
|
||||
"0.5.1 Memory-Retention Regression", "Ton of performance issues after a certain amount of time playing", the Steam Deck's
|
||||
"crash after loading save"). Told what it holds, it lets old areas go as on a Switch. HOS_MEM_QUERY_USED=0: program + system
|
||||
only, as before (also when the census is off: the pages are not counted then) */
|
||||
static uint64_t query_used(void) {
|
||||
static int full = -1;
|
||||
static uint64_t slack;
|
||||
if (full < 0) {
|
||||
const char *e = getenv("HOS_MEM_QUERY_USED"), *k = getenv("HOS_MEM_QUERY_SLACK_MB");
|
||||
full = !(e && *e == '0' && !e[1]) && hos_mem_census_on();
|
||||
slack = (uint64_t)(k && *k ? atoll(k) : 1024) << 20;
|
||||
hos_log("mem: QueryMemoryInfo's memory in use: %s, %llu MB less (HOS_MEM_QUERY_USED, HOS_MEM_QUERY_SLACK_MB)",
|
||||
full ? "the program, the heap and the game's pages, as Horizon" : "the program only, as before",
|
||||
(unsigned long long)(slack >> 20));
|
||||
}
|
||||
const uint64_t base = hos_program_size + (16ULL << 20);
|
||||
if (!full) return base;
|
||||
/* (the slack, 1024 MB by default (HOS_MEM_QUERY_SLACK_MB): room the game's cache may take beyond what a Switch leaves it,
|
||||
as NX2navi's pool extra; from its pages only, so the heap the game sizes at its start from total - used is the same. Our
|
||||
game needs ~3.2 GB of address regions at a save load where a Switch leaves ~2.8: with no slack it evicted and reloaded
|
||||
in every scene (lab tour, A/B in one build: Kokiri 52 fps, Lake Hylia 42 against 60 / 59.5 with the old answer); with
|
||||
1024 MB 60.0 / 59.9 and its own count held at 10.7 GB instead of 12.5 and climbing) */
|
||||
const uint64_t pages = game_pages_now(), used = base + hos_heap_size + (pages > slack ? pages - slack : 0);
|
||||
return used < hos_total_memory ? used : hos_total_memory;
|
||||
}
|
||||
|
||||
/* nn::os::QueryMemoryInfo(nn::os::MemoryInfo*). TOTK reads +0 (total available) and +8 (total used):
|
||||
heap = align_down(total - used, 2 MB) - 0x43800000 (main+0x1131004). */
|
||||
HLE(_ZN2nn2os15QueryMemoryInfoEPNS0_10MemoryInfoE) {
|
||||
uint64_t info = ARG(0);
|
||||
HOS_TRACE_CALL("QueryMemoryInfo");
|
||||
const uint64_t used = query_used();
|
||||
MEM_TRACE("memtrace: query used %llu MB, free %llu MB lr %#llx", (unsigned long long)(used >> 20),
|
||||
(unsigned long long)((hos_total_memory - used) >> 20), (unsigned long long)c->x[30]);
|
||||
G64(info + 0x00) = hos_total_memory; /* total available */
|
||||
G64(info + 0x08) = hos_program_size + (16ULL << 20); /* total used: program + system */
|
||||
G64(info + 0x08) = used; /* total used: program + system (+ heap + the game's pages) */
|
||||
G64(info + 0x10) = hos_heap_size; /* total heap */
|
||||
G64(info + 0x18) = hos_heap_used; /* allocated heap */
|
||||
G64(info + 0x20) = hos_program_size; /* program */
|
||||
@@ -403,6 +522,7 @@ static pthread_mutex_t census_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define CENSUS_UNLOCK() pthread_mutex_unlock(&census_lock)
|
||||
#endif
|
||||
static uint64_t census_touched, census_zeroed, census_discarded, census_given, census_given_runs, census_refused;
|
||||
static int64_t census_game_bytes; /* ((Triforce, 11-19) the game's pages and physical maps, as they are noted: hos_mem_used) */
|
||||
static int census_unsupported; /* (the renderer has no mkwvk_guest_release: no give-back) */
|
||||
|
||||
int hos_mem_census_on(void) {
|
||||
@@ -416,6 +536,15 @@ int hos_mem_census_on(void) {
|
||||
return v;
|
||||
}
|
||||
|
||||
/* ((Triforce, 11-19) The game's pages beyond its heap: the census's GC_GAME map (AllocateMemoryPages, MapPhysicalMemory, less
|
||||
what it let go), counted as the map changes (census_game_bytes, which HOS_MEM_LIMIT's hos_mem_used reads too), so a page mapped
|
||||
over one the game has already counts once. For QueryMemoryInfo's answer above. (HOS_MEM_BUDGET_MB, the budget that was here
|
||||
on 11-19, is HOS_MEM_LIMIT now: the same refusal, with its stutter fix) */
|
||||
static uint64_t game_pages_now(void) {
|
||||
const int64_t g = __atomic_load_n(&census_game_bytes, __ATOMIC_RELAXED);
|
||||
return g > 0 ? (uint64_t)g : 0;
|
||||
}
|
||||
|
||||
void hos_mem_note(int what, uint64_t addr, uint64_t size) {
|
||||
const uint64_t lo = addr, hi = addr + size;
|
||||
if (!size || hi < lo || hi > GC_SPACE || !hos_mem_census_on()) return;
|
||||
@@ -433,25 +562,94 @@ void hos_mem_note(int what, uint64_t addr, uint64_t size) {
|
||||
break;
|
||||
case HOS_MEM_PAGES:
|
||||
case HOS_MEM_MAPPED:
|
||||
gc_change(&census, GC_GAME, lo, hi, 1);
|
||||
__atomic_add_fetch(&census_game_bytes, (int64_t)gc_change(&census, GC_GAME, lo, hi, 1), __ATOMIC_RELAXED);
|
||||
break;
|
||||
case HOS_MEM_DECOMMITTED:
|
||||
gc_change(&census, GC_HELD, lo, hi, 0);
|
||||
gc_change(&census, GC_GAME, lo, hi, 0);
|
||||
__atomic_sub_fetch(&census_game_bytes, (int64_t)gc_change(&census, GC_GAME, lo, hi, 0), __ATOMIC_RELAXED);
|
||||
gc_change(&census, GC_KEPT, lo, hi, 0);
|
||||
break;
|
||||
case HOS_MEM_ZEROED: /* (every page of it committed: the zeroing touched it) */
|
||||
gc_change(&census, GC_HELD, lo, hi, 0);
|
||||
gc_change(&census, GC_GAME, lo, hi, 0);
|
||||
__atomic_sub_fetch(&census_game_bytes, (int64_t)gc_change(&census, GC_GAME, lo, hi, 0), __ATOMIC_RELAXED);
|
||||
__atomic_add_fetch(&census_zeroed, gc_change(&census, GC_KEPT, lo, hi, 1), __ATOMIC_RELAXED);
|
||||
break;
|
||||
case HOS_MEM_DISCARDED: /* (only what was committed stays so) */
|
||||
gc_change(&census, GC_GAME, lo, hi, 0);
|
||||
__atomic_sub_fetch(&census_game_bytes, (int64_t)gc_change(&census, GC_GAME, lo, hi, 0), __ATOMIC_RELAXED);
|
||||
__atomic_add_fetch(&census_discarded, gc_move(&census, GC_HELD, GC_KEPT, lo, hi), __ATOMIC_RELAXED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- (Triforce, 11-19) The game's memory held to what it is told it has (HOS_MEM_LIMIT, the lab's) ----------------------
|
||||
The game is told 9809 MB (hos_total_memory), and on the console that is a limit: its heap, its program and the pages and
|
||||
physical maps it takes count against it, and a map past it is refused (LimitReached). Here nothing was refused until the
|
||||
PC's own commit ran out, and "used" was told as the program and the heap alone, whatever the game had mapped since. So
|
||||
the game holds more than a console lets it: 11.7 GB by its own count standing in a fresh Market, 13.5 GB after a tour of
|
||||
ten areas (the census line), its resources never let go for want of room. Its 3.2 GB GPU heap then stays within some
|
||||
15 MB of full, and its texture compaction, which finds nothing to do in the fresh Market, runs a step every frame from
|
||||
the first area change on (host/oot_tex_compact.c): the after-tour slowdown of the lab's tours.
|
||||
|
||||
HOS_MEM_LIMIT=1: the limit is kept as the console keeps it. AllocateMemoryPages and MapPhysicalMemory are refused when
|
||||
the game's count would pass what it is told it has, and UsedMemorySize is the count (never more than the total).
|
||||
HOS_MEM_LIMIT=<MB> (above 1): refused past that many MB instead, to try a limit between the console's and none.
|
||||
Unset or 0: as before. Needs the census (HOS_MEM_CENSUS, on by default).
|
||||
What the game does when refused (lab round 79): it stays within a few MB of the limit and its Resource Memory thread asks
|
||||
again, some 16,000 times in a run of three areas, each ask a region taken, its pages refused, the region freed. That
|
||||
free's discard of pages nobody had touched was the stutter the limit was first set aside for (the game's main thread
|
||||
waits for that thread): hos_region_discard_needed leaves it out. The regions it frees with pages in them, some hundreds
|
||||
while an area loads, are discarded with the thread's virtual core given up (discard_pages). With both, the game's own
|
||||
part of the frame is what it is without the limit (over 8 ms in 20 frames of a three-area run either way), and the
|
||||
game holds 9.8 GB where it held 11.7. */
|
||||
int64_t hos_mem_limit(void) {
|
||||
static volatile int64_t v = -1;
|
||||
int64_t l = v;
|
||||
if (l < 0) {
|
||||
const char *e = getenv("HOS_MEM_LIMIT");
|
||||
long long n = e && *e ? atoll(e) : 0;
|
||||
if (n > (1LL << 24)) n = 1LL << 24; /* ((Triforce) 16 TB at most: a larger size would overflow the shift below) */
|
||||
if (n > 0 && !hos_mem_census_on())
|
||||
hos_log("mem: HOS_MEM_LIMIT is set but the census is off (HOS_MEM_CENSUS=0): it needs the census's count, so no limit is kept");
|
||||
l = n <= 0 || !hos_mem_census_on() ? 0 : n == 1 ? (int64_t)hos_total_memory : (int64_t)n << 20;
|
||||
if (l) hos_log("mem: the game's memory is held to %lld MB (HOS_MEM_LIMIT; it is told %llu MB)", (long long)(l >> 20),
|
||||
(unsigned long long)(hos_total_memory >> 20));
|
||||
/* ((Triforce, 11-20) the console's own size starves this build: its heap takes 6.9 GB of the 9.8, and an area's
|
||||
resources need 4.7 GB and more (a fresh Market; 6.5 after a tour). The owner's save stayed on its loading screen
|
||||
with the game at 9,807 MB and no longer asking: its load threads idle on their queues, read with the hang watch's
|
||||
asked-for stacks. A size in MB leaves room: 12800 loaded and played four areas) */
|
||||
if (n == 1 && l)
|
||||
hos_log("mem: HOS_MEM_LIMIT=1 is the console's own size, which this build does not fit in: a save's load can stay on "
|
||||
"its loading screen for good. Give a size in MB instead (12800 loaded four areas)");
|
||||
v = l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
/* What the game holds in Horizon's terms: its program, its heap, its pages and physical maps (the census's "own count") */
|
||||
uint64_t hos_mem_used(void) {
|
||||
const int64_t g = __atomic_load_n(&census_game_bytes, __ATOMIC_RELAXED);
|
||||
return hos_program_size + hos_heap_size + (uint64_t)(g > 0 ? g : 0);
|
||||
}
|
||||
/* The rule: 1 when taking `fresh` more bytes keeps the count within the limit (limit 0: no limit, always). A range the game
|
||||
holds whole already (fresh 0) takes nothing, and fits wherever the count stands */
|
||||
int hos_mem_fits(uint64_t used, uint64_t fresh, uint64_t limit) { return !limit || !fresh || used + fresh <= limit; }
|
||||
/* Whether the game may take [addr, addr + size) as pages or a physical map: only the pages of it that it does not hold yet
|
||||
count. A refusal is counted, and the first 16 and every 256th are logged */
|
||||
int hos_mem_room(uint64_t addr, uint64_t size) {
|
||||
const int64_t limit = hos_mem_limit();
|
||||
if (!limit || !size || addr + size < addr || addr + size > GC_SPACE) return 1;
|
||||
const uint64_t held = gc_count(&census, GC_GAME, addr, addr + size);
|
||||
const uint64_t fresh = size > held ? size - held : 0, used = hos_mem_used();
|
||||
if (hos_mem_fits(used, fresh, (uint64_t)limit)) return 1;
|
||||
static int64_t refused;
|
||||
const int64_t n = __atomic_add_fetch(&refused, 1, __ATOMIC_RELAXED);
|
||||
if (n <= 16 || n % 256 == 0)
|
||||
hos_log("mem: refused %llu KB at %#llx: the game holds %llu MB of %lld (HOS_MEM_LIMIT; %lld refusals so far; %lld regions "
|
||||
"freed with no page of the game's in them, not discarded)",
|
||||
(unsigned long long)(fresh >> 10), (unsigned long long)addr, (unsigned long long)(used >> 20), (long long)(limit >> 20),
|
||||
(long long)n, (long long)__atomic_load_n(®ion_frees_bare, __ATOMIC_RELAXED));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* hos_commit's notes (mkw_glue.c), around its commit: held before it, under the lock the give-back checks and decommits under
|
||||
(so no give-back takes a page it is committing), and no longer kept only once the commit is made. A commit that failed
|
||||
puts back the pages it set held (kept ones kept, never committed ones neither); begin's answer goes to end */
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
out differently (both read here at their offsets: SDL_Event is 128 bytes in SDL3, 56 in SDL2). */
|
||||
#include "hos.h"
|
||||
#include "hos_sdl.h"
|
||||
#include "pad_kind.h" /* ((Triforce) 11-20: instruments and dance mats left out of the game's input) */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -25,6 +26,7 @@ static struct {
|
||||
void *PadHasSensor, *PadSensorEnable, *PadSensorData; /* (motion: optional, NULL in an SDL without them) */
|
||||
void *GetGamepads, *GetGamepadID, *Free; /* (SDL3) */
|
||||
void *NumJoysticks, *IsGameController, *DeviceInstanceID, *GetJoystick, *JoystickInstanceID; /* (SDL2) */
|
||||
void *JoyTypeOf, *PadNameOf; /* ((Triforce) 11-20, optional: a controller's type and name before it is opened: pad_kind.h) */
|
||||
} f;
|
||||
#define CALL(type, fn) ((type)f.fn)
|
||||
|
||||
@@ -74,6 +76,9 @@ static int get_all(HMODULE m, int three) {
|
||||
*(FARPROC *)&f.PadHasSensor = GetProcAddress(m, three ? "SDL_GamepadHasSensor" : "SDL_GameControllerHasSensor");
|
||||
*(FARPROC *)&f.PadSensorEnable = GetProcAddress(m, three ? "SDL_SetGamepadSensorEnabled" : "SDL_GameControllerSetSensorEnabled");
|
||||
*(FARPROC *)&f.PadSensorData = GetProcAddress(m, three ? "SDL_GetGamepadSensorData" : "SDL_GameControllerGetSensorData");
|
||||
/* ((Triforce) 11-20) a controller's type and name by its place in the list, for the instruments left out (pad_kind.h) */
|
||||
*(FARPROC *)&f.JoyTypeOf = GetProcAddress(m, three ? "SDL_GetJoystickTypeForID" : "SDL_JoystickGetDeviceType");
|
||||
*(FARPROC *)&f.PadNameOf = GetProcAddress(m, three ? "SDL_GetGamepadNameForID" : "SDL_GameControllerNameForIndex");
|
||||
if (three) {
|
||||
GET(SetWindowPosition, "SDL_SetWindowPosition");
|
||||
GET(GetPrimaryDisplay, "SDL_GetPrimaryDisplay");
|
||||
@@ -563,18 +568,44 @@ void hos_sdl_mic_close(void *mic) {
|
||||
}
|
||||
|
||||
/* ---- controllers ---- */
|
||||
/* ((Triforce) 11-20) whether the controller at SDL's place `what` (SDL3: its id; SDL2: its device index) is an instrument or a
|
||||
dance mat, left out of the game's input (pad_kind.h); each one said once (by its id) */
|
||||
static int pad_left_out(int what, int32_t id) {
|
||||
static int all = -1;
|
||||
if (all < 0) all = getenv("HOS_SDL_ALL_PADS") && atoi(getenv("HOS_SDL_ALL_PADS")) != 0;
|
||||
if (all) return 0;
|
||||
const int type = !f.JoyTypeOf ? 0 : version == 3 ? CALL(int (*)(uint32_t), JoyTypeOf)((uint32_t)what) : CALL(int (*)(int), JoyTypeOf)(what);
|
||||
const char *name = !f.PadNameOf ? NULL : version == 3 ? CALL(const char *(*)(uint32_t), PadNameOf)((uint32_t)what)
|
||||
: CALL(const char *(*)(int), PadNameOf)(what);
|
||||
const char *why = pad_kind_left_out(type, name);
|
||||
if (!why) return 0;
|
||||
static int32_t said[8];
|
||||
static int nsaid;
|
||||
int known = 0;
|
||||
for (int i = 0; i < nsaid; i++) known |= said[i] == id;
|
||||
if (!known) {
|
||||
if (nsaid < 8) said[nsaid++] = id;
|
||||
hos_log("hid: controller \"%s\" left out: %s, not a gamepad (its whammy, tilt or pads would read as held buttons for "
|
||||
"player 1; HOS_SDL_ALL_PADS=1 keeps it)", name ? name : "?", why);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int hos_sdl_pads_list(int32_t *ids, int *opens, int max) { /* (SDL3 opens by id; SDL2 by device index) */
|
||||
int n = 0;
|
||||
if (version == 3) {
|
||||
int count = 0;
|
||||
uint32_t *got = CALL(uint32_t *(*)(int *), GetGamepads)(&count);
|
||||
for (int i = 0; got && i < count && n < max; i++) ids[n] = (int32_t)got[i], opens[n] = (int)got[i], n++;
|
||||
for (int i = 0; got && i < count && n < max; i++)
|
||||
if (!pad_left_out((int)got[i], (int32_t)got[i])) ids[n] = (int32_t)got[i], opens[n] = (int)got[i], n++;
|
||||
if (got) CALL(void (*)(void *), Free)(got);
|
||||
return n;
|
||||
}
|
||||
const int nj = CALL(int (*)(void), NumJoysticks)();
|
||||
for (int j = 0; j < nj && n < max; j++)
|
||||
if (CALL(int (*)(int), IsGameController)(j)) ids[n] = CALL(int32_t (*)(int), DeviceInstanceID)(j), opens[n] = j, n++;
|
||||
for (int j = 0; j < nj && n < max; j++) {
|
||||
if (!CALL(int (*)(int), IsGameController)(j)) continue;
|
||||
const int32_t id = CALL(int32_t (*)(int), DeviceInstanceID)(j);
|
||||
if (!pad_left_out(j, id)) ids[n] = id, opens[n] = j, n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
void *hos_sdl_pad_open(int what) {
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
#define HOS_NX2_REGION_SIZE 0x2000000000ULL
|
||||
#define R_INVALID_ENUM 0xF001 /* svc::ResultInvalidEnumValue */
|
||||
|
||||
/* ((Triforce) HOS_MEM_LIMIT, hos_mem.c: with the limit kept, what the game holds, never more than it is told it has; without,
|
||||
the program and the heap, as before) */
|
||||
static uint64_t hos_mem_used_told(void) {
|
||||
if (!hos_mem_limit()) return hos_program_size + hos_heap_size;
|
||||
const uint64_t used = hos_mem_used();
|
||||
return used < hos_total_memory ? used : hos_total_memory;
|
||||
}
|
||||
|
||||
static uint64_t get_info(uint32_t id0, uint64_t id1, int *ok) {
|
||||
*ok = 1;
|
||||
switch (id0) {
|
||||
@@ -26,7 +34,7 @@ static uint64_t get_info(uint32_t id0, uint64_t id1, int *ok) {
|
||||
case 4: return HOS_HEAP_BASE; /* HeapRegionAddress */
|
||||
case 5: return HOS_SPACE_END - HOS_HEAP_BASE; /* HeapRegionSize */
|
||||
case 6: return hos_total_memory; /* TotalMemorySize */
|
||||
case 7: return hos_program_size + hos_heap_size; /* UsedMemorySize */
|
||||
case 7: return hos_mem_used_told(); /* UsedMemorySize */
|
||||
case 8: return 0; /* DebuggerAttached */
|
||||
case 11: return 0x5A3C9E1F0B7D2468ULL ^ (id1 * 0x9E3779B97F4A7C15ULL); /* RandomEntropy */
|
||||
case 12: return 0x08000000ULL; /* AslrRegionAddress */
|
||||
@@ -42,7 +50,7 @@ static uint64_t get_info(uint32_t id0, uint64_t id1, int *ok) {
|
||||
return ctx_page;
|
||||
}
|
||||
case 21: return hos_total_memory; /* TotalNonSystemMemorySize */
|
||||
case 22: return hos_program_size + hos_heap_size; /* UsedNonSystemMemorySize */
|
||||
case 22: return hos_mem_used_told(); /* UsedNonSystemMemorySize */
|
||||
case 23: return 1; /* IsApplication */
|
||||
/* the Switch 2 SDK's (ids from Eglantine's svc_types.h / svc_info.cpp) */
|
||||
case 24: return 256; /* FreeThreadCount */
|
||||
@@ -463,6 +471,10 @@ void a64_svc(Ctx *c, uint32_t imm) {
|
||||
return;
|
||||
}
|
||||
case 0x2C: { /* MapPhysicalMemory(address, size) */
|
||||
if (!hos_mem_room(c->x[0], c->x[1])) { /* ((Triforce) HOS_MEM_LIMIT, hos_mem.c: the console's own refusal) */
|
||||
c->x[0] = 0x10801; /* (svc::ResultLimitReached) */
|
||||
return;
|
||||
}
|
||||
const int committed = hos_commit(c->x[0], c->x[1]);
|
||||
if (hos_trace) hos_log("MapPhysicalMemory(%#llx, %#llx)", (unsigned long long)c->x[0], (unsigned long long)c->x[1]);
|
||||
if (committed > 0) hos_mem_note(HOS_MEM_MAPPED, c->x[0], c->x[1]); /* (Triforce: the census, the game's physical maps) */
|
||||
|
||||
@@ -31,6 +31,7 @@ struct HosThread {
|
||||
char name[48];
|
||||
HANDLE handle;
|
||||
int started;
|
||||
int bg_kind; int64_t bg_since; /* (HOS_BG_THROTTLE: bg_throttle) */
|
||||
/* the kernel side (hos_svc.c): this thread's Horizon handle and the event it blocks on */
|
||||
uint32_t kernel_handle;
|
||||
HANDLE wake;
|
||||
@@ -349,6 +350,9 @@ void hos_fatal(Ctx *c, const char *fmt, ...) {
|
||||
TerminateProcess(GetCurrentProcess(), 3);
|
||||
ExitProcess(3);
|
||||
}
|
||||
/* (Triforce) what the other threads are doing now, taken while this one reports (host/crash_threads.h) */
|
||||
void hos_crash_threads_begin(void), hos_crash_threads_end(void);
|
||||
hos_crash_threads_begin();
|
||||
if (!c) c = hos_ctx();
|
||||
log_flush();
|
||||
fprintf(stderr, "[hos %s] FATAL: %s", cur ? cur->name : "host", buf);
|
||||
@@ -358,6 +362,8 @@ void hos_fatal(Ctx *c, const char *fmt, ...) {
|
||||
void hos_backtrace(void), hos_hostcall_stats(void);
|
||||
hos_backtrace();
|
||||
hos_hostcall_stats();
|
||||
hos_crash_threads_end();
|
||||
log_flush();
|
||||
/* (Triforce, after NX2navi) TerminateProcess, not ExitProcess: ExitProcess stops the other threads wherever they are
|
||||
and then runs every library's detach on this thread, and a detach that faults there (an upscaler's, a driver's) put
|
||||
a crash report of its own after the lines above, or held the process open. Everything said here is written out
|
||||
@@ -1048,11 +1054,22 @@ void hos_sleep_logged(int64_t ns, uint64_t lr) {
|
||||
frame noticed the GPU's signal late, ~7 ms of the 25 ms frame asleep on its critical path. The GPU writes the event
|
||||
into guest memory itself, so the sleep looks at it between yields (its virtual core given up) and ends once it is
|
||||
1, at the latest when the asked time is up. Only where the poll is nvnEventGetValue. HOS_PRESENT_POLL=1 (an
|
||||
experiment: no fps change measured, and it keeps a core busy while it looks) */
|
||||
experiment: no fps change measured, and it keeps a core busy while it looks).
|
||||
(Triforce, gpu/vk/async_rules.h 4) With the replay on a thread of its own (RX_VK_ASYNC=1) it is on unless
|
||||
HOS_PRESENT_POLL=0: there the poll does sleep, every frame, until the replay thread has recorded the frame and the GPU has
|
||||
run it, and each sleep ended about 0.6 ms late on average by the system's timer. And it does not look the whole time: while
|
||||
the replay thread still has work handed over the event cannot be set by that work, so the poll waits for the thread, asleep
|
||||
(rx_nvn_replay_idle_wait, the asked time at most), and looks between yields only once the GPU has the frame */
|
||||
static int present_poll(Ctx *c, int64_t ns) {
|
||||
static int on = -1;
|
||||
static int on = -1, async = 0;
|
||||
static uint64_t fn_ok, fn_bad;
|
||||
if (on < 0) on = getenv("HOS_PRESENT_POLL") && atoi(getenv("HOS_PRESENT_POLL")) != 0;
|
||||
int rx_async_replay(void);
|
||||
int rx_nvn_replay_idle_wait(uint64_t timeout_ns);
|
||||
if (on < 0) {
|
||||
const char *e = getenv("HOS_PRESENT_POLL");
|
||||
async = rx_async_replay();
|
||||
on = e ? atoi(e) != 0 : async;
|
||||
}
|
||||
if (!on || c->x[30] != 0x80590520 || ns <= 0 || ns > 20000000) return 0;
|
||||
const uint64_t fp = G64(c->x[24]);
|
||||
if (fp != fn_ok) {
|
||||
@@ -1069,6 +1086,10 @@ static int present_poll(Ctx *c, int64_t ns) {
|
||||
if (!hos_nvn_event_value(ev, &v)) return 0;
|
||||
const int away = hos_vcore_away();
|
||||
const int64_t end = hos_now_ns() + ns;
|
||||
if (async && v != 1) { /* (asleep while the replay thread records: the asked time at most, as the sleep it stands for) */
|
||||
rx_nvn_replay_idle_wait((uint64_t)ns);
|
||||
hos_nvn_event_value(ev, &v);
|
||||
}
|
||||
while (v != 1 && hos_now_ns() < end) {
|
||||
SwitchToThread();
|
||||
for (int i = 0; i < 64; i++) _mm_pause();
|
||||
@@ -1606,8 +1627,35 @@ void hos_vcore_back(void) {
|
||||
mkw_glue.c: the poll hands over no context, so the compiler need not spill them). It, and everything it calls, must never
|
||||
read or write the thread's guest context (Ctx) or run guest code: what it would see there may be older than the loop. A
|
||||
stall dump of a thread spinning in a polled loop shows such older registers for the same reason. */
|
||||
/* HOS_BG_THROTTLE=<run us>:<sleep us> (default 300:3000, =0: off): OoT's OptimizeChangeBank (guest priority 27, the lowest:
|
||||
on the console it gets only the time nothing else wants) runs without end here, 35-44% of a logical processor in busy
|
||||
places, at the host's lowest priority, which keeps it off no SMT sibling: the game's executor, module worker or replay
|
||||
thread on the other half of its core ran up to 1.7x slower while it did. After <run> of running it gives its virtual core
|
||||
up and sleeps <sleep>, at a checkpoint (an nn::os call or SVC, where Horizon could switch it out too): ~5-9% of a
|
||||
processor instead. bg_kind: 0 not looked at yet, 1 that thread, 2 any other */
|
||||
static void bg_throttle(HosThread *t) {
|
||||
static int64_t run_ns = -1, sleep_ms;
|
||||
if (run_ns < 0) {
|
||||
const char *e = getenv("HOS_BG_THROTTLE");
|
||||
long long r = 300, s = 3000;
|
||||
if (e && sscanf(e, "%lld:%lld", &r, &s) < 1) r = 300;
|
||||
sleep_ms = s >= 1000 ? s / 1000 : 1;
|
||||
if (r > 0) hos_log("threads: OptimizeChangeBank runs %lld us, then sleeps %lld ms (HOS_BG_THROTTLE)", r, (long long)sleep_ms);
|
||||
run_ns = r > 0 ? r * 1000 : 0;
|
||||
}
|
||||
if (!t->bg_kind) t->bg_kind = strstr(t->name, "OptimizeChange") ? 1 : 2;
|
||||
if (t->bg_kind != 1 || !run_ns) return;
|
||||
const int64_t now = hos_now_ns();
|
||||
if (!t->bg_since) t->bg_since = now;
|
||||
if (now - t->bg_since < run_ns) return;
|
||||
const int away = hos_vcore_away();
|
||||
Sleep((DWORD)sleep_ms);
|
||||
if (away) hos_vcore_back();
|
||||
t->bg_since = hos_now_ns();
|
||||
}
|
||||
void hos_vcore_checkpoint(void) {
|
||||
HosThread *t = cur;
|
||||
if (t && t->bg_kind != 2) bg_throttle(t);
|
||||
if (t && t->vc_kick) vc_yield(t, t->vc_kick == 1);
|
||||
}
|
||||
void hos_vcore_yield(void) {
|
||||
|
||||
@@ -219,10 +219,12 @@ void hos_menu_sound_play(int id, int64_t now_ns) {
|
||||
if (voices[i].started < oldest) oldest = voices[i].started, pick = i;
|
||||
}
|
||||
/* A sound that replaces itself restarts instead of stacking up, and a decision replaces the tick of the same press
|
||||
(a row changes its value in the tick the press is seen). */
|
||||
(a row changes its value in the tick the press is seen). ((Triforce, 11-19) the system menu's tick too: the mouse
|
||||
onto Mods or Quit and its click in one tick is their decide alone) */
|
||||
for (int i = 0; i < VOICES; i++) {
|
||||
const int64_t at = atomic_load_explicit(&voices[i].at, memory_order_acquire);
|
||||
if (at >= 0 && (atomic_load(&voices[i].sound) == id || atomic_load(&voices[i].sound) == HOS_MENU_SOUND_CURSOR) &&
|
||||
const int was = atomic_load(&voices[i].sound);
|
||||
if (at >= 0 && (was == id || was == HOS_MENU_SOUND_CURSOR || was == HOS_MENU_SOUND_SYS_CURSOR) &&
|
||||
AT_FRAME(at) < 2400) { /* started under 50 ms ago */
|
||||
pick = i;
|
||||
break;
|
||||
|
||||
@@ -103,6 +103,10 @@ static LONG WINAPI report_crash(EXCEPTION_POINTERS *info) {
|
||||
report, or the same crash handed here twice (report_fatal below, then the unhandled filter), is not reported again */
|
||||
int hos_ending_enter(void);
|
||||
if (!hos_ending_enter()) return EXCEPTION_CONTINUE_SEARCH;
|
||||
/* (Triforce) first of all, what the other threads are doing now: taken on a helper thread while this one writes its
|
||||
report, written at the report's end (host/crash_threads.h) */
|
||||
void hos_crash_threads_begin(void), hos_crash_threads_end(void);
|
||||
hos_crash_threads_begin();
|
||||
EXCEPTION_RECORD *rec = info->ExceptionRecord;
|
||||
const uint64_t rip = info->ContextRecord->Rip;
|
||||
HMODULE mod = NULL;
|
||||
@@ -185,6 +189,8 @@ static LONG WINAPI report_crash(EXCEPTION_POINTERS *info) {
|
||||
(unsigned long long)peek_guest(base + row + 16), (unsigned long long)peek_guest(base + row + 24));
|
||||
}
|
||||
}
|
||||
hos_log_flush(); /* (the report so far is written before the wait for the other threads' stacks) */
|
||||
hos_crash_threads_end();
|
||||
hos_log_flush();
|
||||
void hos_hostcall_stats(void);
|
||||
hos_hostcall_stats(); /* (HOS_HOSTCALL_STATS=1: the host calls made, and the last 256 of them) */
|
||||
@@ -208,6 +214,16 @@ void hos_backtrace(void) {
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
/* (Triforce) HOS_CRASH_TEST_S=<seconds>, a lab switch: a host thread reads address 8 that long after the start, so that a
|
||||
crash report (and its other threads' lines, host/crash_threads.h) can be looked at from a run in the game */
|
||||
static DWORD WINAPI crash_test_after(void *p) {
|
||||
Sleep((DWORD)(uintptr_t)p * 1000);
|
||||
hos_log("crash test: a read of address 8 now (HOS_CRASH_TEST_S)");
|
||||
hos_log_flush();
|
||||
volatile int *bad = (volatile int *)(uintptr_t)8;
|
||||
return (DWORD)*bad;
|
||||
}
|
||||
|
||||
/* HOS_STATS_AFTER=<seconds> (with HOS_HOSTCALL_STATS=1): the host call counts and the last calls at that time, for
|
||||
runs that are stopped rather than exit (what a quiet game is doing) */
|
||||
static DWORD WINAPI stats_after(void *p) {
|
||||
@@ -235,6 +251,8 @@ void hos_commit_init(void) {
|
||||
SetUnhandledExceptionFilter(report_crash);
|
||||
const char *after = getenv("HOS_STATS_AFTER");
|
||||
if (after && atoi(after) > 0) CreateThread(NULL, 0, stats_after, (void *)(uintptr_t)atoi(after), 0, NULL);
|
||||
const char *crash = getenv("HOS_CRASH_TEST_S");
|
||||
if (crash && atoi(crash) > 0) CreateThread(NULL, 0, crash_test_after, (void *)(uintptr_t)atoi(crash), 0, NULL);
|
||||
}
|
||||
|
||||
/* ---- stand-ins --------------------------------------------------------------------------------------------- */
|
||||
|
||||
@@ -78,6 +78,8 @@ static const char *desired_language(void) {
|
||||
else hos_log("oe: language %s (%s)", lang, from);
|
||||
return lang;
|
||||
}
|
||||
/* (Triforce) prompts.c: the language the game shows (one of languages[]' codes), for the title's messages it serves */
|
||||
const char *hos_desired_language(void) { return desired_language(); }
|
||||
HLE(_ZN2nn2oe18GetDesiredLanguageEv) {
|
||||
uint64_t v = 0;
|
||||
memcpy(&v, desired_language(), strlen(desired_language()));
|
||||
@@ -102,9 +104,14 @@ int hos_ini_option(const char *key, int otherwise) { /* (hookshot: the Insert
|
||||
fclose(f);
|
||||
return otherwise;
|
||||
}
|
||||
/* ((Triforce, options_version 7) The Insert menu's handheld profile is the Output resolution row's 1536 x 864: output_res=7,
|
||||
or HOS_OUTPUT_RES=7. handheld_profile=1 is a file's from before version 7, the row that was, until the menu writes the file
|
||||
again (gpu/vk/merged_rows.h migrate: it becomes output_res=7) */
|
||||
static int output_row(void) { return getenv("HOS_OUTPUT_RES") ? atoi(getenv("HOS_OUTPUT_RES")) : ini_option("output_res", 0); }
|
||||
static int handheld(void) {
|
||||
static int v = -1;
|
||||
if (v < 0) v = getenv("HOS_HANDHELD") ? atoi(getenv("HOS_HANDHELD")) != 0 : ini_option("handheld_profile", 0) != 0;
|
||||
if (v < 0)
|
||||
v = getenv("HOS_HANDHELD") ? atoi(getenv("HOS_HANDHELD")) != 0 : output_row() == 7 || ini_option("handheld_profile", 0) != 0;
|
||||
return v;
|
||||
}
|
||||
/* (hookshot) The Insert menu's Output resolution (output_res=, HOS_OUTPUT_RES over it), docked only: 0 the game's 2048 x 1152,
|
||||
@@ -116,9 +123,9 @@ static int output_mode(void) {
|
||||
static int v = -1;
|
||||
if (v < 0) {
|
||||
static const char *const names[] = {"2048x1152 (the game's)", "2560x1440", "3840x2160", "1920x1080", "5120x1440", "5120x2880", "5120x2160"};
|
||||
v = getenv("HOS_OUTPUT_RES") ? atoi(getenv("HOS_OUTPUT_RES")) : ini_option("output_res", 0);
|
||||
if ((unsigned)v >= sizeof names / sizeof *names || handheld()) v = 0;
|
||||
hos_log("oe: output resolution %s", names[v]);
|
||||
v = output_row();
|
||||
if ((unsigned)v >= sizeof names / sizeof *names || handheld()) v = 0; /* (7, the handheld profile's: handheld() sizes it) */
|
||||
hos_log("oe: output resolution %s", handheld() ? "the handheld profile's (1536x864)" : names[v]);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
170
host/nn_hid.c
170
host/nn_hid.c
@@ -148,6 +148,17 @@ static void mouse_look_tick(void) {
|
||||
static volatile LONG64 player_input_ns;
|
||||
int64_t hos_player_input_ns(void) { return InterlockedCompareExchange64(&player_input_ns, 0, 0); }
|
||||
static void player_used(void) { InterlockedExchange64(&player_input_ns, hos_now_ns()); }
|
||||
/* ((Triforce, 11-19) the device the player used last: 0 none yet, 1 the keys or the mouse (a bound key, a bound mouse
|
||||
button or the captured mouse's motion), 2 a controller (a button, a stick past 12000), for host/prompts.c's Button prompts
|
||||
Auto (the face of the next start) and the overlay's icons. read_input only stores it, and only when it changes; and counts
|
||||
each device's uses (hos_input_uses: prompts.c tells a player using the keys from a key pressed once) */
|
||||
static volatile LONG input_last, input_uses[3];
|
||||
int hos_input_last(void) { return (int)input_last; }
|
||||
unsigned hos_input_uses(int device) { return device >= 1 && device <= 2 ? (unsigned)input_uses[device] : 0; }
|
||||
static void device_used(LONG device) {
|
||||
InterlockedIncrement(&input_uses[device]);
|
||||
if (input_last != device) InterlockedExchange(&input_last, device);
|
||||
}
|
||||
static volatile LONG drag_dx, drag_dy, drag_right;
|
||||
static double drag_x, drag_y;
|
||||
void hos_hid_drag(int dx, int dy, int right) {
|
||||
@@ -823,8 +834,9 @@ static void pads_read(uint64_t *buttons, int32_t stick[4]) {
|
||||
}
|
||||
|
||||
/* (Triforce) Whether XInput has a controller now, for the Button prompts row's Auto (host/prompts.c auto_face), which asks
|
||||
once, at the game's start, and only when SDL names none: a controller read through XInput alone (HOS_NO_SDL=1, or no
|
||||
SDL beside the game) keeps the game's own icons, and only a PC with no controller at all gets the keys' */
|
||||
once, at the game's start, and only when SDL names none: a controller read through XInput alone (HOS_NO_SDL=1, no SDL
|
||||
beside the game, or one SDL had not opened yet) gets the Xbox's icons ((11-19) the Switch's before), XInput reading
|
||||
only pads of the Xbox's layout, and only a PC with no controller there gets the keys' or the last run's device's */
|
||||
int hos_xinput_connected(void) {
|
||||
XInputGetStateFn get = xinput_get;
|
||||
#ifdef _WIN32 /* (as pads_read: System32's) */
|
||||
@@ -994,16 +1006,25 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) {
|
||||
return;
|
||||
}
|
||||
{ /* (Triforce) The options' tabs inside the game's own Options screen (host/oot_menu.c, gpu/vk/vk_menu.cpp): one of
|
||||
our tabs left with Back (the gamepad input B is bound to, Esc, or the mouse's right button) is the game's Back as well, as in its own
|
||||
our tabs left with Back (the gamepad input B is bound to, Esc, a key bound to B, or the mouse's right button) is the game's Back as well, as in its own
|
||||
menus one Back leaves the screen from any tab. The press itself never reaches the game (below), so B is
|
||||
tapped for it. A tab left with L or R is the game's own tab: no tap */
|
||||
int hos_oot_options_front(void);
|
||||
static int was_open;
|
||||
const int open = rx_option(1, 0);
|
||||
/* (and the keys bound to B, as the game's own tab has them: our tabs take a modifier there (Shift, B's default) as it is
|
||||
let go (gpu/vk/vk_menu.cpp menu_tick, so that Shift+Tab still steps back a tab), so it is up by the time they close:
|
||||
one seen down within the last 300 ms counts) */
|
||||
static int64_t b_key_ns;
|
||||
const int64_t now = hos_now_ns();
|
||||
for (int k = 0; k < 2; k++) {
|
||||
const int vk = hos_binding(HOS_BIND_KEY, HOS_SW_B, k);
|
||||
if (vk >= 8 && (GetAsyncKeyState(vk) & 0x8000)) b_key_ns = now;
|
||||
}
|
||||
if (was_open && !open && hos_oot_options_front()) {
|
||||
const int b = hos_binding(HOS_BIND_PAD, HOS_SW_B, 0);
|
||||
if ((b >= 0 && b < HOS_PAD_N && ((uint32_t)pad_raw_now >> b & 1)) || (GetAsyncKeyState(VK_ESCAPE) & 0x8000) ||
|
||||
(GetAsyncKeyState(VK_RBUTTON) & 0x8000))
|
||||
(GetAsyncKeyState(VK_RBUTTON) & 0x8000) || (b_key_ns && now - b_key_ns < 300000000LL))
|
||||
hos_hid_tap("0:B/80");
|
||||
}
|
||||
was_open = open;
|
||||
@@ -1022,12 +1043,12 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) {
|
||||
}
|
||||
if (pb || ps[0] > 12000 || ps[0] < -12000 || ps[1] > 12000 || ps[1] < -12000 || ps[2] > 12000 || ps[2] < -12000 ||
|
||||
ps[3] > 12000 || ps[3] < -12000)
|
||||
player_used();
|
||||
player_used(), device_used(2);
|
||||
}
|
||||
binds_load(); /* (the keys: key_default's, or triforce_options.ini's; the mouse's buttons once its capture is known) */
|
||||
walk_vk = walk_key_code(rx_option(HOS_OPT_WALK_KEY, 0)); /* ((Triforce) before the keys are read: it is none of theirs) */
|
||||
for (int i = 0; i < HOS_SW_N; i++)
|
||||
if (bound_down(i, 0)) *buttons |= 1ULL << i, player_used();
|
||||
if (bound_down(i, 0)) *buttons |= 1ULL << i, player_used(), device_used(1);
|
||||
int32_t mouse[4] = {0};
|
||||
/* the mouse's motion: the camera itself (mouse_native.c) with the menu's Mouse camera on Native, else the right
|
||||
stick; also the stick while the game does not give the camera free control (a menu, a lock-on, the pause menu,
|
||||
@@ -1055,13 +1076,16 @@ static void read_input(uint64_t *buttons, int32_t stick[4]) {
|
||||
mouse_buttons_arm(captured);
|
||||
if (captured)
|
||||
for (int i = 0; i < HOS_SW_N; i++)
|
||||
if (bound_down(i, 1)) *buttons |= 1ULL << i;
|
||||
if (bound_down(i, 1)) *buttons |= 1ULL << i, device_used(1);
|
||||
/* ((Triforce) the captured mouse turning the camera: past an eighth of the stick's travel, not the mouse nudged) */
|
||||
if (mouse[2] > 4096 || mouse[2] < -4096 || mouse[3] > 4096 || mouse[3] < -4096) device_used(1);
|
||||
/* (the left stick's and the camera's keys: WASD and the arrows or IJKL by default) */
|
||||
const int cx = bound_down(HOS_KEY_CAM_RIGHT, captured) - bound_down(HOS_KEY_CAM_LEFT, captured),
|
||||
cy = bound_down(HOS_KEY_CAM_UP, captured) - bound_down(HOS_KEY_CAM_DOWN, captured);
|
||||
int32_t keys[4] = {(bound_down(HOS_KEY_MOVE_RIGHT, captured) - bound_down(HOS_KEY_MOVE_LEFT, captured)) * 32767,
|
||||
(bound_down(HOS_KEY_MOVE_UP, captured) - bound_down(HOS_KEY_MOVE_DOWN, captured)) * 32767,
|
||||
cx * 32767, cy * 32767};
|
||||
if (keys[0] || keys[1] || cx || cy) device_used(1); /* ((Triforce) the movement and camera keys) */
|
||||
/* ((Triforce) the walk key held: the movement keys push the left stick a part of the way. The keys' alone: a
|
||||
controller's stick and the scripted presses are as they are) */
|
||||
if (walk_vk && key(walk_vk)) walk_keys(keys, rx_option(HOS_OPT_WALK_SCALE, 51));
|
||||
@@ -1075,6 +1099,88 @@ static void vibration_send(uint64_t handle, uint64_t value);
|
||||
volatile int64_t hos_hid_last_read;
|
||||
|
||||
volatile uint64_t hos_npad_buttons; /* (Triforce) the buttons of the last state the game was given: host/mod_cheats.c */
|
||||
/* (Triforce) The Mods entry under a game list's last button (host/oot_menu.c, gpu/vk/vk_menu.cpp), from npad_states' read: while
|
||||
the game's cursor is on that last button and our menu is shut, Down (the D-pad's, or the left stick held down) is the
|
||||
entry's, not the game's: the renderer takes the cursor onto Mods at its first frame.
|
||||
While the Mods entry or its screen has the cursor the game gets no input (a pad's is the menu's already, read_input, and the
|
||||
keys' too, key()). What is left is a test's scripted presses (the script, the live input file): they go to the menu as a
|
||||
pad's would (HOS_OPT_MODS_PRESS), not to the game. Buttons held as the cursor goes back to the game are not the game's until
|
||||
let go (the Up that left Mods does not move the game's cursor too).
|
||||
((Triforce, 11-19) the lab's "a normal DOWN from Title Screen skips Mods to Quit": the Down that brought the cursor onto
|
||||
Mods, still held at the next read, counted there as a new press of the entry's (the buttons before were taken as none
|
||||
held), on to Quit; a 16 ms Down, gone by then, landed on Mods. A press is new against the buttons of the read before,
|
||||
whichever side had them: those held as the cursor comes onto Mods, its Down among them, are held, not pressed. And the
|
||||
directions held are told at each read (HOS_MODS_HELD_*), so the menu repeats a held one at its rate as it repeats a
|
||||
pad's or a key's) */
|
||||
static void mods_input(uint64_t *buttons_io, int32_t stick[4]) {
|
||||
int hos_oot_mods_down(void);
|
||||
uint64_t buttons = *buttons_io;
|
||||
const uint64_t raw = buttons; /* (as the devices and the script gave them, before the entry takes its Down) */
|
||||
/* ((Triforce) 11-17) the left stick pushed past half its travel, as the D-pad */
|
||||
const int raw_dir = stick[1] > 16384 ? HOS_MODS_PRESS_UP : stick[1] < -16384 ? HOS_MODS_PRESS_DOWN
|
||||
: stick[0] < -16384 ? HOS_MODS_PRESS_LEFT : stick[0] > 16384 ? HOS_MODS_PRESS_RIGHT : 0;
|
||||
static int was_down;
|
||||
/* (a press only: the Down that brought the game's cursor onto the last button, still held, is not one.
|
||||
((Triforce, 11-19) the stick's Down where the menu's pad bits have it, past half its travel (HOS_PAD_LS_DOWN,
|
||||
pads_read): at -16000 it came onto Mods a read before the menu saw the stick's Down, which it then took as a
|
||||
Down of its own, on to Quit) */
|
||||
const int down = (int)(buttons >> B_DOWN & 1) || stick[1] < -16384;
|
||||
/* ((Triforce, 11-19) a Down held from higher up the list: the game's own repeat takes its cursor onto the last button,
|
||||
and the Down, held from before, was no press there, so the cursor stayed on that button as long as it was held. A
|
||||
held Down goes on onto Mods as a repeat, at the menu's held-direction rate (vk_menu.cpp menu_tick: after 0.35 s held,
|
||||
then a step of 83 ms, 33 ms past 1.5 s): at its first step on the last button once the hold is past the first delay.
|
||||
A Down pressed on the button above, which moves the game's cursor onto the last one, needs the first 0.35 s held as
|
||||
any repeat does: a short press stays there. Its word is 5, a repeat's: the menu repeats on from Mods at the step) */
|
||||
static int64_t down_ns, last_ns; /* (when this Down was pressed; when it was first held on the last button, 0 none) */
|
||||
static int repeated; /* (its repeat onto Mods told: once a hold) */
|
||||
const int64_t now = hos_now_ns();
|
||||
if (down && !was_down) down_ns = now, repeated = 0;
|
||||
if (!rx_option(1, 0) && hos_oot_mods_down() && down) {
|
||||
buttons &= ~(1ULL << B_DOWN);
|
||||
stick[1] = 0;
|
||||
if (!was_down) {
|
||||
rx_option_set(HOS_OPT_MODS_ENTER, 1), last_ns = 0;
|
||||
} else if (!repeated) {
|
||||
if (!last_ns) last_ns = now;
|
||||
const int64_t held = now - down_ns, step = held > 1500000000LL ? 33000000LL : 83000000LL;
|
||||
if (held >= 350000000LL && now - last_ns >= step) rx_option_set(HOS_OPT_MODS_ENTER, 5), repeated = 1, last_ns = 0;
|
||||
}
|
||||
} else {
|
||||
last_ns = 0;
|
||||
}
|
||||
was_down = down;
|
||||
static uint64_t prev, held_over;
|
||||
static int sel_was, stick_over, stick_was;
|
||||
const int sel = rx_option(HOS_OPT_MODS_SELECTED, 0) != 0;
|
||||
if (sel) {
|
||||
static const struct { int bit, press; } map[] = {{B_UP, HOS_MODS_PRESS_UP}, {B_DOWN, HOS_MODS_PRESS_DOWN},
|
||||
{B_LEFT, HOS_MODS_PRESS_LEFT}, {B_RIGHT, HOS_MODS_PRESS_RIGHT}, {B_A, HOS_MODS_PRESS_A}, {B_B, HOS_MODS_PRESS_B},
|
||||
{B_L, HOS_MODS_PRESS_L}, {B_R, HOS_MODS_PRESS_R}};
|
||||
const uint64_t fresh = buttons & ~prev;
|
||||
int bits = 0, held = raw_dir;
|
||||
for (int i = 0; i < (int)(sizeof map / sizeof *map); i++) {
|
||||
if (fresh >> map[i].bit & 1) bits |= map[i].press;
|
||||
if (buttons >> map[i].bit & 1) held |= map[i].press;
|
||||
}
|
||||
if (raw_dir && raw_dir != stick_was) bits |= raw_dir;
|
||||
stick_was = raw_dir;
|
||||
/* (each read: the presses, and the directions held, which the menu repeats; the report bit says it is one) */
|
||||
rx_option_set(HOS_OPT_MODS_PRESS, bits | (held & HOS_MODS_PRESS_DIRS) << HOS_MODS_HELD_SHIFT | HOS_MODS_REPORT);
|
||||
prev = buttons;
|
||||
buttons = 0;
|
||||
memset(stick, 0, 4 * sizeof *stick);
|
||||
} else {
|
||||
if (sel_was) held_over = prev | buttons, stick_over = 1; /* ((Triforce, 11-19) and the keys: the menu's while it was open) */
|
||||
held_over &= buttons;
|
||||
buttons &= ~held_over;
|
||||
if (stick_over && stick[0] > -12000 && stick[0] < 12000 && stick[1] > -12000 && stick[1] < 12000) stick_over = 0;
|
||||
if (stick_over) stick[0] = stick[1] = 0;
|
||||
prev = raw, stick_was = raw_dir; /* (held now: not pressed at the first read with Mods chosen) */
|
||||
}
|
||||
sel_was = sel;
|
||||
*buttons_io = buttons;
|
||||
}
|
||||
|
||||
/* GetNpadStates(State* out, int count, unsigned int const& npadId): the latest state first */
|
||||
static void npad_states(Ctx *c) {
|
||||
uint64_t out = ARG(0);
|
||||
@@ -1106,55 +1212,7 @@ static void npad_states(Ctx *c) {
|
||||
}
|
||||
if (connected) {
|
||||
read_input(&buttons, stick);
|
||||
{ /* (Triforce) the Mods entry under a game list's last button (host/oot_menu.c, gpu/vk/vk_menu.cpp): while the
|
||||
game's cursor is on that last button and our menu is shut, Down (the D-pad's, or the left stick held down)
|
||||
is the entry's, not the game's: the renderer takes the cursor onto Mods at its first frame */
|
||||
int hos_oot_mods_down(void);
|
||||
static int was_down;
|
||||
/* (a press only: the Down that brought the game's cursor onto the last button, still held, is not one) */
|
||||
const int down = (int)(buttons >> B_DOWN & 1) || stick[1] < -16000;
|
||||
if (!rx_option(1, 0) && hos_oot_mods_down() && down) {
|
||||
buttons &= ~(1ULL << B_DOWN);
|
||||
stick[1] = 0;
|
||||
if (!was_down) rx_option_set(HOS_OPT_MODS_ENTER, 1);
|
||||
}
|
||||
was_down = down;
|
||||
/* While the Mods entry or its screen has the cursor the game gets no input (a pad's is the menu's already,
|
||||
above, and the keys' too, key()). What is left is a test's scripted presses: they go to the menu as a pad's
|
||||
would (HOS_OPT_MODS_PRESS), not to the game. Buttons held as the cursor goes back to the game are not the
|
||||
game's until let go (the Up that left Mods does not move the game's cursor too) */
|
||||
static uint64_t prev, held_over;
|
||||
static int sel_was, stick_over;
|
||||
const int sel = rx_option(HOS_OPT_MODS_SELECTED, 0) != 0;
|
||||
if (sel) {
|
||||
static const struct { int bit, press; } map[] = {{B_UP, HOS_MODS_PRESS_UP}, {B_DOWN, HOS_MODS_PRESS_DOWN},
|
||||
{B_LEFT, HOS_MODS_PRESS_LEFT}, {B_RIGHT, HOS_MODS_PRESS_RIGHT}, {B_A, HOS_MODS_PRESS_A}, {B_B, HOS_MODS_PRESS_B},
|
||||
{B_L, HOS_MODS_PRESS_L}, {B_R, HOS_MODS_PRESS_R}};
|
||||
const uint64_t fresh = buttons & ~prev;
|
||||
int bits = 0;
|
||||
for (int i = 0; i < (int)(sizeof map / sizeof *map); i++)
|
||||
if (fresh >> map[i].bit & 1) bits |= map[i].press;
|
||||
{ /* ((Triforce) 11-17) and the left stick pushed past half its travel, as the D-pad */
|
||||
static int stick_was;
|
||||
const int dir = stick[1] > 16384 ? HOS_MODS_PRESS_UP : stick[1] < -16384 ? HOS_MODS_PRESS_DOWN
|
||||
: stick[0] < -16384 ? HOS_MODS_PRESS_LEFT : stick[0] > 16384 ? HOS_MODS_PRESS_RIGHT : 0;
|
||||
if (dir && dir != stick_was) bits |= dir;
|
||||
stick_was = dir;
|
||||
}
|
||||
if (bits) rx_option_set(HOS_OPT_MODS_PRESS, bits);
|
||||
prev = buttons;
|
||||
buttons = 0;
|
||||
memset(stick, 0, 4 * sizeof *stick);
|
||||
} else {
|
||||
if (sel_was) held_over = prev, stick_over = 1;
|
||||
held_over &= buttons;
|
||||
buttons &= ~held_over;
|
||||
if (stick_over && stick[0] > -12000 && stick[0] < 12000 && stick[1] > -12000 && stick[1] < 12000) stick_over = 0;
|
||||
if (stick_over) stick[0] = stick[1] = 0;
|
||||
prev = 0;
|
||||
}
|
||||
sel_was = sel;
|
||||
}
|
||||
mods_input(&buttons, stick); /* (Triforce) the Mods entry's: below */
|
||||
{ /* (Triforce) the sprint button's press is its own while Link plays (host/oot_sprint.c) */
|
||||
void hos_oot_sprint_pad(uint64_t *buttons);
|
||||
hos_oot_sprint_pad(&buttons);
|
||||
|
||||
@@ -343,8 +343,17 @@ NV(nvnMemoryPoolFinalize) {
|
||||
}
|
||||
InterlockedIncrement(&vmap_gen);
|
||||
ReleaseSRWLockExclusive(&vmap_lock);
|
||||
} else if (o->mem) {
|
||||
} else if (o->mem && o->magic == NVN_MAGIC('P', 'O', 'O', 'L')) {
|
||||
hos_gpu_track(o->gpu, o->size, 0);
|
||||
} else if (o->mem) {
|
||||
/* a pool object finalized again (its magic gone with the first Finalize): its range was untracked then, and untracking
|
||||
it again took the counted entry of a newer live pool made over the same memory since (the actor heap's small pools
|
||||
are made again at the same addresses): the renderer's capture would then take that live pool for heap memory
|
||||
(RX_VK_CAP_ONLY_GPU). Nothing to do but say so */
|
||||
static volatile LONG told;
|
||||
if (InterlockedIncrement(&told) <= 8)
|
||||
hos_log("nvn: memory pool %#llx+%#llx finalized again (lr %#llx): left alone", (unsigned long long)o->gpu,
|
||||
(unsigned long long)o->size, (unsigned long long)c->x[30]);
|
||||
}
|
||||
o->magic = 0;
|
||||
}
|
||||
@@ -1106,25 +1115,102 @@ static int sync_log(void) { /* (the first 30000 calls; HOS_NVN_SYNC_LOG=<n>: f
|
||||
fence): NVN starts a submission's work only then, and the game writes what it reads in between. Handed to the replay
|
||||
at the submit, a frame's draws read some of their constants before the game had written them: MKW's terrain tiles
|
||||
flashed as walls for a frame, we thought; measured, holding made them far more frequent (61 vs 0-9 in a 60 s drive):
|
||||
MKW writes some of a frame's data in place right after its submit, as the console's GPU has read it by then. Off by
|
||||
default; HOS_NVN_HOLD=1: held. */
|
||||
typedef struct { int n; uint64_t h[64]; } held_submit;
|
||||
MKW writes some of a frame's data in place right after its submit, as the console's GPU has read it by then.
|
||||
HOS_NVN_HOLD=1: every submit held. HOS_NVN_HOLD=2 (the default; =0: none held): only the submits of threads other than the
|
||||
presenting one, replayed ~20 us later by a host thread (below). */
|
||||
typedef struct { int n; uint64_t h[64]; uint64_t queue; int64_t t; } held_submit;
|
||||
static held_submit held[256];
|
||||
static volatile LONG nheld;
|
||||
static CRITICAL_SECTION held_cs;
|
||||
static CRITICAL_SECTION held_cs, flush_cs; /* (held_cs: the list; flush_cs: a flush and the presenting thread's submit, in order) */
|
||||
static int held_ready, hold_on = -1;
|
||||
static void held_init(void) {
|
||||
if (!held_ready) { InitializeCriticalSection(&held_cs); held_ready = 1; }
|
||||
if (hold_on < 0) { const char *e = getenv("HOS_NVN_HOLD"); hold_on = e && atoi(e) != 0; } /* (off: see below) */
|
||||
/* HOS_NVN_HOLD=2: the submits of threads other than the presenting one (OoT's main thread: two a frame) are held, and a host
|
||||
thread replays them at once, or the presenting thread before its own next submit or its present, or whoever waits for them
|
||||
first (a fence wait, a finish, an event poll). The submit-time capture, the replay of those command buffers and their queue
|
||||
submits leave the main thread's critical path for a thread of their own: the game's main thread was idle in its submit calls
|
||||
for the whole capture and replay (3.4-4.8 ms a frame at the Market measured 11-17, while the Presentation Thread waited for
|
||||
it). The capture is taken at the flush, ~20 us to ~1 ms after the game's submit: elsewhere measured, ~0.14% of the captured
|
||||
pages were written again in between. A held submit's capture copies every page before its replay begins (no copies behind:
|
||||
the game is already running, rx_nvn_submit_held) */
|
||||
static HosThread *present_thread;
|
||||
static HANDLE hold_event;
|
||||
static int64_t st_hold_flushes, st_hold_submits, st_hold_wait_ns, st_hold_replay_ns, st_hold_by[8];
|
||||
enum { HF_FLUSH, HF_FINISH, HF_PRESENT, HF_SYNC, HF_EVENT, HF_SUBMIT, HF_THREAD, HF_OTHER, HF_N };
|
||||
static void held_flush_why(int why);
|
||||
/* the held submits' replay thread: woken at each hold. A host thread: no virtual core, no guest code (the replay runs none) */
|
||||
static DWORD WINAPI hold_flush_thread(void *p) {
|
||||
(void)p;
|
||||
SetThreadDescription(GetCurrentThread(), L"mkw_vk held submits"); /* (named as the renderer's threads: HOS_SAMPLE_ALL samples it) */
|
||||
for (;;) {
|
||||
WaitForSingleObject(hold_event, INFINITE);
|
||||
held_flush_why(HF_THREAD);
|
||||
}
|
||||
}
|
||||
static void held_flush(void) {
|
||||
static void held_init(void) {
|
||||
if (!held_ready) { InitializeCriticalSection(&held_cs); InitializeCriticalSection(&flush_cs); held_ready = 1; }
|
||||
if (hold_on < 0) {
|
||||
const char *e = getenv("HOS_NVN_HOLD");
|
||||
hold_on = e ? atoi(e) : 2;
|
||||
/* ((Triforce) with the replay on a thread of its own (RX_VK_ASYNC=1, gpu/vk/async_rules.h) every submit is already a
|
||||
capture and a hand-over: no submit is held as well, unless HOS_NVN_HOLD is set) */
|
||||
if (!e && rx_async_replay()) {
|
||||
hold_on = 0;
|
||||
hos_log("nvn: no submits held: the replay has a thread of its own (RX_VK_ASYNC=1; HOS_NVN_HOLD=2 to hold them too)");
|
||||
}
|
||||
if (hold_on) hos_log("nvn: submits held (HOS_NVN_HOLD=%d: %s)", hold_on,
|
||||
hold_on == 2 ? "other threads' submits, replayed by a host thread" : "all, until a flush");
|
||||
if (hold_on == 2) {
|
||||
hold_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
||||
HANDLE h = CreateThread(NULL, 0, hold_flush_thread, NULL, 0, NULL);
|
||||
if (h) CloseHandle(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
void rx_nvn_submit_held(int on); /* (rx_backend.c: the renderer's capture copies every page before the replay) */
|
||||
/* the held submits replayed now, on this thread, in their order: under flush_cs, so that no submit of the presenting thread
|
||||
comes between them (held_cs is let go before the replay: the replay reads the recordings under copy_lock). The virtual core
|
||||
is given up before flush_cs is taken and taken back after it is let go: flush_cs is held through a replay, up to hundreds of
|
||||
ms while a zone loads, and a thread that waits for a core while it holds flush_cs, or holds a core while it waits for it,
|
||||
stalls the threads on the other side until the 250 ms escape (the Presentation Thread at area loads). Nothing under flush_cs
|
||||
runs guest code */
|
||||
static void held_flush_why(int why) {
|
||||
held_init();
|
||||
if (!nheld) return;
|
||||
const int away = hos_vcore_away();
|
||||
EnterCriticalSection(&flush_cs);
|
||||
static held_submit local[256];
|
||||
LONG n;
|
||||
EnterCriticalSection(&held_cs);
|
||||
for (LONG i = 0; i < nheld; i++) rx_nvn_submit(held[i].h, held[i].n);
|
||||
n = nheld;
|
||||
memcpy(local, held, sizeof *held * (size_t)n);
|
||||
nheld = 0;
|
||||
LeaveCriticalSection(&held_cs);
|
||||
if (n) {
|
||||
const int64_t t0 = hos_now_ns();
|
||||
for (LONG i = 0; i < n; i++) {
|
||||
if (hold_on == 2) {
|
||||
rx_nvn_submit_held(1);
|
||||
rx_nvn_submit_q(local[i].h, local[i].n, local[i].queue);
|
||||
rx_nvn_submit_held(0);
|
||||
} else {
|
||||
rx_nvn_submit(local[i].h, local[i].n);
|
||||
}
|
||||
st_hold_wait_ns += t0 - local[i].t;
|
||||
}
|
||||
st_hold_replay_ns += hos_now_ns() - t0;
|
||||
st_hold_submits += n, st_hold_by[why < HF_N ? why : HF_OTHER]++;
|
||||
if (++st_hold_flushes % 600 == 0)
|
||||
hos_log("nvn: held submits: %lld flushes (by: queue flush %lld, finish %lld, present %lld, sync wait %lld, event poll %lld, "
|
||||
"the presenting thread's submit %lld, the held submits' thread %lld, other %lld), %lld submits, held %.3f ms each, "
|
||||
"replayed in %.2f ms a flush",
|
||||
(long long)st_hold_flushes, (long long)st_hold_by[0], (long long)st_hold_by[1], (long long)st_hold_by[2],
|
||||
(long long)st_hold_by[3], (long long)st_hold_by[4], (long long)st_hold_by[5], (long long)st_hold_by[6],
|
||||
(long long)st_hold_by[7], (long long)st_hold_submits, st_hold_wait_ns / 1e6 / (double)st_hold_submits,
|
||||
st_hold_replay_ns / 1e6 / (double)st_hold_flushes);
|
||||
}
|
||||
LeaveCriticalSection(&flush_cs);
|
||||
if (away) hos_vcore_back();
|
||||
}
|
||||
static void held_flush(void) { held_flush_why(HF_OTHER); }
|
||||
static uint64_t held_count(void) { return (uint64_t)nheld; }
|
||||
|
||||
NV(nvnQueueFenceSync) {
|
||||
@@ -1201,6 +1287,7 @@ NV(nvnEventGetValue) {
|
||||
if (nowait && (c->x[30] == 0x805904a0 || c->x[30] == 0x80590530)) { RET(1); return; }
|
||||
}
|
||||
const uint64_t ev_gpu = ((const nvn_event *)P(0))->gpu; /* (before RET: it writes x0) */
|
||||
if (hold_on == 2 && nheld) held_flush_why(HF_EVENT); /* (HOS_NVN_HOLD=2: a held submit may be what signals it) */
|
||||
uint32_t v = 0; nvn_gpu_read(ev_gpu, &v, 4); RET(v);
|
||||
if (sync_log()) hos_log("nvn: EventGetValue %#llx = %u (lr %#llx)", (unsigned long long)ev_gpu, v, (unsigned long long)c->x[30]);
|
||||
if (hos_ft_on()) hos_log("ft %.3f eventget %#llx = %u (lr %#llx)", hos_ft_ms(), (unsigned long long)ev_gpu, v, (unsigned long long)c->x[30]);
|
||||
@@ -1242,9 +1329,9 @@ NV(nvnQueueBuilderSetQueueMemory) { QB(P(0))->mem = U64(1); QB(P(0))->mem_sz = U
|
||||
NV(nvnQueueInitialize) { nvn_queue *q = (nvn_queue *)P(0); q->magic = NVN_MAGIC('Q', 'U', 'E', 'U'); q->submits = 0; RET(1); }
|
||||
NV(nvnQueueFinalize) { ((nvn_queue *)P(0))->magic = 0; }
|
||||
NV(nvnQueueGetError) { if (P(1)) memset(P(1), 0, sizeof(NVNqueueErrorInfo)); RET(NVN_QUEUE_GET_ERROR_RESULT_GPU_NO_ERROR); }
|
||||
NV(nvnQueueFlush) { held_flush(); }
|
||||
NV(nvnQueueFlush) { if (hold_on != 2) held_flush_why(HF_FLUSH); } /* (HOS_NVN_HOLD=2: the held submits' thread is on it) */
|
||||
NV(nvnQueueFinish) {
|
||||
held_flush();
|
||||
held_flush_why(HF_FINISH);
|
||||
const int away = hos_vcore_away();
|
||||
const int64_t t0 = hos_now_ns();
|
||||
rx_nvn_finish();
|
||||
@@ -1464,24 +1551,44 @@ static size_t ndead, cap_dead;
|
||||
address, so it is used only when it is in the set, never on what the memory at that address holds. */
|
||||
static uint64_t *live_handles;
|
||||
static size_t live_cap, nlive;
|
||||
/* (hookshot) The set as check_handle reads it without copy_lock (live_handle_seen): the table and its size, published together
|
||||
at each growth. A table is never freed, since a reader may still be in an older one; growth doubles it, so the old ones take
|
||||
at most as much again. The slots are written with atomic stores, so a reader sees each slot whole */
|
||||
typedef struct { uint64_t *slots; size_t cap; } live_table;
|
||||
static live_table *live_pub;
|
||||
static size_t live_at(uint64_t h, size_t cap) { return (size_t)((h * 0x9E3779B97F4A7C15ull) >> 24) & (cap - 1); }
|
||||
static void live_handle_add(uint64_t h) { /* (copy_lock held exclusively) */
|
||||
if ((nlive + 1) * 2 > live_cap) {
|
||||
const size_t cap = live_cap ? live_cap * 2 : 65536;
|
||||
uint64_t *t = (uint64_t *)calloc(cap, sizeof *t);
|
||||
if (!t) die("recording handle set");
|
||||
live_table *pub = (live_table *)malloc(sizeof *pub);
|
||||
if (!t || !pub) die("recording handle set");
|
||||
for (size_t i = 0; i < live_cap; i++) {
|
||||
if (!live_handles[i]) continue;
|
||||
size_t k = live_at(live_handles[i], cap);
|
||||
while (t[k]) k = (k + 1) & (cap - 1);
|
||||
t[k] = live_handles[i];
|
||||
}
|
||||
free(live_handles);
|
||||
live_handles = t, live_cap = cap;
|
||||
live_handles = t, live_cap = cap; /* (the old table stays: live_pub) */
|
||||
pub->slots = t, pub->cap = cap;
|
||||
__atomic_store_n(&live_pub, pub, __ATOMIC_RELEASE);
|
||||
}
|
||||
size_t k = live_at(h, live_cap);
|
||||
while (live_handles[k] && live_handles[k] != h) k = (k + 1) & (live_cap - 1);
|
||||
if (!live_handles[k]) live_handles[k] = h, nlive++;
|
||||
if (!live_handles[k]) __atomic_store_n(&live_handles[k], h, __ATOMIC_RELEASE), nlive++;
|
||||
}
|
||||
/* Whether h is in the set, without copy_lock: a hit is a handle EndRecording added (the game got it from that call, so its
|
||||
store is seen), a miss is not final. A removal running beside the probe can move an entry back past it (live_handle_remove's
|
||||
backward shift), so check_handle asks a miss again under the lock. The probe ends at an empty slot or after the whole table */
|
||||
static int live_handle_seen(uint64_t h) {
|
||||
const live_table *t = __atomic_load_n(&live_pub, __ATOMIC_ACQUIRE);
|
||||
if (!h || !t) return 0;
|
||||
for (size_t k = live_at(h, t->cap), n = 0; n < t->cap; k = (k + 1) & (t->cap - 1), n++) {
|
||||
const uint64_t v = __atomic_load_n(&t->slots[k], __ATOMIC_ACQUIRE);
|
||||
if (v == h) return 1;
|
||||
if (!v) return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int live_handle_has(uint64_t h) { /* (copy_lock held) */
|
||||
if (!h || !live_cap) return 0;
|
||||
@@ -1494,27 +1601,47 @@ static void live_handle_remove(uint64_t h) { /* (copy_lock held exclusively; b
|
||||
size_t k = live_at(h, live_cap);
|
||||
while (live_handles[k] && live_handles[k] != h) k = (k + 1) & (live_cap - 1);
|
||||
if (!live_handles[k]) return;
|
||||
live_handles[k] = 0, nlive--;
|
||||
__atomic_store_n(&live_handles[k], 0, __ATOMIC_RELEASE), nlive--;
|
||||
for (size_t j = (k + 1) & (live_cap - 1); live_handles[j]; j = (j + 1) & (live_cap - 1)) {
|
||||
const size_t want = live_at(live_handles[j], live_cap);
|
||||
/* (move it into the hole when its probe run starts at or before the hole) */
|
||||
/* (move it into the hole when its probe run starts at or before the hole: into the hole first, then out of its slot, so a
|
||||
reader without the lock sees it twice for a moment rather than not at all where it stops) */
|
||||
if (((j - want) & (live_cap - 1)) >= ((j - k) & (live_cap - 1))) {
|
||||
live_handles[k] = live_handles[j], live_handles[j] = 0;
|
||||
__atomic_store_n(&live_handles[k], live_handles[j], __ATOMIC_RELEASE);
|
||||
__atomic_store_n(&live_handles[j], 0, __ATOMIC_RELEASE);
|
||||
k = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* (hookshot) The least `after` of the dead copies (UINT64_MAX: none): every AddControlMemory went through all of them under the
|
||||
exclusive lock, though none could go before the replay passed that one */
|
||||
static uint64_t dead_first = UINT64_MAX;
|
||||
static void free_dead_copies(void) { /* (copy_lock held) */
|
||||
const uint64_t done = rx_nvn_replayed();
|
||||
if (done < dead_first) return;
|
||||
uint64_t first = UINT64_MAX;
|
||||
for (size_t i = 0; i < ndead;) {
|
||||
if (dead[i].after <= done) {
|
||||
InterlockedAdd64(©_bytes, -(LONG64)dead[i].p->bytes);
|
||||
pool_put(dead[i].p, (unsigned)dead[i].p->cls);
|
||||
dead[i] = dead[--ndead];
|
||||
} else {
|
||||
if (dead[i].after < first) first = dead[i].after;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
dead_first = first;
|
||||
}
|
||||
static void dead_copy_add(copy_prefix *p, uint64_t after) { /* (copy_lock held) */
|
||||
if (ndead == cap_dead) {
|
||||
cap_dead = cap_dead ? cap_dead * 2 : 1024;
|
||||
dead = (dead_copy *)realloc(dead, cap_dead * sizeof *dead);
|
||||
if (!dead) die("recording copies let go");
|
||||
}
|
||||
dead[ndead].p = p;
|
||||
dead[ndead].after = after;
|
||||
ndead++;
|
||||
if (after < dead_first) dead_first = after;
|
||||
}
|
||||
static void release_copies(uint64_t lo, uint64_t hi) {
|
||||
if (hi <= lo || !rec_buckets) return;
|
||||
@@ -1535,13 +1662,7 @@ static void release_copies(uint64_t lo, uint64_t hi) {
|
||||
copy_prefix *p = (copy_prefix *)n->copy - 1;
|
||||
p->magic = 0; /* (no submit names it any more) */
|
||||
live_handle_remove((uint64_t)(uintptr_t)n->copy);
|
||||
if (ndead == cap_dead) {
|
||||
cap_dead = cap_dead ? cap_dead * 2 : 1024;
|
||||
dead = (dead_copy *)realloc(dead, cap_dead * sizeof *dead);
|
||||
}
|
||||
dead[ndead].p = p;
|
||||
dead[ndead].after = after;
|
||||
ndead++;
|
||||
dead_copy_add(p, after);
|
||||
*pn = n->next;
|
||||
free(n);
|
||||
ncopies--;
|
||||
@@ -1555,6 +1676,12 @@ static void release_copies(uint64_t lo, uint64_t hi) {
|
||||
control memory was never added again (MKW frees and reallocates its control memory) were kept for good otherwise:
|
||||
~40 per 1000 recordings, ~100,000 after 20 minutes. Swept every 25,000 recordings. HOS_NVN_NO_SWEEP=1: not. */
|
||||
#define COPY_MARK 0x4b52414d59504f43ull /* "COPYMARK" */
|
||||
/* (hookshot) A slice of the buckets at a time: SWEEP_SLICE of them every SWEEP_EVERY recordings, every bucket once in
|
||||
REC_BUCKETS / SWEEP_SLICE * SWEEP_EVERY (~25,000) recordings, as the whole sweep every 25,000 was. That one read every live
|
||||
copy's mark (~68,000 in the Market, scattered in guest memory) with copy_lock held exclusively, and every thread recording
|
||||
or calling a recording waited behind it */
|
||||
#define SWEEP_EVERY 1024u
|
||||
#define SWEEP_SLICE 2688u /* (65536 / 2688 * 1024: every bucket once in ~25,000 recordings) */
|
||||
static void sweep_overwritten_copies(void) { /* (copy_lock held) */
|
||||
static int off = -1;
|
||||
if (off < 0) off = getenv("HOS_NVN_NO_SWEEP") != NULL;
|
||||
@@ -1562,7 +1689,11 @@ static void sweep_overwritten_copies(void) { /* (copy_lock held) */
|
||||
free_dead_copies();
|
||||
const uint64_t after = rx_nvn_pushed() + held_count();
|
||||
size_t swept = 0;
|
||||
for (unsigned b = 0; b < REC_BUCKETS; b++) {
|
||||
static unsigned next_slice; /* (the next slice's first bucket) */
|
||||
const unsigned from = next_slice;
|
||||
next_slice = (next_slice + SWEEP_SLICE) % REC_BUCKETS;
|
||||
for (unsigned s = 0; s < SWEEP_SLICE; s++) {
|
||||
const unsigned b = (from + s) % REC_BUCKETS;
|
||||
for (rec_node **pn = &rec_buckets[b]; *pn;) {
|
||||
rec_node *n = *pn;
|
||||
uint64_t mark[2];
|
||||
@@ -1583,13 +1714,7 @@ static void sweep_overwritten_copies(void) { /* (copy_lock held) */
|
||||
copy_prefix *pre = (copy_prefix *)n->copy - 1;
|
||||
pre->magic = 0;
|
||||
live_handle_remove((uint64_t)(uintptr_t)n->copy);
|
||||
if (ndead == cap_dead) {
|
||||
cap_dead = cap_dead ? cap_dead * 2 : 1024;
|
||||
dead = (dead_copy *)realloc(dead, cap_dead * sizeof *dead);
|
||||
}
|
||||
dead[ndead].p = pre;
|
||||
dead[ndead].after = after;
|
||||
ndead++;
|
||||
dead_copy_add(pre, after);
|
||||
*pn = n->next;
|
||||
free(n);
|
||||
ncopies--;
|
||||
@@ -1690,7 +1815,7 @@ NV(nvnCommandBufferEndRecording) {
|
||||
ncopies++;
|
||||
live_handle_add((uint64_t)(uintptr_t)copy);
|
||||
static uint64_t made;
|
||||
if (++made % 25000 == 0) sweep_overwritten_copies();
|
||||
if (++made % SWEEP_EVERY == 0) sweep_overwritten_copies();
|
||||
if (made % 50000 == 0)
|
||||
hos_log("nvn: %llu recordings made, %zu live copies (%.1f MB), %zu texture copies; %lld command buffers' segments "
|
||||
"(%.1f MB)", (unsigned long long)made, ncopies, copy_bytes / 1048576.0, npins, (long long)seg_count,
|
||||
@@ -1704,10 +1829,18 @@ NV(nvnCommandBufferEndRecording) {
|
||||
RET((uint64_t)(uintptr_t)copy);
|
||||
}
|
||||
NV(nvnCommandBufferIsRecording) { RET(CB(P(0))->recording != 0); }
|
||||
/* (hookshot) Without copy_lock first: every CallCommands handle took it shared, and while a recording thread held it or waited
|
||||
for it (EndRecording, AddControlMemory) the callers slept on it, about 5% of the time of the job workers on the frame's path in
|
||||
the Market (RTX 3090, 7900X, Linux: the SRW lock is a pthread rwlock). A miss is asked again under the lock, as before. A hit
|
||||
beside a removal of the same handle (the game calling a recording whose control memory it is adding again) reads the copy's
|
||||
magic, which the removal cleared first; the copy itself is freed only once the replay passes the submits made before it */
|
||||
static void check_handle(uint64_t h) {
|
||||
AcquireSRWLockShared(©_lock);
|
||||
const int live = live_handle_has(h);
|
||||
ReleaseSRWLockShared(©_lock);
|
||||
int live = live_handle_seen(h);
|
||||
if (!live) {
|
||||
AcquireSRWLockShared(©_lock);
|
||||
live = live_handle_has(h);
|
||||
ReleaseSRWLockShared(©_lock);
|
||||
}
|
||||
if (!live || ((const copy_prefix *)(uintptr_t)h - 1)->magic != COPY_MAGIC)
|
||||
die("command handle %#llx is not a live recording", (unsigned long long)h);
|
||||
}
|
||||
@@ -2397,12 +2530,20 @@ NV(nvnVertexStreamStateSetDivisor) { ST(nvn_vs_st, P(0))->divisor = U32(1); }
|
||||
|
||||
/* ---- submit ---- */
|
||||
/* deferred binds read the game's handle arrays now (it fills them for the next frame as soon as the submit returns) */
|
||||
static void resolve_deferred(uint8_t *p) {
|
||||
/* (Triforce, gpu/vk/async_rules.h) waits, nwaits: with the replay on a thread of its own, the events this recording waits for
|
||||
(NOP_WAIT_EVENT) are added, for rx_nvn_submit_waits; *nwaits -1 once there are more than SUBMIT_WAITS_MAX (then nothing is
|
||||
told, and the back end takes the submission as one that may wait for any event). NULL: not looked for */
|
||||
#define SUBMIT_WAITS_MAX 16
|
||||
static void resolve_deferred(uint8_t *p, uint64_t *waits, int *nwaits) {
|
||||
for (;;) {
|
||||
nvn_op_hdr h;
|
||||
memcpy(&h, p, sizeof h);
|
||||
if (h.size < 8 || (h.size & 7) || h.op >= NOP_COUNT_) die("corrupt recording at submit (op %u size %u)", h.op, h.size);
|
||||
if (h.op == NOP_END) return;
|
||||
if (h.op == NOP_WAIT_EVENT && waits && *nwaits >= 0) {
|
||||
if (*nwaits == SUBMIT_WAITS_MAX) *nwaits = -1;
|
||||
else waits[(*nwaits)++] = ((const nvn_p_wait_event *)(p + 8))->gpu;
|
||||
}
|
||||
if (h.op == NOP_BIND_TEX || h.op == NOP_BIND_IMG || h.op == NOP_BIND_SAMP) {
|
||||
nvn_p_bind_handles *b = (nvn_p_bind_handles *)(p + 8);
|
||||
if (b->src && b->n > 0 && b->n <= 32) memcpy(b->h, gw(b->src, 8 * (size_t)b->n), 8 * (size_t)b->n);
|
||||
@@ -2429,32 +2570,55 @@ NV(nvnQueueSubmitCommands) {
|
||||
hos_log("nvn: QueueSubmitCommands #%ld: queue %p (its #%llu), %d handles (lr %#llx)", (long)i, (void *)q,
|
||||
(unsigned long long)q->submits, n, (unsigned long long)c->x[30]);
|
||||
}
|
||||
/* (Triforce, gpu/vk/async_rules.h) the replay on a thread of its own (RX_VK_ASYNC=1): the events this submit's recordings
|
||||
wait for, told to the back end before the hand-over (resolve_deferred, rx_nvn_submit_waits) */
|
||||
const int async = rx_async_replay();
|
||||
uint64_t waits[SUBMIT_WAITS_MAX];
|
||||
int nwaits = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
check_handle(h[i]);
|
||||
resolve_deferred((uint8_t *)(uintptr_t)h[i]);
|
||||
resolve_deferred((uint8_t *)(uintptr_t)h[i], async ? waits : NULL, &nwaits);
|
||||
}
|
||||
held_init();
|
||||
if (!hold_on) {
|
||||
const int mine = hold_on == 2 && (!present_thread || hos_self() == present_thread); /* (HOS_NVN_HOLD=2: the presenting thread's own) */
|
||||
if (!hold_on || mine) {
|
||||
/* (the replay runs here, on this thread, for ~9 ms a frame (vk_replay.cpp submit_q, RX_VK_ASYNC off): the virtual
|
||||
core is given up for it, as Present and AcquireTexture do, so the game's other threads run on it meanwhile.
|
||||
Nothing in the replay runs guest code or needs the core) */
|
||||
const int away = hos_vcore_away();
|
||||
Nothing in the replay runs guest code or needs the core. Given up before flush_cs is taken and taken back after it
|
||||
is let go, as held_flush_why does) */
|
||||
/* (Triforce, gpu/vk/async_rules.h 3) with the replay on its own thread this call is a capture and a hand-over, a
|
||||
quarter millisecond: the core is kept, as the console's submit keeps it; giving it up meant taking it again while
|
||||
the update's workers hold all of them. HOS_ASYNC_KEEP_CORE=0: given up, as before */
|
||||
static int keep_core = -1;
|
||||
if (keep_core < 0) {
|
||||
const char *e = getenv("HOS_ASYNC_KEEP_CORE");
|
||||
keep_core = async && !(e && atoi(e) == 0);
|
||||
if (async)
|
||||
hos_log("nvn: the replay on a thread of its own (RX_VK_ASYNC=1): a submit %s its virtual core for the hand-over "
|
||||
"(HOS_ASYNC_KEEP_CORE), and tells the events its recordings wait for", keep_core ? "keeps" : "gives up");
|
||||
}
|
||||
const int away = keep_core ? 0 : hos_vcore_away();
|
||||
if (mine) EnterCriticalSection(&flush_cs); /* (the held ones first, and nothing between them and this one) */
|
||||
if (mine && nheld) held_flush_why(HF_SUBMIT); /* (flush_cs already held: a critical section is re-entrant) */
|
||||
const int ft = hos_ft_on();
|
||||
if (ft) hos_log("ft %.3f submit> queue %p, %d handles (lr %#llx)", hos_ft_ms(), (void *)q, n, (unsigned long long)c->x[30]);
|
||||
if (async && nwaits >= 0) rx_nvn_submit_waits(waits, nwaits);
|
||||
rx_nvn_submit_q(h, n, (uint64_t)(uintptr_t)q);
|
||||
if (ft) hos_log("ft %.3f submit< queue %p", hos_ft_ms(), (void *)q);
|
||||
if (mine) LeaveCriticalSection(&flush_cs);
|
||||
if (away) hos_vcore_back();
|
||||
return;
|
||||
}
|
||||
if (nheld >= (LONG)(sizeof held / sizeof *held) - 1) held_flush_why(HF_OTHER); /* (full: what is held goes now) */
|
||||
EnterCriticalSection(&held_cs);
|
||||
if (nheld == (LONG)(sizeof held / sizeof *held)) { /* (full: what is held goes now) */
|
||||
for (LONG i = 0; i < nheld; i++) rx_nvn_submit(held[i].h, held[i].n);
|
||||
nheld = 0;
|
||||
}
|
||||
held[nheld].n = n;
|
||||
memcpy(held[nheld].h, h, 8 * (size_t)n);
|
||||
held_submit *hs = &held[nheld];
|
||||
hs->n = n;
|
||||
memcpy(hs->h, h, 8 * (size_t)n);
|
||||
hs->queue = (uint64_t)(uintptr_t)q;
|
||||
hs->t = hos_now_ns();
|
||||
nheld++;
|
||||
LeaveCriticalSection(&held_cs);
|
||||
if (hold_event) SetEvent(hold_event);
|
||||
}
|
||||
|
||||
/* ---- window ---- */
|
||||
@@ -2556,7 +2720,8 @@ NV(nvnQueuePresentTexture) {
|
||||
nvn_win *o = (nvn_win *)P(1);
|
||||
const int i = I(2);
|
||||
if (i < 0 || i >= o->ntex) die("present of window texture %d", i);
|
||||
held_flush(); /* (a present flushes the queue) */
|
||||
present_thread = hos_self(); /* (HOS_NVN_HOLD=2: the presenting thread, whose submits are not held) */
|
||||
held_flush_why(HF_PRESENT); /* (a present flushes the queue) */
|
||||
{
|
||||
const int away = hos_vcore_away();
|
||||
const int ft = hos_ft_on();
|
||||
|
||||
@@ -19,8 +19,14 @@
|
||||
Options is chosen, from the title and from the pause menu alike, and stops with Back; L and R do nothing on it). While
|
||||
it runs the renderer is told each frame (rx_option_set HOS_OPT_GAME_OPTIONS): the menu draws its tabs over this
|
||||
screen's header, the game's own list the first of them (gpu/vk/vk_menu.cpp), and nn_hid.c passes Back on when one of
|
||||
our tabs is left with it. HOS_OPTIONS_TABS=0 keeps the renderer untold */
|
||||
our tabs is left with it. HOS_OPTIONS_TABS=0 keeps the renderer untold.
|
||||
((Triforce, 11-20) Told as 2, not 1, when it was chosen from the pause menu: the pause menu's screen (its vtable,
|
||||
PAUSE_SCREEN_VTABLE) ran within half a second before this run of the Options screen began. One screen, but its footer's
|
||||
guides band may be another overlay's there (MenuOverlay_00's ends at 2110 units right of the middle, SystemOverlay_00's
|
||||
at 2160: the renderer's guides plate ends with it, game_grid.h guide_band_x1) */
|
||||
#define OPTIONS_SCREEN_VTABLE 0x84c0f108ULL
|
||||
#define PAUSE_SCREEN_VTABLE 0x84c0baa8ULL
|
||||
#define OPTIONS_FROM_PAUSE_NS 500000000LL /* (the pause menu's last update, at most this long before the Options' first) */
|
||||
void rx_option_set(int id, int value); /* rx_backend.c */
|
||||
#if defined(_WIN32) && !defined(HOS_OOT_MENU_NO_MOUSE) /* (the macro: tests/test_oot_menu_mouse.py builds the other half on Windows) */
|
||||
#include <windows.h>
|
||||
@@ -400,6 +406,7 @@ static SRWLOCK mouse_lock = SRWLOCK_INIT;
|
||||
static void mouse_tick_locked(Ctx *c, uint64_t screen);
|
||||
static int mods_entry_hit(float x, float y); /* ((Triforce) below: the Mods entry under a list's last button) */
|
||||
static int quit_entry_hit(float x, float y); /* ((Triforce, 11-19) and Quit under it, the System page's only */
|
||||
int rx_option(int id, int otherwise); /* rx_backend.c */
|
||||
/* (mouse_owner: the thread in mouse_tick: the game's focus handler may run inside its setter) */
|
||||
static void mouse_tick(Ctx *c, uint64_t screen) {
|
||||
if (!TryAcquireSRWLockExclusive(&mouse_lock)) return;
|
||||
@@ -606,6 +613,16 @@ static void mouse_tick_locked(Ctx *c, uint64_t screen) {
|
||||
if (options_screen(screen) && options_tabs_on() && hit.y >= OPT_HEADER_Y) moved = 0, pressed &= ~(uint32_t)HOS_MOUSE_LEFT;
|
||||
if (moved || (pressed & HOS_MOUSE_LEFT)) hit_test(screen, &hit);
|
||||
else hit.hit = 0;
|
||||
/* ((Triforce, 11-19) the Mods entry under the mouse as the game's own entries are, the owner: "make it the same as the other
|
||||
options": the mouse moved onto it takes the cursor (the renderer's word 1, as the pad's Down, with its sound); on the
|
||||
System page Quit under it as well (4: Quit has the cursor), as the game's buttons above take it on hover. Off them
|
||||
again the mouse is the renderer's (the menu is open while they have the cursor): vk_menu.cpp gives the cursor back
|
||||
when it moves up onto the game's list */
|
||||
if (moved && !hit.hit && !rx_option(HOS_OPT_MODS_SELECTED, 0)) {
|
||||
const int onto = mods_entry_hit(hit.x, hit.y) ? 1 : quit_entry_hit(hit.x, hit.y) ? 4 : 0;
|
||||
if (onto) rx_option_set(HOS_OPT_MODS_ENTER, onto);
|
||||
if (onto && trace) hos_log("menu: mouse (%.0f, %.0f): onto the %s entry", hit.x, hit.y, onto == 1 ? "Mods" : "Quit");
|
||||
}
|
||||
/* hover: the focus to the button under the mouse, only as it moves (the pad keeps the focus it moved) */
|
||||
int just = 0;
|
||||
uint8_t state = 0;
|
||||
@@ -828,6 +845,8 @@ static int button_rect(uint64_t button, Rect *r) {
|
||||
takes the cursor onto Mods. A click on the entry opens it (mouse_tick_locked) */
|
||||
#define TITLE_LIST_VTABLE 0x84c106e8ULL
|
||||
static volatile LONG64 mods_last_ns; /* (the last frame a list's last button had the game's cursor) */
|
||||
static volatile LONG64 mods_last_present; /* ((Triforce, 11-19) ...and the game's presents then: hos_oot_mods_down) */
|
||||
extern volatile LONG64 hos_present_count; /* (display.c: the game's own presents) */
|
||||
static Rect mods_entry; /* (the entry's box, as the renderer draws it: under the last button by the pitch) */
|
||||
static Rect quit_entry; /* ((Triforce, 11-19) Quit's, under Mods by the pitch; empty on the title's list */
|
||||
static volatile LONG64 mods_entry_ns;
|
||||
@@ -875,7 +894,6 @@ static uint64_t mods_cursor_button(uint64_t screen, int *pending) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#define PAUSE_SCREEN_VTABLE 0x84c0baa8ULL
|
||||
static void mods_call(Ctx *c, const ModsCall *m) {
|
||||
const uint64_t b = m->button;
|
||||
if (!m->op || !b || !mods_button_vt(peek64(b))) return;
|
||||
@@ -924,17 +942,21 @@ static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {
|
||||
{
|
||||
const int sel = rx_option(HOS_OPT_MODS_SELECTED, 0) != 0;
|
||||
int pending = 0;
|
||||
const uint64_t cur = mods_cursor_button(screen, &pending), btn = l.b[last];
|
||||
if (mods_held.button && (mods_held.screen != screen || mods_held.button != btn)) memset(&mods_held, 0, sizeof mods_held);
|
||||
if (sel && !mods_held.button && (state == 1 || state == 3) && cur == btn && !pending) {
|
||||
*call = (ModsCall){1, screen, btn, title};
|
||||
mods_held.screen = screen, mods_held.button = btn, mods_held.since_ns = 0;
|
||||
/* ((Triforce, 11-19) the button the game's cursor is on, whichever: the last one when the pad's Down came from it, but
|
||||
the mouse may come onto Mods (or click it) from any; that one is let go and given back */
|
||||
const uint64_t cur = mods_cursor_button(screen, &pending);
|
||||
uint8_t cur_state = 0;
|
||||
if (cur) peek(cur + 56, &cur_state, 1);
|
||||
if (mods_held.button && mods_held.screen != screen) memset(&mods_held, 0, sizeof mods_held);
|
||||
if (sel && !mods_held.button && cur && (cur_state == 1 || cur_state == 3) && !pending) {
|
||||
*call = (ModsCall){1, screen, cur, title};
|
||||
mods_held.screen = screen, mods_held.button = cur, mods_held.since_ns = 0;
|
||||
} else if (sel && mods_held.button) {
|
||||
mods_held.since_ns = 0;
|
||||
if ((state == 1 || state == 3) && cur == btn) *call = (ModsCall){1, screen, btn, title}; /* (lit again: again) */
|
||||
if ((cur_state == 1 || cur_state == 3) && cur == mods_held.button) *call = (ModsCall){1, screen, cur, title}; /* (lit again: again) */
|
||||
} else if (!sel && mods_held.button) {
|
||||
if (!mods_held.since_ns) mods_held.since_ns = now;
|
||||
if (cur == btn && !pending) *call = (ModsCall){2, screen, btn, title}, memset(&mods_held, 0, sizeof mods_held);
|
||||
if (cur == mods_held.button && !pending) *call = (ModsCall){2, screen, cur, title}, memset(&mods_held, 0, sizeof mods_held);
|
||||
else if (cur || now - mods_held.since_ns > 1000000000LL) memset(&mods_held, 0, sizeof mods_held); /* (moved on) */
|
||||
}
|
||||
}
|
||||
@@ -946,8 +968,16 @@ static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {
|
||||
}
|
||||
/* (coming or there; 2 is its focus going to another button. Let go for Mods, it is still the game's cursor's place) */
|
||||
const int focused = state == 1 || state == 3 || (mods_held.button && mods_held.button == l.b[last]);
|
||||
if (focused) InterlockedExchange64(&mods_last_ns, (LONG64)now);
|
||||
if (focused) {
|
||||
InterlockedExchange64(&mods_last_present, InterlockedCompareExchange64(&hos_present_count, 0, 0));
|
||||
InterlockedExchange64(&mods_last_ns, (LONG64)now);
|
||||
}
|
||||
mods_entry = (Rect){r.x0, r.y0 - pitch, r.x1, r.y1 - pitch};
|
||||
if (title) { /* ((Triforce, 11-19) the title's: its button a 60 x 60 mark, the line's middle: as list_boxes makes the game's
|
||||
boxes there (1100 wide, meeting the row above halfway), so the word itself is the entry's */
|
||||
const float mx = (r.x0 + r.x1) / 2, my = (r.y0 + r.y1) / 2 - pitch;
|
||||
mods_entry = (Rect){mx - 550, my - pitch / 2, mx + 550, my + pitch / 2};
|
||||
}
|
||||
quit_entry = title ? (Rect){0, 0, 0, 0} : (Rect){r.x0, r.y0 - 2 * pitch, r.x1, r.y1 - 2 * pitch};
|
||||
InterlockedExchange64(&mods_entry_ns, (LONG64)now);
|
||||
rx_option_set(HOS_OPT_MODS_X0, (int)r.x0), rx_option_set(HOS_OPT_MODS_X1, (int)r.x1);
|
||||
@@ -959,19 +989,28 @@ static void mods_list_tick(uint64_t screen, int title, ModsCall *call) {
|
||||
hos_log("menu: mods entry: %s list of %d, last button (%.0f, %.0f)-(%.0f, %.0f), pitch %.0f, focused %d", title ? "the title's" : "System's",
|
||||
l.n, r.x0, r.y0, r.x1, r.y1, pitch, focused);
|
||||
}
|
||||
/* nn_hid.c: the game's cursor is on a list's last button now (the frame before at most): its Down is the Mods entry's */
|
||||
/* nn_hid.c: the game's cursor is on a list's last button now (the frame before at most): its Down is the Mods entry's.
|
||||
((Triforce, 11-19) the lab's "one DOWN from Options on the title did nothing and logged nothing": with the game's window
|
||||
behind another one its frames came 80 to 235 ms apart, and 80 ms after the list's last frame the Down went to the game,
|
||||
which has nothing under its last button. The list's frame is the game's last one (or there has been none since) however
|
||||
long ago that was; within 80 ms as before) */
|
||||
int hos_oot_mods_down(void) {
|
||||
const LONG64 t = InterlockedCompareExchange64(&mods_last_ns, 0, 0);
|
||||
return t && (LONG64)hos_now_ns() - t < 80000000LL;
|
||||
if (!t) return 0;
|
||||
if ((LONG64)hos_now_ns() - t < 80000000LL) return 1;
|
||||
const LONG64 presents = InterlockedCompareExchange64(&hos_present_count, 0, 0) - InterlockedCompareExchange64(&mods_last_present, 0, 0);
|
||||
return presents >= 0 && presents <= 1;
|
||||
}
|
||||
static int quit_entry_hit(float x, float y) {
|
||||
const LONG64 t = InterlockedCompareExchange64(&mods_entry_ns, 0, 0);
|
||||
return t && (LONG64)hos_now_ns() - t < 100000000LL && quit_entry.x1 > quit_entry.x0 && x >= quit_entry.x0 && x <= quit_entry.x1 &&
|
||||
return t && (LONG64)hos_now_ns() - t < 1000000000LL && quit_entry.x1 > quit_entry.x0 && x >= quit_entry.x0 && x <= quit_entry.x1 &&
|
||||
y >= quit_entry.y0 && y <= quit_entry.y1;
|
||||
}
|
||||
static int mods_entry_hit(float x, float y) {
|
||||
const LONG64 t = InterlockedCompareExchange64(&mods_entry_ns, 0, 0);
|
||||
return t && (LONG64)hos_now_ns() - t < 100000000LL && x >= mods_entry.x0 && x <= mods_entry.x1 && y >= mods_entry.y0 && y <= mods_entry.y1;
|
||||
/* ((Triforce, 11-19) a second, not 100 ms: a click in a slow frame (a hitch at 20 fps) missed the entries; the renderer still
|
||||
takes it only while the game's list is fresh) */
|
||||
return t && (LONG64)hos_now_ns() - t < 1000000000LL && x >= mods_entry.x0 && x <= mods_entry.x1 && y >= mods_entry.y0 && y <= mods_entry.y1;
|
||||
}
|
||||
|
||||
/* ---- The screens f_802f1380 runs for (the HUD's, the menus', the title's: each frame each). The mouse is for the one
|
||||
@@ -1043,9 +1082,16 @@ void hos_oot_menu_tick(Ctx *c, uint64_t screen) {
|
||||
/* (Triforce: the game's Options screen runs: the renderer's tabs over its header. Its vtable as it is now, not me->vt:
|
||||
a screen's memory is another screen's later, the Load list ran at the Options' address in the traced run) */
|
||||
me->options = options_screen(screen);
|
||||
/* ((Triforce, 11-20) where this run of the Options screen was chosen from: the pause menu if its screen ran just before
|
||||
(kept for the run; a run begins after 200 ms with no Options frame, as hos_oot_options_front's) */
|
||||
static int64_t pause_ran_ns; /* (under seen_lock) */
|
||||
static int options_from_pause;
|
||||
if (peek64(screen) == PAUSE_SCREEN_VTABLE) pause_ran_ns = now;
|
||||
if (me->options) {
|
||||
const LONG64 was = InterlockedCompareExchange64(&options_seen_ns, 0, 0);
|
||||
if (!was || now - was >= 200000000LL) options_from_pause = pause_ran_ns && now - pause_ran_ns < OPTIONS_FROM_PAUSE_NS;
|
||||
InterlockedExchange64(&options_seen_ns, (LONG64)now);
|
||||
if (options_tabs_on()) rx_option_set(HOS_OPT_GAME_OPTIONS, 1);
|
||||
if (options_tabs_on()) rx_option_set(HOS_OPT_GAME_OPTIONS, options_from_pause ? 2 : 1);
|
||||
}
|
||||
/* ((Triforce) the Mods entry: the pause menu's System page, the title's list; its call into the game after the lock) */
|
||||
ModsCall mods_now = {0};
|
||||
@@ -1116,14 +1162,21 @@ void hos_oot_menu_tick(Ctx *c, uint64_t screen) {
|
||||
uint64_t vt = 0;
|
||||
if (screen < 0x100000 || screen >= HOS_GUEST_SPACE - 8) return;
|
||||
memcpy(&vt, GP(screen), 8);
|
||||
static int64_t pause_ran_ns; /* ((Triforce, 11-20) the pause menu's last update: where the Options were chosen from) */
|
||||
static int options_from_pause;
|
||||
const int64_t now = hos_now_ns();
|
||||
if (vt == PAUSE_SCREEN_VTABLE) __atomic_store_n(&pause_ran_ns, now, __ATOMIC_RELAXED);
|
||||
if (vt != OPTIONS_SCREEN_VTABLE) return;
|
||||
static int tabs = -1;
|
||||
if (tabs < 0) {
|
||||
const char *e = getenv("HOS_OPTIONS_TABS");
|
||||
tabs = !(e && *e == '0');
|
||||
}
|
||||
__atomic_store_n(&options_seen_ns, hos_now_ns(), __ATOMIC_RELAXED);
|
||||
if (tabs) rx_option_set(HOS_OPT_GAME_OPTIONS, 1);
|
||||
const int64_t was = __atomic_load_n(&options_seen_ns, __ATOMIC_RELAXED), paused = __atomic_load_n(&pause_ran_ns, __ATOMIC_RELAXED);
|
||||
if (!was || now - was >= 200000000LL) /* (a new run of the screen: from the pause menu if it ran just before) */
|
||||
__atomic_store_n(&options_from_pause, paused && now - paused < OPTIONS_FROM_PAUSE_NS, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&options_seen_ns, now, __ATOMIC_RELAXED);
|
||||
if (tabs) rx_option_set(HOS_OPT_GAME_OPTIONS, __atomic_load_n(&options_from_pause, __ATOMIC_RELAXED) ? 2 : 1);
|
||||
}
|
||||
int hos_oot_options_front(void) {
|
||||
const int64_t t = __atomic_load_n(&options_seen_ns, __ATOMIC_RELAXED);
|
||||
|
||||
80
host/oot_tex_compact.c
Normal file
80
host/oot_tex_compact.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* (Triforce, 11-19) The game's texture data compaction: counted, and for the lab its cycles held to a pace.
|
||||
|
||||
What it is. The game keeps its textures' data in a heap of its own and has a thread, "aglTextureDataMgr::Compaction", that
|
||||
moves a texture's data to another place in that heap when the free room is in pieces (its planner, f_807da590, weighs the
|
||||
largest free pieces against each other and the heap's size, and takes turns between the heap's two ends). A cycle is the
|
||||
plan, two copies of the data and an end, one step a message, about 18 frames; it moves one texture, some megabytes.
|
||||
|
||||
Why it matters here. Standing in a fresh Market the planner finds nothing to move. After a tour of ten areas it finds work
|
||||
at every ask (lab round 62: the thread idle in the fresh Market's sample, copying in the tour's), and each move is a
|
||||
texture at a new address to this renderer: its pages written by the CPU, so captured and compared at every submit, its
|
||||
storage looked up and hashed again at the draws. That is the "re-upload loop" of the lab's tours: 79 to 88 fps at the
|
||||
Market for 97, a 1% low of 54 to 61 for 75.
|
||||
|
||||
What is here. The thread's handler (f_807da3f0) calls the compaction's step (f_807da480) through hos_oot_tex_compact
|
||||
(nx2/oot_patches.py patch_tex_compact). The step runs as the game has it, and the cycles it starts are counted and logged
|
||||
every 10 s while there are any. With HOS_OOT_TEX_COMPACT_MS set, a cycle is started only that many milliseconds after the
|
||||
one before: an ask in between is answered as the planner answers when it finds nothing (0, the state left idle), and the
|
||||
game asks again. A cycle in flight is never held, and the step's other callers (the game's own waits for a compaction)
|
||||
are not touched. Nothing is held unless the switch is set: whether the game can do with fewer cycles (its heap is the
|
||||
one that fills, host/oot_heap_retry.c) is for the lab to say first.
|
||||
|
||||
HOS_OOT_TEX_COMPACT_MS=<n>: at most one cycle started every n ms. -1 (a test): none started at all. Unset or 0: as shipped. */
|
||||
#include "hos.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* (the supported build's) the compaction's record at the manager's +7992, its state at the record's +8: 3 idle (the next
|
||||
step plans), 0 to 2 a cycle's steps */
|
||||
enum { COMPACT = 7992, STATE = 8, IDLE = 3 };
|
||||
|
||||
static int pace_ms(void) {
|
||||
static int v = -2;
|
||||
if (v == -2) {
|
||||
const char *e = getenv("HOS_OOT_TEX_COMPACT_MS");
|
||||
v = e && *e ? atoi(e) : 0;
|
||||
if (v < -1) v = -1;
|
||||
if (v) hos_log("oot: texture compaction: %s (HOS_OOT_TEX_COMPACT_MS=%d)", v < 0 ? "no cycle is started" : "its cycles held to a pace", v);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
static int readable(uint64_t a) { return a >= 0x80000000ULL && a < (1ULL << 39) - 0x100; }
|
||||
|
||||
/* What an ask with the compaction idle does. now, next: the clock and the earliest start of the next cycle (ns); ms: the
|
||||
switch. 1: the game's step runs (it plans, and starts a cycle or finds nothing); 0: held, answered as nothing to move */
|
||||
int hos_oot_tex_compact_runs(int ms, int64_t now, int64_t next) {
|
||||
if (!ms) return 1;
|
||||
if (ms < 0) return 0;
|
||||
return now >= next;
|
||||
}
|
||||
|
||||
void hos_oot_tex_compact(Ctx *c, A64Fn game) {
|
||||
static int64_t next, said; /* (the game's compaction thread alone comes here) */
|
||||
static long started, held, steps;
|
||||
const uint64_t mgr = c->x[0];
|
||||
int idle = 0;
|
||||
if (readable(mgr)) {
|
||||
const uint64_t rec = recomp_load64(c, mgr + COMPACT);
|
||||
idle = readable(rec) && (uint8_t)recomp_load8(c, rec + STATE) == IDLE;
|
||||
}
|
||||
const int ms = pace_ms();
|
||||
const int64_t now = hos_now_ns();
|
||||
if (idle && !hos_oot_tex_compact_runs(ms, now, next)) {
|
||||
held++;
|
||||
c->x[0] = 0; /* (as the planner's "nothing to move": the handler takes the ask back, and the game asks again) */
|
||||
} else {
|
||||
game(c);
|
||||
steps += !idle;
|
||||
if (idle && (c->x[0] & 1)) {
|
||||
started++;
|
||||
if (ms > 0) next = now + (int64_t)ms * 1000000;
|
||||
}
|
||||
}
|
||||
if (!said) said = now;
|
||||
if (now - said >= 10000000000LL) {
|
||||
if (started || held || steps)
|
||||
hos_log("oot: texture compaction in %.0f s: %ld cycles started, %ld steps of them, %ld asks held (HOS_OOT_TEX_COMPACT_MS=%d)",
|
||||
(now - said) / 1e9, started, steps, held, ms);
|
||||
said = now, started = held = steps = 0;
|
||||
}
|
||||
}
|
||||
35
host/pad_kind.h
Normal file
35
host/pad_kind.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ((Triforce) 11-20, ticket "Controls not working properly") Which of SDL's game controllers are left out of the game's input:
|
||||
instruments and dance mats, which SDL lists as game controllers with a mapping of their own. A "(Guitar Hero )" guitar beside a
|
||||
Switch Pro controller fed its whammy and tilt into player 1 as held triggers: Link was always targeting, his shield came up by
|
||||
itself, the camera would not move and the horse would not turn. HOS_SDL_ALL_PADS=1 keeps every controller, as before.
|
||||
type: SDL's joystick type (SDL2 SDL_JoystickType and SDL3 SDL_JoystickType share these numbers); name: the controller's name
|
||||
(either may be unknown: 0, NULL). Returns why it is left out, or NULL to use it. host/hos_sdl.c hos_sdl_pads_list;
|
||||
tests/test_pad_kind.py */
|
||||
#pragma once
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum { PAD_KIND_DANCE_PAD = 5, PAD_KIND_GUITAR = 6, PAD_KIND_DRUM_KIT = 7 };
|
||||
|
||||
static inline int pad_kind_has_word(const char *name, const char *word) {
|
||||
if (!name) return 0;
|
||||
for (const char *p = name; *p; p++) {
|
||||
size_t i = 0;
|
||||
while (word[i] && p[i] && tolower((unsigned char)p[i]) == word[i]) i++;
|
||||
if (!word[i]) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const char *pad_kind_left_out(int type, const char *name) {
|
||||
if (type == PAD_KIND_GUITAR) return "a guitar";
|
||||
if (type == PAD_KIND_DRUM_KIT) return "a drum kit";
|
||||
if (type == PAD_KIND_DANCE_PAD) return "a dance mat";
|
||||
/* (by its name where SDL did not say: a guitar or drums seen as an Xbox 360 pad through a generic driver) */
|
||||
if (pad_kind_has_word(name, "guitar")) return "a guitar";
|
||||
if (pad_kind_has_word(name, "drum")) return "a drum kit";
|
||||
if (pad_kind_has_word(name, "rock band")) return "a Rock Band instrument";
|
||||
if (pad_kind_has_word(name, "dance pad") || pad_kind_has_word(name, "dance mat")) return "a dance mat";
|
||||
return NULL;
|
||||
}
|
||||
@@ -64,6 +64,10 @@ static uint64_t state_buttons;
|
||||
static int32_t state_stick[4];
|
||||
static int state_count;
|
||||
static char state_name[128]; /* the first controller's name (host/prompts.c: the button prompts' Auto) */
|
||||
static char state_last_name[128]; /* ((Triforce) the name of the open controller used last (used_ns), "" none */
|
||||
/* ((Triforce, 11-19) the scans for controllers done (pads_poll), for Auto's wait at the game's start (host/prompts.c
|
||||
choose_face): -1 when SDL will not run (HOS_NO_SDL, no SDL, or it would not start), 0 while it is starting */
|
||||
static volatile LONG scans;
|
||||
static volatile LONG rumble_low, rumble_high; /* 0..65535, set by the vibration HLE */
|
||||
/* the game's own vibration values per side (0 left, 1 right: {amp_low, freq_low, amp_high, freq_high}), for the pads
|
||||
that play HD rumble; silence until the game sends one */
|
||||
@@ -127,6 +131,7 @@ static int pads_start(void) {
|
||||
if (getenv("HOS_HEADLESS")) hos_sdl_hint("SDL_NO_SIGNAL_HANDLERS", "1");
|
||||
if (!hos_sdl_init(HOS_SDL_GAMEPAD)) {
|
||||
hos_log("hid: SDL could not start its controller support: %s", hos_sdl_error());
|
||||
InterlockedExchange(&scans, -1);
|
||||
return 0;
|
||||
}
|
||||
hos_log("hid: SDL controller support ready (DualSense, DualShock 4, Switch Pro, Xbox and others)");
|
||||
@@ -345,14 +350,17 @@ static void motion_poll(int64_t now, int count) {
|
||||
ReleaseSRWLockExclusive(&state_lock);
|
||||
}
|
||||
|
||||
/* one poll: controllers plugged in or gone (each second), then every open one's buttons, sticks and rumble */
|
||||
/* one poll: controllers plugged in or gone (each second; (Triforce) each quarter second for the first two, while the
|
||||
button prompts' Auto waits for them: SCANS_FAST), then every open one's buttons, sticks and rumble */
|
||||
#define SCANS_FAST 8
|
||||
static void pads_poll(void) {
|
||||
static int64_t next_scan = 0;
|
||||
static int64_t gone_ns; /* (Triforce) when a controller last disconnected, for the log */
|
||||
hos_sdl_pads_update();
|
||||
const int64_t now = hos_now_ns();
|
||||
if (now >= next_scan) { /* new controllers (and ones that went away) */
|
||||
next_scan = now + 1000000000LL;
|
||||
const int scanned = now >= next_scan;
|
||||
if (scanned) { /* new controllers (and ones that went away) */
|
||||
next_scan = now + (scans < SCANS_FAST ? 250000000LL : 1000000000LL);
|
||||
for (int i = 0; i < MAX_PADS; i++)
|
||||
if (pads[i].gc && !hos_sdl_pad_connected(pads[i].gc)) {
|
||||
/* (Triforce) how long it had been connected: a pad that leaves after seconds or minutes, again and
|
||||
@@ -491,7 +499,15 @@ static void pads_poll(void) {
|
||||
snprintf(state_name, sizeof state_name, "%s", name ? name : "");
|
||||
break;
|
||||
}
|
||||
{ /* ((Triforce) the one used last: its name, for the overlay's icons and Auto's next start) */
|
||||
int last = -1;
|
||||
for (int i = 0; i < MAX_PADS; i++)
|
||||
if (pads[i].gc && (last < 0 || pads[i].used_ns > pads[last].used_ns)) last = i;
|
||||
const char *name = last >= 0 ? hos_sdl_pad_name(pads[last].gc) : NULL;
|
||||
snprintf(state_last_name, sizeof state_last_name, "%s", name ? name : "");
|
||||
}
|
||||
ReleaseSRWLockExclusive(&state_lock);
|
||||
if (scanned && scans >= 0) InterlockedIncrement(&scans); /* (after the names: a scan counted has them) */
|
||||
}
|
||||
|
||||
static DWORD WINAPI pad_main(void *arg) {
|
||||
@@ -521,9 +537,13 @@ void hos_sdl_pads_pump(void) {
|
||||
int hos_sdl_pads(uint64_t *buttons, int32_t stick[4]) {
|
||||
static volatile LONG started;
|
||||
if (!started && !InterlockedExchange(&started, 1)) {
|
||||
if (getenv("HOS_NO_SDL")) return 0;
|
||||
if (getenv("HOS_NO_SDL")) {
|
||||
InterlockedExchange(&scans, -1);
|
||||
return 0;
|
||||
}
|
||||
if (!hos_sdl_load()) {
|
||||
hos_log("hid: no SDL beside the exe or on the system: only XInput controllers (Xbox pads) work");
|
||||
InterlockedExchange(&scans, -1);
|
||||
return 0;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
@@ -562,6 +582,15 @@ void hos_sdl_pad_first_name(char *out, size_t cap) {
|
||||
snprintf(out, cap, "%s", state_name);
|
||||
ReleaseSRWLockShared(&state_lock);
|
||||
}
|
||||
/* ((Triforce) The name of the open controller used last into out ("" with none) */
|
||||
void hos_sdl_pad_last_name(char *out, size_t cap) {
|
||||
AcquireSRWLockShared(&state_lock);
|
||||
snprintf(out, cap, "%s", state_last_name);
|
||||
ReleaseSRWLockShared(&state_lock);
|
||||
}
|
||||
/* ((Triforce) The scans for controllers done so far (pads_poll's: the first at once, then each quarter second for the
|
||||
first SCANS_FAST, then each second); -1 when SDL will not run */
|
||||
int hos_sdl_pad_scans(void) { return (int)scans; }
|
||||
|
||||
/* Vibration from the game (0..1 amplitudes of the low and high bands), for the pads that rumble. */
|
||||
void hos_sdl_rumble(float low, float high) {
|
||||
|
||||
262
host/prompts.c
262
host/prompts.c
@@ -8,6 +8,12 @@
|
||||
(SDL), else 1 Switch, 2 Xbox, 3 PlayStation 4, 4 PlayStation 5, 5 Steam Deck, 6 Keyboard & mouse. The game reads the font
|
||||
once, at its start: a new face or new controls show at the next start.
|
||||
|
||||
(Triforce, 11-19) Auto follows the device used last over runs: with no controller there at the start it takes the face of
|
||||
the device the player used last in the run before (<user>/prompts_auto.txt, follow_main). And while the game has the keys'
|
||||
face, the overlay's own prompts (the Insert menu, Mods, the Quit dialog, the options' tabs) show the icons of the
|
||||
controller used last, from a font of that controller's face built during play (prompts/External.pad.<n>.bfotf.zs, n
|
||||
its HOS_PROMPT_*): the game's own texts keep the face they were given at the start.
|
||||
|
||||
(Triforce) The keyboard and mouse face (NX2navi's prompts = pc; nx2/prompt_keys.py draws it): its font has an icon per
|
||||
key that can be bound, at U+F700 + the key's code, and each button's icon is that of the first key bound to it
|
||||
(bound_input). The left stick's and the d-pad's icons there are those keys side by side (bind_keys); the right stick's
|
||||
@@ -31,6 +37,12 @@ int hos_binding(int set, int button, int slot); /* nn_hid.c */
|
||||
int hos_sdl_pads(uint64_t *buttons, int32_t stick[4]); /* pad_sdl.c */
|
||||
void hos_sdl_pad_first_name(char *out, size_t cap);
|
||||
int hos_xinput_connected(void); /* nn_hid.c */
|
||||
int hos_input_last(void); /* nn_hid.c: 0 none yet, 1 the keys or the mouse, 2 a controller */
|
||||
unsigned hos_input_uses(int device); /* nn_hid.c: that device's uses so far */
|
||||
extern const char *hos_user_dir; /* nn_fs.c: the saves' folder */
|
||||
void hos_sdl_pad_last_name(char *out, size_t cap); /* pad_sdl.c */
|
||||
int hos_sdl_pad_scans(void);
|
||||
void hos_host_thread_register_self(const char *name); /* hos_prof.c */
|
||||
int hos_mods_has(const char *prefix, const char *suffix); /* mods.c */
|
||||
|
||||
#define FONT_PATH "font2/scalable/external.nin_ounce_nvn2.bfotf.zs" /* (as hos_mods_romfs's keys: lower case) */
|
||||
@@ -64,14 +76,17 @@ static int contains(const char *text, const char *word) { /* (any case) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (Triforce) Auto's face: the first controller's, from its name (SDL's; "": it has none). With none the keyboard and mouse
|
||||
are what the player has: their keys' icons, where the Switch's were shown before. xinput: XInput has a controller that
|
||||
SDL does not name (HOS_NO_SDL=1, or no SDL beside the game): the game's own icons, as before.
|
||||
The game reads its icons once, at its start, so Auto is chosen once, then: it cannot follow the device used last during
|
||||
play, as NX2navi's prompts setting could not (a fixed choice, after a restart). A controller that is there at the start
|
||||
is the face even while the keys are used with it, so the two never take turns */
|
||||
static int auto_face(const char *name, int xinput) {
|
||||
if (!name[0]) return xinput ? HOS_PROMPT_SWITCH : HOS_PROMPT_KEYBOARD;
|
||||
/* (Triforce) Auto's face: the first controller's, from its name (SDL's; "": it has none). xinput: XInput has a controller
|
||||
that SDL does not name (HOS_NO_SDL=1, no SDL beside the game, or one SDL had not opened yet): the Xbox's, as XInput
|
||||
reads only pads of the Xbox's layout ((11-19) it was the Switch's: an Xbox pad SDL had not opened in time showed the
|
||||
Switch's letters). With none, remembered: the face of the device used last in the run before (remembered_face,
|
||||
follow_main; -1 none), so a controller switched on after the game started is the face at the next start; without one
|
||||
the keyboard and mouse are what the player has: their keys' icons.
|
||||
The game reads its icons once, at its start, so Auto is chosen once, then: its texts cannot follow the device used last
|
||||
during play, as NX2navi's prompts setting could not. A controller that is there at the start is the face even while the
|
||||
keys are used with it, so the two never take turns */
|
||||
static int auto_face(const char *name, int xinput, int remembered) {
|
||||
if (!name[0]) return xinput ? HOS_PROMPT_XBOX : remembered >= 0 && remembered < HOS_PROMPT_N ? remembered : HOS_PROMPT_KEYBOARD;
|
||||
if (contains(name, "dualsense") || contains(name, "ps5")) return HOS_PROMPT_PS5;
|
||||
if (contains(name, "dualshock") || contains(name, "ps4") || contains(name, "playstation")) return HOS_PROMPT_PS4;
|
||||
if (contains(name, "steam deck")) return HOS_PROMPT_STEAMDECK;
|
||||
@@ -79,6 +94,37 @@ static int auto_face(const char *name, int xinput) {
|
||||
return HOS_PROMPT_XBOX; /* (Xbox pads, and the many that copy their layout) */
|
||||
}
|
||||
|
||||
/* ((Triforce, 11-19) where Auto keeps the device used last: <user>/prompts_auto.txt, beside the saves and mouse_sens.txt.
|
||||
Not in prompts/, which Setup makes again from nothing when its tools or the game's files change (nx2/make_game.py
|
||||
Prompts.finish), as a release's update does: the face remembered went with it, and the first start after each update
|
||||
without a controller ready had the keys' face again */
|
||||
static void auto_path(char *out, size_t cap) {
|
||||
snprintf(out, cap, "%s/prompts_auto.txt", hos_user_dir ? hos_user_dir : "user");
|
||||
}
|
||||
/* ((Triforce) the face auto_path has (faces[]), the device used last in the run before (follow_main), or prompts/auto.txt's,
|
||||
where an older build kept it; -1 none */
|
||||
static int remembered_face(const char *dir) {
|
||||
char path[MAX_PATH], line[32] = "";
|
||||
auto_path(path, sizeof path);
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) {
|
||||
snprintf(path, sizeof path, "%sprompts/auto.txt", dir);
|
||||
f = fopen(path, "r");
|
||||
}
|
||||
if (!f) return -1;
|
||||
if (!fgets(line, sizeof line, f)) line[0] = 0;
|
||||
fclose(f);
|
||||
line[strcspn(line, "\r\n")] = 0;
|
||||
for (int i = 0; i < HOS_PROMPT_N; i++)
|
||||
if (!strcmp(line, faces[i])) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* (Triforce) Auto's wait at the start: SDL's first scan for controllers and four more, a second of them (pad_sdl.c scans
|
||||
each quarter second at first), 3 s at most; none without SDL */
|
||||
#define AUTO_SCANS 5
|
||||
static int chosen_auto; /* (choose_face's: the row is on Auto) */
|
||||
|
||||
/* HOS_PROMPT_* (faces[]) */
|
||||
static int choose_face(const char *dir) {
|
||||
char path[MAX_PATH], line[80];
|
||||
@@ -91,18 +137,23 @@ static int choose_face(const char *dir) {
|
||||
fclose(f);
|
||||
}
|
||||
if (choice >= 1 && choice <= HOS_PROMPT_N) return choice - 1;
|
||||
/* Auto: the first controller SDL opens (it scans every second: up to 1.5 s for one, at the game's start) */
|
||||
chosen_auto = 1;
|
||||
/* Auto: the first controller SDL opens, as long as AUTO_SCANS's wait */
|
||||
char name[128] = "";
|
||||
uint64_t b = 0;
|
||||
int32_t s[4] = {0};
|
||||
for (int i = 0; i < 30 && !name[0]; i++) {
|
||||
for (int i = 0; i < 60; i++) {
|
||||
hos_sdl_pads(&b, s);
|
||||
hos_sdl_pad_first_name(name, sizeof name);
|
||||
if (!name[0]) Sleep(50);
|
||||
const int scans = hos_sdl_pad_scans();
|
||||
if (name[0] || scans < 0 || scans >= AUTO_SCANS) break;
|
||||
Sleep(50);
|
||||
}
|
||||
const int xinput = !name[0] && hos_xinput_connected();
|
||||
const int face = auto_face(name, xinput);
|
||||
hos_log("prompts: auto: controller \"%s\": %s", name[0] ? name : xinput ? "(XInput's, no name)" : "(none)", faces[face]);
|
||||
const int remembered = name[0] || xinput ? -1 : remembered_face(dir);
|
||||
const int face = auto_face(name, xinput, remembered);
|
||||
hos_log("prompts: auto: controller \"%s\": %s", name[0] ? name : xinput ? "(XInput's, no name)" :
|
||||
remembered >= 0 ? "(none: the device used last in the run before, prompts_auto.txt)" : "(none)", faces[face]);
|
||||
return face;
|
||||
}
|
||||
|
||||
@@ -272,6 +323,7 @@ static uint8_t *read_all(const char *path, const char *magic, long *n) { /* (t
|
||||
}
|
||||
|
||||
static volatile LONG setup_state; /* setup's: 0 not looked, 1 looking, 2 prompts, 3 none */
|
||||
static DWORD WINAPI follow_main(void *arg);
|
||||
|
||||
/* the game folder and the face, found once; 0 when the folder has no prompts/ (built before them: the game's own icons) */
|
||||
static int setup(char *dir, size_t cap, int *face) {
|
||||
@@ -289,6 +341,11 @@ static int setup(char *dir, size_t cap, int *face) {
|
||||
setting did nothing, and the log said nothing of it) */
|
||||
else hos_log("prompts: no prompts folder beside the game: the game's own icons, whatever Button prompts is set to "
|
||||
"(Setup's Update makes them)");
|
||||
/* ((Triforce) the device used last followed, on Auto or with the keys' face: follow_main, which waits for this) */
|
||||
if (ok && (chosen_auto || f == HOS_PROMPT_KEYBOARD)) {
|
||||
HANDLE t = CreateThread(NULL, 0, follow_main, NULL, 0, NULL);
|
||||
if (t) CloseHandle(t);
|
||||
}
|
||||
InterlockedExchange(&setup_state, ok ? 2 : 3);
|
||||
}
|
||||
while (setup_state == 1) Sleep(1);
|
||||
@@ -558,29 +615,19 @@ static int build_layouts(char *out, size_t cap) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* builds prompts/External.bfotf.zs for this run; 1 when there is one */
|
||||
static int build(char *out, size_t cap) {
|
||||
char dir[MAX_PATH], path[MAX_PATH];
|
||||
int face;
|
||||
if (!setup(dir, sizeof dir, &face)) return 0;
|
||||
/* (a mod's size table is served, not ours: the faces' fonts, larger than the game's, do not fit it. ((Triforce, 11-18)
|
||||
unless the lifted code asks host/mods.c's hos_mods_table_size for each file's room, which gives the font its own: so
|
||||
only when that hook has not run in this game, an older build of it) */
|
||||
extern volatile LONG hos_mods_size_hook_seen;
|
||||
if (hos_mods_has(SIZES_PATH, ".rsizetable.zs")) {
|
||||
if (!hos_mods_size_hook_seen) {
|
||||
hos_log("prompts: a mod has the resource size table: the game's own icons in texts");
|
||||
return 0;
|
||||
}
|
||||
hos_log("prompts: a mod has the resource size table: the font's room comes from the size hook (host/mods.c)");
|
||||
}
|
||||
/* face's font (prompts/<face>/External.bfotf) with these controls, written to prompts/<name> (out its path); 1 when written,
|
||||
-1 when the folder has no font of that face. pad: (Triforce) the overlay's font of the controller used last
|
||||
(follow_main), written whole and then put in place: (11-19) once a run for each face, before the overlay is told of it,
|
||||
so never while it reads it */
|
||||
static int build_font(const char *dir, int face, const char *name, int pad, char *out, size_t cap) {
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, sizeof path, "%sprompts/%s/External.bfotf", dir, faces[face]);
|
||||
long n;
|
||||
uint8_t *b = read_all(path, NULL, &n);
|
||||
if (!b || n < 16 || n % 4) {
|
||||
hos_log("prompts: no %s: the game's own icons", path);
|
||||
free(b);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
const uint32_t key = rd32le(b) ^ MAGIC;
|
||||
for (long i = 8; i < n; i += 4) wr32le(b + i, rd32le(b + i) ^ key);
|
||||
@@ -594,10 +641,15 @@ static int build(char *out, size_t cap) {
|
||||
free(k);
|
||||
}
|
||||
for (long i = 8; i < n; i += 4) wr32le(b + i, rd32le(b + i) ^ key);
|
||||
snprintf(out, cap, "%sprompts/External.bfotf.zs", dir);
|
||||
const int ok = write_zstd_raw(out, b, (size_t)n);
|
||||
snprintf(out, cap, "%sprompts/%s", dir, name);
|
||||
snprintf(path, sizeof path, "%s.new", out);
|
||||
const int ok = pad ? write_zstd_raw(path, b, (size_t)n) && MoveFileExA(path, out, MOVEFILE_REPLACE_EXISTING)
|
||||
: write_zstd_raw(out, b, (size_t)n);
|
||||
free(b);
|
||||
if (face == HOS_PROMPT_KEYBOARD)
|
||||
if (pad)
|
||||
hos_log("prompts: the overlay's icons of the controller used last: %s, %d buttons on this pad's controls%s", faces[face],
|
||||
bound, ok ? "" : ": could not be written");
|
||||
else if (face == HOS_PROMPT_KEYBOARD)
|
||||
hos_log("prompts: %s icons, %d buttons and directions on these keys, %d keys in the icons of several%s", faces[face],
|
||||
bound, several, ok ? "" : ": could not be written");
|
||||
else
|
||||
@@ -605,6 +657,120 @@ static int build(char *out, size_t cap) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* builds prompts/External.bfotf.zs for this run; 1 when there is one */
|
||||
static int build(char *out, size_t cap) {
|
||||
char dir[MAX_PATH];
|
||||
int face;
|
||||
if (!setup(dir, sizeof dir, &face)) return 0;
|
||||
/* (a mod's size table is served, not ours: the faces' fonts, larger than the game's, do not fit it. ((Triforce, 11-18)
|
||||
unless the lifted code asks host/mods.c's hos_mods_table_size for each file's room, which gives the font its own: so
|
||||
only when that hook has not run in this game, an older build of it) */
|
||||
extern volatile LONG hos_mods_size_hook_seen;
|
||||
if (hos_mods_has(SIZES_PATH, ".rsizetable.zs")) {
|
||||
if (!hos_mods_size_hook_seen) {
|
||||
hos_log("prompts: a mod has the resource size table: the game's own icons in texts");
|
||||
return 0;
|
||||
}
|
||||
hos_log("prompts: a mod has the resource size table: the font's room comes from the size hook (host/mods.c)");
|
||||
}
|
||||
return build_font(dir, face, "External.bfotf.zs", 0, out, cap) > 0;
|
||||
}
|
||||
|
||||
/* the face of the device used last (device: hos_input_last's; name: the controller used last's, SDL's, "" none: XInput's,
|
||||
an Xbox pad), -1 none yet */
|
||||
static int device_face(int device, const char *name) {
|
||||
return device == 2 ? auto_face(name, 1, -1) : device == 1 ? HOS_PROMPT_KEYBOARD : -1;
|
||||
}
|
||||
|
||||
/* follow_main's: the device's face (device_face) held since held_ns, the looks it was used in since (active), and the face
|
||||
auto_path has (-1 none) */
|
||||
typedef struct { int held, recorded; int64_t held_ns; int active; } Follow;
|
||||
/* ((Triforce, 11-19) the keys' face is recorded once they have been used in this many of the looks (a quarter second
|
||||
each) while they were the device used last: a key pressed once, or the mouse bumped, and the game then left alone is
|
||||
not a player of the keys */
|
||||
#define KEYS_ACTIVE 20
|
||||
/* face seen at now, its device used since the last look or not (active): whether auto_path is to have it now (then
|
||||
recorded is it) */
|
||||
static int follow_record(Follow *f, int face, int64_t now, int active) {
|
||||
if (face < 0) return 0;
|
||||
if (face != f->held) f->held = face, f->held_ns = now, f->active = 0;
|
||||
if (active) f->active++;
|
||||
const int keys = face == HOS_PROMPT_KEYBOARD;
|
||||
if (face == f->recorded || now - f->held_ns < (keys ? 30 : 3) * 1000000000LL || (keys && f->active < KEYS_ACTIVE)) return 0;
|
||||
f->recorded = face;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ((Triforce, 11-19) the overlay's icons follow a controller once it has been the one used last this long: two controllers
|
||||
of two faces given the same presses (a DualSense and the virtual Xbox pad DS4Windows makes of it, a Steam Input pad)
|
||||
take turns as the one used last, and the icons would change at each press */
|
||||
#define PAD_HOLD_NS 1000000000LL
|
||||
/* whether the overlay is to show face's icons now: the game has the keys' face, face is a controller's, not the one shown
|
||||
(shown: -1 none), the one used last for PAD_HOLD_NS (held_ns) unless none is shown yet, and not one whose font cannot be
|
||||
made (failed: a bit a face) */
|
||||
static int pad_font_due(int served, int face, int shown, int64_t held_ns, unsigned failed) {
|
||||
return served == HOS_PROMPT_KEYBOARD && face >= 0 && face != HOS_PROMPT_KEYBOARD && face != shown && !(failed >> face & 1) &&
|
||||
(shown < 0 || held_ns >= PAD_HOLD_NS);
|
||||
}
|
||||
|
||||
/* ((Triforce, 11-19) The device the player uses (host/nn_hid.c hos_input_last), looked at four times a second on a thread
|
||||
of its own, from the start (setup) on Auto or with the keys' face:
|
||||
- while the game has the keys' face, a controller used builds the overlay's font of its face (build_font's pad), once a
|
||||
run for each face (prompts/External.pad.<n>.bfotf.zs), and hos_prompts_pad_face says which to show once written;
|
||||
another face's after it has been the last for a second (pad_font_due). One not written is tried again 2 s on;
|
||||
- on Auto, the face of the device used last (a controller: its name's, auto_face; the keys or the mouse: theirs) goes
|
||||
into auto_path for the next start (remembered_face) once it has been the last for 3 s, the keys' for 30 s and used in
|
||||
5 s of them (a key pressed between a controller's presses, or to close the game, keeps the controller's); written
|
||||
only when it changes. Never on the input's thread: read_input only stores the device */
|
||||
static volatile LONG pad_face_shown = -1; /* the face of the overlay's font to show this run (built), -1 none */
|
||||
static DWORD WINAPI follow_main(void *arg) {
|
||||
(void)arg;
|
||||
hos_host_thread_register_self("button prompts");
|
||||
char dir[MAX_PATH];
|
||||
int served;
|
||||
setup(dir, sizeof dir, &served);
|
||||
Follow follow = {-1, remembered_face(dir), 0, 0};
|
||||
unsigned built = 0, failed = 0, uses[3] = {0};
|
||||
int seen = -1; /* (the face used last, since seen_ns) */
|
||||
int64_t seen_ns = 0, retry_ns[HOS_PROMPT_N] = {0};
|
||||
for (;;) {
|
||||
Sleep(250);
|
||||
char name[128] = "";
|
||||
const int device = hos_input_last();
|
||||
if (device == 2) hos_sdl_pad_last_name(name, sizeof name);
|
||||
const int face = device_face(device, name);
|
||||
const int64_t now = hos_now_ns();
|
||||
const unsigned used = hos_input_uses(device);
|
||||
const int active = device >= 1 && device <= 2 && used != uses[device];
|
||||
if (device >= 1 && device <= 2) uses[device] = used;
|
||||
if (face != seen) seen = face, seen_ns = now;
|
||||
if (pad_font_due(served, face, (int)pad_face_shown, now - seen_ns, failed) && now >= retry_ns[face]) {
|
||||
char out[MAX_PATH], file[48];
|
||||
snprintf(file, sizeof file, "External.pad.%d.bfotf.zs", face);
|
||||
const int got = built >> face & 1 ? 1 : build_font(dir, face, file, 1, out, sizeof out);
|
||||
if (got > 0) built |= 1u << face, InterlockedExchange(&pad_face_shown, face);
|
||||
else if (got < 0) failed |= 1u << face; /* (no font of that face: not tried again) */
|
||||
else retry_ns[face] = now + 2000000000LL; /* (not written: again in 2 s) */
|
||||
}
|
||||
if (chosen_auto && follow_record(&follow, face, now, active)) { /* (written or not: again only when it changes) */
|
||||
char path[MAX_PATH];
|
||||
auto_path(path, sizeof path);
|
||||
FILE *f = fopen(path, "w");
|
||||
int ok = f && fputs(faces[face], f) >= 0;
|
||||
if (f) ok &= fclose(f) == 0;
|
||||
hos_log("prompts: auto: the device used last has the %s face: the next start's without a controller%s",
|
||||
faces[face], ok ? "" : " (prompts_auto.txt could not be written)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ((Triforce) the face of the controller used last whose icons the overlay is to show, from prompts/External.pad.<n>.bfotf.zs
|
||||
(n the face's HOS_PROMPT_*), built while the game has the keys' face (follow_main); -1 none (no controller used yet, or the
|
||||
game has a controller's face) */
|
||||
int hos_prompts_pad_face(void) {
|
||||
return (int)pad_face_shown;
|
||||
}
|
||||
|
||||
/* (Triforce) The Insert menu's Camera speed row (camera_speed= in the options file, percent; HOS_CAMERA_SPEED=<percent>
|
||||
over it): how fast the right stick turns the camera, times the game's own speed at any of the five Camera sensitivity
|
||||
settings of its Options. The rates are five floats in the game's camera pack (nx2/prompt_assets.py CAMERA has where and
|
||||
@@ -670,12 +836,42 @@ int hos_prompts_font_file(const char *key, char *out, size_t cap) {
|
||||
return hos_prompts_romfs(FONT_PATH, out, cap);
|
||||
}
|
||||
|
||||
/* (Triforce) The title screen's third entry, "Options / ZELDA NOTES Setting" in US English, reads "Options / Triforce":
|
||||
prompts/mals/<language>.product.110.sarc.zs is that language's messages (Mals/, its name in lower case) with the entry's
|
||||
rest after the game's word for Options made Triforce's (nx2/prompt_assets.py title_messages; the wording is its
|
||||
TITLE_TEXT), built at Setup's Update from the player's own files. The one of the language the game shows is served
|
||||
(desired_language: language.txt, HOS_LANGUAGE over it), each language's messages are a file of their own. No larger
|
||||
than the game's file (title_messages writes no other), so the size table's entry holds it with its allowance. A mod's file of the same name wins (mods.c asks here only without one) */
|
||||
const char *hos_desired_language(void); /* nn_applet.c */
|
||||
static const struct { const char *code, *mals; } title_languages[] = { /* (nn_applet.c languages[] -> romfs/Mals) */
|
||||
{"en-US", "usen"}, {"en-GB", "euen"}, {"fr", "eufr"}, {"fr-CA", "usfr"}, {"de", "eude"}, {"it", "euit"},
|
||||
{"es", "eues"}, {"es-419", "uses"}, {"pt-BR", "uspt"}, {"nl", "eunl"}, {"pl", "eupl"}, {"ru", "euru"},
|
||||
{"ja", "jpja"}, {"ko", "krko"}, {"zh-Hans", "cnzh"}, {"zh-Hant", "twzh"},
|
||||
};
|
||||
static int title_messages(const char *key, char *out, size_t cap) {
|
||||
char dir[MAX_PATH], want[16];
|
||||
int face;
|
||||
const char *lang = hos_desired_language(), *mals = "usen";
|
||||
for (size_t i = 0; i < sizeof title_languages / sizeof *title_languages; i++)
|
||||
if (!strcmp(lang, title_languages[i].code)) mals = title_languages[i].mals;
|
||||
snprintf(want, sizeof want, "mals/%s.", mals);
|
||||
if (strncmp(key, want, strlen(want)) || !setup(dir, sizeof dir, &face)) return 0; /* (another language's: the game's) */
|
||||
snprintf(out, cap, "%sprompts/%s", dir, key);
|
||||
const int ok = GetFileAttributesA(out) != INVALID_FILE_ATTRIBUTES;
|
||||
static volatile LONG logged;
|
||||
if (InterlockedExchange(&logged, 1) == 0)
|
||||
hos_log(ok ? "prompts: the title's Options entry from prompts/%s (%s)"
|
||||
: "prompts: no prompts/%s (%s): the title's Options entry is the game's (Setup's Update makes it)", key, lang);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* mods.c: the file for a RomFS path the prompts replace (key: lower case, '/'), 1 with one. Asked only when no mod has
|
||||
the file: a mod's own wins */
|
||||
int hos_prompts_romfs(const char *key, char *out, size_t cap) {
|
||||
static volatile LONG state[4]; /* the font, the textures, the layouts, the camera: 0 not built, 1 being built, 2 built, 3 none */
|
||||
static char path[4][MAX_PATH];
|
||||
const size_t kn = strlen(key);
|
||||
if (!strncmp(key, "mals/", 5) && kn > 8 && !strcmp(key + kn - 8, ".sarc.zs")) return title_messages(key, out, cap);
|
||||
if (!strncmp(key, SIZES_PATH, sizeof SIZES_PATH - 1) && kn > 14 && !strcmp(key + kn - 14, ".rsizetable.zs")) {
|
||||
char dir[MAX_PATH]; /* (the game's size table with room for the faces' fonts, larger than its: nx2/prompt_assets.py) */
|
||||
int face;
|
||||
|
||||
@@ -59,6 +59,7 @@ const char *hos_mic_name(int index);
|
||||
void hos_mic_select(int mode, const char *name, int index);
|
||||
void hos_bind(int set, int button, int slot, int code);
|
||||
int hos_prompts_face(void); /* prompts.c */
|
||||
int hos_prompts_pad_face(void);
|
||||
#if defined(A64_WRITE_TRACK) && !defined(__EMSCRIPTEN__)
|
||||
void hos_mark_written(const void *p, size_t n);
|
||||
#endif
|
||||
@@ -84,7 +85,80 @@ static int page_collected(uint64_t page) { /* is the page in a range some coll
|
||||
return in;
|
||||
}
|
||||
#endif
|
||||
#ifndef A64_MARK_ONE
|
||||
/* RX_VK_COLLECT_FAST (default on; =0: the walk below): the same scan with unaligned loads at the ranges' edges. collect_in
|
||||
skips clean marks 32 or 8 at a time only from a page number aligned to that size, so each of the ~1,500 capture ranges (and
|
||||
~760 the replay collects) began and ended with up to ~38 single-page atomic loads, twice a submit, six submits a frame.
|
||||
Here the blocks are read wherever the walk is (the marks are bytes: memcpy into words is an unaligned load), 256 pages a
|
||||
look, and only a non-zero byte of a non-zero block is exchanged. Same result: a page is taken when its mark reads non-zero
|
||||
and the exchange that clears it returns non-zero (acquire), in ascending page order within a range and in range order. A
|
||||
mark the game sets after the block was read is left for the next scan, as collect_in leaves a mark set after its own load
|
||||
of that byte. The block reads are plain loads of bytes others store atomically, as collect_in's skips always were (x86-64:
|
||||
a byte load is atomic) */
|
||||
static int collect_fast_on(void) {
|
||||
static int v = -1;
|
||||
if (v < 0) {
|
||||
const char *e = getenv("RX_VK_COLLECT_FAST");
|
||||
v = !e || atoi(e) != 0;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
static inline void collect_take(uint64_t p, uint32_t **out, size_t *n, size_t *cap) {
|
||||
if (__atomic_exchange_n(&a64_dirty[p], 0, __ATOMIC_ACQUIRE)) {
|
||||
if (*n == *cap) *out = realloc(*out, (*cap *= 2) * sizeof **out);
|
||||
(*out)[(*n)++] = (uint32_t)p;
|
||||
}
|
||||
}
|
||||
static int64_t collect_in_fast(const uint64_t (*ranges)[2], int nranges, uint32_t **pages) {
|
||||
size_t n = 0, cap = 4096;
|
||||
uint32_t *out = malloc(cap * sizeof *out);
|
||||
for (int r = 0; r < nranges; r++) {
|
||||
const uint64_t lo = ranges[r][0], hi = ranges[r][1] < hos_guest_size() ? ranges[r][1] : hos_guest_size();
|
||||
uint64_t p1 = (hi + 4095) >> 12;
|
||||
if (p1 > A64_DIRTY_PAGES) p1 = A64_DIRTY_PAGES;
|
||||
uint64_t p = lo >> 12;
|
||||
while (p < p1) {
|
||||
if (p + 256 <= p1) {
|
||||
uint64_t w[32], any = 0;
|
||||
memcpy(w, &a64_dirty[p], 256);
|
||||
for (int k = 0; k < 32; k++) any |= w[k];
|
||||
if (any)
|
||||
for (int k = 0; k < 32; k++)
|
||||
for (int b = 0; w[k] && b < 8; b++)
|
||||
if ((w[k] >> (8 * b)) & 0xFF) collect_take(p + 8 * k + b, &out, &n, &cap);
|
||||
p += 256;
|
||||
continue;
|
||||
}
|
||||
if (p + 32 <= p1) {
|
||||
uint64_t w[4];
|
||||
memcpy(w, &a64_dirty[p], 32);
|
||||
if (w[0] | w[1] | w[2] | w[3])
|
||||
for (int k = 0; k < 4; k++)
|
||||
for (int b = 0; w[k] && b < 8; b++)
|
||||
if ((w[k] >> (8 * b)) & 0xFF) collect_take(p + 8 * k + b, &out, &n, &cap);
|
||||
p += 32;
|
||||
continue;
|
||||
}
|
||||
if (p + 8 <= p1) {
|
||||
uint64_t w;
|
||||
memcpy(&w, &a64_dirty[p], 8);
|
||||
for (int b = 0; w && b < 8; b++)
|
||||
if ((w >> (8 * b)) & 0xFF) collect_take(p + b, &out, &n, &cap);
|
||||
p += 8;
|
||||
continue;
|
||||
}
|
||||
if (__atomic_load_n(&a64_dirty[p], __ATOMIC_RELAXED)) collect_take(p, &out, &n, &cap);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
*pages = out;
|
||||
return (int64_t)n;
|
||||
}
|
||||
#endif
|
||||
static int64_t collect_in(const uint64_t (*ranges)[2], int nranges, uint32_t **pages) {
|
||||
#ifndef A64_MARK_ONE
|
||||
if (collect_fast_on()) return collect_in_fast(ranges, nranges, pages);
|
||||
#endif
|
||||
size_t n = 0, cap = 4096;
|
||||
uint32_t *out = malloc(cap * sizeof *out);
|
||||
for (int r = 0; r < nranges; r++) {
|
||||
@@ -230,7 +304,7 @@ static const MkwVkHost vk_host = {
|
||||
hos_gpu_maps_generation, nvn_vmap_generation, hos_reserved_cpus, host_collect_in, host_guest_alloc,
|
||||
host_watch_guest_writes, hos_pad_raw, hos_binding, hos_bind, host_aspect_ratio, host_take_key_press,
|
||||
hos_mouse_pointer, hos_mic_count, hos_mic_name, hos_mic_select, hos_sdl_gyro_status, hos_log_flush, hos_prompts_face,
|
||||
host_romfs_dir, host_wide_menus, hos_bench_state,
|
||||
host_romfs_dir, host_wide_menus, hos_bench_state, hos_prompts_pad_face,
|
||||
};
|
||||
|
||||
static const MkwVkRenderer *vk; /* the Vulkan back end, when it was chosen and started */
|
||||
@@ -318,6 +392,32 @@ void hos_guest_io_end(int held) {
|
||||
if (held && end) end(held);
|
||||
}
|
||||
|
||||
/* (Triforce, gpu/vk/async_rules.h) The replay on a thread of the back end's own (RX_VK_ASYNC=1, off by default): what the host
|
||||
does differently then. rx_async_replay: whether it is on (the back end reads the same switch). rx_nvn_submit_waits: the events
|
||||
the submit this thread makes next waits for (nvn_native.c resolve_deferred sees the wait ops), so that a signal of the CPU's
|
||||
takes its capture only when a submission handed over may still wait for it. rx_nvn_replay_idle_wait: the game's present poll
|
||||
waits for the replay thread without looking while its frame is still recorded (hos_thread.c present_poll); 1 when the thread
|
||||
has nothing left, or there is none. Both back end calls are found by name, as the lazy write-back's; without them nothing is
|
||||
told and the wait returns at once */
|
||||
static void (*volatile submit_waits_fn)(const uint64_t *, int); /* (the back end's mkwvk_submit_waits, once it runs) */
|
||||
static int (*volatile replay_idle_wait_fn)(uint64_t);
|
||||
int rx_async_replay(void) {
|
||||
static volatile int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = getenv("RX_VK_ASYNC");
|
||||
on = e && atoi(e) != 0;
|
||||
}
|
||||
return on;
|
||||
}
|
||||
void rx_nvn_submit_waits(const uint64_t *events, int n) {
|
||||
void (*fn)(const uint64_t *, int) = submit_waits_fn;
|
||||
if (fn) fn(events, n);
|
||||
}
|
||||
int rx_nvn_replay_idle_wait(uint64_t timeout_ns) {
|
||||
int (*fn)(uint64_t) = replay_idle_wait_fn;
|
||||
return fn ? fn(timeout_ns) : 1;
|
||||
}
|
||||
|
||||
/* dll: mkw_vk.dll (our Vulkan back end) or mkw_eden.dll (Eden's renderer driven natively, gpu/eden): one export */
|
||||
static const MkwVkRenderer *load_vulkan(const char *dll) {
|
||||
char path[MAX_PATH];
|
||||
@@ -352,6 +452,9 @@ int rx_start(void *hwnd) {
|
||||
lazy_io_end = (void (*)(int))(void *)GetProcAddress(vk_module, "mkwvk_lazy_io_end");
|
||||
if (lazy_io_end)
|
||||
lazy_io_begin = (int (*)(const void *, uint64_t))(void *)GetProcAddress(vk_module, "mkwvk_lazy_io_begin");
|
||||
/* (Triforce: the replay thread's two calls, rx_async_replay above; a back end without them has none) */
|
||||
submit_waits_fn = (void (*)(const uint64_t *, int))(void *)GetProcAddress(vk_module, "mkwvk_submit_waits");
|
||||
replay_idle_wait_fn = (int (*)(uint64_t))(void *)GetProcAddress(vk_module, "mkwvk_replay_idle_wait");
|
||||
hos_log("rx: renderer: %s (%s)", eden ? "Eden's" : "Vulkan", dll);
|
||||
flush_early();
|
||||
return 1;
|
||||
@@ -385,6 +488,17 @@ void rx_nvn_submit_q(const uint64_t *handles, int n, uint64_t queue) {
|
||||
if (vk && vk->nvn_submit_q) vk->nvn_submit_q(handles, n, queue);
|
||||
else rx_nvn_submit(handles, n);
|
||||
}
|
||||
/* (HOS_NVN_HOLD=2, nvn_native.c held_flush_why) the next submit on this thread is a held one: the game's thread that made it is
|
||||
already running again, so its capture copies every page before the replay (gpu/vk/vk_replay.cpp mkwvk_submit_held) */
|
||||
void rx_nvn_submit_held(int on) {
|
||||
static void (*fn)(int);
|
||||
static int looked;
|
||||
if (!looked) {
|
||||
if (vk_module) fn = (void (*)(int))(void *)GetProcAddress(vk_module, "mkwvk_submit_held");
|
||||
looked = 1;
|
||||
}
|
||||
if (fn) fn(on);
|
||||
}
|
||||
uint64_t rx_nvn_fence(void) { return vk ? vk->nvn_fence() : wgr_nvn_fence(); }
|
||||
uint64_t rx_nvn_fence_q(uint64_t queue) { return vk && vk->nvn_fence_q ? vk->nvn_fence_q(queue) : rx_nvn_fence(); }
|
||||
uint64_t rx_nvn_pushed(void) { return vk ? vk->nvn_pushed() : wgr_nvn_pushed(); }
|
||||
|
||||
Reference in New Issue
Block a user