Repository navigation
fix(ngs2): buffer voice setups, waveform blocks and patches sent during processing - #12995
Conversation
|
@hugodearaujo thanks, this removes the abort the title was hitting and the buffered setups and patches read well. Four points need work before it can land, all in the new buffered path:
The new title sequence and ordering tests look right; these four need their own cases. |
|
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.
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.
|
Capture no longer reads the block deque that render jobs pop: the voice publishes its queued block count (atomically, also from Ngs2FinishBlock), the tail of its last block and, for capture during jobs, the decode state at the start of the grain; PLAY only follows the buffered setups' channel count. Buffered blocks and setups now run the immediate path's checks against the queued state (block fit, append with nothing pending or a partial frame, dataless silence blocks on non-I16 voices, ATRAC9 config match), so bad input still fails in sceNgs2VoiceControl. If a control still throws when applied, it and the controls before it are dropped instead of being re-applied on every later render. The port query follows the empty sampler setup rule, and pending patches whose destination rack is destroyed are applied as disconnected ports.
|
@oneandonlydean thanks for the careful read. All four are addressed in 8ba88e6, on top of 2c87f46:
Each new scenario fails at 2c87f46 (the race one under TSan). |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — new head, changes requested
The latest head addresses the reported runtime issues, but it still has unresolved merge conflicts with seven open NGS2 PRs and declares no dependency, contrary to the repository overlap rule.
What I ran
Head tested: 8ba88e61f7bf74a6c6168abfce153345fac347e0; base: main at d820fef1827f27247cd28da7b4eec7891904bae5. The merge preview against current main is clean (8b8301dedb946ec3ea928fd480b5b12ffce45f7e). Environment: Linux x86_64; no compiler/build was run.
git diff --check upstream/main...refs/review/pr-12995-head
python3 tools/check_conventions.py --base upstream/main
git merge-tree --write-tree upstream/main refs/review/pr-12995-head
for pr in 1384 5548 9149 10599 11388 12107 12673; do git merge-tree --write-tree refs/review/pr-12995-head "refs/review/pr-${pr}-head"; doneResults
| Check | Result |
|---|---|
| Diff whitespace check | Pass; no output. |
| Repository conventions | Pass; command exited successfully. |
Merge preview against current main |
Clean. |
| Pairwise merge previews | Conflicts with #1384, #5548, #9149, #10599, #11388, #12107, and #12673. |
| Hosted CI | Windows product job passed; Linux and specialized jobs were skipped. |
| Focused Linux/TSan/runtime tests | Reported by the PR author; not independently run in this review. |
Raw merge-preview conflict output
#1384: CONFLICT in Ngs2 CMakeLists.txt, Ngs2Library.cmake, Ngs2Types.hpp,
Ngs2Internal.hpp, Rack.cpp, Render.cpp, Reverb.cpp, Voice.cpp,
libSceNgs2 CMakeLists.txt, docs/dev/TechnicalDebt.md
#5548: CONFLICT in Ngs2 CMakeLists.txt, Ngs2Internal.hpp, Render.cpp,
tests/Ngs2Pcm.cpp, libSceNgs2 CMakeLists.txt
#9149: CONFLICT in tests/Ngs2Parse.cpp and docs/dev/debt/libSceNgs2.native.md
#10599: CONFLICT in Ngs2 CMakeLists.txt, Custom.cpp, Voice.cpp,
docs/dev/debt/libSceNgs2.native.md
#11388: CONFLICT in Ngs2 CMakeLists.txt, Ngs2Library.cmake, Ngs2Internal.hpp,
Render.cpp, Voice.cpp
#12107: CONFLICT in docs/dev/debt/libSceNgs2.native.md
#12673: CONFLICT in Ngs2 CMakeLists.txt, Custom.cpp, Voice.cpp,
docs/dev/debt/libSceNgs2.native.md
Findings
Blocking
The pairwise merge previews show content conflicts with the seven open PRs listed above, and this PR currently declares Depends on: none. The repository requires authors to agree on ordering when open PRs overlap and declare that order with Depends on. Please coordinate with the affected authors and update the dependency declaration to reflect the agreed order; then I can re-check the resulting head and combined merge state. Pinned contribution rule
Non-blocking
The reported fixes and regression coverage address the four issues raised earlier. Linux test, TSan, and runtime results are author-reported and were not independently reproduced here.
Not verified
I did not run a local build, CTest, TSan, or Linux runtime tests. I did not verify GPU or console behavior. The corresponding CI jobs were skipped where noted above.
To get this to a good state
Please coordinate merge order with the affected PR authors and record the agreed dependencies in this PR. I will re-run the overlap previews and the same static checks on the new head.
Correction — exact merge conflict outputThe conflict list in my review summarized the affected paths; below is the exact Exact conflict lines |
rooklz
left a comment
There was a problem hiding this comment.
Re-checked at 8ba88e6 against the four points from @oneandonlydean. Host only: macOS arm64, Apple clang, x86_64 target. I did not run a game.
-
git merge-treeagainst main d820fef is clean.git diff --checkandcheck_conventions.py --base upstream/main(title and body included) are clean too. -
I built standalone: every
libSceNgs2.native/src/*.cppplusExport.cpp, and LibAtrac9 at the pinned 946e05a921. The shim has host threads for the 8scePthread*imports, a temp-dirResolvePath, and a throwingNotImplemented.- With ASan+UBSan,
Ngs2JobBufferreports 169 scenarios, andvalidation,recover,emptysetup,destroyedandraceeach pass on their own. The other 23 ngs2 suites (33 runs, counting theThreadsandCustomSafetycases) pass at this head and at the base bb04a4f. - I took the head test back to the first commit 2c87f46. There
validation,recover,emptysetupanddestroyedfail (line 479, the uncaught "appending data requires a waveform", line 517, and the uncaughtPatchDest). - Under TSan at 2c87f46,
racereports 2 races in 3 of 3 runs (Ngs2FinishBlockpop_front, Render.cpp:63, against the capture). This head reports none in 5 of 5 runs and none on the full suite. So points 1 to 4 have real RED/GREEN coverage.
- With ASan+UBSan,
-
Mutants, test unchanged:
- Killed (13 by the new scenarios): capture without
CheckBlocks, no ATRAC9 config match, no partial-frame check, silence allowed on any format, erasingappliedinstead ofapplied + 1, no erase, the empty-setup port rule removed or always resetting (2),PatchDestGonealways false, GetPortInfo ignoring a gone destination, the pending shape ignoring a buffered setup, and, under TSan, the liveblocks.size()and the liveNgs2DecodePendinginCurrentShape. Ngs2FinishBlockwithoutNgs2PublishBlockCountis killed by the existingSamplersuite.- The queue-limit
>to>=survives, but that comparison predates this PR.
- Killed (13 by the new scenarios): capture without
-
Survivors that matter for point 4 and the recover path. Optional, but they cover the "reused handle" case you were asked about:
- Dropping
Ngs2DetachPendingPatchesfromNgs2DestroyRacksurvives. So doesPatchDestGonewithout thedestDestroyedflag (lookup only). Thedestroyedscenario only queries after the rack is gone, so the handle lookup alone already gives 0. Recreating the rack in the same buffer gives back the same handle and kills both. Patching a second source to the rack handle (rather than its voice) also covers the rack-handle branch ofnamed. - Dropping the
PublishPendingEventloop in the catch block survives. A PLAY buffered after the failing append, plus aFlags == INUSEcheck right after the throwing render, kills it.
Patch with both, verified: head passes all 169 scenarios plus
recoveranddestroyed, and the 3 mutants are killed:@@ TestApplyFailureRecovers Control(voice, SCE_NGS2_VOICE_PARAM_PORT_VOLUME, Ngs2VoicePortVolumeParam{{}, 0, 0.5f}); + Event(voice, SCE_NGS2_VOICE_EVENT_PLAY); }; RenderGrain(setup.system); RequireThrows<std::invalid_argument>([&] { RenderGrain(setup.system); }); + Require(Flags(voice) == SCE_NGS2_VOICE_STATE_FLAG_INUSE); @@ TestPendingPatchDestroyedDest - const auto destRack = CreateRack(setup.system, SCE_NGS2_RACK_ID_SUBMIXER); + Ngs2ContextBufferInfo query{}; + Require(sceNgs2RackQueryBufferSize(SCE_NGS2_RACK_ID_SUBMIXER, nullptr, &query) == SCE_NGS2_OK); + const auto destBuffer = Buffer(query); + std::uintptr_t destRack = 0; + Require(TestRackCreate(setup.system, SCE_NGS2_RACK_ID_SUBMIXER, nullptr, &destBuffer, &destRack) == SCE_NGS2_OK); const auto dest = Voice(destRack); Control(dest, SCE_NGS2_SUBMIXER_VOICE_PARAM_SETUP, Ngs2SubmixerVoiceSetupParam{{}, 1, 0}); + const auto rackSource = Voice(CreateRack(setup.system, SCE_NGS2_RACK_ID_SUBMIXER)); + Control(rackSource, SCE_NGS2_SUBMIXER_VOICE_PARAM_SETUP, Ngs2SubmixerVoiceSetupParam{{}, 1, 0}); peer.action = [&](unsigned tick) { if (tick != 0) return; Patch(source, dest); + Patch(rackSource, destRack); RequirePort(source, dest, 1.0f); + RequirePort(rackSource, dest, 1.0f); }; RenderGrain(setup.system); RequirePort(source, dest, 1.0f); Require(sceNgs2RackDestroy(destRack, nullptr) == SCE_NGS2_OK); RequirePort(source, 0, 1.0f); + std::uintptr_t reused = 0; + Require(TestRackCreate(setup.system, SCE_NGS2_RACK_ID_SUBMIXER, nullptr, &destBuffer, &reused) == SCE_NGS2_OK && reused == destRack); + RequirePort(source, 0, 1.0f); + RequirePort(rackSource, 0, 1.0f); RenderGrain(setup.system); RequirePort(source, 0, 1.0f); + RequirePort(rackSource, 0, 1.0f); - Dropping
-
Still uncovered, non-blocking:
- Removing
applyEvents()from the catch block. A PAUSE before the failing append did not reach it. shape.decodePendingin the append check, and thedecodePendingAtGrainsnapshot. Both are the residual you describe in your comment.destDestroyedis redundant with the lookup only when no handle is reused (see 1).
- Removing
-
pr_overlap: 12 PRs share files or exports. The 7 it could not compare (#1384, #5548, #9149, #10599, #11388, #12107, #12673) already conflict with main on their own. It reports no conflict caused by this PR.
Approving, with the diff above as an optional follow-up.
…ailed control Recreating the destroyed rack in the same buffer gives back its handle, so the destroyed scenario now checks that a pending patch to it stays disconnected, through a voice and through the rack handle; the recover scenario checks that a PLAY buffered behind the failing control still takes effect. Suggested by rooklz in review.
|
@rooklz thanks, your patch for the reused handle and the PLAY behind the failing control is in c709971 (tests only); @MarcZX10 thanks, I've put the overlaps and a proposed order in |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — new head, changes requested
The new head adds the requested recovery and reused-handle assertions, but the proposed #12995-first order is not yet agreed by the affected authors and the PR checklist still says Depends on: none.
What I ran
Reviewed head c70997185117ca637b5b2caad73db6a7ad1a1686, PR base 58b2753d74df72635a68bef79c977539332caf2e). A merge preview against current main fdd1753` was clean. Environment: Linux; no compiler was invoked.
git diff --check refs/remotes/upstream/main...refs/review/pr-12995-current
python3 tools/check_conventions.py --base refs/remotes/upstream/main --head refs/review/pr-12995-current
git merge-tree --write-tree refs/remotes/upstream/main refs/review/pr-12995-current
git diff --unified=20 refs/review/pr-12995-head..refs/review/pr-12995-current -- core/libs/prx/libSceNgs2.native/tests/Ngs2JobBuffer.cppI read the exact-head test-only update, the PR checklist and latest discussion, the repository overlap rule, and current statuses for #1384, #5548, #9149, #10599, #11388, #12107, and #12673.
Results
| Check | Result |
|---|---|
| Patch whitespace | Pass; exit 0, no output |
| Repository conventions | Pass |
| Merge preview against current main | Clean |
| New test diff | Adds a PLAY behind the failing control and checks recovery state; expands the destroyed-destination case to reuse the rack handle and confirm pending patches stay disconnected |
| Author-reported tests | ctest -R ngs2 passes 44/44 three times on the updated test head; not independently run |
| Hosted checks | Windows pending; conventions, labels, report and eligibility pass; Linux and specialized jobs are skipped |
Unedited local command output
git diff --check refs/remotes/upstream/main...refs/review/pr-12995-current
(no output; exit 0)
python3 tools/check_conventions.py --base refs/remotes/upstream/main --head refs/review/pr-12995-current
All conventions checks passed.
git merge-tree --write-tree refs/remotes/upstream/main refs/review/pr-12995-current
c2e7b50a3361f9ab5107c1ea36ccaabc1aaf90f8
git diff --stat refs/review/pr-12995-head..refs/review/pr-12995-current
core/libs/prx/libSceNgs2.native/tests/Ngs2JobBuffer.cpp | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
Findings
Blocking
The latest comment proposes that this PR land first and asks the seven affected authors to agree, but no agreement is present in the thread yet. The checklist still says Depends on: none. The repository requires agreement on the landing order and a matching Depends on declaration where a PR needs another one first. All seven named PRs remain open and currently report a dirty merge state. Please record the agreed order in the affected checklists before approval.
Non-blocking
The new test assertions are directionally useful and I found no defect in this test-only update by source inspection. I did not rerun the seven pairwise merge previews on this new head; the earlier review recorded conflicts on the prior head, and this update changes only Ngs2JobBuffer.cpp.
Sources
Not verified
I did not build or run tests. The 44/44 three-run result is author-reported. The current Windows job is pending; hosted Linux is skipped. I did not rerun the pairwise merge previews on this head.
To get this to a good state
Please record the affected authors’ agreed order in the relevant PR checklists, including a Depends on entry wherever another PR must land first. I will rerun the overlap previews and the same static checks on the resulting head.
Correction — base SHA formattingThe PR base is |
Correction — hosted Windows statusThe Windows job completed successfully after my review was posted; it now passes on head |
|
Checked the buffered setup, waveform-block and patch paths against the immediate path (same validation at capture, same |
What
Since #11315, a voice control that arrives while a system is processing voices (the render thread is inside an unlocked UserFx handler, or render jobs are running) is buffered for the next grain, and
CaptureParamControlthrowsNGS2: this buffered voice parameter is not implementedfor every param it does not list. Before #11315 these calls were applied immediately.Skyrim (PPSA03747) hits this at random points: its main and audio threads set up voices while the render thread is inside the legacy submixer UserFx handler. A local log in the capture path showed the params it sends there:
0x20000000(rack0x2000, size 16, voice not set up yet,processingVoices=1,jobsExecuting=0), followed by submixer UserFx and a PLAY command;0x10000000(rack0x1000, size 40), followed by two patches (0x5),ADD_WAVEFORM_BLOCKS0x10000001(size 32), pitch and a PLAY command.This change buffers those params with the immediate path's semantics:
ADD_WAVEFORM_BLOCKSand patches are copied (the block list is owned by the queue, so the caller's array may go away) and applied through the sameApplyParamat the next grain, in call order: events queued before one of them are applied first;0x804A8054, checked against the queue as the earlier buffered setups and blocks leave it;sceNgs2VoiceGetPortInforeports the pending patch destination and the port reset of a pending setup, like it already does for pending volume and matrix.Other params (filters, reverb and mastering setups, ...) still throw on the buffered path.
Tested
Arch Linux (kernel 7.2.11), GCC 16.2.1, Release, Ryzen 7 9800X3D; this branch is on
mainbb04a4f and merges cleanly with 58b2753.ctest -R ngs2: 44/44 on main bb04a4f, 44/44 at 2c87f46 and 44/44 with this change;ngs2_jobbufferruns 164 scenarios at 2c87f46 and 169 now. The first commit's four scenarios cover a submixer setup with no event, PLAY before and after it, and the Skyrim sampler sequence (setup, callback, patch, blocks from a stack array, a rejected second block list, PLAY, plus a fresh submixer setup and PLAY); they abort on main withNGS2: this buffered voice parameter is not implemented, and reverting any single part of that commit fails them.c709971 (tests only, suggested in review): the
destroyedscenario also recreates the rack in the same buffer, which gives back the destroyed handle, and checks that pending patches to it, through a voice and through the rack handle, stay disconnected;recoveralso buffers a PLAY behind the failing control and checks it took effect.ctest -R ngs244/44, three runs.Review scenarios, each runnable alone as
ngs2_jobbuffer_tests <name>, each failing at 2c87f46:validation: from the unlocked UserFx handler, a block whose data does not fit, an append with nothing pending, a partial-frame append, a dataless silence block on a float voice, an ATRAC9 setup with a mismatched config, and a block that does not fit a buffered setup must all throw fromsceNgs2VoiceControl. At 2c87f46 all six are accepted.recover: an append buffered while its stream still has a block, whose last block then ends in the same grain, throws at the next render; the render after it must succeed and apply the port volume buffered behind it. At 2c87f46 every later render throwsNGS2: appending data requires a waveformagain.emptysetup: an empty sampler setup buffered on a configured voice keeps the port (destination, volume) before and after the grain; on an unconfigured voice it resets it. At 2c87f46 the configured voice reports a reset port while the setup is pending.destroyed: a patch buffered from the handler, then the destination rack destroyed after the render returns: the port query and the next render must see a disconnected port. At 2c87f46 the query throwsPatchDest: invalid argument.race: a job manager runs the render jobs on worker threads while another thread buffers a reset block list and a PLAY for a sampler whose last block a worker pops in that grain. It passes functionally at 2c87f46 too; under ThreadSanitizer (-DANYPS5_ENABLE_TSAN=ON, RelWithDebInfo, onlyngs2_jobbuffer_testsbuilt) it reports a data race betweenstd::deque::pop_frontinNgs2FinishBlockanddeque::sizeinCurrentBlockQueue(reached from a buffered PLAY) in 3 of 3 runs at 2c87f46, and none in 5 runs of the scenario and one run of the whole suite with this change.Skyrim PPSA03747, 420 s runs on main bb04a4f + fix(shader): decide each resource branch condition once per plan #11506 (needed to reach gameplay) + fix(agc): don't release a label wait on a store its queue already took and reset #12923 (label stall that otherwise stops presenting at about 130-200 s), Cross pressed every 30 s:
NGS2: this buffered voice parameter is not implemented, at 15 s and 288 sWith the review commit 8ba88e6 (same recipe): 2 runs of 420 s, presenting until 402 and 404 s, no NGS2 message in the log.
Other main-based Skyrim runs on this machine hit the same abort at 219 and 303 s (efc2451 + fix(shader): decide each resource branch condition once per plan #11506), 297 and 320 s (1408347 + fix(shader): decide each resource branch condition once per plan #11506 + fix(agc): don't release a label wait on a store its queue already took and reset #12923) and 11 s (bb04a4f + fix(shader): decide each resource branch condition once per plan #11506 + a logging patch); most runs without fix(agc): don't release a label wait on a store its queue already took and reset #12923 stop presenting at 130-200 s, before it can show up.
With a local stress hook that sleeps 2 ms inside the unlocked UserFx window (so more controls take the buffered path), main aborts at 15 s on a buffered sampler setup; this change runs to 325-346 s, where it stops on
NGS2: deferred events for this voice configuration are not implemented(an event for a voice that is neither a sampler nor a mixer, which in Skyrim can only be its reverb voice; a separate limitation of the buffered path that this PR does not touch).tools/check_conventions.py: clean.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Voice.cpp,Render.cpp,Ngs2Internal.hpp,Custom.cpp, the CMake lists, tests and the debt file) and already conflict withmainon their own. Proposed order: this PR first, since it removes an abort onmain(since feat(ngs2): implement custom PitchShift and external render jobs #11315) and merges cleanly, and those rebase over it along withmain; I'll help with theVoice.cppparts. Asked their authors on this PR.