From 41623cec85cdc1e5f19e0ac95b13558d6972d306 Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:46:15 +0100 Subject: [PATCH] Call vkLatencySleepNV under the present lock The swapchain must be externally synchronised, and the acquire and the present use it under g_pl on the present thread while the game thread calls vk_reflex_sleep. With reflex = boost and TOTK_VK_VALIDATION=1 the validation layer reported 20 threading errors in 30 s (vkLatencySleepNV against vkAcquireNextImageKHR and vkQueuePresentKHR). The earlier head of #638 (318acd8) took the lock here; the rebase onto dev lost it. The semaphore wait stays outside. Co-Authored-By: Claude Opus 5.5 --- runtime/gfx_present.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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,