diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index f57a165f00..c4c51634a7 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -1488,6 +1488,17 @@ extern "C" { */ #define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC" +/** + * \brief A variable controlling whether the Metal render driver select low power device over default one + * + * This variable can be set to the following values: + * "0" - Use the prefered OS device + * "1" - Select a low power one + * + * By default the prefered OS device is used. + */ +#define SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE "SDL_RENDER_METAL_PREFER_LOW_POWER_DEVICE" + /** * \brief A variable controlling if VSYNC is automatically disable if doesn't reach the enough FPS * diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index a83f982221..3f038f272d 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -1754,8 +1754,22 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window *window, Uint32 flags) return NULL; } - // !!! FIXME: MTLCopyAllDevices() can find other GPUs on macOS... - mtldevice = MTLCreateSystemDefaultDevice(); +#ifdef __MACOS__ + if (SDL_GetHintBoolean(SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE, SDL_TRUE)) { + NSArray> *devices = MTLCopyAllDevices(); + + for (id device in devices) { + if (device.isLowPower) { + mtldevice = device; + break; + } + } + } +#endif + + if (mtldevice == nil) { + mtldevice = MTLCreateSystemDefaultDevice(); + } if (mtldevice == nil) { SDL_free(renderer);