MCPcopy Create free account
hub / github.com/ConfettiFX/The-Forge / parseGPUDataFile

Function parseGPUDataFile

Common_3/Graphics/GraphicsConfig.cpp:895–1047  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

893}
894
895void parseGPUDataFile()
896{
897 gDefaultPresetLevel = GPUPresetLevel::GPU_PRESET_LOW;
898
899 FileStream fh = {};
900 if (!fsOpenStreamFromPath(RD_OTHER_FILES, "gpu.data", FM_READ, &fh))
901 {
902 LOGF(LogLevel::eERROR, "Failed to open gpu.data file. Function %s failed with error: %s", FS_ERR_CTX.func,
903 getFSErrCodeString(FS_ERR_CTX.code));
904 LOGF(LogLevel::eWARNING, "Setting preset will be set to Low as a default.");
905 return;
906 }
907 DataParsingStatus parsingStatus = DataParsingStatus::DATA_PARSE_NONE;
908 char currentLineStr[1024] = {};
909 gGPUVendorCount = 0;
910 char* gpuListBeginFileCursor = nullptr;
911 char* gpuListEndFileCursor = nullptr;
912
913 size_t fileSize = fsGetStreamFileSize(&fh);
914 char* gpuDataFileBuffer = (char*)tf_malloc(fileSize * sizeof(char));
915 fsReadFromStream(&fh, (void*)gpuDataFileBuffer, fileSize);
916 char* fileCursor = gpuDataFileBuffer;
917 char* gGpuDataFileEnd = gpuDataFileBuffer + fileSize;
918 char* previousLineCursor = fileCursor;
919
920 if (bufferedGetLine(currentLineStr, &fileCursor, gGpuDataFileEnd))
921 {
922 uint32_t versionMajor = 0;
923 uint32_t versionMinor = 0;
924 int read = sscanf(currentLineStr, "version:%u.%u", &versionMajor, &versionMinor);
925 if (read != 2)
926 {
927 LOGF(eINFO, "Ill-formatted gpu.data file. Missing version at beginning of file");
928 fsCloseStream(&fh);
929 tf_free(gpuDataFileBuffer);
930 return;
931 }
932 else if (versionMajor != GPUCFG_VERSION_MAJOR || versionMinor != GPUCFG_VERSION_MINOR)
933 {
934 LOGF(eINFO, "gpu.data version mismatch. Expected version %u.%u but got %u.%u", GPUCFG_VERSION_MAJOR, GPUCFG_VERSION_MINOR,
935 versionMajor, versionMinor);
936 fsCloseStream(&fh);
937 tf_free(gpuDataFileBuffer);
938 return;
939 }
940 }
941
942 while (bufferedGetLine(currentLineStr, &fileCursor, gGpuDataFileEnd))
943 {
944 char* lineCursor = currentLineStr;
945 // skip spaces, empty line and comments
946 size_t ruleLength = strcspn(lineCursor, "#");
947 const char* pLineEnd = lineCursor + ruleLength;
948 while (currentLineStr != pLineEnd && isspace(*lineCursor))
949 {
950 ++lineCursor;
951 }
952 if (lineCursor == pLineEnd)

Callers 1

addGPUConfigurationRulesFunction · 0.85

Calls 12

fsOpenStreamFromPathFunction · 0.85
getFSErrCodeStringFunction · 0.85
fsGetStreamFileSizeFunction · 0.85
tf_mallocFunction · 0.85
fsReadFromStreamFunction · 0.85
bufferedGetLineFunction · 0.85
fsCloseStreamFunction · 0.85
tf_freeFunction · 0.85
parseGPUVendorLineFunction · 0.85
parseGPUModelLineFunction · 0.85
presetLevelToStringFunction · 0.85

Tested by

no test coverage detected