Check environment variable to force integrated Metal device (#3757)

This commit is contained in:
Ben Doherty
2021-04-05 14:43:38 -07:00
committed by GitHub
parent 82fcb656d9
commit 9130ef5451

View File

@@ -55,7 +55,29 @@ MetalDriver::MetalDriver(backend::MetalPlatform* platform) noexcept
mPlatform(*platform),
mContext(new MetalContext) {
mContext->driver = this;
mContext->device = MTLCreateSystemDefaultDevice();
#if !defined(IOS)
const bool forceIntegrated =
NSProcessInfo.processInfo.environment[@"FILAMENT_FORCE_INTEGRATED_GPU"] != nil;
if (forceIntegrated) {
// Find the first low power device, which is likely the integrated GPU.
NSArray<id<MTLDevice>>* const devices = MTLCopyAllDevices();
for (id<MTLDevice> device in devices) {
if (device.isLowPower) {
mContext->device = device;
break;
}
}
} else
#endif
{
mContext->device = MTLCreateSystemDefaultDevice();
}
utils::slog.i << "Selected physical device '"
<< [mContext->device.name cStringUsingEncoding:NSUTF8StringEncoding] << "'"
<< utils::io::endl;
mContext->commandQueue = [mContext->device newCommandQueue];
mContext->commandQueue.label = @"Filament";
mContext->pipelineStateCache.setDevice(mContext->device);