libvulkan: Fix count returned for incomplete wsi queries
When vkGetPhysicalDeviceSurfaceFormatsKHR,
vkGetPhysicalDevicePresentModesKHR, and vkGetSwapchainImagesKHR
returned VK_INCOMPLETE, they would overwrite the count parameter with
the number of available items, rather than the number of returned
items.
Change-Id: I6a736770f90b95ad15bfcfbe5afb4d2886817dcb
Fixes: 31490492
Test: https://gerrit.khronos.org/#/c/158/
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index adc7d5c..63c597c 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -361,9 +361,11 @@
if (formats) {
if (*count < kNumFormats)
result = VK_INCOMPLETE;
- std::copy(kFormats, kFormats + std::min(*count, kNumFormats), formats);
+ *count = std::min(*count, kNumFormats);
+ std::copy(kFormats, kFormats + *count, formats);
+ } else {
+ *count = kNumFormats;
}
- *count = kNumFormats;
return result;
}
@@ -381,9 +383,11 @@
if (modes) {
if (*count < kNumModes)
result = VK_INCOMPLETE;
- std::copy(kModes, kModes + std::min(*count, kNumModes), modes);
+ *count = std::min(*count, kNumModes);
+ std::copy(kModes, kModes + *count, modes);
+ } else {
+ *count = kNumModes;
}
- *count = kNumModes;
return result;
}
@@ -751,8 +755,10 @@
}
for (uint32_t i = 0; i < n; i++)
images[i] = swapchain.images[i].image;
+ *count = n;
+ } else {
+ *count = swapchain.num_images;
}
- *count = swapchain.num_images;
return result;
}