diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 09:16:29 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 09:16:29 -0500 |
| commit | 399ecdd511fe8499d2feb3681e82efda37ced17d (patch) | |
| tree | c6194830ee1d33870b9867329676c57366aff581 /docs | |
| parent | f5f67b4a9daae13d5a8a68358c1167e6866ec293 (diff) | |
| parent | 4cfbdfc0b2e39e9137b7f40c48863f1e0e444adc (diff) | |
Merge #2044 from BubsMcgee: decode Opus packets through a Rust sidecar (RT-XAPU-OPUS-DECODE), with #1144 from nicoco23: xapu.dll as a command queue (RT-XAPU-CONNECT-LAYOUTS)
Head 4cfbdfc0b, which contains #1144's head 6ee7ef89b.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/audio_hal_exe_calls.md | 20 | ||||
| -rw-r--r-- | docs/runtime_imports.md | 26 |
2 files changed, 34 insertions, 12 deletions
diff --git a/docs/audio_hal_exe_calls.md b/docs/audio_hal_exe_calls.md index c04943c7d..a500e16fc 100644 --- a/docs/audio_hal_exe_calls.md +++ b/docs/audio_hal_exe_calls.md | |||
| @@ -52,6 +52,26 @@ turns such an address back into a pointer. That is an inference from the shapes; | |||
| 52 | `XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue | 52 | `XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue |
| 53 | with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read. | 53 | with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read. |
| 54 | 54 | ||
| 55 | `runtime/shims/xapu_queue.cpp` serves the five `xapu.dll` imports and `runtime/shims/xapu_chad.cpp` the five | ||
| 56 | `chad.dll` ones. | ||
| 57 | The `xapu.dll` signatures, structure layouts, command kinds, option bits and error codes come from Marvisak/VIctory | ||
| 58 | (<https://github.com/Marvisak/VIctory>, GPL-3.0-or-later, `crates/victory-hle/src/modules/apu.rs` at commit `ffe310e`), | ||
| 59 | which runs the retail executable through these calls. Only the facts are used (see | ||
| 60 | [related_projects.md](related_projects.md)); the top of `xapu_queue.cpp` lists them. They agree with the shapes above: | ||
| 61 | |||
| 62 | | Shape measured here | What the layout says | | ||
| 63 | |---|---| | ||
| 64 | | `XApuConnect`: a 24-byte title global first, a 16-byte output second | the global is an input of six dwords (processing kind, streams, commands per stream, memory bytes, frames per output, options); the output is the zeroed memory and a result event | | ||
| 65 | | `XApuEnqueueCommand`: a stack-built command whose first dword is 1, 2 or 3 and second a stream slot, then 0 | a 24-byte command id (kind, stream, sequence, options, context): 1 activates, 2 deactivates, 3 processes an Opus packet; the third argument is an optional count of the commands accepted | | ||
| 66 | | `XApuDequeueResult`: a 0x50-byte result, read at +0, +4 and +0x34 | the command id at +0, the output byte count at +0x34; `0x8AC81001` while none is ready | | ||
| 67 | | `XApuDisconnect`: the handle, then `0x20` | the second argument is not read | | ||
| 68 | |||
| 69 | What the results carry is the shim's own: each accepted command gets one result in command order, with the error codes | ||
| 70 | of the layout. A process result carries the frame count and PCM when `runtime/opus_decoder` is built, and otherwise the | ||
| 71 | frame count of the Opus packet's table-of-contents byte (RFC 6716, section 3.1) with zeros in its output (silence). | ||
| 72 | `xapu_chad_test` covers the layouts and the silent path; `xapu_opus_test` covers the decoded path with a generated | ||
| 73 | packet. | ||
| 74 | |||
| 55 | ## `xg_xs.dll` and `XCRDAPI.dll` | 75 | ## `xg_xs.dll` and `XCRDAPI.dll` |
| 56 | 76 | ||
| 57 | | Import | Sites | What the sites show | | 77 | | Import | Sites | What the sites show | |
diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index e38dfbf74..e408d223d 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md | |||
| @@ -170,7 +170,7 @@ policy "other" (none is counted as returning an `HRESULT`), and they come from s | |||
| 170 | | `xg_xs.dll` | 2: `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | texture layout computation | | 170 | | `xg_xs.dll` | 2: `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | texture layout computation | |
| 171 | | `XCRDAPI.dll` | 1: `DStorageGetFactory` | DirectStorage | | 171 | | `XCRDAPI.dll` | 1: `DStorageGetFactory` | DirectStorage | |
| 172 | | `chad.dll` | 5: `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | the audio DSP | | 172 | | `chad.dll` | 5: `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | the audio DSP | |
| 173 | | `xapu.dll` | 5: `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | the audio processing unit | | 173 | | `xapu.dll` | 5: `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | the audio processing unit (Opus decode when `runtime/opus_decoder` is built) | |
| 174 | | `AcpHal.dll` | 9: `AcpHalAllocateShapeContexts`, `AcpHalCreate`, `AcpHalReleaseShapeContexts`, `ApuAlloc`, `ApuCreateHeap`, `ApuFree`, `ApuIsVirtualAddressValid`, `ApuMapApuAddress`, `ApuMapVirtualAddress` | the audio hardware layer | | 174 | | `AcpHal.dll` | 9: `AcpHalAllocateShapeContexts`, `AcpHalCreate`, `AcpHalReleaseShapeContexts`, `ApuAlloc`, `ApuCreateHeap`, `ApuFree`, `ApuIsVirtualAddressValid`, `ApuMapApuAddress`, `ApuMapVirtualAddress` | the audio hardware layer | |
| 175 | 175 | ||
| 176 | The game executable imports two functions from `xg_xs.dll`, the console's texture layout library: | 176 | The game executable imports two functions from `xg_xs.dll`, the console's texture layout library: |
| @@ -203,17 +203,19 @@ again at detach (reason 0), and there is no `exception`, `error` or `unimplement | |||
| 203 | unimplemented imports is reached by the TLS callbacks or the `DllMain`s. | 203 | unimplemented imports is reached by the TLS callbacks or the `DllMain`s. |
| 204 | 204 | ||
| 205 | The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, | 205 | The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, |
| 206 | `XApuEnqueueCommand`, `XApuGetResultCount`) and `chad.dll` (`XDspActivate`, `XDspConnectWithMaximumStreamLimit`, | 206 | `XApuEnqueueCommand`, `XApuGetResultCount`) are served by `runtime/shims/xapu_queue.cpp`; `chad.dll` |
| 207 | `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand`) are served by `runtime/shims/xapu_chad.cpp`. The shapes were | 207 | (`XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand`) by |
| 208 | read statically from the executable's call sites: one each, four for `XApuEnqueueCommand`. Both connects succeed with | 208 | `runtime/shims/xapu_chad.cpp`. The shapes were read statically from the executable's call sites: one each, four for |
| 209 | a handle; the APU connect also returns a zeroed shared buffer the title writes stream input to and reads output from. | 209 | `XApuEnqueueCommand`. `XApuConnect` reads the title's 24-byte `ConnectInput` (process 1 = Opus at 48 kHz, stream |
| 210 | Commands are accepted and not processed, so the audio stays silent. A stream open (type 1) and a stream close | 210 | count, commands per stream, a shared buffer, options) and returns `{shared buffer, result event}`; it never writes the |
| 211 | (type 2) each queue one result of the same type and slot, because the title frees a stream id only when the close | 211 | input. Activate, process, deactivate and reset commands are copied from the title's stack command, and each queues one |
| 212 | result arrives. `XDspActivate` writes its two outputs as pointers to zeroed memory, which the title reads as "command | 212 | result in order. A process command decodes its Opus packet through `runtime/opus_decoder` (Rust over the BSD-3-Clause |
| 213 | done" after each `XDspSubmitCommand`. `XApuConnect` leaves its first argument, a global of the title, untouched. The | 213 | `opus-pure`) into the slot's output, honouring first frame, frame count, output length and the deinterleaved option; |
| 214 | buffer size (128 stream slots), the two results and the zeroed DSP status are hypotheses, explained in the file. | 214 | without the crate the result carries the table-of-contents frame count and silence. The layouts follow Marvisak/VIctory |
| 215 | `xapu_chad_test` calls all ten in those shapes. With `--trace`, the first call of each, and the first command of each type, is an | 215 | `crates/victory-hle/src/modules/apu.rs` (GPL-3.0-or-later). `XDspActivate` writes its two outputs as pointers to zeroed |
| 216 | `audio_queue` event. | 216 | memory, which the title reads as "command done" after each `XDspSubmitCommand`; the DSP stays silent. `xapu_chad_test` |
| 217 | covers the layouts, the queue and the silent path; `xapu_opus_test` the decoded path. With `--trace`, the first call of | ||
| 218 | each, and the first command of each type, is an `audio_queue` event. | ||
| 217 | The table above was measured before this shim and still lists these ten as unimplemented; they are served now. The call shapes agree with `docs/audio_hal_exe_calls.md`, which was measured with `tools/import_call_sites.py`. | 219 | The table above was measured before this shim and still lists these ten as unimplemented; they are served now. The call shapes agree with `docs/audio_hal_exe_calls.md`, which was measured with `tools/import_call_sites.py`. |
| 218 | 220 | ||
| 219 | What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be | 221 | What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be |