fix(ngs2): stop stale rendering after waveform callbacks #6029

Merged
Ondra97 merged 1 commit from upstream-pr/6029 into main 2026-10-17 04:10:16 +00:00
Ondra97 commented 2026-10-14 19:38:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-14T19:38:47Z.


What

A PCM block-end/repeat callback can replace a waveform through sceNgs2VoiceControl, but the renderer ignores Ngs2FinishBlock's revision result and keeps consuming the replacement with the old pitch step. A one-frame block at pitch 2 consumes 16 samples in the current grain after a callback RESET, instead of leaving the replacement untouched for the next grain.

Callback SETUP can also change a mono voice into an eight-channel voice after its grain buffer was allocated for mono. Continuing with the new channel count writes past that buffer; filtering/mixing also need a valid channel layout after the callback.

Honor block completion's revision/state result and stop PCM consumption when the waveform revision changes, matching the existing ATRAC9 renderer. Preserve the already-rendered prefix for a same-channel RESET. If the channel count changes, replace the invalidated grain with a zeroed buffer of the new layout before filters or effects can use it. Ordinary queue refills continue within the current grain, and pause/refill remains resumable.

Tested

I tested on Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs), Release/Ninja, bundled dependencies and BUILD_TESTING=ON.

  • Main fd6c5ad9c: the new public-API RESET regression fails with PCM callback reset consumed 16 samples before the next grain, expected 1 (0.23 s). The failure is a decoded-count assertion; I did not run an ASan build or claim a measured retail crash.
  • The added cases check RESET from end/repeat callbacks at pitch 2, replacement data/counters before the next grain, exact next-grain audio, ordinary queue refill, pause/resume, and mono-to-stereo/eight-channel SETUP from both callback kinds. The reconfigured grain is silent and its replacement queue remains untouched; the next render produces the exact interleaved samples and byte counts.
  • Full default Windows build passed. All 10 NGS2 tests passed (0.78 s), including the core and native renderer, ATRAC9, filters, custom racks, parsing, streams, UserFx, reports and geometry. Both renderer variants also passed five consecutive runs each (10 executions, 1.79 s).
  • I compared the exact current patches of all five open PRs sharing these files against the complete 449-PR inventory. Their input retention, codec support, output capacity, effects and reverb changes do not implement this callback cleanup.

After rebase onto main 9f03c4fe0, the full default Windows build passed and all 10 NGS2 tests passed again (0.73 s). Conventions, the complete PR description, git diff --check, and the repository overlap checker passed on commit 18114a241. I refreshed the full open-PR inventory immediately before publication; the five shared PR heads are unchanged and none implements this fix.

No title replay, console callback timing measurement or Linux run was performed. No title-specific behavior, exports, dependencies or cache budgets are added.

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 in technical debt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes — Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4863467315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6029). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-14T19:38:47Z. --- ### What A PCM block-end/repeat callback can replace a waveform through `sceNgs2VoiceControl`, but the renderer ignores `Ngs2FinishBlock`'s revision result and keeps consuming the replacement with the old pitch step. A one-frame block at pitch 2 consumes 16 samples in the current grain after a callback RESET, instead of leaving the replacement untouched for the next grain. Callback SETUP can also change a mono voice into an eight-channel voice after its grain buffer was allocated for mono. Continuing with the new channel count writes past that buffer; filtering/mixing also need a valid channel layout after the callback. Honor block completion's revision/state result and stop PCM consumption when the waveform revision changes, matching the existing ATRAC9 renderer. Preserve the already-rendered prefix for a same-channel RESET. If the channel count changes, replace the invalidated grain with a zeroed buffer of the new layout before filters or effects can use it. Ordinary queue refills continue within the current grain, and pause/refill remains resumable. ### Tested I tested on Windows 11 Pro 10.0.26300, MinGW-w64 GCC 15.2.0 (WinLibs), Release/Ninja, bundled dependencies and `BUILD_TESTING=ON`. - Main `fd6c5ad9c`: the new public-API RESET regression fails with `PCM callback reset consumed 16 samples before the next grain, expected 1` (0.23 s). The failure is a decoded-count assertion; I did not run an ASan build or claim a measured retail crash. - The added cases check RESET from end/repeat callbacks at pitch 2, replacement data/counters before the next grain, exact next-grain audio, ordinary queue refill, pause/resume, and mono-to-stereo/eight-channel SETUP from both callback kinds. The reconfigured grain is silent and its replacement queue remains untouched; the next render produces the exact interleaved samples and byte counts. - Full default Windows build passed. All 10 NGS2 tests passed (0.78 s), including the core and native renderer, ATRAC9, filters, custom racks, parsing, streams, UserFx, reports and geometry. Both renderer variants also passed five consecutive runs each (10 executions, 1.79 s). - I compared the exact current patches of all five open PRs sharing these files against the complete 449-PR inventory. Their input retention, codec support, output capacity, effects and reverb changes do not implement this callback cleanup. After rebase onto main `9f03c4fe0`, the full default Windows build passed and all 10 NGS2 tests passed again (0.73 s). Conventions, the complete PR description, `git diff --check`, and the repository overlap checker passed on commit `18114a241`. I refreshed the full open-PR inventory immediately before publication; the five shared PR heads are unchanged and none implements this fix. No title replay, console callback timing measurement or Linux run was performed. No title-specific behavior, exports, dependencies or cache budgets are added. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in technical debt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes — Codex
coltken95 commented 2026-10-15 00:41:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T00:41:48Z.


Tested on Linux x86-64 (Release build), with 18114a241 merged into main ab9a47684:

  • With the PR: ngs2_core_render and ngs2_render pass.
  • With main's libSceNgs2.native/src/Render.cpp: both abort with PCM callback reset consumed 16 samples before the next grain, expected 1 / NGS2 check failed at line 335.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181699272 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6029#issuecomment-6181699272). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T00:41:48Z. --- Tested on Linux x86-64 (Release build), with 18114a241 merged into main ab9a47684: - With the PR: `ngs2_core_render` and `ngs2_render` pass. - With main's `libSceNgs2.native/src/Render.cpp`: both abort with `PCM callback reset consumed 16 samples before the next grain, expected 1` / `NGS2 check failed at line 335`. AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-15 12:13:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:13:39Z.


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 1384 core/libs/prx/libSceNgs2.native/src/Render.cpp
PR 5797 core/libs/prx/libSceNgs2.native/src/Render.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191775707 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6029#issuecomment-6191775707). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:13:39Z. --- <!-- 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 1384](https://www.github.com/boykopovar/AnyPS5/pull/1384) | `core/libs/prx/libSceNgs2.native/src/Render.cpp` | | [PR 5797](https://www.github.com/boykopovar/AnyPS5/pull/5797) | `core/libs/prx/libSceNgs2.native/src/Render.cpp` |
adriadam10 commented 2026-10-16 21:16:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T21:16:46Z.


Checked the Ngs2FinishBlock result handling against the ATRAC9 path, the channel-change grain reset, and the three new tests. The ngs2 tests pass (10/10) and ngs2_render fails with Render.cpp reverted. Also confirmed on Linux by @coltken95; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224859061 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6029#issuecomment-6224859061). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T21:16:46Z. --- Checked the `Ngs2FinishBlock` result handling against the ATRAC9 path, the channel-change grain reset, and the three new tests. The ngs2 tests pass (10/10) and `ngs2_render` fails with `Render.cpp` reverted. Also confirmed on Linux by @coltken95; merging.
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!6029
No description provided.