Skip to content

Commit 665ebc9

Browse files
authored
Merge pull request #254 from XenHat/xenhat/gpu-string-cleanup
(Linux) Add method to remove the Mesa driver information from LastGPU…
2 parents 6ad538d + 34d88b9 commit 665ebc9

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

indra/newview/llfeaturemanager.cpp

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,64 @@ F32 logExceptionBenchmark()
403403
}
404404
#endif
405405

406+
/**
407+
* Removes the Mesa information from the GPU model string.
408+
*
409+
* The Mesa graphics utilities injects the current kernel name and version,
410+
* as well as Mesa's own name and version into the device name, which causes
411+
* several usability headaches when doing A/B testing across kernel and Mesa
412+
* releases, as the original behavior of the viewer is to reset the graphics
413+
* settings every time this string changes.
414+
* This function thus strips everything but the physical device information
415+
* from the string to greatly aid both the developer and the end user
416+
* experience.
417+
*
418+
* @param[out] device_name Contains the new GPU model string, after being cleaned if applicable.
419+
*/
420+
bool extractGLDeviceModel(std::string& device_name)
421+
{
422+
const std::string gl_string = ll_safe_string((const char*)(glGetString(GL_RENDERER)));
423+
#if LL_LINUX
424+
// Get the kernel version; essentially 'uname -r' on Linux
425+
// TODO: *BSD
426+
std::istringstream iss(LLOSInfo::instance().getOSString());
427+
std::string first, second;
428+
iss >> first >> second;
429+
const std::string kernel_version = (first == "Linux") ? second : "";
430+
431+
if (!kernel_version.empty())
432+
{
433+
LL_WARNS("RenderInit") << "Linux detected, performing GPU String cleanup!" << LL_ENDL;
434+
std::string new_gpu_string = gl_string;
435+
if (new_gpu_string.find(kernel_version) != std::string::npos)
436+
{
437+
LL_WARNS("RenderInit") << "GPU String contains the kernel version, removing" << LL_ENDL;
438+
// Strip the extra information on AMD adapters
439+
if (const size_t paren_pos = new_gpu_string.find('('); paren_pos != std::string::npos)
440+
{
441+
std::string result = new_gpu_string.substr(0, paren_pos);
442+
// Trim trailing whitespace
443+
result.erase(std::find_if(result.rbegin(), result.rend(),
444+
[](unsigned char c) { return !std::isspace(c); }).base(),
445+
result.end());
446+
new_gpu_string = result;
447+
}
448+
}
449+
// Strip leading 'Mesa' keyword on Intel adapters
450+
if (const size_t paren_pos = new_gpu_string.find("Mesa "); paren_pos != std::string::npos)
451+
{
452+
LL_WARNS("RenderInit") << "GPU String contains 'Mesa', removing" << LL_ENDL;
453+
std::string result = new_gpu_string.substr(5, std::string::npos);
454+
new_gpu_string = result;
455+
}
456+
device_name = new_gpu_string;
457+
return true;
458+
}
459+
#endif // LL_LINUX
460+
device_name = gl_string;
461+
return false;
462+
}
463+
406464
bool LLFeatureManager::loadGPUClass()
407465
{
408466
if (!gSavedSettings.getBOOL("SkipBenchmark"))
@@ -483,8 +541,10 @@ bool LLFeatureManager::loadGPUClass()
483541
mGPUClass = GPU_CLASS_1;
484542
}
485543

544+
if (extractGLDeviceModel(mGPUString)) {
545+
LL_INFOS("RenderInit") << "GPU String has been stripped of their driver identification" << LL_ENDL;
546+
}
486547
// defaults
487-
mGPUString = gGLManager.getRawGLString();
488548
mGPUSupported = true;
489549

490550
return true; // indicates that a gpu value was established

0 commit comments

Comments
 (0)