summarylogtreecommitdiffstats
path: root/0062-gallium-pvr-support-DRI-Image-extension-v21.patch
blob: 7cc2bb1e1c9febf0aece9d85d7baca5a9e3dc3a4 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
From d9777cee3bd82e3451e0e9a6a422612c62adf967 Mon Sep 17 00:00:00 2001
From: Brendan King <Brendan.King@imgtec.com>
Date: Thu, 18 Aug 2022 19:14:29 +0100
Subject: [PATCH] gallium/pvr: support DRI Image extension v21

IMG NOTE: This patch should be merged into the "Add PVR Gallium
driver" patch the next time the Mesa version is upgraded in the
IMG DDK.

---
 src/gallium/frontends/pvr/dri_support.h    | 46 +++++++++++
 src/gallium/frontends/pvr/pvrcompat.c      | 74 +++++++++++++++++
 src/gallium/frontends/pvr/pvrdri_support.h | 27 +++++++
 src/gallium/frontends/pvr/pvrext.c         | 94 +++++++++++++++++++++-
 4 files changed, 240 insertions(+), 1 deletion(-)

diff --git a/src/gallium/frontends/pvr/dri_support.h b/src/gallium/frontends/pvr/dri_support.h
index b0b3106..3cc8f29 100644
--- a/src/gallium/frontends/pvr/dri_support.h
+++ b/src/gallium/frontends/pvr/dri_support.h
@@ -489,6 +489,52 @@ struct  PVRDRISupportInterfaceV2
 	struct {
 		bool (*HaveGetFenceFromCLEvent)(void);
 	} v4;
+	/* The v5 interface is an extension of v4, so v4 is required as well */
+	struct {
+		__DRIimage *(*CreateImageFromDMABufs3)
+			(struct DRISUPScreen *psDRISUPScreen,
+			 int iWidth,
+			 int iHeight,
+			 int iFourCC,
+			 uint64_t uModifier,
+			 int *piFDs,
+			 int iNumFDs,
+			 int *piStrides,
+			 int *piOffsets,
+			 unsigned int uColorSpace,
+			 unsigned int uSampleRange,
+			 unsigned int uHorizSiting,
+			 unsigned int uVertSiting,
+			 uint32_t uFlags,
+			 unsigned int *puError,
+			 void *pvLoaderPrivate);
+
+		__DRIimage *(*CreateImageWithModifiers2)
+			(struct DRISUPScreen *psDRISUPScreen,
+			 int iWidth,
+			 int iHeight,
+			 int iFourCC,
+			 const uint64_t *puModifiers,
+			 const unsigned int uModifierCount,
+			 unsigned int uUsage,
+			 void *pvLoaderPrivate);
+
+		__DRIimage *(*CreateImageFromFDs2)
+			(struct DRISUPScreen *psDRISUPcreen,
+			 int iWidth,
+			 int iHeight,
+			 int iFourCC,
+			 int *piFDs,
+			 int iNumFDs,
+			 uint32_t uFlags,
+			 int *piStrides,
+			 int *piOffsets,
+			 void *pvLoaderPrivate);
+
+		void (*SetInFenceFD)
+			(__DRIimage *psImage,
+			 int iFD);
+	} v5;
 };
 
 struct PVRDRIImageList {
diff --git a/src/gallium/frontends/pvr/pvrcompat.c b/src/gallium/frontends/pvr/pvrcompat.c
index 23a57dd..782c900 100644
--- a/src/gallium/frontends/pvr/pvrcompat.c
+++ b/src/gallium/frontends/pvr/pvrcompat.c
@@ -55,6 +55,10 @@ static pthread_mutex_t gsCompatLock = PTHREAD_MUTEX_INITIALIZER;
       ptr = dlsym(gpvSupLib, MAKESTRING(func)); \
    } while(0)
 
+/* Check if a function exists in the DRI Support interface structure */
+#define HaveFuncV2(field)                       \
+      ((gsSupV2.field) != NULL)                 \
+
 /* Call a function via the DRI Support interface structure */
 #define CallFuncV2(field, ...)                  \
    do {                                         \
@@ -238,6 +242,7 @@ MODSUPRegisterSupportInterfaceV2(const void *pvInterface,
    case 2:
    case 3:
    case 4:
+   case 5:
       /* These versions require version 0 */
       return false;
    default:
@@ -247,6 +252,13 @@ MODSUPRegisterSupportInterfaceV2(const void *pvInterface,
    /* The "default" case should be associated with the latest version */
    switch (uVersion) {
    default:
+   case 5:
+      /* This version is an extension of versions 0 to 4 */
+      if (uMinVersion > 0)
+         return false;
+
+      uEnd = PVRDRIInterfaceV2End(v5);
+      break;
    case 4:
       /* This version is an extension of versions 0 to 3 */
       if (uMinVersion > 0)
@@ -836,3 +848,65 @@ DRISUPHaveGetFenceFromCLEvent(void)
 
    return true;
 }
+
+__DRIimage *
+DRISUPCreateImageFromDMABufs3(struct DRISUPScreen *psDRISUPScreen,
+                              int iWidth, int iHeight, int iFourCC,
+                              uint64_t uModifier, int *piFDs, int iNumFDs,
+                              int *piStrides, int *piOffsets,
+                              unsigned int uColorSpace,
+                              unsigned int uSampleRange,
+                              unsigned int uHorizSiting,
+                              unsigned int uVertSiting,
+                              uint32_t uFlags,
+                              unsigned int *puError, void *pvLoaderPrivate)
+{
+   CallFuncV2(v5.CreateImageFromDMABufs3,
+              psDRISUPScreen, iWidth, iHeight, iFourCC, uModifier,
+              piFDs, iNumFDs, piStrides, piOffsets, uColorSpace, uSampleRange,
+              uHorizSiting, uVertSiting, uFlags, puError, pvLoaderPrivate);
+
+   return NULL;
+}
+
+__DRIimage *
+DRISUPCreateImageWithModifiers2(struct DRISUPScreen *psDRISUPScreen,
+                                int iWidth, int iHeight, int iFourCC,
+                                const uint64_t *puModifiers,
+                                const unsigned int uModifierCount,
+                                unsigned int uUse,
+                                void *pvLoaderPrivate)
+{
+   CallFuncV2(v5.CreateImageWithModifiers2,
+              psDRISUPScreen, iWidth, iHeight, iFourCC, puModifiers,
+              uModifierCount, uUse, pvLoaderPrivate);
+
+   return NULL;
+}
+
+__DRIimage *
+DRISUPCreateImageFromFDs2(struct DRISUPScreen *psDRISUPcreen,
+                          int iWidth, int iHeight, int iFourCC,
+                          int *piFDs, int iNumFDs, uint32_t uFlags,
+                          int *piStrides, int *piOffsets,
+                          void *pvLoaderPrivate)
+{
+   CallFuncV2(v5.CreateImageFromFDs2,
+              psDRISUPcreen, iWidth, iHeight, iFourCC, piFDs, iNumFDs,
+              uFlags, piStrides, piOffsets, pvLoaderPrivate);
+
+   return NULL;
+}
+
+bool
+DRISUPHaveSetInFenceFd(void)
+{
+	return HaveFuncV2(v5.SetInFenceFD);
+}
+
+void
+DRISUPSetInFenceFd(__DRIimage *psImage, int iFd)
+{
+   CallFuncV2(v5.SetInFenceFD,
+              psImage, iFd);
+}
diff --git a/src/gallium/frontends/pvr/pvrdri_support.h b/src/gallium/frontends/pvr/pvrdri_support.h
index 58ea350..f735354 100644
--- a/src/gallium/frontends/pvr/pvrdri_support.h
+++ b/src/gallium/frontends/pvr/pvrdri_support.h
@@ -203,4 +203,31 @@ void DRISUPSetDamageRegion(struct DRISUPDrawable *psDRISUPDrawable,
 
 bool DRISUPHaveGetFenceFromCLEvent(void);
 
+__DRIimage *DRISUPCreateImageFromDMABufs3(struct DRISUPScreen *psDRISUPScreen,
+                                          int iWidth, int iHeight,
+                                          int iFourCC, uint64_t uModifier,
+                                          int *piFDs, int iNumFDs,
+                                          int *piStrides, int *piOffsets,
+                                          unsigned int uColorSpace,
+                                          unsigned int uSampleRange,
+                                          unsigned int uHorizSiting,
+                                          unsigned int uVertSiting,
+                                          uint32_t uFlags,
+                                          unsigned int *puError,
+                                          void *pvLoaderPrivate);
+__DRIimage *DRISUPCreateImageWithModifiers2(struct DRISUPScreen *psDRISUPScreen,
+                                            int iWidth, int iHeight,
+                                            int iFourCC,
+                                            const uint64_t *puModifiers,
+                                            const unsigned int uModifierCount,
+                                            unsigned int uUse,
+                                            void *pvLoaderPrivate);
+__DRIimage *DRISUPCreateImageFromFDs2(struct DRISUPScreen *psDRISUPcreen,
+                                      int iWidth, int iHeight, int iFourCC,
+                                      int *piFDs, int iNumFDs, uint32_t uFlags,
+                                      int *piStrides, int *piOffsets,
+                                      void *pvLoaderPrivate);
+
+bool DRISUPHaveSetInFenceFd(void);
+void DRISUPSetInFenceFd(__DRIimage *psImage, int iFd);
 #endif /* defined(__PVRDRI_SUPPORT_H__) */
diff --git a/src/gallium/frontends/pvr/pvrext.c b/src/gallium/frontends/pvr/pvrext.c
index 4783996..826e84f 100644
--- a/src/gallium/frontends/pvr/pvrext.c
+++ b/src/gallium/frontends/pvr/pvrext.c
@@ -71,7 +71,7 @@
 /* Maximum version numbers for each supported extension */
 #define PVR_DRI_TEX_BUFFER_VERSION      3
 #define PVR_DRI2_FLUSH_VERSION          4
-#define PVR_DRI_IMAGE_VERSION           17
+#define PVR_DRI_IMAGE_VERSION           21
 #define PVR_DRI2_ROBUSTNESS_VERSION     1
 #define PVR_DRI2_FENCE_VERSION          2
 #define PVR_DRI2_RENDERER_QUERY_VERSION 1
@@ -445,6 +445,68 @@ PVRDRICreateImageFromRenderbuffer2(__DRIcontext *psDRIContext,
                                              pvLoaderPrivate, puError);
 }
 
+static __DRIimage *
+PVRDRICreateImageFromDmaBufs3(__DRIscreen *psDRIScreen,
+                              int iWidth, int iHeight,
+                              int iFourCC, uint64_t uModifier,
+                              int *piFDs, int iNumFDs,
+                              int *piStrides, int *piOffsets,
+                              enum __DRIYUVColorSpace eColorSpace,
+                              enum __DRISampleRange eSampleRange,
+                              enum __DRIChromaSiting eHorizSiting,
+                              enum __DRIChromaSiting eVertSiting,
+                              uint32_t uFlags, unsigned int *puError,
+                              void *pvLoaderPrivate)
+{
+   PVRDRIScreen *psPVRScreen = psDRIScreen->driverPrivate;
+
+   return DRISUPCreateImageFromDMABufs3(psPVRScreen->psDRISUPScreen,
+                                        iWidth, iHeight, iFourCC, uModifier,
+                                        piFDs, iNumFDs, piStrides, piOffsets,
+                                        (unsigned int) eColorSpace,
+                                        (unsigned int) eSampleRange,
+                                        (unsigned int) eHorizSiting,
+                                        (unsigned int) eVertSiting,
+                                        uFlags, puError, pvLoaderPrivate);
+}
+
+static __DRIimage *
+PVRDRICreateImageWithModifiers2(__DRIscreen *psDRIScreen,
+                                int iWidth, int iHeight, int iFormat,
+                                const uint64_t *puModifiers,
+                                const unsigned int uModifierCount,
+                                unsigned int uUse,
+                                void *pvLoaderPrivate)
+{
+   PVRDRIScreen *psPVRScreen = psDRIScreen->driverPrivate;
+   int iFourCC = PVRDRIFormatToFourCC(iFormat);
+
+   return DRISUPCreateImageWithModifiers2(psPVRScreen->psDRISUPScreen,
+                                          iWidth, iHeight, iFourCC,
+                                          puModifiers, uModifierCount,
+                                          uUse, pvLoaderPrivate);
+}
+
+static __DRIimage *
+PVRDRICreateImageFromFds2(__DRIscreen *psDRIScreen, int iWidth, int iHeight,
+                          int iFourCC, int *piFDs, int iNumFDs,
+                          uint32_t uFlags, int *piStrides, int *piOffsets,
+                          void *pvLoaderPrivate)
+{
+   PVRDRIScreen *psPVRScreen = psDRIScreen->driverPrivate;
+
+   return DRISUPCreateImageFromFDs2(psPVRScreen->psDRISUPScreen,
+                                    iWidth, iHeight, iFourCC, piFDs, iNumFDs,
+                                    uFlags, piStrides, piOffsets,
+                                    pvLoaderPrivate);
+}
+
+static void
+PVRDRISetInFenceFd(__DRIimage *psImage, int iFd)
+{
+   return DRISUPSetInFenceFd(psImage, iFd);
+}
+
 #if defined(EGL_IMG_cl_image)
 static __DRIimage *
 PVRDRICreateImageFromBuffer(__DRIcontext *psDRIContext, int iTarget,
@@ -486,6 +548,10 @@ static __DRIimageExtension pvrDRIImage = {
    .queryDmaBufFormatModifierAttribs =
    PVRDRIQueryDmaBufFormatModifierAttribs,
    .createImageFromRenderbuffer2 = PVRDRICreateImageFromRenderbuffer2,
+   .createImageFromDmaBufs3 = PVRDRICreateImageFromDmaBufs3,
+   .createImageWithModifiers2 = PVRDRICreateImageWithModifiers2,
+   .createImageFromFds2 = PVRDRICreateImageFromFds2,
+   .setInFenceFd = PVRDRISetInFenceFd,
 #if defined(EGL_IMG_cl_image)
    .createImageFromBuffer = PVRDRICreateImageFromBuffer,
 #endif
@@ -684,8 +750,10 @@ PVRDRIScreenExtensionVersionInfo(void)
 void
 PVRDRIAdjustExtensions(unsigned int uVersion, unsigned int uMinVersion)
 {
+   /* __DRI2fenceExtension adjustment */
    switch (uVersion) {
    default:
+   case 5:
    case 4:
       /* Is the KHR_cl_event2 EGL extension supported? */
       if (!DRISUPHaveGetFenceFromCLEvent())
@@ -701,4 +769,28 @@ PVRDRIAdjustExtensions(unsigned int uVersion, unsigned int uMinVersion)
       pvrDRIFenceExtension.get_fence_from_cl_event = NULL;
       break;
    }
+
+   /* __DRIimageExtension adjustment */
+   switch (uVersion) {
+   default:
+   case 5:
+      if (!DRISUPHaveSetInFenceFd())
+         pvrDRIImage.setInFenceFd = NULL;
+
+      break;
+   case 4:
+   case 3:
+   case 2:
+   case 1:
+   case 0:
+      /*
+       * The following are not supported:
+       *    createImageFromDmaBufs3
+       *    createImageWithModifiers2
+       *    createImageFromFds2
+       *    setInFenceFd
+       */
+      pvrDRIImage.base.version = 17;
+      break;
+   }
 }