123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "gpu-control.h"
- #include "logging.h"
- #include <stdio.h>
- enum GPUVendor gamemode_get_gpu_vendor(long device)
- {
- enum GPUVendor vendor = Vendor_Invalid;
-
- char path[64] = { 0 };
- if (snprintf(path, 64, "/sys/class/drm/card%ld/device/vendor", device) < 0) {
- LOG_ERROR("snprintf failed, will not apply gpu optimisations!\n");
- return Vendor_Invalid;
- }
- FILE *file = fopen(path, "r");
- if (!file) {
- LOG_ERROR("Couldn't open vendor file at %s, will not apply gpu optimisations!\n", path);
- return Vendor_Invalid;
- }
- char buff[64];
- bool got_line = fgets(buff, 64, file) != NULL;
- fclose(file);
- if (got_line) {
- vendor = strtol(buff, NULL, 0);
- } else {
- LOG_ERROR("Coudn't read contents of file %s, will not apply optimisations!\n", path);
- return Vendor_Invalid;
- }
-
- if (!GPUVendorValid(vendor)) {
- LOG_ERROR("Unknown vendor value (0x%04x) found, cannot apply optimisations!\n",
- (unsigned int)vendor);
- LOG_ERROR("Known values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n",
- (unsigned int)Vendor_NVIDIA,
- (unsigned int)Vendor_AMD,
- (unsigned int)Vendor_Intel);
- return Vendor_Invalid;
- }
- return vendor;
- }
|