venus: scrub ignored fields for descriptor writes for push descriptor
authorYiwei Zhang <zzyiwei@chromium.org>
Tue, 6 Dec 2022 22:03:02 +0000 (14:03 -0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 8 Dec 2022 01:56:35 +0000 (01:56 +0000)
Fixes: 933ca11f1a4 ("venus: implement vkCmdPushDescriptorSetWithTemplateKHR")

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Corentin Noël <corentin.noel@collabora.com>
Reviewed-by: Dawn Han <dawnhan@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20191>

src/virtio/vulkan/vn_command_buffer.c
src/virtio/vulkan/vn_descriptor_set.c
src/virtio/vulkan/vn_descriptor_set.h

index f2a6f54..95002c0 100644 (file)
@@ -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
index f9fd868..e0b11f1 100644 (file)
@@ -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");
index ee4c1df..c2652c2 100644 (file)
@@ -136,6 +136,13 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_update_template,
                                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,
    struct vn_descriptor_set *set,