From 765feb6fe1eb1088ffb423c0449892c4e7b0be93 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 15 Apr 2021 21:25:39 +0100 Subject: [PATCH] c/main: Refactor mesh descriptor and UBO upload --- src/xrt/compositor/main/comp_renderer.c | 60 +++++++++++++++------- src/xrt/compositor/render/comp_render.h | 20 ++++++-- src/xrt/compositor/render/comp_rendering.c | 41 +++++++++------ 3 files changed, 82 insertions(+), 39 deletions(-) diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index d7451c7ae..63f377546 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -218,12 +218,25 @@ renderer_build_rendering(struct comp_renderer *r, struct comp_rendering *rr, uin struct xrt_view *l_v = &r->c->xdev->hmd->views[0]; struct xrt_view *r_v = &r->c->xdev->hmd->views[1]; - struct comp_mesh_ubo_data l_data = { - .vertex_rot = l_v->rot, - }; - struct comp_mesh_ubo_data r_data = { - .vertex_rot = r_v->rot, + /* + * Init + */ + + comp_rendering_init(c, &c->nr, rr); + + + /* + * Update + */ + + struct comp_mesh_ubo_data distortion_data[2] = { + { + .vertex_rot = l_v->rot, + }, + { + .vertex_rot = r_v->rot, + }, }; const struct xrt_matrix_2x2 rotation_90_cw = {{ @@ -235,15 +248,30 @@ renderer_build_rendering(struct comp_renderer *r, struct comp_rendering *rr, uin }}; if (pre_rotate) { - math_matrix_2x2_multiply(&l_v->rot, &rotation_90_cw, &l_data.vertex_rot); - math_matrix_2x2_multiply(&r_v->rot, &rotation_90_cw, &r_data.vertex_rot); + math_matrix_2x2_multiply(&distortion_data[0].vertex_rot, // + &rotation_90_cw, // + &distortion_data[0].vertex_rot); // + math_matrix_2x2_multiply(&distortion_data[1].vertex_rot, // + &rotation_90_cw, // + &distortion_data[1].vertex_rot); // } - /* - * Init - */ + comp_draw_update_distortion(rr, // + 0, // view_index + r->lr->framebuffers[0].sampler, // + r->lr->framebuffers[0].view, // + &distortion_data[0]); // - comp_rendering_init(c, &c->nr, rr); + comp_draw_update_distortion(rr, // + 1, // view_index + r->lr->framebuffers[1].sampler, // + r->lr->framebuffers[1].view, // + &distortion_data[1]); // + + + /* + * Target + */ comp_draw_begin_target_single( // rr, // @@ -260,10 +288,7 @@ renderer_build_rendering(struct comp_renderer *r, struct comp_rendering *rr, uin 0, // view_index &l_viewport_data); // viewport_data - comp_draw_distortion(rr, // - r->lr->framebuffers[0].sampler, // - r->lr->framebuffers[0].view, // - &l_data); // + comp_draw_distortion(rr); comp_draw_end_view(rr); @@ -277,10 +302,7 @@ renderer_build_rendering(struct comp_renderer *r, struct comp_rendering *rr, uin 1, // view_index &r_viewport_data); // viewport_data - comp_draw_distortion(rr, // - r->lr->framebuffers[1].sampler, // - r->lr->framebuffers[1].view, // - &r_data); // + comp_draw_distortion(rr); comp_draw_end_view(rr); diff --git a/src/xrt/compositor/render/comp_render.h b/src/xrt/compositor/render/comp_render.h index 7f7c2e3cb..9103316e4 100644 --- a/src/xrt/compositor/render/comp_render.h +++ b/src/xrt/compositor/render/comp_render.h @@ -390,10 +390,22 @@ comp_draw_cylinder_layer( struct comp_rendering *rr, uint32_t layer, VkSampler sampler, VkImageView image_view, struct xrt_layer_data *data); void -comp_draw_distortion(struct comp_rendering *rr, - VkSampler sampler, - VkImageView image_view, - struct comp_mesh_ubo_data *data); +comp_draw_distortion(struct comp_rendering *rr); + + +/* + * + * Update functions. + * + */ + +void +comp_draw_update_distortion(struct comp_rendering *rr, + uint32_t view, + VkSampler sampler, + VkImageView image_view, + struct comp_mesh_ubo_data *data); + /* diff --git a/src/xrt/compositor/render/comp_rendering.c b/src/xrt/compositor/render/comp_rendering.c index 0bb1c0326..a0836ed53 100644 --- a/src/xrt/compositor/render/comp_rendering.c +++ b/src/xrt/compositor/render/comp_rendering.c @@ -736,10 +736,7 @@ comp_draw_end_view(struct comp_rendering *rr) } void -comp_draw_distortion(struct comp_rendering *rr, - VkSampler sampler, - VkImageView image_view, - struct comp_mesh_ubo_data *data) +comp_draw_distortion(struct comp_rendering *rr) { struct vk_bundle *vk = &rr->c->vk; struct comp_resources *r = rr->r; @@ -751,18 +748,6 @@ comp_draw_distortion(struct comp_rendering *rr, * Descriptors and pipeline. */ - comp_buffer_write(vk, &v->mesh.ubo, data, sizeof(struct comp_mesh_ubo_data)); - - update_mesh_discriptor_set( // - vk, // vk_bundle - r->mesh.src_binding, // src_binding - sampler, // sampler - image_view, // image_view - r->mesh.ubo_binding, // ubo_binding - v->mesh.ubo.buffer, // buffer - VK_WHOLE_SIZE, // size - v->mesh.descriptor_set); // descriptor_set - VkDescriptorSet descriptor_sets[1] = {v->mesh.descriptor_set}; vk->vkCmdBindDescriptorSets( // rr->cmd, // commandBuffer @@ -823,3 +808,27 @@ comp_draw_distortion(struct comp_rendering *rr, 0); // firstInstance } } + +void +comp_draw_update_distortion(struct comp_rendering *rr, + uint32_t view_index, + VkSampler sampler, + VkImageView image_view, + struct comp_mesh_ubo_data *data) +{ + struct vk_bundle *vk = &rr->c->vk; + struct comp_resources *r = rr->r; + struct comp_rendering_view *v = &rr->views[view_index]; + + comp_buffer_write(vk, &v->mesh.ubo, data, sizeof(struct comp_mesh_ubo_data)); + + update_mesh_discriptor_set( // + vk, // vk_bundle + r->mesh.src_binding, // src_binding + sampler, // sampler + image_view, // image_view + r->mesh.ubo_binding, // ubo_binding + v->mesh.ubo.buffer, // buffer + VK_WHOLE_SIZE, // size + v->mesh.descriptor_set); // descriptor_set +}