Report render frame stalls once per stall and on X11

With --debug-rendering, the "No render frame received" message was
logged on every main loop wakeup while frames were stalled, which can be
indefinitely, for example, while a Wayland window is hidden. Report each
stall only once, till a render frame is next received.

Also report stalls on X11, when the X server stops reporting vertical
blanks and frames are rendered without them. A single missed frame while
frames are arriving is a glitch and is not reported.
This commit is contained in:
Kovid Goyal 2026-11-07 15:31:58 +05:30
parent a1057b00af
commit acab091317
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 26 additions and 8 deletions

View file

@ -194,16 +194,24 @@ lazy_render_frame_deadline(OSWindow *w) {
}
#endif
// Report a stall in the delivery of render frames, at most once per stall, since
// stalls can last indefinitely, for example, while a Wayland window is hidden,
// during which this is called on every main loop wakeup
static void
report_render_frame_stall(OSWindow *w, monotonic_t waited) {
if (!global_state.debug_rendering || w->render_frame_stall_reported) return;
w->render_frame_stall_reported = true;
if (global_state.is_wayland) {
log_error("No render frame received in %.2f seconds", monotonic_t_to_s_double(waited));
} else {
log_error("No render frame received in %.2f seconds, rendering without them", monotonic_t_to_s_double(waited));
}
}
static bool
no_render_frame_received_recently(OSWindow *w, monotonic_t now, monotonic_t max_wait) {
bool ans = now - w->last_render_frame_received_at > max_wait;
if (ans && global_state.debug_rendering) {
if (global_state.is_wayland) {
log_error("No render frame received in %.2f seconds", monotonic_t_to_s_double(max_wait));
} else {
log_error("No render frame received in %.2f seconds, rendering without them", monotonic_t_to_s_double(max_wait));
}
}
if (ans) report_render_frame_stall(w, max_wait);
return ans;
}
@ -236,7 +244,13 @@ is_render_deferred_by_frame_pacing(OSWindow *w, monotonic_t now) {
if (w->render_state == RENDER_FRAME_READY) return false;
}
const monotonic_t deadline = lazy_render_frame_deadline(w);
if (now >= deadline || is_thumbnail) return false;
if (now >= deadline) {
// Missing a frame while they are arriving is a glitch, only
// report when the X server has stopped reporting vertical blanks
if (deadline - w->render_frame_requested_at >= RENDER_FRAME_STALL_TIMEOUT) report_render_frame_stall(w, now - w->render_frame_requested_at);
return false;
}
if (is_thumbnail) return false;
set_maximum_wait(deadline - now);
w->tick_on_render_frame = true;
return true;

View file

@ -3763,6 +3763,7 @@ static void
render_frame_received(OSWindow *w) {
w->render_state = RENDER_FRAME_READY;
w->last_render_frame_received_at = monotonic();
w->render_frame_stall_reported = false;
// Frames are often requested after every render, so only wake up the main
// loop if something is waiting for this frame, otherwise animations would
// be sampled at the monitor refresh rate.

View file

@ -658,6 +658,9 @@ typedef struct OSWindow {
// Whether to wake up the main loop when the next render frame arrives, as
// something is waiting for it, see is_render_deferred_by_frame_pacing()
bool tick_on_render_frame;
// Whether a stall in the delivery of render frames has been reported since
// the last render frame was received, see no_render_frame_received_recently()
bool render_frame_stall_reported;
uint64_t render_calls;
uint32_t frame_counter;
id_type last_focused_counter;