From 498f1d7eb1b972df8a9a5eb2bf4d52df20fcefa0 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 4 Apr 2024 19:23:17 -0700 Subject: [PATCH] venus: simplify push descriptor update with template No need to track is_push_descriptor in templ. No need to conditionally decide to use set or NULL handle since we pass NULL handle from the cmd side. Also fixed the arg type mismatch in the template helper. Signed-off-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_command_buffer.c | 2 +- src/virtio/vulkan/vn_descriptor_set.c | 28 +++++++++++---------------- src/virtio/vulkan/vn_descriptor_set.h | 9 +++++---- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/virtio/vulkan/vn_command_buffer.c b/src/virtio/vulkan/vn_command_buffer.c index 3672eddb8df..d586c820cbb 100644 --- a/src/virtio/vulkan/vn_command_buffer.c +++ b/src/virtio/vulkan/vn_command_buffer.c @@ -2237,7 +2237,7 @@ vn_CmdPushDescriptorSetWithTemplateKHR( vn_update_descriptor_set_with_template_locked(templ, VK_NULL_HANDLE, pData); VN_CMD_ENQUEUE(vkCmdPushDescriptorSetKHR, commandBuffer, - templ->pipeline_bind_point, layout, set, + templ->push.pipeline_bind_point, layout, set, update->write_count, update->writes); mtx_unlock(&templ->mutex); diff --git a/src/virtio/vulkan/vn_descriptor_set.c b/src/virtio/vulkan/vn_descriptor_set.c index df33710946a..7c57ec0f673 100644 --- a/src/virtio/vulkan/vn_descriptor_set.c +++ b/src/virtio/vulkan/vn_descriptor_set.c @@ -1040,13 +1040,12 @@ vn_CreateDescriptorUpdateTemplate( return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY); } - templ->is_push_descriptor = - pCreateInfo->templateType == - VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR; - if (templ->is_push_descriptor) { - templ->pipeline_bind_point = pCreateInfo->pipelineBindPoint; - templ->pipeline_layout = + if (pCreateInfo->templateType == + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR) { + struct vn_pipeline_layout *pipeline_layout = vn_pipeline_layout_from_handle(pCreateInfo->pipelineLayout); + templ->push.pipeline_bind_point = pCreateInfo->pipelineBindPoint; + templ->push.set_layout = pipeline_layout->push_descriptor_set_layout; } mtx_init(&templ->mutex, mtx_plain); @@ -1086,27 +1085,23 @@ vn_DestroyDescriptorUpdateTemplate( struct vn_update_descriptor_sets * vn_update_descriptor_set_with_template_locked( struct vn_descriptor_update_template *templ, - struct vn_descriptor_set *set, + VkDescriptorSet set_handle, const void *data) { struct vn_update_descriptor_sets *update = templ->update; + struct vn_descriptor_set *set = vn_descriptor_set_from_handle(set_handle); for (uint32_t i = 0; i < update->write_count; i++) { const struct vn_descriptor_update_template_entry *entry = &templ->entries[i]; - const struct vn_descriptor_set_layout *set_layout = - templ->is_push_descriptor - ? templ->pipeline_layout->push_descriptor_set_layout - : set->layout; + templ->push.set_layout ? templ->push.set_layout : set->layout; const struct vn_descriptor_set_layout_binding *binding = &set_layout->bindings[update->writes[i].dstBinding]; VkWriteDescriptorSet *write = &update->writes[i]; - write->dstSet = templ->is_push_descriptor - ? VK_NULL_HANDLE - : vn_descriptor_set_to_handle(set); + write->dstSet = set_handle; switch (write->descriptorType) { case VK_DESCRIPTOR_TYPE_SAMPLER: @@ -1179,12 +1174,11 @@ vn_UpdateDescriptorSetWithTemplate( struct vn_device *dev = vn_device_from_handle(device); struct vn_descriptor_update_template *templ = vn_descriptor_update_template_from_handle(descriptorUpdateTemplate); - struct vn_descriptor_set *set = - vn_descriptor_set_from_handle(descriptorSet); mtx_lock(&templ->mutex); struct vn_update_descriptor_sets *update = - vn_update_descriptor_set_with_template_locked(templ, set, pData); + vn_update_descriptor_set_with_template_locked(templ, descriptorSet, + pData); vn_async_vkUpdateDescriptorSets(dev->primary_ring, device, update->write_count, update->writes, 0, diff --git a/src/virtio/vulkan/vn_descriptor_set.h b/src/virtio/vulkan/vn_descriptor_set.h index 1f4816e51a7..0b201dcf77b 100644 --- a/src/virtio/vulkan/vn_descriptor_set.h +++ b/src/virtio/vulkan/vn_descriptor_set.h @@ -116,9 +116,10 @@ struct vn_descriptor_update_template_entry { struct vn_descriptor_update_template { struct vn_object_base base; - bool is_push_descriptor; - VkPipelineBindPoint pipeline_bind_point; - struct vn_pipeline_layout *pipeline_layout; + struct { + VkPipelineBindPoint pipeline_bind_point; + struct vn_descriptor_set_layout *set_layout; + } push; mtx_t mutex; struct vn_update_descriptor_sets *update; @@ -148,7 +149,7 @@ vn_descriptor_set_get_writes(uint32_t write_count, struct vn_update_descriptor_sets * vn_update_descriptor_set_with_template_locked( struct vn_descriptor_update_template *templ, - struct vn_descriptor_set *set, + VkDescriptorSet set_handle, const void *data); void