XAudio2: honor requested alignment for 32-bit APU addresses in ApuAlloc #1460
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1470"
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?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T16:36:24Z.
ApuAlloc(va, apu, size, alignment, flags)aligned the host VA viaalloc_aligned(size, alignment), butApu::address/Apu::find_free_rangehardcoded 4 KiB (0x1000) alignment for the returned 32-bit APU address. After any earlier smaller allocation advancedAPU.nextoff a larger boundary, a subsequentApuAllocrequestingalignment > 0x1000(e.g.0x20000) returned a misaligned APU address.This threads
alignmentthroughApu::address_alignedandApu::find_free_range, aligning candidate starts and overlap skips up toalignment.max(1).checked_next_power_of_two()?.max(0x1000)with checked arithmetic.What is in it
crates/xcl/src/hle/acphal.rs: addalignparameter toApu::find_free_range, addApu::address_alignedcalled byApuAlloc, and add unit testapu_alloc_honors_alignment_for_apu_address(verified failing before the fix withapu % 0x20000 == 0x1000).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 771 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib acphal: 8 passed, 0 failed (apu_alloc_honors_alignment_for_apu_addressfailed before the fix)Regression run
main:
PR:
Not tested
AI use
hle/acphal.rs, wrote the fix and unit test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:57:44Z.
Full-suite run, since this PR has no test report yet. Tested exact head
7fa09f3(on its baseb7aa9f3).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 771 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.apu_alloc_honors_alignment_for_apu_address.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 771 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:53:08Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
upstream-sync referenced this pull request2026-11-25 14:08:43 +00:00
Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T17:09:51Z.
amd-win test report for
7fa09f37(exact head7fa09f37b99fc8feef6a063f4f4d07cbb50b73cb) on AMD Radeon RX 7800 XTTested
main; the merged tree was not tested). Merges cleanly intoorigin/main55d64c27(git merge-tree)cargo test -p xcl --lib acphal: 8 passed, 0 failed (includes the newapu_alloc_honors_alignment_for_apu_address)cargo test --workspace -- --test-threads=4: 771 passed, 0 failed, 41 ignored; no SKIPPED lines printedRegression run (own test title
tests/testtitle, 60 s, release; same title and time for both. The test title exits with code 2 by design and shows no frames, socrashes: 1is its normal exit and is the same on both)PR head:
main(b7aa9f3):Not tested
mainAI use
oni-swr. No code was changed.Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:43:58Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T13:24:36Z.
merge-check claim
head:
7fa09f37b9Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T13:36:31Z.
merge-check
base:
9dfbe3ea66head:
7fa09f37b9merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored, 28 SKIPPED lines). 28 SKIPPED lines, as on the base. The new test
hle::acphal::tests::apu_alloc_honors_alignment_for_apu_addresspassed, as did the existing acphal tests.review: no blocking finding; one file, every hunk read.
ApuAllocaligned the host address to the requested alignment but handed out a 32-bit APU address aligned to a page only.find_free_rangenow takes the alignment (rounded up to a power of two, at least 0x1000), aligns the first candidate and each candidate after an overlap with checked arithmetic, andApuAllocpasses itsalignment; the other caller keeps page alignment throughaddress. For alignments up to a page the candidates are the same as before. One thing to know: a larger alignment can leave gaps below the aligned address; they are found again on the wrap toAPU_BASE. Not tested by me: a title that asks for an alignment above a page.performance: none to speak of.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T14:11:28Z.
merge-check
base:
9dfbe3ea66head:
7fa09f37b9merge: clean
build: cargo build --workspace -> ok (also
cargo build --release -p xcl)tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing:
gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it).hle::acphal::tests::apu_alloc_honors_alignment_for_apu_addressran and passed. WithApuAlloccalling the old page-alignedaddressagain, it fails atacphal.rs:1328(APU address 0x20000-aligned: left 4096, right 0); file restored after.review: one file, whole diff read.
find_free_range(acphal.rs:221) rounds the alignment up to a power of two and to at least a page (acphal.rs:225), the same roundingalloc_aligneduses for the host address (acphal.rs:276), so the two agree for odd values too. Candidate starts and overlap skips are aligned with checked adds; an overflow ends the search andApuAllocreturnsE_OUTOFMEMORYafter freeing the host memory (acphal.rs:317-320), as before.ApuMapVirtualAddressstill uses page alignment throughaddress. What the title asks for, measured: withXCL_TRACE_APU=1on the base and on the merge, the title makes threeApuAlloccalls in its menus, with alignments 0x100, 0x800 and 0x800, and gets the same APU addresses on both (0x10000000, 0x10006000, 0x10229000). No alignment above a page is requested there, so the changed path was not reached by the title.performance:
scripts/smoke.ps1, 60 s of a retail title, release: 1653 frames and 17995 MB peak commit against 1659 frames and 17322 MB on the base (today's base run after one warm-up). The traced pair: 1673 frames, 18272 MB against 1670 frames, 18142 MB on the base. No device removal, no crash in any of the four. Audio initialised as on the base: the sameacphalandxapulines (ApuCreateHeap, DSP connected with 128 streams, audio processor connected,xapu: decoder connectedwith 256 streams).verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests and smoke, reviewed the diff against the merged source and wrote this)
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:52:46Z.
Triage (#1607) – head
7fa09f3#939 makes the same
find_free_rangechange, rounding candidates to the requested alignment, which is passed fromApuAlloc. #939 also changes theApuMapVirtualAddress/ApuIsVirtualAddressValidABI, which this PR does not touch. If #939 is merged as is, this PR is superseded; if its ABI change is not taken, this is the alignment fix on its own. The change is not on main.No problems found in the diff:
align_upis checked, non-power-of-two alignments round up, andapu_alloc_honors_alignment_for_apu_addresschecks the APU address and the VA.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.