WIP: fix(vk): frame generation's made frames at their own times with V-Sync Off #1362
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!1362
Loading…
Reference in a new issue
No description provided.
Delete branch "pmwork-personal/Longshot:fix/fg-paced-without-vsync"
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: medium · Tested on: Windows 11, RTX 5090 (NVIDIA 621.24) · Needs: Windows with another NVIDIA card (RTX 40), AMD and Intel (FSR 3.1 FG and the built-in maker), a fixed-refresh display, Linux
Why
With V-Sync Off, frame generation made its frames but the screen hardly showed them: DLSS Frame Gen at 3x looked like the
game's own frame rate. The display thread presented each set (the made frames and the game's frame) as soon as it came,
all within a millisecond, and a swapchain that does not wait for a refresh shows each present at once, so the game's
frame covered the made ones. The FPS counter and the log said the frames were made and shown on time. V-Sync On looked
smooth only because FIFO shows one present a refresh (which also holds the game at the refresh rate over the multiplier).
This PR shows each frame of a set at its own time. One more wait, after the present call, is not this PR's to turn on
for everyone (the present queue, Hookshot issue 1161 from before the fork): the hint and docs say how players turn it on.
See #315 (its "the log shows frames being presented on time, but the motion doesn't match": the log counts the present
calls, and both waits are after them).
How to reproduce
Seen on: Windows 11 Pro build 26300, RTX 5090, NVIDIA 621.24 (32.0.16.2124), 5120x2160 at 165 Hz with G-Sync
Settings and switches: V-Sync Off, Frame generation 3x (Frame generation by: Auto, DLSS FG), Frame pacing Off (its
default), NVIDIA Reflex On + Boost, NVIDIA DLAA
Steps: in play, turn the camera at an even speed. For numbers, run PresentMon on
longshot.exemeanwhile.Expected: the motion of three times the game's frame rate: each frame on the screen about a third of a game frame
(~6 ms at ~55 fps).
Actual: the motion of the game's frame rate: on main 66% of the frames are on the screen under 2 ms, and about 55 a
second for 2 ms or more (the game's own).
What changed
Where the swapchain does not wait for a refresh (V-Sync Off: immediate; mailbox), a fixed multiplier's set is now shown on
the game's timeline: each frame at its place between the game's two frames, after the GPU's delay, its copies submitted
ahead together, whatever Frame pacing says. The next set is taken while the current one is shown, so its copies reach the
GPU when it comes. FIFO (V-Sync On, and Auto with DLSS Frame Gen) keeps its path.
RX_VK_FG_TIMELINE=0gives the oldbehaviour back.
gpu/vk/vk_framegen.cpp:fixed_dues(frame k of a set at (k + 1) / (made + 1) of the way from the game framebefore, so each frame moves as far as its time),
pace_lead(made / (made + 1) of a game frame: no frame shown before itsgame frame came),
pace_delay(the GPU's delay: up by half, down by a sixteenth, at most a game frame),fixed_on_timeline(immediate and mailbox only,RX_VK_FG_TIMELINE).display_main:take/copy_up_to(a set's copies presented ahead, as many as swapchain imagesare free),
take_early(the next set taken during the current set's waits, not within 3 ms of a present), the firstcopy's fence polled every 2 ms of a wait (
ready_at), and the delay fed back only from sets whose first copy went within3 ms of their coming (
as_came, set incopyonce that copy'spresent_imagereturned): a set late for other reasonsraised the delay by its own lateness before.
gpu/vk/vk_replay.cpppresent_slots_for: where the swapchain is made for two sets, a slot per frame ofboth while frame generation runs (2 x the multiplier: 4, 6 and 8 at 2x, 3x and 4x, at most
kPresentSlotsMax, 8,vk_internal.h; ImGui keeps one more vertex buffer,vk_imgui.cpp). Each present waits for the copy last made in itsslot: with 3 slots a set's 4th copy waited for its own first copy, and with a slot per frame of one set the next set's
copy k for the shown set's copy k, each behind the game's work queued before it. The count is the swapchain's
(
dev.swap_slots, set bycreate_swapchain); FIFO,RX_VK_FG_TIMELINE=0and frame generation off keep 3.gpu/vk/vk_main.cppcreate_swapchain: two sets' spare images where the swapchain does not wait fora refresh (an NVIDIA surface: 6 at 2x, its most, 8, from 3x up); FIFO and
RX_VK_FG_TIMELINE=0one set's.frame interpolation:line has a<2 msbucket and counts a frame late against its own time; a second linegives the sets on the timeline, taken early, left out of the delay, and the copies' end and the delay.
times at V-Sync Off and that
RX_VK_PRESENT_QUEUE=1makes them the most even;docs/development.mdhasRX_VK_FG_TIMELINEandRX_VK_PRESENT_QUEUE;gpu/vk/switches.defhasRX_VK_FG_TIMELINE(#1300).docs/design.mdsection 13 writes the five rules down (pacing measured on thescreen; sets on the game's timeline; the delay only from sets taken as they came; a slot per frame of both sets and two
sets' images; a present waits on its queue), with
// doc:anchors on the functions that keep them (held bytests/test_doc_anchors.py). The measure skill measures a change to how frames are shown with PresentMon's on-screentimes, and counts which engine made the frames in the measured stretch only.
tests/test_framegen_fixed_pace.py(new) runs the real timing functions through a model of the display loop:game frames 15.5 to 22 ms apart, a 60 ms frame, a GPU slower than a frame, 4x with 6 spare images (the delay settles at
14.6 ms, as with images to spare; before the image fix it ran to 17.9 of the 18.5 ms game frame), and checks the slot
counts and where they come from;
tests/test_present_semaphores.pychecks that a retired swapchain counts 3 slots.Measurements
Verdict: it helps a lot. At 3x the frames on the screen under 2 ms went from 66% to 33% and the frames with their own
time on the screen from 55 to 111 a second; at 4x from 70% to 45%, and 60 to 111 a second. With
RX_VK_PRESENT_QUEUE=1too, 0.0 to 0.1% at both: every frame on the screen for its own time (3x: 4.8 to 7.2 ms, p10 to p90). The tester,
watching the runs: main "not super smooth", this PR with the present queue "this is the best"; a 14-minute play test of
the PR's first version with the present queue: "a lot better now".
Hardware: Windows 11 Pro build 26300, RTX 5090, NVIDIA 621.24, AMD Ryzen 7 9800X3D, 64 GB
Scene: Hyrule Market (child), a saved spot where the camera can turn; 5120x2160 at 165 Hz with G-Sync, fullscreen, V-Sync
Off, NVIDIA DLAA, Frame generation 3x and 4x by Auto (DLSS FG), Frame pacing Off, Reflex On + Boost, frame rate cap
Uncapped
Method: main at this PR's merge base and this PR, each a
dev_packs.pypack on one base (nightly-396 @7887c497), awarm-up run of each, then main, this PR and this PR with
RX_VK_PRESENT_QUEUE=1in turn, two rounds at 3x and two at4x (2026-11-17 00:48 to 01:01). The control bridge turns the camera with the right stick (60 degrees a second) for 30 s,
the pad, keys and mouse left out; PresentMon 2.3.0 on
longshot.exefor 26 s of it. Each run's number is shown (tworuns: their median is their mean). In play DLSS-G made 600 of each 600 presents in every run (
DLSS Frame Gen (NGX): of the last 600 presents 600 made by DLSS-G; the title screen before it, the built-in maker). A first A/B of this PR'searlier version (fac3ec4c, before the review fixes) on nightly-396 gave the same numbers within a point.
The head,
311d9d8d, adds the second review's two fixes aftera44ef0fb, not run on the screen: the slot count is storedafter the old chain's
retire_swapchain(each run above made one swapchain, logged, so it ran with the head's count),and
as_cameleaves the first copy's own submit out (between the first A/B's version, timed at take, and a44ef0fb's,timed after the copy, which gave the same numbers within a point).
How to reproduce: a save at a spot to turn the camera; the settings above; PresentMon 2.x
--process_name longshot.exe --timed 26 --terminate_after_timed --output_file <csv>while the camera turns; from the CSV the share ofDisplayedTimeunder 2 ms. Rows:
docs/tested/2026-11-17-fg-pacing-pmwork-personal-*.md(and the first A/B's,docs/tested/2026-11-16-fg-pacing-pmwork-personal-*.md).544229a2a44ef0fbRX_VK_PRESENT_QUEUE=1: this PR @a44ef0fbDisplayedTimemedian (p10 to p90), stdev, msDisplayedTimemedian (p10 to p90), stdev, msWhere the rest waits (from the same CSVs: the call at
CPUStartTime+CPUBusy, the screen atCPUStartTime+DisplayLatency): main presents a set's frames 0.37 ms apart (median), so they reach the screen together. This PR callsthem at their times (3x: 5.96 ms apart, p10 5.12, p90 7.11; 4x: 4.82 ms), but each present then waits 3 to 12 ms on the
replay's queue behind the game's next frame and reaches the screen the moment that GPU work ends (0.01 ms after it):
every one of the 1610 pairs under 2 ms apart on the screen at 3x was called ~5.9 ms apart. With the present queue the
call reaches the screen 1.1 to 1.8 ms later (p10 to p90), and the screen's gaps are the calls' (3x: 5.71 ms, 4x: 4.61).
Flags and settings
One new switch,
RX_VK_FG_TIMELINE(a kill switch, on as it ships);RX_VK_PRESENT_QUEUEis unchanged and now documented.No menu row or ini key changes; the Frame pacing row's hint is longer.
RX_VK_FG_TIMELINE=0off=0: as main=0for an A/B or if a GPU shows a regressionRX_VK_PRESENT_QUEUE=1: presents on a compute family's queue of their ownTesting
Tested:
Game-free:
python -I -B tests/run_all.pyona44ef0fb(Windows, llvm-mingw): 627 passed, 48 failed, 47 skipped. All 48fail on main on this PC too (an export of
544229a2): they callg++orsetenv, read Linux paths, or check main's ownsources (
test_switch_table:RX_VK_PGO_FILE;test_vk_swapchain_compat: the Linux start, after itscreate_swapchainchecks pass;test_tested_configurations:2026-11-16-shadow-map-slots-gumminaomi-on.md). Four(
fastfp_fma,fpx_sticky,spawn_emit,finish_output) pass or fail from run to run on this PC, on main as here.tests/test_framegen_fixed_pace.py(new) and the checks that cut the changed sources pass.The 48 of the last run, each failing on main too
auto_handheld bug_report bug_report_defaults cpu_report crash_dialog crash_groups crt_options damage_debug_menu
display_startup_failure dlss_feature_size failed_compile_keeps_objects finish_output framegen_preset
fsr_uniform_ownership guest_imported hardware_report hud_layout_row import_reach invalidate_vcore job_queue
linux_preflight linux_pressure mirror_budget missing_nup pads_after_menu parallel_init_order pending_guest_import
perf_report pipeline_play_cache portable_builder_startup present_thread profiling_mode readback_timeout_source
recorder_sync replay_write_order rumble_menu run_all_changed slow_frames staging_burst switch_table target_image_pool
tested_configurations upscaler_round_trip upscaler_rows vcore_escape vk_occlusion_queries vk_swapchain_compat walk_key
A cold review of the whole diff by a second agent: no high-severity finding (no image lost or presented twice, no
acquire past the swapchain's limit, no hang); its four findings (the slots across two sets, FIFO's slot count, the count
following the menu live,
as_camebefore the first copy) are fixed ina44ef0fb, and measured above. Its read of thosefixes found that
retire_swapchainset the new count back to 3 on every chain made over an old one, and thatas_camecounted the copy's own submit: both fixed in311d9d8d, with test checks that fail on the old order.In the game, Windows 11, RTX 5090, NVIDIA 621.24, 5120x2160 at 165 Hz with G-Sync: the runs above (V-Sync Off, 3x and
4x, DLSS-G making the frames in play), the first A/B of fac3ec4c, and a 14-minute play test of fac3ec4c at 3x with
RX_VK_PRESENT_QUEUE=1by the tester (no present error, no device lost; DLSS-G made 597 to 600 of each 600 presentsin play).
Not tested: the head's two fixes on the screen (
311d9d8d, above), and a swapchain made again in play (a multiplier orV-Sync change, a resize) with this PR; V-Sync On (FIFO) and Auto, whose path is unchanged (and now keeps main's 3 slots); 2x and 5x to 8x (5x and
6x are presented ahead where the surface holds them, 7x and 8x not); a mailbox swapchain; FSR 3.1 frame generation; AMD,
Intel and RTX 40 cards; a fixed-refresh display; Linux. Latency was not measured: the game's frame is shown later than on
main, after the made frames before it (made / (made + 1) of a game frame: ~12 ms at 3x and ~55 fps), as interpolation's
pacing needs.
Must be tested:
second
frame interpolation:line with most sets taken early (Test Farm: @Beanstalk windows nvidia, V-Sync Off withDLSS frame generation at 3x and 4x, the camera turning; the frame interpolation log lines and PresentMon's on-screen
times against main)
(Test Farm: @Beanstalk amd windows and amd linux, the same)
tester with such a display)
Risks
What could break: frame generation at V-Sync Off and mailbox with a fixed multiplier: each frame now waits for its
time, so the game's frame is shown made / (made + 1) of a game frame later than on main (~12 ms at 3x and ~55 fps); the
swapchain asks for two sets' images at V-Sync Off (an NVIDIA surface: 8 from 3x up, was 5 at 3x and 6 at 4x; 6 at 2x,
was 4: 88 to 133 MB more at 5120x2160); present_image keeps up to 8 frame slots there while frame generation runs, so up
to 8 presents can be on the GPU at once (3 before).
Turning it off:
RX_VK_FG_TIMELINE=0(the sets, the swapchain's images and the frame slots as on main).Compatibility: Nothing changes: no save,
longshot_options.inikey, cache or vk ABI change.Issues
See #315
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).mainand passing here.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
With V-Sync Off, a fixed frame generation multiplier's frames are shown at their own times on the game's timeline whether Frame pacing is On or Off (where the swapchain holds a set's frames at once: up to 6x on an NVIDIA card). The hint for Off ("As soon as it is ready.") and README's Frame pacing text did not say so. Both hints now add it, in the 13 languages of menu_i18n.h (machine-made, as the file says). tests/test_menu_i18n.py fails on main on this PC too (pt-BR's count). Co-Authored-By: Claude Opus 5.5 <[email protected]>544229a2, the PR, the PR with the present queue) d68011f268Tested in game: Windows 11 Pro build 26300, RTX 5090, NVIDIA 621.24, 5120x2160 at 165 Hz with G-Sync, Hyrule Market (child): V-Sync Off, DLSS frame generation at 3x and 4x (DLSS-G made every frame in play), Reflex On + Boost, DLAA. Scripted 30 s camera turns with PresentMon, main @
544229a2against this PR @a44ef0fbas packs on one base, interleaved, two runs each: frames on the screen under 2 ms 66% -> 33% at 3x and 70% -> 45% at 4x; with RX_VK_PRESENT_QUEUE=1 as well, 0.0-0.1% at both (on screen 4.8-7.2 ms apart at 3x). The tester watched the runs: main 'not super smooth', this PR with the present queue 'this is the best'; a 14-minute play test of an earlier version (fac3ec4c) with the present queue: 'a lot better now', no present error or device lost. The head311d9d8d(the second review's fixes) builds and passes the checks; it was not run on the screen (the description says why the numbers hold).2e530f46(docs only): the present queue's black screen is Hookshot issue 1161, from before the fork, not Longshot's #1161 (another pull request). The README, docs/design.md section 13, docs/development.md and this description now say so. No code change.@Beanstalk please run this branch against main with V-Sync Off and Frame generation at 3x and at 4x, turning the camera in play for about 30 s each, on: Windows with an RTX 40 card (DLSS frame generation), AMD on Windows and on Linux (FSR 3.1 frame generation), and Intel (the built-in frame generation). What to look at: the two
vk: frame interpolation:lines in longshot_log.txt (frames shown on time and late; sets on the game's timeline, taken early), and where PresentMon runs, the share of frames whose DisplayedTime is under 2 ms. Expected: far fewer frames under 2 ms than on main, and no new stutter, errors or device loss. RX_VK_FG_TIMELINE=0 gives main's behaviour on the same build, for an A/B.@pmwork-personal 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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.