Files
fastfetch/src/modules/gpu.c
T

63 lines
1.9 KiB
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
#include "common/printing.h"
2022-09-04 12:43:30 +02:00
#include "detection/host/host.h"
2022-09-05 17:42:42 +02:00
#include "detection/gpu/gpu.h"
2021-02-18 22:25:36 +01:00
2022-07-17 16:11:08 +02:00
#include <stdlib.h>
2021-04-15 18:59:26 +02:00
#define FF_GPU_MODULE_NAME "GPU"
2022-09-16 18:11:39 +08:00
#define FF_GPU_NUM_FORMAT_ARGS 5
2021-04-03 21:51:50 +02:00
2022-12-17 11:39:10 +08:00
static void printGPUResult(FFinstance* instance, uint8_t index, FFGPUResult* gpu)
2022-09-01 17:14:50 +02:00
{
2022-12-17 11:39:10 +08:00
if(instance->config.gpu.outputFormat.length == 0)
2022-06-17 23:38:33 +02:00
{
2022-12-17 11:39:10 +08:00
ffPrintLogoAndKey(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu.key);
FFstrbuf output;
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
2022-09-01 17:14:50 +02:00
2022-12-17 11:39:10 +08:00
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
{
ffStrbufAppend(&output, &gpu->vendor);
ffStrbufAppendC(&output, ' ');
}
2022-09-01 17:14:50 +02:00
2022-12-17 11:39:10 +08:00
ffStrbufAppend(&output, &gpu->name);
2022-09-16 18:11:39 +08:00
2022-12-17 11:39:10 +08:00
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
2022-09-25 15:23:00 +08:00
2022-12-17 11:39:10 +08:00
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
2022-06-01 00:04:58 +02:00
2022-12-17 11:39:10 +08:00
ffStrbufPutTo(&output, stdout);
ffStrbufDestroy(&output);
}
else
{
ffPrintFormat(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature},
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
});
}
2021-02-18 22:25:36 +01:00
}
2021-11-13 18:25:35 +01:00
void ffPrintGPU(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2022-09-05 17:42:42 +02:00
const FFlist* gpus = ffDetectGPU(instance);
2021-04-03 21:51:50 +02:00
2022-09-05 17:42:42 +02:00
if(gpus->length == 0)
{
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "No GPUs found");
2022-06-01 00:04:58 +02:00
return;
2022-09-05 17:42:42 +02:00
}
2022-09-05 17:42:42 +02:00
for(uint8_t i = 0; i < (uint8_t) gpus->length; i++)
2022-12-17 11:39:10 +08:00
printGPUResult(instance, gpus->length == 1 ? 0 : (uint8_t) (i + 1), ffListGet(gpus, i));
2021-11-13 18:25:35 +01:00
}