Vulkan: improve calculation of swapchain image count
Based on present mode, different values for the image count make sense.
In mailbox mode, the driver will increase the number as necessary. In
immediate mode, two buffers suffice. In fifo mode, we would ideally
want triple-buffering.
Bug: angleproject:2932
Change-Id: I45eec83d0292eea472b931fe81e49cde6d105c27
Reviewed-on: https://chromium-review.googlesource.com/c/1454290
Reviewed-by: Ian Elliott <ianelliott@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/SurfaceVk.cpp b/src/libANGLE/renderer/vulkan/SurfaceVk.cpp
index 12f1acd..108f7f1 100644
--- a/src/libANGLE/renderer/vulkan/SurfaceVk.cpp
+++ b/src/libANGLE/renderer/vulkan/SurfaceVk.cpp
@@ -392,8 +392,26 @@
mSwapchainPresentMode = GetDesiredPresentMode(presentModes, minSwapInterval, maxSwapInterval);
- // Determine number of swapchain images. Aim for one more than the minimum.
- uint32_t minImageCount = surfaceCaps.minImageCount + 1;
+ // Determine the number of swapchain images:
+ //
+ // - On mailbox, we use minImageCount. The drivers may increase the number so that non-blocking
+ // mailbox actually makes sense.
+ // - On immediate, we use max(2, minImageCount). The vkQueuePresentKHR call immediately frees
+ // up the other image, so there is no point in having any more images.
+ // - On fifo, we use max(3, minImageCount). Triple-buffering allows us to present an image,
+ // have one in the queue and record in another. Note: on certain configurations (windows +
+ // nvidia + windowed mode), we could get away with a smaller number.
+ uint32_t minImageCount = surfaceCaps.minImageCount;
+ if (mSwapchainPresentMode == VK_PRESENT_MODE_IMMEDIATE_KHR)
+ {
+ minImageCount = std::max<uint32_t>(2, minImageCount);
+ }
+ else if (mSwapchainPresentMode == VK_PRESENT_MODE_FIFO_KHR)
+ {
+ minImageCount = std::max<uint32_t>(3, minImageCount);
+ }
+
+ // Make sure we don't exceed maxImageCount.
if (surfaceCaps.maxImageCount > 0 && minImageCount > surfaceCaps.maxImageCount)
{
minImageCount = surfaceCaps.maxImageCount;