[CP-stable][Impeller] Make ContextVK hash values globally unique (#171239)

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

### Issue Link:
What is the link to the issue this cherry-pick is addressing?

https://github.com/flutter/flutter/issues/170141

### Changelog Description:
Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples

Fixes an issue in the Impeller Vulkan back end that can cause crashes when transitioning between different Android activities that use Flutter.

### Impact Description:
What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch)

Potential crash in apps with multiple Android activities running Flutter with Impeller/Vulkan.

### Workaround:
Is there a workaround for this issue?

Disable Impeller

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
What are the steps to validate that this fix works?

The `appShortcutLaunchActivityAfterStarting` test for the `quick_actions_android` plugin will no longer crash on Firebase Test Lab after this fix is applied.  I don't know of a simpler way to manually verify the fix.
This commit is contained in:
flutteractionsbot
2025-07-07 15:00:17 -07:00
committed by GitHub
parent d779fc779d
commit 331c569830
2 changed files with 18 additions and 4 deletions

View File

@@ -119,11 +119,9 @@ size_t ContextVK::ChooseThreadCountForWorkers(size_t hardware_concurrency) {
}
namespace {
thread_local uint64_t tls_context_count = 0;
std::atomic_uint64_t 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;
return context_count.fetch_add(1);
}
} // namespace

View File

@@ -392,5 +392,21 @@ TEST(ContextVKTest, AHBSwapchainCapabilitiesCanBeMissing) {
} // namespace impeller
TEST(ContextVKTest, HashIsUniqueAcrossThreads) {
uint64_t hash1, hash2;
std::thread thread1([&]() {
auto context = MockVulkanContextBuilder().Build();
hash1 = context->GetHash();
});
std::thread thread2([&]() {
auto context = MockVulkanContextBuilder().Build();
hash2 = context->GetHash();
});
thread1.join();
thread2.join();
EXPECT_NE(hash1, hash2);
}
} // namespace testing
} // namespace impeller