XAudio2: add lock-free hook trampoline lookup, atomic silent-voice fast path, and zero-copy decoded PCM #2683
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2683
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2683"
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?
@Decodere on GitHub · 2026-11-26 06:11 UTC · original
Decodere:fix-xaudio2-lockfree-dispatch-and-zerocopy-pcm→main· +225 −29 · 1 files · 1 commits · openWhat is in it
Removes per-call global mutex traffic, eliminates decoded PCM double-allocation/byte-copying, and replaces up-to-32 MiB decode-error heap allocations with the shared silence mapping in
crates/xcl/src/hle/xaudio2.rs:FastOriginals,FAST_ORIG_CAP = 32): Mirrors the first 32(vtable, slot, orig)entries published inpatch()intoFAST_ORIGINALS(Release/Acquirelen, while still pushing toORIGINALSso existing checks remain intact).original()now resolves patched slots lock-free without acquiringORIGINALS, falling back toORIGINALS.lock()only if the 32-slot cache is full.SILENT_LIVE_COUNT): Tracks live silent voices viaSILENT_LIVE_COUNT: AtomicUsizeupdated strictly while holding theXMAlock (create_source_voiceon.is_none(),destroy_voiceon.is_some()), allowingsubmit_source_bufferanddestroy_voiceto bypassXMA.lock()when zero silent voices exist.DecodedBuffer._pcm: Vec<i16>+prepare_decoded_pcm): Assertscfg!(target_endian = "little")at compile time and hands decodedVec<i16>buffers directly to XAudio2 without allocating a secondVec<u8>or copying 2 bytes per sample.prepare_decoded_pcmclamps whole frames withinXAUDIO2_MAX_BUFFER_BYTES, returnsNoneif fewer than 1 complete frame was decoded, and constructsBox::new(DecodedBuffer { ... })before readingboxed._pcm.as_ptr().silence()fallback (prepare_fallback_silence): On decode error or< 1decoded frame,submit_decoded_bufferpointsnb.audio_dataat the process-wide read-onlysilence()mapping with_pcm: Vec::new()(0 bytes heap allocated, never overwritingnb.audio_data/nb.audio_byteswhen_pcm.is_empty()), instead of allocating up toSILENCE_BYTES(32 MiB) on the heap.pcm16_for_rate,submit_decoded_bufferentry,get_state,DECODED_VOICESteardown, and existing tests untouched.Tested
origin/main(b49be183,cargo test -p xcl --lib "hle::xaudio2::tests::failing_first" -- --test-threads=1 --nocapture): confirmed pre-fixsubmit_decoded_bufferbyte-by-byte conversion copiedVec<i16>into a separate heap allocation (0x445320 != 0x445410) and did not reject< 1complete frame.XCL_ADAPTER=warp,XCL_WARP=1,cargo test -p xcl --lib "hle::xaudio2::tests::" -- --test-threads=1 --nocapture):12 passed; 0 failed; 0 ignored; 0 skipped(0.25s, including real Windows XAudio2 2.9 Opus & XMA2 decode/fallback andengine_from_the_system_dll; zero compiler warnings inxaudio2.rs).XCL_ADAPTER=warp,XCL_WARP=1,cargo test --release -p xcl --lib "hle::xaudio2::tests::" -- --test-threads=1 --nocapture):12 passed; 0 failed; 0 ignored; 0 skipped(1.28s).XAUDIO2_BENCH_NS):originallookup over 6 entries (200,000 iters):21.21 ns->3.65 ns(5.8xfaster, WARP run) /17.98 ns->3.74 ns(4.8xfaster, RTX run).4,365.6 ns->131.5 ns(33.2xfaster, WARP run) /2,203.0 ns->121.9 ns(18.1xfaster, RTX run).cargo clippy --all-targets):0new warnings incrates/xcl/src/hle/xaudio2.rs(only the 3 pre-existing lints on untouchedXAudio2Create,XAudio2CreateWithVersionInfo, andcreate_decoded_voice).cargo test --release -p xcl --lib "hle::xaudio2::tests::" -- --test-threads=1 --nocapture):12 passed; 0 failed; 0 ignored; 0 skipped(0.41s).Regression run
Full release workspace on RTX 4060 (
cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture):37test binaries,1438 passed; 0 failed; 47 ignored,29pre-existing environment-gatedSKIPPEDlines:21skipped:no wave64(RTX 4060 is wave32)3skipped: wave32per-lane form: refusedby driver (f16 arithmetic,f16 packed,f32 conversions)3skipped: no D3D12 debug layer (d3d12SDKLayers.dllunavailable on host: debug-layerdred: false/trueanduploads_start_from_each_subresources_state)1skipped:pso_measurement_compiles_an_exact_synthetic_record(cannot disable driver cache on Windows)1skipped:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)Paired 60 s RTX 4060 smoke capture (
scripts/smoke.ps1):Base (
origin/mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):PR (
c970f2257e0935d8e1c17f14e62d9aade3838ee4):Not tested
29host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows).AI use
Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, micro-benchmarks, and paired 60 s GPU smoke captures were executed directly in this workspace.
@luckyteagirl on GitHub · 2026-11-26 06:18 UTC · original · reviewed
At the new decoded-error path in
submit_decoded_buffer,prepare_fallback_silence()now requires the process-wide 32 MiBsilence()mapping. If thatVirtualAllocfails once,OnceLock<usize>permanently stores the null result, so every later decoded-error or short-frame fallback returnsE_FAILeven if memory becomes available. Before this PR, the decoded path allocated only the selected buffer'ssb.audio_bytesof silence (the PR's 480-stereo-frame case needs 1,920 bytes). Could the shared mapping stay the fast path while allocation failure falls back to a buffer-sized owned silence allocation or a retryable mapping? A test with an injectable failing mapping would cover the recovery case; the new test currently exercises only successful mapping.This is an exact-head source review of
c970f2257e0935d8e1c17f14e62d9aade3838ee4; I did not force an allocation failure or run a retail title. AI-assisted review with Codex.@luckyteagirl on GitHub · 2026-11-26 06:18 UTC · original · reviewed
The new
FAST_ORIG_CAPtest fills a localFastOriginalsto 32 entries and checks that an unknown key requests fallback. The lateroriginal()assertion uses a separate process-wide registry with just one patched entry, so the production lookup's overflow path (Err(())toORIGINALS) is never exercised. This test would still pass iforiginal()accidentally returnedNonefor every entry beyond the fast table. Could a fresh-process fixture register 33 distinct originals and assert thatoriginal()resolves both a mirrored key and the 33rd key (while an absent key stays absent), or could an injectable local fast/slow pair test the same path without polluting process-wide tables with short-lived stack vtables?This is an exact-head source review of
c970f2257e0935d8e1c17f14e62d9aade3838ee4; no runtime build was run. AI-assisted review with Codex.@SlopTart on GitHub · 2026-11-26 06:50 UTC · original · edited 2026-11-26 07:02 UTC
Tested on the Linux/Wine lane, full standard env (AMD rig: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT 20 GB, Arch kernel 7.2.15, Mesa 26.2.5 RADV, wine-11.0 Proton, rustc 1.94.0;
d3d12,d3d12core,dxgi,d3d11,d3d10core=n,boverrides, official DXC kit,VKD3D_CONFIG=ignore_shared_fence, threads=2), headc970f225, mergeable against mainb49be183:non-gpu suite (
--skip gpu::): 600 passed, 2 failed, 4 ignored, 733 filtered.The failure set is identical to bare main
b49be183measured on the same rig the same day (596 passed, 3 failed): gpu_promoted_uav_clear (our #2490), xma2_source_voice (#2481, vendored-FAudio gate). The third red, the sparse tile video-memory test, is a known batch flake (green solo; it did not reproduce in this run).Zero delta from this PR; every test it adds passes inside the suite.
Not tested: gpu suite, Windows native.
Correction: an earlier version of this row reported three extra reds; those runs lacked the
d3d12,d3d12core=n,bDLL overrides and hit stub-DLL NOTIMPL artifacts. Re-ran with the standard env, artifacts gone.AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.
@sage-sage on GitHub · 2026-11-26 07:05 UTC · original
Test report: passes on NVIDIA. Exact head
c970f225(its base is currentmainb49be18, so head = merged).Tested
cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the 3 new tests passmainon this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dllnot installed), 1no heap windows, 1pso_measurement_compiles_an_exact_synthetic_record(Developer Mode off)Not tested
Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.