dsp: compute the coprocessor's convolutions (room reverbs, the phone speaker) on a thread of their own #497
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!497
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-497"
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?
@PimpMastre on GitHub · 2026-12-04 18:41 UTC · original
PimpMastre:dsp-convolution-reverb→main· +942 −35 · 2 files · 3 commits · openProblem
The audio DSP's convolutions (
chad.dll) are not computed. Onmain, a convolution whose response has at most 65,536 floats passes its input through at 5x and hard-clipped (b69806a, for callers' voices), and every other output is silence. Indoors this puts a second, louder copy of the dry sound on top of it, so dialogue and footsteps sound doubled. Reverbs are dry, and the phone speaker carries the clean voice with no speaker filter.The response layout
Read from the title's own responses.
VICTORY_DSP_DUMP=1writes every distinct response a stream is activated with to<data>/dsp-dump.k(2048 floats) is the 2048-point spectrum of the response's samples(k-1)*1024 .. (k+1)*1024. The first half of block 0 is zeros.0xFFFFACE1.Read that way, the overlapping halves of neighbouring blocks agree to float rounding on all 27 responses one play activated. The speaker filters peak at exactly 1.0. The phone filter's gain in the voice band (about +10 dB) also explains why the pass-through needed 5x. The VIctory-xmem-RDNA3 fork arrived at the same layout independently, from 49 responses.
Change
VICTORY_DSP_REVERB=0, keep #457's rule: speaker filters, recognised by their shape, pass through, and rooms are dry.XDspSubmitCommandcopies the input block and queues the command. The thread writes the output and completes the command, well inside the block the title waits before it checks. Deactivation waits for a stream's queued commands. Run inside the call instead, it added a few percent of a core to the title's mixer thread.Overlap with #457
This includes #457's speaker-shape rule and its bounded read of the response (credit to @niiniiniintje), because they are the fallback here. If #457 is merged first, this rebases onto it. Otherwise this replaces it.
Measured
cargo clippyshows no warnings indsp.rs, andrustfmtis clean.Settings
VICTORY_DSP_REVERB=0VICTORY_DSP_DUMP=1🤖 Generated with Claude Code
@Bushyon on GitHub · 2026-12-04 19:18 UTC · original · edited 2026-12-04 19:42 UTC
tried it Fedora 44, Proton Experimental, merged with
b2449c4: sound is better and the volume sliders work for me (they didn't yesterday on main)@Kal0s-design on GitHub · 2026-12-04 19:22 UTC · original
Checked
cc2542don native Windows (didn't run the game, no game data, so this checks the math against the layout as described in the PR, not the layout itself).cargo test -p victory-hle --libgives 168 passed, 2 ignored on the PR and 162 passed, 1 ignored on main. The difference is exactly the new dsp tests. Clippy prints the same warnings on both and none of them are in dsp.rs. The branch merges cleanly onto current main.I wrote a throwaway test (not pushed) that lays out responses with its own f64 FFT, runs
Convolverblock by block and compares against a direct f64 convolution. Cases were single taps at 0 to 5000 including every block edge, decaying noise, a 4.5 block room with silences of parts-1, parts and parts+1 blocks between sounds, and the max size the bound allows (255 partitions plus footer, run long enough for the ring to wrap).runzeroes it (dsp.rs:815).XDspSubmitCommandwith different responses each match their own reference, so the state is per stream. Each activation builds a fresh convolver, so nothing carries over on reactivate.A response with no footer still convolves correctly. A footer that isn't last, an odd size, a footer only, a size over the bound, or a NaN in the response all get no convolver and no pass, so the output is silence. A NaN or Inf in the input gets past the
!= 0.0check (dsp.rs:768), makes exactlypartsoutput blocks non-finite, and then the stream recovers.Only mono 1024-frame streams are convolved (dsp.rs:456). The existing test still has a comment saying the title asks for a stereo convolution with option 2 (dsp.rs:1110), while the body says every stream it activates is mono 1024. Is that comment just old?
recvwhen idle, so it doesn't spin.completedstayed at 0, so the title sees an overrun and the output is written late.completedcan go backwards. A command with a null output on a convolving stream skips the queue and completes at once (dsp.rs:595 falls through to 633). With 3 commands queued I sawcompletedgo to 4, then back to 3 when the worker drained. The title probably never does this, but not completing whilepending > 0would close it.XDspDeactivategives up after 500 ms (dsp.rs:511-517). With a job held past that, deactivate returned and the job then wrote into the output buffer, which in the game could already be freed or belong to a new stream. It's unlikely with jobs this short, but waiting without a limit, or having the job check a cancelled flag before writing, would be safer.reverb_on(dsp.rs:524-525) says "as before they were", butVICTORY_DSP_REVERB=0gives #457's rule, not main's size rule.That leaves room for about 160 streams of the longest room per 21.3 ms block on the one thread, so it keeps up easily.
This PR carries #457's code unchanged. Whichever lands second conflicts in dsp.rs. SETTINGS.md merges by itself, but #457's paragraph saying convolutions are not computed would be wrong once this one is in.
Overall the convolution looks right for the layout as described. The deactivate timeout and the backwards ticket are the two things I'd look at.
AI-assisted: yes
@WillyBrown69 on GitHub · 2026-12-04 19:37 UTC · original
fixed #493
@PimpMastre on GitHub · 2026-12-04 19:39 UTC · original
@Kal0s-design Thanks for the thorough check. The Nyquist-term breakdown is a useful way to bound the error. Pushed
ed92a79with the fixes:Tickets going backwards. Every command of a convolving stream now goes through the DSP thread, including one with a null output. Its block still enters the convolution, so the response's tail is right in the block after it.
completedcan no longer move backwards. There's a test that submits output / no output / output and checks thatcompletednever decreases.Deactivate timeout. The 500 ms wait is gone. Deactivation takes the stream's convolver out under its lock. The DSP thread writes the output while holding that lock, so a command that runs afterwards writes nothing into the title's buffers, and one that is mid-write finishes first. That's well under a millisecond.
NaN/Inf in the input is now treated as silence when the block is copied, so one bad block no longer gives
partsblocks of non-finite output (covered in the same test).Layout checks. I checked both against the 27 responses from the dump:
Both conditions are now checked when a stream is activated and logged once if either fails (with a test).
The stereo test's comment was stale. It now says that stereo with option 2 isn't convolved (the title's streams are mono, 1024 frames), so the speaker rule applies.
reverb_on's doc now saysVICTORY_DSP_REVERB=0gives #457's rule.Tested
ed92a79in play: about 6 minutes on this branch over current main (RX 7900 XT/XTX, CachyOS), going in and out of interiors and cars, with phone calls and the pause menu. Reverb and the phone filter behave as before, and the layout check logged nothing across 18 response shapes. There were a few tiny audio dropouts, and they lined up with frame hitches of 150–400 ms (main has no real-time priority for the title's mixer without #149). No new warnings.On #457: agreed, whichever of the two lands second conflicts in
dsp.rs, and #457's SETTINGS paragraph would be wrong once this one is in. If #457 goes first, I'll rebase onto it and update the paragraph. Otherwise this PR replaces it.@Bushyon thanks for testing on the 7800 XT, good to hear the volume sliders work now.
@WillyBrown69 thanks for confirming. That's the radio and phone filters (#493) coming through now that the speaker responses are computed.
@Kal0s-design on GitHub · 2026-12-04 19:54 UTC · original
Re-checked
ed92a79on native Windows (didn't run the game, no game data).Tests give 170 passed, 2 ignored, against 162 and 1 on main. Clippy shows the same warnings on both, none in dsp.rs, and the branch still merges cleanly. I re-ran my earlier throwaway checks and all the points I raised are fixed. Accuracy and timing per block haven't changed. Tickets stay in order with output and no-output commands mixed and a long queue, and the blocks with no output still go into the convolution (the output matches a convolver fed every block, bit for bit). Deactivate now waits for a stalled job however long it takes, and nothing is written after it returns. NaN and Inf in the input give finite output.
One small thing, not blocking. Deactivate can end up waiting for the stream's whole queue, not just the job that's running, because the DSP thread keeps getting the lock back between jobs. In one run with 500 jobs of the 104-part room queued, it waited about 50 ms. The title shouldn't build a queue like that, but if you want the wait capped at one job, an atomic flag set before the lock and checked in
Job::runwould do it.AI-assisted: yes
@PimpMastre on GitHub · 2026-12-04 20:30 UTC · original
@Kal0s-design Thanks for re-checking. The stop flag is in
91ab9ab. Deactivation now sets it before taking the lock, and a command of a stopped stream completes its ticket without taking the lock, so the wait is capped at the command that's running.The new test holds the stream's lock, stops the stream and runs a queued command. The command has to complete and must not write its output. With the flag check removed, the command waits for the lock and the test fails. All 10 dsp tests pass, and there's nothing from clippy in
dsp.rs.@niiniiniintje on GitHub · 2026-12-05 01:46 UTC · original
Manual testing shows that the audio reproduction is basically perfect now. Good stuff
@PimpMastre on GitHub · 2026-12-05 19:42 UTC · original
A status note, since the queue in #516 lists this under "Next" as "DSP threads; no provable defect":
ed92a79and91ab9ab, and both heads were re-checked on native Windows, with all the points confirmed fixed.main(a5c6484) and touches onlydsp.rsanddocs/SETTINGS.md.It fixes doubled dialogue and footsteps indoors, dry reverbs, and the missing phone and radio speaker filter. With no open findings and no conflicts, it may be worth moving up the queue.
91ab9ab865toa9ef503ebc@PimpMastre on GitHub · 2026-12-05 21:11 UTC · original
Rebased onto current
mainnow that #457 is in, so this merges cleanly again.dsp.rs, where #457's speaker-shape rule and bounded response read sit. This PR already carried both as its fallback, so the resolveddsp.rsis identical to the previous head (91ab9ab).docs/SETTINGS.mdnote #457 added ("convolutions are not computed") now says they are computed for mono 1024-frame streams, with #457's rule as the fallback for other shapes andVICTORY_DSP_REVERB=0.mainis still onlydsp.rsanddocs/SETTINGS.md, and all the DSP tests pass under Wine.@niiniiniintje on GitHub · 2026-12-05 23:29 UTC · original
Thank you for the rebase.
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.