diff --git a/nx2navi.ini.example b/nx2navi.ini.example index 53189bc8..a0cdd692 100644 --- a/nx2navi.ini.example +++ b/nx2navi.ini.example @@ -477,3 +477,7 @@ # "ref" is perf_lock_timing_here, which the link map names), the recorder's waits, and the texture lock's holds over # 1 ms. Off by default. # lock_time = 0 +# Texture entries the bindless texture pool may create in one refresh (images and their uploads); the rest wait for +# the next refresh and show their stand-in until then. Lower spreads streaming over more frames (smaller hitches, a +# frame or two of pop-in); higher loads sooner. +# pool_create_budget = 16 diff --git a/runtime/astc_probe.c b/runtime/astc_probe.c index 87bd2f6e..0cdb06aa 100644 --- a/runtime/astc_probe.c +++ b/runtime/astc_probe.c @@ -13,6 +13,7 @@ #include #include +#include "cfg.h" #include "platform/platform.h" #include "host.h" #include "tex.h" @@ -560,7 +561,7 @@ static void timing(VkCtx *c, uint32_t bw, uint32_t bh) { } int probe_astc(void) { - plat_setenv("NX2NAVI_ASTC_BC", "1"); // also builds the BC3 encoder; the RGBA8 cases pass bc 0 and do not use it + cfg_setenv("NX2NAVI_ASTC_BC", "1"); // also builds the BC3 encoder; the RGBA8 cases pass bc 0 and do not use it if (!vk_init()) { printf("probe-astc: FAIL vk_init\n"); return 1; } VkCtx *c = vk_ctx(); printf("probe-astc: GPU %s, textureCompressionASTC_LDR %d, mode %d\n", c->props.deviceName, c->has_astc_ldr, diff --git a/runtime/cfg.c b/runtime/cfg.c index 3befaa9a..97e99b18 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -66,7 +66,7 @@ static const char *const known[] = { "ZSTD_CHECK", "ZSTD_NATIVE", "BIND_REUSE", "DYN_DELTA", "STG_ARENA", "SUBMIT_BATCH", "ASTC_GPU_DESWIZZLE", "ASTC_SCRATCH_KEEP", "ASTC_ARENA", "TEXUP_LOG_MS", "DYN_RES", "DYN_RES_TARGET", "DYN_RES_STEP", - "RECORDER_CORE", "RECORDER_PRIO", "REPLAY_TIME", "LOCK_TIME", + "RECORDER_CORE", "RECORDER_PRIO", "REPLAY_TIME", "LOCK_TIME", "POOL_CREATE_BUDGET", }; // The nx2navi.ini section a key cfg_set may write goes to when the file lacks it (nx2navi.ini.example's sections). @@ -105,7 +105,7 @@ static const struct { const char *key, *section; } sections[] = { {"DYN_RES", "performance"}, {"DYN_RES_TARGET", "performance"}, {"DYN_RES_STEP", "performance"}, {"RECORDER_CORE", "performance"}, {"RECORDER_PRIO", "performance"}, {"BIND_REUSE", "performance"}, {"DYN_DELTA", "performance"}, {"STG_ARENA", "performance"}, {"SUBMIT_BATCH", "performance"}, - {"ASTC_GPU_DESWIZZLE", "performance"}, {"ASTC_SCRATCH_KEEP", "performance"}, {"ASTC_ARENA", "performance"}, + {"ASTC_GPU_DESWIZZLE", "performance"}, {"ASTC_SCRATCH_KEEP", "performance"}, {"ASTC_ARENA", "performance"}, {"POOL_CREATE_BUDGET", "performance"}, {"TIMER_1MS", "performance"}, {"PIPE_WAIT", "performance"}, {"PIPE_SKIP", "performance"}, {"LIB_PREBUILD", "performance"}, {"LIB_PREBUILD_THREADS", "performance"}, {"PIPE_PREBUILD", "performance"}, {"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"}, @@ -190,7 +190,7 @@ static const CfgMeta metas[] = { {"DYN_RES", "0", "0|1", LIVE}, {"DYN_RES_TARGET", "16.7", "1..100", LIVE}, {"DYN_RES_STEP", "45", "8..600", LIVE}, // the recording thread: a core of its own (auto: with 12 or more logical processors) and the highest priority // (vk_exec.c vk_exec_record) - {"RECORDER_CORE", "auto", "auto|0|1", RESTART}, {"RECORDER_PRIO", "1", "0|1", RESTART}, {"REPLAY_TIME", "0", "0|1", RESTART}, {"LOCK_TIME", "0", "0|1", RESTART}, + {"RECORDER_CORE", "auto", "auto|0|1", RESTART}, {"RECORDER_PRIO", "1", "0|1", RESTART}, {"REPLAY_TIME", "0", "0|1", RESTART}, {"LOCK_TIME", "0", "0|1", RESTART}, {"POOL_CREATE_BUDGET", "16", "1..4096", RESTART}, // held submissions handed to the queue together (vk_sync.c, submit batching) {"SUBMIT_BATCH", "4", "1..16", RESTART}, // shaders and pipelines @@ -286,6 +286,7 @@ static void migrate(void) { int cfg_load(const char *path) { clear(); + __atomic_add_fetch(&version, 1, __ATOMIC_RELEASE); // the lookup memo (cfg_memo) forgets the freed strings uint64_t size = 0; uint8_t *data = plat_file_read(path, &size); if (!data) return 0; @@ -369,7 +370,7 @@ static const char *raw_get(const char *name) { return NULL; } -const char *cfg_get(const char *name) { +static const char *cfg_get_now(const char *name) { const char *v = raw_get(name); if (v || strncmp(name, PREFIX, PREFIX_LEN) || !profile_of()) return v; for (size_t i = 0; i < sizeof DECK / sizeof *DECK; i++) @@ -382,6 +383,12 @@ int cfg_is_set(const char *name) { return raw_get(name) != NULL; } unsigned cfg_version(void) { return __atomic_load_n(&version, __ATOMIC_ACQUIRE); } +int cfg_setenv(const char *name, const char *value) { + int ok = plat_setenv(name, value); + __atomic_add_fetch(&version, 1, __ATOMIC_RELEASE); + return ok; +} + int cfg_from_env(const char *name) { return getenv(name) != NULL; } void cfg_set(const char *name, const char *value) { @@ -473,14 +480,47 @@ const char *cfg_default(const char *key) { 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); +static const char *cfg_value_now(const char *name) { + const char *e = cfg_get_now(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; } +// Lookup memo. cfg_get reads the environment (getenv walks the whole block comparing names) and then the file's +// entries and the settings table by name, and several per-draw paths ask for live settings: on the replay thread those +// lookups were about a sixth of the samples in a play profile (ucrtbase's string routines). Each thread keeps the +// answers it got per name until the settings version changes (cfg_set, cfg_reset, cfg_load); values stay valid that +// long because a set keeps the old string for readers and a load bumps the version. NX2NAVI_CFG_MEMO=0 (environment +// only, read once) asks every time. +#define CFG_MEMO_N 256 +typedef struct { unsigned ver; uint32_t h; uint8_t kind; char name[55]; const char *v; } CfgMemo; +static _Thread_local CfgMemo cfg_memo[CFG_MEMO_N]; +static int cfg_memo_on = -1; + +static const char *cfg_memo_get(const char *name, int kind) { + if (cfg_memo_on < 0) { + const char *e = getenv(PREFIX "CFG_MEMO"); + cfg_memo_on = !(e && !strcmp(e, "0")); + } + size_t len = strlen(name); + if (!cfg_memo_on || len >= sizeof cfg_memo[0].name) return kind ? cfg_value_now(name) : cfg_get_now(name); + uint32_t h = 2166136261u; + for (size_t i = 0; i < len; i++) h = (h ^ (uint8_t)name[i]) * 16777619u; + h = h * 2 + (uint32_t)kind; + CfgMemo *m = &cfg_memo[h % CFG_MEMO_N]; + unsigned ver = __atomic_load_n(&version, __ATOMIC_ACQUIRE) + 1; // 0 marks an empty slot + if (m->ver == ver && m->h == h && m->kind == kind && !memcmp(m->name, name, len + 1)) return m->v; + const char *v = kind ? cfg_value_now(name) : cfg_get_now(name); // read after ver: a change meanwhile misses next time + m->ver = ver, m->h = h, m->kind = (uint8_t)kind, m->v = v; + memcpy(m->name, name, len + 1); + return v; +} + +const char *cfg_get(const char *name) { return cfg_memo_get(name, 0); } +const char *cfg_value(const char *name) { return cfg_memo_get(name, 1); } + // 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); diff --git a/runtime/cfg.h b/runtime/cfg.h index 7a1085d9..da86b2b9 100644 --- a/runtime/cfg.h +++ b/runtime/cfg.h @@ -19,6 +19,8 @@ void cfg_set(const char *name, const char *value); // Bumped by every cfg_set. A consumer that keeps a parsed value compares this with the number it last saw (one atomic // load) and parses again when it changed. unsigned cfg_version(void); +// plat_setenv for an NX2NAVI_ variable the process reads back: also bumps cfg_version, so lookups see the new value. +int cfg_setenv(const char *name, const char *value); // 1 when the environment sets name: cfg_set cannot change what cfg_get returns (the menu greys the setting out). int cfg_from_env(const char *name); // 1 when the player set name (the environment or nx2navi.ini), 0 when cfg_get gives a device profile's default or NULL. diff --git a/runtime/cfg_probe.c b/runtime/cfg_probe.c index 674162e7..68bf13b1 100644 --- a/runtime/cfg_probe.c +++ b/runtime/cfg_probe.c @@ -36,8 +36,8 @@ int probe_cfg(void) { "no_such_setting = 1\r\n" "no equals sign\r\n" "last = no newline at the end"; - plat_setenv("NX2NAVI_LOCALE", NULL); - plat_setenv("NX2NAVI_FPS60", NULL); + cfg_setenv("NX2NAVI_LOCALE", NULL); + cfg_setenv("NX2NAVI_FPS60", NULL); CHECK(plat_file_write(path, ini, sizeof ini - 1), "write the probe ini"); CHECK(cfg_load(path) == 1, "load the probe ini"); CHECK(EQ(cfg_get("NX2NAVI_FPS60"), "0"), "value read, whitespace trimmed, lower-case key"); @@ -49,9 +49,9 @@ int probe_cfg(void) { CHECK(cfg_get("NX2NAVI_CLOTH_REALTIME") == NULL, "absent key is NULL"); CHECK(cfg_get("NX2NAVI_comment") == NULL, "comment is not a key"); CHECK(EQ(cfg_get("NX2NAVI_NO_SUCH_SETTING"), "1"), "unknown key is still readable"); - plat_setenv("NX2NAVI_FPS60", "1"); + cfg_setenv("NX2NAVI_FPS60", "1"); CHECK(EQ(cfg_get("NX2NAVI_FPS60"), "1"), "environment overrides the file"); - plat_setenv("NX2NAVI_FPS60", NULL); + cfg_setenv("NX2NAVI_FPS60", NULL); CHECK(EQ(cfg_get("NX2NAVI_FPS60"), "0"), "file value returns when the variable is removed"); plat_file_delete(path); CHECK(cfg_load(path) == 0, "missing file is not an error"); @@ -91,9 +91,9 @@ int probe_cfg(void) { "\r\n" "[audio]\r\n" "volume = 40\r\n"; - plat_setenv("NX2NAVI_MOTION", NULL); - plat_setenv("NX2NAVI_VOLUME", NULL); - plat_setenv("NX2NAVI_RUMBLE_STRENGTH", NULL); + cfg_setenv("NX2NAVI_MOTION", NULL); + cfg_setenv("NX2NAVI_VOLUME", NULL); + cfg_setenv("NX2NAVI_RUMBLE_STRENGTH", NULL); CHECK(plat_file_write(path, before, sizeof before - 1), "write the save ini"); CHECK(cfg_load(path) == 1, "load the save ini"); unsigned v0 = cfg_version(); @@ -118,11 +118,11 @@ int probe_cfg(void) { EQ(cfg_get("NX2NAVI_RUMBLE_STRENGTH"), "80") && EQ(cfg_get("NX2NAVI_VOLUME"), "40") && EQ(cfg_get("NX2NAVI_ROMFS_MODS"), "C:\\mods"), "the saved file reads back"); const char *held = cfg_get("NX2NAVI_VOLUME"); - plat_setenv("NX2NAVI_VOLUME", "70"); + cfg_setenv("NX2NAVI_VOLUME", "70"); cfg_set("NX2NAVI_VOLUME", "90"); CHECK(cfg_from_env("NX2NAVI_VOLUME") && EQ(cfg_get("NX2NAVI_VOLUME"), "70"), "environment wins over cfg_set"); CHECK(EQ(held, "40"), "a pointer cfg_get handed out stays valid after cfg_set"); - plat_setenv("NX2NAVI_VOLUME", NULL); + cfg_setenv("NX2NAVI_VOLUME", NULL); CHECK(!cfg_from_env("NX2NAVI_VOLUME") && EQ(cfg_get("NX2NAVI_VOLUME"), "90"), "cfg_set value returns without the variable"); plat_file_delete(path); CHECK(cfg_save_to(path) == 1, "cfg_save_to creates a missing file"); @@ -161,7 +161,7 @@ int probe_cfg(void) { // cfg_reset: the key's active lines leave nx2navi.ini, the commented example stays static const char rbase[] = "[audio]\n# volume = 100\n[input]\nmotion = 0\n"; static const char *const vol[] = {"VOLUME"}; - plat_setenv("NX2NAVI_VOLUME", NULL); + cfg_setenv("NX2NAVI_VOLUME", NULL); CHECK(plat_file_write(path, rbase, sizeof rbase - 1), "write the reset ini"); CHECK(cfg_load(path) == 1, "load the reset ini"); cfg_set("NX2NAVI_VOLUME", "40"); @@ -200,9 +200,9 @@ int probe_cfg(void) { // a key the environment sets is skipped and keeps its file line CHECK(cfg_load(path) == 1 && EQ(cfg_get("NX2NAVI_VOLUME"), "60"), "reset: reload"); - plat_setenv("NX2NAVI_VOLUME", "70"); + cfg_setenv("NX2NAVI_VOLUME", "70"); CHECK(cfg_reset(vol, 1) == 0, "reset: an environment-set key is skipped"); - plat_setenv("NX2NAVI_VOLUME", NULL); + cfg_setenv("NX2NAVI_VOLUME", NULL); CHECK(EQ(cfg_get("NX2NAVI_VOLUME"), "60"), "reset: the skipped key keeps its value"); CHECK(cfg_save_to(path) == 1, "reset: save after a skip"); got = plat_file_read(path, &got_n); @@ -295,19 +295,19 @@ int probe_cfg(void) { "pad stick: a square gate's corner stays on the unit circle"); input_pad_stick(0, 32767 / 2 + 1, 0.2f, st); CHECK(abs(st[1] - 32767 * 3 / 8) <= 3, "pad stick: half deflection past a 20% zone is (0.5 - 0.2) / 0.8 of full"); - plat_setenv("NX2NAVI_STICK_DEADZONE", "12"); - plat_setenv("NX2NAVI_LSTICK_DEADZONE", NULL); - plat_setenv("NX2NAVI_RSTICK_DEADZONE", NULL); + cfg_setenv("NX2NAVI_STICK_DEADZONE", "12"); + cfg_setenv("NX2NAVI_LSTICK_DEADZONE", NULL); + cfg_setenv("NX2NAVI_RSTICK_DEADZONE", NULL); CHECK(fabsf(input_pad_deadzone(0) - 0.12f) < 1e-6f && fabsf(input_pad_deadzone(1) - 0.12f) < 1e-6f, "pad dead zone: both sticks follow stick_deadzone while lstick/rstick are unset"); - plat_setenv("NX2NAVI_RSTICK_DEADZONE", "20"); + cfg_setenv("NX2NAVI_RSTICK_DEADZONE", "20"); CHECK(fabsf(input_pad_deadzone(0) - 0.12f) < 1e-6f && fabsf(input_pad_deadzone(1) - 0.20f) < 1e-6f, "pad dead zone: rstick_deadzone sets the right stick alone"); - plat_setenv("NX2NAVI_LSTICK_DEADZONE", "80"); + cfg_setenv("NX2NAVI_LSTICK_DEADZONE", "80"); CHECK(fabsf(input_pad_deadzone(0) - 0.5f) < 1e-6f, "pad dead zone: clamped to 50%"); - plat_setenv("NX2NAVI_STICK_DEADZONE", NULL); - plat_setenv("NX2NAVI_LSTICK_DEADZONE", NULL); - plat_setenv("NX2NAVI_RSTICK_DEADZONE", NULL); + cfg_setenv("NX2NAVI_STICK_DEADZONE", NULL); + cfg_setenv("NX2NAVI_LSTICK_DEADZONE", NULL); + cfg_setenv("NX2NAVI_RSTICK_DEADZONE", NULL); CHECK(input_stick_percent(32767, 0) > 99.99 && input_stick_percent(32767, 0) < 100.01 && input_stick_percent(0, 0) == 0 && fabs(input_stick_percent(3000, -4000) - 5000 * 100.0 / 32767) < 1e-9, "stick percent: an axis's end is 100%, the centre 0%, round in between"); @@ -449,27 +449,27 @@ int probe_cfg(void) { CHECK(!strcmp(line, "none"), "edit: a stick direction without keys is none"); // defaults live in the CfgMeta table: cfg_value and the typed accessors fall back to it cfg_load("cfg-probe-missing.ini"); - plat_setenv("NX2NAVI_FPS60", NULL); - plat_setenv("NX2NAVI_MOUSE_SENS", NULL); - plat_setenv("NX2NAVI_FREE_CORES", NULL); + cfg_setenv("NX2NAVI_FPS60", NULL); + cfg_setenv("NX2NAVI_MOUSE_SENS", NULL); + cfg_setenv("NX2NAVI_FREE_CORES", NULL); CHECK(cfg_bool("NX2NAVI_FPS60") == 1, "default: unset FPS60 is on"); CHECK(EQ(cfg_value("NX2NAVI_VK_PRESENT"), "mailbox") && cfg_int("NX2NAVI_SPLIT_DRAWS") == 64, "default: text and integer"); - plat_setenv("NX2NAVI_MOUSE_SENS", "2.5"); + cfg_setenv("NX2NAVI_MOUSE_SENS", "2.5"); CHECK(cfg_double("NX2NAVI_MOUSE_SENS") == 2.5, "double: the environment value"); - plat_setenv("NX2NAVI_MOUSE_SENS", "fast"); + cfg_setenv("NX2NAVI_MOUSE_SENS", "fast"); CHECK(cfg_double("NX2NAVI_MOUSE_SENS") == 1.0, "double: a value that does not parse gives the default"); - plat_setenv("NX2NAVI_MOUSE_SENS", NULL); + cfg_setenv("NX2NAVI_MOUSE_SENS", NULL); cfg_set("NX2NAVI_MOUSE_SENS", "3"); CHECK(cfg_double("NX2NAVI_MOUSE_SENS") == 3.0 && cfg_int("NX2NAVI_MOUSE_SENS") == 3, "a cfg_set value beats the default"); CHECK(cfg_bool("NX2NAVI_FREE_CORES") == 0, "free_cores unset: off"); - plat_setenv("NX2NAVI_FREE_CORES", "0"); + cfg_setenv("NX2NAVI_FREE_CORES", "0"); CHECK(cfg_bool("NX2NAVI_FREE_CORES") == 0, "free_cores 0 gives the same as unset"); - plat_setenv("NX2NAVI_FREE_CORES", "1"); + cfg_setenv("NX2NAVI_FREE_CORES", "1"); CHECK(cfg_bool("NX2NAVI_FREE_CORES") == 1, "free_cores 1: on"); - plat_setenv("NX2NAVI_FREE_CORES", NULL); + cfg_setenv("NX2NAVI_FREE_CORES", NULL); // 0.1.9's pad_layout = xbox_prompts (cfg.c migrate): read as the Nintendo layout with the Xbox prompts, saved so - plat_setenv("NX2NAVI_PAD_LAYOUT", NULL); - plat_setenv("NX2NAVI_PROMPTS", NULL); + cfg_setenv("NX2NAVI_PAD_LAYOUT", NULL); + cfg_setenv("NX2NAVI_PROMPTS", NULL); static const char old_layout[] = "[input]\r\npad_layout = xbox_prompts\r\n"; CHECK(plat_file_write(path, old_layout, sizeof old_layout - 1) && cfg_load(path) == 1 && EQ(cfg_get("NX2NAVI_PAD_LAYOUT"), "nintendo") && EQ(cfg_get("NX2NAVI_PROMPTS"), "xbox"), @@ -493,7 +493,7 @@ int probe_cfg(void) { listed++; char name[96]; snprintf(name, sizeof name, "NX2NAVI_%s", m->key); - plat_setenv(name, ""); + cfg_setenv(name, ""); CHECK(EQ(cfg_value(name), m->def), "cfg_value returns the table default"); int ok = 0; if (!m->values) ok = 1; diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index b00d8267..cb2a9def 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -85,7 +85,7 @@ void gfx_window_closed(void) { rtss_limit_restore(); // RivaTuner Statistics Server's profile as it was fs_save_flush(); // last: the game's threads still run until plat_exit, and a Commit after this one is refused if (restart) { - plat_setenv("NX2NAVI_REEXEC", NULL); // the new process counts its own address-space retries (memory.c) + cfg_setenv("NX2NAVI_REEXEC", NULL); // the new process counts its own address-space retries (memory.c) if (!plat_restart()) rt_log("gfx: the restart could not start the game again"); } plat_exit(0); diff --git a/runtime/gfx_shader_probe.c b/runtime/gfx_shader_probe.c index 6525de9e..1ae4d43d 100644 --- a/runtime/gfx_shader_probe.c +++ b/runtime/gfx_shader_probe.c @@ -7,6 +7,7 @@ #include #include +#include "cfg.h" #include "gfx.h" #include "host.h" #include "platform/platform.h" @@ -160,7 +161,7 @@ int probe_shader(void) { char tmp[PLAT_PATH_MAX]; if (!plat_temp_dir(tmp, sizeof tmp)) strcpy(tmp, "."); snprintf(dir, sizeof dir, "%s/nx2navi-shader-probe-%u", tmp, plat_process_id()); - CHECK(plat_setenv("NX2NAVI_SHADER_CACHE", dir), "cannot set NX2NAVI_SHADER_CACHE"); + CHECK(cfg_setenv("NX2NAVI_SHADER_CACHE", dir), "cannot set NX2NAVI_SHADER_CACHE"); // pass 1: translate through the service const GfxShader *first[WANT]; diff --git a/runtime/memory.c b/runtime/memory.c index 4b7928e0..8ea70681 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -203,7 +203,7 @@ static void reexec_or_fail(const char *what) { if (n >= REEXEC_LIMIT) rt_fatal("memory: %s is not free after %d attempts", what, n); char buf[16]; snprintf(buf, sizeof buf, "%d", n + 1); - plat_setenv("NX2NAVI_REEXEC", buf); + cfg_setenv("NX2NAVI_REEXEC", buf); plat_reexec(); } diff --git a/runtime/nvn_api_cmd.c b/runtime/nvn_api_cmd.c index 158eea15..ce851b39 100644 --- a/runtime/nvn_api_cmd.c +++ b/runtime/nvn_api_cmd.c @@ -998,9 +998,10 @@ NVN_API(nvnCommandBufferSetStencilRef) { NVN_API(nvnCommandBufferSetPolygonOffsetClamp) { *REC(cmd_of(c), OP_POLY_OFFSET, p_poly_offset) = (p_poly_offset){arg_s(c, 0), arg_s(c, 1), arg_s(c, 2)}; // NX2NAVI_POLY_OFFSET_LOG: what the game asks for, to tell a decal that relies on the offset from one that does not - static int logged; + static int logged, on = -1; // the environment read once: this runs for every offset the game sets + if (on < 0) on = getenv("NX2NAVI_POLY_OFFSET_LOG") != NULL; float f = (float)arg_s(c, 0), u = (float)arg_s(c, 1), cl = (float)arg_s(c, 2); - if (getenv("NX2NAVI_POLY_OFFSET_LOG") && logged < 24 && (f != 0.0f || u != 0.0f)) { + if (on && logged < 24 && (f != 0.0f || u != 0.0f)) { logged++; rt_log("nvn: polygon offset factor %.3f units %.3f clamp %.3f", f, u, cl); } diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index 503c5dfc..ce17e46c 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -243,7 +243,7 @@ static char *lang(void) { return s; } -static void set_env(const char *name, const char *value) { plat_setenv(name, value); } // NULL removes it +static void set_env(const char *name, const char *value) { cfg_setenv(name, value); } // NULL removes it static void probe_oe(void) { char *keep_lang = cfg_get("NX2NAVI_LANG") ? strdup(cfg_get("NX2NAVI_LANG")) : NULL; @@ -956,9 +956,9 @@ static void probe_main(Cpu *c) { static uint32_t run_child(const char *mode, const char *env, char *out, size_t cap) { char name[64] = ""; const char *eq = env ? strchr(env, '=') : NULL; - if (eq) snprintf(name, sizeof name, "%.*s", (int)(eq - env), env), plat_setenv(name, eq + 1); + if (eq) snprintf(name, sizeof name, "%.*s", (int)(eq - env), env), cfg_setenv(name, eq + 1); int code = plat_run_self(CHILD_ENV, mode, out, cap, 0); - if (eq) plat_setenv(name, NULL); + if (eq) cfg_setenv(name, NULL); if (code < 0) rt_fatal("probe-services: cannot start the %s child", mode); return (uint32_t)code; } diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 027fe517..a2496962 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -1764,7 +1764,18 @@ static uint16_t pool_kind_type(int k) { } #define POOL_WBATCH 512 -#define POOL_CREATE_BUDGET 64 // texture entries a pool sync may create (images and uploads), the rest next time +// Texture entries a pool sync may create (images and uploads), the rest at the next sync (NX2NAVI_POOL_CREATE_BUDGET, +// default 16). The sync holds the texture lock throughout, and with 64 streaming in new textures made frames of 20-40 ms +// with the replay and other threads waiting on that lock (24 ms of holds per slow frame in a dense area); 16 brought +// that to 5 ms with no pop-in a player could see. The slots it leaves keep their stand-in until the next sync. +static int pool_create_budget(void) { + static int n = -1; + if (n < 0) { + n = cfg_int("NX2NAVI_POOL_CREATE_BUDGET"); + if (n < 1) n = 1; + } + return n; +} static VkWriteDescriptorSet pool_w[POOL_WBATCH]; static VkDescriptorImageInfo pool_ii[POOL_WBATCH]; static uint32_t pool_nw; @@ -1994,7 +2005,7 @@ static void pool_sync_entries(VkExec *ex) { } int retry = 0; // slots whose texture the creation budget left: filled again by the next sync if (fresh || gen != PL.gen || ep != PL.epoch || PL.retry) { - vk_texture_create_budget_locked(POOL_CREATE_BUDGET); + vk_texture_create_budget_locked(pool_create_budget()); // Only a slot change since the last sync (no new kinds, no new submission, nothing left over): the slots that // changed (vk_texture_dirty_slots_locked), not the whole table PoolDirty pd = {ex, used, n, 0}; @@ -3120,7 +3131,8 @@ static int draw_skipped(const VkExec *ex, int mesh, int why) { // NX2NAVI_SKIP_PROG=[,...]: diagnostics. Drops every draw whose program serial is listed, so something // on screen can be attributed to one program by elimination: pass the programs of the pass it appears in, then half of -// them, and so on. Environment only, and nothing is skipped without it. +// them, and so on. Environment only, and nothing is skipped without it. Read once: a getenv on every draw scanned the +// whole environment block and was a sixth of the replay thread's samples in a play profile. static int skip_prog_list[32], n_skip_prog = -1; static int skip_prog_wanted(uint64_t serial) { if (n_skip_prog < 0) { @@ -3157,7 +3169,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int VkRect2D sc = vk_exec_scissor(ex); if (!sc.extent.width || !sc.extent.height) return draw_skipped(ex, mesh, SK_SCISSOR); if (!ex->prog) return draw_skipped(ex, mesh, SK_NO_PROGRAM); - if (getenv("NX2NAVI_SKIP_PROG") && skip_prog_wanted(ex->prog->serial)) return draw_skipped(ex, mesh, SK_DISABLED); + if (n_skip_prog && skip_prog_wanted(ex->prog->serial)) return draw_skipped(ex, mesh, SK_DISABLED); // -1 until read int has_vs, has_fs, vs_wait = 0, fs_wait = 0, memo = mesh ? 0 : shader_memo_on(); int has_ts = 0, ts_wait = 0, vst = mesh ? NVN_STAGE_MESH : NVN_STAGE_VS; const GfxShader *vs, *fs, *ts = NULL; diff --git a/runtime/vk_exec_probe.c b/runtime/vk_exec_probe.c index 158ce0a2..c2152406 100644 --- a/runtime/vk_exec_probe.c +++ b/runtime/vk_exec_probe.c @@ -128,7 +128,7 @@ static int test_present(const GfxBackend *b, uint8_t *guest, int *w_out, int *h_ uint64_t frames = gfx_stats().frames; // the exact colour check needs the bilinear blit: FSR's approximate reciprocals move a flat colour by 1/255 - plat_setenv("NX2NAVI_UPSCALER", "bilinear"); + cfg_setenv("NX2NAVI_UPSCALER", "bilinear"); vk_present_capture(1); const int crop[4] = {0, 0, TEX_W, TEX_H}; b->present(&t, crop, 0); diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index eefdf380..c372fd8e 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -446,7 +446,9 @@ static Tex *create_tex(const tex_t *t, const TexKey *k, int defer_init) { return NULL; } // NX2NAVI_ASTC_BC_PROBE (environment; diagnostics only): measure what a data-driven alpha rule would compress - if (f.astc_bw && getenv("NX2NAVI_ASTC_BC_PROBE")) astc_probe_alpha(t, &f); + static int bc_probe = -1; // read once: this runs for every texture created + if (bc_probe < 0) bc_probe = getenv("NX2NAVI_ASTC_BC_PROBE") != NULL; + if (f.astc_bw && bc_probe) astc_probe_alpha(t, &f); nvn_texlayout L; nvn_tex_layout(d, &L); uint32_t w = umax(d->width, 1), h = umax(d->height, 1), depth = 1, layers = 1;