Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions impeller/renderer/backend/vulkan/descriptor_pool_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "flutter/testing/testing.h" // IWYU pragma: keep.
#include "fml/closure.h"
#include "fml/synchronization/waitable_event.h"
#include "impeller/renderer/backend/vulkan/descriptor_pool_vk.h"
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
Expand All @@ -23,27 +24,6 @@ TEST(DescriptorPoolRecyclerVKTest, GetDescriptorPoolRecyclerCreatesNewPools) {
context->Shutdown();
}

namespace {

// Invokes the provided callback when the destructor is called.
//
// Can be moved, but not copied.
class DeathRattle final {
public:
explicit DeathRattle(std::function<void()> callback)
: callback_(std::move(callback)) {}

DeathRattle(DeathRattle&&) = default;
DeathRattle& operator=(DeathRattle&&) = default;

~DeathRattle() { callback_(); }

private:
std::function<void()> callback_;
};

} // namespace

TEST(DescriptorPoolRecyclerVKTest, ReclaimMakesDescriptorPoolAvailable) {
auto const context = MockVulkanContextBuilder().Build();

Expand All @@ -64,10 +44,10 @@ TEST(DescriptorPoolRecyclerVKTest, ReclaimMakesDescriptorPoolAvailable) {
// destroyed. That should give us a non-flaky signal that the pool has been
// reclaimed as well.
auto waiter = fml::AutoResetWaitableEvent();
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
{
UniqueResourceVKT<DeathRattle> resource(context->GetResourceManager(),
std::move(rattle));
UniqueResourceVKT<fml::ScopedCleanupClosure> resource(
context->GetResourceManager(), std::move(rattle));
}
waiter.Wait();
}
Expand Down Expand Up @@ -98,10 +78,10 @@ TEST(DescriptorPoolRecyclerVKTest, ReclaimDropsDescriptorPoolIfSizeIsExceeded) {
// See note above.
for (auto i = 0u; i < 2; i++) {
auto waiter = fml::AutoResetWaitableEvent();
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
{
UniqueResourceVKT<DeathRattle> resource(context->GetResourceManager(),
std::move(rattle));
UniqueResourceVKT<fml::ScopedCleanupClosure> resource(
context->GetResourceManager(), std::move(rattle));
}
waiter.Wait();
}
Expand All @@ -126,10 +106,10 @@ TEST(DescriptorPoolRecyclerVKTest, ReclaimDropsDescriptorPoolIfSizeIsExceeded) {

for (auto i = 0u; i < 2; i++) {
auto waiter = fml::AutoResetWaitableEvent();
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
{
UniqueResourceVKT<DeathRattle> resource(context->GetResourceManager(),
std::move(rattle));
UniqueResourceVKT<fml::ScopedCleanupClosure> resource(
context->GetResourceManager(), std::move(rattle));
}
waiter.Wait();
}
Expand Down
27 changes: 4 additions & 23 deletions impeller/renderer/backend/vulkan/resource_manager_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <functional>
#include <memory>
#include <utility>
#include "fml/closure.h"
#include "fml/synchronization/waitable_event.h"
#include "gtest/gtest.h"
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
Expand All @@ -20,39 +21,19 @@ TEST(ResourceManagerVKTest, CreatesANewInstance) {
EXPECT_NE(a, b);
}

namespace {

// Invokes the provided callback when the destructor is called.
//
// Can be moved, but not copied.
class DeathRattle final {
public:
explicit DeathRattle(std::function<void()> callback)
: callback_(std::move(callback)) {}

DeathRattle(DeathRattle&&) = default;
DeathRattle& operator=(DeathRattle&&) = default;

~DeathRattle() { callback_(); }

private:
std::function<void()> callback_;
};

} // namespace

TEST(ResourceManagerVKTest, ReclaimMovesAResourceAndDestroysIt) {
auto const manager = ResourceManagerVK::Create();

auto waiter = fml::AutoResetWaitableEvent();
auto dead = false;
auto rattle = DeathRattle([&waiter]() { waiter.Signal(); });
auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });

// Not killed immediately.
EXPECT_FALSE(waiter.IsSignaledForTest());

{
auto resource = UniqueResourceVKT<DeathRattle>(manager, std::move(rattle));
auto resource = UniqueResourceVKT<fml::ScopedCleanupClosure>(
manager, std::move(rattle));
}

waiter.Wait();
Expand Down