diff --git a/docs/architecture.md b/docs/architecture.md index 1c7009c6..f4b4e3d6 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -76,7 +76,7 @@ Every guest thread is a host thread. TotK assumes Horizon's scheduler: three app - Replay thread. `TOTK_REPLAY_ASYNC=1` moves the replay off the submitting thread onto a queue at most one frame behind the game; reads of GPU results wait for the newest writer instead of draining the queue (`vk_backend.c`). It is off by default because no timing has shown a gain yet. - Driver data. The NVN driver keeps a per-stage constant bank (c0) that shaders read for things like point size, dispatch size and base instance. The back end fills it the way the driver does. - Shaders: the Ryujinx translator 1.3.2 with MacNativeGames' patches and ours (`tools/xlate/patches/`), built with .NET 10 NativeAOT as `totk_xlate.exe` and run as a separate process. Its SPIR-V goes to Vulkan directly. Translated shaders are cached on disk. -- Pipelines: `VK_EXT_graphics_pipeline_library` where the driver has it. Shader stages are compiled ahead into libraries; a draw that meets a new state links them at once (fast link), and an optimised pipeline replaces the linked one when a background thread finishes it. Pipeline keys seen in play are saved and built at boot. A draw whose pipeline is not ready is skipped when one of its pass's targets was rendered in the previous frame, and waits otherwise, so one-shot passes are never lost (`TOTK_PIPE_SKIP`); the stage libraries a waiting draw needs are built on idle workers in parallel (`TOTK_PIPE_WAIT`). Without the extension, a missing pipeline is built on a worker and the draw waits or is skipped by the same rule. +- Pipelines: `VK_EXT_graphics_pipeline_library` where the driver has it. Shader stages are compiled ahead into libraries; a draw that meets a new state links them at once (fast link), and an optimised pipeline replaces the linked one when a background thread finishes it. Pipeline keys seen in play are saved and built at boot. A draw whose pipeline is not ready is skipped when one of its pass's targets was rendered in the previous frame, and waits otherwise, so one-shot passes are never lost; a full-screen draw is skipped as well rather than waiting (`TOTK_PIPE_SKIP`); the stage libraries a waiting draw needs are built on idle workers in parallel (`TOTK_PIPE_WAIT`). Without the extension, a missing pipeline is built on a worker and the draw waits or is skipped by the same rule. - Occlusion queries never block the CPU; a result that is not ready counts as visible. - ASTC textures are uploaded as they are where the device reports `textureCompressionASTC_LDR`, and decoded by a compute shader everywhere else (`vk_astc.c`, `TOTK_ASTC`). The CPU decoder (`tex_astc*.c`) is the fallback and the test oracle. - Draw state. A draw whose program, bound state and textures repeat reuses the previous draw's shaders and skips rebuilding its descriptor sets; descriptor sets are written through update templates (`vk_exec_draw.c`, `vk_pipeline.c`). diff --git a/docs/controls.md b/docs/controls.md index 7745a09c..51896224 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -60,9 +60,9 @@ The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sti @ LSTICK|RSTICK [hold_ms] ``` -`` counts presented frames. `@` counts milliseconds of the world clock: game time stepped since the end of the first save load (the player leaves the title screen's origin), so a timed event lands at the same game time at any frame rate and load length. A later load, such as fast travel, still shifts what follows. Each event logs once (`input: script frame N: A`). `tools/input/load_save.txt` loads the first save from the title screen. +`` counts 60 Hz ticks of game time since the first frame (presented frames at 60 fps), so the title menus get the presses at the same game time at any frame limit. `@` counts milliseconds of the world clock: game time stepped since the end of the first save load (the player leaves the title screen's origin), so a timed event lands at the same game time at any frame rate and load length. A later load, such as fast travel, still shifts what follows. In a script with timed lines the untimed ones stop when the world clock starts, as the load ends at another tick in each run. Each event logs once (`input: script frame N tick T: A`). `tools/input/load_save.txt` loads the first save from the title screen. -`TOTK_INPUT_RECORD=` (`input_record` in `totk.ini`, or Input recording in the menu) writes the merged input in the same format, one line per button press and per stick segment: events before the world clock starts by frame, the rest timed. The file replays as a script, which makes it the repro to attach to a bug report. +`TOTK_INPUT_RECORD=` (`input_record` in `totk.ini`, or Input recording in the menu) writes the merged input in the same format, one line per button press and per stick segment: events before the world clock starts by tick, the rest timed; a button or stick held when the world clock starts is cut there and goes on as a timed event. The file replays as a script, which makes it the repro to attach to a bug report. ## RenderDoc capture (blocked) diff --git a/runtime/cfg.c b/runtime/cfg.c index 231b46db..79ea9378 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -100,7 +100,7 @@ static const CfgMeta metas[] = { {"ASYNC_PREEMPT", "1", "0|1|2", RESTART}, {"REPLAY_ASYNC", "0", "0|1", RESTART}, {"FREE_CORES", "0", "0|1", RESTART}, {"TIMER_1MS", "1", "0|1", RESTART}, // shaders and pipelines - {"PIPE_WAIT", "default", "default|draw", RESTART}, {"PIPE_SKIP", "any", "strict|any|fullscreen", RESTART}, + {"PIPE_WAIT", "default", "default|draw", RESTART}, {"PIPE_SKIP", "fullscreen", "strict|any|fullscreen", RESTART}, {"LIB_PREBUILD", "1", "0|1", RESTART}, {"LIB_PREBUILD_THREADS", "", "1..64", RESTART}, {"PIPE_PREBUILD", "1", "0|1", RESTART}, {"PREWARM_XLATE", "", "1..64", RESTART}, {"GPL", "1", "0|1", RESTART}, // textures and memory diff --git a/runtime/frame_rate.c b/runtime/frame_rate.c index 5af49495..c5c2818b 100644 --- a/runtime/frame_rate.c +++ b/runtime/frame_rate.c @@ -49,12 +49,14 @@ #define STEP_FIRST_S (1.0 / 60.0) static _Atomic uint64_t *step_word; // patch page +0: ratio (low float), seconds (high float) +static double step_now = STEP_FIRST_S; // the step the patch page holds: what the game steps each frame static _Atomic uint32_t *step_interval; // patch page +8: seconds * 60 (patches-v143.txt realtime) static uint64_t last_ns; static double samples[STEP_SAMPLES]; static unsigned sample_count, sample_next; static void step_store(float seconds) { + step_now = seconds; float ratio = seconds * 30.0f, interval = seconds * 60.0f; uint32_t lo, hi, iv; memcpy(&lo, &ratio, 4); @@ -217,9 +219,11 @@ static void speed_report(uint64_t now, double step, int interval) { } static _Atomic int64_t world_us = -1; +static _Atomic uint64_t game_us; // game time stepped since the first present (frame_step_ticks) static uint64_t presents; int64_t frame_step_world_us(void) { return atomic_load_explicit(&world_us, memory_order_relaxed); } +uint64_t frame_step_ticks(void) { return atomic_load_explicit(&game_us, memory_order_relaxed) * 60 / 1000000; } static void world_clock(double dt, double step) { presents++; @@ -253,6 +257,11 @@ void frame_step_present(uint64_t display_ns, int interval) { } } last_ns = display_ns; + // The game clock of untimed script lines: what the game stepped this frame, the patch page's step with the + // real-time step (kept through a reset), whole vsyncs without it. + double game = step_word ? step_now : (interval > 0 ? interval : 1) / 60.0; + atomic_store_explicit(&game_us, atomic_load_explicit(&game_us, memory_order_relaxed) + (uint64_t)(game * 1e6 + 0.5), + memory_order_relaxed); world_clock(dt, step); if (rt_trace & RT_TRACE_PERF) speed_report(display_ns, step, interval); } diff --git a/runtime/host.h b/runtime/host.h index 137e6179..72de7c81 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -249,6 +249,7 @@ uint64_t frame_step_cap_ns(void); // with the real-time 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 // (TOTK_FPS_LIMIT, live) +uint64_t frame_step_ticks(void); // game time since the first present in 60 Hz ticks (input scripts) void frame_step_present(uint64_t display_ns, int interval); // nvnQueuePresentTexture: the frame's display time and // present interval (60 Hz ticks) // ---- boot (boot.c, main.c) diff --git a/runtime/input_win.c b/runtime/input_win.c index c2a2553f..390fb31f 100644 --- a/runtime/input_win.c +++ b/runtime/input_win.c @@ -41,10 +41,13 @@ static const SDL_GamepadButton pad_sdl[PAD_COUNT] = { }; // TOTK_INPUT_SCRIPT=: lines "