@@ -138,9 +138,12 @@ core::smart_refctd_ptr<CVulkanSwapchain> CVulkanSwapchain::create(core::smart_re
138
138
.pNext = nullptr ,
139
139
.flags = 0
140
140
};
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);
141
144
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)
144
147
{
145
148
// handle successful allocs before failure
146
149
for (auto j=0u ; j<i; j++)
@@ -153,7 +156,7 @@ core::smart_refctd_ptr<CVulkanSwapchain> CVulkanSwapchain::create(core::smart_re
153
156
// read https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap34.html#swapchain-acquire-forward-progress
154
157
const uint8_t maxAcquiresWithoutPresent = core::min (imageCount,ISwapchain::MaxImages) - caps.minImageCount + 1u ;
155
158
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);
157
160
}
158
161
159
162
CVulkanSwapchain::CVulkanSwapchain (
@@ -165,7 +168,8 @@ CVulkanSwapchain::CVulkanSwapchain(
165
168
const VkSemaphore* const _acquireAdaptorSemaphores,
166
169
const VkSemaphore* const _prePresentSemaphores,
167
170
const VkSemaphore* const _presentAdaptorSemaphores,
168
- const uint8_t maxAcquiresBeforePresent)
171
+ const uint8_t maxAcquiresBeforePresent,
172
+ const uint8_t maxAcquiresInFlight)
169
173
: ISwapchain(std::move(logicalDevice),std::move(params),imageCount,std::move(oldSwapchain)),
170
174
m_imgMemRequirements{.size =0 ,.memoryTypeBits =0x0u ,.alignmentLog2 =63 ,.prefersDedicatedAllocation =true ,.requiresDedicatedAllocation =true }, m_vkSwapchainKHR(swapchain), m_maxBlockingAcquiresBeforePresent(maxAcquiresBeforePresent)
171
175
{
@@ -179,8 +183,6 @@ CVulkanSwapchain::CVulkanSwapchain(
179
183
auto retval = vulkanDevice->getFunctionTable ()->vk .vkGetSwapchainImagesKHR (vulkanDevice->getInternalObject (),m_vkSwapchainKHR,&dummy,m_images);
180
184
assert (retval==VK_SUCCESS && dummy==getImageCount ());
181
185
}
182
- const uint8_t maxAcquiresInFlight = getMaxAcquiresInFlight ();
183
- assert (maxAcquiresInFlight == imageCount);
184
186
assert (getMaxBlockingAcquiresBeforePresent () <= imageCount);
185
187
186
188
std::copy_n (_acquireAdaptorSemaphores,maxAcquiresInFlight,m_acquireAdaptorSemaphores);
0 commit comments