diff options
author | Jason Ekstrand <[email protected]> | 2019-10-28 20:12:24 -0500 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2019-10-31 13:46:08 +0000 |
commit | b781c85c79944ccc0a6b0e49daae574672c6dd26 (patch) | |
tree | 59dc436634979b4c53f5037cdeec2383c3d87737 /src/intel/vulkan | |
parent | 5534358ef6189fe1169ad181ac4578d41bec6835 (diff) |
anv: Replace ANV_BO_EXTERNAL with anv_bo::is_external
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 <[email protected]>
Diffstat (limited to 'src/intel/vulkan')
-rw-r--r-- | src/intel/vulkan/anv_allocator.c | 13 | ||||
-rw-r--r-- | src/intel/vulkan/anv_batch_chain.c | 2 | ||||
-rw-r--r-- | src/intel/vulkan/anv_device.c | 9 | ||||
-rw-r--r-- | src/intel/vulkan/anv_intel.c | 2 | ||||
-rw-r--r-- | src/intel/vulkan/anv_private.h | 11 | ||||
-rw-r--r-- | src/intel/vulkan/anv_queue.c | 5 |
6 files changed, 22 insertions, 20 deletions
diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 53f4c446cb6..a39a1715d53 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -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) diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index 5ff58e87b66..fcd8754ac6c 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -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; } diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 80e37838a50..996705f0988 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -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; diff --git a/src/intel/vulkan/anv_intel.c b/src/intel/vulkan/anv_intel.c index 146fc41d8a8..e68a6897e62 100644 --- a/src/intel/vulkan/anv_intel.c +++ b/src/intel/vulkan/anv_intel.c @@ -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) diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 328b3a85d09..512acb513f8 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -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; diff --git a/src/intel/vulkan/anv_queue.c b/src/intel/vulkan/anv_queue.c index 67b402a2654..5aa0f100900 100644 --- a/src/intel/vulkan/anv_queue.c +++ b/src/intel/vulkan/anv_queue.c @@ -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; |