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