aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Schultz <karl@lunarg.com>2016-11-11 16:09:47 -0700
committerKarl Schultz <karl@lunarg.com>2016-11-14 16:45:30 -0700
commit0e52ea6371179dfa8854ecbf6460fea2bd3b0f5b (patch)
tree0a19112768f2080f59e46ebbcbb1814da6b6393c
parentb4b15c89e0c303bb50af95b6bb2ef135fc9ee789 (diff)
downloadusermoji-0e52ea6371179dfa8854ecbf6460fea2bd3b0f5b.tar.xz
layers: gh125 Add check for memory obj max count
Fixes #125 Change-Id: I1b0b4eb2894494dc6df9c8dd1beab6f3645a707c
-rw-r--r--layers/core_validation.cpp36
-rw-r--r--layers/vk_validation_error_database.txt2
2 files changed, 30 insertions, 8 deletions
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<const uint64_t &>(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<std::mutex> 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<std::mutex> 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;
}
diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt
index 68b99ff3..2ba8152a 100644
--- a/layers/vk_validation_error_database.txt
+++ b/layers/vk_validation_error_database.txt
@@ -601,7 +601,7 @@ VALIDATION_ERROR_00607~^~U~^~Unknown~^~vkCmdBindPipeline~^~For more information
VALIDATION_ERROR_00608~^~U~^~Unknown~^~vkCmdBindPipeline~^~For more information refer to Vulkan Spec Section '10.1. Host Memory' which states 'If either of pfnInternalAllocation or pfnInternalFree is not NULL, both must be valid callbacks' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#VkAllocationCallbacks)~^~
VALIDATION_ERROR_00609~^~Y~^~Unknown~^~vkGetPhysicalDeviceMemoryProperties~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'physicalDevice must be a valid VkPhysicalDevice handle' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkGetPhysicalDeviceMemoryProperties)~^~
VALIDATION_ERROR_00610~^~U~^~Unknown~^~vkGetPhysicalDeviceMemoryProperties~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'pMemoryProperties must be a pointer to a VkPhysicalDeviceMemoryProperties structure' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkGetPhysicalDeviceMemoryProperties)~^~
-VALIDATION_ERROR_00611~^~U~^~Unknown~^~vkAllocateMemory~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'The number of currently valid memory objects, allocated from device, must be less than VkPhysicalDeviceLimits::maxMemoryAllocationCount' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkAllocateMemory)~^~
+VALIDATION_ERROR_00611~^~Y~^~None~^~vkAllocateMemory~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'The number of currently valid memory objects, allocated from device, must be less than VkPhysicalDeviceLimits::maxMemoryAllocationCount' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkAllocateMemory)~^~Need Device Profile (spoofing) layer to write test.
VALIDATION_ERROR_00612~^~Y~^~Unknown~^~vkAllocateMemory~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'device must be a valid VkDevice handle' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkAllocateMemory)~^~
VALIDATION_ERROR_00613~^~U~^~Unknown~^~vkAllocateMemory~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'pAllocateInfo must be a pointer to a valid VkMemoryAllocateInfo structure' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkAllocateMemory)~^~
VALIDATION_ERROR_00614~^~U~^~Unknown~^~vkAllocateMemory~^~For more information refer to Vulkan Spec Section '10.2. Device Memory' which states 'If pAllocator is not NULL, pAllocator must be a pointer to a valid VkAllocationCallbacks structure' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/xhtml/vkspec.html#vkAllocateMemory)~^~