WIP: fix(fps): Havok cloth keeps the clock above a 60 fps cap, solved at most 60 times a second (HOS_FPS_CLOTH_60=1, off by default) (#1485) #1628
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1628
Loading…
Reference in a new issue
No description provided.
Delete branch "enum/Longshot:perf/cloth-above-60"
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: fix · Risk: low · Tested on: Windows 11, RTX 4070 · Needs: Linux, AMD, Steam Deck (a look at cloth above a 60 cap)
Stacked on #1384 (its head
e418c77a): review the last three commits only. It builds on #1384'spatch_cloth_timeand leaves its below-60 behaviour as it is.TL;DR
Above a 60 fps cap, the cloth in the game (King Zora's robe, Link's cap, people's clothes) was simulated once every frame, each time as if a 60th of a second had passed, so at 240 fps it moved four times too fast and cost four times the work. With
HOS_FPS_CLOTH_60=1it is simulated at most 60 times a second and holds its pose in between. A new game-free test fails without the fix (240 solves in 240 frames at 240 fps) and passes with it (60); in the game the cloth looked right with it on, and the frame rate was the same within the spread. Off by default for now.Breakdown
HOS_FPS_CLOTH_60=1, a frame shorter than a 60th solves only when the game clock has crossed a whole 60th; otherwise the job returns at once and the cloth keeps its last pose.Why
Issue #1485 is a frame-rate drop near King Zora in Zora's Domain. A profile there (comments on #1485) put the Havok cloth solve at 45.7 % of the game's job workers' time, about 10.5 ms of CPU a frame against about 2 ms on the path below, and #1384's reading of the cloth's timing says why it runs every frame above 60: each solve is a 60th of a second, so above a 60 cap the cloth both runs too fast and costs one solve a frame. #1384 left that case open on purpose; dukenheimer agreed this should take it (#1384 (comment) and the reply after it).
This PR fixes the speed. It does not fix #1485's frame rate on its own: at the stairs behind King Zora the frame is already slower than 60 on a 7900X (a frame step of about 1.1), so each frame solves at most once and there is nothing for the gate to skip. What lifted that spot in my runs was compiling the cloth's code at
-O2, which is a separate proposal.See #1485.
How to reproduce
Seen on: Windows 11, RTX 4070 (NVIDIA 616.56), Ryzen 9 7900X
Settings and switches: a cap above 60 (
HOS_FPS_MAX=240),HOS_FPS_LOG=1Steps: play anywhere with cloth near the camera (Zora's Domain, child) and read the log.
Expected: the cloth solved about 60 times a second.
Actual: every solve job runs every frame. With this PR and
HOS_FPS_CLOTH_60=1, the log'soot: cloth solved N of the last 600 solve jobsline says how many ran (396 of 600 at the Zora's Domain arrival at a step of 0.65).What changed
The cloth's solve job is gated through the host: on a frame shorter than a 60th, it runs only when the game clock has crossed a whole 60th since the frame before; every job of one frame makes the same choice.
oot_cloth_gate()inhost/oot_high_fps.h(the rule, and why, in the header's comment);hos_oot_cloth_solve()inhost/oot_high_fps.creads the game clock (hos_step_probe + 0xd58, asnn_vi.c's log does) and the frame step, under a lock, and counts the solves forHOS_FPS_LOG.patch_cloth_solve()innx2/oot_patches.pyputs the gate at the head off_81b47080, the cloth's solve job, before its first line; a held frame returns the job's own result, 0. The report warns when the site is not found once.nn::os::GetSystemTick), thread-local lookups and a scratch buffer; no indirect call, no job started or signalled, nothing the setup allocated freed. Returning early leaves the job runner what a solve leaves it.docs/development.md;gpu/vk/switches.defgets its row.tests/test_oot_cloth_60.py(new).Measurements
Verdict: no change in frame rate (within the spread at all three spots); the cloth is solved about 60 times a second above the cap, as intended.
Hardware: Windows 11 Pro (26300), RTX 4070 12 GB (NVIDIA 616.56), Ryzen 9 7900X, 64 GB
Scene: teleport arrivals: Market (child), Hyrule Field (adult), Zora's Domain (child); output 2560x1440 in a 1280x720 window, Quality preset Auto (tier 4, the game's own upscaler), frame generation off, cap 240
Method: one game folder (this branch at
8aadf550over a310e7c9dbase, lifted chunks at-O1as a player's build has them),HOS_FPS_CLOTH_60unset against=1; each spot settled 12 s, then 20 s by the game's frame counter, hands off; one session a run in the job queue's timing mode, interleaved a1 b1 a2 b2 a3 b3; the median of three. The PC was busy outside the game (1.8-4.3 cores), so small differences are not resolvable here.How to reproduce: the switch and
HOS_FPS_LOG=1as above; any save; the control bridge'steleportto the three destinations.Baseline: the before column is this branch with the switch unset, which runs the cloth as main does (the gate stands aside).
The game-free test, before the fix (
fc86e2ab) and after (0663d20f):Flags and settings
One new switch, off by default.
HOS_FPS_CLOTH_60Testing
Tested: Windows 11, RTX 4070, NVIDIA 616.56: with the switch on at a 240 cap, Zora's Domain (child), from the arrival to the stairs behind King Zora: King Zora's robe and Link's cap looked right, nothing trailing or held that I saw, and the log counted the solves as above. The three timed pairs above.
tests/test_oot_cloth_60.pyfails atfc86e2ab(240 of 240 frames solve at 240 fps) and passes here, and fails again with the gate's key line or the patch's call to it broken by hand. #1384'stest_oot_cloth_timepasses as it is. The pack's lift reportedoot_patches: the cloth's solves above 60 fps in code_024.c(found once, no warning).python -I -B tests/run_all.pyon Windows: 685 passed, 49 failed, 48 skipped; every one of the 49 also fails at #1384's head (e418c77a).Not tested: Linux (the host code is the same, the lock is
SRWLOCKas the sound gate's next to it), AMD, Intel and the Steam Deck; frame generation; cutscenes with cloth.Must be tested:
HOS_FPS_CLOTH_60=1 HOS_FPS_LOG=1at a cap above 60, go to Zora's Domain as a child and look at King Zora's robe and Link's cap, expecting them to move as at 60 and the log to count fewer solves than jobs (Test Farm: @Beanstalk linux, amd and the Steam Deck: Zora's Domain as a child with HOS_FPS_CLOTH_60=1 at a cap of 240; check the log for "oot: cloth solved")Risks
What could break: with the switch on, a cloth's pinned points could trail its body for up to three frames at 240 fps between solves (not seen on this PC). With it off, nothing changes.
Turning it off: leave
HOS_FPS_CLOTH_60unset (the default).Compatibility: the game is translated again with the patch (a lift change), as any change to
nx2/oot_patches.pydoes; saves, options and the shader and pipeline caches are unchanged.Issues
See #1485
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main. (Stacked on #1384's head, on main430eef4f; it rebases when #1384 merges.)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).mainand passing here.🤖 Generated with Claude Code
Tested in game: Windows 11, RTX 4070, NVIDIA 616.56, Ryzen 9 7900X: HOS_FPS_CLOTH_60=1 at a 240 cap, Zora's Domain (child) from the arrival to the stairs behind King Zora: King Zora's robe and Link's cap looked right; the log counted 396 of 600 solve jobs at the arrival (step 0.65), all of them at the stairs (step 1.1, slower than 60).
@Beanstalk linux on AMD (RADV) and the Steam Deck. This PR changes how often the game's cloth is simulated above a 60 fps cap (a lift patch, off unless HOS_FPS_CLOTH_60=1). Build this PR and main; with HOS_FPS_CLOTH_60=1 and HOS_FPS_MAX=240, start the kokiri-start save, teleport to Zora's Domain as the child and stand there 30 s, take a picture there to compare with main's, and check the log for "oot: cloth solved" (expected: present, no crash).
@enum only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.