[Question] Is it possible to set SDL2 to use integrated graphics only?

Hi, I’m wondering if there is a way for SDL2 to use e.g. Intel graphics card only under a hybrid graphic cards system (specifically macOS). Someone mentioned the use of gfxCardStatus to force use of integrated graphics but apparently when running the SDL2 program, it gets switched back to use discrete graphics card. Does anybody know if it’s feasible? Thanks!

Same question here. Did you have any luck?

Assuming you are using the SDL renderer and the metal backend specifically, you’re out of luck as SDL_render_metal.m invokes MTLCreateSystemDefaultDevice directly to assign the device (and also has a “FIXME” note indicating that MTLCopyAllDevices can be used to identify other GPUs available on MacOS).

If you’re creating an OpenGL backend (which I believe you can enforce on Mac for the time being until OpenGL is deprecated), you can try passing the SDL_RENDERER_SOFTWARE flag when creating a renderer although performance will be worse for obvious reasons.

In general, you can set NSSupportsAutomaticGraphicsSwitching in your Info.plist and stay on the integrated GPU.

This explains the various complications:

http://supermegaultragroovy.com/2016/12/10/auto-graphics-switching/

SDL already specifies NSOpenGLPFAAllowOfflineRenderers when creating GL contexts on the Mac, which means it just needs you to add the Info.plist setting to get the Mac to select the integrated GPU

Don’t switch to the software renderer (on the Mac, we will still use OpenGL to get the software-rendered pixels to the screen, which not only means you used the CPU to render and the discrete GPU to display it, but it’ll likely be slower than just using the integrated GPU for this due to bus transfers.

Metal is a whole different story, but that’s only for a (at the moment) non-default 2D render API backend.

And long may it remain “non-default”! :slight_smile:

Sadly, it’s probably the best way to get at the GPU on a Mac, so it’ll become the default sooner than later in SDL. Naturally, it’ll fallback to OpenGL if it finds itself running on a Mac or iPhone without Metal support. I’m not thrilled with Apple’s behavior here, but this is the situation they’ve put everyone in.

Mostly we’ve been waiting for it to stabilize, and Alex did a ton of work on it, so we’re probably just about there now.

The default in Windows isn’t OpenGL either, so I override it with:

SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");

So long as that works in MacOS too I’ll be content, which I presume it will unless and until Apple actually remove OpenGL.

1 Like

Yeah, we absolutely won’t remove it.

And since we dynamically load OpenGL, even if the libraries are literally removed from the OS, we can still support older systems and a theoretical port of Mesa that uses Metal behind the scenes to provide a GL interface at some point in the future.

For SDL apps which are usually ok with integrated, but might want discrete in some modes (i.e. certain screen filters), is there a way to switch to the discrete GPU at runtime?