| 1047 | } |
| 1048 | |
| 1049 | void parseGPUConfigFile(ExtendedSettings* pExtendedSettings, uint32_t preferedGpuId) |
| 1050 | { |
| 1051 | FileStream fh = {}; |
| 1052 | if (!fsOpenStreamFromPath(RD_GPU_CONFIG, "gpu.cfg", FM_READ, &fh)) |
| 1053 | { |
| 1054 | LOGF(LogLevel::eERROR, "Failed to open gpu.cfg file. Function %s failed with error: %s", FS_ERR_CTX.func, |
| 1055 | getFSErrCodeString(FS_ERR_CTX.code)); |
| 1056 | LOGF(LogLevel::eWARNING, "Setting first gpu found as active gpu."); |
| 1057 | return; |
| 1058 | } |
| 1059 | ConfigParsingStatus parsingStatus = ConfigParsingStatus::CONFIG_PARSE_NONE; |
| 1060 | char currentLineStr[1024] = {}; |
| 1061 | gGraphicsConfigRules.mDriverRejectionRules = |
| 1062 | (DriverRejectionRule*)tf_malloc(MAXIMUM_GPU_CONFIGURATION_RULES * sizeof(DriverRejectionRule)); |
| 1063 | gGraphicsConfigRules.mGPUConfigurationRulesCount = 0; |
| 1064 | gGraphicsConfigRules.mDriverRejectionRulesCount = 0; |
| 1065 | gGraphicsConfigRules.mGPUSelectionRulesCount = 0; |
| 1066 | gGraphicsConfigRules.mTextureSupportRulesCount = 0; |
| 1067 | gGraphicsConfigRules.mExtendedConfigurationRulesCount = 0; |
| 1068 | |
| 1069 | size_t fileSize = fsGetStreamFileSize(&fh); |
| 1070 | char* fileBuffer = (char*)tf_malloc(fileSize * sizeof(char)); |
| 1071 | fsReadFromStream(&fh, fileBuffer, fileSize); |
| 1072 | char* fileCursor = fileBuffer; |
| 1073 | char* fileEnd = fileBuffer + fileSize; |
| 1074 | while (bufferedGetLine(currentLineStr, &fileCursor, fileEnd)) |
| 1075 | { |
| 1076 | char* lineCursor = currentLineStr; |
| 1077 | // skip spaces, empty line and comments |
| 1078 | size_t ruleLength = strcspn(lineCursor, "#"); |
| 1079 | const char* pLineEnd = lineCursor + ruleLength; |
| 1080 | while (currentLineStr != pLineEnd && isspace(*lineCursor)) |
| 1081 | ++lineCursor; |
| 1082 | if (lineCursor == pLineEnd) |
| 1083 | continue; |
| 1084 | |
| 1085 | // parse configuration rules and settings |
| 1086 | switch (parsingStatus) |
| 1087 | { |
| 1088 | case ConfigParsingStatus::CONFIG_PARSE_NONE: |
| 1089 | if (strcmp(currentLineStr, "BEGIN_GPU_SELECTION;") == 0) |
| 1090 | { |
| 1091 | parsingStatus = ConfigParsingStatus::CONFIG_PARSE_SELECTION_RULE; |
| 1092 | } |
| 1093 | else if (strcmp(currentLineStr, "BEGIN_DRIVER_REJECTION;") == 0) |
| 1094 | { |
| 1095 | parsingStatus = ConfigParsingStatus::CONFIG_PARSE_DRIVER_REJECTION; |
| 1096 | } |
| 1097 | else if (strcmp(currentLineStr, "BEGIN_GPU_SETTINGS;") == 0) |
| 1098 | { |
| 1099 | parsingStatus = ConfigParsingStatus::CONFIG_PARSE_GPU_CONFIGURATION; |
| 1100 | } |
| 1101 | else if (strcmp(currentLineStr, "BEGIN_TEXTURE_FORMAT;") == 0) |
| 1102 | { |
| 1103 | parsingStatus = ConfigParsingStatus::CONFIG_PARSE_TEXTURE_FORMAT; |
| 1104 | } |
| 1105 | else if (strcmp(currentLineStr, "BEGIN_RESOLUTION_SETTINGS;") == 0) |
| 1106 | { |
no test coverage detected