Repository navigation
runtime: implement chad.dll audio DSP shim (XDsp*) - #8848
SweatierKey wants to merge 2 commits into
Conversation
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Verified on Windows 11.
- Clean implementation of Scarlett hardware audio DSP exports in
untime/shims/chad.cpp\ and
untime/src/chad_dsp.h:- Implements \XDspConnectWithMaximumStreamLimit, \XDspDisconnect, \XDspActivate, \XDspDeactivate, and \XDspSubmitCommand.
- Proper memory and lifecycle management for stream descriptors (0x1C bytes), command packets (0x20 bytes), and zeroed stream state buffers (0x40 bytes).
- Handles invalid stream pointers and stale handles safely with \E_INVALIDARG.
- Unit tests in \chad_dsp_test.cpp\ and \chad_test.cpp\ pass cleanly.
- Clean-room check and \git diff --check\ pass.
LGTM!
|
Verified head
AI-assisted. |
Ysergic
left a comment
There was a problem hiding this comment.
Independent Linux portable-engine review of f727415. The existing chad_dsp_test passes under GCC 16.2.1 with -O2 -Wall -Wextra -Wconversion -Werror. Two additional lifecycle probes reproduce defects that its success-path checks miss; comments are attached to the relevant lines. Synthetic backing buffers/descriptors only, no game files or Windows ABI execution. AI-assisted with Codex.
| stream->state.block_size = desc->block_size; | ||
|
|
||
| Stream* raw = stream.get(); | ||
| ++ctx->active_streams; |
There was a problem hiding this comment.
[P2] Commit the stream count only after successful map insertion
When the Stream allocation succeeds but unordered_map insertion throws std::bad_alloc, active_streams has already been incremented. In a valid context with max_streams=1, I permitted the Stream allocation and failed the next allocation: the exception escaped, active_stream_count() was 0, and a retry with allocation restored returned Status::out_of_memory while the map was still empty. The context permanently loses its only slot. Increment after successful insertion and translate allocation failures to Status::out_of_memory; connect() also lets allocation exceptions escape its Status/HRESULT boundary. A fault-injection regression should verify recovery, not just failure of the first call.
| Status deactivate(void* stream_handle) { | ||
| if (!stream_handle) return Status::invalid_arg; | ||
| std::lock_guard<std::mutex> lock(mu_); | ||
| auto sit = streams_.find(stream_handle); |
There was a problem hiding this comment.
[P2] Prevent a released handle from identifying a later stream
The lookup key is the address of an owned Stream, and deactivate() frees that allocation. With the standard allocator in an ordinary GCC -O2 build, activate -> deactivate -> activate reused the address. Calling deactivate with the old handle then returned Status::ok and removed the new live stream. This breaks the stale-handle rejection promised by the class; the current test checks the stale handle only before another activation. Use a handle identity that does not alias a later allocation (for example a generation/id), or explicitly narrow the contract if this reuse is intended, and test the stale handle after reactivation. The mutex does not prevent this identity reuse.
|
Thanks @Ysergic for the sharp lifecycle review and fault-injection findings, and thanks @abnalstlll-byte and @smowlyy for the Windows verification! Fixed both defects in commit
Verified locally on Linux (GCC C++20
|
|
Retested both earlier findings at the updated head
AI-assisted, synthetic backing storage only; CPU-only Linux x86_64. Windows wrappers remain outside my validation. I attempted UBSan, but this host's GCC installation has a missing |
|
Tested
So the proof here is compile-level: on Whether the Windows shim half of this PR is correct is not verified here (no Windows build on this host). Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) with the agent's recheck.sh before posting. |
svds12343
left a comment
There was a problem hiding this comment.
Independent native Windows review of 3a031a7d257587c73c9a8d92ff9f29110439e468: the allocation-recovery and stale-handle fixes also pass through the actual registry-resolved Windows wrappers.
Windows 11 x64 build 26200, MSVC 19.44.35230, Windows SDK 10.0.26100, CMake 4.4.5/Ninja, RelWithDebInfo. CPU-only synthetic inputs; RTX 3070 / driver 610.88 not used. No game files or GPU execution.
- Built
chad_dsp_testandchad_testfrom this exact head. CTest passed 2/2; the stock Windows shim test passed all 15 checks. - A separate
/O2executable links the PR's unmodifiedchad.cppandregistry.cppand resolves all five exports throughrt::shims::find. Across 24 fresh-process allocation cases, the ten injected failures (object/node allocation and map growth) returnedE_OUTOFMEMORY, cleared connect/activate outputs and recovered on retry. Existing streams remained usable during map-growth failures. The 14 cases with no allocation failure succeeded. The first-call attribution logger was warmed before targeting engine allocations. - The same native wrappers completed 2,000 connect/activate/deactivate/reactivate/disconnect/reconnect cycles: 8,000 distinct handles and 38,000 successful assertions. Stale stream/context calls were rejected after replacement; replacement streams, state fields and command tokens remained correct, and disconnect invalidated orphan streams.
- Negative control: compile the identical probe against the preceding
f727415457e713a35e8ea67b13e6a94611b38b85. Allocation failures escape asstd::bad_alloc; stream map-insertion failure consumes the available slot and prevents retry. The first lifecycle cycle also reuses a stream identity, allowing the stale deactivate to remove its replacement. These are behavioral failures, not a missing-header/compile control.
No additional blocking issue found in this focused scope. This checks the implemented shim contract and revised lifecycle behavior; it does not validate the measured console ABI against game execution, DSP audio processing, first-call logging allocation failures, or integration with the other open chad implementations.
Claim: #9235 (comment)
AI-assisted (Codex).
|
Checked Pass
Needs changes
AI-assisted: Codex GPT-6.2 Sol ran the checks, Claude Opus 5.5 reviewed the report. The retail executable and package DLLs were read in place (executable SHA-256 |
LaugeM
left a comment
There was a problem hiding this comment.
Read at 3a031a7d against main 5d74c2723. The handle bookkeeping is solid, but the status block XDspActivate returns doesn't fit how the title reads it, and as written the title would wait forever.
- The status block never reads as done (
runtime/src/chad_dsp.h:62-68,:132-134,:168-172). AfterXDspSubmitCommandthe title waits until the status dword at+0xcis 0 and the one at+4equals the id the call wrote (#6981's call-site read, confirmed by Razuri0 and kennymaakay there).DspStreamStateputsversion = 1at+0,kindat+4,channel_countat+8andblock_sizeat+0xc.submit_commandhands out tokens 1, 2, 3 and so on, and keeps them only instream->last_token, never in the status. So+0xcholds the descriptor's block size and+4its kind, and the wait ends only by accident (kind equal to the token and a block size of 0). Confirmed (code read), assuming #6981's read of the wait is right. - A zero buffer size is refused (
chad_dsp.h:78). Silliana reported on #7009 that the measuredXDspConnectWithMaximumStreamLimitcall passes 0 there.connectreturnsinvalid_argformemory_size == 0, and the title takes that as "no DSP". Plausible (the measurement is theirs). - Overlap. The description says #6981 covers only
xapu.dll, butruntime/shims/xapu_chad.cppin #6981 registers all fivechad.dllnames, and #7009 and #9168 do too.SHIM_TABLE(chad, …)here (runtime/shims/chad.cpp:80) would silently replace or be replaced by whichever one links later. #6981 has been checked against the call sites for longer, and with #6885 it has a 10-minute retail run. I'd close this, or rebase it onto #6981 and keep only the lifecycle checks once the status layout matches the title.
AI-assisted review (Opus 5.5). Read the diff against main; not built.
|
Thanks @LaugeM for the sharp review! Agreed on all three points:
Recommending maintainers take |
Claim: #8504 (comment)
Depends on: none
Summary
Implements the 5 Xbox Series
chad.dllhardware audio DSP exports observed unimplemented in #7154 frame-loop runs (XDspConnectWithMaximumStreamLimit,XDspDisconnect,XDspActivate,XDspDeactivate,XDspSubmitCommand):runtime/src/chad_dsp.h(portable C++20, no Windows/Vulkan dependency):leonida::chad::DspEnginetracking live context handles and stream handles so stale, double-freed, or foreign handles are rejected withE_INVALIDARGwithout dereferencing invalid pointers.DspActivateDesc(0x1Cbytes),DspCommand(0x20bytes), and owned zero-initializedDspStreamState(0x40bytes) returned throughXDspActivate's third argument.max_streamsper context (E_OUTOFMEMORYwhen full), issues monotonic non-zerouint32_tcompletion tokens onXDspSubmitCommand, frees stream slots onXDspDeactivate, and cleans up orphaned streams onXDspDisconnect.runtime/shims/chad.cpp: registers all 5chad.dllexports viaSHIM_TABLE(chad, ...), logs first call once per export, and delegates toDspEngine.runtime/test/chad_dsp_test.cpp&runtime/test/chad_test.cpp: portable unit tests + Windows shim registry ABI tests, wired intoruntime/CMakeLists.txtandscripts/build_runtime.ps1.Overlap check
Checked open PRs and #8504: no open PR or claim covers
chad.dll/XDsp*(#6981 coversxapu.dllonly). No game files or game data included.Testing
-O2 -Wall -Wextra -Wconversion -Werror -fsanitize=address,undefined), CMake + CTest.chad_dsp_test: PASS (0 warnings, 0 ASan/UBSan issues, CTest1/1passed).chad_test(compiled with minimal Win32 stub headers + ASan/UBSan): PASS (15 checks, 0 failures).python3 -I scripts/check_no_game_data.pyon all changed files: exit 0.chad_test/gta6rtleft for Windows reviewers (no MSVC on this Linux host).AI-assisted.