From 34b28cfb7d9d7475f093bfdc8aca31d4c1c71dd5 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 6 Dec 2022 14:03:02 -0800 Subject: [PATCH] venus: scrub ignored fields for descriptor writes for push descriptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: 933ca11f1a4 ("venus: implement vkCmdPushDescriptorSetWithTemplateKHR") Signed-off-by: Yiwei Zhang Reviewed-by: Corentin Noël Reviewed-by: Dawn Han Part-of: --- src/virtio/vulkan/vn_command_buffer.c | 15 ++++++++++++++- src/virtio/vulkan/vn_descriptor_set.c | 19 ++++++++++++------- src/virtio/vulkan/vn_descriptor_set.h | 7 +++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/virtio/vulkan/vn_command_buffer.c b/src/virtio/vulkan/vn_command_buffer.c index f2a6f545551..95002c035c3 100644 --- a/src/virtio/vulkan/vn_command_buffer.c +++ b/src/virtio/vulkan/vn_command_buffer.c @@ -2052,8 +2052,21 @@ vn_CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites) { + struct vn_command_buffer *cmd = + vn_command_buffer_from_handle(commandBuffer); + struct vn_update_descriptor_sets *update = + vn_update_descriptor_sets_parse_writes( + descriptorWriteCount, pDescriptorWrites, &cmd->allocator, layout); + if (!update) { + cmd->state = VN_COMMAND_BUFFER_STATE_INVALID; + vn_log(cmd->device->instance, "descriptor set push ignored due to OOM"); + return; + } + VN_CMD_ENQUEUE(vkCmdPushDescriptorSetKHR, commandBuffer, pipelineBindPoint, - layout, set, descriptorWriteCount, pDescriptorWrites); + layout, set, update->write_count, update->writes); + + vk_free(&cmd->allocator, update); } void diff --git a/src/virtio/vulkan/vn_descriptor_set.c b/src/virtio/vulkan/vn_descriptor_set.c index f9fd86830fd..e0b11f17377 100644 --- a/src/virtio/vulkan/vn_descriptor_set.c +++ b/src/virtio/vulkan/vn_descriptor_set.c @@ -799,10 +799,11 @@ vn_update_descriptor_sets_alloc(uint32_t write_count, return update; } -static struct vn_update_descriptor_sets * +struct vn_update_descriptor_sets * vn_update_descriptor_sets_parse_writes(uint32_t write_count, const VkWriteDescriptorSet *writes, - const VkAllocationCallbacks *alloc) + const VkAllocationCallbacks *alloc, + VkPipelineLayout pipeline_layout_handle) { uint32_t img_count = 0; for (uint32_t i = 0; i < write_count; i++) { @@ -834,11 +835,15 @@ vn_update_descriptor_sets_parse_writes(uint32_t write_count, */ memcpy(update->writes, writes, sizeof(*writes) * write_count); img_count = 0; + const struct vn_pipeline_layout *pipeline_layout = + vn_pipeline_layout_from_handle(pipeline_layout_handle); for (uint32_t i = 0; i < write_count; i++) { - const struct vn_descriptor_set *set = - vn_descriptor_set_from_handle(writes[i].dstSet); + const struct vn_descriptor_set_layout *set_layout = + pipeline_layout + ? pipeline_layout->push_descriptor_set_layout + : vn_descriptor_set_from_handle(writes[i].dstSet)->layout; const struct vn_descriptor_set_layout_binding *binding = - &set->layout->bindings[writes[i].dstBinding]; + &set_layout->bindings[writes[i].dstBinding]; VkWriteDescriptorSet *write = &update->writes[i]; VkDescriptorImageInfo *imgs = &update->images[img_count]; @@ -912,8 +917,8 @@ vn_UpdateDescriptorSets(VkDevice device, const VkAllocationCallbacks *alloc = &dev->base.base.alloc; struct vn_update_descriptor_sets *update = - vn_update_descriptor_sets_parse_writes(descriptorWriteCount, - pDescriptorWrites, alloc); + vn_update_descriptor_sets_parse_writes( + descriptorWriteCount, pDescriptorWrites, alloc, VK_NULL_HANDLE); if (!update) { /* TODO update one-by-one? */ vn_log(dev->instance, "TODO descriptor set update ignored due to OOM"); diff --git a/src/virtio/vulkan/vn_descriptor_set.h b/src/virtio/vulkan/vn_descriptor_set.h index ee4c1df4209..c2652c22bfe 100644 --- a/src/virtio/vulkan/vn_descriptor_set.h +++ b/src/virtio/vulkan/vn_descriptor_set.h @@ -135,6 +135,13 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_update_template, VkDescriptorUpdateTemplate, VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE) +struct vn_update_descriptor_sets * +vn_update_descriptor_sets_parse_writes( + uint32_t write_count, + const VkWriteDescriptorSet *writes, + const VkAllocationCallbacks *alloc, + VkPipelineLayout pipeline_layout_handle); + struct vn_update_descriptor_sets * vn_update_descriptor_set_with_template_locked( struct vn_descriptor_update_template *templ,