From 714b431cf9a2d5fd401e8e005575d71a0a2dec74 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 5 Feb 2019 14:35:29 -0800 Subject: [PATCH] Vulkan: use a longer swap chain to avoid stalls. This is consistent with the Willems demos, the Overvoorde tutorials, as well as Intel's "API without Secrets" guidance. Fixes #778 --- .../src/driver/vulkan/VulkanDriverImpl.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/filament/src/driver/vulkan/VulkanDriverImpl.cpp b/filament/src/driver/vulkan/VulkanDriverImpl.cpp index 15ceb7b358..aa714cf856 100644 --- a/filament/src/driver/vulkan/VulkanDriverImpl.cpp +++ b/filament/src/driver/vulkan/VulkanDriverImpl.cpp @@ -267,13 +267,19 @@ void getSurfaceCaps(VulkanContext& context, VulkanSurfaceContext& sc) { } void createSwapChainAndImages(VulkanContext& context, VulkanSurfaceContext& surfaceContext) { - // Pick an image count and format. According to section 30.5 of VK 1.1, maxImageCount of zero - // apparently means "that there is no limit on the number of images, though there may be limits - // related to the total amount of memory used by presentable images." - uint32_t desiredImageCount = 2; + // The general advice is to require one more than the minimum swap chain length, since the + // absolute minimum could easily require waiting for a driver or presentation layer to release + // the previous frame's buffer. The only situation in which we'd ask for the minimum length is + // when using a MAILBOX presentation strategy for low-latency situations where tearing is + // acceptable. const uint32_t maxImageCount = surfaceContext.surfaceCapabilities.maxImageCount; - if (desiredImageCount < surfaceContext.surfaceCapabilities.minImageCount || - (maxImageCount != 0 && desiredImageCount > maxImageCount)) { + const uint32_t minImageCount = surfaceContext.surfaceCapabilities.minImageCount; + uint32_t desiredImageCount = minImageCount + 1; + + // According to section 30.5 of VK 1.1, maxImageCount of zero means "that there is no limit on + // the number of images, though there may be limits related to the total amount of memory used + // by presentable images." + if (maxImageCount != 0 && desiredImageCount > maxImageCount) { utils::slog.e << "Swap chain does not support " << desiredImageCount << " images.\n"; desiredImageCount = surfaceContext.surfaceCapabilities.minImageCount; }