diff options
author | Jason Ekstrand <jason.ekstrand@intel.com> | 2015-12-17 11:00:38 -0800 |
---|---|---|
committer | Jason Ekstrand <jason.ekstrand@intel.com> | 2015-12-17 11:00:38 -0800 |
commit | b1325404c5931e0ec744b696eb078774f813505d (patch) | |
tree | b0fce742bbdf39b5b94ccb5c9b43b0c25756e4ab /src | |
parent | c643e9cea87b4676e648e431d5c39f2880a1454c (diff) | |
download | external_mesa3d-b1325404c5931e0ec744b696eb078774f813505d.zip external_mesa3d-b1325404c5931e0ec744b696eb078774f813505d.tar.gz external_mesa3d-b1325404c5931e0ec744b696eb078774f813505d.tar.bz2 |
anv/device: Handle zero-sized memory allocations
Diffstat (limited to 'src')
-rw-r--r-- | src/vulkan/anv_device.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index fe44d1c..17056e3 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -1002,6 +1002,12 @@ VkResult anv_AllocateMemory( assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO); + if (pAllocateInfo->allocationSize == 0) { + /* Apparently, this is allowed */ + *pMem = VK_NULL_HANDLE; + return VK_SUCCESS; + } + /* We support exactly one memory heap. */ assert(pAllocateInfo->memoryTypeIndex == 0 || (!device->info.has_llc && pAllocateInfo->memoryTypeIndex < 2)); @@ -1037,6 +1043,9 @@ void anv_FreeMemory( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_device_memory, mem, _mem); + if (mem == NULL) + return; + if (mem->bo.map) anv_gem_munmap(mem->bo.map, mem->bo.size); @@ -1057,6 +1066,11 @@ VkResult anv_MapMemory( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_device_memory, mem, _memory); + if (mem == NULL) { + *ppData = NULL; + return VK_SUCCESS; + } + /* FIXME: Is this supposed to be thread safe? Since vkUnmapMemory() only * takes a VkDeviceMemory pointer, it seems like only one map of the memory * at a time is valid. We could just mmap up front and return an offset @@ -1081,6 +1095,9 @@ void anv_UnmapMemory( { ANV_FROM_HANDLE(anv_device_memory, mem, _memory); + if (mem == NULL) + return; + anv_gem_munmap(mem->map, mem->map_size); } @@ -1207,8 +1224,13 @@ VkResult anv_BindBufferMemory( ANV_FROM_HANDLE(anv_device_memory, mem, _memory); ANV_FROM_HANDLE(anv_buffer, buffer, _buffer); - buffer->bo = &mem->bo; - buffer->offset = memoryOffset; + if (mem) { + buffer->bo = &mem->bo; + buffer->offset = memoryOffset; + } else { + buffer->bo = NULL; + buffer->offset = 0; + } return VK_SUCCESS; } @@ -1222,8 +1244,13 @@ VkResult anv_BindImageMemory( ANV_FROM_HANDLE(anv_device_memory, mem, _memory); ANV_FROM_HANDLE(anv_image, image, _image); - image->bo = &mem->bo; - image->offset = memoryOffset; + if (mem) { + image->bo = &mem->bo; + image->offset = memoryOffset; + } else { + image->bo = NULL; + image->offset = 0; + } return VK_SUCCESS; } |