c/render: Refactor gfx distortion dispatch

This commit is contained in:
Jakob Bornecrantz 2023-10-01 21:09:19 +01:00
parent 996195f544
commit 975ca891c3
3 changed files with 57 additions and 70 deletions

View file

@ -816,19 +816,13 @@ do_gfx_mesh(struct comp_renderer *r,
i, // view_index i, // view_index
&viewport_datas[i]); // viewport_data &viewport_datas[i]); // viewport_data
struct render_gfx_mesh_ubo_data data = { render_gfx_distortion( //
.vertex_rot = vertex_rots[i], rr, //
.post_transform = src_norm_rects[i], i, //
}; &vertex_rots[i], //
src_samplers[i], //
render_gfx_update_distortion( // src_image_views[i], //
rr, // rr &src_norm_rects[i]); //
i, // view,
src_samplers[i], // sampler,
src_image_views[i], // image_view,
&data); // data
render_gfx_distortion(rr);
render_gfx_end_view(rr); render_gfx_end_view(rr);
} }

View file

@ -711,19 +711,50 @@ render_gfx_end_view(struct render_gfx *rr)
} }
void 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 vk_bundle *vk = vk_from_rr(rr);
struct render_resources *r = rr->r; struct render_resources *r = rr->r;
uint32_t view = rr->current_view; assert(view_index == rr->current_view);
struct render_gfx_view *v = &rr->views[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. * 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( // vk->vkCmdBindDescriptorSets( //
r->cmd, // commandBuffer r->cmd, // commandBuffer
VK_PIPELINE_BIND_POINT_GRAPHICS, // pipelineBindPoint VK_PIPELINE_BIND_POINT_GRAPHICS, // pipelineBindPoint
@ -767,13 +798,13 @@ render_gfx_distortion(struct render_gfx *rr)
0, // offset 0, // offset
VK_INDEX_TYPE_UINT32); // indexType VK_INDEX_TYPE_UINT32); // indexType
vk->vkCmdDrawIndexed( // vk->vkCmdDrawIndexed( //
r->cmd, // commandBuffer r->cmd, // commandBuffer
r->mesh.index_counts[view], // indexCount r->mesh.index_counts[view_index], // indexCount
1, // instanceCount 1, // instanceCount
r->mesh.index_offsets[view], // firstIndex r->mesh.index_offsets[view_index], // firstIndex
0, // vertexOffset 0, // vertexOffset
0); // firstInstance 0); // firstInstance
} else { } else {
vk->vkCmdDraw( // vk->vkCmdDraw( //
r->cmd, // commandBuffer r->cmd, // commandBuffer
@ -783,27 +814,3 @@ render_gfx_distortion(struct render_gfx *rr)
0); // firstInstance 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
}

View file

@ -759,36 +759,22 @@ void
render_gfx_end_view(struct render_gfx *rr); render_gfx_end_view(struct render_gfx *rr);
/*! /*!
* Dispatch one mesh shader instance into the current view.
*
* @public @memberof render_gfx * @public @memberof render_gfx
*/ */
void 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);
//! @}
/* /*
* *