feat(ngs2): custom submixer rack with UserFx2 modules #781

Merged
adriadam10 merged 2 commits from upstream-pr/781 into main 2026-10-06 09:30:35 +00:00
adriadam10 commented 2026-10-05 23:29:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T23:29:15Z.


What

NGS2 custom submixer rack (0x4002) whose modules are all UserFx2 (title-supplied effect callbacks). Before this, sceNgs2RackQueryBufferSize/sceNgs2RackCreate threw for any custom rack id.

  • Rack option, module/port info, UserFx2 module option, the setup/cleanup/control/process contexts, the custom submixer voice setup and the UserFx2 voice param: layouts from shadPS4's ngs2_custom.h/ngs2.h (SDK-style headers). KytyPS5's structs have the same sizes (72/72/104/40 bytes), checked with static_assert.
  • Behaviour from KytyPS5 (src/libs/ngs2.cpp), the only reference with a body:
    • module id 0x1f = UserFx2; setup_handler is called for every voice of every module at rack creation (common/param/work buffers sized from the option, max_voices, voice_index, user_data); cleanup_handler for every voice at rack destruction (also from sceNgs2SystemDestroy).
    • voice param 0x40001f00 | module index copies data into the module's param buffer (size must equal param_size) and sets process flag 2 for the next process call; the flag is cleared after it.
    • at render, after the patched inputs are mixed, each module's process_handler runs in order on the voice's channels in place (input = output channels, grain, system sample rate, per-module state buffer of state_size). Nothing is processed when no input produced samples.
    • custom submixer setup 0x40020000 sets the channel count (input must equal output).
  • Throws (unmodelled, same as KytyPS5's EXIT_NOT_IMPLEMENTED or not covered there): other module ids, num_buffers != 1, module/port buffer ids other than 0, a module control_handler when its param is set, input != output channels, setup flags, a null rack option (default custom options), a handler returning non-zero, sceNgs2VoiceGetState on this rack. Null process_handler, wrong module option size, too many modules/ports and out-of-range module index or channel count are invalid arguments.
  • KytyPS5 also accepts custom sampler/mastering racks but ignores every non-UserFx2 module (sampler, envelope, filter...), so those stay throwing here.
  • ParamAs moved from Voice.cpp to Ngs2Internal.hpp so Custom.cpp uses the same check.
  • TechnicalDebt "Unknown function info": what comes from KytyPS5 only, and that module state is a separate buffer, not the state_offset slice of the voice state.

Port delay, reverb rack and submixer filters/envelopes were checked too: KytyPS5 only logs or ignores them and no other reference has a body, so they stay throwing.

Tested

Linux, GCC Release (-O3) and the fast build. New ngs2_custom test (registered in ctest): two UserFx2 modules on a sampler → custom submixer → mastering chain, pins the rendered samples (gain from param, offset from common, module order), setup/cleanup call order per voice and module, the process flag (0, 2 after a param update, then 0), and every throwing/invalid path above. It fails on main (rack id 0x4002 throws). 18 mutations of the implementation (process call, flag set/clear, setup, cleanup, per-module common, each validation) each make the test fail. ngs2_render, ngs2_atrac9 and all guest_* tests pass.

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 TechnicalDebt
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none (touches the same test foreach line as #778; whichever merges second gets a one-word rebase)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4752015357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/781). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T23:29:15Z. --- ### What NGS2 custom submixer rack (`0x4002`) whose modules are all UserFx2 (title-supplied effect callbacks). Before this, `sceNgs2RackQueryBufferSize`/`sceNgs2RackCreate` threw for any custom rack id. - Rack option, module/port info, UserFx2 module option, the setup/cleanup/control/process contexts, the custom submixer voice setup and the UserFx2 voice param: layouts from shadPS4's `ngs2_custom.h`/`ngs2.h` (SDK-style headers). KytyPS5's structs have the same sizes (72/72/104/40 bytes), checked with `static_assert`. - Behaviour from KytyPS5 (`src/libs/ngs2.cpp`), the only reference with a body: - module id `0x1f` = UserFx2; `setup_handler` is called for every voice of every module at rack creation (common/param/work buffers sized from the option, `max_voices`, `voice_index`, `user_data`); `cleanup_handler` for every voice at rack destruction (also from `sceNgs2SystemDestroy`). - voice param `0x40001f00 | module index` copies `data` into the module's param buffer (size must equal `param_size`) and sets process flag 2 for the next process call; the flag is cleared after it. - at render, after the patched inputs are mixed, each module's `process_handler` runs in order on the voice's channels in place (input = output channels, grain, system sample rate, per-module state buffer of `state_size`). Nothing is processed when no input produced samples. - custom submixer setup `0x40020000` sets the channel count (input must equal output). - Throws (unmodelled, same as KytyPS5's `EXIT_NOT_IMPLEMENTED` or not covered there): other module ids, `num_buffers != 1`, module/port buffer ids other than 0, a module `control_handler` when its param is set, input != output channels, setup flags, a null rack option (default custom options), a handler returning non-zero, `sceNgs2VoiceGetState` on this rack. Null `process_handler`, wrong module option size, too many modules/ports and out-of-range module index or channel count are invalid arguments. - KytyPS5 also accepts custom sampler/mastering racks but ignores every non-UserFx2 module (sampler, envelope, filter...), so those stay throwing here. - `ParamAs` moved from `Voice.cpp` to `Ngs2Internal.hpp` so `Custom.cpp` uses the same check. - TechnicalDebt "Unknown function info": what comes from KytyPS5 only, and that module state is a separate buffer, not the `state_offset` slice of the voice state. Port delay, reverb rack and submixer filters/envelopes were checked too: KytyPS5 only logs or ignores them and no other reference has a body, so they stay throwing. ### Tested Linux, GCC Release (`-O3`) and the fast build. New `ngs2_custom` test (registered in ctest): two UserFx2 modules on a sampler → custom submixer → mastering chain, pins the rendered samples (gain from param, offset from common, module order), setup/cleanup call order per voice and module, the process flag (0, 2 after a param update, then 0), and every throwing/invalid path above. It fails on `main` (rack id `0x4002` throws). 18 mutations of the implementation (process call, flag set/clear, setup, cleanup, per-module common, each validation) each make the test fail. `ngs2_render`, `ngs2_atrac9` and all `guest_*` tests pass. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none (touches the same test `foreach` line as #778; whichever merges second gets a one-word rebase) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-05 23:29:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T23:29:38Z.


Progress report (481c85e → 5a031f3)

📈 System libraries: 82.34% (+0.03%, +5 implemented functions)

✅ 5 implemented
Library Name
libSceNgs2.native Cleanup
libSceNgs2.native ControlHandler
libSceNgs2.native Gain
libSceNgs2.native Offset
libSceNgs2.native Setup
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6005427003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/781#issuecomment-6005427003). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T23:29:38Z. --- <!-- progress-report --> ### Progress report (481c85e → 5a031f3) 📈 **System libraries**: 82.34% (+0.03%, +5 implemented functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libSceNgs2.native | `Cleanup` | | libSceNgs2.native | `ControlHandler` | | libSceNgs2.native | `Gain` | | libSceNgs2.native | `Offset` | | libSceNgs2.native | `Setup` | </details>
oneandonlydean commented 2026-10-06 01:12:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T01:12:37Z.


Thanks. The layouts match shadPS4's ngs2.h/ngs2_custom.h (contexts 72/72/72/104, module option 72, module info 40, the submixer setup and UserFx2 params 24), and the handler typedefs use APS5_VABI like the existing allocator and voice callbacks, so the calls are right on Windows too.

One difference from KytyPS5, which the PR follows for the behaviour: its per-voice module state starts with flags = 1 (struct Module { ... uint32_t flags = 1; } in src/libs/ngs2.cpp). So the first process_handler call after setup sees 1, later calls see 0, and the call after a param change sees 2 (module.flags |= 2, then module.flags = 0 after the call). Here Ngs2UserFx2::flags starts at 0 (Ngs2Internal.hpp:61), and Ngs2Custom.cpp pins {0} and {0, 2, 0}. If the first-call bit is what tells an effect to initialise its work/state, an effect would start on uninitialised buffers. Could you start at 1 and pin {1} and {1, 2, 0}?

Minor: process runs only when an input produced samples (as in KytyPS5), so an effect tail stops and a pending flag 2 waits for the next audible grain. That's worth a few words in the TechnicalDebt entry. This also conflicts with #778 on the foreach line in libSceNgs2.native/CMakeLists.txt (Filter vs Custom). Whichever lands second only needs both names.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6007248053 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/781#issuecomment-6007248053). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T01:12:37Z. --- Thanks. The layouts match shadPS4's `ngs2.h`/`ngs2_custom.h` (contexts 72/72/72/104, module option 72, module info 40, the submixer setup and UserFx2 params 24), and the handler typedefs use `APS5_VABI` like the existing allocator and voice callbacks, so the calls are right on Windows too. One difference from KytyPS5, which the PR follows for the behaviour: its per-voice module state starts with `flags = 1` (`struct Module { ... uint32_t flags = 1; }` in `src/libs/ngs2.cpp`). So the first `process_handler` call after setup sees 1, later calls see 0, and the call after a param change sees 2 (`module.flags |= 2`, then `module.flags = 0` after the call). Here `Ngs2UserFx2::flags` starts at 0 (`Ngs2Internal.hpp:61`), and `Ngs2Custom.cpp` pins `{0}` and `{0, 2, 0}`. If the first-call bit is what tells an effect to initialise its `work`/`state`, an effect would start on uninitialised buffers. Could you start at 1 and pin `{1}` and `{1, 2, 0}`? Minor: process runs only when an input produced samples (as in KytyPS5), so an effect tail stops and a pending flag 2 waits for the next audible grain. That's worth a few words in the TechnicalDebt entry. This also conflicts with #778 on the `foreach` line in `libSceNgs2.native/CMakeLists.txt` (`Filter` vs `Custom`). Whichever lands second only needs both names.
adriadam10 commented 2026-10-06 05:17:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T05:17:47Z.


Fixed, thanks:

  • UserFx2 flags now start at 1 when the voice is set up (KytyPS5 Module::flags = 1); the test pins {1} and {1, 2, 0} (fails if the init is removed).
  • TechnicalDebt entry now lists the flags (1 first call, 2 after a param change, 0 otherwise) and that process runs only on grains where an input produced samples, so a tail stops and a pending flag 2 waits for the next audible grain.
  • Rebased on current main. The foreach conflict with #778 stays: whichever lands second needs both names.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6009851779 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/781#issuecomment-6009851779). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T05:17:47Z. --- Fixed, thanks: - UserFx2 flags now start at 1 when the voice is set up (KytyPS5 `Module::flags = 1`); the test pins `{1}` and `{1, 2, 0}` (fails if the init is removed). - TechnicalDebt entry now lists the flags (1 first call, 2 after a param change, 0 otherwise) and that process runs only on grains where an input produced samples, so a tail stops and a pending flag 2 waits for the next audible grain. - Rebased on current `main`. The `foreach` conflict with #778 stays: whichever lands second needs both names.
adriadam10 commented 2026-10-06 05:40:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T05:40:45Z.


Rebased on main after #778: the only conflict was the test foreach line, now Render Atrac9 Filter Custom. ngs2_render/atrac9/filter/custom pass (Release, GCC).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6010134845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/781#issuecomment-6010134845). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T05:40:45Z. --- Rebased on main after #778: the only conflict was the test `foreach` line, now `Render Atrac9 Filter Custom`. ngs2_render/atrac9/filter/custom pass (Release, GCC).
oneandonlydean commented 2026-10-06 09:27:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T09:27:54Z.


Thanks, that covers both points: the flags start at 1 at setup and the test pins {1} and {1, 2, 0}, and the TechnicalDebt entry now lists the flags and the process-only-on-audible-grains behaviour. The feature commit is unchanged apart from the #778 context, and it merges cleanly with main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6013355759 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/781#issuecomment-6013355759). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T09:27:54Z. --- Thanks, that covers both points: the flags start at 1 at setup and the test pins `{1}` and `{1, 2, 0}`, and the TechnicalDebt entry now lists the flags and the process-only-on-audible-grains behaviour. The feature commit is unchanged apart from the #778 context, and it merges cleanly with main.
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!781
No description provided.