anv: Move device memory maps back to anv_device_memory

This effectively partially reverts 13fe43714c ("anv: Add helpers in
anv_allocator for mapping BOs") where we both added helpers and reworked
memory mapping to stash the maps on the BO.  The problem comes with
external memory.  Due to GEM rules, if a memory object is exported and
then imported or imported twice,  we have to deduplicate the anv_bo
struct but, according to Vulkan rules, they are separate VkDeviceMemory
objects.  This means we either need to always map whole objects and
reference-count the map or we need to handle maps separately for
separate VkDeviceMemory objects.  For now, take the later path.

Fixes: 13fe43714c ("anv: Add helpers in anv_allocator for mapping BOs")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5612
Reviewed-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13795>
This commit is contained in:
Jason Ekstrand
2021-11-15 11:32:38 -06:00
committed by Marge Bot
parent 32c0c5fcd9
commit e6b4678fdb
3 changed files with 29 additions and 25 deletions
+6 -12
View File
@@ -1606,7 +1606,7 @@ anv_bo_finish(struct anv_device *device, struct anv_bo *bo)
anv_vma_free(device, bo->offset, bo->size + bo->_ccs_size);
if (bo->map && !bo->from_host_ptr)
anv_device_unmap_bo(device, bo);
anv_device_unmap_bo(device, bo, bo->map, bo->size);
assert(bo->gem_handle != 0);
anv_gem_close(device, bo->gem_handle);
@@ -1717,7 +1717,8 @@ anv_device_alloc_bo(struct anv_device *device,
};
if (alloc_flags & ANV_BO_ALLOC_MAPPED) {
VkResult result = anv_device_map_bo(device, &new_bo, 0, size, 0, NULL);
VkResult result = anv_device_map_bo(device, &new_bo, 0, size,
0 /* gem_flags */, &new_bo.map);
if (unlikely(result != VK_SUCCESS)) {
anv_gem_close(device, new_bo.gem_handle);
return result;
@@ -1785,7 +1786,6 @@ anv_device_map_bo(struct anv_device *device,
{
assert(!bo->is_wrapper && !bo->from_host_ptr);
assert(size > 0);
assert(bo->map == NULL && bo->map_size == 0);
void *map = anv_gem_mmap(device, bo->gem_handle, offset, size, gem_flags);
if (unlikely(map == MAP_FAILED))
@@ -1793,9 +1793,6 @@ anv_device_map_bo(struct anv_device *device,
assert(map != NULL);
bo->map = map;
bo->map_size = size;
if (map_out)
*map_out = map;
@@ -1804,15 +1801,12 @@ anv_device_map_bo(struct anv_device *device,
void
anv_device_unmap_bo(struct anv_device *device,
struct anv_bo *bo)
struct anv_bo *bo,
void *map, size_t map_size)
{
assert(!bo->is_wrapper && !bo->from_host_ptr);
assert(bo->map != NULL && bo->map_size > 0);
anv_gem_munmap(device, bo->map, bo->map_size);
bo->map = NULL;
bo->map_size = 0;
anv_gem_munmap(device, map, map_size);
}
VkResult