Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macos] Reland default metal and also check if the system supports metal before defaulting to it #24601

Merged

Conversation

iskakaushik
Copy link
Contributor

@iskakaushik iskakaushik commented Feb 24, 2021

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@iskakaushik iskakaushik force-pushed the reland-make-metal-default-macos branch from a3b67ee to b91185b Compare February 24, 2021 17:59
@iskakaushik iskakaushik changed the title [macos] Also check if the system supports metal before defaulting to it [macos] Reland default metal and also check if the system supports metal before defaulting to it Feb 24, 2021
#import <QuartzCore/QuartzCore.h>

@implementation FlutterRenderingBackend

+ (BOOL)renderUsingMetal {
if (@available(macOS 10.14, *)) {
return YES;
// Do not use MTLCreateSystemDefaultDevice() to check if not-null
// as that can force a mux switch to the discrete GPU.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little confused by this comment. If the only Metal-supporting GPU is the discrete GPU, then presumably this would happen anyway; you don't have any logic here to avoid using Metal if that GPU isn't already active.

Can you elaborate on what the intended behavior is for a multi-GPU device?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was to delay the switch from happening until absolutely needed. Which sounds a little premature in retrospect. I will remove change it to be MTLCreateSystemDefaultDevice(), this should be fine as that is (default device) indeed the device we use for rendering when there are multiple GPUs.

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'm not sure if the following scenario can happen, 2 GPUs one metal capable and the other isn't and MTLCreateSystemDefaultDevice returns nil as default device isn't capable of metal. This isn't ideal in that scenario, but we will need to address that more broadly.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM

#import <QuartzCore/QuartzCore.h>

@implementation FlutterRenderingBackend

+ (BOOL)renderUsingMetal {
if (@available(macOS 10.14, *)) {
return YES;
BOOL systemSupportsMetal = MTLCreateSystemDefaultDevice() != nil;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the intermediate variable, vs just returning the RHS directly?

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 adds more clarity to the reader IMO.

@iskakaushik iskakaushik merged commit aa00016 into flutter:master Feb 25, 2021
@iskakaushik iskakaushik deleted the reland-make-metal-default-macos branch February 25, 2021 11:49
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 25, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
chriscraws pushed a commit to chriscraws/engine that referenced this pull request Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants