xapu: decode Opus packets through a Rust sidecar (RT-XAPU-OPUS-DECODE) #2044

Merged
BubsMcgee merged 6 commits from upstream-pr/2044 into main 2026-11-26 14:41:03 +00:00
BubsMcgee commented 2026-11-25 18:54:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by BubsMcgee on 2026-11-25T18:54:19Z.


Claimed as RT-XAPU-OPUS-DECODE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170709281).

Depends on: #1144 (RT-XAPU-CONNECT-LAYOUTS). The branch is stacked on #1144 and also merges main (b9320a118): the #1144 head predates a slot-133 kernel_writes fix and crashed early in a retail boot without it. When #1144 lands, this reduces to the decoder alone.

What and why

#1144 keeps the xapu command queue and layouts and leaves fill_silence() for a decoder; this wires one in:

  • runtime/opus_decoder: a Rust C-ABI crate over BSD-3-Clause opus-pure, built by cargo like runtime/xma_decoder (-DLEONIDA_REQUIRE_OPUS_DECODER=ON requires it; -DLEONIDA_OPUS_DECODER_LIB=<path> links a prebuilt one).
  • xapu_queue.cpp::fill() decodes each process packet into f32 PCM, honouring first_frame, frame_count, output_bytes and the deinterleaved option; without cargo it keeps the table-of-contents frame count and silence.
  • A decoder is created on activate and destroyed on deactivate/disconnect.

The layouts stay #1144's (credited to Marvisak/VIctory apu.rs, GPL-3.0-or-later); no VIctory source is copied, and the new files use leonida names.

Tested

  • xapu_opus (new): 29/29. A generated 440 Hz stereo packet decodes to 960 frames / 0x1E00 bytes with energy; first_frame / frame_count / output_bytes clipping; empty, null and stray-stream errors; deactivate and reactivate.
  • xapu_chad (#1144's): passes unchanged (layouts + silent path).
  • acphal, acphal_noncached_only, xapu_chad, xapu_opus, xapu: 5/5 CTest.
  • Retail 1.0.2.1 boot, 121 s: full time, session d, 1905 presents, 32/32 non-black, no faults. The runtime logs xapu: connected for Opus decoding, 256 streams; packets decoded. RTX 3080 Ti, NVIDIA 616.64, Windows 11.
  • No game data.

Notes

  • The main merge is only for the slot-133 fix; it can be dropped on rebase after #1144 lands.
  • xapu.cpp is the legacy test-only shim; the runtime serves xapu from xapu_queue.cpp (#1144) and chad from xapu_chad.cpp.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497279937 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2044). Originally posted by [BubsMcgee](https://github.com/BubsMcgee) on 2026-11-25T18:54:19Z. --- Claimed as RT-XAPU-OPUS-DECODE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170709281). Depends on: #1144 (RT-XAPU-CONNECT-LAYOUTS). The branch is stacked on #1144 and also merges `main` (`b9320a118`): the #1144 head predates a slot-133 `kernel_writes` fix and crashed early in a retail boot without it. When #1144 lands, this reduces to the decoder alone. ## What and why #1144 keeps the xapu command queue and layouts and leaves `fill_silence()` for a decoder; this wires one in: - `runtime/opus_decoder`: a Rust C-ABI crate over BSD-3-Clause `opus-pure`, built by cargo like `runtime/xma_decoder` (`-DLEONIDA_REQUIRE_OPUS_DECODER=ON` requires it; `-DLEONIDA_OPUS_DECODER_LIB=<path>` links a prebuilt one). - `xapu_queue.cpp::fill()` decodes each process packet into f32 PCM, honouring `first_frame`, `frame_count`, `output_bytes` and the deinterleaved option; without cargo it keeps the table-of-contents frame count and silence. - A decoder is created on activate and destroyed on deactivate/disconnect. The layouts stay #1144's (credited to Marvisak/VIctory `apu.rs`, GPL-3.0-or-later); no VIctory source is copied, and the new files use leonida names. ## Tested - `xapu_opus` (new): 29/29. A generated 440 Hz stereo packet decodes to 960 frames / 0x1E00 bytes with energy; `first_frame` / `frame_count` / `output_bytes` clipping; empty, null and stray-stream errors; deactivate and reactivate. - `xapu_chad` (#1144's): passes unchanged (layouts + silent path). - `acphal`, `acphal_noncached_only`, `xapu_chad`, `xapu_opus`, `xapu`: 5/5 CTest. - Retail 1.0.2.1 boot, 121 s: full time, session `d`, 1905 presents, 32/32 non-black, no faults. The runtime logs `xapu: connected for Opus decoding, 256 streams; packets decoded`. RTX 3080 Ti, NVIDIA 616.64, Windows 11. - No game data. ## Notes - The `main` merge is only for the slot-133 fix; it can be dropped on rebase after #1144 lands. - `xapu.cpp` is the legacy test-only shim; the runtime serves xapu from `xapu_queue.cpp` (#1144) and chad from `xapu_chad.cpp`. AI-assisted.
BubsMcgee commented 2026-11-25 18:56:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by BubsMcgee on 2026-11-25T18:56:18Z.


CI shows action_required on No Game Data, Runtime and CI (the fork's first run needs a maintainer to approve it), so mergeStateStatus is UNSTABLE until then. Local verification on this head: xapu_chad_test 41/41, acphal / acphal_noncached_only / xapu_chad / xapu 4/4, and a 120 s retail boot (RTX 3080 Ti, NVIDIA 616.64) with 33/33 non-black frames and no faults. No game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7171605613 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2044#issuecomment-7171605613). Originally posted by [BubsMcgee](https://github.com/BubsMcgee) on 2026-11-25T18:56:18Z. --- CI shows `action_required` on **No Game Data**, **Runtime** and **CI** (the fork's first run needs a maintainer to approve it), so `mergeStateStatus` is UNSTABLE until then. Local verification on this head: `xapu_chad_test` 41/41, `acphal` / `acphal_noncached_only` / `xapu_chad` / `xapu` 4/4, and a 120 s retail boot (RTX 3080 Ti, NVIDIA 616.64) with 33/33 non-black frames and no faults. No game data.
BubsMcgee commented 2026-11-25 18:57:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by BubsMcgee on 2026-11-25T18:57:42Z.


Overlap found after opening: #1144 (RT-XAPU-CONNECT-LAYOUTS, @nicoco23) implements the same ConnectInput / 24-byte CommandId / 0x50-byte result layouts and moves xapu to runtime/shims/xapu_queue.cpp, deliberately leaving fill_silence() for a decoder. This PR currently touches xapu_chad.cpp and duplicates that layout work, so the two will conflict.

Plan: rebase this onto #1144 and keep only the Opus decode — runtime/opus_decoder (Rust over BSD-3 opus-pure) plus the decode call inside #1144's fill_silence(), keeping the zero-frame fallback. I will add Depends on: #1144 and force-push the reduced branch. If @nicoco23 would rather fold the decode into #1144, I can hand over the crate/CMake patch instead.

Holding the current head until that is settled. No game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7171635842 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2044#issuecomment-7171635842). Originally posted by [BubsMcgee](https://github.com/BubsMcgee) on 2026-11-25T18:57:42Z. --- Overlap found after opening: **#1144** (`RT-XAPU-CONNECT-LAYOUTS`, @nicoco23) implements the same `ConnectInput` / 24-byte `CommandId` / 0x50-byte result layouts and moves xapu to `runtime/shims/xapu_queue.cpp`, deliberately leaving `fill_silence()` for a decoder. This PR currently touches `xapu_chad.cpp` and duplicates that layout work, so the two will conflict. Plan: rebase this onto #1144 and keep only the Opus decode — `runtime/opus_decoder` (Rust over BSD-3 `opus-pure`) plus the decode call inside #1144's `fill_silence()`, keeping the zero-frame fallback. I will add `Depends on: #1144` and force-push the reduced branch. If @nicoco23 would rather fold the decode into #1144, I can hand over the crate/CMake patch instead. Holding the current head until that is settled. No game data.
BubsMcgee commented 2026-11-25 19:16:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by BubsMcgee on 2026-11-25T19:16:35Z.


Rebased onto #1144 and force-pushed (4cfbdfc0b). The layouts/queue are #1144's; this only adds runtime/opus_decoder and the decode in fill(), plus xapu_opus_test. xapu_chad_test (layouts + silence) is unchanged and still passes.

main was merged into the branch because the #1144 head predates the slot-133 kernel_writes fix; on the old base the runtime crashed at title_page_watch.h:662 in a retail boot before any XAPU call. With the merge: 121 s boot, session d, 1905 presents, no faults, and xapu: connected for Opus decoding, 256 streams; packets decoded.

CTest: acphal, acphal_noncached_only, xapu_chad, xapu_opus, xapu — 5/5. xapu_opus 29/29.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7172070805 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2044#issuecomment-7172070805). Originally posted by [BubsMcgee](https://github.com/BubsMcgee) on 2026-11-25T19:16:35Z. --- Rebased onto #1144 and force-pushed (`4cfbdfc0b`). The layouts/queue are #1144's; this only adds `runtime/opus_decoder` and the decode in `fill()`, plus `xapu_opus_test`. `xapu_chad_test` (layouts + silence) is unchanged and still passes. `main` was merged into the branch because the #1144 head predates the slot-133 `kernel_writes` fix; on the old base the runtime crashed at `title_page_watch.h:662` in a retail boot before any XAPU call. With the merge: 121 s boot, session `d`, 1905 presents, no faults, and `xapu: connected for Opus decoding, 256 streams; packets decoded`. CTest: `acphal`, `acphal_noncached_only`, `xapu_chad`, `xapu_opus`, `xapu` — 5/5. `xapu_opus` 29/29.
aslan2142 commented 2026-11-26 14:42:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-26T14:42:02Z.


Thank you, @BubsMcgee. This went into main through #2350 (RT-LINUX-AMD-WORLD), merged at your head 4cfbdfc0b with your commits and authorship kept, together with #1144 underneath it. It gave us the first decoded game audio on our machine. GitHub shows this PR as merged for that reason, so nothing needs closing.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7195195159 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2044#issuecomment-7195195159). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-26T14:42:02Z. --- Thank you, @BubsMcgee. This went into `main` through #2350 (RT-LINUX-AMD-WORLD), merged at your head `4cfbdfc0b` with your commits and authorship kept, together with #1144 underneath it. It gave us the first decoded game audio on our machine. GitHub shows this PR as merged for that reason, so nothing needs closing. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
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!2044
No description provided.