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
176 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R10G10B10A2_UNORM,
177 profile,
178 entrypoint) ||
179 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_B10G10R10A2_UNORM,
180 profile,
181 entrypoint) ||
182 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R10G10B10X2_UNORM,
183 profile,
184 entrypoint) ||
185 pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_B10G10R10X2_UNORM,
186 profile,
187 entrypoint))
188 supported_rt_formats |= VA_RT_FORMAT_RGB32_10;
189
190 if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_R8_G8_B8_UNORM,
191 profile,
192 entrypoint))
193 supported_rt_formats |= VA_RT_FORMAT_RGBP;
194
195
196 return supported_rt_formats;
197 }
198
199 VAStatus
vlVaGetConfigAttributes(VADriverContextP ctx,VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attrib_list,int num_attribs)200 vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
201 VAConfigAttrib *attrib_list, int num_attribs)
202 {
203 struct pipe_screen *pscreen;
204 int i;
205
206 if (!ctx)
207 return VA_STATUS_ERROR_INVALID_CONTEXT;
208
209 pscreen = VL_VA_PSCREEN(ctx);
210
211 for (i = 0; i < num_attribs; ++i) {
212 unsigned int value;
213 if ((entrypoint == VAEntrypointVLD) &&
214 (vl_codec_supported(pscreen, ProfileToPipe(profile), false))) {
215 switch (attrib_list[i].type) {
216 case VAConfigAttribRTFormat:
217 /*
218 * Different gallium drivers will have different supported formats
219 * If modifying this, please query the driver like below
220 */
221 value = get_screen_supported_va_rt_formats(pscreen,
222 ProfileToPipe(profile),
223 PIPE_VIDEO_ENTRYPOINT_BITSTREAM);
224 break;
225 case VAConfigAttribMaxPictureWidth:
226 {
227 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
228 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
229 PIPE_VIDEO_CAP_MAX_WIDTH);
230 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
231 } break;
232 case VAConfigAttribMaxPictureHeight:
233 {
234 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
235 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
236 PIPE_VIDEO_CAP_MAX_HEIGHT);
237 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
238 } break;
239 #if VA_CHECK_VERSION(1, 21, 0)
240 case VAConfigAttribDecJPEG:
241 {
242 VAConfigAttribValDecJPEG attr_jpeg = { .value = 0 };
243 /* Check if ROI Decode is supported */
244 int supportsCropDec =
245 pscreen->get_video_param(pscreen, ProfileToPipe(profile),
246 PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
247 PIPE_VIDEO_CAP_ROI_CROP_DEC);
248 if (supportsCropDec <= 0)
249 value = VA_ATTRIB_NOT_SUPPORTED;
250 else {
251 attr_jpeg.bits.crop = 1;
252 value = attr_jpeg.value;
253 }
254 } break;
255 #endif
256 default:
257 value = VA_ATTRIB_NOT_SUPPORTED;
258 break;
259 }
260 } else if ((entrypoint == VAEntrypointEncSlice) &&
261 (vl_codec_supported(pscreen, ProfileToPipe(profile), true))) {
262 switch (attrib_list[i].type) {
263 case VAConfigAttribRTFormat:
264 value = get_screen_supported_va_rt_formats(pscreen,
265 ProfileToPipe(profile),
266 PIPE_VIDEO_ENTRYPOINT_ENCODE);
267 break;
268 case VAConfigAttribRateControl:
269 {
270 /* Legacy behavior reports these three modes for all drivers */
271 value = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR;
272
273 /* Check for optional mode QVBR */
274 int supports_qvbr = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
275 PIPE_VIDEO_ENTRYPOINT_ENCODE,
276 PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR);
277 if (supports_qvbr > 0)
278 value |= VA_RC_QVBR;
279 } break;
280 case VAConfigAttribEncRateControlExt:
281 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
282 PIPE_VIDEO_ENTRYPOINT_ENCODE,
283 PIPE_VIDEO_CAP_MAX_TEMPORAL_LAYERS);
284 assert(value <= 4);
285 if (value > 0) {
286 value -= 1;
287 value |= (1 << 8); /* temporal_layer_bitrate_control_flag */
288 }
289 break;
290 case VAConfigAttribEncPackedHeaders:
291 value = VA_ENC_PACKED_HEADER_NONE;
292 if ((u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_MPEG4_AVC))
293 value |= ENC_PACKED_HEADERS_H264;
294 else if ((u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_HEVC))
295 value |= ENC_PACKED_HEADERS_HEVC;
296 else if (u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_AV1)
297 value |= ENC_PACKED_HEADERS_AV1;
298
299 break;
300 case VAConfigAttribEncMaxSlices:
301 {
302 /**
303 * \brief Maximum number of slices per frame. Read-only.
304 *
305 * This attribute determines the maximum number of slices the
306 * driver can support to encode a single frame.
307 */
308 int maxSlicesPerEncodedPic = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
309 PIPE_VIDEO_ENTRYPOINT_ENCODE,
310 PIPE_VIDEO_CAP_ENC_MAX_SLICES_PER_FRAME);
311 if (maxSlicesPerEncodedPic <= 0)
312 value = VA_ATTRIB_NOT_SUPPORTED;
313 else
314 value = maxSlicesPerEncodedPic;
315 } break;
316 case VAConfigAttribEncMaxRefFrames:
317 {
318 int maxL0L1ReferencesPerFrame = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
319 PIPE_VIDEO_ENTRYPOINT_ENCODE,
320 PIPE_VIDEO_CAP_ENC_MAX_REFERENCES_PER_FRAME);
321 if (maxL0L1ReferencesPerFrame <= 0)
322 value = 1;
323 else
324 value = maxL0L1ReferencesPerFrame;
325 } break;
326 case VAConfigAttribEncSliceStructure:
327 {
328 /* The VA enum values match the pipe_video_cap_slice_structure definitions*/
329 int supportedSliceStructuresFlagSet = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
330 PIPE_VIDEO_ENTRYPOINT_ENCODE,
331 PIPE_VIDEO_CAP_ENC_SLICES_STRUCTURE);
332 if (supportedSliceStructuresFlagSet <= 0)
333 value = VA_ATTRIB_NOT_SUPPORTED;
334 else
335 value = supportedSliceStructuresFlagSet;
336 } break;
337 case VAConfigAttribEncQualityRange:
338 {
339 /*
340 * this quality range provides different options within the range; and it isn't strictly
341 * faster when higher value used.
342 * 0, not used; 1, default value; others are using vlVaQualityBits for different modes.
343 */
344 int quality_range = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
345 PIPE_VIDEO_ENTRYPOINT_ENCODE,
346 PIPE_VIDEO_CAP_ENC_QUALITY_LEVEL);
347 value = quality_range ? quality_range : VA_ATTRIB_NOT_SUPPORTED;
348 } break;
349 case VAConfigAttribMaxFrameSize:
350 {
351 /* Max Frame Size can be used to control picture level frame size.
352 * This frame size is in bits.
353 */
354 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
355 PIPE_VIDEO_ENTRYPOINT_ENCODE,
356 PIPE_VIDEO_CAP_ENC_SUPPORTS_MAX_FRAME_SIZE);
357 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
358 } break;
359 case VAConfigAttribMaxPictureWidth:
360 {
361 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
362 PIPE_VIDEO_ENTRYPOINT_ENCODE,
363 PIPE_VIDEO_CAP_MAX_WIDTH);
364 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
365 } break;
366 case VAConfigAttribMaxPictureHeight:
367 {
368 value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
369 PIPE_VIDEO_ENTRYPOINT_ENCODE,
370 PIPE_VIDEO_CAP_MAX_HEIGHT);
371 value = value ? value : VA_ATTRIB_NOT_SUPPORTED;
372 } break;
373 #if VA_CHECK_VERSION(1, 12, 0)
374 case VAConfigAttribEncHEVCFeatures:
375 {
376 union pipe_h265_enc_cap_features pipe_features;
377 pipe_features.value = 0u;
378 /* get_video_param sets pipe_features.bits.config_supported = 1
379 to distinguish between supported cap with all bits off and unsupported by driver
380 with value = 0
381 */
382 int supportedHEVCEncFeaturesFlagSet = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
383 PIPE_VIDEO_ENTRYPOINT_ENCODE,
384 PIPE_VIDEO_CAP_ENC_HEVC_FEATURE_FLAGS);
385 if (supportedHEVCEncFeaturesFlagSet <= 0)
386 value = VA_ATTRIB_NOT_SUPPORTED;
387 else {
388 /* Assign unsigned typed variable "value" after checking supportedHEVCEncFeaturesFlagSet > 0 */
389 pipe_features.value = supportedHEVCEncFeaturesFlagSet;
390 VAConfigAttribValEncHEVCFeatures va_features;
391 va_features.value = 0;
392 va_features.bits.separate_colour_planes = pipe_features.bits.separate_colour_planes;
393 va_features.bits.scaling_lists = pipe_features.bits.scaling_lists;
394 va_features.bits.amp = pipe_features.bits.amp;
395 va_features.bits.sao = pipe_features.bits.sao;
396 va_features.bits.pcm = pipe_features.bits.pcm;
397 va_features.bits.temporal_mvp = pipe_features.bits.temporal_mvp;
398 va_features.bits.strong_intra_smoothing = pipe_features.bits.strong_intra_smoothing;
399 va_features.bits.dependent_slices = pipe_features.bits.dependent_slices;
400 va_features.bits.sign_data_hiding = pipe_features.bits.sign_data_hiding;
401 va_features.bits.constrained_intra_pred = pipe_features.bits.constrained_intra_pred;
402 va_features.bits.transform_skip = pipe_features.bits.transform_skip;
403 va_features.bits.cu_qp_delta = pipe_features.bits.cu_qp_delta;
404 va_features.bits.weighted_prediction = pipe_features.bits.weighted_prediction;
405 va_features.bits.transquant_bypass = pipe_features.bits.transquant_bypass;
406 va_features.bits.deblocking_filter_disable = pipe_features.bits.deblocking_filter_disable;
407 value = va_features.value;
408 }
409 } break;
410 case VAConfigAttribEncHEVCBlockSizes:
411 {
412 union pipe_h265_enc_cap_block_sizes pipe_block_sizes;
413 pipe_block_sizes.value = 0;
414 /* get_video_param sets pipe_block_sizes.bits.config_supported = 1
415 to distinguish between supported cap with all bits off and unsupported by driver
416 with value = 0
417 */
418 int supportedHEVCEncBlockSizes = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
419 PIPE_VIDEO_ENTRYPOINT_ENCODE,
420 PIPE_VIDEO_CAP_ENC_HEVC_BLOCK_SIZES);
421 if (supportedHEVCEncBlockSizes <= 0)
422 value = VA_ATTRIB_NOT_SUPPORTED;
423 else {
424 /* Assign unsigned typed variable "value" after checking supportedHEVCEncBlockSizes > 0 */
425 pipe_block_sizes.value = supportedHEVCEncBlockSizes;
426 VAConfigAttribValEncHEVCBlockSizes va_block_sizes;
427 va_block_sizes.value = 0;
428 va_block_sizes.bits.log2_max_coding_tree_block_size_minus3 =
429 pipe_block_sizes.bits.log2_max_coding_tree_block_size_minus3;
430 va_block_sizes.bits.log2_min_coding_tree_block_size_minus3 =
431 pipe_block_sizes.bits.log2_min_coding_tree_block_size_minus3;
432 va_block_sizes.bits.log2_min_luma_coding_block_size_minus3 =
433 pipe_block_sizes.bits.log2_min_luma_coding_block_size_minus3;
434 va_block_sizes.bits.log2_max_luma_transform_block_size_minus2 =
435 pipe_block_sizes.bits.log2_max_luma_transform_block_size_minus2;
436 va_block_sizes.bits.log2_min_luma_transform_block_size_minus2 =
437 pipe_block_sizes.bits.log2_min_luma_transform_block_size_minus2;
438 va_block_sizes.bits.max_max_transform_hierarchy_depth_inter =
439 pipe_block_sizes.bits.max_max_transform_hierarchy_depth_inter;
440 va_block_sizes.bits.min_max_transform_hierarchy_depth_inter =
441 pipe_block_sizes.bits.min_max_transform_hierarchy_depth_inter;
442 va_block_sizes.bits.max_max_transform_hierarchy_depth_intra =
443 pipe_block_sizes.bits.max_max_transform_hierarchy_depth_intra;
444 va_block_sizes.bits.min_max_transform_hierarchy_depth_intra =
445 pipe_block_sizes.bits.min_max_transform_hierarchy_depth_intra;
446 va_block_sizes.bits.log2_max_pcm_coding_block_size_minus3 =
447 pipe_block_sizes.bits.log2_max_pcm_coding_block_size_minus3;
448 va_block_sizes.bits.log2_min_pcm_coding_block_size_minus3 =
449 pipe_block_sizes.bits.log2_min_pcm_coding_block_size_minus3;
450 value = va_block_sizes.value;
451 }
452 } break;
453 #endif
454 #if VA_CHECK_VERSION(1, 6, 0)
455 case VAConfigAttribPredictionDirection:
456 {
457 /* The VA enum values match the pipe_h265_enc_pred_direction definitions*/
458 int h265_enc_pred_direction = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
459 PIPE_VIDEO_ENTRYPOINT_ENCODE,
460 PIPE_VIDEO_CAP_ENC_HEVC_PREDICTION_DIRECTION);
461 if (h265_enc_pred_direction <= 0)
462 value = VA_ATTRIB_NOT_SUPPORTED;
463 else
464 value = h265_enc_pred_direction;
465 } break;
466 #endif
467 #if VA_CHECK_VERSION(1, 16, 0)
468 case VAConfigAttribEncAV1:
469 {
470 union pipe_av1_enc_cap_features features;
471 features.value = 0;
472
473 int support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
474 PIPE_VIDEO_ENTRYPOINT_ENCODE,
475 PIPE_VIDEO_CAP_ENC_AV1_FEATURE);
476 if (support <= 0)
477 value = VA_ATTRIB_NOT_SUPPORTED;
478 else {
479 VAConfigAttribValEncAV1 attrib;
480 features.value = support;
481 attrib.value = features.value;
482 value = attrib.value;
483 }
484 } break;
485 case VAConfigAttribEncAV1Ext1:
486 {
487 union pipe_av1_enc_cap_features_ext1 features_ext1;
488 features_ext1.value = 0;
489 int support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
490 PIPE_VIDEO_ENTRYPOINT_ENCODE,
491 PIPE_VIDEO_CAP_ENC_AV1_FEATURE_EXT1);
492 if (support <= 0)
493 value = VA_ATTRIB_NOT_SUPPORTED;
494 else {
495 VAConfigAttribValEncAV1Ext1 attrib;
496 features_ext1.value = support;
497 attrib.value = features_ext1.value;
498 value = attrib.value;
499 }
500
501 } break;
502 case VAConfigAttribEncAV1Ext2:
503 {
504 union pipe_av1_enc_cap_features_ext2 features_ext2;
505 features_ext2.value = 0;
506
507 int support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
508 PIPE_VIDEO_ENTRYPOINT_ENCODE,
509 PIPE_VIDEO_CAP_ENC_AV1_FEATURE_EXT2);
510 if (support <= 0)
511 value = VA_ATTRIB_NOT_SUPPORTED;
512 else {
513 VAConfigAttribValEncAV1Ext2 attrib;
514 features_ext2.value = support;
515 attrib.value = features_ext2.value;
516 value = attrib.value;
517 }
518
519 } break;
520 case VAConfigAttribEncTileSupport:
521 {
522 int encode_tile_support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
523 PIPE_VIDEO_ENTRYPOINT_ENCODE,
524 PIPE_VIDEO_CAP_ENC_SUPPORTS_TILE);
525 if (encode_tile_support <= 0)
526 value = VA_ATTRIB_NOT_SUPPORTED;
527 else
528 value = encode_tile_support;
529 } break;
530 #endif
531 #if VA_CHECK_VERSION(1, 21, 0)
532 case VAConfigAttribEncMaxTileRows:
533 {
534 int max_tile_rows = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
535 PIPE_VIDEO_ENTRYPOINT_ENCODE,
536 PIPE_VIDEO_CAP_ENC_MAX_TILE_ROWS);
537 if (max_tile_rows <= 0)
538 value = VA_ATTRIB_NOT_SUPPORTED;
539 else
540 value = max_tile_rows;
541 } break;
542 case VAConfigAttribEncMaxTileCols:
543 {
544 int max_tile_cols = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
545 PIPE_VIDEO_ENTRYPOINT_ENCODE,
546 PIPE_VIDEO_CAP_ENC_MAX_TILE_COLS);
547 if (max_tile_cols <= 0)
548 value = VA_ATTRIB_NOT_SUPPORTED;
549 else
550 value = max_tile_cols;
551 } break;
552 #endif
553 case VAConfigAttribEncIntraRefresh:
554 {
555 int ir_support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
556 PIPE_VIDEO_ENTRYPOINT_ENCODE,
557 PIPE_VIDEO_CAP_ENC_INTRA_REFRESH);
558 if (ir_support <= 0)
559 value = VA_ATTRIB_NOT_SUPPORTED;
560 else
561 value = ir_support;
562 } break;
563
564 case VAConfigAttribEncROI:
565 {
566 int roi_support = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
567 PIPE_VIDEO_ENTRYPOINT_ENCODE,
568 PIPE_VIDEO_CAP_ENC_ROI);
569 if (roi_support <= 0)
570 value = VA_ATTRIB_NOT_SUPPORTED;
571 else
572 value = roi_support;
573 } break;
574
575 default:
576 value = VA_ATTRIB_NOT_SUPPORTED;
577 break;
578 }
579 } else if (entrypoint == VAEntrypointVideoProc) {
580 switch (attrib_list[i].type) {
581 case VAConfigAttribRTFormat:
582 value = get_screen_supported_va_rt_formats(pscreen,
583 PIPE_VIDEO_PROFILE_UNKNOWN,
584 PIPE_VIDEO_ENTRYPOINT_PROCESSING);
585 break;
586 default:
587 value = VA_ATTRIB_NOT_SUPPORTED;
588 break;
589 }
590 } else {
591 value = VA_ATTRIB_NOT_SUPPORTED;
592 }
593 attrib_list[i].value = value;
594 }
595
596 return VA_STATUS_SUCCESS;
597 }
598
599 VAStatus
vlVaCreateConfig(VADriverContextP ctx,VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attrib_list,int num_attribs,VAConfigID * config_id)600 vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
601 VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id)
602 {
603 vlVaDriver *drv;
604 vlVaConfig *config;
605 struct pipe_screen *pscreen;
606 enum pipe_video_profile p;
607 unsigned int supported_rt_formats;
608
609 if (!ctx)
610 return VA_STATUS_ERROR_INVALID_CONTEXT;
611
612 drv = VL_VA_DRIVER(ctx);
613 pscreen = VL_VA_PSCREEN(ctx);
614
615 if (!drv)
616 return VA_STATUS_ERROR_INVALID_CONTEXT;
617
618 config = CALLOC(1, sizeof(vlVaConfig));
619 if (!config)
620 return VA_STATUS_ERROR_ALLOCATION_FAILED;
621
622 if (profile == VAProfileNone) {
623 if (entrypoint != VAEntrypointVideoProc) {
624 FREE(config);
625 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
626 }
627
628 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_PROCESSING;
629 config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
630 supported_rt_formats = get_screen_supported_va_rt_formats(pscreen,
631 config->profile,
632 config->entrypoint);
633 for (int i = 0; i < num_attribs; i++) {
634 if (attrib_list[i].type == VAConfigAttribRTFormat) {
635 if (attrib_list[i].value & supported_rt_formats) {
636 config->rt_format = attrib_list[i].value;
637 } else {
638 FREE(config);
639 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
640 }
641 } else {
642 /*other attrib_types are not supported.*/
643 FREE(config);
644 return VA_STATUS_ERROR_INVALID_VALUE;
645 }
646 }
647
648 /* Default value if not specified in the input attributes. */
649 if (!config->rt_format)
650 config->rt_format = supported_rt_formats;
651
652 mtx_lock(&drv->mutex);
653 *config_id = handle_table_add(drv->htab, config);
654 mtx_unlock(&drv->mutex);
655 return VA_STATUS_SUCCESS;
656 }
657
658 p = ProfileToPipe(profile);
659 if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||
660 (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&
661 !debug_get_option_mpeg4())) {
662 FREE(config);
663 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
664 }
665
666 switch (entrypoint) {
667 case VAEntrypointVLD:
668 if (!vl_codec_supported(pscreen, p, false)) {
669 FREE(config);
670 if (!vl_codec_supported(pscreen, p, true))
671 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
672 else
673 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
674 }
675
676 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;
677 break;
678
679 case VAEntrypointEncSlice:
680 if (!vl_codec_supported(pscreen, p, true)) {
681 FREE(config);
682 if (!vl_codec_supported(pscreen, p, false))
683 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
684 else
685 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
686 }
687
688 config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE;
689 break;
690
691 default:
692 FREE(config);
693 if (!vl_codec_supported(pscreen, p, false) &&
694 !vl_codec_supported(pscreen, p, true))
695 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
696 else
697 return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
698 }
699
700 config->profile = p;
701 supported_rt_formats = get_screen_supported_va_rt_formats(pscreen,
702 config->profile,
703 config->entrypoint);
704 for (int i = 0; i <num_attribs ; i++) {
705 if (attrib_list[i].type != VAConfigAttribRTFormat &&
706 entrypoint == VAEntrypointVLD ) {
707 FREE(config);
708 return VA_STATUS_ERROR_INVALID_VALUE;
709 }
710 if (attrib_list[i].type == VAConfigAttribRateControl) {
711 if (attrib_list[i].value == VA_RC_CBR)
712 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT;
713 else if (attrib_list[i].value == VA_RC_VBR)
714 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE;
715 else if (attrib_list[i].value == VA_RC_CQP)
716 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE;
717 else if (attrib_list[i].value == VA_RC_QVBR &&
718 (pscreen->get_video_param(pscreen, ProfileToPipe(profile),
719 PIPE_VIDEO_ENTRYPOINT_ENCODE,
720 PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR) > 0))
721 config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE;
722 else {
723 FREE(config);
724 return VA_STATUS_ERROR_INVALID_VALUE;
725 }
726 }
727 if (attrib_list[i].type == VAConfigAttribRTFormat) {
728 if (attrib_list[i].value & supported_rt_formats) {
729 config->rt_format = attrib_list[i].value;
730 } else {
731 FREE(config);
732 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
733 }
734 }
735 if (attrib_list[i].type == VAConfigAttribEncPackedHeaders) {
736 uint32_t attrib_value = attrib_list[i].value;
737 if (config->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE ||
738 (((attrib_value != 0)) &&
739 ((attrib_value & ENC_PACKED_HEADERS_H264) != attrib_value ||
740 u_reduce_video_profile(ProfileToPipe(profile)) != PIPE_VIDEO_FORMAT_MPEG4_AVC) &&
741 ((attrib_value & ENC_PACKED_HEADERS_HEVC) != attrib_value ||
742 u_reduce_video_profile(ProfileToPipe(profile)) != PIPE_VIDEO_FORMAT_HEVC) &&
743 ((attrib_value & ENC_PACKED_HEADERS_AV1) != attrib_value ||
744 u_reduce_video_profile(ProfileToPipe(profile)) != PIPE_VIDEO_FORMAT_AV1))) {
745 FREE(config);
746 return VA_STATUS_ERROR_INVALID_VALUE;
747 }
748 }
749 }
750
751 /* Default value if not specified in the input attributes. */
752 if (!config->rt_format)
753 config->rt_format = supported_rt_formats;
754
755 mtx_lock(&drv->mutex);
756 *config_id = handle_table_add(drv->htab, config);
757 mtx_unlock(&drv->mutex);
758
759 return VA_STATUS_SUCCESS;
760 }
761
762 VAStatus
vlVaDestroyConfig(VADriverContextP ctx,VAConfigID config_id)763 vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id)
764 {
765 vlVaDriver *drv;
766 vlVaConfig *config;
767
768 if (!ctx)
769 return VA_STATUS_ERROR_INVALID_CONTEXT;
770
771 drv = VL_VA_DRIVER(ctx);
772
773 if (!drv)
774 return VA_STATUS_ERROR_INVALID_CONTEXT;
775
776 mtx_lock(&drv->mutex);
777 config = handle_table_get(drv->htab, config_id);
778
779 if (!config) {
780 mtx_unlock(&drv->mutex);
781 return VA_STATUS_ERROR_INVALID_CONFIG;
782 }
783
784 FREE(config);
785 handle_table_remove(drv->htab, config_id);
786 mtx_unlock(&drv->mutex);
787
788 return VA_STATUS_SUCCESS;
789 }
790
791 VAStatus
vlVaQueryConfigAttributes(VADriverContextP ctx,VAConfigID config_id,VAProfile * profile,VAEntrypoint * entrypoint,VAConfigAttrib * attrib_list,int * num_attribs)792 vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,
793 VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs)
794 {
795 vlVaDriver *drv;
796 vlVaConfig *config;
797
798 if (!ctx)
799 return VA_STATUS_ERROR_INVALID_CONTEXT;
800
801 drv = VL_VA_DRIVER(ctx);
802
803 if (!drv)
804 return VA_STATUS_ERROR_INVALID_CONTEXT;
805
806 mtx_lock(&drv->mutex);
807 config = handle_table_get(drv->htab, config_id);
808 mtx_unlock(&drv->mutex);
809
810 if (!config)
811 return VA_STATUS_ERROR_INVALID_CONFIG;
812
813 *profile = PipeToProfile(config->profile);
814
815 switch (config->entrypoint) {
816 case PIPE_VIDEO_ENTRYPOINT_BITSTREAM:
817 *entrypoint = VAEntrypointVLD;
818 break;
819 case PIPE_VIDEO_ENTRYPOINT_ENCODE:
820 *entrypoint = VAEntrypointEncSlice;
821 break;
822 case PIPE_VIDEO_ENTRYPOINT_PROCESSING:
823 *entrypoint = VAEntrypointVideoProc;
824 break;
825 default:
826 return VA_STATUS_ERROR_INVALID_CONFIG;
827 }
828
829 *num_attribs = 1;
830 attrib_list[0].type = VAConfigAttribRTFormat;
831 attrib_list[0].value = config->rt_format;
832
833 return VA_STATUS_SUCCESS;
834 }
835