feat(libSceNgs2): implement the Geom family #1021

Closed
Dextroid17 wants to merge 1 commit from upstream-pr/1021 into main
Dextroid17 commented 2026-10-07 00:41:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-07T00:41:05Z.


What this does

Implements the four sceNgs2Geom* exports, which are the whole Geom (3D listener/source
geometry) family of libSceNgs2.native. All four called NotImplemented_nid_no_patch, so
any title that used them terminated.

Function Before After
sceNgs2GeomResetListenerParam throws fills the listener defaults
sceNgs2GeomResetSourceParam throws fills the source defaults
sceNgs2GeomCalcListener throws identity matrix, velocity and sound speed
sceNgs2GeomApply throws pitch ratio, position, volume and the level diagonal

Also fixes the structures those exports take. They were opaque reserved[] placeholders
and the wrong size: Ngs2GeomAttribute held 128 bytes where the real structure is 308,
and Ngs2GeomListenerParam 128 where it is 60. They now carry the real fields with the size
asserted next to each one, as the rest of the header does.

Where the behaviour comes from

KytyPS5's src/libs/ngs2.cpp is the only source that
implements them. shadPS4's ngs2_geom.h confirms
the structures field for field, but its four implementations only log and return success
without writing the output — so a title would read back whatever it left in its buffer.
KytyPS5 is already the reference this project cites for NGS2 (the sampler filter and the
custom rack), so it is the source used here.

The port is value for value: the reset defaults, the identity matrix, 343 when the param
carries no sound speed, flags & 1 for the coordinate, std::max(min_level, max_level) for
the volume, and the level diagonal at max_level (or 1 when it is zero) for matrix_format
channels (2 when it is zero, clamped to the eight the level matrix holds).

Two deliberate divergences from KytyPS5, both noted for the reviewer:

  • A null output address returns INVALID_OUT_ADDRESS instead of throwing, matching how
    the rest of libSceNgs2.native signals it (Atrac9.cpp), and a null input throws.
  • sceNgs2GeomApply ignores the listener work, as KytyPS5 does — the source is not placed
    relative to the listener. That is recorded as technical debt rather than invented.

Verification

  • ./build/tests/ngs2_geom_tests passes, and the full suite is green.
  • The test covers the reset defaults (including that they overwrite a 0x5a buffer), the
    identity matrix and the velocity/sound speed copy, the coordinate flag, the volume, the
    level diagonal for matrix_format 0 / 2 / 8 / 99, and the null-argument paths.
  • The test has teeth: changing a single documented default (orient_front.z to 0.5)
    aborts it, and dropping the reference's listener == nullptr check aborted it during
    development — it caught that omission.
  • static_asserts fix the eight structure sizes at compile time, and nm -D shows all four
    symbols exported from libSceNgs2.native.prx.

Caveats

  • The values follow KytyPS5 only and are unverified on a PS5 title; there is no
    hardware oracle for them. Recorded in docs/dev/TechnicalDebt.md.
  • One thing worth knowing for anyone writing a similar test: the clamp on the channel count
    is not observable from the output, because GCC proves the out-of-range iterations are
    undefined behaviour and deletes them. The assertion on the surrounding fields documents the
    contract but will not catch its removal on this toolchain.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4766338101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1021). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-07T00:41:05Z. --- ## What this does Implements the four `sceNgs2Geom*` exports, which are the whole Geom (3D listener/source geometry) family of `libSceNgs2.native`. All four called `NotImplemented_nid_no_patch`, so any title that used them terminated. | Function | Before | After | | --- | --- | --- | | `sceNgs2GeomResetListenerParam` | throws | fills the listener defaults | | `sceNgs2GeomResetSourceParam` | throws | fills the source defaults | | `sceNgs2GeomCalcListener` | throws | identity matrix, velocity and sound speed | | `sceNgs2GeomApply` | throws | pitch ratio, position, volume and the level diagonal | Also fixes the structures those exports take. They were opaque `reserved[]` placeholders **and the wrong size**: `Ngs2GeomAttribute` held 128 bytes where the real structure is 308, and `Ngs2GeomListenerParam` 128 where it is 60. They now carry the real fields with the size asserted next to each one, as the rest of the header does. ## Where the behaviour comes from [KytyPS5](https://github.com/KytyPS5/KytyPS5)'s `src/libs/ngs2.cpp` is the only source that implements them. [shadPS4](https://github.com/shadps4-emu/shadPS4)'s `ngs2_geom.h` confirms the structures **field for field**, but its four implementations only log and return success **without writing the output** — so a title would read back whatever it left in its buffer. KytyPS5 is already the reference this project cites for NGS2 (the sampler filter and the custom rack), so it is the source used here. The port is value for value: the reset defaults, the identity matrix, `343` when the param carries no sound speed, `flags & 1` for the coordinate, `std::max(min_level, max_level)` for the volume, and the level diagonal at `max_level` (or `1` when it is zero) for `matrix_format` channels (`2` when it is zero, clamped to the eight the level matrix holds). Two deliberate divergences from KytyPS5, both noted for the reviewer: - **A null output address returns `INVALID_OUT_ADDRESS`** instead of throwing, matching how the rest of `libSceNgs2.native` signals it (`Atrac9.cpp`), and a null input throws. - **`sceNgs2GeomApply` ignores the listener work**, as KytyPS5 does — the source is not placed relative to the listener. That is recorded as technical debt rather than invented. ## Verification - `./build/tests/ngs2_geom_tests` passes, and the full suite is green. - The test covers the reset defaults (including that they overwrite a 0x5a buffer), the identity matrix and the velocity/sound speed copy, the coordinate flag, the volume, the level diagonal for `matrix_format` 0 / 2 / 8 / 99, and the null-argument paths. - The test has teeth: changing a single documented default (`orient_front.z` to `0.5`) aborts it, and dropping the reference's `listener == nullptr` check aborted it during development — it caught that omission. - `static_assert`s fix the eight structure sizes at compile time, and `nm -D` shows all four symbols exported from `libSceNgs2.native.prx`. ## Caveats - The values follow **KytyPS5 only** and are **unverified on a PS5 title**; there is no hardware oracle for them. Recorded in `docs/dev/TechnicalDebt.md`. - One thing worth knowing for anyone writing a similar test: the clamp on the channel count is **not** observable from the output, because GCC proves the out-of-range iterations are undefined behaviour and deletes them. The assertion on the surrounding fields documents the contract but will not catch its removal on this toolchain.
github-actions[bot] commented 2026-10-07 00:41:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T00:41:30Z.


Progress report (ee391a5 → 941344f)

📈 System libraries: 86.76% (+0.14%, +4 implemented functions)

✅ 4 implemented
Library Name
libSceNgs2.native sceNgs2GeomApply
libSceNgs2.native sceNgs2GeomCalcListener
libSceNgs2.native sceNgs2GeomResetListenerParam
libSceNgs2.native sceNgs2GeomResetSourceParam
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6028288455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1021#issuecomment-6028288455). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T00:41:30Z. --- <!-- progress-report --> ### Progress report (ee391a5 → 941344f) 📈 **System libraries**: 86.76% (+0.14%, +4 implemented functions) <details> <summary>✅ 4 implemented</summary> | Library | Name | | - | - | | libSceNgs2.native | `sceNgs2GeomApply` | | libSceNgs2.native | `sceNgs2GeomCalcListener` | | libSceNgs2.native | `sceNgs2GeomResetListenerParam` | | libSceNgs2.native | `sceNgs2GeomResetSourceParam` | </details>
github-actions[bot] commented 2026-10-07 00:43:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T00:43:29Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#946 docs/dev/TechnicalDebt.md L163
#959 core/libs/prx/libSceNgs2.native/CMakeLists.txt L3
core/libs/prx/libSceNgs2.native/src/Unimplemented.cpp L11-58
#962 core/libs/prx/libSceNgs2.native/CMakeLists.txt L1-20
#1018 docs/dev/TechnicalDebt.md L163
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6028317416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1021#issuecomment-6028317416). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T00:43:29Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #946 | `docs/dev/TechnicalDebt.md` [L163](https://github.com/boykopovar/AnyPS5/blob/ee391a5614246338aec9cb7a3a3dd4f479aec9f3/docs/dev/TechnicalDebt.md#L163) | | | | #959 | `core/libs/prx/libSceNgs2.native/CMakeLists.txt` [L3](https://github.com/boykopovar/AnyPS5/blob/ee391a5614246338aec9cb7a3a3dd4f479aec9f3/core/libs/prx/libSceNgs2.native/CMakeLists.txt#L3)<br>`core/libs/prx/libSceNgs2.native/src/Unimplemented.cpp` [L11-58](https://github.com/boykopovar/AnyPS5/blob/ee391a5614246338aec9cb7a3a3dd4f479aec9f3/core/libs/prx/libSceNgs2.native/src/Unimplemented.cpp#L11-L58) | | | | #962 | `core/libs/prx/libSceNgs2.native/CMakeLists.txt` [L1-20](https://github.com/boykopovar/AnyPS5/blob/ee391a5614246338aec9cb7a3a3dd4f479aec9f3/core/libs/prx/libSceNgs2.native/CMakeLists.txt#L1-L20) | | | | #1018 | `docs/dev/TechnicalDebt.md` [L163](https://github.com/boykopovar/AnyPS5/blob/ee391a5614246338aec9cb7a3a3dd4f479aec9f3/docs/dev/TechnicalDebt.md#L163) | | |
oneandonlydean commented 2026-10-07 01:48:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T01:48:02Z.


Thanks for the careful write-up, and for checking the structure sizes against two sources.

I'm closing this one for now, for two reasons:

  • No title is named. The owner has asked us to merge only changes a title needs, and today a title that uses the Geom family stops at a clear NotImplemented with the function name.
  • sceNgs2GeomApply returns success without placing the source relative to the listener, so a title that uses 3D sound would get a plausible but wrong mix and no error. The project's rule is that a function does exactly what it should or throws, and that's harder to keep when the only reference (KytyPS5) is itself a placeholder. The reset functions alone would be easier to justify, but they still need a title.

If a title stops at one of these calls on main, please reopen it (or open a new PR) with the title ID and the log line. If that title only needs the reset functions, or only reads the defaults back, a smaller PR with just those, and Apply left throwing, would be the easiest to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6029133497 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1021#issuecomment-6029133497). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T01:48:02Z. --- Thanks for the careful write-up, and for checking the structure sizes against two sources. I'm closing this one for now, for two reasons: - No title is named. The owner has asked us to merge only changes a title needs, and today a title that uses the Geom family stops at a clear `NotImplemented` with the function name. - `sceNgs2GeomApply` returns success without placing the source relative to the listener, so a title that uses 3D sound would get a plausible but wrong mix and no error. The project's rule is that a function does exactly what it should or throws, and that's harder to keep when the only reference (KytyPS5) is itself a placeholder. The reset functions alone would be easier to justify, but they still need a title. If a title stops at one of these calls on main, please reopen it (or open a new PR) with the title ID and the log line. If that title only needs the reset functions, or only reads the defaults back, a smaller PR with just those, and `Apply` left throwing, would be the easiest to merge.
xXPBSXx commented 2026-10-11 17:59:56 +00:00 (Migrated from github.com)

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


A title for this, as asked in the closing comment: Dead Cells (PPSA15552). On main it first stops on the custom sampler rack id (#3553, #3793); with #3793's head on top of main a11c8f7f7 (Windows, 60 s) it creates its racks and then aborts with

what():  sceNgs2GeomResetSourceParam not implemented

so the reset call comes before any voice parameter. I have not seen it call the other three Geom functions yet, because it stops here first.

On the sources for the defaults, since the reset values are what the title would read back:

  • KytyPS5 (Ngs2GeomResetSourceParam) and iStark/PS5PCEM (src/hle/ngs2_geom.zig, resetSource) agree on every field: direction (0,0,1), cone levels 1 and angles 360, rolloff model 0 with max distance 1000000, factor 1, reference distance 1, Doppler factor 1, levels fbw 1, lfe 1, max 1, min 0, num_speakers 2. They differ on matrix_format: 2 in KytyPS5, 1 in PS5PCEM. Listener reset: front (0,0,1), up (0,1,0), sound speed 343 in both.
  • shadPS4 only logs and returns success without writing, as #1021 says; mattias800/prosper's hle_audio.cpp zero-fills 0xa8 bytes for the source and 0xa0 for the listener, which does not match the 308-byte attribute and 60-byte listener sizes this PR used, so I would not take sizes from it.
  • None of these is a measurement on a console, so matrix_format (and the sizes) remain unconfirmed. A reset-only PR as suggested would have to take a side on matrix_format, or throw for that field's case; I am not opening one until there is a measurement or the title shows which value it reads.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111991563 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1021#issuecomment-6111991563). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T17:59:56Z. --- A title for this, as asked in the closing comment: Dead Cells (PPSA15552). On `main` it first stops on the custom sampler rack id (#3553, #3793); with #3793's head on top of `main` a11c8f7f7 (Windows, 60 s) it creates its racks and then aborts with ``` what(): sceNgs2GeomResetSourceParam not implemented ``` so the reset call comes before any voice parameter. I have not seen it call the other three Geom functions yet, because it stops here first. On the sources for the defaults, since the reset values are what the title would read back: - KytyPS5 (`Ngs2GeomResetSourceParam`) and iStark/PS5PCEM (`src/hle/ngs2_geom.zig`, `resetSource`) agree on every field: direction `(0,0,1)`, cone levels 1 and angles 360, rolloff model 0 with max distance 1000000, factor 1, reference distance 1, Doppler factor 1, levels `fbw 1`, `lfe 1`, `max 1`, `min 0`, `num_speakers 2`. They differ on `matrix_format`: 2 in KytyPS5, 1 in PS5PCEM. Listener reset: front `(0,0,1)`, up `(0,1,0)`, sound speed 343 in both. - shadPS4 only logs and returns success without writing, as #1021 says; mattias800/prosper's `hle_audio.cpp` zero-fills 0xa8 bytes for the source and 0xa0 for the listener, which does not match the 308-byte attribute and 60-byte listener sizes this PR used, so I would not take sizes from it. - None of these is a measurement on a console, so `matrix_format` (and the sizes) remain unconfirmed. A reset-only PR as suggested would have to take a side on `matrix_format`, or throw for that field's case; I am not opening one until there is a measurement or the title shows which value it reads. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-11 21:16:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T21:16:35Z.


This can be reopened once #3793 is in and Dead Cells (PPSA15552) reaches sceNgs2GeomResetSourceParam on main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113850216 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1021#issuecomment-6113850216). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T21:16:35Z. --- This can be reopened once #3793 is in and Dead Cells (PPSA15552) reaches `sceNgs2GeomResetSourceParam` on main.

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