perf(lift): fast float regions span guest stores and vector moves, so more of the game's float maths runs as plain SSE #1880
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1880
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:perf/fastfp-stores"
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?
Summary
On fast PCs the Market's frame is now set by the translated game code: each frame's critical path (HOS_CHAIN) is ~97% lifted code running on a chain across the main thread, the module workers and the job executors, with no GPU or renderer wait on it. Float maths is ~15% of the guest instructions in the hot code, and an op outside a fast float region pays its exactness checks one by one (
RECOMP_FPX_OPEN, the integer checks, the exact fallback); only ~31% of the float ops of the functions play runs sat in fast regions (nx2/fastfp.py).Two changes widen the regions:
A64_FASTFP_STORES, on): a run may hold whole, unconditional guest stores (recomp_store8..64,recomp_stp32/64, their_spforms) when no guest load follows a store in it; the run is cut before such a load (ff_split). The fast copy computes each store's address and value into locals and makes the stores, in order and with their page marks, aftera64_ff_endpassed; on a fall-back the exact copy runs from the region's start with its stores in place, so memory sees the same accesses in the same order either way. Functions anoot_patchesedit names keep their stores out (a patch anchored on a store's text must not miss the fast copy).A64_FASTFP_VMOVES, on): #1576 rewrote LDR Q, DUP, EXT and TBL intoa64_vld16,a64_vdup,A64_EXT16/8anda64_tbl1, which aren't inFF_PURE, so since then they ended runs (~23,700 run ends beside float code in the functions play runs). They are integer SSE with no float flags;a64_vld16counts as a load for the store rule.Float ops in regions in the functions play runs: 31% -> 60% (49.8k -> 95.2k of 158.9k). With both switches
=0the lift is main's.Read first:
ff_regions,ff_split,ff_defer,ff_patchedinnx2/fastfp.py; the tagged lines inemit_function's copy.Testing
Tested: Linux, RTX 3090 (NVIDIA 620.x), Ryzen 9 7900X, 2560x1440: the game built from this branch (main's renderer, the base's work folder) against main's own build on the same base, Castle Town Market standing, walking and turning, three interleaved game starts each after warm caches: no crash, no Vulkan error.
tests/test_fastfp_regions.py(extended: eligible and ineligible store forms, cuts, deferred-store shape and order, x29_spin both copies, check-mode comparisons; C at x86-64-v3 and v2: memory, store order and mark count match the reference on the fast path, each store happens once on every fall-back, 20,000 check-mode runs with 0 mismatches; each check fails when broken on purpose),tests/test_fastfp_override.py(extended) andtests/test_fastfp_fma.pypass.Still to test:
A64_FASTFP=check, the Market and Kokiri Forest for 10 minutes, expecting no "fast region differs" line (by hand: it needs a full game build, which ran out of memory on my PC)mise run test,test_vecfp.py,test_function_ends.py,test_light_passes.py(they callff_region/ff_eligible) expecting them to pass (by hand: CI on this pull request)Measurements
Verdict: a small gain while the game moves (+2.9% walking in the Market, better p99), even standing; the build takes ~6% longer.
Baseline: main @ 89c3d21e's own build (
dev.py rt --emptyon its base) against this PR's game built on the same base with the same renderer, so the two differ only in the lifted code.Setup: Linux, RTX 3090, Ryzen 9 7900X, 2560x1440, Threaded rendering Auto, Castle Town Market; three interleaved game starts each (median, runs in brackets).
89c3d21e1f667883Build time: a full game build of this branch took 10:11 (compile 7:27) against 9:36 for main's base on the same PC; the lifted C grows ~3% (+34 MB from the vector moves, +8 MB from the stores). Both switches ship on: never slower here, and the regions they add are checked to match the exact copy.
Risks
A wrongly deferred store would show as a wrong value in game memory (glitches, physics) on the fast path only:
A64_FASTFP=checkcompares both copies including the stores, andA64_FASTFP_STORES=0/A64_FASTFP_VMOVES=0(lift time) restore main's lift. Other threads see a region's stores slightly later (after the region's register work), never with other values or in another order. The game build takes a little longer. Nothing changes in the player's files; the new lift is built when the game is built.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_017vw8e3aEPBsd7QfUkaatjP
Tested in game: Linux, RTX 3090 (NVIDIA 620.x), Ryzen 9 7900X, 2560x1440: game built from this branch vs main's own build on the same base, Castle Town Market standing/walking/turning, three interleaved starts each; no crash or Vulkan error; walking +2.9%.
@Beanstalk Please test this PR against main on every platform: windows+amd, windows+nvidia, windows+intel, linux+amd, linux+nvidia, linux+intel, the steamdeck, amd+igpu. Settings vsync=2 (Off) and frame_rate_cap=6 (Uncapped), Threaded rendering Auto. From the
kokiri-startsave: Kokiri Forest, Hyrule Field and Castle Town Market, in each 20 s standing, 15 s walking and 15 s turning the camera, two game starts a side; make sure each side has reached the area before measuring it. Measure fps, p99 frame time, stutters and crashes, and compare pictures with main. This changes the translated game code (float maths), so a crash, a hang or a visual or physics difference is the main thing to catch; the gain is expected mostly while moving, on the CPU side.@HumanBean approval of
1f66788recorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.Beanstalk test farm · 🔄 testing (0 of 1 report so far)
Commit
1f66788· approved by HumanBean (reviewed) · dashboardDone (started 18:18 UTC). Comment
@Beanstalkto run it again.anyWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares main and the pull request in Kokiri Forest, Hyrule Field and the Market, with movement, pictures, frame time and FPS measurements. One start per side keeps gameplay testing to roughly 15 minutes per tester; separate repeated lift-cache builds measure build-time changes. A crash, materially slower gameplay, a substantial picture difference or a build-time regression fails the plan.
kokiri-start(settings vsync=2, frame_rate_cap=6), then teleport to Kokiri Forest, move the stick, take the picture kokiri to compare with main, measure kokiri for 15 s (after 3 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 15 s (after 3 s warm-up), teleport to Market, take the picture market to compare with main, measure market for 15 s (after 3 s warm-up); 1 run on each side.Possibly related, for context:
@beanstalk
@HumanBean approval of
1f66788recorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.@Beanstalk
WIP: perf(lift): fast float regions span guest stores and vector moves, so more of the game's float maths runs as plain SSEto perf(lift): fast float regions span guest stores and vector moves, so more of the game's float maths runs as plain SSEAfter the merge, for the record: the two items this PR's Testing still listed, run on the lab (Linux, RX 580, RADV Mesa 26.2.6, i7-9700K, 1080p).
Check mode: a game built from this branch with
A64_FASTFP=check(both copies of every region run and compared, stores included), one session through Kokiri Forest, Hyrule Field and Castle Town Market standing and turning: 118 per-file reports, every one0 mismatched when clean(about 4.2 million region runs a file); no crash, no Vulkan error.fps on AMD: main @ 89c3d21e's own build against this branch's on the same base, at 50% render resolution (the RX 580 still 84-98% busy), two interleaved game starts each:
89c3d21e1f667883Even to slightly better: the GPU limits the frame there, so the CPU side's gain shows only where the CPU holds some of it (turning in the Market and the Field).