[macos] prefer integrated GPU. (#164569)
Attempted fix for https://github.com/flutter/flutter/issues/163218 There are very few macOS devices with multiple GPUs and they were only brielfy sold. We seem to have a problem o the specific devices when choosing the dedicated GPU. INstead, lets try forcing the integrated GPU when its available.
This commit is contained in:
parent
b771b39813
commit
ccf99229c7
@ -38,10 +38,26 @@ static bool OnAcquireExternalTexture(void* user_data,
|
|||||||
FlutterDarwinContextMetalSkia* _darwinMetalContext;
|
FlutterDarwinContextMetalSkia* _darwinMetalContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Attempts to find the integrated GPU backed metal device.
|
||||||
|
//
|
||||||
|
// See also: https://developer.apple.com/documentation/metal/multi-gpu-systems?language=objc
|
||||||
|
id<MTLDevice> SelectMetalDevice() {
|
||||||
|
NSArray<id<MTLDevice>>* devices = MTLCopyAllDevices();
|
||||||
|
for (id<MTLDevice> device in devices) {
|
||||||
|
if (device.hasUnifiedMemory) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MTLCreateSystemDefaultDevice();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
- (instancetype)initWithFlutterEngine:(nonnull FlutterEngine*)flutterEngine {
|
- (instancetype)initWithFlutterEngine:(nonnull FlutterEngine*)flutterEngine {
|
||||||
self = [super initWithDelegate:self engine:flutterEngine];
|
self = [super initWithDelegate:self engine:flutterEngine];
|
||||||
if (self) {
|
if (self) {
|
||||||
_device = MTLCreateSystemDefaultDevice();
|
_device = SelectMetalDevice();
|
||||||
if (!_device) {
|
if (!_device) {
|
||||||
NSLog(@"Could not acquire Metal device.");
|
NSLog(@"Could not acquire Metal device.");
|
||||||
return nil;
|
return nil;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user