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_ARGB, VA_LSB_FIRST, 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
36 {VA_FOURCC_RGBA, VA_LSB_FIRST, 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000},
37 {VA_FOURCC_ABGR, VA_LSB_FIRST, 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000},
38 {VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0},
39 {VA_FOURCC_XRGB, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0},
40 {VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0},
41 {VA_FOURCC_XBGR, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0},
42 {VA_FOURCC_RGB565, VA_LSB_FIRST, 16, 16, 0xf800, 0x07e0, 0x001f, 0},
43 {VA_FOURCC_NV12, VA_LSB_FIRST, 12, 0,0,0,0,0},
44 {VA_FOURCC_NV21, VA_LSB_FIRST, 12, 0,0,0,0,0},
45 {VA_FOURCC_YUY2, VA_LSB_FIRST, 16, 0,0,0,0,0},
46 {VA_FOURCC_UYVY, VA_LSB_FIRST, 16, 0,0,0,0,0},
47 {VA_FOURCC_YV12, VA_LSB_FIRST, 12, 0,0,0,0,0},
48 {VA_FOURCC_I420, VA_LSB_FIRST, 12, 0,0,0,0,0},
49 {VA_FOURCC_422H, VA_LSB_FIRST, 16, 0,0,0,0,0},
50 {VA_FOURCC_422V, VA_LSB_FIRST, 16, 0,0,0,0,0},
51 {VA_FOURCC_444P, VA_LSB_FIRST, 24, 0,0,0,0,0},
52 {VA_FOURCC_IMC3, VA_LSB_FIRST, 16, 0,0,0,0,0}
53 };
54
QueryImageFormats(VAImageFormat * formatList,int32_t * numFormats)55 VAStatus MediaLibvaCapsG8::QueryImageFormats(VAImageFormat *formatList, int32_t *numFormats)
56 {
57 DDI_CHK_NULL(formatList, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
58 DDI_CHK_NULL(numFormats, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
59 int32_t num = 0;
60 uint32_t maxNum = GetImageFormatsMaxNum();
61
62 memset(formatList, 0, sizeof(m_supportedImageformatsG8));
63 for (uint32_t idx = 0; idx < maxNum; idx++)
64 {
65 formatList[num].fourcc = m_supportedImageformatsG8[idx].fourcc;
66 formatList[num].byte_order = m_supportedImageformatsG8[idx].byte_order;
67 formatList[num].bits_per_pixel = m_supportedImageformatsG8[idx].bits_per_pixel;
68 formatList[num].depth = m_supportedImageformatsG8[idx].depth;
69 formatList[num].red_mask = m_supportedImageformatsG8[idx].red_mask;
70 formatList[num].green_mask = m_supportedImageformatsG8[idx].green_mask;
71 formatList[num].blue_mask = m_supportedImageformatsG8[idx].blue_mask;
72 formatList[num].alpha_mask = m_supportedImageformatsG8[idx].alpha_mask;
73 num++;
74 }
75 *numFormats = num;
76
77 return VA_STATUS_SUCCESS;
78 }
79
GetImageFormatsMaxNum()80 uint32_t MediaLibvaCapsG8::GetImageFormatsMaxNum()
81 {
82 return sizeof(m_supportedImageformatsG8)/sizeof(m_supportedImageformatsG8[0]);
83 }
84
IsImageSupported(uint32_t fourcc)85 bool MediaLibvaCapsG8::IsImageSupported(uint32_t fourcc)
86 {
87 uint32_t maxNum = GetImageFormatsMaxNum();
88 for (int32_t idx = 0; idx < maxNum; idx++)
89 {
90 if (m_supportedImageformatsG8[idx].fourcc == fourcc)
91 {
92 return true;
93 }
94 }
95
96 return false;
97 }
98
PopulateColorMaskInfo(VAImageFormat * vaImgFmt)99 VAStatus MediaLibvaCapsG8::PopulateColorMaskInfo(VAImageFormat *vaImgFmt)
100 {
101 uint32_t maxNum = GetImageFormatsMaxNum();
102
103 DDI_CHK_NULL(vaImgFmt, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
104
105 for (int32_t idx = 0; idx < maxNum; idx++)
106 {
107 if (m_supportedImageformatsG8[idx].fourcc == vaImgFmt->fourcc)
108 {
109 vaImgFmt->red_mask = m_supportedImageformatsG8[idx].red_mask;
110 vaImgFmt->green_mask = m_supportedImageformatsG8[idx].green_mask;
111 vaImgFmt->blue_mask = m_supportedImageformatsG8[idx].blue_mask;
112 vaImgFmt->alpha_mask = m_supportedImageformatsG8[idx].alpha_mask;
113
114 return VA_STATUS_SUCCESS;
115 }
116 }
117
118 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
119 }
120
GetPlatformSpecificAttrib(VAProfile profile,VAEntrypoint entrypoint,VAConfigAttribType type,uint32_t * value)121 VAStatus MediaLibvaCapsG8::GetPlatformSpecificAttrib(
122 VAProfile profile,
123 VAEntrypoint entrypoint,
124 VAConfigAttribType type,
125 uint32_t *value)
126 {
127 DDI_CHK_NULL(value, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
128 VAStatus status = VA_STATUS_SUCCESS;
129 *value = VA_ATTRIB_NOT_SUPPORTED;
130 switch ((int32_t)type)
131 {
132 case VAConfigAttribEncMaxRefFrames:
133 {
134 if (entrypoint == VAEntrypointEncSliceLP || !IsHevcProfile(profile))
135 {
136 status = VA_STATUS_ERROR_INVALID_PARAMETER;
137 }
138 else
139 {
140 *value = 1 | (1 << 16);
141 }
142 break;
143 }
144 case VAConfigAttribDecProcessing:
145 {
146 *value = VA_DEC_PROCESSING_NONE;
147 break;
148 }
149 case VAConfigAttribEncIntraRefresh:
150 {
151 if(IsAvcProfile(profile))
152 {
153 *value = VA_ENC_INTRA_REFRESH_ROLLING_COLUMN |
154 VA_ENC_INTRA_REFRESH_ROLLING_ROW;
155 }
156 else
157 {
158 *value = VA_ENC_INTRA_REFRESH_NONE;
159 }
160 break;
161 }
162 case VAConfigAttribEncROI:
163 {
164 VAConfigAttribValEncROI roi_attr = { .value = 0 };
165
166 if (entrypoint == VAEntrypointEncSliceLP)
167 {
168 status = VA_STATUS_ERROR_INVALID_PARAMETER;
169 }
170 else if (IsAvcProfile(profile))
171 {
172 roi_attr.bits.num_roi_regions = ENCODE_DP_AVC_MAX_ROI_NUMBER;
173 }
174
175 *value = roi_attr.value;
176 break;
177 }
178 case VAConfigAttribCustomRoundingControl:
179 {
180 if (IsAvcProfile(profile))
181 {
182 *value = 1;
183 }
184 else
185 {
186 *value = 0;
187 }
188 break;
189 }
190 case VAConfigAttribEncMaxSlices:
191 {
192 *value = ENCODE_AVC_MAX_SLICES_SUPPORTED;
193 break;
194 }
195 default:
196 status = VA_STATUS_ERROR_INVALID_PARAMETER;
197 break;
198 }
199 return status;
200 }
201
LoadProfileEntrypoints()202 VAStatus MediaLibvaCapsG8::LoadProfileEntrypoints()
203 {
204 VAStatus status = VA_STATUS_SUCCESS;
205 status = LoadAvcDecProfileEntrypoints();
206 DDI_CHK_RET(status, "Failed to initialize Caps!");
207 status = LoadAvcEncProfileEntrypoints();
208 DDI_CHK_RET(status, "Failed to initialize Caps!");
209 status = LoadMpeg2DecProfileEntrypoints();
210 DDI_CHK_RET(status, "Failed to initialize Caps!");
211 status = LoadMpeg2EncProfileEntrypoints();
212 DDI_CHK_RET(status, "Failed to initialize Caps!");
213 status = LoadVc1DecProfileEntrypoints();
214 DDI_CHK_RET(status, "Failed to initialize Caps!");
215 status = LoadJpegDecProfileEntrypoints();
216 DDI_CHK_RET(status, "Failed to initialize Caps!");
217 status = LoadJpegEncProfileEntrypoints();
218 DDI_CHK_RET(status, "Failed to initialize Caps!");
219 status = LoadVp8DecProfileEntrypoints();
220 DDI_CHK_RET(status, "Failed to initialize Caps!");
221 status = LoadVp8EncProfileEntrypoints();
222 DDI_CHK_RET(status, "Failed to initialize Caps!");
223 status = LoadVp9DecProfileEntrypoints();
224 DDI_CHK_RET(status, "Failed to initialize Caps!");
225 status = LoadVp9EncProfileEntrypoints();
226 DDI_CHK_RET(status, "Failed to initialize Caps!");
227 #if !defined(_FULL_OPEN_SOURCE) && defined(ENABLE_KERNELS)
228 status = LoadNoneProfileEntrypoints();
229 DDI_CHK_RET(status, "Failed to initialize Caps!");
230 #endif
231 return status;
232 }
233
QueryAVCROIMaxNum(uint32_t rcMode,bool isVdenc,uint32_t * maxNum,bool * isRoiInDeltaQP)234 VAStatus MediaLibvaCapsG8::QueryAVCROIMaxNum(uint32_t rcMode, bool isVdenc, uint32_t *maxNum, bool *isRoiInDeltaQP)
235 {
236 DDI_CHK_NULL(maxNum, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
237 DDI_CHK_NULL(isRoiInDeltaQP, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
238 DDI_CHK_CONDITION(isVdenc == true, "VDEnc is not supported in Gen8", VA_STATUS_ERROR_INVALID_PARAMETER);
239
240 *maxNum = ENCODE_DP_AVC_MAX_ROI_NUMBER;
241 *isRoiInDeltaQP = false;
242 return VA_STATUS_SUCCESS;
243 }
244
GetMbProcessingRateEnc(MEDIA_FEATURE_TABLE * skuTable,uint32_t tuIdx,uint32_t codecMode,bool vdencActive,uint32_t * mbProcessingRatePerSec)245 VAStatus MediaLibvaCapsG8::GetMbProcessingRateEnc(
246 MEDIA_FEATURE_TABLE *skuTable,
247 uint32_t tuIdx,
248 uint32_t codecMode,
249 bool vdencActive,
250 uint32_t *mbProcessingRatePerSec)
251 {
252 DDI_CHK_NULL(skuTable, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
253 DDI_CHK_NULL(mbProcessingRatePerSec, "Null pointer", VA_STATUS_ERROR_INVALID_PARAMETER);
254
255 uint32_t gtIdx = 0;
256
257 if (MEDIA_IS_SKU(skuTable, FtrGT1))
258 {
259 gtIdx = 3;
260 }
261 else if (MEDIA_IS_SKU(skuTable, FtrGT1_5))
262 {
263 gtIdx = 2;
264 }
265 else if (MEDIA_IS_SKU(skuTable, FtrGT2))
266 {
267 gtIdx = 1;
268 }
269 else if (MEDIA_IS_SKU(skuTable, FtrGT3))
270 {
271 gtIdx = 0;
272 }
273 else
274 {
275 return VA_STATUS_ERROR_INVALID_PARAMETER;
276 }
277
278 if (MEDIA_IS_SKU(skuTable, FtrULX))
279 {
280 const uint32_t mbRate[7][4] =
281 {
282 // GT3 | GT2 | GT1.5 | GT1
283 { 0, 750000, 750000, 676280 },
284 { 0, 750000, 750000, 661800 },
285 { 0, 750000, 750000, 640000 },
286 { 0, 750000, 750000, 640000 },
287 { 0, 750000, 750000, 640000 },
288 { 0, 416051, 416051, 317980 },
289 { 0, 214438, 214438, 180655 }
290 };
291
292 if (gtIdx == 0)
293 {
294 return VA_STATUS_ERROR_INVALID_PARAMETER;
295 }
296 *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
297 }
298 else if (MEDIA_IS_SKU(skuTable, FtrULT))
299 {
300 const uint32_t mbRate[7][4] =
301 {
302 // GT3 | GT2 | GT1.5 | GT1
303 { 1544090, 1544090, 1029393, 676280 },
304 { 1462540, 1462540, 975027, 661800 },
305 { 1165381, 1165381, 776921, 640000 },
306 { 1165381, 1165381, 776921, 640000 },
307 { 1165381, 1165381, 776921, 640000 },
308 { 624076, 624076, 416051, 317980 },
309 { 321657, 321657, 214438, 180655 }
310 };
311
312 *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
313 }
314 else
315 {
316 const uint32_t mbRate[7][4] =
317 {
318 // GT3 | GT2 | GT1.5 | GT1
319 { 1544090, 1544090, 1029393, 676280 },
320 { 1462540, 1462540, 975027, 661800 },
321 { 1165381, 1165381, 776921, 640000 },
322 { 1165381, 1165381, 776921, 640000 },
323 { 1165381, 1165381, 776921, 640000 },
324 { 624076, 624076, 416051, 317980 },
325 { 321657, 321657, 214438, 180655 }
326 };
327
328 *mbProcessingRatePerSec = mbRate[tuIdx][gtIdx];
329 }
330
331 return VA_STATUS_SUCCESS;
332 }
333
334 extern template class MediaLibvaCapsFactory<MediaLibvaCaps, DDI_MEDIA_CONTEXT>;
335
336 static bool bdwRegistered = MediaLibvaCapsFactory<MediaLibvaCaps, DDI_MEDIA_CONTEXT>::
337 RegisterCaps<MediaLibvaCapsG8>((uint32_t)IGFX_BROADWELL);
338