Commit f6eeca4a authored by Roman Sedaikin's avatar Roman Sedaikin

More smart choosing graphics card.

parent a53d21ba
......@@ -381,6 +381,7 @@ tasks.withType(LinkSharedLibrary::class.java).configureEach {
"-framework", "CoreServices",
"-framework", "CoreText",
"-framework", "Foundation",
"-framework", "IOKit",
"-framework", "Metal",
"-framework", "OpenGL",
"-framework", "QuartzCore" // for CoreAnimation
......
......@@ -13,6 +13,11 @@
#import <mtl/GrMtlBackendContext.h>
#import <mtl/GrMtlTypes.h>
#define MuxGraphicsCard 7
#define kOpen 0
#define kGetMuxState 3
#define kDriverClassName "AppleGraphicsControl"
@interface AWTMetalLayer : CAMetalLayer
@property jobject javaRef;
......@@ -100,22 +105,52 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skiko_redrawer_MetalRedrawer_makeMeta
return (jlong) renderTarget;
}
id<MTLDevice> MTLCreateIntegratedDevice() {
NSArray<id<MTLDevice>> *devices = MTLCopyAllDevices();
BOOL isUsingIntegratedGPU() {
kern_return_t kernResult = 0;
io_iterator_t iterator = IO_OBJECT_NULL;
io_service_t service = IO_OBJECT_NULL;
kernResult = IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching(kDriverClassName), &iterator);
assert(kernResult == KERN_SUCCESS);
service = IOIteratorNext(iterator);
io_connect_t switcherConnect;
kernResult = IOServiceOpen(service, mach_task_self(), 0, &switcherConnect);
assert(kernResult == KERN_SUCCESS);
kernResult = IOConnectCallScalarMethod(switcherConnect, kOpen, NULL, 0, NULL, NULL);
assert(kernResult == KERN_SUCCESS);
uint64_t output;
uint32_t outputCount = 1;
uint64_t scalarI_64[2] = { 1, MuxGraphicsCard };
kernResult = IOConnectCallScalarMethod(switcherConnect,
kGetMuxState,
scalarI_64,
2,
&output,
&outputCount);
return output != 0;
}
id<MTLDevice> MTLCreateIntegratedDevice() {
BOOL isIntegratedGPU = isUsingIntegratedGPU();
id<MTLDevice> gpu = nil;
if (isIntegratedGPU) {
NSArray<id<MTLDevice>> *devices = MTLCopyAllDevices();
for (id<MTLDevice> device in devices) {
if (device.isLowPower) {
gpu = device;
break;
}
}
}
if (gpu == nil) {
gpu = MTLCreateSystemDefaultDevice();
}
return gpu;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment