Formats: share XMA scale-factor band tables by sample rate #3666

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

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


XMA decoders now share four immutable scale-factor band layouts, one for each normalized sample rate. The original band calculation runs once per rate on demand. Decoder creation, cloning and per-stream state use a reference to that layout.

I compared every band-table entry against the old layout for 12 rates, including the boundaries, and checked the same tables from eight concurrently opening decoders. All 301,056 PCM samples from generated stereo frames matched, across all four rates and three transform modes.

On 64-bit Windows the decoder dropped from 14,304 to 11,480 bytes. Across 17 paired runs of 5,000 constructor calls, the warm-cache median was 0.300 µs, down from 1.738 µs. The formats suite reported 47 passed and five ignored. Strict formats Clippy and the asset policy passed.

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:issue:5536728546 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3666). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T04:40:38Z. --- XMA decoders now share four immutable scale-factor band layouts, one for each normalized sample rate. The original band calculation runs once per rate on demand. Decoder creation, cloning and per-stream state use a reference to that layout. I compared every band-table entry against the old layout for 12 rates, including the boundaries, and checked the same tables from eight concurrently opening decoders. All 301,056 PCM samples from generated stereo frames matched, across all four rates and three transform modes. On 64-bit Windows the decoder dropped from 14,304 to 11,480 bytes. Across 17 paired runs of 5,000 constructor calls, the warm-cache median was 0.300 µs, down from 1.738 µs. The formats suite reported 47 passed and five ignored. Strict formats Clippy and the asset policy passed. 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.
andrewpozdnakov7-jpg commented 2026-11-28 04:43:40 +00:00 (Migrated from github.com)

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


Windows CI passed at 7a37479. The formats tests, Clippy and policy results in the description apply to the same head.

I found a related layout cache in #3383. That branch builds all four tables at the first decoder. This PR is the standalone per-rate option and initializes each table when a decoder first needs that rate. In 21 paired fresh-process 48 kHz probes on the same machine, the first constructor's median was 61.4 µs for #3383 and 31.2 µs here. Both designs share the tables after initialization. The next step is a maintainer decision on which version to land.

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:7234221584 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3666#issuecomment-7234221584). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T04:43:40Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46108652944/job/140867009543) passed at `7a37479`. The formats tests, Clippy and policy results in the description apply to the same head. I found a related layout cache in #3383. That branch builds all four tables at the first decoder. This PR is the standalone per-rate option and initializes each table when a decoder first needs that rate. In 21 paired fresh-process 48 kHz probes on the same machine, the first constructor's median was 61.4 µs for #3383 and 31.2 µs here. Both designs share the tables after initialization. The next step is a maintainer decision on which version to land. 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.
andrewpozdnakov7-jpg commented 2026-11-28 05:15:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T05:15:16Z.


I combined #3671 with the tested #3666/#3383 stack in 646e7ab. The branch keeps both exact PR heads. The merge applied cleanly.

The combined decoder matched all 301,056 PCM samples from the previous combined branch, across four sample rates and three transform modes with varied quantization and scale factors. Over 17 alternating runs per case on the local Windows CPU, complete decode medians were 1.14–1.17x the previous stack. The formats suite passed 50 tests, with five ignored. Strict formats Clippy and the asset policy passed.

The maintainer can use the combined branch to review the two changes together.

Please retain the Git authors 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:7234553897 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3666#issuecomment-7234553897). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T05:15:16Z. --- I combined #3671 with the tested #3666/#3383 stack in [646e7ab](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/646e7ab351dc21094bfcbb320f8f7cd367d5b63a). The branch keeps both exact PR heads. The merge applied cleanly. The combined decoder matched all 301,056 PCM samples from the previous combined branch, across four sample rates and three transform modes with varied quantization and scale factors. Over 17 alternating runs per case on the local Windows CPU, complete decode medians were 1.14–1.17x the previous stack. The formats suite passed 50 tests, with five ignored. Strict formats Clippy and the asset policy passed. The maintainer can use the combined branch to review the two changes together. Please retain the Git authors 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:18 +00:00 (Migrated from github.com)

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


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

  • PR #3666 at head 7a374796597fb5cd4d7afb813a2c4a37b522c958, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-formats --lib -- xma::tests::decoders_share_the_layout_for_their_normalized_sample_rate --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, +74/-32).
  • 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 decoder layout test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237906983 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3666#issuecomment-7237906983). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T10:27:18Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3666 at head `7a374796597fb5cd4d7afb813a2c4a37b522c958`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-formats --lib -- xma::tests::decoders_share_the_layout_for_their_normalized_sample_rate --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, +74/-32). - 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 decoder layout 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/3666:upstream-pr/3666'
git switch 'upstream-pr/3666'

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