venus: move transient storage from cmd to pool
authorYiwei Zhang <zzyiwei@chromium.org>
Sun, 9 Jul 2023 05:11:44 +0000 (22:11 -0700)
committerMarge Bot <emma+marge@anholt.net>
Sat, 22 Jul 2023 01:49:43 +0000 (01:49 +0000)
The storage is for command scope usage, so it fits better for the pool.

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24103>

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

index 2b83bbe..8b2ebc8 100644 (file)
@@ -70,19 +70,20 @@ vn_dependency_info_has_present_src(uint32_t dep_count,
 static void *
 vn_cmd_get_tmp_data(struct vn_command_buffer *cmd, size_t size)
 {
+   struct vn_command_pool *pool = cmd->pool;
    /* avoid shrinking in case of non efficient reallocation implementation */
-   if (size > cmd->builder.tmp.size) {
+   if (size > pool->tmp.size) {
       void *data =
-         vk_realloc(&cmd->pool->allocator, cmd->builder.tmp.data, size,
-                    VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+         vk_realloc(&pool->allocator, pool->tmp.data, size, VN_DEFAULT_ALIGN,
+                    VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
       if (!data)
          return NULL;
 
-      cmd->builder.tmp.data = data;
-      cmd->builder.tmp.size = size;
+      pool->tmp.data = data;
+      pool->tmp.size = size;
    }
 
-   return cmd->builder.tmp.data;
+   return pool->tmp.data;
 }
 
 static inline VkImageMemoryBarrier *
@@ -729,9 +730,6 @@ vn_DestroyCommandPool(VkDevice device,
       if (cmd->builder.present_src_images)
          vk_free(alloc, cmd->builder.present_src_images);
 
-      if (cmd->builder.tmp.data)
-         vk_free(alloc, cmd->builder.tmp.data);
-
       list_for_each_entry_safe(struct vn_command_buffer_query_batch, batch,
                                &cmd->query_batches, head)
          vk_free(alloc, batch);
@@ -743,6 +741,9 @@ vn_DestroyCommandPool(VkDevice device,
                             &pool->free_query_batches, head)
       vk_free(alloc, batch);
 
+   if (pool->tmp.data)
+      vk_free(alloc, pool->tmp.data);
+
    vn_object_base_fini(&pool->base);
    vk_free(alloc, pool);
 }
@@ -875,9 +876,6 @@ vn_FreeCommandBuffers(VkDevice device,
       if (!cmd)
          continue;
 
-      if (cmd->builder.tmp.data)
-         vk_free(alloc, cmd->builder.tmp.data);
-
       if (cmd->builder.present_src_images)
          vk_free(alloc, cmd->builder.present_src_images);
 
index e0821ff..50e687f 100644 (file)
@@ -25,6 +25,16 @@ struct vn_command_pool {
    struct list_head command_buffers;
 
    struct list_head free_query_batches;
+
+   /* Temporary storage for scrubbing VK_IMAGE_LAYOUT_PRESENT_SRC_KHR. The
+    * storage's lifetime is the command pool's lifetime. We increase the
+    * storage as needed, but never shrink it. Upon used by the cmd buffer, the
+    * storage must fit within command scope to avoid locking or suballocation.
+    */
+   struct {
+      void *data;
+      size_t size;
+   } tmp;
 };
 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_command_pool,
                                base.base,
@@ -39,15 +49,6 @@ enum vn_command_buffer_state {
 };
 
 struct vn_command_buffer_builder {
-   /* Temporary storage for scrubbing VK_IMAGE_LAYOUT_PRESENT_SRC_KHR. The
-    * storage's lifetime is the command buffer's lifetime. We increase the
-    * storage as needed, but never shrink it.
-    */
-   struct {
-      void *data;
-      size_t size;
-   } tmp;
-
    const struct vn_render_pass *render_pass;
    const struct vn_framebuffer *framebuffer;
    const struct vn_image **present_src_images;