Unlock the frame rate, shorten cold starts, and describe the Ocarina build in the docs.

Ocarina steps its game by the clock (the same frame-numbered walk covers half the distance at 120 fps), so in a build
without the fps60 and realtime patch sets the pacer holds frames to the frame limit alone: any rate from 30 to 1000,
the monitor's rate, or unlimited (164 fps average in Kokiri Forest). The menu always shows the row, with 165, 240 and
Unlimited added. NX2NAVI_PACE_HZ sets the pacer's rate for tests.

A compute pipeline is compiled outside the pipeline lock, and one compile serves the replay and the boot prebuild
alike; the prebuild uses half the CPUs. The guest waits at most NX2NAVI_PREWARM_WAIT_MS (3000) for the boot prewarm,
which then goes on in the background (a cold start waited 9.8 s). NX2NAVI_TEST_PAD_AT attaches the test gamepad late
and presses it, to test a controller switched on in play.

README, docs/architecture.md, docs/controls.md and AGENTS.md describe the Ocarina build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-07 00:06:12 -05:00
parent f5e3322bf5
commit 4943b50ff2
14 changed files with 297 additions and 347 deletions

View File

@@ -366,8 +366,17 @@ void rt_boot(void) {
ipc_applet_event_init();
hostfn_seal();
uint64_t held = plat_now_ms();
if (warm) plat_thread_join(warm);
else vk_pipeline_prewarm();
// At most NX2NAVI_PREWARM_WAIT_MS (default 3000): a warm start is ready in about 0.3 s, but a cold one (a new
// translator, a new driver) translated 2,132 shaders and built 1,579 pipelines for 9.8 s while the window stayed
// black, for shaders the game first needs in play, well after its intro. Past the wait the prewarm goes on in the
// background; 0 waits for all of it. A --shot image waits for all of it, so that it does not depend on build timing.
const char *pw = cfg_get("NX2NAVI_PREWARM_WAIT_MS");
uint64_t wait_ms = pw && *pw ? strtoull(pw, NULL, 10) : 3000;
if (warm && (rt_config()->shot || !wait_ms)) plat_thread_join(warm);
else if (warm && !plat_thread_join_ns(warm, wait_ms * 1000000ull)) {
plat_thread_detach(warm);
rt_log("boot: the prewarm goes on in the background after %llu ms", (unsigned long long)wait_ms);
} else if (!warm) vk_pipeline_prewarm();
held = plat_now_ms() - held;
rt_log("boot: guest starts %llu ms after process start (%llu ms of it waiting for the prewarm)",
(unsigned long long)(plat_process_uptime_ns() / 1000000), (unsigned long long)held);

View File

@@ -48,8 +48,8 @@ static const char *const known[] = {
"MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_HOST", "MOVIE_PACE",
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
"MV_SURVEY",
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT",
"PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES",
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PACE_HZ", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT",
"PREWARM_WAIT_MS", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES",
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_END", "REEXEC",
"RENDER_SCALE", "REPLAY_ASYNC",
"REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
@@ -57,7 +57,7 @@ static const char *const known[] = {
"SHADER_MEMO", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR",
"SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "STICK_DEADZONE", "STICK_SENS",
"SWKBD_ANSWER",
"SWKBD_TEST", "TEST_PAD", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NO_FLOAT64",
"SWKBD_TEST", "TEST_PAD", "TEST_PAD_AT", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TEX_VRAM_PRESSURE", "TIMER_1MS", "TRACE", "TXD_TRANSPOSE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_A2C", "VK_DYN_VERTEX", "VK_NO_FLOAT64",
"VK_PRESENT", "VK_RECORDER", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VRAM_HEADROOM", "VS_OUTS",
"WALK_KEY", "WALK_SCALE", "WB_EXACT", "WB_FENCE_LIMIT", "WB_MERGE", "WINDOW_SIZE", "XLATE", "XLATE_ID", "XLATE_KEEP", "XLATE_PROCS",
"ZSTD_CHECK", "ZSTD_NATIVE",
@@ -135,7 +135,7 @@ static const CfgMeta metas[] = {
{"SHADOW_RANGE", "100", "50..400", RESTART}, {"CONTACT_SHADOWS", "0", "0..100", RESTART},
{"PCSS", "0", "0..200", RESTART},
// Game
{"FPS_LIMIT", "60", "30|40|45|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE},
{"FPS_LIMIT", "60", "30|40|45|60|90|120|144|165|240|display|unlimited", LIVE}, {"FPS60", "1", "0|1", LIVE},
{"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART},
{"MODS_REBUILD", "auto", "auto|off", RESTART},
{"HIGHFPS_FIX", "1", "0|1", RESTART},

View File

@@ -115,26 +115,37 @@ int frame_step_realtime(void) { return step_word != NULL; }
static int fps60_set = -2;
static int game_interval = 1; // the present interval of the newest frame (frame_step_present)
// The limit can change anything only with the fps60 or realtime patch set (NX2navi's builds). Without them (Ocarina) the
// game picks its own present interval and the pacer follows it (nvn_api_obj.c present_period).
int frame_limit_adjustable(void) { return rt_patch_set("fps60") >= 0 || rt_patch_set("realtime") >= 0; }
// A build without the fps60 and realtime patch sets (Ocarina) steps its game by the clock itself: walked by the same
// frame-numbered input script, Link covered half the distance at 120 fps that he covers at 60. There the pacer holds
// frames to the limit alone (nvn_api_obj.c present_period), the game's own 60 Hz interval aside, and the limit may be
// any rate or none (LIMIT_FREE_MAX_HZ, "unlimited"); NX2navi's physics fails past LIMIT_MAX_HZ, Ocarina has no such floor.
#define LIMIT_FREE_MAX_HZ 1000
int frame_free_running(void) { return rt_patch_set("fps60") < 0 && rt_patch_set("realtime") < 0; }
int frame_limit_adjustable(void) { return 1; }
static unsigned limit_seen;
static int limit_read;
static int limit_hz = -1; // 0: display; -1 before the first read
static int limit_hz = -1; // 0: display; -2: unlimited (free-running builds); -1 before the first read
static int limit_parse(void) {
const char *e = cfg_get("NX2NAVI_FPS_LIMIT"), *old = cfg_get("NX2NAVI_FPS60");
if (!e || !*e) return old && !strcmp(old, "0") ? 30 : 60;
if (!strcmp(e, "display")) return 0;
int free_run = frame_free_running();
if (!strcmp(e, "unlimited")) {
if (free_run) return -2;
rt_log("frame rate: NX2NAVI_FPS_LIMIT=unlimited needs a game that steps by the clock; %d", LIMIT_MAX_HZ);
return LIMIT_MAX_HZ;
}
char *end;
long n = strtol(e, &end, 10);
if (!*end && free_run && n >= LIMIT_MIN_HZ) return n > LIMIT_FREE_MAX_HZ ? LIMIT_FREE_MAX_HZ : (int)n;
if (!*end && n > LIMIT_MAX_HZ) {
rt_log("frame rate: NX2NAVI_FPS_LIMIT=%s is above %d, where the game's physics runs out of memory; %d", e,
LIMIT_MAX_HZ, LIMIT_MAX_HZ);
return LIMIT_MAX_HZ;
}
if (!*end && n >= LIMIT_MIN_HZ) return (int)n;
rt_log("frame rate: NX2NAVI_FPS_LIMIT=%s is not %d..%d or display; 60", e, LIMIT_MIN_HZ, LIMIT_MAX_HZ);
rt_log("frame rate: NX2NAVI_FPS_LIMIT=%s is not %d..%d, display or unlimited; 60", e, LIMIT_MIN_HZ, LIMIT_MAX_HZ);
return 60;
}
@@ -146,10 +157,10 @@ static void frame_limit_live(void) {
int hz = limit_parse();
if (hz == limit_hz) return;
limit_hz = hz;
if (!frame_limit_adjustable()) {
if (hz != 60)
rt_log("frame rate: NX2NAVI_FPS_LIMIT=%s does nothing in this build (no fps60 or realtime patch set); the "
"game sets its own rate", cfg_value("NX2NAVI_FPS_LIMIT"));
if (frame_free_running()) {
if (hz == -2) rt_log("frame rate: unlimited (the game steps by the clock)");
else if (hz) rt_log("frame rate: limit %d fps (the game steps by the clock)", hz);
else rt_log("frame rate: limit at the monitor's refresh rate (the game steps by the clock)");
return;
}
if (fps60_set == -2) fps60_set = rt_patch_set("fps60");
@@ -163,9 +174,11 @@ static void frame_limit_live(void) {
uint64_t frame_step_cap_ns(void) {
frame_limit_live();
if (limit_hz == -2) return 0; // unlimited: the pacer does not hold frames
double hz = limit_hz ? limit_hz : gfx_window_refresh_hz();
if (hz < LIMIT_MIN_HZ) hz = 60; // display rate unknown (no window yet)
if (hz > LIMIT_MAX_HZ) hz = LIMIT_MAX_HZ;
double max = frame_free_running() ? LIMIT_FREE_MAX_HZ : LIMIT_MAX_HZ;
if (hz > max) hz = max;
return (uint64_t)(1e9 / hz + 0.5);
}
@@ -173,7 +186,12 @@ uint64_t frame_step_cap_ns(void) {
// most without the real-time step; the game's own rate (60 Hz over its present interval) in a build without the patch
// sets; 0 before the first frame read the setting.
double frame_step_limit_hz(void) {
if (!frame_limit_adjustable()) return 60.0 / game_interval;
if (frame_free_running()) { // 0 for unlimited, as before the first read
frame_limit_live();
if (limit_hz == -2 || limit_hz == -1) return 0;
double r = limit_hz ? limit_hz : gfx_window_refresh_hz();
return r < LIMIT_MIN_HZ ? 60 : r;
}
int hz = limit_hz;
if (hz < 0) return 0;
double r = hz ? hz : gfx_window_refresh_hz();

View File

@@ -289,7 +289,8 @@ void *rt_patch_page(void); // the page the patch
void frame_step_init(void); // after rt_patches_init: the real-time step's first value
int frame_step_realtime(void); // the real-time step is on: presents ignore the interval
uint64_t frame_step_cap_ns(void); // with the real-time step: the shortest frame in ns
int frame_limit_adjustable(void); // the build has the fps60 or realtime patch set
int frame_limit_adjustable(void); // the frame limit setting changes the rate (always)
int frame_free_running(void); // no fps60/realtime patch set: the game steps by the clock
double frame_step_limit_hz(void); // the frame rate the limit gives (overlay); 0 unknown
int64_t frame_step_world_us(void); // game time since the loaded save's first frame, -1 before
// (NX2NAVI_FPS_LIMIT, live)

View File

@@ -513,9 +513,13 @@ static void binds_refresh(void) {
// NX2NAVI_TEST_PAD=<lx>,<ly>,<rx>,<ry> (test runs): an SDL virtual gamepad whose sticks rest at these raw SDL axis values
// (-32768..32767, down is +y), attached before the first scan so it is the gamepad the game reads: drift and full
// deflection go through the same mapping and dead zone as a real pad.
static void test_pad_attach(void) {
static SDL_Joystick *joy; // kept open: a virtual joystick's axes are set through an open handle
// deflection go through the same mapping and dead zone as a real pad. NX2NAVI_TEST_PAD_AT=<ms>: attached that long after
// input starts instead, like a controller switched on in play, and its south button pressed for half a second one
// second later (the log then shows the hot-plug and the press arriving: scan_pads, pad_physical).
static SDL_Joystick *test_joy; // kept open: a virtual joystick's axes and buttons are set through an open handle
static uint64_t test_attach_ns, test_press_ns; // NX2NAVI_TEST_PAD_AT: when to attach, when to press (0: done)
static void test_pad_make(void) {
const char *e = cfg_get("NX2NAVI_TEST_PAD");
int v[4];
if (!e || !*e) return;
@@ -530,18 +534,42 @@ static void test_pad_attach(void) {
d.nbuttons = SDL_GAMEPAD_BUTTON_COUNT;
d.name = "NX2navi test gamepad";
SDL_JoystickID id = SDL_AttachVirtualJoystick(&d);
joy = id ? SDL_OpenJoystick(id) : NULL;
if (!joy) {
test_joy = id ? SDL_OpenJoystick(id) : NULL;
if (!test_joy) {
rt_log("input: test gamepad not attached (%s)", SDL_GetError());
return;
}
static const SDL_GamepadAxis axes[4] = {SDL_GAMEPAD_AXIS_LEFTX, SDL_GAMEPAD_AXIS_LEFTY, SDL_GAMEPAD_AXIS_RIGHTX,
SDL_GAMEPAD_AXIS_RIGHTY};
for (int i = 0; i < 4; i++)
SDL_SetJoystickVirtualAxis(joy, axes[i], (Sint16)(v[i] < -32768 ? -32768 : v[i] > 32767 ? 32767 : v[i]));
SDL_SetJoystickVirtualAxis(test_joy, axes[i], (Sint16)(v[i] < -32768 ? -32768 : v[i] > 32767 ? 32767 : v[i]));
rt_log("input: test gamepad attached, sticks at %d,%d %d,%d", v[0], v[1], v[2], v[3]);
}
static void test_pad_attach(void) {
const char *at = cfg_get("NX2NAVI_TEST_PAD_AT");
if (at && *at && cfg_get("NX2NAVI_TEST_PAD")) {
test_attach_ns = plat_now_ns() + strtoull(at, NULL, 10) * 1000000ull;
return;
}
test_pad_make();
}
// Under lock, every poll: the delayed attach and the press of NX2NAVI_TEST_PAD_AT.
static void test_pad_tick(void) {
uint64_t now = plat_now_ns();
if (test_attach_ns && now >= test_attach_ns) {
test_attach_ns = 0;
test_pad_make();
if (test_joy) test_press_ns = now + 1000000000ull;
}
if (test_press_ns && test_joy && now >= test_press_ns) {
int down = now < test_press_ns + 500000000ull;
SDL_SetJoystickVirtualButton(test_joy, SDL_GAMEPAD_BUTTON_SOUTH, down);
if (!down) test_press_ns = 0;
}
}
static void start(void) {
binds_refresh();
const char *e = cfg_get("NX2NAVI_INPUT");
@@ -591,6 +619,7 @@ static int32_t shake_stick(int held) {
// Under lock, state 1: the open gamepad's inputs by position (pd[PAD_*] != 0 held); 0 without a connected gamepad.
static int pad_physical(uint8_t pd[PAD_COUNT]) {
test_pad_tick();
// every RESCAN_MS, not only without a gamepad: a second controller, or one that wakes up after the start, is found
if (plat_now_ns() / 1000000u >= next_scan) { next_scan = plat_now_ns() / 1000000u + RESCAN_MS; scan_pads(); }
SDL_UpdateGamepads();

View File

@@ -735,7 +735,10 @@ NVN_API(nvnWindowSetCrop) {
// 2nd or 3rd tick would only add latency and 50 ms frames.
#define VSYNC_HZ 60ull
static uint64_t present_period(const win_t *o) {
if (frame_step_realtime()) return frame_step_cap_ns();
if (frame_step_realtime() || frame_free_running()) return frame_step_cap_ns(); // frame_rate.c: the limit alone
static int pace_hz = -1; // NX2NAVI_PACE_HZ=<n> (test runs): present at n per second whatever the game's interval
if (pace_hz < 0) pace_hz = cfg_get("NX2NAVI_PACE_HZ") ? atoi(cfg_get("NX2NAVI_PACE_HZ")) : 0;
if (pace_hz > 0) return 1000000000ull / (uint64_t)pace_hz;
return (o->interval > 0 ? (uint64_t)o->interval : 1ull) * 1000000000ull / VSYNC_HZ;
}

View File

@@ -56,6 +56,7 @@ int res_adjustable(void);
const char *const *vk_color_preset(const char *name);
double frame_step_limit_hz(void);
int frame_limit_adjustable(void);
int frame_free_running(void);
extern const int rt_game_version;
extern const char rt_port_version[];
void cheats_frame(uint64_t frame); // cheats.c
@@ -633,21 +634,24 @@ static void row_game_lang(void) {
// The frame limit (frame_rate.c): unset, the older fps60 = 0 still means 30. The monitor choice shows the rate it gives.
static void row_fps_limit() {
// 40 and 45: the Steam Deck's screen runs at 40 to 60 Hz (the OLED to 90); 40 divides 40 and 120 Hz evenly
static const char *const vals[] = {"30", "40", "45", "60", "90", "120", "144", "display"};
static const UiTextId ids[] = {UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60,
UI_MENU_FPS_90, UI_MENU_FPS_120, UI_MENU_FPS_144, UI_MENU_FPS_DISPLAY};
enum { N = sizeof vals / sizeof *vals };
const char *names[N];
for (int i = 0; i < N; i++) names[i] = menu_text(ids[i]);
// 165 and 240: common gaming monitors; unlimited only where the game steps by the clock (frame_rate.c)
static const char *const vals[] = {"30", "40", "45", "60", "90", "120", "144", "165", "240", "display", "unlimited"};
static const UiTextId ids[] = {UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60,
UI_MENU_FPS_90, UI_MENU_FPS_120, UI_MENU_FPS_144, UI_MENU_FPS_144,
UI_MENU_FPS_144, UI_MENU_FPS_DISPLAY, UI_MENU_FPS_UNLIMITED};
int n = frame_free_running() ? 11 : 10;
const char *names[11];
for (int i = 0; i < n; i++) names[i] = menu_text(ids[i]);
names[7] = "165 FPS", names[8] = "240 FPS";
static char display[64];
double hz = gfx_window_refresh_hz();
if (hz > 0) {
snprintf(display, sizeof display, menu_text(UI_MENU_FPS_DISPLAY_HZ), hz);
names[N - 1] = display;
names[9] = display;
}
const char *set = cfg_get("NX2NAVI_FPS_LIMIT"), *old = cfg_get("NX2NAVI_FPS60");
int cur = (!set || !*set) && old && !strcmp(old, "0") ? 0 : -1;
opt_choice_list("NX2NAVI_FPS_LIMIT", UI_MENU_FPS_LIMIT, vals, names, N, UI_MENU_FPS_LIMIT_DESC, cur);
opt_choice_list("NX2NAVI_FPS_LIMIT", UI_MENU_FPS_LIMIT, vals, names, n, UI_MENU_FPS_LIMIT_DESC, cur);
}
// The menu's name of a NX2NAVI_VK_PRESENT mode (gfx_window_present_mode); NULL for another.
@@ -727,9 +731,7 @@ static void tab_screen(float scale) {
static void tab_game(float scale) {
opt_begin("##game", scale);
// The limit needs the fps60 or realtime patch set (frame_rate.c frame_limit_adjustable): Ocarina's build has
// neither and runs at the rate it picks itself, so the row would change nothing
if (frame_limit_adjustable()) row_fps_limit();
row_fps_limit(); // frame_rate.c: Ocarina steps by the clock, so the pacer alone sets its rate
row_game_lang();
static const UiTextId mode[] = {UI_MENU_MODE_DOCKED, UI_MENU_MODE_HANDHELD};
opt_choice("NX2NAVI_OPERATION_MODE", UI_MENU_OPERATION_MODE, mode, 2, UI_MENU_OPERATION_MODE_DESC);

View File

@@ -166,12 +166,13 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_FXAA_DESC] = "The game's own FXAA edge smoothing. It blurs fine detail a little; with DLAA on it is not needed.",
[UI_MENU_FPS_LIMIT] = "Frame rate limit",
[UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs the "
"real-time step (realtime = 1 in nx2navi.ini, the default).",
[UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. The game keeps time by the clock, so it "
"plays at the same speed at any rate. Unlimited draws as fast as the PC can.",
[UI_MENU_FPS_30] = "30 FPS", [UI_MENU_FPS_40] = "40 FPS", [UI_MENU_FPS_45] = "45 FPS",
[UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_90] = "90 FPS", [UI_MENU_FPS_120] = "120 FPS", [UI_MENU_FPS_144] = "144 FPS",
// the monitor's refresh rate; printf format with the rate in Hz when it is known
[UI_MENU_FPS_DISPLAY] = "Monitor rate", [UI_MENU_FPS_DISPLAY_HZ] = "Monitor rate (%.0f Hz)",
[UI_MENU_FPS_UNLIMITED] = "Unlimited",
[UI_MENU_REALTIME] = "Game speed follows the clock",
[UI_MENU_REALTIME_DESC] = "Steps the game by real time, so a slow frame does not slow the game down.",
[UI_MENU_CLOTH_REALTIME] = "Cloth on the clock",
@@ -640,11 +641,12 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_FXAA_DESC] = "Собственное сглаживание FXAA. Слегка размывает мелкие детали; с DLAA оно не нужно.",
[UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров",
[UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужен шаг по "
"реальному времени (realtime = 1 в nx2navi.ini, по умолчанию).",
[UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Игра идёт по часам, поэтому её скорость не "
"зависит от частоты кадров. «Без ограничения» рисует так быстро, как может ПК.",
[UI_MENU_FPS_30] = "30 FPS", [UI_MENU_FPS_40] = "40 FPS", [UI_MENU_FPS_45] = "45 FPS",
[UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_90] = "90 FPS", [UI_MENU_FPS_120] = "120 FPS", [UI_MENU_FPS_144] = "144 FPS",
[UI_MENU_FPS_DISPLAY] = "Как у монитора", [UI_MENU_FPS_DISPLAY_HZ] = "Как у монитора (%.0f Гц)",
[UI_MENU_FPS_UNLIMITED] = "Без ограничения",
[UI_MENU_REALTIME] = "Скорость игры по часам",
[UI_MENU_REALTIME_DESC] = "Игра идёт по реальному времени, медленный кадр её не замедляет.",
[UI_MENU_CLOTH_REALTIME] = "Ткань по часам",
@@ -1068,8 +1070,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_SHARPNESS_NEEDS_FSR] = "só com AMD FSR 1",
[UI_MENU_FPS_LIMIT] = "Limite de quadros",
[UI_MENU_FPS_LIMIT_DESC] = "O máximo de quadros por segundo que o jogo desenha. Acima de 60 é experimental e "
"precisa do passo em tempo real (realtime = 1 no nx2navi.ini, o padrão).",
[UI_MENU_FPS_LIMIT_DESC] = "O máximo de quadros por segundo que o jogo desenha. O jogo segue o relógio, então a "
"velocidade é a mesma em qualquer taxa. Sem limite desenha o mais rápido que o PC puder.",
[UI_MENU_FPS_30] = "30 FPS", [UI_MENU_FPS_40] = "40 FPS", [UI_MENU_FPS_45] = "45 FPS",
[UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_90] = "90 FPS", [UI_MENU_FPS_120] = "120 FPS", [UI_MENU_FPS_144] = "144 FPS",
[UI_MENU_ASSUME_FOCUS] = "Continuar rodando fora de foco",
@@ -1078,6 +1080,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
"a janela perde o foco, como no Switch ao apertar Home; um carregamento interrompido "
"assim pode parar de vez.",
[UI_MENU_FPS_DISPLAY] = "Taxa do monitor", [UI_MENU_FPS_DISPLAY_HZ] = "Taxa do monitor (%.0f Hz)",
[UI_MENU_FPS_UNLIMITED] = "Sem limite",
[UI_MENU_REALTIME] = "Velocidade do jogo pelo relógio",
[UI_MENU_REALTIME_DESC] = "Avança o jogo pelo tempo real, para que um quadro lento não deixe o jogo mais lento.",
[UI_MENU_CLOTH_REALTIME] = "Tecidos pelo relógio",
@@ -1600,8 +1603,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_COLOR_GAMMA] = "伽马",
[UI_MENU_COLOR_GAMMA_DESC] = "小于 1 提亮暗部与中间调,大于 1 压暗;1 表示不调整。",
[UI_MENU_FPS_LIMIT] = "帧率上限",
[UI_MENU_FPS_LIMIT_DESC] = "游戏每秒绘制的最高帧数。高于 60 帧为实验性功能,"
"需要实时步进(nx2navi.ini 中 realtime = 1,默认开启)。",
[UI_MENU_FPS_LIMIT_DESC] = "游戏每秒绘制的最高帧数。游戏按时钟计时,任何帧率下速度都相同。"
"不限制时以电脑能达到的最快速度绘制。",
[UI_MENU_FPS_30] = "30 FPS",
[UI_MENU_FPS_40] = "40 FPS",
[UI_MENU_FPS_45] = "45 FPS",
@@ -1611,6 +1614,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_FPS_144] = "144 FPS",
[UI_MENU_FPS_DISPLAY] = "显示器刷新率",
[UI_MENU_FPS_DISPLAY_HZ] = "显示器刷新率(%.0f Hz)",
[UI_MENU_FPS_UNLIMITED] = "不限制",
[UI_MENU_REALTIME] = "游戏速度跟随时钟",
[UI_MENU_REALTIME_DESC] = "按真实时间推进游戏,帧率低时游戏速度也不会变慢。",
[UI_MENU_CLOTH_REALTIME] = "布料跟随时钟",

View File

@@ -61,7 +61,7 @@ typedef enum {
// Game
UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60, UI_MENU_FPS_90,
UI_MENU_FPS_120, UI_MENU_FPS_144,
UI_MENU_FPS_DISPLAY, UI_MENU_FPS_DISPLAY_HZ,
UI_MENU_FPS_DISPLAY, UI_MENU_FPS_DISPLAY_HZ, UI_MENU_FPS_UNLIMITED,
UI_MENU_REALTIME, UI_MENU_REALTIME_DESC,
UI_MENU_CLOTH_REALTIME, UI_MENU_CLOTH_REALTIME_DESC,
UI_MENU_HIGHFPS_FIX, UI_MENU_HIGHFPS_FIX_DESC,

View File

@@ -2897,6 +2897,29 @@ static void journal_mark(int slot, const GfxWarmEnt *e) {
plat_file_pwrite(SK.journal, rec, sizeof rec, (uint64_t)slot * JR_SLOT);
}
// Compute shaders whose pipeline a thread is compiling now (P.lock): a cold driver takes about 2 s for one of Ocarina's
// large compute shaders. The replay used to compile under P.lock, which held every other pipeline lookup that long, and
// compiled a second copy of a pipeline the boot prebuild (lb_compute) was already compiling.
#define CS_FLIGHT 32
static const GfxShader *cs_flight[CS_FLIGHT];
static int cs_flight_has(const GfxShader *cs) {
for (int i = 0; i < CS_FLIGHT; i++)
if (cs_flight[i] == cs) return 1;
return 0;
}
static int cs_flight_add(const GfxShader *cs) { // 0 when the table is full (the caller compiles anyway)
for (int i = 0; i < CS_FLIGHT; i++)
if (!cs_flight[i]) return cs_flight[i] = cs, 1;
return 0;
}
static void cs_flight_remove(const GfxShader *cs) {
for (int i = 0; i < CS_FLIGHT; i++)
if (cs_flight[i] == cs) cs_flight[i] = NULL;
}
VkPipeline vk_pipeline_compute(const GfxShader *cs, const VkPipeInfo **info) {
if (info) *info = NULL;
if (!cs || !ensure_init()) return VK_NULL_HANDLE;
@@ -2904,6 +2927,12 @@ VkPipeline vk_pipeline_compute(const GfxShader *cs, const VkPipeInfo **info) {
uint64_t h = key_hash(&k, sizeof k);
plat_mutex_lock(&P.lock);
Pipe *p = pipe_find(&k, sizeof k, h);
while (!p && cs_flight_has(cs)) { // another thread is compiling it: its result, not a second compile
plat_mutex_unlock(&P.lock);
plat_sleep_ms(1);
plat_mutex_lock(&P.lock);
p = pipe_find(&k, sizeof k, h);
}
if (p) {
P.stats.hits++;
} else {
@@ -2912,19 +2941,27 @@ VkPipeline vk_pipeline_compute(const GfxShader *cs, const VkPipeInfo **info) {
Layout *l = compute_layout(cs, &B, &why);
VkPipeline pipe = VK_NULL_HANDLE;
if (!why) {
int flight = cs_flight_add(cs);
plat_mutex_unlock(&P.lock); // the compile runs without the lock
uint64_t p0 = perf_begin();
pipe = compute_create(cs, l);
perf_end(PERF_PIPE, p0);
plat_mutex_lock(&P.lock);
if (flight) cs_flight_remove(cs);
if (!pipe) why = "pipeline creation failed";
}
if (why) {
P.stats.failures++;
rt_log("vk_pipeline: compute pipeline not built: %s", why);
if ((p = pipe_find(&k, sizeof k, h))) { // another thread added it meanwhile (no flight slot was free)
if (pipe) vkDestroyPipeline(P.device, pipe, NULL);
} else {
P.stats.compute++;
LB.cs_draw++;
if (why) {
P.stats.failures++;
rt_log("vk_pipeline: compute pipeline not built: %s", why);
} else {
P.stats.compute++;
LB.cs_draw++;
}
p = pipe_add(&k, sizeof k, h, pipe, l, l ? &B : NULL, VK_PIPELINE_BIND_POINT_COMPUTE, 0);
}
p = pipe_add(&k, sizeof k, h, pipe, l, l ? &B : NULL, VK_PIPELINE_BIND_POINT_COMPUTE, 0);
}
plat_mutex_unlock(&P.lock);
if (!p) return VK_NULL_HANDLE;
@@ -2973,8 +3010,9 @@ static void lb_compute(const GfxShader *cs) {
Bindings B = {0};
const char *why = NULL;
lb_lock();
Layout *l = pipe_find(&k, sizeof k, h) ? NULL : compute_layout(cs, &B, &why);
int have = !l && !why;
int busy = cs_flight_has(cs); // the replay compiles it now (vk_pipeline_compute)
Layout *l = busy || pipe_find(&k, sizeof k, h) ? NULL : compute_layout(cs, &B, &why);
int have = !l && !why, flight = l ? cs_flight_add(cs) : 0;
lb_unlock();
if (!l) {
lb_count(2, have ? 1 : 2, 0);
@@ -2984,6 +3022,7 @@ static void lb_compute(const GfxShader *cs) {
VkPipeline pipe = compute_create(cs, l);
double ms = now_ms() - t0;
lb_lock();
if (flight) cs_flight_remove(cs);
if (pipe && !pipe_find(&k, sizeof k, h)) {
pipe_add(&k, sizeof k, h, pipe, l, &B, VK_PIPELINE_BIND_POINT_COMPUTE, 0);
P.stats.compute++;
@@ -3131,7 +3170,7 @@ 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_value("NX2NAVI_LIB_PREBUILD"), *ke = cfg_get("NX2NAVI_LIB_PREBUILD_KEEP");
const char *te = cfg_get("NX2NAVI_LIB_PREBUILD_THREADS"); // no fixed default: a quarter of the CPUs when unset
const char *te = cfg_get("NX2NAVI_LIB_PREBUILD_THREADS"); // no fixed default: half the CPUs when unset
if (!A.on || !cfg_bool("NX2NAVI_LIB_PREBUILD")) return;
char dir[PLAT_PATH_MAX * 2];
if (cache_dir(dir, sizeof dir)) skip_init(dir);
@@ -3154,7 +3193,7 @@ static void lb_start(const uint32_t pr_hist[16], const uint32_t fs_hist[4]) {
lb_state(pr_hist, fs_hist);
LB.idle = 1;
int cpus = (int)plat_cpu_usable();
int t = te && *te ? atoi(te) : cpus / 4;
int t = te && *te ? atoi(te) : cpus / 2; // idle priority; a cold driver takes ~2 s per large compute shader
t = t < 1 ? 1 : t > LB_MAX_THREADS ? LB_MAX_THREADS : t;
if ((size_t)t > n) t = (int)n;
LB.t0 = now_ms();