From 6aa20016ac8817b7b2be827d734b6d04aa06d3dd Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Thu, 21 Sep 2023 16:10:37 -0700 Subject: [PATCH] Revert #46131, don't store `vkImage`, reset `vkComandPool` synchronously (flutter/engine#46166) Closes https://github.com/flutter/flutter/issues/135086. Reverts https://github.com/flutter/engine/pull/46131. This PR bundles together 3 changes that removes all validation errors on the `macrobenchmark` apps I could manually find: 1. Reverts https://github.com/flutter/engine/pull/46131, which did not fix the original issue. 2. Added `kResetOnBackgroundThread = false`, which drops performance benefits, but doesn't cause threading issues. 3. Stop tracking `image` for Swapchain presentation (was hitting Vulkan assertion errors about acquired images). /cc @gaaclarke I'd love to talk about how we could run the macrobenchmarks app on CI, with validation errors, after landing. --- .../renderer/backend/vulkan/command_pool_vk.cc | 13 +++++++++---- .../renderer/backend/vulkan/surface_context_vk.cc | 1 + .../renderer/backend/vulkan/swapchain_impl_vk.cc | 9 +-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc index 6b72f1a923..2339ad3f74 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc @@ -56,6 +56,8 @@ class BackgroundCommandPoolVK final { std::weak_ptr recycler_; }; +static bool kResetOnBackgroundThread = false; + CommandPoolVK::~CommandPoolVK() { auto const context = context_.lock(); if (!context) { @@ -66,10 +68,13 @@ CommandPoolVK::~CommandPoolVK() { return; } - UniqueResourceVKT pool( - context->GetResourceManager(), - BackgroundCommandPoolVK(std::move(pool_), std::move(collected_buffers_), - recycler)); + auto reset_pool_when_dropped = BackgroundCommandPoolVK( + std::move(pool_), std::move(collected_buffers_), recycler); + + if (kResetOnBackgroundThread) { + UniqueResourceVKT pool( + context->GetResourceManager(), std::move(reset_pool_when_dropped)); + } } // TODO(matanlurey): Return a status_or<> instead of {} when we have one. diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/surface_context_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/surface_context_vk.cc index 88150f5ba7..2e20d2af5c 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/surface_context_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/surface_context_vk.cc @@ -80,6 +80,7 @@ std::unique_ptr SurfaceContextVK::AcquireNextSurface() { if (auto allocator = parent_->GetResourceAllocator()) { allocator->DidAcquireSurfaceFrame(); } + parent_->GetCommandPoolRecycler()->Dispose(); return surface; } diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc index 7a9ca108de..0af88001b8 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc @@ -424,13 +424,6 @@ bool SwapchainImplVK::Present(const std::shared_ptr& image, //---------------------------------------------------------------------------- /// Transition the image to color-attachment-optimal. /// - - // Increment the frame count right before allocating the cmd buffer below to - // force this to use the next frame's pool. This cmd buffer is completely - // untracked, and so we may end up resetting the cmd pool before all buffers - // have been collected. - context.GetCommandPoolRecycler()->Dispose(); - sync->final_cmd_buffer = context.CreateCommandBuffer(); if (!sync->final_cmd_buffer) { return false; @@ -477,7 +470,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr& image, } } - auto task = [&, index, image, current_frame = current_frame_] { + auto task = [&, index, current_frame = current_frame_] { auto context_strong = context_.lock(); if (!context_strong) { return;