hle(dsp): synchronize XDspSubmitCommand and publish Status atomically #3319
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!3319
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3319"
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 17:29 UTC · original
fuzeofficlal:fix/hle-dsp-status-atomic-sync→main· +333 −22 · 1 files · 1 commits · openSummary
Fix cross-thread undefined behavior, lost command tickets, and backward
Status.completedregressions in thechad.dllaudio DSP HLE (crates/victory-hle/src/modules/dsp.rs).Root Cause
XDspActivatehands title code a*const Statuspointer that other threads poll forcompletedandresult. Previously:XDspSubmitCommandforged unique&mut *streamand&mut *stream.statusborrows while other threads concurrently polled*const Statusor submitted commands, andXDspActivatetook&*new.statusbefore movingnewintoBox::into_raw.Statusstored plainu32/HRESULTfields updated viaptr::write_volatile, which is neither atomic (causing cross-thread data-race UB) nor anOrdering::Releasefence ensuring zeroedcommand.outputbuffers andresultare visible beforecompletedadvances.status.submittedand multi-word volatile stores under concurrentXDspSubmitCommandcalls dropped ticket increments, issued duplicate tickets, and allowed delayed threads to overwritecompletedwith older smaller ticket numbers.Fix
#[repr(C)] Statusfields toAtomicU32/AtomicI32and enforce the exact 16-byte / 4-byte-aligned C ABI layout (offsets 0, 4, 8, 12) with compile-time assertions.submit: Mutex<u32>to serializeXDspSubmitCommandsubmissions, output buffer zeroing, and status publication.XDspActivate, callBox::into_raw(new)before deriving*const Statusviastd::ptr::from_ref(&*(*raw).status).XDspSubmitCommand, borrow(&*stream, &*command)instead of&mut *stream, advance the ticket understream.submit, storesubmitted(Release), zerocommand.output, storeresult(Relaxed), publishcompleted(Release), drop the lock, and write the optional*ticketout-parameter.Testing
Added deterministic
Barrier-synchronized regression tests incrates/victory-hle/src/modules/dsp.rs:concurrent_submit_commands_issue_unique_monotonic_tickets: reproduces lost/duplicate tickets onmain(8491 != 32000) and verifies all32,000concurrent submissions receive unique sequential tickets1..=32000.status_poller_observes_monotonic_completion_and_zeroed_output: reproduces backwardcompletedregression onmain(completed regressed from 51 to 50) and verifies monotoniccompleted <= submittedplus cross-threadAcquire/Releasevisibility of every zeroed output block.status_abi_layout_and_ticket_wraparound: verifiesStatusC ABI layout andu32::MAX -> 0 -> 1ticket wraparound.Verified with:
rustfmt --check --edition 2024 crates/victory-hle/src/modules/dsp.rscargo test -p victory-hle --lib --locked dsp::testscargo test -p victory-hle --lockedandcargo test -p victory-hle --all-features --lockedcargo clippy --workspace --all-targets --locked -- -D warnings(default and--all-features)cargo test -p xtask --locked policy::tests::repository_passes_policy@cloph-dsp on GitHub · 2026-11-26 17:39 UTC · original
Independent local verification of PR #3319 (
hle(dsp): synchronize XDspSubmitCommand and publish Status atomically), head573c13c0ae.cargo test --locked,CARGO_BUILD_JOBS=2,CARGO_TARGET_DIRlocal to the worktree (D:\Victory-Contrib\target-3319).cargo test --locked -p victory-hle --lib -- --exact modules::dsp::tests::concurrent_submit_commands_issue_unique_monotonic_tickets modules::dsp::tests::status_poller_observes_monotonic_completion_and_zeroed_output modules::dsp::tests::status_abi_layout_and_ticket_wraparound-> 3 passed, 0 failed, 152 filtered, exit 0.git diff --check origin/main HEAD-> clean.63bcca43...), so they are genuinely added by this PR.AI-assisted (Hy4 flash). GPU/driver: N/A for these CPU tests. No game data used.
@Dukestar69 on GitHub · 2026-11-26 17:49 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
Statusfields toAtomicU32/AtomicI32(with compile-time size/align/offset assertions), serializingXDspSubmitCommandviaStream::submit, and deriving the publishedstatuspointer afterBox::into_rawcleanly eliminates data races and aliasing UB.cargo test -p victory-hle --lib modules::dsp:: -- --test-threads=1: 4 passed, 0 failed (includingconcurrent_submit_commands_issue_unique_monotonic_tickets,status_abi_layout_and_ticket_wraparound, andstatus_poller_observes_monotonic_completion_and_zeroed_output).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 17:55 UTC · original
Independent verification of PR head
573c13c0aeb8b8f78fe594c07d8775e1c9bd54f4against controlmain63bcca43c6a00a758510398fa43096ce7e4f7df0(merge base is main itself, so it merges cleanly).Environment: Windows 11 x64, CPU only. No physical GPU was used and no game files were involved.
-j 4, separate target dir.Diff read in full (
crates/victory-hle/src/modules/dsp.rsonly):Statusfields become atomics, and the offsets 0/4/8/12 and size 16 are pinned by const asserts. TheStreamborrow is now shared (&*stream) and submissions are serialised by aMutex<u32>.completedis stored with Release after the output buffer is zeroed. The status pointer is derived afterBox::into_raw. The three new tests cover concurrent unique monotonic tickets, a poller observing monotonic completion and zeroed output, and ABI layout plus u32 ticket wraparound. I found no bug. One minor note, not a blocker:submittedis published before the output is zeroed, which is fine because pollers key offcompleted.Results (PR head / main control):
cargo test -p victory-hle --lib dsp: 4 passed, 0 failed, 0 ignored / 1 passed (control has 1 dsp test)cargo test -p victory-hle --lib: PR 154 passed, 1 failed, 0 ignored. Control 151 passed, 1 failed, 0 ignored.modules::dstorage::tests::a_page_list_filled_after_its_request_starts(dstorage.rs:1642). It is flaky on unmodified main: it failed in 3 of 3 full-lib reruns there and 2 of 5 isolated runs (it passed in the very first control run). It is unrelated to dsp.rs and is not caused by this PR.cargo clippy -p victory-hle --all-targets -- -D warnings: cleancargo run -p xtask -- policy:asset policy: 191 files okAI disclosure: this verification was run by Claude Code (Claude Sonnet 5.5).
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.