vulkan/wsi/wayland: Handle VK_INCOMPLETE for GetFormats
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 25 Jan 2017 00:43:01 +0000 (16:43 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 25 Jan 2017 17:04:56 +0000 (09:04 -0800)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: "17.0" <mesa-dev@lists.freedesktop.org>
src/vulkan/wsi/wsi_common_wayland.c

index 687ac9c731bd0887487205f0fabfdecbf8ebaf32..d745413c4035539cb9605414ff35883dbbe6732e 100644 (file)
@@ -409,25 +409,27 @@ wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface,
    if (!display)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
-   uint32_t count = u_vector_length(&display->formats);
-
    if (pSurfaceFormats == NULL) {
-      *pSurfaceFormatCount = count;
+      *pSurfaceFormatCount = u_vector_length(&display->formats);
       return VK_SUCCESS;
    }
 
-   assert(*pSurfaceFormatCount >= count);
-   *pSurfaceFormatCount = count;
-
+   uint32_t count = 0;
    VkFormat *f;
    u_vector_foreach(f, &display->formats) {
-      *(pSurfaceFormats++) = (VkSurfaceFormatKHR) {
+      if (count == *pSurfaceFormatCount)
+         return VK_INCOMPLETE;
+
+      pSurfaceFormats[count++] = (VkSurfaceFormatKHR) {
          .format = *f,
          /* TODO: We should get this from the compositor somehow */
          .colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR,
       };
    }
 
+   assert(*pSurfaceFormatCount <= count);
+   *pSurfaceFormatCount = count;
+
    return VK_SUCCESS;
 }