Frame pacing and present latency: measure first, then waitable swap chain, tearing and an interval override #728

Open
opened 2026-11-26 03:49:50 +00:00 by github-bot · 1 comment
Owner

@⁠Revens2 on GitHub · 2026-11-25 05:48 UTC · original

Problem

Two related questions, kept together because they share the same code:

  1. Is the frame rate capped by anything on the host side, and can it be lifted where that is safe?
  2. How much latency does our present path add, and how little can it be?

Neither is answered by a measurement in this repository today. The reports here measure world frames of roughly 200 to 800 ms (0.4 to 5 fps; for example #696, #616, #535, #418), where the host's pacing clock is not the limit: the cost is in texture preparation, copy-back and GPU work. So this issue matters for menus, videos and for the day the world runs faster, and its first deliverable is a measurement, not a change.

No open or closed issue covers latency or an uncapped frame rate. Overlapping items:

  • #457 (PR): holds a present that came without a flip wait to its flip tick (intro-movie judder). It adds frame::before_present(), so it is a direct neighbour of any change here.
  • #564 (PR): present texture transition through a HostList prelude.
  • #216 (PR): release ready queues before forcing present waits.
  • #142 (PR): encode completed-frame captures off the present thread.
  • #717 (PR): on-screen panel with fps, ms/frame, percentiles; the measurement tool this issue needs.
  • #357 (closed): two frame waits that wake together take two ticks.
  • #143, #602, #269: reports about presentation order, frame-by-frame movie playback and repeated frames.
  • The window/menu issue (opened with this one) proposes an fps_limit setting; that is a cap we add, the opposite of what this issue studies.

Current state of the code (origin/main at 310c6eb)

Frame clock (crates/victory-gpu/src/frame.rs, device methods 0x270 to 0x288):

  • The title sets an interval (set_interval, length in microseconds; 0 means 1/60 s) and a period (pipeline depth) which is read and ignored. Our clock ticks once per interval from that moment, and each event kind (origin, vblank, flip) ends once per tick. Event offsets are ignored (schedule returns success and stores nothing).
  • wait sleeps until the next tick or the time-out. A blocking wait for an event that has already happened (a frame that took longer than a tick) ends at once (the VICTORY_LATE_WAITS=1 switch restores sleeping to the next tick).
  • The title polls origin with a time-out of 0 and "token on time-out", then blocks on the flip before each present (comment in frame.rs). So the title's own cadence is interval as long as its frames take less than that.

Present (crates/victory-gpu/src/host.rs, Presenter, present):

  • IDXGISwapChain3, DXGI_SWAP_EFFECT_FLIP_DISCARD, BUFFERS = 2, SwapChain flags = 0, Present(0, 0) (sync interval 0, no DXGI_PRESENT_ALLOW_TEARING).
  • No DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING, no DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT, no SetMaximumFrameLatency (the DXGI default applies; the value on this device is not measured).
  • The present is a CopyResource of the title's texture into the back buffer then Present. With presents sent ahead (late_free_present) the copy is submitted on its own list and a settle is not waited for.
  • ResizeBuffers is called with flags 0 when the size or format changes; any flag added at creation has to be repeated there.

Proposal, in deliverable phases

  1. Measure first (no behaviour change). Per present: the interval since the previous present, the time Present itself blocked, the time between the title's origin wait ending and the present, and the number of presents with no flip wait since the last one (#457's case). Output goes to the existing frame-rate log line and, when #717 is in, to its panel/overlay.log. Run on the first menu, the opening movie and the world. Deliverable: a table of those figures from one NVIDIA and one AMD run, with no game data.
  2. Swap chain for low latency, off by default behind VICTORY_PRESENT=lowlat: DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT with SetMaximumFrameLatency(1) and a wait on the handle before the back buffer is acquired, and ALLOW_TEARING when CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING) says yes and the window is borderless/fullscreen, with Present(0, DXGI_PRESENT_ALLOW_TEARING). Flags repeated in ResizeBuffers. Keep BUFFERS at 2 first, try 3 only with a measured reason.
  3. Interval override for experiments: VICTORY_FRAME_INTERVAL=<us> replaces the length passed to set_interval. Purpose: find out whether the title's simulation step depends on the interval (it may read the interval as its time step, or measure real time; not verified). A run that shows the game speed changing with the override settles the question and also settles the "unlock" question: if game speed follows the interval, an unlock needs a different mechanism (render faster than simulation), which the host cannot do for a title it does not control.
  4. Only if phase 2 shows game speed is independent of the interval: a documented [display] frame_interval with a bounded range, and movies/menus excluded or tested separately (the intro movie's cadence is already fragile, #457, #602).
  5. Reflex/PCL markers belong to the NVIDIA Reflex issue; they should reuse the timestamps added in phase 0.

Risks

  • Tearing is visible. Default must stay off; only the borderless/fullscreen mode may enable it.
  • Waitable swap chains change when Present blocks; interplay with presents sent ahead (late_free_present), settle_now, and #457's before_present is untested.
  • An interval shorter than the title's own assumptions may change simulation speed, audio sync or movie pacing. Phase 2 exists to find out before any default changes.
  • Removing a pacing that real hardware needs may turn a 3 fps world into a device-removed case through the TDR path if work piles up; the existing watchdog and DRED switches stay.
  • No third-party code, no licence question.

Acceptance criteria (measurable)

  • Phase 0: the figures above are produced for a 60 s run each in the first menu and in the world, in a report with the commit and adapter named.
  • Phase 1: with VICTORY_PRESENT=lowlat, the number of frames queued in the swap chain (the waitable-object count or the present-to-display statistic) is at most 1 in steady state, and the median present-to-present interval is not worse than main's by more than 1 ms in the menu; no device removal over a 10 minute run.
  • Phase 2: three intervals (for example the title's own, half and double) run for 60 s each; the report states for each whether the title's visible motion speed changed (measured against a reference marker such as a fixed on-screen timer, no game data in the report).
  • cargo test --workspace --locked stays green; frame.rs's existing tick test keeps passing.

Not verified

  • Whether the frame rate is capped by the title or by the host in any scene; no measurement in the repository shows it.
  • The DXGI default maximum frame latency on this device, and whether Present(0, 0) ever blocks in the world.
  • Tearing behaviour and DWM composition differences on Windows 10 vs 11 and under Wine/Proton.
  • That the title's simulation is or is not tied to the interval it sets.
**@⁠Revens2** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/fxceless/victory-fork/issues/728) ## Problem Two related questions, kept together because they share the same code: 1. Is the frame rate capped by anything on the host side, and can it be lifted where that is safe? 2. How much latency does our present path add, and how little can it be? Neither is answered by a measurement in this repository today. The reports here measure world frames of roughly 200 to 800 ms (0.4 to 5 fps; for example #696, #616, #535, #418), where the host's pacing clock is not the limit: the cost is in texture preparation, copy-back and GPU work. So this issue matters for menus, videos and for the day the world runs faster, and its first deliverable is a measurement, not a change. ## Related work (checked 2026-11-25; searches: latency, present, vsync, tearing, frame pacing, frame cap, fps limit) No open or closed issue covers latency or an uncapped frame rate. Overlapping items: - #457 (PR): holds a present that came without a flip wait to its flip tick (intro-movie judder). It adds `frame::before_present()`, so it is a direct neighbour of any change here. - #564 (PR): present texture transition through a HostList prelude. - #216 (PR): release ready queues before forcing present waits. - #142 (PR): encode completed-frame captures off the present thread. - #717 (PR): on-screen panel with fps, ms/frame, percentiles; the measurement tool this issue needs. - #357 (closed): two frame waits that wake together take two ticks. - #143, #602, #269: reports about presentation order, frame-by-frame movie playback and repeated frames. - The window/menu issue (opened with this one) proposes an `fps_limit` setting; that is a cap we add, the opposite of what this issue studies. ## Current state of the code (`origin/main` at 310c6eb) Frame clock (`crates/victory-gpu/src/frame.rs`, device methods 0x270 to 0x288): - The title sets an interval (`set_interval`, `length` in microseconds; 0 means 1/60 s) and a `period` (pipeline depth) which is read and ignored. Our clock ticks once per interval from that moment, and each event kind (origin, vblank, flip) ends once per tick. Event offsets are ignored (`schedule` returns success and stores nothing). - `wait` sleeps until the next tick or the time-out. A blocking wait for an event that has already happened (a frame that took longer than a tick) ends at once (the `VICTORY_LATE_WAITS=1` switch restores sleeping to the next tick). - The title polls origin with a time-out of 0 and "token on time-out", then blocks on the flip before each present (comment in `frame.rs`). So the title's own cadence is `interval` as long as its frames take less than that. Present (`crates/victory-gpu/src/host.rs`, `Presenter`, `present`): - `IDXGISwapChain3`, `DXGI_SWAP_EFFECT_FLIP_DISCARD`, `BUFFERS = 2`, `SwapChain flags = 0`, `Present(0, 0)` (sync interval 0, no `DXGI_PRESENT_ALLOW_TEARING`). - No `DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING`, no `DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT`, no `SetMaximumFrameLatency` (the DXGI default applies; the value on this device is not measured). - The present is a `CopyResource` of the title's texture into the back buffer then `Present`. With presents sent ahead (`late_free_present`) the copy is submitted on its own list and a settle is not waited for. - `ResizeBuffers` is called with flags 0 when the size or format changes; any flag added at creation has to be repeated there. ## Proposal, in deliverable phases 0. Measure first (no behaviour change). Per present: the interval since the previous present, the time `Present` itself blocked, the time between the title's origin wait ending and the present, and the number of presents with no flip wait since the last one (#457's case). Output goes to the existing frame-rate log line and, when #717 is in, to its panel/`overlay.log`. Run on the first menu, the opening movie and the world. Deliverable: a table of those figures from one NVIDIA and one AMD run, with no game data. 1. Swap chain for low latency, off by default behind `VICTORY_PRESENT=lowlat`: `DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT` with `SetMaximumFrameLatency(1)` and a wait on the handle before the back buffer is acquired, and `ALLOW_TEARING` when `CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING)` says yes and the window is borderless/fullscreen, with `Present(0, DXGI_PRESENT_ALLOW_TEARING)`. Flags repeated in `ResizeBuffers`. Keep `BUFFERS` at 2 first, try 3 only with a measured reason. 2. Interval override for experiments: `VICTORY_FRAME_INTERVAL=<us>` replaces the length passed to `set_interval`. Purpose: find out whether the title's simulation step depends on the interval (it may read the interval as its time step, or measure real time; not verified). A run that shows the game speed changing with the override settles the question and also settles the "unlock" question: if game speed follows the interval, an unlock needs a different mechanism (render faster than simulation), which the host cannot do for a title it does not control. 3. Only if phase 2 shows game speed is independent of the interval: a documented `[display] frame_interval` with a bounded range, and movies/menus excluded or tested separately (the intro movie's cadence is already fragile, #457, #602). 4. Reflex/PCL markers belong to the NVIDIA Reflex issue; they should reuse the timestamps added in phase 0. ## Risks - Tearing is visible. Default must stay off; only the borderless/fullscreen mode may enable it. - Waitable swap chains change when `Present` blocks; interplay with presents sent ahead (`late_free_present`), `settle_now`, and #457's `before_present` is untested. - An interval shorter than the title's own assumptions may change simulation speed, audio sync or movie pacing. Phase 2 exists to find out before any default changes. - Removing a pacing that real hardware needs may turn a 3 fps world into a device-removed case through the TDR path if work piles up; the existing watchdog and DRED switches stay. - No third-party code, no licence question. ## Acceptance criteria (measurable) - Phase 0: the figures above are produced for a 60 s run each in the first menu and in the world, in a report with the commit and adapter named. - Phase 1: with `VICTORY_PRESENT=lowlat`, the number of frames queued in the swap chain (the waitable-object count or the present-to-display statistic) is at most 1 in steady state, and the median present-to-present interval is not worse than main's by more than 1 ms in the menu; no device removal over a 10 minute run. - Phase 2: three intervals (for example the title's own, half and double) run for 60 s each; the report states for each whether the title's visible motion speed changed (measured against a reference marker such as a fixed on-screen timer, no game data in the report). - `cargo test --workspace --locked` stays green; `frame.rs`'s existing tick test keeps passing. ## Not verified - Whether the frame rate is capped by the title or by the host in any scene; no measurement in the repository shows it. - The DXGI default maximum frame latency on this device, and whether `Present(0, 0)` ever blocks in the world. - Tearing behaviour and DWM composition differences on Windows 10 vs 11 and under Wine/Proton. - That the title's simulation is or is not tied to the interval it sets.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:50 +00:00
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 05:48 UTC · original

Sibling issues opened together: #727 (settings/menu), #728 (frame pacing and latency), #729 (Reflex), #730 (upscaling), #731 (frame generation). Overlaps are named in each body; this set should stay split by subject.

**@⁠Revens2** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/fxceless/victory-fork/issues/728#issuecomment-7154159988) Sibling issues opened together: #727 (settings/menu), #728 (frame pacing and latency), #729 (Reflex), #730 (upscaling), #731 (frame generation). Overlaps are named in each body; this set should stay split by subject.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/fxceless--victory-fork#728
No description provided.