ipc: Improve swapchain handling a tiny bit

This commit is contained in:
Jakob Bornecrantz 2020-04-30 14:00:44 +01:00
parent 11539e28b7
commit a02293e8dd
4 changed files with 47 additions and 34 deletions

View file

@ -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_entry *layer = &slot->layers[icc->layers.num_layers];
struct ipc_layer_stereo_projection *stereo = &layer->stereo; struct ipc_layer_stereo_projection *stereo = &layer->stereo;
struct ipc_client_swapchain *l = ipc_client_swapchain(xscs[0]); 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->timestamp = timestamp;
// stereo->xdev_id = 0; //! @todo Real id. // stereo->xdev_id = 0; //! @todo Real id.

View file

@ -87,8 +87,10 @@ struct ipc_swapchain_data
struct ipc_render_state struct ipc_render_state
{ {
bool rendering; bool rendering;
uint32_t l_render_index; uint32_t l_swapchain_index;
uint32_t r_render_index; uint32_t l_image_index;
uint32_t r_swapchain_index;
uint32_t r_image_index;
}; };
/*! /*!

View file

@ -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_slot *slot = &ism->slots[slot_id];
struct ipc_layer_stereo_projection *stereo = &slot->layers[0].stereo; struct ipc_layer_stereo_projection *stereo = &slot->layers[0].stereo;
// TODO: this is hardcoded for now cs->render_state.l_swapchain_index = stereo->l.swapchain_id;
cs->render_state.l_render_index = stereo->l.image_index; cs->render_state.l_image_index = stereo->l.image_index;
// TODO: this is hardcoded for now cs->render_state.r_swapchain_index = stereo->r.swapchain_id;
cs->render_state.r_render_index = stereo->l.image_index; cs->render_state.r_image_index = stereo->r.image_index;
// printf("SERVER: sending compositor end frame response\n");
cs->render_state.rendering = true; cs->render_state.rendering = true;
*out_free_slot_id = (slot_id + 1) % IPC_MAX_SLOTS; *out_free_slot_id = (slot_id + 1) % IPC_MAX_SLOTS;

View file

@ -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 static int
main_loop(struct ipc_server *vs) main_loop(struct ipc_server *vs)
{ {
@ -413,47 +445,27 @@ main_loop(struct ipc_server *vs)
COMP_DEBUG(c, "Resetting to idle images."); COMP_DEBUG(c, "Resetting to idle images.");
comp_renderer_set_idle_images(c->r); comp_renderer_set_idle_images(c->r);
using_idle_images = true; using_idle_images = true;
last_r = NULL;
last_l = NULL; last_l = NULL;
last_r = NULL;
} }
} else { } else {
// our ipc server thread will fill in l & r set_rendering_state(active_client, &l, &r,
// swapchain indices and toggle wait to false &using_idle_images);
// 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;
}
} }
// Rendering idle images // Rendering idle images
if (r == NULL || l == NULL) { if (l == NULL || r == NULL) {
comp_renderer_frame_cached(c->r); comp_renderer_frame_cached(c->r);
comp_compositor_garbage_collect(c); comp_compositor_garbage_collect(c);
continue; continue;
} }
// Rebuild command buffers if we are showing new buffers. // 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); comp_renderer_reset(c->r);
} }
last_r = r;
last_l = l; last_l = l;
last_r = r;
comp_renderer_frame(c->r, l, 0, r, 0); comp_renderer_frame(c->r, l, 0, r, 0);