anv: Replace ANV_BO_EXTERNAL with anv_bo::is_external
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 29 Oct 2019 01:12:24 +0000 (20:12 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Thu, 31 Oct 2019 13:46:08 +0000 (13:46 +0000)
We're not THAT strapped for space that we can't burn one extra bit for
a boolean.  If we're really worried about it, we can always shrink the
flags field to 16 bits because the kernel only uses 7 currently.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_allocator.c
src/intel/vulkan/anv_batch_chain.c
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_intel.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/anv_queue.c

index 53f4c44..a39a171 100644 (file)
@@ -1624,13 +1624,13 @@ anv_bo_cache_lookup(struct anv_bo_cache *cache, uint32_t gem_handle)
    (EXEC_OBJECT_WRITE | \
     EXEC_OBJECT_ASYNC | \
     EXEC_OBJECT_SUPPORTS_48B_ADDRESS | \
-    EXEC_OBJECT_PINNED | \
-    ANV_BO_EXTERNAL)
+    EXEC_OBJECT_PINNED)
 
 VkResult
 anv_bo_cache_alloc(struct anv_device *device,
                    struct anv_bo_cache *cache,
                    uint64_t size, uint64_t bo_flags,
+                   bool is_external,
                    struct anv_bo **bo_out)
 {
    assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
@@ -1644,6 +1644,7 @@ anv_bo_cache_alloc(struct anv_device *device,
       return result;
 
    new_bo.flags = bo_flags;
+   new_bo.is_external = is_external;
 
    if (!anv_vma_alloc(device, &new_bo)) {
       anv_gem_close(device, new_bo.gem_handle);
@@ -1672,7 +1673,6 @@ anv_bo_cache_import_host_ptr(struct anv_device *device,
                              uint64_t bo_flags, struct anv_bo **bo_out)
 {
    assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
-   assert((bo_flags & ANV_BO_EXTERNAL) == 0);
 
    uint32_t gem_handle = anv_gem_userptr(device, host_ptr, size);
    if (!gem_handle)
@@ -1698,6 +1698,7 @@ anv_bo_cache_import_host_ptr(struct anv_device *device,
       struct anv_bo new_bo;
       anv_bo_init(&new_bo, gem_handle, size);
       new_bo.flags = bo_flags;
+      new_bo.is_external = true;
 
       if (!anv_vma_alloc(device, &new_bo)) {
          anv_gem_close(device, new_bo.gem_handle);
@@ -1723,7 +1724,6 @@ anv_bo_cache_import(struct anv_device *device,
                     struct anv_bo **bo_out)
 {
    assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS));
-   assert(bo_flags & ANV_BO_EXTERNAL);
 
    pthread_mutex_lock(&cache->mutex);
 
@@ -1740,7 +1740,7 @@ anv_bo_cache_import(struct anv_device *device,
        * client has imported a BO twice in different ways and they get what
        * they have coming.
        */
-      uint64_t new_flags = ANV_BO_EXTERNAL;
+      uint64_t new_flags = 0;
       new_flags |= (bo->flags | bo_flags) & EXEC_OBJECT_WRITE;
       new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_ASYNC;
       new_flags |= (bo->flags & bo_flags) & EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
@@ -1789,6 +1789,7 @@ anv_bo_cache_import(struct anv_device *device,
       struct anv_bo new_bo;
       anv_bo_init(&new_bo, gem_handle, size);
       new_bo.flags = bo_flags;
+      new_bo.is_external = true;
 
       if (!anv_vma_alloc(device, &new_bo)) {
          anv_gem_close(device, new_bo.gem_handle);
@@ -1818,7 +1819,7 @@ anv_bo_cache_export(struct anv_device *device,
     * to export it.  This is done based on external options passed into
     * anv_AllocateMemory.
     */
-   assert(bo->flags & ANV_BO_EXTERNAL);
+   assert(bo->is_external);
 
    int fd = anv_gem_handle_to_fd(device, bo->gem_handle);
    if (fd < 0)
index 5ff58e8..fcd8754 100644 (file)
@@ -1113,7 +1113,7 @@ anv_execbuf_add_bo(struct anv_execbuf *exec,
       obj->relocs_ptr = 0;
       obj->alignment = 0;
       obj->offset = bo->offset;
-      obj->flags = (bo->flags & ~ANV_BO_FLAG_MASK) | extra_flags;
+      obj->flags = bo->flags | extra_flags;
       obj->rsvd1 = 0;
       obj->rsvd2 = 0;
    }
index 80e3783..996705f 100644 (file)
@@ -3177,7 +3177,7 @@ VkResult anv_AllocateMemory(
                VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
 
       result = anv_bo_cache_import(device, &device->bo_cache, fd_info->fd,
-                                   bo_flags | ANV_BO_EXTERNAL, &mem->bo);
+                                   bo_flags, &mem->bo);
       if (result != VK_SUCCESS)
          goto fail;
 
@@ -3242,11 +3242,10 @@ VkResult anv_AllocateMemory(
 
    /* Regular allocate (not importing memory). */
 
-   if (export_info && export_info->handleTypes)
-      bo_flags |= ANV_BO_EXTERNAL;
-
+   bool is_external = export_info && export_info->handleTypes;
    result = anv_bo_cache_alloc(device, &device->bo_cache,
-                               pAllocateInfo->allocationSize, bo_flags,
+                               pAllocateInfo->allocationSize,
+                               bo_flags, is_external,
                                &mem->bo);
    if (result != VK_SUCCESS)
       goto fail;
index 146fc41..e68a689 100644 (file)
@@ -72,7 +72,7 @@ VkResult anv_CreateDmaBufImageINTEL(
 
    image = anv_image_from_handle(image_h);
 
-   uint64_t bo_flags = ANV_BO_EXTERNAL;
+   uint64_t bo_flags = 0;
    if (device->instance->physicalDevice.supports_48bit_addresses)
       bo_flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
    if (device->instance->physicalDevice.use_softpin)
index 328b3a8..512acb5 100644 (file)
@@ -597,10 +597,6 @@ anv_multialloc_alloc2(struct anv_multialloc *ma,
    return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
 }
 
-/* Extra ANV-defined BO flags which won't be passed to the kernel */
-#define ANV_BO_EXTERNAL    (1ull << 31)
-#define ANV_BO_FLAG_MASK   (1ull << 31)
-
 struct anv_bo {
    uint32_t gem_handle;
 
@@ -623,6 +619,9 @@ struct anv_bo {
 
    /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
    uint32_t flags;
+
+   /** True if this BO may be shared with other processes */
+   bool is_external:1;
 };
 
 static inline void
@@ -635,6 +634,7 @@ anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
    bo->size = size;
    bo->map = NULL;
    bo->flags = 0;
+   bo->is_external = false;
 }
 
 /* Represents a lock-free linked list of "free" things.  This is used by
@@ -901,6 +901,7 @@ void anv_bo_cache_finish(struct anv_bo_cache *cache);
 VkResult anv_bo_cache_alloc(struct anv_device *device,
                             struct anv_bo_cache *cache,
                             uint64_t size, uint64_t bo_flags,
+                            bool is_external,
                             struct anv_bo **bo);
 VkResult anv_bo_cache_import_host_ptr(struct anv_device *device,
                                       struct anv_bo_cache *cache,
@@ -1219,7 +1220,7 @@ anv_binding_table_pool_free(struct anv_device *device, struct anv_state state) {
 static inline uint32_t
 anv_mocs_for_bo(const struct anv_device *device, const struct anv_bo *bo)
 {
-   if (bo->flags & ANV_BO_EXTERNAL)
+   if (bo->is_external)
       return device->external_mocs;
    else
       return device->default_mocs;
index 67b402a..5aa0f10 100644 (file)
@@ -952,7 +952,8 @@ VkResult anv_CreateSemaphore(
       } else {
          semaphore->permanent.type = ANV_SEMAPHORE_TYPE_BO;
          VkResult result = anv_bo_cache_alloc(device, &device->bo_cache,
-                                              4096, ANV_BO_EXTERNAL,
+                                              4096, 0 /* flags */,
+                                              true /* is_external */,
                                               &semaphore->permanent.bo);
          if (result != VK_SUCCESS) {
             vk_free2(&device->alloc, pAllocator, semaphore);
@@ -1106,7 +1107,7 @@ VkResult anv_ImportSemaphoreFdKHR(
          new_impl.type = ANV_SEMAPHORE_TYPE_BO;
 
          VkResult result = anv_bo_cache_import(device, &device->bo_cache,
-                                               fd, ANV_BO_EXTERNAL,
+                                               fd, 0 /* flags */,
                                                &new_impl.bo);
          if (result != VK_SUCCESS)
             return result;