xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/gen8/ddi/media_libva_caps_g8.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     media_libva_caps_g8.cpp
24 //! \brief    This file implements the C++ class/interface for gen8 media capbilities.
25 //!
26 
27 #include "codec_def_encode_avc.h"
28 #include "media_libva_util.h"
29 #include "media_libva.h"
30 #include "media_libva_caps_g8.h"
31 #include "media_libva_caps_factory.h"
32 
33 const VAImageFormat m_supportedImageformatsG8[] =
34 {   {VA_FOURCC_BGRA,   VA_LSB_FIRST,   32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff,  0xff000000},
35     {VA_FOURCC_RGBA,   VA_LSB_FIRST,   32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000,  0xff000000},
36     {VA_FOURCC_BGRX,   VA_LSB_FIRST,   32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff,  0},
37     {VA_FOURCC_RGBX,   VA_LSB_FIRST,   32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000,  0},
38     {VA_FOURCC_RGB565, VA_LSB_FIRST,   16, 16, 0xf800,     0x07e0,     0x001f,      0},
39     {VA_FOURCC_NV12,   VA_LSB_FIRST,   12, 0,0,0,0,0},
40     {VA_FOURCC_NV21,   VA_LSB_FIRST,   12, 0,0,0,0,0},
41     {VA_FOURCC_YUY2,   VA_LSB_FIRST,   16, 0,0,0,0,0},
42     {VA_FOURCC_UYVY,   VA_LSB_FIRST,   16, 0,0,0,0,0},
43     {VA_FOURCC_YV12,   VA_LSB_FIRST,   12, 0,0,0,0,0},
44     {VA_FOURCC_I420,   VA_LSB_FIRST,   12, 0,0,0,0,0},
45     {VA_FOURCC_422H,   VA_LSB_FIRST,   16, 0,0,0,0,0},
46     {VA_FOURCC_422V,   VA_LSB_FIRST,   16, 0,0,0,0,0},
47     {VA_FOURCC_444P,   VA_LSB_FIRST,   24, 0,0,0,0,0},
48     {VA_FOURCC_IMC3,   VA_LSB_FIRST,   16, 0,0,0,0,0}
49 };
50 
QueryImageFormats(VAImageFormat * formatList,int32_t * numFormats)51 VAStatus MediaLibvaCapsG8::QueryImageFormats(VAImageFormat *formatList, int32_t *numFormats)
52 {
53     DDI_CHK_NULL(formatList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
54     DDI_CHK_NULL(numFormats, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
55     int32_t num = 0;
56     uint32_t maxNum = GetImageFormatsMaxNum();
57 
58     memset(formatList, 0,  sizeof(m_supportedImageformatsG8));
59     for (uint32_t idx = 0; idx < maxNum; idx++)
60     {
61         formatList[num].fourcc           = m_supportedImageformatsG8[idx].fourcc;
62         formatList[num].byte_order       = m_supportedImageformatsG8[idx].byte_order;
63         formatList[num].bits_per_pixel   = m_supportedImageformatsG8[idx].bits_per_pixel;
64         formatList[num].depth            = m_supportedImageformatsG8[idx].depth;
65         formatList[num].red_mask         = m_supportedImageformatsG8[idx].red_mask;
66         formatList[num].green_mask       = m_supportedImageformatsG8[idx].green_mask;
67         formatList[num].blue_mask        = m_supportedImageformatsG8[idx].blue_mask;
68         formatList[num].alpha_mask       = m_supportedImageformatsG8[idx].alpha_mask;
69         num++;
70     }
71     *numFormats = num;
72 
73     return VA_STATUS_SUCCESS;
74 }
75 
GetImageFormatsMaxNum()76 uint32_t MediaLibvaCapsG8::GetImageFormatsMaxNum()
77 {
78     return sizeof(m_supportedImageformatsG8)/sizeof(m_supportedImageformatsG8[0]);
79 }
80 
IsImageSupported(uint32_t fourcc)81 bool MediaLibvaCapsG8::IsImageSupported(uint32_t fourcc)
82 {
83     uint32_t maxNum = GetImageFormatsMaxNum();
84     for (int32_t idx = 0; idx < maxNum; idx++)
85     {
86         if (m_supportedImageformatsG8[idx].fourcc == fourcc)
87         {
88             return true;
89         }
90     }
91 
92     return false;
93 }
94 
PopulateColorMaskInfo(VAImageFormat * vaImgFmt)95 VAStatus MediaLibvaCapsG8::PopulateColorMaskInfo(VAImageFormat *vaImgFmt)
96 {
97     uint32_t maxNum = GetImageFormatsMaxNum();
98 
99     DDI_CHK_NULL(vaImgFmt, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
100 
101     for (int32_t idx = 0; idx < maxNum; idx++)
102     {
103         if (m_supportedImageformatsG8[idx].fourcc == vaImgFmt->fourcc)
104         {
105             vaImgFmt->red_mask   = m_supportedImageformatsG8[idx].red_mask;
106             vaImgFmt->green_mask = m_supportedImageformatsG8[idx].green_mask;
107             vaImgFmt->blue_mask  = m_supportedImageformatsG8[idx].blue_mask;
108             vaImgFmt->alpha_mask = m_supportedImageformatsG8[idx].alpha_mask;
109 
110             return VA_STATUS_SUCCESS;
111         }
112     }
113 
114     return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
115 }
116 
GetPlatformSpecificAttrib(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttribType type,uint32_t * value)117 VAStatus MediaLibvaCapsG8::GetPlatformSpecificAttrib(
118         VAProfile profile,
119         VAEntrypoint entrypoint,
120         VAConfigAttribType type,
121         uint32_t *value)
122 {
123     DDI_CHK_NULL(value, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
124     VAStatus status = VA_STATUS_SUCCESS;
125     *value = VA_ATTRIB_NOT_SUPPORTED;
126     switch ((int32_t)type)
127     {
128         case VAConfigAttribEncMaxRefFrames:
129         {
130             if (entrypoint == VAEntrypointEncSliceLP || !IsHevcProfile(profile))
131             {
132                 status = VA_STATUS_ERROR_INVALID_PARAMETER;
133             }
134             else
135             {
136                 *value = 1 | (1 << 16);
137             }
138             break;
139         }
140         case VAConfigAttribDecProcessing:
141         {
142             *value = VA_DEC_PROCESSING_NONE;
143             break;
144         }
145         case VAConfigAttribEncIntraRefresh:
146         {
147             if(IsAvcProfile(profile))
148             {
149                 *value = VA_ENC_INTRA_REFRESH_ROLLING_COLUMN |
150                     VA_ENC_INTRA_REFRESH_ROLLING_ROW;
151             }
152             else
153             {
154                 *value = VA_ENC_INTRA_REFRESH_NONE;
155             }
156             break;
157         }
158         case VAConfigAttribEncROI:
159         {
160             VAConfigAttribValEncROI roi_attr = { .value = 0 };
161 
162             if (entrypoint == VAEntrypointEncSliceLP)
163             {
164                 status = VA_STATUS_ERROR_INVALID_PARAMETER;
165             }
166             else if (IsAvcProfile(profile))
167             {
168                 roi_attr.bits.num_roi_regions = ENCODE_DP_AVC_MAX_ROI_NUMBER;
169             }
170 
171             *value = roi_attr.value;
172             break;
173         }
174         case VAConfigAttribCustomRoundingControl:
175         {
176             if (IsAvcProfile(profile))
177             {
178                 *value = 1;
179             }
180             else
181             {
182                 *value = 0;
183             }
184             break;
185         }
186         case VAConfigAttribEncMaxSlices:
187         {
188             *value = ENCODE_AVC_MAX_SLICES_SUPPORTED;
189             break;
190         }
191         case VAConfigAttribMaxPictureWidth:
192         {
193             if(profile == VAProfileJPEGBaseline)
194             {
195                 *value = ENCODE_JPEG_MAX_PIC_WIDTH;
196             }
197             else if(IsAvcProfile(profile))
198             {
199                 *value = CODEC_4K_MAX_PIC_WIDTH;
200             }
201             else
202             {
203                 *value = CODEC_MAX_PIC_WIDTH;
204             }
205             break;
206         }
207         case VAConfigAttribMaxPictureHeight:
208         {
209             if(profile == VAProfileJPEGBaseline)
210             {
211                 *value = ENCODE_JPEG_MAX_PIC_HEIGHT;
212             }
213             else if(IsAvcProfile(profile))
214             {
215                 *value = CODEC_4K_MAX_PIC_HEIGHT;
216             }
217             else
218             {
219                 *value = CODEC_MAX_PIC_HEIGHT;
220             }
221             break;
222         }
223         default:
224             status = VA_STATUS_ERROR_INVALID_PARAMETER;
225             break;
226     }
227     return status;
228 }
229 
LoadProfileEntrypoints()230 VAStatus MediaLibvaCapsG8::LoadProfileEntrypoints()
231 {
232     VAStatus status = VA_STATUS_SUCCESS;
233     status = LoadAvcDecProfileEntrypoints();
234     DDI_CHK_RET(status, "Failed to initialize Caps!");
235     status = LoadAvcEncProfileEntrypoints();
236     DDI_CHK_RET(status, "Failed to initialize Caps!");
237     status = LoadMpeg2DecProfileEntrypoints();
238     DDI_CHK_RET(status, "Failed to initialize Caps!");
239     status = LoadMpeg2EncProfileEntrypoints();
240     DDI_CHK_RET(status, "Failed to initialize Caps!");
241     status = LoadVc1DecProfileEntrypoints();
242     DDI_CHK_RET(status, "Failed to initialize Caps!");
243     status = LoadJpegDecProfileEntrypoints();
244     DDI_CHK_RET(status, "Failed to initialize Caps!");
245     status = LoadJpegEncProfileEntrypoints();
246     DDI_CHK_RET(status, "Failed to initialize Caps!");
247     status = LoadVp8DecProfileEntrypoints();
248     DDI_CHK_RET(status, "Failed to initialize Caps!");
249     status = LoadVp8EncProfileEntrypoints();
250     DDI_CHK_RET(status, "Failed to initialize Caps!");
251     status = LoadVp9DecProfileEntrypoints();
252     DDI_CHK_RET(status, "Failed to initialize Caps!");
253     status = LoadVp9EncProfileEntrypoints();
254     DDI_CHK_RET(status, "Failed to initialize Caps!");
255 #if !defined(_FULL_OPEN_SOURCE) && defined(ENABLE_KERNELS)
256     status = LoadNoneProfileEntrypoints();
257     DDI_CHK_RET(status, "Failed to initialize Caps!");
258 #endif
259     return status;
260 }
261 
QueryAVCROIMaxNum(uint32_t rcMode,bool isVdenc,uint32_t * maxNum,bool * isRoiInDeltaQP)262 VAStatus MediaLibvaCapsG8::QueryAVCROIMaxNum(uint32_t rcMode, bool isVdenc, uint32_t *maxNum, bool *isRoiInDeltaQP)
263 {
264     DDI_CHK_NULL(maxNum, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
265     DDI_CHK_NULL(isRoiInDeltaQP, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
266     DDI_CHK_CONDITION(isVdenc == true, "VDEnc is not supported in Gen8", VA_STATUS_ERROR_INVALID_PARAMETER);
267 
268     *maxNum = ENCODE_DP_AVC_MAX_ROI_NUMBER;
269     *isRoiInDeltaQP =  false;
270     return VA_STATUS_SUCCESS;
271 }
272 
GetMbProcessingRateEnc(MEDIA_FEATURE_TABLE * skuTable,uint32_t tuIdx,uint32_t codecMode,bool vdencActive,uint32_t * mbProcessingRatePerSec)273 VAStatus MediaLibvaCapsG8::GetMbProcessingRateEnc(
274         MEDIA_FEATURE_TABLE *skuTable,
275         uint32_t tuIdx,
276         uint32_t codecMode,
277         bool vdencActive,
278         uint32_t *mbProcessingRatePerSec)
279 {
280     DDI_CHK_NULL(skuTable, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
281     DDI_CHK_NULL(mbProcessingRatePerSec, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
282 
283     uint32_t gtIdx = 0;
284 
285     if (MEDIA_IS_SKU(skuTable, FtrGT1))
286     {
287         gtIdx = 3;
288     }
289     else if (MEDIA_IS_SKU(skuTable, FtrGT1_5))
290     {
291         gtIdx = 2;
292     }
293     else if (MEDIA_IS_SKU(skuTable, FtrGT2))
294     {
295         gtIdx = 1;
296     }
297     else if (MEDIA_IS_SKU(skuTable, FtrGT3))
298     {
299         gtIdx = 0;
300     }
301     else
302     {
303         return VA_STATUS_ERROR_INVALID_PARAMETER;
304     }
305 
306     if (MEDIA_IS_SKU(skuTable, FtrULX))
307     {
308         const uint32_t mbRate[7][4] =
309         {
310             // GT3 |  GT2   | GT1.5  |  GT1
311             { 0, 750000, 750000, 676280 },
312             { 0, 750000, 750000, 661800 },
313             { 0, 750000, 750000, 640000 },
314             { 0, 750000, 750000, 640000 },
315             { 0, 750000, 750000, 640000 },
316             { 0, 416051, 416051, 317980 },
317             { 0, 214438, 214438, 180655 }
318         };
319 
320         if (gtIdx == 0)
321         {
322             return VA_STATUS_ERROR_INVALID_PARAMETER;
323         }
324         *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
325     }
326     else if (MEDIA_IS_SKU(skuTable, FtrULT))
327     {
328         const uint32_t mbRate[7][4] =
329         {
330             // GT3   |  GT2   | GT1.5  |  GT1
331             { 1544090, 1544090, 1029393, 676280 },
332             { 1462540, 1462540, 975027, 661800 },
333             { 1165381, 1165381, 776921, 640000 },
334             { 1165381, 1165381, 776921, 640000 },
335             { 1165381, 1165381, 776921, 640000 },
336             { 624076, 624076, 416051, 317980 },
337             { 321657, 321657, 214438, 180655 }
338         };
339 
340         *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
341     }
342     else
343     {
344         const uint32_t mbRate[7][4] =
345         {
346             // GT3   |   GT2  | GT1.5  |  GT1
347             { 1544090, 1544090, 1029393, 676280 },
348             { 1462540, 1462540, 975027, 661800 },
349             { 1165381, 1165381, 776921, 640000 },
350             { 1165381, 1165381, 776921, 640000 },
351             { 1165381, 1165381, 776921, 640000 },
352             { 624076, 624076, 416051, 317980 },
353             { 321657, 321657, 214438, 180655 }
354         };
355 
356         *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
357     }
358 
359     return VA_STATUS_SUCCESS;
360 }
361 
362 extern template class MediaLibvaCapsFactory<MediaLibvaCaps, DDI_MEDIA_CONTEXT>;
363 
364 static bool bdwRegistered = MediaLibvaCapsFactory<MediaLibvaCaps, DDI_MEDIA_CONTEXT>::
365     RegisterCaps<MediaLibvaCapsG8>((uint32_t)IGFX_BROADWELL);
366