From 0e52ea6371179dfa8854ecbf6460fea2bd3b0f5b Mon Sep 17 00:00:00 2001 From: Karl Schultz Date: Fri, 11 Nov 2016 16:09:47 -0700 Subject: layers: gh125 Add check for memory obj max count Fixes #125 Change-Id: I1b0b4eb2894494dc6df9c8dd1beab6f3645a707c --- layers/core_validation.cpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'layers/core_validation.cpp') diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 1ecacd52..3073e056 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -5079,15 +5079,37 @@ QueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits, V return result; } +static bool PreCallValidateAllocateMemory(layer_data *dev_data) { + bool skip = false; + if (dev_data->memObjMap.size() >= dev_data->phys_dev_properties.properties.limits.maxMemoryAllocationCount) { + skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, + reinterpret_cast(dev_data->device), __LINE__, VALIDATION_ERROR_00611, "MEM", + "Number of currently valid memory objects is not less than the maximum allowed (%u). %s", + dev_data->phys_dev_properties.properties.limits.maxMemoryAllocationCount, + validation_error_map[VALIDATION_ERROR_00611]); + } + return skip; +} + +static void PostCallRecordAllocateMemory(layer_data *dev_data, const VkMemoryAllocateInfo *pAllocateInfo, VkDeviceMemory *pMemory) { + add_mem_obj_info(dev_data, dev_data->device, *pMemory, pAllocateInfo); + print_mem_list(dev_data); + return; +} + VKAPI_ATTR VkResult VKAPI_CALL AllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory) { - layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); - VkResult result = my_data->dispatch_table.AllocateMemory(device, pAllocateInfo, pAllocator, pMemory); - if (result == VK_SUCCESS) { - // TODO : Track allocations and overall size here - std::lock_guard lock(global_lock); - add_mem_obj_info(my_data, device, *pMemory, pAllocateInfo); - print_mem_list(my_data); + VkResult result = VK_ERROR_VALIDATION_FAILED_EXT; + layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); + std::unique_lock lock(global_lock); + bool skip = PreCallValidateAllocateMemory(dev_data); + if (!skip) { + lock.unlock(); + result = dev_data->dispatch_table.AllocateMemory(device, pAllocateInfo, pAllocator, pMemory); + lock.lock(); + if (VK_SUCCESS == result) { + PostCallRecordAllocateMemory(dev_data, pAllocateInfo, pMemory); + } } return result; } -- cgit v1.2.3