Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1df0a23

Browse files
authored
[Impeller] Fix swapchain recreation for non-polling cases. (#45740)
Earlier, there was no recovery from vk::Result::eSuboptimalKHR. This made the playground be stuck with a swapchain image size of 1x1 with suboptimal error code on acquisition indefinitely. Towards fixing the playgrounds. There are still some validation errors.
1 parent 865807c commit 1df0a23

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

impeller/renderer/backend/vulkan/surface_context_vk.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ bool SurfaceContextVK::SetWindowSurface(vk::UniqueSurfaceKHR surface) {
6969
std::unique_ptr<Surface> SurfaceContextVK::AcquireNextSurface() {
7070
TRACE_EVENT0("impeller", __FUNCTION__);
7171
auto surface = swapchain_ ? swapchain_->AcquireNextDrawable() : nullptr;
72-
auto pipeline_library = parent_->GetPipelineLibrary();
73-
if (surface && pipeline_library) {
72+
if (!surface) {
73+
return nullptr;
74+
}
75+
if (auto pipeline_library = parent_->GetPipelineLibrary()) {
7476
impeller::PipelineLibraryVK::Cast(*pipeline_library)
7577
.DidAcquireSurfaceFrame();
7678
}
77-
auto allocator = parent_->GetResourceAllocator();
78-
if (allocator) {
79+
if (auto allocator = parent_->GetResourceAllocator()) {
7980
allocator->DidAcquireSurfaceFrame();
8081
}
8182
return surface;

impeller/renderer/backend/vulkan/swapchain_impl_vk.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,20 @@ SwapchainImplVK::AcquireResult SwapchainImplVK::AcquireNextDrawable() {
375375
nullptr // fence
376376
);
377377

378-
if (acq_result == vk::Result::eErrorOutOfDateKHR) {
379-
return AcquireResult{true /* out of date */};
380-
}
381-
382-
if (acq_result != vk::Result::eSuccess &&
383-
acq_result != vk::Result::eSuboptimalKHR) {
384-
VALIDATION_LOG << "Could not acquire next swapchain image: "
385-
<< vk::to_string(acq_result);
386-
return {};
378+
switch (acq_result) {
379+
case vk::Result::eSuccess:
380+
// Keep going.
381+
break;
382+
case vk::Result::eSuboptimalKHR:
383+
case vk::Result::eErrorOutOfDateKHR:
384+
// A recoverable error. Just say we are out of date.
385+
return AcquireResult{true /* out of date */};
386+
break;
387+
default:
388+
// An unrecoverable error.
389+
VALIDATION_LOG << "Could not acquire next swapchain image: "
390+
<< vk::to_string(acq_result);
391+
return AcquireResult{false /* out of date */};
387392
}
388393

389394
if (index >= images_.size()) {

0 commit comments

Comments
 (0)