Module: Mesa Branch: main Commit: f25043feb44ed312cc6e6d9fdfdc3857440cc5dc URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=f25043feb44ed312cc6e6d9fdfdc3857440cc5dc
Author: José Roberto de Souza <jose.so...@intel.com> Date: Mon Nov 6 12:55:24 2023 -0800 anv: Remove anv_bo flags that can be inferred from alloc_flags Now that alloc_flags is stored in anv_bo we can get rid of is_external, has_fixed_address and has_client_visible_address flags that can be inferred from alloc_flags. Signed-off-by: José Roberto de Souza <jose.so...@intel.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwer...@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26099> --- src/intel/vulkan/anv_allocator.c | 23 +++++++---------------- src/intel/vulkan/anv_descriptor_set.c | 2 +- src/intel/vulkan/anv_device.c | 4 ++-- src/intel/vulkan/anv_private.h | 17 +++++++---------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 7e15cbe1c38..469955fe81d 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -1360,7 +1360,7 @@ anv_bo_unmap_close(struct anv_device *device, struct anv_bo *bo) static void anv_bo_vma_free(struct anv_device *device, struct anv_bo *bo) { - if (bo->offset != 0 && !bo->has_fixed_address) { + if (bo->offset != 0 && !(bo->alloc_flags & ANV_BO_ALLOC_FIXED_ADDRESS)) { assert(bo->vma_heap != NULL); anv_vma_free(device, bo->vma_heap, bo->offset, bo->size); } @@ -1408,7 +1408,6 @@ anv_bo_vma_alloc_or_close(struct anv_device *device, align = MAX2(2 * 1024 * 1024, align); if (alloc_flags & ANV_BO_ALLOC_FIXED_ADDRESS) { - bo->has_fixed_address = true; bo->offset = intel_canonical_address(explicit_address); } else { bo->offset = anv_vma_alloc(device, bo->size, align, alloc_flags, @@ -1514,9 +1513,6 @@ anv_device_alloc_bo(struct anv_device *device, .actual_size = actual_size, .flags = bo_flags, .alloc_flags = alloc_flags, - .is_external = (alloc_flags & ANV_BO_ALLOC_EXTERNAL), - .has_client_visible_address = - (alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0, .vram_only = nregions == 1 && regions[0] == device->physical->vram_non_mappable.region, }; @@ -1597,6 +1593,7 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device, ANV_BO_ALLOC_SNOOPED | ANV_BO_ALLOC_DEDICATED | ANV_BO_ALLOC_FIXED_ADDRESS))); + assert(alloc_flags & ANV_BO_ALLOC_EXTERNAL); struct anv_bo_cache *cache = &device->bo_cache; const uint32_t bo_flags = @@ -1632,8 +1629,8 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device, "same host pointer imported two different ways"); } - if (bo->has_client_visible_address != - ((alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0)) { + if ((bo->alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != + (alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS)) { pthread_mutex_unlock(&cache->mutex); return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported with and without buffer " @@ -1661,10 +1658,7 @@ anv_device_import_bo_from_host_ptr(struct anv_device *device, .map = host_ptr, .flags = bo_flags, .alloc_flags = alloc_flags, - .is_external = true, .from_host_ptr = true, - .has_client_visible_address = - (alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0, }; VkResult result = anv_bo_vma_alloc_or_close(device, &new_bo, @@ -1725,8 +1719,8 @@ anv_device_import_bo(struct anv_device *device, } if (bo->refcount > 0) { - if (bo->has_client_visible_address != - ((alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0)) { + if ((bo->alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != + (alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS)) { pthread_mutex_unlock(&cache->mutex); return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, "The same BO was imported with and without buffer " @@ -1749,10 +1743,7 @@ anv_device_import_bo(struct anv_device *device, .gem_handle = gem_handle, .refcount = 1, .offset = -1, - .is_external = true, .alloc_flags = alloc_flags, - .has_client_visible_address = - (alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0, }; off_t size = lseek(fd, 0, SEEK_END); @@ -1799,7 +1790,7 @@ anv_device_export_bo(struct anv_device *device, * to export it. This is done based on external options passed into * anv_AllocateMemory. */ - assert(bo->is_external); + assert(anv_bo_is_external(bo)); int fd = anv_gem_handle_to_fd(device, bo->gem_handle); if (fd < 0) diff --git a/src/intel/vulkan/anv_descriptor_set.c b/src/intel/vulkan/anv_descriptor_set.c index 9b768cce5c6..1fb0ddac75e 100644 --- a/src/intel/vulkan/anv_descriptor_set.c +++ b/src/intel/vulkan/anv_descriptor_set.c @@ -1984,7 +1984,7 @@ anv_descriptor_set_write_buffer(struct anv_device *device, isl_buffer_fill_state(&device->isl_dev, desc_map, .address = anv_address_physical(bind_addr), .mocs = isl_mocs(&device->isl_dev, usage, - bind_addr.bo && bind_addr.bo->is_external), + bind_addr.bo && anv_bo_is_external(bind_addr.bo)), .size_B = desc->bind_range, .format = format, .swizzle = ISL_SWIZZLE_IDENTITY, diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 16b39f26e85..085dad1cc9f 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -4731,7 +4731,7 @@ uint64_t anv_GetDeviceMemoryOpaqueCaptureAddress( { ANV_FROM_HANDLE(anv_device_memory, memory, pInfo->memory); - assert(memory->bo->has_client_visible_address); + assert(memory->bo->alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS); return intel_48b_address(memory->bo->offset); } @@ -4748,7 +4748,7 @@ anv_fill_buffer_surface_state(struct anv_device *device, isl_buffer_fill_state(&device->isl_dev, surface_state_ptr, .address = anv_address_physical(address), .mocs = isl_mocs(&device->isl_dev, usage, - address.bo && address.bo->is_external), + address.bo && anv_bo_is_external(address.bo)), .size_B = range, .format = format, .swizzle = swizzle, diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index d8851ad7f6d..35925ca989a 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -457,22 +457,19 @@ struct anv_bo { enum anv_bo_alloc_flags alloc_flags; - /** True if this BO may be shared with other processes */ - bool is_external:1; - - /** See also ANV_BO_ALLOC_FIXED_ADDRESS */ - bool has_fixed_address:1; - /** True if this BO wraps a host pointer */ bool from_host_ptr:1; - /** See also ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS */ - bool has_client_visible_address:1; - /** True if this BO can only live in VRAM */ bool vram_only:1; }; +static inline bool +anv_bo_is_external(const struct anv_bo *bo) +{ + return bo->alloc_flags & ANV_BO_ALLOC_EXTERNAL; +} + static inline struct anv_bo * anv_bo_ref(struct anv_bo *bo) { @@ -1783,7 +1780,7 @@ anv_mocs(const struct anv_device *device, const struct anv_bo *bo, isl_surf_usage_flags_t usage) { - return isl_mocs(&device->isl_dev, usage, bo && bo->is_external); + return isl_mocs(&device->isl_dev, usage, bo && anv_bo_is_external(bo)); } static inline uint32_t