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

[Impeller] Hold the CommandPoolVK at a higher scope. #46013

Merged
merged 2 commits into from
Sep 19, 2023
Merged
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
43 changes: 23 additions & 20 deletions impeller/renderer/backend/vulkan/command_pool_vk_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "flutter/testing/testing.h" // IWYU pragma: keep.
#include "fml/synchronization/waitable_event.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
#include "impeller/renderer/backend/vulkan/resource_manager_vk.h"
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"

Expand All @@ -13,26 +14,28 @@ namespace testing {
TEST(CommandPoolRecyclerVKTest, GetsACommandPoolPerThread) {
auto const context = MockVulkanContextBuilder().Build();

// Record the memory location of each pointer to a command pool.
int* pool1 = nullptr;
int* pool2 = nullptr;

// Create a command pool in two threads and record the memory location.
std::thread thread1([&]() {
auto const pool = context->GetCommandPoolRecycler()->Get();
pool1 = reinterpret_cast<int*>(pool.get());
});

std::thread thread2([&]() {
auto const pool = context->GetCommandPoolRecycler()->Get();
pool2 = reinterpret_cast<int*>(pool.get());
});

thread1.join();
thread2.join();

// The two command pools should be different.
EXPECT_NE(pool1, pool2);
{
// Record the memory location of each pointer to a command pool.
//
// These pools have to be held at this context, otherwise they will be
// dropped and recycled and potentially reused by another thread, causing
// flaky tests.
std::shared_ptr<CommandPoolVK> pool1;
std::shared_ptr<CommandPoolVK> pool2;

// Create a command pool in two threads and record the memory location.
std::thread thread1(
[&]() { pool1 = context->GetCommandPoolRecycler()->Get(); });

std::thread thread2(
[&]() { pool2 = context->GetCommandPoolRecycler()->Get(); });

thread1.join();
thread2.join();

// The two command pools should be different.
EXPECT_NE(pool1, pool2);
}

context->Shutdown();
}
Expand Down