diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 04b389da..9692afc1 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -347,7 +347,13 @@ void vk_reflex_sleep(void) { .signalSemaphore = g_reflex_sem, .value = val }; - if (g_reflex_sleep(c->device, g_sc, &si) == VK_SUCCESS) { + // vkLatencySleepNV uses the swapchain, which Vulkan wants externally synchronised with the acquire and the present + // (they run under g_pl on the present thread). The wait for the semaphore stays outside the lock. + VkResult r = VK_ERROR_INITIALIZATION_FAILED; + plat_rmutex_lock(&g_pl); + if (g_sc) r = g_reflex_sleep(c->device, g_sc, &si); + plat_rmutex_unlock(&g_pl); + if (r == VK_SUCCESS) { VkSemaphoreWaitInfo wi = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO, .semaphoreCount = 1,