Browse Source

Fill in the GPU vendor automatically

Marc Di Luzio 6 years ago
parent
commit
91deffb6b4
1 changed files with 21 additions and 6 deletions
  1. 21 6
      daemon/gamemode-gpu.c

+ 21 - 6
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,