layers: Don't exceed max allowed color attachments.
authorMichael Lentine <mlentine@google.com>
Wed, 6 Apr 2016 22:40:22 +0000 (17:40 -0500)
committerTobin Ehlis <tobine@google.com>
Thu, 7 Apr 2016 13:36:03 +0000 (07:36 -0600)
layers/device_limits.cpp
layers/device_limits.h
layers/vk_validation_layer_details.md

index ff097b9..44a891b 100644 (file)
@@ -468,6 +468,26 @@ VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, cons
     layer_data_map.erase(key);
 }
 
+VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
+                                                                  const VkAllocationCallbacks *pAllocator,
+                                                                  VkRenderPass *pRenderPass) {
+    layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
+    bool skip_call = false;
+    uint32_t max_color_attachments = dev_data->physicalDeviceProperties.limits.maxColorAttachments;
+    for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
+        if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
+            skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
+                                 reinterpret_cast<uint64_t>(device), __LINE__, DEVLIMITS_INVALID_ATTACHMENT_COUNT, "DL",
+                                 "Cannot create a render pass with %d color attachments. Max is %d.",
+                                 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments);
+        }
+    }
+    if (skip_call) {
+        return VK_ERROR_VALIDATION_FAILED_EXT;
+    }
+    return dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
+}
+
 VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
                                                                    const VkAllocationCallbacks *pAllocator,
                                                                    VkCommandPool *pCommandPool) {
@@ -676,11 +696,13 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkD
         return (PFN_vkVoidFunction)vkDestroyDevice;
     if (!strcmp(funcName, "vkGetDeviceQueue"))
         return (PFN_vkVoidFunction)vkGetDeviceQueue;
-    if (!strcmp(funcName, "CreateCommandPool"))
+    if (!strcmp(funcName, "vkCreateRenderPass"))
+        return (PFN_vkVoidFunction)vkCreateRenderPass;
+    if (!strcmp(funcName, "vkCreateCommandPool"))
         return (PFN_vkVoidFunction)vkCreateCommandPool;
-    if (!strcmp(funcName, "DestroyCommandPool"))
+    if (!strcmp(funcName, "vkDestroyCommandPool"))
         return (PFN_vkVoidFunction)vkDestroyCommandPool;
-    if (!strcmp(funcName, "ResetCommandPool"))
+    if (!strcmp(funcName, "vkResetCommandPool"))
         return (PFN_vkVoidFunction)vkResetCommandPool;
     if (!strcmp(funcName, "vkAllocateCommandBuffers"))
         return (PFN_vkVoidFunction)vkAllocateCommandBuffers;
index c7dfbfe..a55d260 100644 (file)
@@ -36,6 +36,7 @@ typedef enum _DEV_LIMITS_ERROR {
     DEVLIMITS_INVALID_INSTANCE,              // Invalid instance used
     DEVLIMITS_INVALID_PHYSICAL_DEVICE,       // Invalid physical device used
     DEVLIMITS_INVALID_INHERITED_QUERY,       // Invalid use of inherited query
+    DEVLIMITS_INVALID_ATTACHMENT_COUNT,      // Invalid value for the number of attachments
     DEVLIMITS_MUST_QUERY_COUNT,              // Failed to make initial call to an API to query the count
     DEVLIMITS_MUST_QUERY_PROPERTIES,         // Failed to make initial call to an API to query properties
     DEVLIMITS_INVALID_CALL_SEQUENCE,         // Flag generic case of an invalid call sequence by the app
index c5481a8..d4c4661 100644 (file)
@@ -326,6 +326,7 @@ For the second category of errors, VK_LAYER_LUNARG_device_limits stores its own
 | Valid instance | If an invalid instance is used, this error will be flagged | INVALID_INSTANCE | vkEnumeratePhysicalDevices | NA | VK_LAYER_LUNARG_object_tracker should also catch this so if we made sure VK_LAYER_LUNARG_object_tracker was always on top, we could avoid this check |
 | Valid physical device | Enum used for informational messages | INVALID_PHYSICAL_DEVICE | vkEnumeratePhysicalDevices | NA | VK_LAYER_LUNARG_object_tracker should also catch this so if we made sure VK_LAYER_LUNARG_object_tracker was always on top, we could avoid this check |
 | Valid inherited query | If an invalid inherited query is used, this error will be flagged | INVALID_INHERITED_QUERY | vkBeginCommandBuffer | NA | None |
+| Valid attachment count | If the number of attachments exceeds the device max, this error will be flagged | INVALID_ATTACH_COUNT | vkCreateRenderPass | NA | None |
 | Querying array counts | For API calls where an array count should be queried with an initial call and a NULL array pointer, verify that such a call was made before making a call with non-null array pointer. | MUST_QUERY_COUNT | vkEnumeratePhysicalDevices vkGetPhysicalDeviceQueueFamilyProperties | NA | Create focused test |
 | Array count value | For API calls where an array of details is queried, verify that the size of the requested array matches the size of the array supported by the device. | COUNT_MISMATCH | vkEnumeratePhysicalDevices vkGetPhysicalDeviceQueueFamilyProperties | NA | Create focused test |
 | Queue Creation | When creating/requesting queues, make sure that QueueFamilyPropertiesIndex and index/count within that queue family are valid. | INVALID_QUEUE_CREATE_REQUEST | vkGetDeviceQueue vkCreateDevice | NA | Create focused test |