mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-05 04:34:19 +01:00
Chore: run clang-format
```bash find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i ```
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
#include "common/library.h"
|
||||
#include "mtml.h"
|
||||
|
||||
struct FFMtmlData
|
||||
{
|
||||
struct FFMtmlData {
|
||||
FF_LIBRARY_SYMBOL(mtmlDeviceCountGpuCores)
|
||||
FF_LIBRARY_SYMBOL(mtmlDeviceGetBrand)
|
||||
FF_LIBRARY_SYMBOL(mtmlDeviceGetIndex)
|
||||
@@ -26,21 +25,18 @@ struct FFMtmlData
|
||||
FF_LIBRARY_SYMBOL(mtmlLibraryShutDown)
|
||||
|
||||
bool inited;
|
||||
MtmlLibrary *lib;
|
||||
MtmlSystem *sys;
|
||||
MtmlLibrary* lib;
|
||||
MtmlSystem* sys;
|
||||
} mtmlData;
|
||||
|
||||
FF_MAYBE_UNUSED static void shutdownMtml(void)
|
||||
{
|
||||
FF_MAYBE_UNUSED static void shutdownMtml(void) {
|
||||
mtmlData.ffmtmlLibraryShutDown(mtmlData.lib);
|
||||
}
|
||||
|
||||
const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDriverResult result, const char *soName)
|
||||
{
|
||||
const char* ffDetectMthreadsGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName) {
|
||||
#ifndef FF_DISABLE_DLOPEN
|
||||
|
||||
if (!mtmlData.inited)
|
||||
{
|
||||
if (!mtmlData.inited) {
|
||||
mtmlData.inited = true;
|
||||
FF_LIBRARY_LOAD(libmtml, "dlopen mtml failed", soName, 1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libmtml, mtmlLibraryInit)
|
||||
@@ -64,13 +60,11 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libmtml, mtmlData, mtmlMemoryGetUtilization)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libmtml, mtmlData, mtmlLibraryShutDown)
|
||||
|
||||
if (ffmtmlLibraryInit(&mtmlData.lib) != MTML_SUCCESS)
|
||||
{
|
||||
if (ffmtmlLibraryInit(&mtmlData.lib) != MTML_SUCCESS) {
|
||||
mtmlData.ffmtmlLibraryInitSystem = NULL;
|
||||
return "mtmlLibraryInit failed";
|
||||
}
|
||||
if (mtmlData.ffmtmlLibraryInitSystem(mtmlData.lib, &mtmlData.sys) != MTML_SUCCESS)
|
||||
{
|
||||
if (mtmlData.ffmtmlLibraryInitSystem(mtmlData.lib, &mtmlData.sys) != MTML_SUCCESS) {
|
||||
mtmlData.ffmtmlLibraryShutDown(mtmlData.lib);
|
||||
mtmlData.ffmtmlLibraryInitSystem = NULL;
|
||||
return "mtmlLibraryInitSystem failed";
|
||||
@@ -79,124 +73,121 @@ const char *ffDetectMthreadsGpuInfo(const FFGpuDriverCondition *cond, FFGpuDrive
|
||||
libmtml = NULL; // don't close mtml
|
||||
}
|
||||
|
||||
if (mtmlData.ffmtmlLibraryInitSystem == NULL)
|
||||
if (mtmlData.ffmtmlLibraryInitSystem == NULL) {
|
||||
return "loading mtml library failed";
|
||||
}
|
||||
|
||||
MtmlDevice *device = NULL;
|
||||
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
|
||||
{
|
||||
MtmlDevice* device = NULL;
|
||||
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID) {
|
||||
char pciBusIdStr[32];
|
||||
snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
|
||||
|
||||
MtmlReturn ret = mtmlData.ffmtmlLibraryInitDeviceByPciSbdf(mtmlData.lib, pciBusIdStr, &device);
|
||||
if (ret != MTML_SUCCESS)
|
||||
if (ret != MTML_SUCCESS) {
|
||||
return "mtmlLibraryInitDeviceByPciSbdf() failed";
|
||||
}
|
||||
else if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID)
|
||||
{
|
||||
}
|
||||
} else if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID) {
|
||||
uint32_t count;
|
||||
if (mtmlData.ffmtmlLibraryCountDevice(mtmlData.lib, &count) != MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlLibraryCountDevice(mtmlData.lib, &count) != MTML_SUCCESS) {
|
||||
return "mtmlLibraryCountDevice() failed";
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < count; i++, device = NULL)
|
||||
{
|
||||
if (mtmlData.ffmtmlLibraryInitDeviceByIndex(mtmlData.lib, i, &device) != MTML_SUCCESS)
|
||||
for (uint32_t i = 0; i < count; i++, device = NULL) {
|
||||
if (mtmlData.ffmtmlLibraryInitDeviceByIndex(mtmlData.lib, i, &device) != MTML_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MtmlPciInfo pciInfo;
|
||||
if (mtmlData.ffmtmlDeviceGetPciInfo(device, &pciInfo) != MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlDeviceGetPciInfo(device, &pciInfo) != MTML_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pciInfo.pciDeviceId != ((cond->pciDeviceId.deviceId << 16u) | cond->pciDeviceId.vendorId) ||
|
||||
pciInfo.pciSubsystemId != cond->pciDeviceId.subSystemId)
|
||||
pciInfo.pciSubsystemId != cond->pciDeviceId.subSystemId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
if (!device)
|
||||
if (!device) {
|
||||
return "Device not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
} else {
|
||||
return "Unknown condition type";
|
||||
}
|
||||
|
||||
MtmlBrandType brand;
|
||||
if (mtmlData.ffmtmlDeviceGetBrand(device, &brand) == MTML_SUCCESS)
|
||||
{
|
||||
switch (brand)
|
||||
{
|
||||
case MTML_BRAND_MTT:
|
||||
*result.type = FF_GPU_TYPE_DISCRETE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (mtmlData.ffmtmlDeviceGetBrand(device, &brand) == MTML_SUCCESS) {
|
||||
switch (brand) {
|
||||
case MTML_BRAND_MTT:
|
||||
*result.type = FF_GPU_TYPE_DISCRETE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.index)
|
||||
{
|
||||
if (result.index) {
|
||||
unsigned int value;
|
||||
if (mtmlData.ffmtmlDeviceGetIndex(device, &value) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlDeviceGetIndex(device, &value) == MTML_SUCCESS) {
|
||||
*result.index = value;
|
||||
}
|
||||
|
||||
if (result.temp)
|
||||
{
|
||||
MtmlGpu *gpu = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitGpu(device, &gpu) == MTML_SUCCESS)
|
||||
{
|
||||
uint32_t value;
|
||||
if (mtmlData.ffmtmlGpuGetTemperature(gpu, &value) == MTML_SUCCESS)
|
||||
*result.temp = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.memory)
|
||||
{
|
||||
MtmlMemory *mem = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitMemory(device, &mem) == MTML_SUCCESS)
|
||||
{
|
||||
if (result.temp) {
|
||||
MtmlGpu* gpu = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitGpu(device, &gpu) == MTML_SUCCESS) {
|
||||
uint32_t value;
|
||||
if (mtmlData.ffmtmlGpuGetTemperature(gpu, &value) == MTML_SUCCESS) {
|
||||
*result.temp = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.memory) {
|
||||
MtmlMemory* mem = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitMemory(device, &mem) == MTML_SUCCESS) {
|
||||
unsigned long long total;
|
||||
if (mtmlData.ffmtmlMemoryGetTotal(mem, &total) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlMemoryGetTotal(mem, &total) == MTML_SUCCESS) {
|
||||
result.memory->total = total;
|
||||
}
|
||||
|
||||
unsigned long long used;
|
||||
if (mtmlData.ffmtmlMemoryGetUsed(mem, &used) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlMemoryGetUsed(mem, &used) == MTML_SUCCESS) {
|
||||
result.memory->used = used;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.coreCount)
|
||||
if (result.coreCount) {
|
||||
mtmlData.ffmtmlDeviceCountGpuCores(device, result.coreCount);
|
||||
}
|
||||
|
||||
if (result.frequency)
|
||||
{
|
||||
MtmlGpu *gpu = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitGpu(device, &gpu) == MTML_SUCCESS)
|
||||
{
|
||||
if (result.frequency) {
|
||||
MtmlGpu* gpu = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitGpu(device, &gpu) == MTML_SUCCESS) {
|
||||
uint32_t clockMHz;
|
||||
if (mtmlData.ffmtmlGpuGetMaxClock(gpu, &clockMHz) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlGpuGetMaxClock(gpu, &clockMHz) == MTML_SUCCESS) {
|
||||
*result.frequency = clockMHz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.coreUsage)
|
||||
{
|
||||
MtmlGpu *gpu = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitGpu(device, &gpu) == MTML_SUCCESS)
|
||||
{
|
||||
if (result.coreUsage) {
|
||||
MtmlGpu* gpu = NULL;
|
||||
if (mtmlData.ffmtmlDeviceInitGpu(device, &gpu) == MTML_SUCCESS) {
|
||||
unsigned int utilization;
|
||||
if (mtmlData.ffmtmlGpuGetUtilization(gpu, &utilization) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlGpuGetUtilization(gpu, &utilization) == MTML_SUCCESS) {
|
||||
*result.coreUsage = utilization;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.name)
|
||||
{
|
||||
if (result.name) {
|
||||
char name[MTML_DEVICE_NAME_BUFFER_SIZE];
|
||||
if (mtmlData.ffmtmlDeviceGetName(device, name, ARRAY_SIZE(name)) == MTML_SUCCESS)
|
||||
if (mtmlData.ffmtmlDeviceGetName(device, name, ARRAY_SIZE(name)) == MTML_SUCCESS) {
|
||||
ffStrbufSetS(result.name, name);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user