GPU (Windows): support vmem total / usage detection #416

vmem usage detection is guarded behind `--allow-slow-operations`
because it's really slow sometimes
This commit is contained in:
李通洲
2023-02-11 02:29:26 +08:00
parent f05d134aa7
commit b90d543afc
6 changed files with 78 additions and 33 deletions
+21 -3
View File
@@ -1,4 +1,6 @@
#include "fastfetch.h"
#include "common/bar.h"
#include "common/parsing.h"
#include "common/printing.h"
#include "detection/host/host.h"
#include "detection/gpu/gpu.h"
@@ -14,7 +16,7 @@ static void printGPUResult(FFinstance* instance, uint8_t index, const FFGPUResul
{
ffPrintLogoAndKey(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu.key);
FFstrbuf output;
FF_STRBUF_AUTO_DESTROY output;
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
@@ -31,9 +33,25 @@ static void printGPUResult(FFinstance* instance, uint8_t index, const FFGPUResul
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
ffStrbufPutTo(&output, stdout);
if(gpu->dedicatedTotal != FF_GPU_VMEM_SIZE_UNSET)
{
ffStrbufAppendS(&output, " (");
ffStrbufDestroy(&output);
if(gpu->dedicatedUsed != FF_GPU_VMEM_SIZE_UNSET)
{
ffParseSize(gpu->dedicatedUsed, instance->config.binaryPrefixType, &output);
ffStrbufAppendS(&output, " / ");
}
ffParseSize(gpu->dedicatedTotal, instance->config.binaryPrefixType, &output);
if(gpu->dedicatedUsed != FF_GPU_VMEM_SIZE_UNSET)
{
ffStrbufAppendS(&output, ", ");
ffAppendPercentNum(instance, &output, (uint8_t) (gpu->dedicatedUsed * 100 / gpu->dedicatedTotal), 50, 80, false);
}
ffStrbufAppendC(&output, ')');
}
ffStrbufPutTo(&output, stdout);
}
else
{