summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia/onevpl/onevpl/0001-samples-Add-support-of-DRM_FORMAT_NV12-for-console-m.patch
blob: a5191fe2d40d02f273c5d122a405cc1fbe34f318 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From a7f667debb6cf3007ef5b581a91ff7c925d623c3 Mon Sep 17 00:00:00 2001
From: "Yew, Chang Ching" <chang.ching.yew@intel.com>
Date: Wed, 25 Aug 2021 11:13:28 +0000
Subject: [PATCH 1/2] samples: Add support of DRM_FORMAT_NV12 for console mode
 rendering

Currently in drm/console mode only RGB4 direct rendering
is possible. This patch add NV12 format provided your
platform and kernel can support it.

Tested both formats using:
sample_encode h265 -i 4k.h265 -rdrm -nv12
sample_encode h265 -i 4k.h265 -rdrm -rgb4

Upstream-Status: Submitted
innersource PR #221

Signed-off: Fu, Wei A <wei.a.fu@intel.com>
Signed-off-by: Sodhi, Vunny <vunny.sodhi@intel.com>
Signed-off-by: Yew, Chang Ching <chang.ching.yew@intel.com>
---
 .../sample_common/include/vaapi_utils.h       | 11 ++++
 .../sample_common/src/vaapi_allocator.cpp     |  1 +
 .../legacy/sample_common/src/vaapi_utils.cpp  |  1 +
 .../sample_common/src/vaapi_utils_drm.cpp     | 61 +++++++++++++++----
 4 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/tools/legacy/sample_common/include/vaapi_utils.h b/tools/legacy/sample_common/include/vaapi_utils.h
index 53318630..9df5507b 100644
--- a/tools/legacy/sample_common/include/vaapi_utils.h
+++ b/tools/legacy/sample_common/include/vaapi_utils.h
@@ -149,6 +149,16 @@ public:
                                      uint32_t pitch,
                                      uint32_t bo_handle,
                                      uint32_t* buf_id);
+    typedef int (*drmModeAddFB2WithModifiers_type)(int fd,
+                                                   uint32_t width,
+                                                   uint32_t height,
+                                                   uint32_t pixel_format,
+                                                   uint32_t bo_handles[4],
+                                                   uint32_t pitches[4],
+                                                   uint32_t offsets[4],
+                                                   uint64_t modifier[4],
+                                                   uint32_t* buf_id,
+                                                   uint32_t flags);
     typedef void (*drmModeFreeConnector_type)(drmModeConnectorPtr ptr);
     typedef void (*drmModeFreeCrtc_type)(drmModeCrtcPtr ptr);
     typedef void (*drmModeFreeEncoder_type)(drmModeEncoderPtr ptr);
@@ -192,6 +202,7 @@ public:
         #define __DECLARE(name) const name##_type name
     __DECLARE(drmIoctl);
     __DECLARE(drmModeAddFB);
+    __DECLARE(drmModeAddFB2WithModifiers);
     __DECLARE(drmModeFreeConnector);
     __DECLARE(drmModeFreeCrtc);
     __DECLARE(drmModeFreeEncoder);
diff --git a/tools/legacy/sample_common/src/vaapi_allocator.cpp b/tools/legacy/sample_common/src/vaapi_allocator.cpp
index 51690186..12ace297 100644
--- a/tools/legacy/sample_common/src/vaapi_allocator.cpp
+++ b/tools/legacy/sample_common/src/vaapi_allocator.cpp
@@ -364,6 +364,7 @@ mfxStatus vaapiFrameAllocator::AllocImpl(mfxFrameAllocRequest* request,
                 }
             }
             if (m_exporter) {
+                vaapi_mids[i].m_fourcc = va_fourcc;
                 vaapi_mids[i].m_custom = m_exporter->acquire(&vaapi_mids[i]);
                 if (!vaapi_mids[i].m_custom) {
                     mfx_res = MFX_ERR_UNKNOWN;
diff --git a/tools/legacy/sample_common/src/vaapi_utils.cpp b/tools/legacy/sample_common/src/vaapi_utils.cpp
index b69dbe44..9531c65b 100644
--- a/tools/legacy/sample_common/src/vaapi_utils.cpp
+++ b/tools/legacy/sample_common/src/vaapi_utils.cpp
@@ -94,6 +94,7 @@ DRM_Proxy::DRM_Proxy()
         : lib("libdrm.so.2"),
           SIMPLE_LOADER_FUNCTION(drmIoctl),
           SIMPLE_LOADER_FUNCTION(drmModeAddFB),
+          SIMPLE_LOADER_FUNCTION(drmModeAddFB2WithModifiers),
           SIMPLE_LOADER_FUNCTION(drmModeFreeConnector),
           SIMPLE_LOADER_FUNCTION(drmModeFreeCrtc),
           SIMPLE_LOADER_FUNCTION(drmModeFreeEncoder),
diff --git a/tools/legacy/sample_common/src/vaapi_utils_drm.cpp b/tools/legacy/sample_common/src/vaapi_utils_drm.cpp
index c896017b..cf8d7ba7 100644
--- a/tools/legacy/sample_common/src/vaapi_utils_drm.cpp
+++ b/tools/legacy/sample_common/src/vaapi_utils_drm.cpp
@@ -11,9 +11,9 @@
     #include <sys/ioctl.h>
     #include "vaapi_allocator.h"
 
-    #include <stdexcept>
-
     #include <drm_fourcc.h>
+    #include <stdexcept>
+    #include "i915_drm.h"
     #include "vaapi_utils_drm.h"
 
 constexpr mfxU32 MFX_DRI_MAX_NODES_NUM      = 16;
@@ -311,7 +311,8 @@ bool drmRenderer::getPlane() {
         if (plane) {
             if (plane->possible_crtcs & (1 << m_crtcIndex)) {
                 for (uint32_t j = 0; j < plane->count_formats; ++j) {
-                    if (plane->formats[j] == DRM_FORMAT_XRGB8888) {
+                    if ((plane->formats[j] == DRM_FORMAT_XRGB8888) ||
+                        (plane->formats[j] == DRM_FORMAT_NV12)) {
                         m_planeID = plane->plane_id;
                         m_drmlib.drmModeFreePlane(plane);
                         m_drmlib.drmModeFreePlaneResources(planes);
@@ -404,14 +405,52 @@ void* drmRenderer::acquire(mfxMemId mid) {
         if (ret)
             return NULL;
 
-        ret = m_drmlib.drmModeAddFB(m_fd,
-                                    vmid->m_image.width,
-                                    vmid->m_image.height,
-                                    24,
-                                    32,
-                                    vmid->m_image.pitches[0],
-                                    flink_open.handle,
-                                    &fbhandle);
+        uint32_t handles[4], pitches[4], offsets[4], pixel_format;
+        uint64_t modifiers[4];
+
+        memset(&handles, 0, sizeof(handles));
+        memset(&pitches, 0, sizeof(pitches));
+        memset(&offsets, 0, sizeof(offsets));
+        memset(&modifiers, 0, sizeof(modifiers));
+
+        handles[0] = flink_open.handle;
+        pitches[0] = vmid->m_image.pitches[0];
+        offsets[0] = vmid->m_image.offsets[0];
+
+        if (VA_FOURCC_NV12 == vmid->m_fourcc) {
+            struct drm_i915_gem_set_tiling set_tiling;
+
+            pixel_format = DRM_FORMAT_NV12;
+            memset(&set_tiling, 0, sizeof(set_tiling));
+            set_tiling.handle      = flink_open.handle;
+            set_tiling.tiling_mode = I915_TILING_Y;
+            set_tiling.stride      = vmid->m_image.pitches[0];
+            ret = m_drmlib.drmIoctl(m_fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
+            if (ret) {
+                msdk_printf(MSDK_STRING("DRM_IOCTL_I915_GEM_SET_TILING Failed ret = %d\n"), ret);
+                return NULL;
+            }
+
+            handles[1]   = flink_open.handle;
+            pitches[1]   = vmid->m_image.pitches[1];
+            offsets[1]   = vmid->m_image.offsets[1];
+            modifiers[0] = modifiers[1] = I915_FORMAT_MOD_Y_TILED;
+        }
+        else {
+            pixel_format = DRM_FORMAT_XRGB8888;
+        }
+
+        ret = m_drmlib.drmModeAddFB2WithModifiers(m_fd,
+                                                  vmid->m_image.width,
+                                                  vmid->m_image.height,
+                                                  pixel_format,
+                                                  handles,
+                                                  pitches,
+                                                  offsets,
+                                                  modifiers,
+                                                  &fbhandle,
+                                                  0);
+
         if (ret)
             return NULL;
 
-- 
2.31.1