fix(libSceAudioOut): count completed AudioOut2 grains in the queue level #6474

Merged
fdfawef324 merged 1 commit from upstream-pr/6474 into main 2026-10-17 13:05:39 +00:00
fdfawef324 commented 2026-10-15 16:38:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T16:38:20Z.


What

Black Myth: Wukong (PPSA23226) stops 20 s after its first frame, while it loads at 0.1 FPS:

terminate called after throwing an instance of 'std::runtime_error'
  what():  AudioOut2: more than 16 completed grains await a push

Its AudioOut2 output is Wwise's sink, linked into the eboot. I read it in the relinked executable:

  • The context is created with queue_depth 4 (the sink's default).
  • The sink's IsDataNeeded calls sceAudioOut2ContextGetQueueLevel(ctx, NULL, &available) and returns available as the number of frames the sound engine renders.
  • Each rendered frame ends with a job that calls sceAudioOut2ContextAdvance and signals a semaphore (guest 0x111e1e30, the frame in the crash stack, run on one of the game's worker threads).
  • AK::AudioOutThread waits on that semaphore, calls sceAudioOut2ContextPush(ctx, 1) and wakes the sound engine.

Every advance is pushed. They pile up because of the level the title is given. With an SDL device the level is the pushed grains beyond the 40 ms cushion. At startup and after the device runs dry, the pushes that refill the cushion leave the level at 0, so each wake after such a push asks for a full queue again. With queue_depth 4 that adds 3 completed grains per push, and an advance throws after the fifth push.

sceAudioOut2ContextGetQueueLevel now also counts the grains that Advance completed and no push has consumed, up to queue_depth. A title that renders what the level leaves room for then keeps at most queue_depth grains ahead of its pushes. Push still waits only on the pushed grains, so a completed grain goes out as soon as the device has room. The level changes only while completed grains await a push, so titles that never call Advance are unaffected.

The console behaviour is not known. No SDK header or console measurement says whether the console's level counts advanced grains that have not been pushed, or how many such grains a context can hold. The new technical-debt entry records this. The 16-grain limit stays.

#6216 removes the 16-grain limit for PPSA26358, which stops with the same message. That avoids the stop but leaves the backlog growing. With only that change, this PR's test still fails: its producer gets more than queue_depth grains ahead. The two PRs change different lines.

The regression test drives a context the way the sink does: queue_depth 4, render as many distinct grains as available reports, push one per poll. It checks that the producer never gets more than queue_depth grains ahead and that all 48 grains play in order.

Tested

Windows Server 2025, WinLibs GCC 15.2, Release, SDL disk audio driver:

  • audio_out2_port_buffers on main aborts with the PPSA23226 message after its fifth push. With main's limit removed (as in #6216) it aborts on the queue-depth check. With this change it passes 5 of 5 runs (1.8 s).
  • All 16 audio_out* tests pass.
  • tools/check_conventions.py --base upstream/main and git diff --check pass.

PPSA23226, Windows Server 2025, RTX 3060 (driver 591.86), cold shader cache:

  • main 71bd2876e: stops 172 s in, 20 s after its first frame, with the message above.
  • This PR, on its base 0029e62f9 (172 commits after 71bd2876e, with no libSceAudioOut change between them): no AudioOut2 error. The run went on until the harness's timed dump at 1,786 s, with 8,544 frames presented and 5.92 FPS in the window title at the end. The harness stops dumping after 20 frames, so the dumps cover only the first few minutes. They show the Initial Setup, brightness and "Personal Information Protection Policy" screens.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source: n/a
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA23226 (no Game bring-up discussion yet), the AudioOut2 stop at 172 s quoted above
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4876637420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6474). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-15T16:38:20Z. --- ### What Black Myth: Wukong (PPSA23226) stops 20 s after its first frame, while it loads at 0.1 FPS: ``` terminate called after throwing an instance of 'std::runtime_error' what(): AudioOut2: more than 16 completed grains await a push ``` Its AudioOut2 output is Wwise's sink, linked into the eboot. I read it in the relinked executable: - The context is created with `queue_depth` 4 (the sink's default). - The sink's `IsDataNeeded` calls `sceAudioOut2ContextGetQueueLevel(ctx, NULL, &available)` and returns `available` as the number of frames the sound engine renders. - Each rendered frame ends with a job that calls `sceAudioOut2ContextAdvance` and signals a semaphore (guest `0x111e1e30`, the frame in the crash stack, run on one of the game's worker threads). - `AK::AudioOutThread` waits on that semaphore, calls `sceAudioOut2ContextPush(ctx, 1)` and wakes the sound engine. Every advance is pushed. They pile up because of the level the title is given. With an SDL device the level is the pushed grains beyond the 40 ms cushion. At startup and after the device runs dry, the pushes that refill the cushion leave the level at 0, so each wake after such a push asks for a full queue again. With `queue_depth` 4 that adds 3 completed grains per push, and an advance throws after the fifth push. `sceAudioOut2ContextGetQueueLevel` now also counts the grains that Advance completed and no push has consumed, up to `queue_depth`. A title that renders what the level leaves room for then keeps at most `queue_depth` grains ahead of its pushes. `Push` still waits only on the pushed grains, so a completed grain goes out as soon as the device has room. The level changes only while completed grains await a push, so titles that never call Advance are unaffected. The console behaviour is not known. No SDK header or console measurement says whether the console's level counts advanced grains that have not been pushed, or how many such grains a context can hold. The new technical-debt entry records this. The 16-grain limit stays. #6216 removes the 16-grain limit for PPSA26358, which stops with the same message. That avoids the stop but leaves the backlog growing. With only that change, this PR's test still fails: its producer gets more than `queue_depth` grains ahead. The two PRs change different lines. The regression test drives a context the way the sink does: `queue_depth` 4, render as many distinct grains as `available` reports, push one per poll. It checks that the producer never gets more than `queue_depth` grains ahead and that all 48 grains play in order. ### Tested Windows Server 2025, WinLibs GCC 15.2, Release, SDL disk audio driver: - `audio_out2_port_buffers` on `main` aborts with the PPSA23226 message after its fifth push. With `main`'s limit removed (as in #6216) it aborts on the queue-depth check. With this change it passes 5 of 5 runs (1.8 s). - All 16 `audio_out*` tests pass. - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. PPSA23226, Windows Server 2025, RTX 3060 (driver 591.86), cold shader cache: - `main` 71bd2876e: stops 172 s in, 20 s after its first frame, with the message above. - This PR, on its base 0029e62f9 (172 commits after 71bd2876e, with no `libSceAudioOut` change between them): no AudioOut2 error. The run went on until the harness's timed dump at 1,786 s, with 8,544 frames presented and 5.92 FPS in the window title at the end. The harness stops dumping after 20 frames, so the dumps cover only the first few minutes. They show the Initial Setup, brightness and "Personal Information Protection Policy" screens. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source: n/a - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA23226 (no Game bring-up discussion yet), the AudioOut2 stop at 172 s quoted above - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-15 18:09:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T18:09:27Z.

Review: COMMENTED


Linux run, since the PR only has Windows runs.

Ubuntu 26.04, i7-8700, gcc 15.2, Release, BUILD_TESTING=ON, full build. Head 2321f1ac7 applied on main 03c4cb5e7. Headless, so SDL picks the disk audio driver.

  • Test only (the PR's AudioOut2PortBuffers.cpp on main's source): audio_out2_port_buffers aborts with AudioOut2: more than 16 completed grains await a push.
  • With the fix: audio_out2_port_buffers passes 10 of 10 runs (1.5 s each), and the 17 audio_out* tests pass 5 times in a row (-j1 --repeat until-fail:5).
  • Non-GPU suite (649 tests, -E "^agc|gpu|vulkan|video_out", -j8): same result as main. Only file_writer_binary and file_writer_text fail, on main too (this host's coreutils rejects the command they run).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5537797944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6474#pullrequestreview-5537797944). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T18:09:27Z. **Review:** COMMENTED --- Linux run, since the PR only has Windows runs. Ubuntu 26.04, i7-8700, gcc 15.2, Release, `BUILD_TESTING=ON`, full build. Head `2321f1ac7` applied on `main` 03c4cb5e7. Headless, so SDL picks the disk audio driver. - Test only (the PR's `AudioOut2PortBuffers.cpp` on `main`'s source): `audio_out2_port_buffers` aborts with `AudioOut2: more than 16 completed grains await a push`. - With the fix: `audio_out2_port_buffers` passes 10 of 10 runs (1.5 s each), and the 17 `audio_out*` tests pass 5 times in a row (`-j1 --repeat until-fail:5`). - Non-GPU suite (649 tests, `-E "^agc|gpu|vulkan|video_out"`, `-j8`): same result as `main`. Only `file_writer_binary` and `file_writer_text` fail, on `main` too (this host's coreutils rejects the command they run). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
fdfawef324 commented 2026-10-15 20:01:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T20:01:44Z.


I ran this on Black Myth: Wukong (PPSA23226). Setup: Windows Server 2025, RTX 3060 12 GB (driver 591.86), Ryzen 9 5900X, MinGW GCC 15.2 Release, cold shader cache in both runs.

  • main 71bd2876e: stops 172 s in, 20 s after its first frame, with 5 frames presented:
    terminate called after throwing an instance of 'std::runtime_error'
      what():  AudioOut2: more than 16 completed grains await a push
    
  • This PR (2321f1ac7, on its base 0029e62f9, which is 172 commits after 71bd2876e with no libSceAudioOut change between them): no AudioOut2 error. It ran until the harness's timed dump at 1,786 s. By then it had presented 8,544 frames, and the window title showed 5.92 FPS. The harness stops dumping after 20 frames, so the dumps cover only the first few minutes. They show the Initial Setup, brightness and "Personal Information Protection Policy" screens.

I've added this to the Tested section.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6201130502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6474#issuecomment-6201130502). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-15T20:01:44Z. --- I ran this on Black Myth: Wukong (PPSA23226). Setup: Windows Server 2025, RTX 3060 12 GB (driver 591.86), Ryzen 9 5900X, MinGW GCC 15.2 Release, cold shader cache in both runs. - `main` 71bd2876e: stops 172 s in, 20 s after its first frame, with 5 frames presented: ``` terminate called after throwing an instance of 'std::runtime_error' what(): AudioOut2: more than 16 completed grains await a push ``` - This PR (2321f1ac7, on its base 0029e62f9, which is 172 commits after 71bd2876e with no `libSceAudioOut` change between them): no AudioOut2 error. It ran until the harness's timed dump at 1,786 s. By then it had presented 8,544 frames, and the window title showed 5.92 FPS. The harness stops dumping after 20 frames, so the dumps cover only the first few minutes. They show the Initial Setup, brightness and "Personal Information Protection Policy" screens. I've added this to the Tested section. AI-assisted: yes
github-actions[bot] commented 2026-10-16 18:40:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T18:40:10Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libSceAudioOut.md
PR 6447 docs/dev/debt/libSceAudioOut.md
PR 6493 docs/dev/debt/libSceAudioOut.md
PR 6964 docs/dev/debt/libSceAudioOut.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6222305399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6474#issuecomment-6222305399). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T18:40:10Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libSceAudioOut.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `docs/dev/debt/libSceAudioOut.md` | | [PR 6493](https://www.github.com/boykopovar/AnyPS5/pull/6493) | `docs/dev/debt/libSceAudioOut.md` | | [PR 6964](https://www.github.com/boykopovar/AnyPS5/pull/6964) | `docs/dev/debt/libSceAudioOut.md` |
EagleBearerYS commented 2026-10-17 13:05:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-17T13:05:28Z.


A data point from Resident Evil Village (PPSA01556), which stops with this PR's message too. Windows 11 (10.0.26300), RTX 3070 Laptop (driver 617.42), Ryzen 9 5900HS. The trees are local test trees based on main, with main's libSceAudioOut.

Without this PR, one run stopped 11.1 minutes into the boot, after the startup dialogs and before the title screen:

[libc] unhandled exception 'St13runtime_error' thrown from 00007ff96a912858
terminate called after throwing an instance of 'std::runtime_error'
  what():  AudioOut2: more than 16 completed grains await a push
FATAL: abort() (SIGABRT) on thread 18216

It's intermittent here. Two other runs of the same tree that evening didn't stop this way, and no other Resident Evil Village run we've logged since 2026-10-12 did.

With this PR (2321f1ac7f cherry-picked onto that tree, and onto variants of it that change only the AGC driver), 10 runs went through the boot and the title:

  • 8 reached the main menu, and 4 of those stayed there for 11 to 16 minutes.
  • None printed an AudioOut2 line.
  • Each run ended in our own harness (a planned close, a commit guard or a watchdog), none in audio.

Because the stop was rare without the PR, these runs show the change running through boot, title and menu without a new AudioOut2 problem, rather than proving the fix on this game. No scene was loaded, so gameplay isn't covered.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234225425 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6474#issuecomment-6234225425). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-17T13:05:28Z. --- A data point from Resident Evil Village (PPSA01556), which stops with this PR's message too. Windows 11 (10.0.26300), RTX 3070 Laptop (driver 617.42), Ryzen 9 5900HS. The trees are local test trees based on `main`, with `main`'s `libSceAudioOut`. **Without this PR,** one run stopped 11.1 minutes into the boot, after the startup dialogs and before the title screen: ``` [libc] unhandled exception 'St13runtime_error' thrown from 00007ff96a912858 terminate called after throwing an instance of 'std::runtime_error' what(): AudioOut2: more than 16 completed grains await a push FATAL: abort() (SIGABRT) on thread 18216 ``` It's intermittent here. Two other runs of the same tree that evening didn't stop this way, and no other Resident Evil Village run we've logged since 2026-10-12 did. **With this PR** (2321f1ac7f cherry-picked onto that tree, and onto variants of it that change only the AGC driver), 10 runs went through the boot and the title: - 8 reached the main menu, and 4 of those stayed there for 11 to 16 minutes. - None printed an `AudioOut2` line. - Each run ended in our own harness (a planned close, a commit guard or a watchdog), none in audio. Because the stop was rare without the PR, these runs show the change running through boot, title and menu without a new AudioOut2 problem, rather than proving the fix on this game. No scene was loaded, so gameplay isn't covered.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6474
No description provided.