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 == VAProfileVP8Version0_3 ||
977 profile == VAProfileVP9Profile0 ||
978 profile == VAProfileH264ConstrainedBaseline ||
979 profile == VAProfileH264Main ||
980 profile == VAProfileH264High ||
981 profile == VAProfileHEVCMain)
982 attrib_list[i].value |= VA_RC_VBR;
985 } else if (entrypoint == VAEntrypointEncSliceLP) {
986 struct i965_driver_data * const i965 = i965_driver_data(ctx);
988 /* Support low power encoding for H.264 only by now */
989 if (profile == VAProfileH264ConstrainedBaseline ||
990 profile == VAProfileH264Main ||
991 profile == VAProfileH264High)
992 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
994 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
996 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1000 case VAConfigAttribEncPackedHeaders:
1001 if (entrypoint == VAEntrypointEncSlice ||
1002 entrypoint == VAEntrypointEncSliceLP) {
1003 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
1004 if (profile == VAProfileH264ConstrainedBaseline ||
1005 profile == VAProfileH264Main ||
1006 profile == VAProfileH264High ||
1007 profile == VAProfileH264StereoHigh ||
1008 profile == VAProfileH264MultiviewHigh ||
1009 profile == VAProfileHEVCMain ||
1010 profile == VAProfileHEVCMain10) {
1011 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
1012 VA_ENC_PACKED_HEADER_SLICE);
1013 } else if (profile == VAProfileVP9Profile0)
1014 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1016 } else if (entrypoint == VAEntrypointEncPicture) {
1017 if (profile == VAProfileJPEGBaseline)
1018 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1022 case VAConfigAttribEncMaxRefFrames:
1023 if (entrypoint == VAEntrypointEncSlice)
1024 attrib_list[i].value = (1 << 16) | (1 << 0);
1025 else if (entrypoint == VAEntrypointEncSliceLP) {
1026 /* Don't support B frame for low power mode */
1027 if (profile == VAProfileH264ConstrainedBaseline ||
1028 profile == VAProfileH264Main ||
1029 profile == VAProfileH264High)
1030 attrib_list[i].value = (1 << 0);
1032 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1037 case VAConfigAttribEncQualityRange:
1038 if (entrypoint == VAEntrypointEncSlice ||
1039 entrypoint == VAEntrypointEncSliceLP) {
1040 attrib_list[i].value = 1;
1041 if (profile == VAProfileH264ConstrainedBaseline ||
1042 profile == VAProfileH264Main ||
1043 profile == VAProfileH264High) {
1044 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1045 if (entrypoint == VAEntrypointEncSlice) {
1046 if (IS_GEN9(i965->intel.device_info))
1047 attrib_list[i].value = ENCODER_QUALITY_RANGE_AVC;
1049 } else if (profile == VAProfileHEVCMain ||
1050 profile == VAProfileHEVCMain10)
1051 attrib_list[i].value = ENCODER_QUALITY_RANGE_HEVC;
1056 case VAConfigAttribEncJPEG:
1057 if (entrypoint == VAEntrypointEncPicture) {
1058 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*) & (attrib_list[i].value);
1059 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1060 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1061 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1062 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1063 (configVal->bits).max_num_components = 3; // Only 3 components supported
1064 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1065 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1066 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1070 case VAConfigAttribDecSliceMode:
1071 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1074 case VAConfigAttribEncROI:
1075 if (entrypoint == VAEntrypointEncSlice ||
1076 entrypoint == VAEntrypointEncSliceLP) {
1078 if (profile == VAProfileH264ConstrainedBaseline ||
1079 profile == VAProfileH264Main ||
1080 profile == VAProfileH264High) {
1082 if (IS_GEN9(i965->intel.device_info) &&
1083 entrypoint == VAEntrypointEncSlice)
1084 attrib_list[i].value = 0;
1087 VAConfigAttribValEncROI *roi_config =
1088 (VAConfigAttribValEncROI *) & (attrib_list[i].value);
1090 if (entrypoint == VAEntrypointEncSliceLP) {
1091 roi_config->bits.num_roi_regions = 3;
1092 roi_config->bits.roi_rc_priority_support = 0;
1093 roi_config->bits.roi_rc_qp_delat_support = 0;
1095 roi_config->bits.num_roi_regions =
1096 I965_MAX_NUM_ROI_REGIONS;
1097 roi_config->bits.roi_rc_priority_support = 0;
1098 roi_config->bits.roi_rc_qp_delat_support = 1;
1102 attrib_list[i].value = 0;
1108 case VAConfigAttribEncRateControlExt:
1109 if ((profile == VAProfileH264ConstrainedBaseline ||
1110 profile == VAProfileH264Main ||
1111 profile == VAProfileH264High) &&
1112 entrypoint == VAEntrypointEncSlice) {
1113 if (IS_GEN9(i965->intel.device_info))
1114 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1116 VAConfigAttribValEncRateControlExt *val_config = (VAConfigAttribValEncRateControlExt *) & (attrib_list[i].value);
1118 val_config->bits.max_num_temporal_layers_minus1 = MAX_TEMPORAL_LAYERS - 1;
1119 val_config->bits.temporal_layer_bitrate_control_flag = 1;
1122 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1127 case VAConfigAttribEncMaxSlices:
1128 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1129 if (entrypoint == VAEntrypointEncSlice) {
1130 if ((profile == VAProfileH264ConstrainedBaseline ||
1131 profile == VAProfileH264Main ||
1132 profile == VAProfileH264High) ||
1133 profile == VAProfileH264StereoHigh ||
1134 profile == VAProfileH264MultiviewHigh) {
1135 attrib_list[i].value = I965_MAX_NUM_SLICE;
1136 } else if (profile == VAProfileHEVCMain ||
1137 profile == VAProfileHEVCMain10) {
1138 attrib_list[i].value = I965_MAX_NUM_SLICE;
1140 } else if (entrypoint == VAEntrypointEncSliceLP) {
1141 if ((profile == VAProfileH264ConstrainedBaseline ||
1142 profile == VAProfileH264Main ||
1143 profile == VAProfileH264High) ||
1144 profile == VAProfileH264StereoHigh ||
1145 profile == VAProfileH264MultiviewHigh)
1146 attrib_list[i].value = I965_MAX_NUM_SLICE;
1151 case VAConfigAttribEncSliceStructure:
1152 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1153 if (entrypoint == VAEntrypointEncSlice) {
1154 if ((profile == VAProfileH264ConstrainedBaseline ||
1155 profile == VAProfileH264Main ||
1156 profile == VAProfileH264High) ||
1157 profile == VAProfileH264StereoHigh ||
1158 profile == VAProfileH264MultiviewHigh ||
1159 profile == VAProfileHEVCMain ||
1160 profile == VAProfileHEVCMain10) {
1161 attrib_list[i].value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1168 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1173 return VA_STATUS_SUCCESS;
1177 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1179 object_heap_free(heap, obj);
1182 static VAConfigAttrib *
1183 i965_lookup_config_attribute(struct object_config *obj_config,
1184 VAConfigAttribType type)
1188 for (i = 0; i < obj_config->num_attribs; i++) {
1189 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1190 if (attrib->type == type)
1197 i965_append_config_attribute(struct object_config *obj_config,
1198 const VAConfigAttrib *new_attrib)
1200 VAConfigAttrib *attrib;
1202 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1203 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1205 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1206 attrib->type = new_attrib->type;
1207 attrib->value = new_attrib->value;
1208 return VA_STATUS_SUCCESS;
1212 i965_ensure_config_attribute(struct object_config *obj_config,
1213 const VAConfigAttrib *new_attrib)
1215 VAConfigAttrib *attrib;
1217 /* Check for existing attributes */
1218 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1220 /* Update existing attribute */
1221 attrib->value = new_attrib->value;
1222 return VA_STATUS_SUCCESS;
1224 return i965_append_config_attribute(obj_config, new_attrib);
1228 i965_CreateConfig(VADriverContextP ctx,
1230 VAEntrypoint entrypoint,
1231 VAConfigAttrib *attrib_list,
1233 VAConfigID *config_id) /* out */
1235 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1236 struct object_config *obj_config;
1241 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1243 if (VA_STATUS_SUCCESS != vaStatus) {
1247 configID = NEW_CONFIG_ID();
1248 obj_config = CONFIG(configID);
1250 if (NULL == obj_config) {
1251 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1255 obj_config->profile = profile;
1256 obj_config->entrypoint = entrypoint;
1257 obj_config->num_attribs = 0;
1258 obj_config->wrapper_config = VA_INVALID_ID;
1260 for (i = 0; i < num_attribs; i++) {
1261 // add it later and ignore the user input for VAConfigAttribEncMaxSlices
1262 if (attrib_list[i].type == VAConfigAttribEncMaxSlices ||
1263 attrib_list[i].type == VAConfigAttribEncSliceStructure)
1265 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1266 if (vaStatus != VA_STATUS_SUCCESS)
1270 if (vaStatus == VA_STATUS_SUCCESS) {
1271 VAConfigAttrib attrib, *attrib_found;
1272 attrib.type = VAConfigAttribRTFormat;
1273 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1274 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1275 if (!attrib_found || !attrib_found->value)
1276 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1277 else if (!(attrib_found->value & attrib.value))
1278 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1281 if (vaStatus == VA_STATUS_SUCCESS) {
1282 VAConfigAttrib attrib;
1283 attrib.type = VAConfigAttribEncMaxSlices;
1284 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1285 if (entrypoint == VAEntrypointEncSlice) {
1286 if ((profile == VAProfileH264ConstrainedBaseline ||
1287 profile == VAProfileH264Main ||
1288 profile == VAProfileH264High) ||
1289 profile == VAProfileH264StereoHigh ||
1290 profile == VAProfileH264MultiviewHigh) {
1291 attrib.value = I965_MAX_NUM_SLICE;
1292 } else if (profile == VAProfileHEVCMain ||
1293 profile == VAProfileHEVCMain10)
1294 attrib.value = I965_MAX_NUM_SLICE;
1295 } else if (entrypoint == VAEntrypointEncSliceLP) {
1296 if ((profile == VAProfileH264ConstrainedBaseline ||
1297 profile == VAProfileH264Main ||
1298 profile == VAProfileH264High) ||
1299 profile == VAProfileH264StereoHigh ||
1300 profile == VAProfileH264MultiviewHigh)
1301 attrib.value = I965_MAX_NUM_SLICE;
1304 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1305 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1308 if (vaStatus == VA_STATUS_SUCCESS) {
1309 VAConfigAttrib attrib;
1310 attrib.type = VAConfigAttribEncSliceStructure;
1311 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1312 if (entrypoint == VAEntrypointEncSlice) {
1313 if ((profile == VAProfileH264ConstrainedBaseline ||
1314 profile == VAProfileH264Main ||
1315 profile == VAProfileH264High) ||
1316 profile == VAProfileH264StereoHigh ||
1317 profile == VAProfileH264MultiviewHigh) {
1318 attrib.value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1322 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1323 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1326 if ((vaStatus == VA_STATUS_SUCCESS) &&
1327 (profile == VAProfileVP9Profile0) &&
1328 (entrypoint == VAEntrypointVLD) &&
1329 !HAS_VP9_DECODING(i965)) {
1331 if (i965->wrapper_pdrvctx) {
1332 VAGenericID wrapper_config;
1334 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1335 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1336 entrypoint, attrib_list,
1337 num_attribs, &wrapper_config));
1339 if (vaStatus == VA_STATUS_SUCCESS)
1340 obj_config->wrapper_config = wrapper_config;
1344 /* Error recovery */
1345 if (VA_STATUS_SUCCESS != vaStatus) {
1346 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1348 *config_id = configID;
1355 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1357 struct i965_driver_data *i965 = i965_driver_data(ctx);
1358 struct object_config *obj_config = CONFIG(config_id);
1361 if (NULL == obj_config) {
1362 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1366 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1367 i965->wrapper_pdrvctx) {
1368 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1369 vaDestroyConfig(i965->wrapper_pdrvctx,
1370 obj_config->wrapper_config));
1371 obj_config->wrapper_config = VA_INVALID_ID;
1374 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1375 return VA_STATUS_SUCCESS;
1378 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1379 VAConfigID config_id,
1380 VAProfile *profile, /* out */
1381 VAEntrypoint *entrypoint, /* out */
1382 VAConfigAttrib *attrib_list, /* out */
1383 int *num_attribs) /* out */
1385 struct i965_driver_data *i965 = i965_driver_data(ctx);
1386 struct object_config *obj_config = CONFIG(config_id);
1387 VAStatus vaStatus = VA_STATUS_SUCCESS;
1390 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1391 *profile = obj_config->profile;
1392 *entrypoint = obj_config->entrypoint;
1393 *num_attribs = obj_config->num_attribs;
1395 for (i = 0; i < obj_config->num_attribs; i++) {
1396 attrib_list[i] = obj_config->attrib_list[i];
1403 i965_destroy_surface_storage(struct object_surface *obj_surface)
1408 dri_bo_unreference(obj_surface->bo);
1409 obj_surface->bo = NULL;
1411 if (obj_surface->free_private_data != NULL) {
1412 obj_surface->free_private_data(&obj_surface->private_data);
1413 obj_surface->private_data = NULL;
1418 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1420 struct object_surface *obj_surface = (struct object_surface *)obj;
1422 i965_destroy_surface_storage(obj_surface);
1423 object_heap_free(heap, obj);
1426 /* byte-per-pixel of the first plane */
1428 bpp_1stplane_by_fourcc(unsigned int fourcc)
1430 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1432 if (info && (info->flag & I_S))
1433 return info->bpp[0] / 8;
1439 i965_surface_native_memory(VADriverContextP ctx,
1440 struct object_surface *obj_surface,
1442 int expected_fourcc)
1444 struct i965_driver_data *i965 = i965_driver_data(ctx);
1445 int tiling = HAS_TILED_SURFACE(i965);
1447 if (!expected_fourcc)
1448 return VA_STATUS_SUCCESS;
1450 // todo, should we disable tiling for 422 format?
1451 if (expected_fourcc == VA_FOURCC_I420 ||
1452 expected_fourcc == VA_FOURCC_IYUV ||
1453 expected_fourcc == VA_FOURCC_I010 ||
1454 expected_fourcc == VA_FOURCC_YV12 ||
1455 expected_fourcc == VA_FOURCC_YV16)
1458 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1462 i965_suface_external_memory(VADriverContextP ctx,
1463 struct object_surface *obj_surface,
1464 int external_memory_type,
1465 VASurfaceAttribExternalBuffers *memory_attibute,
1468 struct i965_driver_data *i965 = i965_driver_data(ctx);
1469 unsigned int tiling, swizzle;
1471 if (!memory_attibute ||
1472 !memory_attibute->buffers ||
1473 index >= memory_attibute->num_buffers)
1474 return VA_STATUS_ERROR_INVALID_PARAMETER;
1476 obj_surface->size = memory_attibute->data_size;
1477 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1478 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1479 "gem flinked vaapi surface",
1480 memory_attibute->buffers[index]);
1481 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1482 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1483 memory_attibute->buffers[index],
1486 if (!obj_surface->bo)
1487 return VA_STATUS_ERROR_INVALID_PARAMETER;
1489 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
1491 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1492 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1493 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1495 obj_surface->fourcc = memory_attibute->pixel_format;
1496 obj_surface->width = memory_attibute->pitches[0];
1497 int bpp_1stplane = bpp_1stplane_by_fourcc(obj_surface->fourcc);
1498 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1499 ASSERT_RET(obj_surface->width >= obj_surface->orig_width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1501 if (memory_attibute->num_planes == 1)
1502 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1504 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1505 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1506 ASSERT_RET(obj_surface->height >= obj_surface->orig_height, VA_STATUS_ERROR_INVALID_PARAMETER);
1509 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1510 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
1512 ASSERT_RET(IS_ALIGNED(obj_surface->width, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1513 ASSERT_RET(IS_ALIGNED(obj_surface->height, i965->codec_info->min_linear_hpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1516 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1517 obj_surface->x_cr_offset = 0;
1518 if ((obj_surface->fourcc == VA_FOURCC_I420 ||
1519 obj_surface->fourcc == VA_FOURCC_IYUV ||
1520 obj_surface->fourcc == VA_FOURCC_I010 ||
1521 obj_surface->fourcc == VA_FOURCC_YV12 ||
1522 obj_surface->fourcc == VA_FOURCC_YV16) && tiling)
1523 return VA_STATUS_ERROR_INVALID_PARAMETER;
1525 switch (obj_surface->fourcc) {
1526 case VA_FOURCC_NV12:
1527 case VA_FOURCC_P010:
1528 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1529 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1531 obj_surface->subsampling = SUBSAMPLE_YUV420;
1532 obj_surface->y_cb_offset = obj_surface->height;
1533 obj_surface->y_cr_offset = obj_surface->height;
1534 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1535 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1536 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1538 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1540 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1544 case VA_FOURCC_YV12:
1545 case VA_FOURCC_IMC1:
1546 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1547 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1549 obj_surface->subsampling = SUBSAMPLE_YUV420;
1550 obj_surface->y_cr_offset = obj_surface->height;
1551 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1552 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1553 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1554 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1557 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1559 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1563 case VA_FOURCC_I420:
1564 case VA_FOURCC_IYUV:
1565 case VA_FOURCC_IMC3:
1566 case VA_FOURCC_I010:
1567 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1568 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1570 obj_surface->subsampling = SUBSAMPLE_YUV420;
1571 obj_surface->y_cb_offset = obj_surface->height;
1572 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1573 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1574 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1575 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1577 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1579 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1583 case VA_FOURCC_YUY2:
1584 case VA_FOURCC_UYVY:
1585 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1587 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1588 obj_surface->y_cb_offset = 0;
1589 obj_surface->y_cr_offset = 0;
1590 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1591 obj_surface->cb_cr_height = obj_surface->orig_height;
1592 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1596 case VA_FOURCC_RGBA:
1597 case VA_FOURCC_RGBX:
1598 case VA_FOURCC_BGRA:
1599 case VA_FOURCC_BGRX:
1600 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1602 obj_surface->subsampling = SUBSAMPLE_RGBX;
1603 obj_surface->y_cb_offset = 0;
1604 obj_surface->y_cr_offset = 0;
1605 obj_surface->cb_cr_width = 0;
1606 obj_surface->cb_cr_height = 0;
1607 obj_surface->cb_cr_pitch = 0;
1611 case VA_FOURCC_Y800: /* monochrome surface */
1612 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1614 obj_surface->subsampling = SUBSAMPLE_YUV400;
1615 obj_surface->y_cb_offset = 0;
1616 obj_surface->y_cr_offset = 0;
1617 obj_surface->cb_cr_width = 0;
1618 obj_surface->cb_cr_height = 0;
1619 obj_surface->cb_cr_pitch = 0;
1623 case VA_FOURCC_411P:
1624 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1625 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1627 obj_surface->subsampling = SUBSAMPLE_YUV411;
1628 obj_surface->y_cb_offset = obj_surface->height;
1629 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1630 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1631 obj_surface->cb_cr_height = obj_surface->orig_height;
1632 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1634 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1636 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1639 case VA_FOURCC_422H:
1640 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1641 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1643 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1644 obj_surface->y_cb_offset = obj_surface->height;
1645 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1646 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1647 obj_surface->cb_cr_height = obj_surface->orig_height;
1648 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1650 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1652 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1656 case VA_FOURCC_YV16:
1657 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1658 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1660 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1661 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1662 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1663 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1664 obj_surface->cb_cr_height = obj_surface->orig_height;
1665 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1666 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1670 case VA_FOURCC_422V:
1671 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1672 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1674 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1675 obj_surface->y_cb_offset = obj_surface->height;
1676 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1677 obj_surface->cb_cr_width = obj_surface->orig_width;
1678 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1679 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1681 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1683 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1687 case VA_FOURCC_444P:
1688 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1689 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1691 obj_surface->subsampling = SUBSAMPLE_YUV444;
1692 obj_surface->y_cb_offset = obj_surface->height;
1693 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1694 obj_surface->cb_cr_width = obj_surface->orig_width;
1695 obj_surface->cb_cr_height = obj_surface->orig_height;
1696 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1698 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1700 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1705 return VA_STATUS_ERROR_INVALID_PARAMETER;
1708 return VA_STATUS_SUCCESS;
1712 i965_CreateSurfaces2(
1713 VADriverContextP ctx,
1714 unsigned int format,
1716 unsigned int height,
1717 VASurfaceID *surfaces,
1718 unsigned int num_surfaces,
1719 VASurfaceAttrib *attrib_list,
1720 unsigned int num_attribs
1723 struct i965_driver_data *i965 = i965_driver_data(ctx);
1725 VAStatus vaStatus = VA_STATUS_SUCCESS;
1726 int expected_fourcc = 0;
1727 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1728 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1730 for (i = 0; i < num_attribs && attrib_list; i++) {
1731 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1732 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1733 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1734 expected_fourcc = attrib_list[i].value.value.i;
1737 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1738 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1740 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1742 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1743 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1744 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1745 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1746 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1747 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1750 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1751 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1752 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1753 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1757 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1758 * for post-processing (including color conversion) */
1759 if (VA_RT_FORMAT_YUV420 != format &&
1760 VA_RT_FORMAT_YUV420_10BPP != format &&
1761 VA_RT_FORMAT_YUV422 != format &&
1762 VA_RT_FORMAT_YUV444 != format &&
1763 VA_RT_FORMAT_YUV411 != format &&
1764 VA_RT_FORMAT_YUV400 != format &&
1765 VA_RT_FORMAT_RGB32 != format) {
1766 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1769 for (i = 0; i < num_surfaces; i++) {
1770 int surfaceID = NEW_SURFACE_ID();
1771 struct object_surface *obj_surface = SURFACE(surfaceID);
1773 if (NULL == obj_surface) {
1774 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1778 surfaces[i] = surfaceID;
1779 obj_surface->status = VASurfaceReady;
1780 obj_surface->orig_width = width;
1781 obj_surface->orig_height = height;
1782 obj_surface->user_disable_tiling = false;
1783 obj_surface->user_h_stride_set = false;
1784 obj_surface->user_v_stride_set = false;
1785 obj_surface->border_cleared = false;
1787 obj_surface->subpic_render_idx = 0;
1788 for (j = 0; j < I965_MAX_SUBPIC_SUM; j++) {
1789 obj_surface->subpic[j] = VA_INVALID_ID;
1790 obj_surface->obj_subpic[j] = NULL;
1793 assert(i965->codec_info->min_linear_wpitch);
1794 assert(i965->codec_info->min_linear_hpitch);
1795 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1796 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1797 obj_surface->flags = SURFACE_REFERENCED;
1798 obj_surface->fourcc = 0;
1799 obj_surface->expected_format = format;
1800 obj_surface->bo = NULL;
1801 obj_surface->locked_image_id = VA_INVALID_ID;
1802 obj_surface->derived_image_id = VA_INVALID_ID;
1803 obj_surface->private_data = NULL;
1804 obj_surface->free_private_data = NULL;
1805 obj_surface->subsampling = SUBSAMPLE_YUV420;
1807 obj_surface->wrapper_surface = VA_INVALID_ID;
1808 obj_surface->exported_primefd = -1;
1810 switch (memory_type) {
1811 case I965_SURFACE_MEM_NATIVE:
1812 if (memory_attibute) {
1813 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1814 obj_surface->user_disable_tiling = true;
1816 if (memory_attibute->pixel_format) {
1817 if (expected_fourcc)
1818 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1820 expected_fourcc = memory_attibute->pixel_format;
1822 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1823 if (memory_attibute->pitches[0]) {
1824 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1825 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1826 obj_surface->width = memory_attibute->pitches[0];
1827 obj_surface->user_h_stride_set = true;
1828 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1829 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1831 if (memory_attibute->offsets[1]) {
1832 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1833 obj_surface->height = memory_attibute->offsets[1] / memory_attibute->pitches[0];
1834 obj_surface->user_v_stride_set = true;
1835 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1836 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1840 vaStatus = i965_surface_native_memory(ctx,
1846 case I965_SURFACE_MEM_GEM_FLINK:
1847 case I965_SURFACE_MEM_DRM_PRIME:
1848 vaStatus = i965_suface_external_memory(ctx,
1855 if (VA_STATUS_SUCCESS != vaStatus) {
1856 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1861 /* Error recovery */
1862 if (VA_STATUS_SUCCESS != vaStatus) {
1863 /* surfaces[i-1] was the last successful allocation */
1865 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1867 surfaces[i] = VA_INVALID_SURFACE;
1868 assert(obj_surface);
1869 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1877 i965_CreateSurfaces(VADriverContextP ctx,
1882 VASurfaceID *surfaces) /* out */
1884 return i965_CreateSurfaces2(ctx,
1895 i965_DestroySurfaces(VADriverContextP ctx,
1896 VASurfaceID *surface_list,
1899 struct i965_driver_data *i965 = i965_driver_data(ctx);
1901 VAStatus va_status = VA_STATUS_SUCCESS;
1903 for (i = num_surfaces; i--;) {
1904 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1906 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1908 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1909 i965->wrapper_pdrvctx) {
1910 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1911 vaDestroySurfaces(i965->wrapper_pdrvctx,
1912 &(obj_surface->wrapper_surface),
1914 obj_surface->wrapper_surface = VA_INVALID_ID;
1916 if (obj_surface->exported_primefd >= 0) {
1917 close(obj_surface->exported_primefd);
1918 obj_surface->exported_primefd = -1;
1921 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1928 i965_QueryImageFormats(VADriverContextP ctx,
1929 VAImageFormat *format_list, /* out */
1930 int *num_formats) /* out */
1934 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1935 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1937 format_list[n] = m->va_format;
1943 return VA_STATUS_SUCCESS;
1947 * Guess the format when the usage of a VA surface is unknown
1948 * 1. Without a valid context: YV12
1949 * 2. The current context is valid:
1950 * a) always NV12 on GEN6 and later
1951 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1954 i965_guess_surface_format(VADriverContextP ctx,
1955 VASurfaceID surface,
1956 unsigned int *fourcc,
1957 unsigned int *is_tiled)
1959 struct i965_driver_data *i965 = i965_driver_data(ctx);
1960 struct object_context *obj_context = NULL;
1961 struct object_config *obj_config = NULL;
1963 *fourcc = VA_FOURCC_YV12;
1966 if (i965->current_context_id == VA_INVALID_ID)
1969 obj_context = CONTEXT(i965->current_context_id);
1974 obj_config = obj_context->obj_config;
1980 if (IS_GEN6(i965->intel.device_info) ||
1981 IS_GEN7(i965->intel.device_info) ||
1982 IS_GEN8(i965->intel.device_info) ||
1983 IS_GEN9(i965->intel.device_info)) {
1984 *fourcc = VA_FOURCC_NV12;
1989 switch (obj_config->profile) {
1990 case VAProfileMPEG2Simple:
1991 case VAProfileMPEG2Main:
1992 *fourcc = VA_FOURCC_I420;
1997 *fourcc = VA_FOURCC_NV12;
2004 i965_QuerySubpictureFormats(VADriverContextP ctx,
2005 VAImageFormat *format_list, /* out */
2006 unsigned int *flags, /* out */
2007 unsigned int *num_formats) /* out */
2011 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
2012 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
2014 format_list[n] = m->va_format;
2016 flags[n] = m->va_flags;
2022 return VA_STATUS_SUCCESS;
2026 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
2028 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
2030 object_heap_free(heap, obj);
2034 i965_CreateSubpicture(VADriverContextP ctx,
2036 VASubpictureID *subpicture) /* out */
2038 struct i965_driver_data *i965 = i965_driver_data(ctx);
2039 VASubpictureID subpicID = NEW_SUBPIC_ID()
2040 struct object_subpic * obj_subpic = SUBPIC(subpicID);
2043 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2045 struct object_image *obj_image = IMAGE(image);
2047 return VA_STATUS_ERROR_INVALID_IMAGE;
2049 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
2051 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
2053 *subpicture = subpicID;
2054 obj_subpic->image = image;
2055 obj_subpic->obj_image = obj_image;
2056 obj_subpic->format = m->format;
2057 obj_subpic->width = obj_image->image.width;
2058 obj_subpic->height = obj_image->image.height;
2059 obj_subpic->pitch = obj_image->image.pitches[0];
2060 obj_subpic->bo = obj_image->bo;
2061 obj_subpic->global_alpha = 1.0;
2063 return VA_STATUS_SUCCESS;
2067 i965_DestroySubpicture(VADriverContextP ctx,
2068 VASubpictureID subpicture)
2070 struct i965_driver_data *i965 = i965_driver_data(ctx);
2071 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2074 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2076 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2077 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
2078 return VA_STATUS_SUCCESS;
2082 i965_SetSubpictureImage(VADriverContextP ctx,
2083 VASubpictureID subpicture,
2087 return VA_STATUS_ERROR_UNIMPLEMENTED;
2091 i965_SetSubpictureChromakey(VADriverContextP ctx,
2092 VASubpictureID subpicture,
2093 unsigned int chromakey_min,
2094 unsigned int chromakey_max,
2095 unsigned int chromakey_mask)
2098 return VA_STATUS_ERROR_UNIMPLEMENTED;
2102 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
2103 VASubpictureID subpicture,
2106 struct i965_driver_data *i965 = i965_driver_data(ctx);
2107 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2109 if (global_alpha > 1.0 || global_alpha < 0.0) {
2110 return VA_STATUS_ERROR_INVALID_PARAMETER;
2114 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2116 obj_subpic->global_alpha = global_alpha;
2118 return VA_STATUS_SUCCESS;
2122 i965_AssociateSubpicture(VADriverContextP ctx,
2123 VASubpictureID subpicture,
2124 VASurfaceID *target_surfaces,
2126 short src_x, /* upper left offset in subpicture */
2128 unsigned short src_width,
2129 unsigned short src_height,
2130 short dest_x, /* upper left offset in surface */
2132 unsigned short dest_width,
2133 unsigned short dest_height,
2135 * whether to enable chroma-keying or global-alpha
2136 * see VA_SUBPICTURE_XXX values
2140 struct i965_driver_data *i965 = i965_driver_data(ctx);
2141 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2145 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2147 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2149 obj_subpic->src_rect.x = src_x;
2150 obj_subpic->src_rect.y = src_y;
2151 obj_subpic->src_rect.width = src_width;
2152 obj_subpic->src_rect.height = src_height;
2153 obj_subpic->dst_rect.x = dest_x;
2154 obj_subpic->dst_rect.y = dest_y;
2155 obj_subpic->dst_rect.width = dest_width;
2156 obj_subpic->dst_rect.height = dest_height;
2157 obj_subpic->flags = flags;
2159 for (i = 0; i < num_surfaces; i++) {
2160 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2162 return VA_STATUS_ERROR_INVALID_SURFACE;
2164 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2165 if (obj_surface->subpic[j] == VA_INVALID_ID) {
2166 assert(obj_surface->obj_subpic[j] == NULL);
2167 obj_surface->subpic[j] = subpicture;
2168 obj_surface->obj_subpic[j] = obj_subpic;
2173 if (j == I965_MAX_SUBPIC_SUM) {
2174 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2178 return VA_STATUS_SUCCESS;
2183 i965_DeassociateSubpicture(VADriverContextP ctx,
2184 VASubpictureID subpicture,
2185 VASurfaceID *target_surfaces,
2188 struct i965_driver_data *i965 = i965_driver_data(ctx);
2189 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2193 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2195 for (i = 0; i < num_surfaces; i++) {
2196 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2198 return VA_STATUS_ERROR_INVALID_SURFACE;
2200 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2201 if (obj_surface->subpic[j] == subpicture) {
2202 assert(obj_surface->obj_subpic[j] == obj_subpic);
2203 obj_surface->subpic[j] = VA_INVALID_ID;
2204 obj_surface->obj_subpic[j] = NULL;
2209 if (j == I965_MAX_SUBPIC_SUM) {
2210 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2213 return VA_STATUS_SUCCESS;
2217 i965_reference_buffer_store(struct buffer_store **ptr,
2218 struct buffer_store *buffer_store)
2220 assert(*ptr == NULL);
2223 buffer_store->ref_count++;
2224 *ptr = buffer_store;
2229 i965_release_buffer_store(struct buffer_store **ptr)
2231 struct buffer_store *buffer_store = *ptr;
2233 if (buffer_store == NULL)
2236 assert(buffer_store->bo || buffer_store->buffer);
2237 assert(!(buffer_store->bo && buffer_store->buffer));
2238 buffer_store->ref_count--;
2240 if (buffer_store->ref_count == 0) {
2241 dri_bo_unreference(buffer_store->bo);
2242 free(buffer_store->buffer);
2243 buffer_store->bo = NULL;
2244 buffer_store->buffer = NULL;
2252 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2254 struct object_context *obj_context = (struct object_context *)obj;
2257 if (obj_context->hw_context) {
2258 obj_context->hw_context->destroy(obj_context->hw_context);
2259 obj_context->hw_context = NULL;
2262 if (obj_context->codec_type == CODEC_PROC) {
2263 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2265 } else if (obj_context->codec_type == CODEC_ENC) {
2266 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2267 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2269 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2270 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2271 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2273 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2274 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2276 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2277 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2279 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2280 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2281 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2283 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2284 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2286 free(obj_context->codec_state.encode.slice_params_ext);
2287 if (obj_context->codec_state.encode.slice_rawdata_index) {
2288 free(obj_context->codec_state.encode.slice_rawdata_index);
2289 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2291 if (obj_context->codec_state.encode.slice_rawdata_count) {
2292 free(obj_context->codec_state.encode.slice_rawdata_count);
2293 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2296 if (obj_context->codec_state.encode.slice_header_index) {
2297 free(obj_context->codec_state.encode.slice_header_index);
2298 obj_context->codec_state.encode.slice_header_index = NULL;
2301 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2302 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2303 free(obj_context->codec_state.encode.packed_header_params_ext);
2305 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2306 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2307 free(obj_context->codec_state.encode.packed_header_data_ext);
2309 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2311 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2312 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2314 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2315 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2316 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2317 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2319 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2320 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2322 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2323 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2325 free(obj_context->codec_state.decode.slice_params);
2326 free(obj_context->codec_state.decode.slice_datas);
2329 free(obj_context->render_targets);
2330 object_heap_free(heap, obj);
2334 max_resolution(struct i965_driver_data *i965,
2335 struct object_config *obj_config,
2339 if (i965->codec_info->max_resolution) {
2340 i965->codec_info->max_resolution(i965, obj_config, w, h);
2342 *w = i965->codec_info->max_width;
2343 *h = i965->codec_info->max_height;
2348 i965_CreateContext(VADriverContextP ctx,
2349 VAConfigID config_id,
2353 VASurfaceID *render_targets,
2354 int num_render_targets,
2355 VAContextID *context) /* out */
2357 struct i965_driver_data *i965 = i965_driver_data(ctx);
2358 struct object_config *obj_config = CONFIG(config_id);
2359 struct object_context *obj_context = NULL;
2360 VAConfigAttrib *attrib;
2361 VAStatus vaStatus = VA_STATUS_SUCCESS;
2367 if (NULL == obj_config) {
2368 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2372 max_resolution(i965, obj_config, &max_width, &max_height);
2374 if (picture_width > max_width ||
2375 picture_height > max_height) {
2376 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2381 /* Validate picture dimensions */
2382 contextID = NEW_CONTEXT_ID();
2383 obj_context = CONTEXT(contextID);
2385 if (NULL == obj_context) {
2386 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2390 *context = contextID;
2391 obj_context->flags = flag;
2392 obj_context->context_id = contextID;
2393 obj_context->obj_config = obj_config;
2394 obj_context->picture_width = picture_width;
2395 obj_context->picture_height = picture_height;
2396 obj_context->num_render_targets = num_render_targets;
2397 obj_context->render_targets =
2398 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2399 obj_context->hw_context = NULL;
2400 obj_context->wrapper_context = VA_INVALID_ID;
2402 if (!obj_context->render_targets)
2403 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2405 for (i = 0; i < num_render_targets; i++) {
2406 if (NULL == SURFACE(render_targets[i])) {
2407 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2411 obj_context->render_targets[i] = render_targets[i];
2414 if (VA_STATUS_SUCCESS == vaStatus) {
2415 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2416 obj_context->codec_type = CODEC_PROC;
2417 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2418 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2419 assert(i965->codec_info->proc_hw_context_init);
2420 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2421 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2422 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2423 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2424 VAConfigAttrib *packed_attrib;
2425 obj_context->codec_type = CODEC_ENC;
2426 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2427 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2428 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2429 obj_context->codec_state.encode.packed_header_params_ext =
2430 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2431 sizeof(struct buffer_store *));
2433 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2434 obj_context->codec_state.encode.packed_header_data_ext =
2435 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2436 sizeof(struct buffer_store *));
2438 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2439 obj_context->codec_state.encode.slice_rawdata_index =
2440 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2441 obj_context->codec_state.encode.slice_rawdata_count =
2442 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2444 obj_context->codec_state.encode.slice_header_index =
2445 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2447 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2449 obj_context->codec_state.encode.slice_index = 0;
2450 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2451 if (packed_attrib) {
2452 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2453 if (obj_config->profile == VAProfileVP9Profile0)
2454 obj_context->codec_state.encode.packed_header_flag =
2455 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2457 /* use the default value. SPS/PPS/RAWDATA is passed from user
2458 * while Slice_header data is generated by driver.
2460 obj_context->codec_state.encode.packed_header_flag =
2461 VA_ENC_PACKED_HEADER_SEQUENCE |
2462 VA_ENC_PACKED_HEADER_PICTURE |
2463 VA_ENC_PACKED_HEADER_RAW_DATA;
2465 /* it is not used for VP9 */
2466 if (obj_config->profile == VAProfileVP9Profile0)
2467 obj_context->codec_state.encode.packed_header_flag = 0;
2469 assert(i965->codec_info->enc_hw_context_init);
2470 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2472 obj_context->codec_type = CODEC_DEC;
2473 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2474 obj_context->codec_state.decode.current_render_target = -1;
2475 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2476 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2477 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2478 sizeof(*obj_context->codec_state.decode.slice_params));
2479 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2480 sizeof(*obj_context->codec_state.decode.slice_datas));
2482 assert(i965->codec_info->dec_hw_context_init);
2483 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2487 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2489 return VA_STATUS_ERROR_INVALID_CONFIG;
2490 obj_context->codec_state.base.chroma_formats = attrib->value;
2492 if (obj_config->wrapper_config != VA_INVALID_ID) {
2493 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2494 * So it won't check i965->wrapper_pdrvctx again.
2495 * Fixme if it is incorrect.
2497 VAGenericID wrapper_context;
2500 * The render_surface is not passed when calling
2502 * If it is needed, we must get the wrapped surface
2503 * for the corresponding Surface_list.
2504 * So the wrapped surface conversion is deferred.
2506 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2507 vaCreateContext(i965->wrapper_pdrvctx,
2508 obj_config->wrapper_config,
2509 picture_width, picture_height,
2513 if (vaStatus == VA_STATUS_SUCCESS)
2514 obj_context->wrapper_context = wrapper_context;
2516 /* Error recovery */
2517 if (VA_STATUS_SUCCESS != vaStatus) {
2518 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2521 i965->current_context_id = contextID;
2527 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2529 struct i965_driver_data *i965 = i965_driver_data(ctx);
2530 struct object_context *obj_context = CONTEXT(context);
2531 VAStatus va_status = VA_STATUS_SUCCESS;
2533 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2535 if (i965->current_context_id == context)
2536 i965->current_context_id = VA_INVALID_ID;
2538 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2539 i965->wrapper_pdrvctx) {
2540 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2541 vaDestroyContext(i965->wrapper_pdrvctx,
2542 obj_context->wrapper_context));
2544 obj_context->wrapper_context = VA_INVALID_ID;
2547 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2553 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2555 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2557 assert(obj_buffer->buffer_store);
2558 i965_release_buffer_store(&obj_buffer->buffer_store);
2559 object_heap_free(heap, obj);
2563 i965_create_buffer_internal(VADriverContextP ctx,
2564 VAContextID context,
2567 unsigned int num_elements,
2572 struct i965_driver_data *i965 = i965_driver_data(ctx);
2573 struct object_buffer *obj_buffer = NULL;
2574 struct buffer_store *buffer_store = NULL;
2576 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2577 struct object_context *obj_context = CONTEXT(context);
2578 int wrapper_flag = 0;
2582 case VAPictureParameterBufferType:
2583 case VAIQMatrixBufferType:
2584 case VAQMatrixBufferType:
2585 case VABitPlaneBufferType:
2586 case VASliceGroupMapBufferType:
2587 case VASliceParameterBufferType:
2588 case VASliceDataBufferType:
2589 case VAMacroblockParameterBufferType:
2590 case VAResidualDataBufferType:
2591 case VADeblockingParameterBufferType:
2592 case VAImageBufferType:
2593 case VAEncCodedBufferType:
2594 case VAEncSequenceParameterBufferType:
2595 case VAEncPictureParameterBufferType:
2596 case VAEncSliceParameterBufferType:
2597 case VAEncPackedHeaderParameterBufferType:
2598 case VAEncPackedHeaderDataBufferType:
2599 case VAEncMiscParameterBufferType:
2600 case VAProcPipelineParameterBufferType:
2601 case VAProcFilterParameterBufferType:
2602 case VAHuffmanTableBufferType:
2603 case VAProbabilityBufferType:
2604 case VAEncMacroblockMapBufferType:
2609 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2612 bufferID = NEW_BUFFER_ID();
2613 obj_buffer = BUFFER(bufferID);
2615 if (NULL == obj_buffer) {
2616 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2619 if (type == VAEncCodedBufferType) {
2620 size += I965_CODEDBUFFER_HEADER_SIZE;
2621 size += 0x1000; /* for upper bound check */
2624 obj_buffer->max_num_elements = num_elements;
2625 obj_buffer->num_elements = num_elements;
2626 obj_buffer->size_element = size;
2627 obj_buffer->type = type;
2628 obj_buffer->export_refcount = 0;
2629 obj_buffer->buffer_store = NULL;
2630 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2631 obj_buffer->context_id = context;
2633 buffer_store = calloc(1, sizeof(struct buffer_store));
2634 assert(buffer_store);
2635 buffer_store->ref_count = 1;
2638 (obj_context->wrapper_context != VA_INVALID_ID) &&
2639 i965->wrapper_pdrvctx) {
2640 VAGenericID wrapper_buffer;
2641 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2643 CALL_VTABLE(pdrvctx, vaStatus,
2644 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2645 data, &wrapper_buffer));
2646 if (vaStatus == VA_STATUS_SUCCESS) {
2647 obj_buffer->wrapper_buffer = wrapper_buffer;
2655 if (store_bo != NULL) {
2656 buffer_store->bo = store_bo;
2657 dri_bo_reference(buffer_store->bo);
2659 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2660 if (data && !wrapper_flag)
2661 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2662 } else if (type == VASliceDataBufferType ||
2663 type == VAImageBufferType ||
2664 type == VAEncCodedBufferType ||
2665 type == VAEncMacroblockMapBufferType ||
2666 type == VAProbabilityBufferType) {
2668 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2669 * So it is enough to allocate one 64 byte bo
2672 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2675 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2677 size * num_elements, 64);
2678 assert(buffer_store->bo);
2680 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2681 * In fact it can be skipped. But it is still allocated and it is
2682 * only to follow the normal flowchart of buffer_allocation/release.
2684 if (!wrapper_flag) {
2685 if (type == VAEncCodedBufferType) {
2686 struct i965_coded_buffer_segment *coded_buffer_segment;
2688 dri_bo_map(buffer_store->bo, 1);
2689 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2690 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2691 coded_buffer_segment->base.bit_offset = 0;
2692 coded_buffer_segment->base.status = 0;
2693 coded_buffer_segment->base.buf = NULL;
2694 coded_buffer_segment->base.next = NULL;
2695 coded_buffer_segment->mapped = 0;
2696 coded_buffer_segment->codec = 0;
2697 coded_buffer_segment->status_support = 0;
2698 dri_bo_unmap(buffer_store->bo);
2700 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2707 if (type == VAEncPackedHeaderDataBufferType) {
2708 msize = ALIGN(size, 4);
2711 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2713 buffer_store->buffer = malloc(4);
2715 buffer_store->buffer = malloc(msize * num_elements);
2716 assert(buffer_store->buffer);
2718 if (!wrapper_flag) {
2720 memcpy(buffer_store->buffer, data, size * num_elements);
2722 memset(buffer_store->buffer, 0, size * num_elements);
2726 buffer_store->num_elements = obj_buffer->num_elements;
2727 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2728 i965_release_buffer_store(&buffer_store);
2731 return VA_STATUS_SUCCESS;
2735 i965_CreateBuffer(VADriverContextP ctx,
2736 VAContextID context, /* in */
2737 VABufferType type, /* in */
2738 unsigned int size, /* in */
2739 unsigned int num_elements, /* in */
2740 void *data, /* in */
2741 VABufferID *buf_id) /* out */
2743 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2748 i965_BufferSetNumElements(VADriverContextP ctx,
2749 VABufferID buf_id, /* in */
2750 unsigned int num_elements) /* in */
2752 struct i965_driver_data *i965 = i965_driver_data(ctx);
2753 struct object_buffer *obj_buffer = BUFFER(buf_id);
2754 VAStatus vaStatus = VA_STATUS_SUCCESS;
2756 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2758 /* When the wrapper_buffer exists, it will wrapper to the
2759 * buffer allocated from backend driver.
2761 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2762 i965->wrapper_pdrvctx) {
2763 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2765 CALL_VTABLE(pdrvctx, vaStatus,
2766 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2771 if ((num_elements < 0) ||
2772 (num_elements > obj_buffer->max_num_elements)) {
2773 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2775 obj_buffer->num_elements = num_elements;
2776 if (obj_buffer->buffer_store != NULL) {
2777 obj_buffer->buffer_store->num_elements = num_elements;
2785 i965_MapBuffer(VADriverContextP ctx,
2786 VABufferID buf_id, /* in */
2787 void **pbuf) /* out */
2789 struct i965_driver_data *i965 = i965_driver_data(ctx);
2790 struct object_buffer *obj_buffer = BUFFER(buf_id);
2791 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2792 struct object_context *obj_context;
2794 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2796 obj_context = CONTEXT(obj_buffer->context_id);
2798 /* When the wrapper_buffer exists, it will wrapper to the
2799 * buffer allocated from backend driver.
2801 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2802 i965->wrapper_pdrvctx) {
2803 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2805 CALL_VTABLE(pdrvctx, vaStatus,
2806 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2810 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2811 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2813 if (obj_buffer->export_refcount > 0)
2814 return VA_STATUS_ERROR_INVALID_BUFFER;
2816 if (NULL != obj_buffer->buffer_store->bo) {
2817 unsigned int tiling, swizzle;
2819 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2821 if (tiling != I915_TILING_NONE)
2822 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2824 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2826 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2827 *pbuf = obj_buffer->buffer_store->bo->virtual;
2828 vaStatus = VA_STATUS_SUCCESS;
2830 if (obj_buffer->type == VAEncCodedBufferType) {
2832 unsigned char *buffer = NULL;
2833 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2834 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2836 if (!coded_buffer_segment->mapped) {
2837 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2839 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2842 obj_context->hw_context &&
2843 obj_context->hw_context->get_status &&
2844 coded_buffer_segment->status_support) {
2845 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2847 if (coded_buffer_segment->codec == CODEC_H264 ||
2848 coded_buffer_segment->codec == CODEC_H264_MVC) {
2849 delimiter0 = H264_DELIMITER0;
2850 delimiter1 = H264_DELIMITER1;
2851 delimiter2 = H264_DELIMITER2;
2852 delimiter3 = H264_DELIMITER3;
2853 delimiter4 = H264_DELIMITER4;
2854 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2855 delimiter0 = MPEG2_DELIMITER0;
2856 delimiter1 = MPEG2_DELIMITER1;
2857 delimiter2 = MPEG2_DELIMITER2;
2858 delimiter3 = MPEG2_DELIMITER3;
2859 delimiter4 = MPEG2_DELIMITER4;
2860 } else if (coded_buffer_segment->codec == CODEC_JPEG) {
2861 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2864 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2865 delimiter0 = HEVC_DELIMITER0;
2866 delimiter1 = HEVC_DELIMITER1;
2867 delimiter2 = HEVC_DELIMITER2;
2868 delimiter3 = HEVC_DELIMITER3;
2869 delimiter4 = HEVC_DELIMITER4;
2870 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2871 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2874 if (coded_buffer_segment->codec == CODEC_JPEG) {
2875 for (i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2876 if ((buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2880 coded_buffer_segment->base.size = i + 2;
2881 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2882 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2883 so it don't need to traversal the coded buffer */
2884 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2885 if ((buffer[i] == delimiter0) &&
2886 (buffer[i + 1] == delimiter1) &&
2887 (buffer[i + 2] == delimiter2) &&
2888 (buffer[i + 3] == delimiter3) &&
2889 (buffer[i + 4] == delimiter4))
2893 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2894 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2896 coded_buffer_segment->base.size = i;
2899 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2900 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2903 vaStatus = VA_STATUS_SUCCESS;
2906 coded_buffer_segment->mapped = 1;
2908 assert(coded_buffer_segment->base.buf);
2909 vaStatus = VA_STATUS_SUCCESS;
2912 } else if (NULL != obj_buffer->buffer_store->buffer) {
2913 *pbuf = obj_buffer->buffer_store->buffer;
2914 vaStatus = VA_STATUS_SUCCESS;
2921 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2923 struct i965_driver_data *i965 = i965_driver_data(ctx);
2924 struct object_buffer *obj_buffer = BUFFER(buf_id);
2925 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2927 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2928 return VA_STATUS_ERROR_INVALID_BUFFER;
2930 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2931 /* When the wrapper_buffer exists, it will wrapper to the
2932 * buffer allocated from backend driver.
2934 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2935 i965->wrapper_pdrvctx) {
2936 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2938 CALL_VTABLE(pdrvctx, vaStatus,
2939 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2943 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2944 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2946 if (NULL != obj_buffer->buffer_store->bo) {
2947 unsigned int tiling, swizzle;
2949 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2951 if (tiling != I915_TILING_NONE)
2952 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2954 dri_bo_unmap(obj_buffer->buffer_store->bo);
2956 vaStatus = VA_STATUS_SUCCESS;
2957 } else if (NULL != obj_buffer->buffer_store->buffer) {
2959 vaStatus = VA_STATUS_SUCCESS;
2966 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2968 struct i965_driver_data *i965 = i965_driver_data(ctx);
2969 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2970 VAStatus va_status = VA_STATUS_SUCCESS;
2972 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2974 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2975 i965->wrapper_pdrvctx) {
2976 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2977 vaDestroyBuffer(i965->wrapper_pdrvctx,
2978 obj_buffer->wrapper_buffer));
2979 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2982 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2988 i965_BeginPicture(VADriverContextP ctx,
2989 VAContextID context,
2990 VASurfaceID render_target)
2992 struct i965_driver_data *i965 = i965_driver_data(ctx);
2993 struct object_context *obj_context = CONTEXT(context);
2994 struct object_surface *obj_surface = SURFACE(render_target);
2995 struct object_config *obj_config;
2996 VAStatus vaStatus = VA_STATUS_SUCCESS;
2999 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3000 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3001 obj_config = obj_context->obj_config;
3002 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3004 if (is_surface_busy(i965, obj_surface))
3005 return VA_STATUS_ERROR_SURFACE_BUSY;
3007 if (obj_context->codec_type == CODEC_PROC) {
3008 obj_context->codec_state.proc.current_render_target = render_target;
3009 } else if (obj_context->codec_type == CODEC_ENC) {
3011 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
3013 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
3014 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
3016 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
3017 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
3019 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
3020 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
3022 obj_context->codec_state.encode.num_slice_params_ext = 0;
3023 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
3024 obj_context->codec_state.encode.last_packed_header_type = 0;
3025 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
3026 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3027 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
3028 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3029 memset(obj_context->codec_state.encode.slice_header_index, 0,
3030 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3032 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
3033 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
3034 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
3035 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
3036 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
3037 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
3038 obj_context->codec_state.encode.slice_index = 0;
3039 obj_context->codec_state.encode.vps_sps_seq_index = 0;
3041 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
3042 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
3043 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
3045 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
3047 obj_context->codec_state.decode.current_render_target = render_target;
3048 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
3049 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
3050 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
3051 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
3053 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
3054 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
3055 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
3058 obj_context->codec_state.decode.num_slice_params = 0;
3059 obj_context->codec_state.decode.num_slice_datas = 0;
3061 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
3062 i965->wrapper_pdrvctx) {
3063 if (obj_surface->wrapper_surface == VA_INVALID_ID)
3064 vaStatus = i965_surface_wrapper(ctx, render_target);
3066 if (vaStatus != VA_STATUS_SUCCESS)
3069 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
3070 vaBeginPicture(i965->wrapper_pdrvctx,
3071 obj_context->wrapper_context,
3072 obj_surface->wrapper_surface));
3079 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
3081 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
3083 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3084 struct object_context *obj_context, \
3085 struct object_buffer *obj_buffer) \
3087 struct category##_state *category = &obj_context->codec_state.category; \
3088 i965_release_buffer_store(&category->member); \
3089 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
3090 return VA_STATUS_SUCCESS; \
3093 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
3095 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3096 struct object_context *obj_context, \
3097 struct object_buffer *obj_buffer) \
3099 struct category##_state *category = &obj_context->codec_state.category; \
3100 if (category->num_##member == category->max_##member) { \
3101 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
3102 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
3103 category->max_##member += NUM_SLICES; \
3105 i965_release_buffer_store(&category->member[category->num_##member]); \
3106 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
3107 category->num_##member++; \
3108 return VA_STATUS_SUCCESS; \
3111 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
3113 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
3114 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3115 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
3116 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
3117 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3118 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
3120 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
3121 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3122 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
3126 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
3127 VABufferID *buffers,
3130 struct i965_driver_data *i965 = i965_driver_data(ctx);
3131 VAStatus vaStatus = VA_STATUS_SUCCESS;
3133 VADecPictureParameterBufferVP9 *pVp9PicParams;
3134 VADriverContextP pdrvctx;
3135 struct object_buffer *obj_buffer;
3137 pdrvctx = i965->wrapper_pdrvctx;
3138 /* do the conversion of VADecPictureParameterBufferVP9 */
3139 for (i = 0; i < num_buffers; i++) {
3140 obj_buffer = BUFFER(buffers[i]);
3145 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
3148 if (obj_buffer->type == VAPictureParameterBufferType) {
3150 VASurfaceID surface_id;
3151 struct object_surface *obj_surface;
3153 pdrvctx = i965->wrapper_pdrvctx;
3155 CALL_VTABLE(pdrvctx, vaStatus,
3156 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
3157 (void **)(&pVp9PicParams)));
3159 if (vaStatus != VA_STATUS_SUCCESS)
3162 for (j = 0; j < 8; j++) {
3163 surface_id = pVp9PicParams->reference_frames[j];
3164 obj_surface = SURFACE(surface_id);
3169 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
3170 vaStatus = i965_surface_wrapper(ctx, surface_id);
3171 if (vaStatus != VA_STATUS_SUCCESS) {
3172 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
3173 obj_buffer->wrapper_buffer);
3178 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
3180 CALL_VTABLE(pdrvctx, vaStatus,
3181 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3186 return VA_STATUS_SUCCESS;
3193 i965_decoder_wrapper_picture(VADriverContextP ctx,
3194 VAContextID context,
3195 VABufferID *buffers,
3198 struct i965_driver_data *i965 = i965_driver_data(ctx);
3199 struct object_context *obj_context = CONTEXT(context);
3200 VAStatus vaStatus = VA_STATUS_SUCCESS;
3202 VADriverContextP pdrvctx;
3203 struct object_buffer *obj_buffer;
3205 if (obj_context == NULL)
3206 return VA_STATUS_ERROR_INVALID_CONTEXT;
3208 /* When it is not wrapped context, continue the normal flowchart */
3209 if (obj_context->wrapper_context == VA_INVALID_ID)
3212 if (obj_context->obj_config &&
3213 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3214 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3216 return VA_STATUS_ERROR_INVALID_PARAMETER;
3218 pdrvctx = i965->wrapper_pdrvctx;
3220 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3221 obj_buffer = BUFFER(buffers[i]);
3226 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3227 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3231 CALL_VTABLE(pdrvctx, vaStatus,
3232 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3233 &(obj_buffer->wrapper_buffer), 1));
3239 i965_decoder_render_picture(VADriverContextP ctx,
3240 VAContextID context,
3241 VABufferID *buffers,
3244 struct i965_driver_data *i965 = i965_driver_data(ctx);
3245 struct object_context *obj_context = CONTEXT(context);
3246 VAStatus vaStatus = VA_STATUS_SUCCESS;
3249 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3251 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3252 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3255 return VA_STATUS_ERROR_INVALID_BUFFER;
3257 switch (obj_buffer->type) {
3258 case VAPictureParameterBufferType:
3259 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3262 case VAIQMatrixBufferType:
3263 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3266 case VABitPlaneBufferType:
3267 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3270 case VASliceParameterBufferType:
3271 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3274 case VASliceDataBufferType:
3275 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3278 case VAHuffmanTableBufferType:
3279 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3282 case VAProbabilityBufferType:
3283 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3287 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3292 if ((vaStatus == VA_STATUS_SUCCESS) &&
3293 (obj_context->wrapper_context != VA_INVALID_ID))
3294 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3299 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3301 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3302 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3303 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3304 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3305 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3306 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3307 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3308 /* extended buffer */
3309 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3310 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3311 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3313 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3314 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3315 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3317 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3318 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3321 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3322 struct object_context *obj_context,
3323 struct object_buffer *obj_buffer,
3326 struct encode_state *encode = &obj_context->codec_state.encode;
3328 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3329 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3330 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3331 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3333 return VA_STATUS_SUCCESS;
3337 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3338 struct object_context *obj_context,
3339 struct object_buffer *obj_buffer,
3342 struct encode_state *encode = &obj_context->codec_state.encode;
3344 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3345 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3346 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3347 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3349 return VA_STATUS_SUCCESS;
3353 i965_encoder_get_misc_paramerter_buffer_index(VADriverContextP ctx,
3354 struct encode_state *encode,
3355 VAEncMiscParameterBuffer *misc_param)
3359 if (!encode->has_layers)
3362 if (misc_param->type == VAEncMiscParameterTypeRateControl) {
3363 VAEncMiscParameterRateControl *misc_rate_control = (VAEncMiscParameterRateControl *)misc_param->data;
3365 index = misc_rate_control->rc_flags.bits.temporal_id;
3366 } else if (misc_param->type == VAEncMiscParameterTypeFrameRate) {
3367 VAEncMiscParameterFrameRate *misc_frame_rate = (VAEncMiscParameterFrameRate *)misc_param->data;
3369 index = misc_frame_rate->framerate_flags.bits.temporal_id;
3376 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3377 struct object_context *obj_context,
3378 struct object_buffer *obj_buffer)
3380 struct encode_state *encode = &obj_context->codec_state.encode;
3381 VAEncMiscParameterBuffer *param = NULL;
3384 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3385 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3387 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3389 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3390 return VA_STATUS_ERROR_INVALID_PARAMETER;
3392 if (param->type == VAEncMiscParameterTypeTemporalLayerStructure)
3393 encode->has_layers = 1;
3395 index = i965_encoder_get_misc_paramerter_buffer_index(ctx, encode, param);
3397 if (index >= ARRAY_ELEMS(encode->misc_param[0]))
3398 return VA_STATUS_ERROR_INVALID_PARAMETER;
3400 i965_release_buffer_store(&encode->misc_param[param->type][index]);
3401 i965_reference_buffer_store(&encode->misc_param[param->type][index], obj_buffer->buffer_store);
3403 return VA_STATUS_SUCCESS;
3407 i965_encoder_render_picture(VADriverContextP ctx,
3408 VAContextID context,
3409 VABufferID *buffers,
3412 struct i965_driver_data *i965 = i965_driver_data(ctx);
3413 struct object_context *obj_context = CONTEXT(context);
3414 struct object_config *obj_config;
3415 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3416 struct encode_state *encode;
3419 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3420 obj_config = obj_context->obj_config;
3421 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3423 encode = &obj_context->codec_state.encode;
3424 for (i = 0; i < num_buffers; i++) {
3425 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3428 return VA_STATUS_ERROR_INVALID_BUFFER;
3430 switch (obj_buffer->type) {
3431 case VAQMatrixBufferType:
3432 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3435 case VAIQMatrixBufferType:
3436 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3439 case VAEncSequenceParameterBufferType:
3440 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3443 case VAEncPictureParameterBufferType:
3444 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3447 case VAHuffmanTableBufferType:
3448 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3451 case VAEncSliceParameterBufferType:
3452 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3453 if (vaStatus == VA_STATUS_SUCCESS) {
3454 /* When the max number of slices is updated, it also needs
3455 * to reallocate the arrays that is used to store
3456 * the packed data index/count for the slice
3458 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3459 encode->slice_index++;
3461 if (encode->slice_index == encode->max_slice_num) {
3462 int slice_num = encode->max_slice_num;
3463 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3464 (slice_num + NUM_SLICES) * sizeof(int));
3465 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3466 (slice_num + NUM_SLICES) * sizeof(int));
3467 encode->slice_header_index = realloc(encode->slice_header_index,
3468 (slice_num + NUM_SLICES) * sizeof(int));
3469 memset(encode->slice_rawdata_index + slice_num, 0,
3470 sizeof(int) * NUM_SLICES);
3471 memset(encode->slice_rawdata_count + slice_num, 0,
3472 sizeof(int) * NUM_SLICES);
3473 memset(encode->slice_header_index + slice_num, 0,
3474 sizeof(int) * NUM_SLICES);
3476 encode->max_slice_num += NUM_SLICES;
3477 if ((encode->slice_rawdata_index == NULL) ||
3478 (encode->slice_header_index == NULL) ||
3479 (encode->slice_rawdata_count == NULL)) {
3480 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3487 case VAEncPackedHeaderParameterBufferType: {
3488 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3489 encode->last_packed_header_type = param->type;
3491 if ((param->type == VAEncPackedHeaderRawData) ||
3492 (param->type == VAEncPackedHeaderSlice)) {
3493 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3494 } else if ((obj_config->profile == VAProfileHEVCMain ||
3495 obj_config->profile == VAProfileHEVCMain10) &&
3496 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3497 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3500 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3502 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3505 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3510 case VAEncPackedHeaderDataBufferType: {
3511 if (encode->last_packed_header_type == 0) {
3512 WARN_ONCE("the packed header data is passed without type!\n");
3513 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3517 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3518 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3519 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3521 if (obj_config->profile == VAProfileVP9Profile0)
3524 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3525 * the packed_slice_header as the delimeter to decide how
3526 * the packed rawdata is inserted for the given slice.
3527 * Otherwise it will use the VAEncSequenceParameterBuffer
3530 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3531 /* store the first index of the packed header data for current slice */
3532 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3533 encode->slice_rawdata_index[encode->slice_index] =
3534 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3536 encode->slice_rawdata_count[encode->slice_index]++;
3537 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3538 /* find one packed slice_header delimeter. And the following
3539 * packed data is for the next slice
3541 encode->slice_header_index[encode->slice_index] =
3542 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3543 encode->slice_index++;
3544 /* Reallocate the buffer to record the index/count of
3545 * packed_data for one slice.
3547 if (encode->slice_index == encode->max_slice_num) {
3548 int slice_num = encode->max_slice_num;
3550 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3551 (slice_num + NUM_SLICES) * sizeof(int));
3552 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3553 (slice_num + NUM_SLICES) * sizeof(int));
3554 encode->slice_header_index = realloc(encode->slice_header_index,
3555 (slice_num + NUM_SLICES) * sizeof(int));
3556 memset(encode->slice_rawdata_index + slice_num, 0,
3557 sizeof(int) * NUM_SLICES);
3558 memset(encode->slice_rawdata_count + slice_num, 0,
3559 sizeof(int) * NUM_SLICES);
3560 memset(encode->slice_header_index + slice_num, 0,
3561 sizeof(int) * NUM_SLICES);
3562 encode->max_slice_num += NUM_SLICES;
3566 if (vaStatus == VA_STATUS_SUCCESS) {
3567 /* store the first index of the packed header data for current slice */
3568 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3569 encode->slice_rawdata_index[encode->slice_index] =
3570 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3572 encode->slice_rawdata_count[encode->slice_index]++;
3573 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3574 if (encode->slice_header_index[encode->slice_index] == 0) {
3575 encode->slice_header_index[encode->slice_index] =
3576 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3578 WARN_ONCE("Multi slice header data is passed for"
3579 " slice %d!\n", encode->slice_index);
3585 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3586 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3587 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3588 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3589 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3590 VA_STATUS_ERROR_ENCODING_ERROR);
3592 if ((obj_config->profile == VAProfileHEVCMain ||
3593 obj_config->profile == VAProfileHEVCMain10) &&
3594 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3596 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3599 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3600 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3602 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3605 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3609 encode->last_packed_header_type = 0;
3613 case VAEncMiscParameterBufferType:
3614 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3619 case VAEncMacroblockMapBufferType:
3620 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3624 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3632 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3634 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3635 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3638 i965_proc_render_picture(VADriverContextP ctx,
3639 VAContextID context,
3640 VABufferID *buffers,
3643 struct i965_driver_data *i965 = i965_driver_data(ctx);
3644 struct object_context *obj_context = CONTEXT(context);
3645 VAStatus vaStatus = VA_STATUS_SUCCESS;
3648 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3650 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3651 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3654 return VA_STATUS_ERROR_INVALID_BUFFER;
3656 switch (obj_buffer->type) {
3657 case VAProcPipelineParameterBufferType:
3658 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3662 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3671 i965_RenderPicture(VADriverContextP ctx,
3672 VAContextID context,
3673 VABufferID *buffers,
3676 struct i965_driver_data *i965 = i965_driver_data(ctx);
3677 struct object_context *obj_context;
3678 struct object_config *obj_config;
3679 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3681 obj_context = CONTEXT(context);
3682 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3684 if (num_buffers <= 0)
3685 return VA_STATUS_ERROR_INVALID_PARAMETER;
3687 obj_config = obj_context->obj_config;
3688 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3690 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3691 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3692 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
3693 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3694 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3695 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3697 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3704 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3706 struct i965_driver_data *i965 = i965_driver_data(ctx);
3707 struct object_context *obj_context = CONTEXT(context);
3708 struct object_config *obj_config;
3710 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3711 obj_config = obj_context->obj_config;
3712 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3714 if (obj_context->codec_type == CODEC_PROC) {
3715 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3716 } else if (obj_context->codec_type == CODEC_ENC) {
3717 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3718 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3719 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3720 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3722 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3723 obj_context->codec_state.encode.num_packed_header_data_ext) {
3724 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3725 return VA_STATUS_ERROR_INVALID_PARAMETER;
3727 if (!obj_context->codec_state.encode.pic_param_ext) {
3728 return VA_STATUS_ERROR_INVALID_PARAMETER;
3730 if (!obj_context->codec_state.encode.seq_param_ext &&
3731 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3732 /* The seq_param is not mandatory for VP9 encoding */
3733 if (obj_config->profile != VAProfileVP9Profile0)
3734 return VA_STATUS_ERROR_INVALID_PARAMETER;
3736 if ((obj_context->codec_state.encode.num_slice_params_ext <= 0) &&
3737 ((obj_config->profile != VAProfileVP8Version0_3) &&
3738 (obj_config->profile != VAProfileVP9Profile0))) {
3739 return VA_STATUS_ERROR_INVALID_PARAMETER;
3742 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3743 (obj_context->codec_state.encode.num_slice_params_ext !=
3744 obj_context->codec_state.encode.slice_index)) {
3745 WARN_ONCE("packed slice_header data is missing for some slice"
3746 " under packed SLICE_HEADER mode\n");
3747 return VA_STATUS_ERROR_INVALID_PARAMETER;
3750 if (obj_context->codec_state.decode.pic_param == NULL) {
3751 return VA_STATUS_ERROR_INVALID_PARAMETER;
3753 if (obj_context->codec_state.decode.num_slice_params <= 0) {
3754 return VA_STATUS_ERROR_INVALID_PARAMETER;
3756 if (obj_context->codec_state.decode.num_slice_datas <= 0) {
3757 return VA_STATUS_ERROR_INVALID_PARAMETER;
3760 if (obj_context->codec_state.decode.num_slice_params !=
3761 obj_context->codec_state.decode.num_slice_datas) {
3762 return VA_STATUS_ERROR_INVALID_PARAMETER;
3765 if (obj_context->wrapper_context != VA_INVALID_ID) {
3766 /* call the vaEndPicture of wrapped driver */
3767 VADriverContextP pdrvctx;
3770 pdrvctx = i965->wrapper_pdrvctx;
3771 CALL_VTABLE(pdrvctx, va_status,
3772 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3778 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3779 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3783 i965_SyncSurface(VADriverContextP ctx,
3784 VASurfaceID render_target)
3786 struct i965_driver_data *i965 = i965_driver_data(ctx);
3787 struct object_surface *obj_surface = SURFACE(render_target);
3789 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3791 if (obj_surface->bo)
3792 drm_intel_bo_wait_rendering(obj_surface->bo);
3794 return VA_STATUS_SUCCESS;
3798 i965_QuerySurfaceStatus(VADriverContextP ctx,
3799 VASurfaceID render_target,
3800 VASurfaceStatus *status) /* out */
3802 struct i965_driver_data *i965 = i965_driver_data(ctx);
3803 struct object_surface *obj_surface = SURFACE(render_target);
3805 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3807 if (obj_surface->bo) {
3808 if (drm_intel_bo_busy(obj_surface->bo)) {
3809 *status = VASurfaceRendering;
3811 *status = VASurfaceReady;
3814 *status = VASurfaceReady;
3817 return VA_STATUS_SUCCESS;
3820 static VADisplayAttribute *
3821 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3823 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3826 if (!i965->display_attributes)
3829 for (i = 0; i < i965->num_display_attributes; i++) {
3830 if (i965->display_attributes[i].type == type)
3831 return &i965->display_attributes[i];
3837 i965_display_attributes_terminate(VADriverContextP ctx)
3839 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3841 if (i965->display_attributes) {
3842 free(i965->display_attributes);
3843 i965->display_attributes = NULL;
3844 i965->num_display_attributes = 0;
3849 i965_display_attributes_init(VADriverContextP ctx)
3851 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3853 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3854 i965->display_attributes = malloc(
3855 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3856 if (!i965->display_attributes)
3860 i965->display_attributes,
3861 i965_display_attributes,
3862 sizeof(i965_display_attributes)
3865 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3866 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3867 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3868 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3869 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3871 if (!i965->rotation_attrib ||
3872 !i965->brightness_attrib ||
3873 !i965->contrast_attrib ||
3874 !i965->hue_attrib ||
3875 !i965->saturation_attrib) {
3881 i965_display_attributes_terminate(ctx);
3886 * Query display attributes
3887 * The caller must provide a "attr_list" array that can hold at
3888 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3889 * returned in "attr_list" is returned in "num_attributes".
3892 i965_QueryDisplayAttributes(
3893 VADriverContextP ctx,
3894 VADisplayAttribute *attribs, /* out */
3895 int *num_attribs_ptr /* out */
3898 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3900 if (attribs && num_attribs > 0)
3901 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3903 if (num_attribs_ptr)
3904 *num_attribs_ptr = num_attribs;
3906 return VA_STATUS_SUCCESS;
3910 * Get display attributes
3911 * This function returns the current attribute values in "attr_list".
3912 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3913 * from vaQueryDisplayAttributes() can have their values retrieved.
3916 i965_GetDisplayAttributes(
3917 VADriverContextP ctx,
3918 VADisplayAttribute *attribs, /* inout */
3919 int num_attribs /* in */
3924 for (i = 0; i < num_attribs; i++) {
3925 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3927 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3929 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3930 dst_attrib->min_value = src_attrib->min_value;
3931 dst_attrib->max_value = src_attrib->max_value;
3932 dst_attrib->value = src_attrib->value;
3933 dst_attrib->flags = src_attrib->flags;
3934 } else if (src_attrib &&
3935 (src_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE)) {
3936 dst_attrib->flags = src_attrib->flags;
3938 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3940 return VA_STATUS_SUCCESS;
3944 * Set display attributes
3945 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3946 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3947 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3950 i965_SetDisplayAttributes(
3951 VADriverContextP ctx,
3952 VADisplayAttribute *attribs, /* in */
3953 int num_attribs /* in */
3958 for (i = 0; i < num_attribs; i++) {
3959 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3961 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3963 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3965 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3968 if (src_attrib->value < dst_attrib->min_value ||
3969 src_attrib->value > dst_attrib->max_value)
3970 return VA_STATUS_ERROR_INVALID_PARAMETER;
3972 dst_attrib->value = src_attrib->value;
3973 /* XXX: track modified attributes through timestamps */
3975 return VA_STATUS_SUCCESS;
3979 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3980 VASurfaceID surface,
3981 void **buffer, /* out */
3982 unsigned int *stride) /* out */
3985 return VA_STATUS_ERROR_UNIMPLEMENTED;
3989 i965_destroy_heap(struct object_heap *heap,
3990 void (*func)(struct object_heap *heap, struct object_base *object))
3992 struct object_base *object;
3993 object_heap_iterator iter;
3995 object = object_heap_first(heap, &iter);
4001 object = object_heap_next(heap, &iter);
4004 object_heap_destroy(heap);
4009 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
4012 i965_CreateImage(VADriverContextP ctx,
4013 VAImageFormat *format,
4016 VAImage *out_image) /* out */
4018 struct i965_driver_data *i965 = i965_driver_data(ctx);
4019 struct object_image *obj_image;
4020 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4022 unsigned int size2, size, awidth, aheight;
4024 out_image->image_id = VA_INVALID_ID;
4025 out_image->buf = VA_INVALID_ID;
4027 image_id = NEW_IMAGE_ID();
4028 if (image_id == VA_INVALID_ID)
4029 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4031 obj_image = IMAGE(image_id);
4033 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4034 obj_image->bo = NULL;
4035 obj_image->palette = NULL;
4036 obj_image->derived_surface = VA_INVALID_ID;
4038 VAImage * const image = &obj_image->image;
4039 image->image_id = image_id;
4040 image->buf = VA_INVALID_ID;
4042 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
4044 if ((format->fourcc == VA_FOURCC_YV12) ||
4045 (format->fourcc == VA_FOURCC_I420)) {
4046 if (awidth % 128 != 0) {
4047 awidth = ALIGN(width, 128);
4051 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
4052 size = awidth * aheight;
4053 size2 = (awidth / 2) * (aheight / 2);
4055 image->num_palette_entries = 0;
4056 image->entry_bytes = 0;
4057 memset(image->component_order, 0, sizeof(image->component_order));
4059 switch (format->fourcc) {
4060 case VA_FOURCC_IA44:
4061 case VA_FOURCC_AI44:
4062 image->num_planes = 1;
4063 image->pitches[0] = awidth;
4064 image->offsets[0] = 0;
4065 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4066 image->num_palette_entries = 16;
4067 image->entry_bytes = 3;
4068 image->component_order[0] = 'R';
4069 image->component_order[1] = 'G';
4070 image->component_order[2] = 'B';
4072 case VA_FOURCC_IA88:
4073 case VA_FOURCC_AI88:
4074 image->num_planes = 1;
4075 image->pitches[0] = awidth * 2;
4076 image->offsets[0] = 0;
4077 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4078 image->num_palette_entries = 256;
4079 image->entry_bytes = 3;
4080 image->component_order[0] = 'R';
4081 image->component_order[1] = 'G';
4082 image->component_order[2] = 'B';
4084 case VA_FOURCC_ARGB:
4085 case VA_FOURCC_ABGR:
4086 case VA_FOURCC_BGRA:
4087 case VA_FOURCC_RGBA:
4088 case VA_FOURCC_BGRX:
4089 case VA_FOURCC_RGBX:
4090 image->num_planes = 1;
4091 image->pitches[0] = awidth * 4;
4092 image->offsets[0] = 0;
4093 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4095 case VA_FOURCC_YV12:
4096 image->num_planes = 3;
4097 image->pitches[0] = awidth;
4098 image->offsets[0] = 0;
4099 image->pitches[1] = awidth / 2;
4100 image->offsets[1] = size;
4101 image->pitches[2] = awidth / 2;
4102 image->offsets[2] = size + size2;
4103 image->data_size = size + 2 * size2;
4105 case VA_FOURCC_I420:
4106 image->num_planes = 3;
4107 image->pitches[0] = awidth;
4108 image->offsets[0] = 0;
4109 image->pitches[1] = awidth / 2;
4110 image->offsets[1] = size;
4111 image->pitches[2] = awidth / 2;
4112 image->offsets[2] = size + size2;
4113 image->data_size = size + 2 * size2;
4115 case VA_FOURCC_422H:
4116 image->num_planes = 3;
4117 image->pitches[0] = awidth;
4118 image->offsets[0] = 0;
4119 image->pitches[1] = awidth / 2;
4120 image->offsets[1] = size;
4121 image->pitches[2] = awidth / 2;
4122 image->offsets[2] = size + (awidth / 2) * aheight;
4123 image->data_size = size + 2 * ((awidth / 2) * aheight);
4125 case VA_FOURCC_NV12:
4126 image->num_planes = 2;
4127 image->pitches[0] = awidth;
4128 image->offsets[0] = 0;
4129 image->pitches[1] = awidth;
4130 image->offsets[1] = size;
4131 image->data_size = size + 2 * size2;
4133 case VA_FOURCC_YUY2:
4134 case VA_FOURCC_UYVY:
4135 image->num_planes = 1;
4136 image->pitches[0] = awidth * 2;
4137 image->offsets[0] = 0;
4138 image->data_size = size * 2;
4140 case VA_FOURCC_P010:
4141 image->num_planes = 2;
4142 image->pitches[0] = awidth * 2;
4143 image->offsets[0] = 0;
4144 image->pitches[1] = awidth * 2;
4145 image->offsets[1] = size * 2;
4146 image->data_size = size * 2 + 2 * size2 * 2;
4152 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
4153 image->data_size, 1, NULL, &image->buf);
4154 if (va_status != VA_STATUS_SUCCESS)
4157 struct object_buffer *obj_buffer = BUFFER(image->buf);
4160 !obj_buffer->buffer_store ||
4161 !obj_buffer->buffer_store->bo)
4162 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4164 obj_image->bo = obj_buffer->buffer_store->bo;
4165 dri_bo_reference(obj_image->bo);
4167 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4168 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4169 if (!obj_image->palette)
4173 image->image_id = image_id;
4174 image->format = *format;
4175 image->width = width;
4176 image->height = height;
4178 *out_image = *image;
4179 return VA_STATUS_SUCCESS;
4182 i965_DestroyImage(ctx, image_id);
4187 i965_check_alloc_surface_bo(VADriverContextP ctx,
4188 struct object_surface *obj_surface,
4190 unsigned int fourcc,
4191 unsigned int subsampling)
4193 struct i965_driver_data *i965 = i965_driver_data(ctx);
4194 int region_width, region_height;
4196 if (obj_surface->bo) {
4197 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4198 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4199 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4200 return VA_STATUS_SUCCESS;
4203 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4204 obj_surface->x_cr_offset = 0;
4206 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4208 if ((tiled && !obj_surface->user_disable_tiling)) {
4209 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4210 fourcc != VA_FOURCC_IYUV &&
4211 fourcc != VA_FOURCC_YV12,
4212 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4214 if (obj_surface->user_h_stride_set) {
4215 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4217 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4219 if (obj_surface->user_v_stride_set) {
4220 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4222 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4224 region_height = obj_surface->height;
4227 case VA_FOURCC_NV12:
4228 case VA_FOURCC_P010:
4229 assert(subsampling == SUBSAMPLE_YUV420);
4230 obj_surface->cb_cr_pitch = obj_surface->width;
4231 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4232 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4233 obj_surface->y_cb_offset = obj_surface->height;
4234 obj_surface->y_cr_offset = obj_surface->height;
4235 region_width = obj_surface->width;
4236 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4240 case VA_FOURCC_IMC1:
4241 assert(subsampling == SUBSAMPLE_YUV420);
4242 obj_surface->cb_cr_pitch = obj_surface->width;
4243 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4244 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4245 obj_surface->y_cr_offset = obj_surface->height;
4246 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4247 region_width = obj_surface->width;
4248 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4252 case VA_FOURCC_IMC3:
4253 assert(subsampling == SUBSAMPLE_YUV420);
4254 obj_surface->cb_cr_pitch = obj_surface->width;
4255 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4256 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4257 obj_surface->y_cb_offset = obj_surface->height;
4258 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4259 region_width = obj_surface->width;
4260 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4264 case VA_FOURCC_422H:
4265 assert(subsampling == SUBSAMPLE_YUV422H);
4266 obj_surface->cb_cr_pitch = obj_surface->width;
4267 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4268 obj_surface->cb_cr_height = obj_surface->orig_height;
4269 obj_surface->y_cb_offset = obj_surface->height;
4270 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4271 region_width = obj_surface->width;
4272 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4276 case VA_FOURCC_422V:
4277 assert(subsampling == SUBSAMPLE_YUV422V);
4278 obj_surface->cb_cr_pitch = obj_surface->width;
4279 obj_surface->cb_cr_width = obj_surface->orig_width;
4280 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4281 obj_surface->y_cb_offset = obj_surface->height;
4282 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4283 region_width = obj_surface->width;
4284 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4288 case VA_FOURCC_411P:
4289 assert(subsampling == SUBSAMPLE_YUV411);
4290 obj_surface->cb_cr_pitch = obj_surface->width;
4291 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4292 obj_surface->cb_cr_height = obj_surface->orig_height;
4293 obj_surface->y_cb_offset = obj_surface->height;
4294 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4295 region_width = obj_surface->width;
4296 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4300 case VA_FOURCC_444P:
4301 assert(subsampling == SUBSAMPLE_YUV444);
4302 obj_surface->cb_cr_pitch = obj_surface->width;
4303 obj_surface->cb_cr_width = obj_surface->orig_width;
4304 obj_surface->cb_cr_height = obj_surface->orig_height;
4305 obj_surface->y_cb_offset = obj_surface->height;
4306 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4307 region_width = obj_surface->width;
4308 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4312 case VA_FOURCC_Y800:
4313 assert(subsampling == SUBSAMPLE_YUV400);
4314 obj_surface->cb_cr_pitch = 0;
4315 obj_surface->cb_cr_width = 0;
4316 obj_surface->cb_cr_height = 0;
4317 obj_surface->y_cb_offset = 0;
4318 obj_surface->y_cr_offset = 0;
4319 region_width = obj_surface->width;
4320 region_height = obj_surface->height;
4324 case VA_FOURCC_YUY2:
4325 case VA_FOURCC_UYVY:
4326 assert(subsampling == SUBSAMPLE_YUV422H);
4327 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4328 obj_surface->cb_cr_pitch = obj_surface->width;
4329 obj_surface->y_cb_offset = 0;
4330 obj_surface->y_cr_offset = 0;
4331 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4332 obj_surface->cb_cr_height = obj_surface->orig_height;
4333 region_width = obj_surface->width;
4334 region_height = obj_surface->height;
4338 case VA_FOURCC_RGBA:
4339 case VA_FOURCC_RGBX:
4340 case VA_FOURCC_BGRA:
4341 case VA_FOURCC_BGRX:
4342 assert(subsampling == SUBSAMPLE_RGBX);
4344 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4345 region_width = obj_surface->width;
4346 region_height = obj_surface->height;
4350 /* Never get here */
4351 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4355 assert(subsampling == SUBSAMPLE_YUV420 ||
4356 subsampling == SUBSAMPLE_YUV422H ||
4357 subsampling == SUBSAMPLE_YUV422V ||
4358 subsampling == SUBSAMPLE_RGBX);
4360 region_width = obj_surface->width;
4361 region_height = obj_surface->height;
4364 case VA_FOURCC_NV12:
4365 case VA_FOURCC_P010:
4366 obj_surface->y_cb_offset = obj_surface->height;
4367 obj_surface->y_cr_offset = obj_surface->height;
4368 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4369 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) *
4371 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4372 obj_surface->cb_cr_pitch = obj_surface->width;
4373 region_width = obj_surface->width;
4374 region_height = obj_surface->height + obj_surface->height / 2;
4377 case VA_FOURCC_YV16:
4378 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4379 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4380 obj_surface->cb_cr_height = obj_surface->orig_height;
4381 obj_surface->y_cr_offset = obj_surface->height;
4382 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4383 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4384 region_width = obj_surface->width;
4385 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4388 case VA_FOURCC_YV12:
4389 case VA_FOURCC_I420:
4390 case VA_FOURCC_IYUV:
4391 if (fourcc == VA_FOURCC_YV12) {
4392 obj_surface->y_cr_offset = obj_surface->height;
4393 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4395 obj_surface->y_cb_offset = obj_surface->height;
4396 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4399 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4400 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4401 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4402 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4403 region_width = obj_surface->width;
4404 region_height = obj_surface->height + obj_surface->height / 2;
4407 case VA_FOURCC_I010:
4408 obj_surface->y_cb_offset = obj_surface->height;
4409 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4410 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4411 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
4412 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4413 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4414 region_width = obj_surface->width;
4415 region_height = obj_surface->height + obj_surface->height / 2;
4418 case VA_FOURCC_YUY2:
4419 case VA_FOURCC_UYVY:
4420 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4421 obj_surface->y_cb_offset = 0;
4422 obj_surface->y_cr_offset = 0;
4423 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4424 obj_surface->cb_cr_height = obj_surface->orig_height;
4425 obj_surface->cb_cr_pitch = obj_surface->width;
4426 region_width = obj_surface->width;
4427 region_height = obj_surface->height;
4429 case VA_FOURCC_RGBA:
4430 case VA_FOURCC_RGBX:
4431 case VA_FOURCC_BGRA:
4432 case VA_FOURCC_BGRX:
4433 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4434 region_width = obj_surface->width;
4435 region_height = obj_surface->height;
4439 /* Never get here */
4440 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4445 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4447 if ((tiled && !obj_surface->user_disable_tiling)) {
4448 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4449 unsigned long pitch;
4451 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4459 assert(tiling_mode == I915_TILING_Y);
4460 assert(pitch == obj_surface->width);
4462 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4468 obj_surface->fourcc = fourcc;
4469 obj_surface->subsampling = subsampling;
4470 assert(obj_surface->bo);
4471 return VA_STATUS_SUCCESS;
4474 VAStatus i965_DeriveImage(VADriverContextP ctx,
4475 VASurfaceID surface,
4476 VAImage *out_image) /* out */
4478 struct i965_driver_data *i965 = i965_driver_data(ctx);
4479 struct object_image *obj_image;
4480 struct object_surface *obj_surface;
4482 unsigned int w_pitch;
4483 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4485 out_image->image_id = VA_INVALID_ID;
4486 obj_surface = SURFACE(surface);
4489 return VA_STATUS_ERROR_INVALID_SURFACE;
4491 if (!obj_surface->bo) {
4492 unsigned int is_tiled = 0;
4493 unsigned int fourcc = VA_FOURCC_YV12;
4494 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4495 int sampling = get_sampling_from_fourcc(fourcc);
4496 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4497 if (va_status != VA_STATUS_SUCCESS)
4501 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4503 w_pitch = obj_surface->width;
4505 image_id = NEW_IMAGE_ID();
4507 if (image_id == VA_INVALID_ID)
4508 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4510 obj_image = IMAGE(image_id);
4513 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4515 obj_image->bo = NULL;
4516 obj_image->palette = NULL;
4517 obj_image->derived_surface = VA_INVALID_ID;
4519 VAImage * const image = &obj_image->image;
4521 memset(image, 0, sizeof(*image));
4522 image->image_id = image_id;
4523 image->buf = VA_INVALID_ID;
4524 image->num_palette_entries = 0;
4525 image->entry_bytes = 0;
4526 image->width = obj_surface->orig_width;
4527 image->height = obj_surface->orig_height;
4528 image->data_size = obj_surface->size;
4530 image->format.fourcc = obj_surface->fourcc;
4531 image->format.byte_order = VA_LSB_FIRST;
4532 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4534 if (!image->format.bits_per_pixel)
4537 switch (image->format.fourcc) {
4538 case VA_FOURCC_YV12:
4539 image->num_planes = 3;
4540 image->pitches[0] = w_pitch; /* Y */
4541 image->offsets[0] = 0;
4542 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4543 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4544 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4545 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4548 case VA_FOURCC_YV16:
4549 image->num_planes = 3;
4550 image->pitches[0] = w_pitch; /* Y */
4551 image->offsets[0] = 0;
4552 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4553 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4554 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4555 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4558 case VA_FOURCC_NV12:
4559 case VA_FOURCC_P010:
4560 image->num_planes = 2;
4561 image->pitches[0] = w_pitch; /* Y */
4562 image->offsets[0] = 0;
4563 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4564 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4567 case VA_FOURCC_I420:
4568 case VA_FOURCC_I010:
4569 case VA_FOURCC_422H:
4570 case VA_FOURCC_IMC3:
4571 case VA_FOURCC_444P:
4572 case VA_FOURCC_422V:
4573 case VA_FOURCC_411P:
4574 image->num_planes = 3;
4575 image->pitches[0] = w_pitch; /* Y */
4576 image->offsets[0] = 0;
4577 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4578 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4579 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4580 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4583 case VA_FOURCC_YUY2:
4584 case VA_FOURCC_UYVY:
4585 case VA_FOURCC_Y800:
4586 image->num_planes = 1;
4587 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4588 image->offsets[0] = 0;
4590 case VA_FOURCC_RGBA:
4591 case VA_FOURCC_RGBX:
4592 case VA_FOURCC_BGRA:
4593 case VA_FOURCC_BGRX:
4594 image->num_planes = 1;
4595 image->pitches[0] = obj_surface->width;
4597 switch (image->format.fourcc) {
4598 case VA_FOURCC_RGBA:
4599 case VA_FOURCC_RGBX:
4600 image->format.red_mask = 0x000000ff;
4601 image->format.green_mask = 0x0000ff00;
4602 image->format.blue_mask = 0x00ff0000;
4604 case VA_FOURCC_BGRA:
4605 case VA_FOURCC_BGRX:
4606 image->format.red_mask = 0x00ff0000;
4607 image->format.green_mask = 0x0000ff00;
4608 image->format.blue_mask = 0x000000ff;
4614 switch (image->format.fourcc) {
4615 case VA_FOURCC_RGBA:
4616 case VA_FOURCC_BGRA:
4617 image->format.alpha_mask = 0xff000000;
4618 image->format.depth = 32;
4620 case VA_FOURCC_RGBX:
4621 case VA_FOURCC_BGRX:
4622 image->format.alpha_mask = 0x00000000;
4623 image->format.depth = 24;
4634 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4635 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4636 if (va_status != VA_STATUS_SUCCESS)
4639 struct object_buffer *obj_buffer = BUFFER(image->buf);
4642 !obj_buffer->buffer_store ||
4643 !obj_buffer->buffer_store->bo)
4644 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4646 obj_image->bo = obj_buffer->buffer_store->bo;
4647 dri_bo_reference(obj_image->bo);
4649 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4650 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4651 if (!obj_image->palette) {
4652 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4657 *out_image = *image;
4658 obj_surface->flags |= SURFACE_DERIVED;
4659 obj_surface->derived_image_id = image_id;
4660 obj_image->derived_surface = surface;
4662 return VA_STATUS_SUCCESS;
4665 i965_DestroyImage(ctx, image_id);
4670 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4672 object_heap_free(heap, obj);
4677 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4679 struct i965_driver_data *i965 = i965_driver_data(ctx);
4680 struct object_image *obj_image = IMAGE(image);
4681 struct object_surface *obj_surface;
4684 return VA_STATUS_SUCCESS;
4686 dri_bo_unreference(obj_image->bo);
4687 obj_image->bo = NULL;
4689 if (obj_image->image.buf != VA_INVALID_ID) {
4690 i965_DestroyBuffer(ctx, obj_image->image.buf);
4691 obj_image->image.buf = VA_INVALID_ID;
4694 if (obj_image->palette) {
4695 free(obj_image->palette);
4696 obj_image->palette = NULL;
4699 obj_surface = SURFACE(obj_image->derived_surface);
4702 obj_surface->flags &= ~SURFACE_DERIVED;
4703 obj_surface->derived_image_id = VA_INVALID_ID;
4706 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4708 return VA_STATUS_SUCCESS;
4712 * pointer to an array holding the palette data. The size of the array is
4713 * num_palette_entries * entry_bytes in size. The order of the components
4714 * in the palette is described by the component_order in VASubpicture struct
4717 i965_SetImagePalette(VADriverContextP ctx,
4719 unsigned char *palette)
4721 struct i965_driver_data *i965 = i965_driver_data(ctx);
4724 struct object_image *obj_image = IMAGE(image);
4726 return VA_STATUS_ERROR_INVALID_IMAGE;
4728 if (!obj_image->palette)
4729 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4731 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4732 obj_image->palette[i] = (((unsigned int)palette[3 * i + 0] << 16) |
4733 ((unsigned int)palette[3 * i + 1] << 8) |
4734 (unsigned int)palette[3 * i + 2]);
4735 return VA_STATUS_SUCCESS;
4739 get_sampling_from_fourcc(unsigned int fourcc)
4741 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4743 if (info && (info->flag & I_S))
4744 return info->subsampling;
4750 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4751 const uint8_t *src, unsigned int src_stride,
4752 unsigned int len, unsigned int height)
4756 for (i = 0; i < height; i++) {
4757 memcpy(dst, src, len);
4764 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4765 struct object_surface *obj_surface,
4766 const VARectangle *rect)
4768 uint8_t *dst[3], *src[3];
4770 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4771 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4772 unsigned int tiling, swizzle;
4773 VAStatus va_status = VA_STATUS_SUCCESS;
4775 if (!obj_surface->bo)
4776 return VA_STATUS_ERROR_INVALID_SURFACE;
4778 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4779 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4781 if (tiling != I915_TILING_NONE)
4782 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4784 dri_bo_map(obj_surface->bo, 0);
4786 if (!obj_surface->bo->virtual)
4787 return VA_STATUS_ERROR_INVALID_SURFACE;
4789 /* Dest VA image has either I420 or YV12 format.
4790 Source VA surface alway has I420 format */
4791 dst[Y] = image_data + obj_image->image.offsets[Y];
4792 src[0] = (uint8_t *)obj_surface->bo->virtual;
4793 dst[U] = image_data + obj_image->image.offsets[U];
4794 src[1] = src[0] + obj_surface->width * obj_surface->height;
4795 dst[V] = image_data + obj_image->image.offsets[V];
4796 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4799 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4800 src[0] += rect->y * obj_surface->width + rect->x;
4801 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4802 src[0], obj_surface->width,
4803 rect->width, rect->height);
4806 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4807 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4808 memcpy_pic(dst[U], obj_image->image.pitches[U],
4809 src[1], obj_surface->width / 2,
4810 rect->width / 2, rect->height / 2);
4813 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4814 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4815 memcpy_pic(dst[V], obj_image->image.pitches[V],
4816 src[2], obj_surface->width / 2,
4817 rect->width / 2, rect->height / 2);
4819 if (tiling != I915_TILING_NONE)
4820 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4822 dri_bo_unmap(obj_surface->bo);
4828 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4829 struct object_surface *obj_surface,
4830 const VARectangle *rect)
4832 uint8_t *dst[2], *src[2];
4833 unsigned int tiling, swizzle;
4834 VAStatus va_status = VA_STATUS_SUCCESS;
4836 if (!obj_surface->bo)
4837 return VA_STATUS_ERROR_INVALID_SURFACE;
4839 assert(obj_surface->fourcc);
4840 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4842 if (tiling != I915_TILING_NONE)
4843 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4845 dri_bo_map(obj_surface->bo, 0);
4847 if (!obj_surface->bo->virtual)
4848 return VA_STATUS_ERROR_INVALID_SURFACE;
4850 /* Both dest VA image and source surface have NV12 format */
4851 dst[0] = image_data + obj_image->image.offsets[0];
4852 src[0] = (uint8_t *)obj_surface->bo->virtual;
4853 dst[1] = image_data + obj_image->image.offsets[1];
4854 src[1] = src[0] + obj_surface->width * obj_surface->height;
4857 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4858 src[0] += rect->y * obj_surface->width + rect->x;
4859 memcpy_pic(dst[0], obj_image->image.pitches[0],
4860 src[0], obj_surface->width,
4861 rect->width, rect->height);
4864 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4865 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4866 memcpy_pic(dst[1], obj_image->image.pitches[1],
4867 src[1], obj_surface->width,
4868 rect->width, rect->height / 2);
4870 if (tiling != I915_TILING_NONE)
4871 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4873 dri_bo_unmap(obj_surface->bo);
4879 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4880 struct object_surface *obj_surface,
4881 const VARectangle *rect)
4884 unsigned int tiling, swizzle;
4885 VAStatus va_status = VA_STATUS_SUCCESS;
4887 if (!obj_surface->bo)
4888 return VA_STATUS_ERROR_INVALID_SURFACE;
4890 assert(obj_surface->fourcc);
4891 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4893 if (tiling != I915_TILING_NONE)
4894 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4896 dri_bo_map(obj_surface->bo, 0);
4898 if (!obj_surface->bo->virtual)
4899 return VA_STATUS_ERROR_INVALID_SURFACE;
4901 /* Both dest VA image and source surface have YUYV format */
4902 dst = image_data + obj_image->image.offsets[0];
4903 src = (uint8_t *)obj_surface->bo->virtual;
4906 dst += rect->y * obj_image->image.pitches[0] + rect->x * 2;
4907 src += rect->y * obj_surface->width + rect->x * 2;
4908 memcpy_pic(dst, obj_image->image.pitches[0],
4909 src, obj_surface->width * 2,
4910 rect->width * 2, rect->height);
4912 if (tiling != I915_TILING_NONE)
4913 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4915 dri_bo_unmap(obj_surface->bo);
4921 i965_sw_getimage(VADriverContextP ctx,
4922 struct object_surface *obj_surface, struct object_image *obj_image,
4923 const VARectangle *rect)
4925 void *image_data = NULL;
4928 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4929 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4931 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4932 if (va_status != VA_STATUS_SUCCESS)
4935 switch (obj_image->image.format.fourcc) {
4936 case VA_FOURCC_YV12:
4937 case VA_FOURCC_I420:
4938 get_image_i420(obj_image, image_data, obj_surface, rect);
4940 case VA_FOURCC_NV12:
4941 get_image_nv12(obj_image, image_data, obj_surface, rect);
4943 case VA_FOURCC_YUY2:
4944 /* YUY2 is the format supported by overlay plane */
4945 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4948 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4951 if (va_status != VA_STATUS_SUCCESS)
4954 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4959 i965_hw_getimage(VADriverContextP ctx,
4960 struct object_surface *obj_surface, struct object_image *obj_image,
4961 const VARectangle *rect)
4963 struct i965_surface src_surface;
4964 struct i965_surface dst_surface;
4966 src_surface.base = (struct object_base *)obj_surface;
4967 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4968 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4970 dst_surface.base = (struct object_base *)obj_image;
4971 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4972 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4974 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4978 i965_GetImage(VADriverContextP ctx,
4979 VASurfaceID surface,
4980 int x, /* coordinates of the upper left source pixel */
4982 unsigned int width, /* width and height of the region */
4983 unsigned int height,
4986 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4987 struct object_surface * const obj_surface = SURFACE(surface);
4988 struct object_image * const obj_image = IMAGE(image);
4993 return VA_STATUS_ERROR_INVALID_SURFACE;
4994 if (!obj_surface->bo) /* don't get anything, keep previous data */
4995 return VA_STATUS_SUCCESS;
4996 if (is_surface_busy(i965, obj_surface))
4997 return VA_STATUS_ERROR_SURFACE_BUSY;
4999 if (!obj_image || !obj_image->bo)
5000 return VA_STATUS_ERROR_INVALID_IMAGE;
5001 if (is_image_busy(i965, obj_image, surface))
5002 return VA_STATUS_ERROR_SURFACE_BUSY;
5005 return VA_STATUS_ERROR_INVALID_PARAMETER;
5006 if (x + width > obj_surface->orig_width ||
5007 y + height > obj_surface->orig_height)
5008 return VA_STATUS_ERROR_INVALID_PARAMETER;
5009 if (x + width > obj_image->image.width ||
5010 y + height > obj_image->image.height)
5011 return VA_STATUS_ERROR_INVALID_PARAMETER;
5016 rect.height = height;
5018 if (HAS_ACCELERATED_GETIMAGE(i965))
5019 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
5021 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
5027 put_image_i420(struct object_surface *obj_surface,
5028 const VARectangle *dst_rect,
5029 struct object_image *obj_image, uint8_t *image_data,
5030 const VARectangle *src_rect)
5032 uint8_t *dst[3], *src[3];
5034 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
5035 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
5036 unsigned int tiling, swizzle;
5037 VAStatus va_status = VA_STATUS_SUCCESS;
5039 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5041 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5042 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5043 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5044 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5046 if (tiling != I915_TILING_NONE)
5047 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5049 dri_bo_map(obj_surface->bo, 0);
5051 if (!obj_surface->bo->virtual)
5052 return VA_STATUS_ERROR_INVALID_SURFACE;
5054 /* Dest VA image has either I420 or YV12 format.
5055 Source VA surface alway has I420 format */
5056 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5057 src[Y] = image_data + obj_image->image.offsets[Y];
5058 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5059 src[U] = image_data + obj_image->image.offsets[U];
5060 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
5061 src[V] = image_data + obj_image->image.offsets[V];
5064 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5065 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
5066 memcpy_pic(dst[0], obj_surface->width,
5067 src[Y], obj_image->image.pitches[Y],
5068 src_rect->width, src_rect->height);
5071 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5072 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
5073 memcpy_pic(dst[1], obj_surface->width / 2,
5074 src[U], obj_image->image.pitches[U],
5075 src_rect->width / 2, src_rect->height / 2);
5078 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5079 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
5080 memcpy_pic(dst[2], obj_surface->width / 2,
5081 src[V], obj_image->image.pitches[V],
5082 src_rect->width / 2, src_rect->height / 2);
5084 if (tiling != I915_TILING_NONE)
5085 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5087 dri_bo_unmap(obj_surface->bo);
5093 put_image_nv12(struct object_surface *obj_surface,
5094 const VARectangle *dst_rect,
5095 struct object_image *obj_image, uint8_t *image_data,
5096 const VARectangle *src_rect)
5098 uint8_t *dst[2], *src[2];
5099 unsigned int tiling, swizzle;
5100 VAStatus va_status = VA_STATUS_SUCCESS;
5102 if (!obj_surface->bo)
5103 return VA_STATUS_ERROR_INVALID_SURFACE;
5105 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5106 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5107 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5108 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5110 if (tiling != I915_TILING_NONE)
5111 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5113 dri_bo_map(obj_surface->bo, 0);
5115 if (!obj_surface->bo->virtual)
5116 return VA_STATUS_ERROR_INVALID_SURFACE;
5118 /* Both dest VA image and source surface have NV12 format */
5119 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5120 src[0] = image_data + obj_image->image.offsets[0];
5121 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5122 src[1] = image_data + obj_image->image.offsets[1];
5125 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5126 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
5127 memcpy_pic(dst[0], obj_surface->width,
5128 src[0], obj_image->image.pitches[0],
5129 src_rect->width, src_rect->height);
5132 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
5133 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
5134 memcpy_pic(dst[1], obj_surface->width,
5135 src[1], obj_image->image.pitches[1],
5136 src_rect->width, src_rect->height / 2);
5138 if (tiling != I915_TILING_NONE)
5139 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5141 dri_bo_unmap(obj_surface->bo);
5147 put_image_yuy2(struct object_surface *obj_surface,
5148 const VARectangle *dst_rect,
5149 struct object_image *obj_image, uint8_t *image_data,
5150 const VARectangle *src_rect)
5153 unsigned int tiling, swizzle;
5154 VAStatus va_status = VA_STATUS_SUCCESS;
5156 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5157 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5158 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5159 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5160 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5162 if (tiling != I915_TILING_NONE)
5163 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5165 dri_bo_map(obj_surface->bo, 0);
5167 if (!obj_surface->bo->virtual)
5168 return VA_STATUS_ERROR_INVALID_SURFACE;
5170 /* Both dest VA image and source surface have YUY2 format */
5171 dst = (uint8_t *)obj_surface->bo->virtual;
5172 src = image_data + obj_image->image.offsets[0];
5174 /* YUYV packed plane */
5175 dst += dst_rect->y * obj_surface->width + dst_rect->x * 2;
5176 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x * 2;
5177 memcpy_pic(dst, obj_surface->width * 2,
5178 src, obj_image->image.pitches[0],
5179 src_rect->width * 2, src_rect->height);
5181 if (tiling != I915_TILING_NONE)
5182 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5184 dri_bo_unmap(obj_surface->bo);
5190 i965_sw_putimage(VADriverContextP ctx,
5191 struct object_surface *obj_surface, struct object_image *obj_image,
5192 const VARectangle *src_rect, const VARectangle *dst_rect)
5194 VAStatus va_status = VA_STATUS_SUCCESS;
5195 void *image_data = NULL;
5197 /* XXX: don't allow scaling */
5198 if (src_rect->width != dst_rect->width ||
5199 src_rect->height != dst_rect->height)
5200 return VA_STATUS_ERROR_INVALID_PARAMETER;
5202 if (obj_surface->fourcc) {
5203 /* Don't allow format mismatch */
5204 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5205 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5209 /* VA is surface not used for decoding, use same VA image format */
5210 va_status = i965_check_alloc_surface_bo(
5213 0, /* XXX: don't use tiled surface */
5214 obj_image->image.format.fourcc,
5215 get_sampling_from_fourcc(obj_image->image.format.fourcc));
5218 if (va_status != VA_STATUS_SUCCESS)
5221 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5222 if (va_status != VA_STATUS_SUCCESS)
5225 switch (obj_image->image.format.fourcc) {
5226 case VA_FOURCC_YV12:
5227 case VA_FOURCC_I420:
5228 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5230 case VA_FOURCC_NV12:
5231 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5233 case VA_FOURCC_YUY2:
5234 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5237 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5240 if (va_status != VA_STATUS_SUCCESS)
5243 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5248 i965_hw_putimage(VADriverContextP ctx,
5249 struct object_surface *obj_surface, struct object_image *obj_image,
5250 const VARectangle *src_rect, const VARectangle *dst_rect)
5252 struct i965_surface src_surface, dst_surface;
5253 VAStatus va_status = VA_STATUS_SUCCESS;
5255 if (!obj_surface->bo) {
5256 unsigned int tiling, swizzle;
5257 int surface_sampling = get_sampling_from_fourcc(obj_image->image.format.fourcc);;
5258 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5260 i965_check_alloc_surface_bo(ctx,
5263 obj_image->image.format.fourcc,
5267 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5269 src_surface.base = (struct object_base *)obj_image;
5270 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5271 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5273 dst_surface.base = (struct object_base *)obj_surface;
5274 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5275 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5277 va_status = i965_image_processing(ctx,
5287 i965_PutImage(VADriverContextP ctx,
5288 VASurfaceID surface,
5292 unsigned int src_width,
5293 unsigned int src_height,
5296 unsigned int dest_width,
5297 unsigned int dest_height)
5299 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5300 struct object_surface * const obj_surface = SURFACE(surface);
5301 struct object_image * const obj_image = IMAGE(image);
5302 VARectangle src_rect, dst_rect;
5306 return VA_STATUS_ERROR_INVALID_SURFACE;
5307 if (is_surface_busy(i965, obj_surface))
5308 return VA_STATUS_ERROR_SURFACE_BUSY;
5310 if (!obj_image || !obj_image->bo)
5311 return VA_STATUS_ERROR_INVALID_IMAGE;
5312 if (is_image_busy(i965, obj_image, surface))
5313 return VA_STATUS_ERROR_SURFACE_BUSY;
5317 src_x + src_width > obj_image->image.width ||
5318 src_y + src_height > obj_image->image.height)
5319 return VA_STATUS_ERROR_INVALID_PARAMETER;
5323 src_rect.width = src_width;
5324 src_rect.height = src_height;
5328 dest_x + dest_width > obj_surface->orig_width ||
5329 dest_y + dest_height > obj_surface->orig_height)
5330 return VA_STATUS_ERROR_INVALID_PARAMETER;
5332 dst_rect.x = dest_x;
5333 dst_rect.y = dest_y;
5334 dst_rect.width = dest_width;
5335 dst_rect.height = dest_height;
5337 if (HAS_ACCELERATED_PUTIMAGE(i965))
5338 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5339 &src_rect, &dst_rect);
5341 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5342 &src_rect, &dst_rect);
5348 i965_PutSurface(VADriverContextP ctx,
5349 VASurfaceID surface,
5350 void *draw, /* X Drawable */
5353 unsigned short srcw,
5354 unsigned short srch,
5357 unsigned short destw,
5358 unsigned short desth,
5359 VARectangle *cliprects, /* client supplied clip list */
5360 unsigned int number_cliprects, /* number of clip rects in the clip list */
5361 unsigned int flags) /* de-interlacing flags */
5364 if (IS_VA_X11(ctx)) {
5365 VARectangle src_rect, dst_rect;
5369 src_rect.width = srcw;
5370 src_rect.height = srch;
5374 dst_rect.width = destw;
5375 dst_rect.height = desth;
5377 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5378 cliprects, number_cliprects, flags);
5381 return VA_STATUS_ERROR_UNIMPLEMENTED;
5386 VADriverContextP ctx, /* in */
5387 VABufferID buf_id, /* in */
5388 VABufferType *type, /* out */
5389 unsigned int *size, /* out */
5390 unsigned int *num_elements /* out */
5393 struct i965_driver_data *i965 = NULL;
5394 struct object_buffer *obj_buffer = NULL;
5396 i965 = i965_driver_data(ctx);
5397 obj_buffer = BUFFER(buf_id);
5399 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5401 *type = obj_buffer->type;
5402 *size = obj_buffer->size_element;
5403 *num_elements = obj_buffer->num_elements;
5405 return VA_STATUS_SUCCESS;
5410 VADriverContextP ctx, /* in */
5411 VASurfaceID surface, /* in */
5412 unsigned int *fourcc, /* out */
5413 unsigned int *luma_stride, /* out */
5414 unsigned int *chroma_u_stride, /* out */
5415 unsigned int *chroma_v_stride, /* out */
5416 unsigned int *luma_offset, /* out */
5417 unsigned int *chroma_u_offset, /* out */
5418 unsigned int *chroma_v_offset, /* out */
5419 unsigned int *buffer_name, /* out */
5420 void **buffer /* out */
5423 VAStatus vaStatus = VA_STATUS_SUCCESS;
5424 struct i965_driver_data *i965 = i965_driver_data(ctx);
5425 struct object_surface *obj_surface = NULL;
5428 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5429 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5430 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5431 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5432 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5433 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5434 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5435 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5436 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5438 tmpImage.image_id = VA_INVALID_ID;
5440 obj_surface = SURFACE(surface);
5441 if (obj_surface == NULL) {
5442 // Surface is absent.
5443 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5447 // Lock functionality is absent now.
5448 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5449 // Surface is locked already.
5450 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5454 vaStatus = i965_DeriveImage(
5458 if (vaStatus != VA_STATUS_SUCCESS) {
5462 obj_surface->locked_image_id = tmpImage.image_id;
5464 vaStatus = i965_MapBuffer(
5468 if (vaStatus != VA_STATUS_SUCCESS) {
5472 *fourcc = tmpImage.format.fourcc;
5473 *luma_offset = tmpImage.offsets[0];
5474 *luma_stride = tmpImage.pitches[0];
5475 *chroma_u_offset = tmpImage.offsets[1];
5476 *chroma_u_stride = tmpImage.pitches[1];
5477 *chroma_v_offset = tmpImage.offsets[2];
5478 *chroma_v_stride = tmpImage.pitches[2];
5479 *buffer_name = tmpImage.buf;
5482 if (vaStatus != VA_STATUS_SUCCESS) {
5491 VADriverContextP ctx, /* in */
5492 VASurfaceID surface /* in */
5495 VAStatus vaStatus = VA_STATUS_SUCCESS;
5496 struct i965_driver_data *i965 = i965_driver_data(ctx);
5497 struct object_image *locked_img = NULL;
5498 struct object_surface *obj_surface = NULL;
5500 obj_surface = SURFACE(surface);
5502 if (obj_surface == NULL) {
5503 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5506 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5507 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5511 locked_img = IMAGE(obj_surface->locked_image_id);
5512 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5513 // Work image was deallocated before i965_UnlockSurface()
5514 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5518 vaStatus = i965_UnmapBuffer(
5520 locked_img->image.buf);
5521 if (vaStatus != VA_STATUS_SUCCESS) {
5525 vaStatus = i965_DestroyImage(
5527 locked_img->image.image_id);
5528 if (vaStatus != VA_STATUS_SUCCESS) {
5532 locked_img->image.image_id = VA_INVALID_ID;
5535 obj_surface->locked_image_id = VA_INVALID_ID;
5541 i965_GetSurfaceAttributes(
5542 VADriverContextP ctx,
5544 VASurfaceAttrib *attrib_list,
5545 unsigned int num_attribs
5548 VAStatus vaStatus = VA_STATUS_SUCCESS;
5549 struct i965_driver_data *i965 = i965_driver_data(ctx);
5550 struct object_config *obj_config;
5553 if (config == VA_INVALID_ID)
5554 return VA_STATUS_ERROR_INVALID_CONFIG;
5556 obj_config = CONFIG(config);
5558 if (obj_config == NULL)
5559 return VA_STATUS_ERROR_INVALID_CONFIG;
5561 if (attrib_list == NULL || num_attribs == 0)
5562 return VA_STATUS_ERROR_INVALID_PARAMETER;
5564 for (i = 0; i < num_attribs; i++) {
5565 switch (attrib_list[i].type) {
5566 case VASurfaceAttribPixelFormat:
5567 attrib_list[i].value.type = VAGenericValueTypeInteger;
5568 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5570 if (attrib_list[i].value.value.i == 0) {
5571 if (IS_G4X(i965->intel.device_info)) {
5572 if (obj_config->profile == VAProfileMPEG2Simple ||
5573 obj_config->profile == VAProfileMPEG2Main) {
5574 attrib_list[i].value.value.i = VA_FOURCC_I420;
5577 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5579 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5580 if (obj_config->profile == VAProfileMPEG2Simple ||
5581 obj_config->profile == VAProfileMPEG2Main) {
5582 attrib_list[i].value.value.i = VA_FOURCC_I420;
5583 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5584 obj_config->profile == VAProfileH264Main ||
5585 obj_config->profile == VAProfileH264High) {
5586 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5587 } else if (obj_config->profile == VAProfileNone) {
5588 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5591 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5593 } else if (IS_GEN6(i965->intel.device_info)) {
5594 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5595 } else if (IS_GEN7(i965->intel.device_info) ||
5596 IS_GEN8(i965->intel.device_info) ||
5597 IS_GEN9(i965->intel.device_info)) {
5598 if (obj_config->profile == VAProfileJPEGBaseline)
5599 attrib_list[i].value.value.i = 0; /* internal format */
5601 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5604 if (IS_G4X(i965->intel.device_info)) {
5605 if (obj_config->profile == VAProfileMPEG2Simple ||
5606 obj_config->profile == VAProfileMPEG2Main) {
5607 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5608 attrib_list[i].value.value.i = 0;
5609 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5613 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5615 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5616 if (obj_config->profile == VAProfileMPEG2Simple ||
5617 obj_config->profile == VAProfileMPEG2Main) {
5618 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5619 attrib_list[i].value.value.i = 0;
5620 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5622 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5623 obj_config->profile == VAProfileH264Main ||
5624 obj_config->profile == VAProfileH264High) {
5625 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5626 attrib_list[i].value.value.i = 0;
5627 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5629 } else if (obj_config->profile == VAProfileNone) {
5630 switch (attrib_list[i].value.value.i) {
5631 case VA_FOURCC_NV12:
5632 case VA_FOURCC_I420:
5633 case VA_FOURCC_YV12:
5634 case VA_FOURCC_YUY2:
5635 case VA_FOURCC_BGRA:
5636 case VA_FOURCC_BGRX:
5637 case VA_FOURCC_RGBX:
5638 case VA_FOURCC_RGBA:
5641 attrib_list[i].value.value.i = 0;
5642 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5647 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5649 } else if (IS_GEN6(i965->intel.device_info)) {
5650 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5651 obj_config->entrypoint == VAEntrypointVideoProc) {
5652 switch (attrib_list[i].value.value.i) {
5653 case VA_FOURCC_NV12:
5654 case VA_FOURCC_I420:
5655 case VA_FOURCC_YV12:
5656 case VA_FOURCC_YUY2:
5657 case VA_FOURCC_BGRA:
5658 case VA_FOURCC_BGRX:
5659 case VA_FOURCC_RGBX:
5660 case VA_FOURCC_RGBA:
5663 attrib_list[i].value.value.i = 0;
5664 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5668 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5669 attrib_list[i].value.value.i = 0;
5670 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5673 } else if (IS_GEN7(i965->intel.device_info) ||
5674 IS_GEN8(i965->intel.device_info) ||
5675 IS_GEN9(i965->intel.device_info)) {
5676 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5677 obj_config->entrypoint == VAEntrypointVideoProc ||
5678 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5679 switch (attrib_list[i].value.value.i) {
5680 case VA_FOURCC_NV12:
5681 case VA_FOURCC_I420:
5682 case VA_FOURCC_YV12:
5685 attrib_list[i].value.value.i = 0;
5686 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5690 if (obj_config->profile == VAProfileJPEGBaseline) {
5691 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5692 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5694 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5695 attrib_list[i].value.value.i = 0;
5696 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5704 case VASurfaceAttribMinWidth:
5705 /* FIXME: add support for it later */
5706 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5708 case VASurfaceAttribMaxWidth:
5709 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5711 case VASurfaceAttribMinHeight:
5712 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5714 case VASurfaceAttribMaxHeight:
5715 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5718 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5727 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5729 VASurfaceAttrib *attrib_list,
5730 unsigned int *num_attribs)
5732 VAStatus vaStatus = VA_STATUS_SUCCESS;
5733 struct i965_driver_data *i965 = i965_driver_data(ctx);
5734 struct object_config *obj_config;
5736 VASurfaceAttrib *attribs = NULL;
5740 if (config == VA_INVALID_ID)
5741 return VA_STATUS_ERROR_INVALID_CONFIG;
5743 obj_config = CONFIG(config);
5745 if (obj_config == NULL)
5746 return VA_STATUS_ERROR_INVALID_CONFIG;
5748 if (!attrib_list && !num_attribs)
5749 return VA_STATUS_ERROR_INVALID_PARAMETER;
5751 if (attrib_list == NULL) {
5752 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5753 return VA_STATUS_SUCCESS;
5756 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES * sizeof(*attribs));
5758 if (attribs == NULL)
5759 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5761 if (IS_G4X(i965->intel.device_info)) {
5762 if (obj_config->profile == VAProfileMPEG2Simple ||
5763 obj_config->profile == VAProfileMPEG2Main) {
5764 attribs[i].type = VASurfaceAttribPixelFormat;
5765 attribs[i].value.type = VAGenericValueTypeInteger;
5766 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5767 attribs[i].value.value.i = VA_FOURCC_I420;
5770 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5771 switch (obj_config->profile) {
5772 case VAProfileMPEG2Simple:
5773 case VAProfileMPEG2Main:
5774 attribs[i].type = VASurfaceAttribPixelFormat;
5775 attribs[i].value.type = VAGenericValueTypeInteger;
5776 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5777 attribs[i].value.value.i = VA_FOURCC_I420;
5782 case VAProfileH264ConstrainedBaseline:
5783 case VAProfileH264Main:
5784 case VAProfileH264High:
5785 attribs[i].type = VASurfaceAttribPixelFormat;
5786 attribs[i].value.type = VAGenericValueTypeInteger;
5787 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5788 attribs[i].value.value.i = VA_FOURCC_NV12;
5792 attribs[i].type = VASurfaceAttribPixelFormat;
5793 attribs[i].value.type = VAGenericValueTypeInteger;
5794 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5795 attribs[i].value.value.i = VA_FOURCC_NV12;
5798 attribs[i].type = VASurfaceAttribPixelFormat;
5799 attribs[i].value.type = VAGenericValueTypeInteger;
5800 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5801 attribs[i].value.value.i = VA_FOURCC_I420;
5809 } else if (IS_GEN6(i965->intel.device_info)) {
5810 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5811 attribs[i].type = VASurfaceAttribPixelFormat;
5812 attribs[i].value.type = VAGenericValueTypeInteger;
5813 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5814 attribs[i].value.value.i = VA_FOURCC_NV12;
5816 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5817 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5818 attribs[i].type = VASurfaceAttribPixelFormat;
5819 attribs[i].value.type = VAGenericValueTypeInteger;
5820 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5821 attribs[i].value.value.i = VA_FOURCC_NV12;
5824 attribs[i].type = VASurfaceAttribPixelFormat;
5825 attribs[i].value.type = VAGenericValueTypeInteger;
5826 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5827 attribs[i].value.value.i = VA_FOURCC_I420;
5830 attribs[i].type = VASurfaceAttribPixelFormat;
5831 attribs[i].value.type = VAGenericValueTypeInteger;
5832 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5833 attribs[i].value.value.i = VA_FOURCC_YV12;
5836 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5837 attribs[i].type = VASurfaceAttribPixelFormat;
5838 attribs[i].value.type = VAGenericValueTypeInteger;
5839 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5840 attribs[i].value.value.i = VA_FOURCC_YUY2;
5843 attribs[i].type = VASurfaceAttribPixelFormat;
5844 attribs[i].value.type = VAGenericValueTypeInteger;
5845 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5846 attribs[i].value.value.i = VA_FOURCC_RGBA;
5849 attribs[i].type = VASurfaceAttribPixelFormat;
5850 attribs[i].value.type = VAGenericValueTypeInteger;
5851 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5852 attribs[i].value.value.i = VA_FOURCC_RGBX;
5856 } else if (IS_GEN7(i965->intel.device_info)) {
5857 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5858 if (obj_config->profile == VAProfileJPEGBaseline) {
5859 attribs[i].type = VASurfaceAttribPixelFormat;
5860 attribs[i].value.type = VAGenericValueTypeInteger;
5861 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5862 attribs[i].value.value.i = VA_FOURCC_IMC3;
5865 attribs[i].type = VASurfaceAttribPixelFormat;
5866 attribs[i].value.type = VAGenericValueTypeInteger;
5867 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5868 attribs[i].value.value.i = VA_FOURCC_IMC1;
5871 attribs[i].type = VASurfaceAttribPixelFormat;
5872 attribs[i].value.type = VAGenericValueTypeInteger;
5873 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5874 attribs[i].value.value.i = VA_FOURCC_Y800;
5877 attribs[i].type = VASurfaceAttribPixelFormat;
5878 attribs[i].value.type = VAGenericValueTypeInteger;
5879 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5880 attribs[i].value.value.i = VA_FOURCC_411P;
5883 attribs[i].type = VASurfaceAttribPixelFormat;
5884 attribs[i].value.type = VAGenericValueTypeInteger;
5885 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5886 attribs[i].value.value.i = VA_FOURCC_422H;
5889 attribs[i].type = VASurfaceAttribPixelFormat;
5890 attribs[i].value.type = VAGenericValueTypeInteger;
5891 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5892 attribs[i].value.value.i = VA_FOURCC_422V;
5895 attribs[i].type = VASurfaceAttribPixelFormat;
5896 attribs[i].value.type = VAGenericValueTypeInteger;
5897 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5898 attribs[i].value.value.i = VA_FOURCC_444P;
5900 } else if (obj_config->profile == VAProfileHEVCMain10) {
5901 attribs[i].type = VASurfaceAttribPixelFormat;
5902 attribs[i].value.type = VAGenericValueTypeInteger;
5903 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5904 attribs[i].value.value.i = VA_FOURCC_P010;
5907 attribs[i].type = VASurfaceAttribPixelFormat;
5908 attribs[i].value.type = VAGenericValueTypeInteger;
5909 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5910 attribs[i].value.value.i = VA_FOURCC_NV12;
5913 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5914 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5915 attribs[i].type = VASurfaceAttribPixelFormat;
5916 attribs[i].value.type = VAGenericValueTypeInteger;
5917 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5918 attribs[i].value.value.i = VA_FOURCC_NV12;
5921 attribs[i].type = VASurfaceAttribPixelFormat;
5922 attribs[i].value.type = VAGenericValueTypeInteger;
5923 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5924 attribs[i].value.value.i = VA_FOURCC_I420;
5927 attribs[i].type = VASurfaceAttribPixelFormat;
5928 attribs[i].value.type = VAGenericValueTypeInteger;
5929 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5930 attribs[i].value.value.i = VA_FOURCC_YV12;
5933 attribs[i].type = VASurfaceAttribPixelFormat;
5934 attribs[i].value.type = VAGenericValueTypeInteger;
5935 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5936 attribs[i].value.value.i = VA_FOURCC_IMC3;
5939 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5940 attribs[i].type = VASurfaceAttribPixelFormat;
5941 attribs[i].value.type = VAGenericValueTypeInteger;
5942 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5943 attribs[i].value.value.i = VA_FOURCC_YUY2;
5946 attribs[i].type = VASurfaceAttribPixelFormat;
5947 attribs[i].value.type = VAGenericValueTypeInteger;
5948 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5949 attribs[i].value.value.i = VA_FOURCC_RGBA;
5952 attribs[i].type = VASurfaceAttribPixelFormat;
5953 attribs[i].value.type = VAGenericValueTypeInteger;
5954 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5955 attribs[i].value.value.i = VA_FOURCC_RGBX;
5958 attribs[i].type = VASurfaceAttribPixelFormat;
5959 attribs[i].value.type = VAGenericValueTypeInteger;
5960 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5961 attribs[i].value.value.i = VA_FOURCC_BGRA;
5964 attribs[i].type = VASurfaceAttribPixelFormat;
5965 attribs[i].value.type = VAGenericValueTypeInteger;
5966 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5967 attribs[i].value.value.i = VA_FOURCC_BGRX;
5970 attribs[i].type = VASurfaceAttribPixelFormat;
5971 attribs[i].value.type = VAGenericValueTypeInteger;
5972 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5973 attribs[i].value.value.i = VA_FOURCC_YV16;
5977 } else if (IS_GEN8(i965->intel.device_info) ||
5978 IS_GEN9(i965->intel.device_info)) {
5979 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5980 if (obj_config->profile == VAProfileJPEGBaseline) {
5981 attribs[i].type = VASurfaceAttribPixelFormat;
5982 attribs[i].value.type = VAGenericValueTypeInteger;
5983 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5984 attribs[i].value.value.i = VA_FOURCC_IMC3;
5987 attribs[i].type = VASurfaceAttribPixelFormat;
5988 attribs[i].value.type = VAGenericValueTypeInteger;
5989 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5990 attribs[i].value.value.i = VA_FOURCC_IMC1;
5993 attribs[i].type = VASurfaceAttribPixelFormat;
5994 attribs[i].value.type = VAGenericValueTypeInteger;
5995 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5996 attribs[i].value.value.i = VA_FOURCC_Y800;
5999 attribs[i].type = VASurfaceAttribPixelFormat;
6000 attribs[i].value.type = VAGenericValueTypeInteger;
6001 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6002 attribs[i].value.value.i = VA_FOURCC_411P;
6005 attribs[i].type = VASurfaceAttribPixelFormat;
6006 attribs[i].value.type = VAGenericValueTypeInteger;
6007 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6008 attribs[i].value.value.i = VA_FOURCC_422H;
6011 attribs[i].type = VASurfaceAttribPixelFormat;
6012 attribs[i].value.type = VAGenericValueTypeInteger;
6013 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6014 attribs[i].value.value.i = VA_FOURCC_422V;
6017 attribs[i].type = VASurfaceAttribPixelFormat;
6018 attribs[i].value.type = VAGenericValueTypeInteger;
6019 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6020 attribs[i].value.value.i = VA_FOURCC_444P;
6023 attribs[i].type = VASurfaceAttribPixelFormat;
6024 attribs[i].value.type = VAGenericValueTypeInteger;
6025 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6026 attribs[i].value.value.i = VA_FOURCC_NV12;
6029 if ((obj_config->profile == VAProfileHEVCMain10) ||
6030 (obj_config->profile == VAProfileVP9Profile2)) {
6031 attribs[i].type = VASurfaceAttribPixelFormat;
6032 attribs[i].value.type = VAGenericValueTypeInteger;
6033 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6034 attribs[i].value.value.i = VA_FOURCC_P010;
6038 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6039 obj_config->entrypoint == VAEntrypointVideoProc ||
6040 obj_config->entrypoint == VAEntrypointEncSliceLP ||
6041 obj_config->entrypoint == VAEntrypointEncPicture) {
6043 if (obj_config->profile == VAProfileHEVCMain10) {
6044 attribs[i].type = VASurfaceAttribPixelFormat;
6045 attribs[i].value.type = VAGenericValueTypeInteger;
6046 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6047 attribs[i].value.value.i = VA_FOURCC_P010;
6050 attribs[i].type = VASurfaceAttribPixelFormat;
6051 attribs[i].value.type = VAGenericValueTypeInteger;
6052 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6053 attribs[i].value.value.i = VA_FOURCC_NV12;
6056 attribs[i].type = VASurfaceAttribPixelFormat;
6057 attribs[i].value.type = VAGenericValueTypeInteger;
6058 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6059 attribs[i].value.value.i = VA_FOURCC_I420;
6062 attribs[i].type = VASurfaceAttribPixelFormat;
6063 attribs[i].value.type = VAGenericValueTypeInteger;
6064 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6065 attribs[i].value.value.i = VA_FOURCC_YV12;
6068 attribs[i].type = VASurfaceAttribPixelFormat;
6069 attribs[i].value.type = VAGenericValueTypeInteger;
6070 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6071 attribs[i].value.value.i = VA_FOURCC_IMC3;
6075 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6076 attribs[i].type = VASurfaceAttribPixelFormat;
6077 attribs[i].value.type = VAGenericValueTypeInteger;
6078 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6079 attribs[i].value.value.i = VA_FOURCC_YUY2;
6082 attribs[i].type = VASurfaceAttribPixelFormat;
6083 attribs[i].value.type = VAGenericValueTypeInteger;
6084 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6085 attribs[i].value.value.i = VA_FOURCC_RGBA;
6088 attribs[i].type = VASurfaceAttribPixelFormat;
6089 attribs[i].value.type = VAGenericValueTypeInteger;
6090 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6091 attribs[i].value.value.i = VA_FOURCC_RGBX;
6094 attribs[i].type = VASurfaceAttribPixelFormat;
6095 attribs[i].value.type = VAGenericValueTypeInteger;
6096 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6097 attribs[i].value.value.i = VA_FOURCC_BGRA;
6100 attribs[i].type = VASurfaceAttribPixelFormat;
6101 attribs[i].value.type = VAGenericValueTypeInteger;
6102 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6103 attribs[i].value.value.i = VA_FOURCC_BGRX;
6106 attribs[i].type = VASurfaceAttribPixelFormat;
6107 attribs[i].value.type = VAGenericValueTypeInteger;
6108 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6109 attribs[i].value.value.i = VA_FOURCC_YV16;
6112 if (HAS_VPP_P010(i965)) {
6113 attribs[i].type = VASurfaceAttribPixelFormat;
6114 attribs[i].value.type = VAGenericValueTypeInteger;
6115 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6116 attribs[i].value.value.i = VA_FOURCC_P010;
6119 attribs[i].type = VASurfaceAttribPixelFormat;
6120 attribs[i].value.type = VAGenericValueTypeInteger;
6121 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6122 attribs[i].value.value.i = VA_FOURCC_I010;
6127 /* Additional support for jpeg encoder */
6128 if (obj_config->profile == VAProfileJPEGBaseline
6129 && obj_config->entrypoint == VAEntrypointEncPicture) {
6130 attribs[i].type = VASurfaceAttribPixelFormat;
6131 attribs[i].value.type = VAGenericValueTypeInteger;
6132 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6133 attribs[i].value.value.i = VA_FOURCC_YUY2;
6136 attribs[i].type = VASurfaceAttribPixelFormat;
6137 attribs[i].value.type = VAGenericValueTypeInteger;
6138 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6139 attribs[i].value.value.i = VA_FOURCC_UYVY;
6142 attribs[i].type = VASurfaceAttribPixelFormat;
6143 attribs[i].value.type = VAGenericValueTypeInteger;
6144 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6145 attribs[i].value.value.i = VA_FOURCC_YV16;
6148 attribs[i].type = VASurfaceAttribPixelFormat;
6149 attribs[i].value.type = VAGenericValueTypeInteger;
6150 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6151 attribs[i].value.value.i = VA_FOURCC_Y800;
6157 attribs[i].type = VASurfaceAttribMemoryType;
6158 attribs[i].value.type = VAGenericValueTypeInteger;
6159 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6160 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
6161 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
6162 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
6165 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
6166 attribs[i].value.type = VAGenericValueTypePointer;
6167 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
6168 attribs[i].value.value.p = NULL; /* ignore */
6171 max_resolution(i965, obj_config, &max_width, &max_height);
6173 attribs[i].type = VASurfaceAttribMaxWidth;
6174 attribs[i].value.type = VAGenericValueTypeInteger;
6175 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6176 attribs[i].value.value.i = max_width;
6179 attribs[i].type = VASurfaceAttribMaxHeight;
6180 attribs[i].value.type = VAGenericValueTypeInteger;
6181 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6182 attribs[i].value.value.i = max_height;
6185 if (i > *num_attribs) {
6188 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6192 memcpy(attrib_list, attribs, i * sizeof(*attribs));
6198 /* Acquires buffer handle for external API usage (internal implementation) */
6200 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
6201 uint32_t mem_type, VABufferInfo *out_buf_info)
6203 struct buffer_store *buffer_store;
6205 buffer_store = obj_buffer->buffer_store;
6206 if (!buffer_store || !buffer_store->bo)
6207 return VA_STATUS_ERROR_INVALID_BUFFER;
6209 /* Synchronization point */
6210 drm_intel_bo_wait_rendering(buffer_store->bo);
6212 if (obj_buffer->export_refcount > 0) {
6213 if (obj_buffer->export_state.mem_type != mem_type)
6214 return VA_STATUS_ERROR_INVALID_PARAMETER;
6216 VABufferInfo * const buf_info = &obj_buffer->export_state;
6219 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
6221 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
6222 return VA_STATUS_ERROR_INVALID_BUFFER;
6223 buf_info->handle = name;
6226 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6228 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
6229 return VA_STATUS_ERROR_INVALID_BUFFER;
6230 buf_info->handle = (intptr_t)fd;
6235 buf_info->type = obj_buffer->type;
6236 buf_info->mem_type = mem_type;
6237 buf_info->mem_size =
6238 obj_buffer->num_elements * obj_buffer->size_element;
6241 obj_buffer->export_refcount++;
6242 *out_buf_info = obj_buffer->export_state;
6243 return VA_STATUS_SUCCESS;
6246 /* Releases buffer handle after usage (internal implementation) */
6248 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6250 if (obj_buffer->export_refcount == 0)
6251 return VA_STATUS_ERROR_INVALID_BUFFER;
6253 if (--obj_buffer->export_refcount == 0) {
6254 VABufferInfo * const buf_info = &obj_buffer->export_state;
6256 switch (buf_info->mem_type) {
6257 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6258 close((intptr_t)buf_info->handle);
6262 buf_info->mem_type = 0;
6264 return VA_STATUS_SUCCESS;
6267 /** Acquires buffer handle for external API usage */
6269 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6270 VABufferInfo *buf_info)
6272 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6273 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6274 uint32_t i, mem_type;
6276 /* List of supported memory types, in preferred order */
6277 static const uint32_t mem_types[] = {
6278 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6279 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6284 return VA_STATUS_ERROR_INVALID_BUFFER;
6285 /* XXX: only VA surface|image like buffers are supported for now */
6286 if (obj_buffer->type != VAImageBufferType)
6287 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6290 * As the allocated buffer by calling vaCreateBuffer is related with
6291 * the specific context, it is unnecessary to export it.
6292 * So it is not supported when the buffer is allocated from wrapped
6295 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6296 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6300 return VA_STATUS_ERROR_INVALID_PARAMETER;
6302 if (!buf_info->mem_type)
6303 mem_type = mem_types[0];
6306 for (i = 0; mem_types[i] != 0; i++) {
6307 if (buf_info->mem_type & mem_types[i]) {
6308 mem_type = buf_info->mem_type;
6313 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6315 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6318 /** Releases buffer handle after usage from external API */
6320 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6322 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6323 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6326 return VA_STATUS_ERROR_INVALID_BUFFER;
6328 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6329 return VA_STATUS_ERROR_INVALID_BUFFER;
6332 return i965_release_buffer_handle(obj_buffer);
6336 i965_os_has_ring_support(VADriverContextP ctx,
6339 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6343 return i965->intel.has_bsd;
6346 return i965->intel.has_blt;
6348 case I965_RING_VEBOX:
6349 return i965->intel.has_vebox;
6351 case I965_RING_NULL:
6352 return 1; /* Always support */
6355 /* should never get here */
6364 * Query video processing pipeline
6366 VAStatus i965_QueryVideoProcFilters(
6367 VADriverContextP ctx,
6368 VAContextID context,
6369 VAProcFilterType *filters,
6370 unsigned int *num_filters
6373 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6374 unsigned int i = 0, num = 0;
6376 if (!num_filters || !filters)
6377 return VA_STATUS_ERROR_INVALID_PARAMETER;
6379 for (i = 0; i < i965->codec_info->num_filters; i++) {
6380 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6381 if (num == *num_filters) {
6382 *num_filters = i965->codec_info->num_filters;
6384 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6387 filters[num++] = i965->codec_info->filters[i].type;
6393 return VA_STATUS_SUCCESS;
6396 VAStatus i965_QueryVideoProcFilterCaps(
6397 VADriverContextP ctx,
6398 VAContextID context,
6399 VAProcFilterType type,
6401 unsigned int *num_filter_caps
6405 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6407 if (!filter_caps || !num_filter_caps)
6408 return VA_STATUS_ERROR_INVALID_PARAMETER;
6410 for (i = 0; i < i965->codec_info->num_filters; i++) {
6411 if (type == i965->codec_info->filters[i].type &&
6412 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6416 if (i == i965->codec_info->num_filters)
6417 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6422 case VAProcFilterNoiseReduction:
6423 case VAProcFilterSharpening: {
6424 VAProcFilterCap *cap = filter_caps;
6426 if (*num_filter_caps < 1) {
6427 *num_filter_caps = 1;
6428 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6431 cap->range.min_value = 0.0;
6432 cap->range.max_value = 1.0;
6433 cap->range.default_value = 0.5;
6434 cap->range.step = 0.03125; /* 1.0 / 32 */
6440 case VAProcFilterDeinterlacing: {
6441 VAProcFilterCapDeinterlacing *cap = filter_caps;
6443 if (*num_filter_caps < VAProcDeinterlacingCount) {
6444 *num_filter_caps = VAProcDeinterlacingCount;
6445 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6448 cap->type = VAProcDeinterlacingBob;
6453 if (i965->codec_info->has_di_motion_adptive) {
6454 cap->type = VAProcDeinterlacingMotionAdaptive;
6459 if (i965->codec_info->has_di_motion_compensated) {
6460 cap->type = VAProcDeinterlacingMotionCompensated;
6468 case VAProcFilterColorBalance: {
6469 VAProcFilterCapColorBalance *cap = filter_caps;
6471 if (*num_filter_caps < VAProcColorBalanceCount) {
6472 *num_filter_caps = VAProcColorBalanceCount;
6473 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6476 cap->type = VAProcColorBalanceHue;
6477 cap->range.min_value = -180.0;
6478 cap->range.max_value = 180.0;
6479 cap->range.default_value = 0.0;
6480 cap->range.step = 1.0;
6484 cap->type = VAProcColorBalanceSaturation;
6485 cap->range.min_value = 0.0;
6486 cap->range.max_value = 10.0;
6487 cap->range.default_value = 1.0;
6488 cap->range.step = 0.1;
6492 cap->type = VAProcColorBalanceBrightness;
6493 cap->range.min_value = -100.0;
6494 cap->range.max_value = 100.0;
6495 cap->range.default_value = 0.0;
6496 cap->range.step = 1.0;
6500 cap->type = VAProcColorBalanceContrast;
6501 cap->range.min_value = 0.0;
6502 cap->range.max_value = 10.0;
6503 cap->range.default_value = 1.0;
6504 cap->range.step = 0.1;
6516 *num_filter_caps = i;
6518 return VA_STATUS_SUCCESS;
6521 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6522 VAProcColorStandardBT601,
6525 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6526 VAProcColorStandardBT601,
6529 VAStatus i965_QueryVideoProcPipelineCaps(
6530 VADriverContextP ctx,
6531 VAContextID context,
6532 VABufferID *filters,
6533 unsigned int num_filters,
6534 VAProcPipelineCaps *pipeline_cap /* out */
6537 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6540 pipeline_cap->pipeline_flags = 0;
6541 pipeline_cap->filter_flags = 0;
6542 pipeline_cap->num_forward_references = 0;
6543 pipeline_cap->num_backward_references = 0;
6544 pipeline_cap->num_input_color_standards = 1;
6545 pipeline_cap->input_color_standards = vpp_input_color_standards;
6546 pipeline_cap->num_output_color_standards = 1;
6547 pipeline_cap->output_color_standards = vpp_output_color_standards;
6549 for (i = 0; i < num_filters; i++) {
6550 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6553 !obj_buffer->buffer_store ||
6554 !obj_buffer->buffer_store->buffer)
6555 return VA_STATUS_ERROR_INVALID_BUFFER;
6557 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6559 if (base->type == VAProcFilterNoiseReduction) {
6560 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6562 } else if (base->type == VAProcFilterDeinterlacing) {
6563 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6565 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6566 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6567 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6568 VA_STATUS_ERROR_INVALID_PARAMETER);
6570 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6571 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6572 pipeline_cap->num_forward_references++;
6573 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6574 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6579 return VA_STATUS_SUCCESS;
6582 extern struct hw_codec_info *i965_get_codec_info(int devid);
6585 i965_driver_data_init(VADriverContextP ctx)
6587 struct i965_driver_data *i965 = i965_driver_data(ctx);
6589 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6591 if (!i965->codec_info)
6594 if (object_heap_init(&i965->config_heap,
6595 sizeof(struct object_config),
6597 goto err_config_heap;
6598 if (object_heap_init(&i965->context_heap,
6599 sizeof(struct object_context),
6601 goto err_context_heap;
6603 if (object_heap_init(&i965->surface_heap,
6604 sizeof(struct object_surface),
6606 goto err_surface_heap;
6607 if (object_heap_init(&i965->buffer_heap,
6608 sizeof(struct object_buffer),
6610 goto err_buffer_heap;
6611 if (object_heap_init(&i965->image_heap,
6612 sizeof(struct object_image),
6614 goto err_image_heap;
6615 if (object_heap_init(&i965->subpic_heap,
6616 sizeof(struct object_subpic),
6618 goto err_subpic_heap;
6620 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6621 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6622 _i965InitMutex(&i965->render_mutex);
6623 _i965InitMutex(&i965->pp_mutex);
6628 object_heap_destroy(&i965->image_heap);
6630 object_heap_destroy(&i965->buffer_heap);
6632 object_heap_destroy(&i965->surface_heap);
6634 object_heap_destroy(&i965->context_heap);
6636 object_heap_destroy(&i965->config_heap);
6643 i965_driver_data_terminate(VADriverContextP ctx)
6645 struct i965_driver_data *i965 = i965_driver_data(ctx);
6647 _i965DestroyMutex(&i965->pp_mutex);
6648 _i965DestroyMutex(&i965->render_mutex);
6651 intel_batchbuffer_free(i965->batch);
6654 intel_batchbuffer_free(i965->pp_batch);
6656 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6657 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6658 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6659 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6660 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6661 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6665 bool (*init)(VADriverContextP ctx);
6666 void (*terminate)(VADriverContextP ctx);
6668 } i965_sub_ops[] = {
6671 intel_driver_terminate,
6676 i965_driver_data_init,
6677 i965_driver_data_terminate,
6682 i965_display_attributes_init,
6683 i965_display_attributes_terminate,
6688 i965_post_processing_init,
6689 i965_post_processing_terminate,
6695 i965_render_terminate,
6699 #ifdef HAVE_VA_WAYLAND
6701 i965_output_wayland_init,
6702 i965_output_wayland_terminate,
6709 i965_output_dri_init,
6710 i965_output_dri_terminate,
6716 i965_gpe_table_init,
6717 i965_gpe_table_terminate,
6723 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6727 if (i965->va_vendor[0] != '\0')
6731 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6732 "%s %s driver for %s - %d.%d.%d",
6733 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6734 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6735 INTEL_DRIVER_MICRO_VERSION);
6736 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6740 if (INTEL_DRIVER_PRE_VERSION > 0) {
6741 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6742 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6743 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6747 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6748 " (%s)", INTEL_DRIVER_GIT_VERSION);
6749 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6756 i965->va_vendor[0] = '\0';
6757 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6761 /* Only when the option of "enable-wrapper" is passed, it is possible
6762 * to initialize/load the wrapper context of backend driver.
6763 * Otherwise it is not loaded.
6765 #if HAVE_HYBRID_CODEC
6768 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6770 #define DRIVER_EXTENSION "_drv_video.so"
6772 struct i965_driver_data *i965 = i965_driver_data(ctx);
6774 VADriverContextP wrapper_pdrvctx;
6775 struct VADriverVTable *vtable;
6776 char *search_path, *driver_dir;
6778 char driver_path[256];
6779 void *handle = NULL;
6780 VAStatus va_status = VA_STATUS_SUCCESS;
6781 bool driver_loaded = false;
6783 if (HAS_VP9_DECODING(i965)) {
6784 i965->wrapper_pdrvctx = NULL;
6788 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6789 vtable = calloc(1, sizeof(*vtable));
6791 if (!wrapper_pdrvctx || !vtable) {
6792 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6793 free(wrapper_pdrvctx);
6795 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6798 /* use the same drm_state with CTX */
6799 wrapper_pdrvctx->drm_state = ctx->drm_state;
6800 wrapper_pdrvctx->display_type = ctx->display_type;
6801 wrapper_pdrvctx->vtable = vtable;
6803 search_path = VA_DRIVERS_PATH;
6804 search_path = strdup((const char *)search_path);
6806 driver_dir = strtok_r(search_path, ":", &saveptr);
6807 while (driver_dir && !driver_loaded) {
6808 memset(driver_path, 0, sizeof(driver_path));
6809 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6811 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6813 fprintf(stderr, "failed to open %s\n", driver_path);
6814 driver_dir = strtok_r(NULL, ":", &saveptr);
6818 VADriverInit init_func = NULL;
6819 char init_func_s[256];
6822 static const struct {
6825 } compatible_versions[] = {
6826 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6835 for (i = 0; compatible_versions[i].major >= 0; i++) {
6836 snprintf(init_func_s, sizeof(init_func_s),
6837 "__vaDriverInit_%d_%d",
6838 compatible_versions[i].major,
6839 compatible_versions[i].minor);
6840 init_func = (VADriverInit)dlsym(handle, init_func_s);
6845 if (compatible_versions[i].major < 0) {
6847 fprintf(stderr, "%s has no function %s\n",
6848 driver_path, init_func_s);
6849 driver_dir = strtok_r(NULL, ":", &saveptr);
6854 va_status = (*init_func)(wrapper_pdrvctx);
6856 if (va_status != VA_STATUS_SUCCESS) {
6858 fprintf(stderr, "%s init failed\n", driver_path);
6859 driver_dir = strtok_r(NULL, ":", &saveptr);
6863 wrapper_pdrvctx->handle = handle;
6864 driver_loaded = true;
6870 if (driver_loaded) {
6871 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6872 return VA_STATUS_SUCCESS;
6874 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6876 free(wrapper_pdrvctx);
6877 return VA_STATUS_ERROR_OPERATION_FAILED;
6883 i965_Init(VADriverContextP ctx)
6885 struct i965_driver_data *i965 = i965_driver_data(ctx);
6887 const char *chipset;
6889 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6890 if ((i965_sub_ops[i].display_type == 0 ||
6891 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6892 !i965_sub_ops[i].init(ctx))
6896 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6897 switch (i965->intel.device_id) {
6899 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6900 #include "i965_pciids.h"
6902 chipset = "Unknown Intel Chipset";
6906 if (!ensure_vendor_string(i965, chipset))
6907 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6909 i965->current_context_id = VA_INVALID_ID;
6911 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6912 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6914 #if HAVE_HYBRID_CODEC
6915 i965_initialize_wrapper(ctx, "hybrid");
6918 return VA_STATUS_SUCCESS;
6922 for (; i >= 0; i--) {
6923 if (i965_sub_ops[i].display_type == 0 ||
6924 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6925 i965_sub_ops[i].terminate(ctx);
6929 return VA_STATUS_ERROR_UNKNOWN;
6934 i965_Terminate(VADriverContextP ctx)
6936 struct i965_driver_data *i965 = i965_driver_data(ctx);
6940 #if HAVE_HYBRID_CODEC
6941 if (i965->wrapper_pdrvctx) {
6942 VADriverContextP pdrvctx;
6943 pdrvctx = i965->wrapper_pdrvctx;
6944 if (pdrvctx->handle) {
6945 pdrvctx->vtable->vaTerminate(pdrvctx);
6946 dlclose(pdrvctx->handle);
6947 pdrvctx->handle = NULL;
6949 free(pdrvctx->vtable);
6951 i965->wrapper_pdrvctx = NULL;
6955 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6956 if (i965_sub_ops[i - 1].display_type == 0 ||
6957 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6958 i965_sub_ops[i - 1].terminate(ctx);
6962 ctx->pDriverData = NULL;
6965 return VA_STATUS_SUCCESS;
6969 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6972 VA_DRIVER_INIT_FUNC(VADriverContextP ctx)
6974 struct VADriverVTable * const vtable = ctx->vtable;
6975 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6977 struct i965_driver_data *i965;
6978 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6980 ctx->version_major = VA_MAJOR_VERSION;
6981 ctx->version_minor = VA_MINOR_VERSION;
6982 ctx->max_profiles = I965_MAX_PROFILES;
6983 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6984 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6985 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6986 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6987 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6989 vtable->vaTerminate = i965_Terminate;
6990 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6991 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6992 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6993 vtable->vaCreateConfig = i965_CreateConfig;
6994 vtable->vaDestroyConfig = i965_DestroyConfig;
6995 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6996 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6997 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6998 vtable->vaCreateContext = i965_CreateContext;
6999 vtable->vaDestroyContext = i965_DestroyContext;
7000 vtable->vaCreateBuffer = i965_CreateBuffer;
7001 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
7002 vtable->vaMapBuffer = i965_MapBuffer;
7003 vtable->vaUnmapBuffer = i965_UnmapBuffer;
7004 vtable->vaDestroyBuffer = i965_DestroyBuffer;
7005 vtable->vaBeginPicture = i965_BeginPicture;
7006 vtable->vaRenderPicture = i965_RenderPicture;
7007 vtable->vaEndPicture = i965_EndPicture;
7008 vtable->vaSyncSurface = i965_SyncSurface;
7009 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
7010 vtable->vaPutSurface = i965_PutSurface;
7011 vtable->vaQueryImageFormats = i965_QueryImageFormats;
7012 vtable->vaCreateImage = i965_CreateImage;
7013 vtable->vaDeriveImage = i965_DeriveImage;
7014 vtable->vaDestroyImage = i965_DestroyImage;
7015 vtable->vaSetImagePalette = i965_SetImagePalette;
7016 vtable->vaGetImage = i965_GetImage;
7017 vtable->vaPutImage = i965_PutImage;
7018 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
7019 vtable->vaCreateSubpicture = i965_CreateSubpicture;
7020 vtable->vaDestroySubpicture = i965_DestroySubpicture;
7021 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
7022 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
7023 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
7024 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
7025 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
7026 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
7027 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
7028 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
7029 vtable->vaBufferInfo = i965_BufferInfo;
7030 vtable->vaLockSurface = i965_LockSurface;
7031 vtable->vaUnlockSurface = i965_UnlockSurface;
7032 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
7033 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
7034 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
7037 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
7038 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
7040 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
7041 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
7042 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
7044 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
7047 ctx->pDriverData = NULL;
7049 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7052 i965->wrapper_pdrvctx = NULL;
7053 ctx->pDriverData = (void *)i965;
7054 ret = i965_Init(ctx);
7056 if (ret == VA_STATUS_SUCCESS) {
7057 ctx->str_vendor = i965->va_vendor;
7060 ctx->pDriverData = NULL;