Module: Mesa
Branch: main
Commit: f49989148aeaa4320f836cd545739f93733d118c
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f49989148aeaa4320f836cd545739f93733d118c

Author: José Roberto de Souza <[email protected]>
Date:   Mon Jul 31 11:29:14 2023 -0700

anv: Return earlier in anv_reloc_list functions

Xe KMD don't need relocs, so calling a nop function and avoiding the
CPU cycles and memory waste with reloc.

Signed-off-by: José Roberto de Souza <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24411>

---

 src/intel/vulkan/anv_batch_chain.c | 14 +++++++++-----
 src/intel/vulkan/anv_device.c      |  2 ++
 src/intel/vulkan/anv_pipeline.c    |  3 ++-
 src/intel/vulkan/anv_private.h     | 16 +++++++++++++---
 src/intel/vulkan/anv_utrace.c      |  6 ++++--
 5 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/intel/vulkan/anv_batch_chain.c 
b/src/intel/vulkan/anv_batch_chain.c
index fa00bf9d031..0dacca9b688 100644
--- a/src/intel/vulkan/anv_batch_chain.c
+++ b/src/intel/vulkan/anv_batch_chain.c
@@ -53,10 +53,12 @@
 
 VkResult
 anv_reloc_list_init(struct anv_reloc_list *list,
-                    const VkAllocationCallbacks *alloc)
+                    const VkAllocationCallbacks *alloc,
+                    bool uses_relocs)
 {
    assert(alloc != NULL);
    memset(list, 0, sizeof(*list));
+   list->uses_relocs = uses_relocs;
    list->alloc = alloc;
    return VK_SUCCESS;
 }
@@ -113,8 +115,8 @@ anv_reloc_list_grow_deps(struct anv_reloc_list *list,
 }
 
 VkResult
-anv_reloc_list_add_bo(struct anv_reloc_list *list,
-                      struct anv_bo *target_bo)
+anv_reloc_list_add_bo_impl(struct anv_reloc_list *list,
+                           struct anv_bo *target_bo)
 {
    uint32_t idx = target_bo->gem_handle;
    VkResult result = anv_reloc_list_grow_deps(list,
@@ -254,7 +256,8 @@ anv_batch_bo_create(struct anv_cmd_buffer *cmd_buffer,
    if (result != VK_SUCCESS)
       goto fail_alloc;
 
-   result = anv_reloc_list_init(&bbo->relocs, &cmd_buffer->vk.pool->alloc);
+   const bool uses_relocs = cmd_buffer->device->physical->uses_relocs;
+   result = anv_reloc_list_init(&bbo->relocs, &cmd_buffer->vk.pool->alloc, 
uses_relocs);
    if (result != VK_SUCCESS)
       goto fail_bo_alloc;
 
@@ -849,8 +852,9 @@ anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer 
*cmd_buffer)
    if (!success)
       goto fail_seen_bbos;
 
+   const bool uses_relocs = cmd_buffer->device->physical->uses_relocs;
    result = anv_reloc_list_init(&cmd_buffer->surface_relocs,
-                                &cmd_buffer->vk.pool->alloc);
+                                &cmd_buffer->vk.pool->alloc, uses_relocs);
    if (result != VK_SUCCESS)
       goto fail_bt_blocks;
 
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 48f0b27da87..d9eee5cd15b 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -1359,6 +1359,8 @@ anv_physical_device_try_create(struct vk_instance 
*vk_instance,
                                                                
device->info.kmd_type,
                                                                &u64_ignore);
 
+   device->uses_relocs = device->info.kmd_type != INTEL_KMD_TYPE_XE;
+
    device->always_flush_cache = INTEL_DEBUG(DEBUG_STALL) ||
       driQueryOptionb(&instance->dri_options, "always_flush_cache");
 
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 208bd9c2426..c49341c9766 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -264,8 +264,9 @@ anv_pipeline_init(struct anv_pipeline *pipeline,
    pipeline->batch.relocs = &pipeline->batch_relocs;
    pipeline->batch.status = VK_SUCCESS;
 
+   const bool uses_relocs = device->physical->uses_relocs;
    result = anv_reloc_list_init(&pipeline->batch_relocs,
-                                pipeline->batch.alloc);
+                                pipeline->batch.alloc, uses_relocs);
    if (result != VK_SUCCESS)
       return result;
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index b5f0ec92472..80eafea20ae 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -945,6 +945,8 @@ struct anv_physical_device {
      */
     bool                                        indirect_descriptors;
 
+    bool                                        uses_relocs;
+
     struct {
       uint32_t                                  family_count;
       struct anv_queue_family                   
families[ANV_MAX_QUEUE_FAMILIES];
@@ -1432,17 +1434,25 @@ void anv_vma_free(struct anv_device *device,
                   uint64_t address, uint64_t size);
 
 struct anv_reloc_list {
+   bool                                         uses_relocs;
    uint32_t                                     dep_words;
    BITSET_WORD *                                deps;
    const VkAllocationCallbacks                  *alloc;
 };
 
 VkResult anv_reloc_list_init(struct anv_reloc_list *list,
-                             const VkAllocationCallbacks *alloc);
+                             const VkAllocationCallbacks *alloc,
+                             bool uses_relocs);
 void anv_reloc_list_finish(struct anv_reloc_list *list);
 
-VkResult anv_reloc_list_add_bo(struct anv_reloc_list *list,
-                               struct anv_bo *target_bo);
+VkResult
+anv_reloc_list_add_bo_impl(struct anv_reloc_list *list, struct anv_bo 
*target_bo);
+
+static inline VkResult
+anv_reloc_list_add_bo(struct anv_reloc_list *list, struct anv_bo *target_bo)
+{
+   return list->uses_relocs ? anv_reloc_list_add_bo_impl(list, target_bo) : 
VK_SUCCESS;
+}
 
 struct anv_batch_bo {
    /* Link in the anv_cmd_buffer.owned_batch_bos list */
diff --git a/src/intel/vulkan/anv_utrace.c b/src/intel/vulkan/anv_utrace.c
index 5151c348207..0862598f558 100644
--- a/src/intel/vulkan/anv_utrace.c
+++ b/src/intel/vulkan/anv_utrace.c
@@ -167,7 +167,8 @@ anv_device_utrace_flush_cmd_buffers(struct anv_queue *queue,
       if (result != VK_SUCCESS)
          goto error_batch_buf;
 
-      result = anv_reloc_list_init(&submit->relocs, &device->vk.alloc);
+      const bool uses_relocs = device->physical->uses_relocs;
+      result = anv_reloc_list_init(&submit->relocs, &device->vk.alloc, 
uses_relocs);
       if (result != VK_SUCCESS)
          goto error_reloc_list;
 
@@ -463,7 +464,8 @@ anv_queue_trace(struct anv_queue *queue, const char *label, 
bool frame, bool beg
    if (result != VK_SUCCESS)
       goto error_sync;
 
-   result = anv_reloc_list_init(&submit->relocs, &device->vk.alloc);
+   const bool uses_relocs = device->physical->uses_relocs;
+   result = anv_reloc_list_init(&submit->relocs, &device->vk.alloc, 
uses_relocs);
    if (result != VK_SUCCESS)
       goto error_batch_bo;
 

Reply via email to