summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia/onevpl/onevpl/0001-Fix-the-rendering-to-X11-failures.patch
blob: 9335c214ad71208329ac7ed7566ae04167005066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
From 775669dbdd97a52dc32dab82c3d5efd160f9e807 Mon Sep 17 00:00:00 2001
From: "Chew, Tong Liang" <tong.liang.chew@intel.com>
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 <tong.liang.chew@intel.com>
Signed-off-by: Teng, Jin Chung <jin.chung.teng@intel.com>
---
 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 <fcntl.h>
+            #include <sys/ioctl.h>
 
             #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 <dlfcn.h>
-    #if defined(X11_DRI3_SUPPORT)
-        #include <fcntl.h>
-    #endif
+    #include <fcntl.h>
+    #include <sys/ioctl.h>
 
     #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