From a02293e8dd067102eb5dcc3ba89f73c0547ce854 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 30 Apr 2020 14:00:44 +0100 Subject: [PATCH] ipc: Improve swapchain handling a tiny bit --- src/xrt/ipc/ipc_client_compositor.c | 2 +- src/xrt/ipc/ipc_server.h | 6 ++- src/xrt/ipc/ipc_server_client.c | 9 ++-- src/xrt/ipc/ipc_server_process.c | 64 +++++++++++++++++------------ 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/xrt/ipc/ipc_client_compositor.c b/src/xrt/ipc/ipc_client_compositor.c index 6aa067469..116222ce7 100644 --- a/src/xrt/ipc/ipc_client_compositor.c +++ b/src/xrt/ipc/ipc_client_compositor.c @@ -397,7 +397,7 @@ ipc_compositor_end_frame(struct xrt_compositor *xc, struct ipc_layer_entry *layer = &slot->layers[icc->layers.num_layers]; struct ipc_layer_stereo_projection *stereo = &layer->stereo; struct ipc_client_swapchain *l = ipc_client_swapchain(xscs[0]); - struct ipc_client_swapchain *r = ipc_client_swapchain(xscs[0]); + struct ipc_client_swapchain *r = ipc_client_swapchain(xscs[1]); // stereo->timestamp = timestamp; // stereo->xdev_id = 0; //! @todo Real id. diff --git a/src/xrt/ipc/ipc_server.h b/src/xrt/ipc/ipc_server.h index a90cd5e01..55610201f 100644 --- a/src/xrt/ipc/ipc_server.h +++ b/src/xrt/ipc/ipc_server.h @@ -87,8 +87,10 @@ struct ipc_swapchain_data struct ipc_render_state { bool rendering; - uint32_t l_render_index; - uint32_t r_render_index; + uint32_t l_swapchain_index; + uint32_t l_image_index; + uint32_t r_swapchain_index; + uint32_t r_image_index; }; /*! diff --git a/src/xrt/ipc/ipc_server_client.c b/src/xrt/ipc/ipc_server_client.c index 956a76581..e3c0f3238 100644 --- a/src/xrt/ipc/ipc_server_client.c +++ b/src/xrt/ipc/ipc_server_client.c @@ -107,11 +107,10 @@ ipc_handle_compositor_layer_sync(volatile struct ipc_client_state *cs, struct ipc_layer_slot *slot = &ism->slots[slot_id]; struct ipc_layer_stereo_projection *stereo = &slot->layers[0].stereo; - // TODO: this is hardcoded for now - cs->render_state.l_render_index = stereo->l.image_index; - // TODO: this is hardcoded for now - cs->render_state.r_render_index = stereo->l.image_index; - // printf("SERVER: sending compositor end frame response\n"); + cs->render_state.l_swapchain_index = stereo->l.swapchain_id; + cs->render_state.l_image_index = stereo->l.image_index; + cs->render_state.r_swapchain_index = stereo->r.swapchain_id; + cs->render_state.r_image_index = stereo->r.image_index; cs->render_state.rendering = true; *out_free_slot_id = (slot_id + 1) % IPC_MAX_SLOTS; diff --git a/src/xrt/ipc/ipc_server_process.c b/src/xrt/ipc/ipc_server_process.c index f850e9a76..c778eb7d4 100644 --- a/src/xrt/ipc/ipc_server_process.c +++ b/src/xrt/ipc/ipc_server_process.c @@ -366,6 +366,38 @@ check_epoll(struct ipc_server *vs) } } +static void +set_rendering_state(volatile struct ipc_client_state *active_client, + struct comp_swapchain_image **l, + struct comp_swapchain_image **r, + bool *using_idle_images) +{ + // our ipc server thread will fill in l & r + // swapchain indices and toggle wait to false + // when the client calls end_frame, signalling + // us to render. + volatile struct ipc_render_state *render_state = + &active_client->render_state; + + if (!render_state->rendering) { + return; + } + + uint32_t li = render_state->l_swapchain_index; + uint32_t ri = render_state->r_swapchain_index; + struct comp_swapchain *cl = comp_swapchain(active_client->xscs[li]); + struct comp_swapchain *cr = comp_swapchain(active_client->xscs[ri]); + *l = &cl->images[render_state->l_image_index]; + *r = &cr->images[render_state->r_image_index]; + + // set our client state back to waiting. + render_state->rendering = false; + + // comp_compositor_garbage_collect(c); + + *using_idle_images = false; +} + static int main_loop(struct ipc_server *vs) { @@ -413,47 +445,27 @@ main_loop(struct ipc_server *vs) COMP_DEBUG(c, "Resetting to idle images."); comp_renderer_set_idle_images(c->r); using_idle_images = true; - last_r = NULL; last_l = NULL; + last_r = NULL; } } else { - // our ipc server thread will fill in l & r - // swapchain indices and toggle wait to false - // when the client calls end_frame, signalling - // us to render. - volatile struct ipc_render_state *render_state = - &active_client->render_state; - - if (render_state->rendering) { - struct comp_swapchain *cl = - comp_swapchain(active_client->xscs[0]); - struct comp_swapchain *cr = - comp_swapchain(active_client->xscs[1]); - l = &cl->images[render_state->l_render_index]; - r = &cr->images[render_state->r_render_index]; - - // set our client state back to waiting. - render_state->rendering = false; - - comp_compositor_garbage_collect(c); - - using_idle_images = false; - } + set_rendering_state(active_client, &l, &r, + &using_idle_images); } // Rendering idle images - if (r == NULL || l == NULL) { + if (l == NULL || r == NULL) { comp_renderer_frame_cached(c->r); comp_compositor_garbage_collect(c); continue; } // Rebuild command buffers if we are showing new buffers. - if (last_r != r || last_l != l) { + if (last_l != l || last_r != r) { comp_renderer_reset(c->r); } - last_r = r; last_l = l; + last_r = r; comp_renderer_frame(c->r, l, 0, r, 0);