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

Closed
opened 2026-11-26 20:18:48 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/671
Author: @aslan2142
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: frame-pacer-bounded-queue


📝 Commits (3)

  • b464a2c FramePacer: at most latency frames in flight while armed (mailbox replace)
  • d5304a8 Merge upstream main into frame-pacer-bounded-queue (after #891, BL-6)
  • 6f9ee9a FramePacer: BL-6 statistics count a frame the bounded queue replaces

📊 Changes

4 files changed (+188 additions, -16 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+12 -4)
📝 runtime/src/frame_pacer.h (+30 -10)
📝 runtime/test/frame_pacer_test.cpp (+143 -0)
📝 runtime/test/xbox_present_test.cpp (+3 -2)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/671 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `frame-pacer-bounded-queue` --- ### 📝 Commits (3) - [`b464a2c`](https://github.com/ubiquitarianism/leonida/commit/b464a2c529d784c952f795fef5298e7ad5f79e4f) FramePacer: at most `latency` frames in flight while armed (mailbox replace) - [`d5304a8`](https://github.com/ubiquitarianism/leonida/commit/d5304a83b4583022a340413357c364718a56c508) Merge upstream main into frame-pacer-bounded-queue (after #891, BL-6) - [`6f9ee9a`](https://github.com/ubiquitarianism/leonida/commit/6f9ee9a81546cb04e2b8e221a624868e64ae424d) FramePacer: BL-6 statistics count a frame the bounded queue replaces ### 📊 Changes **4 files changed** (+188 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+12 -4) 📝 `runtime/src/frame_pacer.h` (+30 -10) 📝 `runtime/test/frame_pacer_test.cpp` (+143 -0) 📝 `runtime/test/xbox_present_test.cpp` (+3 -2) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:48 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#712
No description provided.