Skip to content

Instantly share code, notes, and snippets.

@kssreeram
Created February 21, 2021 17:11
Show Gist options
  • Save kssreeram/533086a1972da68d45ff0fca564565e6 to your computer and use it in GitHub Desktop.
Save kssreeram/533086a1972da68d45ff0fca564565e6 to your computer and use it in GitHub Desktop.
Prefer integrated GPU
diff --git a/sokol/sokol_app.h b/sokol/sokol_app.h
index 0115970..149c336 100644
--- a/sokol/sokol_app.h
+++ b/sokol/sokol_app.h
@@ -3016,7 +3016,17 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) {
_sapp.macos.win_dlg = [[_sapp_macos_window_delegate alloc] init];
_sapp.macos.window.delegate = _sapp.macos.win_dlg;
#if defined(SOKOL_METAL)
- _sapp.macos.mtl_device = MTLCreateSystemDefaultDevice();
+ id<MTLDevice> chosen = nil;
+ for (id<MTLDevice> device in MTLCopyAllDevices()) {
+ if (device.isLowPower) {
+ chosen = device;
+ break;
+ }
+ }
+ if (!chosen) {
+ chosen = MTLCreateSystemDefaultDevice();
+ }
+ _sapp.macos.mtl_device = chosen;
_sapp.macos.view = [[_sapp_macos_view alloc] init];
[_sapp.macos.view updateTrackingAreas];
_sapp.macos.view.preferredFramesPerSecond = 60 / _sapp.swap_interval;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment