Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
Add GPU power saver mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
fewtarius committed Apr 28, 2024
1 parent c30116d commit 7e807f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
24 changes: 19 additions & 5 deletions py_modules/gpu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def set_gpu_frequency(current_game_id):
except Exception as e:
decky_plugin.logger.error(f"{__name__} default mode error {e}")
return False
elif gpu_mode == GpuModes.POWERSAVE.value:
try:
with open(GPU_LEVEL_PATH,'w') as f:
f.write("low")
f.close()
return True
except Exception as e:
decky_plugin.logger.error(f"{__name__} powersaver mode error {e}")
return False
elif gpu_mode == GpuModes.RANGE.value:
new_min = tdp_profile.get(GpuRange.MIN.value, 0)
new_max = tdp_profile.get(GpuRange.MAX.value, 0)
Expand All @@ -70,11 +79,16 @@ def set_gpu_frequency_range(new_min: int, new_max: int):
if not (new_min >= min and new_max <= max and new_min <= new_max):
# invalid values, just change back to auto
# decky_plugin.logger.info(f'auto')

with open(GPU_LEVEL_PATH,'w') as f:
f.write("auto")
f.close()
return True
if (new_min == 0):
with open(GPU_LEVEL_PATH,'w') as f:
f.write("auto")
f.close()
return True
elif (new_min == -1):
with open(GPU_LEVEL_PATH,'w') as f:
f.write("low")
f.close()
return True
# decky_plugin.logger.info(f'manual')

with open(GPU_LEVEL_PATH,'w') as file:
Expand Down
3 changes: 2 additions & 1 deletion py_modules/plugin_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class GpuModes(Enum):
DEFAULT = "DEFAULT"
RANGE = "RANGE"
FIXED = "FIXED"
POWERSAVE = "POWERSAVE"

class GpuRange(Enum):
MIN = "minGpuFrequency"
MAX = "maxGpuFrequency"
FIXED = "fixedGpuFrequency"
FIXED = "fixedGpuFrequency"
5 changes: 5 additions & 0 deletions py_modules/plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def set_gpu_for_tdp_profile(tdp_profile):
if gpu_mode == 'DEFAULT':
set_gpu_frequency_range(0, 0)
return True
elif gpu_mode == 'POWERSAVE':
set_gpu_frequency_range(-1, -1)
return True
elif gpu_mode == 'FIXED' and fixed_frequency:
set_gpu_frequency_range(fixed_frequency, fixed_frequency)
return True
Expand Down Expand Up @@ -116,6 +119,8 @@ def persist_gpu(minGpuFrequency, maxGpuFrequency, game_id):

if minGpuFrequency == 0 and maxGpuFrequency == 0:
gpu_mode = 'DEFAULT'
elif minGpuFrequency == -1 and maxGpuFrequency == -1:
gpu_mode = 'POWERSAVE'
elif minGpuFrequency == maxGpuFrequency:
gpu_mode = 'FIXED'
profile_contents["fixedGpuFrequency"] = maxGpuFrequency
Expand Down
1 change: 1 addition & 0 deletions src/backend/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum GpuModes {
DEFAULT = "DEFAULT",
RANGE = "RANGE",
FIXED = "FIXED",
POWERSAVE = "POWERSAVE",
}

export enum ServerAPIMethods {
Expand Down
1 change: 1 addition & 0 deletions src/components/atoms/GpuModeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum Mode {
DEFAULT = 0,
RANGE = 1,
FIXED = 2,
POWERSAVE = 3,
}

const GpuModeSlider: FC<{ showSeparator: boolean }> = ({ showSeparator }) => {
Expand Down

0 comments on commit 7e807f5

Please sign in to comment.