From nobody Fri Nov 12 14:46:59 2021 X-Original-To: dev-commits-ports-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2AF5A184ADCE; Fri, 12 Nov 2021 14:47:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HrLyX5sSJz4Wp6; Fri, 12 Nov 2021 14:47:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B37A62158E; Fri, 12 Nov 2021 14:46:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ACEkx7G094320; Fri, 12 Nov 2021 14:46:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ACEkxBq094319; Fri, 12 Nov 2021 14:46:59 GMT (envelope-from git) Date: Fri, 12 Nov 2021 14:46:59 GMT Message-Id: <202111121446.1ACEkxBq094319@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Jan Beich Subject: git: 1f08de175960 - main - multimedia/intel-media-sdk: detect GPU generation for VPL handover List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-main@freebsd.org X-BeenThere: dev-commits-ports-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jbeich X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1f08de175960433c739c0c1ae027778b2394475a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jbeich: URL: https://cgit.FreeBSD.org/ports/commit/?id=1f08de175960433c739c0c1ae027778b2394475a commit 1f08de175960433c739c0c1ae027778b2394475a Author: Jan Beich AuthorDate: 2021-11-12 11:12:43 +0000 Commit: Jan Beich CommitDate: 2021-11-12 14:45:28 +0000 multimedia/intel-media-sdk: detect GPU generation for VPL handover PR: 258976 Inspired by: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/201 --- multimedia/intel-media-sdk/Makefile | 1 + .../intel-media-sdk/files/patch-drm-to-pciid | 86 ++++++++++++++++++++++ .../intel-media-sdk/files/patch-msdk-default | 28 ------- 3 files changed, 87 insertions(+), 28 deletions(-) diff --git a/multimedia/intel-media-sdk/Makefile b/multimedia/intel-media-sdk/Makefile index 1d8ff951b217..16f2f98d8cc3 100644 --- a/multimedia/intel-media-sdk/Makefile +++ b/multimedia/intel-media-sdk/Makefile @@ -1,6 +1,7 @@ PORTNAME= intel-media-sdk DISTVERSIONPREFIX= intel-mediasdk- DISTVERSION= 21.4.1 +PORTREVISION= 1 CATEGORIES= multimedia MAINTAINER= jbeich@FreeBSD.org diff --git a/multimedia/intel-media-sdk/files/patch-drm-to-pciid b/multimedia/intel-media-sdk/files/patch-drm-to-pciid new file mode 100644 index 000000000000..0a89fcec1c7c --- /dev/null +++ b/multimedia/intel-media-sdk/files/patch-drm-to-pciid @@ -0,0 +1,86 @@ +/sys/class/drm/renderD*/device/device is Linux-only, so use a BSD extension +to get vendor/device identifiers from rendor nodes. Based on libdrm code. + +According to https://github.com/intel/libva/issues/540 some nodes maybe +missing, so unlike Linux keep searching in case iGPU is older than dGPU. +mfxloader.cpp later uses the newest GPU to decide the default. + +$ ffmpeg -hide_banner -init_hw_device qsv=auto -i foo.y4m -vf hwupload=extra_hw_frames=64,format=qsv -c:v h264_qsv -y foo.mkv +[AVHWDeviceContext @ 0x8062d0140] Error initializing an MFX session: -3. +Device creation failed: -1313558101. +Failed to set value 'qsv=auto' for option 'init_hw_device': Unknown error occurred +Error parsing global options: Unknown error occurred + +--- api/mfx_dispatch/linux/device_ids.h.orig 2021-10-26 06:00:35 UTC ++++ api/mfx_dispatch/linux/device_ids.h +@@ -404,7 +404,62 @@ static inline eMFXHWType get_platform(int device_id) { + return MFX_HW_UNKNOWN; + } + ++#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) ++#if defined(__FreeBSD__) && __FreeBSD__ < 13 ++#include ++#else ++#include ++#include ++#include ++#endif // defined(__FreeBSD__) && __FreeBSD__ < 13 ++ ++struct drm_pciinfo { ++ uint16_t domain; ++ uint8_t bus; ++ uint8_t dev; ++ uint8_t func; ++ uint16_t vendor_id; ++ uint16_t device_id; ++ uint16_t subvendor_id; ++ uint16_t subdevice_id; ++ uint8_t revision_id; ++}; ++ ++#define DRM_IOCTL_BASE 'd' ++#define DRM_IOR(nr,type) _IOR(DRM_IOCTL_BASE,nr,type) ++#define DRM_IOCTL_GET_PCIINFO DRM_IOR(0x15, struct drm_pciinfo) ++#endif ++ + std::vector get_devices() { ++#ifdef DRM_IOCTL_GET_PCIINFO ++ std::vector result; ++ for (int i = 0; i < 64; ++i) { ++#if defined(__FreeBSD__) && __FreeBSD__ < 13 ++ std::string mib = "dev.drm." + std::to_string(128 + i) + ".PCI_ID"; ++ char pci_id[20]; ++ size_t len = sizeof(pci_id); ++ if (sysctlbyname(mib.c_str(), pci_id, &len, NULL, 0)) continue; ++ Device device; ++ sscanf(pci_id, "%x:%x", &device.vendor_id, &device.device_id); ++#else ++ std::string path = "/dev/dri/renderD" + std::to_string(128 + i); ++ int fd = open(path.c_str(), O_RDONLY); ++ if (fd == -1) continue; ++ struct drm_pciinfo pinfo; ++ if (ioctl(fd, DRM_IOCTL_GET_PCIINFO, &pinfo)) { ++ close(fd); ++ continue; ++ } ++ Device device = { .vendor_id = pinfo.vendor_id, .device_id = pinfo.device_id }; ++ close(fd); ++#endif // defined(__FreeBSD__) && __FreeBSD__ < 13 ++ if (device.vendor_id != 0x8086) { // Filter out non-Intel devices ++ continue; ++ } ++ device.platform = get_platform(device.device_id); ++ result.emplace_back(device); ++ } ++#else + const char *dir = "/sys/class/drm"; + const char *device_id_file = "/device/device"; + const char *vendor_id_file = "/device/vendor"; +@@ -431,6 +486,7 @@ std::vector get_devices() { + device.platform = get_platform(device.device_id); + result.emplace_back(device); + } ++#endif + std::sort(result.begin(), result.end(), [](const Device &a, const Device &b) { + return a.platform < b.platform; + }); diff --git a/multimedia/intel-media-sdk/files/patch-msdk-default b/multimedia/intel-media-sdk/files/patch-msdk-default deleted file mode 100644 index 503fcbbf792f..000000000000 --- a/multimedia/intel-media-sdk/files/patch-msdk-default +++ /dev/null @@ -1,28 +0,0 @@ -/sys/class/drm/renderD*/device/device is Linux-only, so default to -INTEL_MEDIA_RUNTIME=MSDK on other systems. - -$ ffmpeg -hide_banner -init_hw_device qsv=auto -i foo.y4m -vf hwupload=extra_hw_frames=64,format=qsv -c:v h264_qsv -y foo.mkv -[AVHWDeviceContext @ 0x8062d0140] Error initializing an MFX session: -3. -Device creation failed: -1313558101. -Failed to set value 'qsv=auto' for option 'init_hw_device': Unknown error occurred -Error parsing global options: Unknown error occurred - ---- api/mfx_dispatch/linux/mfxloader.cpp.orig 2021-09-29 15:58:50 UTC -+++ api/mfx_dispatch/linux/mfxloader.cpp -@@ -181,11 +181,16 @@ mfxStatus LoaderCtx::Init(mfxInitParam& par) - return MFX_ERR_UNSUPPORTED; - } - -+#ifdef __linux__ - eMFXHWType platform = MFX_HW_UNKNOWN; - auto devices = get_devices(); - if (devices.size()) { - platform = devices[devices.size() - 1].platform; - } -+#else -+ // Assume a legacy generation not supported by oneVPL-intel-gpu -+ eMFXHWType platform = MFX_HW_SKL; -+#endif - - std::vector libs; -