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
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1469
Loading…
Reference in a new issue
No description provided.
Delete branch "marclemieux64/Longshot:local-regs"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
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'snmost-used registers as C locals) andA64_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.
nx2/lift.py'sLOCAL_DEFAULTS(A64_LOCAL_REGS=6,A64_LOCAL_FLAGS=1), set withsetdefaultat the top ofmain(), 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.patched_functions(): everyf_XXXXXXXXnamed inPATCH_MODULES(oot_patches.py, lift_fixes.py, fastfp.py) joinsLifter.no_local. Their text matchesc->x[N]andc->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.spliced_functions(): every function with C spliced in after one of its instructions (Lifter.after: oot_wide, oot_fov, oot_shadow, oot_jitter) joinsno_localtoo. That C hands the context to the host, andhos_oot_shadowreads and writesc->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 nox23_. (#1209'sentry_hooks.pykeeps its own hooked functions inno_local.)nx2/fastfp.py'semit_functionkeeps ano_localfunction's flags in the context too (a64-kit's would rename them; oot_patches matchesc->z). Tagged# (fastfp)as the copy's check wants.tests/test_local_regs_default.py, below.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 26vk: N presents, X fpslines 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
c14641a6against this branch at1354234e(the same change before the rebase):c14641a61354234ems, mediangame_mswait_gpu_mswait_main_msmain_blocked_msdraw_ms/desc_ms/cmds_ms/programs_msgame_msrises 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'ss_…_Npieces of the giant functions, which only the side without locals has) over the script's last 60 s, per frame:A share that counts only
f_symbols makes this PR look 25% more expensive (8.2 against 6.6 ms), because the giant functions ares_pieces only without locals.The first measurement (3 rounds, the same method): main
c14641a645.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%,=6withA64_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=0no gain; every lifted chunk at-O2+2.7% (4 of 5 rounds) with a 55-minute build (main'sLONGSHOT_CHUNK_OPT=allwith #1431's parts is being measured now);RX_VK_MESH_OPT=160 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=1no 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_REGSandA64_LOCAL_FLAGS(a64-kit's, lift time) change default.A64_LOCAL_REGS0to compareA64_LOCAL_FLAGSA64_LOCAL_FLAGS=) to compareTesting
Tested:
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 keepsc->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'soperator newfromrefresh_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 thatmain()sets them before the Lifter and discovery; thatpatched_functions()is every function the patch modules name andspliced_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 inno_localitself (as #1209'sentry_hooks.pydoes), so a new text patch can't silently break under local registers.python -I -B tests/run_all.pyon Windows, before the rebase: 634 passed, 46 failed, 45 skipped, every failure also failing on mainc14641a6(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.pyandtest_spawn_emit.pypass;test_libc_hooks.pyfails here and on maina35130c0alike (it looks forL.discover(in nx2/lift.py, which callsdiscover.discover(L, ...)).Not tested:
Must be tested:
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
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
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@Beanstalk Please build this branch and main
c14641a6on 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).@marclemieux64 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk
@llun approval of
db7e4ccrecorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.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 · dashboardWhat 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.
Done (started 2026-11-17 21:36 UTC, last report 00:02 UTC). Comment
@Beanstalkto run it again.This diff touches sensitive paths, so it needs two members of
BigBeans:nx2/fastfp.py,nx2/lift.pyunknown, unknown; 2: linux+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce RTX 3080 Ti, 620.70.6Measurements · any
Verdict: fail on any (2/1 report):
forest-field screenshot.max_difffailed.Hardware: 1: linux+other
unknown, unknownAMD Ryzen 7 5700X3D 8-Core Processor, 128 GB RAM; 2: linux+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce RTX 3080 Ti, 620.70.6AMD Ryzen 9 3900X 12-Core Processor, 48 GB RAMScene: 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 (
@Beanstalkon this PR runs it again)c14641adb7e4ccBuild times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept))
c14641adb7e4ccFlags and settings
None: the plan varied no setting, switch or build option.
Markdown for the PR description
@Beanstalk
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\ fromefresh_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 \
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
db7e4cc2against 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
c14641a6make_game.pybefore the shaderscode_028.c)code_025_1.c)longshotOne 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_msis the frame trace's (RX_VK_FRAME_TRACE=1): the game's own loop, median over the standing section.game_msgame_msgame_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.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_msand 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
Thanks, HumanBean, that's the run this needed.
game_msprofile in the Market is the direct test. I'll add the same from the 3900X:RX_VK_FRAME_TRACE=1,game_msmedians, main against this branch, interleaved, standing and turning in Kokiri. Ifgame_msdoesn't drop there either, the fps gain I measured needs another explanation and I'll say so.0xc0000374crash (above), to see whether it follows the branch.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; mainc14641a6and this branch1354234ealternating, 10 launches each, unattended):Crashes: none in 20 launches. With the runs before,
0xc0000374is 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):
ms(the frame)game_mswait_gpu_mswait_main_msmain_blocked_msdraw_ms/desc_ms/cmds_ms/programs_msgame_msper run: main 12.23 to 12.78, this branch 13.14 to 14.87, longer in every pair, as you saw in the Market. Sogame_msgoing 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_msholds waits too, which is why it andwait_gpu_mstrade. 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=0no gain; every lifted file at -O2 +2.7% but a 55-minute build, so not proposed.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. Fromall.txt: over the script's last 60 s, the samples (2 ms a tick) whose leaf is lifted code (f_…, and #385'ss_…_Npieces, which only the side without locals has), in ms per presented frame, by thread group.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. Andgame_msdoesn'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 asf_<addr>. A share that counts onlyf_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.
db7e4cc2870332de56d0Beanstalk test farm
Commit
0332de5· tier untrusted · approved by nobody yet · dashboardThis diff touches sensitive paths, so it needs two members of
BigBeans:nx2/fastfp.py,nx2/lift.pyA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Rebased on main
a35130c0(no conflicts), now0332de56.nx2/entry_hooks.pywrites lifted C with register names, and the new check caught it, as it should. It keeps its hooked functions inLifter.no_localitself, so it is safe; the check now accepts a module that does that (test(lift)commit).test_libc_hooks.pyfails here and on maina35130c0alike: it looks forL.discover(in nx2/lift.py, which callsdiscover.discover(L, ...).a35130c0against this branch, 5 interleaved rounds, after a warm start of each so a pipeline rebuild can't skew it; then this branch withLONGSHOT_CHUNK_OPT=all(#1431). I'll post both.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 main544229a2(e6d55bf1 + 5724b7df, added and deleted lines identical to the PR's), built the same way as main544229a2: Linux x86-64-v3, tools.lock a3dc5d80, no hot list, noA64_LOCAL_*in the environment (so this PR's defaults: 6 registers and flags as locals). At0332de56(on maina35130c0) the same matcher and name-based exclusion remain in the source; we have not rebuilt this head.patched_functionsandpatch_dynresare unchanged, no patch module namesf_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 textif (!((c->x[8] >> 0) & 1)) { goto L_8082640c; }inf_80825aa0.544229a2: applied (oot_patches: dynamic resolution switch).f_80825aa0uses a local-register name rather than the context-register spellingpatch_dynresexpects, so the build logsoot_patches: WARNING: the dynamic resolution branch was found 0 timesand carries on.patched_functionsdoesn't excludef_80825aa0.Why it matters (from the host code, not measured):
hos_dynres_runsstarts at 0 and its increment is supplied by the missing patch.host/nn_vi.cassignshos_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_80825aa0out of locals, or havepatched_functionsfind 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
0332de56before we rebuild?Thank you, dukenheimer: confirmed, and it's worse than one patch.
On
0332de56(rebased ona35130c0), 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_dynresanchors onL_8082640c, a label, andpatched_functionsonly collectedf_names, sof_80825aa0got 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, butA64_LOCAL_FLAGSchanges how a64-kit writes every scalar float compare (vectorize_fcmp:_fk = a64_fcmp32k(...)with the flags' stores in the text, in every function), soHORSE_TESTno 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.pylabelled_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 thatL_8082640cis among the labels).nx2/oot_patches.py:patch_horse_jumptakes the compare in either form (HORSE_TESTS); applied offline to this branch's liftedcode_040.cit patches, andtests/test_horse_jump_step.pypasses.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_resolutionthen 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 maina35130c0and this branch now withHOS_RES_LOG=1to 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.)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%):Without the dynamic resolution patch,
hos_fixed_resolutionnever 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 whywait_gpu_msfell 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
a35130c0with 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.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_FLAGSsilently break text patches unless their functions keep the context: those named byf_(76), those holding a label a patch anchors on (patch_dynres,L_8082640c), those with spliced C (Lifter.after;hos_oot_shadowwritesc->x[23]), and #1209's entry hooks (which handle it themselves).A64_LOCAL_FLAGSalso rewrites every scalar float compare (a64_fcmp32k), which broke #1434's horse patch.oot_patcheslines against main's, and run withHOS_RES_LOG=1to see both sides at3D scale 1.000.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.
Three things found while measuring this on a Ryzen 9 3900X + RTX 3080 (Windows 11), over
310e7c9dwith #1560:nx2/lift_fixes.py's fix 4), thegoto L_<entry>;goes in right after the head, beforelocalize_regsdeclares 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.A64_LOCAL_FLAGSbreaks two game patches. With flags as locals the kit writes every FCMP in another form, and the horse jump and dynamic-resolution patches innx2/oot_patches.py, which match the C text, no longer find their lines (the lift printsoot_patches: WARNINGfor 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.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.Pull request closed