Skip to content

Commit 9342d74

Browse files
committed
GPU: support detection by EGLext
Support multi-gpus
1 parent d602837 commit 9342d74

File tree

8 files changed

+70
-0
lines changed

8 files changed

+70
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ set(LIBFASTFETCH_SRC
354354
src/detection/editor/editor.c
355355
src/detection/font/font.c
356356
src/detection/gpu/gpu.c
357+
src/detection/gpu/gpu_eglext.c
357358
src/detection/media/media.c
358359
src/detection/netio/netio.c
359360
src/detection/opencl/opencl.c

doc/json_schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,7 @@
20412041
"pci",
20422042
"vulkan",
20432043
"opencl",
2044+
"eglext",
20442045
"opengl"
20452046
],
20462047
"default": "auto"

src/data/help.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@
11321132
"pci": "Search PCI devices, which do not requires GPU driver installed. Not supported on Windows and macOS",
11331133
"vulkan": "Use Vulkan API. Slow and requires proper vulkan driver installed. Used for Android",
11341134
"opencl": "Use OpenCL API. Slow and requires proper OpenCL driver installed",
1135+
"eglext": "Use extensions of EGL API. Slow but support multiple GPUs",
11351136
"opengl": "Use OpenGL API. Slow and only detects one GPU"
11361137
},
11371138
"default": "auto"

src/detection/gpu/gpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result)
114114
return NULL;
115115
}
116116
}
117+
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_EGLEXT)
118+
{
119+
if (ffGPUDetectByEglext(result) == NULL)
120+
return NULL;
121+
}
117122
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_OPENGL)
118123
{
119124
if (detectByOpenGL(result) == NULL)

src/detection/gpu/gpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result);
4747
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus);
4848

4949
const char* ffGetGPUVendorString(unsigned vendorId);
50+
const char* ffGPUDetectByEglext(FFlist* gpus);
5051

5152
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__NetBSD__) || defined(__OpenBSD__)
5253
void ffGPUFillVendorAndName(uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu);

src/detection/gpu/gpu_eglext.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "detection/gpu/gpu.h"
2+
#include "common/library.h"
3+
4+
#if defined(FF_HAVE_EGL) || __has_include(<EGL/egl.h>)
5+
#include <EGL/egl.h>
6+
#include <EGL/eglext.h>
7+
8+
const char* ffGPUDetectByEglext(FFlist* gpus)
9+
{
10+
FF_LIBRARY_LOAD(egl, "dlopen libEGL" FF_LIBRARY_EXTENSION " failed", "libEGL" FF_LIBRARY_EXTENSION, 1);
11+
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(egl, eglGetProcAddress);
12+
13+
PFNEGLQUERYDEVICESEXTPROC ffeglQueryDevicesEXT = (PFNEGLQUERYDEVICESEXTPROC) ffeglGetProcAddress("eglQueryDevicesEXT");
14+
if (!ffeglQueryDevicesEXT)
15+
return "eglGetProcAddress(\"eglQueryDevicesEXT\") returned NULL";
16+
PFNEGLQUERYDEVICESTRINGEXTPROC ffeglQueryDeviceStringEXT = (PFNEGLQUERYDEVICESTRINGEXTPROC) ffeglGetProcAddress("eglQueryDeviceStringEXT");
17+
if (!ffeglQueryDeviceStringEXT)
18+
return "eglGetProcAddress(\"eglQueryDeviceStringEXT\") returned NULL";
19+
20+
EGLDeviceEXT devs[32];
21+
EGLint numDevs;
22+
if (ffeglQueryDevicesEXT(ARRAY_SIZE(devs), devs, &numDevs))
23+
{
24+
for (EGLint i = 0; i < numDevs; i++)
25+
{
26+
const char* renderer = ffeglQueryDeviceStringEXT(devs[i], EGL_RENDERER_EXT);
27+
if (!renderer) continue;
28+
29+
FFGPUResult* gpu = (FFGPUResult*) ffListAdd(gpus);
30+
ffStrbufInitS(&gpu->name, renderer);
31+
ffStrbufInitS(&gpu->vendor, ffeglQueryDeviceStringEXT(devs[i], EGL_VENDOR));
32+
ffStrbufInitS(&gpu->driver, ffeglQueryDeviceStringEXT(devs[i], EGL_DRIVER_NAME_EXT));
33+
gpu->index = FF_GPU_INDEX_UNSET;
34+
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
35+
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
36+
gpu->temperature = FF_GPU_TEMP_UNSET;
37+
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
38+
gpu->type = FF_GPU_TYPE_UNKNOWN;
39+
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
40+
gpu->deviceId = 0;
41+
ffStrbufInitStatic(&gpu->platformApi, "EGLext");
42+
}
43+
}
44+
45+
return NULL;
46+
}
47+
48+
#else
49+
50+
const char* ffGPUDetectByEglext(FF_MAYBE_UNUSED FFlist* gpus)
51+
{
52+
return "fastfetch was compiled without egl support";
53+
}
54+
55+
#endif

src/modules/gpu/gpu.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char
165165
{ "pci", FF_GPU_DETECTION_METHOD_PCI },
166166
{ "vulkan", FF_GPU_DETECTION_METHOD_VULKAN },
167167
{ "opencl", FF_GPU_DETECTION_METHOD_OPENCL },
168+
{ "eglext", FF_GPU_DETECTION_METHOD_EGLEXT },
168169
{ "opengl", FF_GPU_DETECTION_METHOD_OPENGL },
169170
{},
170171
});
@@ -221,6 +222,7 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module)
221222
{ "pci", FF_GPU_DETECTION_METHOD_PCI },
222223
{ "vulkan", FF_GPU_DETECTION_METHOD_VULKAN },
223224
{ "opencl", FF_GPU_DETECTION_METHOD_OPENCL },
225+
{ "eglext", FF_GPU_DETECTION_METHOD_EGLEXT },
224226
{ "opengl", FF_GPU_DETECTION_METHOD_OPENGL },
225227
{},
226228
});
@@ -280,6 +282,9 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
280282
case FF_GPU_DETECTION_METHOD_OPENCL:
281283
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "opencl");
282284
break;
285+
case FF_GPU_DETECTION_METHOD_EGLEXT:
286+
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "eglext");
287+
break;
283288
case FF_GPU_DETECTION_METHOD_OPENGL:
284289
yyjson_mut_obj_add_str(doc, module, "detectionMethod", "opengl");
285290
break;

src/modules/gpu/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef enum __attribute__((__packed__)) FFGPUDetectionMethod
1818
FF_GPU_DETECTION_METHOD_PCI,
1919
FF_GPU_DETECTION_METHOD_VULKAN,
2020
FF_GPU_DETECTION_METHOD_OPENCL,
21+
FF_GPU_DETECTION_METHOD_EGLEXT,
2122
FF_GPU_DETECTION_METHOD_OPENGL,
2223
} FFGPUDetectionMethod;
2324

0 commit comments

Comments
 (0)