runtime: wake blocked waiters in FramePacer::set_uncapped() and prevent timeout/clock overflow #1971

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/1971 into main
IlyassRS3 commented 2026-11-25 17:04:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T17:04:24Z.


Claim: RT-FRAME-PACER-UNCAP-WAKE-AND-OVERFLOW (claim comment #7168928060 on #1608).

Fixes (runtime/src/frame_pacer.h)

  1. Wake blocked waiters in FramePacer::set_uncapped(): previously set_uncapped() only flipped uncapped_ without calling cv_.notify_all(), leaving any thread already blocked inside wait_frame_event() (e.g. with infinite_timeout_ms on the vblank grid or latency throttle) stuck until the next vblank or timeout.
  2. Saturate give_up timeout arithmetic in wait_locked(): previously start + std::uint64_t(timeout_ms) * 1000 could wrap uint64_t when start is large, setting give_up < start and causing an immediate false timeout. Now saturates cleanly at no_deadline.
  3. Prevent signed int64_t / time_point overflow in SteadyFrameClock::wait(): previously start_ + std::chrono::microseconds(deadline_us) converted an unsigned uint64_t directly to signed std::chrono::microseconds::rep (int64_t), wrapping negative for deadline_us > INT64_MAX and spinning immediately. Now computes a relative remaining duration bounded to 24 hours per cv.wait_for() call (matching the FrameClock::wait contract where callers loop on wake).

Verification

  • AI-assisted: yes.
  • GPUs tested: none (host is macOS arm64; no retail files; 0 CMakeLists.txt changes).
  • Expanded runtime/test/frame_pacer_test.cpp with three new tests: set_uncapped(true) waking a thread blocked on infinite_timeout_ms, saturating timeout near UINT64_MAX, and SteadyFrameClock::wait() with a > INT64_MAX deadline blocking cleanly until notified.
  • Ran frame_pacer_test cleanly under:
    • clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -pthread
    • clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -pthread
    • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pthread
  • Ran python3 -I scripts/check_no_game_data.py on both files and python3 -I tests/test_text_write_line_endings.py: all passed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5495670277 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1971). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T17:04:24Z. --- Claim: `RT-FRAME-PACER-UNCAP-WAKE-AND-OVERFLOW` (claim comment `#7168928060` on #1608). ### Fixes (`runtime/src/frame_pacer.h`) 1. **Wake blocked waiters in `FramePacer::set_uncapped()`**: previously `set_uncapped()` only flipped `uncapped_` without calling `cv_.notify_all()`, leaving any thread already blocked inside `wait_frame_event()` (e.g. with `infinite_timeout_ms` on the vblank grid or latency throttle) stuck until the next vblank or timeout. 2. **Saturate `give_up` timeout arithmetic in `wait_locked()`**: previously `start + std::uint64_t(timeout_ms) * 1000` could wrap `uint64_t` when `start` is large, setting `give_up < start` and causing an immediate false timeout. Now saturates cleanly at `no_deadline`. 3. **Prevent signed `int64_t` / `time_point` overflow in `SteadyFrameClock::wait()`**: previously `start_ + std::chrono::microseconds(deadline_us)` converted an unsigned `uint64_t` directly to signed `std::chrono::microseconds::rep` (`int64_t`), wrapping negative for `deadline_us > INT64_MAX` and spinning immediately. Now computes a relative remaining duration bounded to 24 hours per `cv.wait_for()` call (matching the `FrameClock::wait` contract where callers loop on wake). ### Verification - **AI-assisted**: yes. - **GPUs tested**: none (host is macOS arm64; no retail files; 0 `CMakeLists.txt` changes). - Expanded `runtime/test/frame_pacer_test.cpp` with three new tests: `set_uncapped(true)` waking a thread blocked on `infinite_timeout_ms`, saturating timeout near `UINT64_MAX`, and `SteadyFrameClock::wait()` with a `> INT64_MAX` deadline blocking cleanly until notified. - Ran `frame_pacer_test` cleanly under: - `clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror -pthread` - `clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror -pthread` - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pthread` - Ran `python3 -I scripts/check_no_game_data.py` on both files and `python3 -I tests/test_text_write_line_endings.py`: all passed.
copilot-pull-request-reviewer[bot] commented 2026-11-25 17:04:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T17:04:40Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6061727715 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1971#pullrequestreview-6061727715). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T17:04:40Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 02:51:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:51:40Z.


Hi @IlyassRS3, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/test/frame_pacer_test.cpp), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232640318 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1971#issuecomment-7232640318). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:51:40Z. --- Hi @IlyassRS3, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/test/frame_pacer_test.cpp`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
OreoFR commented 2026-11-28 21:57:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:57:17Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head 943e37c90
  • Test: not run (merge conflict with main)
  • Red on main: not run
  • Green with the PR: not run
  • Verdict: CONFLICT (conflicts with main in runtime/test/frame_pacer_test.cpp (same insertion point as another test); frame_pacer.h merges cleanly, test-side conflict is trivial)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246392252 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1971#issuecomment-7246392252). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:57:17Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `943e37c90` - Test: not run (merge conflict with main) - Red on main: not run - Green with the PR: not run - Verdict: CONFLICT (conflicts with main in runtime/test/frame_pacer_test.cpp (same insertion point as another test); frame_pacer.h merges cleanly, test-side conflict is trivial) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:40:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:40:29Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318010371 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1971#issuecomment-7318010371). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:40:29Z. --- 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.

Pull request closed

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
ProjectLeonida/mandy!1971
No description provided.