From 31fe817cf481229c7a465bcd2ff62d2e9a7ca6d3 Mon Sep 17 00:00:00 2001 From: "Teng, Jin Chung" Date: Mon, 9 Aug 2021 14:51:11 +0800 Subject: onevpl: Fixing render issue on virtual environment The i915 render device node is not always in renderD128. For example render node on virtual env is renderD129. Change the hard coded with autodetect the i915 device via ioctl Signed-off-by: Teng, Jin Chung Signed-off-by: Anuj Mittal --- .../0001-Fix-the-rendering-to-X11-failures.patch | 135 +++++++++++++++++++++ recipes-multimedia/onevpl/onevpl_2021.4.0.bb | 1 + 2 files changed, 136 insertions(+) create mode 100644 recipes-multimedia/onevpl/onevpl/0001-Fix-the-rendering-to-X11-failures.patch (limited to 'recipes-multimedia') diff --git a/recipes-multimedia/onevpl/onevpl/0001-Fix-the-rendering-to-X11-failures.patch b/recipes-multimedia/onevpl/onevpl/0001-Fix-the-rendering-to-X11-failures.patch new file mode 100644 index 00000000..9335c214 --- /dev/null +++ b/recipes-multimedia/onevpl/onevpl/0001-Fix-the-rendering-to-X11-failures.patch @@ -0,0 +1,135 @@ +From 775669dbdd97a52dc32dab82c3d5efd160f9e807 Mon Sep 17 00:00:00 2001 +From: "Chew, Tong Liang" +Date: Mon, 9 Aug 2021 02:19:01 +0000 +Subject: [PATCH] Fix the rendering to X11 failures + +The i915 render device node is not always in renderD128. +Change the hard coded with autodetect the i915 device via ioctl + +Upstream-Status: Submitted +https://github.com/oneapi-src/oneVPL/pull/21 + +Signed-off-by: Chew, Tong Liang +Signed-off-by: Teng, Jin Chung +--- + tools/legacy/sample_common/src/vaapi_device.cpp | 24 +++++++++++++- + tools/legacy/sample_common/src/vaapi_utils_x11.cpp | 38 +++++++++++++++++++--- + 2 files changed, 57 insertions(+), 5 deletions(-) + +diff --git a/tools/legacy/sample_common/src/vaapi_device.cpp b/tools/legacy/sample_common/src/vaapi_device.cpp +index b034376..f78c5aa 100644 +--- a/tools/legacy/sample_common/src/vaapi_device.cpp ++++ b/tools/legacy/sample_common/src/vaapi_device.cpp +@@ -20,6 +20,7 @@ + #include "vaapi_allocator.h" + #if defined(X11_DRI3_SUPPORT) + #include ++ #include + + #define ALIGN(x, y) (((x) + (y)-1) & -(y)) + #define PAGE_ALIGN(x) ALIGN(x, 4096) +@@ -27,6 +28,11 @@ + + #define VAAPI_GET_X_DISPLAY(_display) (Display*)(_display) + #define VAAPI_GET_X_WINDOW(_window) (Window*)(_window) ++ const char* MFX_DEVICE_NODE_RENDER = "/dev/dri/renderD"; ++ const char* MFX_DEVICE_DRIVER_NAME = "i915"; ++ constexpr mfxU32 MFX_DEVICE_DRIVER_NAME_LEN = 4; ++ constexpr mfxU32 MFX_DEVICE_NODE_INDEX = 128; ++ constexpr mfxU32 MFX_DEVICE_MAX_NODES = 16; + + CVAAPIDeviceX11::~CVAAPIDeviceX11(void) { + Close(); +@@ -73,7 +79,23 @@ mfxStatus CVAAPIDeviceX11::Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNu + + // it's enough to pass render node, because we only request + // information from kernel via m_dri_fd +- m_dri_fd = open("/dev/dri/renderD128", O_RDWR); ++ for (mfxU32 i = 0; i < MFX_DEVICE_MAX_NODES; ++i) { ++ std::string devPath = MFX_DEVICE_NODE_RENDER + std::to_string(MFX_DEVICE_NODE_INDEX + i); ++ m_dri_fd = open(devPath.c_str(), O_RDWR); ++ if (m_dri_fd < 0) continue; ++ ++ char driverName[MFX_DEVICE_DRIVER_NAME_LEN + 1] = {}; ++ drm_version_t version = {}; ++ version.name_len = MFX_DEVICE_DRIVER_NAME_LEN; ++ version.name = driverName; ++ ++ if(!ioctl(m_dri_fd, DRM_IOWR(0, drm_version), &version) && ++ !strcmp(driverName, MFX_DEVICE_DRIVER_NAME)) { ++ break; ++ } ++ close(m_dri_fd); ++ } ++ + if (m_dri_fd < 0) { + msdk_printf(MSDK_STRING("Failed to open dri device\n")); + return MFX_ERR_NOT_INITIALIZED; +diff --git a/tools/legacy/sample_common/src/vaapi_utils_x11.cpp b/tools/legacy/sample_common/src/vaapi_utils_x11.cpp +index 9770a2f..734cd10 100644 +--- a/tools/legacy/sample_common/src/vaapi_utils_x11.cpp ++++ b/tools/legacy/sample_common/src/vaapi_utils_x11.cpp +@@ -10,18 +10,24 @@ + #include "sample_defs.h" + + #include +- #if defined(X11_DRI3_SUPPORT) +- #include +- #endif ++ #include ++ #include + + #define VAAPI_X_DEFAULT_DISPLAY ":0.0" + ++ const char* MFX_X11_NODE_RENDER = "/dev/dri/renderD"; ++ const char* MFX_X11_DRIVER_NAME = "i915"; ++ constexpr mfxU32 MFX_X11_DRIVER_NAME_LEN = 4; ++ constexpr mfxU32 MFX_X11_NODE_INDEX = 128; ++ constexpr mfxU32 MFX_X11_MAX_NODES = 16; ++ + X11LibVA::X11LibVA(void) + : CLibVA(MFX_LIBVA_X11), + m_display(0), + m_configID(VA_INVALID_ID), + m_contextID(VA_INVALID_ID) { + char* currentDisplay = getenv("DISPLAY"); ++ int fd = -1; + + m_display = (currentDisplay) ? m_x11lib.XOpenDisplay(currentDisplay) + : m_x11lib.XOpenDisplay(VAAPI_X_DEFAULT_DISPLAY); +@@ -32,7 +38,31 @@ X11LibVA::X11LibVA(void) + throw std::bad_alloc(); + } + +- m_va_dpy = m_vax11lib.vaGetDisplay(m_display); ++ for (mfxU32 i = 0; i < MFX_X11_MAX_NODES; ++i) { ++ std::string devPath = MFX_X11_NODE_RENDER + std::to_string(MFX_X11_NODE_INDEX + i); ++ fd = -1; ++ fd = open(devPath.c_str(), O_RDWR); ++ if (fd < 0) continue; ++ ++ char driverName[MFX_X11_DRIVER_NAME_LEN + 1] = {}; ++ drm_version_t version = {}; ++ version.name_len = MFX_X11_DRIVER_NAME_LEN; ++ version.name = driverName; ++ ++ if(!ioctl(fd, DRM_IOWR(0, drm_version), &version) && ++ !strcmp(driverName, MFX_X11_DRIVER_NAME)) { ++ break; ++ } ++ close(fd); ++ } ++ ++ if (fd < 0) { ++ m_x11lib.XCloseDisplay(m_display); ++ msdk_printf(MSDK_STRING("Failed to open adapter\n")); ++ throw std::bad_alloc(); ++ } ++ ++ m_va_dpy = m_vadrmlib.vaGetDisplayDRM(fd); + if (!m_va_dpy) { + m_x11lib.XCloseDisplay(m_display); + msdk_printf(MSDK_STRING("Failed to get VA Display\n")); +-- +2.7.4 + diff --git a/recipes-multimedia/onevpl/onevpl_2021.4.0.bb b/recipes-multimedia/onevpl/onevpl_2021.4.0.bb index cdd22a34..5982c18a 100644 --- a/recipes-multimedia/onevpl/onevpl_2021.4.0.bb +++ b/recipes-multimedia/onevpl/onevpl_2021.4.0.bb @@ -13,6 +13,7 @@ SRC_URI = "git://github.com/oneapi-src/oneVPL.git;protocol=https \ file://0001-Corrected-the-install-path.patch \ file://0001-Adding-X11-DRI3-support.patch \ file://0001-Fix-sample_multi_transcode-join-issue.patch \ + file://0001-Fix-the-rendering-to-X11-failures.patch \ " SRCREV = "d5c072584ee6f81305ed85de8759658ab7854606" S = "${WORKDIR}/git" -- cgit v1.2.3-54-g00ecf