HLE: update shared XMA context fields atomically and publish read offset before clearing valid #3290
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3290
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3290"
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?
@fuzeofficlal on GitHub · 2026-11-26 16:06 UTC · original
fuzeofficlal:fix/hle-xma-context-atomic-fields→main· +335 −7 · 1 files · 1 commits · openSummary
Fix concurrent lost-update races and release-ordering bugs on shared XMA hardware context words in
crates/victory-hle/src/modules/audio.rs:Atomic bitfield updates on shared XMA context words (
Context::get,Context::set_field):ADVANCE_XMA_READ).Context::set_fieldperformed a non-atomicread_volatile-> mask ->write_volatilesequence, which silently clobbered concurrent title atomic updates tovalid0/valid1and input bank packet counts (causing live streams to drop queued banks or fail permanently withINPUT_INVALID), and constituted a cross-thread data race without Acquire/Release synchronization.Contextnow accesses the 4-byte-aligned words in the live XMA context array viaAtomicU32(Acquireloads andAcqRel/Acquirefetch_updateCAS loops inset_field), preserving unrelated bitfields written concurrently and synchronizing buffer payloads with context flags.Publish
read_bitreset before clearingvalidon bank completion (decode):decodeclearedvalid[current]in word 0 before resetting word 2's read bit offset to0, allowing a title pollingvalid == 0to observe a stale non-zero read offset or have a freshly written offset overwritten.decodenow writes word 2's updated read offset before clearing the finished bank's valid bit withAcqRelordering.Testing
All verification runs executed on Windows (
cargo ... --locked), no game data used:crates/victory-hle/src/modules/audio.rs:xma_set_field_preserves_concurrent_atomic_updates_to_shared_wordsxma_double_buffered_streaming_preserves_concurrent_bank_refillsxma_end_of_input_updates_read_bit_before_clearing_valid63bcca43before the fix (lost valid1=9, lost input1 size=1114;lost valid1=224, lost input1 size=176;stale_read_bit=8in 0.09s) and pass after the fix.cargo test -p victory-hle --lib --locked modules::audio::tests::— 11 passed (plus 20/20 repeated stress runs of the three new tests).cargo test -p victory-hle --lockedand--all-features— 155 lib + integration tests passed.cargo clippy --workspace --all-targets --locked -- -D warnings(default and--all-features) — 0 warnings.cargo test -p xtask --locked policy::tests::repository_passes_policy— passed.@Dukestar69 on GitHub · 2026-11-26 16:07 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
Context::set_fieldwithAtomicU32::fetch_update(AcqRel/Acquire) and publishing the reset read offset (word 2) before clearing the bank valid bit (word 0) cleanly prevents lost concurrent bank updates and premature bank handoff.cargo test -p victory-hle --lib modules::audio:: -- --test-threads=1: 11 passed, 0 failed (includingxma_set_field_preserves_concurrent_atomic_updates_to_shared_words,xma_end_of_input_updates_read_bit_before_clearing_valid, andxma_double_buffered_streaming_preserves_concurrent_bank_refills).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@oni-swr on GitHub · 2026-11-26 16:55 UTC · original
Independent verification of #3290 (claimed on #1633). Test report only, no code changes. AI use: Claude Code (Claude Sonnet 5.5), run on behalf of oni-swr.
9ad6acbcaaf9d7a0d21190ed514cb8c163f925e0. Control:main=63bcca43c6a00a758510398fa43096ce7e4f7df0(the PR's merge base).modules::audio::filter with--test-threads=1, and had no control on main, so I did not treat it as covering this.cargo test -j 4 -p victory-hle --lib --lockedon head and on the control;cargo test -j 4 -p victory-hle --lockedon head; the 3 new tests run 10 times on head and 6 times on the control.use std::sync::atomic::{AtomicU32, Ordering};at the top ofaudio.rs, which the tests need). No source change.All three claimed tests exist at head:
xma_set_field_preserves_concurrent_atomic_updates_to_shared_words,xma_double_buffered_streaming_preserves_concurrent_bank_refills,xma_end_of_input_updates_read_bit_before_clearing_valid.Do they catch a real bug on main? Yes, all three, deterministically in 6 of 6 control runs. Failure messages on main:
lost valid1=434, lost input1 size=7329(set_field test),lost valid1=75, lost input1 size=368(double-buffered test), and a stale read-bit assertion in the third. The first two simulate the title's updates with their own atomic operations in the test, so what they prove is that the old volatile read-modify-write loses concurrent updates.No flakes seen in these runs. Not verified: real XMA data or a title, other CPUs or memory models, clippy and policy xtask.
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.