MR 289: layers: Change the test about "too many images".
authorIan Elliott <ianelliott@google.com>
Wed, 6 Apr 2016 20:29:56 +0000 (14:29 -0600)
committerIan Elliott <ianelliott@google.com>
Thu, 7 Apr 2016 15:08:37 +0000 (09:08 -0600)
Given new spec language coming out in early April (clarifying various aspects
of acquiring presentable images), a change was needed to the WSI-swapchain
validation layer.  The new validate-layer test will work for "BlitModel"
drivers that advertise a minImageCount of 1.  Failing the test now results in
an error instead of a performance warning.

layers/swapchain.cpp
layers/swapchain.h
layers/vk_validation_layer_details.md

index c456352..34f8ccb 100644 (file)
@@ -1745,31 +1745,36 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(VkDevice de
     if ((semaphore == VK_NULL_HANDLE) && (fence == VK_NULL_HANDLE)) {
         skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice", SWAPCHAIN_NO_SYNC_FOR_ACQUIRE,
                               "%s() called with both the semaphore and fence parameters set to "
-                              "VK_NULL_HANDLE (at least one should be used).", __FUNCTION__);
+                              "VK_NULL_HANDLE (at least one should be used)\n.", __FUNCTION__);
     }
     SwpSwapchain *pSwapchain = &my_data->swapchainMap[swapchain];
-    if (pSwapchain) {
-        // Look to see if the application is trying to own too many images at
-        // the same time (i.e. not leave any to display):
-        uint32_t imagesOwnedByApp = 0;
+    SwpPhysicalDevice *pPhysicalDevice = pDevice->pPhysicalDevice;
+    if (pSwapchain && pPhysicalDevice && pPhysicalDevice->gotSurfaceCapabilities) {
+        // Look to see if the application has already acquired the maximum
+        // number of images, and this will push it past the spec-defined
+        // limits:
+        uint32_t minImageCount = pPhysicalDevice->surfaceCapabilities.minImageCount;
+        uint32_t imagesAcquiredByApp = 0;
         for (uint32_t i = 0; i < pSwapchain->imageCount; i++) {
             if (pSwapchain->images[i].ownedByApp) {
-                imagesOwnedByApp++;
+                imagesAcquiredByApp++;
             }
         }
-        if (imagesOwnedByApp >= (pSwapchain->imageCount - 1)) {
-            skipCall |= LOG_PERF_WARNING(VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, swapchain, "VkSwapchainKHR",
-                                         SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES, "%s() called when the application "
-                                                                             "already owns all presentable images "
-                                                                             "in this swapchain except for the "
-                                                                             "image currently being displayed.  "
-                                                                             "This call to %s() cannot succeed "
-                                                                             "unless another thread calls the "
-                                                                             "vkQueuePresentKHR() function in "
-                                                                             "order to release ownership of one of "
-                                                                             "the presentable images of this "
-                                                                             "swapchain.",
-                                         __FUNCTION__, __FUNCTION__);
+        if (imagesAcquiredByApp > (pSwapchain->imageCount - minImageCount)) {
+            skipCall |= LOG_ERROR(
+                VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT,
+                swapchain, "VkSwapchainKHR",
+                SWAPCHAIN_APP_ACQUIRES_TOO_MANY_IMAGES,
+                "%s() called when it cannot succeed.  The application has "
+                "acquired %d image(s) that have not yet been presented.  The "
+                "maximum number of images that the application can "
+                "simultaneously acquire from this swapchain (including this "
+                "call to %s()) is %d.  That value is derived by subtracting "
+                "VkSurfaceCapabilitiesKHR::minImageCount (%d) from the number "
+                "of images in the swapchain (%d) and adding 1.\n",
+                __FUNCTION__, imagesAcquiredByApp, __FUNCTION__,
+                (pSwapchain->imageCount - minImageCount + 1),
+                minImageCount, pSwapchain->imageCount);
         }
     }
     if (!pImageIndex) {
index e6c1f4a..56458f6 100644 (file)
@@ -64,7 +64,7 @@ typedef enum _SWAPCHAIN_ERROR {
     SWAPCHAIN_CREATE_SWAP_DIFF_SURFACE, // Called vkCreateSwapchainKHR() with pCreateInfo->oldSwapchain that has a different surface
                                         // than pCreateInfo->surface
     SWAPCHAIN_DESTROY_SWAP_DIFF_DEVICE, // Called vkDestroySwapchainKHR() with a different VkDevice than vkCreateSwapchainKHR()
-    SWAPCHAIN_APP_OWNS_TOO_MANY_IMAGES, // vkAcquireNextImageKHR() asked for more images than are available
+    SWAPCHAIN_APP_ACQUIRES_TOO_MANY_IMAGES, // vkAcquireNextImageKHR() asked for more images than are available
     SWAPCHAIN_INDEX_TOO_LARGE,          // Index is too large for swapchain
     SWAPCHAIN_INDEX_NOT_IN_USE,         // vkQueuePresentKHR() given index that is not owned by app
     SWAPCHAIN_BAD_BOOL,                 // VkBool32 that doesn't have value of VK_TRUE or VK_FALSE (e.g. is a non-zero form of true)
index d4c4661..19623e5 100644 (file)
@@ -378,7 +378,7 @@ This layer is a work in progress. VK_LAYER_LUNARG_swapchain layer is intended to
 | vkCreateSwapchainKHR(pCreateInfo->imageSharingMode) | Validates vkCreateSwapchainKHR(pCreateInfo->imageSharingMode) | CREATE_SWAP_BAD_SHARING_VALUES | vkCreateSwapchainKHR | NA | None |
 | vkCreateSwapchainKHR(pCreateInfo->oldSwapchain and pCreateInfo->surface) | pCreateInfo->surface must match pCreateInfo->oldSwapchain's surface | CREATE_SWAP_DIFF_SURFACE | vkCreateSwapchainKHR | NA | None |
 | Use same device for swapchain | Validates that vkDestroySwapchainKHR() called with the same VkDevice as vkCreateSwapchainKHR() | DESTROY_SWAP_DIFF_DEVICE | vkCreateSwapchainKHR vkDestroySwapchainKHR | NA | None |
-| Don't use too many images | Validates that app never tries to own too many swapchain images at a time | APP_OWNS_TOO_MANY_IMAGES | vkAcquireNextImageKHR | NA | None |
+| Don't acquire too many images | Validates that app never tries to acquire too many swapchain images at a time | APP_ACQUIRES_TOO_MANY_IMAGES | vkAcquireNextImageKHR | NA | None |
 | Index too large | Validates that an image index is within the number of images in a swapchain | INDEX_TOO_LARGE | vkQueuePresentKHR | NA | None |
 | Can't present a non-owned image | Validates that application only presents images that it owns | INDEX_NOT_IN_USE | vkQueuePresentKHR | NA | None |
 | A VkBool32 must have values of VK_TRUE or VK_FALSE | Validates that a VkBool32 must have values of VK_TRUE or VK_FALSE | BAD_BOOL | vkCreateSwapchainKHR | NA | None |