Skip to content

Commit a8b734c

Browse files
committed
GPU: change option --gpu-force-vulkan to --gpu-detection-method
1 parent 10ca776 commit a8b734c

File tree

8 files changed

+110
-50
lines changed

8 files changed

+110
-50
lines changed

completions/bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ __fastfetch_completion()
197197
"--disk-show-subvolumes"
198198
"--gpu-hide-integrated"
199199
"--gpu-hide-discrete"
200-
"--gpu-force-vulkan"
200+
"--gpu-force-method"
201201
"--disk-show-unknown"
202202
"--bluetooth-show-disconnected"
203203
)

doc/json_schema.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,16 @@
14551455
"type": "boolean",
14561456
"default": false
14571457
},
1458-
"forceVulkan": {
1459-
"description": "Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`",
1460-
"type": "boolean",
1461-
"default": false
1458+
"detectionMethod": {
1459+
"description": "Force using a specified method to detect GPUs",
1460+
"type": "string",
1461+
"enum": [
1462+
"auto",
1463+
"pci",
1464+
"vulkan",
1465+
"opengl"
1466+
],
1467+
"default": "auto"
14621468
},
14631469
"hideType": {
14641470
"description": "Specify the type of GPUs should not be printed",

src/data/help.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,13 +1197,18 @@
11971197
}
11981198
},
11991199
{
1200-
"long": "gpu-force-vulkan",
1201-
"desc": "Force using vulkan to detect GPUs",
1202-
"remark": "Vulkan supports video memory usage detection",
1200+
"long": "gpu-detection-method",
1201+
"desc": "Force using a specified method to detect GPUs",
12031202
"arg": {
1204-
"type": "bool",
1203+
"type": "enum",
12051204
"optional": true,
1206-
"default": false
1205+
"enum": {
1206+
"auto": "DRM (Linux only) -> PCI (Linux, FreeBSD and other platform specific methods) -> Vulkan -> OpenGL",
1207+
"pci": "PCI -> Vulkan -> OpenGL",
1208+
"vulkan": "Vulkan -> OpenGL",
1209+
"opengl": "OpenGL"
1210+
},
1211+
"default": "auto"
12071212
}
12081213
},
12091214
{

src/detection/gpu/gpu.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,28 @@ const char* detectByOpenGL(FFlist* gpus)
4646
{
4747
FFGPUResult* gpu = (FFGPUResult*) ffListAdd(gpus);
4848
gpu->type = FF_GPU_TYPE_UNKNOWN;
49-
ffStrbufInitMove(&gpu->vendor, &result.vendor);
49+
ffStrbufInit(&gpu->vendor);
5050
ffStrbufInitMove(&gpu->name, &result.renderer);
51-
ffStrbufInit(&gpu->driver);
51+
ffStrbufInitMove(&gpu->driver, &result.vendor);
5252
ffStrbufInitF(&gpu->platformApi, "OpenGL %s", result.version.chars);
5353
gpu->temperature = FF_GPU_TEMP_UNSET;
5454
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
5555
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
5656
gpu->dedicated = gpu->shared = (FFGPUMemory){0, 0};
5757
gpu->deviceId = 0;
5858

59-
if (ffStrbufIgnCaseEqualS(&gpu->vendor, "Mesa"))
60-
ffStrbufClear(&gpu->vendor);
61-
62-
if (!gpu->vendor.length)
59+
if (ffStrbufContainS(&gpu->name, "Apple"))
6360
{
64-
if (ffStrbufContainS(&gpu->name, "Apple"))
65-
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
66-
else if (ffStrbufContainS(&gpu->name, "Intel"))
67-
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
68-
else if (ffStrbufContainS(&gpu->name, "AMD") || ffStrbufContainS(&gpu->name, "ATI"))
69-
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
70-
else if (ffStrbufContainS(&gpu->name, "NVIDIA"))
71-
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
72-
}
73-
if (ffStrbufEqualS(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE))
61+
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
7462
gpu->type = FF_GPU_TYPE_INTEGRATED;
63+
}
64+
else if (ffStrbufContainS(&gpu->name, "Intel"))
65+
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
66+
else if (ffStrbufContainS(&gpu->name, "AMD") || ffStrbufContainS(&gpu->name, "ATI"))
67+
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
68+
else if (ffStrbufContainS(&gpu->name, "NVIDIA"))
69+
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
70+
7571
}
7672

7773
ffStrbufDestroy(&result.version);
@@ -83,20 +79,26 @@ const char* detectByOpenGL(FFlist* gpus)
8379

8480
const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result)
8581
{
86-
if (!options->forceVulkan)
82+
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_PCI)
8783
{
8884
const char* error = ffDetectGPUImpl(options, result);
8985
if (!error && result->length > 0) return NULL;
9086
}
91-
FFVulkanResult* vulkan = ffDetectVulkan();
92-
if (!vulkan->error && vulkan->gpus.length > 0)
87+
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_VULKAN)
88+
{
89+
FFVulkanResult* vulkan = ffDetectVulkan();
90+
if (!vulkan->error && vulkan->gpus.length > 0)
91+
{
92+
ffListDestroy(result);
93+
ffListInitMove(result, &vulkan->gpus);
94+
return NULL;
95+
}
96+
}
97+
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_OPENGL)
9398
{
94-
ffListDestroy(result);
95-
ffListInitMove(result, &vulkan->gpus);
96-
return NULL;
99+
if (detectByOpenGL(result) == NULL)
100+
return NULL;
97101
}
98-
if (detectByOpenGL(result) == NULL)
99-
return NULL;
100102

101103
return "GPU detection failed";
102104
}

src/detection/gpu/gpu_linux.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,16 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
460460

461461
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
462462
{
463-
#ifdef FF_HAVE_DIRECTX_HEADERS
464-
const char* ffGPUDetectByDirectX(const FFGPUOptions* options, FFlist* gpus);
465-
if (ffGPUDetectByDirectX(options, gpus) == NULL)
466-
return NULL;
467-
#endif
468-
469-
if (drmDetectGPUs(options, gpus) == NULL && gpus->length > 0)
470-
return NULL;
463+
if (options->detectionMethod == FF_GPU_DETECTION_METHOD_AUTO)
464+
{
465+
#ifdef FF_HAVE_DIRECTX_HEADERS
466+
const char* ffGPUDetectByDirectX(const FFGPUOptions* options, FFlist* gpus);
467+
if (ffGPUDetectByDirectX(options, gpus) == NULL)
468+
return NULL;
469+
#endif
471470

471+
if (drmDetectGPUs(options, gpus) == NULL && gpus->length > 0)
472+
return NULL;
473+
}
472474
return pciDetectGPUs(options, gpus);
473475
}

src/fastfetch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ static bool printSpecificCommandHelp(const char* command)
234234
}
235235
}
236236

237+
yyjson_doc_free(doc);
237238
return true;
238239
}
239240
}
240241
}
242+
243+
yyjson_doc_free(doc);
241244
return false;
242245
}
243246

src/modules/gpu/gpu.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,15 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char
144144
return true;
145145
}
146146

147-
if (ffStrEqualsIgnCase(subKey, "force-vulkan"))
147+
if (ffStrEqualsIgnCase(subKey, "detection-method"))
148148
{
149-
options->forceVulkan = ffOptionParseBoolean(value);
149+
options->detectionMethod = ffOptionParseEnum(key, value, (FFKeyValuePair[]) {
150+
{ "auto", FF_GPU_DETECTION_METHOD_AUTO },
151+
{ "pci", FF_GPU_DETECTION_METHOD_PCI },
152+
{ "vulkan", FF_GPU_DETECTION_METHOD_VULKAN },
153+
{ "opengl", FF_GPU_DETECTION_METHOD_OPENGL },
154+
{},
155+
});
150156
return true;
151157
}
152158

@@ -191,9 +197,20 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module)
191197
continue;
192198
}
193199

194-
if (ffStrEqualsIgnCase(key, "forceVulkan"))
200+
if (ffStrEqualsIgnCase(key, "detectionMethod"))
195201
{
196-
options->forceVulkan = yyjson_get_bool(val);
202+
int value;
203+
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
204+
{ "auto", FF_GPU_DETECTION_METHOD_AUTO },
205+
{ "pci", FF_GPU_DETECTION_METHOD_PCI },
206+
{ "vulkan", FF_GPU_DETECTION_METHOD_VULKAN },
207+
{ "opengl", FF_GPU_DETECTION_METHOD_OPENGL },
208+
{},
209+
});
210+
if (error)
211+
ffPrintError(FF_GPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Invalid %s value: %s", key, error);
212+
else
213+
options->detectionMethod = (FFGPUDetectionMethod) value;
197214
continue;
198215
}
199216

@@ -230,8 +247,24 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
230247
if (options->driverSpecific != defaultOptions.driverSpecific)
231248
yyjson_mut_obj_add_bool(doc, module, "driverSpecific", options->driverSpecific);
232249

233-
if (options->forceVulkan != defaultOptions.forceVulkan)
234-
yyjson_mut_obj_add_bool(doc, module, "forceVulkan", options->forceVulkan);
250+
if (options->detectionMethod != defaultOptions.detectionMethod)
251+
{
252+
switch (options->detectionMethod)
253+
{
254+
case FF_GPU_DETECTION_METHOD_AUTO:
255+
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "auto");
256+
break;
257+
case FF_GPU_DETECTION_METHOD_PCI:
258+
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "pci");
259+
break;
260+
case FF_GPU_DETECTION_METHOD_VULKAN:
261+
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "vulkan");
262+
break;
263+
case FF_GPU_DETECTION_METHOD_OPENGL:
264+
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "opengl");
265+
break;
266+
}
267+
}
235268

236269
ffTempsGenerateJsonConfig(doc, module, defaultOptions.temp, defaultOptions.tempConfig, options->temp, options->tempConfig);
237270

@@ -366,7 +399,7 @@ void ffInitGPUOptions(FFGPUOptions* options)
366399
ffOptionInitModuleArg(&options->moduleArgs);
367400

368401
options->driverSpecific = false;
369-
options->forceVulkan = false;
402+
options->detectionMethod = FF_GPU_DETECTION_METHOD_AUTO;
370403
options->temp = false;
371404
options->hideType = FF_GPU_TYPE_UNKNOWN;
372405
options->tempConfig = (FFColorRangeConfig) { 60, 80 };

src/modules/gpu/option.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ typedef enum FFGPUType
1212
FF_GPU_TYPE_DISCRETE,
1313
} FFGPUType;
1414

15+
typedef enum FFGPUDetectionMethod
16+
{
17+
FF_GPU_DETECTION_METHOD_AUTO,
18+
FF_GPU_DETECTION_METHOD_PCI,
19+
FF_GPU_DETECTION_METHOD_VULKAN,
20+
FF_GPU_DETECTION_METHOD_OPENGL,
21+
} FFGPUDetectionMethod;
22+
1523
typedef struct FFGPUOptions
1624
{
1725
FFModuleBaseInfo moduleInfo;
1826
FFModuleArgs moduleArgs;
1927

2028
FFGPUType hideType;
29+
FFGPUDetectionMethod detectionMethod;
2130
bool temp;
2231
bool driverSpecific;
23-
bool forceVulkan;
32+
bool forceMethod;
2433
FFColorRangeConfig tempConfig;
2534
FFColorRangeConfig percent;
2635
} FFGPUOptions;

0 commit comments

Comments
 (0)