Skip to content

Commit

Permalink
[dxvk] Dirty swapchain if present returns SUBOPTIMAL
Browse files Browse the repository at this point in the history
May fix some issues in case the WSI implementation can return SUBOPTIMAL
from present but not acquire. Also ensure to keep state consistent.
  • Loading branch information
doitsujin committed Jan 14, 2025
1 parent 9a1f130 commit c6a21f5
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/dxvk/dxvk_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,30 @@ namespace dxvk {
VkResult status = m_vkd->vkQueuePresentKHR(
m_device->queues().graphics.queueHandle, &info);

// Maintain valid state if presentation succeeded, even
// if we want to recreate the swapchain.
if (m_device->features().extSwapchainMaintenance1.swapchainMaintenance1)
currSync.fenceSignaled = status >= 0;

if (status != VK_SUCCESS && status != VK_SUBOPTIMAL_KHR)
return status;
if (status >= 0) {
m_acquireStatus = VK_NOT_READY;

m_frameIndex += 1;
m_frameIndex %= m_semaphores.size();
}

// Recreate the swapchain on the next acquire, even if we get suboptimal.
// There is no guarantee that suboptimal state is returned by both functions.
if (status != VK_SUCCESS) {
Logger::info(str::format("Presenter: Got ", status, ", recreating swapchain"));

// Try to acquire next image already, in order to hide
// potential delays from the application thread.
m_frameIndex += 1;
m_frameIndex %= m_semaphores.size();
std::lock_guard lock(m_surfaceMutex);
m_dirtySwapchain = true;
return status;
}

// On a successful present, try to acquire next image already, in
// order to hide potential delays from the application thread.
PresenterSync& nextSync = m_semaphores.at(m_frameIndex);
waitForSwapchainFence(nextSync);

Expand Down Expand Up @@ -590,7 +603,6 @@ namespace dxvk {

m_imageIndex = 0;
m_frameIndex = 0;
m_acquireStatus = VK_NOT_READY;

m_dynamicModes = std::move(dynamicModes);
return VK_SUCCESS;
Expand Down Expand Up @@ -952,6 +964,7 @@ namespace dxvk {
m_dynamicModes.clear();

m_swapchain = VK_NULL_HANDLE;
m_acquireStatus = VK_NOT_READY;
}


Expand Down

0 comments on commit c6a21f5

Please sign in to comment.