2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#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"
|
2023-01-12 11:41:07 +01:00
|
|
|
#define FF_GPU_NUM_FORMAT_ARGS 6
|
2021-04-03 21:51:50 +02:00
|
|
|
|
2023-01-12 11:41:07 +01:00
|
|
|
static void printGPUResult(FFinstance* instance, uint8_t index, const 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
|
|
|
{
|
2023-01-12 11:41:07 +01:00
|
|
|
ffPrintLogoAndKey(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu.key);
|
2022-12-17 11:39:10 +08:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2023-01-12 11:41:07 +01:00
|
|
|
FFstrbuf type;
|
|
|
|
|
if(gpu->type == FF_GPU_TYPE_INTEGRATED)
|
|
|
|
|
ffStrbufInitS(&type, "Integrated");
|
|
|
|
|
else if(gpu->type == FF_GPU_TYPE_DISCRETE)
|
|
|
|
|
ffStrbufInitS(&type, "Discrete");
|
|
|
|
|
else
|
|
|
|
|
ffStrbufInitS(&type, "Unknown");
|
|
|
|
|
|
2022-12-17 11:39:10 +08:00
|
|
|
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},
|
2023-01-12 11:41:07 +01:00
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &type},
|
2022-12-17 11:39:10 +08:00
|
|
|
});
|
2023-01-12 11:41:07 +01:00
|
|
|
|
|
|
|
|
ffStrbufDestroy(&type);
|
2022-12-17 11:39:10 +08:00
|
|
|
}
|
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
|
|
|
|
2023-01-12 11:41:07 +01:00
|
|
|
FFlist selectedGpus;
|
|
|
|
|
ffListInitA(&selectedGpus, sizeof(const FFGPUResult*), gpus->length);
|
|
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < gpus->length; i++)
|
2022-09-05 17:42:42 +02:00
|
|
|
{
|
2023-01-12 11:41:07 +01:00
|
|
|
const FFGPUResult* gpu = ffListGet(gpus, i);
|
|
|
|
|
|
|
|
|
|
if(gpu->type == FF_GPU_TYPE_INTEGRATED && instance->config.gpuHideIntegrated)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if(gpu->type == FF_GPU_TYPE_DISCRETE && instance->config.gpuHideDiscrete)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
* (const FFGPUResult**) ffListAdd(&selectedGpus) = gpu;
|
2022-09-05 17:42:42 +02:00
|
|
|
}
|
2021-10-19 18:44:59 +02:00
|
|
|
|
2023-01-12 11:41:07 +01:00
|
|
|
for(uint32_t i = 0; i < selectedGpus.length; i++)
|
|
|
|
|
printGPUResult(instance, selectedGpus.length == 1 ? 0 : (uint8_t) (i + 1), * (const FFGPUResult**) ffListGet(&selectedGpus, i));
|
|
|
|
|
|
|
|
|
|
if(selectedGpus.length == 0)
|
|
|
|
|
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "No GPUs found");
|
|
|
|
|
|
|
|
|
|
ffListDestroy(&selectedGpus);
|
2021-11-13 18:25:35 +01:00
|
|
|
}
|