Formats: speed up XMA PCM rounding #3656

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3656 into main
andrewpozdnakov7-jpg commented 2026-11-28 03:25:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T03:25:40Z.


Change

Convert decoded XMA samples to i16 by scaling in f64, adding a half with the sample's sign and casting. The wider addition keeps f32 values immediately next to a tie on the correct side. The cast truncates and saturates, giving the existing ties-away-from-zero rounding and clipping.

Verification

  • Matched the previous conversion on 6,426,282 inputs, including neighborhoods around every PCM rounding boundary and special floats. Added a regression for ties and both adjacent f32 values, clipping and non-finite values.
  • Decoded 288 generated stereo frames per fixture at 24, 32, 44.1 and 48 kHz, plus flush. All 301,056 PCM samples per fixture matched. In Windows x64 optimized builds on an Intel i7-870, 17 alternating pairs per configuration gave 1.97–2.16× faster decode for the sparse fixture in two runs and 1.83–1.89× for the fixture with 96 nonzero coefficients per channel.
  • Release formats suite passed 42 tests, with five ignored and five unrelated noise tests filtered from the local run. Strict formats Clippy and the asset policy passed.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5536213013 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3656). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T03:25:40Z. --- ## Change Convert decoded XMA samples to i16 by scaling in f64, adding a half with the sample's sign and casting. The wider addition keeps f32 values immediately next to a tie on the correct side. The cast truncates and saturates, giving the existing ties-away-from-zero rounding and clipping. ## Verification - Matched the previous conversion on 6,426,282 inputs, including neighborhoods around every PCM rounding boundary and special floats. Added a regression for ties and both adjacent f32 values, clipping and non-finite values. - Decoded 288 generated stereo frames per fixture at 24, 32, 44.1 and 48 kHz, plus flush. All 301,056 PCM samples per fixture matched. In Windows x64 optimized builds on an Intel i7-870, 17 alternating pairs per configuration gave **1.97–2.16×** faster decode for the sparse fixture in two runs and **1.83–1.89×** for the fixture with 96 nonzero coefficients per channel. - Release formats suite passed 42 tests, with five ignored and five unrelated noise tests filtered from the local run. Strict formats Clippy and the asset policy passed. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 03:31:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T03:31:45Z.


Verified 32fd04874e340acf25b595ad54710dbca4ef77dc on Windows CI. Both Clippy stages and the workspace test stage passed.

The conversion probe matched the old result on 6,426,282 inputs. In a local negative control, adding the signed half in f32 rounded sample 0x377fffff to 1 instead of 0. The committed regression catches that and passes with the f64 operation.

The 288-frame stereo fixtures match all 301,056 PCM samples each. The dense fixture gave a 1.83–1.89× median decode speedup on this Windows CPU. The integration with #3631 also matched the dense PCM output exactly.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7233147235 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3656#issuecomment-7233147235). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T03:31:45Z. --- Verified `32fd04874e340acf25b595ad54710dbca4ef77dc` on [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46102798169/job/140848816269). Both Clippy stages and the workspace test stage passed. The conversion probe matched the old result on 6,426,282 inputs. In a local negative control, adding the signed half in f32 rounded sample `0x377fffff` to 1 instead of 0. The committed regression catches that and passes with the f64 operation. The 288-frame stereo fixtures match all 301,056 PCM samples each. The dense fixture gave a 1.83–1.89× median decode speedup on this Windows CPU. The [integration with #3631](https://github.com/Marvisak/VIctory/pull/3631#issuecomment-7233090960) also matched the dense PCM output exactly. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-28 10:27:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T10:27:17Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3656 at head 32fd04874e340acf25b595ad54710dbca4ef77dc, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-formats --lib -- xma::tests::pcm_rounds_ties_away_from_zero_and_saturates --exact --test-threads=1 --quiet → 1 passed, 0 failed, 51 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (1 file, +26/-1).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; the full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only XMA rounding test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237906814 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3656#issuecomment-7237906814). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T10:27:17Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3656 at head `32fd04874e340acf25b595ad54710dbca4ef77dc`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-formats --lib -- xma::tests::pcm_rounds_ties_away_from_zero_and_saturates --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 51 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new on this PR); `git diff --check 63bcca4 HEAD` clean (1 file, +26/-1). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; the full workspace suite and clippy were not run locally. - GPU/driver: N/A (CPU-only XMA rounding test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3656:upstream-pr/3656'
git switch 'upstream-pr/3656'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3656'
git switch 'upstream-pr/3656'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3656'
git switch 'upstream-pr/3656'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3656'
git switch 'main'
git merge --squash 'upstream-pr/3656'
git switch 'main'
git merge --ff-only 'upstream-pr/3656'
git switch 'main'
git merge 'upstream-pr/3656'
git push origin 'main'
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
Marvisak/VIctory!3656
No description provided.