Skip to content

Vectorize exact MP3 PCM quantization in audio WASM - #270

Merged
Hona merged 16 commits into
mainfrom
work/tf2-wasm-simd-performance
Sep 1, 2026
Merged

Hona merged 16 commits into
mainfrom
work/tf2-wasm-simd-performance

Conversation

@Hona

@Hona Hona commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Quantize independent MP3 synthesis samples with standard 128-bit WASM SIMD, preserving the special scalar pair, nearest-even rounding, signed saturation and bounded tails.
  • Enable SIMD only for the separately built audio module. Gameplay compilation features, shared memory, TLS and binding contracts are unchanged; gameplay SIMD expansion is excluded.
  • Preserve native scalar behavior, PCM buffer capacity, build identities, unshared audio memory, and pre-instantiation browser capability checks.

Verification

  • Native and actual scalar/SIMD WASM tests cover mono/stereo groups, short/unaligned tails, infinities, NaNs, signed zero and subnormals.
  • Five decoder inputs totaling 2,108,160 samples match the public decoder reference exactly. Configured Windows input is read from its pinned local archive, not transferred test media.
  • Retained complete audio WASM comparisons preserve Float32 paint bytes for six master gains, including signed zero and subnormal values.
  • Existing real headed Windows x64 Edge 152 evidence measured 1.6934 → 1.4959 ms per decode (median of 32-call batches), an approximately 11.7% reduction, with identical initial/final PCM hashes and linear-memory sizes. This is decoder-kernel evidence, not end-to-end loading, gameplay FPS or a fix for one-second freezes.
  • After integrating current main, 26 focused tests / 226 assertions passed locally, including configured native and actual scalar/SIMD WASM PCM tests, audio lifecycle/worklet tests, compiler flags/remaps and unsupported-target admission.

Headed decoder evidence

This retained screenshot reports 32-call batch means, not individual-call tail percentiles. The profiler now supports individual durations and explicit sample age; no additional results from that instrumentation are claimed here.

Configured MP3 waveform and actual headed Edge decoder comparison

Evidence limits

The reported performance evidence is the existing headed x64 PCM/batch measurement; current-main verification uses focused exact-audio and build checks. New individual-call browser tail distributions, ARM headed performance, live-device capture completion and a full 90-second gameplay campaign remain unmeasured. The pending remote task has not been relaunched; its prior unknown outcome/teardown is not treated as successful acceptance.

No graphics, bot work, simulation cadence, networking or production changes. The abandoned live-gameplay profiling extension was removed from this narrow change.

@Hona
Hona force-pushed the work/tf2-wasm-simd-performance branch from d4c088e to d5789ee Compare September 1, 2026 02:26
@Hona
Hona marked this pull request as ready for review September 1, 2026 02:27
Copilot AI lite review requested due to automatic review settings September 1, 2026 02:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

It changes correctness-sensitive MP3 PCM quantization and introduces new SIMD/fixture workflows that warrant final human verification despite strong test/evidence additions.

Pull request overview

This PR adds a WebAssembly-SIMD128 vectorized quantization path for MP3 PCM output while preserving exact scalar behavior for the special “first pair” lanes, and wires up build/test/profile infrastructure so SIMD is enabled only for the separately built audio/decoder module (not gameplay).

Changes:

  • Vectorize MP3 float→i16 quantization on wasm32 with simd128, preserving scalar-pair rounding and exact tail handling.
  • Add an explicit audio WASM Rust-flag path (-Ctarget-feature=+simd128) distinct from threaded/gameplay flags, plus tests asserting the separation.
  • Add configured parity evidence generation and a headed Playwright profile (simd-decoder) for scalar vs SIMD decoder comparison.
File summaries
File Description
tools/playsrc/tests/tf2-wasm-build.test.ts Adds coverage ensuring gameplay/threaded flags do not pick up SIMD, and audio flags do.
tools/playsrc/tests/simd-configured.test.ts Adds opt-in configured parity test that produces retained scalar/SIMD WASM artifacts + PCM hashes.
tools/playsrc/src/tf2-wasm-build.ts Factors remap flags and introduces audioWasmRustFlags() to enable SIMD only for audio WASM builds.
tools/playsrc/src/profile-runner.ts Registers a new simd-decoder profile runner entry (with Windows Edge channel override).
tools/playsrc/profile/simd-decoder.profile.ts Adds headed-browser scalar vs SIMD decoder execution + timing/hash evidence capture.
tools/playsrc/local-jobs.md Documents how to prepare and run the new simd-decoder workflow.
playwright.simd-profile.config.ts Adds a dedicated Playwright config for the SIMD decoder profile.
packages/presentation/audio/tests/wasm.test.ts Adds tests for preflight SIMD support checks and “no compile if unsupported” behavior.
packages/presentation/audio/src/wasm.ts Introduces compileAudioModule() which bounds size and rejects unsupported SIMD targets early.
packages/presentation/audio/src/playback.ts Routes audio module compilation through compileAudioModule() to enforce SIMD/capacity checks.
packages/formats/mp3/rust/tests/configured.rs Updates configured test to read pinned local TF2 archive input and retain cow1.mp3 evidence.
packages/formats/mp3/rust/src/lib.rs Reworks decode output fill to a bulk quantize step with a SIMD128 fast-path on wasm.
packages/formats/mp3/rust/Cargo.toml Adds dev-dependencies needed by the configured evidence test.
Cargo.lock Locks new dev-dependency resolution for the mp3 crate.
Review details
  • Files reviewed: 13/14 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3 to +6
// (module (func (drop (v128.const i32x4 0 0 0 0))))
// Check standard SIMD without validating the complete audio module twice.
const SIMD128 = new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,23,1,21,0,253,12,...Array(16).fill(0),26,11])

@Hona
Hona force-pushed the work/tf2-wasm-simd-performance branch 2 times, most recently from fc46b5c to bfe821c Compare September 1, 2026 02:47
@Hona
Hona force-pushed the work/tf2-wasm-simd-performance branch from bfe821c to 98896f2 Compare September 1, 2026 02:55
@Hona
Hona merged commit 972a820 into main Sep 1, 2026
1 check passed
@Hona
Hona deleted the work/tf2-wasm-simd-performance branch September 1, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants