diff --git a/src/xrt/compositor/client/comp_gl_client.c b/src/xrt/compositor/client/comp_gl_client.c index 5c050f216..6881bb1d0 100644 --- a/src/xrt/compositor/client/comp_gl_client.c +++ b/src/xrt/compositor/client/comp_gl_client.c @@ -99,8 +99,8 @@ client_gl_compositor_end_session(struct xrt_compositor *xc) static void client_gl_compositor_wait_frame(struct xrt_compositor *xc, - int64_t *predicted_display_time, - int64_t *predicted_display_period) + uint64_t *predicted_display_time, + uint64_t *predicted_display_period) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. diff --git a/src/xrt/compositor/client/comp_vk_client.c b/src/xrt/compositor/client/comp_vk_client.c index fea8d36e1..8b2fc18f4 100644 --- a/src/xrt/compositor/client/comp_vk_client.c +++ b/src/xrt/compositor/client/comp_vk_client.c @@ -118,8 +118,8 @@ client_vk_compositor_end_session(struct xrt_compositor *xc) static void client_vk_compositor_wait_frame(struct xrt_compositor *xc, - int64_t *predicted_display_time, - int64_t *predicted_display_period) + uint64_t *predicted_display_time, + uint64_t *predicted_display_period) { struct client_vk_compositor *c = client_vk_compositor(xc); // Pipe down call into fd compositor. diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 84fc4caea..b186ed8fd 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -55,6 +55,8 @@ #include "main/comp_compositor.h" +#include "xrt/xrt_gfx_fd.h" + #include #include @@ -128,7 +130,7 @@ static bool compositor_wait_vsync_or_time(struct comp_compositor *c, int64_t wake_up_time) { - int64_t now_ns = time_state_get_now(c->timekeeping); + int64_t now_ns = os_monotonic_get_ns(); /*! * @todo this is not accurate, but it serves the purpose of not letting * us sleep longer than the next vsync usually @@ -152,15 +154,16 @@ compositor_wait_vsync_or_time(struct comp_compositor *c, int64_t wake_up_time) } // Busy-wait for fine-grained delays. while (now_ns < wake_up_time) { - now_ns = time_state_get_now(c->timekeeping); + now_ns = os_monotonic_get_ns(); } return ret; } + static void compositor_wait_frame(struct xrt_compositor *xc, - int64_t *predicted_display_time, - int64_t *predicted_display_period) + uint64_t *predicted_display_time, + uint64_t *predicted_display_period) { struct comp_compositor *c = comp_compositor(xc); COMP_SPEW(c, "WAIT_FRAME"); @@ -168,7 +171,7 @@ compositor_wait_frame(struct xrt_compositor *xc, // A little bit easier to read. int64_t interval_ns = (int64_t)c->settings.nominal_frame_interval_ns; - int64_t now_ns = time_state_get_now(c->timekeeping); + int64_t now_ns = os_monotonic_get_ns(); if (c->last_next_display_time == 0) { // First frame, we'll just assume we will display immediately @@ -216,7 +219,7 @@ compositor_begin_frame(struct xrt_compositor *xc) { struct comp_compositor *c = comp_compositor(xc); COMP_SPEW(c, "BEGIN_FRAME"); - c->app_profiling.last_begin = time_state_get_now(c->timekeeping); + c->app_profiling.last_begin = os_monotonic_get_ns(); } static void @@ -250,7 +253,7 @@ compositor_end_frame(struct xrt_compositor *xc, } // Record the time of this frame. - c->last_frame_time_ns = time_state_get_now(c->timekeeping); + c->last_frame_time_ns = os_monotonic_get_ns(); c->app_profiling.last_end = c->last_frame_time_ns; //! @todo do a time-weighted average or something. @@ -754,9 +757,7 @@ compositor_init_renderer(struct comp_compositor *c) struct xrt_compositor_fd * -xrt_gfx_provider_create_fd(struct xrt_device *xdev, - struct time_state *timekeeping, - bool flip_y) +xrt_gfx_provider_create_fd(struct xrt_device *xdev, bool flip_y) { struct comp_compositor *c = U_TYPED_CALLOC(struct comp_compositor); @@ -769,7 +770,6 @@ xrt_gfx_provider_create_fd(struct xrt_device *xdev, c->base.base.end_frame = compositor_end_frame; c->base.base.destroy = compositor_destroy; c->xdev = xdev; - c->timekeeping = timekeeping; COMP_DEBUG(c, "Doing init %p", (void *)c); @@ -777,7 +777,7 @@ xrt_gfx_provider_create_fd(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); + c->last_frame_time_ns = os_monotonic_get_ns(); c->frame_overhead_ns = 2000000; //! @todo set this to an estimate that's better than 6ms c->expected_app_duration_ns = 6000000; diff --git a/src/xrt/compositor/main/comp_compositor.h b/src/xrt/compositor/main/comp_compositor.h index 61c919bac..0a5568ff4 100644 --- a/src/xrt/compositor/main/comp_compositor.h +++ b/src/xrt/compositor/main/comp_compositor.h @@ -82,9 +82,6 @@ struct comp_compositor //! The device we are displaying to. struct xrt_device *xdev; - //! The timekeeping state object. - struct time_state *timekeeping; - //! The settings. struct comp_settings settings; diff --git a/src/xrt/include/xrt/xrt_compositor.h b/src/xrt/include/xrt/xrt_compositor.h index 43fac005e..52af382a2 100644 --- a/src/xrt/include/xrt/xrt_compositor.h +++ b/src/xrt/include/xrt/xrt_compositor.h @@ -169,8 +169,8 @@ struct xrt_compositor * See xrWaitFrame. */ void (*wait_frame)(struct xrt_compositor *xc, - int64_t *predicted_display_time, - int64_t *predicted_display_period); + uint64_t *predicted_display_time, + uint64_t *predicted_display_period); /*! * See xrBeginFrame. @@ -282,8 +282,8 @@ xrt_comp_end_session(struct xrt_compositor *xc) */ XRT_MAYBE_UNUSED static void xrt_comp_wait_frame(struct xrt_compositor *xc, - int64_t *predicted_display_time, - int64_t *predicted_display_period) + uint64_t *predicted_display_time, + uint64_t *predicted_display_period) { xc->wait_frame(xc, predicted_display_time, predicted_display_period); } diff --git a/src/xrt/include/xrt/xrt_gfx_fd.h b/src/xrt/include/xrt/xrt_gfx_fd.h index 13e4fcb21..c8b18a6a0 100644 --- a/src/xrt/include/xrt/xrt_gfx_fd.h +++ b/src/xrt/include/xrt/xrt_gfx_fd.h @@ -25,9 +25,7 @@ struct time_state; * @ingroup xrt_iface */ struct xrt_compositor_fd * -xrt_gfx_provider_create_fd(struct xrt_device *xdev, - struct time_state *timekeeping, - bool flip_y); +xrt_gfx_provider_create_fd(struct xrt_device *xdev, bool flip_y); #ifdef __cplusplus diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index e9042ffee..5a9f24068 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -396,9 +396,15 @@ oxr_session_frame_wait(struct oxr_logger *log, struct xrt_compositor *xc = sess->compositor; if (xc != NULL) { - xrt_comp_wait_frame(xc, &frameState->predictedDisplayTime, - &frameState->predictedDisplayPeriod); + uint64_t predicted_display_time; + uint64_t predicted_display_period; + xrt_comp_wait_frame(xc, &predicted_display_time, + &predicted_display_period); + frameState->shouldRender = should_render(sess->state); + frameState->predictedDisplayPeriod = predicted_display_period; + frameState->predictedDisplayTime = time_state_from_monotonic_ns( + sess->sys->inst->timekeeping, predicted_display_time); } else { frameState->shouldRender = XR_FALSE; } diff --git a/src/xrt/state_trackers/oxr/oxr_session_egl.c b/src/xrt/state_trackers/oxr/oxr_session_egl.c index 73c07c8cf..921c13535 100644 --- a/src/xrt/state_trackers/oxr/oxr_session_egl.c +++ b/src/xrt/state_trackers/oxr/oxr_session_egl.c @@ -63,7 +63,7 @@ oxr_session_populate_egl(struct oxr_logger *log, } struct xrt_compositor_fd *xcfd = - xrt_gfx_provider_create_fd(sys->head, sys->inst->timekeeping, true); + xrt_gfx_provider_create_fd(sys->head, true); if (xcfd == NULL) { return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, " failed create a fd compositor"); diff --git a/src/xrt/state_trackers/oxr/oxr_session_gl.c b/src/xrt/state_trackers/oxr/oxr_session_gl.c index c874a6f22..60f70e6f7 100644 --- a/src/xrt/state_trackers/oxr/oxr_session_gl.c +++ b/src/xrt/state_trackers/oxr/oxr_session_gl.c @@ -32,7 +32,7 @@ oxr_session_populate_gl_xlib(struct oxr_logger *log, struct oxr_session *sess) { struct xrt_compositor_fd *xcfd = - xrt_gfx_provider_create_fd(sys->head, sys->inst->timekeeping, true); + xrt_gfx_provider_create_fd(sys->head, true); if (xcfd == NULL) { return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, " failed create a fd compositor"); diff --git a/src/xrt/state_trackers/oxr/oxr_session_vk.c b/src/xrt/state_trackers/oxr/oxr_session_vk.c index 76037711b..02e0f40ff 100644 --- a/src/xrt/state_trackers/oxr/oxr_session_vk.c +++ b/src/xrt/state_trackers/oxr/oxr_session_vk.c @@ -26,8 +26,8 @@ oxr_session_populate_vk(struct oxr_logger *log, XrGraphicsBindingVulkanKHR const *next, struct oxr_session *sess) { - struct xrt_compositor_fd *xcfd = xrt_gfx_provider_create_fd( - sys->head, sys->inst->timekeeping, false); + struct xrt_compositor_fd *xcfd = + xrt_gfx_provider_create_fd(sys->head, false); if (xcfd == NULL) { return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, " failed create a fd compositor");