acphal: audio frame deadlines are exact 1/375 s per frame index #463

Open
DavidM1911 wants to merge 1 commit from upstream-pr/468 into main
DavidM1911 commented 2026-11-24 00:43:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T00:43:36Z.


Part of #329 (item 3).

FRAME was 2667 µs where one audio frame (128 samples at 48 kHz) is exactly 1/375 s = 2666.6 µs, and each pop scheduled the next frame by adding it — so the cadence drifted +0.333 µs per frame (+125 ppm, ~0.45 s per hour of audio). Deadlines are now computed per 1-based frame index as epoch + k/375 s in integer nanoseconds (frame_deadline), so there is no accumulation. The "a frame more than 8 late is not made up for" rule is kept by fast-forwarding the index to the same floor (now - 8·FRAME).

What is in it

  • crates/xcl/src/hle/acphal.rs: Channel stores epoch + next_frame index instead of Option<Instant>; frame_due/pop/connect reworked; frame_deadline helper; FRAME_CATCHUP constant; a test that walks 375 frames (exactly 1 s) checking each is due at epoch + k/375 s and not 1 ns earlier.

Tested

  • Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 x86_64-pc-windows-msvc:
    • cargo test -p xcl --lib acphal: 8 passed, 0 failed
    • cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored
  • Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, scripts/smoke.ps1 -Seconds 60, cargo build --release -p xcl:

main a6f5f7a:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14437 MB

this PR's head 0d407cf:

xcl-smoke v1
commit: 0d407cfcf81756012401c85f27462e41747b7165
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1498 (PresentX 1498)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14449 MB

Not tested

  • Long-run audible drift (the fix is arithmetic; the unit test pins the grid for 1 s of frames)
  • AMD adapter smoke run

AI use

  • Devin (SWE-2 Flash Medium): implemented the fix and test, ran the suites and smoke runs.
<!-- greyfinch-sync:ivall/xcl:issue:5463876249 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/468). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T00:43:36Z. --- Part of #329 (item 3). `FRAME` was 2667 µs where one audio frame (128 samples at 48 kHz) is exactly 1/375 s = 2666.6 µs, and each `pop` scheduled the next frame by adding it — so the cadence drifted +0.333 µs per frame (+125 ppm, ~0.45 s per hour of audio). Deadlines are now computed per 1-based frame index as `epoch + k/375 s` in integer nanoseconds (`frame_deadline`), so there is no accumulation. The "a frame more than 8 late is not made up for" rule is kept by fast-forwarding the index to the same floor (`now - 8·FRAME`). **What is in it** - `crates/xcl/src/hle/acphal.rs`: `Channel` stores `epoch` + `next_frame` index instead of `Option<Instant>`; `frame_due`/`pop`/`connect` reworked; `frame_deadline` helper; `FRAME_CATCHUP` constant; a test that walks 375 frames (exactly 1 s) checking each is due at `epoch + k/375 s` and not 1 ns earlier. **Tested** - Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 `x86_64-pc-windows-msvc`: - `cargo test -p xcl --lib acphal`: 8 passed, 0 failed - `cargo test --workspace -- --test-threads=4`: 677 passed, 0 failed, 41 ignored - Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, `scripts/smoke.ps1 -Seconds 60`, `cargo build --release -p xcl`: main `a6f5f7a`: ``` xcl-smoke v1 commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1503 (PresentX 1503) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14437 MB ``` this PR's head `0d407cf`: ``` xcl-smoke v1 commit: 0d407cfcf81756012401c85f27462e41747b7165 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1498 (PresentX 1498) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14449 MB ``` **Not tested** - Long-run audible drift (the fix is arithmetic; the unit test pins the grid for 1 s of frames) - AMD adapter smoke run **AI use** - Devin (SWE-2 Flash Medium): implemented the fix and test, ran the suites and smoke runs.
ethandepstein-del commented 2026-11-24 07:05:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ethandepstein-del on 2026-11-24T01:02:13Z.


Code audit + NVIDIA RTX 5080 test run on 0d407cfcf81756012401c85f27462e41747b7165 (part of #329):

Review

Looks clean — frame_deadline(epoch, k) computes epoch + floor(k * 10^9 / 375) in u128 nanoseconds with zero cumulative drift, and the catch-up floor ceiling (wait_ns * 375 + 999_999_999) / 1_000_000_000 preserves the FRAME_CATCHUP = 8 cap cleanly. (Small note: this and #471 both touch Channel::connect one line apart, so whichever merges second will need a trivial rebase.)

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored.
  • New test hle::acphal::tests::frames_stay_on_the_48k_grid_without_drift: passed.
  • SKIPPED GPU tests (2, wave32-only adapter): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

<!-- greyfinch-sync:ivall/xcl:comment:7118687582 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/468#issuecomment-7118687582). Originally posted by [ethandepstein-del](https://github.com/ethandepstein-del) on 2026-11-24T01:02:13Z. --- Code audit + NVIDIA RTX 5080 test run on `0d407cfcf81756012401c85f27462e41747b7165` (part of #329): ### Review Looks clean — `frame_deadline(epoch, k)` computes `epoch + floor(k * 10^9 / 375)` in `u128` nanoseconds with zero cumulative drift, and the catch-up floor ceiling `(wait_ns * 375 + 999_999_999) / 1_000_000_000` preserves the `FRAME_CATCHUP = 8` cap cleanly. *(Small note: this and #471 both touch `Channel::connect` one line apart, so whichever merges second will need a trivial rebase.)* ### Tested - Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), `rustc 1.100.0` (MSVC), debug build. - `cargo build --workspace && cargo test --workspace -- --test-threads=4`: **677 passed, 0 failed, 41 ignored**. - New test `hle::acphal::tests::frames_stay_on_the_48k_grid_without_drift`: **passed**. - `SKIPPED` GPU tests (2, wave32-only adapter): `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64`. ### Not tested - Retail title / `scripts/smoke.ps1` run (test suite only). - AMD / Intel GPUs. *AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.*
alpz1000 commented 2026-11-24 07:05:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by alpz1000 on 2026-11-24T01:38:36Z.


Independent check of audio frame scheduling at 0d407cfcf81756012401c85f27462e41747b7165 on Windows 11 Home 26200.9974, Intel Core i5-8400, Rust 1.100.0 x86_64-pc-windows-msvc, debug.

Tested: cargo test --locked -p xcl --lib acphal on the unmodified PR head: 8 passed, 0 failed. Then I temporarily extended only the loop bound in frames_stay_on_the_48k_grid_without_drift from 375 to 1,350,000 and reran that test. It passed across one simulated hour at 375 frames/s, checking at every frame that it was not due 1 ns before its deadline and was due at the deadline. The local edit was reverted.

Not tested: audible drift, actual audio playback, retail titles, or the full workspace suite. This checks the scheduler against simulated timestamps.

AI use: OpenAI Codex (GPT-6) ran the tests and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7119304569 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/468#issuecomment-7119304569). Originally posted by [alpz1000](https://github.com/alpz1000) on 2026-11-24T01:38:36Z. --- Independent check of audio frame scheduling at `0d407cfcf81756012401c85f27462e41747b7165` on Windows 11 Home 26200.9974, Intel Core i5-8400, Rust 1.100.0 x86_64-pc-windows-msvc, debug. **Tested**: `cargo test --locked -p xcl --lib acphal` on the unmodified PR head: 8 passed, 0 failed. Then I temporarily extended only the loop bound in `frames_stay_on_the_48k_grid_without_drift` from 375 to 1,350,000 and reran that test. It passed across one simulated hour at 375 frames/s, checking at every frame that it was not due 1 ns before its deadline and was due at the deadline. The local edit was reverted. **Not tested**: audible drift, actual audio playback, retail titles, or the full workspace suite. This checks the scheduler against simulated timestamps. **AI use**: OpenAI Codex (GPT-6) ran the tests and drafted this report.
ryosen0 commented 2026-11-24 07:05:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ryosen0 on 2026-11-24T01:57:23Z.


Data point from the same NVIDIA card the PR was tested on, different CPU/driver: RTX 3060 Ti 8 GB, Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11. Head 0d407cf merged onto main 508a0c7 (clean), together with #456 and #508 (adjacent paths).

  • cargo test -p xcl --lib -- --test-threads=1 title_textures xaudio2 acphal: 27 passed, 0 failed, including the 375-frame deadline walk.
  • The integer-ns epoch + k/375 s construction reads right: no accumulation, and the fast-forward floor keeps the >8-late rule without a second drift source.

Not tested: audible retail audio on this stack (the run ended early on its own at t≈34 s, exit 0x0 - unrelated early-exit behaviour of the title); no long-run drift measurement.

AI use: GPT-6.2 Astra (API model selector) in DSH ran the tests and wrote this comment; the human contributor reviewed it.

<!-- greyfinch-sync:ivall/xcl:comment:7119614185 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/468#issuecomment-7119614185). Originally posted by [ryosen0](https://github.com/ryosen0) on 2026-11-24T01:57:23Z. --- Data point from the same NVIDIA card the PR was tested on, different CPU/driver: RTX 3060 Ti 8 GB, Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11. Head `0d407cf` merged onto `main` `508a0c7` (clean), together with #456 and #508 (adjacent paths). - `cargo test -p xcl --lib -- --test-threads=1 title_textures xaudio2 acphal`: **27 passed, 0 failed**, including the 375-frame deadline walk. - The integer-ns `epoch + k/375 s` construction reads right: no accumulation, and the fast-forward floor keeps the >8-late rule without a second drift source. Not tested: audible retail audio on this stack (the run ended early on its own at t≈34 s, exit 0x0 - unrelated early-exit behaviour of the title); no long-run drift measurement. AI use: GPT-6.2 Astra (API model selector) in DSH ran the tests and wrote this comment; the human contributor reviewed it.
MesshM commented 2026-11-24 07:06:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T04:21:29Z.


Test run of 0d407cfcf81756012401c85f27462e41747b7165 on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 702 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 661 passed, 0 failed, 21 ignored
  • 0 SKIPPED; frames_stay_on_the_48k_grid_without_drift passes.

Review: Deadlines are epoch + k/375 s in integer nanoseconds per frame index, so there is no accumulated rounding, and FRAME_CATCHUP bounds how many frames a late pop releases at once. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

<!-- greyfinch-sync:ivall/xcl:comment:7121943929 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/468#issuecomment-7121943929). Originally posted by [MesshM](https://github.com/MesshM) on 2026-11-24T04:21:29Z. --- Test run of `0d407cfcf81756012401c85f27462e41747b7165` on AMD RDNA4. I merged it onto current `main` `f4ce27c` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **702 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 661 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `frames_stay_on_the_48k_grid_without_drift` passes. **Review:** Deadlines are `epoch + k/375 s` in integer nanoseconds per frame index, so there is no accumulated rounding, and `FRAME_CATCHUP` bounds how many frames a late `pop` releases at once. I found nothing to change. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Alpha325 commented 2026-11-25 03:05:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Alpha325 on 2026-11-25T02:45:56Z.


I added a synthetic Channel::pop test that leaves the channel unpolled for one hour, then drains the frames due at that instant. I ran it at the exact one-hour boundary and 1 ms after it.

First poll Parent 2997c9a PR 0d407cf
1 hour 10 frames drained 10 frames drained
1 hour + 1 ms 10 frames drained 9 frames drained

The totals include the first frame emitted before the catch-up clamp. After draining, neither revision emitted a frame 1 ns before the next deadline on the original 375 Hz grid. At that exact deadline, 2,666,666 ns after the hour boundary, the PR emitted MSG_AUDIO_FRAME in both cases. The parent emitted nothing and failed the fixture as expected.

On Windows 11 with Rust 1.100.0 MSVC, cargo test --offline --locked -p xcl --lib acphal -- --test-threads=1 --nocapture returned 9 passed, 0 failed on the PR. This checks scheduling with synthetic timestamps. It does not measure audible playback.

AI use — OpenAI Codex (GPT-6) wrote and ran the fixture and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7151157675 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/468#issuecomment-7151157675). Originally posted by [Alpha325](https://github.com/Alpha325) on 2026-11-25T02:45:56Z. --- I added a synthetic `Channel::pop` test that leaves the channel unpolled for one hour, then drains the frames due at that instant. I ran it at the exact one-hour boundary and 1 ms after it. | First poll | Parent `2997c9a` | PR `0d407cf` | |---|---|---| | 1 hour | 10 frames drained | 10 frames drained | | 1 hour + 1 ms | 10 frames drained | 9 frames drained | The totals include the first frame emitted before the catch-up clamp. After draining, neither revision emitted a frame 1 ns before the next deadline on the original 375 Hz grid. At that exact deadline, 2,666,666 ns after the hour boundary, the PR emitted `MSG_AUDIO_FRAME` in both cases. The parent emitted nothing and failed the fixture as expected. On Windows 11 with Rust 1.100.0 MSVC, `cargo test --offline --locked -p xcl --lib acphal -- --test-threads=1 --nocapture` returned 9 passed, 0 failed on the PR. This checks scheduling with synthetic timestamps. It does not measure audible playback. AI use — OpenAI Codex (GPT-6) wrote and ran the fixture and drafted this report.
DavidM1911 commented 2026-11-25 15:07:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T14:15:44Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7165005360 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/468#issuecomment-7165005360). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T14:15:44Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
github-actions[bot] commented 2026-11-29 20:41:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:41:57Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7262287081 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/468#issuecomment-7262287081). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:41:57Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 03:10:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:10:46Z.


Triage (#1607) – head 0d407cf

#463 fixes a different bug from the same issue #329 (PopMessage BOOL width); #471 (merged) fixed the stale-message item. Main's Channel still advances next_frame by FRAME (2667 us), so the drift is not fixed there.
frame_deadline computes frame k at k/375 s in integer nanoseconds, and the catch-up floor matches the old 8-frame behaviour. No problems found in the diff. The PR conflicts with main (main's Channel::connect changed in #471).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7299412828 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/468#issuecomment-7299412828). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:10:46Z. --- **Triage (#1607)** – head 0d407cf #463 fixes a different bug from the same issue #329 (PopMessage BOOL width); #471 (merged) fixed the stale-message item. Main's `Channel` still advances `next_frame` by `FRAME` (2667 us), so the drift is not fixed there. `frame_deadline` computes frame k at k/375 s in integer nanoseconds, and the catch-up floor matches the old 8-frame behaviour. No problems found in the diff. The PR conflicts with main (main's `Channel::connect` changed in #471). Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/468:upstream-pr/468'
git switch 'upstream-pr/468'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/468'
git switch 'upstream-pr/468'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/468'
git switch 'upstream-pr/468'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/468'
git switch 'main'
git merge --squash 'upstream-pr/468'
git switch 'main'
git merge --ff-only 'upstream-pr/468'
git switch 'main'
git merge 'upstream-pr/468'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!463
No description provided.