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

Merged
Andretuta merged 10 commits from upstream-pr/404 into main 2026-11-24 13:44:46 +00:00
Andretuta commented 2026-11-24 04:44:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T04:44:01Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466227655 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/404). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T04:44:01Z. --- 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)
QemmHD commented 2026-11-24 14:10:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T14:10:31Z.


Post-merge check of main d0da7dade on Windows 11 / RTX 4070 SUPER (VS 2022, Ninja, RelWithDebInfo, cargo 1.98.0): the XMA2 decoder builds and links, the full build succeeds, and full ctest is 304/306 with the same two pre-existing failures as before (d3d12_execute_indirect_validation, d3d12_depth_resolve). The new acphal_noncached_only passes. Without cargo on PATH, configure prints "cargo not found" and skips the decoder, and acphal_test still passes 166/166.

Two supply-chain notes now that CMake builds this by default and CI requires it (LEONIDA_REQUIRE_XMA2_DECODER=ON, runtime.yml:260):

  1. The only dependency, xma, is a git dependency on a personal repo created 2026-11-21 (runtime/xma_decoder/Cargo.toml:13, rev 27122f7). Git sources get no checksum in Cargo.lock, so the commit hash is the only integrity check. If that repo is deleted or force-pushed, every cold build loses the decoder and CI fails. I read the pinned crate: it has no build.rs, no proc-macros, no unsafe, and no network or file access outside its tests, so it's fine today. Vendoring it, with cargo vendor or a fork under this org, would make the build reproducible. CMake runs cargo with --locked but not --offline (runtime/CMakeLists.txt:112-145), so a cold configure fetches from GitHub.
  2. Linking the Rust staticlib pulls Rust std's networking into gta6rt.exe: the cargo build now has a static WS2_32.dll import (getaddrinfo, connect, sendto, WSASocketW…) plus USERENV and bcryptprimitives, which the no-cargo build doesn't. The title can't reach them through the shim tables, so this isn't a leak, but it contradicts the "gta6rt needs no static ws2_32.lib link dependency" note in the ws2_offline.cpp header. That note, or the docs, should mention it.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7133956076 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/404#issuecomment-7133956076). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T14:10:31Z. --- Post-merge check of main d0da7dade on Windows 11 / RTX 4070 SUPER (VS 2022, Ninja, RelWithDebInfo, cargo 1.98.0): the XMA2 decoder builds and links, the full build succeeds, and full ctest is 304/306 with the same two pre-existing failures as before (d3d12_execute_indirect_validation, d3d12_depth_resolve). The new `acphal_noncached_only` passes. Without cargo on PATH, configure prints "cargo not found" and skips the decoder, and `acphal_test` still passes 166/166. Two supply-chain notes now that CMake builds this by default and CI requires it (`LEONIDA_REQUIRE_XMA2_DECODER=ON`, runtime.yml:260): 1. The only dependency, `xma`, is a git dependency on a personal repo created 2026-11-21 (`runtime/xma_decoder/Cargo.toml:13`, rev 27122f7). Git sources get no checksum in Cargo.lock, so the commit hash is the only integrity check. If that repo is deleted or force-pushed, every cold build loses the decoder and CI fails. I read the pinned crate: it has no build.rs, no proc-macros, no `unsafe`, and no network or file access outside its tests, so it's fine today. Vendoring it, with `cargo vendor` or a fork under this org, would make the build reproducible. CMake runs cargo with `--locked` but not `--offline` (`runtime/CMakeLists.txt:112-145`), so a cold configure fetches from GitHub. 2. Linking the Rust staticlib pulls Rust std's networking into gta6rt.exe: the cargo build now has a static `WS2_32.dll` import (getaddrinfo, connect, sendto, WSASocketW…) plus USERENV and bcryptprimitives, which the no-cargo build doesn't. The title can't reach them through the shim tables, so this isn't a leak, but it contradicts the "gta6rt needs no static ws2_32.lib link dependency" note in the `ws2_offline.cpp` header. That note, or the docs, should mention it. AI-assisted (Claude Code, Claude Opus 5.5).
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
ProjectLeonida/mandy!404
No description provided.