OLD-9189: restore old upstream PR 9189 - FramePacer: at most latency frames in flight while armed (mailbox replace) #671

Merged
aslan2142 merged 3 commits from upstream-pr/671 into main 2026-11-25 23:01:38 +00:00
aslan2142 commented 2026-11-24 11:22:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T11:22:08Z.


Claimed in the coordination issue as: OLD-9189 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129812657

Restoration of my original pull request, old upstream PR 9189 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c; the commit applied without changes. The only edit is in the commit message, where an old issue number is now plain text. The uncap mode added to main since then (LEONIDA_PRESENT_UNCAP) is untouched: an uncapped present still returns before it reaches the queue.

What and why

  • The bug: on main, commit_present_token and note_untokened_present add one queued frame for every present, each one period after the last.
    • So presents with no WaitFrameEventX between them grow the queue without limit, and the next wait blocks until the first of them is shown.
    • Example: at latency 2, 1000 blank presents leave 1000 frames in flight, and the next wait passes 999 periods later.
  • The fix (runtime/src/frame_pacer.h): at most latency frames are in flight while the event is armed.
    • A present into a full queue replaces the newest queued frame and takes its vblank, like a mailbox.
    • The replaced frame is never shown, so it has no display statistic. The older frames keep their vblanks.
    • The next wait passes when the oldest frame is shown.
  • A lowered latency: if SetFrameIntervalX sets a latency below the number of frames already queued, the next present cuts the queue back to the new latency from the newest end.
  • Unchanged: presents made before the event is armed stay unpaced, and a frame queued behind another still cannot be shown at once.
  • frame_pacer_test now covers:
    • 1000 untokened presents after one wait, at latency 1, 2 and 3;
    • tokened presents beyond the latency: the older frames keep their vblanks, and the replaced frame has no display statistic;
    • one present per wait;
    • a lowered latency.
  • xbox_present_test: it expected a blank present after a frame at latency 1 to leave 2 frames in flight. That is now 1.
  • docs/d3d12_vulkan.md: documents the limit.

Tested

Linux, with gcc for the native build and clang 23 targeting mingw x64, run under Wine 11.22. MSVC is left to CI.

Build frame_pacer_test (gcc, Linux) frame_pacer_test (clang mingw, Wine) xbox_present_test (clang mingw, Wine)
main pass pass pass
main with only this PR's test changes fails: 128 of 399 checks fails: 128 of 399 checks fails at the changed in-flight check
this branch pass, 399 of 399 checks pass, 399 of 399 checks pass
  • xbox_present_test on this branch passed 26 cases on both GPUs. The HDR10 swapchain case was skipped because the display lists no ST.2084 format.
  • xbox_present.h is the only other file that includes frame_pacer.h. d3d12_boot_movie_test also uses it, but it needs the retail package, so I didn't run it.
  • git diff --check and python -I scripts/check_no_game_data.py on the changed files: clean.
  • Merges cleanly with the open pull requests that touch frame_pacer.h or the present path: #402, #414, #526, #551, #553.

GPUs tested: AMD Radeon RX 7900 XTX (RADV NAVI31) and AMD Ryzen 9 7950X3D integrated GPU (RADV RAPHAEL_MENDOCINO), both Mesa 26.3.1, Arch Linux, through Wine 11.22 (xbox_present_test only; frame_pacer_test needs no GPU)

AI-assisted: yes

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)

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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5471179584 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/671). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T11:22:08Z. --- Claimed in the coordination issue as: OLD-9189 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129812657 Restoration of my original pull request, old upstream PR 9189 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8c675c62f9dbffc318ce6a59d57faf31; the commit applied without changes. The only edit is in the commit message, where an old issue number is now plain text. The uncap mode added to `main` since then (`LEONIDA_PRESENT_UNCAP`) is untouched: an uncapped present still returns before it reaches the queue. ### What and why - **The bug:** on `main`, `commit_present_token` and `note_untokened_present` add one queued frame for every present, each one period after the last. - So presents with no `WaitFrameEventX` between them grow the queue without limit, and the next wait blocks until the first of them is shown. - Example: at latency 2, 1000 blank presents leave 1000 frames in flight, and the next wait passes 999 periods later. - **The fix (`runtime/src/frame_pacer.h`):** at most `latency` frames are in flight while the event is armed. - A present into a full queue replaces the newest queued frame and takes its vblank, like a mailbox. - The replaced frame is never shown, so it has no display statistic. The older frames keep their vblanks. - The next wait passes when the oldest frame is shown. - **A lowered latency:** if `SetFrameIntervalX` sets a latency below the number of frames already queued, the next present cuts the queue back to the new latency from the newest end. - **Unchanged:** presents made before the event is armed stay unpaced, and a frame queued behind another still cannot be shown at once. - **`frame_pacer_test` now covers:** - 1000 untokened presents after one wait, at latency 1, 2 and 3; - tokened presents beyond the latency: the older frames keep their vblanks, and the replaced frame has no display statistic; - one present per wait; - a lowered latency. - **`xbox_present_test`:** it expected a blank present after a frame at latency 1 to leave 2 frames in flight. That is now 1. - **`docs/d3d12_vulkan.md`:** documents the limit. ### Tested Linux, with gcc for the native build and clang 23 targeting mingw x64, run under Wine 11.22. MSVC is left to CI. | Build | `frame_pacer_test` (gcc, Linux) | `frame_pacer_test` (clang mingw, Wine) | `xbox_present_test` (clang mingw, Wine) | |---|---|---|---| | `main` | pass | pass | pass | | `main` with only this PR's test changes | fails: 128 of 399 checks | fails: 128 of 399 checks | fails at the changed in-flight check | | this branch | pass, 399 of 399 checks | pass, 399 of 399 checks | pass | - `xbox_present_test` on this branch passed 26 cases on both GPUs. The HDR10 swapchain case was skipped because the display lists no ST.2084 format. - `xbox_present.h` is the only other file that includes `frame_pacer.h`. `d3d12_boot_movie_test` also uses it, but it needs the retail package, so I didn't run it. - `git diff --check` and `python -I scripts/check_no_game_data.py` on the changed files: clean. - Merges cleanly with the open pull requests that touch `frame_pacer.h` or the present path: #402, #414, #526, #551, #553. GPUs tested: AMD Radeon RX 7900 XTX (RADV NAVI31) and AMD Ryzen 9 7950X3D integrated GPU (RADV RAPHAEL_MENDOCINO), both Mesa 26.3.1, Arch Linux, through Wine 11.22 (`xbox_present_test` only; `frame_pacer_test` needs no GPU) AI-assisted: yes ### 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) AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-11-24 19:30:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:30:58Z.


Merged main after #891 (BL-6) to clear the conflict.

Conflict

  • One hunk in runtime/src/frame_pacer.h: both PRs add a private helper in the same place, queue_flip_locked (this PR) and record_present_timing_locked (#891). Both are kept.
  • note_untokened_present merged on its own: it records its timing first (#891), then queues through queue_flip_locked (this PR).

Dropped frames and the BL-6 statistics

  • #891 records the interval at PresentX, before the frame is queued. A frame the bounded queue replaces was still presented, so it counts with its real present-to-present interval. The replacement adds no interval and removes none.
  • So the statistics stay meaningful: they describe the title's present cadence, not the frames shown. A burst of presents between two waits shows up as short intervals, with or without this PR.
  • No code change. docs/d3d12_vulkan.md now says this next to the BL-6 text.
  • New case in frame_pacer_test, at latency 1: four presents, two of them replaced. It checks frames 4, samples 3, mean, drift, nearest-rank p50/p95/p99, two origin-to-present latencies (the replaced token included), and that the frames that are shown keep their vblanks.

Tests (Linux, portable runtime subset)

  • ctest: 74/74 passed, 2 skipped (shader_library_corpus, vk_sync_validation), the same as main alone. Vulkan tests ran on the AMD iGPU (RDNA2, RADV).
  • frame_pacer_test: passes, including the new case and this PR's bounded-queue cases.
  • python -I tests/test_boot_trace.py: 33/33.
  • check_no_game_data.py on every changed file: clean.
  • xbox_present_test is Windows-only and was not run here.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142208680 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/671#issuecomment-7142208680). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:30:58Z. --- Merged `main` after #891 (BL-6) to clear the conflict. **Conflict** - One hunk in `runtime/src/frame_pacer.h`: both PRs add a private helper in the same place, `queue_flip_locked` (this PR) and `record_present_timing_locked` (#891). Both are kept. - `note_untokened_present` merged on its own: it records its timing first (#891), then queues through `queue_flip_locked` (this PR). **Dropped frames and the BL-6 statistics** - #891 records the interval at `PresentX`, before the frame is queued. A frame the bounded queue replaces was still presented, so it counts with its real present-to-present interval. The replacement adds no interval and removes none. - So the statistics stay meaningful: they describe the title's present cadence, not the frames shown. A burst of presents between two waits shows up as short intervals, with or without this PR. - No code change. `docs/d3d12_vulkan.md` now says this next to the BL-6 text. - New case in `frame_pacer_test`, at latency 1: four presents, two of them replaced. It checks `frames` 4, `samples` 3, mean, drift, nearest-rank `p50`/`p95`/`p99`, two origin-to-present latencies (the replaced token included), and that the frames that are shown keep their vblanks. **Tests** (Linux, portable runtime subset) - `ctest`: 74/74 passed, 2 skipped (`shader_library_corpus`, `vk_sync_validation`), the same as `main` alone. Vulkan tests ran on the AMD iGPU (RDNA2, RADV). - `frame_pacer_test`: passes, including the new case and this PR's bounded-queue cases. - `python -I tests/test_boot_trace.py`: 33/33. - `check_no_game_data.py` on every changed file: clean. - `xbox_present_test` is Windows-only and was not run here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-11-25 23:01:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T23:01:40Z.


Merged: FramePacer keeps at most latency frames in flight while armed (mailbox replace).

  • Changed since review: nothing since the merge with #891 (BL-6), and it merges cleanly with current main. The BL-6 statistics still describe the title's present cadence, as that comment explained.
  • Tested: the full Windows suite under Wine on main 5fab93967 with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail. frame_pacer passes on both.
  • Checked on main 8564bb48b + 6f9ee9a81: it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 4 changed files.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7177061765 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/671#issuecomment-7177061765). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T23:01:40Z. --- Merged: `FramePacer` keeps at most `latency` frames in flight while armed (mailbox replace). - **Changed since review:** nothing since the merge with #891 (BL-6), and it merges cleanly with current `main`. The BL-6 statistics still describe the title's present cadence, as that comment explained. - **Tested:** the full Windows suite under Wine on `main` `5fab93967` with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail. `frame_pacer` passes on both. - **Checked on `main` `8564bb48b` + `6f9ee9a81`:** it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 4 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
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!671
No description provided.