acphal: reuse freed APU heap blocks and report the 20-byte heap state #410

Merged
glovepost merged 1 commit from upstream-pr/410 into main 2026-11-29 01:31:53 +00:00
glovepost commented 2026-11-28 20:43:53 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-28T20:43:53Z.


Summary

The APU heap only ever grew. ApuFree and AcpHalReleaseShapeContexts returned success without freeing anything, and ApuHeapGetState wrote two u32 counters.

  • ApuFree now returns a block to a first-fit free list and merges it with its free neighbours. AcpHalReleaseShapeContexts gives the XMA context array back to the heap.
  • ApuHeapGetState fills the 20-byte heap state: free, allocated and lost bytes, the largest free block, and the allocation count.
  • ApuCreateHeap sizes the heap from both of its size arguments, cached and non-cached. ApuIsVirtualAddressValid checks the range against live allocations.
  • AcpHalAllocateShapeContexts treats the SHAPE context record as 0x60 bytes and also writes the XMA array's 32-bit APU address at offset 0x58.
  • xapu: completions of process commands fill the result offsets, and control completions keep the caller's fields.

The record and state layouts come from a clean-room comparison with the GDKX 2026.10 headers. No retail trace has confirmed them yet, so the README still marks DSP/XMA decoding as incomplete. The README now describes the free list and the release path.

Tests are in runtime/acphal/src/tests/lib.rs and runtime/xapu/src/tests/commands.rs. They cover merging adjacent free blocks, the state layout and alignment, the SHAPE record writes, and both completion paths. Each fails on main, where the functions or fields it checks don't exist.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both: "Another provider under runtime/" needs its suite on any card.

No Lanes scenario: Lanes doesn't load AcpHal or xapu. The xapu verify suite covers xapu, and acphal has no guest suite.

GPU, driver and backend: NVIDIA GeForce RTX 2070 SUPER, driver 620.73.04, GE-Proton11-14

Commands run and their results:

python tuxbox.py check --no-gpu                      passed (Python, shader compiler, DXBC, XG layout, storage codec, D3D12 Windows typecheck)
cargo test --locked --target x86_64-unknown-linux-gnu -p tuxbox-acphal -p tuxbox-xapu   4 passed
cargo check --locked --tests --target x86_64-pc-windows-msvc -p tuxbox-acphal -p tuxbox-xapu   clean
python tuxbox.py verify --only xapu --backend proton --adapter 10de:1e84   PASS  xapu PASS Opus=960 pre-skip=312 output=648 queue=ordered

AI use: Claude Code ported this from a local branch, moved the tests into src/tests, wrote the README change and ran the checks above. glovepost published it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5544398149 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/410). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-28T20:43:53Z. --- ## Summary The APU heap only ever grew. `ApuFree` and `AcpHalReleaseShapeContexts` returned success without freeing anything, and `ApuHeapGetState` wrote two `u32` counters. - `ApuFree` now returns a block to a first-fit free list and merges it with its free neighbours. `AcpHalReleaseShapeContexts` gives the XMA context array back to the heap. - `ApuHeapGetState` fills the 20-byte heap state: free, allocated and lost bytes, the largest free block, and the allocation count. - `ApuCreateHeap` sizes the heap from both of its size arguments, cached and non-cached. `ApuIsVirtualAddressValid` checks the range against live allocations. - `AcpHalAllocateShapeContexts` treats the SHAPE context record as `0x60` bytes and also writes the XMA array's 32-bit APU address at offset `0x58`. - xapu: completions of process commands fill the result offsets, and control completions keep the caller's fields. The record and state layouts come from a clean-room comparison with the GDKX 2026.10 headers. No retail trace has confirmed them yet, so the README still marks DSP/XMA decoding as incomplete. The README now describes the free list and the release path. Tests are in `runtime/acphal/src/tests/lib.rs` and `runtime/xapu/src/tests/commands.rs`. They cover merging adjacent free blocks, the state layout and alignment, the SHAPE record writes, and both completion paths. Each fails on `main`, where the functions or fields it checks don't exist. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both: "Another provider under `runtime/`" needs its suite on any card. No Lanes scenario: Lanes doesn't load AcpHal or xapu. The `xapu` verify suite covers xapu, and acphal has no guest suite. GPU, driver and backend: NVIDIA GeForce RTX 2070 SUPER, driver 620.73.04, GE-Proton11-14 Commands run and their results: ```text python tuxbox.py check --no-gpu passed (Python, shader compiler, DXBC, XG layout, storage codec, D3D12 Windows typecheck) cargo test --locked --target x86_64-unknown-linux-gnu -p tuxbox-acphal -p tuxbox-xapu 4 passed cargo check --locked --tests --target x86_64-pc-windows-msvc -p tuxbox-acphal -p tuxbox-xapu clean python tuxbox.py verify --only xapu --backend proton --adapter 10de:1e84 PASS xapu PASS Opus=960 pre-skip=312 output=648 queue=ordered ``` _AI use: Claude Code ported this from a local branch, moved the tests into `src/tests`, wrote the README change and ran the checks above. glovepost published it._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!410
No description provided.