Triforce v0.8.4

Smoother frames and less memory: a compact pipeline cache on NVIDIA, the renderer and game-code profiles, native float in the hot game code, late GPU work left as before. A PC whose NVIDIA shader cache drops the game's gets a driver cache folder of its own. Fixes from the 0.8.3 reports: RenoDX's encoder and tone mapping matched on NVIDIA again; the out-of-memory notice at the next start; no microphone open without a recording device; Evil HD undergrowth kept to 80/120 m; the FG HUD layer keeps what it learned; a stick past 92% is a full push; the DualSense jack read only when used; Linux Save Select, Quit and Restart, and the Linux launcher's sound; the update check uses the program's own version.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-26 20:04:11 -06:00
parent ecb4d5cc99
commit 2df08c751e
45 changed files with 2828 additions and 567 deletions

View File

@@ -49,8 +49,13 @@ static const float evil_hd_foliage_game[EVIL_HD_FOLIAGE_COUNT] = {40.0f, 60.0f,
and 105 m (3x) and were steady at 70 and 75 m; the low trees' shoot leaves (the Lost Woods' leaves overhead) flickered at
120 m and were steady at 30 and 70 m. The game's own areas set them no farther than 75 m (Hyrule Castle's ornaments) and
70 m (Zora's Domain's shoot leaves): the foliage system seems to have room for about that many of them. The other six
showed no flicker at 4x and keep the whole factor. 0: no bound */
static const float evil_hd_foliage_most[EVIL_HD_FOLIAGE_COUNT] = {0.0f, 0.0f, 75.0f, 70.0f, 0.0f, 0.0f, 0.0f, 0.0f};
showed no flicker at 4x and keep the whole factor. 0: no bound
(11-26, measured on child Kokiri Forest, KokiriForest_Child, by the Lost Woods entrance) The undergrowth too: its low,
uncuttable ground cover popped in and out on camera turns at 4x, 3x, 2.5x and 2.25x and was steady at 2x (80 and 120 m).
With one factor per distance: 80/120 m steady, 80/135 m steady, 90/120 m borderline, 90/135 m, 80/180 m, 160/120 m and
80/240 m popped. The two kinds seem to share one room (more of one leaves less for the other), so both are kept to the
steady pair, 80 and 120 m: twice the game's. */
static const float evil_hd_foliage_most[EVIL_HD_FOLIAGE_COUNT] = {80.0f, 120.0f, 75.0f, 70.0f, 0.0f, 0.0f, 0.0f, 0.0f};
/* One distance at a factor: the game's times it, kept to its most */
static inline float evil_hd_foliage_one(int i, float factor) {
const float v = factor == 1.0f ? evil_hd_foliage_game[i] : evil_hd_foliage_game[i] * factor;
@@ -97,7 +102,7 @@ static inline void evil_hd_foliage(float factor, float out[EVIL_HD_FOLIAGE_COUNT
/* Whether the eight floats at the defaults' place are a version of them this rule knows: the game's own, or the game's
times a factor of 1 to EVIL_HD_DIST_MOST (what an earlier write of this left). Another game version's bytes: left alone */
static inline int evil_hd_foliage_known(const float have[EVIL_HD_FOLIAGE_COUNT]) {
const float f = have[0] / evil_hd_foliage_game[0];
const float f = have[5] / evil_hd_foliage_game[5]; /* (the low trees' distance: no most, so it carries the factor) */
if (!(f >= 1.0f && f <= EVIL_HD_DIST_MOST)) return 0;
for (int i = 0; i < EVIL_HD_FOLIAGE_COUNT; i++) {
const float want = evil_hd_foliage_one(i, f), d = have[i] - want;

View File

@@ -157,6 +157,11 @@ uint64_t hos_thread_mask(HosThread *t);
int hos_thread_priority(HosThread *t, int set, int value);
int hos_thread_core(HosThread *t);
int hos_cores(void);
/* ((Triforce) ProjectReLink's) MXCSR's FTZ and DAZ follow the guest's FPCR.FZ once a lift with A64_NATIVE_FP asked
(hos_fpcr_follow, from its constructor): after its MSR FPCR (hos_fpcr_sync) and at a thread's and a fiber's start */
void hos_fpcr_follow(void);
void hos_fpcr_sync(Ctx *c);
void hos_fpcr_start(const Ctx *c);
/* virtual cores (hos_thread.c, HOS_VCORES=1): a guest thread gives its core up for a block (hos_vcore_away: 1 if it
held one, or ran without one since an escape) and takes one again after it (hos_vcore_back); checkpoints hand it to a
better waiter that asked */

View File

@@ -2563,6 +2563,36 @@ static void memory_notice(void) {
ram = ((unsigned long long)si.totalram * si.mem_unit) >> 20, swap = ((unsigned long long)si.totalswap * si.mem_unit) >> 20;
#else
return;
#endif
#ifdef _WIN32
/* ((Triforce, 11-26) the last session reached Windows' commit limit (mkw_glue.c hos_commit_limit_mark): said now, once,
before play, with this PC's RAM and page file. Its marker is removed when said (a lab run, headless, leaves it) */
{
char mark[MAX_PATH];
const DWORD len = hos_game_path_a(mark, MAX_PATH);
char *slash = len ? strrchr(mark, '\\') : NULL;
if (slash) {
snprintf(slash + 1, (size_t)(mark + MAX_PATH - slash - 1), "triforce_commit_limit.txt");
FILE *f = fopen(mark, "r");
if (f) {
fclose(f);
hos_log("boot: the last session reached Windows' commit limit (%llu MB of memory, %llu MB of page file): said "
"once now (%s)", ram, swap, mark);
if (!getenv("HOS_HEADLESS")) {
char said[900];
snprintf(said, sizeof said,
"The last time Triforce ran, Windows ran out of memory for it: this PC's RAM (%.1f GB) and page file "
"(%.1f GB) were full. That is what closed or froze the game.\n\nTo fix it, let Windows size the page "
"file: search \"Adjust the appearance and performance of Windows\", Advanced tab, Virtual memory: "
"Change, tick \"Automatically manage paging file size for all drives\", OK, then restart the PC. "
"Closing other programs while playing helps too.",
ram / 1024.0, swap / 1024.0);
MessageBoxA(NULL, said, "Triforce: out of memory last time", MB_OK | MB_ICONWARNING);
remove(mark);
}
}
}
}
#endif
char text[512];
if (!memory_notice_text(ram, swap, text, sizeof text)) {

View File

@@ -1189,6 +1189,12 @@ static void pad_headphones_forget(void *pad) { /* (the pad closed: its handle
if (hp_dev) hos_sdl_hid_close(hp_dev);
hp_dev = NULL, hp_pad = NULL, hp_failed = 0, hp_last = -2;
}
/* ((Triforce, 11-26) the reader let go while nothing needs the jack (host/pad_speaker.c headphones): its second handle
closed. A report of 11-26 had a DualSense drop seconds after every connection since v0.8.0, with the speaker rows off */
void hos_sdl_pad_headphones_release(void) {
if (hp_dev) hos_sdl_hid_close(hp_dev);
hp_dev = NULL, hp_pad = NULL, hp_failed = 0, hp_last = -2;
}
int hos_sdl_pad_headphones(void *pad) {
vib_calls_look();
if (!vib_calls.HidReadTimeout || !vib_calls.HidOpenPath || !vib_calls.HidClose || !pad) return -1;
@@ -1209,9 +1215,10 @@ int hos_sdl_pad_headphones(void *pad) {
int got = 0;
for (int i = 0; i < 256; i++) { /* (up to a second of reports queued: the newest counts) */
const int n = ((int (*)(void *, unsigned char *, size_t, int))vib_calls.HidReadTimeout)(hp_dev, report, sizeof report, 0);
if (n < 0) {
if (n < 0) { /* ((Triforce, 11-26) and not opened again each second: once a pad's life, as a failed open) */
hos_sdl_hid_close(hp_dev);
hp_dev = NULL;
hp_dev = NULL, hp_failed = 1;
hos_log("sdl: the DualSense's input report stopped reading beside SDL's: its headphones are not seen");
return -1;
}
if (n == 0) break;

View File

@@ -134,3 +134,4 @@ void hos_sdl_hid_close(void *hid);
when it cannot say) */
int hos_sdl_pad_audio_endpoint(void *pad);
int hos_sdl_pad_headphones(void *pad);
void hos_sdl_pad_headphones_release(void); /* ((Triforce, 11-26) its second handle closed: nothing needs the jack */

View File

@@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#define WIN32_LEAN_AND_MEAN
#include <xmmintrin.h> /* ((Triforce) _mm_getcsr / _mm_setcsr: hos_fpcr_sync) */
#include <windows.h>
#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION /* (older Windows SDKs lack it: Windows 10 1803 and later take it) */
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002
@@ -615,14 +616,52 @@ Ctx *hos_boot_main_thread(uint64_t stack_size) {
cur = t;
track(t);
hos_vcore_back(); /* (virtual cores: before any guest code) */
hos_fpcr_start(&t->ctx);
return &t->ctx;
}
/* (Triforce, 11-26: ProjectReLink's, pixl27) The host's MXCSR follows the guest's FPCR.FZ: results flushed to zero (FTZ) and
subnormal operands read as zeros (DAZ), which is what Arm's flush-to-zero mode does. With the lift option A64_NATIVE_FP
(nx2/nativefp.py) the hot functions' floating point runs on the host's own instructions, and those flush as the guest
expects only with both bits set; the exact helpers keep their values under them (with FZ they flush what they compute
themselves). Such a lift's constructor calls hos_fpcr_follow() before main, and its code calls hos_fpcr_sync() after every
MSR FPCR; the host syncs again at a thread's and a fiber's start (MXCSR is a thread's, and a fiber's with
FIBER_FLAG_FLOAT_SWITCH). A lift without the option never asks: MXCSR is left alone, as before. HOS_FPCR_SYNC=0: left
alone in any build (then a native lift's FZ is the host's default, no flush: a measurement switch only). */
static volatile LONG fpcr_follow;
static int fpcr_sync_on(void) {
static int on = -1;
if (on < 0) {
const char *e = getenv("HOS_FPCR_SYNC");
on = !(e && e[0] == '0');
}
return on;
}
static void fpcr_apply(const Ctx *c) {
#if defined(__x86_64__) || defined(_M_X64)
const unsigned want = ((uint32_t)c->fpcr & (1u << 24)) ? 0x8040u : 0u;
const unsigned now = _mm_getcsr();
if ((now & 0x8040u) != want) _mm_setcsr((now & ~0x8040u) | want);
#else
(void)c;
#endif
}
void hos_fpcr_follow(void) {
if (fpcr_sync_on()) InterlockedExchange(&fpcr_follow, 1);
}
void hos_fpcr_sync(Ctx *c) {
if (fpcr_follow) fpcr_apply(c);
}
void hos_fpcr_start(const Ctx *c) {
if (fpcr_follow) fpcr_apply(c);
}
static DWORD WINAPI thread_main(void *p) {
HosThread *t = (HosThread *)p;
hos_stack_guarantee();
cur = t;
Ctx *c = &t->ctx;
hos_fpcr_start(c);
c->x[0] = t->arg;
c->x[30] = 0;
c->x[31] = (t->stack + t->stack_size) & ~15ULL;
@@ -1639,6 +1678,7 @@ static void WINAPI fiber_main(void *p) {
c->x[0] = f->arg;
c->x[30] = 0;
c->x[31] = (f->stack + f->size) & ~15ULL;
hos_fpcr_start(c); /* (a new fiber has the default MXCSR and the FPCR of whoever started it) */
a64_icall(c, f->fn); /* FiberType* (*)(void*) */
const uint64_t next = c->x[0];
f->done = 1;

View File

@@ -126,6 +126,18 @@ void hos_update_check(void) {
char have[128], builder[MAX_PATH * 3], skipped[128] = "", tag[128];
_snwprintf(file, MAX_PATH + 64, L"%ls\\triforce_version.txt", dir);
if (!read_value(file, "version", have, sizeof have) || !safe_tag(have)) return;
{ /* ((Triforce, 11-26, a player's report: "the launcher is updated to 0.8.3 but in the folder it remains 0.8.1") the
program's own version over the file's: a folder whose triforce_version.txt says the new release while its program
is still the old one was never offered the update again */
const char *hos_version(void);
char mine[128];
snprintf(mine, sizeof mine, "%s", hos_version());
mine[strcspn(mine, " +")] = 0;
if (safe_tag(mine) && strcmp(mine, have)) {
fprintf(stderr, "update: triforce_version.txt says %s but this program is %s: taken as %s\n", have, mine, mine);
snprintf(have, sizeof have, "%s", mine);
}
}
_snwprintf(file, MAX_PATH + 64, L"%ls\\user\\triforce_update_skip.txt", dir);
read_value(file, "skip", skipped, sizeof skipped);
if (!latest_tag(tag, sizeof tag)) {

View File

@@ -32,8 +32,26 @@ int hos_commit_wait_ms(void) {
if (ms < 0) ms = host_alloc_wait_ms(getenv("HOS_COMMIT_WAIT_MS"));
return ms;
}
/* ((Triforce, 11-26) A session that reached Windows' commit limit leaves triforce_commit_limit.txt beside the game, once: the
next start's notice (hos_main.c memory_notice) says why before play. Three reports of 11-26 (an RX 7900 XTX after the Deku
Tree, another on pausing after 3 hours, a third loading a save) ended there with a page file of a fixed 0.6 to 8 GB, the
game holding 28 to 38 GB: their message box at the moment, over a full-screen game, was not seen) */
void hos_commit_limit_mark(void) {
static volatile LONG done;
if (InterlockedExchange(&done, 1)) return;
char path[MAX_PATH];
const DWORD len = hos_game_path_a(path, MAX_PATH);
char *slash = len ? strrchr(path, '\\') : NULL;
if (!slash) return;
snprintf(slash + 1, (size_t)(path + MAX_PATH - slash - 1), "triforce_commit_limit.txt");
FILE *f = fopen(path, "w");
if (!f) return;
fputs("Windows' commit limit (RAM and page file) was reached in the last session: the next start says so\n", f);
fclose(f);
}
static int commit_wait(void *p, SIZE_T size) {
static volatile LONG made, given_up;
hos_commit_limit_mark();
const int tries = host_alloc_tries(hos_commit_wait_ms()); /* ((Triforce, OS-04) 100 for the 5 s; 0: the refusal stands at once) */
for (int i = 0; i < tries; i++) {
Sleep(50);
@@ -940,6 +958,7 @@ static DWORD WINAPI sample_all_thread(void *p) {
const long ms = (long)((hos_now_ns() - t0) / 1000000);
for (int i = 0; i < nt; i++) {
if (SuspendThread(th[i]) == (DWORD)-1) continue;
const int64_t at = hos_now_ns(); /* ((Triforce, 11-26) the sample's own time: scripts/chain.py puts it on HOS_CHAIN's clock */
CONTEXT ctx = {0};
ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
const BOOL got = GetThreadContext(th[i], &ctx);
@@ -965,7 +984,7 @@ static DWORD WINAPI sample_all_thread(void *p) {
if (!unwind_step(&ctx, stack)) break;
}
ResumeThread(th[i]);
fprintf(out, "%s\n", line);
fprintf(out, "# at %lld\n%s\n", (long long)at, line);
}
}
return 0;
@@ -1243,11 +1262,66 @@ static void census_figures(GcCensus *c) {
#endif
}
/* ((Triforce, 11-26, diagnostics) HOS_HEAP_WALK=<seconds>: once, that long after the start, every heap of the process walked
(HeapLock, HeapWalk): its busy bytes and blocks by size, its committed regions, its biggest blocks. Which owner holds the
"heaps and other private memory" of the memory line (7 GB at the owner's spot). Never by default */
#ifdef _WIN32
#include <malloc.h>
static void heap_walk_report(void) {
HANDLE heaps[256];
const DWORD n = GetProcessHeaps(256, heaps);
const HANDLE proc = GetProcessHeap();
const HANDLE crt = (HANDLE)_get_heap_handle();
hos_log("mem: heap walk: %lu heaps (the process heap %p, the C runtime's %p)", (unsigned long)n, (void *)proc, (void *)crt);
for (DWORD i = 0; i < n && i < 256; i++) {
uint64_t busy = 0, committed = 0, uncommitted = 0, blocks = 0, by[6] = {0}, by_bytes[6] = {0}, top[6] = {0};
PROCESS_HEAP_ENTRY e;
memset(&e, 0, sizeof e);
if (!HeapLock(heaps[i])) continue;
const int64_t t0 = hos_now_ns();
while (HeapWalk(heaps[i], &e)) {
if (e.wFlags & PROCESS_HEAP_REGION) {
committed += e.Region.dwCommittedSize, uncommitted += e.Region.dwUnCommittedSize;
} else if (e.wFlags & PROCESS_HEAP_ENTRY_BUSY) {
const uint64_t sz = e.cbData;
busy += sz, blocks++;
const int k = sz < 256 ? 0 : sz < 4096 ? 1 : sz < 65536 ? 2 : sz < (1u << 20) ? 3 : sz < (16u << 20) ? 4 : 5;
by[k]++, by_bytes[k] += sz;
for (int t = 0; t < 6; t++)
if (sz > top[t]) {
for (int u = 5; u > t; u--) top[u] = top[u - 1];
top[t] = sz;
break;
}
}
}
HeapUnlock(heaps[i]);
if (busy < (16ull << 20)) continue; /* (the small ones: not the question) */
hos_log("mem: heap %p%s: %.0f MB busy in %llu blocks (regions committed %.0f MB, uncommitted %.0f MB; walked in %.0f ms); "
"by size: <256 B %llu (%.0f MB), <4 KB %llu (%.0f MB), <64 KB %llu (%.0f MB), <1 MB %llu (%.0f MB), <16 MB %llu (%.0f MB), "
"16 MB+ %llu (%.0f MB); biggest %.1f, %.1f, %.1f, %.1f, %.1f, %.1f MB",
(void *)heaps[i], heaps[i] == proc ? " (the process heap)" : heaps[i] == crt ? " (the C runtime's)" : "",
busy / 1048576.0, (unsigned long long)blocks, committed / 1048576.0, uncommitted / 1048576.0, (hos_now_ns() - t0) / 1e6,
(unsigned long long)by[0], by_bytes[0] / 1048576.0, (unsigned long long)by[1], by_bytes[1] / 1048576.0,
(unsigned long long)by[2], by_bytes[2] / 1048576.0, (unsigned long long)by[3], by_bytes[3] / 1048576.0,
(unsigned long long)by[4], by_bytes[4] / 1048576.0, (unsigned long long)by[5], by_bytes[5] / 1048576.0,
top[0] / 1048576.0, top[1] / 1048576.0, top[2] / 1048576.0, top[3] / 1048576.0, top[4] / 1048576.0, top[5] / 1048576.0);
}
}
#else
static void heap_walk_report(void) {}
#endif
static DWORD WINAPI census_main(void *unused) {
(void)unused;
hos_host_thread_register_self("hos memory census");
const char *hw = getenv("HOS_HEAP_WALK");
const int heap_walk_at = hw ? atoi(hw) : 0;
int elapsed = 0, heap_walked = 0;
for (;;) {
Sleep((DWORD)census_every * 1000);
elapsed += census_every;
if (heap_walk_at > 0 && !heap_walked && elapsed >= heap_walk_at) heap_walked = 1, heap_walk_report();
GcCensus c;
memset(&c, 0, sizeof c);
census_figures(&c);

View File

@@ -173,6 +173,14 @@ static int find_device(const Source *src, uint32_t *id) {
const int n = hos_sdl_mic_list(ids, names, MAX_DEVICES);
return pick(ids, names, n, src, id);
}
/* ((Triforce, 11-26) the system has a microphone at all: with none (Windows' Recording tab empty), SDL's open of the default
blocks for seconds before it fails (WASAPI: "can't find requested audio endpoint"), on the game's thread, at every retry:
a report had the Ocarina freeze the game 1 to 15 s at a time while it was out. The list is SDL's own, made at no cost) */
static int any_mic(void) {
uint32_t ids[MAX_DEVICES];
char names[MAX_DEVICES][128];
return hos_sdl_mic_list(ids, names, MAX_DEVICES) > 0;
}
static const char *wanted(const Source *src) { return src->mode == 2 ? src->want : "the default microphone"; }
static void close_mic(Source *src, int64_t now) {
if (src->mic) {
@@ -197,7 +205,7 @@ static void missed(Source *src, int64_t now, const char *why) {
}
static void stand_in(Source *src, int64_t now) { /* (the default, while the wanted one cannot be had) */
if (src->standin) return;
void *standin = hos_sdl_mic_open(0, src->rate, src->channels, sdl_format(src->format));
void *standin = any_mic() ? hos_sdl_mic_open(0, src->rate, src->channels, sdl_format(src->format)) : NULL;
if (standin) use(src, standin, 1, now);
else close_mic(src, now);
}
@@ -218,7 +226,7 @@ static void connect(Source *src) {
}
uint32_t id = 0; /* (the system's default) */
void *mic = NULL;
const int found = src->mode == 1 || find_device(src, &id);
const int found = src->mode == 1 ? any_mic() : find_device(src, &id);
if (found) mic = hos_sdl_mic_open(id, src->rate, src->channels, sdl_format(src->format));
if (mic) {
if (!src->failures) hos_log("audio in: %s open (%d Hz, %d channel%s)", wanted(src), src->rate, src->channels,

View File

@@ -930,7 +930,64 @@ static int event_wait_atomic(Obj *e, int64_t timeout_ns, int try_only) { /* (H
if (got && wake_lat_on()) wake_lat_note(slept ? 2 : 1, slept ? hos_now_ns() - signaled_at : 0);
return got;
}
/* (Triforce, 11-26) Which stage limits the frame. OoT's frame is two stages that overlap: the game's update (main thread and
its job threads) and the drawing (the Presentation Thread's submits, where the replay runs, and its present). They meet
twice a frame: the Presentation Thread waits for the main thread's hand-over of the next frame (a message queue receive,
lr 0x834a3084), and the main thread waits for the Presentation Thread's present (an event, lr 0x81207a6c). Whichever
side waits is the faster one. Every 5 s: "stages: ..." with both waits a frame and which stage limits. A test of a change to
one stage at a spot the other limits reads no gain (the drawing thread waited 2.7 ms a frame at the owner's spot, 11-26:
the game's update limited it). HOS_STAGE_LOG=0: off */
static int stage_on(void) {
static int on = -1;
if (on < 0) { const char *e = getenv("HOS_STAGE_LOG"); on = !(e && e[0] == '0'); }
return on;
}
static volatile LONG64 stage_ns[2], stage_t0, stage_p0;
static int stage_of(void) {
if (!stage_on()) return -1;
const Ctx *c = hos_ctx();
if (!c) return -1;
const int k = c->x[30] == 0x834a3084ULL ? 0 : c->x[30] == 0x81207a6cULL ? 1 : -1;
if (k < 0) return -1;
/* (the queue receive at 0x834a3084 is the game's own, its job threads wait there too: only the presenting thread's wait
and the main thread's count; the thread's kind looked up once) */
static _Thread_local int who = -1; /* (0 the Presentation Thread, 1 the main thread, 2 another) */
if (who < 0) {
HosThread *self = hos_self();
const char *n = self ? hos_thread_name(self) : NULL;
who = n && !strcmp(n, "Presentation Thread") ? 0 : n && !strcmp(n, "sead::MainThread") ? 1 : 2;
}
return who == k ? k : -1;
}
static void stage_note(int k, int64_t ns) {
extern volatile LONG64 hos_present_count; /* display.c */
InterlockedAdd64(&stage_ns[k], ns);
const int64_t now = hos_now_ns(), t0 = stage_t0;
if (!t0) { InterlockedCompareExchange64(&stage_t0, now, 0); stage_p0 = hos_present_count; return; }
if (now - t0 < 5000000000LL || InterlockedCompareExchange64(&stage_t0, now, t0) != t0) return;
const int64_t p = hos_present_count, frames = p - stage_p0;
stage_p0 = p;
const double draw_w = InterlockedExchange64(&stage_ns[0], 0) / 1e6, game_w = InterlockedExchange64(&stage_ns[1], 0) / 1e6;
if (frames <= 0) return;
const double dw = draw_w / (double)frames, gw = game_w / (double)frames, fms = (now - t0) / 1e6 / (double)frames;
const char *lim = dw >= 0.5 && dw > gw ? "the game's update (its threads; the drawing thread waits for it)"
: gw >= 0.5 && gw > dw ? "the drawing (the replay and the present; the game waits for it)"
: "neither by more than 0.5 ms (close)";
hos_log("stages (%lld frames, %.2f ms each): the drawing thread waited %.2f ms a frame for the game's hand-over, the game "
"waited %.2f ms a frame for the present: the frame is limited by %s (HOS_STAGE_LOG=0: off)", (long long)frames,
fms, dw, gw, lim);
}
static int event_wait_body(Obj *e, int64_t timeout_ns, int try_only);
static int event_wait(Obj *e, int64_t timeout_ns, int try_only) {
const int k = try_only ? -1 : stage_of();
if (k < 0) return event_wait_body(e, timeout_ns, try_only);
const int64_t t0 = hos_now_ns();
const int got = event_wait_body(e, timeout_ns, try_only);
stage_note(k, hos_now_ns() - t0);
return got;
}
static int event_wait_body(Obj *e, int64_t timeout_ns, int try_only) {
if (event_atomic()) return event_wait_atomic(e, timeout_ns, try_only);
int64_t deadline = timeout_ns > 0 ? hos_now_ns() + timeout_ns : 0;
const int was_set = e->signaled > 0;
@@ -1257,7 +1314,16 @@ static int queue_put(Obj *q, uint64_t v, int jam, int try_only) {
return 1;
}
/* take: remove it; timeout_ns: < 0 forever, 0 try, > 0 timed. Returns 1 if a value was read. */
static int queue_get(Obj *q, uint64_t *out, int take, int64_t timeout_ns) {
static int queue_get_body(Obj *q, uint64_t *out, int take, int64_t timeout_ns);
static int queue_get(Obj *q, uint64_t *out, int take, int64_t timeout_ns) { /* ((Triforce) the stage note: stage_of) */
const int k = timeout_ns != 0 ? stage_of() : -1;
if (k < 0) return queue_get_body(q, out, take, timeout_ns);
const int64_t t0 = hos_now_ns();
const int got = queue_get_body(q, out, take, timeout_ns);
stage_note(k, hos_now_ns() - t0);
return got;
}
static int queue_get_body(Obj *q, uint64_t *out, int take, int64_t timeout_ns) {
int64_t deadline = timeout_ns > 0 ? hos_now_ns() + timeout_ns : 0;
const int was_set = q->qlen > 0;
const int chain = timeout_ns != 0 && !was_set && hos_chain_on; /* ((Triforce) HOS_CHAIN) */

View File

@@ -1307,6 +1307,17 @@ NV(nvnSyncWait) {
(unsigned long long)s->fence, (unsigned long long)U64(1), (unsigned long long)c->x[30],
(unsigned long long)rx_nvn_fence(), (unsigned long long)rx_nvn_replayed());
if (!s->fenced) { RET(NVN_SYNC_WAIT_RESULT_TIMEOUT_EXPIRED); return; }
{ /* ((Triforce, 11-26, LAB ONLY) HOS_SYNC_SKIP_LR=<hex lr>: a blocking wait from that return address answers "signalled" at
once: what the game's own per-frame GPU wait costs, its readbacks left to their own write-back waits. NOT correct for
anything the game reads without a readback; never on by default) */
static uint64_t skip_lr = ~0ull;
if (skip_lr == ~0ull) skip_lr = getenv("HOS_SYNC_SKIP_LR") ? strtoull(getenv("HOS_SYNC_SKIP_LR"), NULL, 16) : 0;
if (skip_lr && c->x[30] == skip_lr && U64(1)) {
if (s->fenced == 1 && s->fence > rx_nvn_fence()) held_flush();
RET(NVN_SYNC_WAIT_RESULT_CONDITION_SATISFIED);
return;
}
}
if (s->fenced == 1 && s->fence > rx_nvn_fence()) held_flush(); /* (a wait flushes what it waits for) */
if (rx_nvn_wait(s->fence, 0)) { RET(NVN_SYNC_WAIT_RESULT_ALREADY_SIGNALED); return; }
static int block = -1; /* HOS_NVN_SYNC_BLOCK=1 (experiment): a poll waits for the GPU */

View File

@@ -31,7 +31,7 @@
void rx_option_set(int id, int value); /* rx_backend.c */
/* ((Triforce, 11-22) Both halves': the guest reads, a screen's list of entries and its buttons' boxes, and benchmark mode's
presses through the start's screens (bench_menu). Without them the Linux half pressed nothing, and the benchmark stood
on the title screen (#bug-tracker, 11-21). The mouse, Quit and Mods stay the Windows half's */
on the title screen (#bug-tracker, 11-21). The mouse, Quit and Mods are the first half's (Windows and Linux) */
#include <stdlib.h>
#include <string.h>
#include "hos_bench.h" /* ((Triforce, 11-19) benchmark mode) */
@@ -123,7 +123,10 @@ static void autoload_menu(uint64_t screen, uint64_t vt) {
if (hos_oot_autoload_menu(vt, l.index)) hos_hid_tap("0:A/120");
}
#if defined(_WIN32) && !defined(HOS_OOT_MENU_NO_MOUSE) /* (the macro: tests/test_oot_menu_mouse.py builds the other half on Windows) */
#if !defined(HOS_OOT_MENU_NO_MOUSE) /* (the macro: tests/test_oot_menu_mouse.py builds the other half. Linux runs this half too: the
System page's Mods and Quit entries (Quit Game / Restart Game: gpu/vk/vk_menu.cpp end_game, whose WM_CLOSE and WM_APP + 9
host/posix/display_sdl.c hos_posix_post_message takes as the Insert menu's). Its mouse bridges are inert there: no free
mouse in the game's menus, keyboard and pads only) */
#include <windows.h>
#include <ctype.h>
#include <stdio.h>
@@ -1238,7 +1241,7 @@ void hos_oot_menu_tick(Ctx *c, uint64_t screen) {
if (screen == pause_screen_now()) InterlockedIncrement(&ticks);
}
#else
/* Not Windows: the mouse in the game's menus is the Windows window's (display.c), not here. The game's own Options
/* HOS_OOT_MENU_NO_MOUSE (the tests' build): no mouse, Quit or Mods entry here. The game's own Options
screen is named all the same, each frame it runs, so the options' tabs sit in it as on Windows: they are the only way
to our options since the keys that opened them over the game went (gpu/vk/vk_menu.cpp overlay_allowed), and with this
left out a Linux build had none at all (2026-11-14). The screen is the one whose update the lifted game is running

View File

@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> /* ((Triforce, 11-26) sqrt: a stick's full push */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "hos_sdl.h"
@@ -801,6 +802,19 @@ static void pads_poll(void) {
the dead zone. The values are clamped already and the circle keeps them, so nothing else changes) */
hos_filter_stick((int16_t)v[0], (int16_t)v[1], z, own[0], v);
hos_filter_stick((int16_t)v[2], (int16_t)v[3], z, own[1], v + 2);
/* ((Triforce, 11-26, a player's input recording: "clicking the left stick stops rolling when moving forward") A
push past 92% of the travel is a full one, in its direction. SDL's Switch driver widens an axis's range to the
furthest it has read: after a hard click at full tilt the same full push forward read 31083, then ~30600 (93-95%),
and the game rolls only from a full one (angled pushes, past 32767 together, still rolled) */
for (int st = 0; st < 4; st += 2) {
const double m = sqrt((double)v[st] * v[st] + (double)v[st + 1] * v[st + 1]);
if (m >= 30146.0 && m < 32767.0) { /* (30146: 92% of 32767) */
for (int a = st; a < st + 2; a++) {
const double x = v[a] * 32767.0 / m;
v[a] = x >= 32767 ? 32767 : x <= -32767 ? -32767 : (int32_t)(x < 0 ? x - 0.5 : x + 0.5);
}
}
}
/* Camera inversion changes output, not whether the physical stick crossed its rest position. Otherwise
toggling the setting admits a held phantom axis, which stays admitted after the setting is restored. */
if (inv_x) v[2] = -v[2];

View File

@@ -432,6 +432,14 @@ void hos_pad_speaker_forget(void *pad) {
/* Headphones in the jack: what the pad says (-1: it does not say), or the switch over it, each second */
static void headphones(void *pad) {
int plugged = env_int("HOS_PAD_SPEAKER_HEADPHONES", -1, 0, 1);
/* ((Triforce, 11-26) the pad's jack read only while a row uses it: the Headphones row on, or a class of sounds sent to the
pad. Read every second with them all off (the default), a second handle on the DualSense drained its reports, and a
player's pad dropped seconds after each connection since v0.8.0 (unproven as the cause; the only new code on it) */
const int needed = atomic_read(&hp_mode) != HOS_PAD_HEADPHONES_OFF || atomic_read(&any_class);
if (plugged < 0 && !needed) {
hos_sdl_pad_headphones_release();
plugged = 0;
}
if (plugged < 0) plugged = pad ? hos_sdl_pad_headphones(pad) : 0;
if (plugged < 0) plugged = 0;
if (plugged != atomic_read(&hp_plugged)) hos_log("pad speaker: headphones %s the pad's jack", plugged ? "in" : "out of");

View File

@@ -41,6 +41,15 @@ int hos_mouse_take(int32_t *dx, int32_t *dy) {
/* (nn_hid.c) the game's menus do not take the mouse here: its capture, and with it its buttons, stay the game's */
int hos_mouse_in_game_menu(void) { return 0; }
/* (host/oot_menu.c's first half, built here for the System page's Mods and Quit entries: the game's menus get no free mouse
on this window, so it finds none (0) and leaves the cursor and the wheel alone; host/display.c has the Windows ones) */
void hos_mouse_game_menu(void) {}
void hos_mouse_game_menu_gone(void) {}
int hos_mouse_wheel_take(void) { return 0; }
int hos_mouse_game_pointer(int *x, int *y, int *w, int *h, uint32_t *pressed, int *wheel) {
*x = *y = *w = *h = 0, *pressed = 0, *wheel = 0;
return 0;
}
/* (mouse_native.c) motion taken and not used, put back for the next taker (the player camera's) */
void hos_mouse_give_back(int32_t dx, int32_t dy) {

View File

@@ -148,7 +148,9 @@ static int last_saved(int file, char *when, size_t when_cap, char *picture, size
/* ((Triforce) 11-18, his picture of the game's own load list beside the card: "the screenshot doesn't match the last
autosave either nor does the time". The slot written last cannot be told from the disk: the game writes them all
again whenever it saves one. Where the slots are, then, and the menu reads each one's own time out of it) */
if (saved && snprintf(picture, picture_cap, "%s\\save\\%s\\slot_", dir, fd.cFileName) >= (int)picture_cap) picture[0] = 0;
/* (the menu opens these with its own fopen, not through the Find shim: the folder's own separator, '/' on Linux) */
const char sep = strchr(dir, '\\') ? '\\' : '/';
if (saved && snprintf(picture, picture_cap, "%s%csave%c%s%cslot_", dir, sep, sep, fd.cFileName, sep) >= (int)picture_cap) picture[0] = 0;
/* ((Triforce) 11-18, his picture: File 2, a new game started and not yet saved, said "Saved game" with no picture. The
game makes account.sav as it starts on a file: a file has a save once it has a slot) */
if (!saved) when[0] = 0;