From 8c373778532ff1981dc4049f6f103df49678fcaf Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Sun, 17 Mar 2019 20:28:09 -0700 Subject: [PATCH] comp: Keep track of nominal display interval and last time --- src/xrt/compositor/main/comp_compositor.c | 8 ++++++++ src/xrt/compositor/main/comp_compositor.h | 3 +++ src/xrt/compositor/main/comp_settings.c | 2 ++ src/xrt/compositor/main/comp_settings.h | 3 +++ 4 files changed, 16 insertions(+) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 86629cff7..f76a5bd51 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -14,6 +14,7 @@ #include "util/u_debug.h" #include "util/u_misc.h" +#include "util/u_time.h" #include "main/comp_compositor.h" #include "main/comp_client_interface.h" @@ -79,6 +80,9 @@ compositor_wait_frame(struct xrt_compositor *xc, { struct comp_compositor *c = comp_compositor(xc); COMP_SPEW(c, "WAIT_FRAME"); + *predicted_display_period = c->settings.nominal_frame_interval_ns; + *predicted_display_time = + c->last_frame_time_ns + c->settings.nominal_frame_interval_ns; //! @todo set *predicted_display_time @@ -121,6 +125,9 @@ compositor_end_frame(struct xrt_compositor *xc, } else { COMP_ERROR(c, "non-stereo rendering not supported"); } + + // Record the time of this frame. + c->last_frame_time_ns = time_state_get_now(c->timekeeping); } @@ -487,6 +494,7 @@ comp_compositor_create(struct xrt_device *xdev, comp_settings_init(&c->settings, xdev); c->settings.flip_y = flip_y; + c->last_frame_time_ns = time_state_get_now(c->timekeeping); // Need to select window backend before creating Vulkan, then // swapchain will initialize the window fully and the swapchain, and diff --git a/src/xrt/compositor/main/comp_compositor.h b/src/xrt/compositor/main/comp_compositor.h index 046ed068e..ab5ce9216 100644 --- a/src/xrt/compositor/main/comp_compositor.h +++ b/src/xrt/compositor/main/comp_compositor.h @@ -118,6 +118,9 @@ struct comp_compositor //! Vulkan bundle of things. struct vk_bundle vk; + //! Timestamp of last-rendered (immersive) frame. + int64_t last_frame_time_ns; + /*! * The current state we are tracking. * diff --git a/src/xrt/compositor/main/comp_settings.c b/src/xrt/compositor/main/comp_settings.c index 418855237..3394aacef 100644 --- a/src/xrt/compositor/main/comp_settings.c +++ b/src/xrt/compositor/main/comp_settings.c @@ -30,6 +30,8 @@ comp_settings_init(struct comp_settings *s, struct xrt_device *xdev) s->distortion_model = xdev->distortion.preferred; s->width = xdev->screens[0].w_pixels; s->height = xdev->screens[0].h_pixels; + s->nominal_frame_interval_ns = + xdev->screens[0].nominal_frame_interval_ns; s->print_spew = debug_get_bool_option_print_spew(); s->print_debug = debug_get_bool_option_print_debug(); diff --git a/src/xrt/compositor/main/comp_settings.h b/src/xrt/compositor/main/comp_settings.h index 97c491ecd..92a0f31f5 100644 --- a/src/xrt/compositor/main/comp_settings.h +++ b/src/xrt/compositor/main/comp_settings.h @@ -67,6 +67,9 @@ struct comp_settings //! Should we flip y axis for compositor buffers (for GL) bool flip_y; + + //! Nominal frame interval + uint64_t nominal_frame_interval_ns; }; /*!