2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-07-25 13:36:58 +02:00
|
|
|
#include "common/caching.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-09-05 17:42:42 +02:00
|
|
|
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* gpu)
|
2022-09-01 17:14:50 +02:00
|
|
|
{
|
2022-09-05 17:42:42 +02:00
|
|
|
FFstrbuf output;
|
|
|
|
|
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
|
2022-09-01 17:14:50 +02:00
|
|
|
|
|
|
|
|
if(gpu->vendor.length > 0)
|
2022-06-17 23:38:33 +02:00
|
|
|
{
|
2022-09-05 17:42:42 +02:00
|
|
|
ffStrbufAppend(&output, &gpu->vendor);
|
|
|
|
|
ffStrbufAppendC(&output, ' ');
|
2022-06-17 23:38:33 +02:00
|
|
|
}
|
2022-09-01 17:14:50 +02:00
|
|
|
|
2022-09-05 17:42:42 +02:00
|
|
|
ffStrbufAppend(&output, &gpu->name);
|
2022-09-01 17:14:50 +02:00
|
|
|
|
2022-09-16 18:11:39 +08:00
|
|
|
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
|
|
|
|
|
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
|
|
|
|
|
|
2022-09-05 17:42:42 +02:00
|
|
|
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &output, 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},
|
2022-09-16 18:11:39 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
|
2022-09-05 17:42:42 +02:00
|
|
|
});
|
2022-06-01 00:04:58 +02:00
|
|
|
|
2022-09-05 17:42:42 +02:00
|
|
|
ffStrbufDestroy(&output);
|
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-06-17 18:15:36 +02:00
|
|
|
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS))
|
2021-11-13 18:25:35 +01:00
|
|
|
return;
|
2021-02-28 17:38:26 +01:00
|
|
|
|
2022-09-04 12:43:30 +02:00
|
|
|
if(ffStrbufCompS(&ffDetectHost()->productName, FF_HOST_PRODUCT_NAME_WSL) == 0)
|
|
|
|
|
{
|
2022-07-20 20:44:16 +02:00
|
|
|
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "WSL doesn't expose senseful GPU names");
|
2022-07-17 16:11:08 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
2021-10-19 18:44:59 +02:00
|
|
|
|
2022-09-05 17:42:42 +02:00
|
|
|
FFcache cache;
|
|
|
|
|
ffCacheOpenWrite(instance, FF_GPU_MODULE_NAME, &cache);
|
|
|
|
|
|
|
|
|
|
for(uint8_t i = 0; i < (uint8_t) gpus->length; i++)
|
|
|
|
|
printGPUResult(instance, gpus->length == 1 ? 0 : (uint8_t) (i + 1), &cache, ffListGet(gpus, i));
|
|
|
|
|
|
|
|
|
|
ffCacheClose(&cache);
|
2021-11-13 18:25:35 +01:00
|
|
|
}
|