diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 553655372f..314f0f415d 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -2275,16 +2275,18 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk) vkCreateSemaphore(vk->context.device, &sem_info, NULL, &vk->context.swapchain_semaphores[index]); - vkWaitForFences(vk->context.device, 1, &fence, true, UINT64_MAX); + if (err == VK_SUCCESS) + vkWaitForFences(vk->context.device, 1, &fence, true, UINT64_MAX); vkDestroyFence(vk->context.device, fence, NULL); next_fence = &vk->context.swapchain_fences[index]; if (*next_fence != VK_NULL_HANDLE) { - vkWaitForFences(vk->context.device, 1, next_fence, true, UINT64_MAX); - + if (vk->context.swapchain_fences_signalled[index]) + vkWaitForFences(vk->context.device, 1, next_fence, true, UINT64_MAX); vkResetFences(vk->context.device, 1, next_fence); + vk->context.swapchain_fences_signalled[index] = false; } else vkCreateFence(vk->context.device, &fence_info, NULL, next_fence); diff --git a/gfx/common/vulkan_common.h b/gfx/common/vulkan_common.h index 04785517fd..26ade3cd30 100644 --- a/gfx/common/vulkan_common.h +++ b/gfx/common/vulkan_common.h @@ -109,6 +109,7 @@ typedef struct vulkan_context VkImage swapchain_images[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkFence swapchain_fences[VULKAN_MAX_SWAPCHAIN_IMAGES]; + bool swapchain_fences_signalled[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkSemaphore swapchain_semaphores[VULKAN_MAX_SWAPCHAIN_IMAGES]; VkFormat swapchain_format; diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index 45be4a4e70..1e14aeb11b 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -1569,6 +1569,7 @@ static void vulkan_inject_black_frame(vk_t *vk, video_frame_info_t *video_info) #endif vkQueueSubmit(vk->context->queue, 1, &submit_info, vk->context->swapchain_fences[frame_index]); + vk->context->swapchain_fences_signalled[frame_index] = true; #ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); #endif @@ -1935,6 +1936,7 @@ static bool vulkan_frame(void *data, const void *frame, #endif vkQueueSubmit(vk->context->queue, 1, &submit_info, vk->context->swapchain_fences[frame_index]); + vk->context->swapchain_fences_signalled[frame_index] = true; #ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); #endif