Swapchain: Start keeping better track of surface-queueFamilyIndices.
authorIan Elliott <ianelliott@google.com>
Wed, 20 Jan 2016 15:52:08 +0000 (08:52 -0700)
committerJon Ashburn <jon@lunarg.com>
Thu, 28 Jan 2016 18:18:40 +0000 (11:18 -0700)
layers/swapchain.cpp
layers/swapchain.h
layers/vk_validation_layer_details.md

index 841105f..ea9d8be 100644 (file)
@@ -488,11 +488,6 @@ VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentatio
         // Call down the call chain:
         result = my_data->instance_dispatch_table->GetPhysicalDeviceMirPresentationSupportKHR(
                 physicalDevice, queueFamilyIndex, connection);
-
-        if (pPhysicalDevice) {
-            // Record the result of this query:
-            pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
-        }
     }
     return result;
 }
@@ -572,11 +567,6 @@ VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresent
         // Call down the call chain:
         result = my_data->instance_dispatch_table->GetPhysicalDeviceWaylandPresentationSupportKHR(
                 physicalDevice, queueFamilyIndex, display);
-
-        if (pPhysicalDevice) {
-            // Record the result of this query:
-            pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
-        }
     }
     return result;
 }
@@ -655,11 +645,6 @@ VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32Presentat
         // Call down the call chain:
         result = my_data->instance_dispatch_table->GetPhysicalDeviceWin32PresentationSupportKHR(
                 physicalDevice, queueFamilyIndex);
-
-        if (pPhysicalDevice) {
-            // Record the result of this query:
-            pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
-        }
     }
     return result;
 }
@@ -740,11 +725,6 @@ VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentatio
         // Call down the call chain:
         result = my_data->instance_dispatch_table->GetPhysicalDeviceXcbPresentationSupportKHR(
                 physicalDevice, queueFamilyIndex, connection, visual_id);
-
-        if (pPhysicalDevice) {
-            // Record the result of this query:
-            pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
-        }
     }
     return result;
 }
@@ -825,11 +805,6 @@ VK_LAYER_EXPORT VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentati
         // Call down the call chain:
         result = my_data->instance_dispatch_table->GetPhysicalDeviceXlibPresentationSupportKHR(
                 physicalDevice, queueFamilyIndex, dpy, visualID);
-
-        if (pPhysicalDevice) {
-            // Record the result of this query:
-            pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] = result;
-        }
     }
     return result;
 }
@@ -999,7 +974,9 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupport
         if ((result == VK_SUCCESS) && pSupported && pPhysicalDevice) {
             // Record the result of this query:
             pPhysicalDevice->queueFamilyIndexSupport[queueFamilyIndex] =
-                *pSupported;
+                surface;
+            pPhysicalDevice->surfaceSupport[surface] =
+                queueFamilyIndex;
             // TODO: We need to compare this with the actual queue used for
             // presentation, to ensure it was advertised to the application as
             // supported for presentation.
@@ -1249,6 +1226,20 @@ static VkBool32 validateCreateSwapchainKHR(
                               "vkGetPhysicalDeviceSurfaceCapabilitiesKHR().",
                               fn);
     } else if (pCreateInfo) {
+        // Validate pCreateInfo->surface to make sure that
+        // vkGetPhysicalDeviceSurfaceSupportKHR() reported this as a supported
+        // surface:
+        uint32_t queueFamilyIndex = pPhysicalDevice->surfaceSupport[pCreateInfo->surface];
+        if (!queueFamilyIndex) {
+            skipCall |= LOG_ERROR(VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, device, "VkDevice",
+                                  SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE,
+                                  "%s() called with pCreateInfo->surface that "
+                                  "was not returned by "
+                                  "vkGetPhysicalDeviceSurfaceSupportKHR() "
+                                  "for the device.",
+                                  fn);
+        }
+
         // Validate pCreateInfo->minImageCount against
         // VkSurfaceCapabilitiesKHR::{min|max}ImageCount:
         VkSurfaceCapabilitiesKHR *pCapabilities = &pPhysicalDevice->surfaceCapabilities;
index 7076697..3508cbe 100644 (file)
@@ -64,6 +64,7 @@ typedef enum _SWAPCHAIN_ERROR
     SWAPCHAIN_NULL_POINTER,                     // Pointer set to NULL, instead of being a valid pointer
     SWAPCHAIN_EXT_NOT_ENABLED_BUT_USED,         // Did not enable WSI extension, but called WSI function 
     SWAPCHAIN_DEL_DEVICE_BEFORE_SWAPCHAINS,     // Called vkDestroyDevice() before vkDestroySwapchainKHR()
+    SWAPCHAIN_CREATE_UNSUPPORTED_SURFACE,       // Called vkCreateSwapchainKHR() with a pCreateInfo->surface that wasn't seen as supported by vkGetPhysicalDeviceSurfaceSupportKHR for the device
     SWAPCHAIN_CREATE_SWAP_WITHOUT_QUERY,        // Called vkCreateSwapchainKHR() without calling a query (e.g. vkGetPhysicalDeviceSurfaceCapabilitiesKHR())
     SWAPCHAIN_CREATE_SWAP_BAD_MIN_IMG_COUNT,    // Called vkCreateSwapchainKHR() with out-of-bounds minImageCount
     SWAPCHAIN_CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS,// Called vkCreateSwapchainKHR() with out-of-bounds imageExtent
@@ -214,8 +215,13 @@ struct _SwpPhysicalDevice {
     // VkInstance that this VkPhysicalDevice is associated with:
     SwpInstance *pInstance;
 
-    // Which queueFamilyIndices support presenting with WSI swapchains:
-    unordered_map<uint32_t, VkBool32> queueFamilyIndexSupport;
+    // Record all supported queueFamilyIndex-surface pairs that support
+    // presenting with WSI swapchains:
+    unordered_map<uint32_t, VkSurfaceKHR> queueFamilyIndexSupport;
+
+    // Record all supported surface-queueFamilyIndex pairs that support
+    // presenting with WSI swapchains:
+    unordered_map<VkSurfaceKHR, uint32_t> surfaceSupport;
 
 // TODO: Record/use this info per-surface, not per-device, once a
 // non-dispatchable surface object is added to WSI:
index ce002ad..c09ff33 100644 (file)
@@ -348,6 +348,7 @@ This layer is a work in progress. VK_LAYER_LUNARG_swapchain layer is intended to
 | Valid pointer | If a NULL pointer is used, this error will be flagged | NULL_POINTER | vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfacePresentModesKHR vkCreateSwapchainKHR vkGetSwapchainImagesKHR vkAcquireNextImageKHR vkQueuePresentKHR | NA | None |
 | Extension enabled before use | Validates that a WSI extension is enabled before its functions are used | EXT_NOT_ENABLED_BUT_USED | vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfacePresentModesKHR vkCreateSwapchainKHR vkDestroySwapchainKHR vkGetSwapchainImagesKHR vkAcquireNextImageKHR vkQueuePresentKHR | NA | None |
 | Swapchains destroyed before devices | Validates that  vkDestroySwapchainKHR() is called for all swapchains associated with a device before vkDestroyDevice() is called | DEL_DEVICE_BEFORE_SWAPCHAINS | vkDestroyDevice | NA | None |
+| Supported surface used with a swapchain | Validates that vkGetPhysicalDeviceSurfaceSupportKHR() was seen to support the surface used with a swapchain | CREATE_SWAP_UNSUPPORTED_SURFACE | vkCreateSwapchainKHR | NA | None |
 | Queries occur before swapchain creation | Validates that vkGetPhysicalDeviceSurfaceCapabilitiesKHR(), vkGetPhysicalDeviceSurfaceFormatsKHR() and vkGetPhysicalDeviceSurfacePresentModesKHR() are called before vkCreateSwapchainKHR() | CREATE_SWAP_WITHOUT_QUERY | vkCreateSwapchainKHR | NA | None |
 | vkCreateSwapchainKHR(pCreateInfo->minImageCount) | Validates vkCreateSwapchainKHR(pCreateInfo->minImageCount) | CREATE_SWAP_BAD_MIN_IMG_COUNT | vkCreateSwapchainKHR | NA | None |
 | vkCreateSwapchainKHR(pCreateInfo->imageExtent) | Validates vkCreateSwapchainKHR(pCreateInfo->imageExtent) when window has no fixed size | CREATE_SWAP_OUT_OF_BOUNDS_EXTENTS | vkCreateSwapchainKHR | NA | None |