feat(libSceNgs2): add custom sampler and custom mastering racks #3793

Closed
Techx3 wants to merge 1 commit from upstream-pr/3793 into main
Techx3 commented 2026-10-11 16:44:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Techx3 on 2026-10-11T16:44:20Z.


Add the custom sampler (0x4001) and custom mastering (0x4003) racks on top of the custom submixer support:

  • Ngs2CustomSamplerRackOption (1304 bytes) and Ngs2CustomMasteringRackOption (1288 bytes), with their voice states (48 and 16 bytes).
  • The racks render as the sampler / mastering rack they are built on and run their UserFx2 modules like the custom submixer.
  • Custom sampler params are the sampler params under the custom rack id; the custom mastering setup param 0x40030000 sets the channel count.
  • Built-in (non-UserFx2) modules are accepted on these two racks but not run individually; their controls are ignored and logged once. The custom submixer keeps rejecting them. Recorded in docs/dev/TechnicalDebt.md.

Seen on PPSA15552 (Dead Cells), which creates both racks at start-up. (It also patches voices to a rack handle, which still fails and is not part of this change.)
Tests cover both racks in tests/Ngs2Custom.cpp.

Claude-Session: https://claude.ai/code/session_017Dqgm9nUKygsXzr6poJsHJ

What

Adds the NGS2 custom sampler (0x4001) and custom mastering (0x4003) racks next to the existing custom submixer:

  • Ngs2CustomSamplerRackOption (1304 bytes) and Ngs2CustomMasteringRackOption (1288 bytes), and their voice states Ngs2CustomSamplerVoiceState (48) and Ngs2CustomMasteringVoiceState (16); the sizes are checked with static_assert. Layouts follow KytyPS5, where the same title runs.
  • The racks render like the sampler / mastering rack they are built on and run their UserFx2 modules like the custom submixer.
  • Custom sampler params are the sampler params under the custom rack id (0x4001xxxx); the custom mastering setup param 0x40030000 sets the channel count with the custom submixer setup layout.
  • Built-in (non-UserFx2) modules are accepted on these two racks but not run one by one: the rack's own sampler or mastering processing stands for the chain, and their controls (0x4000xxxx outside UserFx2) are ignored and logged once. The custom submixer keeps rejecting them. Recorded in TechnicalDebt.

Tested

  • Linux (GCC 13): ngs2_custom, ngs2_render, ngs2_core_render, ngs2_atrac9, ngs2_filter, ngs2_parse, ngs2_stream and ngs2_userfx pass. New cases in tests/Ngs2Custom.cpp cover both racks (sampler playback with a UserFx2 gain and a built-in module, custom mastering output, voice states).
  • Windows 11, PPSA15552 (Dead Cells): on current main it stops at NGS2: rack id 0x4001 is not implemented; with this change it creates both racks (built-in module 0x13 in the custom sampler) and continues. The title then patches voices to a rack handle, which is not part of this PR.

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
  • AI-assisted: yes (Claude)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820654837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3793). Originally posted by [Techx3](https://github.com/Techx3) on 2026-10-11T16:44:20Z. --- Add the custom sampler (0x4001) and custom mastering (0x4003) racks on top of the custom submixer support: - Ngs2CustomSamplerRackOption (1304 bytes) and Ngs2CustomMasteringRackOption (1288 bytes), with their voice states (48 and 16 bytes). - The racks render as the sampler / mastering rack they are built on and run their UserFx2 modules like the custom submixer. - Custom sampler params are the sampler params under the custom rack id; the custom mastering setup param 0x40030000 sets the channel count. - Built-in (non-UserFx2) modules are accepted on these two racks but not run individually; their controls are ignored and logged once. The custom submixer keeps rejecting them. Recorded in docs/dev/TechnicalDebt.md. Seen on PPSA15552 (Dead Cells), which creates both racks at start-up. (It also patches voices to a rack handle, which still fails and is not part of this change.) Tests cover both racks in tests/Ngs2Custom.cpp. Claude-Session: https://claude.ai/code/session_017Dqgm9nUKygsXzr6poJsHJ ### What Adds the NGS2 custom sampler (`0x4001`) and custom mastering (`0x4003`) racks next to the existing custom submixer: - `Ngs2CustomSamplerRackOption` (1304 bytes) and `Ngs2CustomMasteringRackOption` (1288 bytes), and their voice states `Ngs2CustomSamplerVoiceState` (48) and `Ngs2CustomMasteringVoiceState` (16); the sizes are checked with `static_assert`. Layouts follow KytyPS5, where the same title runs. - The racks render like the sampler / mastering rack they are built on and run their UserFx2 modules like the custom submixer. - Custom sampler params are the sampler params under the custom rack id (`0x4001xxxx`); the custom mastering setup param `0x40030000` sets the channel count with the custom submixer setup layout. - Built-in (non-UserFx2) modules are accepted on these two racks but not run one by one: the rack's own sampler or mastering processing stands for the chain, and their controls (`0x4000xxxx` outside UserFx2) are ignored and logged once. The custom submixer keeps rejecting them. Recorded in TechnicalDebt. ### Tested - Linux (GCC 13): `ngs2_custom`, `ngs2_render`, `ngs2_core_render`, `ngs2_atrac9`, `ngs2_filter`, `ngs2_parse`, `ngs2_stream` and `ngs2_userfx` pass. New cases in `tests/Ngs2Custom.cpp` cover both racks (sampler playback with a UserFx2 gain and a built-in module, custom mastering output, voice states). - Windows 11, PPSA15552 (Dead Cells): on current main it stops at `NGS2: rack id 0x4001 is not implemented`; with this change it creates both racks (built-in module `0x13` in the custom sampler) and continues. The title then patches voices to a rack handle, which is not part of this PR. ### 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 TechnicalDebt - [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 - [x] AI-assisted: yes (Claude)
adriadam10 commented 2026-10-11 16:53:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T16:53:39Z.

Review: CHANGES_REQUESTED


Thanks, the layouts match KytyPS5 (Ngs2CustomSamplerRackOption 1304, Ngs2CustomMasteringRackOption 1288, voice states 48/16) and ngs2_custom plus the other Ngs2 tests pass here. A few things before this can merge:

  • Custom.cpp:23-30, Custom.cpp:112-120: built-in modules are accepted, skipped and only logged to stderr. That returns plausible-but-wrong audio where main threw. Please either throw for any built-in module whose behaviour isn't implemented, or show (a test, or a log from the title) that skipping module 0x13 is exact for what the title does with it and limit the skip to exactly that id/controls.
  • tests/Ngs2Custom.cpp:256-257, :275, :294-295: the project doesn't allow code comments (CONTRIBUTING); please remove them.
  • docs/dev/TechnicalDebt.md:241: KytyPS5 doesn't read the 0x40030000 setup param at all (it only checks the rack type), so "as KytyPS5 handles them" is wrong for the mastering setup layout. Please say the custom-submixer layout is an assumption. Since the skip changes behaviour, the line also belongs under "### Functional", not "### Unknown function info".
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5484127842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3793#pullrequestreview-5484127842). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T16:53:39Z. **Review:** CHANGES_REQUESTED --- Thanks, the layouts match KytyPS5 (`Ngs2CustomSamplerRackOption` 1304, `Ngs2CustomMasteringRackOption` 1288, voice states 48/16) and `ngs2_custom` plus the other Ngs2 tests pass here. A few things before this can merge: - `Custom.cpp:23-30`, `Custom.cpp:112-120`: built-in modules are accepted, skipped and only logged to stderr. That returns plausible-but-wrong audio where `main` threw. Please either throw for any built-in module whose behaviour isn't implemented, or show (a test, or a log from the title) that skipping module `0x13` is exact for what the title does with it and limit the skip to exactly that id/controls. - `tests/Ngs2Custom.cpp:256-257`, `:275`, `:294-295`: the project doesn't allow code comments (CONTRIBUTING); please remove them. - `docs/dev/TechnicalDebt.md:241`: KytyPS5 doesn't read the `0x40030000` setup param at all (it only checks the rack type), so "as KytyPS5 handles them" is wrong for the mastering setup layout. Please say the custom-submixer layout is an assumption. Since the skip changes behaviour, the line also belongs under "### Functional", not "### Unknown function info".
xXPBSXx commented 2026-10-11 17:57:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T17:57:48Z.


Windows data point for Dead Cells (PPSA15552) with this PR: Windows 10, MinGW/Ninja Release build of the PR head on top of main a11c8f7f7, relinked from the reconstructed ELF (1 module, 0 absent imports), 60 s run. ctest -R ngs2_custom passes. The title creates its custom sampler rack and then aborts on the next missing call:

what():  sceNgs2GeomResetSourceParam not implemented
FATAL: abort() (SIGABRT)

So on this machine it gets past the rack id and does not reach the voice patch to a rack handle mentioned in the description; the Geom call comes first.

The option block I captured with a local trace before this PR (not committed) agrees with the layout here: rack id 0x4001, option size = 0x518 (1304), name "Default", max_voices = 256, max_ports = 8, max_matrices = 1, state_size = 48, num_buffers = 1, num_modules = 1, and that module has module_id = 0x13, option = nullptr, state_size = 0; the title creates this rack twice. I had a smaller branch for the same rack (xXPBSXx:fix/ngs2-custom-sampler-rack, 58c902fe2: only the rack creation and a test, no voices or rendering). This PR covers it, so I am not opening mine.

What I did not check: audio, the mastering rack, Linux.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111973080 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3793#issuecomment-6111973080). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T17:57:48Z. --- Windows data point for Dead Cells (PPSA15552) with this PR: Windows 10, MinGW/Ninja Release build of the PR head on top of `main` a11c8f7f7, relinked from the reconstructed ELF (1 module, 0 absent imports), 60 s run. `ctest -R ngs2_custom` passes. The title creates its custom sampler rack and then aborts on the next missing call: ``` what(): sceNgs2GeomResetSourceParam not implemented FATAL: abort() (SIGABRT) ``` So on this machine it gets past the rack id and does not reach the voice patch to a rack handle mentioned in the description; the Geom call comes first. The option block I captured with a local trace before this PR (not committed) agrees with the layout here: rack id `0x4001`, option `size = 0x518` (1304), name "Default", `max_voices = 256`, `max_ports = 8`, `max_matrices = 1`, `state_size = 48`, `num_buffers = 1`, `num_modules = 1`, and that module has `module_id = 0x13`, `option = nullptr`, `state_size = 0`; the title creates this rack twice. I had a smaller branch for the same rack (`xXPBSXx:fix/ngs2-custom-sampler-rack`, `58c902fe2`: only the rack creation and a test, no voices or rendering). This PR covers it, so I am not opening mine. What I did not check: audio, the mastering rack, Linux. AI-assisted (Claude Code).
hansjm10 commented 2026-10-11 18:05:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hansjm10 on 2026-10-11T18:05:18Z.


Linux matches @xXPBSXx's data (Debian 12, GCC 14, RADV gfx1036 and llvmpipe, main a11c8f7f7): the same 1304-byte option with the single module 0x13 (no option, no state), sampler limits 256 / 16 / 256 / 256 / 0 / 32, and with a 0x4001 rack the next stop is sceNgs2GeomResetSourceParam not implemented.

Two points for review:

  • Built-in modules: in this title the only built-in module is 0x13, so 0x4001 doesn't need the accept-and-ignore path here. Accepting exactly 0x13 and throwing for other built-in ids and their 0x4000xxxx controls covers PPSA15552 and keeps "exact behaviour or a throw". I have that variant locally (rack creation only, with a test that fails on main); I'm not opening it.
  • Geom and later stops: the next stop is the Geom family from #1021 and #1875, both closed because no title reached them. With #1021 applied locally, the title ran for about 120 s. It sent no 0x4001xxxx voice parameters and made no sceNgs2VoiceGetState call on this rack's voices. It never requested rack 0x4003 either; that build had no 0x4003 and would have thrown. It then stopped on an unrelated shader limit of this GPU (Barycentric geometry SPIR-V: the emulated barycentric inputs exceed 32 locations). So the voice side and the mastering rack are not exercised on Linux yet.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112040714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3793#issuecomment-6112040714). Originally posted by [hansjm10](https://github.com/hansjm10) on 2026-10-11T18:05:18Z. --- Linux matches @xXPBSXx's data (Debian 12, GCC 14, RADV gfx1036 and llvmpipe, `main` a11c8f7f7): the same 1304-byte option with the single module `0x13` (no option, no state), sampler limits 256 / 16 / 256 / 256 / 0 / 32, and with a 0x4001 rack the next stop is `sceNgs2GeomResetSourceParam not implemented`. Two points for review: - **Built-in modules:** in this title the only built-in module is `0x13`, so 0x4001 doesn't need the accept-and-ignore path here. Accepting exactly `0x13` and throwing for other built-in ids and their `0x4000xxxx` controls covers PPSA15552 and keeps "exact behaviour or a throw". I have that variant locally (rack creation only, with a test that fails on `main`); I'm not opening it. - **Geom and later stops:** the next stop is the Geom family from #1021 and #1875, both closed because no title reached them. With #1021 applied locally, the title ran for about 120 s. It sent no `0x4001xxxx` voice parameters and made no `sceNgs2VoiceGetState` call on this rack's voices. It never requested rack `0x4003` either; that build had no 0x4003 and would have thrown. It then stopped on an unrelated shader limit of this GPU (`Barycentric geometry SPIR-V: the emulated barycentric inputs exceed 32 locations`). So the voice side and the mastering rack are not exercised on Linux yet. AI-assisted: yes (Claude Code).
MarcZX10 commented 2026-10-12 01:37:26 +00:00 (Migrated from github.com)

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


I reviewed the ready branch for #3759 against this PR and current main. It overlaps the custom sampler implementation here, so I have not opened a parallel PR.

The useful difference is the built-in module case from Dead Cells: the candidate accepts and skips module 0x13 only on the custom sampler/mastering racks (custom submixer still throws), logs the unimplemented module/control once, keeps the UserFx2 module processing, and has a test that verifies sampler output and UserFx2 gain while a 0x13 module/control is present. This is aimed at the review request to either throw for unsupported built-ins or demonstrate and limit the skip for the title's 0x13 module. It also adds rejection tests for loop/filter/other unsupported parameters, buffer-count bounds, and checks custom sampler voice state.

I rebased the original one-commit branch onto current upstream/main; aside from the TechnicalDebt append it applied unchanged and preserves screamm as commit author. Linux Release validation on GCC 12: all nine ngs2_* CTests pass, including ngs2_custom; conventions and git diff --check pass. The full issue report attributes the rack layout to KytyPS5 and shadPS4, but the sampler behavior itself is still not console-verified.

If this follow-up is useful, the branch is MarcZX100:codex/carry-ngs2-custom-sampler-3759 (commit 99ff1fa6b). It is currently not pushed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116211780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3793#issuecomment-6116211780). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T01:37:26Z. --- I reviewed the ready branch for #3759 against this PR and current `main`. It overlaps the custom sampler implementation here, so I have not opened a parallel PR. The useful difference is the built-in module case from Dead Cells: the candidate accepts and skips module `0x13` only on the custom sampler/mastering racks (custom submixer still throws), logs the unimplemented module/control once, keeps the UserFx2 module processing, and has a test that verifies sampler output and UserFx2 gain while a `0x13` module/control is present. This is aimed at the review request to either throw for unsupported built-ins or demonstrate and limit the skip for the title's `0x13` module. It also adds rejection tests for loop/filter/other unsupported parameters, buffer-count bounds, and checks custom sampler voice state. I rebased the original one-commit branch onto current `upstream/main`; aside from the TechnicalDebt append it applied unchanged and preserves screamm as commit author. Linux Release validation on GCC 12: all nine `ngs2_*` CTests pass, including `ngs2_custom`; conventions and `git diff --check` pass. The full issue report attributes the rack layout to KytyPS5 and shadPS4, but the sampler behavior itself is still not console-verified. If this follow-up is useful, the branch is `MarcZX100:codex/carry-ngs2-custom-sampler-3759` (commit `99ff1fa6b`). It is currently not pushed.
oneandonlydean commented 2026-10-13 07:46:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T07:46:34Z.


Closing in favour of #4417: the points from 10-11 are still open (built-in modules accepted and skipped, 0x40001300 ignored), and #4417 implements module 0x13 instead of skipping it. No title requests rack 0x4003 yet. Thanks, the run in #4334 on this branch is what showed the remaining stops. If you decide to continue, please reopen.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140846340 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3793#issuecomment-6140846340). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T07:46:34Z. --- Closing in favour of #4417: the points from 10-11 are still open (built-in modules accepted and skipped, `0x40001300` ignored), and #4417 implements module `0x13` instead of skipping it. No title requests rack `0x4003` yet. Thanks, the run in #4334 on this branch is what showed the remaining stops. If you decide to continue, please reopen.

Pull request closed

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!3793
No description provided.