[Impeller] Release a texture during Playground teardown (flutter/engine#45832)
Closes https://github.com/flutter/flutter/issues/134678. Partial work towards https://github.com/flutter/flutter/issues/133708, https://github.com/flutter/flutter/issues/133506. This gets us closer to being able to run `aiks_unittests` with validations enabled, removing a VMA allocation error: ## Before ```txt Note: Google Test filter = Play/AiksTest.ReleasesTextureOnTeardown/Vulkan [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from Play/AiksTest [ RUN ] Play/AiksTest.ReleasesTextureOnTeardown/Vulkan [INFO:capabilities_vk.cc(50)] Vulkan validations are enabled. [FATAL:third_party/vulkan_memory_allocator/include/vk_mem_alloc.h(6179)] Check failed: (false && "Unfreed dedicated allocations found!"). Vulkan Memory Allocator Failure! ``` ## After ```txt Note: Google Test filter = Play/AiksTest.ReleasesTextureOnTeardown/Vulkan [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from Play/AiksTest [ RUN ] Play/AiksTest.ReleasesTextureOnTeardown/Vulkan [INFO:capabilities_vk.cc(50)] Vulkan validations are enabled. [ OK ] Play/AiksTest.ReleasesTextureOnTeardown/Vulkan (1192 ms) [----------] 1 test from Play/AiksTest (1192 ms total) [----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (1192 ms total) [ PASSED ] 1 test. ``` --- Added a test that will catch regressions.
This commit is contained in:
@@ -23,6 +23,11 @@ void AiksPlayground::SetTypographerContext(
|
||||
typographer_context_ = std::move(typographer_context);
|
||||
}
|
||||
|
||||
void AiksPlayground::TearDown() {
|
||||
inspector_.HackResetDueToTextureLeaks();
|
||||
PlaygroundTest::TearDown();
|
||||
}
|
||||
|
||||
bool AiksPlayground::OpenPlaygroundHere(Picture picture) {
|
||||
return OpenPlaygroundHere([&picture](AiksContext& renderer) -> Picture {
|
||||
return std::move(picture);
|
||||
|
||||
@@ -22,6 +22,8 @@ class AiksPlayground : public PlaygroundTest {
|
||||
|
||||
~AiksPlayground();
|
||||
|
||||
void TearDown() override;
|
||||
|
||||
void SetTypographerContext(
|
||||
std::shared_ptr<TypographerContext> typographer_context);
|
||||
|
||||
|
||||
@@ -63,6 +63,10 @@ const std::optional<Picture>& AiksInspector::RenderInspector(
|
||||
return last_picture_;
|
||||
}
|
||||
|
||||
void AiksInspector::HackResetDueToTextureLeaks() {
|
||||
last_picture_.reset();
|
||||
}
|
||||
|
||||
static const auto kPropertiesProcTable = CaptureProcTable{
|
||||
.boolean =
|
||||
[](CaptureBooleanProperty& p) {
|
||||
|
||||
@@ -21,6 +21,17 @@ class AiksInspector {
|
||||
AiksContext& aiks_context,
|
||||
const std::function<std::optional<Picture>()>& picture_callback);
|
||||
|
||||
// Resets (releases) the underlying |Picture| object.
|
||||
//
|
||||
// Underlying issue: <https://github.com/flutter/flutter/issues/134678>.
|
||||
//
|
||||
// The tear-down code is not running in the right order; we still have a
|
||||
// reference to the |Picture| object when the |Context| is being destroyed,
|
||||
// which causes the |Texture| objects to leak.
|
||||
//
|
||||
// TODO(matanlurey): https://github.com/flutter/flutter/issues/134748.
|
||||
void HackResetDueToTextureLeaks();
|
||||
|
||||
private:
|
||||
void RenderCapture(CaptureContext& capture_context);
|
||||
void RenderCaptureElement(CaptureElement& element);
|
||||
|
||||
@@ -3409,5 +3409,38 @@ TEST_P(AiksTest, CaptureInactivatedByDefault) {
|
||||
ASSERT_FALSE(GetContext()->capture.IsActive());
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/134678.
|
||||
TEST_P(AiksTest, ReleasesTextureOnTeardown) {
|
||||
auto context = GetContext();
|
||||
std::weak_ptr<Texture> weak_texture;
|
||||
|
||||
{
|
||||
auto texture = CreateTextureForFixture("table_mountain_nx.png");
|
||||
|
||||
Canvas canvas;
|
||||
canvas.Scale(GetContentScale());
|
||||
canvas.Translate({100.0f, 100.0f, 0});
|
||||
|
||||
Paint paint;
|
||||
paint.color_source = ColorSource::MakeImage(
|
||||
texture, Entity::TileMode::kClamp, Entity::TileMode::kClamp, {}, {});
|
||||
canvas.DrawRect({0, 0, 600, 600}, paint);
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
// See https://github.com/flutter/flutter/issues/134751.
|
||||
//
|
||||
// If the fence waiter was working this may not be released by the end of the
|
||||
// scope above. Adding a manual shutdown so that future changes to the fence
|
||||
// waiter will not flake this test.
|
||||
context->Shutdown();
|
||||
|
||||
// The texture should be released by now.
|
||||
ASSERT_TRUE(weak_texture.expired()) << "When the texture is no longer in use "
|
||||
"by the backend, it should be "
|
||||
"released.";
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
Reference in New Issue
Block a user