From f986a604519af16e54e12bdad585f874e71e0481 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Wed, 11 Mar 2020 12:56:34 +0100 Subject: [PATCH] v3dv: drop assert for map of a mapped buffer This triggers when dumping CLIF because the dump process involves internally mapping all the BOs. We could unmap them there after we are done, but there is really no reason why we need to assert on this, so let's just keep things simple and unmap. If the user is really double mapping, that should be caught by the validation layers. Part-of: --- src/broadcom/vulkan/v3dv_device.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index 12033618b6d..f8bff270ed4 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -1250,18 +1250,34 @@ device_free(struct v3dv_device *device, struct v3dv_device_memory *mem) v3dv_bo_free(device, mem->bo); } +static void +device_unmap(struct v3dv_device *device, struct v3dv_device_memory *mem) +{ + assert(mem && mem->bo->map && mem->bo->map_size > 0); + v3dv_bo_unmap(device, mem->bo); +} + static VkResult device_map(struct v3dv_device *device, struct v3dv_device_memory *mem, uint32_t size) { + assert(mem && mem->bo); + /* From the spec: * * "After a successful call to vkMapMemory the memory object memory is * considered to be currently host mapped. It is an application error to * call vkMapMemory on a memory object that is already host mapped." + * + * We are not concerned with this ourselves (validation layers should + * catch these errors and warn users), however, the driver may internally + * map things (for example for debug CLIF dumps) so by the time the user + * call here the buffer might already been mapped internally, so let's just + * make sure we unmap if needed. */ - assert(mem && mem->bo->map == NULL); + if (mem->bo->map) + device_unmap(device, mem); bool ok = v3dv_bo_map(device, mem->bo, size); if (!ok) @@ -1270,13 +1286,6 @@ device_map(struct v3dv_device *device, return VK_SUCCESS; } -static void -device_unmap(struct v3dv_device *device, struct v3dv_device_memory *mem) -{ - assert(mem && mem->bo->map && mem->bo->map_size > 0); - v3dv_bo_unmap(device, mem->bo); -} - static VkResult device_import_bo(struct v3dv_device *device, const VkAllocationCallbacks *pAllocator,