c/main&ipc: Adopt to flip y in layers change

Client side changes by Lubosz Sarnecki.
This commit is contained in:
Jakob Bornecrantz 2020-05-24 16:58:41 +01:00
parent 9c8d0ae3cc
commit 7ab48b691c
11 changed files with 63 additions and 28 deletions

View file

@ -305,7 +305,8 @@ compositor_layer_stereo_projection(struct xrt_compositor *xc,
struct xrt_rect *r_rect,
uint32_t r_array_index,
struct xrt_fov *r_fov,
struct xrt_pose *r_pose)
struct xrt_pose *r_pose,
bool flip_y)
{
struct comp_compositor *c = comp_compositor(xc);
@ -334,7 +335,8 @@ compositor_layer_quad(struct xrt_compositor *xc,
struct xrt_rect *rect,
uint32_t array_index,
struct xrt_pose *pose,
struct xrt_vec2 *size)
struct xrt_vec2 *size,
bool flip_y)
{
// Noop!
}
@ -361,7 +363,8 @@ compositor_layer_commit(struct xrt_compositor *xc)
uint32_t l_array_index = stereo->l.array_index;
uint32_t r_array_index = stereo->r.array_index;
comp_renderer_frame(c->r, left, l_array_index, right, r_array_index);
comp_renderer_frame(c->r, left, l_array_index, right, r_array_index,
layer->flip_y);
compositor_add_frame_timing(c);

View file

@ -100,6 +100,7 @@ struct comp_layer
{
int64_t timestamp;
enum xrt_layer_composition_flags flags;
bool flip_y;
union {
struct comp_layer_quad quad;
struct comp_layer_stereo stereo;

View file

@ -49,7 +49,8 @@ comp_distortion_init_buffers(struct comp_distortion *d,
XRT_MAYBE_UNUSED static void
comp_distortion_update_descriptor_sets(struct comp_distortion *d,
VkSampler samplers[2],
VkImageView views[2]);
VkImageView views[2],
bool flip_y);
static void
comp_distortion_init_descriptor_set_layout(struct comp_distortion *d);
@ -495,7 +496,8 @@ void
comp_distortion_update_descriptor_set(struct comp_distortion *d,
VkSampler sampler,
VkImageView view,
uint32_t eye)
uint32_t eye,
bool flip_y)
{
struct vk_bundle *vk = d->vk;
@ -518,16 +520,21 @@ comp_distortion_update_descriptor_set(struct comp_distortion *d,
vk->vkUpdateDescriptorSets(vk->device,
ARRAY_SIZE(write_descriptor_sets),
write_descriptor_sets, 0, NULL);
d->ubo_vp_data[eye].flip_y = flip_y;
memcpy(d->ubo_viewport_handles[eye].mapped, &d->ubo_vp_data[eye],
sizeof(d->ubo_vp_data[eye]));
}
static void
comp_distortion_update_descriptor_sets(struct comp_distortion *d,
VkSampler samplers[2],
VkImageView views[2])
VkImageView views[2],
bool flip_y)
{
for (uint32_t i = 0; i < 2; i++) {
comp_distortion_update_descriptor_set(d, samplers[i], views[i],
i);
i, flip_y);
}
}

View file

@ -145,7 +145,8 @@ void
comp_distortion_update_descriptor_set(struct comp_distortion *d,
VkSampler sampler,
VkImageView view,
uint32_t eye);
uint32_t eye,
bool flip_y);
/*!
* Submit draw commands to the given command_buffer.

View file

@ -76,7 +76,8 @@ static void
renderer_set_swapchain_image(struct comp_renderer *r,
uint32_t eye,
struct comp_swapchain_image *image,
uint32_t layer);
uint32_t layer,
bool flip_y);
static void
renderer_render(struct comp_renderer *r);
@ -160,10 +161,11 @@ comp_renderer_frame(struct comp_renderer *r,
struct comp_swapchain_image *left,
uint32_t left_layer,
struct comp_swapchain_image *right,
uint32_t right_layer)
uint32_t right_layer,
bool flip_y)
{
renderer_set_swapchain_image(r, 0, left, left_layer);
renderer_set_swapchain_image(r, 1, right, right_layer);
renderer_set_swapchain_image(r, 0, left, left_layer, flip_y);
renderer_set_swapchain_image(r, 1, right, right_layer, flip_y);
renderer_render(r);
}
@ -534,7 +536,7 @@ _set_dummy_images(struct comp_renderer *r)
for (uint32_t i = 0; i < 2; i++)
comp_distortion_update_descriptor_set(
r->distortion, r->dummy_images[i].sampler,
r->dummy_images[i].views[0], i);
r->dummy_images[i].views[0], i, false);
}
static void
@ -583,7 +585,8 @@ static void
renderer_set_swapchain_image(struct comp_renderer *r,
uint32_t eye,
struct comp_swapchain_image *image,
uint32_t layer)
uint32_t layer,
bool flip_y)
{
if (eye > 1) {
COMP_ERROR(r->c, "Swapchain image %p %u not found",
@ -598,7 +601,7 @@ renderer_set_swapchain_image(struct comp_renderer *r,
(void *)image, eye);
comp_distortion_update_descriptor_set(
r->distortion, image->sampler, image->views[layer],
(uint32_t)eye);
(uint32_t)eye, flip_y);
renderer_rebuild_command_buffers(r);
r->one_buffer_imported[eye] = true;
}

View file

@ -39,7 +39,8 @@ comp_renderer_frame(struct comp_renderer *r,
struct comp_swapchain_image *left,
uint32_t left_layer,
struct comp_swapchain_image *right,
uint32_t right_layer);
uint32_t right_layer,
bool flip_y);
/*!
* Reset renderer as input has changed.

View file

@ -328,7 +328,8 @@ ipc_compositor_layer_stereo_projection(
struct xrt_rect *r_rect,
uint32_t r_array_index,
struct xrt_fov *r_fov,
struct xrt_pose *r_pose)
struct xrt_pose *r_pose,
bool flip_y)
{
struct ipc_client_compositor *icc = ipc_client_compositor(xc);
@ -356,6 +357,8 @@ ipc_compositor_layer_stereo_projection(
stereo->r.fov = *r_fov;
stereo->r.pose = *r_pose;
layer->flip_y = flip_y;
layer->type = IPC_LAYER_STEREO_PROJECTION;
// Increment the number of layers.
@ -374,7 +377,8 @@ ipc_compositor_layer_quad(struct xrt_compositor *xc,
struct xrt_rect *rect,
uint32_t array_index,
struct xrt_pose *pose,
struct xrt_vec2 *size)
struct xrt_vec2 *size,
bool flip_y)
{
struct ipc_client_compositor *icc = ipc_client_compositor(xc);
@ -395,6 +399,7 @@ ipc_compositor_layer_quad(struct xrt_compositor *xc,
quad->pose = *pose;
quad->size = *size;
layer->flip_y = flip_y;
layer->type = IPC_LAYER_QUAD;
// Increment the number of layers.

View file

@ -114,6 +114,7 @@ enum ipc_layer_type
struct ipc_layer_entry
{
enum ipc_layer_type type;
bool flip_y;
union {
struct ipc_layer_quad quad;

View file

@ -89,6 +89,7 @@ struct ipc_swapchain_data
struct ipc_render_state
{
bool rendering;
bool flip_y;
uint32_t l_swapchain_index;
uint32_t l_image_index;
uint32_t r_swapchain_index;

View file

@ -101,8 +101,10 @@ ipc_handle_compositor_layer_sync(volatile struct ipc_client_state *cs,
{
struct ipc_shared_memory *ism = cs->server->ism;
struct ipc_layer_slot *slot = &ism->slots[slot_id];
struct ipc_layer_stereo_projection *stereo = &slot->layers[0].stereo;
struct ipc_layer_entry *layer = &slot->layers[0];
struct ipc_layer_stereo_projection *stereo = &layer->stereo;
cs->render_state.flip_y = layer->flip_y;
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;
@ -416,6 +418,14 @@ client_loop(volatile struct ipc_client_state *cs)
cs->active = false;
cs->num_swapchains = 0;
// Make sure to reset the renderstate fully.
cs->render_state.flip_y = false;
cs->render_state.l_swapchain_index = 0;
cs->render_state.l_image_index = 0;
cs->render_state.r_swapchain_index = 0;
cs->render_state.r_image_index = 0;
cs->render_state.rendering = false;
for (uint32_t j = 0; j < IPC_MAX_CLIENT_SWAPCHAINS; j++) {
xrt_swapchain_destroy((struct xrt_swapchain **)&cs->xscs[j]);
cs->swapchain_handles[j] = -1;

View file

@ -518,7 +518,8 @@ 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)
bool *using_idle_images,
bool *flip_y)
{
// our ipc server thread will fill in l & r
// swapchain indices and toggle wait to false
@ -537,6 +538,7 @@ set_rendering_state(volatile struct ipc_client_state *active_client,
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];
*flip_y = render_state->flip_y;
// set our client state back to waiting.
render_state->rendering = false;
@ -586,11 +588,13 @@ main_loop(struct ipc_server *vs)
struct comp_swapchain_image *l = NULL;
struct comp_swapchain_image *r = NULL;
bool flip_y = false;
if (active_client == NULL || !active_client->active ||
active_client->num_swapchains == 0) {
if (!using_idle_images) {
COMP_DEBUG(c, "Resetting to idle images.");
comp_renderer_reset(c->r);
comp_renderer_set_idle_images(c->r);
using_idle_images = true;
last_l = NULL;
@ -598,25 +602,23 @@ main_loop(struct ipc_server *vs)
}
} else {
set_rendering_state(active_client, &l, &r,
&using_idle_images);
&using_idle_images, &flip_y);
}
// Rendering idle images
if (l == NULL || r == NULL) {
// Render the idle images or already cached images state.
if ((l == NULL || r == NULL) || (l == last_l && r == last_r)) {
comp_renderer_frame_cached(c->r);
comp_compositor_garbage_collect(c);
continue;
}
// Rebuild command buffers if we are showing new buffers.
if (last_l != l || last_r != r) {
comp_renderer_reset(c->r);
}
comp_renderer_reset(c->r);
comp_renderer_frame(c->r, l, 0, r, 0, flip_y);
last_l = l;
last_r = r;
comp_renderer_frame(c->r, l, 0, r, 0);
// Now is a good time to destroy objects.
comp_compositor_garbage_collect(c);
}