acphal: power-of-two alignment in ApuIsVirtualAddressValid; ApuAlloc(flags=2) gets the lazy default heap (RT-ACPHAL-ALIGNMENT-AND-LAZY-HEAP) #2535
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2535
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-acphal-alignment-lazy-heap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: RT-ACPHAL-ALIGNMENT-AND-LAZY-HEAP (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231475417)
What and why
Item 4 of @kevincommits' batch 18 in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231277215). Thanks for the repro.
runtime/shims/acphal.cpp, the audio hardware layer's APU heaps:ApuIsVirtualAddressValidwith an alignment that is not a power of two.ApuRegion::is_valid_addresstested((p - b) & (alignment - 1)) == 0for any alignment. That is an alignment test only for a power of two: with 6 (mask 5), offset 2 passed and offset 6 failed.ApuAllocalready refuses such an alignment (E_INVALIDARG). NowApuIsVirtualAddressValidandis_valid_addresstreat it as invalid too, and 0 still means 1. The title's own calls use 0x40, 0x80 and 0x800 (docs/audio_hal_exe_calls.md), which are unaffected.ApuAlloc(flags=2)beforeApuCreateHeap. With flags 0 or 1, the first allocation creates a 64 MiB default cached heap. With flags 2 (prefer non-cached), it fell back to the cached heap but did not create it, and returnedE_OUTOFMEMORY. The fallback now comes first, so flags 2 gets the same lazy default heap. Theg_apu_heap_createdguard stays: after an explicitApuCreateHeapthat left the cached heap out, it stays unavailable, whichacphal_noncached_onlychecks.Overlap: no open PR touches
acphal.cpp.Tested
Windows 11, MSVC (VS 18), RelWithDebInfo, on
main431ceba4f. CPU only.acphal_test:ApuIsVirtualAddressValidrefuses alignment 6 at offsets 2 and 6, and alignment 3. It keeps powers of two (offset 2 valid for 2, invalid for 4) and 0 as 1.--lazy-noncached(ctestacphal_lazy_noncached), since the heap configuration is per process:ApuCreateHeap,ApuAlloc(flags=2)succeeds with a valid, mapped block;flags=1allocation uses the same default heap;ApuCreateHeapafterwards fails as already created.main'sacphal.cpp: 2 checks fail in the default mode (the alignment cases) and 2 in--lazy-noncached(E_OUTOFMEMORYfor flags 2). With the fix:acphal173/173,acphal_noncached_only14/14,acphal_lazy_noncached14/14.scripts/check_no_game_data.py: clean.Not tested: a game boot (the title's first
ApuAlloccomes after itsApuCreateHeap, so the lazy path matters for other callers and orderings).GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU tests only)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Reviewed at head
0f43a7804on Windows 11 (MSVC 202219.44).Verification
acphal_test.acphal_test(default): 169/169 checks passed.acphal_test --lazy-noncached: 169/169 checks passed.Notes
ApuIsVirtualAddressValid(acphal.cpp:233-242,1180-1186) normalizes0to1and rejects non-powers of two before masking, matchingApuAlloc(1108-1119), with 64-bit rounding/bounds math (262-277).g_apu_mutex(1124-1159) cleanly routes first-useApuAlloc(flags=2)to the lazy default heap while preserving explicit heap behavior.Approve.
AI-assisted review + local MSVC verification.
#2535 | head 0f43a7804beec409cb294cfe7c866c3fca03f8bb (merged cleanly with main 6dfca642807631bbe41d6925f152529f99c71ce2) |
ctest --test-dir runtime/build -C RelWithDebInfo -R "^(acphal|acphal_noncached_only|acphal_lazy_noncached|xapu_chad)$" --output-on-failure| red on main:acphal_testfails (173 checks, 2 failures:ApuIsVirtualAddressValidaccepts non-power-of-twoalignment=6at unaligned offset2because(2 & 5) == 0);acphal_test --lazy-noncachedfails (14 checks, 2 failures:ApuAllocwithflags=2beforeApuCreateHeapreturnedE_OUTOFMEMORYinstead of creating the lazy default cached heap) | green on PR+main:4/4CTests pass (acphal173/173in0.58s,acphal_lazy_noncached14/14in0.03s,acphal_noncached_only14/14in0.04s,xapu_chad0failures);check_no_game_data.py0violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yesTested
0f43a7804merged (no commit) withmainaa918e5d9. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), RelWithDebInfo, Ninja.acphal,acphal_noncached_onlyand the newacphal_lazy_noncachedpass (3/3).runtime/shims/acphal.cppback tomain,acphalandacphal_lazy_noncachedfail:ApuIsVirtualAddressValid refuses alignment 6 (unaligned offset 2)ApuIsVirtualAddressValid refuses any alignment that is not a power of twoApuAlloc flags=2 before ApuCreateHeap gets the lazy default heapThe flags=2 block is valid and mappedxbox_present, which fails the same way on plainmainon this machine. The rest pass or skip (environment-dependent skips, as onmain).No blocker from my side. AI-assisted (Claude Code).
Merged after TheGeogeo's red/green check (check:
acphal,acphal_noncached_onlyandacphal_lazy_noncachedpass with this PR,acphalandacphal_lazy_noncachedfail withmain'sacphal.cpp; no regression over 304 relinked tests) and a re-check here: no conflict withmainadfb3821a, same head as checked,no-game-datagreen, and the Windows CI job passes all threeacphaltests. The red jobs come from elsewhere:vk_xdxr_postbuild_readback(Windows) andvk_bindless_dimensions(macOS) are Vulkan tests this diff does not touch, and the Python jobs fail onmaintoo.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.