From 975ca891c3f691e3c9c2184f00a08044330327ea Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 1 Oct 2023 21:09:19 +0100 Subject: [PATCH] c/render: Refactor gfx distortion dispatch --- src/xrt/compositor/main/comp_renderer.c | 20 ++--- src/xrt/compositor/render/render_gfx.c | 77 +++++++++++--------- src/xrt/compositor/render/render_interface.h | 30 ++------ 3 files changed, 57 insertions(+), 70 deletions(-) diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index 0272ef136..e5f42ba9d 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -816,19 +816,13 @@ do_gfx_mesh(struct comp_renderer *r, i, // view_index &viewport_datas[i]); // viewport_data - struct render_gfx_mesh_ubo_data data = { - .vertex_rot = vertex_rots[i], - .post_transform = src_norm_rects[i], - }; - - render_gfx_update_distortion( // - rr, // rr - i, // view, - src_samplers[i], // sampler, - src_image_views[i], // image_view, - &data); // data - - render_gfx_distortion(rr); + render_gfx_distortion( // + rr, // + i, // + &vertex_rots[i], // + src_samplers[i], // + src_image_views[i], // + &src_norm_rects[i]); // render_gfx_end_view(rr); } diff --git a/src/xrt/compositor/render/render_gfx.c b/src/xrt/compositor/render/render_gfx.c index b46ae55bb..cba006762 100644 --- a/src/xrt/compositor/render/render_gfx.c +++ b/src/xrt/compositor/render/render_gfx.c @@ -711,19 +711,50 @@ render_gfx_end_view(struct render_gfx *rr) } void -render_gfx_distortion(struct render_gfx *rr) +render_gfx_distortion(struct render_gfx *rr, + uint32_t view_index, + const struct xrt_matrix_2x2 *vertex_rot, + VkSampler sampler, + VkImageView image_view, + const struct xrt_normalized_rect *src_rect) { struct vk_bundle *vk = vk_from_rr(rr); struct render_resources *r = rr->r; - uint32_t view = rr->current_view; - struct render_gfx_view *v = &rr->views[view]; + assert(view_index == rr->current_view); + + struct render_gfx_view *v = &rr->views[view_index]; + + struct render_buffer *ubo = &r->mesh.ubos[view_index]; + VkDescriptorSet descriptor_set = v->mesh.descriptor_set; + + /* + * UBO data. + */ + + struct render_gfx_mesh_ubo_data data = { + .vertex_rot = *vertex_rot, + .post_transform = *src_rect, + }; + + render_buffer_write(vk, ubo, &data, sizeof(struct render_gfx_mesh_ubo_data)); + /* * Descriptors and pipeline. */ - VkDescriptorSet descriptor_sets[1] = {v->mesh.descriptor_set}; + 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 + ubo->buffer, // buffer + VK_WHOLE_SIZE, // size + descriptor_set); // descriptor_set + + VkDescriptorSet descriptor_sets[1] = {descriptor_set}; vk->vkCmdBindDescriptorSets( // r->cmd, // commandBuffer VK_PIPELINE_BIND_POINT_GRAPHICS, // pipelineBindPoint @@ -767,13 +798,13 @@ render_gfx_distortion(struct render_gfx *rr) 0, // offset VK_INDEX_TYPE_UINT32); // indexType - vk->vkCmdDrawIndexed( // - r->cmd, // commandBuffer - r->mesh.index_counts[view], // indexCount - 1, // instanceCount - r->mesh.index_offsets[view], // firstIndex - 0, // vertexOffset - 0); // firstInstance + vk->vkCmdDrawIndexed( // + r->cmd, // commandBuffer + r->mesh.index_counts[view_index], // indexCount + 1, // instanceCount + r->mesh.index_offsets[view_index], // firstIndex + 0, // vertexOffset + 0); // firstInstance } else { vk->vkCmdDraw( // r->cmd, // commandBuffer @@ -783,27 +814,3 @@ render_gfx_distortion(struct render_gfx *rr) 0); // firstInstance } } - -void -render_gfx_update_distortion(struct render_gfx *rr, - uint32_t view_index, - VkSampler sampler, - VkImageView image_view, - struct render_gfx_mesh_ubo_data *data) -{ - struct vk_bundle *vk = vk_from_rr(rr); - struct render_resources *r = rr->r; - struct render_gfx_view *v = &rr->views[view_index]; - - render_buffer_write(vk, &r->mesh.ubos[view_index], data, sizeof(struct render_gfx_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 - r->mesh.ubos[view_index].buffer, // buffer - VK_WHOLE_SIZE, // size - v->mesh.descriptor_set); // descriptor_set -} diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h index 7f58c3d41..bb16ee454 100644 --- a/src/xrt/compositor/render/render_interface.h +++ b/src/xrt/compositor/render/render_interface.h @@ -759,36 +759,22 @@ void render_gfx_end_view(struct render_gfx *rr); /*! + * Dispatch one mesh shader instance into the current view. + * * @public @memberof render_gfx */ void -render_gfx_distortion(struct render_gfx *rr); +render_gfx_distortion(struct render_gfx *rr, + uint32_t view_index, + const struct xrt_matrix_2x2 *vertex_rot, + VkSampler sampler, + VkImageView image_view, + const struct xrt_normalized_rect *src_rect); /*! * @} */ -/* - * - * Update functions. - * - */ - -/*! - * @name Update functions - * @{ - */ -/*! - * @public @memberof render_gfx - */ -void -render_gfx_update_distortion(struct render_gfx *rr, - uint32_t view, - VkSampler sampler, - VkImageView image_view, - struct render_gfx_mesh_ubo_data *data); -//! @} - /* *