Files
Triforce-Source/host/oot_tex_compact.c
ruckus7382sfgsgdf 4fa4f9188b Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
2026-11-25 10:21:32 -06:00

121 lines
6.5 KiB
C

/* (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.
(Triforce) And before that, the ask: the manager's step (f_80797240) asks for a round at most once a second
(hos_oot_tex_compact_due, nx2/oot_patches.py patch_tex_ask; the rule and HOS_OOT_TEX_ASK_MS in oot_tex_compact.h). Asking
every frame against never, standing at the Market: 11.0% and 9.8% of frames of 16.7 ms or more against 3.0% and 1.2%. */
#include "hos.h"
#include "oot_tex_compact.h"
#include "input_movie.h" /* ((Triforce) HosMovieTime: the game clock's time while an input recording is recorded or played) */
#include <stdio.h>
#include <stdlib.h>
#include <windows.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;
}
}
/* (Triforce) Whether the manager's step may ask for a round now (patch_tex_ask: called where it would ask, with no round asked
for and the ask's bit set). The asks let through and held are logged every 10 s while there are any */
int hos_oot_tex_compact_due(void) {
static SRWLOCK lock = SRWLOCK_INIT;
static int ms = -2;
static int64_t last = -1, said;
static long let, held;
/* ((Triforce) the ask's clock: the wall's, or the game clock's while an input recording is recorded or played, so an
ask falls on the same frame of a replay as of its recording: host/input_movie.c; under the lock) */
int64_t hos_input_movie_time(HosMovieTime *t, int64_t wall_ns);
static HosMovieTime ask_time;
AcquireSRWLockExclusive(&lock);
if (ms == -2) {
const char *e = getenv("HOS_OOT_TEX_ASK_MS");
ms = hos_oot_tex_ask_ms(e);
if (ms > 0) hos_log("oot: texture compaction: at most one ask every %d ms (HOS_OOT_TEX_ASK_MS; 0: every ask, as shipped)", ms);
else hos_log("oot: texture compaction: %s (HOS_OOT_TEX_ASK_MS=%s)", ms ? "no ask let through" : "every ask, as shipped", e);
}
const int64_t now = hos_now_ns();
const int due = hos_oot_tex_ask_due(ms, hos_input_movie_time(&ask_time, now), &last);
if (due) let++;
else held++;
if (!said) said = now;
if (now - said >= 10000000000LL) {
if (let || held)
hos_log("oot: texture compaction asks in %.0f s: %ld let through, %ld held (HOS_OOT_TEX_ASK_MS=%d)",
(now - said) / 1e9, let, held, ms);
said = now, let = held = 0;
}
ReleaseSRWLockExclusive(&lock);
return due;
}