fix(libSceNgs2): support listener transforms in sceNgs2GeomCalcListener #5810

Merged
mohammad-alosta merged 2 commits from upstream-pr/5810 into main 2026-10-15 18:34:08 +00:00
mohammad-alosta commented 2026-10-14 11:54:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mohammad-alosta on 2026-10-14T11:54:36Z.


What

Restore world-to-listener matrix construction in sceNgs2GeomCalcListener (core/libs/prx/libSceNgs2.native/src/Geom.cpp). The previous implementation rejected non-default listener orientation, listener translation, and listener coordinate flags. That rejection stopped Dead Cells (PPSA15552) after its custom sampler rack startup because the title uses a non-default listener orientation.

This change computes an orthonormal row-major world-to-listener matrix from position, orient_front and orient_up, applies the right-handed axis flip for flag 1, stores translation in the matrix, and preserves finite velocity and positive finite sound speed. Unknown flags, invalid or non-finite input, non-unit orientation axes, and unrepresentable translation still throw without changing the output. Source attenuation, panning and Doppler in sceNgs2GeomApply remain unimplemented.

Updated docs/dev/debt/libSceNgs2.native.md and core/libs/prx/libSceNgs2.native/tests/Ngs2Geom.cpp to match the restored behavior.

Tested

  • Linux
  • cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
  • cmake --build build --target ngs2_geom_tests
  • ctest --test-dir build -R '^ngs2_geom$' --output-on-failure
  • Result: Test #760: ngs2_geom passed (100% tests passed, 0 failures)
  • Tested behavior: non-default listener orientation and translation produce the expected transform; invalid flags, orientation, finite input and unrepresentable translation remain rejected.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA15552 Dead Cells
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4857463476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5810). Originally posted by [mohammad-alosta](https://github.com/mohammad-alosta) on 2026-10-14T11:54:36Z. --- ### What Restore world-to-listener matrix construction in `sceNgs2GeomCalcListener` (`core/libs/prx/libSceNgs2.native/src/Geom.cpp`). The previous implementation rejected non-default listener orientation, listener translation, and listener coordinate flags. That rejection stopped Dead Cells (PPSA15552) after its custom sampler rack startup because the title uses a non-default listener orientation. This change computes an orthonormal row-major world-to-listener matrix from `position`, `orient_front` and `orient_up`, applies the right-handed axis flip for flag 1, stores translation in the matrix, and preserves finite velocity and positive finite sound speed. Unknown flags, invalid or non-finite input, non-unit orientation axes, and unrepresentable translation still throw without changing the output. Source attenuation, panning and Doppler in `sceNgs2GeomApply` remain unimplemented. Updated `docs/dev/debt/libSceNgs2.native.md` and `core/libs/prx/libSceNgs2.native/tests/Ngs2Geom.cpp` to match the restored behavior. ### Tested - Linux - `cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON` - `cmake --build build --target ngs2_geom_tests` - `ctest --test-dir build -R '^ngs2_geom$' --output-on-failure` - Result: `Test #760: ngs2_geom` passed (`100% tests passed, 0 failures`) - Tested behavior: non-default listener orientation and translation produce the expected transform; invalid flags, orientation, finite input and unrepresentable translation remain rejected. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA15552 Dead Cells - [x] GPUs tested: n/a - [x] AI-assisted: yes
orishamir commented 2026-10-14 13:56:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-14T13:56:41Z.


Windows run: Windows 11, WinLibs GCC 15.2.0 r7, Release, this head (3918d43f0) merged onto main 28b6f1987.

  • ngs2_geom passes 5 of 5, and the full ctest has 0 failures out of 1184.
  • With only core/libs/prx/libSceNgs2.native/src/Geom.cpp taken back to main, ngs2_geom fails with NGS2: listener translation is unsupported.

AI-assisted: yes (Claude Code Opus 5.5)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6170059946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5810#issuecomment-6170059946). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-14T13:56:41Z. --- Windows run: Windows 11, WinLibs GCC 15.2.0 r7, Release, this head (3918d43f0) merged onto `main` 28b6f1987. - `ngs2_geom` passes 5 of 5, and the full `ctest` has 0 failures out of 1184. - With only `core/libs/prx/libSceNgs2.native/src/Geom.cpp` taken back to `main`, `ngs2_geom` fails with `NGS2: listener translation is unsupported`. AI-assisted: yes (Claude Code Opus 5.5)
github-actions[bot] commented 2026-10-15 12:09:52 +00:00 (Migrated from github.com)

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


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
PR 6447 core/libs/prx/libSceNgs2.native/src/Geom.cpp L1-2, L7-8
docs/dev/debt/libSceNgs2.native.md L27-28

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 5797 docs/dev/debt/libSceNgs2.native.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191708708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5810#issuecomment-6191708708). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:09:52Z. --- <!-- 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 | |---|---|---|---| | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libSceNgs2.native/src/Geom.cpp` [L1-2](https://github.com/boykopovar/AnyPS5/blob/0029e62f974c453a5f6c7333f3bdb13e770e3903/core/libs/prx/libSceNgs2.native/src/Geom.cpp#L1-L2), [L7-8](https://github.com/boykopovar/AnyPS5/blob/0029e62f974c453a5f6c7333f3bdb13e770e3903/core/libs/prx/libSceNgs2.native/src/Geom.cpp#L7-L8)<br>`docs/dev/debt/libSceNgs2.native.md` [L27-28](https://github.com/boykopovar/AnyPS5/blob/0029e62f974c453a5f6c7333f3bdb13e770e3903/docs/dev/debt/libSceNgs2.native.md#L27-L28) | | | 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 5797](https://www.github.com/boykopovar/AnyPS5/pull/5797) | `docs/dev/debt/libSceNgs2.native.md` |
adriadam10 commented 2026-10-15 13:04:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:04:57Z.


Checked the transform against PS5PCEM's calcListener (rows right/up/front, translation -dot(axis, position), flag 1 = right-handed) and ran ngs2_geom with and without the Geom.cpp change (it fails without). Thanks to @orishamir for the Windows run.

Pushed one docs-only commit on top (docs/dev/debt/libSceNgs2.native.md):

  • The PS5PCEM link pointed at a .md that doesn't exist at that SHA; it now points to src/hle/ngs2_geom.zig.
  • The entry (and the PR body) said non-unit orientation vectors throw; the code normalises them and makes up perpendicular to front, so it now says that.
  • Added that a non-positive sound_speed throws where PS5PCEM and KytyPS5 default it to 343, and that KytyPS5 only ever writes the identity, so the matrix convention rests on PS5PCEM alone.

Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6192750032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5810#issuecomment-6192750032). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:04:57Z. --- Checked the transform against PS5PCEM's `calcListener` (rows right/up/front, translation `-dot(axis, position)`, flag 1 = right-handed) and ran `ngs2_geom` with and without the `Geom.cpp` change (it fails without). Thanks to @orishamir for the Windows run. Pushed one docs-only commit on top (`docs/dev/debt/libSceNgs2.native.md`): - The PS5PCEM link pointed at a `.md` that doesn't exist at that SHA; it now points to `src/hle/ngs2_geom.zig`. - The entry (and the PR body) said non-unit orientation vectors throw; the code normalises them and makes up perpendicular to front, so it now says that. - Added that a non-positive `sound_speed` throws where PS5PCEM and KytyPS5 default it to 343, and that KytyPS5 only ever writes the identity, so the matrix convention rests on PS5PCEM alone. Merging once CI is green.
Matheuswells commented 2026-10-15 18:25:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Matheuswells on 2026-10-15T18:25:28Z.


I tested this PR's sceNgs2GeomCalcListener with Dead Cells (PPSA15552), combined with a local sceNgs2GeomApply and filter type 0 support so the game would reach it. The only change to this PR's code was a debug print of the arguments.

Test environment:

  • OS: Windows 11 Pro, build 10.0.26200
  • CPU: Intel Core i5-13450HX (10 cores, 16 threads), Intel host
  • RAM: 24 GB
  • GPU used by the game: NVIDIA GeForce RTX 3050 6GB Laptop GPU (Windows driver version 32.0.16.1742); the Intel UHD Graphics iGPU was also present
  • Toolchain: WinLibs GCC 15.2.0 r7, Release build

Dead Cells aborts after 2,682 listener calls:

[LISTENERDBG] flags=0 pos=-56.5,96,16 front=0,0,1 up=0,-0,1
terminate called after throwing an instance of 'std::invalid_argument'
  what():  Unit: invalid argument

Front and up are parallel on that call, so their cross product is zero and Unit(...) throws.

Over a separate run of about 60 s, the listener calls (about 3,700) were almost all flags 0 with distinct vectors:

  • front (1, 0, 0), up (0, 0, 1), position at the origin: about 2,700 calls
  • front (0, 0, 1), up (0, 1, 0), translated position (for example (-56.5, 94.75, 16)): about 960 calls
  • front (1, 0, 0), up (0, 1, 0): once
  • front (0, 0, 1), up (0, 0, 1): once (the parallel case)

When I replaced up with a perpendicular reference in the parallel case (up = +Y, or +Z when front is closer to the Y axis), the game did not crash. Whether the console does the same is unknown, so it would need a documented assumption in the debt entry.

For reference, the fallback adapted to this PR's helpers (my tested version used different helper names; this form compiles standalone and gives the expected axes for the cases above):

Vector Cross(const Vector& left, const Vector& right) {
    return {left[1] * right[2] - left[2] * right[1], left[2] * right[0] - left[0] * right[2], left[0] * right[1] - left[1] * right[0]};
}

// in Ngs2GeomCalcListener, replacing the right/up computation:
const Vector front = Unit(ReadVector(param->orient_front));
Vector up = Unit(ReadVector(param->orient_up));
Vector right = Cross(up, front);
if (!(std::hypot(right[0], right[1], right[2]) > 1e-6)) {
    up = std::abs(front[1]) < 0.5 ? Vector{0.0, 1.0, 0.0} : Vector{0.0, 0.0, 1.0};
    right = Cross(up, front);
}
right = Unit(right);
up = Cross(front, right);
if (flags == 1) for (auto& component : right) component = -component;

Results of that snippet for the cases above (front, up → right, up, front):

(0,0,1), (0,0,1)   -> right (1,0,0),  up (0,1,0), front (0,0,1)    identity
(0,0,1), (0,0,-1)  -> right (1,0,0),  up (0,1,0), front (0,0,1)
(0,1,0), (0,1,0)   -> right (-1,0,0), up (0,0,1), front (0,1,0)
(1,0,0), (0,0,1)   -> right (0,1,0),  up (0,0,1), front (1,0,0)    Dead Cells' common case
(0,0,1), (0,1,0)   -> right (1,0,0),  up (0,1,0), front (0,0,1)    default

Two smaller points: the tests dropped the exhaustive non-finite checks and the default-listener -0.0 case, and ReadVector(param->velocity); is called only for its validation.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6199289009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5810#issuecomment-6199289009). Originally posted by [Matheuswells](https://github.com/Matheuswells) on 2026-10-15T18:25:28Z. --- I tested this PR's `sceNgs2GeomCalcListener` with Dead Cells (PPSA15552), combined with a local `sceNgs2GeomApply` and filter type 0 support so the game would reach it. The only change to this PR's code was a debug print of the arguments. Test environment: - OS: Windows 11 Pro, build 10.0.26200 - CPU: Intel Core i5-13450HX (10 cores, 16 threads), Intel host - RAM: 24 GB - GPU used by the game: NVIDIA GeForce RTX 3050 6GB Laptop GPU (Windows driver version 32.0.16.1742); the Intel UHD Graphics iGPU was also present - Toolchain: WinLibs GCC 15.2.0 r7, Release build Dead Cells aborts after 2,682 listener calls: ``` [LISTENERDBG] flags=0 pos=-56.5,96,16 front=0,0,1 up=0,-0,1 terminate called after throwing an instance of 'std::invalid_argument' what(): Unit: invalid argument ``` Front and up are parallel on that call, so their cross product is zero and `Unit(...)` throws. Over a separate run of about 60 s, the listener calls (about 3,700) were almost all flags 0 with distinct vectors: - front (1, 0, 0), up (0, 0, 1), position at the origin: about 2,700 calls - front (0, 0, 1), up (0, 1, 0), translated position (for example (-56.5, 94.75, 16)): about 960 calls - front (1, 0, 0), up (0, 1, 0): once - front (0, 0, 1), up (0, 0, 1): once (the parallel case) When I replaced up with a perpendicular reference in the parallel case (up = +Y, or +Z when front is closer to the Y axis), the game did not crash. Whether the console does the same is unknown, so it would need a documented assumption in the debt entry. For reference, the fallback adapted to this PR's helpers (my tested version used different helper names; this form compiles standalone and gives the expected axes for the cases above): ```cpp Vector Cross(const Vector& left, const Vector& right) { return {left[1] * right[2] - left[2] * right[1], left[2] * right[0] - left[0] * right[2], left[0] * right[1] - left[1] * right[0]}; } // in Ngs2GeomCalcListener, replacing the right/up computation: const Vector front = Unit(ReadVector(param->orient_front)); Vector up = Unit(ReadVector(param->orient_up)); Vector right = Cross(up, front); if (!(std::hypot(right[0], right[1], right[2]) > 1e-6)) { up = std::abs(front[1]) < 0.5 ? Vector{0.0, 1.0, 0.0} : Vector{0.0, 0.0, 1.0}; right = Cross(up, front); } right = Unit(right); up = Cross(front, right); if (flags == 1) for (auto& component : right) component = -component; ``` Results of that snippet for the cases above (front, up → right, up, front): ``` (0,0,1), (0,0,1) -> right (1,0,0), up (0,1,0), front (0,0,1) identity (0,0,1), (0,0,-1) -> right (1,0,0), up (0,1,0), front (0,0,1) (0,1,0), (0,1,0) -> right (-1,0,0), up (0,0,1), front (0,1,0) (1,0,0), (0,0,1) -> right (0,1,0), up (0,0,1), front (1,0,0) Dead Cells' common case (0,0,1), (0,1,0) -> right (1,0,0), up (0,1,0), front (0,0,1) default ``` Two smaller points: the tests dropped the exhaustive non-finite checks and the default-listener `-0.0` case, and `ReadVector(param->velocity);` is called only for its validation. AI-assisted: yes.
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!5810
No description provided.