mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-20 00:31:44 +00:00
metal: Add hint to select low power device instead of the default one (#8182)
On some system like MacBook Pro Intel with AMD card, asking for the default device will always return the AMD GPU. This is not an issue for 99% of the case when the renderer context is here to provide the maximum performance level like for game. However, for video application using GPU for 1 quad and 1 texture, using the discrete GPU for that lead to an important power consumption (4 to 8W), heat increase, and fan noise. With this patch, I successfully amend ffplay to only use the integrated GPU (i.e. the Intel one), instead of the discrete GPU (i.e. the AMD one).
This commit is contained in:

committed by
Sam Lantinga

parent
0b995f21e7
commit
aa7ba62978
@@ -1654,8 +1654,22 @@ static SDL_Renderer *METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// !!! FIXME: MTLCopyAllDevices() can find other GPUs on macOS...
|
||||
mtldevice = MTLCreateSystemDefaultDevice();
|
||||
#ifdef __MACOSX__
|
||||
if (SDL_GetHintBoolean(SDL_HINT_RENDER_METAL_PREFER_LOW_POWER_DEVICE, SDL_TRUE)) {
|
||||
NSArray<id<MTLDevice>> *devices = MTLCopyAllDevices();
|
||||
|
||||
for (id<MTLDevice> device in devices) {
|
||||
if (device.isLowPower) {
|
||||
mtldevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mtldevice == nil) {
|
||||
mtldevice = MTLCreateSystemDefaultDevice();
|
||||
}
|
||||
|
||||
if (mtldevice == nil) {
|
||||
SDL_free(renderer);
|
||||
|
Reference in New Issue
Block a user