anv: Implement VK_KHR_map_memory2

Reviewed-by: Iván Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22031>
This commit is contained in:
Faith Ekstrand 2023-03-20 17:02:45 -05:00 committed by Marge Bot
parent f4a5b2d59e
commit 92ea49edcb
2 changed files with 22 additions and 15 deletions

View file

@ -1,2 +1,3 @@
VK_EXT_pipeline_library_group_handles on RADV
VK_EXT_image_sliced_view_of_3d on RADV/GFX10+
VK_KHR_map_memory2 on ANV

View file

@ -227,6 +227,7 @@ get_device_extensions(const struct anv_physical_device *device,
.KHR_maintenance2 = true,
.KHR_maintenance3 = true,
.KHR_maintenance4 = true,
.KHR_map_memory2 = true,
.KHR_multiview = true,
.KHR_performance_query =
device->perf &&
@ -3981,8 +3982,13 @@ void anv_FreeMemory(
list_del(&mem->link);
pthread_mutex_unlock(&device->mutex);
if (mem->map)
anv_UnmapMemory(_device, _mem);
if (mem->map) {
const VkMemoryUnmapInfoKHR unmap = {
.sType = VK_STRUCTURE_TYPE_MEMORY_UNMAP_INFO_KHR,
.memory = _mem,
};
anv_UnmapMemory2KHR(_device, &unmap);
}
p_atomic_add(&device->physical->memory.heaps[mem->type->heapIndex].used,
-mem->bo->size);
@ -3997,16 +4003,13 @@ void anv_FreeMemory(
vk_object_free(&device->vk, pAllocator, mem);
}
VkResult anv_MapMemory(
VkResult anv_MapMemory2KHR(
VkDevice _device,
VkDeviceMemory _memory,
VkDeviceSize offset,
VkDeviceSize size,
VkMemoryMapFlags flags,
const VkMemoryMapInfoKHR* pMemoryMapInfo,
void** ppData)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
ANV_FROM_HANDLE(anv_device_memory, mem, pMemoryMapInfo->memory);
if (mem == NULL) {
*ppData = NULL;
@ -4014,7 +4017,7 @@ VkResult anv_MapMemory(
}
if (mem->host_ptr) {
*ppData = mem->host_ptr + offset;
*ppData = mem->host_ptr + pMemoryMapInfo->offset;
return VK_SUCCESS;
}
@ -4028,8 +4031,9 @@ VkResult anv_MapMemory(
"Memory object not mappable.");
}
if (size == VK_WHOLE_SIZE)
size = mem->size - offset;
const VkDeviceSize offset = pMemoryMapInfo->offset;
const VkDeviceSize size = pMemoryMapInfo->size == VK_WHOLE_SIZE ?
mem->size - offset : pMemoryMapInfo->size;
/* From the Vulkan spec version 1.0.32 docs for MapMemory:
*
@ -4083,21 +4087,23 @@ VkResult anv_MapMemory(
return VK_SUCCESS;
}
void anv_UnmapMemory(
VkResult anv_UnmapMemory2KHR(
VkDevice _device,
VkDeviceMemory _memory)
const VkMemoryUnmapInfoKHR* pMemoryUnmapInfo)
{
ANV_FROM_HANDLE(anv_device, device, _device);
ANV_FROM_HANDLE(anv_device_memory, mem, _memory);
ANV_FROM_HANDLE(anv_device_memory, mem, pMemoryUnmapInfo->memory);
if (mem == NULL || mem->host_ptr)
return;
return VK_SUCCESS;
anv_device_unmap_bo(device, mem->bo, mem->map, mem->map_size);
mem->map = NULL;
mem->map_size = 0;
mem->map_delta = 0;
return VK_SUCCESS;
}
VkResult anv_FlushMappedMemoryRanges(