【问题标题】:How to request use of integrated GPU when using Metal API?使用 Metal API 时如何请求使用集成 GPU?
【发布时间】:2017-01-16 11:19:39
【问题描述】:

根据 Apple 文档,将键“NSSupportsAutomaticGraphicsSwitching”的值“YES”(或 true)添加到 OSX 应用程序的 Info.plist 文件时,将在双 GPU 系统上调用集成 GPU(而不是离散 GPU)。这很有用,因为集成的 GPU(虽然性能较低)足以满足我的应用程序的需求并且消耗更少的能量。

不幸的是,按照上述方法进行构建并随后检查 Activity Monitor(能量选项卡:“需要高性能 GPU”列)显示,我启用了 Metal API 的应用仍然使用离散 GPU,尽管请求了集成 GPU。

有什么方法可以提示 Metal 系统本身使用集成 GPU?

【问题讨论】:

    标签: macos cocoa objective-c++ metal


    【解决方案1】:

    问题在于 Metal API 默认使用离散 GPU。使用以下代码以及上面详述的正确 Info.plist 配置,可以使用集成 GPU:

        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();
    

    如果您使用的是 MTKView,请记住将 gpu_ 传递给它的 initWithFrame:device: 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-08
      • 1970-01-01
      • 2020-06-12
      • 2021-06-30
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      相关资源
      最近更新 更多