diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index 21b341c..2ae3374 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -73,9 +73,6 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) /* Get the config parameters */ new_info->device = config_get_gpu_device(config); - /* TODO fill in GPU vendor */ - new_info->vendor = 0; - /* verify device ID */ if (new_info->device == -1) { LOG_ERROR( @@ -85,11 +82,29 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) return -1; } + /* Fill in GPU vendor */ + char path[64] = { 0 }; + if (snprintf(path, 64, "/sys/class/drm/card%ld/device/vendor", new_info->device) < 0) { + LOG_ERROR("snprintf failed, will not apply gpu optimisations!\n"); + return -1; + } + FILE *vendor = fopen(path, "r"); + if (!vendor) { + LOG_ERROR("Couldn't open vendor file at %s, will not apply gpu optimisations!\n", path); + return -1; + } + char buff[64]; + if (fgets(buff, 64, vendor) != NULL) { + new_info->vendor = strtol(buff, NULL, 0); + } else { + LOG_ERROR("Coudn't read contents of file %s, will not apply optimisations!\n", path); + return -1; + } + /* verify GPU vendor */ if (!GPUVendorValid(new_info->vendor)) { - LOG_ERROR( - "Unknown vendor value (0x%04x) found, cannot apply optimisations!\n", - (unsigned int)new_info->vendor); + LOG_ERROR("Unknown vendor value (0x%04x) found, cannot apply optimisations!\n", + (unsigned int)new_info->vendor); LOG_ERROR("Known values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n", Vendor_NVIDIA, Vendor_AMD,