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

Conversation

@gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented Oct 12, 2023

Design doc: link
fixes: flutter/flutter#135245

One slight deviation from the design doc is that I decided to make ContextMTL respond to changes to the SyncSwitch instead of having it observe the app state directly. The benefits are:

  1. This keeps that functionality in one location
  2. It makes writing tests much easier
  3. There's no need of conditional compilation between macos and ios
  4. There is no need to add an objc class

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • 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 the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

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

@gaaclarke gaaclarke force-pushed the retry-tobytedata2 branch 2 times, most recently from 556afdd to 234fcd7 Compare October 13, 2023 16:18
@gaaclarke gaaclarke marked this pull request as ready for review October 13, 2023 20:18

void ContextMTL::StoreTaskForGPU(std::function<void()> task) {
tasks_awaiting_gpu_.emplace_back(std::move(task));
while (tasks_awaiting_gpu_.size() > kMaxTasksAwaitingGPU) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a maximum limit of tasks? If we do have a limit, do we need a mechanism to drop them gracefully?

For example, if there is a Future pending from toByteData, I'd think that dropping the task should cause an error to be thrown?

Copy link
Member Author

Choose a reason for hiding this comment

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

EncodeImageFailsWithoutGPUImpeller tests this, it's handled gracefully since you have to check for the GPU in the callback and we never retry more than once. Getting dropped is just like the behavior we had before we implemented the retry.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, so when we exceed the size we execute the task, and then the task sees the GPU is still unavailable and errors? makes sense. I would document that a bit.

Copy link
Member Author

@gaaclarke gaaclarke Oct 13, 2023

Choose a reason for hiding this comment

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

Added that info to the Context::StoreTaskForGPU docstring.

Comment on lines 86 to 118
if (!status.ok()) {
if (status.code() == fml::StatusCode::kUnavailable) {
impeller_context->StoreTaskForGPU(
[dl_image, encode_task = std::move(encode_task),
is_gpu_disabled_sync_switch, impeller_context,
retry_runner]() mutable {
auto retry_task = [dl_image, encode_task = std::move(encode_task),
is_gpu_disabled_sync_switch, impeller_context] {
fml::Status retry_status = DoConvertImageToRasterImpeller(
dl_image, encode_task, is_gpu_disabled_sync_switch,
impeller_context);
if (!retry_status.ok()) {
encode_task(retry_status);
}
};
if (retry_runner) {
retry_runner->PostTask(retry_task);
} else {
retry_task();
}
});
} else {
encode_task(status);
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is a little hard to read. Are we dropping the status here in the event its not OK and the code isn't unavailable, or does that percolate up elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some comments. Let me know if you think this is the right amount and if it is helpful.


/// The maximum number of tasks that should ever be stored for
/// `StoreTaskForGPU`.
static constexpr int32_t kMaxTasksAwaitingGPU = 10;
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh by the way. I'm open to increasing this. I just pulled this number out of nowhere but I knew I didn't want it to be completely unbounded.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave a note that this was arbitrarily chosen so we're not afraid to increase it in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@gaaclarke
Copy link
Member Author

Turns out some tests were using nullptr for the syncswitch when it shouldn't. I've updated the test. Those tests are a pain to debug.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 16, 2023
@auto-submit auto-submit bot merged commit 6b262a0 into flutter:main Oct 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 16, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 16, 2023
…136665)

flutter/engine@ca8cf6b...c24f303

2023-10-16 skia-flutter-autoroll@skia.org Roll Skia from 675f088b9ac4 to 68de6e352585 (1 revision) (flutter/engine#46956)
2023-10-16 30870216+gaaclarke@users.noreply.github.com [Impeller] implements a retry mechanism for dart:ui/Image.toByteData. (flutter/engine#46840)
2023-10-16 jason-simmons@users.noreply.github.com [Impeller] Adjust clip coverage operations to handle per-pass clip stacks (flutter/engine#46912)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
…#46840)

Design doc: [link](https://docs.google.com/document/d/1Uuiw3pdQxNFTA8OQuZ-kuvYg1NB42XgccQCZeqr4oII/edit#heading=h.hn6wreyrz6fm)
fixes: flutter/flutter#135245

One slight deviation from the design doc is that I decided to make ContextMTL respond to changes to the SyncSwitch instead of having it observe the app state directly.  The benefits are:
1) This keeps that functionality in one location
1) It makes writing tests much easier
1) There's no need of conditional compilation between macos and ios
1) There is no need to add an objc class

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App e: impeller platform-ios

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

[Impeller] Image.toByteData throws when the app goes to background.

2 participants