From cee2351c55e21bb6cc3246f7449ea631081e5a06 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Thu, 31 Jan 2019 17:35:18 +0000 Subject: [PATCH] Add config for vendor and device --- daemon/daemon_config.c | 18 ++++++++++++++++++ daemon/daemon_config.h | 2 ++ daemon/gamemode-gpu.c | 6 +++++- daemon/gpu-query.c | 4 ++-- daemon/gpu-query.h | 4 ++-- example/gamemode.ini | 4 ++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/daemon/daemon_config.c b/daemon/daemon_config.c index c9bd11a..f342254 100644 --- a/daemon/daemon_config.c +++ b/daemon/daemon_config.c @@ -77,6 +77,8 @@ struct GameModeConfig { long reaper_frequency; long apply_gpu_optimisations; + long gpu_vendor; + long gpu_device; long nv_core_clock_mhz_offset; long nv_mem_clock_mhz_offset; long amd_core_clock_percentage; @@ -183,6 +185,10 @@ static int inih_handler(void *user, const char *section, const char *name, const /* GPU subsection */ if (strcmp(name, "apply_gpu_optimisations") == 0) { valid = get_long_value(name, value, &self->apply_gpu_optimisations); + } else if (strcmp(name, "gpu_vendor") == 0) { + valid = get_long_value(name, value, &self->gpu_device); + } else if (strcmp(name, "gpu_device") == 0) { + valid = get_long_value(name, value, &self->gpu_device); } else if (strcmp(name, "nv_core_clock_mhz_offset") == 0) { valid = get_long_value(name, value, &self->nv_core_clock_mhz_offset); } else if (strcmp(name, "nv_mem_clock_mhz_offset") == 0) { @@ -254,6 +260,8 @@ static void load_config_files(GameModeConfig *self) self->reaper_frequency = DEFAULT_REAPER_FREQ; self->inhibit_screensaver = 1; /* Defaults to on */ self->apply_gpu_optimisations = 0; + self->gpu_vendor = 0; + self->gpu_device = 0; self->nv_core_clock_mhz_offset = 0; self->nv_mem_clock_mhz_offset = 0; self->amd_core_clock_percentage = 0; @@ -494,6 +502,16 @@ void config_get_apply_gpu_optimisations(GameModeConfig *self, long *value) memcpy_locked_config(self, value, &self->apply_gpu_optimisations, sizeof(long)); } +void config_get_gpu_vendor(GameModeConfig *self, long *value) +{ + memcpy_locked_config(self, value, &self->gpu_vendor, sizeof(long)); +} + +void config_get_gpu_device(GameModeConfig *self, long *value) +{ + memcpy_locked_config(self, value, &self->gpu_device, sizeof(long)); +} + void config_get_nv_core_clock_mhz_offset(GameModeConfig *self, long *value) { memcpy_locked_config(self, value, &self->nv_core_clock_mhz_offset, sizeof(long)); diff --git a/daemon/daemon_config.h b/daemon/daemon_config.h index 0253c28..21c9fd0 100644 --- a/daemon/daemon_config.h +++ b/daemon/daemon_config.h @@ -134,6 +134,8 @@ void config_get_ioprio_value(GameModeConfig *self, int *value); * Get various config info for gpu optimisations */ void config_get_apply_gpu_optimisations(GameModeConfig *self, long *value); +void config_get_gpu_vendor(GameModeConfig *self, long *value); +void config_get_gpu_device(GameModeConfig *self, long *value); void config_get_nv_core_clock_mhz_offset(GameModeConfig *self, long *value); void config_get_nv_mem_clock_mhz_offset(GameModeConfig *self, long *value); void config_get_amd_core_clock_percentage(GameModeConfig *self, long *value); diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index 386666f..d37e941 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -68,7 +68,11 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) GameModeGPUInfo *new_info = malloc(sizeof(GameModeGPUInfo)); memset(new_info, 0, sizeof(GameModeGPUInfo)); - // TODO: Fill in the GPU vendor and device + // TODO: Fill in the GPU vendor and device automatically + + /* Get the config parameters */ + config_get_gpu_vendor(config, &new_info->vendor); + config_get_gpu_device(config, &new_info->device); /* Load the config based on GPU */ switch (new_info->vendor) { diff --git a/daemon/gpu-query.c b/daemon/gpu-query.c index 7bf515c..0f6b2e2 100644 --- a/daemon/gpu-query.c +++ b/daemon/gpu-query.c @@ -49,7 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. * Get the gpu state * Populates the struct with the GPU info on the system */ -int get_gpu_state( struct GameModeGPUInfo* info ) +int get_gpu_state(struct GameModeGPUInfo *info) { return 0; } @@ -58,7 +58,7 @@ int get_gpu_state( struct GameModeGPUInfo* info ) * Set the gpu state based on input parameters * Only works when run as root */ -int set_gpu_state( struct GameModeGPUInfo* info ) +int set_gpu_state(struct GameModeGPUInfo *info) { return 0; } diff --git a/daemon/gpu-query.h b/daemon/gpu-query.h index cab5214..5c3eebc 100644 --- a/daemon/gpu-query.h +++ b/daemon/gpu-query.h @@ -52,10 +52,10 @@ struct GameModeGPUInfo { * Get the gpu state * Populates the struct with the GPU info on the system */ -int get_gpu_state( struct GameModeGPUInfo* info ); +int get_gpu_state(struct GameModeGPUInfo *info); /** * Set the gpu state based on input parameters * Only works when run as root */ -int set_gpu_state( struct GameModeGPUInfo* info ); +int set_gpu_state(struct GameModeGPUInfo *info); diff --git a/example/gamemode.ini b/example/gamemode.ini index f366e46..1a2f2a9 100644 --- a/example/gamemode.ini +++ b/example/gamemode.ini @@ -42,6 +42,10 @@ inhibit_screensaver=1 ; Setting this to 1 will allow gamemode to attempt to apply GPU optimisations such as overclocks ;apply_gpu_optimisations=0 +; Set these to specify which vendor and device ID you want apply optimisations to +;gpu_vendor=0x0000 +;gpu_device=0 + ; Nvidia specific settings (these are Mhz offsets from the baseline, ie. 0 applies no change) ;nv_core_clock_mhz_offset=0 ;nv_mem_clock_mhz_offset=0