- improve swap chain resize and handle the edge cases for the swap chain
This commit is contained in:
parent
20fde9f8be
commit
c98dfd1790
4 changed files with 134 additions and 37 deletions
|
|
@ -157,20 +157,7 @@ void VulkanFrameBuffer::Update()
|
|||
|
||||
Flush3D.Clock();
|
||||
|
||||
int newWidth = GetClientWidth();
|
||||
int newHeight = GetClientHeight();
|
||||
if (lastSwapWidth != newWidth || lastSwapHeight != newHeight)
|
||||
{
|
||||
swapChain.reset();
|
||||
swapChain = std::make_unique<VulkanSwapChain>(device);
|
||||
|
||||
lastSwapWidth = newWidth;
|
||||
lastSwapHeight = newHeight;
|
||||
}
|
||||
|
||||
VkResult result = vkAcquireNextImageKHR(device->device, swapChain->swapChain, std::numeric_limits<uint64_t>::max(), mSwapChainImageAvailableSemaphore->semaphore, VK_NULL_HANDLE, &presentImageIndex);
|
||||
if (result != VK_SUCCESS)
|
||||
throw std::runtime_error("Failed to acquire next image!");
|
||||
presentImageIndex = swapChain->AcquireImage(GetClientWidth(), GetClientHeight(), mSwapChainImageAvailableSemaphore.get());
|
||||
|
||||
GetPostprocess()->SetActiveRenderTarget();
|
||||
|
||||
|
|
@ -180,7 +167,8 @@ void VulkanFrameBuffer::Update()
|
|||
mRenderState->EndRenderPass();
|
||||
mRenderState->EndFrame();
|
||||
|
||||
mPostprocess->DrawPresentTexture(mOutputLetterbox, true, true);
|
||||
if (presentImageIndex != 0xffffffff)
|
||||
mPostprocess->DrawPresentTexture(mOutputLetterbox, true, true);
|
||||
|
||||
SubmitCommands(true);
|
||||
|
||||
|
|
@ -191,17 +179,8 @@ void VulkanFrameBuffer::Update()
|
|||
Finish.Reset();
|
||||
Finish.Clock();
|
||||
|
||||
VkSemaphore waitSemaphores[] = { mRenderFinishedSemaphore->semaphore };
|
||||
VkSwapchainKHR swapChains[] = { swapChain->swapChain };
|
||||
VkPresentInfoKHR presentInfo = {};
|
||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
presentInfo.waitSemaphoreCount = 1;
|
||||
presentInfo.pWaitSemaphores = waitSemaphores;
|
||||
presentInfo.swapchainCount = 1;
|
||||
presentInfo.pSwapchains = swapChains;
|
||||
presentInfo.pImageIndices = &presentImageIndex;
|
||||
presentInfo.pResults = nullptr;
|
||||
vkQueuePresentKHR(device->presentQueue, &presentInfo);
|
||||
if (presentImageIndex != 0xffffffff)
|
||||
swapChain->QueuePresent(presentImageIndex, mRenderFinishedSemaphore.get());
|
||||
|
||||
vkWaitForFences(device->device, 1, &mRenderFinishedFence->fence, VK_TRUE, std::numeric_limits<uint64_t>::max());
|
||||
vkResetFences(device->device, 1, &mRenderFinishedFence->fence);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue