[Impeller] removed collisions of dead command pools between tests. (flutter/engine#41490)

fixes https://github.com/flutter/flutter/issues/125321

Tests coverage from existing tests (see issue).

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I added new tests to check the change I am making or feature I am
adding, or Hixie said the PR is test-exempt. See [testing the engine]
for instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
gaaclarke
2023-04-26 10:23:28 -07:00
committed by GitHub
parent 3dad6c5612
commit 98718ceb9b
3 changed files with 19 additions and 5 deletions

View File

@@ -14,9 +14,11 @@
namespace impeller {
using CommandPoolMap =
std::map<const ContextVK*, std::shared_ptr<CommandPoolVK>>;
using CommandPoolMap = std::map<uint64_t, std::shared_ptr<CommandPoolVK>>;
// TODO(tbd): This is storing tons of CommandPoolVK's in the test runner since
// many contexts are created on the same thread. We need to come up
// with a different way to clean these up.
FML_THREAD_LOCAL fml::ThreadLocalUniquePtr<CommandPoolMap> tls_command_pool;
static Mutex g_all_pools_mutex;
@@ -33,7 +35,7 @@ std::shared_ptr<CommandPoolVK> CommandPoolVK::GetThreadLocal(
tls_command_pool.reset(new CommandPoolMap());
}
CommandPoolMap& pool_map = *tls_command_pool.get();
auto found = pool_map.find(context);
auto found = pool_map.find(context->GetHash());
if (found != pool_map.end() && found->second->IsValid()) {
return found->second;
}
@@ -41,7 +43,7 @@ std::shared_ptr<CommandPoolVK> CommandPoolVK::GetThreadLocal(
if (!pool->IsValid()) {
return nullptr;
}
pool_map[context] = pool;
pool_map[context->GetHash()] = pool;
{
Lock pool_lock(g_all_pools_mutex);
g_all_pools[context].push_back(pool);

View File

@@ -95,7 +95,16 @@ std::shared_ptr<ContextVK> ContextVK::Create(Settings settings) {
return context;
}
ContextVK::ContextVK() = default;
namespace {
thread_local uint64_t tls_context_count = 0;
uint64_t CalculateHash(void* ptr) {
// You could make a context once per nanosecond for 584 years on one thread
// before this overflows.
return ++tls_context_count;
}
} // namespace
ContextVK::ContextVK() : hash_(CalculateHash(this)) {}
ContextVK::~ContextVK() {
if (device_) {

View File

@@ -46,6 +46,8 @@ class ContextVK final : public Context, public BackendCast<ContextVK, Context> {
static std::shared_ptr<ContextVK> Create(Settings settings);
uint64_t GetHash() const { return hash_; }
// |Context|
~ContextVK() override;
@@ -134,6 +136,7 @@ class ContextVK final : public Context, public BackendCast<ContextVK, Context> {
std::shared_ptr<const Capabilities> device_capabilities_;
std::shared_ptr<FenceWaiterVK> fence_waiter_;
std::string device_name_;
const uint64_t hash_;
bool is_valid_ = false;