Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
mohammad-alosta:fix/libSceNgs2-listener-transform
Oct 15, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
mohammad-alosta:fix/libSceNgs2-listener-transform

Conversation

@mohammad-alosta

Copy link
Copy Markdown
Contributor

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

@orishamir

Copy link
Copy Markdown
Contributor

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

  • 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)

mohammad-alosta added a commit to mohammad-alosta/AnyPS5 that referenced this pull request Oct 14, 2026
Allow custom voice filter type 0 to clear the destination filter,
matching the sampler filter convention. Type 1 continues to configure
the biquad frequency, Q and level. Other unsupported filter types
still throw.

This follows the listener-transform support in
fix/libSceNgs2-listener-transform and is needed for Dead Cells
(PPSA15552), which reaches this path after the custom sampler rack.

Depends on: fix(libSceNgs2): support listener transforms in sceNgs2GeomCalcListener- boykopovar#5810
Unblocks: PPSA15552
AI assistance: yes
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

@adriadam10 adriadam10 self-assigned this Oct 15, 2026
mohammad-alosta and others added 2 commits October 15, 2026 15:03
Restore world-to-listener matrix construction instead of rejecting
non-default orientation, translation or flags.

- Build an orthonormal row-major matrix from position, orient_front
  and orient_up; apply the right-handed axis flip for flag 1.
- Store the negated dotted translation in each matrix row.
- Validate unknown flags, invalid or non-finite input, short
  orientation axes, and unrepresentable translation without changing
  the output.
- Preserve finite velocity and positive finite sound speed.
- Update NGS2 geometry tests and the libSceNgs2 technical debt note.

AI assistance: yes
…ntation handling as implemented

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 force-pushed the fix/libSceNgs2-listener-transform branch from 3918d43 to 2f25a54 Compare October 15, 2026 13:04
@Matheuswells

Copy link
Copy Markdown

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.

@adriadam10
adriadam10 merged commit dee15e2 into boykopovar:main Oct 15, 2026
8 checks passed
mohammad-alosta added a commit to mohammad-alosta/AnyPS5 that referenced this pull request Oct 15, 2026
Allow custom voice filter type 0 to clear the destination filter,
matching the sampler filter convention. Type 1 continues to configure
the biquad frequency, Q and level. Other unsupported filter types
still throw.

This follows the listener-transform support in
fix/libSceNgs2-listener-transform and is needed for Dead Cells
(PPSA15552), which reaches this path after the custom sampler rack.

Depends on: fix(libSceNgs2): support listener transforms in sceNgs2GeomCalcListener- boykopovar#5810
Unblocks: PPSA15552
AI assistance: yes
mohammad-alosta added a commit to mohammad-alosta/AnyPS5 that referenced this pull request Oct 15, 2026
Allow custom voice filter type 0 to clear the destination filter,
matching the sampler filter convention. Type 1 continues to configure
the biquad frequency, Q and level. Other unsupported filter types
still throw.

This follows the listener-transform support in
fix/libSceNgs2-listener-transform and is needed for Dead Cells
(PPSA15552), which reaches this path after the custom sampler rack.

Depends on: fix(libSceNgs2): support listener transforms in sceNgs2GeomCalcListener- boykopovar#5810
Unblocks: PPSA15552
AI assistance: yes
adriadam10 pushed a commit to mohammad-alosta/AnyPS5 that referenced this pull request Oct 16, 2026
Allow custom voice filter type 0 to clear the destination filter,
matching the sampler filter convention. Type 1 continues to configure
the biquad frequency, Q and level. Other unsupported filter types
still throw.

This follows the listener-transform support in
fix/libSceNgs2-listener-transform and is needed for Dead Cells
(PPSA15552), which reaches this path after the custom sampler rack.

Depends on: fix(libSceNgs2): support listener transforms in sceNgs2GeomCalcListener- boykopovar#5810
Unblocks: PPSA15552
AI assistance: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants