Skip to content

Commit

Permalink
GPU (Linux): don't query DRM drivers for driver version
Browse files Browse the repository at this point in the history
Fix #956
  • Loading branch information
CarterLi committed May 22, 2024
1 parent a3dbac7 commit d196b80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
8 changes: 4 additions & 4 deletions src/data/help.json
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,13 @@
{
"long": "gpu-detection-method",
"desc": "Force using a specified method to detect GPUs",
"remark": "Methods are used in this order: DRM (Linux only) -> PCI (Linux, FreeBSD and other platform specific methods) -> Vulkan -> OpenGL",
"remark": "Will fall back to next methods if the specified method fails",
"arg": {
"type": "enum",
"enum": {
"auto": "Use DRM if available, which is most feature-rich. Requires proper DRM driver installed",
"pci": "Search PCI devices, which do not requires any driver installed",
"vulkan": "Use Vulkan API. Slow and requires vulkan driver installed",
"auto": "Query platform specific graphic APIs. Requires proper GPU drivers installed. Not supported on FreeBSD",
"pci": "Search PCI devices, which do not requires GPU driver installed. Not supported on Windows and macOS",
"vulkan": "Use Vulkan API. Slow and requires vulkan driver installed. Used for Android",
"opengl": "Use OpenGL API. Slow and only detects one GPU"
},
"default": "auto"
Expand Down
42 changes: 0 additions & 42 deletions src/detection/gpu/gpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,8 @@
#endif
#endif


#if FF_HAVE_DRM_H
static const char* drmDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, const char* drmKey)
{
ffStrbufSetS(buffer, "/dev/dri/");
ffStrbufAppendS(buffer, drmKey);
FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY);
if (fd < 0) return "open(/dev/dri/drm_key) failed";

ffStrbufEnsureFixedLengthFree(&gpu->driver, 128);
drm_version_t version = {
.name = gpu->driver.chars,
.name_len = gpu->driver.allocated,
};
if (ioctl(fd, DRM_IOCTL_VERSION, &version) < 0) return "ioctl(DRM_IOCTL_VERSION) failed";
gpu->driver.length = (uint32_t) version.name_len;
gpu->driver.chars[gpu->driver.length] = '\0';

if (version.version_major || version.version_minor || version.version_patchlevel)
ffStrbufAppendF(&gpu->driver, " %d.%d.%d", version.version_major, version.version_minor, version.version_patchlevel);
else
{
ffStrbufAppendS(pciDir, "/driver/module/version");
if (ffReadFileBuffer(pciDir->chars, buffer))
{
ffStrbufTrimRightSpace(buffer);
ffStrbufAppendC(&gpu->driver, ' ');
ffStrbufAppend(&gpu->driver, buffer);
}
}
return NULL;
}
#endif

static bool pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, FF_MAYBE_UNUSED const char* drmKey)
{
#if FF_HAVE_DRM_H
if (drmKey)
{
drmDetectDriver(gpu, pciDir, buffer, drmKey);
if (gpu->driver.length > 0) return true;
}
#endif

ffStrbufAppendS(pciDir, "/driver");
char pathBuf[PATH_MAX];
ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf));
Expand Down

0 comments on commit d196b80

Please sign in to comment.