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

Purge resources on rasterizer teardown #33890

Merged
merged 10 commits into from
Jun 8, 2022

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Jun 7, 2022

This should normally happen when the GrDirectContext is collected, but for various reasons that may not happen or it may take longer to achieve. Roughly speaking, this can happen in an Android app that:

  • Renders some scene that causes resource cache occupation
  • Gets dismissed in a state where the resource cache has purgeable bytes
  • Preserves the Flutter Engine/Dart VM for some time after that, in some way where the GrDirectContext does not get collected

Adds a test that causes the Skia resource cache to become occupied, and then asserts that it has purgeable bytes before teardown and no purgeable bytes after teardown.

Fixes flutter/flutter#105453 - the context may still be retained, but the app will no longer suffer from retaining purgeable cache memory.

@@ -76,7 +77,7 @@ class MockExternalViewEmbedder : public ExternalViewEmbedder {
} // namespace

TEST(RasterizerTest, create) {
MockDelegate delegate;
NiceMock<MockDelegate> delegate;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are not essential to this patch, but eliminate a lot of noise when running these test targets related to unexpected mock function calls.

@dnfield
Copy link
Contributor Author

dnfield commented Jun 7, 2022

@goderbauer FYI - not sure what impact this might have on multi-window

@dnfield
Copy link
Contributor Author

dnfield commented Jun 7, 2022

(looking into test failures...)

@dnfield
Copy link
Contributor Author

dnfield commented Jun 8, 2022

The ShellTest vulkan related tests are crashing because they can't find libvulkan.so - it's not part of this build and isn't available on CI AFAICT.

They pass before this change because no calls are made that actually touch the rendering backend, but now tearing down the rasterizer may trigger such calls.

@dnfield
Copy link
Contributor Author

dnfield commented Jun 8, 2022

I'm not sure about the FEMU failures. The test that's timing out is ShellTest.ReportTimingsIsCalled. I do see in the log that libvulkan.so is failing to transfer over to the device - but I wouldn't expect that to make this particular test fail. See https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8811953693866211137/+/u/FEMU_Test/test:_Run_FEMU_Test_Suite_shell_tests/stdout#L34492_0

@akbiggs do you have any ideas about how to debug this further? I do see something in the test file about tests with similar names being skipped (but those tests don't exist anymore). The test is just timing out and getting killed. One other possibility is that the new call in rasterizer teardown is somehow deadlocking...

if (auto* context = surface_->GetContext()) {
context->purgeUnlockedResources(/*scratchResourcesOnly=*/false);
}
}
}

surface_.reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can move the surface_.reset() into the if (surface_) block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 8, 2022
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Linux Fuchsia FEMU has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 8, 2022
@dnfield
Copy link
Contributor Author

dnfield commented Jun 8, 2022

FEMU failures seem to be related to trying to use swiftshader on FEMU. Using system libvulkan seems to be making more progress... here's hoping.

@@ -8,6 +8,16 @@
#include "flutter/shell/common/context_options.h"
#include "flutter/vulkan/vulkan_utilities.h"

#if OS_FUCHSIA
#define VULKAN_SO_PATH "libvulkan.so"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akbiggs FYI

@dnfield dnfield added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jun 8, 2022
@fluttergithubbot fluttergithubbot merged commit d7ef306 into flutter:main Jun 8, 2022
@dnfield dnfield deleted the rasterizer_cache branch June 9, 2022 00:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GrContext may be getting retained after rasterizer teardown on Android
3 participants