@@ -1344,7 +1344,9 @@ static void vulkan_acquire_clear_fences(gfx_ctx_vulkan_data_t *vk)
13441344 {
13451345 struct vulkan_context * ctx = & vk -> context ;
13461346 VkSemaphore sem = vk -> context .swapchain_wait_semaphores [i ];
1347- assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
1347+ #ifdef DEBUG
1348+ retro_assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
1349+ #endif
13481350 ctx -> swapchain_recycled_semaphores [ctx -> num_recycled_acquire_semaphores ++ ] = sem ;
13491351 }
13501352 vk -> context .swapchain_wait_semaphores [i ] = VK_NULL_HANDLE ;
@@ -1406,7 +1408,9 @@ static void vulkan_acquire_wait_fences(gfx_ctx_vulkan_data_t *vk)
14061408 {
14071409 struct vulkan_context * ctx = & vk -> context ;
14081410 VkSemaphore sem = vk -> context .swapchain_wait_semaphores [index ];
1409- assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
1411+ #ifdef DEBUG
1412+ retro_assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
1413+ #endif
14101414 ctx -> swapchain_recycled_semaphores [ctx -> num_recycled_acquire_semaphores ++ ] = sem ;
14111415 }
14121416 vk -> context .swapchain_wait_semaphores [index ] = VK_NULL_HANDLE ;
@@ -1469,8 +1473,10 @@ bool vulkan_buffer_chain_alloc(const struct vulkan_context *context,
14691473
14701474 chain -> current = chain -> current -> next ;
14711475 chain -> offset = 0 ;
1476+ #ifdef DEBUG
14721477 /* This cannot possibly fail. */
14731478 retro_assert (vulkan_buffer_chain_suballoc (chain , len , range ));
1479+ #endif
14741480 }
14751481 return true;
14761482}
@@ -1597,15 +1603,16 @@ VkDescriptorSet vulkan_descriptor_manager_alloc(
15971603 }
15981604
15991605 manager -> current -> next = vulkan_alloc_descriptor_pool (device , manager );
1606+ #ifdef DEBUG
16001607 retro_assert (manager -> current -> next );
1608+ #endif
16011609
16021610 manager -> current = manager -> current -> next ;
16031611 manager -> count = 0 ;
16041612 }
16051613 return manager -> current -> sets [manager -> count ++ ];
16061614}
16071615
1608-
16091616bool vulkan_surface_create (gfx_ctx_vulkan_data_t * vk ,
16101617 enum vulkan_wsi_type type ,
16111618 void * display , void * surface ,
@@ -1872,7 +1879,9 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk)
18721879 }
18731880 }
18741881
1882+ #ifdef DEBUG
18751883 retro_assert (!(vk -> context .flags & VK_CTX_FLAG_HAS_ACQUIRED_SWAPCHAIN ));
1884+ #endif
18761885
18771886 if (vk -> flags & VK_DATA_FLAG_EMULATING_MAILBOX )
18781887 {
@@ -1903,16 +1912,16 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk)
19031912 vkWaitForFences (vk -> context .device , 1 , & fence , true, UINT64_MAX );
19041913 vk -> context .flags |= VK_CTX_FLAG_HAS_ACQUIRED_SWAPCHAIN ;
19051914
1906- if (vk -> context .swapchain_acquire_semaphore )
1915+ /* Recycle the previous acquire semaphore rather than stalling the device.
1916+ * vkDeviceWaitIdle here was a significant hot-path bottleneck. */
1917+ if (vk -> context .swapchain_acquire_semaphore != VK_NULL_HANDLE )
19071918 {
1908- #ifdef HAVE_THREADS
1909- slock_lock (vk -> context .queue_lock );
1910- #endif
1911- vkDeviceWaitIdle (vk -> context .device );
1912- vkDestroySemaphore (vk -> context .device , vk -> context .swapchain_acquire_semaphore , NULL );
1913- #ifdef HAVE_THREADS
1914- slock_unlock (vk -> context .queue_lock );
1919+ struct vulkan_context * ctx = & vk -> context ;
1920+ #ifdef DEBUG
1921+ retro_assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
19151922#endif
1923+ ctx -> swapchain_recycled_semaphores [ctx -> num_recycled_acquire_semaphores ++ ] =
1924+ vk -> context .swapchain_acquire_semaphore ;
19161925 }
19171926 vk -> context .swapchain_acquire_semaphore = semaphore ;
19181927 }
@@ -1923,7 +1932,9 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk)
19231932 {
19241933 struct vulkan_context * ctx = & vk -> context ;
19251934 VkSemaphore sem = semaphore ;
1926- assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
1935+ #ifdef DEBUG
1936+ retro_assert (ctx -> num_recycled_acquire_semaphores < VULKAN_MAX_SWAPCHAIN_IMAGES );
1937+ #endif
19271938 ctx -> swapchain_recycled_semaphores [ctx -> num_recycled_acquire_semaphores ++ ] = sem ;
19281939 }
19291940 }
0 commit comments