perf(vk): cut 120 Hz Auto framegen latency 68-83% and lift native FPS 20-48% (+27-53% 1% low) on GPU-limited GPUs via AutoGuard and Visual FPS target #2369
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2369
Loading…
Reference in a new issue
No description provided.
Delete branch "Jer9/Longshot:feat/vk-auto-framegen-guard-and-target"
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 high-refresh displays (120 Hz, 180 Hz, 240 Hz), setting Frame generation to Auto (
frame_generation=1) computesauto_cap() = clamp((hz + 29) / 30, 2, 4)and generates up to 3–4 frames per game frame. When the GPU is saturated (such as integrated GPUs or power-constrained laptops running at 22–35 FPS native), generating 3 made frames adds ~11–18 ms of FSR 3.1 optical-flow and interpolation passes per game frame. That triggers a negative feedback loop: GPU frame time climbs, native FPS drops 20–48%, display latency balloons past 120–145 ms, and presentations bunch under 2 ms. In issue #2226, locking the game to 30 FPS with V-Sync (FIFO) on 120–180 Hz displays caused Auto frame generation to collapse native FPS to ~24 FPS with ~147 ms of display lag.This PR resolves the overload loop with two complementary additions:
gpu/vk/framegen_auto.h): Tracks smoothed native frame time (game_ns), GPU time (gpu_ns), and presentation bunching. When GPU load is heavy, native FPS falls under GPU saturation, or pacing bunches,AutoGuardstepsauto_mostdown conservatively and skips multi-frame interpolation across single-frame hitches (> 50 ms and > 2x smoothed frame time). Thresholds are maker-aware (distinguishing light Built-in FG from heavy FSR 3.1 FI), allow recovery under capped play (such as a 30 FPS cap when spare GPU headroom returns), and reset state cleanly whenever the cap,Visual FPS target, or active frame-generation maker changes (including clearing the GPU EMA on maker switches and guarding missing initial GPU timestamp deltas).RX_VK_FG_AUTO_GUARD=0disables the guard and hitch suppression completely, restoring prior behavior.longshot_options.ini: frame_generation_target): Adds a row under Frame generation (visible while Frame generation is Auto) offering Display Hz (default), 60, 72, 90, or 120 FPS (never above the display's refresh), published atomically viamenu_framegen_target()and clamping Auto's target period and made-frame cap immediately.What a player notices:
Visual FPS target(e.g.0 -> 1 -> 2 -> 3, ~119.4 FPS with Built-in FG) once GPU headroom returns instead of staying latched at1/3.Helps:
No measurable impact:
frame_generation=0) or Fixed multipliers (frame_generation >= 2).Addresses #2226.
Files to read first:
gpu/vk/framegen_auto.h:AutoGuardEMA filters, maker-aware overload/recovery thresholds, hitch suppression, and state reset on(cap, target_choice, heavy_maker).gpu/vk/vk_framegen.cpp: integration withauto_slots(),framegen_record(),have_gpu_deltaguard, andframegen_idle().gpu/vk/menu/framegen.cppandgpu/vk/menu_i18n.h: theVisual FPS targetmenu row and translations.tests/test_framegen_auto.py: game-free unit tests covering overload step-down, capped recovery, maker asymmetry, target/maker reset, missing GPU delta, hitch suppression, and target clamping.Testing
Tested:
main(8aa5ab87vs this PR):market-entrance, walked straight forward ~5 s0:LUP/5000to the central fountain before panning, 1600x1000 windowed @ 120 Hz, FSR 3.167% render scale, FSR 3.1 FG Auto Uncapped,RX_VK_PRECOMPILE=1, 2 interleaved rounds): Immediate native FPS23.47 -> 33.49 FPS(+42.7%), 1% low13.61 -> 17.28 FPS(+27.0%),fg_latency.csvmedian127.7 -> 22.0 ms(-82.8%). FIFO (vsync=1) native FPS22.47 -> 33.29 FPS(+48.2%), 1% low13.72 -> 18.09 FPS(+31.9%),fg_latency.csvmedian139.5 -> 30.7 ms(-78.0%).castle-gate, 2 interleaved rounds, Immediate): native FPS23.70 -> 31.40 FPS(+32.5%), 1% low15.12 -> 19.87 FPS(+31.4%),fg_latency.csvmedian132.6 -> 31.7 ms(-76.1%).Visual FPS target = 120):1680x1048,50% render scale,21.5–22.3 msGPU): recovered0 -> 1 -> 2 -> 3(step-ups=4), reached119.4 FPS(597frames/5 s,cap 3/3), held steady with0seesaw.1280x720,50% render scale,15.3–18.4 msGPU): recovered0 -> 1 -> 2 -> 3(step-ups=4,112.2 FPS); under heavier Market load (24.2–26.2 msGPU) held1/3(60 FPS,0<2 msacross 6 windows,0late).cap=3unchanged): switchingDisplay Hz -> 120 FPSresetcap 1/3 -> 3/3; switchingFSR 3.1 FG -> Built-in FGresetcap 0/3 -> 3/3.RX_VK_MIRROR=1 RX_VK_ASYNC=1,RX_VK_RECORDER=off,RX_VK_FG_AUTO_GUARD=0, andframe_generation=0all ran cleanly with0device-lost or crashes.0e32bc10): Market Uncapped+19.7%FPS /+40.5%1% low /-73.5%latency, Hyrule Uncapped+25.7%FPS /+53.0%1% low /-68.4%latency, Market 60 cap+20.3%FPS /-73.6%latency, and #2226 Kokiri 30 cap FIFO24.01 -> 29.99 FPS/-77.4%latency /99 -> 0<2 msbunching.tests/test_framegen_auto.py(failed before the fix onmainand before the recovery fix onf6860d2f, passes here with bothclang++andg++); all 9test_framegen_*and 21/21 targeted framegen/menu/switch/doc--strictchecks pass; fullpython -I -B tests/run_all.py --strict --jobs 12passed 900 checks (51skipped) with0regressions unique to this PR (27/27 pre-existing Windows baseline failures reproduced identically on cleanforge/main @ 8aa5ab87, including the 3 unrelated#2383menu failurestest_crt_options,test_rumble_menu,test_vibration_menu, plus Windows/POSIX/PATH baseline checks such astest_auto_handheld,test_crash_dialog,test_dev_*,test_linux_preflight,test_pads_after_menu,test_perf_report,test_portable_builder_*,test_vram_compact;test_srccut.pypasses via canonical path).How to test:
Upscaler = AMD FSR 3.1,Render resolution = 67%,Frame generation = Auto, andVisual FPS target = Display Hz.market-entrance, walk straight forward ~5 s (0:LUP/5000) to the central fountain before panning, and comparevk: frame interpolation:display latency and native FPS againstRX_VK_FG_AUTO_GUARD=0(ormain).Game frame rate cap = 30,Frame generation = Auto,Visual FPS target = 120, andFrame generation by = Built-in FGat50% render scale, verifyingvk: frame interpolation:logsstep-ups> 0 and reachescap 3/3(~120 FPS visual).Still to test:
Measurements
Verdict: On current
main(8aa5ab87, Radeon 860M @ 120 Hz,67% render scale), cuts Auto framegenfg_latency.csvmedian display latency by 76.1%–82.8% (127.7–139.5 ms -> 22.0–31.7 ms), lifts native FPS by +32.5% to +48.2%, and lifts 1% low FPS by +27.0% to +31.9%; in prior 3-round A/B (0e32bc10), also verified -68.4% to -77.4% log display latency, +19.7% to +25.7% native FPS, +40.5% to +53.0% 1% lows, and #2226 30 FPS cap FIFO recovery (24.01 -> 29.99 FPS,99 -> 0<2 msbunching). Under a 30 FPS cap withVisual FPS target = 120, Auto now recovers0 -> 1 -> 2 -> 3(step-ups=4,119.4 FPSBuilt-in FG /112.2 FPSFSR 3.1 FI). Zero impact when Frame Generation is Off (< 0.5% variance) or whenRX_VK_FG_AUTO_GUARD=0.Setup: Windows 11 (build 26200), AMD Ryzen AI 7 350, AMD Radeon(TM) 860M Graphics (8 CUs, RDNA 3.5 iGPU, 6 GB VRAM), Adrenalin 26.10.1 (LLPC),
1600x1000windowed at 120 Hz (screen 2880x1800 at 120 Hz), AMD FSR 3.1 (dlss=3),67% render scale, AMD FSR 3.1 Frame Generation (frame_generation=1,frame_generation_by=0),RX_VK_PRECOMPILE=1,>= 12 spost-load settle, interleaved runs (2 rounds Immediate in Market & Hyrule Field, 1 interleaved pair FIFO in Market). (A/B binary was built from commit49097aae; follow-up commits657af9bd/670c2411only add thehave_gpu_deltainitial-sample guard andmaker_changedsettle frames, leaving steady-state A/B paths identical.)Where it makes a difference (current
main@8aa5ab87,67% render scale):8aa5ab87670c2411fg_latency.csvmedian display latencyfg_latency.csvmedian display latencycastle-gate) Uncapped, Immediate, Auto (Display Hz), 67% render scale:fg_latency.csvmedian display latencyPrior 3-round standalone A/B (
0e32bc10,#222630 FPS cap FIFO + 60 FPS cap,67% render scale):0e32bc1095afa556< 2 msapart (per 5 s)Where it does NOT make a difference (within run-to-run variance):
0e32bc1095afa556frame_generation=0), 67% render scale — Native FPSRX_VK_FG_AUTO_GUARD=0, 67% render scale — Native FPSRX_VK_FG_AUTO_GUARD=0, 67% render scale — Display latencyRaw log excerpt — capped 30 FPS recovery (
Visual FPS target = 120, Built-in FG, Market1680x1048,50% render scale):Risks
RX_VK_FG_AUTO_GUARD=0inlongshot_env.txtdisables the overload guard and hitch suppression completely, restoring prior unguarded Auto behavior.frame_generation_targetdefaults to0(Display Hz) inlongshot_options.ini; existing configs remain fully backwards-compatible.MKWVK_API_VERSIONremains 45. No game assets or save files are touched.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
mainand passes here.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.Possibly related, for context:
@Beanstalk Please test Frame generation: Auto on Linux AMD RADV (120+ Hz), Steam Deck (60 Hz / 90 Hz), and Windows NVIDIA RTX 40/50 (DLSS-G + high-headroom Auto) to confirm overload guard backoff on GPU-limited hardware and zero throttling on high-headroom GPUs.
@Jer9 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@review
Recommendation: Request changes. The guard can permanently reduce visual frame rate when the game is CPU-limited even though the GPU has ample headroom, and the new live setting is accessed across threads without synchronization. The reported iGPU gains are substantial, but the default also needs coverage on the other systems it affects.
Auto frame generation gains an overload guard, hitch suppression, and a selectable visual FPS target. The reported Windows iGPU runs show lower latency and higher native FPS at the cost of fewer displayed frames; the guard can also unnecessarily reduce smoothness on CPU-limited systems.
Blocking (1): must change before merging.
gpu/vk/framegen_auto.h:169: Low native FPS alone is treated as GPU overload, even when GPU timing shows ample headroom. (more on the line) Do: Distinguish CPU-limited low FPS from GPU overload, and allow recovery when GPU timing shows sufficient headroom; add a sustained CPU-limited case to the guard tests.Should fix (1): not blocking, but worth doing before merging.
gpu/vk/vk_framegen.cpp:1691: The replay thread reads the new plain integer while the menu can write it on the display thread, creating a data race. (more on the line) Do: Publish the selected target through an atomic or the existing appropriate synchronization mechanism, and read a synchronized snapshot in framegen_record.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_framegen.cpp:1711: The default guard changes Auto pacing on Linux AMD and Steam Deck, where no run is reported. (more on the line) Do: Run Auto under load and after load clears on Linux RADV and Steam Deck, comparing native FPS, frame times and presentation pacing against the base.gpu/vk/vk_framegen.cpp:1711: The default guard also changes Auto on NVIDIA systems, but high-headroom behavior has not been measured there. (more on the line) Do: Compare Auto against the base on a Windows NVIDIA Tier 1 GPU, including a high-headroom scene and a transition out of load.@fixcan do L1 and L2.Questions (1) (not confirmed from the code; they don't hold the recommendation)
tests/test_framegen_auto.py:488: Is there a current production case where the guard decision fails to control the generated slots?Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes on the reported Radeon 860M workload: three interleaved runs report 25.52 to 30.54 native FPS and 123.7 to 32.8 ms display latency in Market, with 1% lows rising from 18.39 to 25.83 FPS. The baseline is
0e32bc10rather than the merge base, and the effect on other hardware remains unproven.Other systems: Auto uses FSR or the built-in interpolator on Windows and Linux, including NVIDIA, AMD, Intel and Steam Deck; fixed multipliers use a separate path. The guard consumes replay GPU timing and display-thread pacing feedback, so both timing and presentation behavior need coverage. The supplied runs cover Windows Radeon 860M; Linux RADV, Steam Deck and NVIDIA results are pending.
Switches: RX_VK_FG_AUTO_GUARD is added, default on, with a switches.def row; its default is measured on the 860M but is not yet established across affected hardware. Setting it to 0 disables the guard and hitch suppression. The saved frame_generation_target option defaults to Display Hz and offers 60, 72, 90 and 120 FPS.
Reviewed:
95afa5567aagainst958b71f957: Read the repository rules, PR template, standards, commit messages, framegen_auto.h and the changed frame-generation integration and menu paths. Reviewed the test fixture and changed test wiring; skimmed translation additions and user documentation. The complete vk_framegen.cpp and vk_replay.cpp files and the full translation tables were not read. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no builds, tests, or project scripts were run. The PR reports Windows iGPU runs and game-free tests; CI is still running.
Overlaps and merge order: Not checked; network access is unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +166,4 @@if (max_made >= 2) {const bool gpu_over =gpu_ready && smooth_gpu_ns >= kGpuHeavyNs && smooth_gpu_ns * 100 >= smooth_game_ns * 72;const bool fps_over = smooth_game_ns > kLowFpsMultiNs;L1 (blocking): Low native FPS alone is treated as GPU overload, even when GPU timing shows ample headroom.
When: At a sustained CPU-limited 25 FPS with a 5 ms GPU time and a 120 Hz display, fps_over steps the cap from three made frames to one. Recovery requires a frame time of at most 35 ms, so Auto stays near 50 displayed FPS instead of using the available GPU headroom to approach 100 FPS.
Do: Distinguish CPU-limited low FPS from GPU overload, and allow recovery when GPU timing shows sufficient headroom; add a sustained CPU-limited case to the guard tests.
@ -1648,2 +1689,3 @@if (auto_rate) { // (Auto: a frame for each of the display's refreshes or Visual FPS target, with overload guard)const int mhz = display_refresh_mhz();const int64_t period = (int64_t)(1e12 / (mhz > 0 ? mhz : 60000));const int target_choice = opts.framegen_target;L2 (should fix): The replay thread reads the new plain integer while the menu can write it on the display thread, creating a data race.
When: Changing Visual FPS target while Auto is running writes opts.framegen_target through the menu row while framegen_record reads it to choose the period and cap. Those unsynchronized concurrent accesses have undefined behavior.
Do: Publish the selected target through an atomic or the existing appropriate synchronization mechanism, and read a synchronized snapshot in framegen_record.
@ -1653,2 +1709,3 @@if (blend) {n = auto_slots(before, now, period, fg.slot_next, t, at, std::min(fg.mult, kMaxMult));const uint32_t d0 = fg_auto.auto_guard.step_downs, u0 = fg_auto.auto_guard.step_ups, h0 = fg_auto.auto_guard.hitches_capped;const auto dec = fg_auto.auto_guard.step({now - before, gpu_delta, gpu_now > 0, pace_bad, cap_made,L3 (should fix): The default guard changes Auto pacing on Linux AMD and Steam Deck, where no run is reported.
When: The same pacing feedback and step-down logic runs on RADV and the Deck, but the supplied evidence cannot show its cadence, recovery or performance there.
Do: Run Auto under load and after load clears on Linux RADV and Steam Deck, comparing native FPS, frame times and presentation pacing against the base.
L4 (should fix): The default guard also changes Auto on NVIDIA systems, but high-headroom behavior has not been measured there.
When: Auto uses the same guard and display pacing feedback on NVIDIA; the reported AMD iGPU runs do not show whether it preserves high-refresh cadence on that driver.
Do: Compare Auto against the base on a Windows NVIDIA Tier 1 GPU, including a high-headroom scene and a transition out of load.
Beanstalk test farm
Commit
670c241· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.@beanstalk send job to zireael9797
@beanstalk
Addressed BeanBot review findings L1 and L2 in commit
19e565649ce90977495c61e1bfa9a70f04acebc4(also updated the stale## Summarydescription offps_over):Changes
L1 (
gpu/vk/framegen_auto.h:169-170, 211-224) — Distinguish CPU-limited low FPS from GPU overload:fps_over(max_made >= 2) on GPU utilization whengpu_readyis true (smooth_game_ns > kLowFpsMultiNs && (!gpu_ready || smooth_gpu_ns * 100 >= smooth_game_ns * 72)), so sustained CPU-limited low native FPS with ample GPU headroom does not trigger overload backoff.0 -> 1and1 -> 3step-up recovery whengpu_readyshows ample GPU headroom (smooth_gpu_ns <= kGpuHeadroomNs && smooth_gpu_ns * 100 <= smooth_game_ns * 55) even under sustained CPU-limited low FPS.0 -> 1 -> 2 -> 3recovery tests plus atomic target wiring checks intests/test_framegen_auto.py.## Measurements, where GPU busy time remains well above the overload thresholds.L2 (
gpu/vk/vk_menu.cpp,gpu/vk/vk_menu.h,gpu/vk/vk_framegen.cpp:1691) — Synchronizeopts.framegen_targetreads:std::atomic<int> framegen_target_now{0}(matchinggrass_distance_now), updated onmenu_init()andset_row(), and exposed viamenu_framegen_target()for lock-free reading inframegen_record().srccuttest fixtures (tests/present_source_crop_test.cpp,tests/test_crt_options.py,tests/test_framegen_preset.py,tests/test_rumble_menu.py,tests/test_upscaler_round_trip.py,tests/test_vibration_menu.py).Verification
python -I -B tests/run_all.py --strictacross all 15 affected checks (test_framegen_auto,test_present_source_crop,test_crt_options,test_framegen_preset,test_rumble_menu,test_upscaler_round_trip,test_vibration_menu,test_switch_table,test_menu_modules,test_menu_rows_model,test_menu_i18n_count,test_preset_exempt,test_framegen_by_row,test_framegen_dlss_cap,test_framegen_fixed_pace): 15 passed, 0 failed, 0 skipped.python -I -B tests/run_all.py --changed 958b71f9on Windows: 144 passed, 5 failed, 4 skipped (all 5 failures are unrelated Windows console encoding / path /llvm-mingw-Wunused-but-set-globalissues:test_crash_dialog,test_dev_ab,test_dev_packs,test_input_movie,test_srccut).python -I scripts/dev.py vkon Windows (llvm-mingw): builds cleanly (longshot_vk.dll).Remaining Hardware Coverage (
Should fixL3 & L4)19e565649c7bd7b80a57perf(vk): cut 120 Hz Auto framegen latency 68-77% and lift native FPS 20-26% (+41-53% 1% low) on GPU-limited GPUs via overload guard and Visual FPS targetto WIP: perf(vk): cut 120 Hz Auto framegen latency 68-77% and lift native FPS 20-26% (+41-53% 1% low) on GPU-limited GPUs via overload guard and Visual FPS targetMoving back to
WIP:briefly after catching anAutoGuardrecovery issue in extended playtesting on Radeon 860M:30 FPScap (33.3 msframe budget) with Built-in FG andVisual FPS target: 120(on a 100 Hz display), onceAutoGuardstepped down3 -> 2 -> 1made frames, it stayed latched at1/3(60 FPS) with0step-ups even while GPU time sat around19.1–19.9 ms(>13 ms spare headroom, and fixed8xran smoothly).smooth_gpu_ns <= 18.0 msand<= 55%of frame time) is too tight for capped30 FPSplay and applies the same FSR 3.1 FI-tuned thresholds to the much lighter Built-in FG path; additionally, switching betweenDisplay Hzand120 FPSdoesn't resetAutoGuardwhencap == last_cap.I will update
AutoGuardrecovery/maker awareness + target-change reset, re-run the A/B and unit tests, and mark ready again once verified.7bd7b80a57670c2411ccWIP: perf(vk): cut 120 Hz Auto framegen latency 68-77% and lift native FPS 20-26% (+41-53% 1% low) on GPU-limited GPUs via overload guard and Visual FPS targetto WIP: perf(vk): cut 120 Hz Auto framegen latency 68-83% and lift native FPS 20-48% (+27-53% 1% low) on GPU-limited GPUs via AutoGuard and Visual FPS targetWIP: perf(vk): cut 120 Hz Auto framegen latency 68-83% and lift native FPS 20-48% (+27-53% 1% low) on GPU-limited GPUs via AutoGuard and Visual FPS targetto perf(vk): cut 120 Hz Auto framegen latency 68-83% and lift native FPS 20-48% (+27-53% 1% low) on GPU-limited GPUs via AutoGuard and Visual FPS targetUpdated head
670c2411(rebased ontoforge/main @ 8aa5ab87,AutoGuardcapped30 FPSrecovery, maker-aware thresholds, and target/maker switch state reset verified on Windows 11 Radeon 860M).@Beanstalk please test on the updated head:
@Jer9 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.