seertaak
seertaak

Reputation: 1147

How to request use of integrated GPU when using Metal API?

According to Apple documentation, when adding the value "YES" (or true) for key "NSSupportsAutomaticGraphicsSwitching" to the Info.plist file for an OSX app, the integrated GPU will be invoked on dual-GPU systems (as opposed to the discrete GPU). This is useful as the integrated GPU -- while less performant -- is adequate for my app's needs and consumes less energy.

Unfortunately, building as per above and subsequently inspecting the Activity Monitor (Energy tab: "Requires High Perf GPU" column) reveals that my Metal API-enabled app still uses the discrete GPU, despite requesting the integrated GPU.

Is there any way I can give a hint to the Metal system itself to use the integrated GPU?

Upvotes: 2

Views: 874

Answers (1)

seertaak
seertaak

Reputation: 1147

The problem was that Metal API defaults to using the discrete GPU. Using the following code, along with the correct Info.plist configuration detailed above, results in the integrated GPU being used:

    NSArray<id<MTLDevice>> *devices = MTLCopyAllDevices();

    gpu_ = nil;

    // Low power device is sufficient - try to use it!
    for (id<MTLDevice> device in devices) {
        if (device.isLowPower) {
            gpu_ = device;
            break;
        }
    }

    // below: probably not necessary since there is always 
    // integrated GPU, but doesn't hurt.
    if (gpu_ == nil)
        gpu_ = MTLCreateSystemDefaultDevice();

If you're using an MTKView remember to pass gpu_ to the its initWithFrame:device: method.

Upvotes: 2

Related Questions