mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 04:55:56 +00:00
Keep every default in the settings table: cfg_value, cfg_int, cfg_double and cfg_bool read it, and the consumers of table keys drop their own defaults
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7b85a2681a
commit
8b514f6ead
25 files changed
+164
-102
No files matched your search
@@ -56,7 +56,7 @@ typedef struct Mixer {
|
||||
|
||||
static _Atomic float device_volume = 1.0f;
|
||||
|
||||
// TOTK_VOLUME: the player's volume in percent (0..100, default 100) on top of the game's own; a live setting (the
|
||||
// TOTK_VOLUME: the player's volume in percent (0..100) on top of the game's own; a live setting (the
|
||||
// menu), parsed again when cfg_version changes. Render thread only.
|
||||
static float host_volume(void) {
|
||||
static float v = 1.0f;
|
||||
@@ -64,10 +64,7 @@ static float host_volume(void) {
|
||||
unsigned ver = cfg_version();
|
||||
if (ver == seen) return v;
|
||||
seen = ver;
|
||||
const char *e = cfg_get("TOTK_VOLUME");
|
||||
char *end;
|
||||
double pct = e ? strtod(e, &end) : 100;
|
||||
if (!e || end == e || *end || pct != pct) pct = 100;
|
||||
double pct = cfg_double("TOTK_VOLUME");
|
||||
v = (float)((pct < 0 ? 0 : pct > 100 ? 100 : pct) / 100);
|
||||
return v;
|
||||
}
|
||||
|
||||
+34
-2
@@ -71,8 +71,9 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"TRACE", "diagnostics"}, {"FLIGHT", "diagnostics"}, {"FLIGHT_SPIKE_MS", "diagnostics"},
|
||||
};
|
||||
|
||||
// The settings the menu shows: the value each consumer uses when the key is unset, and what the key accepts. Defaults
|
||||
// are copied from the consumers (grep cfg_get("TOTK_<KEY>")); the consumers keep parsing as they do.
|
||||
// The settings the menu shows: the value in effect when the key is unset, and what the key accepts. The only place a
|
||||
// default lives: consumers read cfg_value / cfg_int / cfg_double / cfg_bool. A row with an empty default has no fixed
|
||||
// value (it depends on the machine); its consumer reads cfg_get and keeps an "unset" branch.
|
||||
#define LIVE 1
|
||||
#define RESTART 0
|
||||
static const CfgMeta metas[] = {
|
||||
@@ -254,6 +255,37 @@ const CfgMeta *cfg_meta(const char *key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const CfgMeta *cfg_meta_at(int i) { return i >= 0 && (size_t)i < sizeof metas / sizeof *metas ? &metas[i] : NULL; }
|
||||
|
||||
const char *cfg_value(const char *name) {
|
||||
const char *e = cfg_get(name);
|
||||
if (e && *e) return e;
|
||||
const CfgMeta *m = cfg_meta(name);
|
||||
if (!m) rt_fatal("cfg: %s has no row in the settings table", name);
|
||||
return m->def;
|
||||
}
|
||||
|
||||
// The row's default as a number, for a set value that does not parse.
|
||||
static double default_number(const char *name) {
|
||||
return strtod(cfg_meta(name)->def, NULL);
|
||||
}
|
||||
|
||||
double cfg_double(const char *name) {
|
||||
const char *v = cfg_value(name);
|
||||
char *end;
|
||||
double d = strtod(v, &end);
|
||||
return end == v || *end || d != d ? default_number(name) : d;
|
||||
}
|
||||
|
||||
int cfg_int(const char *name) {
|
||||
const char *v = cfg_value(name);
|
||||
char *end;
|
||||
long l = strtol(v, &end, 10);
|
||||
return end == v || *end ? (int)default_number(name) : (int)l;
|
||||
}
|
||||
|
||||
int cfg_bool(const char *name) { return strcmp(cfg_value(name), "0") != 0; }
|
||||
|
||||
// ---- cfg_save: the file as lines, each with its line ending
|
||||
typedef struct { const char *s; size_t n; } Line; // n includes the '\n' (and '\r') when present
|
||||
|
||||
|
||||
@@ -41,3 +41,15 @@ int cfg_last_save_ok(void);
|
||||
typedef struct { const char *key, *def, *values; int live; } CfgMeta;
|
||||
// The row of key (prefix and case ignored); NULL for a key the menu does not show.
|
||||
const CfgMeta *cfg_meta(const char *key);
|
||||
// The i-th row (0-based, table order); NULL past the last.
|
||||
const CfgMeta *cfg_meta_at(int i);
|
||||
|
||||
// The setting's value for consumers: the environment or totk.ini value, else the CfgMeta default. name has the TOTK_
|
||||
// prefix, like cfg_get; a name without a row is a bug (rt_fatal). A row with an empty default has no fixed value: its
|
||||
// consumer reads cfg_get and keeps its own "unset" branch. An empty value counts as unset.
|
||||
const char *cfg_value(const char *name);
|
||||
// cfg_value parsed. A set value that does not parse (int: whole string; double: strtod) gives the default's number.
|
||||
// cfg_bool: "0" is false, anything else true.
|
||||
int cfg_int(const char *name);
|
||||
double cfg_double(const char *name);
|
||||
int cfg_bool(const char *name);
|
||||
@@ -261,6 +261,53 @@ int probe_cfg(void) {
|
||||
CHECK((int64_t)st[0] * st[0] + (int64_t)st[1] * st[1] <= 32768ll * 32768, "mouse: clamped to the unit circle");
|
||||
input_mouse_stick(30, 0, 1.0 / 60, 0, st);
|
||||
CHECK(st[0] == 0 && st[1] == 0, "mouse: sensitivity 0 is off");
|
||||
// defaults live in the CfgMeta table: cfg_value and the typed accessors fall back to it
|
||||
cfg_load("cfg-probe-missing.ini");
|
||||
_putenv_s("TOTK_FPS60", "");
|
||||
_putenv_s("TOTK_MOUSE_SENS", "");
|
||||
_putenv_s("TOTK_FREE_CORES", "");
|
||||
CHECK(cfg_bool("TOTK_FPS60") == 1, "default: unset FPS60 is on");
|
||||
CHECK(EQ(cfg_value("TOTK_VK_PRESENT"), "mailbox") && cfg_int("TOTK_SPLIT_DRAWS") == 64, "default: text and integer");
|
||||
_putenv_s("TOTK_MOUSE_SENS", "2.5");
|
||||
CHECK(cfg_double("TOTK_MOUSE_SENS") == 2.5, "double: the environment value");
|
||||
_putenv_s("TOTK_MOUSE_SENS", "fast");
|
||||
CHECK(cfg_double("TOTK_MOUSE_SENS") == 1.0, "double: a value that does not parse gives the default");
|
||||
_putenv_s("TOTK_MOUSE_SENS", "");
|
||||
cfg_set("TOTK_MOUSE_SENS", "3");
|
||||
CHECK(cfg_double("TOTK_MOUSE_SENS") == 3.0 && cfg_int("TOTK_MOUSE_SENS") == 3, "a cfg_set value beats the default");
|
||||
CHECK(cfg_bool("TOTK_FREE_CORES") == 0, "free_cores unset: off");
|
||||
_putenv_s("TOTK_FREE_CORES", "0");
|
||||
CHECK(cfg_bool("TOTK_FREE_CORES") == 0, "free_cores 0 gives the same as unset");
|
||||
_putenv_s("TOTK_FREE_CORES", "1");
|
||||
CHECK(cfg_bool("TOTK_FREE_CORES") == 1, "free_cores 1: on");
|
||||
_putenv_s("TOTK_FREE_CORES", "");
|
||||
cfg_load("cfg-probe-missing.ini");
|
||||
int listed = 0;
|
||||
for (int i = 0; cfg_meta_at(i); i++) {
|
||||
const CfgMeta *m = cfg_meta_at(i);
|
||||
if (!*m->def) continue;
|
||||
listed++;
|
||||
char name[96];
|
||||
snprintf(name, sizeof name, "TOTK_%s", m->key);
|
||||
_putenv_s(name, "");
|
||||
CHECK(EQ(cfg_value(name), m->def), "cfg_value returns the table default");
|
||||
int ok = 0;
|
||||
if (!m->values) ok = 1;
|
||||
else if (strstr(m->values, "..")) {
|
||||
long lo = strtol(m->values, NULL, 10), hi = strtol(strstr(m->values, "..") + 2, NULL, 10);
|
||||
double d = strtod(m->def, NULL);
|
||||
ok = d >= (double)lo && d <= (double)hi;
|
||||
} else {
|
||||
size_t dl = strlen(m->def);
|
||||
for (const char *v = m->values; *v;) {
|
||||
size_t n = strcspn(v, "|");
|
||||
ok |= n == dl && !strncmp(v, m->def, n);
|
||||
v += n + (v[n] == '|');
|
||||
}
|
||||
}
|
||||
if (!ok) fprintf(stderr, "FAIL cfg: default '%s' of %s is not one of its values '%s'\n", m->def, m->key, m->values), fails++;
|
||||
}
|
||||
CHECK(listed >= 30, "the defaults table was walked");
|
||||
printf("probe-cfg: %s\n", fails ? "FAIL" : "ok");
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
+2
-3
@@ -65,13 +65,12 @@ static unsigned env_u(const char *name, unsigned def) {
|
||||
}
|
||||
|
||||
void flight_init(void) {
|
||||
const char *e = cfg_get("TOTK_FLIGHT");
|
||||
if (!e || strcmp(e, "1")) return;
|
||||
if (strcmp(cfg_value("TOTK_FLIGHT"), "1")) return;
|
||||
ring_n = (int)env_u("TOTK_FLIGHT_FRAMES", 600);
|
||||
if (ring_n < 64) ring_n = 64;
|
||||
if (ring_n > 7200) ring_n = 7200;
|
||||
if (!(ring = calloc((size_t)ring_n, sizeof *ring))) { rt_log("flight: no memory for %d records, off", ring_n); return; }
|
||||
spike_ns = (uint64_t)env_u("TOTK_FLIGHT_SPIKE_MS", 100) * 1000000ull;
|
||||
spike_ns = (uint64_t)cfg_int("TOTK_FLIGHT_SPIKE_MS") * 1000000ull;
|
||||
for (const char *p = cfg_get("TOTK_FLIGHT_AT"); p && *p && n_at < 16;) {
|
||||
char *end;
|
||||
unsigned long long f = strtoull(p, &end, 10);
|
||||
|
||||
@@ -83,8 +83,7 @@ static void frame_limit_live(void) {
|
||||
fps60_seen = v;
|
||||
if (fps60_set == -2) fps60_set = rt_patch_set("fps60");
|
||||
if (fps60_set < 0) return;
|
||||
const char *e = cfg_get("TOTK_FPS60");
|
||||
int on = e && *e ? strcmp(e, "0") != 0 : 1;
|
||||
int on = cfg_bool("TOTK_FPS60");
|
||||
if (on == rt_patch_enabled(fps60_set)) return;
|
||||
rt_patch_switch(fps60_set, on);
|
||||
rt_log("frame rate: limit %d fps (TOTK_FPS60=%d)", on ? 60 : 30, on);
|
||||
|
||||
+12
-15
@@ -184,17 +184,16 @@ static WINDOWPLACEMENT g_saved_place = {sizeof g_saved_place}; // the window b
|
||||
|
||||
static int is_fullscreen(HWND h) { return !(GetWindowLongW(h, GWL_STYLE) & WS_OVERLAPPEDWINDOW); }
|
||||
|
||||
// TOTK_FULLSCREEN=1: borderless window over the monitor. TOTK_WINDOW_SIZE=<w>x<h>: client area of the window, default
|
||||
// 1920x1080 (the swapchain follows the window; the game image is scaled to it).
|
||||
// TOTK_FULLSCREEN=1: borderless window over the monitor. TOTK_WINDOW_SIZE=<w>x<h>: client area of the window (the
|
||||
// swapchain follows the window; the game image is scaled to it).
|
||||
static int cfg_fullscreen(void) {
|
||||
const char *e = cfg_get("TOTK_FULLSCREEN");
|
||||
return e && !strcmp(e, "1");
|
||||
return cfg_bool("TOTK_FULLSCREEN");
|
||||
}
|
||||
|
||||
static void cfg_window_size(int *w, int *h) {
|
||||
const char *e = cfg_get("TOTK_WINDOW_SIZE");
|
||||
int x = 0, y = 0;
|
||||
if (!e || sscanf(e, "%dx%d", &x, &y) != 2 || x < 640 || y < 360 || x > 7680 || y > 4320) x = 1920, y = 1080;
|
||||
if (sscanf(cfg_value("TOTK_WINDOW_SIZE"), "%dx%d", &x, &y) != 2 || x < 640 || y < 360 || x > 7680 || y > 4320)
|
||||
sscanf(cfg_meta("WINDOW_SIZE")->def, "%dx%d", &x, &y); // unparsable or out of range: the default
|
||||
*w = x;
|
||||
*h = y;
|
||||
}
|
||||
@@ -223,16 +222,14 @@ static char g_applied_size[32];
|
||||
static int g_applied_fs;
|
||||
|
||||
static void note_applied(void) {
|
||||
const char *e = cfg_get("TOTK_WINDOW_SIZE");
|
||||
snprintf(g_applied_size, sizeof g_applied_size, "%s", e ? e : "");
|
||||
snprintf(g_applied_size, sizeof g_applied_size, "%s", cfg_value("TOTK_WINDOW_SIZE"));
|
||||
g_applied_fs = cfg_fullscreen();
|
||||
}
|
||||
|
||||
// Window thread: the window takes the size and fullscreen state of the settings when they changed. In fullscreen the
|
||||
// size goes into the placement restored when fullscreen ends.
|
||||
static void apply_settings(HWND h) {
|
||||
const char *e = cfg_get("TOTK_WINDOW_SIZE");
|
||||
int size_changed = strcmp(e ? e : "", g_applied_size) != 0, fs = cfg_fullscreen(), fs_changed = fs != g_applied_fs;
|
||||
int size_changed = strcmp(cfg_value("TOTK_WINDOW_SIZE"), g_applied_size) != 0, fs = cfg_fullscreen(), fs_changed = fs != g_applied_fs;
|
||||
note_applied();
|
||||
if (size_changed) {
|
||||
int cw, ch;
|
||||
@@ -272,9 +269,9 @@ static void window_settings_live(void) {
|
||||
unsigned v = cfg_version();
|
||||
if (started && v == seen) return;
|
||||
seen = v;
|
||||
const char *e = cfg_get("TOTK_VK_PRESENT");
|
||||
if (!started || strncmp(e ? e : "", present, sizeof present - 1)) {
|
||||
snprintf(present, sizeof present, "%s", e ? e : "");
|
||||
const char *e = cfg_value("TOTK_VK_PRESENT");
|
||||
if (!started || strncmp(e, present, sizeof present - 1)) {
|
||||
snprintf(present, sizeof present, "%s", e);
|
||||
if (started) InterlockedExchange(&g_dirty, 1);
|
||||
}
|
||||
if (started) gfx_window_apply_settings();
|
||||
@@ -364,8 +361,8 @@ static DWORD WINAPI window_main(void *arg) {
|
||||
|
||||
// ---- swapchain
|
||||
static VkPresentModeKHR pick_present_mode(VkPhysicalDevice pd) {
|
||||
const char *e = cfg_get("TOTK_VK_PRESENT");
|
||||
VkPresentModeKHR want = !e || !strcmp(e, "mailbox") ? VK_PRESENT_MODE_MAILBOX_KHR
|
||||
const char *e = cfg_value("TOTK_VK_PRESENT");
|
||||
VkPresentModeKHR want = !strcmp(e, "mailbox") ? VK_PRESENT_MODE_MAILBOX_KHR
|
||||
: !strcmp(e, "immediate") ? VK_PRESENT_MODE_IMMEDIATE_KHR : VK_PRESENT_MODE_FIFO_KHR;
|
||||
uint32_t n = 0;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(pd, g_surface, &n, NULL);
|
||||
|
||||
+4
-9
@@ -134,7 +134,7 @@ static void rec_flush_all(void) {
|
||||
|
||||
static void rec_apply(uint64_t b, const int32_t sl[2], const int32_t sr[2]) {
|
||||
if (!rec_state) {
|
||||
const char *path = cfg_get("TOTK_INPUT_RECORD");
|
||||
const char *path = cfg_get("TOTK_INPUT_RECORD"); // no default: not recording when unset
|
||||
rec = path && *path ? fopen(path, "w") : NULL;
|
||||
rec_state = rec ? 1 : -1;
|
||||
if (path && *path && !rec) rt_log("input: cannot open TOTK_INPUT_RECORD %s", path);
|
||||
@@ -203,10 +203,7 @@ static float mouse_sens_get(void) {
|
||||
unsigned ver = cfg_version();
|
||||
if (mouse_sens >= 0 && ver == mouse_sens_seen) return mouse_sens;
|
||||
mouse_sens_seen = ver;
|
||||
const char *e = cfg_get("TOTK_MOUSE_SENS");
|
||||
char *end;
|
||||
double v = e ? strtod(e, &end) : 1;
|
||||
if (!e || end == e || *end || v != v) v = 1;
|
||||
double v = cfg_double("TOTK_MOUSE_SENS");
|
||||
mouse_sens = (float)(v < 0 ? 0 : v > 10 ? 10 : v);
|
||||
return mouse_sens;
|
||||
}
|
||||
@@ -480,8 +477,7 @@ uint16_t rumble_motor(float a, float curve, float strength) {
|
||||
}
|
||||
|
||||
int input_rumble_triggers_enabled(void) {
|
||||
const char *e = cfg_get("TOTK_RUMBLE_TRIGGERS");
|
||||
return e && !strcmp(e, "1");
|
||||
return cfg_bool("TOTK_RUMBLE_TRIGGERS");
|
||||
}
|
||||
|
||||
int input_rumble(uint16_t low, uint16_t high, uint32_t ms) {
|
||||
@@ -538,8 +534,7 @@ int input_motion_enabled(void) {
|
||||
unsigned v = cfg_version();
|
||||
if (on < 0 || v != seen) {
|
||||
seen = v;
|
||||
const char *e = cfg_get("TOTK_MOTION");
|
||||
on = !(e && !strcmp(e, "0"));
|
||||
on = cfg_bool("TOTK_MOTION");
|
||||
}
|
||||
return on;
|
||||
}
|
||||
|
||||
+4
-5
@@ -266,8 +266,7 @@ static void ap_init(void);
|
||||
|
||||
static int cores_enabled(void) {
|
||||
if (g_cores_on < 0) {
|
||||
const char *fc = cfg_get("TOTK_FREE_CORES");
|
||||
g_cores_on = fc && strcmp(fc, "0") ? 0 : 1; // "0" keeps the gate, like unset
|
||||
g_cores_on = !cfg_bool("TOTK_FREE_CORES"); // "0" keeps the gate, like unset
|
||||
diag_init();
|
||||
ap_init();
|
||||
}
|
||||
@@ -308,9 +307,9 @@ void kern_ap_stub(void);
|
||||
|
||||
static void ap_init(void) {
|
||||
if (g_ap >= 0) return;
|
||||
const char *e = cfg_get("TOTK_ASYNC_PREEMPT");
|
||||
g_ap = !(e && !strcmp(e, "0"));
|
||||
g_ap_int = g_ap && !(e && !strcmp(e, "2"));
|
||||
const char *e = cfg_value("TOTK_ASYNC_PREEMPT");
|
||||
g_ap = strcmp(e, "0") != 0;
|
||||
g_ap_int = g_ap && strcmp(e, "2") != 0;
|
||||
if (g_ap) {
|
||||
RtModule m[16];
|
||||
int n = rt_linked_modules(m, 16);
|
||||
|
||||
@@ -417,8 +417,7 @@ static void test_cores(Cpu *c) {
|
||||
int now, held_max;
|
||||
kern_core_stats(&now, &held_max);
|
||||
DWORD cpus = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||
const char *fc = cfg_get("TOTK_FREE_CORES");
|
||||
int gate = !fc || !strcmp(fc, "0"); // the kernel's own switch
|
||||
int gate = !cfg_bool("TOTK_FREE_CORES"); // the kernel's own switch
|
||||
int ok = g_run_max <= 3 && held_max <= 3 && !g_core_clash && (cpus < 4 || g_run_max == 3);
|
||||
printf("virtual cores: %d threads x %d runs on %lu host CPUs: at most %ld running guest code at once, at most %d "
|
||||
"core holders (kernel count), %ld core-number clashes: %s\n", CORE_WORKERS, CORE_RUNS, cpus, g_run_max,
|
||||
|
||||
+2
-3
@@ -47,7 +47,7 @@ void rt_log(const char *fmt, ...) {
|
||||
}
|
||||
|
||||
static void parse_trace(void) {
|
||||
const char *e = cfg_get("TOTK_TRACE");
|
||||
const char *e = cfg_get("TOTK_TRACE"); // no default: nothing is traced when unset
|
||||
if (!e) return;
|
||||
static const struct { const char *name; unsigned bit; } names[] = {
|
||||
{"svc", RT_TRACE_SVC}, {"host", RT_TRACE_HOSTCALL}, {"ipc", RT_TRACE_IPC}, {"fs", RT_TRACE_FS},
|
||||
@@ -433,8 +433,7 @@ int main(int argc, char **argv) {
|
||||
prof_start();
|
||||
// Timed guest waits (kernel.c block_inner) sleep in whole milliseconds; at the default 15.6 ms tick a 1 ms wait
|
||||
// costs a full tick. TOTK_TIMER_1MS=0 keeps the default for comparison.
|
||||
const char *tick = cfg_get("TOTK_TIMER_1MS");
|
||||
if (!tick || strcmp(tick, "0")) timeBeginPeriod(1);
|
||||
if (cfg_bool("TOTK_TIMER_1MS")) timeBeginPeriod(1);
|
||||
cfg = (RtConfig){.exefs = rt_default_exefs, .romfs = rt_default_romfs, .profile = rt_default_profile,
|
||||
.gpu = cfg_get("TOTK_GPU")};
|
||||
portable_paths(&cfg); // command-line paths below still win
|
||||
|
||||
@@ -605,8 +605,7 @@ static void obs_release_read(Cpu *c) {
|
||||
if (lr != 0x70008c70c8ull) return;
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_LOD_GUARD");
|
||||
on = !(e && !strcmp(e, "0"));
|
||||
on = cfg_bool("TOTK_LOD_GUARD");
|
||||
}
|
||||
if (!on || *(volatile uint8_t *)(uintptr_t)(obj + 0x528) != *(volatile uint8_t *)(uintptr_t)(obj + 0x529)) return;
|
||||
uint64_t e = __atomic_load_n(&lod_entered, __ATOMIC_SEQ_CST);
|
||||
|
||||
+4
-7
@@ -193,19 +193,16 @@ static void once(volatile long *flag, const char *fmt, uint32_t v) {
|
||||
static float rumble_strength = 1.3f, rumble_curve = 0.6f;
|
||||
static volatile long rumble_cfg_logged;
|
||||
static unsigned rumble_cfg_seen = ~0u;
|
||||
static float cfg_float(const char *name, float def, float lo, float hi) {
|
||||
const char *e = cfg_get(name);
|
||||
char *end;
|
||||
double v = e ? strtod(e, &end) : 0;
|
||||
if (!e || end == e || *end || v != v) return def;
|
||||
static float cfg_float(const char *name, float lo, float hi) {
|
||||
double v = cfg_double(name);
|
||||
return (float)(v < lo ? lo : v > hi ? hi : v);
|
||||
}
|
||||
static void rumble_cfg(void) {
|
||||
unsigned v = cfg_version();
|
||||
if (v == rumble_cfg_seen) return;
|
||||
rumble_cfg_seen = v;
|
||||
rumble_strength = cfg_float("TOTK_RUMBLE_STRENGTH", 130, 0, 300) / 100;
|
||||
rumble_curve = cfg_float("TOTK_RUMBLE_CURVE", 0.6f, 0.2f, 1.5f);
|
||||
rumble_strength = cfg_float("TOTK_RUMBLE_STRENGTH", 0, 300) / 100;
|
||||
rumble_curve = cfg_float("TOTK_RUMBLE_CURVE", 0.2f, 1.5f);
|
||||
int trig = input_rumble_triggers_enabled();
|
||||
if (!InterlockedExchange(&rumble_cfg_logged, 1))
|
||||
rt_log("hid: rumble strength %.0f%%, curve %.2f, triggers %s", rumble_strength * 100, rumble_curve, trig ? "on" : "off");
|
||||
|
||||
+3
-3
@@ -43,8 +43,8 @@ int ov_handheld(void) {
|
||||
static volatile LONG v = -1;
|
||||
LONG h = v;
|
||||
if (h < 0) {
|
||||
const char *e = cfg_get("TOTK_OPERATION_MODE");
|
||||
if (!e || !strcmp(e, "docked")) h = 0;
|
||||
const char *e = cfg_value("TOTK_OPERATION_MODE");
|
||||
if (!strcmp(e, "docked")) h = 0;
|
||||
else if (!strcmp(e, "handheld")) h = 1;
|
||||
else rt_fatal("TOTK_OPERATION_MODE must be docked or handheld, not '%s'", e);
|
||||
if (InterlockedCompareExchange(&v, h, -1) == -1)
|
||||
@@ -92,7 +92,7 @@ static const char *switch_language(const char *tag) {
|
||||
const char *ov_language(void) {
|
||||
static const char *const codes[] = {"ja", "en-US", "fr", "de", "it", "es", "zh-CN", "ko", "nl", "pt", "ru",
|
||||
"zh-TW", "en-GB", "fr-CA", "es-419", "zh-Hans", "zh-Hant", "pt-BR"};
|
||||
const char *code = cfg_get("TOTK_LANG");
|
||||
const char *code = cfg_get("TOTK_LANG"); // no fixed default: TOTK_LOCALE or the Windows user locale decides when unset
|
||||
if (code && *code) {
|
||||
for (size_t i = 0; i < sizeof codes / sizeof *codes; i++)
|
||||
if (!strcmp(code, codes[i])) return codes[i];
|
||||
|
||||
+2
-1
@@ -45,7 +45,8 @@ void rt_patches_init(void) {
|
||||
list[0] = 0;
|
||||
for (int i = 0; i < RT_PATCH_COUNT; i++) {
|
||||
const char *e = cfg_get(sets[i].env);
|
||||
rt_patch_on[i] = (uint8_t)(e && *e ? strcmp(e, "0") != 0 : sets[i].on);
|
||||
// a set with a row in the settings table takes its default from there; the generated default serves the rest
|
||||
rt_patch_on[i] = (uint8_t)(cfg_meta(sets[i].env) ? cfg_bool(sets[i].env) : e && *e ? strcmp(e, "0") != 0 : sets[i].on);
|
||||
n += (size_t)snprintf(list + n, sizeof list - n, "%s%s %s", i ? ", " : "", sets[i].name,
|
||||
rt_patch_on[i] ? "on" : "off");
|
||||
if (n >= sizeof list) n = sizeof list - 1;
|
||||
|
||||
+2
-2
@@ -309,8 +309,8 @@ int vk_astc_mode(void) {
|
||||
AcquireSRWLockExclusive(&g_lock);
|
||||
reset_for(c);
|
||||
if (G.mode < 0) {
|
||||
const char *e = cfg_get("TOTK_ASTC");
|
||||
int want = !e || !*e || !strcmp(e, "auto") ? -1 : !strcmp(e, "cpu") ? VK_ASTC_CPU : !strcmp(e, "gpu") ? VK_ASTC_GPU
|
||||
const char *e = cfg_value("TOTK_ASTC");
|
||||
int want = !strcmp(e, "auto") ? -1 : !strcmp(e, "cpu") ? VK_ASTC_CPU : !strcmp(e, "gpu") ? VK_ASTC_GPU
|
||||
: !strcmp(e, "native") ? VK_ASTC_NATIVE : !strcmp(e, "check") ? VK_ASTC_CHECK : -2;
|
||||
if (want == -2) rt_log("vk: TOTK_ASTC=%s is not cpu, gpu, native, check or auto: auto", e), want = -1;
|
||||
if ((want == -1 || want == VK_ASTC_NATIVE) && native_device(c)) m = VK_ASTC_NATIVE;
|
||||
|
||||
@@ -169,8 +169,7 @@ static uint64_t ck_reads, ck_diff, ck_diff_unexplained, ck_diff_idle;
|
||||
int vk_replay_async(void) {
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_REPLAY_ASYNC");
|
||||
on = e && !strcmp(e, "1"); // off by default: no measured gain yet, one more frame of latency
|
||||
on = cfg_bool("TOTK_REPLAY_ASYNC"); // off by default: no measured gain yet, one more frame of latency
|
||||
rt_log("vk: replay %s (TOTK_REPLAY_ASYNC=%d)",
|
||||
on ? "on its own thread, at most one frame behind the game" : "on the submitting thread", on);
|
||||
}
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ int vk_caps_gpl(const VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT *f,
|
||||
const VkPhysicalDeviceGraphicsPipelineLibraryPropertiesEXT *p) {
|
||||
gpl_lib = f->graphicsPipelineLibrary;
|
||||
gpl_fast = p->graphicsPipelineLibraryFastLinking;
|
||||
vk_caps.gpl = gpl_lib && gpl_fast && env_u32("TOTK_GPL", 1);
|
||||
vk_caps.gpl = gpl_lib && gpl_fast && cfg_bool("TOTK_GPL");
|
||||
return vk_caps.gpl;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void vk_caps_init(VkCtx *c) {
|
||||
vk_caps.sbuf_align = l->minStorageBufferOffsetAlignment > 4 ? (uint32_t)l->minStorageBufferOffsetAlignment : 0;
|
||||
|
||||
uint32_t want = env_u32("TOTK_VK_SUBGROUP", 32);
|
||||
int pin = f13.subgroupSizeControl && env_u32("TOTK_VK_SUBGROUP_PIN", 1) && p13.minSubgroupSize <= want &&
|
||||
int pin = f13.subgroupSizeControl && cfg_bool("TOTK_VK_SUBGROUP_PIN") && p13.minSubgroupSize <= want &&
|
||||
want <= p13.maxSubgroupSize;
|
||||
vk_caps.sg_size = want;
|
||||
vk_caps.sg_pin_stages = pin ? p13.requiredSubgroupSizeStages : 0;
|
||||
|
||||
+2
-3
@@ -45,8 +45,7 @@ static int create_instance(void) {
|
||||
const char *ext[4] = {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME};
|
||||
uint32_t n_ext = 2;
|
||||
const char *layers[] = {"VK_LAYER_KHRONOS_validation"};
|
||||
const char *v = cfg_get("TOTK_VK_VALIDATION");
|
||||
int validate = v && *v && *v != '0';
|
||||
int validate = cfg_bool("TOTK_VK_VALIDATION");
|
||||
if (validate && !layer_present(layers[0])) {
|
||||
rt_log("vk: TOTK_VK_VALIDATION set but %s is not installed; continuing without", layers[0]);
|
||||
validate = 0;
|
||||
@@ -115,7 +114,7 @@ static int pick_device(void) {
|
||||
if (!n) { rt_log("vk: no Vulkan device"); return 0; }
|
||||
VkPhysicalDevice *pd = calloc(n, sizeof *pd);
|
||||
vkEnumeratePhysicalDevices(g_vk.instance, &n, pd);
|
||||
const char *e = cfg_get("TOTK_GPU_INDEX");
|
||||
const char *e = cfg_get("TOTK_GPU_INDEX"); // no fixed default: the best device when unset
|
||||
int want = e && *e ? atoi(e) : -1;
|
||||
const char *name = cfg_get("TOTK_GPU_NAME");
|
||||
int best = -1, best_score = -1;
|
||||
|
||||
+1
-2
@@ -599,8 +599,7 @@ static uint64_t n_parts, n_subs;
|
||||
|
||||
static void maybe_split(VkExec *ex) {
|
||||
if (split_n < 0) {
|
||||
const char *e = cfg_get("TOTK_SPLIT_DRAWS");
|
||||
split_n = e ? atoi(e) : 64;
|
||||
split_n = cfg_int("TOTK_SPLIT_DRAWS");
|
||||
if (split_n < 0) split_n = 0;
|
||||
rt_log("vk: replay command buffer split every %d draws between passes%s", split_n, split_n ? "" : " (off)");
|
||||
}
|
||||
|
||||
+8
-10
@@ -725,8 +725,7 @@ void vk_c0_fill(uint8_t bank[VK_C0_BYTES], int stage, const p_bind_buf ssbo[16],
|
||||
static int c0_on(void) { // TOTK_FIX_C0=0: c0 reads zeros, as in M4
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_FIX_C0");
|
||||
on = !(e && !strcmp(e, "0"));
|
||||
on = cfg_bool("TOTK_FIX_C0");
|
||||
}
|
||||
return on;
|
||||
}
|
||||
@@ -1043,8 +1042,7 @@ static void repeat_stats(const VkExec *ex, const VkPipeInfo *info) {
|
||||
static int push_skip_on(void) { // TOTK_PUSH_SKIP=0: every graphics draw pushes its set again
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_PUSH_SKIP");
|
||||
on = !(e && !strcmp(e, "0"));
|
||||
on = cfg_bool("TOTK_PUSH_SKIP");
|
||||
}
|
||||
return on;
|
||||
}
|
||||
@@ -1068,8 +1066,8 @@ static int push_skip_on(void) { // TOTK_PUSH_SKIP=0: every graphics draw pushe
|
||||
// writes, census counts or descriptor commands.
|
||||
static int bind_skip_on(void) {
|
||||
if (RS.on < 0) {
|
||||
const char *e = cfg_get("TOTK_BIND_SKIP");
|
||||
RS.on = e && !strcmp(e, "check") ? 2 : !(e && !strcmp(e, "0"));
|
||||
const char *e = cfg_value("TOTK_BIND_SKIP");
|
||||
RS.on = !strcmp(e, "check") ? 2 : strcmp(e, "0") != 0;
|
||||
if (RS.on != 1) rt_log("vk_exec: descriptor build skip %s", RS.on ? "check" : "off");
|
||||
}
|
||||
return RS.on;
|
||||
@@ -1458,8 +1456,8 @@ static void bind_vertex_buffers(VkExec *ex) {
|
||||
static int pipe_skip_mode(void) {
|
||||
static int mode = -1;
|
||||
if (mode < 0) {
|
||||
const char *e = cfg_get("TOTK_PIPE_SKIP");
|
||||
mode = !e || !*e ? 1 : !strcmp(e, "strict") || !strcmp(e, "0") ? 0 : !strcmp(e, "fullscreen") || !strcmp(e, "2") ? 2 : 1;
|
||||
const char *e = cfg_value("TOTK_PIPE_SKIP");
|
||||
mode = !strcmp(e, "strict") || !strcmp(e, "0") ? 0 : !strcmp(e, "fullscreen") || !strcmp(e, "2") ? 2 : 1;
|
||||
static const char *const what[3] = {"only draws into per-frame passes (TOTK_PIPE_SKIP=strict)",
|
||||
"draws into passes with a target the previous frame rendered",
|
||||
"those and full-screen draws (TOTK_PIPE_SKIP=fullscreen)"};
|
||||
@@ -1499,8 +1497,8 @@ static int memo_match(const VkExec *ex, uint32_t gen, const MemoKey *k) {
|
||||
|
||||
static int shader_memo_on(void) {
|
||||
if (SM.on < 0) {
|
||||
const char *e = cfg_get("TOTK_SHADER_MEMO");
|
||||
SM.on = e && !strcmp(e, "check") ? 2 : !(e && !strcmp(e, "0"));
|
||||
const char *e = cfg_value("TOTK_SHADER_MEMO");
|
||||
SM.on = !strcmp(e, "check") ? 2 : strcmp(e, "0") != 0;
|
||||
}
|
||||
return SM.on;
|
||||
}
|
||||
|
||||
@@ -908,7 +908,7 @@ int probe_vkexec(void) {
|
||||
nvnx_bytes);
|
||||
printf("probe-vkexec: c0 and zero parts passed (c0 tables, dispatch size, point size and base instance at their offsets, "
|
||||
"unbound slots zero; %d bytes of an unwritten physical-pool texture read zero, TOTK_FIX_ZERO=%s)\n",
|
||||
zero_bytes, cfg_get("TOTK_FIX_ZERO") ? cfg_get("TOTK_FIX_ZERO") : "1");
|
||||
zero_bytes, cfg_value("TOTK_FIX_ZERO"));
|
||||
if (vk_mirror_on)
|
||||
printf("probe-vkexec: mirror part passed (B2B and fill in a VRAM mirror written back by the fence, a CPU write "
|
||||
"between submissions mirrored, CPU bytes beside a fill kept, %d bytes compared)\n", mirror_bytes);
|
||||
|
||||
+3
-4
@@ -213,8 +213,7 @@ static int alloc_physical(VkCtx *c, PoolRec *r) {
|
||||
int vk_fix_zero(void) {
|
||||
static int on = -1;
|
||||
if (on < 0) {
|
||||
const char *e = cfg_get("TOTK_FIX_ZERO");
|
||||
on = !(e && !strcmp(e, "0"));
|
||||
on = cfg_bool("TOTK_FIX_ZERO");
|
||||
}
|
||||
return on;
|
||||
}
|
||||
@@ -969,10 +968,10 @@ static volatile LONG64 m_live_n, m_live_bytes, m_refused_n[MR_N], m_refused_byte
|
||||
static volatile LONG64 m_flush_calls, m_flush_bytes, v_pages, v_skipped, v_mismatch;
|
||||
|
||||
static void mirror_mode(int discrete) {
|
||||
const char *e = cfg_get("TOTK_MEMORY");
|
||||
const char *e = cfg_value("TOTK_MEMORY");
|
||||
int mode = discrete ? 1 : 0; // 0 import, 1 mirror, 2 verify
|
||||
const char *why = discrete ? "auto, discrete gpu" : "auto, uma";
|
||||
if (e && *e && strcmp(e, "auto")) {
|
||||
if (strcmp(e, "auto")) {
|
||||
if (!strcmp(e, "import")) mode = 0, why = "TOTK_MEMORY=import";
|
||||
else if (!strcmp(e, "mirror")) mode = 1, why = "TOTK_MEMORY=mirror";
|
||||
else if (!strcmp(e, "verify")) mode = 2, why = "TOTK_MEMORY=verify";
|
||||
|
||||
+12
-15
@@ -251,8 +251,7 @@ static int ensure_init(void) {
|
||||
// Descriptor update templates (core 1.1; the push variant comes with VK_KHR_push_descriptor on 1.1): the driver
|
||||
// walks a layout prepared when the layout is made instead of parsing write structs every draw (DXVK does so for the
|
||||
// same reason). TOTK_DESC_TEMPLATE=0 keeps the write structs.
|
||||
const char *dt = cfg_get("TOTK_DESC_TEMPLATE");
|
||||
if (dt && !strcmp(dt, "0")) {
|
||||
if (!cfg_bool("TOTK_DESC_TEMPLATE")) {
|
||||
rt_log("vk_pipeline: descriptor update templates off (TOTK_DESC_TEMPLATE=0)");
|
||||
} else if (c->props.apiVersion >= VK_API_VERSION_1_1 && PROC(tpl_create, "vkCreateDescriptorUpdateTemplate") &&
|
||||
PROC(tpl_destroy, "vkDestroyDescriptorUpdateTemplate") && PROC(tpl_update, "vkUpdateDescriptorSetWithTemplate")) {
|
||||
@@ -265,7 +264,7 @@ static int ensure_init(void) {
|
||||
// TOTK_VK_DYN_VERTEX=0/1 forces dynamic vertex input off or on. Default off on Intel's frozen Windows driver for its
|
||||
// older integrated GPUs (UHD 630, Ice Lake: Vulkan 1.3.215 and older), which draws nothing with it (LAS Recomp
|
||||
// 61fe44ff, its issues #8 and #357).
|
||||
const char *dv = cfg_get("TOTK_VK_DYN_VERTEX");
|
||||
const char *dv = cfg_get("TOTK_VK_DYN_VERTEX"); // no fixed default: it depends on the GPU, see above
|
||||
int intel_legacy = c->props.vendorID == 0x8086 && c->props.apiVersion <= VK_MAKE_API_VERSION(0, 1, 3, 215);
|
||||
int dv_on = dv && *dv ? strcmp(dv, "0") != 0 : !intel_legacy;
|
||||
P.dyn_vi = dv_on && c->has_vertex_input_dynamic_state && PROC(set_vi, "vkCmdSetVertexInputEXT");
|
||||
@@ -2119,8 +2118,7 @@ static void workers_drain(void) {
|
||||
}
|
||||
|
||||
void vk_pipeline_async_enable(void) {
|
||||
const char *w = cfg_get("TOTK_PIPE_WAIT");
|
||||
U.on = !(w && !strcmp(w, "draw"));
|
||||
U.on = strcmp(cfg_value("TOTK_PIPE_WAIT"), "draw") != 0;
|
||||
const char *e = cfg_get("TOTK_PIPE_SYNC");
|
||||
if (e && *e && strcmp(e, "0")) return;
|
||||
A.on = 1;
|
||||
@@ -2405,10 +2403,10 @@ static DWORD WINAPI warm_builder(void *arg) {
|
||||
static void lb_start(const uint32_t pr_hist[16], const uint32_t fs_hist[4]);
|
||||
|
||||
void vk_pipeline_prewarm(void) {
|
||||
const char *e = cfg_get("TOTK_PIPE_PREBUILD"), *gpu = rt_config()->gpu;
|
||||
const char *gpu = rt_config()->gpu;
|
||||
uint32_t pr_hist[16] = {0}, fs_hist[4] = {0}; // library state of the recorded pipelines (lb_start)
|
||||
if (!A.on || (gpu && !strcmp(gpu, "null"))) return;
|
||||
if (e && !strcmp(e, "0")) { // prebuild_start logs the off case
|
||||
if (!cfg_bool("TOTK_PIPE_PREBUILD")) { // prebuild_start logs the off case
|
||||
if (ensure_init()) lb_start(pr_hist, fs_hist);
|
||||
return;
|
||||
}
|
||||
@@ -2436,7 +2434,7 @@ void vk_pipeline_prewarm(void) {
|
||||
for (size_t i = 0; i < m; i++)
|
||||
if (!u || memcmp(ids[u - 1], ids[i], 32)) memcpy(ids[u++], ids[i], 32);
|
||||
int cpus = (int)GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||
const char *pe = cfg_get("TOTK_PREWARM_XLATE");
|
||||
const char *pe = cfg_get("TOTK_PREWARM_XLATE"); // no fixed default: half the CPUs, at most 16, when unset
|
||||
int procs = pe && *pe ? atoi(pe) : cpus / 2 > 16 ? 16 : cpus / 2;
|
||||
gfx_shader_prewarm((const uint8_t(*)[32])ids, u, sh, cpus, procs < 1 ? 1 : procs);
|
||||
double t1 = now_ms();
|
||||
@@ -2509,9 +2507,8 @@ void vk_pipeline_prewarm(void) {
|
||||
static void prebuild_start(void) {
|
||||
AcquireSRWLockExclusive(&P.lock);
|
||||
if (K.file && !K.warm) {
|
||||
const char *e = cfg_get("TOTK_PIPE_PREBUILD");
|
||||
rt_log("vk_pipeline: prebuild off%s; %zu records not built",
|
||||
e && !strcmp(e, "0") ? " (TOTK_PIPE_PREBUILD=0)" : " (no boot prewarm)", K.file_n);
|
||||
!cfg_bool("TOTK_PIPE_PREBUILD") ? " (TOTK_PIPE_PREBUILD=0)" : " (no boot prewarm)", K.file_n);
|
||||
free(K.file);
|
||||
K.file = NULL;
|
||||
}
|
||||
@@ -2801,9 +2798,9 @@ static void lb_state(const uint32_t pr_hist[16], const uint32_t fs_hist[4]) {
|
||||
|
||||
// Boot: compute shaders of the warm list (recorded and prepared), then the first KEEP recorded graphics variants.
|
||||
static void lb_start(const uint32_t pr_hist[16], const uint32_t fs_hist[4]) {
|
||||
const char *e = cfg_get("TOTK_LIB_PREBUILD"), *te = cfg_get("TOTK_LIB_PREBUILD_THREADS"),
|
||||
*ke = cfg_get("TOTK_LIB_PREBUILD_KEEP");
|
||||
if (!A.on || (e && !strcmp(e, "0"))) return;
|
||||
const char *e = cfg_value("TOTK_LIB_PREBUILD"), *ke = cfg_get("TOTK_LIB_PREBUILD_KEEP");
|
||||
const char *te = cfg_get("TOTK_LIB_PREBUILD_THREADS"); // no fixed default: a quarter of the CPUs when unset
|
||||
if (!A.on || !cfg_bool("TOTK_LIB_PREBUILD")) return;
|
||||
GfxWarmEnt *all = NULL;
|
||||
size_t total = gfx_shader_warm_list(&all), n = 0, n_cs = 0;
|
||||
LB.keep_n = ke && *ke ? atoi(ke) : 0;
|
||||
@@ -2814,7 +2811,7 @@ static void lb_start(const uint32_t pr_hist[16], const uint32_t fs_hist[4]) {
|
||||
for (size_t i = 0; LB.e && i < total && (LONG)(n - n_cs) < LB.keep_n; i++)
|
||||
if (all[i].stage != GFX_STAGE_CS && all[i].prio == 0) LB.e[n++] = all[i];
|
||||
free(all);
|
||||
if (e && atoi(e) > 0 && (size_t)atoi(e) < n) n = (size_t)atoi(e);
|
||||
if (atoi(e) > 1 && (size_t)atoi(e) < n) n = (size_t)atoi(e); // a count above 1 caps the list; 1 is plain on
|
||||
if (!n) {
|
||||
free(LB.e), LB.e = NULL;
|
||||
return;
|
||||
@@ -2922,7 +2919,7 @@ int vk_pipeline_prepare_shaders(void) {
|
||||
if (!cut) return 1;
|
||||
*cut = 0;
|
||||
int cpus = (int)GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||
const char *pe = cfg_get("TOTK_PREWARM_XLATE");
|
||||
const char *pe = cfg_get("TOTK_PREWARM_XLATE"); // no fixed default: half the CPUs, at most 16, when unset
|
||||
int procs = pe && *pe ? atoi(pe) : cpus / 2 > 16 ? 16 : cpus / 2;
|
||||
int rc = gfx_shader_prepare_seed(dir, cpus, procs < 1 ? 1 : procs);
|
||||
if (!rc) lb_warm_prepared(dir);
|
||||
|
||||
@@ -741,8 +741,7 @@ static Tex *entry_of(const tex_t *t) {
|
||||
Tex *e = nvn_hm_get(&by_key, &k);
|
||||
if (!e) {
|
||||
if (tex_alias < 0) {
|
||||
const char *v = cfg_get("TOTK_TEX_ALIAS");
|
||||
tex_alias = !(v && !strcmp(v, "0"));
|
||||
tex_alias = cfg_bool("TOTK_TEX_ALIAS");
|
||||
rt_log("vk: texture aliases: %s", tex_alias ? "a new image takes the live image's content" : "a new image starts empty");
|
||||
}
|
||||
if (!(e = create_tex(t, &k, tex_alias))) return NULL;
|
||||
|
||||
Reference in new issue
Block a user