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

Remove #if SHELL_ENABLE_METAL checks in iOS code #51636

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Mar 22, 2024

All physical iOS devices Flutter supports (iOS 12+) can run Metal. The only time Flutter doesn't use Metal afaik is for iOS simulators running < iOS 13, which is covered by a few if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) checks.

#if TARGET_OS_SIMULATOR
#define METAL_IOS_VERSION_BASELINE 13.0
#else
#define METAL_IOS_VERSION_BASELINE 10.0
#endif // TARGET_OS_SIMULATOR

Remove hardware checks for physical devices.

Remove shell_enable_metal from the gn files and the #if SHELL_ENABLE_METAL checks in the iOS embedder.

I limited this PR to just iOS, but I imagine it's safe to remove shell_enable_metal everywhere?

enable_metal = shell_enable_metal

engine/tools/gn

Lines 673 to 679 in 41da00a

if sys.platform == 'darwin' and args.target_os not in ['android', 'fuchsia']:
# OpenGL is deprecated on macOS > 10.11.
# This is not necessarily needed but enabling this until we have a way to
# build a macOS metal only shell and a gl only shell.
gn_args['allow_deprecated_api_calls'] = True
gn_args['skia_use_metal'] = True
gn_args['shell_enable_metal'] = True

@jmagman jmagman self-assigned this Mar 22, 2024
@jmagman jmagman marked this pull request as ready for review April 4, 2024 03:59
@jmagman jmagman requested review from chinmaygarde and cbracken April 4, 2024 04:00
@cbracken
Copy link
Member

cbracken commented Apr 4, 2024

I imagine it's safe to remove shell_enable_metal everywhere?

I removed GL support from the macOS embedder and we don't have the software compositing fallback in that embedder, so should be safe to remove anything in the mac embedder if it still exists.

Does the iOS embedder still support software rendering? I know we used to use it for simulators, but IIRC those moved to Metal. Or was simulator Metal adoption limited to arm64 macs?

#include "flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h"
#include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h"
#endif // SHELL_ENABLE_METAL
#include "flutter/shell/platform/darwin/ios/ios_context_software.h"
Copy link
Member

Choose a reason for hiding this comment

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

Curious what this is still used for.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

I suspect that all devices/simulators have metal support, but if so, I'd think we should be able to kill off the software rasterisation fallback. It seems a little contradictory to require metal but also support the software fallback.

lgtm modulo that question (and the question below as to whether we're still using it on simulators on intel).

@jmagman
Copy link
Member Author

jmagman commented Apr 4, 2024

I know we used to use it for simulators, but IIRC those moved to Metal. Or was simulator Metal adoption limited to arm64 macs?

The only time Flutter doesn't use Metal afaik is for iOS simulators running < iOS 13 #17881. However, I think to run an iOS 12 simulator you need an older version of Xcode than the current one, which itself needs to be run on an older version of macOS. It is still possible though with that setup.

#if TARGET_OS_SIMULATOR
#define METAL_IOS_VERSION_BASELINE 13.0
#else
#define METAL_IOS_VERSION_BASELINE 10.0
#endif // TARGET_OS_SIMULATOR

@jmagman
Copy link
Member Author

jmagman commented Apr 4, 2024

The only time Flutter doesn't use Metal afaik is for iOS simulators running < iOS 13 #17881.

Oh also when software rendering is "forced" for simulators, forgot about that. Used for... scubas?

@jmagman
Copy link
Member Author

jmagman commented Apr 4, 2024

I'd think we should be able to kill off the software rasterisation fallback

I think we may need to continue to support softrware rendering until the Skia fallback is removed in favor of Impeller. #44346

FML_CHECK(backend != IOSRenderingBackend::kImpeller)
<< "Software rendering is incompatible with Impeller.\n"
"Software rendering may have been automatically selected when running on a simulator "
"in an environment that does not support Metal. Enabling GPU pass through in your "
"environment may fix this. If that is not possible, then disable Impeller.";

@bdero is that a true statement?

@cbracken
Copy link
Member

cbracken commented Apr 4, 2024

I think to run an iOS 12 simulator you need an older version of Xcode than the current one, which itself needs to be run on an older version of macOS. It is still possible though with that setup.

Is that still a supported deployment target? If not, I'm all for scrub scrub scrub.

Oh also when software rendering is "forced" for simulators, forgot about that. Used for... scubas?

It's possible/likely it's changed since 2016 when @goderbauer and I wrote the original scuba support but I think at that point we were using the exact same underlying mechanism for screenshotting the tool uses -- i.e. wiring through the call to [NSView drawLayer:inContext:].

But now that you mention it, maybe we did force software rasterisation? Something about reproducible results? i.e. the same reason we run our GPU screenshot tests through SwiftShader in engine tests? The sad part is I think we'd need to work that out from the code, cause 2016 is definitely further back than I clearly remember, and either way, so much has changed that even if I could, the chance it still applies is near 0%.

@jmagman
Copy link
Member Author

jmagman commented Apr 4, 2024

Is that still a supported deployment target? If not, I'm all for scrub scrub scrub.

Technically yes, iOS 12 is the minimum supported. Though it is really tricky getting that simulator installed. We can rip out support next year when Apple (likely) drops support for it.

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 4, 2024
@auto-submit auto-submit bot merged commit e3104af into flutter:main Apr 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 4, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 4, 2024
…146300)

flutter/engine@fa4d97e...e3104af

2024-04-04 [email protected] Remove #if SHELL_ENABLE_METAL checks in iOS code (flutter/engine#51636)
2024-04-04 [email protected] Roll Skia from d58a6dbaaadb to f9dfb0308594 (1 revision) (flutter/engine#51913)

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://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
@jmagman jmagman deleted the enable-metal branch April 4, 2024 23:32
@jmagman
Copy link
Member Author

jmagman commented Apr 5, 2024

Used for... scubas?

Sigh, yes, scubas. Reverting.
b/333039358

@jmagman jmagman added the revert Label used to revert changes in a closed and merged pull request. label Apr 5, 2024
Copy link
Contributor

auto-submit bot commented Apr 5, 2024

A reason for requesting a revert of flutter/engine/51636 could
not be found or the reason was not properly formatted. Begin a comment with 'Reason for revert:' to tell the bot why
this issue is being reverted.

@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Apr 5, 2024
@jmagman
Copy link
Member Author

jmagman commented Apr 5, 2024

Reason for revert: This caused a slew of unexpected Scuba changes b/333039358

@jmagman jmagman added the revert Label used to revert changes in a closed and merged pull request. label Apr 5, 2024
auto-submit bot pushed a commit that referenced this pull request Apr 5, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Apr 5, 2024
auto-submit bot added a commit that referenced this pull request Apr 5, 2024
…51941)

Reverts: #51636
Initiated by: jmagman
Reason for reverting: This caused a slew of unexpected Scuba changes b/333039358
Original PR Author: jmagman

Reviewed By: {cbracken}

This change reverts the following previous change:
All physical iOS devices Flutter supports (iOS 12+) can run Metal.  The only time Flutter doesn't use Metal afaik is for iOS simulators running < iOS 13, which is covered by a few `if (@available(iOS METAL_IOS_VERSION_BASELINE, *))` checks.

https://github.com/flutter/engine/blob/8a51e124fbf168295a1b05f8d66459bfb29ae8a9/shell/platform/darwin/ios/rendering_api_selection.h#L37-L41

Remove hardware checks for physical devices.

Remove `shell_enable_metal` from the gn files and the `#if SHELL_ENABLE_METAL` checks in the iOS embedder.

I limited this PR to just iOS, but I imagine it's safe to remove `shell_enable_metal` everywhere? 
https://github.com/flutter/engine/blob/41da00ac46bc38a97a63ed0635450271d71afd9f/shell/platform/darwin/macos/BUILD.gn#L18
https://github.com/flutter/engine/blob/41da00ac46bc38a97a63ed0635450271d71afd9f/tools/gn#L673-L679
@@ -18,18 +16,6 @@

namespace flutter {

#if SHELL_ENABLE_METAL
bool ShouldUseMetalRenderer() {
Copy link
Member

@jonahwilliams jonahwilliams Apr 5, 2024

Choose a reason for hiding this comment

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

Removing this is likely what broke the google3 test harness. Despite running on a version of iOS sim that is required to support metal - due to the lack of supported GPU passthrough (and in defiance of all that is holy), creation of the MTLDevice will fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, I'll fix it up. Thank you for looking at it!

jmagman added a commit to jmagman/engine that referenced this pull request Apr 5, 2024
All physical iOS devices Flutter supports (iOS 12+) can run Metal.  The only time Flutter doesn't use Metal afaik is for iOS simulators running < iOS 13, which is covered by a few `if (@available(iOS METAL_IOS_VERSION_BASELINE, *))` checks.

https://github.com/flutter/engine/blob/8a51e124fbf168295a1b05f8d66459bfb29ae8a9/shell/platform/darwin/ios/rendering_api_selection.h#L37-L41

Remove hardware checks for physical devices.

Remove `shell_enable_metal` from the gn files and the `#if SHELL_ENABLE_METAL` checks in the iOS embedder.

I limited this PR to just iOS, but I imagine it's safe to remove `shell_enable_metal` everywhere? 
https://github.com/flutter/engine/blob/41da00ac46bc38a97a63ed0635450271d71afd9f/shell/platform/darwin/macos/BUILD.gn#L18
https://github.com/flutter/engine/blob/41da00ac46bc38a97a63ed0635450271d71afd9f/tools/gn#L673-L679
auto-submit bot pushed a commit that referenced this pull request Apr 8, 2024
Same as #51636 except:

1. The original change caused scuba changes because those simulators are running on Macs without GPU passthrough, and so fallback to software rendering when `MTLCreateSystemDefaultDevice()` fails.  Re-add that `MTLCreateSystemDefaultDevice` check

https://github.com/flutter/engine/pull/51636/files#diff-1db60a8a74c1cfb40c970541dd1f7f0f6301853a2ba17451f5117f154036d732L22-L31

2. Set `enable_metal` to always true for `macos/BUILD.gn`
 
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
…lutter#146300)

flutter/engine@fa4d97e...e3104af

2024-04-04 [email protected] Remove #if SHELL_ENABLE_METAL checks in iOS code (flutter/engine#51636)
2024-04-04 [email protected] Roll Skia from d58a6dbaaadb to f9dfb0308594 (1 revision) (flutter/engine#51913)

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://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
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 platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants