Commit Graph
20 Commits
Author SHA1 Message Date
LibretroAdmin 1656558977 video: add Skip Duplicate Frames
A repeat the core sends as a NULL frame is left unpresented, so the
display receives the content's own frame rate and frame generation or
interpolation tools see the real cadence. It stays out of the way where
the presents are the effect (Black Frame Insertion, shader sub-frames,
Threaded Video Frame Repeat, a headset) and with the menu open,
fast-forward or a cached frame shown again.

While repeats are being skipped, the runloop holds the loop to the
content's period with its timer wherever only VSync or the threaded
hold would have, since neither can block on a frame that is never
presented, and the driver's release stands aside. Lanes in
samples/runloop/pacing and samples/gfx/threaded_video pin both halves.

Idea from beetle-psx-libretro#1013 by Razor221.
2026-11-12 21:11:42 +01:00
davey a580d0f3de runloop: never count more play time than has passed
Closes #20019
2026-11-06 22:32:02 +01:00
libretroadmin 23f465bf2d runloop: hold the content rate where Driver Pacing has no backend
With Driver Pacing on and nothing else holding the loop, the backend's
release keeps the content's frame period. On a driver without a backend
- gl, glcore, or a GPU without the extension - the setting did nothing,
and with vsync and audio sync off the loop ran unthrottled. The frame
limiter now holds the content's period in exactly the iterations a
backend would have owned: a content frame at normal speed, focused, the
menu down, and nothing else pacing. Driver Pacing off is unchanged.
2026-11-03 14:55:28 +01:00
LibretroAdmin 80398df3b1 runloop: Driver Pacing alone keeps the content's rate
With Driver Pacing in effect and nothing else holding the loop - vsync
and audio sync off, no rate control, Threaded Video Display Pacing off -
the minimum interval handed to the driver was 0, and the driver's
release, which never sleeps for a rate it was not given, let the core run
unthrottled. The interval is now the content's period there too, as it
already was under Display Pacing; the timer's period still goes where the
timer would hold, and nothing where vsync, audio or a scanline already
hold the loop. Fast-forward never reaches the driver's release.

The choice moves into runloop.h as runloop_pace_driver_interval(), and
samples/runloop/pacing checks it against the whole pace decision (the
"driver alone" row fails on the old expression).
2026-10-21 01:20:47 +02:00
libretroadmin 08d96aba04 video: Driver Pacing releases the frames Display Pacing would hold
Threaded video's Display Pacing and Driver Pacing each decide when the
core's next frame starts, so with both on Driver Pacing stood down -
its status read "off: menu, pause, fast-forward or unfocused" - and
the presenter's hold, sleeping to its own estimate of core and render
time, kept the release.

The driver's sleep is now the hold's release: with both on and Driver
Pacing in effect, the runloop sleeps on the driver as it does without
Display Pacing, and the hold in the wrapper's frame handover stands
aside for a frame the driver released (one whose frame info carries a
release identity) instead of sleeping a second time. The cadence the
hold kept - the content's period, which on a display faster than the
content is not the display's - goes to the driver as the minimum
interval it is to keep. A release the driver could not give leaves the
frame to the hold as before, and where Driver Pacing stands aside (the
menu, pause, fast-forward) the hold holds. Scanline Sync still keeps
Driver Pacing out.

Off by default with Driver Pacing; with Display Pacing alone nothing
changes. The two settings' descriptions say how they combine.

The pacing table's display-pacing row now has the driver beside the
hold, and a new row keeps the menu to the hold alone. The threaded
harness lane checks, under Display Pacing, that every frame is
released by the driver, that the hold stood aside for them, that the
content's period reached the driver with the frame, that a failed
release leaves the hold to hold, and that turning Display Pacing off
leaves the driver alone with its own interval.
2026-10-19 18:03:57 +02:00
libretroadmin 23aed644e1 video: Driver Pacing under threaded video, and through BFI, sub-frames and swap intervals
The presenter now owns the backend's frame side and the frame loop
only waits: each content frame carries its identity and the minimum
present interval in video_frame_info_t, the presenter marks, presents
and issues the one sleep after the frame's own present, and the frame
loop waits on the timeline semaphore for the identity it last handed
over before it samples the next frame's input. That is the same shape
on the direct path and under the threaded wrapper, which forwards the
three pokes to the driver unchanged, so Driver Pacing is no longer
turned off by Threaded Video; only Threaded Video Display Pacing, the
presenter's own hold, keeps the release to itself.

Any present after a frame's own - a repeat, a dark frame, a shader
sub-frame, a swap interval the driver emulates by presenting again -
is marked out of band on the same identity, which is what the
extension's attribution rules provide for, so Black Frame Insertion,
Shader Sub-frames and swap intervals above one no longer keep the mode
off; Scanline Sync, which paces the present itself, still does. The
Direct3D backends mark their presents the same way through a helper
around every Present, and take the interval from the frame on the
presenter's thread.

What crosses between the two threads in the Vulkan backend is
lock-free: the mode request and the presenter's answer are atomics
(a request the presenter has not seen reads as pending, never as in
effect); the swapchain the frame loop's input and simulation markers
may name is published under a generation, rewritten only while that
thread is seen outside a marker call, and a replaced swapchain is kept
until it is, so a marker never names a destroyed one. A wait the
driver does not satisfy four times running takes the mode off and
reports failure; asking again tries anew.

The fake-backend sample covers the sleep-after-present cadence, the
out-of-band markers, the cross-thread request and the kept swapchain;
the harness lane adds the threaded path through the wrapper on the
null driver and on Vulkan, and the pacing table pins the wrapper row.
2026-10-19 06:54:41 +02:00
libretroadmin d08a156604 video: Driver Pacing, the graphics driver's release of each frame, on Vulkan
A new Driver Pacing setting (video_driver_pacing: Off, On, On + Boost;
Off by default, so nothing changes until it is asked for) lets the
graphics driver say when each core frame should start, through NVIDIA
Reflex's VK_NV_low_latency2 on the Vulkan driver. The runloop holds on
the driver's own timeline semaphore where Frame Delay used to sleep,
before the frame's input is sampled, and reports the input, simulation,
render and present markers on the frame's identity so the driver can
place the release. Where the gap limiter or the content-rate timer
would hold, its period goes to the driver as the minimum present
interval rather than being slept a second time; vsync and audio keep
holding where they do, since the release schedules the start of a frame
and not its presentation. The mode is a property of one swapchain: a
replaced one starts over, and nothing names one the mode was not set
on. A backend error, or a sleep the driver never signals within the
bound the runloop allows, falls back to the existing pacing for good.

The release is owned only for a content frame the core made, on the
unthreaded path, at normal speed, focused, with the menu down; pause,
the menu and fast-forward keep their pacing, and Black Frame Insertion,
Shader Sub-frames, Scanline Sync and a swap interval above one keep the
mode off until their present schedule is mapped onto the extension's
one sleep between presents. The driver pokes (driver_pacing_set, _wait,
_mark) are vendor-neutral so other backends can sit behind them; the
requested mode and the reason it is or is not in effect show on the
statistics overlay and in System Information. The runloop's decision is
pinned in samples/runloop/pacing, the Vulkan backend's state machine
runs on fake entry points in samples/gfx/vulkan_driver_pacing (a new CI
job), and the runloop's side runs against a fake backend as a lane of
the threaded-video harness, on the null driver and on Vulkan.
2026-10-19 05:33:57 +02:00
LibretroAdmin 21635dd171 samples: build with -g1 instead of -g
The sample and test builds used full debug info. -g1 keeps what
sanitizer reports and backtraces need - function names, files and line
numbers - and drops the variable and type information nobody reads in
CI. Objects get about 30% smaller (rh265.o under ASan+UBSan: 5.1MB to
3.7MB), so the ccache caches hold more of each job's build and are
quicker to restore and save.
2026-10-13 11:50:11 +02:00
libretroadmin b655a205b1 runloop: fast-forward's frameskip decides before the core runs, and a core that asks need not render a dropped frame
The frameskip picks the frames it presents at the top of the iteration
instead of in video_driver_frame, with the same accumulator, target and
forced render after a dupe; video_driver_frame consumes the decision, or
makes it itself for a frame no decision waits for. GET_AUDIO_VIDEO_ENABLE
then leaves video out for a frame that will be dropped, so a core that
honours it skips the render instead of spending the GPU on a frame
nobody sees. Under threaded video a hardware core rendering at a high
internal resolution could queue so far ahead of the presenter that
presents stalled for seconds in fast-forward. When a render turn lands
on a dupe, the core is asked for video until a real frame arrives, as
the forced render presented it before.

samples/runloop/pacing pins the accumulator step and the owed-frame rule.
2026-10-08 11:46:42 +02:00
LibretroAdmin d2d2fb21b9 runloop: fast-forward ratio stays out of the menu, high ratios reach their rate, vsync and Scanline Sync apply live
Scanline Sync holds the focused menu as vsync does, so the frame limit
the menu leaves standing - the fast-forward period - no longer runs a
timer there; between locks the gap limiter bridges at the display rate.
Closing the menu over running content restores the fast-forward limit.

The sleep margin may follow the OS timer up to 2 ms, and at most a
whole period, so a fast-forward period shorter than the timer can
sleep is spun to its deadline and every ratio reaches its rate.

Video, Scanline Sync and Adaptive VSync toggles reapply the driver's
blocking state, and every caller derives it from runloop_vsync_blocks():
vsync blocks only without Scanline Sync, a forced nonblock or
fast-forward. Switching Scanline Sync on reads the output lines afresh.

The menu stick-to-D-pad mapping computes its bit unsigned.

samples/runloop/pacing pins the menu row, fast-forward at 15x/30x/60x
over a 0.25-2 ms timer, and the blocking predicate.
2026-10-06 17:29:00 +02:00
libretroadmin 4c6d8311b9 runloop, video thread: the menu at Content Rate under display pacing has one clock
With Threaded Video Display Pacing on, the menu at Menu Frame Rate
'Content Rate' over a stopped core is held to the content's period by
the display pacing hold alone. The hold keeps the content's period
there rather than the display's, and the frame limiter's timer stands
aside for it, as it already does at 'Display Rate'. The two, at nearly
the same period and never an exact multiple of each other, beat, and a
frame landed a vblank early or late every so often.

The menu pacing table's Content Rate + Display row reads Display alone,
and the threaded-video harness measures the menu over a paused core at
both rates.
2026-10-04 03:39:04 +02:00
libretroadmin 74935dc166 menu: Menu Frame Rate replaces Throttle Menu Framerate
Menu Frame Rate sets the rate the menu runs at while content is loaded,
in every sync mode: 'Display Rate', the default, runs it at the refresh
rate of the monitor the window is on, and 'Content Rate' at the
content's frame rate. At 'Display Rate' the silence the menu feeds is
written without blocking and measured out by the clock, so audio no
longer holds the menu to the content's rate; a core left running behind
the menu keeps its own clock, running when its next frame is due while
the menu re-presents its last frame in between; and behind the threaded
video wrapper without the display pacing hold, the timer holds the menu
to the display's period. A configuration with Sync to Exact Content
Framerate and Throttle Menu Framerate on keeps the content rate it had,
and the old key is dropped on save.

Display servers gain get_window_refresh_rate, the refresh rate of the
output the window is on, for Win32, X11 and SDL, and Wayland reports it
from surface enter and leave; the frontend keeps the reading until the
window moves, its output changes mode or the menu opens. The pace
decision, the menu pacing table, the threaded video harness and the X11
live sample cover both rates.
2026-10-02 05:29:34 +02:00
LibretroAdmin 2d075314fb Sync to Exact Content Framerate: keep vsync within the skew tolerance
A content rate slightly past what the display presents at the chosen
interval - a 60.0988 Hz core at swap interval 2 on a 120 Hz panel, or
60 Hz content on a 59.94 Hz VRR ceiling - is paced by vsync with audio
skewed as it is without VRR, rather than forcing the loop nonblocking.
Only a content rate beyond audio_max_timing_skew keeps its own rate
with vsync off.

The decision is runloop_sync_plan_for() in runloop.h, pinned by a
table and an invariant sweep in samples/runloop/pacing. Fixes #19600.
2026-09-23 12:38:19 +02:00
LibretroAdmin e57668d229 Derive swap intervals above four, bounded by what the driver presents
'Auto' derives the swap interval as the whole multiple the display rate
is of the content rate, up to MAXIMUM_SWAP_INTERVAL, which the manual
setting's range reads too so the two cannot drift apart. A 480 Hz panel
running 60 fps content holds each frame for eight display frames;
driver_adjust_system_rates() then divides the target by that interval
and the audio rate follows the display.

The multiple has to be one the driver can present: the D3D APIs carry
the interval as a present parameter that stops at four, so those drivers
report that bound through the new get_swap_interval_cap poke and the
ceiling comes down to it. A multiple past the cap falls back to 1 rather
than clamping short, since a short multiple paces the loop fast.

The decision itself moves to runloop_video_swap_interval_for() in
runloop.h, next to the other pure pacing decisions, and
samples/runloop/pacing covers the multiples, the driver cap, the ratios
that are not whole multiples, and the degenerate rates.
2026-09-22 16:47:21 +02:00
libretroadmin e58643e67d runloop: the pace decision's facts are one flag word, not eighteen bools
The facts the decision reads were a struct of eighteen bools: eighteen
bytes gathered, passed by pointer, and loaded one at a time to test.
They are one word now, PACE_FACT_* bits in a runloop_pace_facts_t,
which the tree already speaks everywhere else: the gather ORs bits, the
decision masks them, the sample's table builds its rows with the same
constants. Same decision, same rows; the function reads as the flags
it tests rather than as field names.
2026-09-09 23:52:03 +02:00
libretroadmin 755b1dd8b1 runloop: the pace decision as one pure function, shadowing the paths until they defer to it
What holds the loop each iteration is decided across the menu path,
its early return, the pause path and the pace block, each re-deriving
the same facts - fast-forward four times under two spellings, the menu
three times - and the overlap and the mislabelled early return came
from those decisions not being one. runloop_pace_decide() is that one
decision: a pure function of a struct of this iteration's facts,
returning the RUNLOOP_PACE_* bits. It reproduces the shipping result
bit for bit, the early return included, and says so in an assertion:
debug builds gather the facts once, run both, and assert they agree at
each point the paths decide - the early return, the no-window wait, and
after the gap limiter. The harness runs every lane under it with no
disagreement.

The paths still decide for themselves in this patch; the function only
shadows. Once it has run for a while without the assertion firing, the
paths defer to it and the scattered logic goes. The pacing sample gains
the menu table - thirteen combinations of the sync settings over a
paused core, each row the fact the function returns, so a row that
changes is a behaviour change made on purpose. One row corrects the
table given by hand: Scanline in the menu is Scanline+Timer, since the
menu's refresh-rate timer stands aside for vsync, focus and display
pacing and not for scanline.
2026-09-09 22:21:25 +02:00
libretroadmin 9b94bf7199 video: display pacing paces the loop, and holds with vsync off
Display pacing did nothing on a machine with vsync off, and the
overlay said so in two ways once it could: "Pacing: Timer" with the
setting on, and a "core" reserve of a whole period beside a core that
ran in three milliseconds. Two causes, both real.

With vsync off the runloop's pace came out as none, so its gap limiter
engaged and held the loop to the content frame time on a schedule
anchored on the last frame. That timer fires before the handover's
hold gets its turn; the core runs on the timer's cadence, the push
measures a full period as core time, reserves all of it, and holds for
nothing. The runloop gains RUNLOOP_PACE_DISPLAY, set when the wrapper
is up with display pacing on and fast-forward off, which keeps the gap
limiter out and reads "Pacing: Display".

And the hold stood down on the driver's nonblock state, which
fast-forward sets - and so does vsync off. Pacing a core to the
display's vblank with a present that does not block is the point, not
the exception; the hold now stands down on the fast-forward flag the
frame info carries, and on nothing else.

The harness's display-pacing lane had passed on the gap limiter's
pacing all along, with the hold never running: the harness's menu is
alive over the core, and the hold rightly stands down under the menu.
The lane closes the menu for its measurement and checks the hold on
its own, sixty frames in a second; the pacing sample checks that the
display bit keeps the gap limiter out.
2026-09-09 12:39:19 +02:00
LibretroAdmin e0acbe2639 Audio and frame pacing: rate control on the threaded pipeline, sink rate estimation, the gap limiter, and driver latency fixes (#19515)
Audio and frame pacing: rate control on the threaded pipeline, sink rate estimation, the gap limiter, and driver latency fixes- #19515
Read this for full description
https://github.com/libretro/RetroArch/pull/19515
2026-09-07 23:26:19 +02:00
LibretroAdmin 91920289e3 win32: keep the run loop going during size/move and menu loops
A title bar drag, a border resize, or an open menu enters a modal loop
inside DefWindowProc that holds the thread until the user lets go, so
no frame runs and no audio is written for the length of the drag.

The loop still dispatches posted messages. For its duration a helper
thread sleeps at the content rate on the high resolution timer and
posts a tick, and each tick runs one iteration. The iteration is told
that an external clock is pacing it, through a new RUNLOOP_PACE_EXTERNAL
source: the frame-limit sleep, frame delay, and the no-window wait then
yield to that clock, so the iteration returns as soon as the frame is
out and the modal loop has the mouse back within a frame's work rather
than a frame's period. Content and audio hold their rate at any refresh
the core reports. Where no thread can be had, WM_TIMER drives the ticks
instead.

The thread is created once and parks between sessions, so a drag does
not leave retro_sleep()'s per-thread timer handle behind. Three things
guard the nested iteration: a flag drops a tick pulled out by the
iteration's own pump, the pump leaves mouse messages in the queue while
a tick runs since the modal loop has the mouse captured, and a quit
that an iteration accepted is not repeated on later ticks. Threaded
video is left alone, as the window then belongs to the video thread
and the run loop is not blocked.

Everything used exists on Windows 95; message and timer constants are
defined locally where an SDK lacks them.
2026-09-04 20:22:03 +02:00
LibretroAdmin 976a6c4c69 runloop: a harness for the three pacing decisions, running the shipping code
The last three pacing commits rest on predicates checked with
throwaway models that no longer exist. They are pure functions of
their arguments, they are exactly what a later refactor breaks
quietly, and two of the three failures are silent: a gap limiter that
engages next to another source double-paces and the frontend runs
slow, and one that engages under fast-forward throttles it to 1x -
both read as performance bugs rather than pacing bugs, and neither
trips an assert.

So the three move from runloop.c into runloop.h as inline functions
that runloop.c calls, and samples/runloop/pacing runs those. Not a
copy of the logic: change the header and the test changes with it,
which is the only version of this worth having. They take plain
arguments rather than the runloop state, so the test needs no stubs
and links against nothing.

What it checks. The gap predicate over all 128 combinations of the
five pace bits by nonblocking by fastmotion, asserting that exactly
one of them engages - exhaustive rather than sampled, since the space
is small enough to be. The period over the rates a core can report,
including zero, negative, a thousandth of a hertz and a million, and
for monotonicity, because a clamp written the wrong way round still
passes a bounds check. The sample filter at its boundaries and against
the regression it exists for, by running the same eight-sample average
the runloop keeps: a 0.9 s stall must leave it untouched, a 0.2 s
hitch must still be averaged in.

Confirmed to fail on four plausible regressions, each introduced in
runloop.h and reverted: dropping the fast-forward guard, testing one
pace bit instead of the whole record, inverting the clamp, and
loosening the stall bound back to a second. Each was caught, and the
first line of each failure names the case.

The frontend times the same as before the refactor, 57.8 fps with
both sync options off and 101 with vsync on, and win32 and the
settings table are clean.
2026-09-04 16:03:28 +02:00