For the commit message, I have a suggestion:

---

anv: for pinned BOs, skip relocations, but track bo usage

References to pinned BOs won't need to be relocated, so just write the
final value of the reference into the bo.

Add a `set` to the relocation lists for tracking dependencies that
were previously tracked by relocations. When a batch is executed, we
add the referenced pinned BOs to the exec list.

---

Reviewed-by: Jordan Justen <jordan.l.jus...@intel.com>

On 2018-05-07 17:30:49, Scott D Phillips wrote:
> References to pinned bos won't need relocated, so just write the
> final value of the reference into the bo. Add a `set` to the
> relocation lists for tracking dependencies that were previously
> tracked by relocations.
> 
> v2: - visit bos from the dependency set in a deterministic order (Jason)
> ---
>  src/intel/vulkan/anv_batch_chain.c | 52 
> ++++++++++++++++++++++++++++++++++++++
>  src/intel/vulkan/anv_private.h     |  3 +++
>  2 files changed, 55 insertions(+)
> 
> diff --git a/src/intel/vulkan/anv_batch_chain.c 
> b/src/intel/vulkan/anv_batch_chain.c
> index 53b24551088..eaee9afbd29 100644
> --- a/src/intel/vulkan/anv_batch_chain.c
> +++ b/src/intel/vulkan/anv_batch_chain.c
> @@ -75,11 +75,24 @@ anv_reloc_list_init_clone(struct anv_reloc_list *list,
>        return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
>     }
>  
> +   list->deps = _mesa_set_create(NULL, _mesa_hash_pointer,
> +                                 _mesa_key_pointer_equal);
> +
> +   if (!list->deps) {
> +      vk_free(alloc, list->relocs);
> +      vk_free(alloc, list->reloc_bos);
> +      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
> +   }
> +
>     if (other_list) {
>        memcpy(list->relocs, other_list->relocs,
>               list->array_length * sizeof(*list->relocs));
>        memcpy(list->reloc_bos, other_list->reloc_bos,
>               list->array_length * sizeof(*list->reloc_bos));
> +      struct set_entry *entry;
> +      set_foreach(other_list->deps, entry) {
> +         _mesa_set_add_pre_hashed(list->deps, entry->hash, entry->key);
> +      }
>     }
>  
>     return VK_SUCCESS;
> @@ -98,6 +111,7 @@ anv_reloc_list_finish(struct anv_reloc_list *list,
>  {
>     vk_free(alloc, list->relocs);
>     vk_free(alloc, list->reloc_bos);
> +   _mesa_set_destroy(list->deps, NULL);
>  }
>  
>  static VkResult
> @@ -148,6 +162,11 @@ anv_reloc_list_add(struct anv_reloc_list *list,
>     struct drm_i915_gem_relocation_entry *entry;
>     int index;
>  
> +   if (target_bo->flags & EXEC_OBJECT_PINNED) {
> +      _mesa_set_add(list->deps, target_bo);
> +      return VK_SUCCESS;
> +   }
> +
>     VkResult result = anv_reloc_list_grow(list, alloc, 1);
>     if (result != VK_SUCCESS)
>        return result;
> @@ -185,6 +204,12 @@ anv_reloc_list_append(struct anv_reloc_list *list,
>        list->relocs[i + list->num_relocs].offset += offset;
>  
>     list->num_relocs += other->num_relocs;
> +
> +   struct set_entry *entry;
> +   set_foreach(other->deps, entry) {
> +      _mesa_set_add_pre_hashed(list->deps, entry->hash, entry->key);
> +   }
> +
>     return VK_SUCCESS;
>  }
>  
> @@ -338,6 +363,7 @@ anv_batch_bo_start(struct anv_batch_bo *bbo, struct 
> anv_batch *batch,
>     batch->end = bbo->bo.map + bbo->bo.size - batch_padding;
>     batch->relocs = &bbo->relocs;
>     bbo->relocs.num_relocs = 0;
> +   _mesa_set_clear(bbo->relocs.deps, NULL);
>  }
>  
>  static void
> @@ -783,6 +809,7 @@ anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer 
> *cmd_buffer)
>     cmd_buffer->bt_next = 0;
>  
>     cmd_buffer->surface_relocs.num_relocs = 0;
> +   _mesa_set_clear(cmd_buffer->surface_relocs.deps, NULL);
>     cmd_buffer->last_ss_pool_center = 0;
>  
>     /* Reset the list of seen buffers */
> @@ -985,6 +1012,14 @@ anv_execbuf_finish(struct anv_execbuf *exec,
>     vk_free(alloc, exec->syncobjs);
>  }
>  
> +static int
> +_compar_bo_handles(const void *_bo1, const void *_bo2)
> +{
> +   const struct anv_bo **bo1 = _bo1, **bo2 = _bo2;
> +
> +   return (*bo1)->gem_handle - (*bo2)->gem_handle;
> +}
> +
>  static VkResult
>  anv_execbuf_add_bo(struct anv_execbuf *exec,
>                     struct anv_bo *bo,
> @@ -1068,6 +1103,23 @@ anv_execbuf_add_bo(struct anv_execbuf *exec,
>           if (result != VK_SUCCESS)
>              return result;
>        }
> +
> +      uint32_t entries = relocs->deps->entries;
> +      struct anv_bo *bos[entries], **bo = bos;
> +      struct set_entry *entry;
> +      set_foreach(relocs->deps, entry) {
> +         *bo++ = entry->key;
> +      }
> +
> +      qsort(bos, entries, sizeof(struct anv_bo*), _compar_bo_handles);
> +
> +      for (bo = bos; bo < bos + entries; bo++) {
> +         VkResult result = anv_execbuf_add_bo(exec, *bo, NULL,
> +                                              extra_flags, alloc);
> +
> +         if (result != VK_SUCCESS)
> +            return result;
> +      }
>     }
>  
>     return VK_SUCCESS;
> diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
> index 36e4589abc6..6d9c7d4dfb3 100644
> --- a/src/intel/vulkan/anv_private.h
> +++ b/src/intel/vulkan/anv_private.h
> @@ -46,7 +46,9 @@
>  #include "blorp/blorp.h"
>  #include "compiler/brw_compiler.h"
>  #include "util/macros.h"
> +#include "util/hash_table.h"
>  #include "util/list.h"
> +#include "util/set.h"
>  #include "util/u_atomic.h"
>  #include "util/u_vector.h"
>  #include "util/vma.h"
> @@ -1090,6 +1092,7 @@ struct anv_reloc_list {
>     uint32_t                                     array_length;
>     struct drm_i915_gem_relocation_entry *       relocs;
>     struct anv_bo **                             reloc_bos;
> +   struct set *                                 deps;
>  };
>  
>  VkResult anv_reloc_list_init(struct anv_reloc_list *list,
> -- 
> 2.14.3
> 
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to