Skip to content

runtime: xapu.dll and chad.dll shims, connections that succeed with an empty result queue (RT-489) - #6981

Closed
Jadiac5 wants to merge 4 commits into
ProjectLeonida:mainfrom
Jadiac5:runtime/xapu-chad-shims
Closed

Jadiac5 wants to merge 4 commits into
ProjectLeonida:mainfrom
Jadiac5:runtime/xapu-chad-shims

Conversation

@Jadiac5

@Jadiac5 Jadiac5 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Item: RT-489, shims for xapu.dll and chad.dll (claimed in #6750 (comment)).

What the imports are for

xapu.dll is the console's audio processing unit (APU) command queue and chad.dll its audio DSP. #6715 lists
their ten imports among the 30 the retail executable calls with no binding. A PC has neither unit.

What the call sites show

Read statically from the executable (never run or mapped). Each import is reached through one jump stub; the
direct callers:

  • XApuConnect: 1 site, three pointer arguments (a 24-byte global of the title, a 16-byte output, and a handle).
    Success is read as SUCCEEDED. The first qword of the 16-byte output is used later as the base of a CPU-visible
    buffer: stream input at a 0x280-byte stride from the base, stream output at a 0x1E00-byte stride from
    base + 0x14000. Other title code also addresses the 24-byte global, so it may be an input.
  • XApuEnqueueCommand: 4 sites, (handle, pointer to a stack-built command, 0). The command's first dword is a type
    (1, 2 and 3 seen), the second a stream slot. The return value is never read.
  • XApuGetResultCount: 1 site, (handle, 0). 0 skips the dequeue loop.
  • XApuDequeueResult: 1 site, (handle, pointer to a zeroed 0x50-byte local), called count times; a negative
    result skips that entry. The loop reads a type at +0 and a stream slot at +4. A type 1 result marks the stream
    opened; a type 2 result, after the title enqueued a type 2 command, returns the stream id to the title's free
    list.
  • XApuDisconnect: 1 site, one argument (the handle global, cleared after); the return value is not read.
  • XDspConnectWithMaximumStreamLimit: 1 site, six arguments (a buffer from the title's XMemAlloc, two dwords,
    0x80, 1, a handle output). Success is a return of 0.
  • XDspActivate: 1 site, (handle, pointer to a local description, two output pointers into the caller's object).
    Success is a return of 0, else the caller returns -1. The title later reads dwords at +4 and +0xc through one
    output with no null check and passes the other to XDspSubmitCommand.
  • XDspSubmitCommand: 1 site, (the stream from XDspActivate, a command, pointer to an id the title zeroed).
    Success is a return of 0. The title then waits until the status dword at +0xc is 0 and the one at +4 equals the
    id.
  • XDspDeactivate, XDspDisconnect: 1 tail jump each; the caller returns what they return.

What each function does now

New file runtime/shims/xapu_chad.cpp, registered like xmem.dll (so owns_dll covers both DLLs for run-time
LoadLibrary too):

  • XApuConnect: allocates a zeroed shared buffer, writes {base, size} to the 16-byte output, leaves the 24-byte
    global untouched and returns S_OK with a handle. E_INVALIDARG without a handle pointer.
  • XApuEnqueueCommand: S_OK. A type 1 (open) or type 2 (close) command queues one result of the same type and
    slot; nothing is processed.
  • XApuGetResultCount: the number of queued results. XApuDequeueResult: writes the type and slot of the oldest
    one; E_FAIL without writing when the queue is empty.
  • XApuDisconnect: frees the buffer and the handle, S_OK.
  • XDspConnectWithMaximumStreamLimit: a handle and S_OK. XDspActivate: writes both outputs as pointers to
    zeroed memory the connection owns, S_OK. XDspSubmitCommand: S_OK, the id stays the title's 0, which the
    zeroed status already reports as done. XDspDeactivate: S_OK. XDspDisconnect: frees the handle, S_OK.
  • With --trace, the first call of each function and the first command of each type is an audio_queue event,
    with the caller.

The effect is silent audio: the title's buffers are accepted and nothing is rendered into them.

Hypotheses (also in the file's comment):

  • The buffer size, 0x14000 + 128 × 0x1E00 bytes. 128 slots is what fits 0x14000 at the 0x280 input stride, and the
    DSP connect passes 0x80 as its stream limit; no call site shows a bound.
  • The second qword of the 16-byte output as the size; only the base is read.
  • One result per open and per close command, of the same type and slot. The title's state machine fits that; the
    console is not measured. Only the first two dwords are written. Other command types give no result, so a stream
    that waits for a type 5 result keeps waiting.
  • The zeroed status and stream memory behind XDspActivate's outputs, and that an id of 0 with a status of 0 reads
    as "done".

Tests

  • xapu_chad_test (new, in ctest as xapu_chad): 33 checks, 0 failures. It resolves all ten through the registry,
    checks owns_dll, the connect output, that the 24-byte block is untouched, that the buffer is zeroed and writable
    at the end of slot 127, three command types, the two results they queue, the empty queue after, and the DSP calls
    in their call-site shapes, including the two XDspActivate outputs and what the title's wait reads.
  • ctest xapu_chad, xmem, process_cmdline, file_system, unimplemented_policy, winhttp_offline: 6/6 passed.
    gta6rt builds with the new file.
  • python -I tests/test_docs_repo_paths.py: OK. python -I scripts/check_no_game_data.py: exit 0.

Not tested

Related: #6899 documents the same call sites. It is docs only, so this PR does not depend on it. One difference:
it reads a second argument 0x20 for XApuDisconnect; here that 0x20 goes to an XMemFree call just before, and
the disconnect site loads only the handle.

Tested on Windows 11, MSVC 19.44, AMD Radeon RX 9070 XT, driver 32.0.32029.2010 (no GPU is used by these tests).

AI-assisted (Claude Code).

@Razuri0

Razuri0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Static check at 8f8fb2b6, read from the executable only (SHA-256 e95020b2…8993); nothing executed or mapped. The call-site counts and shapes in the PR hold:

  • XApuConnect 1 site (0x43aee69): rcx = 0x149ae9890, rdx = 0x149ae98a8 (the second block starts 0x18 after the first), r8 = 0x149ae8960 (the handle). Return read as SUCCEEDED.
  • XApuEnqueueCommand 4, XApuGetResultCount 1, XApuDequeueResult 1.
  • XDspConnectWithMaximumStreamLimit 1 (0x5b5262e): rcx = [this+0x490], rdx = [this+0x498], r8 = the caller dword, r9 = 0x80, stack 1, stack this+0x488; success is eax == 0.
  • XDspActivate 1 (0x11d475d): handle first, five arguments; eax != 0 returns -1 to the caller.
  • XDspSubmitCommand 1 (0x4e5b20d): the wrapper swaps rcx/rdx before the call; success is eax == 0.
  • XDspDeactivate and XDspDisconnect are the two tail jumps, as stated.

The XApuDisconnect point is confirmed: the only site (0x43ae930) loads the handle into rcx and calls; it does not set rdx. The mov $0x20, %edx just before (0x43ae90a) feeds the XMemFree call on the path above, so this PR's correction to #6899 is the right reading of the call site.

No Windows ctest here, so this is static confirmation only. No game data: counts, offsets and RVAs only. AI-assisted.

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 8f8fb2b6 on Windows 11, MSVC RelWithDebInfo, merged onto main bd3f061ad, against my own copy of the retail executable (outcomes only):

Details: #6910 (comment). AI-assisted (Claude Code).

@Jadiac5
Jadiac5 force-pushed the runtime/xapu-chad-shims branch from 8f8fb2b to e6515ea Compare November 23, 2026 15:50
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 23, 2026
…d.dll shims)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
seblessa added a commit to seblessa/Leonida that referenced this pull request Nov 23, 2026
On top of ItsNotRexed#6981, from the public GDK reference (xapu.h, XDspAudio.h on
docs.xbox.com) checked against the executable's call sites (static read):

- XApuConnect takes the 24-byte block as input and leaves it alone; base data
  is baseDataLength bytes, zeroed; no result-ready event (the title does not
  ask for one).
- Every XApu command gets exactly one result with its id, visible from the
  second XApuGetResultCount after the enqueue (the title stores a stream's
  state only after the enqueue returns and polls from another job). Without
  results the title's stream slots never return to their free list.
- A process command is answered with one frame of silence in its output
  buffer, bounded by its capacity and the base data; the 0x50-byte result is
  the packed XApuResult, outputDataLength at +0x34. An empty queue is
  XAPU_E_PENDING_RESULTS.
- XDspActivate hands out a zeroed XDspStatus per stream (the voice path reads
  it with no NULL check); XDspSubmitCommand returns sequences 1, 2, ... and
  marks each processed in that block, which the title waits for before the
  next submit. Status blocks are pooled, never freed.
- The documented error codes for refused calls (stream limit, clients,
  invalid command or stream index, handles still active).
- build_runtime.ps1's cl.exe fallback lists acphal.cpp and xapu_chad.cpp,
  which tests/test_build_runtime_fallback.py requires.

xapu_chad_test drives all ten in the title's shapes, with commands against a
no-access page, and one thread enqueuing 20000 commands while another polls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 5f47ed2b3 to clear the conflict in docs/runtime_imports.md (main added a section at the same place); no code change. Rebuilt and rerun on the new base: xapu_chad_test 28 checks, 0 failures. Windows 11, MSVC 19.44. Not run against the retail executable.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 8f8fb2b merged with main e6190e7 on Windows 11 / RTX 4080 SUPER against own copy of the retail exe: pass. The new head e6515ea (the rebase) has the same runtime/ diff byte for byte and merges cleanly with e6190e7, so the result carries over.

  • Build: MSVC 14.51 (VS 18), Ninja, RelWithDebInfo, gta6rt + xapu_chad_test.
  • ctest -R xapu_chad: 1/1 passed.
  • gta6rt --dry-run (LEONIDA_D3D12=vulkan, fresh --trace, --trace-d3d12, --overlay to a scratch folder): main has 30 unimplemented imports (shim 53) and the PR has 20 (shim 63). The only differences are xapu.dll going from 5 to 0 and chad.dll from 5 to 0; the other 20 are unchanged.
  • Negative control: the same dry run on main lists all ten xapu.dll/chad.dll imports as unimplemented.
  • gta6rt --run with LEONIDA_UNIMPLEMENTED=stop: main and the PR stop in the same place. Both exit 3 at the first unimplemented import (d3d12_xs.dll!D3D12ConfigureVirtualMemoryX, d3d12_xs: D3D12ConfigureVirtualMemoryX shim (first unimplemented call of the title) #6792), after 2 TLS callbacks and 4/4 DllMain OK. A stop-mode run on main doesn't reach the xapu/chad calls yet, so the PR alone doesn't move --run.

@Spacecer2

Copy link
Copy Markdown

Tested e6515ea4 on Linux (clang-cl 23.1.5 + xwin Win11 SDK 10.0.26100 + MSVC 14.44, wine-11.22), applied alone to main 07f1d7e: builds, xapu_chad_test 28 checks 0 failures under wine, dry-run 30 → 20 unimplemented with the xapu/chad names gone. The APU buffer arithmetic inverts exactly (0x14000 = 128 * 0x280, 0xF0000 = 128 * 0x1E00) and is page-aligned, so a wrong slot count faults at the first over-range slot rather than corrupting a neighbour. One defect to fix before merge: *handle = new ApuConnection{buffer}; and *handle = new DspConnection{}; are unchecked, so a failed allocation returns S_OK with a null handle — the title reads SUCCEEDED and calls through it. Check the allocation, free the buffer, return E_OUTOFMEMORY with *handle = nullptr. Details and the comparison with the other three PRs are in the coordination issue.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the test and the finding. Fixed in b9540161.

  • XApuConnect and XDspConnectWithMaximumStreamLimit now allocate with new (std::nothrow). On failure they return E_OUTOFMEMORY and leave *handle null. XApuConnect also frees the buffer and no longer writes the two output blocks before the handle exists.
  • One correction to the description: the old plain new would not have returned null. It would have thrown std::bad_alloc into the title's frames, which is worse. The fix covers both.
  • xapu_chad_test: 28 checks, 0 failures on Windows 11, MSVC 19.44. gta6rt builds. No test forces the allocation to fail, so the new branch is checked by reading only.
  • Not run against the retail executable.

AI-assisted (Claude Code).

ErRusso added a commit to ErRusso/Leonida that referenced this pull request Nov 23, 2026
…shapes

- XGCreateTextureComputer: fix signature from 4 args (desc, device, riid,
  out) to the measured 2 args (desc, out**). The out pointer arrives in
  RDX, not R9 — the old 4-arg version wrote through a stale register
  as textureComputer, which the two callers that ignore the HRESULT
  would use as a null/wild vtable call. Now returns a static computer
  with a proper vtable (AddRef/Release for slot 0/1, E_NOTIMPL for
  all other slots with a one-time log).

- XGSuggestSwizzleMode: fix signature from 2 args (desc, mode*) to the
  measured 3 args (desc, flags, mode*). The mode* arrives in R8, not
  RDX, so *mode = 0 was previously writing to a wrong register. Now
  returns E_NOTIMPL and writes nothing (the caller already zeroed the
  field).

- AcpHalCreate: replace the non-dereferenceable id<<4 handle with a
  static object with a proper vtable (IAcpHal COM-like interface).
  Any method call through it logs once per slot and returns E_NOTIMPL
  instead of faulting.

Both fixes match the measured call shapes documented in the overlapping
PRs ItsNotRexed#6891 and ItsNotRexed#6981 and verified by reviewers.

AI-assisted: yes
@AirKyzzZ

Copy link
Copy Markdown
Contributor

Tested b95401617 (the head after the allocation fix) on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 + lld-link (MSVC 14.29 STL), SDK 10.0.26100: pass

Built gta6rt and xapu_chad_test at the head as is, no clang-cl warnings from xapu_chad.cpp or its test. ctest -R "^(xapu_chad|winhttp_offline)$": 2/2 pass, xapu_chad_test 28 checks, 0 failures. The same test linked without shims/xapu_chad.cpp (as on main): all ten exports unregistered and the ownership check fails, so it is not model-only. Not run against the retail executable. No game files. AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Verified at your rebased head e6515ea: merges clean into 8575d36 (the old docs/runtime_imports.md conflict vs #6715 is gone). The shims register through SHIM_TABLE so owns_dll picks both DLLs up without loader changes, and the call shapes match the independently measured docs/audio_hal_exe_calls.md (#6899, tools/import_call_sites.py): 8 xapu + 5 chad sites, the 0x80 stream limit, result queue semantics all consistent; buffer-size guesses are honestly marked HYPOTHESIS. Three things before merge: (1) your own docs/runtime_imports.md:141-142 still says "the other 22 are in five DLLs ... with no shim at all" — that sentence now contradicts this PR (xapu and chad are shimmed here); fix its count and list in the same PR; (2) cite tools/import_call_sites.py for the "read statically from the executable's call sites" claim, matching #6899's convention; (3) XApuDisconnect's shape comment omits the measured second argument 0x20 that audio_hal_exe_calls.md records. C++ not buildable here; xapu_chad_test runs in the windows CI job. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run, C++ review-only).

@Spacecer2

Copy link
Copy Markdown

Re-tested at b9540161, same host as my first check (Linux, clang-cl 23.1.5 + xwin Windows SDK 10.0.26100, wine 11.22), applied alone to main e0816d6: builds, xapu_chad_test 28 checks 0 failures under wine, retail dry-run shim=64 ... unimplemented=19. The defect I flagged is fixed in the source: both handles now come from new (std::nothrow) with return *handle ? S_OK : E_OUTOFMEMORY, and XApuConnect frees the buffer on the failure path. With #6891 that leaves the xmem seven and DStorageGetFactory. Nothing else from me on this one.

ErRusso added a commit to ErRusso/Leonida that referenced this pull request Nov 23, 2026
Update xapu.cpp and chad.cpp to use the measured argument shapes from
the executable (PR ItsNotRexed#6981) instead of GDK-documented struct-based
signatures that mismatch the real call site register layout.

xapu.cpp:
- XApuConnect: (void* out24, void* out16, void** handle) — 3 raw
  pointers matching the measured call, not the GDK struct types.
  Removed the XApuConnectInputParameters/OutputParameters structs
  that were reading garbage from arg1.
- XApuEnqueueCommand: (handle, cmd*, uint64_t flags) — 3rd arg is
  flags (always 0 at call sites), not totalCommandCount*.
- XApuGetResultCount: (handle, uint64_t flags) — 2nd arg is flags,
  not totalResultCount*.
- XApuDequeueResult: (handle, out*) — no arity change.
- XApuDisconnect: (handle) — no arity change.

chad.cpp:
- XDspActivate: (handle, u64, u64, u64, u64) — 5 args (was 4).
  The measured call passes 4 extra uint64_t values; our old 4-arg
  version read status/streamHandle from the wrong registers.
- XDspDeactivate: (handle, u64, u64, u64) — 4 args (was 1).
- XDspSubmitCommand: (void*, void*) — 2 args (was 3 with commandSeq).

Also fix chad_test.cpp to pass baseBufferLength >= 0x10000 so the
shim's validation doesn't reject it, and update error code expectations
(E_POINTER for null handle, not E_INVALIDARG).

Fix acphal_test.cpp APU_ADDRESS struct ordering (must be defined
before the using declarations that reference it).

AI-assisted: yes
@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

New head 28f013c2: one commit on top, no force-push. It also removes the conflict with main's new xmem.dll notes in docs/runtime_imports.md (the paragraph moved into the RT-5 section). Answers to memorypressure's three points:

  1. The paragraph now sits in the RT-5 section and ends with: the table above was measured before this shim and still lists these ten as unimplemented; they are served now. I did not rewrite the "other 22 are in five DLLs" sentence itself: it is a measurement at 1cc6e3c1, main added its own "served now" line right under it, and runtime: AcpHal.dll shim, the audio heap with a 32-bit address mapping and a no-op hardware object (RT-489) #6885 and runtime: xg_xs.dll shim, XGCreateTextureComputer and XGSuggestSwizzleMode as traced E_NOTIMPL (RT-489) #6891 would each have to edit the same sentence and conflict. The counts are best re-measured once after the shims are in.
  2. The paragraph now says the call shapes agree with docs/audio_hal_exe_calls.md, measured with tools/import_call_sites.py.
  3. The shape comment in runtime/shims/xapu_chad.cpp now reads XApuDisconnect(handle, 0x20) and says the constant second argument is not declared because nothing reads it. No code changed.
  • Merges cleanly with main 51e7c9dc (git merge-tree).
  • Built the same code merged on 51e7c9dc on Windows 11, MSVC 19.44: xapu_chad (28 checks), xmem, process_cmdline, file_system, unimplemented_policy, winhttp_offline: 6/6 pass.

Not run against the retail executable.

AI-assisted (Claude Code).

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 28f013c2f on Linux + Wine 11.20 (RTX 5080, NVIDIA 615.78.08), with my own copy of the retail 1.0.2.1 exe: pass — the ten xapu.dll/chad.dll imports bind under --dry-run (29 → 19 unimplemented), xapu_chad_test passes, no ctest regression against main; --run doesn't reach these calls under Wine on main yet, so it is unchanged.

Setup. The head merged alone onto main fd335571a (clean merge; the PR names no Depends on:, nothing else merged). clang-cl 23.1.3 + xwin (MSVC 14.44 STL, SDK 10.0.26100) cross build, Ninja, RelWithDebInfo, -DLEONIDA_SDL3_FETCH=ON -DLEONIDA_VULKAN_HEADERS_FETCH=ON. The same flags for the main baseline build.

Tests

  • ctest -C RelWithDebInfo --output-on-failure -j1 --timeout 300, run on the merge with the previous head b95401617 (the step from it to 28f013c2f changes one source comment and docs/runtime_imports.md only; I checked the diff): 252/268 pass, 16 fail. All 16 also fail on main in the same Wine prefix setup (gameinput_host, device_proxy, device_proxy_trace, file_system, run_tiny_game_abort_exit_codes, and ten d3d12_* tests plus dxgi_swapchain. I didn't look into why they fail under Wine; the PR doesn't touch them). main's full run had two more failures, vk_pipeline_check_cli and a timeout in xdxr_build_check. Neither is touched here, and both pass when run alone on main: vk_pipeline_check_cli passed 1 of 3 runs alone, because its 5 s execute_process limit is shorter than a cold Wine start.
  • Rebuilt at 28f013c2f and reran ctest -R "^(xapu_chad|unimplemented_policy)$": 2/2 pass. xapu_chad_test.exe on its own: 28 checks, 0 failures.

Retail exe (LEONIDA_D3D12=vulkan, --overlay to a scratch folder outside the package, network off via a separate network namespace, fresh --trace, --trace-d3d12)

main fd335571a main + this PR
--dry-run 5 modules, shim=54, 29 unimplemented (AcpHal 9, chad 5, xapu 5, XCRDAPI 1, xg_xs 2, xmem 7) 5 modules, shim=64, 19 unimplemented (AcpHal 9, XCRDAPI 1, xg_xs 2, xmem 7)
--init exit 0, 4 TLS callbacks, 4/4 DllMain ok the same
--run 2 TLS callbacks, 4/4 DllMain ok, then a null read (0xC0000005) in gta6rt's own host_module_name (library_loader.cpp) on the game thread, before any unimplemented import or D3D12 call the same stop

The only change in the dry-run list is the ten imports this PR serves: the five XApu* and five XDsp*. The --run stop is the known Wine form of the /GA TLS index 0 problem (#6603, fixed by #4313). #4313 conflicts with main, so I didn't stack it, and the run never gets to the xapu/chad call sites, before or after. The run ends with exit 5, or winedbg hangs until my timeout.

Not tested: native Windows/MSVC, and the retail --run with a boot stack that reaches the audio calls.

AI-assisted (Claude Code).

cc @shayderrr

@kennymaakay

Copy link
Copy Markdown

Heads-up from comparing this with the 1.0.2.1 executable's call sites (details and RVAs in #7599 (comment)):

  • XDspActivate returns S_OK without writing its outputs. The title passes the addresses of two of its own fields as args 3 and 4 (XDspActivate(conn, &desc, &obj+0x30, &obj+0x38)), and after a successful submit its state 5 reads +0x0c of the status pointer it expects there with no null check (0x43b2b3a), so this looks like a null dereference once audio is reached.
  • The XApu result queue is always empty (XApuGetResultCount → 0). As far as we can read, stream ids only go back to the free list from a close result (0x4eaa8ff → 0x4eaa970), so voice allocation would run out after 256 opens.
  • XApuConnect's first argument is the address of a global block the title owns (rva 0x9ae9890); zeroing 24 bytes of it may wipe values the title set.

Static analysis only (our boot does not reach audio yet). AI-assisted (Claude Code).

FarhatFIN added a commit to FarhatFIN/Leonida that referenced this pull request Nov 23, 2026
Integrate DirectStorage from upstream PR ItsNotRexed#4348 and adapt memory/connection code from ItsNotRexed#6885 and ItsNotRexed#6981. Reject unsupported audio commands instead of reporting successful processing. Validate with synthetic CPU tests under Wine; game execution remains untested.
@auswhalen999-debug

Copy link
Copy Markdown

AI-assisted: yes

Independent verification on rebased head 3d3ff20ef (Windows 11 x64, clang-cl 23.1.6 + lld-link 23.1.6, Windows SDK 10.0.26100, RelWithDebInfo, LEONIDA_SDL3=OFF):

  • Build (xapu_chad_test, gta6rt): succeeded cleanly (0 warnings in shims/xapu_chad.cpp and test/xapu_chad_test.cpp).
  • xapu_chad_test.exe: 33 checks, 0 failures (exit 0).
  • ctest -R xapu_chad --output-on-failure: 1/1 Passed (0.03s).
  • gta6rt.exe --help: linked cleanly and prints usage.

Verdict: PASS on 3d3ff20ef (CPU-only audio shim build and CTest confirmed after rebase).

jeremygold02 added a commit to jeremygold02/Leonida that referenced this pull request Nov 23, 2026
Retain a fork-only sample comparison for the XAPU owner. A system Media Foundation transform can decode these packets without a separate Rust crate or workflow.

Refs: ItsNotRexed#6981, ItsNotRexed#8598
@jeremygold02

Copy link
Copy Markdown
Contributor

@Jadiac5, a Windows backend is available for the type-3 path in 3d3ff20e. I submitted raw Opus packets to the registered Microsoft Opus Audio Decoder (CMSOpusDecMFT) and selected 48 kHz interleaved float32 output. Each stream kept its own decoder for two consecutive 20 ms packets. With zero pre-skip, each mono packet produced 3,840 bytes and each stereo packet 7,680 bytes.

All 5,760 float samples from the four original packets agreed with FFmpeg’s native Opus decoder to a maximum absolute error of 0.000000119. Swapping the two stereo packets preserved both output lengths and raised the sample error to 0.46968, failing the comparison. The Windows SDK and the system decoder supplied the decode path. FFmpeg generated the test inputs and reference. Windows probe · Fixture generator

To reproduce from that fork commit in an x64 Visual Studio Developer PowerShell with FFmpeg on PATH:

$source = (Get-Location).Path
$scratch = Join-Path $env:TEMP ([Guid]::NewGuid().ToString())
python -I "$source/runtime/test/opus_mft_fixture.py" $scratch
Push-Location $scratch
cl /nologo /std:c++20 /EHsc /MD /O2 /DNOMINMAX "$source/runtime/test/opus_mft_probe.cpp" /Fe:opus_mft_probe.exe mfplat.lib mfuuid.lib ole32.lib
.\opus_mft_probe.exe
Pop-Location

This was a decoder-level test on Windows 11 Home 25H2 build 26200.9974, Intel Core Ultra 7 265K, MSVC 19.44. The GeForce RTX 5070 (621.01) was idle. A check through the XAPU shim would submit a type-3 command, compare its destination samples and verify the completion’s stream ID and produced-byte count. The title’s live connection mode, playback and Wine support remain unmeasured here.

AI-assisted by GPT-6.2 Astra.

@egexon

egexon commented Nov 23, 2026

Copy link
Copy Markdown

Tested 3d3ff20 (merged onto main 867d922) on RTX 5070, NVIDIA 621.24, Windows 11 (build 26200), Vulkan validation layer on (LEONIDA_VK_VALIDATION=1, VK_VALIDATION_VALIDATE_SYNC=1): pass.

  • xapu_chad_test: new test; passes with this PR.

Ran the tests that belong to the test files this PR changes (ctest entries, or the test program directly when it is not registered), with no game files (LEONIDA_GAME_DIR unset). AI-assisted (Claude Code).

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

checked: #69813d3ff20 | with: gta6rt xapu_chad_test unimplemented_policy_test, ctest -R "xapu_chad|unimplemented_policy" | on: Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo, RTX 3060 617.14 | result: pass, 2/2
negative control: targeted (the shim file is new): in xapu_chad.cpp XApuEnqueueCommand, command[0] == 1 || command[0] == 2 changed to command[0] == 1 (close commands queue no result) | result: xapu_chad fails 2 of 33 checks (the open and the close each queued a result, XApuDequeueResult returns the type and slot), so the tests catch the change

AI-assisted (Claude Code).

@seblessa

Copy link
Copy Markdown
Contributor

An offer on top of this PR, not a competing one: one commit that makes the connections behave the way the retail executable's call sites expect. seblessa@67a35f69c (branch xapu-chad-results, on this PR's head).

It follows the public GDK reference (xapu.h, XDspAudio.h) and was checked against the executable's call sites by a static read, with no code run:

  • Every XApu command gets exactly one result with its id, visible from the second XApuGetResultCount after the enqueue. With an always-empty queue, the title's stream slots never go back to their free list.
  • A process command is answered with one frame of silence in its output buffer. The 0x50-byte result is the packed XApuResult, with outputDataLength at +0x34. An empty queue returns XAPU_E_PENDING_RESULTS.
  • XDspActivate hands out a zeroed XDspStatus per stream, because the voice path reads it with no NULL check. XDspSubmitCommand returns sequences 1, 2, ... and marks each one processed, which the title waits for before the next submit.
  • Refused calls return the documented error codes.
  • build_runtime.ps1's cl.exe fallback lists acphal.cpp and xapu_chad.cpp.

xapu_chad_test drives all ten exports in the title's shapes, on an RTX 4080 SUPER (driver 617.42, Windows 11 26H2). We're stopping active work, so fold it in or ignore it as you prefer.

AI-assisted (Claude Code).

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
runtime: xapu.dll and chad.dll shims, connections that succeed with an empty result queue (RT-489)

Independent review: ItsNotRexed#6981 (comment)

Fork integration. AI-assisted (Codex).
@KevinPratap

Copy link
Copy Markdown

Tested 3d3ff20ef together with #6885 (3b7c9f424) on RTX 4050 Laptop (NVIDIA 592.82), Windows 11, MSVC 14.44 RelWithDebInfo, LEONIDA_D3D12=vulkan, own 1.0.2.1 copy, gta6rt --run offline, no asserts stepped over: pass. I did not run this PR without #6885.

Merged onto @tibzejoker's rt5-integration 5fef1f1b1 plus #7746, #7922 and #7880, with the 52 builder programs in pipeline_cache.bin (#8858), and #7110 2f2fb2fbb, #7290, #7755 and #6885. There were three runtime/CMakeLists.txt conflicts with #6885: the source list, the test executable and the test registration. I kept both shims' entries, and each add_test has its own if/endif.

With #6885 and this PR, the run that faulted in the title's memset after the missing AcpHal calls goes 10 minutes with no crash and no assert: 65,695 D3D12 calls. I didn't separate this PR's xapu/chad part from #6885's AcpHal part in the boot.

Traces stay local; only outcomes, slot numbers and public formats here. AI-assisted (Claude Code).

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…onnections that succeed with an empty result queue (RT-489)

Squashed from ItsNotRexed#6981 by Jadiac5, head eaeee26 (security scan PASS). Conflicts in runtime/CMakeLists.txt and docs/runtime_imports.md with ItsNotRexed#6885: kept both sides.
@oz-stanislav-zhukov

Copy link
Copy Markdown

Tested 3d3ff20ef (applied with #6885 and #8461 on top of main 5d74c2723).

Boot integration datapoint (base main 5d74c2723, this PR's code merged locally with #8461's DirectStorage shim and the other audio PR, Windows 10 22H2, RTX 5060 Ti 16 GB, NVIDIA 621.24 (32.0.16.2124), MSVC 14.44 RelWithDebInfo, LEONIDA_D3D12=vulkan, own retail 1.0.2.1 copy (AI-assisted: qwen; outcomes only, no game data)):

  • gta6rt --run binds every console import: 5 module(s) mapped, 0 unimplemented import(s) (plain main leaves 20).
  • DStorageGetFactory and IDStorageFactoryX::OpenFile are served, XGameRuntimeInitialize completes, the five XMemVirtualAlloc pools are served.
  • The title then creates its device: D3D12XboxCreateDevice wraps the PC device in the Xbox-ABI proxy over the Vulkan backend (RTX 5060 Ti, subgroup 32..32, bindless set configured).
  • The run stops with an AV 0xC0000005 shortly after device slot 26 (forwarded) first call - inside the D3D12 layer, past every RT-5 boot stop measured so far.

Control: without the audio shims the same build stops earlier at a deterministic AV in the audio-object initialization (game_scarlett_master.exe+0x51d1adc, its TLS field +0x12a8 reads -1); with them that stop is gone. Not a standalone ctest run of this PR's current head - a Windows + NVIDIA boot-integration result.

@LaugeM LaugeM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read at 3d3ff20e against main 5d74c2723. This should be the xapu.dll and chad.dll shim that lands, together with #6885 for AcpHal. XDspActivate (runtime/shims/xapu_chad.cpp:178-185) hands back two zeroed 256-byte blocks of the connection. The title's wait after XDspSubmitCommand (status +0xc == 0 and +4 == *id) holds on that memory as long as the id it compares is 0. #7009's XDspActivate writes no outputs, and #8848's status block holds the descriptor's block size at +0xc. The type 1 and 2 echo in XApuEnqueueCommand (:130) is also what keeps the title's 256 stream ids from running out, and #7009 doesn't have it.

Still open at this head:

  • Types 3 and 5 get no result (xapu_chad.cpp:130). SweatierKey and jeremygold02 read the type 5 (flush) command as moving the stream to a state that only a type 5 result leaves. A type 3 result carries the output byte count at +0x34. With no echo for either, a stream that is flushed once stays stuck, and a decode never reports completion. That doesn't block boot, but it is the next stop once audio streams play. Plausible (their static reads).
  • One status block per connection (:75-78, :183-184). Every XDspActivate on a connection gets the same status and stream pointers. That is harmless while nothing writes them. Once a command really completes, each stream needs its own block, or one stream's completion reads as another's.
  • The fallback $files list in scripts/build_runtime.ps1:84 still lacks shims\xapu_chad.cpp (Hiiva raised it). test_build_runtime_fallback.py will report it, on top of main's existing xg_xs.cpp miss.

Merge note: #8848's description says this PR covers only xapu.dll, but SHIM_TABLE(chad, …) here registers all five chad.dll names. Only one of the two can land.

AI-assisted review (Opus 5.5). Read the diff against main; not built.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.