fix(video): a movie's picture waits for its clock, so its sound is no longer late at 240 fps #2264
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!2264
Loading…
Reference in a new issue
No description provided.
Delete branch "d4nkn3ss/Longshot:fix/movie-pace-av-sync"
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
Fixes #1964. In the opening and on the title screen, the movies' sound came late against their picture: up to a second
or two for the reporter, and 0.73 s by the end of the opening on an RTX 3080 here. Capping the game at 60 in the NVIDIA
app made it go away.
The sound wasn't late. The picture ran early. While a movie plays, Longshot paces at 240 fps (#488, so a 60 fps loop
doesn't skip pictures), and the game takes the next picture when its own count of the movie's 60ths says so
(
hos_movie_frames,host/nn_vi.c). At 240 that count follows the frames' time, not the clock, and drifts: here it ranahead at ~226 fps (0.2 s after 6 s, 0.73 s at the end of the opening). The movie's sound keeps the clock.
dec_acquirealready skipped pictures that fell behind the clock, but handed out early ones.Now a picture more than 25 ms ahead of the movie's clock waits in the queue, and the buffer handed out shows the last
picture again (copied in from the buffer that has it). Not a movie's first or last picture, and only for pools the game
reads through
ReadDecoderOutputImage*, as OoT's are.HOS_VIDEO_NO_HOLD=1turns it off. The movie'svideo: a movie of ...line now counts the holds. Held deliveries also count in the delivery pacing statistics.To see it on main: play the opening (a fresh profile, or Skip opening off) at the default 60 cap on a PC that
holds 240 fps there: the narration and music fall behind the picture as the opening goes on. With
HOS_VIDEO_LOG=1,the
video: acquire N: picture at X s, wall clock Y s (behind by Z s)lines show Z going negative.Read first: the new block in
dec_acquire(host/nn_video.c), after the catch-up.Testing
Tested before the held-delivery accounting change: Windows 11 (26300), RTX 3080, NVIDIA 621.14, a build of this branch. The opening played from a fresh
profile at the default 60 cap (the movie pacing at 240), sound on and recorded with
HOS_AUDIO_DUMP,HOS_VIDEO_LOG=1,and a script stamping each log line and the WAV's growth with the clock. Each run's sound was placed on its picture
timeline and cross-correlated with a run with the pacing off (
HOS_MOVIE_PACE=0, 60 fps, where picture and sound agreewithin 10 ms). With this branch the picture stays within 20 ms of its clock through the opening and on the title's
looping movie, and the sound lines up with the pacing-off run within 10 ms (main: 690 ms). Screenshots during the
opening and on the title: the pictures are whole, no stale or torn frames.
Checks before the held-delivery accounting change:
tests/test_video_hold_early.pyfails on main (the early picture is handed out) and passed on the branch, with clang++and g++, both ways of the switch. The added held-delivery accounting checks are pending.
tests/test_video_catchup.pyand the other checks that readhost/nn_video.cpass.The whole suite (
tests/run_all.py, withouttest_job_queue): 867 passed, 31 failed; the same 31 fail on main@
a2dc5385(Windows-only tool and test-environment failures, e.g.test_switch_table'sRX_VK_GRASS_DISTANCEsort,test_guest_copies,test_crash_dialog).Still to test:
HOS_VIDEO_LOG=1, expecting thebehind byvalues to stay within about 0.03 s. This PC has no Linux toolchain (@Beanstalk or by hand).
skippedcount in the movie's line near#488's (by hand).
Measurements
Verdict: the opening's picture no longer runs ahead of its sound at 240 fps: 0.73 s ahead at the end on main,
0.01 s here.
Setup: Windows 11, RTX 3080, NVIDIA 621.14; the opening (5947 pictures) from a fresh profile, default options, the 60
cap with the movie pacing at 240; measured from the
HOS_VIDEO_LOGlines and the WAV dump as Testing says. The PC waslocked (no one at it), which stalls presents now and then; these are times against the clock, not frame rates.
a2dc53859d487066HOS_MOVIE_PACE=0, 60 fps)The second run of this PR ran at 120 fps (the locked PC halved the present rate for that run, as it did for one run
of main with a probe): there the count runs slow, not fast, so the catch-up skips and nothing is early. Picture at
the end 0.02 s behind, sound -10 ms, 218 pictures skipped and 3 holds, against 230 skipped on main at 120 fps; it is
listed here, not in the table, because the table's two sides are at ~220 fps. Pacing off for reference: 60 fps, 0.01 s,
25 skipped.
Main merged into the branch at
5534c6b8(b9bd74a2, no conflicts); its checks andtest_switch_table(failing as on main) ran again after the merge. Held-delivery accounting changed after the measurements and checks; verification on the current code is pending.Risks
NV12 picture (3 MB, plus RGBA when it was made) when a hold uses a different buffer: 89 holds in the 99 s opening here.
picture by that much. Not changed here.
HOS_VIDEO_NO_HOLD=1, or a revert. Nothing changes in saves or options.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Pending on the current code.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.no Linux toolchain on this PC (Still to test).
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
Tested in game: Windows 11, RTX 3080, NVIDIA 621.14: the opening from a fresh profile at the default cap (movie pacing 240), sound dumped and log stamped; picture within 20 ms of its clock, sound within 10 ms of the pacing-off run (main: 690-830 ms late); title movie and screenshots fine
Possibly related, for context:
@review
Recommendation: Approve. The reported Windows run shows that the picture and sound move back into sync, but holds distort the existing movie pacing statistics. Linux, Steam Deck and other affected Tier 1 systems still need runs, including measurements of the copies' effect on pacing. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
Early movie pictures wait while the previous picture is shown again. The Windows RTX 3080 run reports much better synchronization, at the cost of copying picture buffers on holds and adding a switch and decoder state.
Should fix (1): not blocking, but worth doing before merging.
host/nn_video.c:864: A held acquire returns before updating the existing picture-pacing counters and timestamp. (more on the line) Do: Record the acquire time, gap and shown count for held buffers as well, sharing the accounting with the ordinary output path.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
host/nn_video.c:856: The default-on hold path has not been exercised on Linux or Steam Deck, where decoder and pacing behavior can differ. (more on the line) Do: Build on Linux and run the opening and title loop on Linux and Steam Deck, checking synchronization, holds, skips and completion.host/nn_video.c:859: The full-frame copies on the movie thread have not been measured for their effect on pacing, including on slower CPUs and AMD Tier 1 systems. (more on the line) Do: Compare repeated base and PR opening runs on representative AMD and slower CPU hardware, including frame times, 1% lows and movie pacing. (@fixdoes its part first: Avoid copying the previous image on each hold by retaining or reusing a safe reference to it.)@fixcan do L1 and L3.Questions (1) (not confirmed from the code; they don't hold the recommendation)
host/nn_video.c:849: Can the supported game have two movie decoders performing their first acquire concurrently?Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes, on the reported Windows RTX 3080 run: the picture was 0.01 s ahead at the opening’s end versus 0.73 and 0.86 s on main, and sound alignment improved from 690–830 ms late to 10 ms. The comparable table has one PR run; other platforms and the copy cost remain unmeasured.
Other systems: The hold runs in the shared decoder path for API-read pools, independently of GPU vendor. Windows RTX was tested; Linux, Steam Deck and AMD Tier 1 hardware were not. Direct-memory pools retain the previous behavior. The change does not alter saves, audio or input.
Switches: HOS_VIDEO_NO_HOLD is added as a developer kill switch, default off, so holding is enabled. Its table and reference rows are present. The reported Windows measurement supports the default there; its effect on the other affected systems remains to be checked.
Reviewed:
5534c6b8a7againstb9bd74a25e: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, commit messages, the complete diff, host/nn_video.c, tests/test_video_hold_early.py and the related catch-up fixture. Skimmed the switch reference, switch table, test runner and performance-report consumers. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no builds, tests or project scripts were run. The author reports an in-game Windows RTX 3080 run and game-free checks; CI is still running.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -837,0 +853,4 @@const int from_slot = d->shown_slot - 1;const Pool *from = from_slot >= 0 && from_slot < MAX_SLOTS && d->slot_pts[from_slot] == d->last_pts? (const Pool *)host_of(d->slots[from_slot], POOL_MAGIC) : NULL;if (!no_hold && d->clock_set && d->out_ns && !h->last && h->pts - d->clock_pts > hos_now_ns() - d->clock_ns + early &&L2 (should fix): The default-on hold path has not been exercised on Linux or Steam Deck, where decoder and pacing behavior can differ.
When: A Linux or Deck player can reach this shared decoder path, but the reported Windows run cannot show whether the opening and looping title stay synchronized and progress correctly there.
Do: Build on Linux and run the opening and title loop on Linux and Steam Deck, checking synchronization, holds, skips and completion.
@ -837,0 +856,4 @@if (!no_hold && d->clock_set && d->out_ns && !h->last && h->pts - d->clock_pts > hos_now_ns() - d->clock_ns + early &&to && from && to->read_by_api && from->read_by_api && to->w == from->w && to->h == from->h && to->nv12 && from->nv12) {if (to != from) {memcpy(to->nv12, from->nv12, (size_t)to->w * to->h * 3 / 2);L3 (should fix): The full-frame copies on the movie thread have not been measured for their effect on pacing, including on slower CPUs and AMD Tier 1 systems.
When: Each hold copies about 3 MB for a 1080p NV12 image, and can also copy RGBA. The reported run counts 89 holds but does not measure their frame-time or movie-thread cost, so it cannot rule out visible stalls on slower systems.
Do: Compare repeated base and PR opening runs on representative AMD and slower CPU hardware, including frame times, 1% lows and movie pacing.
@ -837,0 +861,4 @@if (rgba) memcpy(to->rgba, from->rgba, (size_t)to->w * to->h * 4);to->rgba_stale = !rgba;}d->slot_pts[slot] = d->last_pts, d->slot_last[slot] = 0, d->busy[slot] = 1, d->shown_slot = slot + 1;L1 (should fix): A held acquire returns before updating the existing picture-pacing counters and timestamp.
When: When several successive acquires repeat a picture, the next new picture is measured from the last new picture instead of the last acquire. The reported longest wait and late-picture count can therefore indicate a 50 ms or longer delivery gap even though the game received repeated buffers in between, and the shown count omits those buffers.
Do: Record the acquire time, gap and shown count for held buffers as well, sharing the accounting with the ordinary output path.
@fix
Recommendation: Approve. The code is ready: only testing is left. The reported Windows run shows the picture and sound aligning, but Linux and Steam Deck playback and the pacing cost of frame copies remain unmeasured. The current accounting change also awaits verification. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
c1a5e86f8c. I mergedmain(6acae6aa87) into it, as it has merge commits. I edited its description to match the change.Changed
Not done
Nothing was built or run: the checks run again on the new head.
The change holds early movie pictures and repeats the previous picture, reducing the reported opening's sound-to-picture offset at the cost of occasional full-frame copies.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
host/nn_video.c:856: The default-on hold path has not been exercised on Linux or Steam Deck, where decoder and pacing behavior can differ. When: A Linux or Deck player can reach this shared decoder path, but the reported Windows run cannot show whether the opening and looping title stay synchronized and progress correctly there. Do: Build on Linux and run the opening and title loop on Linux and Steam Deck, checking synchronization, holds, skips and completion.host/nn_video.c:859: The full-frame copies on the movie thread have not been measured for their effect on pacing, including on slower CPUs and AMD Tier 1 systems. When: Each hold copies about 3 MB for a 1080p NV12 image, and can also copy RGBA. The reported run counts 89 holds but does not measure their frame-time or movie-thread cost, so it cannot rule out visible stalls on slower systems. Do: Compare repeated base and PR opening runs on representative AMD and slower CPU hardware, including frame times, 1% lows and movie pacing.Checks: they run again on this head; a failure shows on the pull request.
Also noticed (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes on the tested Windows RTX 3080: the description reports sound 690–830 ms late on main versus 10 ms late with the earlier PR build. The current accounting change has not been run, and only one comparable after run is reported.
Other systems: The decoder path also runs on Linux and Steam Deck; neither has a reported playback run. Copy costs on slower CPUs and AMD Tier 1 hardware remain unmeasured.
Switches: HOS_VIDEO_NO_HOLD is added as a kill switch, default off, so holding is enabled. The Windows result supports that default there; Linux, Steam Deck and AMD results are pending. The switch table and reference document have entries.
Reviewed:
c1a5e86f8cagainst6acae6aa87: Read the repository rules, standards, PR template, the video acquisition and reporting paths, the hold test, switch entries, and BeanBot's diff. Skimmed the larger base-to-head diff and commit list; it contains many merged-main files beyond the four listed PR files, which were not read in full. docs/review-checklist.md and the adjacent Tooling rules file were absent.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run tests were executed. The description reports earlier Windows gameplay and game-free checks; CI has not run on the current head.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: fix(video): a movie's picture waits for its clock, so its sound is no longer late at 240 fpsto fix(video): a movie's picture waits for its clock, so its sound is no longer late at 240 fps