@@ -703,7 +703,7 @@ typedef struct WindowData
703703
704704 // Synchronization primitives
705705 VkSemaphore imageAvailableSemaphore [MAX_FRAMES_IN_FLIGHT ];
706- VkSemaphore renderFinishedSemaphore [ MAX_FRAMES_IN_FLIGHT ] ;
706+ VkSemaphore * renderFinishedSemaphore ;
707707 SDL_GPUFence * inFlightFences [MAX_FRAMES_IN_FLIGHT ];
708708
709709 Uint32 frameCounter ;
@@ -3164,7 +3164,6 @@ static void VULKAN_INTERNAL_DestroySwapchain(
31643164 SDL_free (windowData -> textureContainers [i ].activeTexture -> subresources );
31653165 SDL_free (windowData -> textureContainers [i ].activeTexture );
31663166 }
3167- windowData -> imageCount = 0 ;
31683167
31693168 SDL_free (windowData -> textureContainers );
31703169 windowData -> textureContainers = NULL ;
@@ -3193,7 +3192,8 @@ static void VULKAN_INTERNAL_DestroySwapchain(
31933192 NULL );
31943193 windowData -> imageAvailableSemaphore [i ] = VK_NULL_HANDLE ;
31953194 }
3196-
3195+ }
3196+ for (i = 0 ; i < windowData -> imageCount ; i += 1 ) {
31973197 if (windowData -> renderFinishedSemaphore [i ]) {
31983198 renderer -> vkDestroySemaphore (
31993199 renderer -> logicalDevice ,
@@ -3202,6 +3202,10 @@ static void VULKAN_INTERNAL_DestroySwapchain(
32023202 windowData -> renderFinishedSemaphore [i ] = VK_NULL_HANDLE ;
32033203 }
32043204 }
3205+ SDL_free (windowData -> renderFinishedSemaphore );
3206+ windowData -> renderFinishedSemaphore = NULL ;
3207+
3208+ windowData -> imageCount = 0 ;
32053209}
32063210
32073211static void VULKAN_INTERNAL_DestroyGraphicsPipelineResourceLayout (
@@ -4779,6 +4783,12 @@ static Uint32 VULKAN_INTERNAL_CreateSwapchain(
47794783 CHECK_VULKAN_ERROR_AND_RETURN (vulkanResult , vkCreateSemaphore , false);
47804784 }
47814785
4786+ windowData -> inFlightFences [i ] = NULL ;
4787+ }
4788+
4789+ windowData -> renderFinishedSemaphore = SDL_malloc (
4790+ sizeof (VkSemaphore ) * windowData -> imageCount );
4791+ for (i = 0 ; i < windowData -> imageCount ; i += 1 ) {
47824792 vulkanResult = renderer -> vkCreateSemaphore (
47834793 renderer -> logicalDevice ,
47844794 & semaphoreCreateInfo ,
@@ -4798,8 +4808,6 @@ static Uint32 VULKAN_INTERNAL_CreateSwapchain(
47984808 windowData -> swapchain = VK_NULL_HANDLE ;
47994809 CHECK_VULKAN_ERROR_AND_RETURN (vulkanResult , vkCreateSemaphore , false);
48004810 }
4801-
4802- windowData -> inFlightFences [i ] = NULL ;
48034811 }
48044812
48054813 windowData -> needsSwapchainRecreate = false;
@@ -10020,7 +10028,7 @@ static bool VULKAN_INTERNAL_AcquireSwapchainTexture(
1002010028 }
1002110029
1002210030 vulkanCommandBuffer -> signalSemaphores [vulkanCommandBuffer -> signalSemaphoreCount ] =
10023- windowData -> renderFinishedSemaphore [windowData -> frameCounter ];
10031+ windowData -> renderFinishedSemaphore [swapchainImageIndex ];
1002410032 vulkanCommandBuffer -> signalSemaphoreCount += 1 ;
1002510033
1002610034 * swapchainTexture = (SDL_GPUTexture * )swapchainTextureContainer ;
@@ -10561,7 +10569,7 @@ static bool VULKAN_Submit(
1056110569 presentInfo .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR ;
1056210570 presentInfo .pNext = NULL ;
1056310571 presentInfo .pWaitSemaphores =
10564- & presentData -> windowData -> renderFinishedSemaphore [presentData -> windowData -> frameCounter ];
10572+ & presentData -> windowData -> renderFinishedSemaphore [presentData -> swapchainImageIndex ];
1056510573 presentInfo .waitSemaphoreCount = 1 ;
1056610574 presentInfo .pSwapchains = & presentData -> windowData -> swapchain ;
1056710575 presentInfo .swapchainCount = 1 ;
0 commit comments