silent_audio: pace the 10 ms passes with a high-resolution timer (SILENT-AUDIO-PASS-CADENCE) #2134

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

Pull request closed

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

syfyra commented 2026-11-25 22:28:20 +00:00

Claimed in the coordination issue as: SILENT-AUDIO-PASS-CADENCE (claim comment to follow)

What and why

runtime/shims/silent_audio.cpp PeriodicThread::run drives both silent streams' 10 ms passes. It waited for each pass with WaitForSingleObject(stop_, wait) and a timeout in whole milliseconds. On Windows a wait timeout ends on the system timer's tick: 15.625 ms for a process that has not raised the timer resolution, and nothing in runtime/ does (no timeBeginPeriod/NtSetTimerResolution). The 10 ms period therefore woke once per tick, and the fixed schedule re-anchored after each late wake: about 64 passes a second instead of 100.

The title activates ISpatialAudioClient first (docs/runtime_imports.md), and the spatial stream hands out 480 frames per pass and signals its event once per pass. A title paced by that event rendered about 30,700 frames a second against 48,000: its audio clock ran at 64% of real time. The IAudioClient stream's event came at the same rate (its padding is measured with QPC, so only its cadence was off).

The wait now uses a CREATE_WAITABLE_TIMER_HIGH_RESOLUTION timer set to the next pass's due time, with the stop event beside it in WaitForMultipleObjects, as the gameinput and d3d12_xs shims already do. Where the timer cannot be created, the timeout wait remains. It also ends the short busy spin the old loop did when less than 1 ms was left (wait truncated to 0).

Tested

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

  • silent_audio_test now records when each spatial pass's event arrives and checks the median gap of the nine after Start (8 to 12.5 ms), unless the whole run took over 300 ms: a host that starved the passes says nothing about the timer, so there the gaps are only printed.
    • main: 10 passes in 143 to 159 ms, median gap 15.6 to 17.2 ms; the check fails in 3 of 3 runs.
    • this branch: 10 passes in 90 ms, median gap 10.0 ms; all 130 checks pass in 3 of 3 runs (earlier runs: 94 to 102 ms, 9.7 to 10.7 ms).
  • ctest -j 8 (162 CPU tests) passes, apart from xmem_test's system-wide commit check that #1316 addresses.
  • scripts/check_no_game_data.py on both files.

Not tested under Wine; there the high-resolution timer may be unavailable and the old wait stays in use.

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-PASS-CADENCE (claim comment to follow) ### What and why `runtime/shims/silent_audio.cpp` `PeriodicThread::run` drives both silent streams' 10 ms passes. It waited for each pass with `WaitForSingleObject(stop_, wait)` and a timeout in whole milliseconds. On Windows a wait timeout ends on the system timer's tick: 15.625 ms for a process that has not raised the timer resolution, and nothing in `runtime/` does (no `timeBeginPeriod`/`NtSetTimerResolution`). The 10 ms period therefore woke once per tick, and the fixed schedule re-anchored after each late wake: about 64 passes a second instead of 100. The title activates `ISpatialAudioClient` first (docs/runtime_imports.md), and the spatial stream hands out 480 frames per pass and signals its event once per pass. A title paced by that event rendered about 30,700 frames a second against 48,000: its audio clock ran at 64% of real time. The `IAudioClient` stream's event came at the same rate (its padding is measured with QPC, so only its cadence was off). The wait now uses a `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION` timer set to the next pass's due time, with the stop event beside it in `WaitForMultipleObjects`, as the gameinput and d3d12_xs shims already do. Where the timer cannot be created, the timeout wait remains. It also ends the short busy spin the old loop did when less than 1 ms was left (`wait` truncated to 0). ### Tested Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo: - `silent_audio_test` now records when each spatial pass's event arrives and checks the median gap of the nine after `Start` (8 to 12.5 ms), unless the whole run took over 300 ms: a host that starved the passes says nothing about the timer, so there the gaps are only printed. - `main`: 10 passes in 143 to 159 ms, median gap 15.6 to 17.2 ms; the check fails in 3 of 3 runs. - this branch: 10 passes in 90 ms, median gap 10.0 ms; all 130 checks pass in 3 of 3 runs (earlier runs: 94 to 102 ms, 9.7 to 10.7 ms). - `ctest -j 8` (162 CPU tests) passes, apart from `xmem_test`'s system-wide commit check that #1316 addresses. - `scripts/check_no_game_data.py` on both files. Not tested under Wine; there the high-resolution timer may be unavailable and the old wait stays in use. 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)
fiestorra commented 2026-11-30 11:10:26 +00:00

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

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

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 the passes are 10 ms apart, not one system timer tick

The assertion is the change: two consecutive passes must be 10 ms apart rather than one system timer tick - the branch makes the audio shim pace by millisecond sleep instead of by GetTickCount granularity. A timing assertion with a number in it is the easiest kind to trust, provided the machine is not loaded: this ran on an idle box at 12:05.

Heads-up for whoever merges the silent_audio changes: #2133 and #2387 touch the same file, each with a control that bites, in different paths (empty-packet release, format validation). All three will need rebases against each other whichever lands first - and this one is the only one of the three with a timing assertion, so it is the one to run on an idle machine.

What I did not test: whether 10 ms is the right target on a loaded host or under Wine, and the rest of the audio shim.

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

Written with an AI assistant.

Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `d367675c7` without a conflict. Two files: `runtime/shims/silent_audio.cpp` (the change) and the test. **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 the passes are 10 ms apart, not one system timer tick ``` **The assertion is the change**: two consecutive passes must be **10 ms apart** rather than **one system timer tick** - the branch makes the audio shim pace by millisecond sleep instead of by `GetTickCount` granularity. **A timing assertion with a number in it is the easiest kind to trust**, provided the machine is not loaded: this ran on an idle box at 12:05. **Heads-up for whoever merges the `silent_audio` changes:** **#2133 and #2387 touch the same file**, each with a control that bites, in different paths (empty-packet release, format validation). **All three will need rebases against each other** whichever lands first - and **this one is the only one of the three with a timing assertion**, so it is the one to run on an idle machine. **What I did not test:** whether 10 ms is the right target on a loaded host or under Wine, and the rest of the audio shim. **Why I am commenting:** I verify open pull requests that replay onto current `main`, then revert **only** the source change. **28 controls so far: 19 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 12:22:41 +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.)*
aslan2142 commented 2026-12-01 16:42:29 +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.