Skip to content

fix(ngs2): buffer voice setups, waveform blocks and patches sent during processing - #12995

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
hugodearaujo:fix/ngs2-buffer-setup-controls
Oct 30, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
hugodearaujo:fix/ngs2-buffer-setup-controls

Conversation

@hugodearaujo

@hugodearaujo hugodearaujo commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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 CaptureParamControl throws NGS2: this buffered voice parameter is not implemented for 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:

  • submixer setup 0x20000000 (rack 0x2000, size 16, voice not set up yet, processingVoices=1, jobsExecuting=0), followed by submixer UserFx and a PLAY command;
  • sampler setup 0x10000000 (rack 0x1000, size 40), followed by two patches (0x5), ADD_WAVEFORM_BLOCKS 0x10000001 (size 32), pitch and a PLAY command.

This change buffers those params with the immediate path's semantics:

  • sampler and submixer setups, ADD_WAVEFORM_BLOCKS and patches are copied (the block list is owned by the queue, so the caller's array may go away) and applied through the same ApplyParam at the next grain, in call order: events queued before one of them are applied first;
  • the same validation runs at capture time, so invalid params still fail in the call, and a full or closed block queue still returns 0x804A8054, checked against the queue as the earlier buffered setups and blocks leave it;
  • a deferred PLAY checks the channel count the buffered setup will give the voice, so PLAY after a buffered setup is accepted as it is after an immediate one;
  • a callback registered after a buffered setup is buffered behind it, since the setup clears the voice's callback;
  • sceNgs2VoiceGetPortInfo reports 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 main bb04a4f and merges cleanly with 58b2753.

  • ctest -R ngs2: 44/44 on main bb04a4f, 44/44 at 2c87f46 and 44/44 with this change; ngs2_jobbuffer runs 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 with NGS2: this buffered voice parameter is not implemented, and reverting any single part of that commit fails them.

  • c709971 (tests only, suggested in review): the destroyed scenario 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; recover also buffers a PLAY behind the failing control and checks it took effect. ctest -R ngs2 44/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 from sceNgs2VoiceControl. 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 throws NGS2: appending data requires a waveform again.
    • 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 throws PatchDest: 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, only ngs2_jobbuffer_tests built) it reports a data race between std::deque::pop_front in Ngs2FinishBlock and deque::size in CurrentBlockQueue (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:

    build runs result
    main 2 both abort on NGS2: this buffered voice parameter is not implemented, at 15 s and 288 s
    this change 3 all run the full 420 s and present until the end; no NGS2 message in the log

    With 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

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 29, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@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:

  1. Capture reads a block queue that a render worker may be popping. CurrentBlockQueue (Voice.cpp:311) reads voice.blocks.size(), .back() and the last block's info. It runs for a buffered ADD_WAVEFORM_BLOCKS and, through PendingChannels -> PendingBlockQueue (Voice.cpp:346), for every buffered PLAY too. With an external job manager, RenderScheduled releases the global lock around submit, flush and join (Render.cpp:419-446), and the jobs call RenderVoice without it; Ngs2FinishBlock does voice.blocks.pop_front() there (Render.cpp:63). sceNgs2VoiceControl only takes Ngs2Lock and waits on controlOwner, so a control thread can read the deque while a worker pops its last block. Please keep the capture away from worker-owned containers: for PLAY only the channel count is needed (that is not changed by workers), and for blocks a small control-side record (a count that Ngs2FinishBlock decrements atomically, with the end pointer and last user data stored when blocks are appended) or a per-voice lock would do. A test with a job manager whose worker pops the last block while another thread buffers blocks and a PLAY (and a TSan run of it) would show it.
  2. Capture validation is narrower than the immediate path, so some bad input now fails at the next grain. Examples at 2c87f46961: a configured mono PCM_I16L voice, data_size 1 with num_samples 2, is accepted at capture and then throws "does not fit its data" in AddWaveformBlocks (Voice.cpp:736); APPEND on a configured sampler with no waveform pending is accepted and then throws in AppendStreamData (Voice.cpp:676), as does an append that is not a whole PCM frame; an ATRAC9 setup whose config does not match the format is accepted and then throws in Ngs2SetupAtrac9 (Atrac9.cpp:107-109), and a dataless block under the silence flag on a non-PCM voice behaves the same way. At the grain, Ngs2RenderSystem calls ApplyPendingControls (Render.cpp:514) with no handler and pendingControls.clear() only runs after the loop (Voice.cpp:589), so one bad control makes every following sceNgs2SystemRender throw and re-apply the controls before it. Please run these checks at capture against the effective queued state (including MatchingCodecInfo for ATRAC9), with tests that expect the error from sceNgs2VoiceControl, and make ApplyPendingControls leave the list in a sane state if a control still throws (drop the failed one and the ones already applied).
  3. An empty sampler setup does not reset the port in sceNgs2VoiceGetPortInfo. SetupSampler returns without ResetSetup when the format is empty and channels != 0 (Voice.cpp:660-663), so the port keeps its volume, matrix and destination. GetPortInfo (Voice.cpp:1097-1102) reports the default for every pending sampler setup. PendingBlockQueue already follows that rule for channels; please make the port query follow the same sequence, with before/after checks for an empty setup on a configured and on an unconfigured voice.
  4. A buffered patch is not reconciled when its destination goes away. The patch keeps only the destination handle; Ngs2DestroyRack clears materialised port destinations only (Rack.cpp:221). If the destination rack is destroyed after a render has returned with the patch still pending, the next GetPortInfo or ApplyPendingControls calls PatchDest again and throws (Voice.cpp:605), where an immediate patch would just have been disconnected; a reused handle could also point the patch at a different object. Please disconnect (or drop) pending patches that name a destroyed rack or voice when it is destroyed, and have the apply step treat a missing destination like a detached one rather than throw. A test: buffer a patch from the unlocked UserFx handler, return from the render, destroy the destination rack, query the port and render the next grain.

The new title sequence and ordering tests look right; these four need their own cases.

@github-actions

github-actions Bot commented Oct 29, 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 11388 core/libs/prx/libSceNgs2.native/src/Voice.cpp L517-522, L530-533, L572, L589-597

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 1384 core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
core/libs/prx/libSceNgs2.native/src/Rack.cpp
core/libs/prx/libSceNgs2.native/src/Render.cpp
core/libs/prx/libSceNgs2.native/src/Voice.cpp
PR 5548 core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
core/libs/prx/libSceNgs2.native/src/Render.cpp
core/libs/prx/libSceNgs2.native/src/Voice.cpp
docs/dev/debt/libSceNgs2.native.md
PR 12107 docs/dev/debt/libSceNgs2.native.md
PR 12673 core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
core/libs/prx/libSceNgs2.native/src/Voice.cpp
docs/dev/debt/libSceNgs2.native.md

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.
@hugodearaujo

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks for the careful read. All four are addressed in 8ba88e6, on top of 2c87f46:

  1. Capture no longer touches voice.blocks. The voice keeps a control-side record instead: the queued block count (stored through std::atomic_ref, also by Ngs2FinishBlock after its pop_front), and the end pointer and user data of the last block, written only by the control side (workers only pop the front, and with a count of zero the tail is ignored). The one worker-owned value the immediate checks need, whether a stream still has samples to decode, is read live outside render jobs and from a snapshot taken at the start of the grain while jobs run. PLAY only follows the channel count of the buffered setups. I went with the record rather than a per-voice lock because it keeps locking out of the render path and can't deadlock against a UserFx handler that calls back into sceNgs2VoiceControl from a worker. What's left: an append buffered during jobs in the very grain in which its stream drains is checked against the grain-start state, accepted, and then fails at the grain, as an immediate append made just after that grain would; with point 2 that now drops the control instead of wedging the voice. The new race scenario (a job manager with worker threads, another thread buffering a reset block list and a PLAY while a worker pops the last block) reports the pop_front/deque::size race under TSan at 2c87f46 in 3 of 3 runs, and nothing with this change (5 runs of the scenario, plus the whole ngs2_jobbuffer suite once).
  2. The block and setup checks now live in one place (CheckBlocks, plus the ATRAC9 codec match in ValidateSamplerFormat) that both the immediate path and the capture use, the capture against the queued state: block fit, an append with nothing pending, partial-frame appends, dataless silence blocks on non-I16 voices, closed waveforms and an ATRAC9 config mismatch all throw from sceNgs2VoiceControl again. If a control still throws when it's applied, ApplyPendingControls drops it and the controls before it, applies the events already reduced, and recomputes the pending PLAY/KILL state from what's left before rethrowing, so the next render goes on with the controls queued after it (validation and recover scenarios).
  3. sceNgs2VoiceGetPortInfo walks the pending setups with the same rule as the block projection: an empty sampler setup resets the port only when the voice has no channels (emptysetup, on a configured and an unconfigured voice, before and after the grain).
  4. Ngs2DestroyRack marks pending patches that name the destroyed rack or one of its voices, and the apply step and the port query treat a marked or missing destination as a disconnected port, the way an immediate patch ends up after the destroy (destroyed: buffer from the handler, return, destroy the rack, query, render).

Each new scenario fails at 2c87f46 (the race one under TSan). ctest -R ngs2 is 44/44 before and after, and two 420 s Skyrim runs with this commit still run to the end with no NGS2 message.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"; done

Results

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.

@MarcZX10

Copy link
Copy Markdown
Contributor

Correction — exact merge conflict output

The conflict list in my review summarized the affected paths; below is the exact CONFLICT (content) output from the seven pairwise git merge-tree runs.

Exact conflict lines
#1384
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/CMakeLists.txt
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/Ngs2Library.cmake
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/include/Ngs2Types.hpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Rack.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Render.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Voice.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2/CMakeLists.txt
CONFLICT (content): Merge conflict in docs/dev/TechnicalDebt.md
#5548
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/CMakeLists.txt
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Render.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/tests/Ngs2Pcm.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2/CMakeLists.txt
#9149
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/tests/Ngs2Parse.cpp
CONFLICT (content): Merge conflict in docs/dev/debt/libSceNgs2.native.md
#10599
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/CMakeLists.txt
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Custom.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Voice.cpp
CONFLICT (content): Merge conflict in docs/dev/debt/libSceNgs2.native.md
#11388
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/CMakeLists.txt
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/Ngs2Library.cmake
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Ngs2Internal.hpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Render.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Voice.cpp
#12107
CONFLICT (content): Merge conflict in docs/dev/debt/libSceNgs2.native.md
#12673
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/CMakeLists.txt
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Custom.cpp
CONFLICT (content): Merge conflict in core/libs/prx/libSceNgs2.native/src/Voice.cpp
CONFLICT (content): Merge conflict in docs/dev/debt/libSceNgs2.native.md

@rooklz rooklz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-tree against main d820fef is clean. git diff --check and check_conventions.py --base upstream/main (title and body included) are clean too.

  • I built standalone: every libSceNgs2.native/src/*.cpp plus Export.cpp, and LibAtrac9 at the pinned 946e05a921. The shim has host threads for the 8 scePthread* imports, a temp-dir ResolvePath, and a throwing NotImplemented.

    • With ASan+UBSan, Ngs2JobBuffer reports 169 scenarios, and validation, recover, emptysetup, destroyed and race each pass on their own. The other 23 ngs2 suites (33 runs, counting the Threads and CustomSafety cases) pass at this head and at the base bb04a4f.
    • I took the head test back to the first commit 2c87f46. There validation, recover, emptysetup and destroyed fail (line 479, the uncaught "appending data requires a waveform", line 517, and the uncaught PatchDest).
    • Under TSan at 2c87f46, race reports 2 races in 3 of 3 runs (Ngs2FinishBlock pop_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.
  • 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, erasing applied instead of applied + 1, no erase, the empty-setup port rule removed or always resetting (2), PatchDestGone always false, GetPortInfo ignoring a gone destination, the pending shape ignoring a buffered setup, and, under TSan, the live blocks.size() and the live Ngs2DecodePending in CurrentShape.
    • Ngs2FinishBlock without Ngs2PublishBlockCount is killed by the existing Sampler suite.
    • The queue-limit > to >= survives, but that comparison predates this PR.
  • Survivors that matter for point 4 and the recover path. Optional, but they cover the "reused handle" case you were asked about:

    1. Dropping Ngs2DetachPendingPatches from Ngs2DestroyRack survives. So does PatchDestGone without the destDestroyed flag (lookup only). The destroyed scenario 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 of named.
    2. Dropping the PublishPendingEvent loop in the catch block survives. A PLAY buffered after the failing append, plus a Flags == INUSE check right after the throwing render, kills it.

    Patch with both, verified: head passes all 169 scenarios plus recover and destroyed, 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);
  • Still uncovered, non-blocking:

    • Removing applyEvents() from the catch block. A PAUSE before the failing append did not reach it.
    • shape.decodePending in the append check, and the decodePendingAtGrain snapshot. Both are the residual you describe in your comment.
    • destDestroyed is redundant with the lookup only when no handle is reused (see 1).
  • 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.
@hugodearaujo

Copy link
Copy Markdown
Contributor Author

@rooklz thanks, your patch for the reused handle and the PLAY behind the failing control is in c709971 (tests only); ctest -R ngs2 passes 44/44 three times on it.

@MarcZX10 thanks, I've put the overlaps and a proposed order in Depends on. Asking the authors here: @TibixDev (#1384), @JJenkx (#5548), @MarrasFederico (#9149), @kyon-eth (#10599), @nekomancer01 (#11388), @Th3EvilGod (#12107), @2Swagger (#12673) — your PRs share NGS2 files with this one and already conflict with main on their own. Would it work for you if this one lands first? It removes an abort that main has had since #11315 (Skyrim stops on NGS2: this buffered voice parameter is not implemented), and it merges cleanly today. You'd then rebase over it along with main; the overlap is mostly Voice.cpp's control and capture code and the debt entry, and I'm happy to help with those parts. If one of you would rather land first, I'll rebase this PR instead.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cpp

I 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.

@MarcZX10

Copy link
Copy Markdown
Contributor

Correction — base SHA formatting

The PR base is 58b2753d74df72635a68bef79c977539332caf2e; my preceding review omitted the closing backtick after the SHA. The review outcome and findings are unchanged.

@MarcZX10

Copy link
Copy Markdown
Contributor

Correction — hosted Windows status

The Windows job completed successfully after my review was posted; it now passes on head c70997185117ca637b5b2caad73db6a7ad1a1686. The Linux and specialized jobs remain skipped.

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@adriadam10
adriadam10 merged commit a1782bd into boykopovar:main Oct 30, 2026
11 of 12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the buffered setup, waveform-block and patch paths against the immediate path (same validation at capture, same ApplyParam at the grain, call order kept), the race-free queued state that answers the earlier review, and the new ngs2_jobbuffer scenarios (they hit the not implemented abort on main); conventions and Windows are green; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs prx unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants