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>
35 # include "i965_output_dri.h"
38 #ifdef HAVE_VA_WAYLAND
39 # include "i965_output_wayland.h"
42 #include "intel_version.h"
43 #include "intel_driver.h"
44 #include "intel_memman.h"
45 #include "intel_batchbuffer.h"
46 #include "i965_defines.h"
47 #include "i965_drv_video.h"
48 #include "i965_decoder.h"
49 #include "i965_encoder.h"
51 #include "i965_post_processing.h"
53 #include "gen9_vp9_encapi.h"
55 #define CONFIG_ID_OFFSET 0x01000000
56 #define CONTEXT_ID_OFFSET 0x02000000
57 #define SURFACE_ID_OFFSET 0x04000000
58 #define BUFFER_ID_OFFSET 0x08000000
59 #define IMAGE_ID_OFFSET 0x0a000000
60 #define SUBPIC_ID_OFFSET 0x10000000
62 static int get_sampling_from_fourcc(unsigned int fourcc);
64 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
65 #define IS_VA_X11(ctx) \
66 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
68 /* Check whether we are rendering to Wayland */
69 #define IS_VA_WAYLAND(ctx) \
70 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
73 #define I965_2BITS (I965_BIT << 1)
74 #define I965_4BITS (I965_BIT << 2)
75 #define I965_8BITS (I965_BIT << 3)
76 #define I965_16BITS (I965_BIT << 4)
77 #define I965_32BITS (I965_BIT << 5)
89 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
90 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
91 #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} }
94 #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} }
97 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
99 #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} }
101 #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} }
102 #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} }
103 #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} }
104 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
105 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
107 #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} }
109 #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} }
111 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
113 #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} }
114 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
115 #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} }
116 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
118 #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} }
119 #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} }
121 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
122 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
124 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
125 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
130 #define I_SI (I_S | I_I)
132 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
133 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
134 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
135 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
137 static const i965_fourcc_info i965_fourcc_infos[] = {
138 DEF_YUV(NV12, YUV420, I_SI),
139 DEF_YUV(I420, YUV420, I_SI),
140 DEF_YUV(IYUV, YUV420, I_S),
141 DEF_YUV(IMC3, YUV420, I_S),
142 DEF_YUV(YV12, YUV420, I_SI),
143 DEF_YUV(IMC1, YUV420, I_S),
145 DEF_YUV(P010, YUV420, I_SI),
146 DEF_YUV(I010, YUV420, I_S),
148 DEF_YUV(422H, YUV422H, I_SI),
149 DEF_YUV(422V, YUV422V, I_S),
150 DEF_YUV(YV16, YUV422H, I_S),
151 DEF_YUV(YUY2, YUV422H, I_SI),
152 DEF_YUV(UYVY, YUV422H, I_SI),
154 DEF_YUV(444P, YUV444, I_S),
156 DEF_YUV(411P, YUV411, I_S),
158 DEF_YUV(Y800, YUV400, I_S),
160 DEF_RGB(RGBA, RGBX, I_SI),
161 DEF_RGB(RGBX, RGBX, I_SI),
162 DEF_RGB(BGRA, RGBX, I_SI),
163 DEF_RGB(BGRX, RGBX, I_SI),
165 DEF_RGB(ARGB, RGBX, I_I),
166 DEF_RGB(ABGR, RGBX, I_I),
168 DEF_INDEX(IA88, RGBX, I_I),
169 DEF_INDEX(AI88, RGBX, I_I),
171 DEF_INDEX(IA44, RGBX, I_I),
172 DEF_INDEX(AI44, RGBX, I_I)
175 const i965_fourcc_info *
176 get_fourcc_info(unsigned int fourcc)
180 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
181 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
183 if (info->fourcc == fourcc)
191 get_bpp_from_fourcc(unsigned int fourcc)
193 const i965_fourcc_info *info = get_fourcc_info(fourcc);
195 unsigned int bpp = 0;
200 for (i = 0; i < info->num_planes; i++)
207 I965_SURFACETYPE_RGBA = 1,
208 I965_SURFACETYPE_YUV,
209 I965_SURFACETYPE_INDEXED
212 /* List of supported display attributes */
213 static const VADisplayAttribute i965_display_attributes[] = {
215 VADisplayAttribBrightness,
216 -100, 100, DEFAULT_BRIGHTNESS,
217 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
221 VADisplayAttribContrast,
222 0, 100, DEFAULT_CONTRAST,
223 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
228 -180, 180, DEFAULT_HUE,
229 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
233 VADisplayAttribSaturation,
234 0, 100, DEFAULT_SATURATION,
235 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
239 VADisplayAttribRotation,
240 0, 3, VA_ROTATION_NONE,
241 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
245 /* List of supported image formats */
248 VAImageFormat va_format;
249 } i965_image_format_map_t;
251 static const i965_image_format_map_t
252 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
254 I965_SURFACETYPE_YUV,
255 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, }
258 I965_SURFACETYPE_YUV,
259 { VA_FOURCC_I420, VA_LSB_FIRST, 12, }
262 I965_SURFACETYPE_YUV,
263 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, }
266 I965_SURFACETYPE_YUV,
267 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, }
270 I965_SURFACETYPE_YUV,
271 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, }
274 I965_SURFACETYPE_YUV,
275 { VA_FOURCC_422H, VA_LSB_FIRST, 16, }
278 I965_SURFACETYPE_RGBA,
279 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 }
282 I965_SURFACETYPE_RGBA,
283 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff }
286 I965_SURFACETYPE_YUV,
287 { VA_FOURCC_P010, VA_LSB_FIRST, 24, }
291 /* List of supported subpicture formats */
295 VAImageFormat va_format;
296 unsigned int va_flags;
297 } i965_subpic_format_map_t;
299 #define COMMON_SUBPICTURE_FLAGS \
300 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
301 VA_SUBPICTURE_GLOBAL_ALPHA)
303 static const i965_subpic_format_map_t
304 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
306 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
307 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
308 COMMON_SUBPICTURE_FLAGS
311 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
312 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
313 COMMON_SUBPICTURE_FLAGS
316 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
317 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
318 COMMON_SUBPICTURE_FLAGS
321 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
322 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
323 COMMON_SUBPICTURE_FLAGS
326 I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
328 VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
329 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000
331 COMMON_SUBPICTURE_FLAGS
334 I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
336 VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
337 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
339 COMMON_SUBPICTURE_FLAGS
343 static const i965_subpic_format_map_t *
344 get_subpic_format(const VAImageFormat *va_format)
347 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
348 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
349 if (m->va_format.fourcc == va_format->fourcc &&
350 (m->type == I965_SURFACETYPE_RGBA ?
351 (m->va_format.byte_order == va_format->byte_order &&
352 m->va_format.red_mask == va_format->red_mask &&
353 m->va_format.green_mask == va_format->green_mask &&
354 m->va_format.blue_mask == va_format->blue_mask &&
355 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
361 /* Checks whether the surface is in busy state */
363 is_surface_busy(struct i965_driver_data *i965,
364 struct object_surface *obj_surface)
366 assert(obj_surface != NULL);
368 if (obj_surface->locked_image_id != VA_INVALID_ID)
370 if (obj_surface->derived_image_id != VA_INVALID_ID)
375 /* Checks whether the image is in busy state */
377 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
379 struct object_buffer *obj_buffer;
381 assert(obj_image != NULL);
383 if (obj_image->derived_surface != VA_INVALID_ID &&
384 obj_image->derived_surface == surface)
387 obj_buffer = BUFFER(obj_image->image.buf);
388 if (obj_buffer && obj_buffer->export_refcount > 0)
393 #define I965_PACKED_HEADER_BASE 0
394 #define I965_SEQ_PACKED_HEADER_BASE 0
395 #define I965_SEQ_PACKED_HEADER_END 2
396 #define I965_PIC_PACKED_HEADER_BASE 2
397 #define I965_PACKED_MISC_HEADER_BASE 4
400 va_enc_packed_type_to_idx(int packed_type)
404 if (packed_type & VAEncPackedHeaderMiscMask) {
405 idx = I965_PACKED_MISC_HEADER_BASE;
406 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
407 ASSERT_RET(packed_type > 0, 0);
408 idx += (packed_type - 1);
410 idx = I965_PACKED_HEADER_BASE;
412 switch (packed_type) {
413 case VAEncPackedHeaderSequence:
414 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
417 case VAEncPackedHeaderPicture:
418 idx = I965_PIC_PACKED_HEADER_BASE + 0;
421 case VAEncPackedHeaderSlice:
422 idx = I965_PIC_PACKED_HEADER_BASE + 1;
426 /* Should not get here */
432 ASSERT_RET(idx < 5, 0);
436 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
439 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
441 struct i965_driver_data *i965 = i965_driver_data(ctx);
442 struct object_surface *obj_surface = SURFACE(surface);
443 VAStatus va_status = VA_STATUS_SUCCESS;
446 return VA_STATUS_ERROR_INVALID_SURFACE;
449 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
450 /* the wrapped surface already exists. just return it */
454 if (obj_surface->fourcc == 0)
455 i965_check_alloc_surface_bo(ctx, obj_surface,
456 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
459 * TBD: Support more surface formats.
460 * Currently only NV12 is support as NV12 is used by decoding.
462 if (obj_surface->fourcc != VA_FOURCC_NV12)
463 return VA_STATUS_ERROR_INVALID_PARAMETER;
465 if ((i965->wrapper_pdrvctx == NULL) ||
466 (obj_surface->bo == NULL))
467 return VA_STATUS_ERROR_INVALID_PARAMETER;
471 VASurfaceAttrib attrib_list[2];
472 VASurfaceAttribExternalBuffers buffer_descriptor;
473 VAGenericID wrapper_surface;
475 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
476 return VA_STATUS_ERROR_OPERATION_FAILED;
478 obj_surface->exported_primefd = fd_handle;
480 memset(&attrib_list, 0, sizeof(attrib_list));
481 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
483 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
484 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
485 attrib_list[0].value.value.p = &buffer_descriptor;
486 attrib_list[0].value.type = VAGenericValueTypePointer;
488 attrib_list[1].type = VASurfaceAttribMemoryType;
489 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
490 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
491 attrib_list[1].value.type = VAGenericValueTypeInteger;
493 buffer_descriptor.num_buffers = 1;
494 buffer_descriptor.num_planes = 2;
495 buffer_descriptor.width = obj_surface->orig_width;
496 buffer_descriptor.height = obj_surface->orig_height;
497 buffer_descriptor.pixel_format = obj_surface->fourcc;
498 buffer_descriptor.data_size = obj_surface->size;
499 buffer_descriptor.pitches[0] = obj_surface->width;
500 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
501 buffer_descriptor.offsets[0] = 0;
502 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
503 buffer_descriptor.buffers = (void *)&fd_handle;
505 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
506 vaCreateSurfaces2(i965->wrapper_pdrvctx,
508 obj_surface->orig_width,
509 obj_surface->orig_height,
513 if (va_status == VA_STATUS_SUCCESS) {
514 obj_surface->wrapper_surface = wrapper_surface;
516 /* This needs to be checked */
517 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
525 i965_QueryConfigProfiles(VADriverContextP ctx,
526 VAProfile *profile_list, /* out */
527 int *num_profiles) /* out */
529 struct i965_driver_data * const i965 = i965_driver_data(ctx);
532 if (HAS_MPEG2_DECODING(i965) ||
533 HAS_MPEG2_ENCODING(i965)) {
534 profile_list[i++] = VAProfileMPEG2Simple;
535 profile_list[i++] = VAProfileMPEG2Main;
538 if (HAS_H264_DECODING(i965) ||
539 HAS_H264_ENCODING(i965) ||
540 HAS_LP_H264_ENCODING(i965)) {
541 profile_list[i++] = VAProfileH264ConstrainedBaseline;
542 profile_list[i++] = VAProfileH264Main;
543 profile_list[i++] = VAProfileH264High;
545 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
546 HAS_H264_MVC_ENCODING(i965))
547 profile_list[i++] = VAProfileH264MultiviewHigh;
548 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
549 HAS_H264_MVC_ENCODING(i965))
550 profile_list[i++] = VAProfileH264StereoHigh;
552 if (HAS_VC1_DECODING(i965)) {
553 profile_list[i++] = VAProfileVC1Simple;
554 profile_list[i++] = VAProfileVC1Main;
555 profile_list[i++] = VAProfileVC1Advanced;
559 profile_list[i++] = VAProfileNone;
562 if (HAS_JPEG_DECODING(i965) ||
563 HAS_JPEG_ENCODING(i965)) {
564 profile_list[i++] = VAProfileJPEGBaseline;
567 if (HAS_VP8_DECODING(i965) ||
568 HAS_VP8_ENCODING(i965)) {
569 profile_list[i++] = VAProfileVP8Version0_3;
572 if (HAS_HEVC_DECODING(i965) ||
573 HAS_HEVC_ENCODING(i965)) {
574 profile_list[i++] = VAProfileHEVCMain;
577 if (HAS_HEVC10_DECODING(i965) ||
578 HAS_HEVC10_ENCODING(i965)) {
579 profile_list[i++] = VAProfileHEVCMain10;
582 if (HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
583 HAS_VP9_ENCODING(i965)) {
584 profile_list[i++] = VAProfileVP9Profile0;
587 if (HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
588 profile_list[i++] = VAProfileVP9Profile2;
591 if (i965->wrapper_pdrvctx) {
592 VAProfile wrapper_list[4];
594 VADriverContextP pdrvctx;
597 pdrvctx = i965->wrapper_pdrvctx;
598 CALL_VTABLE(pdrvctx, va_status,
599 vaQueryConfigProfiles(pdrvctx,
600 wrapper_list, &wrapper_num));
602 if (va_status == VA_STATUS_SUCCESS) {
604 for (j = 0; j < wrapper_num; j++)
605 if (wrapper_list[j] != VAProfileNone)
606 profile_list[i++] = wrapper_list[j];
610 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
611 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
614 return VA_STATUS_SUCCESS;
618 i965_QueryConfigEntrypoints(VADriverContextP ctx,
620 VAEntrypoint *entrypoint_list, /* out */
621 int *num_entrypoints) /* out */
623 struct i965_driver_data * const i965 = i965_driver_data(ctx);
627 case VAProfileMPEG2Simple:
628 case VAProfileMPEG2Main:
629 if (HAS_MPEG2_DECODING(i965))
630 entrypoint_list[n++] = VAEntrypointVLD;
632 if (HAS_MPEG2_ENCODING(i965))
633 entrypoint_list[n++] = VAEntrypointEncSlice;
637 case VAProfileH264ConstrainedBaseline:
638 case VAProfileH264Main:
639 case VAProfileH264High:
640 if (HAS_H264_DECODING(i965))
641 entrypoint_list[n++] = VAEntrypointVLD;
643 if (HAS_H264_ENCODING(i965))
644 entrypoint_list[n++] = VAEntrypointEncSlice;
646 if (HAS_LP_H264_ENCODING(i965))
647 entrypoint_list[n++] = VAEntrypointEncSliceLP;
650 case VAProfileH264MultiviewHigh:
651 case VAProfileH264StereoHigh:
652 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
653 entrypoint_list[n++] = VAEntrypointVLD;
655 if (HAS_H264_MVC_ENCODING(i965))
656 entrypoint_list[n++] = VAEntrypointEncSlice;
659 case VAProfileVC1Simple:
660 case VAProfileVC1Main:
661 case VAProfileVC1Advanced:
662 if (HAS_VC1_DECODING(i965))
663 entrypoint_list[n++] = VAEntrypointVLD;
668 entrypoint_list[n++] = VAEntrypointVideoProc;
671 case VAProfileJPEGBaseline:
672 if (HAS_JPEG_DECODING(i965))
673 entrypoint_list[n++] = VAEntrypointVLD;
675 if (HAS_JPEG_ENCODING(i965))
676 entrypoint_list[n++] = VAEntrypointEncPicture;
679 case VAProfileVP8Version0_3:
680 if (HAS_VP8_DECODING(i965))
681 entrypoint_list[n++] = VAEntrypointVLD;
683 if (HAS_VP8_ENCODING(i965))
684 entrypoint_list[n++] = VAEntrypointEncSlice;
688 case VAProfileHEVCMain:
689 if (HAS_HEVC_DECODING(i965))
690 entrypoint_list[n++] = VAEntrypointVLD;
692 if (HAS_HEVC_ENCODING(i965))
693 entrypoint_list[n++] = VAEntrypointEncSlice;
697 case VAProfileHEVCMain10:
698 if (HAS_HEVC10_DECODING(i965))
699 entrypoint_list[n++] = VAEntrypointVLD;
701 if (HAS_HEVC10_ENCODING(i965))
702 entrypoint_list[n++] = VAEntrypointEncSlice;
706 case VAProfileVP9Profile0:
707 case VAProfileVP9Profile2:
708 if (HAS_VP9_DECODING_PROFILE(i965, profile))
709 entrypoint_list[n++] = VAEntrypointVLD;
711 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
712 entrypoint_list[n++] = VAEntrypointEncSlice;
714 if (profile == VAProfileVP9Profile0) {
715 if (i965->wrapper_pdrvctx) {
716 VAStatus va_status = VA_STATUS_SUCCESS;
717 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
719 CALL_VTABLE(pdrvctx, va_status,
720 vaQueryConfigEntrypoints(pdrvctx, profile,
733 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
734 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
735 *num_entrypoints = n;
736 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
740 i965_validate_config(VADriverContextP ctx, VAProfile profile,
741 VAEntrypoint entrypoint)
743 struct i965_driver_data * const i965 = i965_driver_data(ctx);
746 /* Validate profile & entrypoint */
748 case VAProfileMPEG2Simple:
749 case VAProfileMPEG2Main:
750 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
751 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
752 va_status = VA_STATUS_SUCCESS;
753 } else if (!HAS_MPEG2_DECODING(i965) && !HAS_MPEG2_ENCODING(i965)) {
754 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
756 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
760 case VAProfileH264ConstrainedBaseline:
761 case VAProfileH264Main:
762 case VAProfileH264High:
763 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
764 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
765 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP)) {
766 va_status = VA_STATUS_SUCCESS;
767 } else if (!HAS_H264_DECODING(i965) && !HAS_H264_ENCODING(i965) &&
768 !HAS_LP_H264_ENCODING(i965)) {
769 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
771 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
775 case VAProfileVC1Simple:
776 case VAProfileVC1Main:
777 case VAProfileVC1Advanced:
778 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
779 va_status = VA_STATUS_SUCCESS;
780 } else if (!HAS_VC1_DECODING(i965)) {
781 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
783 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
788 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
789 va_status = VA_STATUS_SUCCESS;
790 } else if (!HAS_VPP(i965)) {
791 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
793 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
797 case VAProfileJPEGBaseline:
798 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
799 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
800 va_status = VA_STATUS_SUCCESS;
801 } else if (!HAS_JPEG_DECODING(i965) && !HAS_JPEG_ENCODING(i965)) {
802 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
804 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
808 case VAProfileVP8Version0_3:
809 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
810 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
811 va_status = VA_STATUS_SUCCESS;
812 } else if (!HAS_VP8_DECODING(i965) && !HAS_VP8_ENCODING(i965)) {
813 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
815 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
819 case VAProfileH264MultiviewHigh:
820 case VAProfileH264StereoHigh:
821 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
822 entrypoint == VAEntrypointVLD) ||
823 (HAS_H264_MVC_ENCODING(i965) &&
824 entrypoint == VAEntrypointEncSlice)) {
825 va_status = VA_STATUS_SUCCESS;
826 } else if (!HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
827 !HAS_H264_MVC_ENCODING(i965)) {
828 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
830 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
835 case VAProfileHEVCMain:
836 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD)) ||
837 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice))) {
838 va_status = VA_STATUS_SUCCESS;
839 } else if (!HAS_HEVC_DECODING(i965) && !HAS_HEVC_ENCODING(i965)) {
840 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
842 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
847 case VAProfileHEVCMain10:
848 if ((HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD)) ||
849 (HAS_HEVC10_ENCODING(i965) &&
850 (entrypoint == VAEntrypointEncSlice))) {
851 va_status = VA_STATUS_SUCCESS;
852 } else if (!HAS_HEVC10_DECODING(i965) && !HAS_HEVC10_ENCODING(i965)) {
853 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
855 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
860 case VAProfileVP9Profile0:
861 case VAProfileVP9Profile2:
862 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) &&
863 (entrypoint == VAEntrypointVLD)) {
864 va_status = VA_STATUS_SUCCESS;
865 } else if ((HAS_VP9_ENCODING_PROFILE(i965, profile)) &&
866 (entrypoint == VAEntrypointEncSlice)) {
867 va_status = VA_STATUS_SUCCESS;
868 } else if (profile == VAProfileVP9Profile0 &&
869 entrypoint == VAEntrypointVLD &&
870 i965->wrapper_pdrvctx) {
871 va_status = VA_STATUS_SUCCESS;
872 } else if (!HAS_VP9_DECODING_PROFILE(i965, profile) &&
873 !HAS_VP9_ENCODING(i965) && !i965->wrapper_pdrvctx) {
874 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
876 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
882 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
889 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
890 VAEntrypoint entrypoint)
892 struct i965_driver_data * const i965 = i965_driver_data(ctx);
893 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
896 case VAProfileH264ConstrainedBaseline:
897 case VAProfileH264Main:
898 case VAProfileH264High:
899 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
900 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
903 case VAProfileH264MultiviewHigh:
904 case VAProfileH264StereoHigh:
905 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
906 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
909 case VAProfileJPEGBaseline:
910 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
911 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
912 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
913 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
916 case VAProfileHEVCMain10:
917 if (HAS_HEVC10_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)
918 chroma_formats = VA_RT_FORMAT_YUV420_10BPP;
919 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
920 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
924 if (HAS_VPP_P010(i965))
925 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
928 chroma_formats |= VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_RGB32;
931 case VAProfileVP9Profile0:
932 case VAProfileVP9Profile2:
933 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
934 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
940 return chroma_formats;
944 i965_GetConfigAttributes(VADriverContextP ctx,
946 VAEntrypoint entrypoint,
947 VAConfigAttrib *attrib_list, /* in/out */
950 struct i965_driver_data * const i965 = i965_driver_data(ctx);
954 va_status = i965_validate_config(ctx, profile, entrypoint);
955 if (va_status != VA_STATUS_SUCCESS)
958 /* Other attributes don't seem to be defined */
959 /* What to do if we don't know the attribute? */
960 for (i = 0; i < num_attribs; i++) {
961 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
962 switch (attrib_list[i].type) {
963 case VAConfigAttribRTFormat:
964 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
965 profile, entrypoint);
968 case VAConfigAttribRateControl:
969 if (entrypoint == VAEntrypointEncSlice) {
970 attrib_list[i].value = VA_RC_CQP;
972 if (profile != VAProfileMPEG2Main &&
973 profile != VAProfileMPEG2Simple)
974 attrib_list[i].value |= VA_RC_CBR;
976 if (profile == VAProfileVP9Profile0 ||
977 profile == VAProfileH264ConstrainedBaseline ||
978 profile == VAProfileH264Main ||
979 profile == VAProfileH264High ||
980 profile == VAProfileHEVCMain)
981 attrib_list[i].value |= VA_RC_VBR;
984 } else if (entrypoint == VAEntrypointEncSliceLP) {
985 struct i965_driver_data * const i965 = i965_driver_data(ctx);
987 /* Support low power encoding for H.264 only by now */
988 if (profile == VAProfileH264ConstrainedBaseline ||
989 profile == VAProfileH264Main ||
990 profile == VAProfileH264High)
991 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
993 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
995 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
999 case VAConfigAttribEncPackedHeaders:
1000 if (entrypoint == VAEntrypointEncSlice ||
1001 entrypoint == VAEntrypointEncSliceLP) {
1002 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
1003 if (profile == VAProfileH264ConstrainedBaseline ||
1004 profile == VAProfileH264Main ||
1005 profile == VAProfileH264High ||
1006 profile == VAProfileH264StereoHigh ||
1007 profile == VAProfileH264MultiviewHigh ||
1008 profile == VAProfileHEVCMain ||
1009 profile == VAProfileHEVCMain10) {
1010 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
1011 VA_ENC_PACKED_HEADER_SLICE);
1012 } else if (profile == VAProfileVP9Profile0)
1013 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1015 } else if (entrypoint == VAEntrypointEncPicture) {
1016 if (profile == VAProfileJPEGBaseline)
1017 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1021 case VAConfigAttribEncMaxRefFrames:
1022 if (entrypoint == VAEntrypointEncSlice)
1023 attrib_list[i].value = (1 << 16) | (1 << 0);
1024 else if (entrypoint == VAEntrypointEncSliceLP) {
1025 /* Don't support B frame for low power mode */
1026 if (profile == VAProfileH264ConstrainedBaseline ||
1027 profile == VAProfileH264Main ||
1028 profile == VAProfileH264High)
1029 attrib_list[i].value = (1 << 0);
1031 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1036 case VAConfigAttribEncQualityRange:
1037 if (entrypoint == VAEntrypointEncSlice ||
1038 entrypoint == VAEntrypointEncSliceLP) {
1039 attrib_list[i].value = 1;
1040 if (profile == VAProfileH264ConstrainedBaseline ||
1041 profile == VAProfileH264Main ||
1042 profile == VAProfileH264High) {
1043 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1044 if (entrypoint == VAEntrypointEncSlice) {
1045 if (IS_GEN9(i965->intel.device_info))
1046 attrib_list[i].value = ENCODER_QUALITY_RANGE_AVC;
1048 } else if (profile == VAProfileHEVCMain ||
1049 profile == VAProfileHEVCMain10)
1050 attrib_list[i].value = ENCODER_QUALITY_RANGE_HEVC;
1055 case VAConfigAttribEncJPEG:
1056 if (entrypoint == VAEntrypointEncPicture) {
1057 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*) & (attrib_list[i].value);
1058 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1059 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1060 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1061 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1062 (configVal->bits).max_num_components = 3; // Only 3 components supported
1063 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1064 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1065 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1069 case VAConfigAttribDecSliceMode:
1070 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1073 case VAConfigAttribEncROI:
1074 if (entrypoint == VAEntrypointEncSlice ||
1075 entrypoint == VAEntrypointEncSliceLP) {
1077 if (profile == VAProfileH264ConstrainedBaseline ||
1078 profile == VAProfileH264Main ||
1079 profile == VAProfileH264High) {
1081 if (IS_GEN9(i965->intel.device_info) &&
1082 entrypoint == VAEntrypointEncSlice)
1083 attrib_list[i].value = 0;
1086 VAConfigAttribValEncROI *roi_config =
1087 (VAConfigAttribValEncROI *) & (attrib_list[i].value);
1089 if (entrypoint == VAEntrypointEncSliceLP) {
1090 roi_config->bits.num_roi_regions = 3;
1091 roi_config->bits.roi_rc_priority_support = 0;
1092 roi_config->bits.roi_rc_qp_delat_support = 0;
1094 roi_config->bits.num_roi_regions =
1095 I965_MAX_NUM_ROI_REGIONS;
1096 roi_config->bits.roi_rc_priority_support = 0;
1097 roi_config->bits.roi_rc_qp_delat_support = 1;
1101 attrib_list[i].value = 0;
1107 case VAConfigAttribEncRateControlExt:
1108 if ((profile == VAProfileH264ConstrainedBaseline ||
1109 profile == VAProfileH264Main ||
1110 profile == VAProfileH264High) &&
1111 entrypoint == VAEntrypointEncSlice) {
1112 if (IS_GEN9(i965->intel.device_info))
1113 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1115 VAConfigAttribValEncRateControlExt *val_config = (VAConfigAttribValEncRateControlExt *) & (attrib_list[i].value);
1117 val_config->bits.max_num_temporal_layers_minus1 = MAX_TEMPORAL_LAYERS - 1;
1118 val_config->bits.temporal_layer_bitrate_control_flag = 1;
1121 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1126 case VAConfigAttribEncMaxSlices:
1127 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1128 if (entrypoint == VAEntrypointEncSlice) {
1129 if ((profile == VAProfileH264ConstrainedBaseline ||
1130 profile == VAProfileH264Main ||
1131 profile == VAProfileH264High) ||
1132 profile == VAProfileH264StereoHigh ||
1133 profile == VAProfileH264MultiviewHigh) {
1134 attrib_list[i].value = I965_MAX_NUM_SLICE;
1135 } else if (profile == VAProfileHEVCMain ||
1136 profile == VAProfileHEVCMain10) {
1137 attrib_list[i].value = I965_MAX_NUM_SLICE;
1139 } else if (entrypoint == VAEntrypointEncSliceLP) {
1140 if ((profile == VAProfileH264ConstrainedBaseline ||
1141 profile == VAProfileH264Main ||
1142 profile == VAProfileH264High) ||
1143 profile == VAProfileH264StereoHigh ||
1144 profile == VAProfileH264MultiviewHigh)
1145 attrib_list[i].value = I965_MAX_NUM_SLICE;
1150 case VAConfigAttribEncSliceStructure:
1151 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1152 if (entrypoint == VAEntrypointEncSlice) {
1153 if ((profile == VAProfileH264ConstrainedBaseline ||
1154 profile == VAProfileH264Main ||
1155 profile == VAProfileH264High) ||
1156 profile == VAProfileH264StereoHigh ||
1157 profile == VAProfileH264MultiviewHigh ||
1158 profile == VAProfileHEVCMain ||
1159 profile == VAProfileHEVCMain10) {
1160 attrib_list[i].value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1167 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1172 return VA_STATUS_SUCCESS;
1176 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1178 object_heap_free(heap, obj);
1181 static VAConfigAttrib *
1182 i965_lookup_config_attribute(struct object_config *obj_config,
1183 VAConfigAttribType type)
1187 for (i = 0; i < obj_config->num_attribs; i++) {
1188 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1189 if (attrib->type == type)
1196 i965_append_config_attribute(struct object_config *obj_config,
1197 const VAConfigAttrib *new_attrib)
1199 VAConfigAttrib *attrib;
1201 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1202 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1204 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1205 attrib->type = new_attrib->type;
1206 attrib->value = new_attrib->value;
1207 return VA_STATUS_SUCCESS;
1211 i965_ensure_config_attribute(struct object_config *obj_config,
1212 const VAConfigAttrib *new_attrib)
1214 VAConfigAttrib *attrib;
1216 /* Check for existing attributes */
1217 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1219 /* Update existing attribute */
1220 attrib->value = new_attrib->value;
1221 return VA_STATUS_SUCCESS;
1223 return i965_append_config_attribute(obj_config, new_attrib);
1227 i965_CreateConfig(VADriverContextP ctx,
1229 VAEntrypoint entrypoint,
1230 VAConfigAttrib *attrib_list,
1232 VAConfigID *config_id) /* out */
1234 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1235 struct object_config *obj_config;
1240 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1242 if (VA_STATUS_SUCCESS != vaStatus) {
1246 configID = NEW_CONFIG_ID();
1247 obj_config = CONFIG(configID);
1249 if (NULL == obj_config) {
1250 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1254 obj_config->profile = profile;
1255 obj_config->entrypoint = entrypoint;
1256 obj_config->num_attribs = 0;
1257 obj_config->wrapper_config = VA_INVALID_ID;
1259 for (i = 0; i < num_attribs; i++) {
1260 // add it later and ignore the user input for VAConfigAttribEncMaxSlices
1261 if (attrib_list[i].type == VAConfigAttribEncMaxSlices ||
1262 attrib_list[i].type == VAConfigAttribEncSliceStructure)
1264 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1265 if (vaStatus != VA_STATUS_SUCCESS)
1269 if (vaStatus == VA_STATUS_SUCCESS) {
1270 VAConfigAttrib attrib, *attrib_found;
1271 attrib.type = VAConfigAttribRTFormat;
1272 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1273 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1274 if (!attrib_found || !attrib_found->value)
1275 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1276 else if (!(attrib_found->value & attrib.value))
1277 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1280 if (vaStatus == VA_STATUS_SUCCESS) {
1281 VAConfigAttrib attrib;
1282 attrib.type = VAConfigAttribEncMaxSlices;
1283 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1284 if (entrypoint == VAEntrypointEncSlice) {
1285 if ((profile == VAProfileH264ConstrainedBaseline ||
1286 profile == VAProfileH264Main ||
1287 profile == VAProfileH264High) ||
1288 profile == VAProfileH264StereoHigh ||
1289 profile == VAProfileH264MultiviewHigh) {
1290 attrib.value = I965_MAX_NUM_SLICE;
1291 } else if (profile == VAProfileHEVCMain ||
1292 profile == VAProfileHEVCMain10)
1293 attrib.value = I965_MAX_NUM_SLICE;
1294 } else if (entrypoint == VAEntrypointEncSliceLP) {
1295 if ((profile == VAProfileH264ConstrainedBaseline ||
1296 profile == VAProfileH264Main ||
1297 profile == VAProfileH264High) ||
1298 profile == VAProfileH264StereoHigh ||
1299 profile == VAProfileH264MultiviewHigh)
1300 attrib.value = I965_MAX_NUM_SLICE;
1303 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1304 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1307 if (vaStatus == VA_STATUS_SUCCESS) {
1308 VAConfigAttrib attrib;
1309 attrib.type = VAConfigAttribEncSliceStructure;
1310 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1311 if (entrypoint == VAEntrypointEncSlice) {
1312 if ((profile == VAProfileH264ConstrainedBaseline ||
1313 profile == VAProfileH264Main ||
1314 profile == VAProfileH264High) ||
1315 profile == VAProfileH264StereoHigh ||
1316 profile == VAProfileH264MultiviewHigh) {
1317 attrib.value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1321 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1322 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1325 if ((vaStatus == VA_STATUS_SUCCESS) &&
1326 (profile == VAProfileVP9Profile0) &&
1327 (entrypoint == VAEntrypointVLD) &&
1328 !HAS_VP9_DECODING(i965)) {
1330 if (i965->wrapper_pdrvctx) {
1331 VAGenericID wrapper_config;
1333 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1334 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1335 entrypoint, attrib_list,
1336 num_attribs, &wrapper_config));
1338 if (vaStatus == VA_STATUS_SUCCESS)
1339 obj_config->wrapper_config = wrapper_config;
1343 /* Error recovery */
1344 if (VA_STATUS_SUCCESS != vaStatus) {
1345 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1347 *config_id = configID;
1354 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1356 struct i965_driver_data *i965 = i965_driver_data(ctx);
1357 struct object_config *obj_config = CONFIG(config_id);
1360 if (NULL == obj_config) {
1361 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1365 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1366 i965->wrapper_pdrvctx) {
1367 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1368 vaDestroyConfig(i965->wrapper_pdrvctx,
1369 obj_config->wrapper_config));
1370 obj_config->wrapper_config = VA_INVALID_ID;
1373 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1374 return VA_STATUS_SUCCESS;
1377 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1378 VAConfigID config_id,
1379 VAProfile *profile, /* out */
1380 VAEntrypoint *entrypoint, /* out */
1381 VAConfigAttrib *attrib_list, /* out */
1382 int *num_attribs) /* out */
1384 struct i965_driver_data *i965 = i965_driver_data(ctx);
1385 struct object_config *obj_config = CONFIG(config_id);
1386 VAStatus vaStatus = VA_STATUS_SUCCESS;
1389 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1390 *profile = obj_config->profile;
1391 *entrypoint = obj_config->entrypoint;
1392 *num_attribs = obj_config->num_attribs;
1394 for (i = 0; i < obj_config->num_attribs; i++) {
1395 attrib_list[i] = obj_config->attrib_list[i];
1402 i965_destroy_surface_storage(struct object_surface *obj_surface)
1407 dri_bo_unreference(obj_surface->bo);
1408 obj_surface->bo = NULL;
1410 if (obj_surface->free_private_data != NULL) {
1411 obj_surface->free_private_data(&obj_surface->private_data);
1412 obj_surface->private_data = NULL;
1417 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1419 struct object_surface *obj_surface = (struct object_surface *)obj;
1421 i965_destroy_surface_storage(obj_surface);
1422 object_heap_free(heap, obj);
1425 /* byte-per-pixel of the first plane */
1427 bpp_1stplane_by_fourcc(unsigned int fourcc)
1429 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1431 if (info && (info->flag & I_S))
1432 return info->bpp[0] / 8;
1438 i965_surface_native_memory(VADriverContextP ctx,
1439 struct object_surface *obj_surface,
1441 int expected_fourcc)
1443 struct i965_driver_data *i965 = i965_driver_data(ctx);
1444 int tiling = HAS_TILED_SURFACE(i965);
1446 if (!expected_fourcc)
1447 return VA_STATUS_SUCCESS;
1449 // todo, should we disable tiling for 422 format?
1450 if (expected_fourcc == VA_FOURCC_I420 ||
1451 expected_fourcc == VA_FOURCC_IYUV ||
1452 expected_fourcc == VA_FOURCC_I010 ||
1453 expected_fourcc == VA_FOURCC_YV12 ||
1454 expected_fourcc == VA_FOURCC_YV16)
1457 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1461 i965_suface_external_memory(VADriverContextP ctx,
1462 struct object_surface *obj_surface,
1463 int external_memory_type,
1464 VASurfaceAttribExternalBuffers *memory_attibute,
1467 struct i965_driver_data *i965 = i965_driver_data(ctx);
1468 unsigned int tiling, swizzle;
1470 if (!memory_attibute ||
1471 !memory_attibute->buffers ||
1472 index >= memory_attibute->num_buffers)
1473 return VA_STATUS_ERROR_INVALID_PARAMETER;
1475 obj_surface->size = memory_attibute->data_size;
1476 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1477 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1478 "gem flinked vaapi surface",
1479 memory_attibute->buffers[index]);
1480 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1481 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1482 memory_attibute->buffers[index],
1485 if (!obj_surface->bo)
1486 return VA_STATUS_ERROR_INVALID_PARAMETER;
1488 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
1490 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1491 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1492 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1494 obj_surface->fourcc = memory_attibute->pixel_format;
1495 obj_surface->width = memory_attibute->pitches[0];
1496 int bpp_1stplane = bpp_1stplane_by_fourcc(obj_surface->fourcc);
1497 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1498 ASSERT_RET(obj_surface->width >= obj_surface->orig_width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1500 if (memory_attibute->num_planes == 1)
1501 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1503 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1504 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1505 ASSERT_RET(obj_surface->height >= obj_surface->orig_height, VA_STATUS_ERROR_INVALID_PARAMETER);
1508 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1509 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
1511 ASSERT_RET(IS_ALIGNED(obj_surface->width, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1512 ASSERT_RET(IS_ALIGNED(obj_surface->height, i965->codec_info->min_linear_hpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1515 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1516 obj_surface->x_cr_offset = 0;
1517 if ((obj_surface->fourcc == VA_FOURCC_I420 ||
1518 obj_surface->fourcc == VA_FOURCC_IYUV ||
1519 obj_surface->fourcc == VA_FOURCC_I010 ||
1520 obj_surface->fourcc == VA_FOURCC_YV12 ||
1521 obj_surface->fourcc == VA_FOURCC_YV16) && tiling)
1522 return VA_STATUS_ERROR_INVALID_PARAMETER;
1524 switch (obj_surface->fourcc) {
1525 case VA_FOURCC_NV12:
1526 case VA_FOURCC_P010:
1527 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1528 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1530 obj_surface->subsampling = SUBSAMPLE_YUV420;
1531 obj_surface->y_cb_offset = obj_surface->height;
1532 obj_surface->y_cr_offset = obj_surface->height;
1533 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1534 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1535 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1537 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1539 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1543 case VA_FOURCC_YV12:
1544 case VA_FOURCC_IMC1:
1545 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1546 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1548 obj_surface->subsampling = SUBSAMPLE_YUV420;
1549 obj_surface->y_cr_offset = obj_surface->height;
1550 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1551 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1552 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1553 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1556 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1558 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1562 case VA_FOURCC_I420:
1563 case VA_FOURCC_IYUV:
1564 case VA_FOURCC_IMC3:
1565 case VA_FOURCC_I010:
1566 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1567 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1569 obj_surface->subsampling = SUBSAMPLE_YUV420;
1570 obj_surface->y_cb_offset = obj_surface->height;
1571 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1572 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1573 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1574 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1576 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1578 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1582 case VA_FOURCC_YUY2:
1583 case VA_FOURCC_UYVY:
1584 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1586 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1587 obj_surface->y_cb_offset = 0;
1588 obj_surface->y_cr_offset = 0;
1589 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1590 obj_surface->cb_cr_height = obj_surface->orig_height;
1591 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1595 case VA_FOURCC_RGBA:
1596 case VA_FOURCC_RGBX:
1597 case VA_FOURCC_BGRA:
1598 case VA_FOURCC_BGRX:
1599 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1601 obj_surface->subsampling = SUBSAMPLE_RGBX;
1602 obj_surface->y_cb_offset = 0;
1603 obj_surface->y_cr_offset = 0;
1604 obj_surface->cb_cr_width = 0;
1605 obj_surface->cb_cr_height = 0;
1606 obj_surface->cb_cr_pitch = 0;
1610 case VA_FOURCC_Y800: /* monochrome surface */
1611 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1613 obj_surface->subsampling = SUBSAMPLE_YUV400;
1614 obj_surface->y_cb_offset = 0;
1615 obj_surface->y_cr_offset = 0;
1616 obj_surface->cb_cr_width = 0;
1617 obj_surface->cb_cr_height = 0;
1618 obj_surface->cb_cr_pitch = 0;
1622 case VA_FOURCC_411P:
1623 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1624 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1626 obj_surface->subsampling = SUBSAMPLE_YUV411;
1627 obj_surface->y_cb_offset = obj_surface->height;
1628 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1629 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1630 obj_surface->cb_cr_height = obj_surface->orig_height;
1631 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1633 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1635 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1638 case VA_FOURCC_422H:
1639 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1640 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1642 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1643 obj_surface->y_cb_offset = obj_surface->height;
1644 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1645 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1646 obj_surface->cb_cr_height = obj_surface->orig_height;
1647 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1649 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1651 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1655 case VA_FOURCC_YV16:
1656 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1657 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1659 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1660 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1661 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1662 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1663 obj_surface->cb_cr_height = obj_surface->orig_height;
1664 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1665 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1669 case VA_FOURCC_422V:
1670 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1671 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1673 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1674 obj_surface->y_cb_offset = obj_surface->height;
1675 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1676 obj_surface->cb_cr_width = obj_surface->orig_width;
1677 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1678 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1680 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1682 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1686 case VA_FOURCC_444P:
1687 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1688 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1690 obj_surface->subsampling = SUBSAMPLE_YUV444;
1691 obj_surface->y_cb_offset = obj_surface->height;
1692 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1693 obj_surface->cb_cr_width = obj_surface->orig_width;
1694 obj_surface->cb_cr_height = obj_surface->orig_height;
1695 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1697 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1699 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1704 return VA_STATUS_ERROR_INVALID_PARAMETER;
1707 return VA_STATUS_SUCCESS;
1711 i965_CreateSurfaces2(
1712 VADriverContextP ctx,
1713 unsigned int format,
1715 unsigned int height,
1716 VASurfaceID *surfaces,
1717 unsigned int num_surfaces,
1718 VASurfaceAttrib *attrib_list,
1719 unsigned int num_attribs
1722 struct i965_driver_data *i965 = i965_driver_data(ctx);
1724 VAStatus vaStatus = VA_STATUS_SUCCESS;
1725 int expected_fourcc = 0;
1726 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1727 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1729 for (i = 0; i < num_attribs && attrib_list; i++) {
1730 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1731 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1732 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1733 expected_fourcc = attrib_list[i].value.value.i;
1736 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1737 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1739 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1741 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1742 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1743 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1744 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1745 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1746 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1749 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1750 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1751 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1752 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1756 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1757 * for post-processing (including color conversion) */
1758 if (VA_RT_FORMAT_YUV420 != format &&
1759 VA_RT_FORMAT_YUV420_10BPP != format &&
1760 VA_RT_FORMAT_YUV422 != format &&
1761 VA_RT_FORMAT_YUV444 != format &&
1762 VA_RT_FORMAT_YUV411 != format &&
1763 VA_RT_FORMAT_YUV400 != format &&
1764 VA_RT_FORMAT_RGB32 != format) {
1765 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1768 for (i = 0; i < num_surfaces; i++) {
1769 int surfaceID = NEW_SURFACE_ID();
1770 struct object_surface *obj_surface = SURFACE(surfaceID);
1772 if (NULL == obj_surface) {
1773 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1777 surfaces[i] = surfaceID;
1778 obj_surface->status = VASurfaceReady;
1779 obj_surface->orig_width = width;
1780 obj_surface->orig_height = height;
1781 obj_surface->user_disable_tiling = false;
1782 obj_surface->user_h_stride_set = false;
1783 obj_surface->user_v_stride_set = false;
1784 obj_surface->border_cleared = false;
1786 obj_surface->subpic_render_idx = 0;
1787 for (j = 0; j < I965_MAX_SUBPIC_SUM; j++) {
1788 obj_surface->subpic[j] = VA_INVALID_ID;
1789 obj_surface->obj_subpic[j] = NULL;
1792 assert(i965->codec_info->min_linear_wpitch);
1793 assert(i965->codec_info->min_linear_hpitch);
1794 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1795 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1796 obj_surface->flags = SURFACE_REFERENCED;
1797 obj_surface->fourcc = 0;
1798 obj_surface->expected_format = format;
1799 obj_surface->bo = NULL;
1800 obj_surface->locked_image_id = VA_INVALID_ID;
1801 obj_surface->derived_image_id = VA_INVALID_ID;
1802 obj_surface->private_data = NULL;
1803 obj_surface->free_private_data = NULL;
1804 obj_surface->subsampling = SUBSAMPLE_YUV420;
1806 obj_surface->wrapper_surface = VA_INVALID_ID;
1807 obj_surface->exported_primefd = -1;
1809 switch (memory_type) {
1810 case I965_SURFACE_MEM_NATIVE:
1811 if (memory_attibute) {
1812 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1813 obj_surface->user_disable_tiling = true;
1815 if (memory_attibute->pixel_format) {
1816 if (expected_fourcc)
1817 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1819 expected_fourcc = memory_attibute->pixel_format;
1821 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1822 if (memory_attibute->pitches[0]) {
1823 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1824 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1825 obj_surface->width = memory_attibute->pitches[0];
1826 obj_surface->user_h_stride_set = true;
1827 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1828 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1830 if (memory_attibute->offsets[1]) {
1831 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1832 obj_surface->height = memory_attibute->offsets[1] / memory_attibute->pitches[0];
1833 obj_surface->user_v_stride_set = true;
1834 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1835 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1839 vaStatus = i965_surface_native_memory(ctx,
1845 case I965_SURFACE_MEM_GEM_FLINK:
1846 case I965_SURFACE_MEM_DRM_PRIME:
1847 vaStatus = i965_suface_external_memory(ctx,
1854 if (VA_STATUS_SUCCESS != vaStatus) {
1855 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1860 /* Error recovery */
1861 if (VA_STATUS_SUCCESS != vaStatus) {
1862 /* surfaces[i-1] was the last successful allocation */
1864 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1866 surfaces[i] = VA_INVALID_SURFACE;
1867 assert(obj_surface);
1868 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1876 i965_CreateSurfaces(VADriverContextP ctx,
1881 VASurfaceID *surfaces) /* out */
1883 return i965_CreateSurfaces2(ctx,
1894 i965_DestroySurfaces(VADriverContextP ctx,
1895 VASurfaceID *surface_list,
1898 struct i965_driver_data *i965 = i965_driver_data(ctx);
1900 VAStatus va_status = VA_STATUS_SUCCESS;
1902 for (i = num_surfaces; i--;) {
1903 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1905 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1907 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1908 i965->wrapper_pdrvctx) {
1909 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1910 vaDestroySurfaces(i965->wrapper_pdrvctx,
1911 &(obj_surface->wrapper_surface),
1913 obj_surface->wrapper_surface = VA_INVALID_ID;
1915 if (obj_surface->exported_primefd >= 0) {
1916 close(obj_surface->exported_primefd);
1917 obj_surface->exported_primefd = -1;
1920 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1927 i965_QueryImageFormats(VADriverContextP ctx,
1928 VAImageFormat *format_list, /* out */
1929 int *num_formats) /* out */
1933 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1934 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1936 format_list[n] = m->va_format;
1942 return VA_STATUS_SUCCESS;
1946 * Guess the format when the usage of a VA surface is unknown
1947 * 1. Without a valid context: YV12
1948 * 2. The current context is valid:
1949 * a) always NV12 on GEN6 and later
1950 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1953 i965_guess_surface_format(VADriverContextP ctx,
1954 VASurfaceID surface,
1955 unsigned int *fourcc,
1956 unsigned int *is_tiled)
1958 struct i965_driver_data *i965 = i965_driver_data(ctx);
1959 struct object_context *obj_context = NULL;
1960 struct object_config *obj_config = NULL;
1962 *fourcc = VA_FOURCC_YV12;
1965 if (i965->current_context_id == VA_INVALID_ID)
1968 obj_context = CONTEXT(i965->current_context_id);
1973 obj_config = obj_context->obj_config;
1979 if (IS_GEN6(i965->intel.device_info) ||
1980 IS_GEN7(i965->intel.device_info) ||
1981 IS_GEN8(i965->intel.device_info) ||
1982 IS_GEN9(i965->intel.device_info)) {
1983 *fourcc = VA_FOURCC_NV12;
1988 switch (obj_config->profile) {
1989 case VAProfileMPEG2Simple:
1990 case VAProfileMPEG2Main:
1991 *fourcc = VA_FOURCC_I420;
1996 *fourcc = VA_FOURCC_NV12;
2003 i965_QuerySubpictureFormats(VADriverContextP ctx,
2004 VAImageFormat *format_list, /* out */
2005 unsigned int *flags, /* out */
2006 unsigned int *num_formats) /* out */
2010 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
2011 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
2013 format_list[n] = m->va_format;
2015 flags[n] = m->va_flags;
2021 return VA_STATUS_SUCCESS;
2025 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
2027 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
2029 object_heap_free(heap, obj);
2033 i965_CreateSubpicture(VADriverContextP ctx,
2035 VASubpictureID *subpicture) /* out */
2037 struct i965_driver_data *i965 = i965_driver_data(ctx);
2038 VASubpictureID subpicID = NEW_SUBPIC_ID()
2039 struct object_subpic * obj_subpic = SUBPIC(subpicID);
2042 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2044 struct object_image *obj_image = IMAGE(image);
2046 return VA_STATUS_ERROR_INVALID_IMAGE;
2048 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
2050 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
2052 *subpicture = subpicID;
2053 obj_subpic->image = image;
2054 obj_subpic->obj_image = obj_image;
2055 obj_subpic->format = m->format;
2056 obj_subpic->width = obj_image->image.width;
2057 obj_subpic->height = obj_image->image.height;
2058 obj_subpic->pitch = obj_image->image.pitches[0];
2059 obj_subpic->bo = obj_image->bo;
2060 obj_subpic->global_alpha = 1.0;
2062 return VA_STATUS_SUCCESS;
2066 i965_DestroySubpicture(VADriverContextP ctx,
2067 VASubpictureID subpicture)
2069 struct i965_driver_data *i965 = i965_driver_data(ctx);
2070 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2073 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2075 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2076 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
2077 return VA_STATUS_SUCCESS;
2081 i965_SetSubpictureImage(VADriverContextP ctx,
2082 VASubpictureID subpicture,
2086 return VA_STATUS_ERROR_UNIMPLEMENTED;
2090 i965_SetSubpictureChromakey(VADriverContextP ctx,
2091 VASubpictureID subpicture,
2092 unsigned int chromakey_min,
2093 unsigned int chromakey_max,
2094 unsigned int chromakey_mask)
2097 return VA_STATUS_ERROR_UNIMPLEMENTED;
2101 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
2102 VASubpictureID subpicture,
2105 struct i965_driver_data *i965 = i965_driver_data(ctx);
2106 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2108 if (global_alpha > 1.0 || global_alpha < 0.0) {
2109 return VA_STATUS_ERROR_INVALID_PARAMETER;
2113 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2115 obj_subpic->global_alpha = global_alpha;
2117 return VA_STATUS_SUCCESS;
2121 i965_AssociateSubpicture(VADriverContextP ctx,
2122 VASubpictureID subpicture,
2123 VASurfaceID *target_surfaces,
2125 short src_x, /* upper left offset in subpicture */
2127 unsigned short src_width,
2128 unsigned short src_height,
2129 short dest_x, /* upper left offset in surface */
2131 unsigned short dest_width,
2132 unsigned short dest_height,
2134 * whether to enable chroma-keying or global-alpha
2135 * see VA_SUBPICTURE_XXX values
2139 struct i965_driver_data *i965 = i965_driver_data(ctx);
2140 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2144 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2146 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2148 obj_subpic->src_rect.x = src_x;
2149 obj_subpic->src_rect.y = src_y;
2150 obj_subpic->src_rect.width = src_width;
2151 obj_subpic->src_rect.height = src_height;
2152 obj_subpic->dst_rect.x = dest_x;
2153 obj_subpic->dst_rect.y = dest_y;
2154 obj_subpic->dst_rect.width = dest_width;
2155 obj_subpic->dst_rect.height = dest_height;
2156 obj_subpic->flags = flags;
2158 for (i = 0; i < num_surfaces; i++) {
2159 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2161 return VA_STATUS_ERROR_INVALID_SURFACE;
2163 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2164 if (obj_surface->subpic[j] == VA_INVALID_ID) {
2165 assert(obj_surface->obj_subpic[j] == NULL);
2166 obj_surface->subpic[j] = subpicture;
2167 obj_surface->obj_subpic[j] = obj_subpic;
2172 if (j == I965_MAX_SUBPIC_SUM) {
2173 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2177 return VA_STATUS_SUCCESS;
2182 i965_DeassociateSubpicture(VADriverContextP ctx,
2183 VASubpictureID subpicture,
2184 VASurfaceID *target_surfaces,
2187 struct i965_driver_data *i965 = i965_driver_data(ctx);
2188 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2192 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2194 for (i = 0; i < num_surfaces; i++) {
2195 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2197 return VA_STATUS_ERROR_INVALID_SURFACE;
2199 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2200 if (obj_surface->subpic[j] == subpicture) {
2201 assert(obj_surface->obj_subpic[j] == obj_subpic);
2202 obj_surface->subpic[j] = VA_INVALID_ID;
2203 obj_surface->obj_subpic[j] = NULL;
2208 if (j == I965_MAX_SUBPIC_SUM) {
2209 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2212 return VA_STATUS_SUCCESS;
2216 i965_reference_buffer_store(struct buffer_store **ptr,
2217 struct buffer_store *buffer_store)
2219 assert(*ptr == NULL);
2222 buffer_store->ref_count++;
2223 *ptr = buffer_store;
2228 i965_release_buffer_store(struct buffer_store **ptr)
2230 struct buffer_store *buffer_store = *ptr;
2232 if (buffer_store == NULL)
2235 assert(buffer_store->bo || buffer_store->buffer);
2236 assert(!(buffer_store->bo && buffer_store->buffer));
2237 buffer_store->ref_count--;
2239 if (buffer_store->ref_count == 0) {
2240 dri_bo_unreference(buffer_store->bo);
2241 free(buffer_store->buffer);
2242 buffer_store->bo = NULL;
2243 buffer_store->buffer = NULL;
2251 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2253 struct object_context *obj_context = (struct object_context *)obj;
2256 if (obj_context->hw_context) {
2257 obj_context->hw_context->destroy(obj_context->hw_context);
2258 obj_context->hw_context = NULL;
2261 if (obj_context->codec_type == CODEC_PROC) {
2262 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2264 } else if (obj_context->codec_type == CODEC_ENC) {
2265 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2266 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2268 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2269 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2270 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2272 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2273 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2275 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2276 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2278 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2279 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2280 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2282 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2283 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2285 free(obj_context->codec_state.encode.slice_params_ext);
2286 if (obj_context->codec_state.encode.slice_rawdata_index) {
2287 free(obj_context->codec_state.encode.slice_rawdata_index);
2288 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2290 if (obj_context->codec_state.encode.slice_rawdata_count) {
2291 free(obj_context->codec_state.encode.slice_rawdata_count);
2292 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2295 if (obj_context->codec_state.encode.slice_header_index) {
2296 free(obj_context->codec_state.encode.slice_header_index);
2297 obj_context->codec_state.encode.slice_header_index = NULL;
2300 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2301 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2302 free(obj_context->codec_state.encode.packed_header_params_ext);
2304 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2305 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2306 free(obj_context->codec_state.encode.packed_header_data_ext);
2308 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2310 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2311 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2313 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2314 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2315 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2317 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2318 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2320 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2321 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2323 free(obj_context->codec_state.decode.slice_params);
2324 free(obj_context->codec_state.decode.slice_datas);
2327 free(obj_context->render_targets);
2328 object_heap_free(heap, obj);
2332 max_resolution(struct i965_driver_data *i965,
2333 struct object_config *obj_config,
2337 if (i965->codec_info->max_resolution) {
2338 i965->codec_info->max_resolution(i965, obj_config, w, h);
2340 *w = i965->codec_info->max_width;
2341 *h = i965->codec_info->max_height;
2346 i965_CreateContext(VADriverContextP ctx,
2347 VAConfigID config_id,
2351 VASurfaceID *render_targets,
2352 int num_render_targets,
2353 VAContextID *context) /* out */
2355 struct i965_driver_data *i965 = i965_driver_data(ctx);
2356 struct object_config *obj_config = CONFIG(config_id);
2357 struct object_context *obj_context = NULL;
2358 VAConfigAttrib *attrib;
2359 VAStatus vaStatus = VA_STATUS_SUCCESS;
2365 if (NULL == obj_config) {
2366 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2370 max_resolution(i965, obj_config, &max_width, &max_height);
2372 if (picture_width > max_width ||
2373 picture_height > max_height) {
2374 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2379 /* Validate picture dimensions */
2380 contextID = NEW_CONTEXT_ID();
2381 obj_context = CONTEXT(contextID);
2383 if (NULL == obj_context) {
2384 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2388 *context = contextID;
2389 obj_context->flags = flag;
2390 obj_context->context_id = contextID;
2391 obj_context->obj_config = obj_config;
2392 obj_context->picture_width = picture_width;
2393 obj_context->picture_height = picture_height;
2394 obj_context->num_render_targets = num_render_targets;
2395 obj_context->render_targets =
2396 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2397 obj_context->hw_context = NULL;
2398 obj_context->wrapper_context = VA_INVALID_ID;
2400 if (!obj_context->render_targets)
2401 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2403 for (i = 0; i < num_render_targets; i++) {
2404 if (NULL == SURFACE(render_targets[i])) {
2405 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2409 obj_context->render_targets[i] = render_targets[i];
2412 if (VA_STATUS_SUCCESS == vaStatus) {
2413 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2414 obj_context->codec_type = CODEC_PROC;
2415 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2416 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2417 assert(i965->codec_info->proc_hw_context_init);
2418 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2419 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2420 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2421 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2422 VAConfigAttrib *packed_attrib;
2423 obj_context->codec_type = CODEC_ENC;
2424 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2425 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2426 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2427 obj_context->codec_state.encode.packed_header_params_ext =
2428 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2429 sizeof(struct buffer_store *));
2431 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2432 obj_context->codec_state.encode.packed_header_data_ext =
2433 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2434 sizeof(struct buffer_store *));
2436 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2437 obj_context->codec_state.encode.slice_rawdata_index =
2438 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2439 obj_context->codec_state.encode.slice_rawdata_count =
2440 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2442 obj_context->codec_state.encode.slice_header_index =
2443 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2445 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2447 obj_context->codec_state.encode.slice_index = 0;
2448 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2449 if (packed_attrib) {
2450 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2451 if (obj_config->profile == VAProfileVP9Profile0)
2452 obj_context->codec_state.encode.packed_header_flag =
2453 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2455 /* use the default value. SPS/PPS/RAWDATA is passed from user
2456 * while Slice_header data is generated by driver.
2458 obj_context->codec_state.encode.packed_header_flag =
2459 VA_ENC_PACKED_HEADER_SEQUENCE |
2460 VA_ENC_PACKED_HEADER_PICTURE |
2461 VA_ENC_PACKED_HEADER_RAW_DATA;
2463 /* it is not used for VP9 */
2464 if (obj_config->profile == VAProfileVP9Profile0)
2465 obj_context->codec_state.encode.packed_header_flag = 0;
2467 assert(i965->codec_info->enc_hw_context_init);
2468 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2470 obj_context->codec_type = CODEC_DEC;
2471 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2472 obj_context->codec_state.decode.current_render_target = -1;
2473 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2474 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2475 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2476 sizeof(*obj_context->codec_state.decode.slice_params));
2477 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2478 sizeof(*obj_context->codec_state.decode.slice_datas));
2480 assert(i965->codec_info->dec_hw_context_init);
2481 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2485 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2487 return VA_STATUS_ERROR_INVALID_CONFIG;
2488 obj_context->codec_state.base.chroma_formats = attrib->value;
2490 if (obj_config->wrapper_config != VA_INVALID_ID) {
2491 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2492 * So it won't check i965->wrapper_pdrvctx again.
2493 * Fixme if it is incorrect.
2495 VAGenericID wrapper_context;
2498 * The render_surface is not passed when calling
2500 * If it is needed, we must get the wrapped surface
2501 * for the corresponding Surface_list.
2502 * So the wrapped surface conversion is deferred.
2504 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2505 vaCreateContext(i965->wrapper_pdrvctx,
2506 obj_config->wrapper_config,
2507 picture_width, picture_height,
2511 if (vaStatus == VA_STATUS_SUCCESS)
2512 obj_context->wrapper_context = wrapper_context;
2514 /* Error recovery */
2515 if (VA_STATUS_SUCCESS != vaStatus) {
2516 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2519 i965->current_context_id = contextID;
2525 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2527 struct i965_driver_data *i965 = i965_driver_data(ctx);
2528 struct object_context *obj_context = CONTEXT(context);
2529 VAStatus va_status = VA_STATUS_SUCCESS;
2531 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2533 if (i965->current_context_id == context)
2534 i965->current_context_id = VA_INVALID_ID;
2536 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2537 i965->wrapper_pdrvctx) {
2538 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2539 vaDestroyContext(i965->wrapper_pdrvctx,
2540 obj_context->wrapper_context));
2542 obj_context->wrapper_context = VA_INVALID_ID;
2545 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2551 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2553 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2555 assert(obj_buffer->buffer_store);
2556 i965_release_buffer_store(&obj_buffer->buffer_store);
2557 object_heap_free(heap, obj);
2561 i965_create_buffer_internal(VADriverContextP ctx,
2562 VAContextID context,
2565 unsigned int num_elements,
2570 struct i965_driver_data *i965 = i965_driver_data(ctx);
2571 struct object_buffer *obj_buffer = NULL;
2572 struct buffer_store *buffer_store = NULL;
2574 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2575 struct object_context *obj_context = CONTEXT(context);
2576 int wrapper_flag = 0;
2580 case VAPictureParameterBufferType:
2581 case VAIQMatrixBufferType:
2582 case VAQMatrixBufferType:
2583 case VABitPlaneBufferType:
2584 case VASliceGroupMapBufferType:
2585 case VASliceParameterBufferType:
2586 case VASliceDataBufferType:
2587 case VAMacroblockParameterBufferType:
2588 case VAResidualDataBufferType:
2589 case VADeblockingParameterBufferType:
2590 case VAImageBufferType:
2591 case VAEncCodedBufferType:
2592 case VAEncSequenceParameterBufferType:
2593 case VAEncPictureParameterBufferType:
2594 case VAEncSliceParameterBufferType:
2595 case VAEncPackedHeaderParameterBufferType:
2596 case VAEncPackedHeaderDataBufferType:
2597 case VAEncMiscParameterBufferType:
2598 case VAProcPipelineParameterBufferType:
2599 case VAProcFilterParameterBufferType:
2600 case VAHuffmanTableBufferType:
2601 case VAProbabilityBufferType:
2602 case VAEncMacroblockMapBufferType:
2607 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2610 bufferID = NEW_BUFFER_ID();
2611 obj_buffer = BUFFER(bufferID);
2613 if (NULL == obj_buffer) {
2614 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2617 if (type == VAEncCodedBufferType) {
2618 size += I965_CODEDBUFFER_HEADER_SIZE;
2619 size += 0x1000; /* for upper bound check */
2622 obj_buffer->max_num_elements = num_elements;
2623 obj_buffer->num_elements = num_elements;
2624 obj_buffer->size_element = size;
2625 obj_buffer->type = type;
2626 obj_buffer->export_refcount = 0;
2627 obj_buffer->buffer_store = NULL;
2628 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2629 obj_buffer->context_id = context;
2631 buffer_store = calloc(1, sizeof(struct buffer_store));
2632 assert(buffer_store);
2633 buffer_store->ref_count = 1;
2636 (obj_context->wrapper_context != VA_INVALID_ID) &&
2637 i965->wrapper_pdrvctx) {
2638 VAGenericID wrapper_buffer;
2639 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2641 CALL_VTABLE(pdrvctx, vaStatus,
2642 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2643 data, &wrapper_buffer));
2644 if (vaStatus == VA_STATUS_SUCCESS) {
2645 obj_buffer->wrapper_buffer = wrapper_buffer;
2653 if (store_bo != NULL) {
2654 buffer_store->bo = store_bo;
2655 dri_bo_reference(buffer_store->bo);
2657 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2658 if (data && !wrapper_flag)
2659 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2660 } else if (type == VASliceDataBufferType ||
2661 type == VAImageBufferType ||
2662 type == VAEncCodedBufferType ||
2663 type == VAEncMacroblockMapBufferType ||
2664 type == VAProbabilityBufferType) {
2666 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2667 * So it is enough to allocate one 64 byte bo
2670 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2673 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2675 size * num_elements, 64);
2676 assert(buffer_store->bo);
2678 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2679 * In fact it can be skipped. But it is still allocated and it is
2680 * only to follow the normal flowchart of buffer_allocation/release.
2682 if (!wrapper_flag) {
2683 if (type == VAEncCodedBufferType) {
2684 struct i965_coded_buffer_segment *coded_buffer_segment;
2686 dri_bo_map(buffer_store->bo, 1);
2687 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2688 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2689 coded_buffer_segment->base.bit_offset = 0;
2690 coded_buffer_segment->base.status = 0;
2691 coded_buffer_segment->base.buf = NULL;
2692 coded_buffer_segment->base.next = NULL;
2693 coded_buffer_segment->mapped = 0;
2694 coded_buffer_segment->codec = 0;
2695 coded_buffer_segment->status_support = 0;
2696 dri_bo_unmap(buffer_store->bo);
2698 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2705 if (type == VAEncPackedHeaderDataBufferType) {
2706 msize = ALIGN(size, 4);
2709 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2711 buffer_store->buffer = malloc(4);
2713 buffer_store->buffer = malloc(msize * num_elements);
2714 assert(buffer_store->buffer);
2716 if (!wrapper_flag) {
2718 memcpy(buffer_store->buffer, data, size * num_elements);
2720 memset(buffer_store->buffer, 0, size * num_elements);
2724 buffer_store->num_elements = obj_buffer->num_elements;
2725 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2726 i965_release_buffer_store(&buffer_store);
2729 return VA_STATUS_SUCCESS;
2733 i965_CreateBuffer(VADriverContextP ctx,
2734 VAContextID context, /* in */
2735 VABufferType type, /* in */
2736 unsigned int size, /* in */
2737 unsigned int num_elements, /* in */
2738 void *data, /* in */
2739 VABufferID *buf_id) /* out */
2741 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2746 i965_BufferSetNumElements(VADriverContextP ctx,
2747 VABufferID buf_id, /* in */
2748 unsigned int num_elements) /* in */
2750 struct i965_driver_data *i965 = i965_driver_data(ctx);
2751 struct object_buffer *obj_buffer = BUFFER(buf_id);
2752 VAStatus vaStatus = VA_STATUS_SUCCESS;
2754 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2756 /* When the wrapper_buffer exists, it will wrapper to the
2757 * buffer allocated from backend driver.
2759 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2760 i965->wrapper_pdrvctx) {
2761 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2763 CALL_VTABLE(pdrvctx, vaStatus,
2764 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2769 if ((num_elements < 0) ||
2770 (num_elements > obj_buffer->max_num_elements)) {
2771 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2773 obj_buffer->num_elements = num_elements;
2774 if (obj_buffer->buffer_store != NULL) {
2775 obj_buffer->buffer_store->num_elements = num_elements;
2783 i965_MapBuffer(VADriverContextP ctx,
2784 VABufferID buf_id, /* in */
2785 void **pbuf) /* out */
2787 struct i965_driver_data *i965 = i965_driver_data(ctx);
2788 struct object_buffer *obj_buffer = BUFFER(buf_id);
2789 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2790 struct object_context *obj_context;
2792 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2794 obj_context = CONTEXT(obj_buffer->context_id);
2796 /* When the wrapper_buffer exists, it will wrapper to the
2797 * buffer allocated from backend driver.
2799 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2800 i965->wrapper_pdrvctx) {
2801 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2803 CALL_VTABLE(pdrvctx, vaStatus,
2804 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2808 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2809 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2811 if (obj_buffer->export_refcount > 0)
2812 return VA_STATUS_ERROR_INVALID_BUFFER;
2814 if (NULL != obj_buffer->buffer_store->bo) {
2815 unsigned int tiling, swizzle;
2817 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2819 if (tiling != I915_TILING_NONE)
2820 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2822 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2824 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2825 *pbuf = obj_buffer->buffer_store->bo->virtual;
2826 vaStatus = VA_STATUS_SUCCESS;
2828 if (obj_buffer->type == VAEncCodedBufferType) {
2830 unsigned char *buffer = NULL;
2831 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2832 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2834 if (!coded_buffer_segment->mapped) {
2835 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2837 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2840 obj_context->hw_context &&
2841 obj_context->hw_context->get_status &&
2842 coded_buffer_segment->status_support) {
2843 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2845 if (coded_buffer_segment->codec == CODEC_H264 ||
2846 coded_buffer_segment->codec == CODEC_H264_MVC) {
2847 delimiter0 = H264_DELIMITER0;
2848 delimiter1 = H264_DELIMITER1;
2849 delimiter2 = H264_DELIMITER2;
2850 delimiter3 = H264_DELIMITER3;
2851 delimiter4 = H264_DELIMITER4;
2852 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2853 delimiter0 = MPEG2_DELIMITER0;
2854 delimiter1 = MPEG2_DELIMITER1;
2855 delimiter2 = MPEG2_DELIMITER2;
2856 delimiter3 = MPEG2_DELIMITER3;
2857 delimiter4 = MPEG2_DELIMITER4;
2858 } else if (coded_buffer_segment->codec == CODEC_JPEG) {
2859 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2862 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2863 delimiter0 = HEVC_DELIMITER0;
2864 delimiter1 = HEVC_DELIMITER1;
2865 delimiter2 = HEVC_DELIMITER2;
2866 delimiter3 = HEVC_DELIMITER3;
2867 delimiter4 = HEVC_DELIMITER4;
2868 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2869 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2872 if (coded_buffer_segment->codec == CODEC_JPEG) {
2873 for (i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2874 if ((buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2878 coded_buffer_segment->base.size = i + 2;
2879 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2880 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2881 so it don't need to traversal the coded buffer */
2882 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2883 if ((buffer[i] == delimiter0) &&
2884 (buffer[i + 1] == delimiter1) &&
2885 (buffer[i + 2] == delimiter2) &&
2886 (buffer[i + 3] == delimiter3) &&
2887 (buffer[i + 4] == delimiter4))
2891 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2892 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2894 coded_buffer_segment->base.size = i;
2897 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2898 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2901 vaStatus = VA_STATUS_SUCCESS;
2904 coded_buffer_segment->mapped = 1;
2906 assert(coded_buffer_segment->base.buf);
2907 vaStatus = VA_STATUS_SUCCESS;
2910 } else if (NULL != obj_buffer->buffer_store->buffer) {
2911 *pbuf = obj_buffer->buffer_store->buffer;
2912 vaStatus = VA_STATUS_SUCCESS;
2919 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2921 struct i965_driver_data *i965 = i965_driver_data(ctx);
2922 struct object_buffer *obj_buffer = BUFFER(buf_id);
2923 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2925 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2926 return VA_STATUS_ERROR_INVALID_BUFFER;
2928 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2929 /* When the wrapper_buffer exists, it will wrapper to the
2930 * buffer allocated from backend driver.
2932 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2933 i965->wrapper_pdrvctx) {
2934 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2936 CALL_VTABLE(pdrvctx, vaStatus,
2937 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2941 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2942 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2944 if (NULL != obj_buffer->buffer_store->bo) {
2945 unsigned int tiling, swizzle;
2947 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2949 if (tiling != I915_TILING_NONE)
2950 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2952 dri_bo_unmap(obj_buffer->buffer_store->bo);
2954 vaStatus = VA_STATUS_SUCCESS;
2955 } else if (NULL != obj_buffer->buffer_store->buffer) {
2957 vaStatus = VA_STATUS_SUCCESS;
2964 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2966 struct i965_driver_data *i965 = i965_driver_data(ctx);
2967 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2968 VAStatus va_status = VA_STATUS_SUCCESS;
2970 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2972 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2973 i965->wrapper_pdrvctx) {
2974 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2975 vaDestroyBuffer(i965->wrapper_pdrvctx,
2976 obj_buffer->wrapper_buffer));
2977 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2980 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2986 i965_BeginPicture(VADriverContextP ctx,
2987 VAContextID context,
2988 VASurfaceID render_target)
2990 struct i965_driver_data *i965 = i965_driver_data(ctx);
2991 struct object_context *obj_context = CONTEXT(context);
2992 struct object_surface *obj_surface = SURFACE(render_target);
2993 struct object_config *obj_config;
2994 VAStatus vaStatus = VA_STATUS_SUCCESS;
2997 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2998 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2999 obj_config = obj_context->obj_config;
3000 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3002 if (is_surface_busy(i965, obj_surface))
3003 return VA_STATUS_ERROR_SURFACE_BUSY;
3005 if (obj_context->codec_type == CODEC_PROC) {
3006 obj_context->codec_state.proc.current_render_target = render_target;
3007 } else if (obj_context->codec_type == CODEC_ENC) {
3009 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
3011 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
3012 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
3014 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
3015 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
3017 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
3018 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
3020 obj_context->codec_state.encode.num_slice_params_ext = 0;
3021 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
3022 obj_context->codec_state.encode.last_packed_header_type = 0;
3023 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
3024 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3025 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
3026 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3027 memset(obj_context->codec_state.encode.slice_header_index, 0,
3028 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3030 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
3031 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
3032 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
3033 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
3034 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
3035 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
3036 obj_context->codec_state.encode.slice_index = 0;
3037 obj_context->codec_state.encode.vps_sps_seq_index = 0;
3039 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
3040 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
3041 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
3043 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
3045 obj_context->codec_state.decode.current_render_target = render_target;
3046 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
3047 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
3048 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
3049 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
3051 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
3052 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
3053 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
3056 obj_context->codec_state.decode.num_slice_params = 0;
3057 obj_context->codec_state.decode.num_slice_datas = 0;
3059 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
3060 i965->wrapper_pdrvctx) {
3061 if (obj_surface->wrapper_surface == VA_INVALID_ID)
3062 vaStatus = i965_surface_wrapper(ctx, render_target);
3064 if (vaStatus != VA_STATUS_SUCCESS)
3067 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
3068 vaBeginPicture(i965->wrapper_pdrvctx,
3069 obj_context->wrapper_context,
3070 obj_surface->wrapper_surface));
3077 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
3079 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
3081 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3082 struct object_context *obj_context, \
3083 struct object_buffer *obj_buffer) \
3085 struct category##_state *category = &obj_context->codec_state.category; \
3086 i965_release_buffer_store(&category->member); \
3087 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
3088 return VA_STATUS_SUCCESS; \
3091 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
3093 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3094 struct object_context *obj_context, \
3095 struct object_buffer *obj_buffer) \
3097 struct category##_state *category = &obj_context->codec_state.category; \
3098 if (category->num_##member == category->max_##member) { \
3099 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
3100 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
3101 category->max_##member += NUM_SLICES; \
3103 i965_release_buffer_store(&category->member[category->num_##member]); \
3104 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
3105 category->num_##member++; \
3106 return VA_STATUS_SUCCESS; \
3109 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
3111 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
3112 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3113 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
3114 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
3115 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3116 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
3118 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
3119 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3120 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
3124 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
3125 VABufferID *buffers,
3128 struct i965_driver_data *i965 = i965_driver_data(ctx);
3129 VAStatus vaStatus = VA_STATUS_SUCCESS;
3131 VADecPictureParameterBufferVP9 *pVp9PicParams;
3132 VADriverContextP pdrvctx;
3133 struct object_buffer *obj_buffer;
3135 pdrvctx = i965->wrapper_pdrvctx;
3136 /* do the conversion of VADecPictureParameterBufferVP9 */
3137 for (i = 0; i < num_buffers; i++) {
3138 obj_buffer = BUFFER(buffers[i]);
3143 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
3146 if (obj_buffer->type == VAPictureParameterBufferType) {
3148 VASurfaceID surface_id;
3149 struct object_surface *obj_surface;
3151 pdrvctx = i965->wrapper_pdrvctx;
3153 CALL_VTABLE(pdrvctx, vaStatus,
3154 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
3155 (void **)(&pVp9PicParams)));
3157 if (vaStatus != VA_STATUS_SUCCESS)
3160 for (j = 0; j < 8; j++) {
3161 surface_id = pVp9PicParams->reference_frames[j];
3162 obj_surface = SURFACE(surface_id);
3167 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
3168 vaStatus = i965_surface_wrapper(ctx, surface_id);
3169 if (vaStatus != VA_STATUS_SUCCESS) {
3170 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
3171 obj_buffer->wrapper_buffer);
3176 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
3178 CALL_VTABLE(pdrvctx, vaStatus,
3179 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3184 return VA_STATUS_SUCCESS;
3191 i965_decoder_wrapper_picture(VADriverContextP ctx,
3192 VAContextID context,
3193 VABufferID *buffers,
3196 struct i965_driver_data *i965 = i965_driver_data(ctx);
3197 struct object_context *obj_context = CONTEXT(context);
3198 VAStatus vaStatus = VA_STATUS_SUCCESS;
3200 VADriverContextP pdrvctx;
3201 struct object_buffer *obj_buffer;
3203 if (obj_context == NULL)
3204 return VA_STATUS_ERROR_INVALID_CONTEXT;
3206 /* When it is not wrapped context, continue the normal flowchart */
3207 if (obj_context->wrapper_context == VA_INVALID_ID)
3210 if (obj_context->obj_config &&
3211 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3212 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3214 return VA_STATUS_ERROR_INVALID_PARAMETER;
3216 pdrvctx = i965->wrapper_pdrvctx;
3218 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3219 obj_buffer = BUFFER(buffers[i]);
3224 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3225 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3229 CALL_VTABLE(pdrvctx, vaStatus,
3230 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3231 &(obj_buffer->wrapper_buffer), 1));
3237 i965_decoder_render_picture(VADriverContextP ctx,
3238 VAContextID context,
3239 VABufferID *buffers,
3242 struct i965_driver_data *i965 = i965_driver_data(ctx);
3243 struct object_context *obj_context = CONTEXT(context);
3244 VAStatus vaStatus = VA_STATUS_SUCCESS;
3247 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3249 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3250 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3253 return VA_STATUS_ERROR_INVALID_BUFFER;
3255 switch (obj_buffer->type) {
3256 case VAPictureParameterBufferType:
3257 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3260 case VAIQMatrixBufferType:
3261 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3264 case VABitPlaneBufferType:
3265 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3268 case VASliceParameterBufferType:
3269 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3272 case VASliceDataBufferType:
3273 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3276 case VAHuffmanTableBufferType:
3277 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3280 case VAProbabilityBufferType:
3281 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3285 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3290 if ((vaStatus == VA_STATUS_SUCCESS) &&
3291 (obj_context->wrapper_context != VA_INVALID_ID))
3292 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3297 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3299 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3300 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3301 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3302 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3303 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3304 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3305 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3306 /* extended buffer */
3307 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3308 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3309 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3311 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3312 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3313 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3315 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3316 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3319 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3320 struct object_context *obj_context,
3321 struct object_buffer *obj_buffer,
3324 struct encode_state *encode = &obj_context->codec_state.encode;
3326 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3327 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3328 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3329 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3331 return VA_STATUS_SUCCESS;
3335 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3336 struct object_context *obj_context,
3337 struct object_buffer *obj_buffer,
3340 struct encode_state *encode = &obj_context->codec_state.encode;
3342 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3343 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3344 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3345 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3347 return VA_STATUS_SUCCESS;
3351 i965_encoder_get_misc_paramerter_buffer_index(VADriverContextP ctx,
3352 struct encode_state *encode,
3353 VAEncMiscParameterBuffer *misc_param)
3357 if (!encode->has_layers)
3360 if (misc_param->type == VAEncMiscParameterTypeRateControl) {
3361 VAEncMiscParameterRateControl *misc_rate_control = (VAEncMiscParameterRateControl *)misc_param->data;
3363 index = misc_rate_control->rc_flags.bits.temporal_id;
3364 } else if (misc_param->type == VAEncMiscParameterTypeFrameRate) {
3365 VAEncMiscParameterFrameRate *misc_frame_rate = (VAEncMiscParameterFrameRate *)misc_param->data;
3367 index = misc_frame_rate->framerate_flags.bits.temporal_id;
3374 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3375 struct object_context *obj_context,
3376 struct object_buffer *obj_buffer)
3378 struct encode_state *encode = &obj_context->codec_state.encode;
3379 VAEncMiscParameterBuffer *param = NULL;
3382 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3383 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3385 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3387 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3388 return VA_STATUS_ERROR_INVALID_PARAMETER;
3390 if (param->type == VAEncMiscParameterTypeTemporalLayerStructure)
3391 encode->has_layers = 1;
3393 index = i965_encoder_get_misc_paramerter_buffer_index(ctx, encode, param);
3395 if (index >= ARRAY_ELEMS(encode->misc_param[0]))
3396 return VA_STATUS_ERROR_INVALID_PARAMETER;
3398 i965_release_buffer_store(&encode->misc_param[param->type][index]);
3399 i965_reference_buffer_store(&encode->misc_param[param->type][index], obj_buffer->buffer_store);
3401 return VA_STATUS_SUCCESS;
3405 i965_encoder_render_picture(VADriverContextP ctx,
3406 VAContextID context,
3407 VABufferID *buffers,
3410 struct i965_driver_data *i965 = i965_driver_data(ctx);
3411 struct object_context *obj_context = CONTEXT(context);
3412 struct object_config *obj_config;
3413 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3414 struct encode_state *encode;
3417 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3418 obj_config = obj_context->obj_config;
3419 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3421 encode = &obj_context->codec_state.encode;
3422 for (i = 0; i < num_buffers; i++) {
3423 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3426 return VA_STATUS_ERROR_INVALID_BUFFER;
3428 switch (obj_buffer->type) {
3429 case VAQMatrixBufferType:
3430 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3433 case VAIQMatrixBufferType:
3434 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3437 case VAEncSequenceParameterBufferType:
3438 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3441 case VAEncPictureParameterBufferType:
3442 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3445 case VAHuffmanTableBufferType:
3446 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3449 case VAEncSliceParameterBufferType:
3450 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3451 if (vaStatus == VA_STATUS_SUCCESS) {
3452 /* When the max number of slices is updated, it also needs
3453 * to reallocate the arrays that is used to store
3454 * the packed data index/count for the slice
3456 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3457 encode->slice_index++;
3459 if (encode->slice_index == encode->max_slice_num) {
3460 int slice_num = encode->max_slice_num;
3461 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3462 (slice_num + NUM_SLICES) * sizeof(int));
3463 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3464 (slice_num + NUM_SLICES) * sizeof(int));
3465 encode->slice_header_index = realloc(encode->slice_header_index,
3466 (slice_num + NUM_SLICES) * sizeof(int));
3467 memset(encode->slice_rawdata_index + slice_num, 0,
3468 sizeof(int) * NUM_SLICES);
3469 memset(encode->slice_rawdata_count + slice_num, 0,
3470 sizeof(int) * NUM_SLICES);
3471 memset(encode->slice_header_index + slice_num, 0,
3472 sizeof(int) * NUM_SLICES);
3474 encode->max_slice_num += NUM_SLICES;
3475 if ((encode->slice_rawdata_index == NULL) ||
3476 (encode->slice_header_index == NULL) ||
3477 (encode->slice_rawdata_count == NULL)) {
3478 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3485 case VAEncPackedHeaderParameterBufferType: {
3486 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3487 encode->last_packed_header_type = param->type;
3489 if ((param->type == VAEncPackedHeaderRawData) ||
3490 (param->type == VAEncPackedHeaderSlice)) {
3491 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3492 } else if ((obj_config->profile == VAProfileHEVCMain ||
3493 obj_config->profile == VAProfileHEVCMain10) &&
3494 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3495 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3498 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3500 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3503 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3508 case VAEncPackedHeaderDataBufferType: {
3509 if (encode->last_packed_header_type == 0) {
3510 WARN_ONCE("the packed header data is passed without type!\n");
3511 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3515 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3516 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3517 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3519 if (obj_config->profile == VAProfileVP9Profile0)
3522 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3523 * the packed_slice_header as the delimeter to decide how
3524 * the packed rawdata is inserted for the given slice.
3525 * Otherwise it will use the VAEncSequenceParameterBuffer
3528 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3529 /* store the first index of the packed header data for current slice */
3530 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3531 encode->slice_rawdata_index[encode->slice_index] =
3532 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3534 encode->slice_rawdata_count[encode->slice_index]++;
3535 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3536 /* find one packed slice_header delimeter. And the following
3537 * packed data is for the next slice
3539 encode->slice_header_index[encode->slice_index] =
3540 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3541 encode->slice_index++;
3542 /* Reallocate the buffer to record the index/count of
3543 * packed_data for one slice.
3545 if (encode->slice_index == encode->max_slice_num) {
3546 int slice_num = encode->max_slice_num;
3548 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3549 (slice_num + NUM_SLICES) * sizeof(int));
3550 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3551 (slice_num + NUM_SLICES) * sizeof(int));
3552 encode->slice_header_index = realloc(encode->slice_header_index,
3553 (slice_num + NUM_SLICES) * sizeof(int));
3554 memset(encode->slice_rawdata_index + slice_num, 0,
3555 sizeof(int) * NUM_SLICES);
3556 memset(encode->slice_rawdata_count + slice_num, 0,
3557 sizeof(int) * NUM_SLICES);
3558 memset(encode->slice_header_index + slice_num, 0,
3559 sizeof(int) * NUM_SLICES);
3560 encode->max_slice_num += NUM_SLICES;
3564 if (vaStatus == VA_STATUS_SUCCESS) {
3565 /* store the first index of the packed header data for current slice */
3566 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3567 encode->slice_rawdata_index[encode->slice_index] =
3568 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3570 encode->slice_rawdata_count[encode->slice_index]++;
3571 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3572 if (encode->slice_header_index[encode->slice_index] == 0) {
3573 encode->slice_header_index[encode->slice_index] =
3574 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3576 WARN_ONCE("Multi slice header data is passed for"
3577 " slice %d!\n", encode->slice_index);
3583 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3584 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3585 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3586 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3587 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3588 VA_STATUS_ERROR_ENCODING_ERROR);
3590 if ((obj_config->profile == VAProfileHEVCMain ||
3591 obj_config->profile == VAProfileHEVCMain10) &&
3592 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3594 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3597 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3598 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3600 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3603 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3607 encode->last_packed_header_type = 0;
3611 case VAEncMiscParameterBufferType:
3612 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3617 case VAEncMacroblockMapBufferType:
3618 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3622 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3630 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3632 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3633 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3636 i965_proc_render_picture(VADriverContextP ctx,
3637 VAContextID context,
3638 VABufferID *buffers,
3641 struct i965_driver_data *i965 = i965_driver_data(ctx);
3642 struct object_context *obj_context = CONTEXT(context);
3643 VAStatus vaStatus = VA_STATUS_SUCCESS;
3646 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3648 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3649 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3652 return VA_STATUS_ERROR_INVALID_BUFFER;
3654 switch (obj_buffer->type) {
3655 case VAProcPipelineParameterBufferType:
3656 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3660 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3669 i965_RenderPicture(VADriverContextP ctx,
3670 VAContextID context,
3671 VABufferID *buffers,
3674 struct i965_driver_data *i965 = i965_driver_data(ctx);
3675 struct object_context *obj_context;
3676 struct object_config *obj_config;
3677 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3679 obj_context = CONTEXT(context);
3680 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3682 if (num_buffers <= 0)
3683 return VA_STATUS_ERROR_INVALID_PARAMETER;
3685 obj_config = obj_context->obj_config;
3686 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3688 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3689 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3690 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
3691 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3692 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3693 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3695 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3702 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3704 struct i965_driver_data *i965 = i965_driver_data(ctx);
3705 struct object_context *obj_context = CONTEXT(context);
3706 struct object_config *obj_config;
3708 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3709 obj_config = obj_context->obj_config;
3710 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3712 if (obj_context->codec_type == CODEC_PROC) {
3713 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3714 } else if (obj_context->codec_type == CODEC_ENC) {
3715 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3716 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3717 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3718 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3720 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3721 obj_context->codec_state.encode.num_packed_header_data_ext) {
3722 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3723 return VA_STATUS_ERROR_INVALID_PARAMETER;
3725 if (!obj_context->codec_state.encode.pic_param_ext) {
3726 return VA_STATUS_ERROR_INVALID_PARAMETER;
3728 if (!obj_context->codec_state.encode.seq_param_ext &&
3729 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3730 /* The seq_param is not mandatory for VP9 encoding */
3731 if (obj_config->profile != VAProfileVP9Profile0)
3732 return VA_STATUS_ERROR_INVALID_PARAMETER;
3734 if ((obj_context->codec_state.encode.num_slice_params_ext <= 0) &&
3735 ((obj_config->profile != VAProfileVP8Version0_3) &&
3736 (obj_config->profile != VAProfileVP9Profile0))) {
3737 return VA_STATUS_ERROR_INVALID_PARAMETER;
3740 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3741 (obj_context->codec_state.encode.num_slice_params_ext !=
3742 obj_context->codec_state.encode.slice_index)) {
3743 WARN_ONCE("packed slice_header data is missing for some slice"
3744 " under packed SLICE_HEADER mode\n");
3745 return VA_STATUS_ERROR_INVALID_PARAMETER;
3748 if (obj_context->codec_state.decode.pic_param == NULL) {
3749 return VA_STATUS_ERROR_INVALID_PARAMETER;
3751 if (obj_context->codec_state.decode.num_slice_params <= 0) {
3752 return VA_STATUS_ERROR_INVALID_PARAMETER;
3754 if (obj_context->codec_state.decode.num_slice_datas <= 0) {
3755 return VA_STATUS_ERROR_INVALID_PARAMETER;
3758 if (obj_context->codec_state.decode.num_slice_params !=
3759 obj_context->codec_state.decode.num_slice_datas) {
3760 return VA_STATUS_ERROR_INVALID_PARAMETER;
3763 if (obj_context->wrapper_context != VA_INVALID_ID) {
3764 /* call the vaEndPicture of wrapped driver */
3765 VADriverContextP pdrvctx;
3768 pdrvctx = i965->wrapper_pdrvctx;
3769 CALL_VTABLE(pdrvctx, va_status,
3770 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3776 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3777 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3781 i965_SyncSurface(VADriverContextP ctx,
3782 VASurfaceID render_target)
3784 struct i965_driver_data *i965 = i965_driver_data(ctx);
3785 struct object_surface *obj_surface = SURFACE(render_target);
3787 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3789 if (obj_surface->bo)
3790 drm_intel_bo_wait_rendering(obj_surface->bo);
3792 return VA_STATUS_SUCCESS;
3796 i965_QuerySurfaceStatus(VADriverContextP ctx,
3797 VASurfaceID render_target,
3798 VASurfaceStatus *status) /* out */
3800 struct i965_driver_data *i965 = i965_driver_data(ctx);
3801 struct object_surface *obj_surface = SURFACE(render_target);
3803 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3805 if (obj_surface->bo) {
3806 if (drm_intel_bo_busy(obj_surface->bo)) {
3807 *status = VASurfaceRendering;
3809 *status = VASurfaceReady;
3812 *status = VASurfaceReady;
3815 return VA_STATUS_SUCCESS;
3818 static VADisplayAttribute *
3819 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3821 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3824 if (!i965->display_attributes)
3827 for (i = 0; i < i965->num_display_attributes; i++) {
3828 if (i965->display_attributes[i].type == type)
3829 return &i965->display_attributes[i];
3835 i965_display_attributes_terminate(VADriverContextP ctx)
3837 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3839 if (i965->display_attributes) {
3840 free(i965->display_attributes);
3841 i965->display_attributes = NULL;
3842 i965->num_display_attributes = 0;
3847 i965_display_attributes_init(VADriverContextP ctx)
3849 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3851 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3852 i965->display_attributes = malloc(
3853 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3854 if (!i965->display_attributes)
3858 i965->display_attributes,
3859 i965_display_attributes,
3860 sizeof(i965_display_attributes)
3863 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3864 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3865 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3866 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3867 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3869 if (!i965->rotation_attrib ||
3870 !i965->brightness_attrib ||
3871 !i965->contrast_attrib ||
3872 !i965->hue_attrib ||
3873 !i965->saturation_attrib) {
3879 i965_display_attributes_terminate(ctx);
3884 * Query display attributes
3885 * The caller must provide a "attr_list" array that can hold at
3886 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3887 * returned in "attr_list" is returned in "num_attributes".
3890 i965_QueryDisplayAttributes(
3891 VADriverContextP ctx,
3892 VADisplayAttribute *attribs, /* out */
3893 int *num_attribs_ptr /* out */
3896 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3898 if (attribs && num_attribs > 0)
3899 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3901 if (num_attribs_ptr)
3902 *num_attribs_ptr = num_attribs;
3904 return VA_STATUS_SUCCESS;
3908 * Get display attributes
3909 * This function returns the current attribute values in "attr_list".
3910 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3911 * from vaQueryDisplayAttributes() can have their values retrieved.
3914 i965_GetDisplayAttributes(
3915 VADriverContextP ctx,
3916 VADisplayAttribute *attribs, /* inout */
3917 int num_attribs /* in */
3922 for (i = 0; i < num_attribs; i++) {
3923 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3925 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3927 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3928 dst_attrib->min_value = src_attrib->min_value;
3929 dst_attrib->max_value = src_attrib->max_value;
3930 dst_attrib->value = src_attrib->value;
3931 dst_attrib->flags = src_attrib->flags;
3932 } else if (src_attrib &&
3933 (src_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE)) {
3934 dst_attrib->flags = src_attrib->flags;
3936 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3938 return VA_STATUS_SUCCESS;
3942 * Set display attributes
3943 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3944 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3945 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3948 i965_SetDisplayAttributes(
3949 VADriverContextP ctx,
3950 VADisplayAttribute *attribs, /* in */
3951 int num_attribs /* in */
3956 for (i = 0; i < num_attribs; i++) {
3957 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3959 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3961 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3963 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3966 if (src_attrib->value < dst_attrib->min_value ||
3967 src_attrib->value > dst_attrib->max_value)
3968 return VA_STATUS_ERROR_INVALID_PARAMETER;
3970 dst_attrib->value = src_attrib->value;
3971 /* XXX: track modified attributes through timestamps */
3973 return VA_STATUS_SUCCESS;
3977 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3978 VASurfaceID surface,
3979 void **buffer, /* out */
3980 unsigned int *stride) /* out */
3983 return VA_STATUS_ERROR_UNIMPLEMENTED;
3987 i965_destroy_heap(struct object_heap *heap,
3988 void (*func)(struct object_heap *heap, struct object_base *object))
3990 struct object_base *object;
3991 object_heap_iterator iter;
3993 object = object_heap_first(heap, &iter);
3999 object = object_heap_next(heap, &iter);
4002 object_heap_destroy(heap);
4007 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
4010 i965_CreateImage(VADriverContextP ctx,
4011 VAImageFormat *format,
4014 VAImage *out_image) /* out */
4016 struct i965_driver_data *i965 = i965_driver_data(ctx);
4017 struct object_image *obj_image;
4018 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4020 unsigned int size2, size, awidth, aheight;
4022 out_image->image_id = VA_INVALID_ID;
4023 out_image->buf = VA_INVALID_ID;
4025 image_id = NEW_IMAGE_ID();
4026 if (image_id == VA_INVALID_ID)
4027 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4029 obj_image = IMAGE(image_id);
4031 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4032 obj_image->bo = NULL;
4033 obj_image->palette = NULL;
4034 obj_image->derived_surface = VA_INVALID_ID;
4036 VAImage * const image = &obj_image->image;
4037 image->image_id = image_id;
4038 image->buf = VA_INVALID_ID;
4040 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
4042 if ((format->fourcc == VA_FOURCC_YV12) ||
4043 (format->fourcc == VA_FOURCC_I420)) {
4044 if (awidth % 128 != 0) {
4045 awidth = ALIGN(width, 128);
4049 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
4050 size = awidth * aheight;
4051 size2 = (awidth / 2) * (aheight / 2);
4053 image->num_palette_entries = 0;
4054 image->entry_bytes = 0;
4055 memset(image->component_order, 0, sizeof(image->component_order));
4057 switch (format->fourcc) {
4058 case VA_FOURCC_IA44:
4059 case VA_FOURCC_AI44:
4060 image->num_planes = 1;
4061 image->pitches[0] = awidth;
4062 image->offsets[0] = 0;
4063 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4064 image->num_palette_entries = 16;
4065 image->entry_bytes = 3;
4066 image->component_order[0] = 'R';
4067 image->component_order[1] = 'G';
4068 image->component_order[2] = 'B';
4070 case VA_FOURCC_IA88:
4071 case VA_FOURCC_AI88:
4072 image->num_planes = 1;
4073 image->pitches[0] = awidth * 2;
4074 image->offsets[0] = 0;
4075 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4076 image->num_palette_entries = 256;
4077 image->entry_bytes = 3;
4078 image->component_order[0] = 'R';
4079 image->component_order[1] = 'G';
4080 image->component_order[2] = 'B';
4082 case VA_FOURCC_ARGB:
4083 case VA_FOURCC_ABGR:
4084 case VA_FOURCC_BGRA:
4085 case VA_FOURCC_RGBA:
4086 case VA_FOURCC_BGRX:
4087 case VA_FOURCC_RGBX:
4088 image->num_planes = 1;
4089 image->pitches[0] = awidth * 4;
4090 image->offsets[0] = 0;
4091 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4093 case VA_FOURCC_YV12:
4094 image->num_planes = 3;
4095 image->pitches[0] = awidth;
4096 image->offsets[0] = 0;
4097 image->pitches[1] = awidth / 2;
4098 image->offsets[1] = size;
4099 image->pitches[2] = awidth / 2;
4100 image->offsets[2] = size + size2;
4101 image->data_size = size + 2 * size2;
4103 case VA_FOURCC_I420:
4104 image->num_planes = 3;
4105 image->pitches[0] = awidth;
4106 image->offsets[0] = 0;
4107 image->pitches[1] = awidth / 2;
4108 image->offsets[1] = size;
4109 image->pitches[2] = awidth / 2;
4110 image->offsets[2] = size + size2;
4111 image->data_size = size + 2 * size2;
4113 case VA_FOURCC_422H:
4114 image->num_planes = 3;
4115 image->pitches[0] = awidth;
4116 image->offsets[0] = 0;
4117 image->pitches[1] = awidth / 2;
4118 image->offsets[1] = size;
4119 image->pitches[2] = awidth / 2;
4120 image->offsets[2] = size + (awidth / 2) * aheight;
4121 image->data_size = size + 2 * ((awidth / 2) * aheight);
4123 case VA_FOURCC_NV12:
4124 image->num_planes = 2;
4125 image->pitches[0] = awidth;
4126 image->offsets[0] = 0;
4127 image->pitches[1] = awidth;
4128 image->offsets[1] = size;
4129 image->data_size = size + 2 * size2;
4131 case VA_FOURCC_YUY2:
4132 case VA_FOURCC_UYVY:
4133 image->num_planes = 1;
4134 image->pitches[0] = awidth * 2;
4135 image->offsets[0] = 0;
4136 image->data_size = size * 2;
4138 case VA_FOURCC_P010:
4139 image->num_planes = 2;
4140 image->pitches[0] = awidth * 2;
4141 image->offsets[0] = 0;
4142 image->pitches[1] = awidth * 2;
4143 image->offsets[1] = size * 2;
4144 image->data_size = size * 2 + 2 * size2 * 2;
4150 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
4151 image->data_size, 1, NULL, &image->buf);
4152 if (va_status != VA_STATUS_SUCCESS)
4155 struct object_buffer *obj_buffer = BUFFER(image->buf);
4158 !obj_buffer->buffer_store ||
4159 !obj_buffer->buffer_store->bo)
4160 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4162 obj_image->bo = obj_buffer->buffer_store->bo;
4163 dri_bo_reference(obj_image->bo);
4165 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4166 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4167 if (!obj_image->palette)
4171 image->image_id = image_id;
4172 image->format = *format;
4173 image->width = width;
4174 image->height = height;
4176 *out_image = *image;
4177 return VA_STATUS_SUCCESS;
4180 i965_DestroyImage(ctx, image_id);
4185 i965_check_alloc_surface_bo(VADriverContextP ctx,
4186 struct object_surface *obj_surface,
4188 unsigned int fourcc,
4189 unsigned int subsampling)
4191 struct i965_driver_data *i965 = i965_driver_data(ctx);
4192 int region_width, region_height;
4194 if (obj_surface->bo) {
4195 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4196 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4197 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4198 return VA_STATUS_SUCCESS;
4201 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4202 obj_surface->x_cr_offset = 0;
4204 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4206 if ((tiled && !obj_surface->user_disable_tiling)) {
4207 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4208 fourcc != VA_FOURCC_IYUV &&
4209 fourcc != VA_FOURCC_YV12,
4210 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4212 if (obj_surface->user_h_stride_set) {
4213 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4215 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4217 if (obj_surface->user_v_stride_set) {
4218 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4220 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4222 region_height = obj_surface->height;
4225 case VA_FOURCC_NV12:
4226 case VA_FOURCC_P010:
4227 assert(subsampling == SUBSAMPLE_YUV420);
4228 obj_surface->cb_cr_pitch = obj_surface->width;
4229 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4230 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4231 obj_surface->y_cb_offset = obj_surface->height;
4232 obj_surface->y_cr_offset = obj_surface->height;
4233 region_width = obj_surface->width;
4234 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4238 case VA_FOURCC_IMC1:
4239 assert(subsampling == SUBSAMPLE_YUV420);
4240 obj_surface->cb_cr_pitch = obj_surface->width;
4241 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4242 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4243 obj_surface->y_cr_offset = obj_surface->height;
4244 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4245 region_width = obj_surface->width;
4246 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4250 case VA_FOURCC_IMC3:
4251 assert(subsampling == SUBSAMPLE_YUV420);
4252 obj_surface->cb_cr_pitch = obj_surface->width;
4253 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4254 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4255 obj_surface->y_cb_offset = obj_surface->height;
4256 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4257 region_width = obj_surface->width;
4258 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4262 case VA_FOURCC_422H:
4263 assert(subsampling == SUBSAMPLE_YUV422H);
4264 obj_surface->cb_cr_pitch = obj_surface->width;
4265 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4266 obj_surface->cb_cr_height = obj_surface->orig_height;
4267 obj_surface->y_cb_offset = obj_surface->height;
4268 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4269 region_width = obj_surface->width;
4270 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4274 case VA_FOURCC_422V:
4275 assert(subsampling == SUBSAMPLE_YUV422V);
4276 obj_surface->cb_cr_pitch = obj_surface->width;
4277 obj_surface->cb_cr_width = obj_surface->orig_width;
4278 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4279 obj_surface->y_cb_offset = obj_surface->height;
4280 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4281 region_width = obj_surface->width;
4282 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4286 case VA_FOURCC_411P:
4287 assert(subsampling == SUBSAMPLE_YUV411);
4288 obj_surface->cb_cr_pitch = obj_surface->width;
4289 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4290 obj_surface->cb_cr_height = obj_surface->orig_height;
4291 obj_surface->y_cb_offset = obj_surface->height;
4292 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4293 region_width = obj_surface->width;
4294 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4298 case VA_FOURCC_444P:
4299 assert(subsampling == SUBSAMPLE_YUV444);
4300 obj_surface->cb_cr_pitch = obj_surface->width;
4301 obj_surface->cb_cr_width = obj_surface->orig_width;
4302 obj_surface->cb_cr_height = obj_surface->orig_height;
4303 obj_surface->y_cb_offset = obj_surface->height;
4304 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4305 region_width = obj_surface->width;
4306 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4310 case VA_FOURCC_Y800:
4311 assert(subsampling == SUBSAMPLE_YUV400);
4312 obj_surface->cb_cr_pitch = 0;
4313 obj_surface->cb_cr_width = 0;
4314 obj_surface->cb_cr_height = 0;
4315 obj_surface->y_cb_offset = 0;
4316 obj_surface->y_cr_offset = 0;
4317 region_width = obj_surface->width;
4318 region_height = obj_surface->height;
4322 case VA_FOURCC_YUY2:
4323 case VA_FOURCC_UYVY:
4324 assert(subsampling == SUBSAMPLE_YUV422H);
4325 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4326 obj_surface->cb_cr_pitch = obj_surface->width;
4327 obj_surface->y_cb_offset = 0;
4328 obj_surface->y_cr_offset = 0;
4329 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4330 obj_surface->cb_cr_height = obj_surface->orig_height;
4331 region_width = obj_surface->width;
4332 region_height = obj_surface->height;
4336 case VA_FOURCC_RGBA:
4337 case VA_FOURCC_RGBX:
4338 case VA_FOURCC_BGRA:
4339 case VA_FOURCC_BGRX:
4340 assert(subsampling == SUBSAMPLE_RGBX);
4342 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4343 region_width = obj_surface->width;
4344 region_height = obj_surface->height;
4348 /* Never get here */
4349 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4353 assert(subsampling == SUBSAMPLE_YUV420 ||
4354 subsampling == SUBSAMPLE_YUV422H ||
4355 subsampling == SUBSAMPLE_YUV422V ||
4356 subsampling == SUBSAMPLE_RGBX);
4358 region_width = obj_surface->width;
4359 region_height = obj_surface->height;
4362 case VA_FOURCC_NV12:
4363 case VA_FOURCC_P010:
4364 obj_surface->y_cb_offset = obj_surface->height;
4365 obj_surface->y_cr_offset = obj_surface->height;
4366 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4367 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) *
4369 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4370 obj_surface->cb_cr_pitch = obj_surface->width;
4371 region_width = obj_surface->width;
4372 region_height = obj_surface->height + obj_surface->height / 2;
4375 case VA_FOURCC_YV16:
4376 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4377 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4378 obj_surface->cb_cr_height = obj_surface->orig_height;
4379 obj_surface->y_cr_offset = obj_surface->height;
4380 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4381 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4382 region_width = obj_surface->width;
4383 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4386 case VA_FOURCC_YV12:
4387 case VA_FOURCC_I420:
4388 case VA_FOURCC_IYUV:
4389 if (fourcc == VA_FOURCC_YV12) {
4390 obj_surface->y_cr_offset = obj_surface->height;
4391 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4393 obj_surface->y_cb_offset = obj_surface->height;
4394 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4397 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4398 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4399 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4400 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4401 region_width = obj_surface->width;
4402 region_height = obj_surface->height + obj_surface->height / 2;
4405 case VA_FOURCC_I010:
4406 obj_surface->y_cb_offset = obj_surface->height;
4407 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4408 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4409 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
4410 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4411 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4412 region_width = obj_surface->width;
4413 region_height = obj_surface->height + obj_surface->height / 2;
4416 case VA_FOURCC_YUY2:
4417 case VA_FOURCC_UYVY:
4418 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4419 obj_surface->y_cb_offset = 0;
4420 obj_surface->y_cr_offset = 0;
4421 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4422 obj_surface->cb_cr_height = obj_surface->orig_height;
4423 obj_surface->cb_cr_pitch = obj_surface->width;
4424 region_width = obj_surface->width;
4425 region_height = obj_surface->height;
4427 case VA_FOURCC_RGBA:
4428 case VA_FOURCC_RGBX:
4429 case VA_FOURCC_BGRA:
4430 case VA_FOURCC_BGRX:
4431 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4432 region_width = obj_surface->width;
4433 region_height = obj_surface->height;
4437 /* Never get here */
4438 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4443 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4445 if ((tiled && !obj_surface->user_disable_tiling)) {
4446 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4447 unsigned long pitch;
4449 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4457 assert(tiling_mode == I915_TILING_Y);
4458 assert(pitch == obj_surface->width);
4460 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4466 obj_surface->fourcc = fourcc;
4467 obj_surface->subsampling = subsampling;
4468 assert(obj_surface->bo);
4469 return VA_STATUS_SUCCESS;
4472 VAStatus i965_DeriveImage(VADriverContextP ctx,
4473 VASurfaceID surface,
4474 VAImage *out_image) /* out */
4476 struct i965_driver_data *i965 = i965_driver_data(ctx);
4477 struct object_image *obj_image;
4478 struct object_surface *obj_surface;
4480 unsigned int w_pitch;
4481 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4483 out_image->image_id = VA_INVALID_ID;
4484 obj_surface = SURFACE(surface);
4487 return VA_STATUS_ERROR_INVALID_SURFACE;
4489 if (!obj_surface->bo) {
4490 unsigned int is_tiled = 0;
4491 unsigned int fourcc = VA_FOURCC_YV12;
4492 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4493 int sampling = get_sampling_from_fourcc(fourcc);
4494 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4495 if (va_status != VA_STATUS_SUCCESS)
4499 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4501 w_pitch = obj_surface->width;
4503 image_id = NEW_IMAGE_ID();
4505 if (image_id == VA_INVALID_ID)
4506 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4508 obj_image = IMAGE(image_id);
4511 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4513 obj_image->bo = NULL;
4514 obj_image->palette = NULL;
4515 obj_image->derived_surface = VA_INVALID_ID;
4517 VAImage * const image = &obj_image->image;
4519 memset(image, 0, sizeof(*image));
4520 image->image_id = image_id;
4521 image->buf = VA_INVALID_ID;
4522 image->num_palette_entries = 0;
4523 image->entry_bytes = 0;
4524 image->width = obj_surface->orig_width;
4525 image->height = obj_surface->orig_height;
4526 image->data_size = obj_surface->size;
4528 image->format.fourcc = obj_surface->fourcc;
4529 image->format.byte_order = VA_LSB_FIRST;
4530 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4532 if (!image->format.bits_per_pixel)
4535 switch (image->format.fourcc) {
4536 case VA_FOURCC_YV12:
4537 image->num_planes = 3;
4538 image->pitches[0] = w_pitch; /* Y */
4539 image->offsets[0] = 0;
4540 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4541 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4542 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4543 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4546 case VA_FOURCC_YV16:
4547 image->num_planes = 3;
4548 image->pitches[0] = w_pitch; /* Y */
4549 image->offsets[0] = 0;
4550 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4551 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4552 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4553 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4556 case VA_FOURCC_NV12:
4557 case VA_FOURCC_P010:
4558 image->num_planes = 2;
4559 image->pitches[0] = w_pitch; /* Y */
4560 image->offsets[0] = 0;
4561 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4562 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4565 case VA_FOURCC_I420:
4566 case VA_FOURCC_I010:
4567 case VA_FOURCC_422H:
4568 case VA_FOURCC_IMC3:
4569 case VA_FOURCC_444P:
4570 case VA_FOURCC_422V:
4571 case VA_FOURCC_411P:
4572 image->num_planes = 3;
4573 image->pitches[0] = w_pitch; /* Y */
4574 image->offsets[0] = 0;
4575 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4576 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4577 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4578 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4581 case VA_FOURCC_YUY2:
4582 case VA_FOURCC_UYVY:
4583 case VA_FOURCC_Y800:
4584 image->num_planes = 1;
4585 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4586 image->offsets[0] = 0;
4588 case VA_FOURCC_RGBA:
4589 case VA_FOURCC_RGBX:
4590 case VA_FOURCC_BGRA:
4591 case VA_FOURCC_BGRX:
4592 image->num_planes = 1;
4593 image->pitches[0] = obj_surface->width;
4595 switch (image->format.fourcc) {
4596 case VA_FOURCC_RGBA:
4597 case VA_FOURCC_RGBX:
4598 image->format.red_mask = 0x000000ff;
4599 image->format.green_mask = 0x0000ff00;
4600 image->format.blue_mask = 0x00ff0000;
4602 case VA_FOURCC_BGRA:
4603 case VA_FOURCC_BGRX:
4604 image->format.red_mask = 0x00ff0000;
4605 image->format.green_mask = 0x0000ff00;
4606 image->format.blue_mask = 0x000000ff;
4612 switch (image->format.fourcc) {
4613 case VA_FOURCC_RGBA:
4614 case VA_FOURCC_BGRA:
4615 image->format.alpha_mask = 0xff000000;
4616 image->format.depth = 32;
4618 case VA_FOURCC_RGBX:
4619 case VA_FOURCC_BGRX:
4620 image->format.alpha_mask = 0x00000000;
4621 image->format.depth = 24;
4632 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4633 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4634 if (va_status != VA_STATUS_SUCCESS)
4637 struct object_buffer *obj_buffer = BUFFER(image->buf);
4640 !obj_buffer->buffer_store ||
4641 !obj_buffer->buffer_store->bo)
4642 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4644 obj_image->bo = obj_buffer->buffer_store->bo;
4645 dri_bo_reference(obj_image->bo);
4647 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4648 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4649 if (!obj_image->palette) {
4650 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4655 *out_image = *image;
4656 obj_surface->flags |= SURFACE_DERIVED;
4657 obj_surface->derived_image_id = image_id;
4658 obj_image->derived_surface = surface;
4660 return VA_STATUS_SUCCESS;
4663 i965_DestroyImage(ctx, image_id);
4668 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4670 object_heap_free(heap, obj);
4675 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4677 struct i965_driver_data *i965 = i965_driver_data(ctx);
4678 struct object_image *obj_image = IMAGE(image);
4679 struct object_surface *obj_surface;
4682 return VA_STATUS_SUCCESS;
4684 dri_bo_unreference(obj_image->bo);
4685 obj_image->bo = NULL;
4687 if (obj_image->image.buf != VA_INVALID_ID) {
4688 i965_DestroyBuffer(ctx, obj_image->image.buf);
4689 obj_image->image.buf = VA_INVALID_ID;
4692 if (obj_image->palette) {
4693 free(obj_image->palette);
4694 obj_image->palette = NULL;
4697 obj_surface = SURFACE(obj_image->derived_surface);
4700 obj_surface->flags &= ~SURFACE_DERIVED;
4701 obj_surface->derived_image_id = VA_INVALID_ID;
4704 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4706 return VA_STATUS_SUCCESS;
4710 * pointer to an array holding the palette data. The size of the array is
4711 * num_palette_entries * entry_bytes in size. The order of the components
4712 * in the palette is described by the component_order in VASubpicture struct
4715 i965_SetImagePalette(VADriverContextP ctx,
4717 unsigned char *palette)
4719 struct i965_driver_data *i965 = i965_driver_data(ctx);
4722 struct object_image *obj_image = IMAGE(image);
4724 return VA_STATUS_ERROR_INVALID_IMAGE;
4726 if (!obj_image->palette)
4727 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4729 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4730 obj_image->palette[i] = (((unsigned int)palette[3 * i + 0] << 16) |
4731 ((unsigned int)palette[3 * i + 1] << 8) |
4732 (unsigned int)palette[3 * i + 2]);
4733 return VA_STATUS_SUCCESS;
4737 get_sampling_from_fourcc(unsigned int fourcc)
4739 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4741 if (info && (info->flag & I_S))
4742 return info->subsampling;
4748 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4749 const uint8_t *src, unsigned int src_stride,
4750 unsigned int len, unsigned int height)
4754 for (i = 0; i < height; i++) {
4755 memcpy(dst, src, len);
4762 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4763 struct object_surface *obj_surface,
4764 const VARectangle *rect)
4766 uint8_t *dst[3], *src[3];
4768 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4769 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4770 unsigned int tiling, swizzle;
4771 VAStatus va_status = VA_STATUS_SUCCESS;
4773 if (!obj_surface->bo)
4774 return VA_STATUS_ERROR_INVALID_SURFACE;
4776 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4777 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4779 if (tiling != I915_TILING_NONE)
4780 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4782 dri_bo_map(obj_surface->bo, 0);
4784 if (!obj_surface->bo->virtual)
4785 return VA_STATUS_ERROR_INVALID_SURFACE;
4787 /* Dest VA image has either I420 or YV12 format.
4788 Source VA surface alway has I420 format */
4789 dst[Y] = image_data + obj_image->image.offsets[Y];
4790 src[0] = (uint8_t *)obj_surface->bo->virtual;
4791 dst[U] = image_data + obj_image->image.offsets[U];
4792 src[1] = src[0] + obj_surface->width * obj_surface->height;
4793 dst[V] = image_data + obj_image->image.offsets[V];
4794 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4797 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4798 src[0] += rect->y * obj_surface->width + rect->x;
4799 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4800 src[0], obj_surface->width,
4801 rect->width, rect->height);
4804 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4805 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4806 memcpy_pic(dst[U], obj_image->image.pitches[U],
4807 src[1], obj_surface->width / 2,
4808 rect->width / 2, rect->height / 2);
4811 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4812 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4813 memcpy_pic(dst[V], obj_image->image.pitches[V],
4814 src[2], obj_surface->width / 2,
4815 rect->width / 2, rect->height / 2);
4817 if (tiling != I915_TILING_NONE)
4818 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4820 dri_bo_unmap(obj_surface->bo);
4826 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4827 struct object_surface *obj_surface,
4828 const VARectangle *rect)
4830 uint8_t *dst[2], *src[2];
4831 unsigned int tiling, swizzle;
4832 VAStatus va_status = VA_STATUS_SUCCESS;
4834 if (!obj_surface->bo)
4835 return VA_STATUS_ERROR_INVALID_SURFACE;
4837 assert(obj_surface->fourcc);
4838 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4840 if (tiling != I915_TILING_NONE)
4841 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4843 dri_bo_map(obj_surface->bo, 0);
4845 if (!obj_surface->bo->virtual)
4846 return VA_STATUS_ERROR_INVALID_SURFACE;
4848 /* Both dest VA image and source surface have NV12 format */
4849 dst[0] = image_data + obj_image->image.offsets[0];
4850 src[0] = (uint8_t *)obj_surface->bo->virtual;
4851 dst[1] = image_data + obj_image->image.offsets[1];
4852 src[1] = src[0] + obj_surface->width * obj_surface->height;
4855 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4856 src[0] += rect->y * obj_surface->width + rect->x;
4857 memcpy_pic(dst[0], obj_image->image.pitches[0],
4858 src[0], obj_surface->width,
4859 rect->width, rect->height);
4862 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4863 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4864 memcpy_pic(dst[1], obj_image->image.pitches[1],
4865 src[1], obj_surface->width,
4866 rect->width, rect->height / 2);
4868 if (tiling != I915_TILING_NONE)
4869 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4871 dri_bo_unmap(obj_surface->bo);
4877 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4878 struct object_surface *obj_surface,
4879 const VARectangle *rect)
4882 unsigned int tiling, swizzle;
4883 VAStatus va_status = VA_STATUS_SUCCESS;
4885 if (!obj_surface->bo)
4886 return VA_STATUS_ERROR_INVALID_SURFACE;
4888 assert(obj_surface->fourcc);
4889 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4891 if (tiling != I915_TILING_NONE)
4892 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4894 dri_bo_map(obj_surface->bo, 0);
4896 if (!obj_surface->bo->virtual)
4897 return VA_STATUS_ERROR_INVALID_SURFACE;
4899 /* Both dest VA image and source surface have YUYV format */
4900 dst = image_data + obj_image->image.offsets[0];
4901 src = (uint8_t *)obj_surface->bo->virtual;
4904 dst += rect->y * obj_image->image.pitches[0] + rect->x * 2;
4905 src += rect->y * obj_surface->width + rect->x * 2;
4906 memcpy_pic(dst, obj_image->image.pitches[0],
4907 src, obj_surface->width * 2,
4908 rect->width * 2, rect->height);
4910 if (tiling != I915_TILING_NONE)
4911 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4913 dri_bo_unmap(obj_surface->bo);
4919 i965_sw_getimage(VADriverContextP ctx,
4920 struct object_surface *obj_surface, struct object_image *obj_image,
4921 const VARectangle *rect)
4923 void *image_data = NULL;
4926 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4927 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4929 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4930 if (va_status != VA_STATUS_SUCCESS)
4933 switch (obj_image->image.format.fourcc) {
4934 case VA_FOURCC_YV12:
4935 case VA_FOURCC_I420:
4936 get_image_i420(obj_image, image_data, obj_surface, rect);
4938 case VA_FOURCC_NV12:
4939 get_image_nv12(obj_image, image_data, obj_surface, rect);
4941 case VA_FOURCC_YUY2:
4942 /* YUY2 is the format supported by overlay plane */
4943 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4946 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4949 if (va_status != VA_STATUS_SUCCESS)
4952 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4957 i965_hw_getimage(VADriverContextP ctx,
4958 struct object_surface *obj_surface, struct object_image *obj_image,
4959 const VARectangle *rect)
4961 struct i965_surface src_surface;
4962 struct i965_surface dst_surface;
4964 src_surface.base = (struct object_base *)obj_surface;
4965 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4966 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4968 dst_surface.base = (struct object_base *)obj_image;
4969 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4970 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4972 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4976 i965_GetImage(VADriverContextP ctx,
4977 VASurfaceID surface,
4978 int x, /* coordinates of the upper left source pixel */
4980 unsigned int width, /* width and height of the region */
4981 unsigned int height,
4984 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4985 struct object_surface * const obj_surface = SURFACE(surface);
4986 struct object_image * const obj_image = IMAGE(image);
4991 return VA_STATUS_ERROR_INVALID_SURFACE;
4992 if (!obj_surface->bo) /* don't get anything, keep previous data */
4993 return VA_STATUS_SUCCESS;
4994 if (is_surface_busy(i965, obj_surface))
4995 return VA_STATUS_ERROR_SURFACE_BUSY;
4997 if (!obj_image || !obj_image->bo)
4998 return VA_STATUS_ERROR_INVALID_IMAGE;
4999 if (is_image_busy(i965, obj_image, surface))
5000 return VA_STATUS_ERROR_SURFACE_BUSY;
5003 return VA_STATUS_ERROR_INVALID_PARAMETER;
5004 if (x + width > obj_surface->orig_width ||
5005 y + height > obj_surface->orig_height)
5006 return VA_STATUS_ERROR_INVALID_PARAMETER;
5007 if (x + width > obj_image->image.width ||
5008 y + height > obj_image->image.height)
5009 return VA_STATUS_ERROR_INVALID_PARAMETER;
5014 rect.height = height;
5016 if (HAS_ACCELERATED_GETIMAGE(i965))
5017 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
5019 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
5025 put_image_i420(struct object_surface *obj_surface,
5026 const VARectangle *dst_rect,
5027 struct object_image *obj_image, uint8_t *image_data,
5028 const VARectangle *src_rect)
5030 uint8_t *dst[3], *src[3];
5032 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
5033 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
5034 unsigned int tiling, swizzle;
5035 VAStatus va_status = VA_STATUS_SUCCESS;
5037 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5039 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5040 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5041 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5042 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5044 if (tiling != I915_TILING_NONE)
5045 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5047 dri_bo_map(obj_surface->bo, 0);
5049 if (!obj_surface->bo->virtual)
5050 return VA_STATUS_ERROR_INVALID_SURFACE;
5052 /* Dest VA image has either I420 or YV12 format.
5053 Source VA surface alway has I420 format */
5054 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5055 src[Y] = image_data + obj_image->image.offsets[Y];
5056 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5057 src[U] = image_data + obj_image->image.offsets[U];
5058 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
5059 src[V] = image_data + obj_image->image.offsets[V];
5062 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5063 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
5064 memcpy_pic(dst[0], obj_surface->width,
5065 src[Y], obj_image->image.pitches[Y],
5066 src_rect->width, src_rect->height);
5069 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5070 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
5071 memcpy_pic(dst[1], obj_surface->width / 2,
5072 src[U], obj_image->image.pitches[U],
5073 src_rect->width / 2, src_rect->height / 2);
5076 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5077 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
5078 memcpy_pic(dst[2], obj_surface->width / 2,
5079 src[V], obj_image->image.pitches[V],
5080 src_rect->width / 2, src_rect->height / 2);
5082 if (tiling != I915_TILING_NONE)
5083 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5085 dri_bo_unmap(obj_surface->bo);
5091 put_image_nv12(struct object_surface *obj_surface,
5092 const VARectangle *dst_rect,
5093 struct object_image *obj_image, uint8_t *image_data,
5094 const VARectangle *src_rect)
5096 uint8_t *dst[2], *src[2];
5097 unsigned int tiling, swizzle;
5098 VAStatus va_status = VA_STATUS_SUCCESS;
5100 if (!obj_surface->bo)
5101 return VA_STATUS_ERROR_INVALID_SURFACE;
5103 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5104 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5105 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5106 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5108 if (tiling != I915_TILING_NONE)
5109 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5111 dri_bo_map(obj_surface->bo, 0);
5113 if (!obj_surface->bo->virtual)
5114 return VA_STATUS_ERROR_INVALID_SURFACE;
5116 /* Both dest VA image and source surface have NV12 format */
5117 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5118 src[0] = image_data + obj_image->image.offsets[0];
5119 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5120 src[1] = image_data + obj_image->image.offsets[1];
5123 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5124 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
5125 memcpy_pic(dst[0], obj_surface->width,
5126 src[0], obj_image->image.pitches[0],
5127 src_rect->width, src_rect->height);
5130 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
5131 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
5132 memcpy_pic(dst[1], obj_surface->width,
5133 src[1], obj_image->image.pitches[1],
5134 src_rect->width, src_rect->height / 2);
5136 if (tiling != I915_TILING_NONE)
5137 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5139 dri_bo_unmap(obj_surface->bo);
5145 put_image_yuy2(struct object_surface *obj_surface,
5146 const VARectangle *dst_rect,
5147 struct object_image *obj_image, uint8_t *image_data,
5148 const VARectangle *src_rect)
5151 unsigned int tiling, swizzle;
5152 VAStatus va_status = VA_STATUS_SUCCESS;
5154 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5155 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5156 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5157 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5158 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5160 if (tiling != I915_TILING_NONE)
5161 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5163 dri_bo_map(obj_surface->bo, 0);
5165 if (!obj_surface->bo->virtual)
5166 return VA_STATUS_ERROR_INVALID_SURFACE;
5168 /* Both dest VA image and source surface have YUY2 format */
5169 dst = (uint8_t *)obj_surface->bo->virtual;
5170 src = image_data + obj_image->image.offsets[0];
5172 /* YUYV packed plane */
5173 dst += dst_rect->y * obj_surface->width + dst_rect->x * 2;
5174 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x * 2;
5175 memcpy_pic(dst, obj_surface->width * 2,
5176 src, obj_image->image.pitches[0],
5177 src_rect->width * 2, src_rect->height);
5179 if (tiling != I915_TILING_NONE)
5180 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5182 dri_bo_unmap(obj_surface->bo);
5188 i965_sw_putimage(VADriverContextP ctx,
5189 struct object_surface *obj_surface, struct object_image *obj_image,
5190 const VARectangle *src_rect, const VARectangle *dst_rect)
5192 VAStatus va_status = VA_STATUS_SUCCESS;
5193 void *image_data = NULL;
5195 /* XXX: don't allow scaling */
5196 if (src_rect->width != dst_rect->width ||
5197 src_rect->height != dst_rect->height)
5198 return VA_STATUS_ERROR_INVALID_PARAMETER;
5200 if (obj_surface->fourcc) {
5201 /* Don't allow format mismatch */
5202 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5203 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5207 /* VA is surface not used for decoding, use same VA image format */
5208 va_status = i965_check_alloc_surface_bo(
5211 0, /* XXX: don't use tiled surface */
5212 obj_image->image.format.fourcc,
5213 get_sampling_from_fourcc(obj_image->image.format.fourcc));
5216 if (va_status != VA_STATUS_SUCCESS)
5219 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5220 if (va_status != VA_STATUS_SUCCESS)
5223 switch (obj_image->image.format.fourcc) {
5224 case VA_FOURCC_YV12:
5225 case VA_FOURCC_I420:
5226 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5228 case VA_FOURCC_NV12:
5229 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5231 case VA_FOURCC_YUY2:
5232 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5235 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5238 if (va_status != VA_STATUS_SUCCESS)
5241 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5246 i965_hw_putimage(VADriverContextP ctx,
5247 struct object_surface *obj_surface, struct object_image *obj_image,
5248 const VARectangle *src_rect, const VARectangle *dst_rect)
5250 struct i965_surface src_surface, dst_surface;
5251 VAStatus va_status = VA_STATUS_SUCCESS;
5253 if (!obj_surface->bo) {
5254 unsigned int tiling, swizzle;
5255 int surface_sampling = get_sampling_from_fourcc(obj_image->image.format.fourcc);;
5256 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5258 i965_check_alloc_surface_bo(ctx,
5261 obj_image->image.format.fourcc,
5265 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5267 src_surface.base = (struct object_base *)obj_image;
5268 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5269 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5271 dst_surface.base = (struct object_base *)obj_surface;
5272 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5273 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5275 va_status = i965_image_processing(ctx,
5285 i965_PutImage(VADriverContextP ctx,
5286 VASurfaceID surface,
5290 unsigned int src_width,
5291 unsigned int src_height,
5294 unsigned int dest_width,
5295 unsigned int dest_height)
5297 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5298 struct object_surface * const obj_surface = SURFACE(surface);
5299 struct object_image * const obj_image = IMAGE(image);
5300 VARectangle src_rect, dst_rect;
5304 return VA_STATUS_ERROR_INVALID_SURFACE;
5305 if (is_surface_busy(i965, obj_surface))
5306 return VA_STATUS_ERROR_SURFACE_BUSY;
5308 if (!obj_image || !obj_image->bo)
5309 return VA_STATUS_ERROR_INVALID_IMAGE;
5310 if (is_image_busy(i965, obj_image, surface))
5311 return VA_STATUS_ERROR_SURFACE_BUSY;
5315 src_x + src_width > obj_image->image.width ||
5316 src_y + src_height > obj_image->image.height)
5317 return VA_STATUS_ERROR_INVALID_PARAMETER;
5321 src_rect.width = src_width;
5322 src_rect.height = src_height;
5326 dest_x + dest_width > obj_surface->orig_width ||
5327 dest_y + dest_height > obj_surface->orig_height)
5328 return VA_STATUS_ERROR_INVALID_PARAMETER;
5330 dst_rect.x = dest_x;
5331 dst_rect.y = dest_y;
5332 dst_rect.width = dest_width;
5333 dst_rect.height = dest_height;
5335 if (HAS_ACCELERATED_PUTIMAGE(i965))
5336 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5337 &src_rect, &dst_rect);
5339 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5340 &src_rect, &dst_rect);
5346 i965_PutSurface(VADriverContextP ctx,
5347 VASurfaceID surface,
5348 void *draw, /* X Drawable */
5351 unsigned short srcw,
5352 unsigned short srch,
5355 unsigned short destw,
5356 unsigned short desth,
5357 VARectangle *cliprects, /* client supplied clip list */
5358 unsigned int number_cliprects, /* number of clip rects in the clip list */
5359 unsigned int flags) /* de-interlacing flags */
5362 if (IS_VA_X11(ctx)) {
5363 VARectangle src_rect, dst_rect;
5367 src_rect.width = srcw;
5368 src_rect.height = srch;
5372 dst_rect.width = destw;
5373 dst_rect.height = desth;
5375 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5376 cliprects, number_cliprects, flags);
5379 return VA_STATUS_ERROR_UNIMPLEMENTED;
5384 VADriverContextP ctx, /* in */
5385 VABufferID buf_id, /* in */
5386 VABufferType *type, /* out */
5387 unsigned int *size, /* out */
5388 unsigned int *num_elements /* out */
5391 struct i965_driver_data *i965 = NULL;
5392 struct object_buffer *obj_buffer = NULL;
5394 i965 = i965_driver_data(ctx);
5395 obj_buffer = BUFFER(buf_id);
5397 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5399 *type = obj_buffer->type;
5400 *size = obj_buffer->size_element;
5401 *num_elements = obj_buffer->num_elements;
5403 return VA_STATUS_SUCCESS;
5408 VADriverContextP ctx, /* in */
5409 VASurfaceID surface, /* in */
5410 unsigned int *fourcc, /* out */
5411 unsigned int *luma_stride, /* out */
5412 unsigned int *chroma_u_stride, /* out */
5413 unsigned int *chroma_v_stride, /* out */
5414 unsigned int *luma_offset, /* out */
5415 unsigned int *chroma_u_offset, /* out */
5416 unsigned int *chroma_v_offset, /* out */
5417 unsigned int *buffer_name, /* out */
5418 void **buffer /* out */
5421 VAStatus vaStatus = VA_STATUS_SUCCESS;
5422 struct i965_driver_data *i965 = i965_driver_data(ctx);
5423 struct object_surface *obj_surface = NULL;
5426 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5427 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5428 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5429 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5430 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5431 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5432 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5433 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5434 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5436 tmpImage.image_id = VA_INVALID_ID;
5438 obj_surface = SURFACE(surface);
5439 if (obj_surface == NULL) {
5440 // Surface is absent.
5441 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5445 // Lock functionality is absent now.
5446 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5447 // Surface is locked already.
5448 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5452 vaStatus = i965_DeriveImage(
5456 if (vaStatus != VA_STATUS_SUCCESS) {
5460 obj_surface->locked_image_id = tmpImage.image_id;
5462 vaStatus = i965_MapBuffer(
5466 if (vaStatus != VA_STATUS_SUCCESS) {
5470 *fourcc = tmpImage.format.fourcc;
5471 *luma_offset = tmpImage.offsets[0];
5472 *luma_stride = tmpImage.pitches[0];
5473 *chroma_u_offset = tmpImage.offsets[1];
5474 *chroma_u_stride = tmpImage.pitches[1];
5475 *chroma_v_offset = tmpImage.offsets[2];
5476 *chroma_v_stride = tmpImage.pitches[2];
5477 *buffer_name = tmpImage.buf;
5480 if (vaStatus != VA_STATUS_SUCCESS) {
5489 VADriverContextP ctx, /* in */
5490 VASurfaceID surface /* in */
5493 VAStatus vaStatus = VA_STATUS_SUCCESS;
5494 struct i965_driver_data *i965 = i965_driver_data(ctx);
5495 struct object_image *locked_img = NULL;
5496 struct object_surface *obj_surface = NULL;
5498 obj_surface = SURFACE(surface);
5500 if (obj_surface == NULL) {
5501 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5504 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5505 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5509 locked_img = IMAGE(obj_surface->locked_image_id);
5510 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5511 // Work image was deallocated before i965_UnlockSurface()
5512 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5516 vaStatus = i965_UnmapBuffer(
5518 locked_img->image.buf);
5519 if (vaStatus != VA_STATUS_SUCCESS) {
5523 vaStatus = i965_DestroyImage(
5525 locked_img->image.image_id);
5526 if (vaStatus != VA_STATUS_SUCCESS) {
5530 locked_img->image.image_id = VA_INVALID_ID;
5533 obj_surface->locked_image_id = VA_INVALID_ID;
5539 i965_GetSurfaceAttributes(
5540 VADriverContextP ctx,
5542 VASurfaceAttrib *attrib_list,
5543 unsigned int num_attribs
5546 VAStatus vaStatus = VA_STATUS_SUCCESS;
5547 struct i965_driver_data *i965 = i965_driver_data(ctx);
5548 struct object_config *obj_config;
5551 if (config == VA_INVALID_ID)
5552 return VA_STATUS_ERROR_INVALID_CONFIG;
5554 obj_config = CONFIG(config);
5556 if (obj_config == NULL)
5557 return VA_STATUS_ERROR_INVALID_CONFIG;
5559 if (attrib_list == NULL || num_attribs == 0)
5560 return VA_STATUS_ERROR_INVALID_PARAMETER;
5562 for (i = 0; i < num_attribs; i++) {
5563 switch (attrib_list[i].type) {
5564 case VASurfaceAttribPixelFormat:
5565 attrib_list[i].value.type = VAGenericValueTypeInteger;
5566 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5568 if (attrib_list[i].value.value.i == 0) {
5569 if (IS_G4X(i965->intel.device_info)) {
5570 if (obj_config->profile == VAProfileMPEG2Simple ||
5571 obj_config->profile == VAProfileMPEG2Main) {
5572 attrib_list[i].value.value.i = VA_FOURCC_I420;
5575 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5577 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5578 if (obj_config->profile == VAProfileMPEG2Simple ||
5579 obj_config->profile == VAProfileMPEG2Main) {
5580 attrib_list[i].value.value.i = VA_FOURCC_I420;
5581 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5582 obj_config->profile == VAProfileH264Main ||
5583 obj_config->profile == VAProfileH264High) {
5584 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5585 } else if (obj_config->profile == VAProfileNone) {
5586 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5589 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5591 } else if (IS_GEN6(i965->intel.device_info)) {
5592 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5593 } else if (IS_GEN7(i965->intel.device_info) ||
5594 IS_GEN8(i965->intel.device_info) ||
5595 IS_GEN9(i965->intel.device_info)) {
5596 if (obj_config->profile == VAProfileJPEGBaseline)
5597 attrib_list[i].value.value.i = 0; /* internal format */
5599 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5602 if (IS_G4X(i965->intel.device_info)) {
5603 if (obj_config->profile == VAProfileMPEG2Simple ||
5604 obj_config->profile == VAProfileMPEG2Main) {
5605 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5606 attrib_list[i].value.value.i = 0;
5607 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5611 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5613 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5614 if (obj_config->profile == VAProfileMPEG2Simple ||
5615 obj_config->profile == VAProfileMPEG2Main) {
5616 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5617 attrib_list[i].value.value.i = 0;
5618 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5620 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5621 obj_config->profile == VAProfileH264Main ||
5622 obj_config->profile == VAProfileH264High) {
5623 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5624 attrib_list[i].value.value.i = 0;
5625 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5627 } else if (obj_config->profile == VAProfileNone) {
5628 switch (attrib_list[i].value.value.i) {
5629 case VA_FOURCC_NV12:
5630 case VA_FOURCC_I420:
5631 case VA_FOURCC_YV12:
5632 case VA_FOURCC_YUY2:
5633 case VA_FOURCC_BGRA:
5634 case VA_FOURCC_BGRX:
5635 case VA_FOURCC_RGBX:
5636 case VA_FOURCC_RGBA:
5639 attrib_list[i].value.value.i = 0;
5640 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5645 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5647 } else if (IS_GEN6(i965->intel.device_info)) {
5648 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5649 obj_config->entrypoint == VAEntrypointVideoProc) {
5650 switch (attrib_list[i].value.value.i) {
5651 case VA_FOURCC_NV12:
5652 case VA_FOURCC_I420:
5653 case VA_FOURCC_YV12:
5654 case VA_FOURCC_YUY2:
5655 case VA_FOURCC_BGRA:
5656 case VA_FOURCC_BGRX:
5657 case VA_FOURCC_RGBX:
5658 case VA_FOURCC_RGBA:
5661 attrib_list[i].value.value.i = 0;
5662 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5666 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5667 attrib_list[i].value.value.i = 0;
5668 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5671 } else if (IS_GEN7(i965->intel.device_info) ||
5672 IS_GEN8(i965->intel.device_info) ||
5673 IS_GEN9(i965->intel.device_info)) {
5674 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5675 obj_config->entrypoint == VAEntrypointVideoProc ||
5676 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5677 switch (attrib_list[i].value.value.i) {
5678 case VA_FOURCC_NV12:
5679 case VA_FOURCC_I420:
5680 case VA_FOURCC_YV12:
5683 attrib_list[i].value.value.i = 0;
5684 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5688 if (obj_config->profile == VAProfileJPEGBaseline) {
5689 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5690 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5692 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5693 attrib_list[i].value.value.i = 0;
5694 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5702 case VASurfaceAttribMinWidth:
5703 /* FIXME: add support for it later */
5704 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5706 case VASurfaceAttribMaxWidth:
5707 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5709 case VASurfaceAttribMinHeight:
5710 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5712 case VASurfaceAttribMaxHeight:
5713 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5716 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5725 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5727 VASurfaceAttrib *attrib_list,
5728 unsigned int *num_attribs)
5730 VAStatus vaStatus = VA_STATUS_SUCCESS;
5731 struct i965_driver_data *i965 = i965_driver_data(ctx);
5732 struct object_config *obj_config;
5734 VASurfaceAttrib *attribs = NULL;
5738 if (config == VA_INVALID_ID)
5739 return VA_STATUS_ERROR_INVALID_CONFIG;
5741 obj_config = CONFIG(config);
5743 if (obj_config == NULL)
5744 return VA_STATUS_ERROR_INVALID_CONFIG;
5746 if (!attrib_list && !num_attribs)
5747 return VA_STATUS_ERROR_INVALID_PARAMETER;
5749 if (attrib_list == NULL) {
5750 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5751 return VA_STATUS_SUCCESS;
5754 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES * sizeof(*attribs));
5756 if (attribs == NULL)
5757 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5759 if (IS_G4X(i965->intel.device_info)) {
5760 if (obj_config->profile == VAProfileMPEG2Simple ||
5761 obj_config->profile == VAProfileMPEG2Main) {
5762 attribs[i].type = VASurfaceAttribPixelFormat;
5763 attribs[i].value.type = VAGenericValueTypeInteger;
5764 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5765 attribs[i].value.value.i = VA_FOURCC_I420;
5768 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5769 switch (obj_config->profile) {
5770 case VAProfileMPEG2Simple:
5771 case VAProfileMPEG2Main:
5772 attribs[i].type = VASurfaceAttribPixelFormat;
5773 attribs[i].value.type = VAGenericValueTypeInteger;
5774 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5775 attribs[i].value.value.i = VA_FOURCC_I420;
5780 case VAProfileH264ConstrainedBaseline:
5781 case VAProfileH264Main:
5782 case VAProfileH264High:
5783 attribs[i].type = VASurfaceAttribPixelFormat;
5784 attribs[i].value.type = VAGenericValueTypeInteger;
5785 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5786 attribs[i].value.value.i = VA_FOURCC_NV12;
5790 attribs[i].type = VASurfaceAttribPixelFormat;
5791 attribs[i].value.type = VAGenericValueTypeInteger;
5792 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5793 attribs[i].value.value.i = VA_FOURCC_NV12;
5796 attribs[i].type = VASurfaceAttribPixelFormat;
5797 attribs[i].value.type = VAGenericValueTypeInteger;
5798 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5799 attribs[i].value.value.i = VA_FOURCC_I420;
5807 } else if (IS_GEN6(i965->intel.device_info)) {
5808 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5809 attribs[i].type = VASurfaceAttribPixelFormat;
5810 attribs[i].value.type = VAGenericValueTypeInteger;
5811 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5812 attribs[i].value.value.i = VA_FOURCC_NV12;
5814 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5815 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5816 attribs[i].type = VASurfaceAttribPixelFormat;
5817 attribs[i].value.type = VAGenericValueTypeInteger;
5818 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5819 attribs[i].value.value.i = VA_FOURCC_NV12;
5822 attribs[i].type = VASurfaceAttribPixelFormat;
5823 attribs[i].value.type = VAGenericValueTypeInteger;
5824 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5825 attribs[i].value.value.i = VA_FOURCC_I420;
5828 attribs[i].type = VASurfaceAttribPixelFormat;
5829 attribs[i].value.type = VAGenericValueTypeInteger;
5830 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5831 attribs[i].value.value.i = VA_FOURCC_YV12;
5834 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5835 attribs[i].type = VASurfaceAttribPixelFormat;
5836 attribs[i].value.type = VAGenericValueTypeInteger;
5837 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5838 attribs[i].value.value.i = VA_FOURCC_YUY2;
5841 attribs[i].type = VASurfaceAttribPixelFormat;
5842 attribs[i].value.type = VAGenericValueTypeInteger;
5843 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5844 attribs[i].value.value.i = VA_FOURCC_RGBA;
5847 attribs[i].type = VASurfaceAttribPixelFormat;
5848 attribs[i].value.type = VAGenericValueTypeInteger;
5849 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5850 attribs[i].value.value.i = VA_FOURCC_RGBX;
5854 } else if (IS_GEN7(i965->intel.device_info)) {
5855 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5856 if (obj_config->profile == VAProfileJPEGBaseline) {
5857 attribs[i].type = VASurfaceAttribPixelFormat;
5858 attribs[i].value.type = VAGenericValueTypeInteger;
5859 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5860 attribs[i].value.value.i = VA_FOURCC_IMC3;
5863 attribs[i].type = VASurfaceAttribPixelFormat;
5864 attribs[i].value.type = VAGenericValueTypeInteger;
5865 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5866 attribs[i].value.value.i = VA_FOURCC_IMC1;
5869 attribs[i].type = VASurfaceAttribPixelFormat;
5870 attribs[i].value.type = VAGenericValueTypeInteger;
5871 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5872 attribs[i].value.value.i = VA_FOURCC_Y800;
5875 attribs[i].type = VASurfaceAttribPixelFormat;
5876 attribs[i].value.type = VAGenericValueTypeInteger;
5877 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5878 attribs[i].value.value.i = VA_FOURCC_411P;
5881 attribs[i].type = VASurfaceAttribPixelFormat;
5882 attribs[i].value.type = VAGenericValueTypeInteger;
5883 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5884 attribs[i].value.value.i = VA_FOURCC_422H;
5887 attribs[i].type = VASurfaceAttribPixelFormat;
5888 attribs[i].value.type = VAGenericValueTypeInteger;
5889 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5890 attribs[i].value.value.i = VA_FOURCC_422V;
5893 attribs[i].type = VASurfaceAttribPixelFormat;
5894 attribs[i].value.type = VAGenericValueTypeInteger;
5895 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5896 attribs[i].value.value.i = VA_FOURCC_444P;
5898 } else if (obj_config->profile == VAProfileHEVCMain10) {
5899 attribs[i].type = VASurfaceAttribPixelFormat;
5900 attribs[i].value.type = VAGenericValueTypeInteger;
5901 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5902 attribs[i].value.value.i = VA_FOURCC_P010;
5905 attribs[i].type = VASurfaceAttribPixelFormat;
5906 attribs[i].value.type = VAGenericValueTypeInteger;
5907 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5908 attribs[i].value.value.i = VA_FOURCC_NV12;
5911 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5912 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5913 attribs[i].type = VASurfaceAttribPixelFormat;
5914 attribs[i].value.type = VAGenericValueTypeInteger;
5915 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5916 attribs[i].value.value.i = VA_FOURCC_NV12;
5919 attribs[i].type = VASurfaceAttribPixelFormat;
5920 attribs[i].value.type = VAGenericValueTypeInteger;
5921 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5922 attribs[i].value.value.i = VA_FOURCC_I420;
5925 attribs[i].type = VASurfaceAttribPixelFormat;
5926 attribs[i].value.type = VAGenericValueTypeInteger;
5927 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5928 attribs[i].value.value.i = VA_FOURCC_YV12;
5931 attribs[i].type = VASurfaceAttribPixelFormat;
5932 attribs[i].value.type = VAGenericValueTypeInteger;
5933 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5934 attribs[i].value.value.i = VA_FOURCC_IMC3;
5937 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5938 attribs[i].type = VASurfaceAttribPixelFormat;
5939 attribs[i].value.type = VAGenericValueTypeInteger;
5940 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5941 attribs[i].value.value.i = VA_FOURCC_YUY2;
5944 attribs[i].type = VASurfaceAttribPixelFormat;
5945 attribs[i].value.type = VAGenericValueTypeInteger;
5946 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5947 attribs[i].value.value.i = VA_FOURCC_RGBA;
5950 attribs[i].type = VASurfaceAttribPixelFormat;
5951 attribs[i].value.type = VAGenericValueTypeInteger;
5952 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5953 attribs[i].value.value.i = VA_FOURCC_RGBX;
5956 attribs[i].type = VASurfaceAttribPixelFormat;
5957 attribs[i].value.type = VAGenericValueTypeInteger;
5958 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5959 attribs[i].value.value.i = VA_FOURCC_BGRA;
5962 attribs[i].type = VASurfaceAttribPixelFormat;
5963 attribs[i].value.type = VAGenericValueTypeInteger;
5964 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5965 attribs[i].value.value.i = VA_FOURCC_BGRX;
5968 attribs[i].type = VASurfaceAttribPixelFormat;
5969 attribs[i].value.type = VAGenericValueTypeInteger;
5970 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5971 attribs[i].value.value.i = VA_FOURCC_YV16;
5975 } else if (IS_GEN8(i965->intel.device_info) ||
5976 IS_GEN9(i965->intel.device_info)) {
5977 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5978 if (obj_config->profile == VAProfileJPEGBaseline) {
5979 attribs[i].type = VASurfaceAttribPixelFormat;
5980 attribs[i].value.type = VAGenericValueTypeInteger;
5981 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5982 attribs[i].value.value.i = VA_FOURCC_IMC3;
5985 attribs[i].type = VASurfaceAttribPixelFormat;
5986 attribs[i].value.type = VAGenericValueTypeInteger;
5987 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5988 attribs[i].value.value.i = VA_FOURCC_IMC1;
5991 attribs[i].type = VASurfaceAttribPixelFormat;
5992 attribs[i].value.type = VAGenericValueTypeInteger;
5993 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5994 attribs[i].value.value.i = VA_FOURCC_Y800;
5997 attribs[i].type = VASurfaceAttribPixelFormat;
5998 attribs[i].value.type = VAGenericValueTypeInteger;
5999 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6000 attribs[i].value.value.i = VA_FOURCC_411P;
6003 attribs[i].type = VASurfaceAttribPixelFormat;
6004 attribs[i].value.type = VAGenericValueTypeInteger;
6005 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6006 attribs[i].value.value.i = VA_FOURCC_422H;
6009 attribs[i].type = VASurfaceAttribPixelFormat;
6010 attribs[i].value.type = VAGenericValueTypeInteger;
6011 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6012 attribs[i].value.value.i = VA_FOURCC_422V;
6015 attribs[i].type = VASurfaceAttribPixelFormat;
6016 attribs[i].value.type = VAGenericValueTypeInteger;
6017 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6018 attribs[i].value.value.i = VA_FOURCC_444P;
6021 attribs[i].type = VASurfaceAttribPixelFormat;
6022 attribs[i].value.type = VAGenericValueTypeInteger;
6023 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6024 attribs[i].value.value.i = VA_FOURCC_NV12;
6027 if ((obj_config->profile == VAProfileHEVCMain10) ||
6028 (obj_config->profile == VAProfileVP9Profile2)) {
6029 attribs[i].type = VASurfaceAttribPixelFormat;
6030 attribs[i].value.type = VAGenericValueTypeInteger;
6031 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6032 attribs[i].value.value.i = VA_FOURCC_P010;
6036 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6037 obj_config->entrypoint == VAEntrypointVideoProc ||
6038 obj_config->entrypoint == VAEntrypointEncSliceLP ||
6039 obj_config->entrypoint == VAEntrypointEncPicture) {
6041 if (obj_config->profile == VAProfileHEVCMain10) {
6042 attribs[i].type = VASurfaceAttribPixelFormat;
6043 attribs[i].value.type = VAGenericValueTypeInteger;
6044 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6045 attribs[i].value.value.i = VA_FOURCC_P010;
6048 attribs[i].type = VASurfaceAttribPixelFormat;
6049 attribs[i].value.type = VAGenericValueTypeInteger;
6050 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6051 attribs[i].value.value.i = VA_FOURCC_NV12;
6054 attribs[i].type = VASurfaceAttribPixelFormat;
6055 attribs[i].value.type = VAGenericValueTypeInteger;
6056 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6057 attribs[i].value.value.i = VA_FOURCC_I420;
6060 attribs[i].type = VASurfaceAttribPixelFormat;
6061 attribs[i].value.type = VAGenericValueTypeInteger;
6062 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6063 attribs[i].value.value.i = VA_FOURCC_YV12;
6066 attribs[i].type = VASurfaceAttribPixelFormat;
6067 attribs[i].value.type = VAGenericValueTypeInteger;
6068 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6069 attribs[i].value.value.i = VA_FOURCC_IMC3;
6073 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6074 attribs[i].type = VASurfaceAttribPixelFormat;
6075 attribs[i].value.type = VAGenericValueTypeInteger;
6076 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6077 attribs[i].value.value.i = VA_FOURCC_YUY2;
6080 attribs[i].type = VASurfaceAttribPixelFormat;
6081 attribs[i].value.type = VAGenericValueTypeInteger;
6082 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6083 attribs[i].value.value.i = VA_FOURCC_RGBA;
6086 attribs[i].type = VASurfaceAttribPixelFormat;
6087 attribs[i].value.type = VAGenericValueTypeInteger;
6088 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6089 attribs[i].value.value.i = VA_FOURCC_RGBX;
6092 attribs[i].type = VASurfaceAttribPixelFormat;
6093 attribs[i].value.type = VAGenericValueTypeInteger;
6094 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6095 attribs[i].value.value.i = VA_FOURCC_BGRA;
6098 attribs[i].type = VASurfaceAttribPixelFormat;
6099 attribs[i].value.type = VAGenericValueTypeInteger;
6100 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6101 attribs[i].value.value.i = VA_FOURCC_BGRX;
6104 attribs[i].type = VASurfaceAttribPixelFormat;
6105 attribs[i].value.type = VAGenericValueTypeInteger;
6106 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6107 attribs[i].value.value.i = VA_FOURCC_YV16;
6110 if (HAS_VPP_P010(i965)) {
6111 attribs[i].type = VASurfaceAttribPixelFormat;
6112 attribs[i].value.type = VAGenericValueTypeInteger;
6113 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6114 attribs[i].value.value.i = VA_FOURCC_P010;
6117 attribs[i].type = VASurfaceAttribPixelFormat;
6118 attribs[i].value.type = VAGenericValueTypeInteger;
6119 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6120 attribs[i].value.value.i = VA_FOURCC_I010;
6125 /* Additional support for jpeg encoder */
6126 if (obj_config->profile == VAProfileJPEGBaseline
6127 && obj_config->entrypoint == VAEntrypointEncPicture) {
6128 attribs[i].type = VASurfaceAttribPixelFormat;
6129 attribs[i].value.type = VAGenericValueTypeInteger;
6130 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6131 attribs[i].value.value.i = VA_FOURCC_YUY2;
6134 attribs[i].type = VASurfaceAttribPixelFormat;
6135 attribs[i].value.type = VAGenericValueTypeInteger;
6136 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6137 attribs[i].value.value.i = VA_FOURCC_UYVY;
6140 attribs[i].type = VASurfaceAttribPixelFormat;
6141 attribs[i].value.type = VAGenericValueTypeInteger;
6142 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6143 attribs[i].value.value.i = VA_FOURCC_YV16;
6146 attribs[i].type = VASurfaceAttribPixelFormat;
6147 attribs[i].value.type = VAGenericValueTypeInteger;
6148 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6149 attribs[i].value.value.i = VA_FOURCC_Y800;
6155 attribs[i].type = VASurfaceAttribMemoryType;
6156 attribs[i].value.type = VAGenericValueTypeInteger;
6157 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6158 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
6159 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
6160 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
6163 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
6164 attribs[i].value.type = VAGenericValueTypePointer;
6165 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
6166 attribs[i].value.value.p = NULL; /* ignore */
6169 max_resolution(i965, obj_config, &max_width, &max_height);
6171 attribs[i].type = VASurfaceAttribMaxWidth;
6172 attribs[i].value.type = VAGenericValueTypeInteger;
6173 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6174 attribs[i].value.value.i = max_width;
6177 attribs[i].type = VASurfaceAttribMaxHeight;
6178 attribs[i].value.type = VAGenericValueTypeInteger;
6179 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6180 attribs[i].value.value.i = max_height;
6183 if (i > *num_attribs) {
6186 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6190 memcpy(attrib_list, attribs, i * sizeof(*attribs));
6196 /* Acquires buffer handle for external API usage (internal implementation) */
6198 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
6199 uint32_t mem_type, VABufferInfo *out_buf_info)
6201 struct buffer_store *buffer_store;
6203 buffer_store = obj_buffer->buffer_store;
6204 if (!buffer_store || !buffer_store->bo)
6205 return VA_STATUS_ERROR_INVALID_BUFFER;
6207 /* Synchronization point */
6208 drm_intel_bo_wait_rendering(buffer_store->bo);
6210 if (obj_buffer->export_refcount > 0) {
6211 if (obj_buffer->export_state.mem_type != mem_type)
6212 return VA_STATUS_ERROR_INVALID_PARAMETER;
6214 VABufferInfo * const buf_info = &obj_buffer->export_state;
6217 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
6219 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
6220 return VA_STATUS_ERROR_INVALID_BUFFER;
6221 buf_info->handle = name;
6224 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6226 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
6227 return VA_STATUS_ERROR_INVALID_BUFFER;
6228 buf_info->handle = (intptr_t)fd;
6233 buf_info->type = obj_buffer->type;
6234 buf_info->mem_type = mem_type;
6235 buf_info->mem_size =
6236 obj_buffer->num_elements * obj_buffer->size_element;
6239 obj_buffer->export_refcount++;
6240 *out_buf_info = obj_buffer->export_state;
6241 return VA_STATUS_SUCCESS;
6244 /* Releases buffer handle after usage (internal implementation) */
6246 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6248 if (obj_buffer->export_refcount == 0)
6249 return VA_STATUS_ERROR_INVALID_BUFFER;
6251 if (--obj_buffer->export_refcount == 0) {
6252 VABufferInfo * const buf_info = &obj_buffer->export_state;
6254 switch (buf_info->mem_type) {
6255 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6256 close((intptr_t)buf_info->handle);
6260 buf_info->mem_type = 0;
6262 return VA_STATUS_SUCCESS;
6265 /** Acquires buffer handle for external API usage */
6267 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6268 VABufferInfo *buf_info)
6270 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6271 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6272 uint32_t i, mem_type;
6274 /* List of supported memory types, in preferred order */
6275 static const uint32_t mem_types[] = {
6276 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6277 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6282 return VA_STATUS_ERROR_INVALID_BUFFER;
6283 /* XXX: only VA surface|image like buffers are supported for now */
6284 if (obj_buffer->type != VAImageBufferType)
6285 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6288 * As the allocated buffer by calling vaCreateBuffer is related with
6289 * the specific context, it is unnecessary to export it.
6290 * So it is not supported when the buffer is allocated from wrapped
6293 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6294 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6298 return VA_STATUS_ERROR_INVALID_PARAMETER;
6300 if (!buf_info->mem_type)
6301 mem_type = mem_types[0];
6304 for (i = 0; mem_types[i] != 0; i++) {
6305 if (buf_info->mem_type & mem_types[i]) {
6306 mem_type = buf_info->mem_type;
6311 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6313 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6316 /** Releases buffer handle after usage from external API */
6318 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6320 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6321 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6324 return VA_STATUS_ERROR_INVALID_BUFFER;
6326 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6327 return VA_STATUS_ERROR_INVALID_BUFFER;
6330 return i965_release_buffer_handle(obj_buffer);
6334 i965_os_has_ring_support(VADriverContextP ctx,
6337 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6341 return i965->intel.has_bsd;
6344 return i965->intel.has_blt;
6346 case I965_RING_VEBOX:
6347 return i965->intel.has_vebox;
6349 case I965_RING_NULL:
6350 return 1; /* Always support */
6353 /* should never get here */
6362 * Query video processing pipeline
6364 VAStatus i965_QueryVideoProcFilters(
6365 VADriverContextP ctx,
6366 VAContextID context,
6367 VAProcFilterType *filters,
6368 unsigned int *num_filters
6371 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6372 unsigned int i = 0, num = 0;
6374 if (!num_filters || !filters)
6375 return VA_STATUS_ERROR_INVALID_PARAMETER;
6377 for (i = 0; i < i965->codec_info->num_filters; i++) {
6378 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6379 if (num == *num_filters) {
6380 *num_filters = i965->codec_info->num_filters;
6382 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6385 filters[num++] = i965->codec_info->filters[i].type;
6391 return VA_STATUS_SUCCESS;
6394 VAStatus i965_QueryVideoProcFilterCaps(
6395 VADriverContextP ctx,
6396 VAContextID context,
6397 VAProcFilterType type,
6399 unsigned int *num_filter_caps
6403 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6405 if (!filter_caps || !num_filter_caps)
6406 return VA_STATUS_ERROR_INVALID_PARAMETER;
6408 for (i = 0; i < i965->codec_info->num_filters; i++) {
6409 if (type == i965->codec_info->filters[i].type &&
6410 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6414 if (i == i965->codec_info->num_filters)
6415 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6420 case VAProcFilterNoiseReduction:
6421 case VAProcFilterSharpening: {
6422 VAProcFilterCap *cap = filter_caps;
6424 if (*num_filter_caps < 1) {
6425 *num_filter_caps = 1;
6426 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6429 cap->range.min_value = 0.0;
6430 cap->range.max_value = 1.0;
6431 cap->range.default_value = 0.5;
6432 cap->range.step = 0.03125; /* 1.0 / 32 */
6438 case VAProcFilterDeinterlacing: {
6439 VAProcFilterCapDeinterlacing *cap = filter_caps;
6441 if (*num_filter_caps < VAProcDeinterlacingCount) {
6442 *num_filter_caps = VAProcDeinterlacingCount;
6443 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6446 cap->type = VAProcDeinterlacingBob;
6451 if (i965->codec_info->has_di_motion_adptive) {
6452 cap->type = VAProcDeinterlacingMotionAdaptive;
6457 if (i965->codec_info->has_di_motion_compensated) {
6458 cap->type = VAProcDeinterlacingMotionCompensated;
6466 case VAProcFilterColorBalance: {
6467 VAProcFilterCapColorBalance *cap = filter_caps;
6469 if (*num_filter_caps < VAProcColorBalanceCount) {
6470 *num_filter_caps = VAProcColorBalanceCount;
6471 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6474 cap->type = VAProcColorBalanceHue;
6475 cap->range.min_value = -180.0;
6476 cap->range.max_value = 180.0;
6477 cap->range.default_value = 0.0;
6478 cap->range.step = 1.0;
6482 cap->type = VAProcColorBalanceSaturation;
6483 cap->range.min_value = 0.0;
6484 cap->range.max_value = 10.0;
6485 cap->range.default_value = 1.0;
6486 cap->range.step = 0.1;
6490 cap->type = VAProcColorBalanceBrightness;
6491 cap->range.min_value = -100.0;
6492 cap->range.max_value = 100.0;
6493 cap->range.default_value = 0.0;
6494 cap->range.step = 1.0;
6498 cap->type = VAProcColorBalanceContrast;
6499 cap->range.min_value = 0.0;
6500 cap->range.max_value = 10.0;
6501 cap->range.default_value = 1.0;
6502 cap->range.step = 0.1;
6514 *num_filter_caps = i;
6516 return VA_STATUS_SUCCESS;
6519 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6520 VAProcColorStandardBT601,
6523 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6524 VAProcColorStandardBT601,
6527 VAStatus i965_QueryVideoProcPipelineCaps(
6528 VADriverContextP ctx,
6529 VAContextID context,
6530 VABufferID *filters,
6531 unsigned int num_filters,
6532 VAProcPipelineCaps *pipeline_cap /* out */
6535 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6538 pipeline_cap->pipeline_flags = 0;
6539 pipeline_cap->filter_flags = 0;
6540 pipeline_cap->num_forward_references = 0;
6541 pipeline_cap->num_backward_references = 0;
6542 pipeline_cap->num_input_color_standards = 1;
6543 pipeline_cap->input_color_standards = vpp_input_color_standards;
6544 pipeline_cap->num_output_color_standards = 1;
6545 pipeline_cap->output_color_standards = vpp_output_color_standards;
6547 for (i = 0; i < num_filters; i++) {
6548 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6551 !obj_buffer->buffer_store ||
6552 !obj_buffer->buffer_store->buffer)
6553 return VA_STATUS_ERROR_INVALID_BUFFER;
6555 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6557 if (base->type == VAProcFilterNoiseReduction) {
6558 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6560 } else if (base->type == VAProcFilterDeinterlacing) {
6561 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6563 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6564 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6565 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6566 VA_STATUS_ERROR_INVALID_PARAMETER);
6568 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6569 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6570 pipeline_cap->num_forward_references++;
6571 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6572 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6577 return VA_STATUS_SUCCESS;
6580 extern struct hw_codec_info *i965_get_codec_info(int devid);
6583 i965_driver_data_init(VADriverContextP ctx)
6585 struct i965_driver_data *i965 = i965_driver_data(ctx);
6587 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6589 if (!i965->codec_info)
6592 if (object_heap_init(&i965->config_heap,
6593 sizeof(struct object_config),
6595 goto err_config_heap;
6596 if (object_heap_init(&i965->context_heap,
6597 sizeof(struct object_context),
6599 goto err_context_heap;
6601 if (object_heap_init(&i965->surface_heap,
6602 sizeof(struct object_surface),
6604 goto err_surface_heap;
6605 if (object_heap_init(&i965->buffer_heap,
6606 sizeof(struct object_buffer),
6608 goto err_buffer_heap;
6609 if (object_heap_init(&i965->image_heap,
6610 sizeof(struct object_image),
6612 goto err_image_heap;
6613 if (object_heap_init(&i965->subpic_heap,
6614 sizeof(struct object_subpic),
6616 goto err_subpic_heap;
6618 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6619 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6620 _i965InitMutex(&i965->render_mutex);
6621 _i965InitMutex(&i965->pp_mutex);
6626 object_heap_destroy(&i965->image_heap);
6628 object_heap_destroy(&i965->buffer_heap);
6630 object_heap_destroy(&i965->surface_heap);
6632 object_heap_destroy(&i965->context_heap);
6634 object_heap_destroy(&i965->config_heap);
6641 i965_driver_data_terminate(VADriverContextP ctx)
6643 struct i965_driver_data *i965 = i965_driver_data(ctx);
6645 _i965DestroyMutex(&i965->pp_mutex);
6646 _i965DestroyMutex(&i965->render_mutex);
6649 intel_batchbuffer_free(i965->batch);
6652 intel_batchbuffer_free(i965->pp_batch);
6654 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6655 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6656 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6657 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6658 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6659 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6663 bool (*init)(VADriverContextP ctx);
6664 void (*terminate)(VADriverContextP ctx);
6666 } i965_sub_ops[] = {
6669 intel_driver_terminate,
6674 i965_driver_data_init,
6675 i965_driver_data_terminate,
6680 i965_display_attributes_init,
6681 i965_display_attributes_terminate,
6686 i965_post_processing_init,
6687 i965_post_processing_terminate,
6693 i965_render_terminate,
6697 #ifdef HAVE_VA_WAYLAND
6699 i965_output_wayland_init,
6700 i965_output_wayland_terminate,
6707 i965_output_dri_init,
6708 i965_output_dri_terminate,
6714 i965_gpe_table_init,
6715 i965_gpe_table_terminate,
6721 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6725 if (i965->va_vendor[0] != '\0')
6729 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6730 "%s %s driver for %s - %d.%d.%d",
6731 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6732 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6733 INTEL_DRIVER_MICRO_VERSION);
6734 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6738 if (INTEL_DRIVER_PRE_VERSION > 0) {
6739 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6740 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6741 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6745 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6746 " (%s)", INTEL_DRIVER_GIT_VERSION);
6747 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6754 i965->va_vendor[0] = '\0';
6755 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6759 /* Only when the option of "enable-wrapper" is passed, it is possible
6760 * to initialize/load the wrapper context of backend driver.
6761 * Otherwise it is not loaded.
6763 #if HAVE_HYBRID_CODEC
6766 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6768 #define DRIVER_EXTENSION "_drv_video.so"
6770 struct i965_driver_data *i965 = i965_driver_data(ctx);
6772 VADriverContextP wrapper_pdrvctx;
6773 struct VADriverVTable *vtable;
6774 char *search_path, *driver_dir;
6776 char driver_path[256];
6777 void *handle = NULL;
6778 VAStatus va_status = VA_STATUS_SUCCESS;
6779 bool driver_loaded = false;
6781 if (HAS_VP9_DECODING(i965)) {
6782 i965->wrapper_pdrvctx = NULL;
6786 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6787 vtable = calloc(1, sizeof(*vtable));
6789 if (!wrapper_pdrvctx || !vtable) {
6790 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6791 free(wrapper_pdrvctx);
6793 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6796 /* use the same drm_state with CTX */
6797 wrapper_pdrvctx->drm_state = ctx->drm_state;
6798 wrapper_pdrvctx->display_type = ctx->display_type;
6799 wrapper_pdrvctx->vtable = vtable;
6801 search_path = VA_DRIVERS_PATH;
6802 search_path = strdup((const char *)search_path);
6804 driver_dir = strtok_r(search_path, ":", &saveptr);
6805 while (driver_dir && !driver_loaded) {
6806 memset(driver_path, 0, sizeof(driver_path));
6807 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6809 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6811 fprintf(stderr, "failed to open %s\n", driver_path);
6812 driver_dir = strtok_r(NULL, ":", &saveptr);
6816 VADriverInit init_func = NULL;
6817 char init_func_s[256];
6820 static const struct {
6823 } compatible_versions[] = {
6824 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6833 for (i = 0; compatible_versions[i].major >= 0; i++) {
6834 snprintf(init_func_s, sizeof(init_func_s),
6835 "__vaDriverInit_%d_%d",
6836 compatible_versions[i].major,
6837 compatible_versions[i].minor);
6838 init_func = (VADriverInit)dlsym(handle, init_func_s);
6843 if (compatible_versions[i].major < 0) {
6845 fprintf(stderr, "%s has no function %s\n",
6846 driver_path, init_func_s);
6847 driver_dir = strtok_r(NULL, ":", &saveptr);
6852 va_status = (*init_func)(wrapper_pdrvctx);
6854 if (va_status != VA_STATUS_SUCCESS) {
6856 fprintf(stderr, "%s init failed\n", driver_path);
6857 driver_dir = strtok_r(NULL, ":", &saveptr);
6861 wrapper_pdrvctx->handle = handle;
6862 driver_loaded = true;
6868 if (driver_loaded) {
6869 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6870 return VA_STATUS_SUCCESS;
6872 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6874 free(wrapper_pdrvctx);
6875 return VA_STATUS_ERROR_OPERATION_FAILED;
6881 i965_Init(VADriverContextP ctx)
6883 struct i965_driver_data *i965 = i965_driver_data(ctx);
6885 const char *chipset;
6887 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6888 if ((i965_sub_ops[i].display_type == 0 ||
6889 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6890 !i965_sub_ops[i].init(ctx))
6894 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6895 switch (i965->intel.device_id) {
6897 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6898 #include "i965_pciids.h"
6900 chipset = "Unknown Intel Chipset";
6904 if (!ensure_vendor_string(i965, chipset))
6905 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6907 i965->current_context_id = VA_INVALID_ID;
6909 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6910 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6912 #if HAVE_HYBRID_CODEC
6913 i965_initialize_wrapper(ctx, "hybrid");
6916 return VA_STATUS_SUCCESS;
6920 for (; i >= 0; i--) {
6921 if (i965_sub_ops[i].display_type == 0 ||
6922 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6923 i965_sub_ops[i].terminate(ctx);
6927 return VA_STATUS_ERROR_UNKNOWN;
6932 i965_Terminate(VADriverContextP ctx)
6934 struct i965_driver_data *i965 = i965_driver_data(ctx);
6938 #if HAVE_HYBRID_CODEC
6939 if (i965->wrapper_pdrvctx) {
6940 VADriverContextP pdrvctx;
6941 pdrvctx = i965->wrapper_pdrvctx;
6942 if (pdrvctx->handle) {
6943 pdrvctx->vtable->vaTerminate(pdrvctx);
6944 dlclose(pdrvctx->handle);
6945 pdrvctx->handle = NULL;
6947 free(pdrvctx->vtable);
6949 i965->wrapper_pdrvctx = NULL;
6953 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6954 if (i965_sub_ops[i - 1].display_type == 0 ||
6955 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6956 i965_sub_ops[i - 1].terminate(ctx);
6960 ctx->pDriverData = NULL;
6963 return VA_STATUS_SUCCESS;
6967 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6970 VA_DRIVER_INIT_FUNC(VADriverContextP ctx)
6972 struct VADriverVTable * const vtable = ctx->vtable;
6973 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6975 struct i965_driver_data *i965;
6976 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6978 ctx->version_major = VA_MAJOR_VERSION;
6979 ctx->version_minor = VA_MINOR_VERSION;
6980 ctx->max_profiles = I965_MAX_PROFILES;
6981 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6982 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6983 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6984 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6985 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6987 vtable->vaTerminate = i965_Terminate;
6988 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6989 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6990 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6991 vtable->vaCreateConfig = i965_CreateConfig;
6992 vtable->vaDestroyConfig = i965_DestroyConfig;
6993 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6994 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6995 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6996 vtable->vaCreateContext = i965_CreateContext;
6997 vtable->vaDestroyContext = i965_DestroyContext;
6998 vtable->vaCreateBuffer = i965_CreateBuffer;
6999 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
7000 vtable->vaMapBuffer = i965_MapBuffer;
7001 vtable->vaUnmapBuffer = i965_UnmapBuffer;
7002 vtable->vaDestroyBuffer = i965_DestroyBuffer;
7003 vtable->vaBeginPicture = i965_BeginPicture;
7004 vtable->vaRenderPicture = i965_RenderPicture;
7005 vtable->vaEndPicture = i965_EndPicture;
7006 vtable->vaSyncSurface = i965_SyncSurface;
7007 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
7008 vtable->vaPutSurface = i965_PutSurface;
7009 vtable->vaQueryImageFormats = i965_QueryImageFormats;
7010 vtable->vaCreateImage = i965_CreateImage;
7011 vtable->vaDeriveImage = i965_DeriveImage;
7012 vtable->vaDestroyImage = i965_DestroyImage;
7013 vtable->vaSetImagePalette = i965_SetImagePalette;
7014 vtable->vaGetImage = i965_GetImage;
7015 vtable->vaPutImage = i965_PutImage;
7016 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
7017 vtable->vaCreateSubpicture = i965_CreateSubpicture;
7018 vtable->vaDestroySubpicture = i965_DestroySubpicture;
7019 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
7020 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
7021 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
7022 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
7023 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
7024 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
7025 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
7026 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
7027 vtable->vaBufferInfo = i965_BufferInfo;
7028 vtable->vaLockSurface = i965_LockSurface;
7029 vtable->vaUnlockSurface = i965_UnlockSurface;
7030 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
7031 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
7032 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
7035 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
7036 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
7038 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
7039 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
7040 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
7042 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
7045 ctx->pDriverData = NULL;
7047 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7050 i965->wrapper_pdrvctx = NULL;
7051 ctx->pDriverData = (void *)i965;
7052 ret = i965_Init(ctx);
7054 if (ret == VA_STATUS_SUCCESS) {
7055 ctx->str_vendor = i965->va_vendor;
7058 ctx->pDriverData = NULL;