Module: Mesa
Branch: staging/23.3
Commit: 49aa21e327fc0021d3d5aead175297c73c2da829
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=49aa21e327fc0021d3d5aead175297c73c2da829

Author: Juston Li <justo...@google.com>
Date:   Tue Sep 26 15:09:54 2023 -0700

venus: support deferred query feedback recording

Add function to alloc a cmd buffer and record all the deferred query
feedback cmds into it at submission time.

Cc: 23.3 <mesa-stable>
Signed-off-by: Juston Li <justo...@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25413>
(cherry picked from commit 6dcf033dc30e52c1557999bf7588cf0e1c5dcc8c)

---

 .pick_status.json                     |  2 +-
 src/virtio/vulkan/vn_command_buffer.c | 28 +++++----------
 src/virtio/vulkan/vn_feedback.c       | 64 +++++++++++++++++++++++++++++++++++
 src/virtio/vulkan/vn_feedback.h       | 16 +++++++++
 4 files changed, 90 insertions(+), 20 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 141e47f00db..9c8571849f8 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -264,7 +264,7 @@
         "description": "venus: support deferred query feedback recording",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null,
         "notes": null
diff --git a/src/virtio/vulkan/vn_command_buffer.c 
b/src/virtio/vulkan/vn_command_buffer.c
index 7f6d2cffc40..35db167f125 100644
--- a/src/virtio/vulkan/vn_command_buffer.c
+++ b/src/virtio/vulkan/vn_command_buffer.c
@@ -506,22 +506,13 @@ vn_cmd_transfer_present_src_images(
                                  count, img_barriers);
 }
 
-/* query feedback batch for deferred recording */
-struct vn_command_buffer_query_batch {
-   struct vn_query_pool *query_pool;
-   uint32_t query;
-   uint32_t query_count;
-
-   struct list_head head;
-};
-
 static bool
 vn_cmd_query_batch_push(struct vn_command_buffer *cmd,
                         struct vn_query_pool *query_pool,
                         uint32_t query,
                         uint32_t query_count)
 {
-   struct vn_command_buffer_query_batch *batch;
+   struct vn_feedback_query_batch *batch;
    if (list_is_empty(&cmd->pool->free_query_batches)) {
       batch = vk_alloc(&cmd->pool->allocator, sizeof(*batch),
                        VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
@@ -529,7 +520,7 @@ vn_cmd_query_batch_push(struct vn_command_buffer *cmd,
          return false;
    } else {
       batch = list_first_entry(&cmd->pool->free_query_batches,
-                               struct vn_command_buffer_query_batch, head);
+                               struct vn_feedback_query_batch, head);
       list_del(&batch->head);
    }
 
@@ -543,7 +534,7 @@ vn_cmd_query_batch_push(struct vn_command_buffer *cmd,
 
 static inline void
 vn_cmd_query_batch_pop(struct vn_command_buffer *cmd,
-                       struct vn_command_buffer_query_batch *batch)
+                       struct vn_feedback_query_batch *batch)
 {
    list_move_to(&batch->head, &cmd->pool->free_query_batches);
 }
@@ -551,7 +542,7 @@ vn_cmd_query_batch_pop(struct vn_command_buffer *cmd,
 static void
 vn_cmd_record_batched_query_feedback(struct vn_command_buffer *cmd)
 {
-   list_for_each_entry_safe(struct vn_command_buffer_query_batch, batch,
+   list_for_each_entry_safe(struct vn_feedback_query_batch, batch,
                             &cmd->builder.query_batches, head) {
       vn_feedback_query_cmd_record(vn_command_buffer_to_handle(cmd),
                                    vn_query_pool_to_handle(batch->query_pool),
@@ -565,8 +556,7 @@ static inline void
 vn_cmd_merge_batched_query_feedback(struct vn_command_buffer *primary_cmd,
                                     struct vn_command_buffer *secondary_cmd)
 {
-   list_for_each_entry_safe(struct vn_command_buffer_query_batch,
-                            secondary_batch,
+   list_for_each_entry_safe(struct vn_feedback_query_batch, secondary_batch,
                             &secondary_cmd->builder.query_batches, head) {
       if (!vn_cmd_query_batch_push(primary_cmd, secondary_batch->query_pool,
                                    secondary_batch->query,
@@ -766,14 +756,14 @@ vn_DestroyCommandPool(VkDevice device,
       if (cmd->builder.present_src_images)
          vk_free(alloc, cmd->builder.present_src_images);
 
-      list_for_each_entry_safe(struct vn_command_buffer_query_batch, batch,
+      list_for_each_entry_safe(struct vn_feedback_query_batch, batch,
                                &cmd->builder.query_batches, head)
          vk_free(alloc, batch);
 
       vk_free(alloc, cmd);
    }
 
-   list_for_each_entry_safe(struct vn_command_buffer_query_batch, batch,
+   list_for_each_entry_safe(struct vn_feedback_query_batch, batch,
                             &pool->free_query_batches, head)
       vk_free(alloc, batch);
 
@@ -795,7 +785,7 @@ vn_cmd_reset(struct vn_command_buffer *cmd)
    if (cmd->builder.present_src_images)
       vk_free(&cmd->pool->allocator, cmd->builder.present_src_images);
 
-   list_for_each_entry_safe(struct vn_command_buffer_query_batch, batch,
+   list_for_each_entry_safe(struct vn_feedback_query_batch, batch,
                             &cmd->builder.query_batches, head)
       vn_cmd_query_batch_pop(cmd, batch);
 
@@ -912,7 +902,7 @@ vn_FreeCommandBuffers(VkDevice device,
       if (cmd->builder.present_src_images)
          vk_free(alloc, cmd->builder.present_src_images);
 
-      list_for_each_entry_safe(struct vn_command_buffer_query_batch, batch,
+      list_for_each_entry_safe(struct vn_feedback_query_batch, batch,
                                &cmd->builder.query_batches, head)
          vn_cmd_query_batch_pop(cmd, batch);
 
diff --git a/src/virtio/vulkan/vn_feedback.c b/src/virtio/vulkan/vn_feedback.c
index 660549f48f2..5adb55e4d78 100644
--- a/src/virtio/vulkan/vn_feedback.c
+++ b/src/virtio/vulkan/vn_feedback.c
@@ -595,6 +595,70 @@ vn_feedback_query_cmd_record(VkCommandBuffer cmd_handle,
                                         offset, buf_size);
 }
 
+static void
+vn_cmd_record_batched_query_feedback(VkCommandBuffer *cmd_handle,
+                                     struct list_head *combined_query_batches)
+{
+   list_for_each_entry_safe(struct vn_feedback_query_batch, batch,
+                            combined_query_batches, head) {
+      vn_feedback_query_cmd_record(
+         *cmd_handle, vn_query_pool_to_handle(batch->query_pool),
+         batch->query, batch->query_count, batch->copy);
+   }
+}
+
+VkResult
+vn_feedback_query_batch_record(VkDevice dev_handle,
+                               struct vn_feedback_cmd_pool *feedback_pool,
+                               struct list_head *combined_query_batches,
+                               VkCommandBuffer *out_cmd_handle)
+{
+   const VkCommandBufferAllocateInfo info = {
+      .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+      .pNext = NULL,
+      .commandPool = feedback_pool->pool,
+      .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+      .commandBufferCount = 1,
+   };
+   VkCommandBuffer feedback_cmd_handle;
+   VkResult result;
+
+   simple_mtx_lock(&feedback_pool->mutex);
+
+   result =
+      vn_AllocateCommandBuffers(dev_handle, &info, &feedback_cmd_handle);
+   if (result != VK_SUCCESS)
+      goto out_unlock;
+
+   static const VkCommandBufferBeginInfo begin_info = {
+      .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
+   };
+
+   result = vn_BeginCommandBuffer(feedback_cmd_handle, &begin_info);
+   if (result != VK_SUCCESS) {
+      vn_FreeCommandBuffers(dev_handle, feedback_pool->pool, 1,
+                            &feedback_cmd_handle);
+      goto out_unlock;
+   }
+
+   vn_cmd_record_batched_query_feedback(&feedback_cmd_handle,
+                                        combined_query_batches);
+
+   result = vn_EndCommandBuffer(feedback_cmd_handle);
+   if (result != VK_SUCCESS) {
+      vn_FreeCommandBuffers(dev_handle, feedback_pool->pool, 1,
+                            &feedback_cmd_handle);
+      goto out_unlock;
+   }
+
+   *out_cmd_handle = feedback_cmd_handle;
+
+out_unlock:
+   simple_mtx_unlock(&feedback_pool->mutex);
+
+   return result;
+}
+
 VkResult
 vn_feedback_cmd_alloc(VkDevice dev_handle,
                       struct vn_feedback_cmd_pool *pool,
diff --git a/src/virtio/vulkan/vn_feedback.h b/src/virtio/vulkan/vn_feedback.h
index 0069210d454..7084ff221d8 100644
--- a/src/virtio/vulkan/vn_feedback.h
+++ b/src/virtio/vulkan/vn_feedback.h
@@ -64,6 +64,16 @@ struct vn_feedback_buffer {
    struct list_head head;
 };
 
+/* query feedback batch for deferred recording */
+struct vn_feedback_query_batch {
+   struct vn_query_pool *query_pool;
+   uint32_t query;
+   uint32_t query_count;
+   bool copy;
+
+   struct list_head head;
+};
+
 VkResult
 vn_feedback_pool_init(struct vn_device *dev,
                       struct vn_feedback_pool *pool,
@@ -143,6 +153,12 @@ vn_feedback_query_cmd_record(VkCommandBuffer cmd_handle,
                              uint32_t count,
                              bool copy);
 
+VkResult
+vn_feedback_query_batch_record(VkDevice dev_handle,
+                               struct vn_feedback_cmd_pool *feedback_pool,
+                               struct list_head *combined_query_batches,
+                               VkCommandBuffer *out_cmd_handle);
+
 VkResult
 vn_feedback_cmd_alloc(VkDevice dev_handle,
                       struct vn_feedback_cmd_pool *pool,

Reply via email to