[PR #404] [MERGED] acphal: ACP message queue and background XMA ring decoding with the Rust XMA2 decoder (RT-ACPHAL-XMA2) #457

Closed
opened 2026-11-26 20:17:56 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/404
Author: @Andretuta
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: feat/acphal-xma2-decoder


📝 Commits (10+)

  • 4750df6 acphal: add portable XMA2 decoder, ACP message queue, and SHAPE XMA worker
  • 259772e Merge remote-tracking branch 'ubiq/main' into feat/acphal-xma2-decoder
  • 12536c2 acphal: stop the XMA worker it was meant to stop
  • cfcedb5 acphal: decode XMA contexts with runtime/xma_decoder when cargo is available
  • a99a3fb acphal: preserve XMA packet chains and context lifetime
  • a0327ee runtime: target the MSVC ABI for the Rust XMA2 decoder
  • e02ec36 acphal: synchronize XMA context words and bound the output ring
  • 0fe9c0b acphal: recover SHAPE allocation and preserve XMA stream state
  • 4e9407a acphal: isolate voice failures and keep input transitions ordered
  • 713eec5 acphal: stabilize APU mappings and reuse XMA PCM storage

📊 Changes

10 files changed (+1518 additions, -120 deletions)

View changed files

📝 .github/workflows/runtime.yml (+1 -0)
📝 runtime/CMakeLists.txt (+44 -0)
📝 runtime/shims/acphal.cpp (+769 -104)
📝 runtime/test/acphal_test.cpp (+620 -8)
📝 runtime/xma_decoder/README.md (+9 -2)
📝 runtime/xma_decoder/leonida_xma2_decoder.h (+4 -0)
📝 runtime/xma_decoder/src/lib.rs (+46 -5)
📝 runtime/xma_decoder/tests/ffi_contract.rs (+22 -0)
📝 scripts/build_runtime.ps1 (+1 -1)
📝 third_party/xma/NOTICE.md (+2 -0)

📄 Description

Claimed in the coordination issue as: RT-ACPHAL-XMA2 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121796272)

Depends on: #357

What and why

  • Replaces the acphal.dll stub with an ACP command and message queue and a worker that fills SHAPE XMA PCM rings. The worker follows packet skips and refill order, updates shared fields atomically, and bounds each pass to the ring. Repeated enables preserve queued PCM for the same format and reset it when the format changes.
  • CMake builds the Rust decoder in runtime/xma_decoder at configure time through Cargo. The shim outputs silence based on each packet's frame count when Cargo is missing, the build fails, or the direct cl.exe fallback is used. Windows runtime CI explicitly requires the decoder.
  • The hardware constructor keeps the first frame and leaves start skipping to the XMA context. The decoder consumes 2048-byte packets, so read and loop points are rounded to packet boundaries. A loop plays its end packet in full and restarts with a fresh decoder at the start packet. The loop-end subframe is ignored.
  • Each worker uses its own std::jthread stop token. A worker memory failure reports an error for the affected voice. SHAPE allocation publishes a complete table or returns E_OUTOFMEMORY. Release detaches the worker, then frees the process-wide arrays without writing through the opaque HAL handle.
  • APU mappings stay stable after explicit heap configuration. Each voice reuses contiguous PCM storage while consuming its packets.

Tested

  • MSVC 19.44.35230 and Windows SDK 10.0.26100 built and linked gta6rt and acphal_test in Debug and Release with Rust. A separate CMake configuration built acphal_test with the silence fallback in both build types. CTest passed in all four configurations, with 170 checks per normal run with Rust, 166 with silence, and 14 for the separate non-cached-only case in each configuration.
  • MSYS2 Clang 23.1.3 passed three normal runs and the non-cached-only case in both decoder modes. Synthetic tests cover exact PCM block counts, non-silent Rust output across loop rewinds and refills, mono and stereo at all four rates, ring bounds, and allocation failure. In MSVC Release with the silence fallback, a six-frame input required 1 C++ worker allocation, down from 208 on snapshot 4e9407a40.
  • Cargo and rustc 1.97.1 passed formatting and all 10 Rust tests on both x86_64-pc-windows-msvc and x86_64-pc-windows-gnullvm, including a first-frame test for the hardware constructor. Locked release builds succeeded on both targets.
  • Python 3.14.2 and pytest 9.0.2 passed 204 tests and 200 subtests, with 3 skipped. The game-data check passed.
  • With an empty offline Cargo cache and an older archive present, the optional CMake build selected the silence fallback. The configuration requiring Rust failed as expected.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — audio decoder & runtime shim only)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/404 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `feat/acphal-xma2-decoder` --- ### 📝 Commits (10+) - [`4750df6`](https://github.com/ubiquitarianism/leonida/commit/4750df6a06e68c05343c5895f1d6dcddf61e38c3) acphal: add portable XMA2 decoder, ACP message queue, and SHAPE XMA worker - [`259772e`](https://github.com/ubiquitarianism/leonida/commit/259772edb4042e4c81d9196ec5064a6f84c09ed7) Merge remote-tracking branch 'ubiq/main' into feat/acphal-xma2-decoder - [`12536c2`](https://github.com/ubiquitarianism/leonida/commit/12536c2ab33072b8f49a8d012c970093c90c0866) acphal: stop the XMA worker it was meant to stop - [`cfcedb5`](https://github.com/ubiquitarianism/leonida/commit/cfcedb58e2802c5cd38afd1cbde877ae9d71c2a5) acphal: decode XMA contexts with runtime/xma_decoder when cargo is available - [`a99a3fb`](https://github.com/ubiquitarianism/leonida/commit/a99a3fb6ad419bf7f0a255d8b31fbd8112da1b39) acphal: preserve XMA packet chains and context lifetime - [`a0327ee`](https://github.com/ubiquitarianism/leonida/commit/a0327ee1af5bb44abfd1327d00167da526d1ac70) runtime: target the MSVC ABI for the Rust XMA2 decoder - [`e02ec36`](https://github.com/ubiquitarianism/leonida/commit/e02ec36bf315de960a9db244e971bf00cfd66406) acphal: synchronize XMA context words and bound the output ring - [`0fe9c0b`](https://github.com/ubiquitarianism/leonida/commit/0fe9c0bdfb844678209c0d0ffdd37d2533d1f57e) acphal: recover SHAPE allocation and preserve XMA stream state - [`4e9407a`](https://github.com/ubiquitarianism/leonida/commit/4e9407a409641b644393a66b41d35e431f1c5ddb) acphal: isolate voice failures and keep input transitions ordered - [`713eec5`](https://github.com/ubiquitarianism/leonida/commit/713eec5031a6a7d1b1626f090d742531007b28e5) acphal: stabilize APU mappings and reuse XMA PCM storage ### 📊 Changes **10 files changed** (+1518 additions, -120 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/runtime.yml` (+1 -0) 📝 `runtime/CMakeLists.txt` (+44 -0) 📝 `runtime/shims/acphal.cpp` (+769 -104) 📝 `runtime/test/acphal_test.cpp` (+620 -8) 📝 `runtime/xma_decoder/README.md` (+9 -2) 📝 `runtime/xma_decoder/leonida_xma2_decoder.h` (+4 -0) 📝 `runtime/xma_decoder/src/lib.rs` (+46 -5) 📝 `runtime/xma_decoder/tests/ffi_contract.rs` (+22 -0) 📝 `scripts/build_runtime.ps1` (+1 -1) 📝 `third_party/xma/NOTICE.md` (+2 -0) </details> ### 📄 Description Claimed in the coordination issue as: `RT-ACPHAL-XMA2` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121796272) Depends on: #357 ### What and why - Replaces the `acphal.dll` stub with an ACP command and message queue and a worker that fills SHAPE XMA PCM rings. The worker follows packet skips and refill order, updates shared fields atomically, and bounds each pass to the ring. Repeated enables preserve queued PCM for the same format and reset it when the format changes. - CMake builds the Rust decoder in `runtime/xma_decoder` at configure time through Cargo. The shim outputs silence based on each packet's frame count when Cargo is missing, the build fails, or the direct `cl.exe` fallback is used. Windows runtime CI explicitly requires the decoder. - The hardware constructor keeps the first frame and leaves start skipping to the XMA context. The decoder consumes 2048-byte packets, so read and loop points are rounded to packet boundaries. A loop plays its end packet in full and restarts with a fresh decoder at the start packet. The loop-end subframe is ignored. - Each worker uses its own `std::jthread` stop token. A worker memory failure reports an error for the affected voice. SHAPE allocation publishes a complete table or returns `E_OUTOFMEMORY`. Release detaches the worker, then frees the process-wide arrays without writing through the opaque HAL handle. - APU mappings stay stable after explicit heap configuration. Each voice reuses contiguous PCM storage while consuming its packets. ### Tested - MSVC 19.44.35230 and Windows SDK 10.0.26100 built and linked `gta6rt` and `acphal_test` in Debug and Release with Rust. A separate CMake configuration built `acphal_test` with the silence fallback in both build types. CTest passed in all four configurations, with 170 checks per normal run with Rust, 166 with silence, and 14 for the separate non-cached-only case in each configuration. - MSYS2 Clang 23.1.3 passed three normal runs and the non-cached-only case in both decoder modes. Synthetic tests cover exact PCM block counts, non-silent Rust output across loop rewinds and refills, mono and stereo at all four rates, ring bounds, and allocation failure. In MSVC Release with the silence fallback, a six-frame input required 1 C++ worker allocation, down from 208 on snapshot `4e9407a40`. - Cargo and rustc 1.97.1 passed formatting and all 10 Rust tests on both `x86_64-pc-windows-msvc` and `x86_64-pc-windows-gnullvm`, including a first-frame test for the hardware constructor. Locked release builds succeeded on both targets. - Python 3.14.2 and pytest 9.0.2 passed 204 tests and 200 subtests, with 3 skipped. The game-data check passed. - With an empty offline Cargo cache and an older archive present, the optional CMake build selected the silence fallback. The configuration requiring Rust failed as expected. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — audio decoder & runtime shim only) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:56 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#457
No description provided.