commit 61601587295f6d0ef1c4084530fe0318e0c72b16
parent 26c6b2579543e928158fa7d3c00d8b0e04ac270c
Author: Chris Schultz <christopher.schultz@auth0.com>
Date: Fri, 5 Apr 2019 14:08:20 -0500
devdraw: prefer low-power GPU for macOS metal rendering (#231)
Diffstat:
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/cmd/devdraw/cocoa-screen-metal.m b/src/cmd/devdraw/cocoa-screen-metal.m
@@ -153,6 +153,7 @@ threadmain(int argc, char **argv)
id<MTLLibrary> library;
MTLRenderPipelineDescriptor *pipelineDesc;
NSError *error;
+ NSArray *allDevices;
const NSWindowStyleMask Winstyle = NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable
@@ -197,8 +198,18 @@ threadmain(int argc, char **argv)
[win setContentView:myContent];
[myContent setWantsLayer:YES];
[myContent setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawOnSetNeedsDisplay];
-
- device = MTLCreateSystemDefaultDevice();
+
+ device = nil;
+ allDevices = MTLCopyAllDevices();
+ for(id mtlDevice in allDevices) {
+ if ([mtlDevice isLowPower] && ![mtlDevice isRemovable]) {
+ device = mtlDevice;
+ break;
+ }
+ }
+ if(!device)
+ device = MTLCreateSystemDefaultDevice();
+
commandQueue = [device newCommandQueue];
layer = (DrawLayer *)[myContent layer];