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,