CodySchrank / gSwitch

macOS menu bar app that allows control over the gpu on dual gpu macbooks
MIT License
887 stars 46 forks source link

Increased command-line functionality #51

Closed JayBrown closed 4 years ago

JayBrown commented 4 years ago

First off: thank you for this great piece of software! Long time gfxCardStatus user here.

I'm inquiring about the possibilty of a standalone (and slightly expanded) command-line functionality. The reason is this bug in the IINA media player, more precisely in the underlying mpv player. It will probably not be fixed for some time, if at all, so it would be great to have a gswitch CLI to (a) read the current state of the GPU (dynamic switching on/off, integrated or discrete), and (b) the ability to set a new GPU state (or lock the current state by disabling dynamic switching) without launching a new instance of the gSwitch GUI app.

Then we could create an IINA launcher app with AppleScript that would disable dynamic switching before launching IINA itself.

CLI possible?

EDIT: no, strike that. It's not important… just tested this with a "hungry" process, while set to integrated-only, and macOS switches to the dGPU for a brief amount of time, then switches back to the iGPU, and the mpv bug returns. So gSwitch won't be able to help in this matter.

CodySchrank commented 4 years ago

macOS will always trigger the dgpu when a process has gpu acceleration. gSwitch simply detects this had occurred and switches back to the igpu as fast as possible when integrated only is selected. When you run gswitch from the command line you can see the triggers.

Disabling dynamic switching would simply use the dgpu. Does the bug occur on dgpu or igpu? or both?

CodySchrank commented 4 years ago

@JayBrown I skimmed through the thread you reference I think I understand the bug now. If you want to play around with gpu states you can run sudo pmset -b gpuswitch 0 sudo pmset -b gpuswitch 1 sudo pmset -b gpuswitch 2

Which is like a hard switch to the igpu, dgpu, and dynamic switch, respectively. These have nothing to do with gswitch they are internal commands of pmset. They change functionality of the power management settings so be careful with the commands you run.

JayBrown commented 4 years ago

That's some great info, thank you.

Is there a way to read which GPU is currently in use? iGPU or dGPU?

You can read the current battery status with pmset -g batt | head -1 | awk '{print $4}' | sed "s/'//", and the current pm setting with pmset -g | awk '/^ gpuswitch/{print $2}'. If pm is set to 0 or 1, it's clear that it's either the iGPU or the dGPU, but neither command will show you which GPU is actually in use, if pm is set to 2 (dynamic switching).

JayBrown commented 4 years ago

By the way, if you switch to the iGPU or the dGPU with the pmset command, gSwitch doesn't respond, and in the menu the tick doesn't jump from "Dynamic Switching" to "Integrated Only" or "Discrete Only".

CodySchrank commented 4 years ago

Yea I know. pmset is too low level it doesn't trigger the same events that gswitch looks for. Honestly I have no idea how to read the current active gpu with pmset when pm is set to 2, not a whole lot of documentation on it.

CodySchrank commented 4 years ago

@JayBrown gSwitch has an advanced pane that might help you debug in preferences -> advanced. If you pass 3 or 7 in get gpu state that should show you the active gpu even with pmset.