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

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented May 26, 2023

Fixes flutter/flutter#126878

This disables device private upload on iOS when backgrounded, and disables mipmap generation when backgrounded.

We don't have a good way to test the core problem in this repo because it only reproduces on physical iOS hardware - simulators don't really care if you do this stuff in the background.

I'll write a devicelab test in the framework to capture this. In the mean time it can be reviewed.

We could consider making the IOManager a shared_ptr instead of having an fml::WeakPtr and that'd clean up some of the extra arguments to engine construction - or we could consider vending the sync switch from impeller::Context unconditionally, but it's pretty iOS specific...

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Looks good for the most part. The only thing that should get changed is removing the conditional compilation. I think we should treat sync_switch as a nonnull parameter instead. Also, I want clarity in for the true branches of the syncswitches. We should have comments that at least explain their omission.

FML_DLOG(ERROR) << decode_error;
return std::make_pair(nullptr, decode_error);
std::optional<std::string> decode_error;
#if FML_OS_IOS
Copy link
Member

Choose a reason for hiding this comment

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

Other platforms also have a sync switch that is never switched off, so there's no need to introduce conditional compilation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, that will actually make this more testable too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can refactor UploadToPrivate to work more nicely if we're on iOS.

return std::make_pair(nullptr, decode_error);
std::optional<std::string> decode_error;
#if FML_OS_IOS
gpu_disabled_switch->Execute(fml::SyncSwitch::Handlers().SetIfFalse(
Copy link
Member

Choose a reason for hiding this comment

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

Should the true branch be setting decode_error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No - added a comment. We only need to do this unconditionally for GL,and we'll always unconditionally do it for GL.

Copy link
Member

Choose a reason for hiding this comment

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

We ripped out opengl for iOS right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct

std::shared_ptr<fml::ConcurrentTaskRunner> concurrent_task_runner,
fml::WeakPtr<IOManager> io_manager);
fml::WeakPtr<IOManager> io_manager,
const std::shared_ptr<fml::SyncSwitch>& gpu_disabled_switch = nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

Everyone should have a syncswitch so there's no need to support nullptr.

[&needs_upload, &image, &decode_error, &context,
&bitmap_result] {
needs_upload = false;
FML_LOG(ERROR) << "Yay";
Copy link
Member

Choose a reason for hiding this comment

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

Stray log.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(removed the one below too)

#endif
FML_DCHECK(gpu_disabled_switch);
if (gpu_disabled_switch) {
gpu_disabled_switch->Execute(fml::SyncSwitch::Handlers().SetIfFalse(
Copy link
Member

Choose a reason for hiding this comment

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

It's worth adding a comment about the omission of a true branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This got moved and there's no longer an omission.

@dnfield
Copy link
Contributor Author

dnfield commented May 26, 2023

Added a test.

Ideally this would get a screenshot based test on a real device, but that will probably take some more time to write. For now the test I added validates that if the sync switch is disabled we do not create any command buffers.

@dnfield dnfield requested a review from gaaclarke May 26, 2023 17:22
result = UnsafeUploadTextureToPrivate(context, buffer, image_info);
})
.SetIfTrue([&result, context, bitmap, gpu_disabled_switch] {
// create_mips is false because we already know the GPU is disabled.
Copy link
Member

Choose a reason for hiding this comment

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

Can't this result in suboptimal rendering based on when the gpu is disabled? Are we going to get bug reports about blurry images that we can't source back to coming from backgrounded apps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can result in suboptimal rendering. We could choose to build mips when the GPU is available again, but that's going to be a more invasive/risky change. I'd like this to be cherry pickable.

return std::make_pair(nullptr, decode_error);
std::optional<std::string> decode_error;
#if FML_OS_IOS
gpu_disabled_switch->Execute(fml::SyncSwitch::Handlers().SetIfFalse(
Copy link
Member

Choose a reason for hiding this comment

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

We ripped out opengl for iOS right?

/*font_collection=*/std::make_shared<FontCollection>(),
/*runtime_controller=*/std::move(runtime_controller_));
/*runtime_controller=*/std::move(runtime_controller_),
/*gpu_disabled_switch=*/nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

nit: make syncswitches here since technically it isn't supposed to be null. We could also add a dcheck that it isn't null.

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

return;
}
command_buffer->WaitUntilScheduled();
}));
Copy link
Member

Choose a reason for hiding this comment

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

This isn't something we should solve now, but we'll eventually need a solution to defer generating mipmaps. Not generating mipmaps will cause min filtered images to continue appearing more blurry than Skia once we start properly setting the mip bias.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return;
}
blit_pass->SetLabel("Mipmap Blit Pass");
blit_pass->GenerateMipmap(texture);
Copy link
Member

Choose a reason for hiding this comment

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

The texture.NeedsMipmapGeneration() check also needs to be removed from render_pass_mtl.mm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we change that to a DLOG on iOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ifdef'd it out for IOS.

Copy link
Member

@bdero bdero May 26, 2023

Choose a reason for hiding this comment

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

I think we need to rethink these safety checks in general and have the HAL be less opinionated about it. While it's unsafe for GLES and probably worth tracking in some way, fully mipmapped textures can be uploaded and/or single mip levels can be replaced individually (albeit, Impeller doesn't support this yet). One example is storing radiance maps for image based lighting.

@dnfield dnfield requested a review from bdero May 26, 2023 18:03
Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

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

LGTM

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2023
@auto-submit auto-submit bot merged commit 882703b into flutter:main May 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 26, 2023
@dnfield dnfield deleted the decode_safe branch May 26, 2023 20:16
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 26, 2023
…127702)

flutter/engine@858d975...eed12f3

2023-05-26 [email protected] Started executing vulkan unit tests with validation on macos (flutter/engine#42337)
2023-05-26 [email protected] [Impeller] Avoid encoding metal commands while the GPU is unavailable when decoding images. (flutter/engine#42349)

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 [email protected],[email protected],[email protected] 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request May 29, 2023
Issue: flutter/flutter#126878

Picks in #42349 and #42175

The reason for the second is that the first creates many more conflicts without it, and resolving them was a lot easier. The second PR is also very low risk and improves error messaging.
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Images becomes pink when launching from background

3 participants