mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 06:00:08 +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:
@@ -23,7 +23,7 @@ struct FFNvmlData {
|
||||
|
||||
#if defined(_WIN32) && !defined(FF_DISABLE_DLOPEN)
|
||||
|
||||
#include "nvapi.h"
|
||||
# include "nvapi.h"
|
||||
|
||||
struct FFNvapiData {
|
||||
FF_LIBRARY_SYMBOL(nvapi_Unload)
|
||||
@@ -34,33 +34,33 @@ struct FFNvapiData {
|
||||
bool inited;
|
||||
} nvapiData;
|
||||
|
||||
static const char* detectMoreByNvapi(FFGpuDriverResult* result)
|
||||
{
|
||||
if (!nvapiData.inited)
|
||||
{
|
||||
static const char* detectMoreByNvapi(FFGpuDriverResult* result) {
|
||||
if (!nvapiData.inited) {
|
||||
nvapiData.inited = true;
|
||||
|
||||
FF_LIBRARY_LOAD_MESSAGE(libnvapi,
|
||||
#ifdef _WIN64
|
||||
# ifdef _WIN64
|
||||
"nvapi64.dll"
|
||||
#else
|
||||
# else
|
||||
"nvapi.dll"
|
||||
#endif
|
||||
, 1);
|
||||
# endif
|
||||
,
|
||||
1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvapi, nvapi_QueryInterface)
|
||||
#define FF_NVAPI_INTERFACE(iName, iOffset) \
|
||||
__typeof__(&iName) ff ## iName = ffnvapi_QueryInterface(iOffset); \
|
||||
if (ff ## iName == NULL) return "nvapi_QueryInterface " #iName " failed";
|
||||
# define FF_NVAPI_INTERFACE(iName, iOffset) \
|
||||
__typeof__(&iName) ff##iName = ffnvapi_QueryInterface(iOffset); \
|
||||
if (ff##iName == NULL) return "nvapi_QueryInterface " #iName " failed";
|
||||
|
||||
FF_NVAPI_INTERFACE(nvapi_Initialize, NVAPI_INTERFACE_OFFSET_INITIALIZE)
|
||||
FF_NVAPI_INTERFACE(nvapi_Unload, NVAPI_INTERFACE_OFFSET_UNLOAD)
|
||||
FF_NVAPI_INTERFACE(nvapi_EnumPhysicalGPUs, NVAPI_INTERFACE_OFFSET_ENUM_PHYSICAL_GPUS)
|
||||
FF_NVAPI_INTERFACE(nvapi_GPU_GetRamType, NVAPI_INTERFACE_OFFSET_GPU_GET_RAM_TYPE)
|
||||
FF_NVAPI_INTERFACE(nvapi_GPU_GetGPUType, NVAPI_INTERFACE_OFFSET_GPU_GET_GPU_TYPE)
|
||||
#undef FF_NVAPI_INTERFACE
|
||||
# undef FF_NVAPI_INTERFACE
|
||||
|
||||
if (ffnvapi_Initialize() < 0)
|
||||
if (ffnvapi_Initialize() < 0) {
|
||||
return "NvAPI_Initialize() failed";
|
||||
}
|
||||
|
||||
nvapiData.ffnvapi_EnumPhysicalGPUs = ffnvapi_EnumPhysicalGPUs;
|
||||
nvapiData.ffnvapi_GPU_GetRamType = ffnvapi_GPU_GetRamType;
|
||||
@@ -71,32 +71,33 @@ static const char* detectMoreByNvapi(FFGpuDriverResult* result)
|
||||
libnvapi = NULL; // don't close nvapi
|
||||
}
|
||||
|
||||
if (nvapiData.ffnvapi_EnumPhysicalGPUs == NULL)
|
||||
if (nvapiData.ffnvapi_EnumPhysicalGPUs == NULL) {
|
||||
return "loading nvapi library failed";
|
||||
}
|
||||
|
||||
NvPhysicalGpuHandle handles[32];
|
||||
int gpuCount = 0;
|
||||
|
||||
if (nvapiData.ffnvapi_EnumPhysicalGPUs(handles, &gpuCount) < 0)
|
||||
if (nvapiData.ffnvapi_EnumPhysicalGPUs(handles, &gpuCount) < 0) {
|
||||
return "NvAPI_EnumPhysicalGPUs() failed";
|
||||
}
|
||||
|
||||
uint32_t gpuIndex = *result->index;
|
||||
|
||||
if (gpuIndex >= (uint32_t) gpuCount)
|
||||
if (gpuIndex >= (uint32_t) gpuCount) {
|
||||
return "GPU index out of range";
|
||||
}
|
||||
|
||||
// Not very sure. Need to check in multi-GPU system
|
||||
NvPhysicalGpuHandle gpuHandle = handles[gpuIndex];
|
||||
|
||||
NvApiGPUMemoryType memType;
|
||||
if (result->memoryType && nvapiData.ffnvapi_GPU_GetRamType(gpuHandle, &memType) == 0)
|
||||
{
|
||||
switch (memType)
|
||||
{
|
||||
#define FF_NVAPI_MEMORY_TYPE(type) \
|
||||
case NVAPI_GPU_MEMORY_TYPE_##type: \
|
||||
ffStrbufSetStatic(result->memoryType, #type); \
|
||||
break;
|
||||
if (result->memoryType && nvapiData.ffnvapi_GPU_GetRamType(gpuHandle, &memType) == 0) {
|
||||
switch (memType) {
|
||||
# define FF_NVAPI_MEMORY_TYPE(type) \
|
||||
case NVAPI_GPU_MEMORY_TYPE_##type: \
|
||||
ffStrbufSetStatic(result->memoryType, #type); \
|
||||
break;
|
||||
FF_NVAPI_MEMORY_TYPE(UNKNOWN)
|
||||
FF_NVAPI_MEMORY_TYPE(SDRAM)
|
||||
FF_NVAPI_MEMORY_TYPE(DDR1)
|
||||
@@ -114,7 +115,7 @@ static const char* detectMoreByNvapi(FFGpuDriverResult* result)
|
||||
FF_NVAPI_MEMORY_TYPE(GDDR6)
|
||||
FF_NVAPI_MEMORY_TYPE(GDDR6X)
|
||||
FF_NVAPI_MEMORY_TYPE(GDDR7)
|
||||
#undef FF_NVAPI_MEMORY_TYPE
|
||||
# undef FF_NVAPI_MEMORY_TYPE
|
||||
default:
|
||||
ffStrbufSetF(result->memoryType, "Unknown (%d)", memType);
|
||||
break;
|
||||
@@ -122,10 +123,8 @@ static const char* detectMoreByNvapi(FFGpuDriverResult* result)
|
||||
}
|
||||
|
||||
NvApiGPUType gpuType;
|
||||
if (result->type && nvapiData.ffnvapi_GPU_GetGPUType(gpuHandle, &gpuType) == 0)
|
||||
{
|
||||
switch (gpuType)
|
||||
{
|
||||
if (result->type && nvapiData.ffnvapi_GPU_GetGPUType(gpuHandle, &gpuType) == 0) {
|
||||
switch (gpuType) {
|
||||
case NV_SYSTEM_TYPE_IGPU:
|
||||
*result->type = FF_GPU_TYPE_INTEGRATED;
|
||||
break;
|
||||
@@ -143,14 +142,12 @@ static const char* detectMoreByNvapi(FFGpuDriverResult* result)
|
||||
|
||||
#endif
|
||||
|
||||
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName)
|
||||
{
|
||||
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName) {
|
||||
#ifndef FF_DISABLE_DLOPEN
|
||||
|
||||
if (!nvmlData.inited)
|
||||
{
|
||||
if (!nvmlData.inited) {
|
||||
nvmlData.inited = true;
|
||||
FF_LIBRARY_LOAD(libnvml, "dlopen nvml failed", soName , 1);
|
||||
FF_LIBRARY_LOAD(libnvml, "dlopen nvml failed", soName, 1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlInit_v2)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2)
|
||||
@@ -167,8 +164,7 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetIndex)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetName)
|
||||
|
||||
if (ffnvmlInit_v2() != NVML_SUCCESS)
|
||||
{
|
||||
if (ffnvmlInit_v2() != NVML_SUCCESS) {
|
||||
nvmlData.ffnvmlDeviceGetNumGpuCores = NULL;
|
||||
return "nvmlInit_v2() failed";
|
||||
}
|
||||
@@ -176,51 +172,52 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
|
||||
libnvml = NULL; // don't close nvml
|
||||
}
|
||||
|
||||
if (nvmlData.ffnvmlDeviceGetNumGpuCores == NULL)
|
||||
if (nvmlData.ffnvmlDeviceGetNumGpuCores == NULL) {
|
||||
return "loading nvml library failed";
|
||||
}
|
||||
|
||||
nvmlDevice_t device = NULL;
|
||||
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
|
||||
{
|
||||
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID) {
|
||||
char pciBusIdStr[32];
|
||||
snprintf(pciBusIdStr, ARRAY_SIZE(pciBusIdStr), "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
|
||||
|
||||
nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusIdStr, &device);
|
||||
if (ret != NVML_SUCCESS)
|
||||
if (ret != NVML_SUCCESS) {
|
||||
return "nvmlDeviceGetHandleByPciBusId_v2() 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 (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS)
|
||||
if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS) {
|
||||
return "nvmlDeviceGetCount_v2() failed";
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < count; i++, device = NULL)
|
||||
{
|
||||
if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS)
|
||||
for (uint32_t i = 0; i < count; i++, device = NULL) {
|
||||
if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nvmlPciInfo_t pciInfo;
|
||||
if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS)
|
||||
if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_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) return "Device not found";
|
||||
if (!device) {
|
||||
return "Device not found";
|
||||
}
|
||||
|
||||
if (result.type)
|
||||
{
|
||||
if (result.type) {
|
||||
nvmlBrandType_t brand;
|
||||
if (nvmlData.ffnvmlDeviceGetBrand(device, &brand) == NVML_SUCCESS)
|
||||
{
|
||||
switch (brand)
|
||||
{
|
||||
if (nvmlData.ffnvmlDeviceGetBrand(device, &brand) == NVML_SUCCESS) {
|
||||
switch (brand) {
|
||||
case NVML_BRAND_NVIDIA_RTX:
|
||||
case NVML_BRAND_QUADRO_RTX:
|
||||
case NVML_BRAND_GEFORCE:
|
||||
@@ -235,64 +232,60 @@ const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverR
|
||||
}
|
||||
}
|
||||
|
||||
if (result.index)
|
||||
{
|
||||
if (result.index) {
|
||||
unsigned int value;
|
||||
if (nvmlData.ffnvmlDeviceGetIndex(device, &value) == NVML_SUCCESS)
|
||||
{
|
||||
if (nvmlData.ffnvmlDeviceGetIndex(device, &value) == NVML_SUCCESS) {
|
||||
*result.index = value;
|
||||
#ifdef _WIN32
|
||||
# ifdef _WIN32
|
||||
// Don't bother loading nvapi for GPU type detection only
|
||||
if (result.memoryType)
|
||||
if (result.memoryType) {
|
||||
detectMoreByNvapi(&result);
|
||||
#endif
|
||||
}
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
if (result.temp)
|
||||
{
|
||||
if (result.temp) {
|
||||
uint32_t value;
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) == NVML_SUCCESS)
|
||||
if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) == NVML_SUCCESS) {
|
||||
*result.temp = value;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.memory)
|
||||
{
|
||||
nvmlMemory_v2_t memory = { .version = nvmlMemory_v2 };
|
||||
if (nvmlData.ffnvmlDeviceGetMemoryInfo_v2(device, &memory) == NVML_SUCCESS)
|
||||
{
|
||||
if (result.memory) {
|
||||
nvmlMemory_v2_t memory = {.version = nvmlMemory_v2};
|
||||
if (nvmlData.ffnvmlDeviceGetMemoryInfo_v2(device, &memory) == NVML_SUCCESS) {
|
||||
result.memory->total = memory.used + memory.free;
|
||||
result.memory->used = memory.used;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
nvmlMemory_t memory_v1;
|
||||
if (nvmlData.ffnvmlDeviceGetMemoryInfo(device, &memory_v1) == NVML_SUCCESS)
|
||||
{
|
||||
if (nvmlData.ffnvmlDeviceGetMemoryInfo(device, &memory_v1) == NVML_SUCCESS) {
|
||||
result.memory->total = memory_v1.total;
|
||||
result.memory->used = memory_v1.used;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.coreCount)
|
||||
if (result.coreCount) {
|
||||
nvmlData.ffnvmlDeviceGetNumGpuCores(device, result.coreCount);
|
||||
|
||||
if (result.frequency)
|
||||
nvmlData.ffnvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_GRAPHICS, result.frequency);
|
||||
|
||||
if (result.coreUsage)
|
||||
{
|
||||
nvmlUtilization_t utilization;
|
||||
if (nvmlData.ffnvmlDeviceGetUtilizationRates(device, &utilization) == NVML_SUCCESS)
|
||||
*result.coreUsage = utilization.gpu;
|
||||
}
|
||||
|
||||
if (result.name)
|
||||
{
|
||||
if (result.frequency) {
|
||||
nvmlData.ffnvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_GRAPHICS, result.frequency);
|
||||
}
|
||||
|
||||
if (result.coreUsage) {
|
||||
nvmlUtilization_t utilization;
|
||||
if (nvmlData.ffnvmlDeviceGetUtilizationRates(device, &utilization) == NVML_SUCCESS) {
|
||||
*result.coreUsage = utilization.gpu;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.name) {
|
||||
char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE];
|
||||
if (nvmlData.ffnvmlDeviceGetName(device, name, ARRAY_SIZE(name)) == NVML_SUCCESS)
|
||||
if (nvmlData.ffnvmlDeviceGetName(device, name, ARRAY_SIZE(name)) == NVML_SUCCESS) {
|
||||
ffStrbufSetS(result.name, name);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user