Audio: reuse the PCM workspace between Opus commands #2421
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2423"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-25T13:14:21Z.
What
Keep one PCM scratch buffer per APU connection and reuse it across Opus process commands under the existing connection mutex. Grow it only when needed and pass each decoder a slice sized for its channel count. Keep
VecDeque::new()so the guest-provided stream and command counts do not determine an upfront result-queue allocation.How it was tested
The new regression alternates mono and stereo commands and compares result lengths and PCM bytes against independent decoders. It tests decode behavior, not the address or capacity of the backing buffer. The new regression and the existing Opus decode test both passed on the head.
Both workspace Clippy modes (default and all features, with
-D warnings) exited 0 on head and base. The Windows-target workspace test under Wine exited 101 on both, stopping invictory-hle:modules::net::tests::only_loopback_is_reachablehit a missingWSAConnectByListexport on the isolated runner, andmodules::xgamesave::tests::a_kept_blob_past_the_link_limit_is_copieddid not observe the expected NTFS hard-link limit. Native Windows CI remains the final gate.A/B/B/A release microbenchmark on the Windows MSVC target under Wine: identical synthetic Opus enqueue/dequeue workload, seven 1,024-packet samples per arm after warm-up. The arm medians were 27,094.2 / 26,569.9 / 26,505.9 / 26,995.0 ns/packet. Median of arm medians:
63bcca43c627,044.6 ns/packet;349929c0cc26,537.9 ns/packet (1.87% lower). This measures the synthetic packet path, not gameplay or frame time.Radicle project hub (open-source porting and preservation history): https://radicle.network/nodes/rosa.radicle.network/rad:z3rqQw7796wMbgj8RszExtWR4wMSE
Live development stream: https://vdo.ninja/?view=gta6rtx4090live1080p60
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:18:38Z.
Review: APPROVED
Verified against
origin/main(940d32f):cargo test -p victory-hle apu::: 3/3 passed (includingprocess_reuses_decode_scratch_buffer_without_reallocating).cargo clippy -p victory-hle --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:32Z.
Review: COMMENTED
victory-hle(apu): reuse Opus decode scratch buffer, pre-reserve. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:32:24Z.
Automated triage for the maintainers.
Needs work. This keeps a reused
decode_bufin the APUStateinstead of allocatingMAX_FRAMES * channelsfloats per packet inprocess(crates/victory-hle/src/modules/apu.rs), and givesresultsa starting capacity ofstreams * commands_per_stream. The logic is fine and it resizes for streams with more channels. What would change the verdict:process_reuses_decode_scratch_buffer_without_reallocatingasserts the buffer's pointer and capacity stay the same, which is the implementation, not behaviour. The existing decode tests already cover correctness.streams * commands_per_stream); please cap it or keepVecDeque::new().CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:53:32Z.
Sound:
decode_bufis behind the connection mutex (streams can't race on it),neededfalls back toresizefor >2-channel decoders (Opus supports up to 8 —MAX_PCM_SAMPLESonly pre-sizes stereo, not a cap), and the borrow is disjoint (state.streams[x]decoder vsstate.decode_buf).resultspre-reserve matches the documented max queue depth. Test verifies capacity retention — good regression pin.Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-30T23:01:50Z.
Thanks for the review. The update at
349929c0ccaddresses the three requests:XApuConnectkeepsVecDeque::new()(crates/victory-hle/src/modules/apu.rs:211); the guest’sstreams * commands_per_streamno longer controls an upfront allocation.alternating_mono_and_stereo_match_independent_decoderscompares returned lengths and PCM bytes against independent decoders instead of asserting pointer or capacity stability. Both that test anddecodes_opus_as_the_title_drives_itreportedokon this head in the Windows-target run under Wine.63bcca43c627,044.6 ns/packet;349929c0cc26,537.9 ns/packet (1.87% lower). This measures the synthetic packet path, not gameplay or frame time.Both workspace Clippy modes (default and all features, with
-D warnings) exited 0 on head and base. The Windows-target workspace test under Wine exited 101 on both, stopping invictory-hle:modules::net::tests::only_loopback_is_reachablehit a missingWSAConnectByListexport on the isolated runner, andmodules::xgamesave::tests::a_kept_blob_past_the_link_limit_is_copieddid not observe the expected NTFS hard-link limit. Native Windows CI remains the final gate. The previously reported green CI was forcf1607b126, not this update.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.