2 * Copyright ?2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
33 #include <drm_fourcc.h>
36 # include "i965_output_dri.h"
39 #ifdef HAVE_VA_WAYLAND
40 # include "i965_output_wayland.h"
43 #include "intel_version.h"
44 #include "intel_driver.h"
45 #include "intel_memman.h"
46 #include "intel_batchbuffer.h"
47 #include "i965_defines.h"
48 #include "i965_drv_video.h"
49 #include "i965_decoder.h"
50 #include "i965_encoder.h"
52 #include "i965_post_processing.h"
54 #include "gen9_vp9_encapi.h"
56 #define CONFIG_ID_OFFSET 0x01000000
57 #define CONTEXT_ID_OFFSET 0x02000000
58 #define SURFACE_ID_OFFSET 0x04000000
59 #define BUFFER_ID_OFFSET 0x08000000
60 #define IMAGE_ID_OFFSET 0x0a000000
61 #define SUBPIC_ID_OFFSET 0x10000000
63 static int get_sampling_from_fourcc(unsigned int fourcc);
65 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
66 #define IS_VA_X11(ctx) \
67 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
69 /* Check whether we are rendering to Wayland */
70 #define IS_VA_WAYLAND(ctx) \
71 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
74 #define I965_2BITS (I965_BIT << 1)
75 #define I965_4BITS (I965_BIT << 2)
76 #define I965_8BITS (I965_BIT << 3)
77 #define I965_16BITS (I965_BIT << 4)
78 #define I965_32BITS (I965_BIT << 5)
90 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
91 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
92 #define I_I420 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
95 #define I_YV12 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
98 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
100 #define I_I010 2, 2, 3, {I965_16BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
102 #define I_422H 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
103 #define I_422V 1, 2, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
104 #define I_YV16 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
105 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
106 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
108 #define I_444P 1, 1, 3, {I965_8BITS, I965_8BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
110 #define I_411P 4, 1, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
112 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
114 #define I_RGBA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24} }
115 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
116 #define I_BGRA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_24} }
117 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
119 #define I_ARGB 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_0} }
120 #define I_ABGR 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
122 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
123 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
125 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
126 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
131 #define I_SI (I_S | I_I)
133 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
134 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
135 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
136 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
138 static const i965_fourcc_info i965_fourcc_infos[] = {
139 DEF_YUV(NV12, YUV420, I_SI),
140 DEF_YUV(I420, YUV420, I_SI),
141 DEF_YUV(IYUV, YUV420, I_S),
142 DEF_YUV(IMC3, YUV420, I_S),
143 DEF_YUV(YV12, YUV420, I_SI),
144 DEF_YUV(IMC1, YUV420, I_S),
146 DEF_YUV(P010, YUV420, I_SI),
147 DEF_YUV(I010, YUV420, I_S),
149 DEF_YUV(422H, YUV422H, I_SI),
150 DEF_YUV(422V, YUV422V, I_S),
151 DEF_YUV(YV16, YUV422H, I_S),
152 DEF_YUV(YUY2, YUV422H, I_SI),
153 DEF_YUV(UYVY, YUV422H, I_SI),
155 DEF_YUV(444P, YUV444, I_S),
157 DEF_YUV(411P, YUV411, I_S),
159 DEF_YUV(Y800, YUV400, I_S),
161 DEF_RGB(RGBA, RGBX, I_SI),
162 DEF_RGB(RGBX, RGBX, I_SI),
163 DEF_RGB(BGRA, RGBX, I_SI),
164 DEF_RGB(BGRX, RGBX, I_SI),
166 DEF_RGB(ARGB, RGBX, I_I),
167 DEF_RGB(ABGR, RGBX, I_I),
169 DEF_INDEX(IA88, RGBX, I_I),
170 DEF_INDEX(AI88, RGBX, I_I),
172 DEF_INDEX(IA44, RGBX, I_I),
173 DEF_INDEX(AI44, RGBX, I_I)
176 const i965_fourcc_info *
177 get_fourcc_info(unsigned int fourcc)
181 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
182 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
184 if (info->fourcc == fourcc)
192 get_bpp_from_fourcc(unsigned int fourcc)
194 const i965_fourcc_info *info = get_fourcc_info(fourcc);
196 unsigned int bpp = 0;
201 for (i = 0; i < info->num_planes; i++)
208 I965_SURFACETYPE_RGBA = 1,
209 I965_SURFACETYPE_YUV,
210 I965_SURFACETYPE_INDEXED
213 /* List of supported display attributes */
214 static const VADisplayAttribute i965_display_attributes[] = {
216 VADisplayAttribBrightness,
217 -100, 100, DEFAULT_BRIGHTNESS,
218 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
222 VADisplayAttribContrast,
223 0, 100, DEFAULT_CONTRAST,
224 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
229 -180, 180, DEFAULT_HUE,
230 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
234 VADisplayAttribSaturation,
235 0, 100, DEFAULT_SATURATION,
236 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
240 VADisplayAttribRotation,
241 0, 3, VA_ROTATION_NONE,
242 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
246 /* List of supported image formats */
249 VAImageFormat va_format;
250 } i965_image_format_map_t;
252 static const i965_image_format_map_t
253 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
255 I965_SURFACETYPE_YUV,
256 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, }
259 I965_SURFACETYPE_YUV,
260 { VA_FOURCC_I420, VA_LSB_FIRST, 12, }
263 I965_SURFACETYPE_YUV,
264 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, }
267 I965_SURFACETYPE_YUV,
268 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, }
271 I965_SURFACETYPE_YUV,
272 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, }
275 I965_SURFACETYPE_YUV,
276 { VA_FOURCC_422H, VA_LSB_FIRST, 16, }
279 I965_SURFACETYPE_RGBA,
280 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 }
283 I965_SURFACETYPE_RGBA,
284 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff }
287 I965_SURFACETYPE_YUV,
288 { VA_FOURCC_P010, VA_LSB_FIRST, 24, }
292 /* List of supported subpicture formats */
296 VAImageFormat va_format;
297 unsigned int va_flags;
298 } i965_subpic_format_map_t;
300 #define COMMON_SUBPICTURE_FLAGS \
301 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
302 VA_SUBPICTURE_GLOBAL_ALPHA)
304 static const i965_subpic_format_map_t
305 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
307 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
308 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
309 COMMON_SUBPICTURE_FLAGS
312 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
313 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
314 COMMON_SUBPICTURE_FLAGS
317 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
318 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
319 COMMON_SUBPICTURE_FLAGS
322 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
323 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
324 COMMON_SUBPICTURE_FLAGS
327 I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
329 VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
330 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000
332 COMMON_SUBPICTURE_FLAGS
335 I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
337 VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
338 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
340 COMMON_SUBPICTURE_FLAGS
344 static const i965_subpic_format_map_t *
345 get_subpic_format(const VAImageFormat *va_format)
348 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
349 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
350 if (m->va_format.fourcc == va_format->fourcc &&
351 (m->type == I965_SURFACETYPE_RGBA ?
352 (m->va_format.byte_order == va_format->byte_order &&
353 m->va_format.red_mask == va_format->red_mask &&
354 m->va_format.green_mask == va_format->green_mask &&
355 m->va_format.blue_mask == va_format->blue_mask &&
356 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
362 /* Checks whether the surface is in busy state */
364 is_surface_busy(struct i965_driver_data *i965,
365 struct object_surface *obj_surface)
367 assert(obj_surface != NULL);
369 if (obj_surface->locked_image_id != VA_INVALID_ID)
371 if (obj_surface->derived_image_id != VA_INVALID_ID)
376 /* Checks whether the image is in busy state */
378 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
380 struct object_buffer *obj_buffer;
382 assert(obj_image != NULL);
384 if (obj_image->derived_surface != VA_INVALID_ID &&
385 obj_image->derived_surface == surface)
388 obj_buffer = BUFFER(obj_image->image.buf);
389 if (obj_buffer && obj_buffer->export_refcount > 0)
394 #define I965_PACKED_HEADER_BASE 0
395 #define I965_SEQ_PACKED_HEADER_BASE 0
396 #define I965_SEQ_PACKED_HEADER_END 2
397 #define I965_PIC_PACKED_HEADER_BASE 2
398 #define I965_PACKED_MISC_HEADER_BASE 4
401 va_enc_packed_type_to_idx(int packed_type)
405 if (packed_type & VAEncPackedHeaderMiscMask) {
406 idx = I965_PACKED_MISC_HEADER_BASE;
407 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
408 ASSERT_RET(packed_type > 0, 0);
409 idx += (packed_type - 1);
411 idx = I965_PACKED_HEADER_BASE;
413 switch (packed_type) {
414 case VAEncPackedHeaderSequence:
415 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
418 case VAEncPackedHeaderPicture:
419 idx = I965_PIC_PACKED_HEADER_BASE + 0;
422 case VAEncPackedHeaderSlice:
423 idx = I965_PIC_PACKED_HEADER_BASE + 1;
427 /* Should not get here */
433 ASSERT_RET(idx < 5, 0);
437 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
440 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
442 struct i965_driver_data *i965 = i965_driver_data(ctx);
443 struct object_surface *obj_surface = SURFACE(surface);
444 VAStatus va_status = VA_STATUS_SUCCESS;
447 return VA_STATUS_ERROR_INVALID_SURFACE;
450 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
451 /* the wrapped surface already exists. just return it */
455 if (obj_surface->fourcc == 0)
456 i965_check_alloc_surface_bo(ctx, obj_surface,
457 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
460 * TBD: Support more surface formats.
461 * Currently only NV12 is support as NV12 is used by decoding.
463 if (obj_surface->fourcc != VA_FOURCC_NV12)
464 return VA_STATUS_ERROR_INVALID_PARAMETER;
466 if ((i965->wrapper_pdrvctx == NULL) ||
467 (obj_surface->bo == NULL))
468 return VA_STATUS_ERROR_INVALID_PARAMETER;
472 VASurfaceAttrib attrib_list[2];
473 VASurfaceAttribExternalBuffers buffer_descriptor;
474 VAGenericID wrapper_surface;
476 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
477 return VA_STATUS_ERROR_OPERATION_FAILED;
479 obj_surface->exported_primefd = fd_handle;
481 memset(&attrib_list, 0, sizeof(attrib_list));
482 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
484 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
485 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
486 attrib_list[0].value.value.p = &buffer_descriptor;
487 attrib_list[0].value.type = VAGenericValueTypePointer;
489 attrib_list[1].type = VASurfaceAttribMemoryType;
490 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
491 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
492 attrib_list[1].value.type = VAGenericValueTypeInteger;
494 buffer_descriptor.num_buffers = 1;
495 buffer_descriptor.num_planes = 2;
496 buffer_descriptor.width = obj_surface->orig_width;
497 buffer_descriptor.height = obj_surface->orig_height;
498 buffer_descriptor.pixel_format = obj_surface->fourcc;
499 buffer_descriptor.data_size = obj_surface->size;
500 buffer_descriptor.pitches[0] = obj_surface->width;
501 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
502 buffer_descriptor.offsets[0] = 0;
503 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
504 buffer_descriptor.buffers = (void *)&fd_handle;
506 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
507 vaCreateSurfaces2(i965->wrapper_pdrvctx,
509 obj_surface->orig_width,
510 obj_surface->orig_height,
514 if (va_status == VA_STATUS_SUCCESS) {
515 obj_surface->wrapper_surface = wrapper_surface;
517 /* This needs to be checked */
518 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
526 i965_QueryConfigProfiles(VADriverContextP ctx,
527 VAProfile *profile_list, /* out */
528 int *num_profiles) /* out */
530 struct i965_driver_data * const i965 = i965_driver_data(ctx);
533 if (HAS_MPEG2_DECODING(i965) ||
534 HAS_MPEG2_ENCODING(i965)) {
535 profile_list[i++] = VAProfileMPEG2Simple;
536 profile_list[i++] = VAProfileMPEG2Main;
539 if (HAS_H264_DECODING(i965) ||
540 HAS_H264_ENCODING(i965) ||
541 HAS_LP_H264_ENCODING(i965) ||
542 HAS_FEI_H264_ENCODING(i965) ||
543 HAS_H264_PREENC(i965)) {
544 profile_list[i++] = VAProfileH264ConstrainedBaseline;
545 profile_list[i++] = VAProfileH264Main;
546 profile_list[i++] = VAProfileH264High;
548 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
549 HAS_H264_MVC_ENCODING(i965))
550 profile_list[i++] = VAProfileH264MultiviewHigh;
551 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
552 HAS_H264_MVC_ENCODING(i965))
553 profile_list[i++] = VAProfileH264StereoHigh;
555 if (HAS_VC1_DECODING(i965)) {
556 profile_list[i++] = VAProfileVC1Simple;
557 profile_list[i++] = VAProfileVC1Main;
558 profile_list[i++] = VAProfileVC1Advanced;
562 profile_list[i++] = VAProfileNone;
565 if (HAS_JPEG_DECODING(i965) ||
566 HAS_JPEG_ENCODING(i965)) {
567 profile_list[i++] = VAProfileJPEGBaseline;
570 if (HAS_VP8_DECODING(i965) ||
571 HAS_VP8_ENCODING(i965)) {
572 profile_list[i++] = VAProfileVP8Version0_3;
575 if (HAS_HEVC_DECODING(i965) ||
576 HAS_HEVC_ENCODING(i965)) {
577 profile_list[i++] = VAProfileHEVCMain;
580 if (HAS_HEVC10_DECODING(i965) ||
581 HAS_HEVC10_ENCODING(i965)) {
582 profile_list[i++] = VAProfileHEVCMain10;
585 if (HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
586 HAS_VP9_ENCODING(i965) ||
587 HAS_LP_VP9_ENCODING(i965)) {
588 profile_list[i++] = VAProfileVP9Profile0;
591 if (HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
592 profile_list[i++] = VAProfileVP9Profile2;
595 if (i965->wrapper_pdrvctx) {
596 VAProfile wrapper_list[4];
598 VADriverContextP pdrvctx;
601 pdrvctx = i965->wrapper_pdrvctx;
602 CALL_VTABLE(pdrvctx, va_status,
603 vaQueryConfigProfiles(pdrvctx,
604 wrapper_list, &wrapper_num));
606 if (va_status == VA_STATUS_SUCCESS) {
608 for (j = 0; j < wrapper_num; j++)
609 if (wrapper_list[j] != VAProfileNone)
610 profile_list[i++] = wrapper_list[j];
614 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
615 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
618 return VA_STATUS_SUCCESS;
622 i965_QueryConfigEntrypoints(VADriverContextP ctx,
624 VAEntrypoint *entrypoint_list, /* out */
625 int *num_entrypoints) /* out */
627 struct i965_driver_data * const i965 = i965_driver_data(ctx);
631 case VAProfileMPEG2Simple:
632 case VAProfileMPEG2Main:
633 if (HAS_MPEG2_DECODING(i965))
634 entrypoint_list[n++] = VAEntrypointVLD;
636 if (HAS_MPEG2_ENCODING(i965))
637 entrypoint_list[n++] = VAEntrypointEncSlice;
641 case VAProfileH264ConstrainedBaseline:
642 case VAProfileH264Main:
643 case VAProfileH264High:
644 if (HAS_H264_DECODING(i965))
645 entrypoint_list[n++] = VAEntrypointVLD;
647 if (HAS_H264_ENCODING(i965))
648 entrypoint_list[n++] = VAEntrypointEncSlice;
650 if (HAS_LP_H264_ENCODING(i965))
651 entrypoint_list[n++] = VAEntrypointEncSliceLP;
653 if (HAS_FEI_H264_ENCODING(i965))
654 entrypoint_list[n++] = VAEntrypointFEI;
656 if (HAS_H264_PREENC(i965))
657 entrypoint_list[n++] = VAEntrypointStats;
660 case VAProfileH264MultiviewHigh:
661 case VAProfileH264StereoHigh:
662 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
663 entrypoint_list[n++] = VAEntrypointVLD;
665 if (HAS_H264_MVC_ENCODING(i965))
666 entrypoint_list[n++] = VAEntrypointEncSlice;
669 case VAProfileVC1Simple:
670 case VAProfileVC1Main:
671 case VAProfileVC1Advanced:
672 if (HAS_VC1_DECODING(i965))
673 entrypoint_list[n++] = VAEntrypointVLD;
678 entrypoint_list[n++] = VAEntrypointVideoProc;
681 case VAProfileJPEGBaseline:
682 if (HAS_JPEG_DECODING(i965))
683 entrypoint_list[n++] = VAEntrypointVLD;
685 if (HAS_JPEG_ENCODING(i965))
686 entrypoint_list[n++] = VAEntrypointEncPicture;
689 case VAProfileVP8Version0_3:
690 if (HAS_VP8_DECODING(i965))
691 entrypoint_list[n++] = VAEntrypointVLD;
693 if (HAS_VP8_ENCODING(i965))
694 entrypoint_list[n++] = VAEntrypointEncSlice;
698 case VAProfileHEVCMain:
699 if (HAS_HEVC_DECODING(i965))
700 entrypoint_list[n++] = VAEntrypointVLD;
702 if (HAS_HEVC_ENCODING(i965))
703 entrypoint_list[n++] = VAEntrypointEncSlice;
707 case VAProfileHEVCMain10:
708 if (HAS_HEVC10_DECODING(i965))
709 entrypoint_list[n++] = VAEntrypointVLD;
711 if (HAS_HEVC10_ENCODING(i965))
712 entrypoint_list[n++] = VAEntrypointEncSlice;
716 case VAProfileVP9Profile0:
717 case VAProfileVP9Profile2:
718 if (HAS_VP9_DECODING_PROFILE(i965, profile))
719 entrypoint_list[n++] = VAEntrypointVLD;
721 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
722 entrypoint_list[n++] = VAEntrypointEncSlice;
724 if (HAS_LP_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
725 entrypoint_list[n++] = VAEntrypointEncSliceLP;
727 if (profile == VAProfileVP9Profile0) {
728 if (i965->wrapper_pdrvctx) {
729 VAStatus va_status = VA_STATUS_SUCCESS;
730 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
732 CALL_VTABLE(pdrvctx, va_status,
733 vaQueryConfigEntrypoints(pdrvctx, profile,
746 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
747 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
748 *num_entrypoints = n;
749 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
753 i965_validate_config(VADriverContextP ctx, VAProfile profile,
754 VAEntrypoint entrypoint)
756 struct i965_driver_data * const i965 = i965_driver_data(ctx);
759 /* Validate profile & entrypoint */
761 case VAProfileMPEG2Simple:
762 case VAProfileMPEG2Main:
763 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
764 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
765 va_status = VA_STATUS_SUCCESS;
766 } else if (!HAS_MPEG2_DECODING(i965) && !HAS_MPEG2_ENCODING(i965)) {
767 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
769 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
773 case VAProfileH264ConstrainedBaseline:
774 case VAProfileH264Main:
775 case VAProfileH264High:
776 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
777 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
778 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP) ||
779 (HAS_FEI_H264_ENCODING(i965) && entrypoint == VAEntrypointFEI) ||
780 (HAS_H264_PREENC(i965) && entrypoint == VAEntrypointStats)) {
781 va_status = VA_STATUS_SUCCESS;
782 } else if (!HAS_H264_DECODING(i965) && !HAS_H264_ENCODING(i965) &&
783 !HAS_LP_H264_ENCODING(i965) && !HAS_FEI_H264_ENCODING(i965) &&
784 !HAS_H264_PREENC(i965)) {
785 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
787 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
791 case VAProfileVC1Simple:
792 case VAProfileVC1Main:
793 case VAProfileVC1Advanced:
794 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
795 va_status = VA_STATUS_SUCCESS;
796 } else if (!HAS_VC1_DECODING(i965)) {
797 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
799 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
804 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
805 va_status = VA_STATUS_SUCCESS;
806 } else if (!HAS_VPP(i965)) {
807 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
809 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
813 case VAProfileJPEGBaseline:
814 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
815 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
816 va_status = VA_STATUS_SUCCESS;
817 } else if (!HAS_JPEG_DECODING(i965) && !HAS_JPEG_ENCODING(i965)) {
818 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
820 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
824 case VAProfileVP8Version0_3:
825 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
826 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
827 va_status = VA_STATUS_SUCCESS;
828 } else if (!HAS_VP8_DECODING(i965) && !HAS_VP8_ENCODING(i965)) {
829 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
831 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
835 case VAProfileH264MultiviewHigh:
836 case VAProfileH264StereoHigh:
837 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
838 entrypoint == VAEntrypointVLD) ||
839 (HAS_H264_MVC_ENCODING(i965) &&
840 entrypoint == VAEntrypointEncSlice)) {
841 va_status = VA_STATUS_SUCCESS;
842 } else if (!HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
843 !HAS_H264_MVC_ENCODING(i965)) {
844 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
846 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
851 case VAProfileHEVCMain:
852 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD)) ||
853 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice))) {
854 va_status = VA_STATUS_SUCCESS;
855 } else if (!HAS_HEVC_DECODING(i965) && !HAS_HEVC_ENCODING(i965)) {
856 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
858 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
863 case VAProfileHEVCMain10:
864 if ((HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD)) ||
865 (HAS_HEVC10_ENCODING(i965) &&
866 (entrypoint == VAEntrypointEncSlice))) {
867 va_status = VA_STATUS_SUCCESS;
868 } else if (!HAS_HEVC10_DECODING(i965) && !HAS_HEVC10_ENCODING(i965)) {
869 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
871 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
876 case VAProfileVP9Profile0:
877 case VAProfileVP9Profile2:
878 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) &&
879 (entrypoint == VAEntrypointVLD)) {
880 va_status = VA_STATUS_SUCCESS;
881 } else if ((HAS_VP9_ENCODING_PROFILE(i965, profile)) &&
882 (entrypoint == VAEntrypointEncSlice)) {
883 va_status = VA_STATUS_SUCCESS;
884 } else if ((HAS_LP_VP9_ENCODING(i965) &&
885 profile == VAProfileVP9Profile0 &&
886 entrypoint == VAEntrypointEncSliceLP)) {
887 va_status = VA_STATUS_SUCCESS;
888 } else if (profile == VAProfileVP9Profile0 &&
889 entrypoint == VAEntrypointVLD &&
890 i965->wrapper_pdrvctx) {
891 va_status = VA_STATUS_SUCCESS;
892 } else if (!HAS_VP9_DECODING_PROFILE(i965, profile) &&
893 !HAS_VP9_ENCODING(i965) &&
894 !HAS_LP_VP9_ENCODING(i965) &&
895 !i965->wrapper_pdrvctx) {
896 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
898 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
904 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
911 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
912 VAEntrypoint entrypoint)
914 struct i965_driver_data * const i965 = i965_driver_data(ctx);
915 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
918 case VAProfileH264ConstrainedBaseline:
919 case VAProfileH264Main:
920 case VAProfileH264High:
921 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
922 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
925 case VAProfileH264MultiviewHigh:
926 case VAProfileH264StereoHigh:
927 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
928 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
931 case VAProfileJPEGBaseline:
932 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
933 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
934 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
935 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
938 case VAProfileHEVCMain10:
939 if (HAS_HEVC10_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)
940 chroma_formats = VA_RT_FORMAT_YUV420_10BPP;
941 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
942 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
946 if (HAS_VPP_P010(i965))
947 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
950 chroma_formats |= VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_RGB32;
953 case VAProfileVP9Profile0:
954 case VAProfileVP9Profile2:
955 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
956 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
962 return chroma_formats;
966 i965_get_rc_attributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint)
968 struct i965_driver_data * const i965 = i965_driver_data(ctx);
970 uint32_t rc_attribs = VA_ATTRIB_NOT_SUPPORTED;
972 if (entrypoint == VAEntrypointEncSlice) {
974 rc_attribs = VA_RC_CQP;
976 if (profile != VAProfileMPEG2Main &&
977 profile != VAProfileMPEG2Simple)
978 rc_attribs |= VA_RC_CBR;
980 if (profile == VAProfileVP8Version0_3 ||
981 profile == VAProfileHEVCMain ||
982 profile == VAProfileHEVCMain10)
983 rc_attribs |= VA_RC_VBR;
985 if (profile == VAProfileVP9Profile0)
986 rc_attribs = i965->codec_info->vp9_brc_mode;
988 if (profile == VAProfileH264ConstrainedBaseline ||
989 profile == VAProfileH264Main ||
990 profile == VAProfileH264High ||
991 profile == VAProfileH264MultiviewHigh ||
992 profile == VAProfileH264StereoHigh)
993 rc_attribs = i965->codec_info->h264_brc_mode;
995 } else if (entrypoint == VAEntrypointEncSliceLP) {
997 if (profile == VAProfileH264ConstrainedBaseline ||
998 profile == VAProfileH264Main ||
999 profile == VAProfileH264High ||
1000 profile == VAProfileH264MultiviewHigh ||
1001 profile == VAProfileH264StereoHigh)
1002 rc_attribs = i965->codec_info->lp_h264_brc_mode;
1004 else if (profile == VAProfileVP9Profile0)
1005 rc_attribs = i965->codec_info->lp_vp9_brc_mode;
1007 } else if (entrypoint == VAEntrypointFEI) {
1009 if (profile == VAProfileH264ConstrainedBaseline ||
1010 profile == VAProfileH264Main ||
1011 profile == VAProfileH264High)
1012 rc_attribs = VA_RC_CQP;
1014 } else if (entrypoint == VAEntrypointEncPicture) {
1015 if (profile == VAProfileJPEGBaseline)
1016 rc_attribs = VA_RC_CQP;
1023 i965_get_enc_packed_attributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint)
1025 uint32_t enc_packed_attribs = VA_ATTRIB_NOT_SUPPORTED;
1027 if (entrypoint == VAEntrypointEncSlice ||
1028 entrypoint == VAEntrypointEncSliceLP ||
1029 entrypoint == VAEntrypointFEI) {
1032 case VAProfileMPEG2Simple:
1033 case VAProfileMPEG2Main:
1034 enc_packed_attribs = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
1037 case VAProfileH264ConstrainedBaseline:
1038 case VAProfileH264Main:
1039 case VAProfileH264High:
1040 case VAProfileH264StereoHigh:
1041 case VAProfileH264MultiviewHigh:
1042 case VAProfileHEVCMain:
1043 case VAProfileHEVCMain10:
1044 enc_packed_attribs = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
1045 enc_packed_attribs |= (VA_ENC_PACKED_HEADER_RAW_DATA | VA_ENC_PACKED_HEADER_SLICE);
1048 case VAProfileVP9Profile0:
1049 enc_packed_attribs = VA_ENC_PACKED_HEADER_RAW_DATA;
1056 } else if (entrypoint == VAEntrypointEncPicture) {
1057 if (profile == VAProfileJPEGBaseline)
1058 enc_packed_attribs = VA_ENC_PACKED_HEADER_RAW_DATA;
1061 return enc_packed_attribs;
1065 i965_GetConfigAttributes(VADriverContextP ctx,
1067 VAEntrypoint entrypoint,
1068 VAConfigAttrib *attrib_list, /* in/out */
1071 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1075 va_status = i965_validate_config(ctx, profile, entrypoint);
1076 if (va_status != VA_STATUS_SUCCESS)
1079 /* Other attributes don't seem to be defined */
1080 /* What to do if we don't know the attribute? */
1081 for (i = 0; i < num_attribs; i++) {
1082 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1083 switch (attrib_list[i].type) {
1084 case VAConfigAttribRTFormat:
1085 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
1086 profile, entrypoint);
1089 case VAConfigAttribRateControl:
1090 attrib_list[i].value = i965_get_rc_attributes(ctx, profile, entrypoint);
1094 case VAConfigAttribEncPackedHeaders:
1095 attrib_list[i].value = i965_get_enc_packed_attributes(ctx, profile, entrypoint);
1099 case VAConfigAttribEncMaxRefFrames:
1100 if (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointFEI) {
1101 attrib_list[i].value = (1 << 16) | (1 << 0);
1102 if (profile == VAProfileH264ConstrainedBaseline ||
1103 profile == VAProfileH264Main ||
1104 profile == VAProfileH264High ||
1105 profile == VAProfileH264StereoHigh ||
1106 profile == VAProfileH264MultiviewHigh) {
1107 if (IS_GEN8(i965->intel.device_info) ||
1108 IS_GEN9(i965->intel.device_info))
1109 attrib_list[i].value = (1 << 16) | (4 << 0);
1110 } else if (profile == VAProfileHEVCMain ||
1111 profile == VAProfileHEVCMain10) {
1112 if (IS_GEN9(i965->intel.device_info))
1113 attrib_list[i].value = (1 << 16) | (3 << 0);
1114 else if (IS_GEN10(i965->intel.device_info))
1115 attrib_list[i].value = (1 << 16) | (3 << 0);
1117 } else if (entrypoint == VAEntrypointEncSliceLP) {
1118 /* Don't support B frame for low power mode */
1119 if (profile == VAProfileH264ConstrainedBaseline ||
1120 profile == VAProfileH264Main ||
1121 profile == VAProfileH264High)
1122 attrib_list[i].value = (1 << 0);
1124 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1125 } else if (entrypoint == VAEntrypointStats)
1126 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1130 case VAConfigAttribEncQualityRange:
1131 if (entrypoint == VAEntrypointEncSlice ||
1132 entrypoint == VAEntrypointEncSliceLP ||
1133 entrypoint == VAEntrypointFEI) {
1134 attrib_list[i].value = 1;
1135 if (profile == VAProfileH264ConstrainedBaseline ||
1136 profile == VAProfileH264Main ||
1137 profile == VAProfileH264High) {
1138 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1139 if (entrypoint == VAEntrypointEncSlice) {
1140 if (IS_GEN9(i965->intel.device_info) ||
1141 IS_GEN10(i965->intel.device_info))
1142 attrib_list[i].value = ENCODER_QUALITY_RANGE_AVC;
1144 } else if (profile == VAProfileHEVCMain ||
1145 profile == VAProfileHEVCMain10)
1146 attrib_list[i].value = ENCODER_QUALITY_RANGE_HEVC;
1147 else if (profile == VAProfileVP9Profile0 &&
1148 entrypoint == VAEntrypointEncSliceLP) {
1149 attrib_list[i].value = ENCODER_QUALITY_RANGE_VP9;
1153 } else if (entrypoint == VAEntrypointStats)
1154 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1157 case VAConfigAttribEncJPEG:
1158 if (entrypoint == VAEntrypointEncPicture) {
1159 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*) & (attrib_list[i].value);
1160 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1161 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1162 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1163 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1164 (configVal->bits).max_num_components = 3; // Only 3 components supported
1165 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1166 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1167 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1171 case VAConfigAttribDecSliceMode:
1172 if (entrypoint == VAEntrypointVLD)
1173 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1176 case VAConfigAttribEncROI:
1177 if (entrypoint == VAEntrypointEncSlice ||
1178 entrypoint == VAEntrypointEncSliceLP ||
1179 entrypoint == VAEntrypointFEI) {
1180 VAConfigAttribValEncROI *roi_config =
1181 (VAConfigAttribValEncROI *) & (attrib_list[i].value);
1183 if (profile == VAProfileH264ConstrainedBaseline ||
1184 profile == VAProfileH264Main ||
1185 profile == VAProfileH264High) {
1187 if (IS_GEN9(i965->intel.device_info) &&
1188 (entrypoint == VAEntrypointEncSlice ||
1189 entrypoint == VAEntrypointFEI ||
1190 entrypoint == VAEntrypointStats))
1191 attrib_list[i].value = 0;
1192 else if (IS_GEN10(i965->intel.device_info) &&
1193 (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointFEI))
1194 attrib_list[i].value = 0;
1196 if (entrypoint == VAEntrypointEncSliceLP) {
1197 roi_config->bits.num_roi_regions = 3;
1198 roi_config->bits.roi_rc_priority_support = 0;
1199 roi_config->bits.roi_rc_qp_delta_support = 0;
1201 roi_config->bits.num_roi_regions =
1202 I965_MAX_NUM_ROI_REGIONS;
1203 roi_config->bits.roi_rc_priority_support = 0;
1204 roi_config->bits.roi_rc_qp_delta_support = 1;
1207 } else if (profile == VAProfileHEVCMain ||
1208 profile == VAProfileHEVCMain10) {
1209 roi_config->bits.num_roi_regions =
1210 I965_MAX_NUM_ROI_REGIONS;
1211 roi_config->bits.roi_rc_priority_support = 1;
1212 roi_config->bits.roi_rc_qp_delta_support = 1;
1214 attrib_list[i].value = 0;
1220 case VAConfigAttribEncRateControlExt:
1221 if ((profile == VAProfileH264ConstrainedBaseline ||
1222 profile == VAProfileH264Main ||
1223 profile == VAProfileH264High) &&
1224 entrypoint == VAEntrypointEncSlice) {
1225 if (IS_GEN9(i965->intel.device_info))
1226 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1227 else if (IS_GEN10(i965->intel.device_info))
1228 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1230 VAConfigAttribValEncRateControlExt *val_config = (VAConfigAttribValEncRateControlExt *) & (attrib_list[i].value);
1232 val_config->bits.max_num_temporal_layers_minus1 = MAX_TEMPORAL_LAYERS - 1;
1233 val_config->bits.temporal_layer_bitrate_control_flag = 1;
1236 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1241 case VAConfigAttribEncMaxSlices:
1242 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1243 if (entrypoint == VAEntrypointEncSlice) {
1244 if ((profile == VAProfileH264ConstrainedBaseline ||
1245 profile == VAProfileH264Main ||
1246 profile == VAProfileH264High) ||
1247 profile == VAProfileH264StereoHigh ||
1248 profile == VAProfileH264MultiviewHigh) {
1249 attrib_list[i].value = I965_MAX_NUM_SLICE;
1250 } else if (profile == VAProfileHEVCMain ||
1251 profile == VAProfileHEVCMain10) {
1252 attrib_list[i].value = I965_MAX_NUM_SLICE;
1254 } else if (entrypoint == VAEntrypointEncSliceLP || entrypoint == VAEntrypointFEI) {
1255 if ((profile == VAProfileH264ConstrainedBaseline ||
1256 profile == VAProfileH264Main ||
1257 profile == VAProfileH264High) ||
1258 profile == VAProfileH264StereoHigh ||
1259 profile == VAProfileH264MultiviewHigh)
1260 attrib_list[i].value = I965_MAX_NUM_SLICE;
1265 case VAConfigAttribEncSliceStructure:
1266 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1267 if (entrypoint == VAEntrypointEncSlice) {
1268 if ((profile == VAProfileH264ConstrainedBaseline ||
1269 profile == VAProfileH264Main ||
1270 profile == VAProfileH264High) ||
1271 profile == VAProfileH264StereoHigh ||
1272 profile == VAProfileH264MultiviewHigh ||
1273 profile == VAProfileHEVCMain ||
1274 profile == VAProfileHEVCMain10) {
1275 attrib_list[i].value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1281 case VAConfigAttribFEIFunctionType:
1282 /* Supporing all possible modes of FEI */
1283 attrib_list[i].value = VA_FEI_FUNCTION_ENC |
1284 VA_FEI_FUNCTION_PAK | VA_FEI_FUNCTION_ENC_PAK;
1287 case VAConfigAttribFEIMVPredictors:
1288 attrib_list[i].value = 4;
1291 case VAConfigAttribStats:
1292 if (entrypoint == VAEntrypointStats) {
1293 VAConfigAttribValStats *configVal =
1294 (VAConfigAttribValStats*) & (attrib_list[i].value);
1295 (configVal->bits).max_num_past_references = STATS_MAX_NUM_PAST_REFS;
1296 (configVal->bits).max_num_future_references = STATS_MAX_NUM_FUTURE_REFS;
1297 (configVal->bits).num_outputs = STATS_MAX_NUM_OUTPUTS;
1298 (configVal->bits).interlaced = STATS_INTERLACED_SUPPORT;
1304 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1309 return VA_STATUS_SUCCESS;
1313 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1315 object_heap_free(heap, obj);
1318 static VAConfigAttrib *
1319 i965_lookup_config_attribute(struct object_config *obj_config,
1320 VAConfigAttribType type)
1324 for (i = 0; i < obj_config->num_attribs; i++) {
1325 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1326 if (attrib->type == type)
1333 i965_append_config_attribute(struct object_config *obj_config,
1334 const VAConfigAttrib *new_attrib)
1336 VAConfigAttrib *attrib;
1338 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1339 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1341 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1342 attrib->type = new_attrib->type;
1343 attrib->value = new_attrib->value;
1344 return VA_STATUS_SUCCESS;
1348 i965_ensure_config_attribute(struct object_config *obj_config,
1349 const VAConfigAttrib *new_attrib)
1351 VAConfigAttrib *attrib;
1353 /* Check for existing attributes */
1354 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1356 /* Update existing attribute */
1357 attrib->value = new_attrib->value;
1358 return VA_STATUS_SUCCESS;
1360 return i965_append_config_attribute(obj_config, new_attrib);
1364 i965_CreateConfig(VADriverContextP ctx,
1366 VAEntrypoint entrypoint,
1367 VAConfigAttrib *attrib_list,
1369 VAConfigID *config_id) /* out */
1371 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1372 struct object_config *obj_config;
1377 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1379 if (VA_STATUS_SUCCESS != vaStatus) {
1383 configID = NEW_CONFIG_ID();
1384 obj_config = CONFIG(configID);
1386 if (NULL == obj_config) {
1387 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1391 obj_config->profile = profile;
1392 obj_config->entrypoint = entrypoint;
1393 obj_config->num_attribs = 0;
1394 obj_config->wrapper_config = VA_INVALID_ID;
1396 for (i = 0; i < num_attribs; i++) {
1397 // add it later and ignore the user input for VAConfigAttribEncMaxSlices
1398 if (attrib_list[i].type == VAConfigAttribEncMaxSlices ||
1399 attrib_list[i].type == VAConfigAttribEncSliceStructure)
1401 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1402 if (vaStatus != VA_STATUS_SUCCESS)
1406 if (vaStatus == VA_STATUS_SUCCESS) {
1407 VAConfigAttrib attrib, *attrib_found;
1408 attrib.type = VAConfigAttribRTFormat;
1409 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1410 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1411 if (!attrib_found || !attrib_found->value)
1412 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1413 else if (!(attrib_found->value & attrib.value))
1414 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1418 if (vaStatus == VA_STATUS_SUCCESS) {
1419 VAConfigAttrib *attrib_found = i965_lookup_config_attribute(obj_config, VAConfigAttribRateControl);
1422 uint32_t rc_attribs = i965_get_rc_attributes(ctx, profile, entrypoint);
1424 if (!(attrib_found->value & rc_attribs))
1425 vaStatus = VA_STATUS_ERROR_INVALID_VALUE;
1429 if (vaStatus == VA_STATUS_SUCCESS) {
1430 VAConfigAttrib *attrib_found = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
1433 uint32_t enc_packed_attribs = i965_get_enc_packed_attributes(ctx, profile, entrypoint);
1435 if (!(attrib_found->value & enc_packed_attribs))
1436 vaStatus = VA_STATUS_ERROR_INVALID_VALUE;
1440 if (vaStatus == VA_STATUS_SUCCESS) {
1441 VAConfigAttrib attrib;
1442 attrib.type = VAConfigAttribEncMaxSlices;
1443 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1444 if (entrypoint == VAEntrypointEncSlice) {
1445 if ((profile == VAProfileH264ConstrainedBaseline ||
1446 profile == VAProfileH264Main ||
1447 profile == VAProfileH264High) ||
1448 profile == VAProfileH264StereoHigh ||
1449 profile == VAProfileH264MultiviewHigh) {
1450 attrib.value = I965_MAX_NUM_SLICE;
1451 } else if (profile == VAProfileHEVCMain ||
1452 profile == VAProfileHEVCMain10)
1453 attrib.value = I965_MAX_NUM_SLICE;
1454 } else if (entrypoint == VAEntrypointEncSliceLP || entrypoint == VAEntrypointFEI) {
1455 if ((profile == VAProfileH264ConstrainedBaseline ||
1456 profile == VAProfileH264Main ||
1457 profile == VAProfileH264High) ||
1458 profile == VAProfileH264StereoHigh ||
1459 profile == VAProfileH264MultiviewHigh)
1460 attrib.value = I965_MAX_NUM_SLICE;
1463 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1464 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1467 if (vaStatus == VA_STATUS_SUCCESS) {
1468 VAConfigAttrib attrib;
1469 attrib.type = VAConfigAttribEncSliceStructure;
1470 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1471 if (entrypoint == VAEntrypointEncSlice) {
1472 if ((profile == VAProfileH264ConstrainedBaseline ||
1473 profile == VAProfileH264Main ||
1474 profile == VAProfileH264High) ||
1475 profile == VAProfileH264StereoHigh ||
1476 profile == VAProfileH264MultiviewHigh) {
1477 attrib.value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1481 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1482 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1485 if (vaStatus == VA_STATUS_SUCCESS) {
1486 VAConfigAttrib *attrib_found;
1488 attrib_found = i965_lookup_config_attribute(obj_config, VAConfigAttribDecSliceMode);
1491 (entrypoint != VAEntrypointVLD ||
1492 attrib_found->value != VA_DEC_SLICE_MODE_NORMAL))
1493 vaStatus = VA_STATUS_ERROR_INVALID_VALUE;
1496 if ((vaStatus == VA_STATUS_SUCCESS) &&
1497 (profile == VAProfileVP9Profile0) &&
1498 (entrypoint == VAEntrypointVLD) &&
1499 !HAS_VP9_DECODING(i965)) {
1501 if (i965->wrapper_pdrvctx) {
1502 VAGenericID wrapper_config;
1504 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1505 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1506 entrypoint, attrib_list,
1507 num_attribs, &wrapper_config));
1509 if (vaStatus == VA_STATUS_SUCCESS)
1510 obj_config->wrapper_config = wrapper_config;
1514 /* Error recovery */
1515 if (VA_STATUS_SUCCESS != vaStatus) {
1516 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1518 *config_id = configID;
1525 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1527 struct i965_driver_data *i965 = i965_driver_data(ctx);
1528 struct object_config *obj_config = CONFIG(config_id);
1531 if (NULL == obj_config) {
1532 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1536 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1537 i965->wrapper_pdrvctx) {
1538 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1539 vaDestroyConfig(i965->wrapper_pdrvctx,
1540 obj_config->wrapper_config));
1541 obj_config->wrapper_config = VA_INVALID_ID;
1544 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1545 return VA_STATUS_SUCCESS;
1548 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1549 VAConfigID config_id,
1550 VAProfile *profile, /* out */
1551 VAEntrypoint *entrypoint, /* out */
1552 VAConfigAttrib *attrib_list, /* out */
1553 int *num_attribs) /* out */
1555 struct i965_driver_data *i965 = i965_driver_data(ctx);
1556 struct object_config *obj_config = CONFIG(config_id);
1557 VAStatus vaStatus = VA_STATUS_SUCCESS;
1560 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1561 *profile = obj_config->profile;
1562 *entrypoint = obj_config->entrypoint;
1563 *num_attribs = obj_config->num_attribs;
1565 for (i = 0; i < obj_config->num_attribs; i++) {
1566 attrib_list[i] = obj_config->attrib_list[i];
1573 i965_destroy_surface_storage(struct object_surface *obj_surface)
1578 dri_bo_unreference(obj_surface->bo);
1579 obj_surface->bo = NULL;
1581 if (obj_surface->free_private_data != NULL) {
1582 obj_surface->free_private_data(&obj_surface->private_data);
1583 obj_surface->private_data = NULL;
1588 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1590 struct object_surface *obj_surface = (struct object_surface *)obj;
1592 i965_destroy_surface_storage(obj_surface);
1593 object_heap_free(heap, obj);
1596 /* byte-per-pixel of the first plane */
1598 bpp_1stplane_by_fourcc(unsigned int fourcc)
1600 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1602 if (info && (info->flag & I_S))
1603 return info->bpp[0] / 8;
1609 i965_surface_native_memory(VADriverContextP ctx,
1610 struct object_surface *obj_surface,
1612 int expected_fourcc)
1614 struct i965_driver_data *i965 = i965_driver_data(ctx);
1615 int tiling = HAS_TILED_SURFACE(i965);
1617 if (!expected_fourcc)
1618 return VA_STATUS_SUCCESS;
1620 // todo, should we disable tiling for 422 format?
1621 if (expected_fourcc == VA_FOURCC_I420 ||
1622 expected_fourcc == VA_FOURCC_IYUV ||
1623 expected_fourcc == VA_FOURCC_I010 ||
1624 expected_fourcc == VA_FOURCC_YV12 ||
1625 expected_fourcc == VA_FOURCC_YV16)
1628 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1632 i965_suface_external_memory(VADriverContextP ctx,
1633 struct object_surface *obj_surface,
1634 int external_memory_type,
1635 VASurfaceAttribExternalBuffers *memory_attibute,
1638 struct i965_driver_data *i965 = i965_driver_data(ctx);
1639 unsigned int tiling, swizzle;
1641 if (!memory_attibute ||
1642 !memory_attibute->buffers ||
1643 index >= memory_attibute->num_buffers)
1644 return VA_STATUS_ERROR_INVALID_PARAMETER;
1646 obj_surface->size = memory_attibute->data_size;
1647 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1648 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1649 "gem flinked vaapi surface",
1650 memory_attibute->buffers[index]);
1651 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1652 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1653 memory_attibute->buffers[index],
1656 if (!obj_surface->bo)
1657 return VA_STATUS_ERROR_INVALID_PARAMETER;
1659 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
1661 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1662 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1663 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1665 obj_surface->fourcc = memory_attibute->pixel_format;
1666 obj_surface->width = memory_attibute->pitches[0];
1667 int bpp_1stplane = bpp_1stplane_by_fourcc(obj_surface->fourcc);
1668 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1669 ASSERT_RET(obj_surface->width >= obj_surface->orig_width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1671 if (memory_attibute->num_planes == 1)
1672 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1674 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1676 if (memory_attibute->num_planes > 1) {
1677 ASSERT_RET(obj_surface->height >= obj_surface->orig_height, VA_STATUS_ERROR_INVALID_PARAMETER);
1681 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1683 if (memory_attibute->num_planes > 1)
1684 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
1686 ASSERT_RET(IS_ALIGNED(obj_surface->width, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1688 if (memory_attibute->num_planes > 1)
1689 ASSERT_RET(IS_ALIGNED(obj_surface->height, i965->codec_info->min_linear_hpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1692 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1693 obj_surface->x_cr_offset = 0;
1694 if ((obj_surface->fourcc == VA_FOURCC_I420 ||
1695 obj_surface->fourcc == VA_FOURCC_IYUV ||
1696 obj_surface->fourcc == VA_FOURCC_I010 ||
1697 obj_surface->fourcc == VA_FOURCC_YV12 ||
1698 obj_surface->fourcc == VA_FOURCC_YV16) && tiling)
1699 return VA_STATUS_ERROR_INVALID_PARAMETER;
1701 switch (obj_surface->fourcc) {
1702 case VA_FOURCC_NV12:
1703 case VA_FOURCC_P010:
1704 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1705 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1707 obj_surface->subsampling = SUBSAMPLE_YUV420;
1708 obj_surface->y_cb_offset = obj_surface->height;
1709 obj_surface->y_cr_offset = obj_surface->height;
1710 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1711 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1712 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1714 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1716 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1720 case VA_FOURCC_YV12:
1721 case VA_FOURCC_IMC1:
1722 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1723 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1725 obj_surface->subsampling = SUBSAMPLE_YUV420;
1726 obj_surface->y_cr_offset = obj_surface->height;
1727 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1728 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1729 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1730 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1733 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1735 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1739 case VA_FOURCC_I420:
1740 case VA_FOURCC_IYUV:
1741 case VA_FOURCC_IMC3:
1742 case VA_FOURCC_I010:
1743 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1744 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1746 obj_surface->subsampling = SUBSAMPLE_YUV420;
1747 obj_surface->y_cb_offset = obj_surface->height;
1748 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1749 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1750 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1751 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1753 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1755 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1759 case VA_FOURCC_YUY2:
1760 case VA_FOURCC_UYVY:
1761 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1763 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1764 obj_surface->y_cb_offset = 0;
1765 obj_surface->y_cr_offset = 0;
1766 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1767 obj_surface->cb_cr_height = obj_surface->orig_height;
1768 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1772 case VA_FOURCC_RGBA:
1773 case VA_FOURCC_RGBX:
1774 case VA_FOURCC_BGRA:
1775 case VA_FOURCC_BGRX:
1776 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1778 obj_surface->subsampling = SUBSAMPLE_RGBX;
1779 obj_surface->y_cb_offset = 0;
1780 obj_surface->y_cr_offset = 0;
1781 obj_surface->cb_cr_width = 0;
1782 obj_surface->cb_cr_height = 0;
1783 obj_surface->cb_cr_pitch = 0;
1787 case VA_FOURCC_Y800: /* monochrome surface */
1788 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1790 obj_surface->subsampling = SUBSAMPLE_YUV400;
1791 obj_surface->y_cb_offset = 0;
1792 obj_surface->y_cr_offset = 0;
1793 obj_surface->cb_cr_width = 0;
1794 obj_surface->cb_cr_height = 0;
1795 obj_surface->cb_cr_pitch = 0;
1799 case VA_FOURCC_411P:
1800 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1801 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1803 obj_surface->subsampling = SUBSAMPLE_YUV411;
1804 obj_surface->y_cb_offset = obj_surface->height;
1805 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1806 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1807 obj_surface->cb_cr_height = obj_surface->orig_height;
1808 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1810 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1812 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1815 case VA_FOURCC_422H:
1816 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1817 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1819 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1820 obj_surface->y_cb_offset = obj_surface->height;
1821 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1822 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1823 obj_surface->cb_cr_height = obj_surface->orig_height;
1824 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1826 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1828 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1832 case VA_FOURCC_YV16:
1833 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1834 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1836 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1837 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1838 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1839 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1840 obj_surface->cb_cr_height = obj_surface->orig_height;
1841 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1842 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1846 case VA_FOURCC_422V:
1847 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1848 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1850 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1851 obj_surface->y_cb_offset = obj_surface->height;
1852 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1853 obj_surface->cb_cr_width = obj_surface->orig_width;
1854 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1855 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1857 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1859 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1863 case VA_FOURCC_444P:
1864 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1865 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1867 obj_surface->subsampling = SUBSAMPLE_YUV444;
1868 obj_surface->y_cb_offset = obj_surface->height;
1869 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1870 obj_surface->cb_cr_width = obj_surface->orig_width;
1871 obj_surface->cb_cr_height = obj_surface->orig_height;
1872 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1874 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1876 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1881 return VA_STATUS_ERROR_INVALID_PARAMETER;
1884 return VA_STATUS_SUCCESS;
1888 i965_CreateSurfaces2(
1889 VADriverContextP ctx,
1890 unsigned int format,
1892 unsigned int height,
1893 VASurfaceID *surfaces,
1894 unsigned int num_surfaces,
1895 VASurfaceAttrib *attrib_list,
1896 unsigned int num_attribs
1899 struct i965_driver_data *i965 = i965_driver_data(ctx);
1901 VAStatus vaStatus = VA_STATUS_SUCCESS;
1902 int expected_fourcc = 0;
1903 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1904 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1906 for (i = 0; i < num_attribs && attrib_list; i++) {
1907 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1908 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1909 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1910 expected_fourcc = attrib_list[i].value.value.i;
1913 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1914 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1916 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1918 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1919 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1920 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1921 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1922 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1923 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1926 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1927 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1928 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1929 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1933 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1934 * for post-processing (including color conversion) */
1935 if (VA_RT_FORMAT_YUV420 != format &&
1936 VA_RT_FORMAT_YUV420_10BPP != format &&
1937 VA_RT_FORMAT_YUV422 != format &&
1938 VA_RT_FORMAT_YUV444 != format &&
1939 VA_RT_FORMAT_YUV411 != format &&
1940 VA_RT_FORMAT_YUV400 != format &&
1941 VA_RT_FORMAT_RGB32 != format) {
1942 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1945 for (i = 0; i < num_surfaces; i++) {
1946 int surfaceID = NEW_SURFACE_ID();
1947 struct object_surface *obj_surface = SURFACE(surfaceID);
1949 if (NULL == obj_surface) {
1950 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1954 surfaces[i] = surfaceID;
1955 obj_surface->status = VASurfaceReady;
1956 obj_surface->orig_width = width;
1957 obj_surface->orig_height = height;
1958 obj_surface->user_disable_tiling = false;
1959 obj_surface->user_h_stride_set = false;
1960 obj_surface->user_v_stride_set = false;
1961 obj_surface->border_cleared = false;
1963 obj_surface->subpic_render_idx = 0;
1964 for (j = 0; j < I965_MAX_SUBPIC_SUM; j++) {
1965 obj_surface->subpic[j] = VA_INVALID_ID;
1966 obj_surface->obj_subpic[j] = NULL;
1969 assert(i965->codec_info->min_linear_wpitch);
1970 assert(i965->codec_info->min_linear_hpitch);
1971 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1972 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1973 obj_surface->flags = SURFACE_REFERENCED;
1974 obj_surface->fourcc = 0;
1975 obj_surface->expected_format = format;
1976 obj_surface->bo = NULL;
1977 obj_surface->locked_image_id = VA_INVALID_ID;
1978 obj_surface->derived_image_id = VA_INVALID_ID;
1979 obj_surface->private_data = NULL;
1980 obj_surface->free_private_data = NULL;
1981 obj_surface->subsampling = SUBSAMPLE_YUV420;
1983 obj_surface->wrapper_surface = VA_INVALID_ID;
1984 obj_surface->exported_primefd = -1;
1986 switch (memory_type) {
1987 case I965_SURFACE_MEM_NATIVE:
1988 if (memory_attibute) {
1989 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1990 obj_surface->user_disable_tiling = true;
1992 if (memory_attibute->pixel_format) {
1993 if (expected_fourcc)
1994 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1996 expected_fourcc = memory_attibute->pixel_format;
1998 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1999 if (memory_attibute->pitches[0]) {
2000 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
2001 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
2002 obj_surface->width = memory_attibute->pitches[0];
2003 obj_surface->user_h_stride_set = true;
2004 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
2005 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
2007 if (memory_attibute->offsets[1]) {
2008 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
2009 obj_surface->height = memory_attibute->offsets[1] / memory_attibute->pitches[0];
2010 obj_surface->user_v_stride_set = true;
2011 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
2012 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
2016 vaStatus = i965_surface_native_memory(ctx,
2022 case I965_SURFACE_MEM_GEM_FLINK:
2023 case I965_SURFACE_MEM_DRM_PRIME:
2024 vaStatus = i965_suface_external_memory(ctx,
2031 if (VA_STATUS_SUCCESS != vaStatus) {
2032 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
2037 /* Error recovery */
2038 if (VA_STATUS_SUCCESS != vaStatus) {
2039 /* surfaces[i-1] was the last successful allocation */
2041 struct object_surface *obj_surface = SURFACE(surfaces[i]);
2043 surfaces[i] = VA_INVALID_SURFACE;
2044 assert(obj_surface);
2045 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
2053 i965_CreateSurfaces(VADriverContextP ctx,
2058 VASurfaceID *surfaces) /* out */
2060 return i965_CreateSurfaces2(ctx,
2071 i965_DestroySurfaces(VADriverContextP ctx,
2072 VASurfaceID *surface_list,
2075 struct i965_driver_data *i965 = i965_driver_data(ctx);
2077 VAStatus va_status = VA_STATUS_SUCCESS;
2079 for (i = num_surfaces; i--;) {
2080 struct object_surface *obj_surface = SURFACE(surface_list[i]);
2082 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2084 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
2085 i965->wrapper_pdrvctx) {
2086 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2087 vaDestroySurfaces(i965->wrapper_pdrvctx,
2088 &(obj_surface->wrapper_surface),
2090 obj_surface->wrapper_surface = VA_INVALID_ID;
2092 if (obj_surface->exported_primefd >= 0) {
2093 close(obj_surface->exported_primefd);
2094 obj_surface->exported_primefd = -1;
2097 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
2104 i965_QueryImageFormats(VADriverContextP ctx,
2105 VAImageFormat *format_list, /* out */
2106 int *num_formats) /* out */
2110 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
2111 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
2113 format_list[n] = m->va_format;
2119 return VA_STATUS_SUCCESS;
2123 * Guess the format when the usage of a VA surface is unknown
2124 * 1. Without a valid context: YV12
2125 * 2. The current context is valid:
2126 * a) always NV12 on GEN6 and later
2127 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
2130 i965_guess_surface_format(VADriverContextP ctx,
2131 VASurfaceID surface,
2132 unsigned int *fourcc,
2133 unsigned int *is_tiled)
2135 struct i965_driver_data *i965 = i965_driver_data(ctx);
2136 struct object_context *obj_context = NULL;
2137 struct object_config *obj_config = NULL;
2139 *fourcc = VA_FOURCC_YV12;
2142 if (i965->current_context_id == VA_INVALID_ID)
2145 obj_context = CONTEXT(i965->current_context_id);
2150 obj_config = obj_context->obj_config;
2156 if (IS_GEN6(i965->intel.device_info) ||
2157 IS_GEN7(i965->intel.device_info) ||
2158 IS_GEN8(i965->intel.device_info) ||
2159 IS_GEN10(i965->intel.device_info) ||
2160 IS_GEN9(i965->intel.device_info)) {
2161 *fourcc = VA_FOURCC_NV12;
2166 switch (obj_config->profile) {
2167 case VAProfileMPEG2Simple:
2168 case VAProfileMPEG2Main:
2169 *fourcc = VA_FOURCC_I420;
2174 *fourcc = VA_FOURCC_NV12;
2181 i965_QuerySubpictureFormats(VADriverContextP ctx,
2182 VAImageFormat *format_list, /* out */
2183 unsigned int *flags, /* out */
2184 unsigned int *num_formats) /* out */
2188 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
2189 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
2191 format_list[n] = m->va_format;
2193 flags[n] = m->va_flags;
2199 return VA_STATUS_SUCCESS;
2203 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
2205 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
2207 object_heap_free(heap, obj);
2211 i965_CreateSubpicture(VADriverContextP ctx,
2213 VASubpictureID *subpicture) /* out */
2215 struct i965_driver_data *i965 = i965_driver_data(ctx);
2216 VASubpictureID subpicID = NEW_SUBPIC_ID()
2217 struct object_subpic * obj_subpic = SUBPIC(subpicID);
2220 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2222 struct object_image *obj_image = IMAGE(image);
2224 return VA_STATUS_ERROR_INVALID_IMAGE;
2226 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
2228 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
2230 *subpicture = subpicID;
2231 obj_subpic->image = image;
2232 obj_subpic->obj_image = obj_image;
2233 obj_subpic->format = m->format;
2234 obj_subpic->width = obj_image->image.width;
2235 obj_subpic->height = obj_image->image.height;
2236 obj_subpic->pitch = obj_image->image.pitches[0];
2237 obj_subpic->bo = obj_image->bo;
2238 obj_subpic->global_alpha = 1.0;
2240 return VA_STATUS_SUCCESS;
2244 i965_DestroySubpicture(VADriverContextP ctx,
2245 VASubpictureID subpicture)
2247 struct i965_driver_data *i965 = i965_driver_data(ctx);
2248 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2251 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2253 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2254 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
2255 return VA_STATUS_SUCCESS;
2259 i965_SetSubpictureImage(VADriverContextP ctx,
2260 VASubpictureID subpicture,
2264 return VA_STATUS_ERROR_UNIMPLEMENTED;
2268 i965_SetSubpictureChromakey(VADriverContextP ctx,
2269 VASubpictureID subpicture,
2270 unsigned int chromakey_min,
2271 unsigned int chromakey_max,
2272 unsigned int chromakey_mask)
2275 return VA_STATUS_ERROR_UNIMPLEMENTED;
2279 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
2280 VASubpictureID subpicture,
2283 struct i965_driver_data *i965 = i965_driver_data(ctx);
2284 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2286 if (global_alpha > 1.0 || global_alpha < 0.0) {
2287 return VA_STATUS_ERROR_INVALID_PARAMETER;
2291 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2293 obj_subpic->global_alpha = global_alpha;
2295 return VA_STATUS_SUCCESS;
2299 i965_AssociateSubpicture(VADriverContextP ctx,
2300 VASubpictureID subpicture,
2301 VASurfaceID *target_surfaces,
2303 short src_x, /* upper left offset in subpicture */
2305 unsigned short src_width,
2306 unsigned short src_height,
2307 short dest_x, /* upper left offset in surface */
2309 unsigned short dest_width,
2310 unsigned short dest_height,
2312 * whether to enable chroma-keying or global-alpha
2313 * see VA_SUBPICTURE_XXX values
2317 struct i965_driver_data *i965 = i965_driver_data(ctx);
2318 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2322 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2324 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2326 obj_subpic->src_rect.x = src_x;
2327 obj_subpic->src_rect.y = src_y;
2328 obj_subpic->src_rect.width = src_width;
2329 obj_subpic->src_rect.height = src_height;
2330 obj_subpic->dst_rect.x = dest_x;
2331 obj_subpic->dst_rect.y = dest_y;
2332 obj_subpic->dst_rect.width = dest_width;
2333 obj_subpic->dst_rect.height = dest_height;
2334 obj_subpic->flags = flags;
2336 for (i = 0; i < num_surfaces; i++) {
2337 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2339 return VA_STATUS_ERROR_INVALID_SURFACE;
2341 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2342 if (obj_surface->subpic[j] == VA_INVALID_ID) {
2343 assert(obj_surface->obj_subpic[j] == NULL);
2344 obj_surface->subpic[j] = subpicture;
2345 obj_surface->obj_subpic[j] = obj_subpic;
2350 if (j == I965_MAX_SUBPIC_SUM) {
2351 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2355 return VA_STATUS_SUCCESS;
2360 i965_DeassociateSubpicture(VADriverContextP ctx,
2361 VASubpictureID subpicture,
2362 VASurfaceID *target_surfaces,
2365 struct i965_driver_data *i965 = i965_driver_data(ctx);
2366 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2370 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2372 for (i = 0; i < num_surfaces; i++) {
2373 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2375 return VA_STATUS_ERROR_INVALID_SURFACE;
2377 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2378 if (obj_surface->subpic[j] == subpicture) {
2379 assert(obj_surface->obj_subpic[j] == obj_subpic);
2380 obj_surface->subpic[j] = VA_INVALID_ID;
2381 obj_surface->obj_subpic[j] = NULL;
2386 if (j == I965_MAX_SUBPIC_SUM) {
2387 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2390 return VA_STATUS_SUCCESS;
2394 i965_reference_buffer_store(struct buffer_store **ptr,
2395 struct buffer_store *buffer_store)
2397 assert(*ptr == NULL);
2400 buffer_store->ref_count++;
2401 *ptr = buffer_store;
2406 i965_release_buffer_store(struct buffer_store **ptr)
2408 struct buffer_store *buffer_store = *ptr;
2410 if (buffer_store == NULL)
2413 assert(buffer_store->bo || buffer_store->buffer);
2414 assert(!(buffer_store->bo && buffer_store->buffer));
2415 buffer_store->ref_count--;
2417 if (buffer_store->ref_count == 0) {
2418 dri_bo_unreference(buffer_store->bo);
2419 free(buffer_store->buffer);
2420 buffer_store->bo = NULL;
2421 buffer_store->buffer = NULL;
2429 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2431 struct object_context *obj_context = (struct object_context *)obj;
2434 if (obj_context->hw_context) {
2435 obj_context->hw_context->destroy(obj_context->hw_context);
2436 obj_context->hw_context = NULL;
2439 if (obj_context->codec_type == CODEC_PROC) {
2440 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2442 } else if (obj_context->codec_type == CODEC_ENC) {
2443 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2444 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2446 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2447 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2448 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2450 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2451 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2453 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2454 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2456 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2457 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2458 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2460 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2461 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2463 free(obj_context->codec_state.encode.slice_params_ext);
2464 if (obj_context->codec_state.encode.slice_rawdata_index) {
2465 free(obj_context->codec_state.encode.slice_rawdata_index);
2466 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2468 if (obj_context->codec_state.encode.slice_rawdata_count) {
2469 free(obj_context->codec_state.encode.slice_rawdata_count);
2470 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2473 if (obj_context->codec_state.encode.slice_header_index) {
2474 free(obj_context->codec_state.encode.slice_header_index);
2475 obj_context->codec_state.encode.slice_header_index = NULL;
2478 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2479 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2480 free(obj_context->codec_state.encode.packed_header_params_ext);
2482 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2483 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2484 free(obj_context->codec_state.encode.packed_header_data_ext);
2486 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2487 } else if (obj_context->codec_type == CODEC_PREENC) {
2488 /* using the same encode codec_state for preenc too,
2489 * since both sharig all most same code except in few places */
2490 i965_release_buffer_store(&obj_context->codec_state.encode.stat_param_ext);
2492 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2493 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2495 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2496 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2497 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2498 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2500 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2501 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2503 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2504 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2506 free(obj_context->codec_state.decode.slice_params);
2507 free(obj_context->codec_state.decode.slice_datas);
2510 free(obj_context->render_targets);
2511 object_heap_free(heap, obj);
2515 max_resolution(struct i965_driver_data *i965,
2516 struct object_config *obj_config,
2520 if (i965->codec_info->max_resolution) {
2521 i965->codec_info->max_resolution(i965, obj_config, w, h);
2523 *w = i965->codec_info->max_width;
2524 *h = i965->codec_info->max_height;
2529 i965_CreateContext(VADriverContextP ctx,
2530 VAConfigID config_id,
2534 VASurfaceID *render_targets,
2535 int num_render_targets,
2536 VAContextID *context) /* out */
2538 struct i965_driver_data *i965 = i965_driver_data(ctx);
2539 struct object_config *obj_config = CONFIG(config_id);
2540 struct object_context *obj_context = NULL;
2541 VAConfigAttrib *attrib;
2542 VAStatus vaStatus = VA_STATUS_SUCCESS;
2547 int min_width_height = I965_MIN_CODEC_ENC_RESOLUTION_WIDTH_HEIGHT;
2549 if (NULL == obj_config) {
2550 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2554 if (obj_config->profile == VAProfileJPEGBaseline)
2555 min_width_height = 1;
2557 max_resolution(i965, obj_config, &max_width, &max_height);
2559 if (picture_width > max_width ||
2560 picture_height > max_height) {
2561 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2565 if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2566 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2567 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
2568 (VAEntrypointFEI == obj_config->entrypoint)) {
2569 if (picture_width < min_width_height ||
2570 picture_height < min_width_height) {
2571 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2577 /* Validate picture dimensions */
2578 contextID = NEW_CONTEXT_ID();
2579 obj_context = CONTEXT(contextID);
2581 if (NULL == obj_context) {
2582 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2586 *context = contextID;
2587 obj_context->flags = flag;
2588 obj_context->context_id = contextID;
2589 obj_context->obj_config = obj_config;
2590 obj_context->picture_width = picture_width;
2591 obj_context->picture_height = picture_height;
2592 obj_context->num_render_targets = num_render_targets;
2593 obj_context->render_targets =
2594 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2595 obj_context->hw_context = NULL;
2596 obj_context->wrapper_context = VA_INVALID_ID;
2598 if (!obj_context->render_targets)
2599 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2601 for (i = 0; i < num_render_targets; i++) {
2602 if (NULL == SURFACE(render_targets[i])) {
2603 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2607 obj_context->render_targets[i] = render_targets[i];
2610 if (VA_STATUS_SUCCESS == vaStatus) {
2611 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2612 obj_context->codec_type = CODEC_PROC;
2613 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2614 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2615 assert(i965->codec_info->proc_hw_context_init);
2616 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2617 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2618 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2619 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
2620 (VAEntrypointFEI == obj_config->entrypoint)) {
2621 VAConfigAttrib *packed_attrib;
2622 obj_context->codec_type = CODEC_ENC;
2623 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2624 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2625 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2626 obj_context->codec_state.encode.packed_header_params_ext =
2627 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2628 sizeof(struct buffer_store *));
2630 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2631 obj_context->codec_state.encode.packed_header_data_ext =
2632 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2633 sizeof(struct buffer_store *));
2635 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2636 obj_context->codec_state.encode.slice_rawdata_index =
2637 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2638 obj_context->codec_state.encode.slice_rawdata_count =
2639 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2641 obj_context->codec_state.encode.slice_header_index =
2642 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2644 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2646 obj_context->codec_state.encode.slice_index = 0;
2647 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2648 if (packed_attrib) {
2649 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2650 if (obj_config->profile == VAProfileVP9Profile0)
2651 obj_context->codec_state.encode.packed_header_flag =
2652 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2654 /* use the default value. SPS/PPS/RAWDATA is passed from user
2655 * while Slice_header data is generated by driver.
2657 obj_context->codec_state.encode.packed_header_flag =
2658 VA_ENC_PACKED_HEADER_SEQUENCE |
2659 VA_ENC_PACKED_HEADER_PICTURE |
2660 VA_ENC_PACKED_HEADER_RAW_DATA;
2662 /* it is not used for VP9 */
2663 if (obj_config->profile == VAProfileVP9Profile0)
2664 obj_context->codec_state.encode.packed_header_flag = 0;
2666 assert(i965->codec_info->enc_hw_context_init);
2667 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2668 } else if (VAEntrypointStats == obj_config->entrypoint) {
2669 /* PreEnc sharing the ENC structures */
2670 obj_context->codec_type = CODEC_PREENC;
2671 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2672 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2673 assert(i965->codec_info->enc_hw_context_init);
2674 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2676 obj_context->codec_type = CODEC_DEC;
2677 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2678 obj_context->codec_state.decode.current_render_target = -1;
2679 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2680 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2681 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2682 sizeof(*obj_context->codec_state.decode.slice_params));
2683 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2684 sizeof(*obj_context->codec_state.decode.slice_datas));
2686 assert(i965->codec_info->dec_hw_context_init);
2687 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2691 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2693 return VA_STATUS_ERROR_INVALID_CONFIG;
2694 obj_context->codec_state.base.chroma_formats = attrib->value;
2696 if (obj_config->wrapper_config != VA_INVALID_ID) {
2697 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2698 * So it won't check i965->wrapper_pdrvctx again.
2699 * Fixme if it is incorrect.
2701 VAGenericID wrapper_context;
2704 * The render_surface is not passed when calling
2706 * If it is needed, we must get the wrapped surface
2707 * for the corresponding Surface_list.
2708 * So the wrapped surface conversion is deferred.
2710 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2711 vaCreateContext(i965->wrapper_pdrvctx,
2712 obj_config->wrapper_config,
2713 picture_width, picture_height,
2717 if (vaStatus == VA_STATUS_SUCCESS)
2718 obj_context->wrapper_context = wrapper_context;
2721 /* Error recovery */
2722 if (VA_STATUS_SUCCESS != vaStatus) {
2723 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2726 i965->current_context_id = contextID;
2732 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2734 struct i965_driver_data *i965 = i965_driver_data(ctx);
2735 struct object_context *obj_context = CONTEXT(context);
2736 VAStatus va_status = VA_STATUS_SUCCESS;
2738 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2740 if (i965->current_context_id == context)
2741 i965->current_context_id = VA_INVALID_ID;
2743 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2744 i965->wrapper_pdrvctx) {
2745 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2746 vaDestroyContext(i965->wrapper_pdrvctx,
2747 obj_context->wrapper_context));
2749 obj_context->wrapper_context = VA_INVALID_ID;
2752 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2758 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2760 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2762 assert(obj_buffer->buffer_store);
2763 i965_release_buffer_store(&obj_buffer->buffer_store);
2764 object_heap_free(heap, obj);
2768 i965_create_buffer_internal(VADriverContextP ctx,
2769 VAContextID context,
2772 unsigned int num_elements,
2777 struct i965_driver_data *i965 = i965_driver_data(ctx);
2778 struct object_buffer *obj_buffer = NULL;
2779 struct buffer_store *buffer_store = NULL;
2781 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2782 struct object_context *obj_context = CONTEXT(context);
2783 int wrapper_flag = 0;
2787 case VAPictureParameterBufferType:
2788 case VAIQMatrixBufferType:
2789 case VAQMatrixBufferType:
2790 case VABitPlaneBufferType:
2791 case VASliceGroupMapBufferType:
2792 case VASliceParameterBufferType:
2793 case VASliceDataBufferType:
2794 case VAMacroblockParameterBufferType:
2795 case VAResidualDataBufferType:
2796 case VADeblockingParameterBufferType:
2797 case VAImageBufferType:
2798 case VAEncCodedBufferType:
2799 case VAEncSequenceParameterBufferType:
2800 case VAEncPictureParameterBufferType:
2801 case VAEncSliceParameterBufferType:
2802 case VAEncPackedHeaderParameterBufferType:
2803 case VAEncPackedHeaderDataBufferType:
2804 case VAEncMiscParameterBufferType:
2805 case VAProcPipelineParameterBufferType:
2806 case VAProcFilterParameterBufferType:
2807 case VAHuffmanTableBufferType:
2808 case VAProbabilityBufferType:
2809 case VAEncMacroblockMapBufferType:
2810 case VAEncQPBufferType:
2811 case VAEncFEIMVBufferType:
2812 case VAEncFEIMBCodeBufferType:
2813 case VAEncFEIDistortionBufferType:
2814 case VAEncFEIMBControlBufferType:
2815 case VAEncFEIMVPredictorBufferType:
2816 case VAStatsStatisticsParameterBufferType:
2817 case VAStatsStatisticsBufferType:
2818 case VAStatsStatisticsBottomFieldBufferType:
2819 case VAStatsMVBufferType:
2820 case VAStatsMVPredictorBufferType:
2826 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2829 bufferID = NEW_BUFFER_ID();
2830 obj_buffer = BUFFER(bufferID);
2832 if (NULL == obj_buffer) {
2833 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2836 if (type == VAEncCodedBufferType) {
2837 size += I965_CODEDBUFFER_HEADER_SIZE;
2838 size += 0x1000; /* for upper bound check */
2841 obj_buffer->max_num_elements = num_elements;
2842 obj_buffer->num_elements = num_elements;
2843 obj_buffer->size_element = size;
2844 obj_buffer->type = type;
2845 obj_buffer->export_refcount = 0;
2846 obj_buffer->buffer_store = NULL;
2847 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2848 obj_buffer->context_id = context;
2850 buffer_store = calloc(1, sizeof(struct buffer_store));
2851 assert(buffer_store);
2852 buffer_store->ref_count = 1;
2855 (obj_context->wrapper_context != VA_INVALID_ID) &&
2856 i965->wrapper_pdrvctx) {
2857 VAGenericID wrapper_buffer;
2858 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2860 CALL_VTABLE(pdrvctx, vaStatus,
2861 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2862 data, &wrapper_buffer));
2863 if (vaStatus == VA_STATUS_SUCCESS) {
2864 obj_buffer->wrapper_buffer = wrapper_buffer;
2872 if (store_bo != NULL) {
2873 buffer_store->bo = store_bo;
2874 dri_bo_reference(buffer_store->bo);
2876 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2877 if (data && !wrapper_flag)
2878 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2879 } else if (type == VASliceDataBufferType ||
2880 type == VAImageBufferType ||
2881 type == VAEncCodedBufferType ||
2882 type == VAEncMacroblockMapBufferType ||
2883 type == VAProbabilityBufferType ||
2884 type == VAEncQPBufferType ||
2885 type == VAEncFEIMVBufferType ||
2886 type == VAEncFEIMBCodeBufferType ||
2887 type == VAEncFEIDistortionBufferType ||
2888 type == VAEncFEIMBControlBufferType ||
2889 type == VAEncFEIMVPredictorBufferType ||
2890 type == VAEncFEIMVPredictorBufferType ||
2891 type == VAStatsStatisticsBufferType ||
2892 type == VAStatsStatisticsBottomFieldBufferType ||
2893 type == VAStatsMVBufferType ||
2894 type == VAStatsMVPredictorBufferType) {
2896 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2897 * So it is enough to allocate one 64 byte bo
2900 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2903 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2905 size * num_elements, 64);
2906 assert(buffer_store->bo);
2908 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2909 * In fact it can be skipped. But it is still allocated and it is
2910 * only to follow the normal flowchart of buffer_allocation/release.
2912 if (!wrapper_flag) {
2913 if (type == VAEncCodedBufferType) {
2914 struct i965_coded_buffer_segment *coded_buffer_segment;
2916 dri_bo_map(buffer_store->bo, 1);
2917 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2918 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2919 coded_buffer_segment->base.bit_offset = 0;
2920 coded_buffer_segment->base.status = 0;
2921 coded_buffer_segment->base.buf = NULL;
2922 coded_buffer_segment->base.next = NULL;
2923 coded_buffer_segment->mapped = 0;
2924 coded_buffer_segment->codec = 0;
2925 coded_buffer_segment->status_support = 0;
2926 dri_bo_unmap(buffer_store->bo);
2928 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2935 if (type == VAEncPackedHeaderDataBufferType) {
2936 msize = ALIGN(size, 4);
2939 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2941 buffer_store->buffer = malloc(4);
2943 buffer_store->buffer = malloc(msize * num_elements);
2944 assert(buffer_store->buffer);
2946 if (!wrapper_flag) {
2948 memcpy(buffer_store->buffer, data, size * num_elements);
2950 memset(buffer_store->buffer, 0, size * num_elements);
2954 buffer_store->num_elements = obj_buffer->num_elements;
2955 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2956 i965_release_buffer_store(&buffer_store);
2959 return VA_STATUS_SUCCESS;
2963 i965_CreateBuffer(VADriverContextP ctx,
2964 VAContextID context, /* in */
2965 VABufferType type, /* in */
2966 unsigned int size, /* in */
2967 unsigned int num_elements, /* in */
2968 void *data, /* in */
2969 VABufferID *buf_id) /* out */
2971 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2976 i965_BufferSetNumElements(VADriverContextP ctx,
2977 VABufferID buf_id, /* in */
2978 unsigned int num_elements) /* in */
2980 struct i965_driver_data *i965 = i965_driver_data(ctx);
2981 struct object_buffer *obj_buffer = BUFFER(buf_id);
2982 VAStatus vaStatus = VA_STATUS_SUCCESS;
2984 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2986 /* When the wrapper_buffer exists, it will wrapper to the
2987 * buffer allocated from backend driver.
2989 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2990 i965->wrapper_pdrvctx) {
2991 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2993 CALL_VTABLE(pdrvctx, vaStatus,
2994 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2999 if (num_elements > obj_buffer->max_num_elements) {
3000 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
3002 obj_buffer->num_elements = num_elements;
3003 if (obj_buffer->buffer_store != NULL) {
3004 obj_buffer->buffer_store->num_elements = num_elements;
3012 i965_MapBuffer(VADriverContextP ctx,
3013 VABufferID buf_id, /* in */
3014 void **pbuf) /* out */
3016 struct i965_driver_data *i965 = i965_driver_data(ctx);
3017 struct object_buffer *obj_buffer = BUFFER(buf_id);
3018 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3019 struct object_context *obj_context;
3021 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
3023 obj_context = CONTEXT(obj_buffer->context_id);
3025 /* When the wrapper_buffer exists, it will wrapper to the
3026 * buffer allocated from backend driver.
3028 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
3029 i965->wrapper_pdrvctx) {
3030 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
3032 CALL_VTABLE(pdrvctx, vaStatus,
3033 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
3037 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3038 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
3040 if (obj_buffer->export_refcount > 0)
3041 return VA_STATUS_ERROR_INVALID_BUFFER;
3043 if (NULL != obj_buffer->buffer_store->bo) {
3044 unsigned int tiling, swizzle;
3046 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
3048 if (tiling != I915_TILING_NONE)
3049 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
3051 dri_bo_map(obj_buffer->buffer_store->bo, 1);
3053 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
3054 *pbuf = obj_buffer->buffer_store->bo->virtual;
3055 vaStatus = VA_STATUS_SUCCESS;
3057 if (obj_buffer->type == VAEncCodedBufferType) {
3059 unsigned char *buffer = NULL;
3060 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
3061 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
3063 if (!coded_buffer_segment->mapped) {
3064 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
3066 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
3069 obj_context->hw_context &&
3070 obj_context->hw_context->get_status &&
3071 coded_buffer_segment->status_support) {
3072 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
3074 if (coded_buffer_segment->codec == CODEC_H264 ||
3075 coded_buffer_segment->codec == CODEC_H264_MVC) {
3076 delimiter0 = H264_DELIMITER0;
3077 delimiter1 = H264_DELIMITER1;
3078 delimiter2 = H264_DELIMITER2;
3079 delimiter3 = H264_DELIMITER3;
3080 delimiter4 = H264_DELIMITER4;
3081 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
3082 delimiter0 = MPEG2_DELIMITER0;
3083 delimiter1 = MPEG2_DELIMITER1;
3084 delimiter2 = MPEG2_DELIMITER2;
3085 delimiter3 = MPEG2_DELIMITER3;
3086 delimiter4 = MPEG2_DELIMITER4;
3087 } else if (coded_buffer_segment->codec == CODEC_JPEG) {
3088 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
3091 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
3092 delimiter0 = HEVC_DELIMITER0;
3093 delimiter1 = HEVC_DELIMITER1;
3094 delimiter2 = HEVC_DELIMITER2;
3095 delimiter3 = HEVC_DELIMITER3;
3096 delimiter4 = HEVC_DELIMITER4;
3097 } else if (coded_buffer_segment->codec != CODEC_VP8) {
3098 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
3101 if (coded_buffer_segment->codec == CODEC_JPEG) {
3102 for (i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
3103 if ((buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
3107 coded_buffer_segment->base.size = i + 2;
3108 } else if (coded_buffer_segment->codec != CODEC_VP8) {
3109 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
3110 so it don't need to traversal the coded buffer */
3111 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
3112 if ((buffer[i] == delimiter0) &&
3113 (buffer[i + 1] == delimiter1) &&
3114 (buffer[i + 2] == delimiter2) &&
3115 (buffer[i + 3] == delimiter3) &&
3116 (buffer[i + 4] == delimiter4))
3120 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
3121 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
3123 coded_buffer_segment->base.size = i;
3126 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
3127 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
3130 vaStatus = VA_STATUS_SUCCESS;
3133 coded_buffer_segment->mapped = 1;
3135 assert(coded_buffer_segment->base.buf);
3136 vaStatus = VA_STATUS_SUCCESS;
3139 } else if (NULL != obj_buffer->buffer_store->buffer) {
3140 *pbuf = obj_buffer->buffer_store->buffer;
3141 vaStatus = VA_STATUS_SUCCESS;
3148 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
3150 struct i965_driver_data *i965 = i965_driver_data(ctx);
3151 struct object_buffer *obj_buffer = BUFFER(buf_id);
3152 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3154 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
3155 return VA_STATUS_ERROR_INVALID_BUFFER;
3157 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
3158 /* When the wrapper_buffer exists, it will wrapper to the
3159 * buffer allocated from backend driver.
3161 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
3162 i965->wrapper_pdrvctx) {
3163 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
3165 CALL_VTABLE(pdrvctx, vaStatus,
3166 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3170 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
3171 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
3173 if (NULL != obj_buffer->buffer_store->bo) {
3174 unsigned int tiling, swizzle;
3176 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
3178 if (tiling != I915_TILING_NONE)
3179 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
3181 dri_bo_unmap(obj_buffer->buffer_store->bo);
3183 vaStatus = VA_STATUS_SUCCESS;
3184 } else if (NULL != obj_buffer->buffer_store->buffer) {
3186 vaStatus = VA_STATUS_SUCCESS;
3193 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
3195 struct i965_driver_data *i965 = i965_driver_data(ctx);
3196 struct object_buffer *obj_buffer = BUFFER(buffer_id);
3197 VAStatus va_status = VA_STATUS_SUCCESS;
3199 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3201 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
3202 i965->wrapper_pdrvctx) {
3203 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
3204 vaDestroyBuffer(i965->wrapper_pdrvctx,
3205 obj_buffer->wrapper_buffer));
3206 obj_buffer->wrapper_buffer = VA_INVALID_ID;
3209 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
3215 i965_BeginPicture(VADriverContextP ctx,
3216 VAContextID context,
3217 VASurfaceID render_target)
3219 struct i965_driver_data *i965 = i965_driver_data(ctx);
3220 struct object_context *obj_context = CONTEXT(context);
3221 struct object_surface *obj_surface = SURFACE(render_target);
3222 struct object_config *obj_config;
3223 VAStatus vaStatus = VA_STATUS_SUCCESS;
3226 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3227 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3228 obj_config = obj_context->obj_config;
3229 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3231 if (is_surface_busy(i965, obj_surface))
3232 return VA_STATUS_ERROR_SURFACE_BUSY;
3234 if (obj_context->codec_type == CODEC_PROC) {
3235 obj_context->codec_state.proc.current_render_target = render_target;
3236 } else if (obj_context->codec_type == CODEC_ENC) {
3238 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
3240 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
3241 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
3243 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
3244 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
3246 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
3247 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
3249 obj_context->codec_state.encode.num_slice_params_ext = 0;
3250 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
3251 obj_context->codec_state.encode.last_packed_header_type = 0;
3252 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
3253 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3254 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
3255 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3256 memset(obj_context->codec_state.encode.slice_header_index, 0,
3257 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3259 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
3260 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
3261 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
3262 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
3263 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
3264 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
3265 obj_context->codec_state.encode.slice_index = 0;
3266 obj_context->codec_state.encode.vps_sps_seq_index = 0;
3268 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
3269 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
3270 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
3272 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
3273 } else if (obj_context->codec_type == CODEC_PREENC) {
3274 /* PreEnc sharing the ENC structures */
3275 i965_release_buffer_store(&obj_context->codec_state.encode.stat_param_ext);
3276 obj_context->codec_state.encode.current_render_target = render_target;
3278 obj_context->codec_state.decode.current_render_target = render_target;
3279 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
3280 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
3281 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
3282 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
3284 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
3285 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
3286 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
3289 obj_context->codec_state.decode.num_slice_params = 0;
3290 obj_context->codec_state.decode.num_slice_datas = 0;
3292 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
3293 i965->wrapper_pdrvctx) {
3294 if (obj_surface->wrapper_surface == VA_INVALID_ID)
3295 vaStatus = i965_surface_wrapper(ctx, render_target);
3297 if (vaStatus != VA_STATUS_SUCCESS)
3300 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
3301 vaBeginPicture(i965->wrapper_pdrvctx,
3302 obj_context->wrapper_context,
3303 obj_surface->wrapper_surface));
3310 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
3312 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
3314 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3315 struct object_context *obj_context, \
3316 struct object_buffer *obj_buffer) \
3318 struct category##_state *category = &obj_context->codec_state.category; \
3319 i965_release_buffer_store(&category->member); \
3320 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
3321 return VA_STATUS_SUCCESS; \
3324 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
3326 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3327 struct object_context *obj_context, \
3328 struct object_buffer *obj_buffer) \
3330 struct category##_state *category = &obj_context->codec_state.category; \
3331 if (category->num_##member == category->max_##member) { \
3332 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
3333 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
3334 category->max_##member += NUM_SLICES; \
3336 i965_release_buffer_store(&category->member[category->num_##member]); \
3337 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
3338 category->num_##member++; \
3339 return VA_STATUS_SUCCESS; \
3342 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
3344 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
3345 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3346 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
3347 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
3348 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3349 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
3351 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
3352 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3353 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
3357 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
3358 VABufferID *buffers,
3361 struct i965_driver_data *i965 = i965_driver_data(ctx);
3362 VAStatus vaStatus = VA_STATUS_SUCCESS;
3364 VADecPictureParameterBufferVP9 *pVp9PicParams;
3365 VADriverContextP pdrvctx;
3366 struct object_buffer *obj_buffer;
3368 pdrvctx = i965->wrapper_pdrvctx;
3369 /* do the conversion of VADecPictureParameterBufferVP9 */
3370 for (i = 0; i < num_buffers; i++) {
3371 obj_buffer = BUFFER(buffers[i]);
3376 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
3379 if (obj_buffer->type == VAPictureParameterBufferType) {
3381 VASurfaceID surface_id;
3382 struct object_surface *obj_surface;
3384 pdrvctx = i965->wrapper_pdrvctx;
3386 CALL_VTABLE(pdrvctx, vaStatus,
3387 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
3388 (void **)(&pVp9PicParams)));
3390 if (vaStatus != VA_STATUS_SUCCESS)
3393 for (j = 0; j < 8; j++) {
3394 surface_id = pVp9PicParams->reference_frames[j];
3395 obj_surface = SURFACE(surface_id);
3400 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
3401 vaStatus = i965_surface_wrapper(ctx, surface_id);
3402 if (vaStatus != VA_STATUS_SUCCESS) {
3403 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
3404 obj_buffer->wrapper_buffer);
3409 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
3411 CALL_VTABLE(pdrvctx, vaStatus,
3412 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3417 return VA_STATUS_SUCCESS;
3424 i965_decoder_wrapper_picture(VADriverContextP ctx,
3425 VAContextID context,
3426 VABufferID *buffers,
3429 struct i965_driver_data *i965 = i965_driver_data(ctx);
3430 struct object_context *obj_context = CONTEXT(context);
3431 VAStatus vaStatus = VA_STATUS_SUCCESS;
3433 VADriverContextP pdrvctx;
3434 struct object_buffer *obj_buffer;
3436 if (obj_context == NULL)
3437 return VA_STATUS_ERROR_INVALID_CONTEXT;
3439 /* When it is not wrapped context, continue the normal flowchart */
3440 if (obj_context->wrapper_context == VA_INVALID_ID)
3443 if (obj_context->obj_config &&
3444 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3445 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3447 return VA_STATUS_ERROR_INVALID_PARAMETER;
3449 pdrvctx = i965->wrapper_pdrvctx;
3451 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3452 obj_buffer = BUFFER(buffers[i]);
3457 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3458 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3462 CALL_VTABLE(pdrvctx, vaStatus,
3463 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3464 &(obj_buffer->wrapper_buffer), 1));
3470 i965_decoder_render_picture(VADriverContextP ctx,
3471 VAContextID context,
3472 VABufferID *buffers,
3475 struct i965_driver_data *i965 = i965_driver_data(ctx);
3476 struct object_context *obj_context = CONTEXT(context);
3477 VAStatus vaStatus = VA_STATUS_SUCCESS;
3480 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3482 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3483 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3486 return VA_STATUS_ERROR_INVALID_BUFFER;
3488 switch (obj_buffer->type) {
3489 case VAPictureParameterBufferType:
3490 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3493 case VAIQMatrixBufferType:
3494 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3497 case VABitPlaneBufferType:
3498 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3501 case VASliceParameterBufferType:
3502 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3505 case VASliceDataBufferType:
3506 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3509 case VAHuffmanTableBufferType:
3510 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3513 case VAProbabilityBufferType:
3514 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3518 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3523 if ((vaStatus == VA_STATUS_SUCCESS) &&
3524 (obj_context->wrapper_context != VA_INVALID_ID))
3525 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3530 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3532 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3533 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3534 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3535 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3536 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3537 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3538 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3539 /* extended buffer */
3540 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3541 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3542 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3543 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(statistics_parameter_ext, stat_param_ext)
3545 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3546 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3547 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3549 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3550 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3553 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3554 struct object_context *obj_context,
3555 struct object_buffer *obj_buffer,
3558 struct encode_state *encode = &obj_context->codec_state.encode;
3560 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3561 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3562 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3563 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3565 return VA_STATUS_SUCCESS;
3569 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3570 struct object_context *obj_context,
3571 struct object_buffer *obj_buffer,
3574 struct encode_state *encode = &obj_context->codec_state.encode;
3576 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3577 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3578 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3579 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3581 return VA_STATUS_SUCCESS;
3585 i965_encoder_get_misc_paramerter_buffer_index(VADriverContextP ctx,
3586 struct encode_state *encode,
3587 VAEncMiscParameterBuffer *misc_param)
3591 if (!encode->has_layers)
3594 if (misc_param->type == VAEncMiscParameterTypeRateControl) {
3595 VAEncMiscParameterRateControl *misc_rate_control = (VAEncMiscParameterRateControl *)misc_param->data;
3597 index = misc_rate_control->rc_flags.bits.temporal_id;
3598 } else if (misc_param->type == VAEncMiscParameterTypeFrameRate) {
3599 VAEncMiscParameterFrameRate *misc_frame_rate = (VAEncMiscParameterFrameRate *)misc_param->data;
3601 index = misc_frame_rate->framerate_flags.bits.temporal_id;
3608 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3609 struct object_context *obj_context,
3610 struct object_buffer *obj_buffer)
3612 struct encode_state *encode = &obj_context->codec_state.encode;
3613 VAEncMiscParameterBuffer *param = NULL;
3616 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3617 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3619 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3621 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3622 return VA_STATUS_ERROR_INVALID_PARAMETER;
3624 if (param->type == VAEncMiscParameterTypeTemporalLayerStructure)
3625 encode->has_layers = 1;
3627 index = i965_encoder_get_misc_paramerter_buffer_index(ctx, encode, param);
3629 if (index >= ARRAY_ELEMS(encode->misc_param[0]))
3630 return VA_STATUS_ERROR_INVALID_PARAMETER;
3632 i965_release_buffer_store(&encode->misc_param[param->type][index]);
3633 i965_reference_buffer_store(&encode->misc_param[param->type][index], obj_buffer->buffer_store);
3635 return VA_STATUS_SUCCESS;
3639 i965_encoder_render_picture(VADriverContextP ctx,
3640 VAContextID context,
3641 VABufferID *buffers,
3644 struct i965_driver_data *i965 = i965_driver_data(ctx);
3645 struct object_context *obj_context = CONTEXT(context);
3646 struct object_config *obj_config;
3647 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3648 struct encode_state *encode;
3651 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3652 obj_config = obj_context->obj_config;
3653 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3655 encode = &obj_context->codec_state.encode;
3656 for (i = 0; i < num_buffers; i++) {
3657 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3660 return VA_STATUS_ERROR_INVALID_BUFFER;
3662 switch (obj_buffer->type) {
3663 case VAQMatrixBufferType:
3664 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3667 case VAIQMatrixBufferType:
3668 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3671 case VAEncSequenceParameterBufferType:
3672 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3675 case VAEncPictureParameterBufferType:
3676 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3679 case VAHuffmanTableBufferType:
3680 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3683 case VAEncSliceParameterBufferType:
3684 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3685 if (vaStatus == VA_STATUS_SUCCESS) {
3686 /* When the max number of slices is updated, it also needs
3687 * to reallocate the arrays that is used to store
3688 * the packed data index/count for the slice
3690 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3691 encode->slice_index++;
3693 if (encode->slice_index == encode->max_slice_num) {
3694 int slice_num = encode->max_slice_num;
3695 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3696 (slice_num + NUM_SLICES) * sizeof(int));
3697 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3698 (slice_num + NUM_SLICES) * sizeof(int));
3699 encode->slice_header_index = realloc(encode->slice_header_index,
3700 (slice_num + NUM_SLICES) * sizeof(int));
3701 memset(encode->slice_rawdata_index + slice_num, 0,
3702 sizeof(int) * NUM_SLICES);
3703 memset(encode->slice_rawdata_count + slice_num, 0,
3704 sizeof(int) * NUM_SLICES);
3705 memset(encode->slice_header_index + slice_num, 0,
3706 sizeof(int) * NUM_SLICES);
3708 encode->max_slice_num += NUM_SLICES;
3709 if ((encode->slice_rawdata_index == NULL) ||
3710 (encode->slice_header_index == NULL) ||
3711 (encode->slice_rawdata_count == NULL)) {
3712 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3719 case VAEncPackedHeaderParameterBufferType: {
3720 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3721 encode->last_packed_header_type = param->type;
3723 if ((param->type == VAEncPackedHeaderRawData) ||
3724 (param->type == VAEncPackedHeaderSlice)) {
3725 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3726 } else if ((obj_config->profile == VAProfileHEVCMain ||
3727 obj_config->profile == VAProfileHEVCMain10) &&
3728 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3729 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3732 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3734 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3737 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3742 case VAEncPackedHeaderDataBufferType: {
3743 if (encode->last_packed_header_type == 0) {
3744 WARN_ONCE("the packed header data is passed without type!\n");
3745 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3749 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3750 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3751 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3753 if (obj_config->profile == VAProfileVP9Profile0)
3756 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3757 * the packed_slice_header as the delimeter to decide how
3758 * the packed rawdata is inserted for the given slice.
3759 * Otherwise it will use the VAEncSequenceParameterBuffer
3762 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3763 /* store the first index of the packed header data for current slice */
3764 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3765 encode->slice_rawdata_index[encode->slice_index] =
3766 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3768 encode->slice_rawdata_count[encode->slice_index]++;
3769 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3770 /* find one packed slice_header delimeter. And the following
3771 * packed data is for the next slice
3773 encode->slice_header_index[encode->slice_index] =
3774 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3775 encode->slice_index++;
3776 /* Reallocate the buffer to record the index/count of
3777 * packed_data for one slice.
3779 if (encode->slice_index == encode->max_slice_num) {
3780 int slice_num = encode->max_slice_num;
3782 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3783 (slice_num + NUM_SLICES) * sizeof(int));
3784 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3785 (slice_num + NUM_SLICES) * sizeof(int));
3786 encode->slice_header_index = realloc(encode->slice_header_index,
3787 (slice_num + NUM_SLICES) * sizeof(int));
3788 memset(encode->slice_rawdata_index + slice_num, 0,
3789 sizeof(int) * NUM_SLICES);
3790 memset(encode->slice_rawdata_count + slice_num, 0,
3791 sizeof(int) * NUM_SLICES);
3792 memset(encode->slice_header_index + slice_num, 0,
3793 sizeof(int) * NUM_SLICES);
3794 encode->max_slice_num += NUM_SLICES;
3798 if (vaStatus == VA_STATUS_SUCCESS) {
3799 /* store the first index of the packed header data for current slice */
3800 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3801 encode->slice_rawdata_index[encode->slice_index] =
3802 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3804 encode->slice_rawdata_count[encode->slice_index]++;
3805 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3806 if (encode->slice_header_index[encode->slice_index] == 0) {
3807 encode->slice_header_index[encode->slice_index] =
3808 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3810 WARN_ONCE("Multi slice header data is passed for"
3811 " slice %d!\n", encode->slice_index);
3817 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3818 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3819 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3820 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3821 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3822 VA_STATUS_ERROR_ENCODING_ERROR);
3824 if ((obj_config->profile == VAProfileHEVCMain ||
3825 obj_config->profile == VAProfileHEVCMain10) &&
3826 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3828 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3831 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3832 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3834 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3837 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3841 encode->last_packed_header_type = 0;
3845 case VAEncMiscParameterBufferType:
3846 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3851 case VAEncMacroblockMapBufferType:
3852 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3856 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3864 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3866 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3867 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3870 i965_proc_render_picture(VADriverContextP ctx,
3871 VAContextID context,
3872 VABufferID *buffers,
3875 struct i965_driver_data *i965 = i965_driver_data(ctx);
3876 struct object_context *obj_context = CONTEXT(context);
3877 VAStatus vaStatus = VA_STATUS_SUCCESS;
3880 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3882 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3883 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3886 return VA_STATUS_ERROR_INVALID_BUFFER;
3888 switch (obj_buffer->type) {
3889 case VAProcPipelineParameterBufferType:
3890 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3894 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3903 i965_pre_encoder_render_picture(VADriverContextP ctx,
3904 VAContextID context,
3905 VABufferID *buffers,
3908 struct i965_driver_data *i965 = i965_driver_data(ctx);
3909 struct object_context *obj_context = CONTEXT(context);
3910 struct object_config *obj_config;
3911 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3914 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3915 obj_config = obj_context->obj_config;
3916 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3918 for (i = 0; i < num_buffers; i++) {
3919 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3922 return VA_STATUS_ERROR_INVALID_BUFFER;
3924 switch (obj_buffer->type) {
3925 case VAStatsStatisticsParameterBufferType:
3926 vaStatus = I965_RENDER_ENCODE_BUFFER(statistics_parameter_ext);
3930 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3939 i965_RenderPicture(VADriverContextP ctx,
3940 VAContextID context,
3941 VABufferID *buffers,
3944 struct i965_driver_data *i965 = i965_driver_data(ctx);
3945 struct object_context *obj_context;
3946 struct object_config *obj_config;
3947 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3949 obj_context = CONTEXT(context);
3950 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3952 if (num_buffers <= 0)
3953 return VA_STATUS_ERROR_INVALID_PARAMETER;
3955 obj_config = obj_context->obj_config;
3956 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3958 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3959 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3960 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
3961 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3962 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
3963 (VAEntrypointFEI == obj_config->entrypoint)) {
3964 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3965 } else if (VAEntrypointStats == obj_config->entrypoint) {
3966 vaStatus = i965_pre_encoder_render_picture(ctx, context, buffers, num_buffers);
3968 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3975 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3977 struct i965_driver_data *i965 = i965_driver_data(ctx);
3978 struct object_context *obj_context = CONTEXT(context);
3979 struct object_config *obj_config;
3981 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3982 obj_config = obj_context->obj_config;
3983 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3985 if (obj_context->codec_type == CODEC_PROC) {
3986 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3987 } else if (obj_context->codec_type == CODEC_ENC) {
3988 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3989 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3990 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
3991 (VAEntrypointFEI == obj_config->entrypoint)),
3992 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3994 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3995 obj_context->codec_state.encode.num_packed_header_data_ext) {
3996 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3997 return VA_STATUS_ERROR_INVALID_PARAMETER;
3999 if (!obj_context->codec_state.encode.pic_param_ext) {
4000 return VA_STATUS_ERROR_INVALID_PARAMETER;
4002 if (!obj_context->codec_state.encode.seq_param_ext &&
4003 (VAEntrypointEncPicture != obj_config->entrypoint)) {
4004 /* The seq_param is not mandatory for VP9 encoding */
4005 if (obj_config->profile != VAProfileVP9Profile0)
4006 return VA_STATUS_ERROR_INVALID_PARAMETER;
4008 if ((obj_context->codec_state.encode.num_slice_params_ext <= 0) &&
4009 ((obj_config->profile != VAProfileVP8Version0_3) &&
4010 (obj_config->profile != VAProfileVP9Profile0))) {
4011 return VA_STATUS_ERROR_INVALID_PARAMETER;
4014 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
4015 (obj_context->codec_state.encode.num_slice_params_ext !=
4016 obj_context->codec_state.encode.slice_index)) {
4017 WARN_ONCE("packed slice_header data is missing for some slice"
4018 " under packed SLICE_HEADER mode\n");
4019 return VA_STATUS_ERROR_INVALID_PARAMETER;
4021 } else if (obj_context->codec_type == CODEC_PREENC) {
4022 ASSERT_RET((VAEntrypointStats == obj_config->entrypoint),
4023 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
4025 if (!obj_context->codec_state.encode.stat_param_ext) {
4026 return VA_STATUS_ERROR_INVALID_PARAMETER;
4029 if (obj_context->codec_state.decode.pic_param == NULL) {
4030 return VA_STATUS_ERROR_INVALID_PARAMETER;
4032 if (obj_context->codec_state.decode.num_slice_params <= 0) {
4033 return VA_STATUS_ERROR_INVALID_PARAMETER;
4035 if (obj_context->codec_state.decode.num_slice_datas <= 0) {
4036 return VA_STATUS_ERROR_INVALID_PARAMETER;
4039 if (obj_context->codec_state.decode.num_slice_params !=
4040 obj_context->codec_state.decode.num_slice_datas) {
4041 return VA_STATUS_ERROR_INVALID_PARAMETER;
4044 if (obj_context->wrapper_context != VA_INVALID_ID) {
4045 /* call the vaEndPicture of wrapped driver */
4046 VADriverContextP pdrvctx;
4049 pdrvctx = i965->wrapper_pdrvctx;
4050 CALL_VTABLE(pdrvctx, va_status,
4051 vaEndPicture(pdrvctx, obj_context->wrapper_context));
4057 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
4058 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
4062 i965_SyncSurface(VADriverContextP ctx,
4063 VASurfaceID render_target)
4065 struct i965_driver_data *i965 = i965_driver_data(ctx);
4066 struct object_surface *obj_surface = SURFACE(render_target);
4068 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
4070 if (obj_surface->bo)
4071 drm_intel_bo_wait_rendering(obj_surface->bo);
4073 return VA_STATUS_SUCCESS;
4077 i965_QuerySurfaceStatus(VADriverContextP ctx,
4078 VASurfaceID render_target,
4079 VASurfaceStatus *status) /* out */
4081 struct i965_driver_data *i965 = i965_driver_data(ctx);
4082 struct object_surface *obj_surface = SURFACE(render_target);
4084 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
4086 if (obj_surface->bo) {
4087 if (drm_intel_bo_busy(obj_surface->bo)) {
4088 *status = VASurfaceRendering;
4090 *status = VASurfaceReady;
4093 *status = VASurfaceReady;
4096 return VA_STATUS_SUCCESS;
4099 static VADisplayAttribute *
4100 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
4102 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4105 if (!i965->display_attributes)
4108 for (i = 0; i < i965->num_display_attributes; i++) {
4109 if (i965->display_attributes[i].type == type)
4110 return &i965->display_attributes[i];
4116 i965_display_attributes_terminate(VADriverContextP ctx)
4118 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4120 if (i965->display_attributes) {
4121 free(i965->display_attributes);
4122 i965->display_attributes = NULL;
4123 i965->num_display_attributes = 0;
4128 i965_display_attributes_init(VADriverContextP ctx)
4130 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4132 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
4133 i965->display_attributes = malloc(
4134 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
4135 if (!i965->display_attributes)
4139 i965->display_attributes,
4140 i965_display_attributes,
4141 sizeof(i965_display_attributes)
4144 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
4145 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
4146 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
4147 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
4148 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
4150 if (!i965->rotation_attrib ||
4151 !i965->brightness_attrib ||
4152 !i965->contrast_attrib ||
4153 !i965->hue_attrib ||
4154 !i965->saturation_attrib) {
4160 i965_display_attributes_terminate(ctx);
4165 * Query display attributes
4166 * The caller must provide a "attr_list" array that can hold at
4167 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
4168 * returned in "attr_list" is returned in "num_attributes".
4171 i965_QueryDisplayAttributes(
4172 VADriverContextP ctx,
4173 VADisplayAttribute *attribs, /* out */
4174 int *num_attribs_ptr /* out */
4177 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
4179 if (attribs && num_attribs > 0)
4180 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
4182 if (num_attribs_ptr)
4183 *num_attribs_ptr = num_attribs;
4185 return VA_STATUS_SUCCESS;
4189 * Get display attributes
4190 * This function returns the current attribute values in "attr_list".
4191 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
4192 * from vaQueryDisplayAttributes() can have their values retrieved.
4195 i965_GetDisplayAttributes(
4196 VADriverContextP ctx,
4197 VADisplayAttribute *attribs, /* inout */
4198 int num_attribs /* in */
4203 for (i = 0; i < num_attribs; i++) {
4204 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
4206 src_attrib = get_display_attribute(ctx, dst_attrib->type);
4208 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
4209 dst_attrib->min_value = src_attrib->min_value;
4210 dst_attrib->max_value = src_attrib->max_value;
4211 dst_attrib->value = src_attrib->value;
4212 dst_attrib->flags = src_attrib->flags;
4213 } else if (src_attrib &&
4214 (src_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE)) {
4215 dst_attrib->flags = src_attrib->flags;
4217 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
4219 return VA_STATUS_SUCCESS;
4223 * Set display attributes
4224 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
4225 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
4226 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
4229 i965_SetDisplayAttributes(
4230 VADriverContextP ctx,
4231 VADisplayAttribute *attribs, /* in */
4232 int num_attribs /* in */
4237 for (i = 0; i < num_attribs; i++) {
4238 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
4240 dst_attrib = get_display_attribute(ctx, src_attrib->type);
4242 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
4244 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
4247 if (src_attrib->value < dst_attrib->min_value ||
4248 src_attrib->value > dst_attrib->max_value)
4249 return VA_STATUS_ERROR_INVALID_PARAMETER;
4251 dst_attrib->value = src_attrib->value;
4252 /* XXX: track modified attributes through timestamps */
4254 return VA_STATUS_SUCCESS;
4258 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
4259 VASurfaceID surface,
4260 void **buffer, /* out */
4261 unsigned int *stride) /* out */
4264 return VA_STATUS_ERROR_UNIMPLEMENTED;
4268 i965_destroy_heap(struct object_heap *heap,
4269 void (*func)(struct object_heap *heap, struct object_base *object))
4271 struct object_base *object;
4272 object_heap_iterator iter;
4274 object = object_heap_first(heap, &iter);
4280 object = object_heap_next(heap, &iter);
4283 object_heap_destroy(heap);
4288 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
4291 i965_CreateImage(VADriverContextP ctx,
4292 VAImageFormat *format,
4295 VAImage *out_image) /* out */
4297 struct i965_driver_data *i965 = i965_driver_data(ctx);
4298 struct object_image *obj_image;
4299 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4301 unsigned int size2, size, awidth, aheight;
4303 out_image->image_id = VA_INVALID_ID;
4304 out_image->buf = VA_INVALID_ID;
4306 image_id = NEW_IMAGE_ID();
4307 if (image_id == VA_INVALID_ID)
4308 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4310 obj_image = IMAGE(image_id);
4312 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4313 obj_image->bo = NULL;
4314 obj_image->palette = NULL;
4315 obj_image->derived_surface = VA_INVALID_ID;
4317 VAImage * const image = &obj_image->image;
4318 image->image_id = image_id;
4319 image->buf = VA_INVALID_ID;
4321 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
4323 if ((format->fourcc == VA_FOURCC_YV12) ||
4324 (format->fourcc == VA_FOURCC_I420)) {
4325 if (awidth % 128 != 0) {
4326 awidth = ALIGN(width, 128);
4330 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
4331 size = awidth * aheight;
4332 size2 = (awidth / 2) * (aheight / 2);
4334 image->num_palette_entries = 0;
4335 image->entry_bytes = 0;
4336 memset(image->component_order, 0, sizeof(image->component_order));
4338 switch (format->fourcc) {
4339 case VA_FOURCC_IA44:
4340 case VA_FOURCC_AI44:
4341 image->num_planes = 1;
4342 image->pitches[0] = awidth;
4343 image->offsets[0] = 0;
4344 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4345 image->num_palette_entries = 16;
4346 image->entry_bytes = 3;
4347 image->component_order[0] = 'R';
4348 image->component_order[1] = 'G';
4349 image->component_order[2] = 'B';
4351 case VA_FOURCC_IA88:
4352 case VA_FOURCC_AI88:
4353 image->num_planes = 1;
4354 image->pitches[0] = awidth * 2;
4355 image->offsets[0] = 0;
4356 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4357 image->num_palette_entries = 256;
4358 image->entry_bytes = 3;
4359 image->component_order[0] = 'R';
4360 image->component_order[1] = 'G';
4361 image->component_order[2] = 'B';
4363 case VA_FOURCC_ARGB:
4364 case VA_FOURCC_ABGR:
4365 case VA_FOURCC_BGRA:
4366 case VA_FOURCC_RGBA:
4367 case VA_FOURCC_BGRX:
4368 case VA_FOURCC_RGBX:
4369 image->num_planes = 1;
4370 image->pitches[0] = awidth * 4;
4371 image->offsets[0] = 0;
4372 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4374 case VA_FOURCC_YV12:
4375 image->num_planes = 3;
4376 image->pitches[0] = awidth;
4377 image->offsets[0] = 0;
4378 image->pitches[1] = awidth / 2;
4379 image->offsets[1] = size;
4380 image->pitches[2] = awidth / 2;
4381 image->offsets[2] = size + size2;
4382 image->data_size = size + 2 * size2;
4384 case VA_FOURCC_I420:
4385 image->num_planes = 3;
4386 image->pitches[0] = awidth;
4387 image->offsets[0] = 0;
4388 image->pitches[1] = awidth / 2;
4389 image->offsets[1] = size;
4390 image->pitches[2] = awidth / 2;
4391 image->offsets[2] = size + size2;
4392 image->data_size = size + 2 * size2;
4394 case VA_FOURCC_422H:
4395 image->num_planes = 3;
4396 image->pitches[0] = awidth;
4397 image->offsets[0] = 0;
4398 image->pitches[1] = awidth / 2;
4399 image->offsets[1] = size;
4400 image->pitches[2] = awidth / 2;
4401 image->offsets[2] = size + (awidth / 2) * aheight;
4402 image->data_size = size + 2 * ((awidth / 2) * aheight);
4404 case VA_FOURCC_NV12:
4405 image->num_planes = 2;
4406 image->pitches[0] = awidth;
4407 image->offsets[0] = 0;
4408 image->pitches[1] = awidth;
4409 image->offsets[1] = size;
4410 image->data_size = size + 2 * size2;
4412 case VA_FOURCC_YUY2:
4413 case VA_FOURCC_UYVY:
4414 image->num_planes = 1;
4415 image->pitches[0] = awidth * 2;
4416 image->offsets[0] = 0;
4417 image->data_size = size * 2;
4419 case VA_FOURCC_P010:
4420 image->num_planes = 2;
4421 image->pitches[0] = awidth * 2;
4422 image->offsets[0] = 0;
4423 image->pitches[1] = awidth * 2;
4424 image->offsets[1] = size * 2;
4425 image->data_size = size * 2 + 2 * size2 * 2;
4431 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
4432 image->data_size, 1, NULL, &image->buf);
4433 if (va_status != VA_STATUS_SUCCESS)
4436 struct object_buffer *obj_buffer = BUFFER(image->buf);
4439 !obj_buffer->buffer_store ||
4440 !obj_buffer->buffer_store->bo)
4441 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4443 obj_image->bo = obj_buffer->buffer_store->bo;
4444 dri_bo_reference(obj_image->bo);
4446 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4447 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4448 if (!obj_image->palette)
4452 image->image_id = image_id;
4453 image->format = *format;
4454 image->width = width;
4455 image->height = height;
4457 *out_image = *image;
4458 return VA_STATUS_SUCCESS;
4461 i965_DestroyImage(ctx, image_id);
4466 i965_check_alloc_surface_bo(VADriverContextP ctx,
4467 struct object_surface *obj_surface,
4469 unsigned int fourcc,
4470 unsigned int subsampling)
4472 struct i965_driver_data *i965 = i965_driver_data(ctx);
4473 int region_width, region_height;
4475 if (obj_surface->bo) {
4476 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4477 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4478 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4479 return VA_STATUS_SUCCESS;
4482 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4483 obj_surface->x_cr_offset = 0;
4485 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4487 if ((tiled && !obj_surface->user_disable_tiling)) {
4488 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4489 fourcc != VA_FOURCC_IYUV &&
4490 fourcc != VA_FOURCC_YV12,
4491 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4493 if (obj_surface->user_h_stride_set) {
4494 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4496 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4498 if (obj_surface->user_v_stride_set) {
4499 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4501 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4503 region_height = obj_surface->height;
4506 case VA_FOURCC_NV12:
4507 case VA_FOURCC_P010:
4508 assert(subsampling == SUBSAMPLE_YUV420);
4509 obj_surface->cb_cr_pitch = obj_surface->width;
4510 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4511 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4512 obj_surface->y_cb_offset = obj_surface->height;
4513 obj_surface->y_cr_offset = obj_surface->height;
4514 region_width = obj_surface->width;
4515 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4519 case VA_FOURCC_IMC1:
4520 assert(subsampling == SUBSAMPLE_YUV420);
4521 obj_surface->cb_cr_pitch = obj_surface->width;
4522 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4523 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4524 obj_surface->y_cr_offset = obj_surface->height;
4525 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4526 region_width = obj_surface->width;
4527 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4531 case VA_FOURCC_IMC3:
4532 assert(subsampling == SUBSAMPLE_YUV420);
4533 obj_surface->cb_cr_pitch = obj_surface->width;
4534 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4535 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4536 obj_surface->y_cb_offset = obj_surface->height;
4537 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4538 region_width = obj_surface->width;
4539 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4543 case VA_FOURCC_422H:
4544 assert(subsampling == SUBSAMPLE_YUV422H);
4545 obj_surface->cb_cr_pitch = obj_surface->width;
4546 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4547 obj_surface->cb_cr_height = obj_surface->orig_height;
4548 obj_surface->y_cb_offset = obj_surface->height;
4549 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4550 region_width = obj_surface->width;
4551 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4555 case VA_FOURCC_422V:
4556 assert(subsampling == SUBSAMPLE_YUV422V);
4557 obj_surface->cb_cr_pitch = obj_surface->width;
4558 obj_surface->cb_cr_width = obj_surface->orig_width;
4559 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4560 obj_surface->y_cb_offset = obj_surface->height;
4561 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4562 region_width = obj_surface->width;
4563 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4567 case VA_FOURCC_411P:
4568 assert(subsampling == SUBSAMPLE_YUV411);
4569 obj_surface->cb_cr_pitch = obj_surface->width;
4570 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4571 obj_surface->cb_cr_height = obj_surface->orig_height;
4572 obj_surface->y_cb_offset = obj_surface->height;
4573 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4574 region_width = obj_surface->width;
4575 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4579 case VA_FOURCC_444P:
4580 assert(subsampling == SUBSAMPLE_YUV444);
4581 obj_surface->cb_cr_pitch = obj_surface->width;
4582 obj_surface->cb_cr_width = obj_surface->orig_width;
4583 obj_surface->cb_cr_height = obj_surface->orig_height;
4584 obj_surface->y_cb_offset = obj_surface->height;
4585 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4586 region_width = obj_surface->width;
4587 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4591 case VA_FOURCC_Y800:
4592 assert(subsampling == SUBSAMPLE_YUV400);
4593 obj_surface->cb_cr_pitch = 0;
4594 obj_surface->cb_cr_width = 0;
4595 obj_surface->cb_cr_height = 0;
4596 obj_surface->y_cb_offset = 0;
4597 obj_surface->y_cr_offset = 0;
4598 region_width = obj_surface->width;
4599 region_height = obj_surface->height;
4603 case VA_FOURCC_YUY2:
4604 case VA_FOURCC_UYVY:
4605 assert(subsampling == SUBSAMPLE_YUV422H);
4606 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4607 obj_surface->cb_cr_pitch = obj_surface->width;
4608 obj_surface->y_cb_offset = 0;
4609 obj_surface->y_cr_offset = 0;
4610 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4611 obj_surface->cb_cr_height = obj_surface->orig_height;
4612 region_width = obj_surface->width;
4613 region_height = obj_surface->height;
4617 case VA_FOURCC_RGBA:
4618 case VA_FOURCC_RGBX:
4619 case VA_FOURCC_BGRA:
4620 case VA_FOURCC_BGRX:
4621 assert(subsampling == SUBSAMPLE_RGBX);
4623 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4624 region_width = obj_surface->width;
4625 region_height = obj_surface->height;
4629 /* Never get here */
4630 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4634 assert(subsampling == SUBSAMPLE_YUV420 ||
4635 subsampling == SUBSAMPLE_YUV422H ||
4636 subsampling == SUBSAMPLE_YUV422V ||
4637 subsampling == SUBSAMPLE_RGBX);
4639 region_width = obj_surface->width;
4640 region_height = obj_surface->height;
4643 case VA_FOURCC_NV12:
4644 case VA_FOURCC_P010:
4645 obj_surface->y_cb_offset = obj_surface->height;
4646 obj_surface->y_cr_offset = obj_surface->height;
4647 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4648 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) *
4650 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4651 obj_surface->cb_cr_pitch = obj_surface->width;
4652 region_width = obj_surface->width;
4653 region_height = obj_surface->height + obj_surface->height / 2;
4656 case VA_FOURCC_YV16:
4657 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4658 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4659 obj_surface->cb_cr_height = obj_surface->orig_height;
4660 obj_surface->y_cr_offset = obj_surface->height;
4661 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4662 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4663 region_width = obj_surface->width;
4664 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4667 case VA_FOURCC_YV12:
4668 case VA_FOURCC_I420:
4669 case VA_FOURCC_IYUV:
4670 if (fourcc == VA_FOURCC_YV12) {
4671 obj_surface->y_cr_offset = obj_surface->height;
4672 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4674 obj_surface->y_cb_offset = obj_surface->height;
4675 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4678 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4679 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4680 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4681 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4682 region_width = obj_surface->width;
4683 region_height = obj_surface->height + obj_surface->height / 2;
4686 case VA_FOURCC_I010:
4687 obj_surface->y_cb_offset = obj_surface->height;
4688 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4689 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4690 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
4691 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4692 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4693 region_width = obj_surface->width;
4694 region_height = obj_surface->height + obj_surface->height / 2;
4697 case VA_FOURCC_YUY2:
4698 case VA_FOURCC_UYVY:
4699 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4700 obj_surface->y_cb_offset = 0;
4701 obj_surface->y_cr_offset = 0;
4702 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4703 obj_surface->cb_cr_height = obj_surface->orig_height;
4704 obj_surface->cb_cr_pitch = obj_surface->width;
4705 region_width = obj_surface->width;
4706 region_height = obj_surface->height;
4708 case VA_FOURCC_RGBA:
4709 case VA_FOURCC_RGBX:
4710 case VA_FOURCC_BGRA:
4711 case VA_FOURCC_BGRX:
4712 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4713 region_width = obj_surface->width;
4714 region_height = obj_surface->height;
4718 /* Never get here */
4719 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4724 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4726 if ((tiled && !obj_surface->user_disable_tiling)) {
4727 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4728 unsigned long pitch;
4730 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4738 assert(tiling_mode == I915_TILING_Y);
4739 assert(pitch == obj_surface->width);
4741 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4747 obj_surface->fourcc = fourcc;
4748 obj_surface->subsampling = subsampling;
4749 assert(obj_surface->bo);
4750 return VA_STATUS_SUCCESS;
4753 VAStatus i965_DeriveImage(VADriverContextP ctx,
4754 VASurfaceID surface,
4755 VAImage *out_image) /* out */
4757 struct i965_driver_data *i965 = i965_driver_data(ctx);
4758 struct object_image *obj_image;
4759 struct object_surface *obj_surface;
4761 unsigned int w_pitch;
4762 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4764 out_image->image_id = VA_INVALID_ID;
4765 obj_surface = SURFACE(surface);
4768 return VA_STATUS_ERROR_INVALID_SURFACE;
4770 if (!obj_surface->bo) {
4771 unsigned int is_tiled = 0;
4772 unsigned int fourcc = VA_FOURCC_YV12;
4773 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4774 int sampling = get_sampling_from_fourcc(fourcc);
4775 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4776 if (va_status != VA_STATUS_SUCCESS)
4780 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4782 w_pitch = obj_surface->width;
4784 image_id = NEW_IMAGE_ID();
4786 if (image_id == VA_INVALID_ID)
4787 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4789 obj_image = IMAGE(image_id);
4792 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4794 obj_image->bo = NULL;
4795 obj_image->palette = NULL;
4796 obj_image->derived_surface = VA_INVALID_ID;
4798 VAImage * const image = &obj_image->image;
4800 memset(image, 0, sizeof(*image));
4801 image->image_id = image_id;
4802 image->buf = VA_INVALID_ID;
4803 image->num_palette_entries = 0;
4804 image->entry_bytes = 0;
4805 image->width = obj_surface->orig_width;
4806 image->height = obj_surface->orig_height;
4807 image->data_size = obj_surface->size;
4809 image->format.fourcc = obj_surface->fourcc;
4810 image->format.byte_order = VA_LSB_FIRST;
4811 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4813 if (!image->format.bits_per_pixel)
4816 switch (image->format.fourcc) {
4817 case VA_FOURCC_YV12:
4818 image->num_planes = 3;
4819 image->pitches[0] = w_pitch; /* Y */
4820 image->offsets[0] = 0;
4821 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4822 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4823 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4824 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4827 case VA_FOURCC_YV16:
4828 image->num_planes = 3;
4829 image->pitches[0] = w_pitch; /* Y */
4830 image->offsets[0] = 0;
4831 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4832 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4833 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4834 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4837 case VA_FOURCC_NV12:
4838 case VA_FOURCC_P010:
4839 image->num_planes = 2;
4840 image->pitches[0] = w_pitch; /* Y */
4841 image->offsets[0] = 0;
4842 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4843 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4846 case VA_FOURCC_I420:
4847 case VA_FOURCC_I010:
4848 case VA_FOURCC_422H:
4849 case VA_FOURCC_IMC3:
4850 case VA_FOURCC_444P:
4851 case VA_FOURCC_422V:
4852 case VA_FOURCC_411P:
4853 image->num_planes = 3;
4854 image->pitches[0] = w_pitch; /* Y */
4855 image->offsets[0] = 0;
4856 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4857 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4858 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4859 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4862 case VA_FOURCC_YUY2:
4863 case VA_FOURCC_UYVY:
4864 case VA_FOURCC_Y800:
4865 image->num_planes = 1;
4866 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4867 image->offsets[0] = 0;
4869 case VA_FOURCC_RGBA:
4870 case VA_FOURCC_RGBX:
4871 case VA_FOURCC_BGRA:
4872 case VA_FOURCC_BGRX:
4873 image->num_planes = 1;
4874 image->pitches[0] = obj_surface->width;
4876 switch (image->format.fourcc) {
4877 case VA_FOURCC_RGBA:
4878 case VA_FOURCC_RGBX:
4879 image->format.red_mask = 0x000000ff;
4880 image->format.green_mask = 0x0000ff00;
4881 image->format.blue_mask = 0x00ff0000;
4883 case VA_FOURCC_BGRA:
4884 case VA_FOURCC_BGRX:
4885 image->format.red_mask = 0x00ff0000;
4886 image->format.green_mask = 0x0000ff00;
4887 image->format.blue_mask = 0x000000ff;
4893 switch (image->format.fourcc) {
4894 case VA_FOURCC_RGBA:
4895 case VA_FOURCC_BGRA:
4896 image->format.alpha_mask = 0xff000000;
4897 image->format.depth = 32;
4899 case VA_FOURCC_RGBX:
4900 case VA_FOURCC_BGRX:
4901 image->format.alpha_mask = 0x00000000;
4902 image->format.depth = 24;
4913 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4914 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4915 if (va_status != VA_STATUS_SUCCESS)
4918 struct object_buffer *obj_buffer = BUFFER(image->buf);
4921 !obj_buffer->buffer_store ||
4922 !obj_buffer->buffer_store->bo)
4923 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4925 obj_image->bo = obj_buffer->buffer_store->bo;
4926 dri_bo_reference(obj_image->bo);
4928 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4929 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4930 if (!obj_image->palette) {
4931 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4936 *out_image = *image;
4937 obj_surface->flags |= SURFACE_DERIVED;
4938 obj_surface->derived_image_id = image_id;
4939 obj_image->derived_surface = surface;
4941 return VA_STATUS_SUCCESS;
4944 i965_DestroyImage(ctx, image_id);
4949 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4951 object_heap_free(heap, obj);
4956 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4958 struct i965_driver_data *i965 = i965_driver_data(ctx);
4959 struct object_image *obj_image = IMAGE(image);
4960 struct object_surface *obj_surface;
4963 return VA_STATUS_SUCCESS;
4965 dri_bo_unreference(obj_image->bo);
4966 obj_image->bo = NULL;
4968 if (obj_image->image.buf != VA_INVALID_ID) {
4969 i965_DestroyBuffer(ctx, obj_image->image.buf);
4970 obj_image->image.buf = VA_INVALID_ID;
4973 if (obj_image->palette) {
4974 free(obj_image->palette);
4975 obj_image->palette = NULL;
4978 obj_surface = SURFACE(obj_image->derived_surface);
4981 obj_surface->flags &= ~SURFACE_DERIVED;
4982 obj_surface->derived_image_id = VA_INVALID_ID;
4985 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4987 return VA_STATUS_SUCCESS;
4991 * pointer to an array holding the palette data. The size of the array is
4992 * num_palette_entries * entry_bytes in size. The order of the components
4993 * in the palette is described by the component_order in VASubpicture struct
4996 i965_SetImagePalette(VADriverContextP ctx,
4998 unsigned char *palette)
5000 struct i965_driver_data *i965 = i965_driver_data(ctx);
5003 struct object_image *obj_image = IMAGE(image);
5005 return VA_STATUS_ERROR_INVALID_IMAGE;
5007 if (!obj_image->palette)
5008 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
5010 for (i = 0; i < obj_image->image.num_palette_entries; i++)
5011 obj_image->palette[i] = (((unsigned int)palette[3 * i + 0] << 16) |
5012 ((unsigned int)palette[3 * i + 1] << 8) |
5013 (unsigned int)palette[3 * i + 2]);
5014 return VA_STATUS_SUCCESS;
5018 get_sampling_from_fourcc(unsigned int fourcc)
5020 const i965_fourcc_info *info = get_fourcc_info(fourcc);
5022 if (info && (info->flag & I_S))
5023 return info->subsampling;
5029 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
5030 const uint8_t *src, unsigned int src_stride,
5031 unsigned int len, unsigned int height)
5035 for (i = 0; i < height; i++) {
5036 memcpy(dst, src, len);
5043 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
5044 struct object_surface *obj_surface,
5045 const VARectangle *rect)
5047 uint8_t *dst[3], *src[3];
5049 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
5050 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
5051 unsigned int tiling, swizzle;
5052 VAStatus va_status = VA_STATUS_SUCCESS;
5054 if (!obj_surface->bo)
5055 return VA_STATUS_ERROR_INVALID_SURFACE;
5057 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5058 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5060 if (tiling != I915_TILING_NONE)
5061 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5063 dri_bo_map(obj_surface->bo, 0);
5065 if (!obj_surface->bo->virtual)
5066 return VA_STATUS_ERROR_INVALID_SURFACE;
5068 /* Dest VA image has either I420 or YV12 format.
5069 Source VA surface alway has I420 format */
5070 dst[Y] = image_data + obj_image->image.offsets[Y];
5071 src[0] = (uint8_t *)obj_surface->bo->virtual;
5072 dst[U] = image_data + obj_image->image.offsets[U];
5073 src[1] = src[0] + obj_surface->width * obj_surface->height;
5074 dst[V] = image_data + obj_image->image.offsets[V];
5075 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
5078 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
5079 src[0] += rect->y * obj_surface->width + rect->x;
5080 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
5081 src[0], obj_surface->width,
5082 rect->width, rect->height);
5085 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
5086 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
5087 memcpy_pic(dst[U], obj_image->image.pitches[U],
5088 src[1], obj_surface->width / 2,
5089 rect->width / 2, rect->height / 2);
5092 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
5093 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
5094 memcpy_pic(dst[V], obj_image->image.pitches[V],
5095 src[2], obj_surface->width / 2,
5096 rect->width / 2, rect->height / 2);
5098 if (tiling != I915_TILING_NONE)
5099 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5101 dri_bo_unmap(obj_surface->bo);
5107 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
5108 struct object_surface *obj_surface,
5109 const VARectangle *rect)
5111 uint8_t *dst[2], *src[2];
5112 unsigned int tiling, swizzle;
5113 VAStatus va_status = VA_STATUS_SUCCESS;
5115 if (!obj_surface->bo)
5116 return VA_STATUS_ERROR_INVALID_SURFACE;
5118 assert(obj_surface->fourcc);
5119 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5121 if (tiling != I915_TILING_NONE)
5122 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5124 dri_bo_map(obj_surface->bo, 0);
5126 if (!obj_surface->bo->virtual)
5127 return VA_STATUS_ERROR_INVALID_SURFACE;
5129 /* Both dest VA image and source surface have NV12 format */
5130 dst[0] = image_data + obj_image->image.offsets[0];
5131 src[0] = (uint8_t *)obj_surface->bo->virtual;
5132 dst[1] = image_data + obj_image->image.offsets[1];
5133 src[1] = src[0] + obj_surface->width * obj_surface->height;
5136 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
5137 src[0] += rect->y * obj_surface->width + rect->x;
5138 memcpy_pic(dst[0], obj_image->image.pitches[0],
5139 src[0], obj_surface->width,
5140 rect->width, rect->height);
5143 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
5144 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
5145 memcpy_pic(dst[1], obj_image->image.pitches[1],
5146 src[1], obj_surface->width,
5147 rect->width, rect->height / 2);
5149 if (tiling != I915_TILING_NONE)
5150 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5152 dri_bo_unmap(obj_surface->bo);
5158 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
5159 struct object_surface *obj_surface,
5160 const VARectangle *rect)
5163 unsigned int tiling, swizzle;
5164 VAStatus va_status = VA_STATUS_SUCCESS;
5166 if (!obj_surface->bo)
5167 return VA_STATUS_ERROR_INVALID_SURFACE;
5169 assert(obj_surface->fourcc);
5170 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5172 if (tiling != I915_TILING_NONE)
5173 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5175 dri_bo_map(obj_surface->bo, 0);
5177 if (!obj_surface->bo->virtual)
5178 return VA_STATUS_ERROR_INVALID_SURFACE;
5180 /* Both dest VA image and source surface have YUYV format */
5181 dst = image_data + obj_image->image.offsets[0];
5182 src = (uint8_t *)obj_surface->bo->virtual;
5185 dst += rect->y * obj_image->image.pitches[0] + rect->x * 2;
5186 src += rect->y * obj_surface->width + rect->x * 2;
5187 memcpy_pic(dst, obj_image->image.pitches[0],
5188 src, obj_surface->width * 2,
5189 rect->width * 2, rect->height);
5191 if (tiling != I915_TILING_NONE)
5192 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5194 dri_bo_unmap(obj_surface->bo);
5200 i965_sw_getimage(VADriverContextP ctx,
5201 struct object_surface *obj_surface, struct object_image *obj_image,
5202 const VARectangle *rect)
5204 void *image_data = NULL;
5207 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5208 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5210 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5211 if (va_status != VA_STATUS_SUCCESS)
5214 switch (obj_image->image.format.fourcc) {
5215 case VA_FOURCC_YV12:
5216 case VA_FOURCC_I420:
5217 get_image_i420(obj_image, image_data, obj_surface, rect);
5219 case VA_FOURCC_NV12:
5220 get_image_nv12(obj_image, image_data, obj_surface, rect);
5222 case VA_FOURCC_YUY2:
5223 /* YUY2 is the format supported by overlay plane */
5224 get_image_yuy2(obj_image, image_data, obj_surface, rect);
5227 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5230 if (va_status != VA_STATUS_SUCCESS)
5233 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5238 i965_hw_getimage(VADriverContextP ctx,
5239 struct object_surface *obj_surface, struct object_image *obj_image,
5240 const VARectangle *rect)
5242 struct i965_surface src_surface;
5243 struct i965_surface dst_surface;
5245 src_surface.base = (struct object_base *)obj_surface;
5246 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5247 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5249 dst_surface.base = (struct object_base *)obj_image;
5250 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
5251 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5253 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
5257 i965_GetImage(VADriverContextP ctx,
5258 VASurfaceID surface,
5259 int x, /* coordinates of the upper left source pixel */
5261 unsigned int width, /* width and height of the region */
5262 unsigned int height,
5265 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5266 struct object_surface * const obj_surface = SURFACE(surface);
5267 struct object_image * const obj_image = IMAGE(image);
5272 return VA_STATUS_ERROR_INVALID_SURFACE;
5273 if (!obj_surface->bo) /* don't get anything, keep previous data */
5274 return VA_STATUS_SUCCESS;
5275 if (is_surface_busy(i965, obj_surface))
5276 return VA_STATUS_ERROR_SURFACE_BUSY;
5278 if (!obj_image || !obj_image->bo)
5279 return VA_STATUS_ERROR_INVALID_IMAGE;
5280 if (is_image_busy(i965, obj_image, surface))
5281 return VA_STATUS_ERROR_SURFACE_BUSY;
5284 return VA_STATUS_ERROR_INVALID_PARAMETER;
5285 if (x + width > obj_surface->orig_width ||
5286 y + height > obj_surface->orig_height)
5287 return VA_STATUS_ERROR_INVALID_PARAMETER;
5288 if (x + width > obj_image->image.width ||
5289 y + height > obj_image->image.height)
5290 return VA_STATUS_ERROR_INVALID_PARAMETER;
5295 rect.height = height;
5297 if (HAS_ACCELERATED_GETIMAGE(i965))
5298 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
5300 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
5306 put_image_i420(struct object_surface *obj_surface,
5307 const VARectangle *dst_rect,
5308 struct object_image *obj_image, uint8_t *image_data,
5309 const VARectangle *src_rect)
5311 uint8_t *dst[3], *src[3];
5313 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
5314 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
5315 unsigned int tiling, swizzle;
5316 VAStatus va_status = VA_STATUS_SUCCESS;
5318 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5320 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5321 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5322 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5323 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5325 if (tiling != I915_TILING_NONE)
5326 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5328 dri_bo_map(obj_surface->bo, 0);
5330 if (!obj_surface->bo->virtual)
5331 return VA_STATUS_ERROR_INVALID_SURFACE;
5333 /* Dest VA image has either I420 or YV12 format.
5334 Source VA surface alway has I420 format */
5335 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5336 src[Y] = image_data + obj_image->image.offsets[Y];
5337 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5338 src[U] = image_data + obj_image->image.offsets[U];
5339 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
5340 src[V] = image_data + obj_image->image.offsets[V];
5343 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5344 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
5345 memcpy_pic(dst[0], obj_surface->width,
5346 src[Y], obj_image->image.pitches[Y],
5347 src_rect->width, src_rect->height);
5350 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5351 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
5352 memcpy_pic(dst[1], obj_surface->width / 2,
5353 src[U], obj_image->image.pitches[U],
5354 src_rect->width / 2, src_rect->height / 2);
5357 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5358 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
5359 memcpy_pic(dst[2], obj_surface->width / 2,
5360 src[V], obj_image->image.pitches[V],
5361 src_rect->width / 2, src_rect->height / 2);
5363 if (tiling != I915_TILING_NONE)
5364 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5366 dri_bo_unmap(obj_surface->bo);
5372 put_image_nv12(struct object_surface *obj_surface,
5373 const VARectangle *dst_rect,
5374 struct object_image *obj_image, uint8_t *image_data,
5375 const VARectangle *src_rect)
5377 uint8_t *dst[2], *src[2];
5378 unsigned int tiling, swizzle;
5379 VAStatus va_status = VA_STATUS_SUCCESS;
5381 if (!obj_surface->bo)
5382 return VA_STATUS_ERROR_INVALID_SURFACE;
5384 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5385 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5386 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5387 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5389 if (tiling != I915_TILING_NONE)
5390 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5392 dri_bo_map(obj_surface->bo, 0);
5394 if (!obj_surface->bo->virtual)
5395 return VA_STATUS_ERROR_INVALID_SURFACE;
5397 /* Both dest VA image and source surface have NV12 format */
5398 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5399 src[0] = image_data + obj_image->image.offsets[0];
5400 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5401 src[1] = image_data + obj_image->image.offsets[1];
5404 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5405 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
5406 memcpy_pic(dst[0], obj_surface->width,
5407 src[0], obj_image->image.pitches[0],
5408 src_rect->width, src_rect->height);
5411 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
5412 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
5413 memcpy_pic(dst[1], obj_surface->width,
5414 src[1], obj_image->image.pitches[1],
5415 src_rect->width, src_rect->height / 2);
5417 if (tiling != I915_TILING_NONE)
5418 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5420 dri_bo_unmap(obj_surface->bo);
5426 put_image_yuy2(struct object_surface *obj_surface,
5427 const VARectangle *dst_rect,
5428 struct object_image *obj_image, uint8_t *image_data,
5429 const VARectangle *src_rect)
5432 unsigned int tiling, swizzle;
5433 VAStatus va_status = VA_STATUS_SUCCESS;
5435 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5436 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5437 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5438 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5439 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5441 if (tiling != I915_TILING_NONE)
5442 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5444 dri_bo_map(obj_surface->bo, 0);
5446 if (!obj_surface->bo->virtual)
5447 return VA_STATUS_ERROR_INVALID_SURFACE;
5449 /* Both dest VA image and source surface have YUY2 format */
5450 dst = (uint8_t *)obj_surface->bo->virtual;
5451 src = image_data + obj_image->image.offsets[0];
5453 /* YUYV packed plane */
5454 dst += dst_rect->y * obj_surface->width + dst_rect->x * 2;
5455 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x * 2;
5456 memcpy_pic(dst, obj_surface->width * 2,
5457 src, obj_image->image.pitches[0],
5458 src_rect->width * 2, src_rect->height);
5460 if (tiling != I915_TILING_NONE)
5461 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5463 dri_bo_unmap(obj_surface->bo);
5469 i965_sw_putimage(VADriverContextP ctx,
5470 struct object_surface *obj_surface, struct object_image *obj_image,
5471 const VARectangle *src_rect, const VARectangle *dst_rect)
5473 VAStatus va_status = VA_STATUS_SUCCESS;
5474 void *image_data = NULL;
5476 /* XXX: don't allow scaling */
5477 if (src_rect->width != dst_rect->width ||
5478 src_rect->height != dst_rect->height)
5479 return VA_STATUS_ERROR_INVALID_PARAMETER;
5481 if (obj_surface->fourcc) {
5482 /* Don't allow format mismatch */
5483 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5484 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5488 /* VA is surface not used for decoding, use same VA image format */
5489 va_status = i965_check_alloc_surface_bo(
5492 0, /* XXX: don't use tiled surface */
5493 obj_image->image.format.fourcc,
5494 get_sampling_from_fourcc(obj_image->image.format.fourcc));
5497 if (va_status != VA_STATUS_SUCCESS)
5500 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5501 if (va_status != VA_STATUS_SUCCESS)
5504 switch (obj_image->image.format.fourcc) {
5505 case VA_FOURCC_YV12:
5506 case VA_FOURCC_I420:
5507 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5509 case VA_FOURCC_NV12:
5510 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5512 case VA_FOURCC_YUY2:
5513 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5516 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5519 if (va_status != VA_STATUS_SUCCESS)
5522 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5527 i965_hw_putimage(VADriverContextP ctx,
5528 struct object_surface *obj_surface, struct object_image *obj_image,
5529 const VARectangle *src_rect, const VARectangle *dst_rect)
5531 struct i965_surface src_surface, dst_surface;
5532 VAStatus va_status = VA_STATUS_SUCCESS;
5534 if (!obj_surface->bo) {
5535 unsigned int tiling, swizzle;
5536 int surface_sampling = get_sampling_from_fourcc(obj_image->image.format.fourcc);;
5537 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5539 i965_check_alloc_surface_bo(ctx,
5542 obj_image->image.format.fourcc,
5546 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5548 src_surface.base = (struct object_base *)obj_image;
5549 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5550 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5552 dst_surface.base = (struct object_base *)obj_surface;
5553 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5554 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5556 va_status = i965_image_processing(ctx,
5566 i965_PutImage(VADriverContextP ctx,
5567 VASurfaceID surface,
5571 unsigned int src_width,
5572 unsigned int src_height,
5575 unsigned int dest_width,
5576 unsigned int dest_height)
5578 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5579 struct object_surface * const obj_surface = SURFACE(surface);
5580 struct object_image * const obj_image = IMAGE(image);
5581 VARectangle src_rect, dst_rect;
5585 return VA_STATUS_ERROR_INVALID_SURFACE;
5586 if (is_surface_busy(i965, obj_surface))
5587 return VA_STATUS_ERROR_SURFACE_BUSY;
5589 if (!obj_image || !obj_image->bo)
5590 return VA_STATUS_ERROR_INVALID_IMAGE;
5591 if (is_image_busy(i965, obj_image, surface))
5592 return VA_STATUS_ERROR_SURFACE_BUSY;
5596 src_x + src_width > obj_image->image.width ||
5597 src_y + src_height > obj_image->image.height)
5598 return VA_STATUS_ERROR_INVALID_PARAMETER;
5602 src_rect.width = src_width;
5603 src_rect.height = src_height;
5607 dest_x + dest_width > obj_surface->orig_width ||
5608 dest_y + dest_height > obj_surface->orig_height)
5609 return VA_STATUS_ERROR_INVALID_PARAMETER;
5611 dst_rect.x = dest_x;
5612 dst_rect.y = dest_y;
5613 dst_rect.width = dest_width;
5614 dst_rect.height = dest_height;
5616 if (HAS_ACCELERATED_PUTIMAGE(i965))
5617 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5618 &src_rect, &dst_rect);
5620 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5621 &src_rect, &dst_rect);
5627 i965_PutSurface(VADriverContextP ctx,
5628 VASurfaceID surface,
5629 void *draw, /* X Drawable */
5632 unsigned short srcw,
5633 unsigned short srch,
5636 unsigned short destw,
5637 unsigned short desth,
5638 VARectangle *cliprects, /* client supplied clip list */
5639 unsigned int number_cliprects, /* number of clip rects in the clip list */
5640 unsigned int flags) /* de-interlacing flags */
5643 if (IS_VA_X11(ctx)) {
5644 VARectangle src_rect, dst_rect;
5648 src_rect.width = srcw;
5649 src_rect.height = srch;
5653 dst_rect.width = destw;
5654 dst_rect.height = desth;
5656 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5657 cliprects, number_cliprects, flags);
5660 return VA_STATUS_ERROR_UNIMPLEMENTED;
5665 VADriverContextP ctx, /* in */
5666 VABufferID buf_id, /* in */
5667 VABufferType *type, /* out */
5668 unsigned int *size, /* out */
5669 unsigned int *num_elements /* out */
5672 struct i965_driver_data *i965 = NULL;
5673 struct object_buffer *obj_buffer = NULL;
5675 i965 = i965_driver_data(ctx);
5676 obj_buffer = BUFFER(buf_id);
5678 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5680 *type = obj_buffer->type;
5681 *size = obj_buffer->size_element;
5682 *num_elements = obj_buffer->num_elements;
5684 return VA_STATUS_SUCCESS;
5689 VADriverContextP ctx, /* in */
5690 VASurfaceID surface, /* in */
5691 unsigned int *fourcc, /* out */
5692 unsigned int *luma_stride, /* out */
5693 unsigned int *chroma_u_stride, /* out */
5694 unsigned int *chroma_v_stride, /* out */
5695 unsigned int *luma_offset, /* out */
5696 unsigned int *chroma_u_offset, /* out */
5697 unsigned int *chroma_v_offset, /* out */
5698 unsigned int *buffer_name, /* out */
5699 void **buffer /* out */
5702 VAStatus vaStatus = VA_STATUS_SUCCESS;
5703 struct i965_driver_data *i965 = i965_driver_data(ctx);
5704 struct object_surface *obj_surface = NULL;
5707 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5708 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5709 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5710 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5711 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5712 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5713 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5714 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5715 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5717 tmpImage.image_id = VA_INVALID_ID;
5719 obj_surface = SURFACE(surface);
5720 if (obj_surface == NULL) {
5721 // Surface is absent.
5722 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5726 // Lock functionality is absent now.
5727 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5728 // Surface is locked already.
5729 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5733 vaStatus = i965_DeriveImage(
5737 if (vaStatus != VA_STATUS_SUCCESS) {
5741 obj_surface->locked_image_id = tmpImage.image_id;
5743 vaStatus = i965_MapBuffer(
5747 if (vaStatus != VA_STATUS_SUCCESS) {
5751 *fourcc = tmpImage.format.fourcc;
5752 *luma_offset = tmpImage.offsets[0];
5753 *luma_stride = tmpImage.pitches[0];
5754 *chroma_u_offset = tmpImage.offsets[1];
5755 *chroma_u_stride = tmpImage.pitches[1];
5756 *chroma_v_offset = tmpImage.offsets[2];
5757 *chroma_v_stride = tmpImage.pitches[2];
5758 *buffer_name = tmpImage.buf;
5761 if (vaStatus != VA_STATUS_SUCCESS) {
5770 VADriverContextP ctx, /* in */
5771 VASurfaceID surface /* in */
5774 VAStatus vaStatus = VA_STATUS_SUCCESS;
5775 struct i965_driver_data *i965 = i965_driver_data(ctx);
5776 struct object_image *locked_img = NULL;
5777 struct object_surface *obj_surface = NULL;
5779 obj_surface = SURFACE(surface);
5781 if (obj_surface == NULL) {
5782 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5785 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5786 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5790 locked_img = IMAGE(obj_surface->locked_image_id);
5791 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5792 // Work image was deallocated before i965_UnlockSurface()
5793 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5797 vaStatus = i965_UnmapBuffer(
5799 locked_img->image.buf);
5800 if (vaStatus != VA_STATUS_SUCCESS) {
5804 vaStatus = i965_DestroyImage(
5806 locked_img->image.image_id);
5807 if (vaStatus != VA_STATUS_SUCCESS) {
5811 locked_img->image.image_id = VA_INVALID_ID;
5814 obj_surface->locked_image_id = VA_INVALID_ID;
5820 i965_GetSurfaceAttributes(
5821 VADriverContextP ctx,
5823 VASurfaceAttrib *attrib_list,
5824 unsigned int num_attribs
5827 VAStatus vaStatus = VA_STATUS_SUCCESS;
5828 struct i965_driver_data *i965 = i965_driver_data(ctx);
5829 struct object_config *obj_config;
5832 if (config == VA_INVALID_ID)
5833 return VA_STATUS_ERROR_INVALID_CONFIG;
5835 obj_config = CONFIG(config);
5837 if (obj_config == NULL)
5838 return VA_STATUS_ERROR_INVALID_CONFIG;
5840 if (attrib_list == NULL || num_attribs == 0)
5841 return VA_STATUS_ERROR_INVALID_PARAMETER;
5843 for (i = 0; i < num_attribs; i++) {
5844 switch (attrib_list[i].type) {
5845 case VASurfaceAttribPixelFormat:
5846 attrib_list[i].value.type = VAGenericValueTypeInteger;
5847 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5849 if (attrib_list[i].value.value.i == 0) {
5850 if (IS_G4X(i965->intel.device_info)) {
5851 if (obj_config->profile == VAProfileMPEG2Simple ||
5852 obj_config->profile == VAProfileMPEG2Main) {
5853 attrib_list[i].value.value.i = VA_FOURCC_I420;
5856 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5858 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5859 if (obj_config->profile == VAProfileMPEG2Simple ||
5860 obj_config->profile == VAProfileMPEG2Main) {
5861 attrib_list[i].value.value.i = VA_FOURCC_I420;
5862 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5863 obj_config->profile == VAProfileH264Main ||
5864 obj_config->profile == VAProfileH264High) {
5865 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5866 } else if (obj_config->profile == VAProfileNone) {
5867 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5870 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5872 } else if (IS_GEN6(i965->intel.device_info)) {
5873 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5874 } else if (IS_GEN7(i965->intel.device_info) ||
5875 IS_GEN8(i965->intel.device_info) ||
5876 IS_GEN9(i965->intel.device_info) ||
5877 IS_GEN10(i965->intel.device_info)) {
5878 if (obj_config->profile == VAProfileJPEGBaseline)
5879 attrib_list[i].value.value.i = 0; /* internal format */
5881 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5884 if (IS_G4X(i965->intel.device_info)) {
5885 if (obj_config->profile == VAProfileMPEG2Simple ||
5886 obj_config->profile == VAProfileMPEG2Main) {
5887 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5888 attrib_list[i].value.value.i = 0;
5889 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5893 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5895 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5896 if (obj_config->profile == VAProfileMPEG2Simple ||
5897 obj_config->profile == VAProfileMPEG2Main) {
5898 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5899 attrib_list[i].value.value.i = 0;
5900 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5902 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5903 obj_config->profile == VAProfileH264Main ||
5904 obj_config->profile == VAProfileH264High) {
5905 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5906 attrib_list[i].value.value.i = 0;
5907 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5909 } else if (obj_config->profile == VAProfileNone) {
5910 switch (attrib_list[i].value.value.i) {
5911 case VA_FOURCC_NV12:
5912 case VA_FOURCC_I420:
5913 case VA_FOURCC_YV12:
5914 case VA_FOURCC_YUY2:
5915 case VA_FOURCC_BGRA:
5916 case VA_FOURCC_BGRX:
5917 case VA_FOURCC_RGBX:
5918 case VA_FOURCC_RGBA:
5921 attrib_list[i].value.value.i = 0;
5922 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5927 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5929 } else if (IS_GEN6(i965->intel.device_info)) {
5930 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5931 obj_config->entrypoint == VAEntrypointVideoProc) {
5932 switch (attrib_list[i].value.value.i) {
5933 case VA_FOURCC_NV12:
5934 case VA_FOURCC_I420:
5935 case VA_FOURCC_YV12:
5936 case VA_FOURCC_YUY2:
5937 case VA_FOURCC_BGRA:
5938 case VA_FOURCC_BGRX:
5939 case VA_FOURCC_RGBX:
5940 case VA_FOURCC_RGBA:
5943 attrib_list[i].value.value.i = 0;
5944 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5948 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5949 attrib_list[i].value.value.i = 0;
5950 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5953 } else if (IS_GEN7(i965->intel.device_info) ||
5954 IS_GEN8(i965->intel.device_info) ||
5955 IS_GEN9(i965->intel.device_info) ||
5956 IS_GEN10(i965->intel.device_info)) {
5957 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5958 obj_config->entrypoint == VAEntrypointVideoProc ||
5959 obj_config->entrypoint == VAEntrypointEncSliceLP ||
5960 obj_config->entrypoint == VAEntrypointFEI) {
5961 switch (attrib_list[i].value.value.i) {
5962 case VA_FOURCC_NV12:
5963 case VA_FOURCC_I420:
5964 case VA_FOURCC_YV12:
5967 attrib_list[i].value.value.i = 0;
5968 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5971 } else if (obj_config->entrypoint == VAEntrypointStats) {
5972 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5973 attrib_list[i].value.value.i = 0;
5974 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5977 if (obj_config->profile == VAProfileJPEGBaseline) {
5978 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5979 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5981 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5982 attrib_list[i].value.value.i = 0;
5983 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5991 case VASurfaceAttribMinWidth:
5992 /* FIXME: add support for it later */
5993 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5995 case VASurfaceAttribMaxWidth:
5996 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5998 case VASurfaceAttribMinHeight:
5999 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
6001 case VASurfaceAttribMaxHeight:
6002 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
6005 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
6014 i965_QuerySurfaceAttributes(VADriverContextP ctx,
6016 VASurfaceAttrib *attrib_list,
6017 unsigned int *num_attribs)
6019 VAStatus vaStatus = VA_STATUS_SUCCESS;
6020 struct i965_driver_data *i965 = i965_driver_data(ctx);
6021 struct object_config *obj_config;
6023 VASurfaceAttrib *attribs = NULL;
6027 if (config == VA_INVALID_ID)
6028 return VA_STATUS_ERROR_INVALID_CONFIG;
6030 obj_config = CONFIG(config);
6032 if (obj_config == NULL)
6033 return VA_STATUS_ERROR_INVALID_CONFIG;
6035 if (!attrib_list && !num_attribs)
6036 return VA_STATUS_ERROR_INVALID_PARAMETER;
6038 if (attrib_list == NULL) {
6039 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
6040 return VA_STATUS_SUCCESS;
6043 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES * sizeof(*attribs));
6045 if (attribs == NULL)
6046 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6048 if (IS_G4X(i965->intel.device_info)) {
6049 if (obj_config->profile == VAProfileMPEG2Simple ||
6050 obj_config->profile == VAProfileMPEG2Main) {
6051 attribs[i].type = VASurfaceAttribPixelFormat;
6052 attribs[i].value.type = VAGenericValueTypeInteger;
6053 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6054 attribs[i].value.value.i = VA_FOURCC_I420;
6057 } else if (IS_IRONLAKE(i965->intel.device_info)) {
6058 switch (obj_config->profile) {
6059 case VAProfileMPEG2Simple:
6060 case VAProfileMPEG2Main:
6061 attribs[i].type = VASurfaceAttribPixelFormat;
6062 attribs[i].value.type = VAGenericValueTypeInteger;
6063 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6064 attribs[i].value.value.i = VA_FOURCC_I420;
6069 case VAProfileH264ConstrainedBaseline:
6070 case VAProfileH264Main:
6071 case VAProfileH264High:
6072 attribs[i].type = VASurfaceAttribPixelFormat;
6073 attribs[i].value.type = VAGenericValueTypeInteger;
6074 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6075 attribs[i].value.value.i = VA_FOURCC_NV12;
6081 attribs[i].type = VASurfaceAttribPixelFormat;
6082 attribs[i].value.type = VAGenericValueTypeInteger;
6083 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6084 attribs[i].value.value.i = VA_FOURCC_NV12;
6087 attribs[i].type = VASurfaceAttribPixelFormat;
6088 attribs[i].value.type = VAGenericValueTypeInteger;
6089 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6090 attribs[i].value.value.i = VA_FOURCC_I420;
6098 } else if (IS_GEN6(i965->intel.device_info)) {
6099 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
6100 attribs[i].type = VASurfaceAttribPixelFormat;
6101 attribs[i].value.type = VAGenericValueTypeInteger;
6102 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6103 attribs[i].value.value.i = VA_FOURCC_NV12;
6105 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6106 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
6107 attribs[i].type = VASurfaceAttribPixelFormat;
6108 attribs[i].value.type = VAGenericValueTypeInteger;
6109 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6110 attribs[i].value.value.i = VA_FOURCC_NV12;
6113 attribs[i].type = VASurfaceAttribPixelFormat;
6114 attribs[i].value.type = VAGenericValueTypeInteger;
6115 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6116 attribs[i].value.value.i = VA_FOURCC_I420;
6119 attribs[i].type = VASurfaceAttribPixelFormat;
6120 attribs[i].value.type = VAGenericValueTypeInteger;
6121 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6122 attribs[i].value.value.i = VA_FOURCC_YV12;
6125 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6126 attribs[i].type = VASurfaceAttribPixelFormat;
6127 attribs[i].value.type = VAGenericValueTypeInteger;
6128 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6129 attribs[i].value.value.i = VA_FOURCC_YUY2;
6132 attribs[i].type = VASurfaceAttribPixelFormat;
6133 attribs[i].value.type = VAGenericValueTypeInteger;
6134 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6135 attribs[i].value.value.i = VA_FOURCC_RGBA;
6138 attribs[i].type = VASurfaceAttribPixelFormat;
6139 attribs[i].value.type = VAGenericValueTypeInteger;
6140 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6141 attribs[i].value.value.i = VA_FOURCC_RGBX;
6145 } else if (IS_GEN7(i965->intel.device_info)) {
6146 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
6147 if (obj_config->profile == VAProfileJPEGBaseline) {
6148 attribs[i].type = VASurfaceAttribPixelFormat;
6149 attribs[i].value.type = VAGenericValueTypeInteger;
6150 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6151 attribs[i].value.value.i = VA_FOURCC_IMC3;
6154 attribs[i].type = VASurfaceAttribPixelFormat;
6155 attribs[i].value.type = VAGenericValueTypeInteger;
6156 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6157 attribs[i].value.value.i = VA_FOURCC_IMC1;
6160 attribs[i].type = VASurfaceAttribPixelFormat;
6161 attribs[i].value.type = VAGenericValueTypeInteger;
6162 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6163 attribs[i].value.value.i = VA_FOURCC_Y800;
6166 attribs[i].type = VASurfaceAttribPixelFormat;
6167 attribs[i].value.type = VAGenericValueTypeInteger;
6168 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6169 attribs[i].value.value.i = VA_FOURCC_411P;
6172 attribs[i].type = VASurfaceAttribPixelFormat;
6173 attribs[i].value.type = VAGenericValueTypeInteger;
6174 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6175 attribs[i].value.value.i = VA_FOURCC_422H;
6178 attribs[i].type = VASurfaceAttribPixelFormat;
6179 attribs[i].value.type = VAGenericValueTypeInteger;
6180 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6181 attribs[i].value.value.i = VA_FOURCC_422V;
6184 attribs[i].type = VASurfaceAttribPixelFormat;
6185 attribs[i].value.type = VAGenericValueTypeInteger;
6186 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6187 attribs[i].value.value.i = VA_FOURCC_444P;
6189 } else if (obj_config->profile == VAProfileHEVCMain10) {
6190 attribs[i].type = VASurfaceAttribPixelFormat;
6191 attribs[i].value.type = VAGenericValueTypeInteger;
6192 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6193 attribs[i].value.value.i = VA_FOURCC_P010;
6196 attribs[i].type = VASurfaceAttribPixelFormat;
6197 attribs[i].value.type = VAGenericValueTypeInteger;
6198 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6199 attribs[i].value.value.i = VA_FOURCC_NV12;
6202 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6203 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
6204 attribs[i].type = VASurfaceAttribPixelFormat;
6205 attribs[i].value.type = VAGenericValueTypeInteger;
6206 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6207 attribs[i].value.value.i = VA_FOURCC_NV12;
6210 attribs[i].type = VASurfaceAttribPixelFormat;
6211 attribs[i].value.type = VAGenericValueTypeInteger;
6212 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6213 attribs[i].value.value.i = VA_FOURCC_I420;
6216 attribs[i].type = VASurfaceAttribPixelFormat;
6217 attribs[i].value.type = VAGenericValueTypeInteger;
6218 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6219 attribs[i].value.value.i = VA_FOURCC_YV12;
6222 attribs[i].type = VASurfaceAttribPixelFormat;
6223 attribs[i].value.type = VAGenericValueTypeInteger;
6224 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6225 attribs[i].value.value.i = VA_FOURCC_IMC3;
6228 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6229 attribs[i].type = VASurfaceAttribPixelFormat;
6230 attribs[i].value.type = VAGenericValueTypeInteger;
6231 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6232 attribs[i].value.value.i = VA_FOURCC_YUY2;
6235 attribs[i].type = VASurfaceAttribPixelFormat;
6236 attribs[i].value.type = VAGenericValueTypeInteger;
6237 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6238 attribs[i].value.value.i = VA_FOURCC_UYVY;
6241 attribs[i].type = VASurfaceAttribPixelFormat;
6242 attribs[i].value.type = VAGenericValueTypeInteger;
6243 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6244 attribs[i].value.value.i = VA_FOURCC_RGBA;
6247 attribs[i].type = VASurfaceAttribPixelFormat;
6248 attribs[i].value.type = VAGenericValueTypeInteger;
6249 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6250 attribs[i].value.value.i = VA_FOURCC_RGBX;
6253 attribs[i].type = VASurfaceAttribPixelFormat;
6254 attribs[i].value.type = VAGenericValueTypeInteger;
6255 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6256 attribs[i].value.value.i = VA_FOURCC_BGRA;
6259 attribs[i].type = VASurfaceAttribPixelFormat;
6260 attribs[i].value.type = VAGenericValueTypeInteger;
6261 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6262 attribs[i].value.value.i = VA_FOURCC_BGRX;
6265 attribs[i].type = VASurfaceAttribPixelFormat;
6266 attribs[i].value.type = VAGenericValueTypeInteger;
6267 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6268 attribs[i].value.value.i = VA_FOURCC_YV16;
6272 } else if (IS_GEN8(i965->intel.device_info) ||
6273 IS_GEN9(i965->intel.device_info) ||
6274 IS_GEN10(i965->intel.device_info)) {
6275 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
6276 if (obj_config->profile == VAProfileJPEGBaseline) {
6277 attribs[i].type = VASurfaceAttribPixelFormat;
6278 attribs[i].value.type = VAGenericValueTypeInteger;
6279 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6280 attribs[i].value.value.i = VA_FOURCC_IMC3;
6283 attribs[i].type = VASurfaceAttribPixelFormat;
6284 attribs[i].value.type = VAGenericValueTypeInteger;
6285 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6286 attribs[i].value.value.i = VA_FOURCC_IMC1;
6289 attribs[i].type = VASurfaceAttribPixelFormat;
6290 attribs[i].value.type = VAGenericValueTypeInteger;
6291 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6292 attribs[i].value.value.i = VA_FOURCC_Y800;
6295 attribs[i].type = VASurfaceAttribPixelFormat;
6296 attribs[i].value.type = VAGenericValueTypeInteger;
6297 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6298 attribs[i].value.value.i = VA_FOURCC_411P;
6301 attribs[i].type = VASurfaceAttribPixelFormat;
6302 attribs[i].value.type = VAGenericValueTypeInteger;
6303 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6304 attribs[i].value.value.i = VA_FOURCC_422H;
6307 attribs[i].type = VASurfaceAttribPixelFormat;
6308 attribs[i].value.type = VAGenericValueTypeInteger;
6309 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6310 attribs[i].value.value.i = VA_FOURCC_422V;
6313 attribs[i].type = VASurfaceAttribPixelFormat;
6314 attribs[i].value.type = VAGenericValueTypeInteger;
6315 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6316 attribs[i].value.value.i = VA_FOURCC_444P;
6319 attribs[i].type = VASurfaceAttribPixelFormat;
6320 attribs[i].value.type = VAGenericValueTypeInteger;
6321 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6322 attribs[i].value.value.i = VA_FOURCC_NV12;
6325 if ((obj_config->profile == VAProfileHEVCMain10) ||
6326 (obj_config->profile == VAProfileVP9Profile2)) {
6327 attribs[i].type = VASurfaceAttribPixelFormat;
6328 attribs[i].value.type = VAGenericValueTypeInteger;
6329 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6330 attribs[i].value.value.i = VA_FOURCC_P010;
6334 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6335 obj_config->entrypoint == VAEntrypointVideoProc ||
6336 obj_config->entrypoint == VAEntrypointEncSliceLP ||
6337 obj_config->entrypoint == VAEntrypointEncPicture ||
6338 obj_config->entrypoint == VAEntrypointFEI) {
6340 if (obj_config->profile == VAProfileHEVCMain10) {
6341 attribs[i].type = VASurfaceAttribPixelFormat;
6342 attribs[i].value.type = VAGenericValueTypeInteger;
6343 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6344 attribs[i].value.value.i = VA_FOURCC_P010;
6347 attribs[i].type = VASurfaceAttribPixelFormat;
6348 attribs[i].value.type = VAGenericValueTypeInteger;
6349 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6350 attribs[i].value.value.i = VA_FOURCC_NV12;
6353 attribs[i].type = VASurfaceAttribPixelFormat;
6354 attribs[i].value.type = VAGenericValueTypeInteger;
6355 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6356 attribs[i].value.value.i = VA_FOURCC_I420;
6359 attribs[i].type = VASurfaceAttribPixelFormat;
6360 attribs[i].value.type = VAGenericValueTypeInteger;
6361 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6362 attribs[i].value.value.i = VA_FOURCC_YV12;
6365 attribs[i].type = VASurfaceAttribPixelFormat;
6366 attribs[i].value.type = VAGenericValueTypeInteger;
6367 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6368 attribs[i].value.value.i = VA_FOURCC_IMC3;
6372 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6373 attribs[i].type = VASurfaceAttribPixelFormat;
6374 attribs[i].value.type = VAGenericValueTypeInteger;
6375 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6376 attribs[i].value.value.i = VA_FOURCC_YUY2;
6379 attribs[i].type = VASurfaceAttribPixelFormat;
6380 attribs[i].value.type = VAGenericValueTypeInteger;
6381 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6382 attribs[i].value.value.i = VA_FOURCC_UYVY;
6385 attribs[i].type = VASurfaceAttribPixelFormat;
6386 attribs[i].value.type = VAGenericValueTypeInteger;
6387 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6388 attribs[i].value.value.i = VA_FOURCC_RGBA;
6391 attribs[i].type = VASurfaceAttribPixelFormat;
6392 attribs[i].value.type = VAGenericValueTypeInteger;
6393 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6394 attribs[i].value.value.i = VA_FOURCC_RGBX;
6397 attribs[i].type = VASurfaceAttribPixelFormat;
6398 attribs[i].value.type = VAGenericValueTypeInteger;
6399 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6400 attribs[i].value.value.i = VA_FOURCC_BGRA;
6403 attribs[i].type = VASurfaceAttribPixelFormat;
6404 attribs[i].value.type = VAGenericValueTypeInteger;
6405 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6406 attribs[i].value.value.i = VA_FOURCC_BGRX;
6409 attribs[i].type = VASurfaceAttribPixelFormat;
6410 attribs[i].value.type = VAGenericValueTypeInteger;
6411 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6412 attribs[i].value.value.i = VA_FOURCC_YV16;
6415 if (HAS_VPP_P010(i965)) {
6416 attribs[i].type = VASurfaceAttribPixelFormat;
6417 attribs[i].value.type = VAGenericValueTypeInteger;
6418 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6419 attribs[i].value.value.i = VA_FOURCC_P010;
6422 attribs[i].type = VASurfaceAttribPixelFormat;
6423 attribs[i].value.type = VAGenericValueTypeInteger;
6424 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6425 attribs[i].value.value.i = VA_FOURCC_I010;
6430 /* Additional support for jpeg encoder */
6431 if (obj_config->profile == VAProfileJPEGBaseline
6432 && obj_config->entrypoint == VAEntrypointEncPicture) {
6433 attribs[i].type = VASurfaceAttribPixelFormat;
6434 attribs[i].value.type = VAGenericValueTypeInteger;
6435 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6436 attribs[i].value.value.i = VA_FOURCC_YUY2;
6439 attribs[i].type = VASurfaceAttribPixelFormat;
6440 attribs[i].value.type = VAGenericValueTypeInteger;
6441 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6442 attribs[i].value.value.i = VA_FOURCC_UYVY;
6445 attribs[i].type = VASurfaceAttribPixelFormat;
6446 attribs[i].value.type = VAGenericValueTypeInteger;
6447 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6448 attribs[i].value.value.i = VA_FOURCC_YV16;
6451 attribs[i].type = VASurfaceAttribPixelFormat;
6452 attribs[i].value.type = VAGenericValueTypeInteger;
6453 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6454 attribs[i].value.value.i = VA_FOURCC_Y800;
6457 } else if (obj_config->entrypoint == VAEntrypointStats) {
6458 attribs[i].type = VASurfaceAttribPixelFormat;
6459 attribs[i].value.type = VAGenericValueTypeInteger;
6460 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6461 attribs[i].value.value.i = VA_FOURCC_NV12;
6466 attribs[i].type = VASurfaceAttribMemoryType;
6467 attribs[i].value.type = VAGenericValueTypeInteger;
6468 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6469 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
6470 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
6471 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
6474 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
6475 attribs[i].value.type = VAGenericValueTypePointer;
6476 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
6477 attribs[i].value.value.p = NULL; /* ignore */
6480 max_resolution(i965, obj_config, &max_width, &max_height);
6482 attribs[i].type = VASurfaceAttribMaxWidth;
6483 attribs[i].value.type = VAGenericValueTypeInteger;
6484 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6485 attribs[i].value.value.i = max_width;
6488 attribs[i].type = VASurfaceAttribMaxHeight;
6489 attribs[i].value.type = VAGenericValueTypeInteger;
6490 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6491 attribs[i].value.value.i = max_height;
6494 if (obj_config->entrypoint == VAEntrypointEncSlice ||
6495 obj_config->entrypoint == VAEntrypointEncSliceLP ||
6496 obj_config->entrypoint == VAEntrypointEncPicture ||
6497 obj_config->entrypoint == VAEntrypointFEI) {
6498 attribs[i].type = VASurfaceAttribMinWidth;
6499 attribs[i].value.type = VAGenericValueTypeInteger;
6500 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6501 attribs[i].value.value.i = I965_MIN_CODEC_ENC_RESOLUTION_WIDTH_HEIGHT;
6502 if (obj_config->profile == VAProfileJPEGBaseline)
6503 attribs[i].value.value.i = 1;
6506 attribs[i].type = VASurfaceAttribMinHeight;
6507 attribs[i].value.type = VAGenericValueTypeInteger;
6508 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6509 attribs[i].value.value.i = I965_MIN_CODEC_ENC_RESOLUTION_WIDTH_HEIGHT;
6510 if (obj_config->profile == VAProfileJPEGBaseline)
6511 attribs[i].value.value.i = 1;
6515 if (i > *num_attribs) {
6518 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6522 memcpy(attrib_list, attribs, i * sizeof(*attribs));
6528 /* Acquires buffer handle for external API usage (internal implementation) */
6530 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
6531 uint32_t mem_type, VABufferInfo *out_buf_info)
6533 struct buffer_store *buffer_store;
6535 buffer_store = obj_buffer->buffer_store;
6536 if (!buffer_store || !buffer_store->bo)
6537 return VA_STATUS_ERROR_INVALID_BUFFER;
6539 /* Synchronization point */
6540 drm_intel_bo_wait_rendering(buffer_store->bo);
6542 if (obj_buffer->export_refcount > 0) {
6543 if (obj_buffer->export_state.mem_type != mem_type)
6544 return VA_STATUS_ERROR_INVALID_PARAMETER;
6546 VABufferInfo * const buf_info = &obj_buffer->export_state;
6549 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
6551 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
6552 return VA_STATUS_ERROR_INVALID_BUFFER;
6553 buf_info->handle = name;
6556 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6558 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
6559 return VA_STATUS_ERROR_INVALID_BUFFER;
6560 buf_info->handle = (intptr_t)fd;
6565 buf_info->type = obj_buffer->type;
6566 buf_info->mem_type = mem_type;
6567 buf_info->mem_size =
6568 obj_buffer->num_elements * obj_buffer->size_element;
6571 obj_buffer->export_refcount++;
6572 *out_buf_info = obj_buffer->export_state;
6573 return VA_STATUS_SUCCESS;
6576 /* Releases buffer handle after usage (internal implementation) */
6578 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6580 if (obj_buffer->export_refcount == 0)
6581 return VA_STATUS_ERROR_INVALID_BUFFER;
6583 if (--obj_buffer->export_refcount == 0) {
6584 VABufferInfo * const buf_info = &obj_buffer->export_state;
6586 switch (buf_info->mem_type) {
6587 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6588 close((intptr_t)buf_info->handle);
6592 buf_info->mem_type = 0;
6594 return VA_STATUS_SUCCESS;
6597 /** Acquires buffer handle for external API usage */
6599 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6600 VABufferInfo *buf_info)
6602 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6603 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6604 uint32_t i, mem_type;
6606 /* List of supported memory types, in preferred order */
6607 static const uint32_t mem_types[] = {
6608 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6609 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6614 return VA_STATUS_ERROR_INVALID_BUFFER;
6615 /* XXX: only VA surface|image like buffers are supported for now */
6616 if (obj_buffer->type != VAImageBufferType)
6617 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6620 * As the allocated buffer by calling vaCreateBuffer is related with
6621 * the specific context, it is unnecessary to export it.
6622 * So it is not supported when the buffer is allocated from wrapped
6625 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6626 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6630 return VA_STATUS_ERROR_INVALID_PARAMETER;
6632 if (!buf_info->mem_type)
6633 mem_type = mem_types[0];
6636 for (i = 0; mem_types[i] != 0; i++) {
6637 if (buf_info->mem_type & mem_types[i]) {
6638 mem_type = buf_info->mem_type;
6643 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6645 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6648 /** Releases buffer handle after usage from external API */
6650 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6652 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6653 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6656 return VA_STATUS_ERROR_INVALID_BUFFER;
6658 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6659 return VA_STATUS_ERROR_INVALID_BUFFER;
6662 return i965_release_buffer_handle(obj_buffer);
6665 // Locally define DRM_FORMAT values not available in older but still
6666 // supported versions of libdrm.
6667 #ifndef DRM_FORMAT_R8
6668 #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ')
6670 #ifndef DRM_FORMAT_R16
6671 #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ')
6673 #ifndef DRM_FORMAT_GR88
6674 #define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8')
6676 #ifndef DRM_FORMAT_GR1616
6677 #define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2')
6680 static uint32_t drm_format_of_separate_plane(uint32_t fourcc, int plane)
6684 case VA_FOURCC_NV12:
6685 case VA_FOURCC_I420:
6686 case VA_FOURCC_YV12:
6687 case VA_FOURCC_YV16:
6688 case VA_FOURCC_Y800:
6689 return DRM_FORMAT_R8;
6690 case VA_FOURCC_P010:
6691 case VA_FOURCC_I010:
6692 return DRM_FORMAT_R16;
6694 case VA_FOURCC_YUY2:
6695 case VA_FOURCC_UYVY:
6696 // These are not representable as separate planes.
6699 case VA_FOURCC_RGBA:
6700 return DRM_FORMAT_ABGR8888;
6701 case VA_FOURCC_RGBX:
6702 return DRM_FORMAT_XBGR8888;
6703 case VA_FOURCC_BGRA:
6704 return DRM_FORMAT_ARGB8888;
6705 case VA_FOURCC_BGRX:
6706 return DRM_FORMAT_XRGB8888;
6707 case VA_FOURCC_ARGB:
6708 return DRM_FORMAT_BGRA8888;
6709 case VA_FOURCC_ABGR:
6710 return DRM_FORMAT_RGBA8888;
6714 case VA_FOURCC_NV12:
6715 return DRM_FORMAT_GR88;
6716 case VA_FOURCC_I420:
6717 case VA_FOURCC_YV12:
6718 case VA_FOURCC_YV16:
6719 return DRM_FORMAT_R8;
6720 case VA_FOURCC_P010:
6721 return DRM_FORMAT_GR1616;
6722 case VA_FOURCC_I010:
6723 return DRM_FORMAT_R16;
6729 static uint32_t drm_format_of_composite_object(uint32_t fourcc)
6732 case VA_FOURCC_NV12:
6733 return DRM_FORMAT_NV12;
6734 case VA_FOURCC_I420:
6735 return DRM_FORMAT_YUV420;
6736 case VA_FOURCC_YV12:
6737 return DRM_FORMAT_YVU420;
6738 case VA_FOURCC_YV16:
6739 return DRM_FORMAT_YVU422;
6740 case VA_FOURCC_YUY2:
6741 return DRM_FORMAT_YUYV;
6742 case VA_FOURCC_UYVY:
6743 return DRM_FORMAT_UYVY;
6744 case VA_FOURCC_Y800:
6745 return DRM_FORMAT_R8;
6747 case VA_FOURCC_P010:
6748 case VA_FOURCC_I010:
6749 // These currently have no composite DRM format - they are usable
6750 // only as separate planes.
6753 case VA_FOURCC_RGBA:
6754 return DRM_FORMAT_ABGR8888;
6755 case VA_FOURCC_RGBX:
6756 return DRM_FORMAT_XBGR8888;
6757 case VA_FOURCC_BGRA:
6758 return DRM_FORMAT_ARGB8888;
6759 case VA_FOURCC_BGRX:
6760 return DRM_FORMAT_XRGB8888;
6761 case VA_FOURCC_ARGB:
6762 return DRM_FORMAT_BGRA8888;
6763 case VA_FOURCC_ABGR:
6764 return DRM_FORMAT_RGBA8888;
6770 i965_ExportSurfaceHandle(VADriverContextP ctx, VASurfaceID surface_id,
6771 uint32_t mem_type, uint32_t flags,
6774 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6775 struct object_surface *obj_surface = SURFACE(surface_id);
6776 const i965_fourcc_info *info;
6777 VADRMPRIMESurfaceDescriptor *desc;
6778 unsigned int tiling, swizzle;
6779 uint32_t formats[4], pitch, height, offset;
6781 int composite_object =
6782 flags & VA_EXPORT_SURFACE_COMPOSED_LAYERS;
6784 if (!obj_surface || !obj_surface->bo)
6785 return VA_STATUS_ERROR_INVALID_SURFACE;
6787 if (mem_type != VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2) {
6788 i965_log_info(ctx, "vaExportSurfaceHandle: memory type %08x "
6789 "is not supported.\n", mem_type);
6790 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6793 info = get_fourcc_info(obj_surface->fourcc);
6795 return VA_STATUS_ERROR_INVALID_SURFACE;
6796 if (composite_object) {
6798 drm_format_of_composite_object(obj_surface->fourcc);
6800 i965_log_info(ctx, "vaExportSurfaceHandle: fourcc %08x "
6801 "is not supported for export as a composite "
6802 "object.\n", obj_surface->fourcc);
6803 return VA_STATUS_ERROR_INVALID_SURFACE;
6806 for (p = 0; p < info->num_planes; p++) {
6808 drm_format_of_separate_plane(obj_surface->fourcc, p);
6810 i965_log_info(ctx, "vaExportSurfaceHandle: fourcc %08x "
6811 "is not supported for export as separate "
6812 "planes.\n", obj_surface->fourcc);
6813 return VA_STATUS_ERROR_INVALID_SURFACE;
6818 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd))
6819 return VA_STATUS_ERROR_INVALID_SURFACE;
6821 if (drm_intel_bo_get_tiling(obj_surface->bo, &tiling, &swizzle))
6822 tiling = I915_TILING_NONE;
6826 desc->fourcc = obj_surface->fourcc;
6827 desc->width = obj_surface->orig_width;
6828 desc->height = obj_surface->orig_height;
6830 desc->num_objects = 1;
6831 desc->objects[0].fd = fd;
6832 desc->objects[0].size = obj_surface->size;
6835 desc->objects[0].drm_format_modifier = I915_FORMAT_MOD_X_TILED;
6838 desc->objects[0].drm_format_modifier = I915_FORMAT_MOD_Y_TILED;
6840 case I915_TILING_NONE:
6842 desc->objects[0].drm_format_modifier = DRM_FORMAT_MOD_NONE;
6845 if (composite_object) {
6846 desc->num_layers = 1;
6848 desc->layers[0].drm_format = formats[0];
6849 desc->layers[0].num_planes = info->num_planes;
6852 for (p = 0; p < info->num_planes; p++) {
6853 desc->layers[0].object_index[p] = 0;
6856 pitch = obj_surface->width;
6857 height = obj_surface->height;
6859 pitch = obj_surface->cb_cr_pitch;
6860 height = obj_surface->cb_cr_height;
6863 desc->layers[0].offset[p] = offset;
6864 desc->layers[0].pitch[p] = pitch;
6866 offset += pitch * height;
6869 desc->num_layers = info->num_planes;
6872 for (p = 0; p < info->num_planes; p++) {
6873 desc->layers[p].drm_format = formats[p];
6874 desc->layers[p].num_planes = 1;
6876 desc->layers[p].object_index[0] = 0;
6879 pitch = obj_surface->width;
6880 height = obj_surface->height;
6882 pitch = obj_surface->cb_cr_pitch;
6883 height = obj_surface->cb_cr_height;
6886 desc->layers[p].offset[0] = offset;
6887 desc->layers[p].pitch[0] = pitch;
6889 offset += pitch * height;
6893 return VA_STATUS_SUCCESS;
6897 i965_os_has_ring_support(VADriverContextP ctx,
6900 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6904 return i965->intel.has_bsd;
6907 return i965->intel.has_blt;
6909 case I965_RING_VEBOX:
6910 return i965->intel.has_vebox;
6912 case I965_RING_NULL:
6913 return 1; /* Always support */
6916 /* should never get here */
6925 * Query video processing pipeline
6927 VAStatus i965_QueryVideoProcFilters(
6928 VADriverContextP ctx,
6929 VAContextID context,
6930 VAProcFilterType *filters,
6931 unsigned int *num_filters
6934 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6935 unsigned int i = 0, num = 0;
6937 if (!num_filters || !filters)
6938 return VA_STATUS_ERROR_INVALID_PARAMETER;
6940 for (i = 0; i < i965->codec_info->num_filters; i++) {
6941 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6942 if (num == *num_filters) {
6943 *num_filters = i965->codec_info->num_filters;
6945 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6948 filters[num++] = i965->codec_info->filters[i].type;
6954 return VA_STATUS_SUCCESS;
6957 VAStatus i965_QueryVideoProcFilterCaps(
6958 VADriverContextP ctx,
6959 VAContextID context,
6960 VAProcFilterType type,
6962 unsigned int *num_filter_caps
6966 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6968 if (!filter_caps || !num_filter_caps)
6969 return VA_STATUS_ERROR_INVALID_PARAMETER;
6971 for (i = 0; i < i965->codec_info->num_filters; i++) {
6972 if (type == i965->codec_info->filters[i].type &&
6973 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6977 if (i == i965->codec_info->num_filters)
6978 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6983 case VAProcFilterNoiseReduction:
6984 case VAProcFilterSharpening: {
6985 VAProcFilterCap *cap = filter_caps;
6987 if (*num_filter_caps < 1) {
6988 *num_filter_caps = 1;
6989 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6992 cap->range.min_value = 0.0;
6993 cap->range.max_value = 1.0;
6994 cap->range.default_value = 0.5;
6995 cap->range.step = 0.03125; /* 1.0 / 32 */
7001 case VAProcFilterDeinterlacing: {
7002 VAProcFilterCapDeinterlacing *cap = filter_caps;
7004 if (*num_filter_caps < VAProcDeinterlacingCount) {
7005 *num_filter_caps = VAProcDeinterlacingCount;
7006 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
7009 cap->type = VAProcDeinterlacingBob;
7014 if (i965->codec_info->has_di_motion_adptive) {
7015 cap->type = VAProcDeinterlacingMotionAdaptive;
7020 if (i965->codec_info->has_di_motion_compensated) {
7021 cap->type = VAProcDeinterlacingMotionCompensated;
7029 case VAProcFilterColorBalance: {
7030 VAProcFilterCapColorBalance *cap = filter_caps;
7032 if (*num_filter_caps < VAProcColorBalanceCount) {
7033 *num_filter_caps = VAProcColorBalanceCount;
7034 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
7037 cap->type = VAProcColorBalanceHue;
7038 cap->range.min_value = -180.0;
7039 cap->range.max_value = 180.0;
7040 cap->range.default_value = 0.0;
7041 cap->range.step = 1.0;
7045 cap->type = VAProcColorBalanceSaturation;
7046 cap->range.min_value = 0.0;
7047 cap->range.max_value = 10.0;
7048 cap->range.default_value = 1.0;
7049 cap->range.step = 0.1;
7053 cap->type = VAProcColorBalanceBrightness;
7054 cap->range.min_value = -100.0;
7055 cap->range.max_value = 100.0;
7056 cap->range.default_value = 0.0;
7057 cap->range.step = 1.0;
7061 cap->type = VAProcColorBalanceContrast;
7062 cap->range.min_value = 0.0;
7063 cap->range.max_value = 10.0;
7064 cap->range.default_value = 1.0;
7065 cap->range.step = 0.1;
7077 *num_filter_caps = i;
7079 return VA_STATUS_SUCCESS;
7082 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
7083 VAProcColorStandardBT601,
7086 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
7087 VAProcColorStandardBT601,
7090 VAStatus i965_QueryVideoProcPipelineCaps(
7091 VADriverContextP ctx,
7092 VAContextID context,
7093 VABufferID *filters,
7094 unsigned int num_filters,
7095 VAProcPipelineCaps *pipeline_cap /* out */
7098 struct i965_driver_data * const i965 = i965_driver_data(ctx);
7101 pipeline_cap->pipeline_flags = 0;
7102 pipeline_cap->filter_flags = 0;
7103 pipeline_cap->num_forward_references = 0;
7104 pipeline_cap->num_backward_references = 0;
7105 pipeline_cap->num_input_color_standards = 1;
7106 pipeline_cap->input_color_standards = vpp_input_color_standards;
7107 pipeline_cap->num_output_color_standards = 1;
7108 pipeline_cap->output_color_standards = vpp_output_color_standards;
7110 for (i = 0; i < num_filters; i++) {
7111 struct object_buffer *obj_buffer = BUFFER(filters[i]);
7114 !obj_buffer->buffer_store ||
7115 !obj_buffer->buffer_store->buffer)
7116 return VA_STATUS_ERROR_INVALID_BUFFER;
7118 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
7120 if (base->type == VAProcFilterNoiseReduction) {
7121 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
7123 } else if (base->type == VAProcFilterDeinterlacing) {
7124 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
7126 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
7127 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
7128 deint->algorithm == VAProcDeinterlacingMotionCompensated,
7129 VA_STATUS_ERROR_INVALID_PARAMETER);
7131 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
7132 deint->algorithm == VAProcDeinterlacingMotionCompensated)
7133 pipeline_cap->num_forward_references++;
7134 } else if (base->type == VAProcFilterSkinToneEnhancement) {
7135 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
7140 return VA_STATUS_SUCCESS;
7143 void i965_log_error(VADriverContextP ctx, const char *format, ...)
7147 va_start(vl, format);
7149 if (!ctx->error_callback) {
7150 // No error callback: this is a error message which should be
7151 // user-visible, so print it to stderr instead.
7152 vfprintf(stderr, format, vl);
7154 // Put the message on the stack. If it overruns the size of the
7155 // then it will just be truncated - callers shouldn't be sending
7156 // messages which are too long.
7159 ret = vsnprintf(tmp, sizeof(tmp), format, vl);
7161 ctx->error_callback(ctx, tmp);
7167 void i965_log_info(VADriverContextP ctx, const char *format, ...)
7171 va_start(vl, format);
7173 if (!ctx->info_callback) {
7174 // No info callback: this message is only useful for developers,
7175 // so just discard it.
7177 // Put the message on the stack. If it overruns the size of the
7178 // then it will just be truncated - callers shouldn't be sending
7179 // messages which are too long.
7182 ret = vsnprintf(tmp, sizeof(tmp), format, vl);
7184 ctx->info_callback(ctx, tmp);
7190 extern struct hw_codec_info *i965_get_codec_info(int devid);
7193 i965_driver_data_init(VADriverContextP ctx)
7195 struct i965_driver_data *i965 = i965_driver_data(ctx);
7197 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
7199 if (!i965->codec_info)
7202 if (object_heap_init(&i965->config_heap,
7203 sizeof(struct object_config),
7205 goto err_config_heap;
7206 if (object_heap_init(&i965->context_heap,
7207 sizeof(struct object_context),
7209 goto err_context_heap;
7211 if (object_heap_init(&i965->surface_heap,
7212 sizeof(struct object_surface),
7214 goto err_surface_heap;
7215 if (object_heap_init(&i965->buffer_heap,
7216 sizeof(struct object_buffer),
7218 goto err_buffer_heap;
7219 if (object_heap_init(&i965->image_heap,
7220 sizeof(struct object_image),
7222 goto err_image_heap;
7223 if (object_heap_init(&i965->subpic_heap,
7224 sizeof(struct object_subpic),
7226 goto err_subpic_heap;
7228 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
7229 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
7230 _i965InitMutex(&i965->render_mutex);
7231 _i965InitMutex(&i965->pp_mutex);
7236 object_heap_destroy(&i965->image_heap);
7238 object_heap_destroy(&i965->buffer_heap);
7240 object_heap_destroy(&i965->surface_heap);
7242 object_heap_destroy(&i965->context_heap);
7244 object_heap_destroy(&i965->config_heap);
7251 i965_driver_data_terminate(VADriverContextP ctx)
7253 struct i965_driver_data *i965 = i965_driver_data(ctx);
7255 _i965DestroyMutex(&i965->pp_mutex);
7256 _i965DestroyMutex(&i965->render_mutex);
7259 intel_batchbuffer_free(i965->batch);
7262 intel_batchbuffer_free(i965->pp_batch);
7264 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
7265 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
7266 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
7267 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
7268 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
7269 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
7273 bool (*init)(VADriverContextP ctx);
7274 void (*terminate)(VADriverContextP ctx);
7276 } i965_sub_ops[] = {
7279 intel_driver_terminate,
7284 i965_driver_data_init,
7285 i965_driver_data_terminate,
7290 i965_display_attributes_init,
7291 i965_display_attributes_terminate,
7296 i965_post_processing_init,
7297 i965_post_processing_terminate,
7303 i965_render_terminate,
7307 #ifdef HAVE_VA_WAYLAND
7309 i965_output_wayland_init,
7310 i965_output_wayland_terminate,
7317 i965_output_dri_init,
7318 i965_output_dri_terminate,
7324 i965_gpe_table_init,
7325 i965_gpe_table_terminate,
7331 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
7335 if (i965->va_vendor[0] != '\0')
7339 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
7340 "%s %s driver for %s - %d.%d.%d",
7341 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
7342 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
7343 INTEL_DRIVER_MICRO_VERSION);
7344 if (ret < 0 || ret >= sizeof(i965->va_vendor))
7348 if (INTEL_DRIVER_PRE_VERSION > 0) {
7349 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
7350 ".pre%d", INTEL_DRIVER_PRE_VERSION);
7351 if (ret < 0 || ret >= (sizeof(i965->va_vendor) - len))
7355 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
7356 " (%s)", INTEL_DRIVER_GIT_VERSION);
7357 if (ret < 0 || ret >= (sizeof(i965->va_vendor) - len))
7364 i965->va_vendor[0] = '\0';
7365 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
7369 /* Only when the option of "enable-wrapper" is passed, it is possible
7370 * to initialize/load the wrapper context of backend driver.
7371 * Otherwise it is not loaded.
7373 #if HAVE_HYBRID_CODEC
7376 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
7378 #define DRIVER_EXTENSION "_drv_video.so"
7380 struct i965_driver_data *i965 = i965_driver_data(ctx);
7382 VADriverContextP wrapper_pdrvctx;
7383 struct VADriverVTable *vtable;
7384 char *search_path, *driver_dir;
7386 char driver_path[256];
7387 void *handle = NULL;
7388 VAStatus va_status = VA_STATUS_SUCCESS;
7389 bool driver_loaded = false;
7391 if (HAS_VP9_DECODING(i965)) {
7392 i965->wrapper_pdrvctx = NULL;
7396 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
7397 vtable = calloc(1, sizeof(*vtable));
7399 if (!wrapper_pdrvctx || !vtable) {
7400 fprintf(stderr, "Failed to allocate memory for wrapper \n");
7401 free(wrapper_pdrvctx);
7403 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7406 /* use the same drm_state with CTX */
7407 wrapper_pdrvctx->drm_state = ctx->drm_state;
7408 wrapper_pdrvctx->display_type = ctx->display_type;
7409 wrapper_pdrvctx->vtable = vtable;
7411 search_path = VA_DRIVERS_PATH;
7412 search_path = strdup((const char *)search_path);
7414 driver_dir = strtok_r(search_path, ":", &saveptr);
7415 while (driver_dir && !driver_loaded) {
7416 memset(driver_path, 0, sizeof(driver_path));
7417 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
7419 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
7421 fprintf(stderr, "failed to open %s\n", driver_path);
7422 driver_dir = strtok_r(NULL, ":", &saveptr);
7426 VADriverInit init_func = NULL;
7427 char init_func_s[256];
7430 static const struct {
7433 } compatible_versions[] = {
7434 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
7443 for (i = 0; compatible_versions[i].major >= 0; i++) {
7444 snprintf(init_func_s, sizeof(init_func_s),
7445 "__vaDriverInit_%d_%d",
7446 compatible_versions[i].major,
7447 compatible_versions[i].minor);
7448 init_func = (VADriverInit)dlsym(handle, init_func_s);
7453 if (compatible_versions[i].major < 0) {
7455 fprintf(stderr, "%s has no function %s\n",
7456 driver_path, init_func_s);
7457 driver_dir = strtok_r(NULL, ":", &saveptr);
7462 va_status = (*init_func)(wrapper_pdrvctx);
7464 if (va_status != VA_STATUS_SUCCESS) {
7466 fprintf(stderr, "%s init failed\n", driver_path);
7467 driver_dir = strtok_r(NULL, ":", &saveptr);
7471 wrapper_pdrvctx->handle = handle;
7472 driver_loaded = true;
7478 if (driver_loaded) {
7479 i965->wrapper_pdrvctx = wrapper_pdrvctx;
7480 return VA_STATUS_SUCCESS;
7482 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
7484 free(wrapper_pdrvctx);
7485 return VA_STATUS_ERROR_OPERATION_FAILED;
7491 i965_Init(VADriverContextP ctx)
7493 struct i965_driver_data *i965 = i965_driver_data(ctx);
7495 const char *chipset;
7497 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
7498 if ((i965_sub_ops[i].display_type == 0 ||
7499 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
7500 !i965_sub_ops[i].init(ctx))
7504 if (i == ARRAY_ELEMS(i965_sub_ops)) {
7505 switch (i965->intel.device_id) {
7507 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
7508 #include "i965_pciids.h"
7510 chipset = "Unknown Intel Chipset";
7514 if (!ensure_vendor_string(i965, chipset))
7515 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7517 i965->current_context_id = VA_INVALID_ID;
7519 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
7520 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
7522 #if HAVE_HYBRID_CODEC
7523 i965_initialize_wrapper(ctx, "hybrid");
7526 return VA_STATUS_SUCCESS;
7530 for (; i >= 0; i--) {
7531 if (i965_sub_ops[i].display_type == 0 ||
7532 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
7533 i965_sub_ops[i].terminate(ctx);
7537 return VA_STATUS_ERROR_UNKNOWN;
7542 i965_Terminate(VADriverContextP ctx)
7544 struct i965_driver_data *i965 = i965_driver_data(ctx);
7548 #if HAVE_HYBRID_CODEC
7549 if (i965->wrapper_pdrvctx) {
7550 VADriverContextP pdrvctx;
7551 pdrvctx = i965->wrapper_pdrvctx;
7552 if (pdrvctx->handle) {
7553 pdrvctx->vtable->vaTerminate(pdrvctx);
7554 dlclose(pdrvctx->handle);
7555 pdrvctx->handle = NULL;
7557 free(pdrvctx->vtable);
7559 i965->wrapper_pdrvctx = NULL;
7563 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
7564 if (i965_sub_ops[i - 1].display_type == 0 ||
7565 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
7566 i965_sub_ops[i - 1].terminate(ctx);
7570 ctx->pDriverData = NULL;
7573 return VA_STATUS_SUCCESS;
7577 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
7580 VA_DRIVER_INIT_FUNC(VADriverContextP ctx)
7582 struct VADriverVTable * const vtable = ctx->vtable;
7583 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
7585 struct i965_driver_data *i965;
7586 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
7588 ctx->version_major = VA_MAJOR_VERSION;
7589 ctx->version_minor = VA_MINOR_VERSION;
7590 ctx->max_profiles = I965_MAX_PROFILES;
7591 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
7592 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
7593 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
7594 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
7595 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
7597 vtable->vaTerminate = i965_Terminate;
7598 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
7599 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
7600 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
7601 vtable->vaCreateConfig = i965_CreateConfig;
7602 vtable->vaDestroyConfig = i965_DestroyConfig;
7603 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
7604 vtable->vaCreateSurfaces = i965_CreateSurfaces;
7605 vtable->vaDestroySurfaces = i965_DestroySurfaces;
7606 vtable->vaCreateContext = i965_CreateContext;
7607 vtable->vaDestroyContext = i965_DestroyContext;
7608 vtable->vaCreateBuffer = i965_CreateBuffer;
7609 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
7610 vtable->vaMapBuffer = i965_MapBuffer;
7611 vtable->vaUnmapBuffer = i965_UnmapBuffer;
7612 vtable->vaDestroyBuffer = i965_DestroyBuffer;
7613 vtable->vaBeginPicture = i965_BeginPicture;
7614 vtable->vaRenderPicture = i965_RenderPicture;
7615 vtable->vaEndPicture = i965_EndPicture;
7616 vtable->vaSyncSurface = i965_SyncSurface;
7617 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
7618 vtable->vaPutSurface = i965_PutSurface;
7619 vtable->vaQueryImageFormats = i965_QueryImageFormats;
7620 vtable->vaCreateImage = i965_CreateImage;
7621 vtable->vaDeriveImage = i965_DeriveImage;
7622 vtable->vaDestroyImage = i965_DestroyImage;
7623 vtable->vaSetImagePalette = i965_SetImagePalette;
7624 vtable->vaGetImage = i965_GetImage;
7625 vtable->vaPutImage = i965_PutImage;
7626 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
7627 vtable->vaCreateSubpicture = i965_CreateSubpicture;
7628 vtable->vaDestroySubpicture = i965_DestroySubpicture;
7629 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
7630 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
7631 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
7632 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
7633 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
7634 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
7635 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
7636 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
7637 vtable->vaBufferInfo = i965_BufferInfo;
7638 vtable->vaLockSurface = i965_LockSurface;
7639 vtable->vaUnlockSurface = i965_UnlockSurface;
7640 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
7641 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
7642 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
7645 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
7646 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
7649 vtable->vaExportSurfaceHandle = i965_ExportSurfaceHandle;
7651 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
7652 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
7653 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
7655 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
7658 ctx->pDriverData = NULL;
7660 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7663 i965->wrapper_pdrvctx = NULL;
7664 ctx->pDriverData = (void *)i965;
7665 ret = i965_Init(ctx);
7667 if (ret == VA_STATUS_SUCCESS) {
7668 ctx->str_vendor = i965->va_vendor;
7671 ctx->pDriverData = NULL;