acphal: allocate all SHAPE contexts and stop faking the ACP channel #511

Merged
csj0oe merged 3 commits from upstream-pr/511 into main 2026-11-30 19:33:05 +00:00
csj0oe commented 2026-11-29 18:08:53 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-29T18:08:53Z.


What

AcpHalCreate returned a 32-slot vtable whose every method returned S_OK, so Connect and SubmitCommand succeeded while audio commands vanished. AcpHalAllocateShapeContexts handled only XMA and returned E_NOTIMPL for any PCM/SRC/EQ/DMA counts.

  • SHAPE_CONTEXTS is declared in runtime/acphal/abi.h and pinned by static_asserts: six context arrays allocated, validated and released.
  • IAcpHal is a real six-slot implementation. A second allocation returns ACP_E_ALREADY_ALLOCATED instead of S_OK.
  • Connect, SubmitCommand and Disconnect keep the S_OK results earlier builds reported, so the title's audio path behaves as before; each writes one warning naming the call and its arguments that the ACP command queue is not implemented. PopMessage still returns false and GetNumMessages zero.
  • New acphal-control.exe proves invalid shapes fail, XMA and all-six shapes pass, and heap bytes match the declared sizes. It is wired as a tuxbox.py verify --only acphal gate.

Verification

  • Failing first: the same control against the pre-change DLL fails at hr == ACP_E_ALREADY_ALLOCATED (hr=0x00000000).
  • After: acphal PASS shapes=xma,all-six,invalid,max-xma channel=honest.
  • 13 Rust tests pass; cargo check --target x86_64-pc-windows-msvc -p tuxbox-acphal --tests passes.
  • PASS acphal under Proton GE; python tuxbox.py check --no-gpu 10/10.

The analysis this came from also had the ACP error values wrong; the declaration pins 0x8AC80001, 0x8AC80002 and 0x8AC8000A.

Not covered

  • The ACP command queue itself is not implemented. The three calls succeed with a warning so audio start-up is unchanged; a game run with sound is still the check before merge.
  • The title's three AcpHalReleaseShapeContexts call sites and ACP_E_NOT_ALLOCATED on a second release were not traced in a Frosty teardown.
  • The Rust tests were typechecked for Windows but executed on Linux only; the guest ran under Proton GE.
  • ApuCreateHeap and ApuAlloc are unchanged and outside this change.
<!-- greyfinch-sync:brcly/TuxBox:issue:5553586312 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-29T18:08:53Z. --- ## What `AcpHalCreate` returned a 32-slot vtable whose every method returned `S_OK`, so `Connect` and `SubmitCommand` succeeded while audio commands vanished. `AcpHalAllocateShapeContexts` handled only XMA and returned `E_NOTIMPL` for any PCM/SRC/EQ/DMA counts. - `SHAPE_CONTEXTS` is declared in `runtime/acphal/abi.h` and pinned by `static_assert`s: six context arrays allocated, validated and released. - `IAcpHal` is a real six-slot implementation. A second allocation returns `ACP_E_ALREADY_ALLOCATED` instead of `S_OK`. - `Connect`, `SubmitCommand` and `Disconnect` keep the `S_OK` results earlier builds reported, so the title's audio path behaves as before; each writes one warning naming the call and its arguments that the ACP command queue is not implemented. `PopMessage` still returns false and `GetNumMessages` zero. - New `acphal-control.exe` proves invalid shapes fail, XMA and all-six shapes pass, and heap bytes match the declared sizes. It is wired as a `tuxbox.py verify --only acphal` gate. ## Verification - Failing first: the same control against the pre-change DLL fails at `hr == ACP_E_ALREADY_ALLOCATED (hr=0x00000000)`. - After: `acphal PASS shapes=xma,all-six,invalid,max-xma channel=honest`. - 13 Rust tests pass; `cargo check --target x86_64-pc-windows-msvc -p tuxbox-acphal --tests` passes. - `PASS acphal` under Proton GE; `python tuxbox.py check --no-gpu` 10/10. The analysis this came from also had the ACP error values wrong; the declaration pins `0x8AC80001`, `0x8AC80002` and `0x8AC8000A`. ## Not covered - The ACP command queue itself is not implemented. The three calls succeed with a warning so audio start-up is unchanged; a game run with sound is still the check before merge. - The title's three `AcpHalReleaseShapeContexts` call sites and `ACP_E_NOT_ALLOCATED` on a second release were not traced in a Frosty teardown. - The Rust tests were typechecked for Windows but executed on Linux only; the guest ran under Proton GE. - `ApuCreateHeap` and `ApuAlloc` are unchanged and outside this change.
brcly commented 2026-11-29 20:37:58 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T20:37:58Z.


Thanks. Allocating every SHAPE context properly and returning ACP_E_ALREADY_ALLOCATED for a second allocation both look right.

The part that holds it: Connect now returns E_NOTIMPL, which by your own description makes a title's audio init fail where it used to succeed silently. ProjectScarlett has working audio on main today, so before we merge this we need a game run showing it still starts and still has sound with this change. If it does call Connect, I'd keep the current behaviour (or log loudly instead of failing) until the ACP queue is implemented, and land the context allocation on its own.

<!-- greyfinch-sync:brcly/TuxBox:comment:7262235399 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7262235399). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T20:37:58Z. --- Thanks. Allocating every SHAPE context properly and returning `ACP_E_ALREADY_ALLOCATED` for a second allocation both look right. The part that holds it: `Connect` now returns `E_NOTIMPL`, which by your own description makes a title's audio init fail where it used to succeed silently. ProjectScarlett has working audio on `main` today, so before we merge this we need a game run showing it still starts and still has sound with this change. If it does call `Connect`, I'd keep the current behaviour (or log loudly instead of failing) until the ACP queue is implemented, and land the context allocation on its own.
brcly commented 2026-11-29 21:11:45 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T21:11:45Z.


Thanks, this addresses what I raised. It conflicts with main now (after tonight's merges); could you rebase it? Then we'll run it through the check and merge.

<!-- greyfinch-sync:brcly/TuxBox:comment:7262680894 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7262680894). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T21:11:45Z. --- Thanks, this addresses what I raised. It conflicts with `main` now (after tonight's merges); could you rebase it? Then we'll run it through the check and merge.
brcly commented 2026-11-29 22:03:02 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:03:02Z.


Heads-up: we rewrote main's history tonight (one commit per merged PR, to drop files that came in with intermediate commits), and this branch is still based on the old main (on the old #512 merge, 39463ea5). That's why GitHub now shows it with dozens of commits that aren't yours. Your own commits are the ones after 39463ea5; this replays only those onto the new main:

git fetch origin
git rebase --onto origin/main 39463ea5
git push --force-with-lease

Sorry for the extra step.

<!-- greyfinch-sync:brcly/TuxBox:comment:7263360342 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7263360342). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T22:03:02Z. --- Heads-up: we rewrote `main`'s history tonight (one commit per merged PR, to drop files that came in with intermediate commits), and this branch is still based on the old `main` (on the old #512 merge, `39463ea5`). That's why GitHub now shows it with dozens of commits that aren't yours. Your own commits are the ones after `39463ea5`; this replays only those onto the new `main`: ```sh git fetch origin git rebase --onto origin/main 39463ea5 git push --force-with-lease ``` Sorry for the extra step.
brcly commented 2026-11-30 04:12:26 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:26Z.


Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase.

  • Formatting: the whole workspace is now formatted with rustfmt (see the new rustfmt.toml).
  • Lints: every crate denies unwrap(), lossy as casts and undocumented unsafe outside tests.
  • CI: it now also runs cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.

The least painful way is to format your branch first, so the rebase only shows real changes:

git fetch origin
git checkout origin/main -- rustfmt.toml
cargo fmt --all && git commit -am "rustfmt"
git rebase origin/main

Then run python tuxbox.py check --no-gpu, which now includes the format step.

If clippy flags something new:

  • A cast: use From for widening, TryFrom for narrowing, and a mask for bit fields.
  • An unwrap(): use ?, or expect with the reason it can't fail.
  • An unsafe block: it needs a // SAFETY: comment.

CONTRIBUTING's "Code checks" section lists the commands. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7268564072 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7268564072). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:26Z. --- Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase. - **Formatting:** the whole workspace is now formatted with rustfmt (see the new `rustfmt.toml`). - **Lints:** every crate denies `unwrap()`, lossy `as` casts and undocumented `unsafe` outside tests. - **CI:** it now also runs `cargo fmt --check`, rustdoc with warnings denied, and Miri on the providers' unit tests. The least painful way is to format your branch first, so the rebase only shows real changes: ```sh git fetch origin git checkout origin/main -- rustfmt.toml cargo fmt --all && git commit -am "rustfmt" git rebase origin/main ``` Then run `python tuxbox.py check --no-gpu`, which now includes the format step. If clippy flags something new: - **A cast:** use `From` for widening, `TryFrom` for narrowing, and a mask for bit fields. - **An `unwrap()`:** use `?`, or `expect` with the reason it can't fail. - **An `unsafe` block:** it needs a `// SAFETY:` comment. CONTRIBUTING's "Code checks" section lists the commands. Thanks!
brcly commented 2026-11-30 09:52:23 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:52:23Z.


Thanks for the rebase. The behaviour is now what we discussed. One thing blocks the merge, though, and one is still outstanding.

1. abi.h has to be in our own words. The new header's type, field and constant names, its error-code names, the order of its declarations, and its reference to "the two heaps apu.h describes" all match the GDK's own headers name for name. Those headers are under a confidentiality notice, and the project copies nothing from them (see AGENTS.md: GDK material stays out of the repository). The binary layout itself is an interoperability fact we can state: the sizes, offsets, the slot order and the result values. But please:

  • name the fields and constants in our own style (as the Rust side in src/lib.rs already does), not the SDK's;
  • drop the references to SDK header files, and describe each fact by what the title does or what we observed;
  • apply the same to the Rust doc comments and the README where they use the same names.

2. Still needed: a game run with sound, as the PR's own "Not covered" section says. Once the header is reworked I'll boot ProjectScarlett with it myself, check that audio starts and plays, and look for the new warnings in the log.

<!-- greyfinch-sync:brcly/TuxBox:comment:7274801438 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7274801438). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T09:52:23Z. --- Thanks for the rebase. The behaviour is now what we discussed. One thing blocks the merge, though, and one is still outstanding. **1. `abi.h` has to be in our own words.** The new header's type, field and constant names, its error-code names, the order of its declarations, and its reference to "the two heaps apu.h describes" all match the GDK's own headers name for name. Those headers are under a confidentiality notice, and the project copies nothing from them (see AGENTS.md: GDK material stays out of the repository). The binary layout itself is an interoperability fact we can state: the sizes, offsets, the slot order and the result values. But please: - name the fields and constants in our own style (as the Rust side in `src/lib.rs` already does), not the SDK's; - drop the references to SDK header files, and describe each fact by what the title does or what we observed; - apply the same to the Rust doc comments and the README where they use the same names. **2. Still needed:** a game run with sound, as the PR's own "Not covered" section says. Once the header is reworked I'll boot ProjectScarlett with it myself, check that audio starts and plays, and look for the new warnings in the log.
csj0oe commented 2026-11-30 10:04:43 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-30T10:04:43Z.


Reworked, second commit 503929f7, layout unchanged.

  • abi.h now names everything in this repository's style: apu_context_set with src_count … pcm_count, src_host … pcm_host, src_apu … pcm_apu, the kind sizes as src_context/eq_comp_context/…, MAX_*_CONTEXTS, ACP_ALREADY_ALLOCATED/ACP_NOT_ALLOCATED/ACP_NOT_CONNECTED, acp_message, acp_channel, apu_heap_state. The export names stay as they are because those strings are the ABI.
  • No comment cites a header file any more. Each fact says what the title or the control does: which call allocates the defaults first, what a zero cached size returns, where the XMA pointer and its APU address sit, which heap SHAPE contexts come from. The declarations are ordered heap-first rather than mirroring anyone's file.
  • Same treatment in abi.cpp, guest.cpp, the README and the Rust doc comments (including the apu.h citations in src/lib.rs and the tests), which is where the field names were repeated.

Measured: python build.py acphal, then the control under GE-Proton prints acphal PASS shapes=xma,all-six,invalid,max-xma channel=honest; 13 Rust tests pass on the Linux target; Windows typecheck passes; check --no-gpu is 11 passed, 1 failed, the failure being the pre-existing redundant_clone at runtime/dxbc/src/fssm.rs:121 that this branch does not touch.

On your second point I have no audio evidence of my own to add, so I will leave the boot to you rather than guess at it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7275085019 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7275085019). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-30T10:04:43Z. --- Reworked, second commit `503929f7`, layout unchanged. - `abi.h` now names everything in this repository's style: `apu_context_set` with `src_count` … `pcm_count`, `src_host` … `pcm_host`, `src_apu` … `pcm_apu`, the kind sizes as `src_context`/`eq_comp_context`/…, `MAX_*_CONTEXTS`, `ACP_ALREADY_ALLOCATED`/`ACP_NOT_ALLOCATED`/`ACP_NOT_CONNECTED`, `acp_message`, `acp_channel`, `apu_heap_state`. The export names stay as they are because those strings are the ABI. - No comment cites a header file any more. Each fact says what the title or the control does: which call allocates the defaults first, what a zero cached size returns, where the XMA pointer and its APU address sit, which heap SHAPE contexts come from. The declarations are ordered heap-first rather than mirroring anyone's file. - Same treatment in `abi.cpp`, `guest.cpp`, the README and the Rust doc comments (including the `apu.h` citations in `src/lib.rs` and the tests), which is where the field names were repeated. Measured: `python build.py acphal`, then the control under GE-Proton prints `acphal PASS shapes=xma,all-six,invalid,max-xma channel=honest`; 13 Rust tests pass on the Linux target; Windows typecheck passes; `check --no-gpu` is 11 passed, 1 failed, the failure being the pre-existing `redundant_clone` at `runtime/dxbc/src/fssm.rs:121` that this branch does not touch. On your second point I have no audio evidence of my own to add, so I will leave the boot to you rather than guess at it.
brcly commented 2026-11-30 19:13:29 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T19:13:29Z.


Thanks, abi.h reads as our own now: none of its names follow the SDK's.

One leftover: the two Rust constants this PR adds in src/lib.rs, ACP_E_ALREADY_ALLOCATED and ACP_E_NOT_ALLOCATED, keep the SDK's spelling. Please name them like their abi.h counterparts (ACP_ALREADY_ALLOCATED, ACP_NOT_ALLOCATED). The older SDK-style names already on main (APU_E_HEAP_* and others) predate this PR and are ours to clean up separately.

After that, I'll do the audio boot I promised and merge if sound starts and plays.

<!-- greyfinch-sync:brcly/TuxBox:comment:7289040769 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/511#issuecomment-7289040769). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T19:13:29Z. --- Thanks, `abi.h` reads as our own now: none of its names follow the SDK's. One leftover: the two Rust constants this PR adds in `src/lib.rs`, `ACP_E_ALREADY_ALLOCATED` and `ACP_E_NOT_ALLOCATED`, keep the SDK's spelling. Please name them like their `abi.h` counterparts (`ACP_ALREADY_ALLOCATED`, `ACP_NOT_ALLOCATED`). The older SDK-style names already on `main` (`APU_E_HEAP_*` and others) predate this PR and are ours to clean up separately. After that, I'll do the audio boot I promised and merge if sound starts and plays.
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
brcly/TuxBox!511
No description provided.