WIP: perf(lift): a function's 6 most-used registers and its flags as C locals by default (A64_LOCAL_REGS=6, A64_LOCAL_FLAGS=1) #1469

Closed
marclemieux64 wants to merge 3 commits from marclemieux64/Longshot:local-regs into main
First-time contributor

Type: perf · Risk: medium · Tested on: Windows 11, RX 6750 XT, Ryzen 9 3900X · Needs: other CPUs (Intel, Zen 3/4/5), Linux, Steam Deck: fps and long play

TL;DR

Where the game's own code holds the frame rate back, the translated code spends a lot of its time saving and reloading the console CPU's registers. This PR keeps a function's most-used registers and its condition flags in fast local variables instead, a translator feature that was there but off. On a Ryzen 9 3900X in Kokiri Forest it runs at 54.3 fps instead of 48.6 (+12%, faster in 10 of 10 pairs), and a profile shows the translated code taking 5 to 7% less CPU per frame. Builds compile about 66% longer, and faster CPUs gain less or nothing.

Breakdown

  • Who it helps: players whose frame rate is limited by the CPU, most on older or many-core-but-slower CPUs such as Zen 2.
  • What was wrong: the translated code kept every guest register and flag in memory, saved and reloaded around every call and atomic.
  • What changes: a function's 6 most-used registers and its flags live in C locals, synced only where they must be.
  • What does not change: the functions the text patches and hooks edit keep the old form; saves, settings, the renderer and its caches are untouched.
  • How it was checked: a soak of 10 interleaved pairs (+11.8%, no crash), a profile pair, scripted play with screenshots, a new game-free check, the test suite.
  • What is still open: other CPUs and Linux, long play for translation bugs, the longer build, and one unexplained renderer heap crash in about 41 runs.
  • Risk: medium: a register the emitter fails to sync would show as wrong game behaviour; A64_LOCAL_REGS=0 A64_LOCAL_FLAGS= turns it off.

Why

Where the game is CPU-bound, its own translated code is the limit: on a Ryzen 9 3900X in Kokiri Forest the main thread waits on the game's worker threads about 17 ms a frame, and 71% of the workers' running time is lifted code spread over about 4,950 functions, none above 1% (HOS_PROFILE=1). Nothing hot to fix by hand; the cost is in how every function is translated.

The lifted C keeps every guest register (c->x[N]) and the NZCV flags in the context struct, and writes them back and reads them again around every call and every seq_cst atomic. The compiler can't keep them in host registers across those points, so each function does loads and stores the ARM code never did. The job scheduler on the critical path (f_8004ab40) is atomics and CAS loops from top to bottom.

a64-kit already has the fix as an experiment, off by default: A64_LOCAL_REGS=<n> (a function's n most-used registers as C locals) and A64_LOCAL_FLAGS=1 (NZCV as locals), synced with the context only where they must be. Only 31 and more registers had been measured here (no gain, a64_lift.py's notes); totk-pc-recomp found 4 to 6 best. Nobody had tried 4 to 8 on Longshot: searched Longshot (LOCAL_REGS, LOCAL_FLAGS, localize_regs, NZCV, "local registers"), Hookshot and the team chat. Background: https://git.notrexed.dev/Hookshot/Hookshot/issues/995 (CPU-bound low fps).

What changed

Local registers and flags are on by default: 6 registers and the flags, the best of the combinations measured. The functions whose C is edited after the emit, by its text or by code spliced in, keep the context, as before.

  • lift: nx2/lift.py's LOCAL_DEFAULTS (A64_LOCAL_REGS=6, A64_LOCAL_FLAGS=1), set with setdefault at the top of main(), before the Lifter, discovery and the emit's processes (which read the environment). A value set in the environment wins. lift.py is one of the lift's sources, so the lift key changes and the game is translated again.
  • lift: patched_functions(): every f_XXXXXXXX named in PATCH_MODULES (oot_patches.py, lift_fixes.py, fastfp.py) joins Lifter.no_local. Their text matches c->x[N] and c->z; without this the lift stops (oot_patches: the output size places were found [0,0,0,0,1,0,0,0] times). 76 functions.
  • lift: spliced_functions(): every function with C spliced in after one of its instructions (Lifter.after: oot_wide, oot_fov, oot_shadow, oot_jitter) joins no_local too. That C hands the context to the host, and hos_oot_shadow reads and writes c->x[23]: with x23 a local, Shadow resolution's write would be lost and the setting would do nothing. 16 functions. Checked in the lifted C: f_80492370, the shadow hook's function, has no x23_. (#1209's entry_hooks.py keeps its own hooked functions in no_local.)
  • fastfp: nx2/fastfp.py's emit_function keeps a no_local function's flags in the context too (a64-kit's would rename them; oot_patches matches c->z). Tagged # (fastfp) as the copy's check wants.
  • tests: tests/test_local_regs_default.py, below.
  • docs: docs/development.md, Building: the switch's row. docs/tested/: the six runs of the first measurement.

Measurements

Verdict: unconfirmed, being re-measured. Every local-register build below lacked oot_patches' dynamic resolution patch (dukenheimer's finding, comments), which main had, so the numbers may hold a resolution difference; a fix and a measurement with the 3D's scale logged are coming. As measured: +11.8% in Kokiri Forest on a CPU-bound PC (48.6 → 54.3 fps, faster in 10 of 10 interleaved pairs), the lifted code 5 to 7% cheaper per frame in a profile; no gain measured yet on a Ryzen 9 7900X (HumanBean, below). A run on the rebased branch against current main is under way and will be added.

Hardware: Windows 11 Pro 26200, Radeon RX 6750 XT 12 GB (AMD 26.11.1, driver 0x800161), Ryzen 9 3900X (Zen 2, 24 threads), 32 GB
Scene: Kokiri Forest, child, by day, outside Saria's house; 2560x1440 native (Render resolution 100%, Upscaler Off), frame generation off
Method: the save loaded by Skip title screen, 10 s settling, then the camera turned right 30 s and left 30 s by HOS_INPUT_LIVE (0:RRIGHT/30000,30.5:RLEFT/30000); the mean of the first 26 vk: N presents, X fps lines after the script started, and the frame trace's medians over the script (RX_VK_FRAME_TRACE=1). Builds alternated, unattended.
How to reproduce: any CPU-bound save; build main and this branch with make_game.py (the same work folder is fine: the lift key differs), run the same script on each in turn.

The soak: 10 pairs, main c14641a6 against this branch at 1354234e (the same change before the rebase):

Before: main @ c14641a6 After: this PR @ 1354234e
fps, mean of the 10 runs (range) 48.6 (47.6 to 49.95) 54.3 (51.6 to 58.1)
frame ms, median 19.58 17.98
game_ms 12.23 13.54
wait_gpu_ms 3.41 1.92
wait_main_ms 3.26 1.77
main_blocked_ms 15.13 13.58
draw_ms / desc_ms / cmds_ms / programs_ms 7.20 / 3.23 / 2.10 / 1.06 7.36 / 3.35 / 2.15 / 1.08
crashes 0 0

game_ms rises in every pair, and so it did on HumanBean's Linux PC; but it holds the main thread's waits, and here it comes with a frame 1.6 ms shorter, the GPU wait and the render thread's wait on the game each 1.5 ms shorter, and the main thread blocked 1.55 ms less.

The profile pair (the direct test): one branch (this + #1343 + #1321) built with the defaults and with A64_LOCAL_REGS=0 A64_LOCAL_FLAGS=, HOS_PROFILE=1, two runs each; samples (2 ms) whose leaf is lifted code (f_…, and #385's s_…_N pieces of the giant functions, which only the side without locals has) over the script's last 60 s, per frame:

lifted code, ms per frame run 1 run 2
workers, locals on 7.55 7.83
workers, locals off 8.12 8.24
main thread, on / off 0.62 / 0.64 0.62 / 0.65

A share that counts only f_ symbols makes this PR look 25% more expensive (8.2 against 6.6 ms), because the giant functions are s_ pieces only without locals.

The first measurement (3 rounds, the same method): main c14641a6 45.97 fps, this PR 52.60 (rounds 45.31 / 48.59 / 44.01 against 53.27 / 52.73 / 51.81). Main's pipeline cache was only part made in those runs; the soak's was complete.

How many registers, and the flags (on main 544229a2 + #1343, #1321, #1323, 3 rounds each against that base): A64_LOCAL_REGS=4 +10.5%, =6 +10.4%, =8 +11.4%, =6 with A64_LOCAL_FLAGS=1 +12.6%. Then on this branch, 5 interleaved rounds: 8 registers with the flags 53.2 against 6's 53.2 fps. 6 with the flags it is.

Also measured on top of this branch, not proposed: LONGSHOT_LIGHT_PASSES=0 no gain; every lifted chunk at -O2 +2.7% (4 of 5 rounds) with a 55-minute build (main's LONGSHOT_CHUNK_OPT=all with #1431's parts is being measured now); RX_VK_MESH_OPT=1 60 fps in two rounds and a crash at load in the fourth (it hung RX 6600s, issues 461 and 484: out); RX_VK_NATIVE_FADD=1 no effect.

HumanBean, Linux, Ryzen 9 7900X + RTX 3090 (comments): fps within 3% either way in Kokiri Forest and the Market over two pairs, on a PC that was swapping. A faster CPU with the GPU 66 to 78% busy leaves this change little to move; that is the open question for other CPUs.

Flags and settings

A64_LOCAL_REGS and A64_LOCAL_FLAGS (a64-kit's, lift time) change default.

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
A64_LOCAL_REGS a function's n most-used guest registers as C locals unset (0) 6 fewer context loads and stores at every call and atomic helps: Kokiri, Ryzen 9 3900X; no gain measured on a 7900X; others untested on for everyone; 0 to compare
A64_LOCAL_FLAGS NZCV as C locals unset 1 the same for the flags helps: about +2% over registers alone, same PC on for everyone; empty (A64_LOCAL_FLAGS=) to compare

Testing

Tested:

  • In the game, on my PC (Windows 11, RX 6750 XT 26.11.1, Ryzen 9 3900X), all scripted and unattended: the soak (10 pairs) and the first measurement (3 rounds) in Kokiri Forest; 12 runs of the four variants before the splice fix; the profile pair; a 70 s scripted play run (HOS_INPUT_FRAME_CLOCK=1: walk, turn, Z-target, roll, talk, read a sign, attack, camera) on this branch and on main with a screenshot every 120 presents, nothing wrong in them (lighting, shadows, Navi, HUD, prompts and dialogue as on main). Shadow resolution Highest set in every run; the hook's function keeps c->x[23] in the lifted C. One crash in about 41 runs of local-register builds: 0xc0000374 (heap corruption) on the Presentation Thread in the renderer's operator new from refresh_pool_ranges_locked < capture_make, the heap damaged earlier by something unknown; none in the 20-launch soak; main had none in about 30.
  • tests/test_local_regs_default.py, new, game-free: fails on main, passes here. It checks the defaults and that main() sets them before the Lifter and discovery; that patched_functions() is every function the patch modules name and spliced_functions() every function with spliced C (a made-up Lifter); and that every module in nx2/ whose text holds lifted C's register or flag names is a patch module, a splice, or keeps its functions in no_local itself (as #1209's entry_hooks.py does), so a new text patch can't silently break under local registers.
  • python -I -B tests/run_all.py on Windows, before the rebase: 634 passed, 46 failed, 45 skipped, every failure also failing on main c14641a6 (Windows-environment failures: gcc, line endings) or flaky under the full parallel run. After the rebase: this check, test_fastfp_override.py, test_split_giants.py and test_spawn_emit.py pass; test_libc_hooks.py fails here and on main a35130c0 alike (it looks for L.discover( in nx2/lift.py, which calls discover.discover(L, ...)).

Not tested:

  • Any other CPU on Windows (Intel, Zen 3/4/5), the Steam Deck's APU; Linux beyond HumanBean's two pairs.
  • The emulator-hosted DLL build.
  • Long play across areas: a translation difference would show as wrong game behaviour, not a graphics glitch.

Must be tested:

  • Linux, any GPU (Test Farm: @Beanstalk linux, this branch and main, Kokiri Forest and Hyrule Field, fps of each in turn, and a few minutes of play): expecting no failure, and a gain where the CPU is the limit.
  • Windows, Intel or Zen 3/4 with an NVIDIA GPU (Test Farm: @Beanstalk windows nvidia, the same): expecting the same.
  • Steam Deck (Test Farm: @Beanstalk steamdeck, the same at the Deck's settings): expecting a gain, the Deck being CPU-bound in busy areas.
  • By hand, any PC: an hour of normal play on this build (area changes, a dungeon, cutscenes, the ocarina, shops, saving and loading), expecting the game to behave exactly as on main: no crash, no stuck game, no wrong behaviour (by hand: a player who knows the game).

Risks

What could break: the game's behaviour wherever the local-register emission has a bug a64-kit's experiment never met on this game: a register that must be in the context at a point the emitter doesn't sync (a host function given the context, a setjmp/longjmp, an exception or interrupt path). The three classes found so far (text patches, spliced C, #1209's entry hooks) are handled and checked.

The build is slower (measured): HumanBean, from scratch on a Ryzen 9 7900X (Linux): compile 298 → 494 s (+66%), the longest lifted file 72 → 171 s (six over 115 s), the lifted C +5%. (My own builds reused the object cache, so they never measured this.) Part of it is #385's splitting, which leaves functions with locals whole by design, so a giant function compiles unsplit; the rest is the optimiser doing more with the registers it can now keep. Worth working on before this is ready: which files grew most, and whether splitting can learn to cut functions with locals.

Faster CPUs may gain nothing: on a Ryzen 9 7900X no fps gain was measured (two pairs, a swapping PC).

Turning it off: A64_LOCAL_REGS=0 A64_LOCAL_FLAGS= at build time (lift key: re-lifts), or revert the commit.

Compatibility: the game is translated and compiled again after updating (the lift key changes), as after any lift change. Saves, longshot_options.ini, the shader and pipeline caches and the vk ABI are unchanged.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A file in docs/tested/ for each new measured run (format in docs/tested-configurations.md).
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Docs updated.

🤖 Generated with Claude Code

**Type:** perf · **Risk:** medium · **Tested on:** Windows 11, RX 6750 XT, Ryzen 9 3900X · **Needs:** other CPUs (Intel, Zen 3/4/5), Linux, Steam Deck: fps and long play ## TL;DR Where the game's own code holds the frame rate back, the translated code spends a lot of its time saving and reloading the console CPU's registers. This PR keeps a function's most-used registers and its condition flags in fast local variables instead, a translator feature that was there but off. On a Ryzen 9 3900X in Kokiri Forest it runs at 54.3 fps instead of 48.6 (+12%, faster in 10 of 10 pairs), and a profile shows the translated code taking 5 to 7% less CPU per frame. Builds compile about 66% longer, and faster CPUs gain less or nothing. ## Breakdown - **Who it helps:** players whose frame rate is limited by the CPU, most on older or many-core-but-slower CPUs such as Zen 2. - **What was wrong:** the translated code kept every guest register and flag in memory, saved and reloaded around every call and atomic. - **What changes:** a function's 6 most-used registers and its flags live in C locals, synced only where they must be. - **What does not change:** the functions the text patches and hooks edit keep the old form; saves, settings, the renderer and its caches are untouched. - **How it was checked:** a soak of 10 interleaved pairs (+11.8%, no crash), a profile pair, scripted play with screenshots, a new game-free check, the test suite. - **What is still open:** other CPUs and Linux, long play for translation bugs, the longer build, and one unexplained renderer heap crash in about 41 runs. - **Risk:** medium: a register the emitter fails to sync would show as wrong game behaviour; `A64_LOCAL_REGS=0 A64_LOCAL_FLAGS=` turns it off. ## Why Where the game is CPU-bound, its own translated code is the limit: on a Ryzen 9 3900X in Kokiri Forest the main thread waits on the game's worker threads about 17 ms a frame, and 71% of the workers' running time is lifted code spread over about 4,950 functions, none above 1% (HOS_PROFILE=1). Nothing hot to fix by hand; the cost is in how every function is translated. The lifted C keeps every guest register (`c->x[N]`) and the NZCV flags in the context struct, and writes them back and reads them again around every call and every seq_cst atomic. The compiler can't keep them in host registers across those points, so each function does loads and stores the ARM code never did. The job scheduler on the critical path (`f_8004ab40`) is atomics and CAS loops from top to bottom. a64-kit already has the fix as an experiment, off by default: `A64_LOCAL_REGS=<n>` (a function's `n` most-used registers as C locals) and `A64_LOCAL_FLAGS=1` (NZCV as locals), synced with the context only where they must be. Only 31 and more registers had been measured here (no gain, a64_lift.py's notes); totk-pc-recomp found 4 to 6 best. Nobody had tried 4 to 8 on Longshot: searched Longshot (`LOCAL_REGS`, `LOCAL_FLAGS`, `localize_regs`, `NZCV`, "local registers"), Hookshot and the team chat. Background: https://git.notrexed.dev/Hookshot/Hookshot/issues/995 (CPU-bound low fps). ## What changed Local registers and flags are on by default: 6 registers and the flags, the best of the combinations measured. The functions whose C is edited after the emit, by its text or by code spliced in, keep the context, as before. - lift: `nx2/lift.py`'s `LOCAL_DEFAULTS` (`A64_LOCAL_REGS=6`, `A64_LOCAL_FLAGS=1`), set with `setdefault` at the top of `main()`, before the Lifter, discovery and the emit's processes (which read the environment). A value set in the environment wins. lift.py is one of the lift's sources, so the lift key changes and the game is translated again. - lift: `patched_functions()`: every `f_XXXXXXXX` named in `PATCH_MODULES` (oot_patches.py, lift_fixes.py, fastfp.py) joins `Lifter.no_local`. Their text matches `c->x[N]` and `c->z`; without this the lift stops (`oot_patches: the output size places were found [0,0,0,0,1,0,0,0] times`). 76 functions. - lift: `spliced_functions()`: every function with C spliced in after one of its instructions (`Lifter.after`: oot_wide, oot_fov, oot_shadow, oot_jitter) joins `no_local` too. That C hands the context to the host, and `hos_oot_shadow` reads and writes `c->x[23]`: with x23 a local, Shadow resolution's write would be lost and the setting would do nothing. 16 functions. Checked in the lifted C: `f_80492370`, the shadow hook's function, has no `x23_`. (#1209's `entry_hooks.py` keeps its own hooked functions in `no_local`.) - fastfp: `nx2/fastfp.py`'s `emit_function` keeps a `no_local` function's flags in the context too (a64-kit's would rename them; oot_patches matches `c->z`). Tagged `# (fastfp)` as the copy's check wants. - tests: `tests/test_local_regs_default.py`, below. - docs: `docs/development.md`, Building: the switch's row. `docs/tested/`: the six runs of the first measurement. ## Measurements **Verdict: unconfirmed, being re-measured.** Every local-register build below lacked oot_patches' dynamic resolution patch (dukenheimer's finding, comments), which main had, so the numbers may hold a resolution difference; a fix and a measurement with the 3D's scale logged are coming. As measured: +11.8% in Kokiri Forest on a CPU-bound PC (48.6 → 54.3 fps, faster in 10 of 10 interleaved pairs), the lifted code 5 to 7% cheaper per frame in a profile; no gain measured yet on a Ryzen 9 7900X (HumanBean, below). A run on the rebased branch against current main is under way and will be added. Hardware: Windows 11 Pro 26200, Radeon RX 6750 XT 12 GB (AMD 26.11.1, driver 0x800161), Ryzen 9 3900X (Zen 2, 24 threads), 32 GB Scene: Kokiri Forest, child, by day, outside Saria's house; 2560x1440 native (Render resolution 100%, Upscaler Off), frame generation off Method: the save loaded by Skip title screen, 10 s settling, then the camera turned right 30 s and left 30 s by `HOS_INPUT_LIVE` (`0:RRIGHT/30000,30.5:RLEFT/30000`); the mean of the first 26 `vk: N presents, X fps` lines after the script started, and the frame trace's medians over the script (`RX_VK_FRAME_TRACE=1`). Builds alternated, unattended. How to reproduce: any CPU-bound save; build main and this branch with `make_game.py` (the same work folder is fine: the lift key differs), run the same script on each in turn. **The soak:** 10 pairs, main c14641a6 against this branch at 1354234e (the same change before the rebase): | | Before: main @ c14641a6 | After: this PR @ 1354234e | |---|---|---| | fps, mean of the 10 runs (range) | 48.6 (47.6 to 49.95) | 54.3 (51.6 to 58.1) | | frame `ms`, median | 19.58 | 17.98 | | `game_ms` | 12.23 | 13.54 | | `wait_gpu_ms` | 3.41 | 1.92 | | `wait_main_ms` | 3.26 | 1.77 | | `main_blocked_ms` | 15.13 | 13.58 | | `draw_ms` / `desc_ms` / `cmds_ms` / `programs_ms` | 7.20 / 3.23 / 2.10 / 1.06 | 7.36 / 3.35 / 2.15 / 1.08 | | crashes | 0 | 0 | `game_ms` rises in every pair, and so it did on HumanBean's Linux PC; but it holds the main thread's waits, and here it comes with a frame 1.6 ms shorter, the GPU wait and the render thread's wait on the game each 1.5 ms shorter, and the main thread blocked 1.55 ms less. **The profile pair** (the direct test): one branch (this + #1343 + #1321) built with the defaults and with `A64_LOCAL_REGS=0 A64_LOCAL_FLAGS=`, `HOS_PROFILE=1`, two runs each; samples (2 ms) whose leaf is lifted code (`f_…`, and #385's `s_…_N` pieces of the giant functions, which only the side without locals has) over the script's last 60 s, per frame: | lifted code, ms per frame | run 1 | run 2 | |---|---|---| | workers, locals on | 7.55 | 7.83 | | workers, locals off | 8.12 | 8.24 | | main thread, on / off | 0.62 / 0.64 | 0.62 / 0.65 | A share that counts only `f_` symbols makes this PR look 25% more expensive (8.2 against 6.6 ms), because the giant functions are `s_` pieces only without locals. **The first measurement** (3 rounds, the same method): main c14641a6 45.97 fps, this PR 52.60 (rounds 45.31 / 48.59 / 44.01 against 53.27 / 52.73 / 51.81). Main's pipeline cache was only part made in those runs; the soak's was complete. **How many registers, and the flags** (on main 544229a2 + #1343, #1321, #1323, 3 rounds each against that base): `A64_LOCAL_REGS=4` +10.5%, `=6` +10.4%, `=8` +11.4%, `=6` with `A64_LOCAL_FLAGS=1` +12.6%. Then on this branch, 5 interleaved rounds: 8 registers with the flags 53.2 against 6's 53.2 fps. 6 with the flags it is. **Also measured on top of this branch, not proposed:** `LONGSHOT_LIGHT_PASSES=0` no gain; every lifted chunk at `-O2` +2.7% (4 of 5 rounds) with a 55-minute build (main's `LONGSHOT_CHUNK_OPT=all` with #1431's parts is being measured now); `RX_VK_MESH_OPT=1` 60 fps in two rounds and a crash at load in the fourth (it hung RX 6600s, issues 461 and 484: out); `RX_VK_NATIVE_FADD=1` no effect. **HumanBean, Linux, Ryzen 9 7900X + RTX 3090** (comments): fps within 3% either way in Kokiri Forest and the Market over two pairs, on a PC that was swapping. A faster CPU with the GPU 66 to 78% busy leaves this change little to move; that is the open question for other CPUs. ### Flags and settings `A64_LOCAL_REGS` and `A64_LOCAL_FLAGS` (a64-kit's, lift time) change default. | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `A64_LOCAL_REGS` | a function's n most-used guest registers as C locals | unset (0) | 6 | fewer context loads and stores at every call and atomic | helps: Kokiri, Ryzen 9 3900X; no gain measured on a 7900X; others untested | on for everyone; `0` to compare | | `A64_LOCAL_FLAGS` | NZCV as C locals | unset | 1 | the same for the flags | helps: about +2% over registers alone, same PC | on for everyone; empty (`A64_LOCAL_FLAGS=`) to compare | ## Testing **Tested:** - In the game, on my PC (Windows 11, RX 6750 XT 26.11.1, Ryzen 9 3900X), all scripted and unattended: the soak (10 pairs) and the first measurement (3 rounds) in Kokiri Forest; 12 runs of the four variants before the splice fix; the profile pair; a 70 s scripted play run (`HOS_INPUT_FRAME_CLOCK=1`: walk, turn, Z-target, roll, talk, read a sign, attack, camera) on this branch and on main with a screenshot every 120 presents, nothing wrong in them (lighting, shadows, Navi, HUD, prompts and dialogue as on main). Shadow resolution Highest set in every run; the hook's function keeps `c->x[23]` in the lifted C. One crash in about 41 runs of local-register builds: `0xc0000374` (heap corruption) on the Presentation Thread in the renderer's `operator new` from `refresh_pool_ranges_locked` < `capture_make`, the heap damaged earlier by something unknown; none in the 20-launch soak; main had none in about 30. - `tests/test_local_regs_default.py`, new, game-free: fails on main, passes here. It checks the defaults and that `main()` sets them before the Lifter and discovery; that `patched_functions()` is every function the patch modules name and `spliced_functions()` every function with spliced C (a made-up Lifter); and that every module in nx2/ whose text holds lifted C's register or flag names is a patch module, a splice, or keeps its functions in `no_local` itself (as #1209's `entry_hooks.py` does), so a new text patch can't silently break under local registers. - `python -I -B tests/run_all.py` on Windows, before the rebase: 634 passed, 46 failed, 45 skipped, every failure also failing on main c14641a6 (Windows-environment failures: `gcc`, line endings) or flaky under the full parallel run. After the rebase: this check, `test_fastfp_override.py`, `test_split_giants.py` and `test_spawn_emit.py` pass; `test_libc_hooks.py` fails here and on main a35130c0 alike (it looks for `L.discover(` in nx2/lift.py, which calls `discover.discover(L, ...)`). **Not tested:** - Any other CPU on Windows (Intel, Zen 3/4/5), the Steam Deck's APU; Linux beyond HumanBean's two pairs. - The emulator-hosted DLL build. - Long play across areas: a translation difference would show as wrong game behaviour, not a graphics glitch. **Must be tested:** - Linux, any GPU (Test Farm: @Beanstalk linux, this branch and main, Kokiri Forest and Hyrule Field, fps of each in turn, and a few minutes of play): expecting no failure, and a gain where the CPU is the limit. - Windows, Intel or Zen 3/4 with an NVIDIA GPU (Test Farm: @Beanstalk windows nvidia, the same): expecting the same. - Steam Deck (Test Farm: @Beanstalk steamdeck, the same at the Deck's settings): expecting a gain, the Deck being CPU-bound in busy areas. - By hand, any PC: an hour of normal play on this build (area changes, a dungeon, cutscenes, the ocarina, shops, saving and loading), expecting the game to behave exactly as on main: no crash, no stuck game, no wrong behaviour (by hand: a player who knows the game). ## Risks **What could break:** the game's behaviour wherever the local-register emission has a bug a64-kit's experiment never met on this game: a register that must be in the context at a point the emitter doesn't sync (a host function given the context, a setjmp/longjmp, an exception or interrupt path). The three classes found so far (text patches, spliced C, #1209's entry hooks) are handled and checked. **The build is slower (measured):** HumanBean, from scratch on a Ryzen 9 7900X (Linux): compile 298 → 494 s (+66%), the longest lifted file 72 → 171 s (six over 115 s), the lifted C +5%. (My own builds reused the object cache, so they never measured this.) Part of it is #385's splitting, which leaves functions with locals whole by design, so a giant function compiles unsplit; the rest is the optimiser doing more with the registers it can now keep. Worth working on before this is ready: which files grew most, and whether splitting can learn to cut functions with locals. **Faster CPUs may gain nothing:** on a Ryzen 9 7900X no fps gain was measured (two pairs, a swapping PC). **Turning it off:** `A64_LOCAL_REGS=0 A64_LOCAL_FLAGS=` at build time (lift key: re-lifts), or revert the commit. **Compatibility:** the game is translated and compiled again after updating (the lift key changes), as after any lift change. Saves, `longshot_options.ini`, the shader and pipeline caches and the vk ABI are unchanged. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A file in `docs/tested/` for each new measured run (format in `docs/tested-configurations.md`). - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Docs updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The lifted C kept every guest register and the NZCV flags in the context, written back and read again around every
call and seq_cst atomic. a64-kit's A64_LOCAL_REGS / A64_LOCAL_FLAGS keep a function's most-used registers and its
flags in C locals instead, synced only where control leaves. Both were off: only 31 and more registers had been
measured (no gain). 6 with the flags: Kokiri on a Ryzen 9 3900X, 46.0 -> 52.6 fps on this main.

- nx2/lift.py: LOCAL_DEFAULTS set with setdefault in main() (A64_LOCAL_REGS=0 A64_LOCAL_FLAGS= turns both off; the
  file is one of the lift's sources, so the new default re-lifts). The functions the text patches name
  (PATCH_MODULES: oot_patches, lift_fixes, fastfp) keep the context, or their c->x[N] / c->z matches fail; so do
  the functions with C spliced in (Lifter.after), whose host calls read and write the context (hos_oot_shadow:
  c->x[23]).
- nx2/fastfp.py: a no_local function keeps its flags in the context with A64_LOCAL_FLAGS too.
- tests/test_local_regs_default.py: the defaults, their order in main(), both no_local sets, and that every nx2
  module writing lifted C's register names is a patch module or a splice.
- docs/development.md: the switch's row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
docs(tested): Kokiri, local registers against main, Ryzen 9 3900X and RX 6750 XT, three rounds each
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
beanstalk/approval approved by HumanBean, llun (double-reviewed)
beanstalk/any 1/1 fail
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
db7e4cc287
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
First-time contributor

Tested in game: Windows 11 Pro 26200, RX 6750 XT (AMD 26.11.1), Ryzen 9 3900X: Kokiri Forest, 3 scripted camera rounds against main c14641a6 (52.6 vs 46.0 fps) and a 70 s scripted play run (walk, roll, Z-target, talk, sign, attack) with screenshots every 120 presents on both builds; no crash, device lost or error line, screenshots as on main, Shadow resolution Highest set throughout

Tested in game: Windows 11 Pro 26200, RX 6750 XT (AMD 26.11.1), Ryzen 9 3900X: Kokiri Forest, 3 scripted camera rounds against main c14641a6 (52.6 vs 46.0 fps) and a 70 s scripted play run (walk, roll, Z-target, talk, sign, attack) with screenshots every 120 presents on both builds; no crash, device lost or error line, screenshots as on main, Shadow resolution Highest set throughout
Author
First-time contributor

@Beanstalk Please build this branch and main c14641a6 on Linux (any GPU), on Windows with an Intel or newer Ryzen CPU and an NVIDIA GPU, and on the Steam Deck at its own settings. On each: Kokiri Forest and Hyrule Field, the camera turning for 60 s, fps of each build in turn (2 rounds or more); then a few minutes of play on this branch: walking, an area change, talking, the ocarina if the save has it. Looking for: the fps gain where the CPU is the limit, and any crash, stuck game or wrong game behaviour (this changes how every function of the game is translated).

@Beanstalk Please build this branch and main c14641a6 on Linux (any GPU), on Windows with an Intel or newer Ryzen CPU and an NVIDIA GPU, and on the Steam Deck at its own settings. On each: Kokiri Forest and Hyrule Field, the camera turning for 60 s, fps of each build in turn (2 rounds or more); then a few minutes of play on this branch: walking, an area change, talking, the ocarina if the save has it. Looking for: the fps gain where the CPU is the limit, and any crash, stuck game or wrong game behaviour (this changes how every function of the game is translated).
Member

@marclemieux64 only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@marclemieux64 only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Member

@Beanstalk

@Beanstalk
Member

@llun approval of db7e4cc recorded. This diff touches sensitive paths, so a second member of BigBeans must approve it too.

@llun approval of `db7e4cc` recorded. This diff touches sensitive paths, so a second member of `BigBeans` must approve it too.
Member
Beanstalk test farm · an earlier run: commit db7e4cc (the newer results are in a comment below)

Commit db7e4cc · tier double-reviewed · approved by HumanBean, llun · dashboard

What will be tested · AI plan (gpt-6.1-terra)

The plan compares main and the pull request in Kokiri Forest and Hyrule Field, exercising movement, camera control and an area change. It measures frame rate and frametime, compares screenshots, and times repeated lifts and builds; gameplay takes about 14 minutes per tester, with build timing separate. Crashes, failed map transitions, substantial visual differences or major performance regressions fail the plan.

  • Where: any (any PC, 1-2 reports).
  • forest-field: from a new save (settings vsync=2, frame_rate_cap=6, frame_generation=0), then move the stick, press buttons, take the picture forest to compare with main, measure forest for 30 s (after 10 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 30 s (after 10 s warm-up); 1 run on each side.
  • Build times: main and the PR each built 2 times, alternating, each whole in a fresh folder: the lift again (no kept lift, main's compiled objects kept); every stage timed (shader preparation is not), and the lifted C compared.
  • Measured: crashes, frame times, stutters and hitches, draws and frame rate, load times.
  • The PR fails if: it crashes; or frame rate is more than 15% below main; or a picture differs from main by more than 15%; or frame time (p99) is more than 25% above main.
  • Time: about 15 min of game runs per tester (2 game starts), plus the two builds and 4 timed builds (about 80 min).

Done (started 2026-11-17 21:36 UTC, last report 00:02 UTC). Comment @Beanstalk to run it again.

This diff touches sensitive paths, so it needs two members of BigBeans: nx2/fastfp.py, nx2/lift.py

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
any · 1: linux+other unknown, unknown; 2: linux+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3080 Ti, 620.70.6 2/1 1 2 none 14.7 vs 15.2 (−3%) — fail

Measurements · any

Verdict: fail on any (2/1 report): forest-field screenshot.max_diff failed.

Hardware: 1: linux+other unknown, unknown AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM; 2: linux+nvidia+nvidia-proprietary+dgpu NVIDIA GeForce RTX 3080 Ti, 620.70.6 AMD Ryzen 9 3900X 12-Core Processor, 48 GB RAM
Scene: forest-field, from a new save (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); forest-field: 1 game start a side, forest 30 s after 10 s warm-up, field 30 s after 10 s warm-up; timed builds: main and this PR each built 2 times a cache, alternating, each a whole build in a fresh folder (lift; shader preparation not timed); each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (@Beanstalk on this PR runs it again)

Before: main @ c14641a After: this PR @ db7e4cc
forest-field · field · frame rate 79.6 81.5 (+2%)
forest-field · forest · frame rate 51.1 52.5 (+3%)
forest-field · field · frame time (p99) (ms) 15.2 14.7 (−3%)
forest-field · forest · frame time (p99) (ms) 23.5 22.7 (−4%)

Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept))

Before: main @ c14641a After: this PR @ db7e4cc
lift · whole build (s) 523.4 1,034 (+98%)
lift · read (s) 1.9 2.1 (+11%)
lift · lift (s) 85.8 97.7 (+14%)
lift · compile (s) 416.8 915.8 (+120%)
lift · finish (s) 18.6 18.7 (+0%)
lift · lifted C main's differs

Flags and settings

None: the plan varied no setting, switch or build option.

Markdown for the PR description
## Measurements

**Verdict:** fail on any (2/1 report): `forest-field screenshot.max_diff` failed.

Hardware: 1: linux+other `unknown, unknown` `AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM`; 2: linux+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3080 Ti, 620.70.6` `AMD Ryzen 9 3900X 12-Core Processor, 48 GB RAM`  
Scene: forest-field, from a new save (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them  
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); forest-field: 1 game start a side, forest 30 s after 10 s warm-up, field 30 s after 10 s warm-up; timed builds: main and this PR each built 2 times a cache, alternating, each a whole build in a fresh folder (lift; shader preparation not timed); each number the median of the runs, then of 2 reports  
How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again)

| | Before: main @ c14641a | After: this PR @ db7e4cc |
|---|---|---|
| forest-field · field · frame rate | 79.6 | 81.5 (+2%) |
| forest-field · forest · frame rate | 51.1 | 52.5 (+3%) |
| forest-field · field · frame time (p99) (ms) | 15.2 | 14.7 (−3%) |
| forest-field · forest · frame time (p99) (ms) | 23.5 | 22.7 (−4%) |

Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept))

| | Before: main @ c14641a | After: this PR @ db7e4cc |
|---|---|---|
| lift · whole build (s) | 523.4 | 1,034 (+98%) |
| lift · read (s) | 1.9 | 2.1 (+11%) |
| lift · lift (s) | 85.8 | 97.7 (+14%) |
| lift · compile (s) | 416.8 | 915.8 (+120%) |
| lift · finish (s) | 18.6 | 18.7 (+0%) |
| lift · lifted C | main's | differs |

### Flags and settings

None: the plan varied no setting, switch or build option.
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>db7e4cc</code> (the newer results are in a comment below)</summary> Commit `db7e4cc` · tier **double-reviewed** · approved by HumanBean, llun · [dashboard](https://beanstalk.magicbean.dev/prs/1469) **What will be tested** · AI plan (`gpt-6.1-terra`) The plan compares main and the pull request in Kokiri Forest and Hyrule Field, exercising movement, camera control and an area change. It measures frame rate and frametime, compares screenshots, and times repeated lifts and builds; gameplay takes about 14 minutes per tester, with build timing separate. Crashes, failed map transitions, substantial visual differences or major performance regressions fail the plan. - **Where:** any (any PC, 1-2 reports). - **forest-field:** from a new save (settings vsync=2, frame_rate_cap=6, frame_generation=0), then move the stick, press buttons, take the picture forest to compare with main, measure forest for 30 s (after 10 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 30 s (after 10 s warm-up); 1 run on each side. - **Build times:** main and the PR each built 2 times, alternating, each whole in a fresh folder: the lift again (no kept lift, main's compiled objects kept); every stage timed (shader preparation is not), and the lifted C compared. - **Measured:** crashes, frame times, stutters and hitches, draws and frame rate, load times. - **The PR fails if:** it crashes; or frame rate is more than 15% below main; or a picture differs from main by more than 15%; or frame time (p99) is more than 25% above main. - **Time:** about 15 min of game runs per tester (2 game starts), plus the two builds and 4 timed builds (about 80 min). Done (started 2026-11-17 21:36 UTC, last report 00:02 UTC). Comment `@Beanstalk` to run it again. This diff touches sensitive paths, so it needs two members of `BigBeans`: `nx2/fastfp.py`, `nx2/lift.py` | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | any · 1: linux+other `unknown, unknown`; 2: linux+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3080 Ti, 620.70.6` | 2/1 [1](https://beanstalk.magicbean.dev/reports/rp_1f73cfe9f2a053c9) [2](https://beanstalk.magicbean.dev/reports/rp_a74d1bc922a134a0) | none | 14.7 vs 15.2 (−3%) | — | fail | #### Measurements · any **Verdict:** fail on any (2/1 report): `forest-field screenshot.max_diff` failed. Hardware: 1: linux+other `unknown, unknown` `AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM`; 2: linux+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3080 Ti, 620.70.6` `AMD Ryzen 9 3900X 12-Core Processor, 48 GB RAM` Scene: forest-field, from a new save (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); forest-field: 1 game start a side, forest 30 s after 10 s warm-up, field 30 s after 10 s warm-up; timed builds: main and this PR each built 2 times a cache, alternating, each a whole build in a fresh folder (lift; shader preparation not timed); each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) | | Before: main @ c14641a | After: this PR @ db7e4cc | |---|---|---| | forest-field · field · frame rate | 79.6 | 81.5 (+2%) | | forest-field · forest · frame rate | 51.1 | 52.5 (+3%) | | forest-field · field · frame time (p99) (ms) | 15.2 | 14.7 (−3%) | | forest-field · forest · frame time (p99) (ms) | 23.5 | 22.7 (−4%) | Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept)) | | Before: main @ c14641a | After: this PR @ db7e4cc | |---|---|---| | lift · whole build (s) | 523.4 | 1,034 (+98%) | | lift · read (s) | 1.9 | 2.1 (+11%) | | lift · lift (s) | 85.8 | 97.7 (+14%) | | lift · compile (s) | 416.8 | 915.8 (+120%) | | lift · finish (s) | 18.6 | 18.7 (+0%) | | lift · lifted C | main's | differs | ### Flags and settings None: the plan varied no setting, switch or build option. <details><summary>Markdown for the PR description</summary> ```markdown ## Measurements **Verdict:** fail on any (2/1 report): `forest-field screenshot.max_diff` failed. Hardware: 1: linux+other `unknown, unknown` `AMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM`; 2: linux+nvidia+nvidia-proprietary+dgpu `NVIDIA GeForce RTX 3080 Ti, 620.70.6` `AMD Ryzen 9 3900X 12-Core Processor, 48 GB RAM` Scene: forest-field, from a new save (vsync=2, frame_rate_cap=6, frame_generation=0); each cell's settings and switches as the table names them Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); forest-field: 1 game start a side, forest 30 s after 10 s warm-up, field 30 s after 10 s warm-up; timed builds: main and this PR each built 2 times a cache, alternating, each a whole build in a fresh folder (lift; shader preparation not timed); each number the median of the runs, then of 2 reports How to reproduce: the farm's plan above (`@Beanstalk` on this PR runs it again) | | Before: main @ c14641a | After: this PR @ db7e4cc | |---|---|---| | forest-field · field · frame rate | 79.6 | 81.5 (+2%) | | forest-field · forest · frame rate | 51.1 | 52.5 (+3%) | | forest-field · field · frame time (p99) (ms) | 15.2 | 14.7 (−3%) | | forest-field · forest · frame time (p99) (ms) | 23.5 | 22.7 (−4%) | Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept)) | | Before: main @ c14641a | After: this PR @ db7e4cc | |---|---|---| | lift · whole build (s) | 523.4 | 1,034 (+98%) | | lift · read (s) | 1.9 | 2.1 (+11%) | | lift · lift (s) | 85.8 | 97.7 (+14%) | | lift · compile (s) | 416.8 | 915.8 (+120%) | | lift · finish (s) | 18.6 | 18.7 (+0%) | | lift · lifted C | main's | differs | ### Flags and settings None: the plan varied no setting, switch or build option. ``` </details> </details>
Owner

@Beanstalk

@Beanstalk
Author
First-time contributor

One crash seen on this branch (1354234e), 1 of about 31 runs of local-register builds so far; main had none in about 20. In the 10 s after the camera script started, Kokiri: \CRASH: exception 0xc0000374\ (heap corruption) on the Presentation Thread, in the renderer's \operator new\ from
efresh_pool_ranges_locked\ < \capture_make\ < \memory_capture_submit\ < \submit_q\ (gpu/vk/vk_memory.cpp), guest lr 0x80590358 (the present). The heap was damaged before that point, by whatever wrote it. A mistranslated store going outside the guest's memory could do that, so this isn't ruled out as the PR's yet. Next: a soak of about 10 alternating launches each of main and this branch, to see whether it follows the branch. Testers: if you see \

One crash seen on this branch (1354234e), 1 of about 31 runs of local-register builds so far; main had none in about 20. In the 10 s after the camera script started, Kokiri: \CRASH: exception 0xc0000374\ (heap corruption) on the Presentation Thread, in the renderer's \operator new\ from \ efresh_pool_ranges_locked\ < \capture_make\ < \memory_capture_submit\ < \submit_q\ (gpu/vk/vk_memory.cpp), guest lr 0x80590358 (the present). The heap was damaged before that point, by whatever wrote it. A mistranslated store going outside the guest's memory could do that, so this isn't ruled out as the PR's yet. Next: a soak of about 10 alternating launches each of main and this branch, to see whether it follows the branch. Testers: if you see \
Owner

A run of this on Linux, for the Market and for the build time, which the description doesn't cover. It does not reproduce the gain here, and the build is slower. Two pairs on a PC that was swapping, so this is a first reading and more runs are coming.

The PC: Ryzen 9 7900X (24 threads), RTX 3090, NVIDIA 620.70, Linux, 2560x1440, no upscaler, no cap. Head db7e4cc2 against its merge base with main, c14641a6, each built from nothing (LONGSHOT_OBJ_STORE=0 LONGSHOT_LIFT_STORE=0), so the two differ only by this pull request.

Build time

main c14641a6 this PR
make_game.py before the shaders 484 s 594 s +110 s (+23%)
Compile 298 s 494 s +196 s (+66%)
Lifted files, summed compile seconds 2,751 s 3,592 s +31%
Longest lifted file 72 s (code_028.c) 171 s (code_025_1.c) 2.4 times; six files over 115 s
Lifted C 1,565 MB 1,645 MB +5%
longshot 544 MB 534 MB -2%

One build each. Two test jobs ran beside the baseline's lift and the start of its compile, and nothing beside this PR's, so the difference is if anything larger than the table says. The description's "the build here was no slower" is not what this PC measured: about three minutes more on a 24-thread CPU, and the longest file sets the earliest a build can end on any CPU.

In the game

Standing 20 s in each area, after one discarded warm-up session per build, interleaved. game_ms is the frame trace's (RX_VK_FRAME_TRACE=1): the game's own loop, median over the standing section.

Kokiri Forest fps game_ms the Market fps game_ms
pair 1, main 58.2 8.96 65.3 10.97
pair 1, this PR 60.0 12.69 62.5 13.55
pair 2, main 62.5 10.11 64.6 11.50
pair 2, this PR 60.8 9.66 64.3 12.68
  • fps: within 3% either way in both areas, no direction.
  • game_ms: longer with this PR in the Market in both pairs (+2.6 and +1.2 ms); in Kokiri Forest much longer in one pair and a little shorter in the other.
  • The pictures differ from main's as two sessions of main do (mean absolute error 0.023 and 0.012 of 1, against 0.020 and 0.009); no crash, assert or fault line in any log. Twenty-second sections are not a correctness test of a lifter change.

What makes this weak: the PC was swapping in every session (tens to hundreds of thousands of pages swapped in per section), and one session of this PR ran beside another build. game_ms and the wait for the GPU also trade places between the builds (Kokiri, pair 1: 8.96 + 3.33 against 12.69 + 1.65), so part of the difference may be where a wait is counted. A 14% gain would still show through that; it does not.

What may explain the difference from the description's +14%: a CPU two generations newer here (in the Market on this PC the frame is the game's loop at about 13 ms with the GPU 66% busy; in Kokiri Forest the GPU is about 78% busy, so less of a CPU gain reaches fps); clang on Linux against llvm-mingw; and main's pipeline cache being only part built in the description's runs.

Still to do here: two more pairs, and a profile pair standing in the Market that reads the lifted code's own time on the executor and worker threads, which is the direct test of what this change does. I'll post those.

Not tested: Windows, AMD, Intel, a slower CPU (where the description's gain was measured), and anything longer than these sections.

🤖 Generated with Claude Code

A run of this on Linux, for the Market and for the build time, which the description doesn't cover. **It does not reproduce the gain here, and the build is slower. Two pairs on a PC that was swapping, so this is a first reading and more runs are coming.** **The PC:** Ryzen 9 7900X (24 threads), RTX 3090, NVIDIA 620.70, Linux, 2560x1440, no upscaler, no cap. Head db7e4cc2 against its merge base with main, c14641a6, each built from nothing (`LONGSHOT_OBJ_STORE=0 LONGSHOT_LIFT_STORE=0`), so the two differ only by this pull request. ### Build time | | main c14641a6 | this PR | | |---|---|---|---| | `make_game.py` before the shaders | 484 s | 594 s | +110 s (+23%) | | Compile | 298 s | 494 s | **+196 s (+66%)** | | Lifted files, summed compile seconds | 2,751 s | 3,592 s | +31% | | Longest lifted file | 72 s (`code_028.c`) | 171 s (`code_025_1.c`) | 2.4 times; six files over 115 s | | Lifted C | 1,565 MB | 1,645 MB | +5% | | `longshot` | 544 MB | 534 MB | -2% | One build each. Two test jobs ran beside the baseline's lift and the start of its compile, and nothing beside this PR's, so the difference is if anything larger than the table says. The description's "the build here was no slower" is not what this PC measured: about three minutes more on a 24-thread CPU, and the longest file sets the earliest a build can end on any CPU. ### In the game Standing 20 s in each area, after one discarded warm-up session per build, interleaved. `game_ms` is the frame trace's (`RX_VK_FRAME_TRACE=1`): the game's own loop, median over the standing section. | | Kokiri Forest fps | `game_ms` | the Market fps | `game_ms` | |---|---|---|---|---| | pair 1, main | 58.2 | 8.96 | 65.3 | 10.97 | | pair 1, this PR | 60.0 | 12.69 | 62.5 | 13.55 | | pair 2, main | 62.5 | 10.11 | 64.6 | 11.50 | | pair 2, this PR | 60.8 | 9.66 | 64.3 | 12.68 | - **fps:** within 3% either way in both areas, no direction. - **`game_ms`:** longer with this PR in the Market in both pairs (+2.6 and +1.2 ms); in Kokiri Forest much longer in one pair and a little shorter in the other. - The pictures differ from main's as two sessions of main do (mean absolute error 0.023 and 0.012 of 1, against 0.020 and 0.009); no crash, assert or fault line in any log. Twenty-second sections are not a correctness test of a lifter change. **What makes this weak:** the PC was swapping in every session (tens to hundreds of thousands of pages swapped in per section), and one session of this PR ran beside another build. `game_ms` and the wait for the GPU also trade places between the builds (Kokiri, pair 1: 8.96 + 3.33 against 12.69 + 1.65), so part of the difference may be where a wait is counted. A 14% gain would still show through that; it does not. **What may explain the difference from the description's +14%:** a CPU two generations newer here (in the Market on this PC the frame is the game's loop at about 13 ms with the GPU 66% busy; in Kokiri Forest the GPU is about 78% busy, so less of a CPU gain reaches fps); clang on Linux against llvm-mingw; and main's pipeline cache being only part built in the description's runs. **Still to do here:** two more pairs, and a profile pair standing in the Market that reads the lifted code's own time on the executor and worker threads, which is the direct test of what this change does. I'll post those. Not tested: Windows, AMD, Intel, a slower CPU (where the description's gain was measured), and anything longer than these sections. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
First-time contributor

Thanks, HumanBean, that's the run this needed.

  • Build time: you're right, and the description was wrong. My builds reused the object cache, so "no slower" was never measured. Your from-scratch +66% compile (longest file 72 → 171 s) is now in Risks as a cost to work on before ready: which files grew, and whether #385's splitting can cut functions with locals instead of leaving them whole.
  • The farm's "compile +1687%" compares main with its compiled objects kept against this PR compiling everything, so it measures the cache more than the change. Your from-scratch numbers are the ones to go by.
  • fps: agreed that a 7900X with the GPU 66-78% busy leaves this little to move. The gain was measured where the frame is the game's code on a 24-thread Zen 2 (3900X, 46 → 53 fps in Kokiri). Your game_ms profile in the Market is the direct test. I'll add the same from the 3900X: RX_VK_FRAME_TRACE=1, game_ms medians, main against this branch, interleaved, standing and turning in Kokiri. If game_ms doesn't drop there either, the fps gain I measured needs another explanation and I'll say so.
  • Also still open from my side: a soak for the one 0xc0000374 crash (above), to see whether it follows the branch.
Thanks, HumanBean, that's the run this needed. - **Build time: you're right, and the description was wrong.** My builds reused the object cache, so "no slower" was never measured. Your from-scratch +66% compile (longest file 72 → 171 s) is now in Risks as a cost to work on before ready: which files grew, and whether #385's splitting can cut functions with locals instead of leaving them whole. - **The farm's "compile +1687%"** compares main with its compiled objects kept against this PR compiling everything, so it measures the cache more than the change. Your from-scratch numbers are the ones to go by. - **fps:** agreed that a 7900X with the GPU 66-78% busy leaves this little to move. The gain was measured where the frame is the game's code on a 24-thread Zen 2 (3900X, 46 → 53 fps in Kokiri). Your `game_ms` profile in the Market is the direct test. I'll add the same from the 3900X: `RX_VK_FRAME_TRACE=1`, `game_ms` medians, main against this branch, interleaved, standing and turning in Kokiri. If `game_ms` doesn't drop there either, the fps gain I measured needs another explanation and I'll say so. - Also still open from my side: a soak for the one `0xc0000374` crash (above), to see whether it follows the branch.
Author
First-time contributor

The soak and the frame trace from the 3900X (Windows 11, RX 6750 XT, Kokiri Forest, bench save, the 60 s camera script; RX_VK_FRAME_TRACE=1; main c14641a6 and this branch 1354234e alternating, 10 launches each, unattended):

Crashes: none in 20 launches. With the runs before, 0xc0000374 is now 1 in about 41 runs of local-register builds and 0 in about 30 of main: still unexplained, rare, and not clearly following the branch.

fps: +11.8%, this branch faster in 10 of 10 pairs. Mean of each run's fps lines: main 47.6 to 49.95 (mean 48.6), this branch 51.6 to 58.1 (mean 54.3).

Where the frame went (median over the script's frames, one run each, the last pair; every pair looks the same):

main this PR
ms (the frame) 19.58 17.98 −1.60
game_ms 12.23 13.54 +1.31
wait_gpu_ms 3.41 1.92 −1.49
wait_main_ms 3.26 1.77 −1.49
main_blocked_ms 15.13 13.58 −1.55
draw_ms / desc_ms / cmds_ms / programs_ms 7.20 / 3.23 / 2.10 / 1.06 7.36 / 3.35 / 2.15 / 1.08 the same work

game_ms per run: main 12.23 to 12.78, this branch 13.14 to 14.87, longer in every pair, as you saw in the Market. So game_ms going up is real and reproducible, but on this PC it comes with a shorter frame: the GPU wait and the render thread's wait on the game each fall about 1.5 ms, and the game's main thread is blocked 1.55 ms less. Which parts are the lifted code's own time I can't split from the trace: game_ms holds waits too, which is why it and wait_gpu_ms trade. Your profile pair reading the lifted code's time on the executor and worker threads is the right test; I'll try the same here (HOS_PROFILE needs #1343 on Windows, so on a local build with it).

Also measured since, on top of this branch, 5 interleaved rounds each: 8 registers with the flags no better than 6 (53.2 vs 53.2 fps); LONGSHOT_LIGHT_PASSES=0 no gain; every lifted file at -O2 +2.7% but a 55-minute build, so not proposed.

The soak and the frame trace from the 3900X (Windows 11, RX 6750 XT, Kokiri Forest, bench save, the 60 s camera script; `RX_VK_FRAME_TRACE=1`; main c14641a6 and this branch 1354234e alternating, 10 launches each, unattended): **Crashes: none in 20 launches.** With the runs before, `0xc0000374` is now 1 in about 41 runs of local-register builds and 0 in about 30 of main: still unexplained, rare, and not clearly following the branch. **fps: +11.8%, this branch faster in 10 of 10 pairs.** Mean of each run's fps lines: main 47.6 to 49.95 (mean 48.6), this branch 51.6 to 58.1 (mean 54.3). **Where the frame went** (median over the script's frames, one run each, the last pair; every pair looks the same): | | main | this PR | | |---|---|---|---| | `ms` (the frame) | 19.58 | 17.98 | −1.60 | | `game_ms` | 12.23 | 13.54 | +1.31 | | `wait_gpu_ms` | 3.41 | 1.92 | −1.49 | | `wait_main_ms` | 3.26 | 1.77 | −1.49 | | `main_blocked_ms` | 15.13 | 13.58 | −1.55 | | `draw_ms` / `desc_ms` / `cmds_ms` / `programs_ms` | 7.20 / 3.23 / 2.10 / 1.06 | 7.36 / 3.35 / 2.15 / 1.08 | the same work | `game_ms` per run: main 12.23 to 12.78, this branch 13.14 to 14.87, longer in every pair, as you saw in the Market. So `game_ms` going up is real and reproducible, but on this PC it comes with a shorter frame: the GPU wait and the render thread's wait on the game each fall about 1.5 ms, and the game's main thread is blocked 1.55 ms less. Which parts are the lifted code's own time I can't split from the trace: `game_ms` holds waits too, which is why it and `wait_gpu_ms` trade. Your profile pair reading the lifted code's time on the executor and worker threads is the right test; I'll try the same here (HOS_PROFILE needs #1343 on Windows, so on a local build with it). Also measured since, on top of this branch, 5 interleaved rounds each: 8 registers with the flags no better than 6 (53.2 vs 53.2 fps); `LONGSHOT_LIGHT_PASSES=0` no gain; every lifted file at -O2 +2.7% but a 55-minute build, so not proposed.
Author
First-time contributor

The profile pair, the direct test: the lifted code's own CPU time per frame on the 3900X.

How: one branch (this PR + #1343 + #1321, local only) built twice from the same work folder, with this PR's defaults and with A64_LOCAL_REGS=0 A64_LOCAL_FLAGS=, so the two differ only by local registers. HOS_PROFILE=1, the same camera script in Kokiri Forest, two runs each, alternating. From all.txt: over the script's last 60 s, the samples (2 ms a tick) whose leaf is lifted code (f_…, and #385's s_…_N pieces, which only the side without locals has), in ms per presented frame, by thread group.

lifted code, ms per frame run 1 run 2
workers (ModuleSystemWorker, BaseProcExecutor), locals on 7.55 7.83
workers, locals off 8.12 8.24
main thread, on / off 0.62 / 0.64 0.62 / 0.65

The lifted code takes 5 to 7% less CPU per frame on the workers (−0.57 and −0.41 ms); the runtime's own code in longshot.exe is the same on both sides (1.84 to 1.90 ms on the workers). The frame shortens by more than that total (1.6 ms in the soak) because the part that counts is on the chain the main thread waits for, which main_blocked_ms −1.55 also shows. And game_ms doesn't measure this: it counts the main thread's loop with its waits, not the workers' code.

A caution for anyone reading profiles of this: without locals, #385 cuts the giant functions into s_<addr>_<n> pieces; with locals they stay whole as f_<addr>. A share that counts only f_ makes the lifted code look 25% more expensive with this PR (8.2 against 6.6 ms here) when it is less.

Profiling costs fps (40 to 44 here), so these runs give no fps figures; the soak above has those.

The profile pair, the direct test: the lifted code's own CPU time per frame on the 3900X. **How:** one branch (this PR + #1343 + #1321, local only) built twice from the same work folder, with this PR's defaults and with `A64_LOCAL_REGS=0 A64_LOCAL_FLAGS=`, so the two differ only by local registers. `HOS_PROFILE=1`, the same camera script in Kokiri Forest, two runs each, alternating. From `all.txt`: over the script's last 60 s, the samples (2 ms a tick) whose leaf is lifted code (`f_…`, and #385's `s_…_N` pieces, which only the side without locals has), in ms per presented frame, by thread group. | lifted code, ms per frame | run 1 | run 2 | |---|---|---| | workers (ModuleSystemWorker, BaseProcExecutor), locals on | 7.55 | 7.83 | | workers, locals off | 8.12 | 8.24 | | main thread, on / off | 0.62 / 0.64 | 0.62 / 0.65 | **The lifted code takes 5 to 7% less CPU per frame on the workers** (−0.57 and −0.41 ms); the runtime's own code in longshot.exe is the same on both sides (1.84 to 1.90 ms on the workers). The frame shortens by more than that total (1.6 ms in the soak) because the part that counts is on the chain the main thread waits for, which `main_blocked_ms` −1.55 also shows. And `game_ms` doesn't measure this: it counts the main thread's loop with its waits, not the workers' code. A caution for anyone reading profiles of this: without locals, #385 cuts the giant functions into `s_<addr>_<n>` pieces; with locals they stay whole as `f_<addr>`. A share that counts only `f_` makes the lifted code look 25% *more* expensive with this PR (8.2 against 6.6 ms here) when it is less. Profiling costs fps (40 to 44 here), so these runs give no fps figures; the soak above has those.
marclemieux64 force-pushed local-regs from db7e4cc287
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 4s
beanstalk/approval approved by HumanBean, llun (double-reviewed)
beanstalk/any 1/1 fail
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 0332de56d0
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
beanstalk/approval not approved yet
2026-11-18 02:35:56 +00:00
Compare
Member

Beanstalk test farm

Commit 0332de5 · tier untrusted · approved by nobody yet · dashboard

This diff touches sensitive paths, so it needs two members of BigBeans: nx2/fastfp.py, nx2/lift.py

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `0332de5` · tier **untrusted** · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1469) This diff touches sensitive paths, so it needs two members of `BigBeans`: `nx2/fastfp.py`, `nx2/lift.py` A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Author
First-time contributor

Rebased on main a35130c0 (no conflicts), now 0332de56.

  • #1209's new nx2/entry_hooks.py writes lifted C with register names, and the new check caught it, as it should. It keeps its hooked functions in Lifter.no_local itself, so it is safe; the check now accepts a module that does that (test(lift) commit).
  • test_libc_hooks.py fails here and on main a35130c0 alike: it looks for L.discover( in nx2/lift.py, which calls discover.discover(L, ...).
  • The description follows the new template (TL;DR, Breakdown, the two new boxes), and now has the soak, the profile pair and the build time in it.
  • Measuring now on the 3900X: main a35130c0 against this branch, 5 interleaved rounds, after a warm start of each so a pipeline rebuild can't skew it; then this branch with LONGSHOT_CHUNK_OPT=all (#1431). I'll post both.
Rebased on main a35130c0 (no conflicts), now 0332de56. - #1209's new `nx2/entry_hooks.py` writes lifted C with register names, and the new check caught it, as it should. It keeps its hooked functions in `Lifter.no_local` itself, so it is safe; the check now accepts a module that does that (`test(lift)` commit). - `test_libc_hooks.py` fails here and on main a35130c0 alike: it looks for `L.discover(` in nx2/lift.py, which calls `discover.discover(L, ...)`. - The description follows the new template (TL;DR, Breakdown, the two new boxes), and now has the soak, the profile pair and the build time in it. - Measuring now on the 3900X: main a35130c0 against this branch, 5 interleaved rounds, after a warm start of each so a pipeline rebuild can't skew it; then this branch with `LONGSHOT_CHUNK_OPT=all` (#1431). I'll post both.
Contributor

A build finding on this PR, from a Linux build for a Steam Deck A/B (not run in game): with local registers on, one of main's text patches no longer applies, and the build only warns.

Build: this PR's two commits (db7e4cc2) cherry-picked onto main 544229a2 (e6d55bf1 + 5724b7df, added and deleted lines identical to the PR's), built the same way as main 544229a2: Linux x86-64-v3, tools.lock a3dc5d80, no hot list, no A64_LOCAL_* in the environment (so this PR's defaults: 6 registers and flags as locals). At 0332de56 (on main a35130c0) the same matcher and name-based exclusion remain in the source; we have not rebuilt this head. patched_functions and patch_dynres are unchanged, no patch module names f_80825aa0, and this PR's lift.py/fastfp.py hunks match db7e4cc2's.

What happens: nx2/oot_patches.py's dynamic resolution switch (patch_dynres) finds its site by its OLD text if (!((c->x[8] >> 0) & 1)) { goto L_8082640c; } in f_80825aa0.

  • main 544229a2: applied (oot_patches: dynamic resolution switch).
  • this PR: the generated branch in f_80825aa0 uses a local-register name rather than the context-register spelling patch_dynres expects, so the build logs oot_patches: WARNING: the dynamic resolution branch was found 0 times and carries on.
  • The other 45 patch-log lines are the same as main's. Our check of the lifted C (a script on our side) passes: the 76 functions the text patches name and the 15 with spliced hooks have no locals. This patch names a label, not its function, so patched_functions doesn't exclude f_80825aa0.

Why it matters (from the host code, not measured): hos_dynres_runs starts at 0 and its increment is supplied by the missing patch. host/nn_vi.c assigns hos_fixed_resolution = !rx_option(2, 1) && hos_dynres_runs >= 30;, so it would remain 0. The host would therefore not force the requested fixed scale; the game's original resolution-selection path would remain in charge. A fixed-Resolution fps comparison could consequently include a resolution difference as well as local-register effects. We have not measured the resulting in-game resolution or fps.

Possible fixes (yours to choose): restore the exclusion or the match (e.g. keep f_80825aa0 out of locals, or have patched_functions find the function holding each text patch's site), and make a missing required patch fail the build so this can't silently recur.

We have paused this older-head Deck A/B; could you check that the dynamic-resolution patch is applied on 0332de56 before we rebuild?

A build finding on this PR, from a Linux build for a Steam Deck A/B (not run in game): **with local registers on, one of main's text patches no longer applies, and the build only warns.** **Build:** this PR's two commits (db7e4cc2) cherry-picked onto main 544229a2 (e6d55bf1 + 5724b7df, added and deleted lines identical to the PR's), built the same way as main 544229a2: Linux x86-64-v3, tools.lock a3dc5d80, no hot list, no `A64_LOCAL_*` in the environment (so this PR's defaults: 6 registers and flags as locals). At 0332de56 (on main a35130c0) the same matcher and name-based exclusion remain in the source; we have not rebuilt this head. `patched_functions` and `patch_dynres` are unchanged, no patch module names `f_80825aa0`, and this PR's lift.py/fastfp.py hunks match db7e4cc2's. **What happens:** `nx2/oot_patches.py`'s dynamic resolution switch (`patch_dynres`) finds its site by its OLD text `if (!((c->x[8] >> 0) & 1)) { goto L_8082640c; }` in `f_80825aa0`. - main 544229a2: applied (`oot_patches: dynamic resolution switch`). - this PR: the generated branch in `f_80825aa0` uses a local-register name rather than the context-register spelling `patch_dynres` expects, so the build logs `oot_patches: WARNING: the dynamic resolution branch was found 0 times` and carries on. - The other 45 patch-log lines are the same as main's. Our check of the lifted C (a script on our side) passes: the 76 functions the text patches name and the 15 with spliced hooks have no locals. This patch names a label, not its function, so `patched_functions` doesn't exclude `f_80825aa0`. **Why it matters (from the host code, not measured):** `hos_dynres_runs` starts at 0 and its increment is supplied by the missing patch. `host/nn_vi.c` assigns `hos_fixed_resolution = !rx_option(2, 1) && hos_dynres_runs >= 30;`, so it would remain 0. The host would therefore not force the requested fixed scale; the game's original resolution-selection path would remain in charge. A fixed-Resolution fps comparison could consequently include a resolution difference as well as local-register effects. We have not measured the resulting in-game resolution or fps. **Possible fixes (yours to choose):** restore the exclusion or the match (e.g. keep `f_80825aa0` out of locals, or have `patched_functions` find the function holding each text patch's site), and make a missing required patch fail the build so this can't silently recur. We have paused this older-head Deck A/B; could you check that the dynamic-resolution patch is applied on 0332de56 before we rebuild?
Author
First-time contributor

Thank you, dukenheimer: confirmed, and it's worse than one patch.

On 0332de56 (rebased on a35130c0), the patch log against main's, same work folder: two patches are lost, both only warning:

  • oot_patches: WARNING: the dynamic resolution branch was found 0 times (main: dynamic resolution switch in code_007.c): as you found, patch_dynres anchors on L_8082640c, a label, and patched_functions only collected f_ names, so f_80825aa0 got locals.
  • oot_patches: WARNING: the horse's jump step test was found 0 times, not once (main, since #1434: a horse's jump blend above 60 fps in code_040.c). Its function is kept in the context, but A64_LOCAL_FLAGS changes how a64-kit writes every scalar float compare (vectorize_fcmp: _fk = a64_fcmp32k(...) with the flags' stores in the text, in every function), so HORSE_TEST no longer matches.

The other 47 patch lines are identical to main's.

Fixes, on my side, not pushed until a build shows the log equal to main's:

  • nx2/lift.py labelled_functions(): every function holding a label (L_XXXXXXXX) named in the patch modules keeps the context too, the general form of your first suggestion. The check covers it (a made-up Lifter, and that L_8082640c is among the labels).
  • nx2/oot_patches.py: patch_horse_jump takes the compare in either form (HORSE_TESTS); applied offline to this branch's lifted code_040.c it patches, and tests/test_horse_jump_step.py passes.
  • Your second suggestion, failing the build on a lost patch, I agree with; it touches every build's patch report, so I'd rather do it as its own PR unless you think it belongs here.

What this means for the measurements: every local-register build I measured, from the first overnight runs to the soak and the profile's "on" side, lacked the dynamic resolution patch; main and the profile's "off" side had it. With Resolution 100%, hos_fixed_resolution then never turns on, and if the game's own dynamic resolution lowered the 3D's size on this PC, part of the +12% would be resolution, not registers. I don't know yet: running main a35130c0 and this branch now with HOS_RES_LOG=1 to read the 3D scale each side runs at, then measuring the fixed build against main with the scale logged. Until then, please read the fps numbers above as unconfirmed. (The profile pair's lifted-code ms per frame is less exposed, but its "on" side lacked the patch too.)

Thank you, dukenheimer: confirmed, and it's worse than one patch. **On 0332de56 (rebased on a35130c0), the patch log against main's, same work folder:** two patches are lost, both only warning: - `oot_patches: WARNING: the dynamic resolution branch was found 0 times` (main: `dynamic resolution switch in code_007.c`): as you found, `patch_dynres` anchors on `L_8082640c`, a label, and `patched_functions` only collected `f_` names, so `f_80825aa0` got locals. - `oot_patches: WARNING: the horse's jump step test was found 0 times, not once` (main, since #1434: `a horse's jump blend above 60 fps in code_040.c`). Its function is kept in the context, but `A64_LOCAL_FLAGS` changes how a64-kit writes every scalar float compare (`vectorize_fcmp`: `_fk = a64_fcmp32k(...)` with the flags' stores in the text, in every function), so `HORSE_TEST` no longer matches. The other 47 patch lines are identical to main's. **Fixes, on my side, not pushed until a build shows the log equal to main's:** - `nx2/lift.py` `labelled_functions()`: every function holding a label (`L_XXXXXXXX`) named in the patch modules keeps the context too, the general form of your first suggestion. The check covers it (a made-up Lifter, and that `L_8082640c` is among the labels). - `nx2/oot_patches.py`: `patch_horse_jump` takes the compare in either form (`HORSE_TESTS`); applied offline to this branch's lifted `code_040.c` it patches, and `tests/test_horse_jump_step.py` passes. - Your second suggestion, failing the build on a lost patch, I agree with; it touches every build's patch report, so I'd rather do it as its own PR unless you think it belongs here. **What this means for the measurements:** every local-register build I measured, from the first overnight runs to the soak and the profile's "on" side, lacked the dynamic resolution patch; main and the profile's "off" side had it. With Resolution 100%, `hos_fixed_resolution` then never turns on, and if the game's own dynamic resolution lowered the 3D's size on this PC, part of the +12% would be resolution, not registers. I don't know yet: running main a35130c0 and this branch now with `HOS_RES_LOG=1` to read the 3D scale each side runs at, then measuring the fixed build against main with the scale logged. Until then, please read the fps numbers above as unconfirmed. (The profile pair's lifted-code ms per frame is less exposed, but its "on" side lacked the patch too.)
Author
First-time contributor

Confirmed: the fps gain I reported is not valid. With HOS_RES_LOG=1, one run each, Kokiri Forest, the same script and settings (Resolution 100%):

main a35130c0:              vi: res: fixed 1 (scale 1.000), ... +0xe50 1440 2560 1440, 3D scale 1.000   (48.3 fps)
this branch at 0332de56:    vi: res: fixed 0 (scale 1.000), ... +0xe50 1440 2560 1440, 3D scale 0.750   (52.6 fps)

Without the dynamic resolution patch, hos_fixed_resolution never turned on and the game's own dynamic resolution ran the 3D at 75%. So every fps comparison in this PR so far set a local-register build at 75% against main at 100%; that is also why wait_gpu_ms fell in the soak. Thanks again, dukenheimer, and HumanBean, whose doubt was right.

Still standing, as far as I can tell: the profile pair's lifted-code CPU per frame (−5 to −7% on the workers), which a resolution change shouldn't move much, though its "on" side lacked the patch too.

Now running: the fixed build (the two patch fixes above), stopped before measuring unless its patch log equals main's line for line, then 5 interleaved rounds against main a35130c0 with the 3D scale read from every run's log. The description's verdict is marked unconfirmed until then. If the gain at the same resolution is small or none, I'll say so here and change or close this PR.

**Confirmed: the fps gain I reported is not valid.** With `HOS_RES_LOG=1`, one run each, Kokiri Forest, the same script and settings (Resolution 100%): ``` main a35130c0: vi: res: fixed 1 (scale 1.000), ... +0xe50 1440 2560 1440, 3D scale 1.000 (48.3 fps) this branch at 0332de56: vi: res: fixed 0 (scale 1.000), ... +0xe50 1440 2560 1440, 3D scale 0.750 (52.6 fps) ``` Without the dynamic resolution patch, `hos_fixed_resolution` never turned on and the game's own dynamic resolution ran the 3D at 75%. So every fps comparison in this PR so far set a local-register build at 75% against main at 100%; that is also why `wait_gpu_ms` fell in the soak. Thanks again, dukenheimer, and HumanBean, whose doubt was right. Still standing, as far as I can tell: the profile pair's lifted-code CPU per frame (−5 to −7% on the workers), which a resolution change shouldn't move much, though its "on" side lacked the patch too. Now running: the fixed build (the two patch fixes above), stopped before measuring unless its patch log equals main's line for line, then 5 interleaved rounds against main a35130c0 with the 3D scale read from every run's log. The description's verdict is marked unconfirmed until then. If the gain at the same resolution is small or none, I'll say so here and change or close this PR.
Author
First-time contributor

Closing this. The fps gain I reported was the 3D running at 75% on the local-register builds against 100% on main (the lost dynamic resolution patch), not the change itself; no measurement at the same resolution was finished.

For anyone who picks the idea up again, what this PR found that still holds:

  • A64_LOCAL_REGS / A64_LOCAL_FLAGS silently break text patches unless their functions keep the context: those named by f_ (76), those holding a label a patch anchors on (patch_dynres, L_8082640c), those with spliced C (Lifter.after; hos_oot_shadow writes c->x[23]), and #1209's entry hooks (which handle it themselves). A64_LOCAL_FLAGS also rewrites every scalar float compare (a64_fcmp32k), which broke #1434's horse patch.
  • Before trusting any lift change's fps: diff the build's oot_patches lines against main's, and run with HOS_RES_LOG=1 to see both sides at 3D scale 1.000.
  • The profile pair suggested the lifted code takes 5 to 7% less CPU per frame on the workers with locals, but its "on" side lacked the patch too; the build is about 66% slower from scratch (HumanBean).

The branch with the label and horse-patch fixes (uncommitted when this closes) stays on my fork. Thanks dukenheimer and HumanBean for catching what I didn't.

Closing this. The fps gain I reported was the 3D running at 75% on the local-register builds against 100% on main (the lost dynamic resolution patch), not the change itself; no measurement at the same resolution was finished. For anyone who picks the idea up again, what this PR found that still holds: - `A64_LOCAL_REGS` / `A64_LOCAL_FLAGS` silently break text patches unless their functions keep the context: those named by `f_` (76), those holding a label a patch anchors on (`patch_dynres`, `L_8082640c`), those with spliced C (`Lifter.after`; `hos_oot_shadow` writes `c->x[23]`), and #1209's entry hooks (which handle it themselves). `A64_LOCAL_FLAGS` also rewrites every scalar float compare (`a64_fcmp32k`), which broke #1434's horse patch. - Before trusting any lift change's fps: diff the build's `oot_patches` lines against main's, and run with `HOS_RES_LOG=1` to see both sides at `3D scale 1.000`. - The profile pair suggested the lifted code takes 5 to 7% less CPU per frame on the workers with locals, but its "on" side lacked the patch too; the build is about 66% slower from scratch (HumanBean). The branch with the label and horse-patch fixes (uncommitted when this closes) stays on my fork. Thanks dukenheimer and HumanBean for catching what I didn't.
marclemieux64 closed this pull request 2026-11-18 05:04:48 +00:00
Member

Three things found while measuring this on a Ryzen 9 3900X + RTX 3080 (Windows 11), over 310e7c9d with #1560:

  1. The entry goto skips the locals' loads. In functions whose code starts below their entry point (26 in a lift of OoT, nx2/lift_fixes.py's fix 4), the goto L_<entry>; goes in right after the head, before localize_regs declares and loads the register locals, so with local registers on those functions start on whatever the stack holds. #1587 fixes it, with a test that fails on main; a default build's lift is byte-identical.
  2. A64_LOCAL_FLAGS breaks two game patches. With flags as locals the kit writes every FCMP in another form, and the horse jump and dynamic-resolution patches in nx2/oot_patches.py, which match the C text, no longer find their lines (the lift prints oot_patches: WARNING for both). The dynamic-resolution patch also anchors at a label rather than a function name, so it misses in a registers-only build too unless that function is kept out of localisation.
  3. Measured, registers only (A64_LOCAL_REGS=6, flags left in the context, with #1587's fix), 3 interleaved rounds a side of a Hyrule Field walk and look round, then the Market, from a save: Hyrule Field 48.9 → 48.9 fps (+0.2%), Market 33.3 → 33.9 (+1.6%); p99 no better. Within noise on this PC; the game threads' time a frame moved 0.2-0.4 ms.
Three things found while measuring this on a Ryzen 9 3900X + RTX 3080 (Windows 11), over `310e7c9d` with #1560: 1. **The entry goto skips the locals' loads.** In functions whose code starts below their entry point (26 in a lift of OoT, `nx2/lift_fixes.py`'s fix 4), the `goto L_<entry>;` goes in right after the head, before `localize_regs` declares and loads the register locals, so with local registers on those functions start on whatever the stack holds. #1587 fixes it, with a test that fails on main; a default build's lift is byte-identical. 2. **`A64_LOCAL_FLAGS` breaks two game patches.** With flags as locals the kit writes every FCMP in another form, and the horse jump and dynamic-resolution patches in `nx2/oot_patches.py`, which match the C text, no longer find their lines (the lift prints `oot_patches: WARNING` for both). The dynamic-resolution patch also anchors at a label rather than a function name, so it misses in a registers-only build too unless that function is kept out of localisation. 3. **Measured, registers only** (`A64_LOCAL_REGS=6`, flags left in the context, with #1587's fix), 3 interleaved rounds a side of a Hyrule Field walk and look round, then the Market, from a save: Hyrule Field 48.9 → 48.9 fps (+0.2%), Market 33.3 → 33.9 (+1.6%); p99 no better. Within noise on this PC; the game threads' time a frame moved 0.2-0.4 ms.
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
beanstalk/approval not approved yet

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1469
No description provided.