silent_audio: the silent endpoint answers four argument checks as Windows does (SILENT-AUDIO-HOST-ANSWERS) #2387

Closed
leonida/mandy
syfyra wants to merge 0 commits from fix/silent-audio-host-answers into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

syfyra commented 2026-11-26 16:55:57 +00:00

Claimed in the coordination issue as: SILENT-AUDIO-HOST-ANSWERS

What and why

I ran the same IAudioClient / IAudioRenderClient calls against the host's default render endpoint and against the silent endpoint (LEONIDA_AUDIO=silent), side by side in one probe built with silent_audio.cpp, on Windows 11, with a fresh client for each case. Most answers already match. Four calls answer differently:

call host shim on main
Initialize / IsFormatSupported with a malformed WAVEFORMATEX: nChannels, nSamplesPerSec or wBitsPerSample 0, nBlockAlign or nAvgBytesPerSec not following from them, WAVE_FORMAT_EXTENSIBLE with cbSize < 22 E_INVALIDARG AUDCLNT_E_UNSUPPORTED_FORMAT; a wrong nAvgBytesPerSec was taken as a valid format
Initialize with a malformed format on a client that is already initialized AUDCLNT_E_ALREADY_INITIALIZED AUDCLNT_E_UNSUPPORTED_FORMAT (the format was checked first)
GetService(IAudioCaptureClient) on the render client AUDCLNT_E_WRONG_ENDPOINT_TYPE E_NOINTERFACE
Reset when there is nothing to reset (never started, or reset already) S_OK S_FALSE
IAudioRenderClient::ReleaseBuffer(n, flags), n > 0, with any flag but AUDCLNT_BUFFERFLAGS_SILENT and bit 31 (one bit at a time over all 32) E_INVALIDARG, checked before the size, and the packet stays pending flags ignored, released

Each is now answered as the host does. The order of the checks follows the host too:

  • a null format or a null closest is still E_POINTER first;
  • a ReleaseBuffer with nothing pending is still AUDCLNT_E_OUT_OF_ORDER before the flags are read;
  • a 0-frame ReleaseBuffer does not look at the flags (the host returns S_OK there).

Not changed, because the answers depend on the device and engine rather than on the call: which well-formed formats are supported (the shim takes any PCM or float format on purpose), the Initialize stream-flag checks (the host's answers per bit are irregular), and the host's own Initialize refusal of 12-bit or 64-channel formats.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • silent_audio_test gets five checks, matching the table:

    • six malformed formats on a fresh client each: IsFormatSupported and Initialize are both E_INVALIDARG, and nothing comes back in closest;
    • an initialized client with a malformed format answers AUDCLNT_E_ALREADY_INITIALIZED;
    • GetService(IAudioCaptureClient) is AUDCLNT_E_WRONG_ENDPOINT_TYPE;
    • two Resets of an unused stream are S_OK;
    • ReleaseBuffer with DATA_DISCONTINUITY, 0x10, and 0x4 with an oversized count is E_INVALIDARG, and the packet is still released afterwards.

    On main, 5 checks fail, plus one follow-on: main released the packet on the bad flag, so the later release of it fails. With this branch, 134 of 134 pass.

  • Merged together with #2133 and #2134, which also change this file and test: 139 of 139 pass. Both merge cleanly with it (scripts/pr_overlap.py from #2349).

  • scripts/check_no_game_data.py on both files.

Not tested under Wine.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

Claimed in the coordination issue as: SILENT-AUDIO-HOST-ANSWERS ### What and why I ran the same `IAudioClient` / `IAudioRenderClient` calls against the host's default render endpoint and against the silent endpoint (`LEONIDA_AUDIO=silent`), side by side in one probe built with `silent_audio.cpp`, on Windows 11, with a fresh client for each case. Most answers already match. Four calls answer differently: | call | host | shim on `main` | |---|---|---| | `Initialize` / `IsFormatSupported` with a malformed `WAVEFORMATEX`: `nChannels`, `nSamplesPerSec` or `wBitsPerSample` 0, `nBlockAlign` or `nAvgBytesPerSec` not following from them, `WAVE_FORMAT_EXTENSIBLE` with `cbSize` < 22 | `E_INVALIDARG` | `AUDCLNT_E_UNSUPPORTED_FORMAT`; a wrong `nAvgBytesPerSec` was taken as a valid format | | `Initialize` with a malformed format on a client that is already initialized | `AUDCLNT_E_ALREADY_INITIALIZED` | `AUDCLNT_E_UNSUPPORTED_FORMAT` (the format was checked first) | | `GetService(IAudioCaptureClient)` on the render client | `AUDCLNT_E_WRONG_ENDPOINT_TYPE` | `E_NOINTERFACE` | | `Reset` when there is nothing to reset (never started, or reset already) | `S_OK` | `S_FALSE` | | `IAudioRenderClient::ReleaseBuffer(n, flags)`, `n` > 0, with any flag but `AUDCLNT_BUFFERFLAGS_SILENT` and bit 31 (one bit at a time over all 32) | `E_INVALIDARG`, checked before the size, and the packet stays pending | flags ignored, released | Each is now answered as the host does. The order of the checks follows the host too: - a null format or a null `closest` is still `E_POINTER` first; - a `ReleaseBuffer` with nothing pending is still `AUDCLNT_E_OUT_OF_ORDER` before the flags are read; - a 0-frame `ReleaseBuffer` does not look at the flags (the host returns `S_OK` there). Not changed, because the answers depend on the device and engine rather than on the call: which well-formed formats are supported (the shim takes any PCM or float format on purpose), the `Initialize` stream-flag checks (the host's answers per bit are irregular), and the host's own `Initialize` refusal of 12-bit or 64-channel formats. ### Tested Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo: - `silent_audio_test` gets five checks, matching the table: - six malformed formats on a fresh client each: `IsFormatSupported` and `Initialize` are both `E_INVALIDARG`, and nothing comes back in `closest`; - an initialized client with a malformed format answers `AUDCLNT_E_ALREADY_INITIALIZED`; - `GetService(IAudioCaptureClient)` is `AUDCLNT_E_WRONG_ENDPOINT_TYPE`; - two `Reset`s of an unused stream are `S_OK`; - `ReleaseBuffer` with `DATA_DISCONTINUITY`, `0x10`, and `0x4` with an oversized count is `E_INVALIDARG`, and the packet is still released afterwards. On `main`, 5 checks fail, plus one follow-on: main released the packet on the bad flag, so the later release of it fails. With this branch, 134 of 134 pass. - Merged together with #2133 and #2134, which also change this file and test: 139 of 139 pass. Both merge cleanly with it (`scripts/pr_overlap.py` from #2349). - `scripts/check_no_game_data.py` on both files. Not tested under Wine. GPUs tested: n/a (CPU tests) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wavehs reviewed 2026-11-26 18:45:40 +00:00
wavehs left a comment
No description provided.
**macOS arm64 check of #2387** (SILENT-AUDIO-FORMAT-AND-FLAGS-ANSWERS). This is a WASAPI shim and its test, both Windows-only: I could not build or run `silent_audio_test` here, so this review is a static one plus an extracted-function harness. Everything below that I say I ran, I ran. Tested head `d38ef5384` against `main` `bdbc7e923` (`git merge-tree` clean; branch 10 commits behind). Environment: Apple M3 Pro, arm64, macOS 27.2.1, Apple clang 21.0.0, CPython 3.15.2. **Why the test does not run here** `silent_audio_test` is registered in the WIN32-only part of `runtime/CMakeLists.txt` (MSVC flags, `/OPT:NOREF`), and `runtime/shims/silent_audio.cpp` includes `<windows.h>`, `<mmdeviceapi.h>`, `<audioclient.h>` and `<spatialaudioclient.h>`; the repository vendors none of them. There is no MSVC or Wine on this machine, so the new `check()` calls and the malformed-format loop are unexecuted here. The four behaviours the PR adds are all described as measured on Windows 11; I have no Windows host and cannot confirm the measurements themselves. **What I did run: the new classification, extracted verbatim** I copied `malformed_format` (and `valid_format` for the "before" answer) into a small C++ harness and fed it the six shapes the new test builds, plus realistic formats: ``` PCM 16 stereo 48k not malformed PCM 24 stereo 48k not malformed PCM 8 mono 22050 not malformed float32 8ch 48k not malformed extensible, cbSize 22 not malformed (32-bit container) extensible, cbSize 0 malformed ``` and for the test's six cases, `main`'s path vs the PR's: ``` no channels main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG no rate main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG no sample size main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG block align 3 main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG byte rate 1 main S_OK head E_INVALIDARG <-- main accepted it extensible cbSize 0 main AUDCLNT_E_UNSUPPORTED_FORMAT head E_INVALIDARG ``` That is the negative control I can give without Windows: the byte-rate case in particular was **accepted** by `main`, because `valid_format` never looked at `nAvgBytesPerSec`, so the test catches a real hole and not just a different HRESULT. `wBitsPerSample % 8` is required by `valid_format` and not by `malformed_format`, so a 12- or 20-bit container is now `E_INVALIDARG` where it used to be `E_UNSUPPORTED_FORMAT`; both are refusals of a format the shim never took, so that is only an HRESULT change. **Reading the rest of the change** - `IsFormatSupported` nulls `*closest` at entry (`:273`), so the new early return leaves it null and the test's `!closest` holds. - `init()` has `if (!format) return E_POINTER` before the lock (`:451`), so `malformed_format` never sees null; moving `Lock l(lock_)` above `valid_format` is safe. - `valid_format` guards `cbSize >= 22` in both places it reads the extension (`is_float` and its own EXTENSIBLE branch), so the `cbSize < 22` case was already not an out-of-bounds read; the new check makes it a refusal with the right HRESULT, not a crash fix. - `AudioClient::GetService` writes `*ppv = nullptr` first (`:641`), so returning `AUDCLNT_E_WRONG_ENDPOINT_TYPE` for `IAudioCaptureClient` leaves the out pointer null as the test expects, and the `E_NOINTERFACE` log path is untouched. - `release_buffer` checks flags after the `pending_` check and before the size, and returns before touching `pending_`, which is what the test's "packet stays pending, then ReleaseBuffer(frames, 0) succeeds" relies on. - The `Reset` change removes the `S_FALSE` early return, and nothing in the runtime calls `IAudioClient::Reset` (`git grep` over `runtime/` finds only allocator/list `Reset`), so no other shim depends on the old answer. - Note that a malformed format in `AUDCLNT_SHAREMODE_EXCLUSIVE` still gets `AUDCLNT_E_UNSUPPORTED_FORMAT`, because the mode branch comes first; the new rule therefore holds for shared mode, which is the only mode the shim accepts anyway. **Findings** 1. **Signed overflow on the garbage it is meant to reject** - `runtime/shims/silent_audio.cpp:128`: `f->nChannels * f->wBitsPerSample / 8` multiplies two `WORD`s after integer promotion to `int`, so a caller passing `nChannels = 65535, wBitsPerSample = 65535` overflows `int`. UBSan on the extracted function aborts with `signed integer overflow: 65535 * 65535 cannot be represented in type 'int'` before the function can return `true`. This is reachable from `IsFormatSupported` and `Initialize` with a title-supplied struct, in the one function whose job is to classify exactly that input. One cast fixes it and matches the line below: `static_cast<uint64_t>(f->nChannels) * f->wBitsPerSample / 8`. 2. **The shim's documented answers are now stale** - `docs/runtime_imports.md:277` enumerates what the silent endpoint answers ("`GetService` gives `IAudioRenderClient`, `IAudioClock`, `ISimpleAudioVolume` and `IAudioStreamVolume`", "The client takes any PCM or float format in shared mode"). After this PR the paragraph is missing three measured answers: `IAudioCaptureClient` on a render endpoint is `AUDCLNT_E_WRONG_ENDPOINT_TYPE`, a malformed format is `E_INVALIDARG` rather than `AUDCLNT_E_UNSUPPORTED_FORMAT`, and a `Reset` with nothing to reset is `S_OK`. The file's habit elsewhere is to record the host's answer next to the behaviour, and these are the kind of detail a title's error path turns on, so a sentence there is worth the three lines. 3. **Nit in the new test** - `runtime/test/silent_audio_test.cpp:385-397`: `closest` is initialised to `nullptr` and the refusal returns before it can be written, so `|| closest` cannot fail; it would pin "not written" only if it started as a non-null poison value. Harmless, but it is the one check in the loop that cannot bite. **No regressions to measure on this side**: no translator, harness or GPU code changes, so the shader fixtures were not re-run; the same-main baseline stands (195 PASS / 3 FAIL / 70 SKIP MoltenVK, 190 / 5 / 73 KosmicKrisp). `python -I scripts/check_no_game_data.py runtime/shims/silent_audio.cpp runtime/test/silent_audio_test.cpp`: clean. No game files. AI-assisted.
fiestorra commented 2026-11-30 11:07:46 +00:00

Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions.

1. It applies. merge-tree clean; the commits cherry-pick onto main d367675c7 without a conflict. Two files: runtime/shims/silent_audio.cpp and runtime/test/silent_audio_test.cpp.

2. With the branch its test passes:

ctest -R 'silent_audio'
100% tests passed, 0 tests failed out of 1

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/silent_audio.cpp
cmake --build … --target silent_audio_test
ctest -R 'silent_audio' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL IsFormatSupported and Initialize refuse a malformed format with E_INVALIDARG
FAIL an initialized client says so before it looks at the format, as on the host

Both failures name the rule: a malformed format must be refused with E_INVALIDARG by both IsFormatSupported and Initialize, and an already-initialised client must answer "initialised" before it validates the format - the ordering is part of the contract, not an accident of the code.

Note that #2133 touches the same shim (silent_audio.cpp, the empty-packet rule) and its control also bites; the two changes are in different paths of the same file, so they will need a rebase against each other whichever lands second, but neither contains the other.

What I did not test: the rest of the audio shim, and whether the console's real client orders those checks the same way.

Why I am commenting: I verify open pull requests that replay onto current main, then revert only the source change. 26 controls so far: 18 bite.

Written with an AI assistant.

Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `d367675c7` without a conflict. Two files: `runtime/shims/silent_audio.cpp` and `runtime/test/silent_audio_test.cpp`. **2. With the branch its test passes:** ``` ctest -R 'silent_audio' 100% tests passed, 0 tests failed out of 1 ``` **3. The control - revert only the shim, keep the test:** ``` git checkout origin/main -- runtime/shims/silent_audio.cpp cmake --build … --target silent_audio_test ctest -R 'silent_audio' --output-on-failure 0% tests passed, 1 tests failed out of 1 FAIL IsFormatSupported and Initialize refuse a malformed format with E_INVALIDARG FAIL an initialized client says so before it looks at the format, as on the host ``` **Both failures name the rule**: a **malformed format** must be refused with `E_INVALIDARG` by both `IsFormatSupported` **and** `Initialize`, and **an already-initialised client must answer "initialised" before it validates the format** - the ordering is part of the contract, not an accident of the code. **Note that #2133 touches the same shim** (`silent_audio.cpp`, the empty-packet rule) and its control also bites; the two changes are in different paths of the same file, so **they will need a rebase against each other** whichever lands second, but neither contains the other. **What I did not test:** the rest of the audio shim, and whether the console's real client orders those checks the same way. **Why I am commenting:** I verify open pull requests that replay onto current `main`, then revert **only** the source change. **26 controls so far: 18 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 12:35:42 +00:00

Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
merzleckeier commented 2026-12-01 12:56:16 +00:00

Independent WASAPI answer check under Wine 11.22 at d38ef5384 + c95183fd8. I built the same Windows silent_audio_test on both arms (explicit ole32 linkage for the local clang-cl cross-build). The PR passed 140/140 checks. Main with the new test had six failures, including malformed format handling, already-initialized precedence, capture on a render endpoint, Reset with nothing pending, and rejection of the invalid render flag. The final buffer release also differed after the flag check. This exercises the silent shim and mock endpoints.

AI-assisted with OpenAI Codex.

Independent WASAPI answer check under Wine 11.22 at `d38ef5384` + `c95183fd8`. I built the same Windows `silent_audio_test` on both arms (explicit `ole32` linkage for the local clang-cl cross-build). The PR passed 140/140 checks. Main with the new test had six failures, including malformed format handling, already-initialized precedence, capture on a render endpoint, Reset with nothing pending, and rejection of the invalid render flag. The final buffer release also differed after the flag check. This exercises the silent shim and mock endpoints. AI-assisted with OpenAI Codex.
aslan2142 commented 2026-12-01 16:44:27 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.