diff options
author | Jason Ekstrand <[email protected]> | 2018-05-30 15:34:25 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-06-01 14:27:10 -0700 |
commit | b0d50247a7049350ef30adcefc609039ce86beee (patch) | |
tree | 327a448861a4dfe10aca0ee31d2984544666481e /src/intel/vulkan/anv_allocator.c | |
parent | 27cc68d9e90c8d2031383fa6dc28fe910a351eb6 (diff) |
anv/allocator: Set the BO flags in bo_cache_alloc/import
It's safer to set them there because we have the opportunity to properly
handle combining flags if a BO is imported more than once.
Reviewed-by: Scott D Phillips <[email protected]>
Diffstat (limited to 'src/intel/vulkan/anv_allocator.c')
-rw-r--r-- | src/intel/vulkan/anv_allocator.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index a597280930a..697da5f8c1a 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -1237,11 +1237,19 @@ anv_bo_cache_lookup(struct anv_bo_cache *cache, uint32_t gem_handle) return bo ? &bo->bo : NULL; } +#define ANV_BO_CACHE_SUPPORTED_FLAGS \ + (EXEC_OBJECT_WRITE | \ + EXEC_OBJECT_ASYNC | \ + EXEC_OBJECT_SUPPORTS_48B_ADDRESS) + VkResult anv_bo_cache_alloc(struct anv_device *device, struct anv_bo_cache *cache, - uint64_t size, struct anv_bo **bo_out) + uint64_t size, uint64_t bo_flags, + struct anv_bo **bo_out) { + assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS)); + struct anv_cached_bo *bo = vk_alloc(&device->alloc, sizeof(struct anv_cached_bo), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); @@ -1259,6 +1267,8 @@ anv_bo_cache_alloc(struct anv_device *device, return result; } + bo->bo.flags = bo_flags; + assert(bo->bo.gem_handle); pthread_mutex_lock(&cache->mutex); @@ -1276,8 +1286,11 @@ anv_bo_cache_alloc(struct anv_device *device, VkResult anv_bo_cache_import(struct anv_device *device, struct anv_bo_cache *cache, - int fd, struct anv_bo **bo_out) + int fd, uint64_t bo_flags, + struct anv_bo **bo_out) { + assert(bo_flags == (bo_flags & ANV_BO_CACHE_SUPPORTED_FLAGS)); + pthread_mutex_lock(&cache->mutex); uint32_t gem_handle = anv_gem_fd_to_handle(device, fd); @@ -1288,6 +1301,18 @@ anv_bo_cache_import(struct anv_device *device, struct anv_cached_bo *bo = anv_bo_cache_lookup_locked(cache, gem_handle); if (bo) { + /* We have to be careful how we combine flags so that it makes sense. + * Really, though, if we get to this case and it actually matters, the + * client has imported a BO twice in different ways and they get what + * they have coming. + */ + uint64_t new_flags = 0; + new_flags |= (bo->bo.flags | bo_flags) & EXEC_OBJECT_WRITE; + new_flags |= (bo->bo.flags & bo_flags) & EXEC_OBJECT_ASYNC; + new_flags |= (bo->bo.flags & bo_flags) & EXEC_OBJECT_SUPPORTS_48B_ADDRESS; + + bo->bo.flags = new_flags; + __sync_fetch_and_add(&bo->refcount, 1); } else { off_t size = lseek(fd, 0, SEEK_END); @@ -1308,6 +1333,7 @@ anv_bo_cache_import(struct anv_device *device, bo->refcount = 1; anv_bo_init(&bo->bo, gem_handle, size); + bo->bo.flags = bo_flags; _mesa_hash_table_insert(cache->bo_map, (void *)(uintptr_t)gem_handle, bo); } |