Skip to content

audio (every game; changes present_interval display games with FPSLocker rows): no frame pace for a game on its own clock - #1945

Draft
tapionallanaire wants to merge 1 commit into
igawa6:devfrom
tapionallanaire:pr/audio-follower-own-clock
Draft

tapionallanaire wants to merge 1 commit into
igawa6:devfrom
tapionallanaire:pr/audio-follower-own-clock

Conversation

@tapionallanaire

Copy link
Copy Markdown
Collaborator

What and why

Touches every game's audio follower path; only games with present_interval display, reviewed fpslocker rows and no present cap behave differently (list below).

Symptom. A game run at a frame limit by reviewed FPSLocker rows under present_interval display sounds ahead of the picture whenever the device does not hold the limit. Red Dead Redemption with its 60 fps rows (#1801 plus the 60 fps profile PR that follows it) on a hot AYN Thor at 46 to 55 fps: the follower's lines read the game at a median 0.86 of real time, the tempo sat at its 0.99 floor and the sound led the picture by a median 188 ms, up to 392 ms, with 28 underruns in 16 minutes of play.

Cause. peanuts_audiosync.c takes the game's pace from presented frames / nvn_game_fps. Under present_interval display with no present cap that is 60, so every frame not presented counts as game time lost. Red Dead Redemption steps by measured time (RAGE TIME::Update adds the tick delta each frame), so its game clock keeps real time at any frame rate: the follower took a slow device for a slow game. The automatic mode only slows the sound by 1 %, so the lead it integrated kept growing.

Change.

  • dm/host/hle_fpslock.c: dm_fpslocker_rate(), the limit the reviewed rows last wrote (0: no rows, or no limit).
  • dm/gfx/nvn/hle_nvn.c: nvn_game_clock_own(): present_interval display (which dm/games/README.md reserves for games whose logic does not count frames), no present cap, and a limit written by reviewed rows.
  • dm/peanuts/peanuts.c passes a frame rate of 0 for such a game, and pn_as_frame counts nothing for 0 (it used to treat 0 as 60; no caller passed 0). The follower then sees no pace, so the sound stays at real time: tempo 1, no lead, no resync finding.
  • Unchanged: games without reviewed rows, present_interval game, a present cap, and PN_AUDIO_FOLLOW=0/2 semantics. nvn_game_fps is unchanged (the in-game panel reads it only as "presenting").
  • docs/reference/audio.md: a new entry under the follower's section; docs_symptoms.py and docs_patches.py (line numbers in hle_fpslock.c) rerun.

Impact on other profiles

Scan of every dm/games/*/game.tsv for present_interval display together with fpslocker rows (README and docs/reference/*.md read for how each game steps time). shader_map.tsv tables are not touched. 16 profiles on dev match (Red Dead Redemption is the 17th, in #1801):

No fps_target, so no present cap unless the player picks one: the follower now counts none of their frames while the rows write a limit.

  • Advance Wars 1+2: Re-Boot Camp (0100300012F2A000, vsync_u32, limit 60): Unity runs Update every frame and the row only changes how often it renders (its README), so the sound keeps real time as the game does.
  • Fire Emblem: Three Houses (010055D009F78000, frame_scaled_f32, limit 60): KTGL runs 60 updates a second whatever it shows (its README).
  • OCTOPATH TRAVELER (010057D006492000, UE 4.18 target_f32, limit 60): Unreal's frame delta.
  • DRAGON BALL Z: KAKAROT (010051C0134F8000) and Demon Slayer: The Hinokami Chronicles 2 (0100AD80208A8000), Unreal, limit 30: by the code, the old path counted their 30 presented frames as 1/60 s each (a pace of 0.5, inside the follower's 0.45 to 1.05 window) and held the tempo at 0.99. Now tempo 1. Not measured on these games.
  • Fire Emblem Engage (0100A6301214E000, vsync_u32 + inverse_f32, limit 60): the one profile whose note says part of its logic counts frames (about 96 per-frame pieces step by VsyncFixedCount). Below 60 presented, those run slow, and the old path slowed the sound by up to 1 % with them; now the sound keeps real time and only the game's own resync applies. This is the profile most worth a listen.

With fps_target 60: RAIN CODE (0100149019460000), DRAGON QUEST III HD-2D Remake (01003E601E324000), OCTOPATH TRAVELER 0 (01005270232F2000), FINAL FANTASY RESONANCE (0100606026F12000, 0100B8A026F14000), DRAGON QUEST XI S (01006C300E9F0000), No More Heroes 3 (01007C600EB42000), Europa (0100C8E01DD16000), One Piece Odyssey (0100D9601A994000), Breath of the Wild (01007EF00011E000, frame step). Where the host holds the 60 cap (fps_present_cap: an engine limit or the frame step), nvn_game_clock_own is false and nothing changes; a player's "Game owned" pick, or a game whose engine limit the host does not find, takes the path above. Not confirmed per game on a device.

No table, extension, magic or key collision (the change adds no profile key). The documented invariant it relies on is present_interval display's own ("only right for games whose logic does not count frames"); Engage is the exception the scan found.

Open PRs: #1875 also edits hle_fpslock.c; the code merges cleanly, only the generated docs/agents/game-patches.md (its hle_fpslock.c line numbers) needs docs_patches.py again for whichever lands second.

Smoke shortlist: Fire Emblem Engage (frame-counted logic under the new path), Advance Wars 1+2 (the same vsync_u32 row kind as Red Dead Redemption), DRAGON BALL Z: KAKAROT (a 30 limit).

Checked

  • Unit tests:

    • t_peanuts_audiosync (Linux x86-64 container, clang): all passed at this head, including the new case (a game on its own clock presenting 0.86 of its rate: tempo 1.000, lead 0 ms). The new case against dev's peanuts_audiosync.c: FAIL, tempo 0.990, lead 250 ms. dev itself: all passed.
    • t_fpslock (NDK 29 static arm64, run under qemu user emulation, with local stubs for now_ns and three plat_* functions): the new fpslocker_rate_check passes (0 before a tick, 30 with the row writing 2, 60 with it writing 1). step_check and one check case (line 111, a Unity row's write count) fail the same way at dev and at this head under emulation; not run on a device.
  • Python tests: python -m unittest discover -s dm/tools/tests, this head and dev 07cc0805a on Windows: 1,912 tests, the same 100 failures and 154 errors at both (Windows environment: no clang, POSIX tools, game dumps), no new one.

  • pr_ready.py --base upstream/dev: nothing to fix (the scope warning is answered above). docs_symptoms.py --check, docs_patches.py --check current.

  • Phone runs: AYN Thor (Snapdragon 8 Gen 2, Adreno 740, 11.0 GiB, Android 13), Turnip 27.0.0-R2 (Mesa 27.0.0-devel 2648b2059f, Vulkan 1.4.367), Red Dead Redemption 1.0.7 (main 37531419DA76), base v0 and update v458752 NSZs imported and prepared in the app on the device. The build had the 0.1.10 runtime, games: Red Dead Redemption (01007820196A6000) profile, RAGE RPF6 and Double Eleven pack shader readers #1801's profile with the 60 fps rows, vk_android: start cumulative SAMPLES_PASSED on first report without ResetCounter (every NVN game) #1738, and this change in an earlier form that also made nvn_game_fps answer the rows' limit; this PR leaves that out, since the follower no longer reads nvn_game_fps when nvn_game_clock_own holds. Log: interval mode display, frame limit 60 fps (game profile fps_limit), no present cap.

    Follower on and off for the behaviour change (same device, profile and driver; before = the build without it):

    60 limit, before 60 limit, after 30 limit, before 30 limit, after
    play (player control) about 16 min 18.2 min about 13 min 12.3 min
    presented fps (host's 5 s pace lines) 46 to 55 median 57.9, p10 54.0, min 45.6 30 median 29.7
    sound ahead of the picture median 188 ms, max 392 0 (no follower lines) median 2 ms, max 25 0
    tempo 0.99 1.000 0.99 to 0.999 1.000
    game time against real time read as 0.86 from frames 0.994 (TIME counter, 30 s) read as 0.99 1.004
    underruns in play 28 0 2 0

    The after run was less throttled than the before run (median 57.9 fps against 46 to 55), so not all of the underrun difference is the follower's. Played on foot around Armadillo (station, saloon, corrals); the before runs also rode out toward Fort Mercer. A second launch at 60 through the opening cutscene: no follower lines, 58 underruns over the load and the cutscene (the 30 limit before had 72 there).

  • Not checked:

    • Qualcomm's system driver with this change.
    • Lip sync by ear (two 60 fps cutscene clips with device audio were recorded, not judged).
    • No other game was run on a device: Fire Emblem Engage, Advance Wars 1+2 and DRAGON BALL Z: KAKAROT from the shortlist are open; the effect on them above is from the code and their notes.
    • The build tested was 0.1.10 with the profile, not dev 07cc0805a with this commit.

Docs

  • The finding is in docs/reference/audio.md ("Sound ahead of the picture below a frame limit with present_interval display"), and python3 dm/tools/docs_symptoms.py was run
  • No game files, keys or data extracted from a game in the change or the attachments
  • Source only: no binaries, nothing under dm/third_party/, no change to dmsh_chain.lock; the branch starts from the current dev

…nt_interval display

The follower (peanuts_audiosync.c) takes the game's pace from presented
frames / nvn_game_fps. Under present_interval display with no present cap
nvn_game_fps answers 60, so a game that reviewed FPSLocker rows run at a
frame limit was read by its presented frames: Red Dead Redemption on the
AYN Thor at 46 to 55 fps under the 60 limit read as a game at 0.86 of real
time, the tempo sat at its 0.99 floor and the integrated lead ramped to its
0.4 s reset (median 188 ms, 28 underruns in 16 minutes), while the game
itself steps by measured time (RAGE TIME::Update) and ran at real time.

hle_fpslock.c records the limit its rows last wrote (dm_fpslocker_rate).
hle_nvn.c nvn_game_clock_own answers whether the game keeps its own clock:
present_interval display (only for games whose logic does not count frames),
no present cap, and a limit written by reviewed rows. peanuts.c then passes
a frame rate of 0 and pn_as_frame counts nothing: the follower sees no pace
and the sound stays at real time (tempo 1, no lead). Games without rows,
present_interval game and a present cap are counted as before.

t_peanuts_audiosync: a game on its own clock presenting 0.86 of its rate
(tempo 0.990 and a 250 ms lead before, 1.000 and 0 after). t_fpslock: the
recorded limit follows the rows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant