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

Manually merged
github merged 3 commits from gh-pr/671/head into gh-pr/671/base 2026-11-26 09:15:20 +00:00
Owner

@⁠aslan2142 on GitHub · 2026-11-24 11:22 UTC · original
aslan2142:frame-pacer-bounded-queue → main · +188 −16 · 4 files · 3 commits · merged 2026-11-25 23:01 UTC

Claimed in the coordination issue as: OLD-9189 #14

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).

**@⁠aslan2142** on GitHub · 2026-11-24 11:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/671) `aslan2142:frame-pacer-bounded-queue` → `main` · +188 −16 · 4 files · 3 commits · merged 2026-11-25 23:01 UTC Claimed in the coordination issue as: OLD-9189 https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 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).
commit_present_token and note_untokened_present appended a slot for every
present, each one period after the last, so presents made with no
WaitFrameEventX between them grew the queue without limit and the next wait
blocked until the first of them was shown: at latency 2, 1000 blank presents
left 1000 frames in flight and the next wait passed 999 periods later.

A present into a full queue now replaces the newest queued frame and takes
its vblank, like a mailbox: the replaced frame is never shown (no display
statistic), the older frames keep their vblanks, and the queue never reaches
further than `latency` vblanks ahead, so the next wait passes when the oldest
frame is shown. A queue longer than a lowered latency is cut back the same
way at the next present. Presents before the event is armed stay unpaced
(old upstream PR 4419), and a frame behind a queued one still cannot be
shown at once.

frame_pacer_test: 1000 untokened presents after one wait at latency 1, 2
and 3, tokened presents beyond the latency (the older ones keep their
vblanks, the replaced one has no display statistic), the one-present-per-wait
cadence, and a lowered latency. xbox_present_test expected the blank present
after a frame at latency 1 to make 2 frames in flight; it is 1 now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	runtime/src/frame_pacer.h

Both branches added a private helper in the same place: queue_flip_locked (the bounded queue) and
record_present_timing_locked (BL-6 pacing statistics). Both are kept; note_untokened_present records its timing
first and then queues through queue_flip_locked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pacing statistics are recorded at PresentX, before the frame is queued, so a frame replaced in a full queue
(never shown) still counts as a present with its real present-to-present interval; the replacement adds and removes
no interval. frame_pacer_test pins that at latency 1: four presents, two replaced, three intervals with known
nearest-rank percentiles and mean, two origin-to-present latencies (the replaced token included), and the shown
frames keep their vblanks. docs/d3d12_vulkan.md says the intervals are between PresentX calls, not frames shown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:15:19 +00:00
github manually merged commit 6f9ee9a815 into gh-pr/671/base 2026-11-26 09:15:20 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:30 UTC · original

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** on GitHub · 2026-11-24 19:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/671#issuecomment-7142208680) 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).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 23:01 UTC · original

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).

**@⁠aslan2142** on GitHub · 2026-11-25 23:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/671#issuecomment-7177061765) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.