core: check we have both frame time and render time before pacing

We only checked render time. If we don't have frame time estimates, we
would divide by zero and end up with wild scheduling delays.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2023-04-27 04:06:56 +01:00
parent fcb9dc8cfd
commit 336cb0917a
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
1 changed files with 5 additions and 5 deletions

View File

@ -230,16 +230,16 @@ void schedule_render(session_t *ps) {
// TODO(yshui): why 1500?
const int SLACK = 1500;
int render_time_estimate = rolling_max_get_max(ps->render_stats);
if (render_time_estimate < 0) {
// We don't have render time estimates, maybe there's no frame rendered
// yet, or the backend doesn't support render timing information,
// schedule render immediately.
auto frame_time = (uint64_t)rolling_avg_get_avg(ps->frame_time);
if (render_time_estimate < 0 || frame_time == 0) {
// We don't have render time, and/or frame time estimates, maybe there's
// no frame rendered yet, or the backend doesn't support render timing
// information, schedule render immediately.
ps->target_msc = ps->last_msc + 1;
goto schedule;
}
render_time_estimate += SLACK;
auto frame_time = (uint64_t)rolling_avg_get_avg(ps->frame_time);
auto minimal_target_us = now_us + (uint64_t)render_time_estimate;
auto frame_delay = (uint64_t)ceil(
(double)(minimal_target_us - ps->last_msc_instant) / (double)frame_time);