1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "pipe/p_screen.h"
30
31 #include "util/u_video.h"
32 #include "util/u_memory.h"
33
34 #include "vl/vl_winsys.h"
35 #include "vl/vl_codec.h"
36
37 #include "va_private.h"
38
39 #include "util/u_handle_table.h"
40
41 DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false)
42
43 VAStatus
vlVaQueryConfigProfiles(VADriverContextP ctx,VAProfile * profile_list,int * num_profiles)44 vlVaQueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list, int *num_profiles)
45 {
46 struct pipe_screen *pscreen;
47 enum pipe_video_profile p;
48 VAProfile vap;
49
50 if (!ctx)
51 return VA_STATUS_ERROR_INVALID_CONTEXT;
52
53 *num_profiles = 0;
54
55 pscreen = VL_VA_PSCREEN(ctx);
56 for (p = PIPE_VIDEO_PROFILE_MPEG2_SIMPLE; p <= PIPE_VIDEO_PROFILE_AV1_MAIN; ++p) {
57 if (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 && !debug_get_option_mpeg4())
58 continue;
59
60 if (vl_codec_supported(pscreen, p, false) ||
61 vl_codec_supported(pscreen, p, true)) {
62 vap = PipeToProfile(p);
63 if (vap != VAProfileNone)
64 profile_list[(*num_profiles)++] = vap;
65 }
66 }
67
68 /* Support postprocessing through vl_compositor */
69 profile_list[(*num_profiles)++] = VAProfileNone;
70
71 return VA_STATUS_SUCCESS;
72 }
73
74 VAStatus
vlVaQueryConfigEntrypoints(VADriverContextP ctx,VAProfile profile,VAEntrypoint * entrypoint_list,int * num_entrypoints)75 vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,
76 VAEntrypoint *entrypoint_list, int *num_entrypoints)
77 {
78 struct pipe_screen *pscreen;
79 enum pipe_video_profile p;
80 bool check_av1enc_support = false;
81
82 if (!ctx)
83 return VA_STATUS_ERROR_INVALID_CONTEXT;
84
85 *num_entrypoints = 0;
86
87 if (profile == VAProfileNone) {
88 entrypoint_list[(*num_entrypoints)++] = VAEntrypointVideoProc;
89 return VA_STATUS_SUCCESS;
90 }
91
92 p = ProfileToPipe(profile);
93 if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||
94 (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&
95 !debug_get_option_mpeg4()))
96 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
97
98 pscreen = VL_VA_PSCREEN(ctx);
99 if (vl_codec_supported(pscreen, p, false))
100 entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD;
101
102 #if VA_CHECK_VERSION(1, 16, 0)
103 if (p == PIPE_VIDEO_PROFILE_AV1_MAIN)
104 check_av1enc_support = true;
105 #endif
106
107 if (p != PIPE_VIDEO_PROFILE_AV1_MAIN || check_av1enc_support == true)
108 if (vl_codec_supported(pscreen, p, true))
109 entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncSlice;
110
111 if (*num_entrypoints == 0)
112 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
113
114 assert(*num_entrypoints <= ctx->max_entrypoints);
115
116 return VA_STATUS_SUCCESS;
117 }
118
get_screen_supported_va_rt_formats(struct pipe_screen * pscreen,enum pipe_video_profile profile,enum pipe_video_entrypoint entrypoint)119 static unsigned int get_screen_supported_va_rt_formats(struct pipe_screen *pscreen,
120 enum pipe_video_profile profile,
121 enum pipe_video_entrypoint entrypoint)
122 {
123 unsigned int supported_rt_formats = 0;
124
125 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_NV12,
126 profile,
127 entrypoint) ||
128 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YV12,
129 profile,
130 entrypoint) ||
131 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_IYUV,
132 profile,
133 entrypoint))
134 supported_rt_formats |= VA_RT_FORMAT_YUV420;
135
136 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
137 profile,
138 entrypoint) ||
139 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
140 profile,
141 entrypoint))
142 supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP;
143
144 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_400_UNORM,
145 profile,
146 entrypoint))
147 supported_rt_formats |= VA_RT_FORMAT_YUV400;
148
149 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_Y8_U8_V8_444_UNORM,
150 profile,
151 entrypoint))
152 supported_rt_formats |= VA_RT_FORMAT_YUV444;
153
154 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_UYVY,
155 profile,
156 entrypoint) ||
157 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_YUYV,
158 profile,
159 entrypoint))
160 supported_rt_formats |= VA_RT_FORMAT_YUV422;
161
162 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UNORM,
163 profile,
164 entrypoint) ||
165 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8A8_UINT,
166 profile,
167 entrypoint) ||
168 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UNORM,
169 profile,
170 entrypoint) ||
171 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8G8B8X8_UINT,
172 profile,
173 entrypoint))
174 supported_rt_formats |= VA_RT_FORMAT_RGB32;
175 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8_G8_B8_UNORM,
176 profile,
177 entrypoint))
178 supported_rt_formats |= VA_RT_FORMAT_RGBP;
179
180
181 return supported_rt_formats;
182 }
183
184 VAStatus
vlVaGetConfigAttributes(VADriverContextP ctx,VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attrib_list,int num_attribs)185 vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
186 VAConfigAttrib *attrib_list, int num_attribs)
187 {
188 struct pipe_screen *pscreen;
189 int i;
190
191 if (!ctx)
192 return VA_STATUS_ERROR_INVALID_CONTEXT;
193
194 pscreen = VL_VA_PSCREEN(ctx);
195
196 for (i = 0; i < num_attribs; ++i) {
197 unsigned int value;
198 if ((entrypoint == VAEntrypointVLD) &&
199 (vl_codec_supported(pscreen, ProfileToPipe(profile), false))) {
200 switch (attrib_list[i].type) {
201 case VAConfigAttribRTFormat:
202 /*
203 * Different gallium drivers will have different supported formats
204 * If modifying this, please query the driver like below
205 */
206 value = get_screen_supported_va_rt_formats(pscreen,
207 ProfileToPipe(profile),
208 PIPE_VIDEO_ENTRYPOINT_BITSTREAM);
209 break;
210 case VAConfigAttribMaxPictureWidth:
211 {
212 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
213 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
214 PIPE_VIDEO_CAP_MAX_WIDTH);
215 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
216 } break;
217 case VAConfigAttribMaxPictureHeight:
218 {
219 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
220 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
221 PIPE_VIDEO_CAP_MAX_HEIGHT);
222 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
223 } break;
224 #if VA_CHECK_VERSION(1, 21, 0)
225 case VAConfigAttribDecJPEG:
226 {
227 VAConfigAttribValDecJPEG attr_jpeg = { .value = 0 };
228 /* Check if ROI Decode is supported */
229 int supportsCropDec =
230 pscreen->get_video_param(pscreen, ProfileToPipe(profile),
231 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
232 PIPE_VIDEO_CAP_ROI_CROP_DEC);
233 if (supportsCropDec <= 0)
234 value = VA_ATTRIB_NOT_SUPPORTED;
235 else {
236 attr_jpeg.bits.crop = 1;
237 value = attr_jpeg.value;
238 }
239 } break;
240 #endif
241 default:
242 value = VA_ATTRIB_NOT_SUPPORTED;
243 break;
244 }
245 } else if ((entrypoint == VAEntrypointEncSlice) &&
246 (vl_codec_supported(pscreen, ProfileToPipe(profile), true))) {
247 switch (attrib_list[i].type) {
248 case VAConfigAttribRTFormat:
249 value = get_screen_supported_va_rt_formats(pscreen,
250 ProfileToPipe(profile),
251 PIPE_VIDEO_ENTRYPOINT_ENCODE);
252 break;
253 case VAConfigAttribRateControl:
254 {
255 /* Legacy behavior reports these three modes for all drivers */
256 value = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR;
257
258 /* Check for optional mode QVBR */
259 int supports_qvbr = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
260 PIPE_VIDEO_ENTRYPOINT_ENCODE,
261 PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR);
262 if (supports_qvbr > 0)
263 value |= VA_RC_QVBR;
264 } break;
265 case VAConfigAttribEncRateControlExt:
266 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
267 PIPE_VIDEO_ENTRYPOINT_ENCODE,
268 PIPE_VIDEO_CAP_MAX_TEMPORAL_LAYERS);
269 if (value > 0) {
270 value -= 1;
271 value |= (1 << 8); /* temporal_layer_bitrate_control_flag */
272 }
273 break;
274 case VAConfigAttribEncPackedHeaders:
275 value = VA_ENC_PACKED_HEADER_NONE;
276 if ((u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_MPEG4_AVC))
277 value |= VA_ENC_PACKED_HEADER_SEQUENCE;
278 if ((u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_HEVC))
279 value |= VA_ENC_PACKED_HEADER_SEQUENCE;
280 else if (u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_AV1)
281 value |= (VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE);
282 break;
283 case VAConfigAttribEncMaxSlices:
284 {
285 /**
286 * \brief Maximum number of slices per frame. Read-only.
287 *
288 * This attribute determines the maximum number of slices the
289 * driver can support to encode a single frame.
290 */
291 int maxSlicesPerEncodedPic = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
292 PIPE_VIDEO_ENTRYPOINT_ENCODE,
293 PIPE_VIDEO_CAP_ENC_MAX_SLICES_PER_FRAME);
294 if (maxSlicesPerEncodedPic <= 0)
295 value = VA_ATTRIB_NOT_SUPPORTED;
296 else
297 value = maxSlicesPerEncodedPic;
298 } break;
299 case VAConfigAttribEncMaxRefFrames:
300 {
301 int maxL0L1ReferencesPerFrame = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
302 PIPE_VIDEO_ENTRYPOINT_ENCODE,
303 PIPE_VIDEO_CAP_ENC_MAX_REFERENCES_PER_FRAME);
304 if (maxL0L1ReferencesPerFrame <= 0)
305 value = 1;
306 else
307 value = maxL0L1ReferencesPerFrame;
308 } break;
309 case VAConfigAttribEncSliceStructure:
310 {
311 /* The VA enum values match the pipe_video_cap_slice_structure definitions*/
312 int supportedSliceStructuresFlagSet = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
313 PIPE_VIDEO_ENTRYPOINT_ENCODE,
314 PIPE_VIDEO_CAP_ENC_SLICES_STRUCTURE);
315 if (supportedSliceStructuresFlagSet <= 0)
316 value = VA_ATTRIB_NOT_SUPPORTED;
317 else
318 value = supportedSliceStructuresFlagSet;
319 } break;
320 case VAConfigAttribEncQualityRange:
321 {
322 /*
323 * this quality range provides different options within the range; and it isn't strictly
324 * faster when higher value used.
325 * 0, not used; 1, default value; others are using vlVaQualityBits for different modes.
326 */
327 int quality_range = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
328 PIPE_VIDEO_ENTRYPOINT_ENCODE,
329 PIPE_VIDEO_CAP_ENC_QUALITY_LEVEL);
330 value = quality_range ? quality_range : VA_ATTRIB_NOT_SUPPORTED;
331 } break;
332 case VAConfigAttribMaxFrameSize:
333 {
334 /* Max Frame Size can be used to control picture level frame size.
335 * This frame size is in bits.
336 */
337 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
338 PIPE_VIDEO_ENTRYPOINT_ENCODE,
339 PIPE_VIDEO_CAP_ENC_SUPPORTS_MAX_FRAME_SIZE);
340 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
341 } break;
342 case VAConfigAttribMaxPictureWidth:
343 {
344 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
345 PIPE_VIDEO_ENTRYPOINT_ENCODE,
346 PIPE_VIDEO_CAP_MAX_WIDTH);
347 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
348 } break;
349 case VAConfigAttribMaxPictureHeight:
350 {
351 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
352 PIPE_VIDEO_ENTRYPOINT_ENCODE,
353 PIPE_VIDEO_CAP_MAX_HEIGHT);
354 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
355 } break;
356 #if VA_CHECK_VERSION(1, 12, 0)
357 case VAConfigAttribEncHEVCFeatures:
358 {
359 union pipe_h265_enc_cap_features pipe_features;
360 pipe_features.value = 0u;
361 /* get_video_param sets pipe_features.bits.config_supported = 1
362 to distinguish between supported cap with all bits off and unsupported by driver
363 with value = 0
364 */
365 int supportedHEVCEncFeaturesFlagSet = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
366 PIPE_VIDEO_ENTRYPOINT_ENCODE,
367 PIPE_VIDEO_CAP_ENC_HEVC_FEATURE_FLAGS);
368 if (supportedHEVCEncFeaturesFlagSet <= 0)
369 value = VA_ATTRIB_NOT_SUPPORTED;
370 else {
371 /* Assign unsigned typed variable "value" after checking supportedHEVCEncFeaturesFlagSet > 0 */
372 pipe_features.value = supportedHEVCEncFeaturesFlagSet;
373 VAConfigAttribValEncHEVCFeatures va_features;
374 va_features.value = 0;
375 va_features.bits.separate_colour_planes = pipe_features.bits.separate_colour_planes;
376 va_features.bits.scaling_lists = pipe_features.bits.scaling_lists;
377 va_features.bits.amp = pipe_features.bits.amp;
378 va_features.bits.sao = pipe_features.bits.sao;
379 va_features.bits.pcm = pipe_features.bits.pcm;
380 va_features.bits.temporal_mvp = pipe_features.bits.temporal_mvp;
381 va_features.bits.strong_intra_smoothing = pipe_features.bits.strong_intra_smoothing;
382 va_features.bits.dependent_slices = pipe_features.bits.dependent_slices;
383 va_features.bits.sign_data_hiding = pipe_features.bits.sign_data_hiding;
384 va_features.bits.constrained_intra_pred = pipe_features.bits.constrained_intra_pred;
385 va_features.bits.transform_skip = pipe_features.bits.transform_skip;
386 va_features.bits.cu_qp_delta = pipe_features.bits.cu_qp_delta;
387 va_features.bits.weighted_prediction = pipe_features.bits.weighted_prediction;
388 va_features.bits.transquant_bypass = pipe_features.bits.transquant_bypass;
389 va_features.bits.deblocking_filter_disable = pipe_features.bits.deblocking_filter_disable;
390 value = va_features.value;
391 }
392 } break;
393 case VAConfigAttribEncHEVCBlockSizes:
394 {
395 union pipe_h265_enc_cap_block_sizes pipe_block_sizes;
396 pipe_block_sizes.value = 0;
397 /* get_video_param sets pipe_block_sizes.bits.config_supported = 1
398 to distinguish between supported cap with all bits off and unsupported by driver
399 with value = 0
400 */
401 int supportedHEVCEncBlockSizes = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
402 PIPE_VIDEO_ENTRYPOINT_ENCODE,
403 PIPE_VIDEO_CAP_ENC_HEVC_BLOCK_SIZES);
404 if (supportedHEVCEncBlockSizes <= 0)
405 value = VA_ATTRIB_NOT_SUPPORTED;
406 else {
407 /* Assign unsigned typed variable "value" after checking supportedHEVCEncBlockSizes > 0 */
408 pipe_block_sizes.value = supportedHEVCEncBlockSizes;
409 VAConfigAttribValEncHEVCBlockSizes va_block_sizes;
410 va_block_sizes.value = 0;
411 va_block_sizes.bits.log2_max_coding_tree_block_size_minus3 =
412 pipe_block_sizes.bits.log2_max_coding_tree_block_size_minus3;
413 va_block_sizes.bits.log2_min_coding_tree_block_size_minus3 =
414 pipe_block_sizes.bits.log2_min_coding_tree_block_size_minus3;
415 va_block_sizes.bits.log2_min_luma_coding_block_size_minus3 =
416 pipe_block_sizes.bits.log2_min_luma_coding_block_size_minus3;
417 va_block_sizes.bits.log2_max_luma_transform_block_size_minus2 =
418 pipe_block_sizes.bits.log2_max_luma_transform_block_size_minus2;
419 va_block_sizes.bits.log2_min_luma_transform_block_size_minus2 =
420 pipe_block_sizes.bits.log2_min_luma_transform_block_size_minus2;
421 va_block_sizes.bits.max_max_transform_hierarchy_depth_inter =
422 pipe_block_sizes.bits.max_max_transform_hierarchy_depth_inter;
423 va_block_sizes.bits.min_max_transform_hierarchy_depth_inter =
424 pipe_block_sizes.bits.min_max_transform_hierarchy_depth_inter;
425 va_block_sizes.bits.max_max_transform_hierarchy_depth_intra =
426 pipe_block_sizes.bits.max_max_transform_hierarchy_depth_intra;
427 va_block_sizes.bits.min_max_transform_hierarchy_depth_intra =
428 pipe_block_sizes.bits.min_max_transform_hierarchy_depth_intra;
429 va_block_sizes.bits.log2_max_pcm_coding_block_size_minus3 =
430 pipe_block_sizes.bits.log2_max_pcm_coding_block_size_minus3;
431 va_block_sizes.bits.log2_min_pcm_coding_block_size_minus3 =
432 pipe_block_sizes.bits.log2_min_pcm_coding_block_size_minus3;
433 value = va_block_sizes.value;
434 }
435 } break;
436 #endif
437 #if VA_CHECK_VERSION(1, 6, 0)
438 case VAConfigAttribPredictionDirection:
439 {
440 /* The VA enum values match the pipe_h265_enc_pred_direction definitions*/
441 int h265_enc_pred_direction = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
442 PIPE_VIDEO_ENTRYPOINT_ENCODE,
443 PIPE_VIDEO_CAP_ENC_HEVC_PREDICTION_DIRECTION);
444 if (h265_enc_pred_direction <= 0)
445 value = VA_ATTRIB_NOT_SUPPORTED;
446 else
447 value = h265_enc_pred_direction;
448 } break;
449 #endif
450 #if VA_CHECK_VERSION(1, 16, 0)
451 case VAConfigAttribEncAV1:
452 {
453 union pipe_av1_enc_cap_features features;
454 features.value = 0;
455
456 int support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
457 PIPE_VIDEO_ENTRYPOINT_ENCODE,
458 PIPE_VIDEO_CAP_ENC_AV1_FEATURE);
459 if (support <= 0)
460 value = VA_ATTRIB_NOT_SUPPORTED;
461 else {
462 VAConfigAttribValEncAV1 attrib;
463 features.value = support;
464 attrib.value = features.value;
465 value = attrib.value;
466 }
467 } break;
468 case VAConfigAttribEncAV1Ext1:
469 {
470 union pipe_av1_enc_cap_features_ext1 features_ext1;
471 features_ext1.value = 0;
472 int support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
473 PIPE_VIDEO_ENTRYPOINT_ENCODE,
474 PIPE_VIDEO_CAP_ENC_AV1_FEATURE_EXT1);
475 if (support <= 0)
476 value = VA_ATTRIB_NOT_SUPPORTED;
477 else {
478 VAConfigAttribValEncAV1Ext1 attrib;
479 features_ext1.value = support;
480 attrib.value = features_ext1.value;
481 value = attrib.value;
482 }
483
484 } break;
485 case VAConfigAttribEncAV1Ext2:
486 {
487 union pipe_av1_enc_cap_features_ext2 features_ext2;
488 features_ext2.value = 0;
489
490 int support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
491 PIPE_VIDEO_ENTRYPOINT_ENCODE,
492 PIPE_VIDEO_CAP_ENC_AV1_FEATURE_EXT2);
493 if (support <= 0)
494 value = VA_ATTRIB_NOT_SUPPORTED;
495 else {
496 VAConfigAttribValEncAV1Ext2 attrib;
497 features_ext2.value = support;
498 attrib.value = features_ext2.value;
499 value = attrib.value;
500 }
501
502 } break;
503 case VAConfigAttribEncTileSupport:
504 {
505 int encode_tile_support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
506 PIPE_VIDEO_ENTRYPOINT_ENCODE,
507 PIPE_VIDEO_CAP_ENC_SUPPORTS_TILE);
508 if (encode_tile_support <= 0)
509 value = VA_ATTRIB_NOT_SUPPORTED;
510 else
511 value = encode_tile_support;
512 } break;
513 #endif
514 #if VA_CHECK_VERSION(1, 21, 0)
515 case VAConfigAttribEncMaxTileRows:
516 {
517 int max_tile_rows = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
518 PIPE_VIDEO_ENTRYPOINT_ENCODE,
519 PIPE_VIDEO_CAP_ENC_MAX_TILE_ROWS);
520 if (max_tile_rows <= 0)
521 value = VA_ATTRIB_NOT_SUPPORTED;
522 else
523 value = max_tile_rows;
524 } break;
525 case VAConfigAttribEncMaxTileCols:
526 {
527 int max_tile_cols = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
528 PIPE_VIDEO_ENTRYPOINT_ENCODE,
529 PIPE_VIDEO_CAP_ENC_MAX_TILE_COLS);
530 if (max_tile_cols <= 0)
531 value = VA_ATTRIB_NOT_SUPPORTED;
532 else
533 value = max_tile_cols;
534 } break;
535 #endif
536 case VAConfigAttribEncIntraRefresh:
537 {
538 int ir_support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
539 PIPE_VIDEO_ENTRYPOINT_ENCODE,
540 PIPE_VIDEO_CAP_ENC_INTRA_REFRESH);
541 if (ir_support <= 0)
542 value = VA_ATTRIB_NOT_SUPPORTED;
543 else
544 value = ir_support;
545 } break;
546
547 case VAConfigAttribEncROI:
548 {
549 int roi_support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
550 PIPE_VIDEO_ENTRYPOINT_ENCODE,
551 PIPE_VIDEO_CAP_ENC_ROI);
552 if (roi_support <= 0)
553 value = VA_ATTRIB_NOT_SUPPORTED;
554 else
555 value = roi_support;
556 } break;
557
558 default:
559 value = VA_ATTRIB_NOT_SUPPORTED;
560 break;
561 }
562 } else if (entrypoint == VAEntrypointVideoProc) {
563 switch (attrib_list[i].type) {
564 case VAConfigAttribRTFormat:
565 value = get_screen_supported_va_rt_formats(pscreen,
566 PIPE_VIDEO_PROFILE_UNKNOWN,
567 PIPE_VIDEO_ENTRYPOINT_PROCESSING);
568 break;
569 default:
570 value = VA_ATTRIB_NOT_SUPPORTED;
571 break;
572 }
573 } else {
574 value = VA_ATTRIB_NOT_SUPPORTED;
575 }
576 attrib_list[i].value = value;
577 }
578
579 return VA_STATUS_SUCCESS;
580 }
581
582 VAStatus
vlVaCreateConfig(VADriverContextP ctx,VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attrib_list,int num_attribs,VAConfigID * config_id)583 vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
584 VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id)
585 {
586 vlVaDriver *drv;
587 vlVaConfig *config;
588 struct pipe_screen *pscreen;
589 enum pipe_video_profile p;
590 unsigned int supported_rt_formats;
591
592 if (!ctx)
593 return VA_STATUS_ERROR_INVALID_CONTEXT;
594
595 drv = VL_VA_DRIVER(ctx);
596 pscreen = VL_VA_PSCREEN(ctx);
597
598 if (!drv)
599 return VA_STATUS_ERROR_INVALID_CONTEXT;
600
601 config = CALLOC(1, sizeof(vlVaConfig));
602 if (!config)
603 return VA_STATUS_ERROR_ALLOCATION_FAILED;
604
605 if (profile == VAProfileNone) {
606 if (entrypoint != VAEntrypointVideoProc) {
607 FREE(config);
608 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
609 }
610
611 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_PROCESSING;
612 config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
613 supported_rt_formats = get_screen_supported_va_rt_formats(pscreen,
614 config->profile,
615 config->entrypoint);
616 for (int i = 0; i < num_attribs; i++) {
617 if (attrib_list[i].type == VAConfigAttribRTFormat) {
618 if (attrib_list[i].value & supported_rt_formats) {
619 config->rt_format = attrib_list[i].value;
620 } else {
621 FREE(config);
622 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
623 }
624 } else {
625 /*other attrib_types are not supported.*/
626 FREE(config);
627 return VA_STATUS_ERROR_INVALID_VALUE;
628 }
629 }
630
631 /* Default value if not specified in the input attributes. */
632 if (!config->rt_format)
633 config->rt_format = supported_rt_formats;
634
635 mtx_lock(&drv->mutex);
636 *config_id = handle_table_add(drv->htab, config);
637 mtx_unlock(&drv->mutex);
638 return VA_STATUS_SUCCESS;
639 }
640
641 p = ProfileToPipe(profile);
642 if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||
643 (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&
644 !debug_get_option_mpeg4())) {
645 FREE(config);
646 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
647 }
648
649 switch (entrypoint) {
650 case VAEntrypointVLD:
651 if (!vl_codec_supported(pscreen, p, false)) {
652 FREE(config);
653 if (!vl_codec_supported(pscreen, p, true))
654 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
655 else
656 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
657 }
658
659 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;
660 break;
661
662 case VAEntrypointEncSlice:
663 if (!vl_codec_supported(pscreen, p, true)) {
664 FREE(config);
665 if (!vl_codec_supported(pscreen, p, false))
666 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
667 else
668 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
669 }
670
671 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE;
672 break;
673
674 default:
675 FREE(config);
676 if (!vl_codec_supported(pscreen, p, false) &&
677 !vl_codec_supported(pscreen, p, true))
678 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
679 else
680 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
681 }
682
683 config->profile = p;
684 supported_rt_formats = get_screen_supported_va_rt_formats(pscreen,
685 config->profile,
686 config->entrypoint);
687 for (int i = 0; i <num_attribs ; i++) {
688 if (attrib_list[i].type != VAConfigAttribRTFormat &&
689 entrypoint == VAEntrypointVLD ) {
690 FREE(config);
691 return VA_STATUS_ERROR_INVALID_VALUE;
692 }
693 if (attrib_list[i].type == VAConfigAttribRateControl) {
694 if (attrib_list[i].value == VA_RC_CBR)
695 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT;
696 else if (attrib_list[i].value == VA_RC_VBR)
697 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE;
698 else if (attrib_list[i].value == VA_RC_CQP)
699 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE;
700 else if (attrib_list[i].value == VA_RC_QVBR &&
701 (pscreen->get_video_param(pscreen, ProfileToPipe(profile),
702 PIPE_VIDEO_ENTRYPOINT_ENCODE,
703 PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR) > 0))
704 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE;
705 else {
706 FREE(config);
707 return VA_STATUS_ERROR_INVALID_VALUE;
708 }
709 }
710 if (attrib_list[i].type == VAConfigAttribRTFormat) {
711 if (attrib_list[i].value & supported_rt_formats) {
712 config->rt_format = attrib_list[i].value;
713 } else {
714 FREE(config);
715 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
716 }
717 }
718 if (attrib_list[i].type == VAConfigAttribEncPackedHeaders) {
719 if (config->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE ||
720 (((attrib_list[i].value != 0)) &&
721 ((attrib_list[i].value != 1) || u_reduce_video_profile(ProfileToPipe(profile))
722 != PIPE_VIDEO_FORMAT_MPEG4_AVC) &&
723 ((attrib_list[i].value != 1) || u_reduce_video_profile(ProfileToPipe(profile))
724 != PIPE_VIDEO_FORMAT_HEVC) &&
725 ((attrib_list[i].value != 3) || u_reduce_video_profile(ProfileToPipe(profile))
726 != PIPE_VIDEO_FORMAT_AV1))) {
727 FREE(config);
728 return VA_STATUS_ERROR_INVALID_VALUE;
729 }
730 }
731 }
732
733 /* Default value if not specified in the input attributes. */
734 if (!config->rt_format)
735 config->rt_format = supported_rt_formats;
736
737 mtx_lock(&drv->mutex);
738 *config_id = handle_table_add(drv->htab, config);
739 mtx_unlock(&drv->mutex);
740
741 return VA_STATUS_SUCCESS;
742 }
743
744 VAStatus
vlVaDestroyConfig(VADriverContextP ctx,VAConfigID config_id)745 vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id)
746 {
747 vlVaDriver *drv;
748 vlVaConfig *config;
749
750 if (!ctx)
751 return VA_STATUS_ERROR_INVALID_CONTEXT;
752
753 drv = VL_VA_DRIVER(ctx);
754
755 if (!drv)
756 return VA_STATUS_ERROR_INVALID_CONTEXT;
757
758 mtx_lock(&drv->mutex);
759 config = handle_table_get(drv->htab, config_id);
760
761 if (!config) {
762 mtx_unlock(&drv->mutex);
763 return VA_STATUS_ERROR_INVALID_CONFIG;
764 }
765
766 FREE(config);
767 handle_table_remove(drv->htab, config_id);
768 mtx_unlock(&drv->mutex);
769
770 return VA_STATUS_SUCCESS;
771 }
772
773 VAStatus
vlVaQueryConfigAttributes(VADriverContextP ctx,VAConfigID config_id,VAProfile * profile,VAEntrypoint * entrypoint,VAConfigAttrib * attrib_list,int * num_attribs)774 vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,
775 VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs)
776 {
777 vlVaDriver *drv;
778 vlVaConfig *config;
779
780 if (!ctx)
781 return VA_STATUS_ERROR_INVALID_CONTEXT;
782
783 drv = VL_VA_DRIVER(ctx);
784
785 if (!drv)
786 return VA_STATUS_ERROR_INVALID_CONTEXT;
787
788 mtx_lock(&drv->mutex);
789 config = handle_table_get(drv->htab, config_id);
790 mtx_unlock(&drv->mutex);
791
792 if (!config)
793 return VA_STATUS_ERROR_INVALID_CONFIG;
794
795 *profile = PipeToProfile(config->profile);
796
797 switch (config->entrypoint) {
798 case PIPE_VIDEO_ENTRYPOINT_BITSTREAM:
799 *entrypoint = VAEntrypointVLD;
800 break;
801 case PIPE_VIDEO_ENTRYPOINT_ENCODE:
802 *entrypoint = VAEntrypointEncSlice;
803 break;
804 case PIPE_VIDEO_ENTRYPOINT_PROCESSING:
805 *entrypoint = VAEntrypointVideoProc;
806 break;
807 default:
808 return VA_STATUS_ERROR_INVALID_CONFIG;
809 }
810
811 *num_attribs = 1;
812 attrib_list[0].type = VAConfigAttribRTFormat;
813 attrib_list[0].value = config->rt_format;
814
815 return VA_STATUS_SUCCESS;
816 }
817