Skip to content

Commit c5c83a6

Browse files
authored
vk: fix spurious VK_ERROR_OUT_OF_DATE_KHR on swapchain resize (#9482)
Fixes #9476 Fixes #8604
1 parent ccf0d62 commit c5c83a6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

filament/backend/src/vulkan/VulkanSwapChain.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "VulkanCommands.h"
2020
#include "VulkanTexture.h"
2121

22+
#include <utils/debug.h>
2223
#include <utils/FixedCapacityVector.h>
2324
#include <utils/Panic.h>
2425

@@ -105,6 +106,11 @@ void VulkanSwapChain::update() {
105106
}
106107

107108
void VulkanSwapChain::present(DriverBase& driver) {
109+
// The last acquire failed, so just skip presenting.
110+
if (!mAcquired) {
111+
return;
112+
}
113+
108114
if (!mHeadless && mTransitionSwapChainImageLayoutForPresent) {
109115
VulkanCommandBuffer& commands = mCommands->get();
110116
VkImageSubresourceRange const subresources{
@@ -161,7 +167,15 @@ void VulkanSwapChain::acquire(bool& resized) {
161167

162168
VulkanPlatform::ImageSyncData imageSyncData;
163169
VkResult const result = mPlatform->acquire(swapChain, &imageSyncData);
170+
171+
if (result != VK_SUCCESS) {
172+
// We just don't set mAcquired here so the next present will just skip.
173+
FVK_LOGD << "Failed to acquire next image in the swapchain result=" << (int) result;
174+
return;
175+
}
176+
164177
mCurrentSwapIndex = imageSyncData.imageIndex;
178+
assert_invariant(mCurrentSwapIndex < mFinishedDrawing.size());
165179
mFinishedDrawing[mCurrentSwapIndex] = {};
166180
FILAMENT_CHECK_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)
167181
<< "Cannot acquire in swapchain. error=" << static_cast<int32_t>(result);

0 commit comments

Comments
 (0)