@@ -138,9 +138,12 @@ core::smart_refctd_ptr<CVulkanSwapchain> CVulkanSwapchain::create(core::smart_re
138138 .pNext = nullptr ,
139139 .flags = 0
140140 };
141+
142+ // imageCount + 2u, because we allow max 2 pending submissions to wait on image availability while others are being presented or rendered into.
143+ const uint8_t maxAcquiresinFlight = core::min (imageCount + 2u , ISwapchain::MaxImages);
141144 VkSemaphore semaphores[ISwapchain::MaxImages];
142- for (auto i=0u ; i<3 *imageCount ; i++)
143- if (vk.vkCreateSemaphore (vk_device,i<imageCount ? (&timelineInfo):(&adaptorInfo),nullptr ,semaphores+i)!=VK_SUCCESS)
145+ for (auto i=0u ; i<3 *maxAcquiresinFlight ; i++)
146+ if (vk.vkCreateSemaphore (vk_device,i<maxAcquiresinFlight ? (&timelineInfo):(&adaptorInfo),nullptr ,semaphores+i)!=VK_SUCCESS)
144147 {
145148 // handle successful allocs before failure
146149 for (auto j=0u ; j<i; j++)
@@ -153,7 +156,7 @@ core::smart_refctd_ptr<CVulkanSwapchain> CVulkanSwapchain::create(core::smart_re
153156 // read https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap34.html#swapchain-acquire-forward-progress
154157 const uint8_t maxAcquiresWithoutPresent = core::min (imageCount,ISwapchain::MaxImages) - caps.minImageCount + 1u ;
155158
156- return core::smart_refctd_ptr<CVulkanSwapchain>(new CVulkanSwapchain (std::move (device),std::move (params),imageCount,std::move (oldSwapchain),vk_swapchain,semaphores+imageCount ,semaphores,semaphores+2 *imageCount , maxAcquiresWithoutPresent),core::dont_grab);
159+ return core::smart_refctd_ptr<CVulkanSwapchain>(new CVulkanSwapchain (std::move (device),std::move (params),imageCount,std::move (oldSwapchain),vk_swapchain,semaphores+maxAcquiresinFlight ,semaphores,semaphores+2 *maxAcquiresinFlight , maxAcquiresWithoutPresent, maxAcquiresinFlight ),core::dont_grab);
157160}
158161
159162CVulkanSwapchain::CVulkanSwapchain (
@@ -165,7 +168,8 @@ CVulkanSwapchain::CVulkanSwapchain(
165168 const VkSemaphore* const _acquireAdaptorSemaphores,
166169 const VkSemaphore* const _prePresentSemaphores,
167170 const VkSemaphore* const _presentAdaptorSemaphores,
168- const uint8_t maxAcquiresBeforePresent)
171+ const uint8_t maxAcquiresBeforePresent,
172+ const uint8_t maxAcquiresInFlight)
169173 : ISwapchain(std::move(logicalDevice),std::move(params),imageCount,std::move(oldSwapchain)),
170174 m_imgMemRequirements{.size =0 ,.memoryTypeBits =0x0u ,.alignmentLog2 =63 ,.prefersDedicatedAllocation =true ,.requiresDedicatedAllocation =true }, m_vkSwapchainKHR(swapchain), m_maxBlockingAcquiresBeforePresent(maxAcquiresBeforePresent)
171175{
@@ -179,8 +183,6 @@ CVulkanSwapchain::CVulkanSwapchain(
179183 auto retval = vulkanDevice->getFunctionTable ()->vk .vkGetSwapchainImagesKHR (vulkanDevice->getInternalObject (),m_vkSwapchainKHR,&dummy,m_images);
180184 assert (retval==VK_SUCCESS && dummy==getImageCount ());
181185 }
182- const uint8_t maxAcquiresInFlight = getMaxAcquiresInFlight ();
183- assert (maxAcquiresInFlight == imageCount);
184186 assert (getMaxBlockingAcquiresBeforePresent () <= imageCount);
185187
186188 std::copy_n (_acquireAdaptorSemaphores,maxAcquiresInFlight,m_acquireAdaptorSemaphores);
0 commit comments