u/pacing: Add variable tracking to fake pacer

This commit is contained in:
Jakob Bornecrantz 2023-05-02 11:46:30 +01:00
parent 04d5942fa5
commit 5511be3c2d

View file

@ -1,4 +1,4 @@
// Copyright 2020-2021, Collabora, Ltd.
// Copyright 2020-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
@ -9,6 +9,7 @@
#include "os/os_time.h"
#include "util/u_var.h"
#include "util/u_time.h"
#include "util/u_misc.h"
#include "util/u_debug.h"
@ -48,7 +49,7 @@ struct fake_timing
* the display engine starts scanning out from the buffers we provided,
* and not when the pixels turned into photons that the user sees.
*/
uint64_t present_to_display_offset_ns;
struct u_var_draggable_f32 present_to_display_offset_ms;
// The amount of time that the application needs to render frame.
uint64_t comp_time_ns;
@ -82,6 +83,14 @@ predict_next_frame_present_time(struct fake_timing *ft, uint64_t now_ns)
return predicted_present_time_ns;
}
static uint64_t
calc_display_time(struct fake_timing *ft, uint64_t present_time_ns)
{
double offset_ms = ft->present_to_display_offset_ms.val;
uint64_t offset_ns = (uint64_t)(offset_ms * (double)U_TIME_1MS_IN_NS);
return present_time_ns + offset_ns;
}
static uint64_t
get_percent_of_time(uint64_t time_ns, uint32_t fraction_percent)
{
@ -111,7 +120,8 @@ pc_predict(struct u_pacing_compositor *upc,
int64_t frame_id = ft->frame_id_generator++;
uint64_t desired_present_time_ns = predict_next_frame_present_time(ft, now_ns);
uint64_t predicted_display_time_ns = desired_present_time_ns + ft->present_to_display_offset_ns;
uint64_t predicted_display_time_ns = calc_display_time(ft, desired_present_time_ns);
uint64_t wake_up_time_ns = desired_present_time_ns - ft->comp_time_ns;
uint64_t present_slop_ns = U_TIME_HALF_MS_IN_NS;
uint64_t predicted_display_period_ns = ft->frame_period_ns;
@ -219,13 +229,18 @@ pc_update_present_offset(struct u_pacing_compositor *upc, int64_t frame_id, uint
// not associating with frame IDs right now.
(void)frame_id;
ft->present_to_display_offset_ns = present_to_display_offset_ns;
double offset_ms = (double)present_to_display_offset_ns / (double)U_TIME_1MS_IN_NS;
ft->present_to_display_offset_ms.val = offset_ms;
}
static void
pc_destroy(struct u_pacing_compositor *upc)
{
struct fake_timing *ft = fake_timing(upc);
u_var_remove_root(ft);
free(ft);
}
@ -253,8 +268,13 @@ u_pc_fake_create(uint64_t estimated_frame_period_ns, uint64_t now_ns, struct u_p
// To make sure the code can start from a non-zero frame id.
ft->frame_id_generator = 5;
// An arbitrary guess.
ft->present_to_display_offset_ns = U_TIME_1MS_IN_NS * 4;
// Present to display offset, aka vblank to pixel turning into photons.
ft->present_to_display_offset_ms = (struct u_var_draggable_f32){
.val = 4.0, // An arbitrary guess, that happens to be based on Index.
.min = 1.0, // A lot of things assumes this is not negative.
.step = 0.1,
.max = +40.0,
};
// 20% of the frame time.
ft->comp_time_ns = get_percent_of_time(estimated_frame_period_ns, 20);
@ -267,6 +287,13 @@ u_pc_fake_create(uint64_t estimated_frame_period_ns, uint64_t now_ns, struct u_p
// Make the next present time be in the future.
ft->last_present_time_ns = now_ns + U_TIME_1MS_IN_NS * 50;
// U variable tracking.
u_var_add_root(ft, "Compositor timing info", true);
u_var_add_draggable_f32(ft, &ft->present_to_display_offset_ms, "Present to display offset(ms)");
u_var_add_ro_u64(ft, &ft->frame_period_ns, "Frame period(ns)");
u_var_add_ro_u64(ft, &ft->comp_time_ns, "Compositor time(ns)");
u_var_add_ro_u64(ft, &ft->last_present_time_ns, "Last present time(ns)");
// Return value.
*out_upc = &ft->base;