mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Feat] (MG_Test/Backend/DirectVulkan): properly handle out-of-date/suboptimal swapchain
This commit is contained in:
@@ -390,17 +390,29 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
presentInfo.pSwapchains = swapChains;
|
presentInfo.pSwapchains = swapChains;
|
||||||
presentInfo.pImageIndices = &m_imageIndexAcquired;
|
presentInfo.pImageIndices = &m_imageIndexAcquired;
|
||||||
presentInfo.pResults = nullptr;
|
presentInfo.pResults = nullptr;
|
||||||
VK_VERIFY(vkQueuePresentKHR(m_presentQueue, &presentInfo));
|
auto result = vkQueuePresentKHR(m_presentQueue, &presentInfo);
|
||||||
|
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
|
||||||
|
MGLOG_D("Present, vkQueuePresentKHR got %d, recreating swapchain", result);
|
||||||
|
RecreateSwapchain();
|
||||||
|
result = VK_SUCCESS;
|
||||||
|
}
|
||||||
|
VK_VERIFY(result, "Present, vkQueuePresentKHR");
|
||||||
|
|
||||||
// 3) Advance frame slot.
|
// 3) Advance frame slot.
|
||||||
m_currentFrameIndex = (m_currentFrameIndex + 1) % m_config.MaxFramesInFlight;
|
m_currentFrameIndex = (m_currentFrameIndex + 1) % m_config.MaxFramesInFlight;
|
||||||
|
|
||||||
// 4) Wait/reset/acquire for next frame.
|
// 4) Wait/reset/acquire for next frame.
|
||||||
VK_VERIFY(vkWaitForFences(m_device, 1, &m_imageInFlightFences[m_currentFrameIndex], VK_TRUE, UINT64_MAX));
|
VK_VERIFY(vkWaitForFences(m_device, 1, &m_imageInFlightFences[m_currentFrameIndex], VK_TRUE, UINT64_MAX), "Present, vkWaitForFences");
|
||||||
VK_VERIFY(vkResetFences(m_device, 1, &m_imageInFlightFences[m_currentFrameIndex]));
|
VK_VERIFY(vkResetFences(m_device, 1, &m_imageInFlightFences[m_currentFrameIndex]), "Present, vkResetFences");
|
||||||
VK_VERIFY(vkAcquireNextImageKHR(m_device, m_swapchain, UINT64_MAX,
|
result = vkAcquireNextImageKHR(m_device, m_swapchain, UINT64_MAX,
|
||||||
m_imageAvailableSemaphores[m_currentFrameIndex],
|
m_imageAvailableSemaphores[m_currentFrameIndex],
|
||||||
VK_NULL_HANDLE, &m_imageIndexAcquired));
|
VK_NULL_HANDLE, &m_imageIndexAcquired);
|
||||||
|
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) {
|
||||||
|
MGLOG_D("Present, vkAcquireNextImageKHR got %d, recreating swapchain", result);
|
||||||
|
RecreateSwapchain();
|
||||||
|
result = VK_SUCCESS;
|
||||||
|
}
|
||||||
|
VK_VERIFY(result, "Present, vkAcquireNextImageKHR");
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanRenderer::CreateInstance() {
|
void VulkanRenderer::CreateInstance() {
|
||||||
@@ -1085,6 +1097,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_physicalDevice.swapchainCapabilities = GetSwapchainCapabilities(m_physicalDevice.handle, m_surface);
|
||||||
|
|
||||||
auto& supportedSurfaceFormats = m_physicalDevice.swapchainCapabilities.surfaceFormats;
|
auto& supportedSurfaceFormats = m_physicalDevice.swapchainCapabilities.surfaceFormats;
|
||||||
MGLOG_I("Got %d surface formats: ", supportedSurfaceFormats.size());
|
MGLOG_I("Got %d surface formats: ", supportedSurfaceFormats.size());
|
||||||
for (auto& surfaceFormat : supportedSurfaceFormats) {
|
for (auto& surfaceFormat : supportedSurfaceFormats) {
|
||||||
|
|||||||
Reference in New Issue
Block a user