@@ -57,6 +57,7 @@ SwapChainVkImpl::SwapChainVkImpl(IReferenceCounters* pRefCounters,
57
57
58
58
AcquireNextImage (pDeviceContextVk);
59
59
// Note that the image may be immediately out of date.
60
+ // https://github.com/DiligentGraphics/DiligentCore/issues/632
60
61
61
62
FenceDesc FenceCI;
62
63
FenceCI.Name = " Swap chain frame complete fence" ;
@@ -597,6 +598,14 @@ void SwapChainVkImpl::InitBuffersAndViews()
597
598
}
598
599
}
599
600
601
+ void SwapChainVkImpl::ThrottleFrameSubmission ()
602
+ {
603
+ if (m_FrameIndex > m_SwapChainDesc.BufferCount )
604
+ {
605
+ m_FrameCompleteFence->Wait (m_FrameIndex - m_SwapChainDesc.BufferCount );
606
+ }
607
+ }
608
+
600
609
VkResult SwapChainVkImpl::AcquireNextImage (DeviceContextVkImpl* pDeviceCtxVk)
601
610
{
602
611
RenderDeviceVkImpl* pDeviceVk = m_pRenderDevice.RawPtr <RenderDeviceVkImpl>();
@@ -612,10 +621,7 @@ VkResult SwapChainVkImpl::AcquireNextImage(DeviceContextVkImpl* pDeviceCtxVk)
612
621
// vkAcquireNextImageKHR requires that the semaphore is not in use, so we must wait
613
622
// for the frame (FrameIndex - BufferCount) to complete.
614
623
// This also ensures that there are no more than BufferCount frames in flight at any time.
615
- if (m_FrameIndex > m_SwapChainDesc.BufferCount )
616
- {
617
- m_FrameCompleteFence->Wait (m_FrameIndex - m_SwapChainDesc.BufferCount );
618
- }
624
+ ThrottleFrameSubmission ();
619
625
620
626
RefCntAutoPtr<ManagedSemaphore>& ImageAcquiredSemaphore = m_ImageAcquiredSemaphores[m_SemaphoreIndex];
621
627
@@ -673,14 +679,15 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval)
673
679
// The context can be empty if no render commands were issued by the app
674
680
// VERIFY(pImmediateCtxVk->GetNumCommandsInCtx() != 0, "The context must not be flushed");
675
681
pImmediateCtxVk->AddSignalSemaphore (DrawCompleteSemaphore);
676
- pImmediateCtxVk->EnqueueSignal (m_FrameCompleteFence, m_FrameIndex++);
677
682
}
678
683
684
+ pImmediateCtxVk->EnqueueSignal (m_FrameCompleteFence, m_FrameIndex++);
679
685
pImmediateCtxVk->Flush ();
680
686
681
687
if (!m_IsMinimized)
682
688
{
683
689
VkResult Result = VK_ERROR_OUT_OF_DATE_KHR;
690
+ // Only present if the image was acquired successfully
684
691
if (m_ImageAcquired)
685
692
{
686
693
VkPresentInfoKHR PresentInfo{};
@@ -750,6 +757,12 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval)
750
757
}
751
758
// The image may still be out of date if the window keeps changing size
752
759
}
760
+ else
761
+ {
762
+ // Throttle frame submission to make sure that resources are released
763
+ // https://github.com/DiligentGraphics/DiligentSamples/issues/234
764
+ ThrottleFrameSubmission ();
765
+ }
753
766
}
754
767
755
768
void SwapChainVkImpl::ReleaseSwapChainResources (DeviceContextVkImpl* pImmediateCtxVk, bool DestroyVkSwapChain)
0 commit comments