2 * Copyright ?2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
33 #include <drm_fourcc.h>
36 # include "i965_output_dri.h"
39 #ifdef HAVE_VA_WAYLAND
40 # include "i965_output_wayland.h"
43 #include "intel_version.h"
44 #include "intel_driver.h"
45 #include "intel_memman.h"
46 #include "intel_batchbuffer.h"
47 #include "i965_defines.h"
48 #include "i965_drv_video.h"
49 #include "i965_decoder.h"
50 #include "i965_encoder.h"
52 #include "i965_post_processing.h"
54 #include "gen9_vp9_encapi.h"
56 #define CONFIG_ID_OFFSET 0x01000000
57 #define CONTEXT_ID_OFFSET 0x02000000
58 #define SURFACE_ID_OFFSET 0x04000000
59 #define BUFFER_ID_OFFSET 0x08000000
60 #define IMAGE_ID_OFFSET 0x0a000000
61 #define SUBPIC_ID_OFFSET 0x10000000
63 static int get_sampling_from_fourcc(unsigned int fourcc);
65 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
66 #define IS_VA_X11(ctx) \
67 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
69 /* Check whether we are rendering to Wayland */
70 #define IS_VA_WAYLAND(ctx) \
71 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
74 #define I965_2BITS (I965_BIT << 1)
75 #define I965_4BITS (I965_BIT << 2)
76 #define I965_8BITS (I965_BIT << 3)
77 #define I965_16BITS (I965_BIT << 4)
78 #define I965_32BITS (I965_BIT << 5)
90 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
91 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
92 #define I_I420 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
95 #define I_YV12 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
98 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
100 #define I_I010 2, 2, 3, {I965_16BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
102 #define I_422H 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
103 #define I_422V 1, 2, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
104 #define I_YV16 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
105 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
106 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
108 #define I_444P 1, 1, 3, {I965_8BITS, I965_8BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
110 #define I_411P 4, 1, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
112 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
114 #define I_RGBA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24} }
115 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
116 #define I_BGRA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_24} }
117 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
119 #define I_ARGB 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_0} }
120 #define I_ABGR 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
122 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
123 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
125 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
126 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
131 #define I_SI (I_S | I_I)
133 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
134 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
135 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
136 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
138 static const i965_fourcc_info i965_fourcc_infos[] = {
139 DEF_YUV(NV12, YUV420, I_SI),
140 DEF_YUV(I420, YUV420, I_SI),
141 DEF_YUV(IYUV, YUV420, I_S),
142 DEF_YUV(IMC3, YUV420, I_S),
143 DEF_YUV(YV12, YUV420, I_SI),
144 DEF_YUV(IMC1, YUV420, I_S),
146 DEF_YUV(P010, YUV420, I_SI),
147 DEF_YUV(I010, YUV420, I_S),
149 DEF_YUV(422H, YUV422H, I_SI),
150 DEF_YUV(422V, YUV422V, I_S),
151 DEF_YUV(YV16, YUV422H, I_S),
152 DEF_YUV(YUY2, YUV422H, I_SI),
153 DEF_YUV(UYVY, YUV422H, I_SI),
155 DEF_YUV(444P, YUV444, I_S),
157 DEF_YUV(411P, YUV411, I_S),
159 DEF_YUV(Y800, YUV400, I_S),
161 DEF_RGB(RGBA, RGBX, I_SI),
162 DEF_RGB(RGBX, RGBX, I_SI),
163 DEF_RGB(BGRA, RGBX, I_SI),
164 DEF_RGB(BGRX, RGBX, I_SI),
166 DEF_RGB(ARGB, RGBX, I_I),
167 DEF_RGB(ABGR, RGBX, I_I),
169 DEF_INDEX(IA88, RGBX, I_I),
170 DEF_INDEX(AI88, RGBX, I_I),
172 DEF_INDEX(IA44, RGBX, I_I),
173 DEF_INDEX(AI44, RGBX, I_I)
176 const i965_fourcc_info *
177 get_fourcc_info(unsigned int fourcc)
181 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
182 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
184 if (info->fourcc == fourcc)
192 get_bpp_from_fourcc(unsigned int fourcc)
194 const i965_fourcc_info *info = get_fourcc_info(fourcc);
196 unsigned int bpp = 0;
201 for (i = 0; i < info->num_planes; i++)
208 I965_SURFACETYPE_RGBA = 1,
209 I965_SURFACETYPE_YUV,
210 I965_SURFACETYPE_INDEXED
213 /* List of supported display attributes */
214 static const VADisplayAttribute i965_display_attributes[] = {
216 VADisplayAttribBrightness,
217 -100, 100, DEFAULT_BRIGHTNESS,
218 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
222 VADisplayAttribContrast,
223 0, 100, DEFAULT_CONTRAST,
224 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
229 -180, 180, DEFAULT_HUE,
230 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
234 VADisplayAttribSaturation,
235 0, 100, DEFAULT_SATURATION,
236 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
240 VADisplayAttribRotation,
241 0, 3, VA_ROTATION_NONE,
242 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
246 /* List of supported image formats */
249 VAImageFormat va_format;
250 } i965_image_format_map_t;
252 static const i965_image_format_map_t
253 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
255 I965_SURFACETYPE_YUV,
256 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, }
259 I965_SURFACETYPE_YUV,
260 { VA_FOURCC_I420, VA_LSB_FIRST, 12, }
263 I965_SURFACETYPE_YUV,
264 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, }
267 I965_SURFACETYPE_YUV,
268 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, }
271 I965_SURFACETYPE_YUV,
272 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, }
275 I965_SURFACETYPE_YUV,
276 { VA_FOURCC_422H, VA_LSB_FIRST, 16, }
279 I965_SURFACETYPE_RGBA,
280 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 }
283 I965_SURFACETYPE_RGBA,
284 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff }
287 I965_SURFACETYPE_YUV,
288 { VA_FOURCC_P010, VA_LSB_FIRST, 24, }
292 /* List of supported subpicture formats */
296 VAImageFormat va_format;
297 unsigned int va_flags;
298 } i965_subpic_format_map_t;
300 #define COMMON_SUBPICTURE_FLAGS \
301 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
302 VA_SUBPICTURE_GLOBAL_ALPHA)
304 static const i965_subpic_format_map_t
305 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
307 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
308 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
309 COMMON_SUBPICTURE_FLAGS
312 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
313 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
314 COMMON_SUBPICTURE_FLAGS
317 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
318 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
319 COMMON_SUBPICTURE_FLAGS
322 I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
323 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
324 COMMON_SUBPICTURE_FLAGS
327 I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
329 VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
330 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000
332 COMMON_SUBPICTURE_FLAGS
335 I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
337 VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
338 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000
340 COMMON_SUBPICTURE_FLAGS
344 static const i965_subpic_format_map_t *
345 get_subpic_format(const VAImageFormat *va_format)
348 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
349 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
350 if (m->va_format.fourcc == va_format->fourcc &&
351 (m->type == I965_SURFACETYPE_RGBA ?
352 (m->va_format.byte_order == va_format->byte_order &&
353 m->va_format.red_mask == va_format->red_mask &&
354 m->va_format.green_mask == va_format->green_mask &&
355 m->va_format.blue_mask == va_format->blue_mask &&
356 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
362 /* Checks whether the surface is in busy state */
364 is_surface_busy(struct i965_driver_data *i965,
365 struct object_surface *obj_surface)
367 assert(obj_surface != NULL);
369 if (obj_surface->locked_image_id != VA_INVALID_ID)
371 if (obj_surface->derived_image_id != VA_INVALID_ID)
376 /* Checks whether the image is in busy state */
378 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
380 struct object_buffer *obj_buffer;
382 assert(obj_image != NULL);
384 if (obj_image->derived_surface != VA_INVALID_ID &&
385 obj_image->derived_surface == surface)
388 obj_buffer = BUFFER(obj_image->image.buf);
389 if (obj_buffer && obj_buffer->export_refcount > 0)
394 #define I965_PACKED_HEADER_BASE 0
395 #define I965_SEQ_PACKED_HEADER_BASE 0
396 #define I965_SEQ_PACKED_HEADER_END 2
397 #define I965_PIC_PACKED_HEADER_BASE 2
398 #define I965_PACKED_MISC_HEADER_BASE 4
401 va_enc_packed_type_to_idx(int packed_type)
405 if (packed_type & VAEncPackedHeaderMiscMask) {
406 idx = I965_PACKED_MISC_HEADER_BASE;
407 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
408 ASSERT_RET(packed_type > 0, 0);
409 idx += (packed_type - 1);
411 idx = I965_PACKED_HEADER_BASE;
413 switch (packed_type) {
414 case VAEncPackedHeaderSequence:
415 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
418 case VAEncPackedHeaderPicture:
419 idx = I965_PIC_PACKED_HEADER_BASE + 0;
422 case VAEncPackedHeaderSlice:
423 idx = I965_PIC_PACKED_HEADER_BASE + 1;
427 /* Should not get here */
433 ASSERT_RET(idx < 5, 0);
437 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
440 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
442 struct i965_driver_data *i965 = i965_driver_data(ctx);
443 struct object_surface *obj_surface = SURFACE(surface);
444 VAStatus va_status = VA_STATUS_SUCCESS;
447 return VA_STATUS_ERROR_INVALID_SURFACE;
450 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
451 /* the wrapped surface already exists. just return it */
455 if (obj_surface->fourcc == 0)
456 i965_check_alloc_surface_bo(ctx, obj_surface,
457 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
460 * TBD: Support more surface formats.
461 * Currently only NV12 is support as NV12 is used by decoding.
463 if (obj_surface->fourcc != VA_FOURCC_NV12)
464 return VA_STATUS_ERROR_INVALID_PARAMETER;
466 if ((i965->wrapper_pdrvctx == NULL) ||
467 (obj_surface->bo == NULL))
468 return VA_STATUS_ERROR_INVALID_PARAMETER;
472 VASurfaceAttrib attrib_list[2];
473 VASurfaceAttribExternalBuffers buffer_descriptor;
474 VAGenericID wrapper_surface;
476 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
477 return VA_STATUS_ERROR_OPERATION_FAILED;
479 obj_surface->exported_primefd = fd_handle;
481 memset(&attrib_list, 0, sizeof(attrib_list));
482 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
484 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
485 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
486 attrib_list[0].value.value.p = &buffer_descriptor;
487 attrib_list[0].value.type = VAGenericValueTypePointer;
489 attrib_list[1].type = VASurfaceAttribMemoryType;
490 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
491 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
492 attrib_list[1].value.type = VAGenericValueTypeInteger;
494 buffer_descriptor.num_buffers = 1;
495 buffer_descriptor.num_planes = 2;
496 buffer_descriptor.width = obj_surface->orig_width;
497 buffer_descriptor.height = obj_surface->orig_height;
498 buffer_descriptor.pixel_format = obj_surface->fourcc;
499 buffer_descriptor.data_size = obj_surface->size;
500 buffer_descriptor.pitches[0] = obj_surface->width;
501 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
502 buffer_descriptor.offsets[0] = 0;
503 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
504 buffer_descriptor.buffers = (void *)&fd_handle;
506 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
507 vaCreateSurfaces2(i965->wrapper_pdrvctx,
509 obj_surface->orig_width,
510 obj_surface->orig_height,
514 if (va_status == VA_STATUS_SUCCESS) {
515 obj_surface->wrapper_surface = wrapper_surface;
517 /* This needs to be checked */
518 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
526 i965_QueryConfigProfiles(VADriverContextP ctx,
527 VAProfile *profile_list, /* out */
528 int *num_profiles) /* out */
530 struct i965_driver_data * const i965 = i965_driver_data(ctx);
533 if (HAS_MPEG2_DECODING(i965) ||
534 HAS_MPEG2_ENCODING(i965)) {
535 profile_list[i++] = VAProfileMPEG2Simple;
536 profile_list[i++] = VAProfileMPEG2Main;
539 if (HAS_H264_DECODING(i965) ||
540 HAS_H264_ENCODING(i965) ||
541 HAS_LP_H264_ENCODING(i965) ||
542 HAS_FEI_H264_ENCODING(i965)) {
543 profile_list[i++] = VAProfileH264ConstrainedBaseline;
544 profile_list[i++] = VAProfileH264Main;
545 profile_list[i++] = VAProfileH264High;
547 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
548 HAS_H264_MVC_ENCODING(i965))
549 profile_list[i++] = VAProfileH264MultiviewHigh;
550 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
551 HAS_H264_MVC_ENCODING(i965))
552 profile_list[i++] = VAProfileH264StereoHigh;
554 if (HAS_VC1_DECODING(i965)) {
555 profile_list[i++] = VAProfileVC1Simple;
556 profile_list[i++] = VAProfileVC1Main;
557 profile_list[i++] = VAProfileVC1Advanced;
561 profile_list[i++] = VAProfileNone;
564 if (HAS_JPEG_DECODING(i965) ||
565 HAS_JPEG_ENCODING(i965)) {
566 profile_list[i++] = VAProfileJPEGBaseline;
569 if (HAS_VP8_DECODING(i965) ||
570 HAS_VP8_ENCODING(i965)) {
571 profile_list[i++] = VAProfileVP8Version0_3;
574 if (HAS_HEVC_DECODING(i965) ||
575 HAS_HEVC_ENCODING(i965)) {
576 profile_list[i++] = VAProfileHEVCMain;
579 if (HAS_HEVC10_DECODING(i965) ||
580 HAS_HEVC10_ENCODING(i965)) {
581 profile_list[i++] = VAProfileHEVCMain10;
584 if (HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
585 HAS_VP9_ENCODING(i965)) {
586 profile_list[i++] = VAProfileVP9Profile0;
589 if (HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
590 profile_list[i++] = VAProfileVP9Profile2;
593 if (i965->wrapper_pdrvctx) {
594 VAProfile wrapper_list[4];
596 VADriverContextP pdrvctx;
599 pdrvctx = i965->wrapper_pdrvctx;
600 CALL_VTABLE(pdrvctx, va_status,
601 vaQueryConfigProfiles(pdrvctx,
602 wrapper_list, &wrapper_num));
604 if (va_status == VA_STATUS_SUCCESS) {
606 for (j = 0; j < wrapper_num; j++)
607 if (wrapper_list[j] != VAProfileNone)
608 profile_list[i++] = wrapper_list[j];
612 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
613 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
616 return VA_STATUS_SUCCESS;
620 i965_QueryConfigEntrypoints(VADriverContextP ctx,
622 VAEntrypoint *entrypoint_list, /* out */
623 int *num_entrypoints) /* out */
625 struct i965_driver_data * const i965 = i965_driver_data(ctx);
629 case VAProfileMPEG2Simple:
630 case VAProfileMPEG2Main:
631 if (HAS_MPEG2_DECODING(i965))
632 entrypoint_list[n++] = VAEntrypointVLD;
634 if (HAS_MPEG2_ENCODING(i965))
635 entrypoint_list[n++] = VAEntrypointEncSlice;
639 case VAProfileH264ConstrainedBaseline:
640 case VAProfileH264Main:
641 case VAProfileH264High:
642 if (HAS_H264_DECODING(i965))
643 entrypoint_list[n++] = VAEntrypointVLD;
645 if (HAS_H264_ENCODING(i965))
646 entrypoint_list[n++] = VAEntrypointEncSlice;
648 if (HAS_LP_H264_ENCODING(i965))
649 entrypoint_list[n++] = VAEntrypointEncSliceLP;
651 if (HAS_FEI_H264_ENCODING(i965))
652 entrypoint_list[n++] = VAEntrypointFEI;
655 case VAProfileH264MultiviewHigh:
656 case VAProfileH264StereoHigh:
657 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
658 entrypoint_list[n++] = VAEntrypointVLD;
660 if (HAS_H264_MVC_ENCODING(i965))
661 entrypoint_list[n++] = VAEntrypointEncSlice;
664 case VAProfileVC1Simple:
665 case VAProfileVC1Main:
666 case VAProfileVC1Advanced:
667 if (HAS_VC1_DECODING(i965))
668 entrypoint_list[n++] = VAEntrypointVLD;
673 entrypoint_list[n++] = VAEntrypointVideoProc;
676 case VAProfileJPEGBaseline:
677 if (HAS_JPEG_DECODING(i965))
678 entrypoint_list[n++] = VAEntrypointVLD;
680 if (HAS_JPEG_ENCODING(i965))
681 entrypoint_list[n++] = VAEntrypointEncPicture;
684 case VAProfileVP8Version0_3:
685 if (HAS_VP8_DECODING(i965))
686 entrypoint_list[n++] = VAEntrypointVLD;
688 if (HAS_VP8_ENCODING(i965))
689 entrypoint_list[n++] = VAEntrypointEncSlice;
693 case VAProfileHEVCMain:
694 if (HAS_HEVC_DECODING(i965))
695 entrypoint_list[n++] = VAEntrypointVLD;
697 if (HAS_HEVC_ENCODING(i965))
698 entrypoint_list[n++] = VAEntrypointEncSlice;
702 case VAProfileHEVCMain10:
703 if (HAS_HEVC10_DECODING(i965))
704 entrypoint_list[n++] = VAEntrypointVLD;
706 if (HAS_HEVC10_ENCODING(i965))
707 entrypoint_list[n++] = VAEntrypointEncSlice;
711 case VAProfileVP9Profile0:
712 case VAProfileVP9Profile2:
713 if (HAS_VP9_DECODING_PROFILE(i965, profile))
714 entrypoint_list[n++] = VAEntrypointVLD;
716 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
717 entrypoint_list[n++] = VAEntrypointEncSlice;
719 if (profile == VAProfileVP9Profile0) {
720 if (i965->wrapper_pdrvctx) {
721 VAStatus va_status = VA_STATUS_SUCCESS;
722 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
724 CALL_VTABLE(pdrvctx, va_status,
725 vaQueryConfigEntrypoints(pdrvctx, profile,
738 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
739 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
740 *num_entrypoints = n;
741 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
745 i965_validate_config(VADriverContextP ctx, VAProfile profile,
746 VAEntrypoint entrypoint)
748 struct i965_driver_data * const i965 = i965_driver_data(ctx);
751 /* Validate profile & entrypoint */
753 case VAProfileMPEG2Simple:
754 case VAProfileMPEG2Main:
755 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
756 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
757 va_status = VA_STATUS_SUCCESS;
758 } else if (!HAS_MPEG2_DECODING(i965) && !HAS_MPEG2_ENCODING(i965)) {
759 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
761 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
765 case VAProfileH264ConstrainedBaseline:
766 case VAProfileH264Main:
767 case VAProfileH264High:
768 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
769 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
770 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP) ||
771 (HAS_FEI_H264_ENCODING(i965) && entrypoint == VAEntrypointFEI)) {
772 va_status = VA_STATUS_SUCCESS;
773 } else if (!HAS_H264_DECODING(i965) && !HAS_H264_ENCODING(i965) &&
774 !HAS_LP_H264_ENCODING(i965) && !HAS_FEI_H264_ENCODING(i965)) {
775 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
777 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
781 case VAProfileVC1Simple:
782 case VAProfileVC1Main:
783 case VAProfileVC1Advanced:
784 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
785 va_status = VA_STATUS_SUCCESS;
786 } else if (!HAS_VC1_DECODING(i965)) {
787 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
789 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
794 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
795 va_status = VA_STATUS_SUCCESS;
796 } else if (!HAS_VPP(i965)) {
797 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
799 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
803 case VAProfileJPEGBaseline:
804 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
805 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
806 va_status = VA_STATUS_SUCCESS;
807 } else if (!HAS_JPEG_DECODING(i965) && !HAS_JPEG_ENCODING(i965)) {
808 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
810 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
814 case VAProfileVP8Version0_3:
815 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
816 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
817 va_status = VA_STATUS_SUCCESS;
818 } else if (!HAS_VP8_DECODING(i965) && !HAS_VP8_ENCODING(i965)) {
819 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
821 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
825 case VAProfileH264MultiviewHigh:
826 case VAProfileH264StereoHigh:
827 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
828 entrypoint == VAEntrypointVLD) ||
829 (HAS_H264_MVC_ENCODING(i965) &&
830 entrypoint == VAEntrypointEncSlice)) {
831 va_status = VA_STATUS_SUCCESS;
832 } else if (!HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
833 !HAS_H264_MVC_ENCODING(i965)) {
834 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
836 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
841 case VAProfileHEVCMain:
842 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD)) ||
843 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice))) {
844 va_status = VA_STATUS_SUCCESS;
845 } else if (!HAS_HEVC_DECODING(i965) && !HAS_HEVC_ENCODING(i965)) {
846 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
848 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
853 case VAProfileHEVCMain10:
854 if ((HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD)) ||
855 (HAS_HEVC10_ENCODING(i965) &&
856 (entrypoint == VAEntrypointEncSlice))) {
857 va_status = VA_STATUS_SUCCESS;
858 } else if (!HAS_HEVC10_DECODING(i965) && !HAS_HEVC10_ENCODING(i965)) {
859 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
861 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
866 case VAProfileVP9Profile0:
867 case VAProfileVP9Profile2:
868 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) &&
869 (entrypoint == VAEntrypointVLD)) {
870 va_status = VA_STATUS_SUCCESS;
871 } else if ((HAS_VP9_ENCODING_PROFILE(i965, profile)) &&
872 (entrypoint == VAEntrypointEncSlice)) {
873 va_status = VA_STATUS_SUCCESS;
874 } else if (profile == VAProfileVP9Profile0 &&
875 entrypoint == VAEntrypointVLD &&
876 i965->wrapper_pdrvctx) {
877 va_status = VA_STATUS_SUCCESS;
878 } else if (!HAS_VP9_DECODING_PROFILE(i965, profile) &&
879 !HAS_VP9_ENCODING(i965) && !i965->wrapper_pdrvctx) {
880 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
882 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
888 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
895 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
896 VAEntrypoint entrypoint)
898 struct i965_driver_data * const i965 = i965_driver_data(ctx);
899 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
902 case VAProfileH264ConstrainedBaseline:
903 case VAProfileH264Main:
904 case VAProfileH264High:
905 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
906 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
909 case VAProfileH264MultiviewHigh:
910 case VAProfileH264StereoHigh:
911 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
912 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
915 case VAProfileJPEGBaseline:
916 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
917 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
918 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
919 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
922 case VAProfileHEVCMain10:
923 if (HAS_HEVC10_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)
924 chroma_formats = VA_RT_FORMAT_YUV420_10BPP;
925 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
926 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
930 if (HAS_VPP_P010(i965))
931 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
934 chroma_formats |= VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_RGB32;
937 case VAProfileVP9Profile0:
938 case VAProfileVP9Profile2:
939 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
940 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
946 return chroma_formats;
950 i965_GetConfigAttributes(VADriverContextP ctx,
952 VAEntrypoint entrypoint,
953 VAConfigAttrib *attrib_list, /* in/out */
956 struct i965_driver_data * const i965 = i965_driver_data(ctx);
960 va_status = i965_validate_config(ctx, profile, entrypoint);
961 if (va_status != VA_STATUS_SUCCESS)
964 /* Other attributes don't seem to be defined */
965 /* What to do if we don't know the attribute? */
966 for (i = 0; i < num_attribs; i++) {
967 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
968 switch (attrib_list[i].type) {
969 case VAConfigAttribRTFormat:
970 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
971 profile, entrypoint);
974 case VAConfigAttribRateControl:
975 if (entrypoint == VAEntrypointEncSlice) {
976 attrib_list[i].value = VA_RC_CQP;
978 if (profile != VAProfileMPEG2Main &&
979 profile != VAProfileMPEG2Simple)
980 attrib_list[i].value |= VA_RC_CBR;
982 if (profile == VAProfileVP8Version0_3 ||
983 profile == VAProfileVP9Profile0 ||
984 profile == VAProfileHEVCMain)
985 attrib_list[i].value |= VA_RC_VBR;
987 if (profile == VAProfileH264ConstrainedBaseline ||
988 profile == VAProfileH264Main ||
989 profile == VAProfileH264High)
990 attrib_list[i].value = i965->codec_info->h264_brc_mode;
993 } else if (entrypoint == VAEntrypointEncSliceLP) {
994 struct i965_driver_data * const i965 = i965_driver_data(ctx);
996 /* Support low power encoding for H.264 only by now */
997 if (profile == VAProfileH264ConstrainedBaseline ||
998 profile == VAProfileH264Main ||
999 profile == VAProfileH264High)
1000 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
1002 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1003 } else if (entrypoint == VAEntrypointFEI) {
1004 /* Only CQP is supported in FEI Entrypoint */
1005 if (profile == VAProfileH264ConstrainedBaseline ||
1006 profile == VAProfileH264Main ||
1007 profile == VAProfileH264High)
1008 attrib_list[i].value = VA_RC_CQP;
1010 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1012 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1016 case VAConfigAttribEncPackedHeaders:
1017 if (entrypoint == VAEntrypointEncSlice ||
1018 entrypoint == VAEntrypointEncSliceLP ||
1019 entrypoint == VAEntrypointFEI) {
1020 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
1021 if (profile == VAProfileH264ConstrainedBaseline ||
1022 profile == VAProfileH264Main ||
1023 profile == VAProfileH264High ||
1024 profile == VAProfileH264StereoHigh ||
1025 profile == VAProfileH264MultiviewHigh ||
1026 profile == VAProfileHEVCMain ||
1027 profile == VAProfileHEVCMain10) {
1028 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
1029 VA_ENC_PACKED_HEADER_SLICE);
1030 } else if (profile == VAProfileVP9Profile0)
1031 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1033 } else if (entrypoint == VAEntrypointEncPicture) {
1034 if (profile == VAProfileJPEGBaseline)
1035 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1039 case VAConfigAttribEncMaxRefFrames:
1040 if (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointFEI) {
1041 attrib_list[i].value = (1 << 16) | (1 << 0);
1042 if (profile == VAProfileH264ConstrainedBaseline ||
1043 profile == VAProfileH264Main ||
1044 profile == VAProfileH264High ||
1045 profile == VAProfileH264StereoHigh ||
1046 profile == VAProfileH264MultiviewHigh) {
1047 if (IS_GEN9(i965->intel.device_info))
1048 attrib_list[i].value = (2 << 16) | (8 << 0);
1049 } else if (profile == VAProfileHEVCMain ||
1050 profile == VAProfileHEVCMain10) {
1051 if (IS_GEN9(i965->intel.device_info))
1052 attrib_list[i].value = (1 << 16) | (3 << 0);
1054 } else if (entrypoint == VAEntrypointEncSliceLP) {
1055 /* Don't support B frame for low power mode */
1056 if (profile == VAProfileH264ConstrainedBaseline ||
1057 profile == VAProfileH264Main ||
1058 profile == VAProfileH264High)
1059 attrib_list[i].value = (1 << 0);
1061 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1066 case VAConfigAttribEncQualityRange:
1067 if (entrypoint == VAEntrypointEncSlice ||
1068 entrypoint == VAEntrypointEncSliceLP ||
1069 entrypoint == VAEntrypointFEI) {
1070 attrib_list[i].value = 1;
1071 if (profile == VAProfileH264ConstrainedBaseline ||
1072 profile == VAProfileH264Main ||
1073 profile == VAProfileH264High) {
1074 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1075 if (entrypoint == VAEntrypointEncSlice) {
1076 if (IS_GEN9(i965->intel.device_info))
1077 attrib_list[i].value = ENCODER_QUALITY_RANGE_AVC;
1079 } else if (profile == VAProfileHEVCMain ||
1080 profile == VAProfileHEVCMain10)
1081 attrib_list[i].value = ENCODER_QUALITY_RANGE_HEVC;
1086 case VAConfigAttribEncJPEG:
1087 if (entrypoint == VAEntrypointEncPicture) {
1088 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*) & (attrib_list[i].value);
1089 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1090 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1091 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1092 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1093 (configVal->bits).max_num_components = 3; // Only 3 components supported
1094 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1095 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1096 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1100 case VAConfigAttribDecSliceMode:
1101 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1104 case VAConfigAttribEncROI:
1105 if (entrypoint == VAEntrypointEncSlice ||
1106 entrypoint == VAEntrypointEncSliceLP ||
1107 entrypoint == VAEntrypointFEI) {
1108 VAConfigAttribValEncROI *roi_config =
1109 (VAConfigAttribValEncROI *) & (attrib_list[i].value);
1111 if (profile == VAProfileH264ConstrainedBaseline ||
1112 profile == VAProfileH264Main ||
1113 profile == VAProfileH264High) {
1115 if (IS_GEN9(i965->intel.device_info) &&
1116 (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointFEI))
1117 attrib_list[i].value = 0;
1119 if (entrypoint == VAEntrypointEncSliceLP) {
1120 roi_config->bits.num_roi_regions = 3;
1121 roi_config->bits.roi_rc_priority_support = 0;
1122 roi_config->bits.roi_rc_qp_delta_support = 0;
1124 roi_config->bits.num_roi_regions =
1125 I965_MAX_NUM_ROI_REGIONS;
1126 roi_config->bits.roi_rc_priority_support = 0;
1127 roi_config->bits.roi_rc_qp_delta_support = 1;
1130 } else if (profile == VAProfileHEVCMain ||
1131 profile == VAProfileHEVCMain10) {
1132 roi_config->bits.num_roi_regions =
1133 I965_MAX_NUM_ROI_REGIONS;
1134 roi_config->bits.roi_rc_priority_support = 1;
1135 roi_config->bits.roi_rc_qp_delta_support = 1;
1137 attrib_list[i].value = 0;
1143 case VAConfigAttribEncRateControlExt:
1144 if ((profile == VAProfileH264ConstrainedBaseline ||
1145 profile == VAProfileH264Main ||
1146 profile == VAProfileH264High) &&
1147 entrypoint == VAEntrypointEncSlice) {
1148 if (IS_GEN9(i965->intel.device_info))
1149 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1151 VAConfigAttribValEncRateControlExt *val_config = (VAConfigAttribValEncRateControlExt *) & (attrib_list[i].value);
1153 val_config->bits.max_num_temporal_layers_minus1 = MAX_TEMPORAL_LAYERS - 1;
1154 val_config->bits.temporal_layer_bitrate_control_flag = 1;
1157 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1162 case VAConfigAttribEncMaxSlices:
1163 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1164 if (entrypoint == VAEntrypointEncSlice) {
1165 if ((profile == VAProfileH264ConstrainedBaseline ||
1166 profile == VAProfileH264Main ||
1167 profile == VAProfileH264High) ||
1168 profile == VAProfileH264StereoHigh ||
1169 profile == VAProfileH264MultiviewHigh) {
1170 attrib_list[i].value = I965_MAX_NUM_SLICE;
1171 } else if (profile == VAProfileHEVCMain ||
1172 profile == VAProfileHEVCMain10) {
1173 attrib_list[i].value = I965_MAX_NUM_SLICE;
1175 } else if (entrypoint == VAEntrypointEncSliceLP || entrypoint == VAEntrypointFEI) {
1176 if ((profile == VAProfileH264ConstrainedBaseline ||
1177 profile == VAProfileH264Main ||
1178 profile == VAProfileH264High) ||
1179 profile == VAProfileH264StereoHigh ||
1180 profile == VAProfileH264MultiviewHigh)
1181 attrib_list[i].value = I965_MAX_NUM_SLICE;
1186 case VAConfigAttribEncSliceStructure:
1187 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1188 if (entrypoint == VAEntrypointEncSlice) {
1189 if ((profile == VAProfileH264ConstrainedBaseline ||
1190 profile == VAProfileH264Main ||
1191 profile == VAProfileH264High) ||
1192 profile == VAProfileH264StereoHigh ||
1193 profile == VAProfileH264MultiviewHigh ||
1194 profile == VAProfileHEVCMain ||
1195 profile == VAProfileHEVCMain10) {
1196 attrib_list[i].value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1202 case VAConfigAttribFEIFunctionType:
1203 /* Supporing all possible modes of FEI */
1204 attrib_list[i].value = VA_FEI_FUNCTION_ENC |
1205 VA_FEI_FUNCTION_PAK | VA_FEI_FUNCTION_ENC_PAK;
1208 case VAConfigAttribFEIMVPredictors:
1209 attrib_list[i].value = 4;
1214 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1219 return VA_STATUS_SUCCESS;
1223 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1225 object_heap_free(heap, obj);
1228 static VAConfigAttrib *
1229 i965_lookup_config_attribute(struct object_config *obj_config,
1230 VAConfigAttribType type)
1234 for (i = 0; i < obj_config->num_attribs; i++) {
1235 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1236 if (attrib->type == type)
1243 i965_append_config_attribute(struct object_config *obj_config,
1244 const VAConfigAttrib *new_attrib)
1246 VAConfigAttrib *attrib;
1248 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1249 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1251 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1252 attrib->type = new_attrib->type;
1253 attrib->value = new_attrib->value;
1254 return VA_STATUS_SUCCESS;
1258 i965_ensure_config_attribute(struct object_config *obj_config,
1259 const VAConfigAttrib *new_attrib)
1261 VAConfigAttrib *attrib;
1263 /* Check for existing attributes */
1264 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1266 /* Update existing attribute */
1267 attrib->value = new_attrib->value;
1268 return VA_STATUS_SUCCESS;
1270 return i965_append_config_attribute(obj_config, new_attrib);
1274 i965_CreateConfig(VADriverContextP ctx,
1276 VAEntrypoint entrypoint,
1277 VAConfigAttrib *attrib_list,
1279 VAConfigID *config_id) /* out */
1281 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1282 struct object_config *obj_config;
1287 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1289 if (VA_STATUS_SUCCESS != vaStatus) {
1293 configID = NEW_CONFIG_ID();
1294 obj_config = CONFIG(configID);
1296 if (NULL == obj_config) {
1297 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1301 obj_config->profile = profile;
1302 obj_config->entrypoint = entrypoint;
1303 obj_config->num_attribs = 0;
1304 obj_config->wrapper_config = VA_INVALID_ID;
1306 for (i = 0; i < num_attribs; i++) {
1307 // add it later and ignore the user input for VAConfigAttribEncMaxSlices
1308 if (attrib_list[i].type == VAConfigAttribEncMaxSlices ||
1309 attrib_list[i].type == VAConfigAttribEncSliceStructure)
1311 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1312 if (vaStatus != VA_STATUS_SUCCESS)
1316 if (vaStatus == VA_STATUS_SUCCESS) {
1317 VAConfigAttrib attrib, *attrib_found;
1318 attrib.type = VAConfigAttribRTFormat;
1319 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1320 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1321 if (!attrib_found || !attrib_found->value)
1322 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1323 else if (!(attrib_found->value & attrib.value))
1324 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1328 if (vaStatus == VA_STATUS_SUCCESS) {
1329 VAConfigAttrib attrib, *attrib_found;
1330 attrib.type = VAConfigAttribRateControl;
1331 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1333 case VAProfileH264ConstrainedBaseline:
1334 case VAProfileH264Main:
1335 case VAProfileH264High:
1336 if ((entrypoint == VAEntrypointEncSlice) && attrib_found &&
1337 !(attrib_found->value & i965->codec_info->h264_brc_mode))
1338 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1339 else if ((entrypoint == VAEntrypointEncSliceLP) && attrib_found &&
1340 !(attrib_found->value & i965->codec_info->lp_h264_brc_mode))
1341 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1342 else if ((entrypoint == VAEntrypointFEI) && attrib_found &&
1343 !(attrib_found->value == VA_RC_CQP))
1344 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1351 if (vaStatus == VA_STATUS_SUCCESS) {
1352 VAConfigAttrib attrib;
1353 attrib.type = VAConfigAttribEncMaxSlices;
1354 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1355 if (entrypoint == VAEntrypointEncSlice) {
1356 if ((profile == VAProfileH264ConstrainedBaseline ||
1357 profile == VAProfileH264Main ||
1358 profile == VAProfileH264High) ||
1359 profile == VAProfileH264StereoHigh ||
1360 profile == VAProfileH264MultiviewHigh) {
1361 attrib.value = I965_MAX_NUM_SLICE;
1362 } else if (profile == VAProfileHEVCMain ||
1363 profile == VAProfileHEVCMain10)
1364 attrib.value = I965_MAX_NUM_SLICE;
1365 } else if (entrypoint == VAEntrypointEncSliceLP || entrypoint == VAEntrypointFEI) {
1366 if ((profile == VAProfileH264ConstrainedBaseline ||
1367 profile == VAProfileH264Main ||
1368 profile == VAProfileH264High) ||
1369 profile == VAProfileH264StereoHigh ||
1370 profile == VAProfileH264MultiviewHigh)
1371 attrib.value = I965_MAX_NUM_SLICE;
1374 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1375 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1378 if (vaStatus == VA_STATUS_SUCCESS) {
1379 VAConfigAttrib attrib;
1380 attrib.type = VAConfigAttribEncSliceStructure;
1381 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1382 if (entrypoint == VAEntrypointEncSlice) {
1383 if ((profile == VAProfileH264ConstrainedBaseline ||
1384 profile == VAProfileH264Main ||
1385 profile == VAProfileH264High) ||
1386 profile == VAProfileH264StereoHigh ||
1387 profile == VAProfileH264MultiviewHigh) {
1388 attrib.value = VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS;
1392 if (attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1393 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1396 if ((vaStatus == VA_STATUS_SUCCESS) &&
1397 (profile == VAProfileVP9Profile0) &&
1398 (entrypoint == VAEntrypointVLD) &&
1399 !HAS_VP9_DECODING(i965)) {
1401 if (i965->wrapper_pdrvctx) {
1402 VAGenericID wrapper_config;
1404 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1405 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1406 entrypoint, attrib_list,
1407 num_attribs, &wrapper_config));
1409 if (vaStatus == VA_STATUS_SUCCESS)
1410 obj_config->wrapper_config = wrapper_config;
1414 /* Error recovery */
1415 if (VA_STATUS_SUCCESS != vaStatus) {
1416 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1418 *config_id = configID;
1425 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1427 struct i965_driver_data *i965 = i965_driver_data(ctx);
1428 struct object_config *obj_config = CONFIG(config_id);
1431 if (NULL == obj_config) {
1432 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1436 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1437 i965->wrapper_pdrvctx) {
1438 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1439 vaDestroyConfig(i965->wrapper_pdrvctx,
1440 obj_config->wrapper_config));
1441 obj_config->wrapper_config = VA_INVALID_ID;
1444 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1445 return VA_STATUS_SUCCESS;
1448 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1449 VAConfigID config_id,
1450 VAProfile *profile, /* out */
1451 VAEntrypoint *entrypoint, /* out */
1452 VAConfigAttrib *attrib_list, /* out */
1453 int *num_attribs) /* out */
1455 struct i965_driver_data *i965 = i965_driver_data(ctx);
1456 struct object_config *obj_config = CONFIG(config_id);
1457 VAStatus vaStatus = VA_STATUS_SUCCESS;
1460 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1461 *profile = obj_config->profile;
1462 *entrypoint = obj_config->entrypoint;
1463 *num_attribs = obj_config->num_attribs;
1465 for (i = 0; i < obj_config->num_attribs; i++) {
1466 attrib_list[i] = obj_config->attrib_list[i];
1473 i965_destroy_surface_storage(struct object_surface *obj_surface)
1478 dri_bo_unreference(obj_surface->bo);
1479 obj_surface->bo = NULL;
1481 if (obj_surface->free_private_data != NULL) {
1482 obj_surface->free_private_data(&obj_surface->private_data);
1483 obj_surface->private_data = NULL;
1488 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1490 struct object_surface *obj_surface = (struct object_surface *)obj;
1492 i965_destroy_surface_storage(obj_surface);
1493 object_heap_free(heap, obj);
1496 /* byte-per-pixel of the first plane */
1498 bpp_1stplane_by_fourcc(unsigned int fourcc)
1500 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1502 if (info && (info->flag & I_S))
1503 return info->bpp[0] / 8;
1509 i965_surface_native_memory(VADriverContextP ctx,
1510 struct object_surface *obj_surface,
1512 int expected_fourcc)
1514 struct i965_driver_data *i965 = i965_driver_data(ctx);
1515 int tiling = HAS_TILED_SURFACE(i965);
1517 if (!expected_fourcc)
1518 return VA_STATUS_SUCCESS;
1520 // todo, should we disable tiling for 422 format?
1521 if (expected_fourcc == VA_FOURCC_I420 ||
1522 expected_fourcc == VA_FOURCC_IYUV ||
1523 expected_fourcc == VA_FOURCC_I010 ||
1524 expected_fourcc == VA_FOURCC_YV12 ||
1525 expected_fourcc == VA_FOURCC_YV16)
1528 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1532 i965_suface_external_memory(VADriverContextP ctx,
1533 struct object_surface *obj_surface,
1534 int external_memory_type,
1535 VASurfaceAttribExternalBuffers *memory_attibute,
1538 struct i965_driver_data *i965 = i965_driver_data(ctx);
1539 unsigned int tiling, swizzle;
1541 if (!memory_attibute ||
1542 !memory_attibute->buffers ||
1543 index >= memory_attibute->num_buffers)
1544 return VA_STATUS_ERROR_INVALID_PARAMETER;
1546 obj_surface->size = memory_attibute->data_size;
1547 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1548 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1549 "gem flinked vaapi surface",
1550 memory_attibute->buffers[index]);
1551 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1552 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1553 memory_attibute->buffers[index],
1556 if (!obj_surface->bo)
1557 return VA_STATUS_ERROR_INVALID_PARAMETER;
1559 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
1561 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1562 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1563 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1565 obj_surface->fourcc = memory_attibute->pixel_format;
1566 obj_surface->width = memory_attibute->pitches[0];
1567 int bpp_1stplane = bpp_1stplane_by_fourcc(obj_surface->fourcc);
1568 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1569 ASSERT_RET(obj_surface->width >= obj_surface->orig_width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1571 if (memory_attibute->num_planes == 1)
1572 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1574 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1576 if (memory_attibute->num_planes > 1) {
1577 ASSERT_RET(obj_surface->height >= obj_surface->orig_height, VA_STATUS_ERROR_INVALID_PARAMETER);
1581 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1583 if (memory_attibute->num_planes > 1)
1584 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
1586 ASSERT_RET(IS_ALIGNED(obj_surface->width, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1588 if (memory_attibute->num_planes > 1)
1589 ASSERT_RET(IS_ALIGNED(obj_surface->height, i965->codec_info->min_linear_hpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1592 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1593 obj_surface->x_cr_offset = 0;
1594 if ((obj_surface->fourcc == VA_FOURCC_I420 ||
1595 obj_surface->fourcc == VA_FOURCC_IYUV ||
1596 obj_surface->fourcc == VA_FOURCC_I010 ||
1597 obj_surface->fourcc == VA_FOURCC_YV12 ||
1598 obj_surface->fourcc == VA_FOURCC_YV16) && tiling)
1599 return VA_STATUS_ERROR_INVALID_PARAMETER;
1601 switch (obj_surface->fourcc) {
1602 case VA_FOURCC_NV12:
1603 case VA_FOURCC_P010:
1604 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1605 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1607 obj_surface->subsampling = SUBSAMPLE_YUV420;
1608 obj_surface->y_cb_offset = obj_surface->height;
1609 obj_surface->y_cr_offset = obj_surface->height;
1610 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1611 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1612 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1614 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1616 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1620 case VA_FOURCC_YV12:
1621 case VA_FOURCC_IMC1:
1622 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1623 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1625 obj_surface->subsampling = SUBSAMPLE_YUV420;
1626 obj_surface->y_cr_offset = obj_surface->height;
1627 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1628 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1629 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1630 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1633 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1635 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1639 case VA_FOURCC_I420:
1640 case VA_FOURCC_IYUV:
1641 case VA_FOURCC_IMC3:
1642 case VA_FOURCC_I010:
1643 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1644 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1646 obj_surface->subsampling = SUBSAMPLE_YUV420;
1647 obj_surface->y_cb_offset = obj_surface->height;
1648 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1649 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1650 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1651 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1653 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1655 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1659 case VA_FOURCC_YUY2:
1660 case VA_FOURCC_UYVY:
1661 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1663 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1664 obj_surface->y_cb_offset = 0;
1665 obj_surface->y_cr_offset = 0;
1666 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1667 obj_surface->cb_cr_height = obj_surface->orig_height;
1668 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1672 case VA_FOURCC_RGBA:
1673 case VA_FOURCC_RGBX:
1674 case VA_FOURCC_BGRA:
1675 case VA_FOURCC_BGRX:
1676 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1678 obj_surface->subsampling = SUBSAMPLE_RGBX;
1679 obj_surface->y_cb_offset = 0;
1680 obj_surface->y_cr_offset = 0;
1681 obj_surface->cb_cr_width = 0;
1682 obj_surface->cb_cr_height = 0;
1683 obj_surface->cb_cr_pitch = 0;
1687 case VA_FOURCC_Y800: /* monochrome surface */
1688 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1690 obj_surface->subsampling = SUBSAMPLE_YUV400;
1691 obj_surface->y_cb_offset = 0;
1692 obj_surface->y_cr_offset = 0;
1693 obj_surface->cb_cr_width = 0;
1694 obj_surface->cb_cr_height = 0;
1695 obj_surface->cb_cr_pitch = 0;
1699 case VA_FOURCC_411P:
1700 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1701 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1703 obj_surface->subsampling = SUBSAMPLE_YUV411;
1704 obj_surface->y_cb_offset = obj_surface->height;
1705 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1706 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1707 obj_surface->cb_cr_height = obj_surface->orig_height;
1708 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1710 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1712 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1715 case VA_FOURCC_422H:
1716 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1717 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1719 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1720 obj_surface->y_cb_offset = obj_surface->height;
1721 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1722 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1723 obj_surface->cb_cr_height = obj_surface->orig_height;
1724 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1726 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1728 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1732 case VA_FOURCC_YV16:
1733 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1734 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1736 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1737 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1738 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1739 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1740 obj_surface->cb_cr_height = obj_surface->orig_height;
1741 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1742 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1746 case VA_FOURCC_422V:
1747 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1748 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1750 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1751 obj_surface->y_cb_offset = obj_surface->height;
1752 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1753 obj_surface->cb_cr_width = obj_surface->orig_width;
1754 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1755 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1757 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1759 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1763 case VA_FOURCC_444P:
1764 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1765 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1767 obj_surface->subsampling = SUBSAMPLE_YUV444;
1768 obj_surface->y_cb_offset = obj_surface->height;
1769 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1770 obj_surface->cb_cr_width = obj_surface->orig_width;
1771 obj_surface->cb_cr_height = obj_surface->orig_height;
1772 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1774 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
1776 ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch, i965->codec_info->min_linear_wpitch), VA_STATUS_ERROR_INVALID_PARAMETER);
1781 return VA_STATUS_ERROR_INVALID_PARAMETER;
1784 return VA_STATUS_SUCCESS;
1788 i965_CreateSurfaces2(
1789 VADriverContextP ctx,
1790 unsigned int format,
1792 unsigned int height,
1793 VASurfaceID *surfaces,
1794 unsigned int num_surfaces,
1795 VASurfaceAttrib *attrib_list,
1796 unsigned int num_attribs
1799 struct i965_driver_data *i965 = i965_driver_data(ctx);
1801 VAStatus vaStatus = VA_STATUS_SUCCESS;
1802 int expected_fourcc = 0;
1803 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1804 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1806 for (i = 0; i < num_attribs && attrib_list; i++) {
1807 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1808 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1809 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1810 expected_fourcc = attrib_list[i].value.value.i;
1813 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1814 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1816 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1818 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1819 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1820 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1821 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1822 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1823 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1826 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1827 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1828 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1829 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1833 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1834 * for post-processing (including color conversion) */
1835 if (VA_RT_FORMAT_YUV420 != format &&
1836 VA_RT_FORMAT_YUV420_10BPP != format &&
1837 VA_RT_FORMAT_YUV422 != format &&
1838 VA_RT_FORMAT_YUV444 != format &&
1839 VA_RT_FORMAT_YUV411 != format &&
1840 VA_RT_FORMAT_YUV400 != format &&
1841 VA_RT_FORMAT_RGB32 != format) {
1842 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1845 for (i = 0; i < num_surfaces; i++) {
1846 int surfaceID = NEW_SURFACE_ID();
1847 struct object_surface *obj_surface = SURFACE(surfaceID);
1849 if (NULL == obj_surface) {
1850 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1854 surfaces[i] = surfaceID;
1855 obj_surface->status = VASurfaceReady;
1856 obj_surface->orig_width = width;
1857 obj_surface->orig_height = height;
1858 obj_surface->user_disable_tiling = false;
1859 obj_surface->user_h_stride_set = false;
1860 obj_surface->user_v_stride_set = false;
1861 obj_surface->border_cleared = false;
1863 obj_surface->subpic_render_idx = 0;
1864 for (j = 0; j < I965_MAX_SUBPIC_SUM; j++) {
1865 obj_surface->subpic[j] = VA_INVALID_ID;
1866 obj_surface->obj_subpic[j] = NULL;
1869 assert(i965->codec_info->min_linear_wpitch);
1870 assert(i965->codec_info->min_linear_hpitch);
1871 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1872 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1873 obj_surface->flags = SURFACE_REFERENCED;
1874 obj_surface->fourcc = 0;
1875 obj_surface->expected_format = format;
1876 obj_surface->bo = NULL;
1877 obj_surface->locked_image_id = VA_INVALID_ID;
1878 obj_surface->derived_image_id = VA_INVALID_ID;
1879 obj_surface->private_data = NULL;
1880 obj_surface->free_private_data = NULL;
1881 obj_surface->subsampling = SUBSAMPLE_YUV420;
1883 obj_surface->wrapper_surface = VA_INVALID_ID;
1884 obj_surface->exported_primefd = -1;
1886 switch (memory_type) {
1887 case I965_SURFACE_MEM_NATIVE:
1888 if (memory_attibute) {
1889 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1890 obj_surface->user_disable_tiling = true;
1892 if (memory_attibute->pixel_format) {
1893 if (expected_fourcc)
1894 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1896 expected_fourcc = memory_attibute->pixel_format;
1898 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1899 if (memory_attibute->pitches[0]) {
1900 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1901 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1902 obj_surface->width = memory_attibute->pitches[0];
1903 obj_surface->user_h_stride_set = true;
1904 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1905 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1907 if (memory_attibute->offsets[1]) {
1908 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1909 obj_surface->height = memory_attibute->offsets[1] / memory_attibute->pitches[0];
1910 obj_surface->user_v_stride_set = true;
1911 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1912 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1916 vaStatus = i965_surface_native_memory(ctx,
1922 case I965_SURFACE_MEM_GEM_FLINK:
1923 case I965_SURFACE_MEM_DRM_PRIME:
1924 vaStatus = i965_suface_external_memory(ctx,
1931 if (VA_STATUS_SUCCESS != vaStatus) {
1932 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1937 /* Error recovery */
1938 if (VA_STATUS_SUCCESS != vaStatus) {
1939 /* surfaces[i-1] was the last successful allocation */
1941 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1943 surfaces[i] = VA_INVALID_SURFACE;
1944 assert(obj_surface);
1945 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1953 i965_CreateSurfaces(VADriverContextP ctx,
1958 VASurfaceID *surfaces) /* out */
1960 return i965_CreateSurfaces2(ctx,
1971 i965_DestroySurfaces(VADriverContextP ctx,
1972 VASurfaceID *surface_list,
1975 struct i965_driver_data *i965 = i965_driver_data(ctx);
1977 VAStatus va_status = VA_STATUS_SUCCESS;
1979 for (i = num_surfaces; i--;) {
1980 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1982 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1984 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1985 i965->wrapper_pdrvctx) {
1986 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1987 vaDestroySurfaces(i965->wrapper_pdrvctx,
1988 &(obj_surface->wrapper_surface),
1990 obj_surface->wrapper_surface = VA_INVALID_ID;
1992 if (obj_surface->exported_primefd >= 0) {
1993 close(obj_surface->exported_primefd);
1994 obj_surface->exported_primefd = -1;
1997 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
2004 i965_QueryImageFormats(VADriverContextP ctx,
2005 VAImageFormat *format_list, /* out */
2006 int *num_formats) /* out */
2010 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
2011 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
2013 format_list[n] = m->va_format;
2019 return VA_STATUS_SUCCESS;
2023 * Guess the format when the usage of a VA surface is unknown
2024 * 1. Without a valid context: YV12
2025 * 2. The current context is valid:
2026 * a) always NV12 on GEN6 and later
2027 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
2030 i965_guess_surface_format(VADriverContextP ctx,
2031 VASurfaceID surface,
2032 unsigned int *fourcc,
2033 unsigned int *is_tiled)
2035 struct i965_driver_data *i965 = i965_driver_data(ctx);
2036 struct object_context *obj_context = NULL;
2037 struct object_config *obj_config = NULL;
2039 *fourcc = VA_FOURCC_YV12;
2042 if (i965->current_context_id == VA_INVALID_ID)
2045 obj_context = CONTEXT(i965->current_context_id);
2050 obj_config = obj_context->obj_config;
2056 if (IS_GEN6(i965->intel.device_info) ||
2057 IS_GEN7(i965->intel.device_info) ||
2058 IS_GEN8(i965->intel.device_info) ||
2059 IS_GEN9(i965->intel.device_info)) {
2060 *fourcc = VA_FOURCC_NV12;
2065 switch (obj_config->profile) {
2066 case VAProfileMPEG2Simple:
2067 case VAProfileMPEG2Main:
2068 *fourcc = VA_FOURCC_I420;
2073 *fourcc = VA_FOURCC_NV12;
2080 i965_QuerySubpictureFormats(VADriverContextP ctx,
2081 VAImageFormat *format_list, /* out */
2082 unsigned int *flags, /* out */
2083 unsigned int *num_formats) /* out */
2087 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
2088 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
2090 format_list[n] = m->va_format;
2092 flags[n] = m->va_flags;
2098 return VA_STATUS_SUCCESS;
2102 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
2104 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
2106 object_heap_free(heap, obj);
2110 i965_CreateSubpicture(VADriverContextP ctx,
2112 VASubpictureID *subpicture) /* out */
2114 struct i965_driver_data *i965 = i965_driver_data(ctx);
2115 VASubpictureID subpicID = NEW_SUBPIC_ID()
2116 struct object_subpic * obj_subpic = SUBPIC(subpicID);
2119 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2121 struct object_image *obj_image = IMAGE(image);
2123 return VA_STATUS_ERROR_INVALID_IMAGE;
2125 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
2127 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
2129 *subpicture = subpicID;
2130 obj_subpic->image = image;
2131 obj_subpic->obj_image = obj_image;
2132 obj_subpic->format = m->format;
2133 obj_subpic->width = obj_image->image.width;
2134 obj_subpic->height = obj_image->image.height;
2135 obj_subpic->pitch = obj_image->image.pitches[0];
2136 obj_subpic->bo = obj_image->bo;
2137 obj_subpic->global_alpha = 1.0;
2139 return VA_STATUS_SUCCESS;
2143 i965_DestroySubpicture(VADriverContextP ctx,
2144 VASubpictureID subpicture)
2146 struct i965_driver_data *i965 = i965_driver_data(ctx);
2147 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2150 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2152 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2153 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
2154 return VA_STATUS_SUCCESS;
2158 i965_SetSubpictureImage(VADriverContextP ctx,
2159 VASubpictureID subpicture,
2163 return VA_STATUS_ERROR_UNIMPLEMENTED;
2167 i965_SetSubpictureChromakey(VADriverContextP ctx,
2168 VASubpictureID subpicture,
2169 unsigned int chromakey_min,
2170 unsigned int chromakey_max,
2171 unsigned int chromakey_mask)
2174 return VA_STATUS_ERROR_UNIMPLEMENTED;
2178 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
2179 VASubpictureID subpicture,
2182 struct i965_driver_data *i965 = i965_driver_data(ctx);
2183 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2185 if (global_alpha > 1.0 || global_alpha < 0.0) {
2186 return VA_STATUS_ERROR_INVALID_PARAMETER;
2190 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2192 obj_subpic->global_alpha = global_alpha;
2194 return VA_STATUS_SUCCESS;
2198 i965_AssociateSubpicture(VADriverContextP ctx,
2199 VASubpictureID subpicture,
2200 VASurfaceID *target_surfaces,
2202 short src_x, /* upper left offset in subpicture */
2204 unsigned short src_width,
2205 unsigned short src_height,
2206 short dest_x, /* upper left offset in surface */
2208 unsigned short dest_width,
2209 unsigned short dest_height,
2211 * whether to enable chroma-keying or global-alpha
2212 * see VA_SUBPICTURE_XXX values
2216 struct i965_driver_data *i965 = i965_driver_data(ctx);
2217 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2221 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2223 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2225 obj_subpic->src_rect.x = src_x;
2226 obj_subpic->src_rect.y = src_y;
2227 obj_subpic->src_rect.width = src_width;
2228 obj_subpic->src_rect.height = src_height;
2229 obj_subpic->dst_rect.x = dest_x;
2230 obj_subpic->dst_rect.y = dest_y;
2231 obj_subpic->dst_rect.width = dest_width;
2232 obj_subpic->dst_rect.height = dest_height;
2233 obj_subpic->flags = flags;
2235 for (i = 0; i < num_surfaces; i++) {
2236 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2238 return VA_STATUS_ERROR_INVALID_SURFACE;
2240 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2241 if (obj_surface->subpic[j] == VA_INVALID_ID) {
2242 assert(obj_surface->obj_subpic[j] == NULL);
2243 obj_surface->subpic[j] = subpicture;
2244 obj_surface->obj_subpic[j] = obj_subpic;
2249 if (j == I965_MAX_SUBPIC_SUM) {
2250 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2254 return VA_STATUS_SUCCESS;
2259 i965_DeassociateSubpicture(VADriverContextP ctx,
2260 VASubpictureID subpicture,
2261 VASurfaceID *target_surfaces,
2264 struct i965_driver_data *i965 = i965_driver_data(ctx);
2265 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2269 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2271 for (i = 0; i < num_surfaces; i++) {
2272 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2274 return VA_STATUS_ERROR_INVALID_SURFACE;
2276 for (j = 0; j < I965_MAX_SUBPIC_SUM; j ++) {
2277 if (obj_surface->subpic[j] == subpicture) {
2278 assert(obj_surface->obj_subpic[j] == obj_subpic);
2279 obj_surface->subpic[j] = VA_INVALID_ID;
2280 obj_surface->obj_subpic[j] = NULL;
2285 if (j == I965_MAX_SUBPIC_SUM) {
2286 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2289 return VA_STATUS_SUCCESS;
2293 i965_reference_buffer_store(struct buffer_store **ptr,
2294 struct buffer_store *buffer_store)
2296 assert(*ptr == NULL);
2299 buffer_store->ref_count++;
2300 *ptr = buffer_store;
2305 i965_release_buffer_store(struct buffer_store **ptr)
2307 struct buffer_store *buffer_store = *ptr;
2309 if (buffer_store == NULL)
2312 assert(buffer_store->bo || buffer_store->buffer);
2313 assert(!(buffer_store->bo && buffer_store->buffer));
2314 buffer_store->ref_count--;
2316 if (buffer_store->ref_count == 0) {
2317 dri_bo_unreference(buffer_store->bo);
2318 free(buffer_store->buffer);
2319 buffer_store->bo = NULL;
2320 buffer_store->buffer = NULL;
2328 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2330 struct object_context *obj_context = (struct object_context *)obj;
2333 if (obj_context->hw_context) {
2334 obj_context->hw_context->destroy(obj_context->hw_context);
2335 obj_context->hw_context = NULL;
2338 if (obj_context->codec_type == CODEC_PROC) {
2339 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2341 } else if (obj_context->codec_type == CODEC_ENC) {
2342 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2343 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2345 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2346 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2347 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2349 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2350 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2352 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2353 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2355 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2356 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2357 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2359 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2360 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2362 free(obj_context->codec_state.encode.slice_params_ext);
2363 if (obj_context->codec_state.encode.slice_rawdata_index) {
2364 free(obj_context->codec_state.encode.slice_rawdata_index);
2365 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2367 if (obj_context->codec_state.encode.slice_rawdata_count) {
2368 free(obj_context->codec_state.encode.slice_rawdata_count);
2369 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2372 if (obj_context->codec_state.encode.slice_header_index) {
2373 free(obj_context->codec_state.encode.slice_header_index);
2374 obj_context->codec_state.encode.slice_header_index = NULL;
2377 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2378 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2379 free(obj_context->codec_state.encode.packed_header_params_ext);
2381 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2382 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2383 free(obj_context->codec_state.encode.packed_header_data_ext);
2385 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2387 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2388 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2390 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2391 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2392 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2393 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2395 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2396 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2398 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2399 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2401 free(obj_context->codec_state.decode.slice_params);
2402 free(obj_context->codec_state.decode.slice_datas);
2405 free(obj_context->render_targets);
2406 object_heap_free(heap, obj);
2410 max_resolution(struct i965_driver_data *i965,
2411 struct object_config *obj_config,
2415 if (i965->codec_info->max_resolution) {
2416 i965->codec_info->max_resolution(i965, obj_config, w, h);
2418 *w = i965->codec_info->max_width;
2419 *h = i965->codec_info->max_height;
2424 i965_CreateContext(VADriverContextP ctx,
2425 VAConfigID config_id,
2429 VASurfaceID *render_targets,
2430 int num_render_targets,
2431 VAContextID *context) /* out */
2433 struct i965_driver_data *i965 = i965_driver_data(ctx);
2434 struct object_config *obj_config = CONFIG(config_id);
2435 struct object_context *obj_context = NULL;
2436 VAConfigAttrib *attrib;
2437 VAStatus vaStatus = VA_STATUS_SUCCESS;
2443 if (NULL == obj_config) {
2444 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2448 max_resolution(i965, obj_config, &max_width, &max_height);
2450 if (picture_width > max_width ||
2451 picture_height > max_height) {
2452 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2457 /* Validate picture dimensions */
2458 contextID = NEW_CONTEXT_ID();
2459 obj_context = CONTEXT(contextID);
2461 if (NULL == obj_context) {
2462 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2466 *context = contextID;
2467 obj_context->flags = flag;
2468 obj_context->context_id = contextID;
2469 obj_context->obj_config = obj_config;
2470 obj_context->picture_width = picture_width;
2471 obj_context->picture_height = picture_height;
2472 obj_context->num_render_targets = num_render_targets;
2473 obj_context->render_targets =
2474 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2475 obj_context->hw_context = NULL;
2476 obj_context->wrapper_context = VA_INVALID_ID;
2478 if (!obj_context->render_targets)
2479 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2481 for (i = 0; i < num_render_targets; i++) {
2482 if (NULL == SURFACE(render_targets[i])) {
2483 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2487 obj_context->render_targets[i] = render_targets[i];
2490 if (VA_STATUS_SUCCESS == vaStatus) {
2491 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2492 obj_context->codec_type = CODEC_PROC;
2493 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2494 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2495 assert(i965->codec_info->proc_hw_context_init);
2496 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2497 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2498 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2499 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
2500 (VAEntrypointFEI == obj_config->entrypoint)) {
2501 VAConfigAttrib *packed_attrib;
2502 obj_context->codec_type = CODEC_ENC;
2503 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2504 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2505 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2506 obj_context->codec_state.encode.packed_header_params_ext =
2507 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2508 sizeof(struct buffer_store *));
2510 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2511 obj_context->codec_state.encode.packed_header_data_ext =
2512 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2513 sizeof(struct buffer_store *));
2515 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2516 obj_context->codec_state.encode.slice_rawdata_index =
2517 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2518 obj_context->codec_state.encode.slice_rawdata_count =
2519 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2521 obj_context->codec_state.encode.slice_header_index =
2522 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2524 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2526 obj_context->codec_state.encode.slice_index = 0;
2527 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2528 if (packed_attrib) {
2529 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2530 if (obj_config->profile == VAProfileVP9Profile0)
2531 obj_context->codec_state.encode.packed_header_flag =
2532 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2534 /* use the default value. SPS/PPS/RAWDATA is passed from user
2535 * while Slice_header data is generated by driver.
2537 obj_context->codec_state.encode.packed_header_flag =
2538 VA_ENC_PACKED_HEADER_SEQUENCE |
2539 VA_ENC_PACKED_HEADER_PICTURE |
2540 VA_ENC_PACKED_HEADER_RAW_DATA;
2542 /* it is not used for VP9 */
2543 if (obj_config->profile == VAProfileVP9Profile0)
2544 obj_context->codec_state.encode.packed_header_flag = 0;
2546 assert(i965->codec_info->enc_hw_context_init);
2547 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2549 obj_context->codec_type = CODEC_DEC;
2550 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2551 obj_context->codec_state.decode.current_render_target = -1;
2552 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2553 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2554 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2555 sizeof(*obj_context->codec_state.decode.slice_params));
2556 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2557 sizeof(*obj_context->codec_state.decode.slice_datas));
2559 assert(i965->codec_info->dec_hw_context_init);
2560 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2564 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2566 return VA_STATUS_ERROR_INVALID_CONFIG;
2567 obj_context->codec_state.base.chroma_formats = attrib->value;
2569 if (obj_config->wrapper_config != VA_INVALID_ID) {
2570 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2571 * So it won't check i965->wrapper_pdrvctx again.
2572 * Fixme if it is incorrect.
2574 VAGenericID wrapper_context;
2577 * The render_surface is not passed when calling
2579 * If it is needed, we must get the wrapped surface
2580 * for the corresponding Surface_list.
2581 * So the wrapped surface conversion is deferred.
2583 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2584 vaCreateContext(i965->wrapper_pdrvctx,
2585 obj_config->wrapper_config,
2586 picture_width, picture_height,
2590 if (vaStatus == VA_STATUS_SUCCESS)
2591 obj_context->wrapper_context = wrapper_context;
2593 /* Error recovery */
2594 if (VA_STATUS_SUCCESS != vaStatus) {
2595 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2598 i965->current_context_id = contextID;
2604 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2606 struct i965_driver_data *i965 = i965_driver_data(ctx);
2607 struct object_context *obj_context = CONTEXT(context);
2608 VAStatus va_status = VA_STATUS_SUCCESS;
2610 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2612 if (i965->current_context_id == context)
2613 i965->current_context_id = VA_INVALID_ID;
2615 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2616 i965->wrapper_pdrvctx) {
2617 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2618 vaDestroyContext(i965->wrapper_pdrvctx,
2619 obj_context->wrapper_context));
2621 obj_context->wrapper_context = VA_INVALID_ID;
2624 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2630 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2632 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2634 assert(obj_buffer->buffer_store);
2635 i965_release_buffer_store(&obj_buffer->buffer_store);
2636 object_heap_free(heap, obj);
2640 i965_create_buffer_internal(VADriverContextP ctx,
2641 VAContextID context,
2644 unsigned int num_elements,
2649 struct i965_driver_data *i965 = i965_driver_data(ctx);
2650 struct object_buffer *obj_buffer = NULL;
2651 struct buffer_store *buffer_store = NULL;
2653 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2654 struct object_context *obj_context = CONTEXT(context);
2655 int wrapper_flag = 0;
2659 case VAPictureParameterBufferType:
2660 case VAIQMatrixBufferType:
2661 case VAQMatrixBufferType:
2662 case VABitPlaneBufferType:
2663 case VASliceGroupMapBufferType:
2664 case VASliceParameterBufferType:
2665 case VASliceDataBufferType:
2666 case VAMacroblockParameterBufferType:
2667 case VAResidualDataBufferType:
2668 case VADeblockingParameterBufferType:
2669 case VAImageBufferType:
2670 case VAEncCodedBufferType:
2671 case VAEncSequenceParameterBufferType:
2672 case VAEncPictureParameterBufferType:
2673 case VAEncSliceParameterBufferType:
2674 case VAEncPackedHeaderParameterBufferType:
2675 case VAEncPackedHeaderDataBufferType:
2676 case VAEncMiscParameterBufferType:
2677 case VAProcPipelineParameterBufferType:
2678 case VAProcFilterParameterBufferType:
2679 case VAHuffmanTableBufferType:
2680 case VAProbabilityBufferType:
2681 case VAEncMacroblockMapBufferType:
2682 case VAEncQPBufferType:
2683 case VAEncFEIMVBufferType:
2684 case VAEncFEIMBCodeBufferType:
2685 case VAEncFEIDistortionBufferType:
2686 case VAEncFEIMBControlBufferType:
2687 case VAEncFEIMVPredictorBufferType:
2692 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2695 bufferID = NEW_BUFFER_ID();
2696 obj_buffer = BUFFER(bufferID);
2698 if (NULL == obj_buffer) {
2699 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2702 if (type == VAEncCodedBufferType) {
2703 size += I965_CODEDBUFFER_HEADER_SIZE;
2704 size += 0x1000; /* for upper bound check */
2707 obj_buffer->max_num_elements = num_elements;
2708 obj_buffer->num_elements = num_elements;
2709 obj_buffer->size_element = size;
2710 obj_buffer->type = type;
2711 obj_buffer->export_refcount = 0;
2712 obj_buffer->buffer_store = NULL;
2713 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2714 obj_buffer->context_id = context;
2716 buffer_store = calloc(1, sizeof(struct buffer_store));
2717 assert(buffer_store);
2718 buffer_store->ref_count = 1;
2721 (obj_context->wrapper_context != VA_INVALID_ID) &&
2722 i965->wrapper_pdrvctx) {
2723 VAGenericID wrapper_buffer;
2724 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2726 CALL_VTABLE(pdrvctx, vaStatus,
2727 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2728 data, &wrapper_buffer));
2729 if (vaStatus == VA_STATUS_SUCCESS) {
2730 obj_buffer->wrapper_buffer = wrapper_buffer;
2738 if (store_bo != NULL) {
2739 buffer_store->bo = store_bo;
2740 dri_bo_reference(buffer_store->bo);
2742 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2743 if (data && !wrapper_flag)
2744 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2745 } else if (type == VASliceDataBufferType ||
2746 type == VAImageBufferType ||
2747 type == VAEncCodedBufferType ||
2748 type == VAEncMacroblockMapBufferType ||
2749 type == VAProbabilityBufferType ||
2750 type == VAEncQPBufferType ||
2751 type == VAEncFEIMVBufferType ||
2752 type == VAEncFEIMBCodeBufferType ||
2753 type == VAEncFEIDistortionBufferType ||
2754 type == VAEncFEIMBControlBufferType ||
2755 type == VAEncFEIMVPredictorBufferType) {
2757 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2758 * So it is enough to allocate one 64 byte bo
2761 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2764 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2766 size * num_elements, 64);
2767 assert(buffer_store->bo);
2769 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2770 * In fact it can be skipped. But it is still allocated and it is
2771 * only to follow the normal flowchart of buffer_allocation/release.
2773 if (!wrapper_flag) {
2774 if (type == VAEncCodedBufferType) {
2775 struct i965_coded_buffer_segment *coded_buffer_segment;
2777 dri_bo_map(buffer_store->bo, 1);
2778 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2779 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2780 coded_buffer_segment->base.bit_offset = 0;
2781 coded_buffer_segment->base.status = 0;
2782 coded_buffer_segment->base.buf = NULL;
2783 coded_buffer_segment->base.next = NULL;
2784 coded_buffer_segment->mapped = 0;
2785 coded_buffer_segment->codec = 0;
2786 coded_buffer_segment->status_support = 0;
2787 dri_bo_unmap(buffer_store->bo);
2789 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2796 if (type == VAEncPackedHeaderDataBufferType) {
2797 msize = ALIGN(size, 4);
2800 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2802 buffer_store->buffer = malloc(4);
2804 buffer_store->buffer = malloc(msize * num_elements);
2805 assert(buffer_store->buffer);
2807 if (!wrapper_flag) {
2809 memcpy(buffer_store->buffer, data, size * num_elements);
2811 memset(buffer_store->buffer, 0, size * num_elements);
2815 buffer_store->num_elements = obj_buffer->num_elements;
2816 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2817 i965_release_buffer_store(&buffer_store);
2820 return VA_STATUS_SUCCESS;
2824 i965_CreateBuffer(VADriverContextP ctx,
2825 VAContextID context, /* in */
2826 VABufferType type, /* in */
2827 unsigned int size, /* in */
2828 unsigned int num_elements, /* in */
2829 void *data, /* in */
2830 VABufferID *buf_id) /* out */
2832 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2837 i965_BufferSetNumElements(VADriverContextP ctx,
2838 VABufferID buf_id, /* in */
2839 unsigned int num_elements) /* in */
2841 struct i965_driver_data *i965 = i965_driver_data(ctx);
2842 struct object_buffer *obj_buffer = BUFFER(buf_id);
2843 VAStatus vaStatus = VA_STATUS_SUCCESS;
2845 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2847 /* When the wrapper_buffer exists, it will wrapper to the
2848 * buffer allocated from backend driver.
2850 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2851 i965->wrapper_pdrvctx) {
2852 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2854 CALL_VTABLE(pdrvctx, vaStatus,
2855 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2860 if ((num_elements < 0) ||
2861 (num_elements > obj_buffer->max_num_elements)) {
2862 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2864 obj_buffer->num_elements = num_elements;
2865 if (obj_buffer->buffer_store != NULL) {
2866 obj_buffer->buffer_store->num_elements = num_elements;
2874 i965_MapBuffer(VADriverContextP ctx,
2875 VABufferID buf_id, /* in */
2876 void **pbuf) /* out */
2878 struct i965_driver_data *i965 = i965_driver_data(ctx);
2879 struct object_buffer *obj_buffer = BUFFER(buf_id);
2880 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2881 struct object_context *obj_context;
2883 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2885 obj_context = CONTEXT(obj_buffer->context_id);
2887 /* When the wrapper_buffer exists, it will wrapper to the
2888 * buffer allocated from backend driver.
2890 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2891 i965->wrapper_pdrvctx) {
2892 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2894 CALL_VTABLE(pdrvctx, vaStatus,
2895 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2899 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2900 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2902 if (obj_buffer->export_refcount > 0)
2903 return VA_STATUS_ERROR_INVALID_BUFFER;
2905 if (NULL != obj_buffer->buffer_store->bo) {
2906 unsigned int tiling, swizzle;
2908 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2910 if (tiling != I915_TILING_NONE)
2911 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2913 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2915 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2916 *pbuf = obj_buffer->buffer_store->bo->virtual;
2917 vaStatus = VA_STATUS_SUCCESS;
2919 if (obj_buffer->type == VAEncCodedBufferType) {
2921 unsigned char *buffer = NULL;
2922 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2923 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2925 if (!coded_buffer_segment->mapped) {
2926 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2928 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2931 obj_context->hw_context &&
2932 obj_context->hw_context->get_status &&
2933 coded_buffer_segment->status_support) {
2934 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2936 if (coded_buffer_segment->codec == CODEC_H264 ||
2937 coded_buffer_segment->codec == CODEC_H264_MVC) {
2938 delimiter0 = H264_DELIMITER0;
2939 delimiter1 = H264_DELIMITER1;
2940 delimiter2 = H264_DELIMITER2;
2941 delimiter3 = H264_DELIMITER3;
2942 delimiter4 = H264_DELIMITER4;
2943 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2944 delimiter0 = MPEG2_DELIMITER0;
2945 delimiter1 = MPEG2_DELIMITER1;
2946 delimiter2 = MPEG2_DELIMITER2;
2947 delimiter3 = MPEG2_DELIMITER3;
2948 delimiter4 = MPEG2_DELIMITER4;
2949 } else if (coded_buffer_segment->codec == CODEC_JPEG) {
2950 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2953 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2954 delimiter0 = HEVC_DELIMITER0;
2955 delimiter1 = HEVC_DELIMITER1;
2956 delimiter2 = HEVC_DELIMITER2;
2957 delimiter3 = HEVC_DELIMITER3;
2958 delimiter4 = HEVC_DELIMITER4;
2959 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2960 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2963 if (coded_buffer_segment->codec == CODEC_JPEG) {
2964 for (i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2965 if ((buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2969 coded_buffer_segment->base.size = i + 2;
2970 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2971 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2972 so it don't need to traversal the coded buffer */
2973 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2974 if ((buffer[i] == delimiter0) &&
2975 (buffer[i + 1] == delimiter1) &&
2976 (buffer[i + 2] == delimiter2) &&
2977 (buffer[i + 3] == delimiter3) &&
2978 (buffer[i + 4] == delimiter4))
2982 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2983 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2985 coded_buffer_segment->base.size = i;
2988 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2989 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2992 vaStatus = VA_STATUS_SUCCESS;
2995 coded_buffer_segment->mapped = 1;
2997 assert(coded_buffer_segment->base.buf);
2998 vaStatus = VA_STATUS_SUCCESS;
3001 } else if (NULL != obj_buffer->buffer_store->buffer) {
3002 *pbuf = obj_buffer->buffer_store->buffer;
3003 vaStatus = VA_STATUS_SUCCESS;
3010 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
3012 struct i965_driver_data *i965 = i965_driver_data(ctx);
3013 struct object_buffer *obj_buffer = BUFFER(buf_id);
3014 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3016 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
3017 return VA_STATUS_ERROR_INVALID_BUFFER;
3019 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
3020 /* When the wrapper_buffer exists, it will wrapper to the
3021 * buffer allocated from backend driver.
3023 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
3024 i965->wrapper_pdrvctx) {
3025 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
3027 CALL_VTABLE(pdrvctx, vaStatus,
3028 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3032 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
3033 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
3035 if (NULL != obj_buffer->buffer_store->bo) {
3036 unsigned int tiling, swizzle;
3038 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
3040 if (tiling != I915_TILING_NONE)
3041 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
3043 dri_bo_unmap(obj_buffer->buffer_store->bo);
3045 vaStatus = VA_STATUS_SUCCESS;
3046 } else if (NULL != obj_buffer->buffer_store->buffer) {
3048 vaStatus = VA_STATUS_SUCCESS;
3055 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
3057 struct i965_driver_data *i965 = i965_driver_data(ctx);
3058 struct object_buffer *obj_buffer = BUFFER(buffer_id);
3059 VAStatus va_status = VA_STATUS_SUCCESS;
3061 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3063 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
3064 i965->wrapper_pdrvctx) {
3065 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
3066 vaDestroyBuffer(i965->wrapper_pdrvctx,
3067 obj_buffer->wrapper_buffer));
3068 obj_buffer->wrapper_buffer = VA_INVALID_ID;
3071 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
3077 i965_BeginPicture(VADriverContextP ctx,
3078 VAContextID context,
3079 VASurfaceID render_target)
3081 struct i965_driver_data *i965 = i965_driver_data(ctx);
3082 struct object_context *obj_context = CONTEXT(context);
3083 struct object_surface *obj_surface = SURFACE(render_target);
3084 struct object_config *obj_config;
3085 VAStatus vaStatus = VA_STATUS_SUCCESS;
3088 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3089 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3090 obj_config = obj_context->obj_config;
3091 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3093 if (is_surface_busy(i965, obj_surface))
3094 return VA_STATUS_ERROR_SURFACE_BUSY;
3096 if (obj_context->codec_type == CODEC_PROC) {
3097 obj_context->codec_state.proc.current_render_target = render_target;
3098 } else if (obj_context->codec_type == CODEC_ENC) {
3100 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
3102 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
3103 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
3105 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
3106 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
3108 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
3109 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
3111 obj_context->codec_state.encode.num_slice_params_ext = 0;
3112 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
3113 obj_context->codec_state.encode.last_packed_header_type = 0;
3114 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
3115 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3116 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
3117 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3118 memset(obj_context->codec_state.encode.slice_header_index, 0,
3119 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
3121 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
3122 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
3123 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
3124 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
3125 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
3126 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
3127 obj_context->codec_state.encode.slice_index = 0;
3128 obj_context->codec_state.encode.vps_sps_seq_index = 0;
3130 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
3131 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
3132 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
3134 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
3136 obj_context->codec_state.decode.current_render_target = render_target;
3137 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
3138 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
3139 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
3140 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
3142 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
3143 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
3144 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
3147 obj_context->codec_state.decode.num_slice_params = 0;
3148 obj_context->codec_state.decode.num_slice_datas = 0;
3150 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
3151 i965->wrapper_pdrvctx) {
3152 if (obj_surface->wrapper_surface == VA_INVALID_ID)
3153 vaStatus = i965_surface_wrapper(ctx, render_target);
3155 if (vaStatus != VA_STATUS_SUCCESS)
3158 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
3159 vaBeginPicture(i965->wrapper_pdrvctx,
3160 obj_context->wrapper_context,
3161 obj_surface->wrapper_surface));
3168 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
3170 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
3172 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3173 struct object_context *obj_context, \
3174 struct object_buffer *obj_buffer) \
3176 struct category##_state *category = &obj_context->codec_state.category; \
3177 i965_release_buffer_store(&category->member); \
3178 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
3179 return VA_STATUS_SUCCESS; \
3182 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
3184 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
3185 struct object_context *obj_context, \
3186 struct object_buffer *obj_buffer) \
3188 struct category##_state *category = &obj_context->codec_state.category; \
3189 if (category->num_##member == category->max_##member) { \
3190 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
3191 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
3192 category->max_##member += NUM_SLICES; \
3194 i965_release_buffer_store(&category->member[category->num_##member]); \
3195 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
3196 category->num_##member++; \
3197 return VA_STATUS_SUCCESS; \
3200 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
3202 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
3203 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3204 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
3205 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
3206 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3207 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
3209 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
3210 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3211 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
3215 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
3216 VABufferID *buffers,
3219 struct i965_driver_data *i965 = i965_driver_data(ctx);
3220 VAStatus vaStatus = VA_STATUS_SUCCESS;
3222 VADecPictureParameterBufferVP9 *pVp9PicParams;
3223 VADriverContextP pdrvctx;
3224 struct object_buffer *obj_buffer;
3226 pdrvctx = i965->wrapper_pdrvctx;
3227 /* do the conversion of VADecPictureParameterBufferVP9 */
3228 for (i = 0; i < num_buffers; i++) {
3229 obj_buffer = BUFFER(buffers[i]);
3234 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
3237 if (obj_buffer->type == VAPictureParameterBufferType) {
3239 VASurfaceID surface_id;
3240 struct object_surface *obj_surface;
3242 pdrvctx = i965->wrapper_pdrvctx;
3244 CALL_VTABLE(pdrvctx, vaStatus,
3245 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
3246 (void **)(&pVp9PicParams)));
3248 if (vaStatus != VA_STATUS_SUCCESS)
3251 for (j = 0; j < 8; j++) {
3252 surface_id = pVp9PicParams->reference_frames[j];
3253 obj_surface = SURFACE(surface_id);
3258 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
3259 vaStatus = i965_surface_wrapper(ctx, surface_id);
3260 if (vaStatus != VA_STATUS_SUCCESS) {
3261 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
3262 obj_buffer->wrapper_buffer);
3267 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
3269 CALL_VTABLE(pdrvctx, vaStatus,
3270 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3275 return VA_STATUS_SUCCESS;
3282 i965_decoder_wrapper_picture(VADriverContextP ctx,
3283 VAContextID context,
3284 VABufferID *buffers,
3287 struct i965_driver_data *i965 = i965_driver_data(ctx);
3288 struct object_context *obj_context = CONTEXT(context);
3289 VAStatus vaStatus = VA_STATUS_SUCCESS;
3291 VADriverContextP pdrvctx;
3292 struct object_buffer *obj_buffer;
3294 if (obj_context == NULL)
3295 return VA_STATUS_ERROR_INVALID_CONTEXT;
3297 /* When it is not wrapped context, continue the normal flowchart */
3298 if (obj_context->wrapper_context == VA_INVALID_ID)
3301 if (obj_context->obj_config &&
3302 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3303 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3305 return VA_STATUS_ERROR_INVALID_PARAMETER;
3307 pdrvctx = i965->wrapper_pdrvctx;
3309 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3310 obj_buffer = BUFFER(buffers[i]);
3315 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3316 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3320 CALL_VTABLE(pdrvctx, vaStatus,
3321 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3322 &(obj_buffer->wrapper_buffer), 1));
3328 i965_decoder_render_picture(VADriverContextP ctx,
3329 VAContextID context,
3330 VABufferID *buffers,
3333 struct i965_driver_data *i965 = i965_driver_data(ctx);
3334 struct object_context *obj_context = CONTEXT(context);
3335 VAStatus vaStatus = VA_STATUS_SUCCESS;
3338 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3340 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3341 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3344 return VA_STATUS_ERROR_INVALID_BUFFER;
3346 switch (obj_buffer->type) {
3347 case VAPictureParameterBufferType:
3348 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3351 case VAIQMatrixBufferType:
3352 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3355 case VABitPlaneBufferType:
3356 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3359 case VASliceParameterBufferType:
3360 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3363 case VASliceDataBufferType:
3364 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3367 case VAHuffmanTableBufferType:
3368 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3371 case VAProbabilityBufferType:
3372 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3376 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3381 if ((vaStatus == VA_STATUS_SUCCESS) &&
3382 (obj_context->wrapper_context != VA_INVALID_ID))
3383 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3388 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3390 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3391 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3392 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3393 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3394 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3395 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3396 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3397 /* extended buffer */
3398 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3399 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3400 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3402 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3403 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3404 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3406 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3407 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3410 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3411 struct object_context *obj_context,
3412 struct object_buffer *obj_buffer,
3415 struct encode_state *encode = &obj_context->codec_state.encode;
3417 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3418 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3419 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3420 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3422 return VA_STATUS_SUCCESS;
3426 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3427 struct object_context *obj_context,
3428 struct object_buffer *obj_buffer,
3431 struct encode_state *encode = &obj_context->codec_state.encode;
3433 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3434 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3435 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3436 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3438 return VA_STATUS_SUCCESS;
3442 i965_encoder_get_misc_paramerter_buffer_index(VADriverContextP ctx,
3443 struct encode_state *encode,
3444 VAEncMiscParameterBuffer *misc_param)
3448 if (!encode->has_layers)
3451 if (misc_param->type == VAEncMiscParameterTypeRateControl) {
3452 VAEncMiscParameterRateControl *misc_rate_control = (VAEncMiscParameterRateControl *)misc_param->data;
3454 index = misc_rate_control->rc_flags.bits.temporal_id;
3455 } else if (misc_param->type == VAEncMiscParameterTypeFrameRate) {
3456 VAEncMiscParameterFrameRate *misc_frame_rate = (VAEncMiscParameterFrameRate *)misc_param->data;
3458 index = misc_frame_rate->framerate_flags.bits.temporal_id;
3465 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3466 struct object_context *obj_context,
3467 struct object_buffer *obj_buffer)
3469 struct encode_state *encode = &obj_context->codec_state.encode;
3470 VAEncMiscParameterBuffer *param = NULL;
3473 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3474 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3476 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3478 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3479 return VA_STATUS_ERROR_INVALID_PARAMETER;
3481 if (param->type == VAEncMiscParameterTypeTemporalLayerStructure)
3482 encode->has_layers = 1;
3484 index = i965_encoder_get_misc_paramerter_buffer_index(ctx, encode, param);
3486 if (index >= ARRAY_ELEMS(encode->misc_param[0]))
3487 return VA_STATUS_ERROR_INVALID_PARAMETER;
3489 i965_release_buffer_store(&encode->misc_param[param->type][index]);
3490 i965_reference_buffer_store(&encode->misc_param[param->type][index], obj_buffer->buffer_store);
3492 return VA_STATUS_SUCCESS;
3496 i965_encoder_render_picture(VADriverContextP ctx,
3497 VAContextID context,
3498 VABufferID *buffers,
3501 struct i965_driver_data *i965 = i965_driver_data(ctx);
3502 struct object_context *obj_context = CONTEXT(context);
3503 struct object_config *obj_config;
3504 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3505 struct encode_state *encode;
3508 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3509 obj_config = obj_context->obj_config;
3510 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3512 encode = &obj_context->codec_state.encode;
3513 for (i = 0; i < num_buffers; i++) {
3514 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3517 return VA_STATUS_ERROR_INVALID_BUFFER;
3519 switch (obj_buffer->type) {
3520 case VAQMatrixBufferType:
3521 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3524 case VAIQMatrixBufferType:
3525 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3528 case VAEncSequenceParameterBufferType:
3529 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3532 case VAEncPictureParameterBufferType:
3533 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3536 case VAHuffmanTableBufferType:
3537 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3540 case VAEncSliceParameterBufferType:
3541 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3542 if (vaStatus == VA_STATUS_SUCCESS) {
3543 /* When the max number of slices is updated, it also needs
3544 * to reallocate the arrays that is used to store
3545 * the packed data index/count for the slice
3547 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3548 encode->slice_index++;
3550 if (encode->slice_index == encode->max_slice_num) {
3551 int slice_num = encode->max_slice_num;
3552 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3553 (slice_num + NUM_SLICES) * sizeof(int));
3554 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3555 (slice_num + NUM_SLICES) * sizeof(int));
3556 encode->slice_header_index = realloc(encode->slice_header_index,
3557 (slice_num + NUM_SLICES) * sizeof(int));
3558 memset(encode->slice_rawdata_index + slice_num, 0,
3559 sizeof(int) * NUM_SLICES);
3560 memset(encode->slice_rawdata_count + slice_num, 0,
3561 sizeof(int) * NUM_SLICES);
3562 memset(encode->slice_header_index + slice_num, 0,
3563 sizeof(int) * NUM_SLICES);
3565 encode->max_slice_num += NUM_SLICES;
3566 if ((encode->slice_rawdata_index == NULL) ||
3567 (encode->slice_header_index == NULL) ||
3568 (encode->slice_rawdata_count == NULL)) {
3569 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3576 case VAEncPackedHeaderParameterBufferType: {
3577 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3578 encode->last_packed_header_type = param->type;
3580 if ((param->type == VAEncPackedHeaderRawData) ||
3581 (param->type == VAEncPackedHeaderSlice)) {
3582 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3583 } else if ((obj_config->profile == VAProfileHEVCMain ||
3584 obj_config->profile == VAProfileHEVCMain10) &&
3585 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3586 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3589 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3591 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3594 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3599 case VAEncPackedHeaderDataBufferType: {
3600 if (encode->last_packed_header_type == 0) {
3601 WARN_ONCE("the packed header data is passed without type!\n");
3602 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3606 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3607 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3608 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3610 if (obj_config->profile == VAProfileVP9Profile0)
3613 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3614 * the packed_slice_header as the delimeter to decide how
3615 * the packed rawdata is inserted for the given slice.
3616 * Otherwise it will use the VAEncSequenceParameterBuffer
3619 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3620 /* store the first index of the packed header data for current slice */
3621 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3622 encode->slice_rawdata_index[encode->slice_index] =
3623 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3625 encode->slice_rawdata_count[encode->slice_index]++;
3626 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3627 /* find one packed slice_header delimeter. And the following
3628 * packed data is for the next slice
3630 encode->slice_header_index[encode->slice_index] =
3631 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3632 encode->slice_index++;
3633 /* Reallocate the buffer to record the index/count of
3634 * packed_data for one slice.
3636 if (encode->slice_index == encode->max_slice_num) {
3637 int slice_num = encode->max_slice_num;
3639 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3640 (slice_num + NUM_SLICES) * sizeof(int));
3641 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3642 (slice_num + NUM_SLICES) * sizeof(int));
3643 encode->slice_header_index = realloc(encode->slice_header_index,
3644 (slice_num + NUM_SLICES) * sizeof(int));
3645 memset(encode->slice_rawdata_index + slice_num, 0,
3646 sizeof(int) * NUM_SLICES);
3647 memset(encode->slice_rawdata_count + slice_num, 0,
3648 sizeof(int) * NUM_SLICES);
3649 memset(encode->slice_header_index + slice_num, 0,
3650 sizeof(int) * NUM_SLICES);
3651 encode->max_slice_num += NUM_SLICES;
3655 if (vaStatus == VA_STATUS_SUCCESS) {
3656 /* store the first index of the packed header data for current slice */
3657 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3658 encode->slice_rawdata_index[encode->slice_index] =
3659 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3661 encode->slice_rawdata_count[encode->slice_index]++;
3662 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3663 if (encode->slice_header_index[encode->slice_index] == 0) {
3664 encode->slice_header_index[encode->slice_index] =
3665 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3667 WARN_ONCE("Multi slice header data is passed for"
3668 " slice %d!\n", encode->slice_index);
3674 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3675 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3676 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3677 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3678 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3679 VA_STATUS_ERROR_ENCODING_ERROR);
3681 if ((obj_config->profile == VAProfileHEVCMain ||
3682 obj_config->profile == VAProfileHEVCMain10) &&
3683 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3685 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3688 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3689 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3691 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3694 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3698 encode->last_packed_header_type = 0;
3702 case VAEncMiscParameterBufferType:
3703 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3708 case VAEncMacroblockMapBufferType:
3709 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3713 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3721 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3723 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3724 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3727 i965_proc_render_picture(VADriverContextP ctx,
3728 VAContextID context,
3729 VABufferID *buffers,
3732 struct i965_driver_data *i965 = i965_driver_data(ctx);
3733 struct object_context *obj_context = CONTEXT(context);
3734 VAStatus vaStatus = VA_STATUS_SUCCESS;
3737 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3739 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3740 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3743 return VA_STATUS_ERROR_INVALID_BUFFER;
3745 switch (obj_buffer->type) {
3746 case VAProcPipelineParameterBufferType:
3747 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3751 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3760 i965_RenderPicture(VADriverContextP ctx,
3761 VAContextID context,
3762 VABufferID *buffers,
3765 struct i965_driver_data *i965 = i965_driver_data(ctx);
3766 struct object_context *obj_context;
3767 struct object_config *obj_config;
3768 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3770 obj_context = CONTEXT(context);
3771 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3773 if (num_buffers <= 0)
3774 return VA_STATUS_ERROR_INVALID_PARAMETER;
3776 obj_config = obj_context->obj_config;
3777 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3779 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3780 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3781 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
3782 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3783 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
3784 (VAEntrypointFEI == obj_config->entrypoint)) {
3785 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3787 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3794 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3796 struct i965_driver_data *i965 = i965_driver_data(ctx);
3797 struct object_context *obj_context = CONTEXT(context);
3798 struct object_config *obj_config;
3800 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3801 obj_config = obj_context->obj_config;
3802 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3804 if (obj_context->codec_type == CODEC_PROC) {
3805 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3806 } else if (obj_context->codec_type == CODEC_ENC) {
3807 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3808 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3809 (VAEntrypointEncSliceLP == obj_config->entrypoint) ||
3810 (VAEntrypointFEI == obj_config->entrypoint)),
3811 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3813 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3814 obj_context->codec_state.encode.num_packed_header_data_ext) {
3815 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3816 return VA_STATUS_ERROR_INVALID_PARAMETER;
3818 if (!obj_context->codec_state.encode.pic_param_ext) {
3819 return VA_STATUS_ERROR_INVALID_PARAMETER;
3821 if (!obj_context->codec_state.encode.seq_param_ext &&
3822 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3823 /* The seq_param is not mandatory for VP9 encoding */
3824 if (obj_config->profile != VAProfileVP9Profile0)
3825 return VA_STATUS_ERROR_INVALID_PARAMETER;
3827 if ((obj_context->codec_state.encode.num_slice_params_ext <= 0) &&
3828 ((obj_config->profile != VAProfileVP8Version0_3) &&
3829 (obj_config->profile != VAProfileVP9Profile0))) {
3830 return VA_STATUS_ERROR_INVALID_PARAMETER;
3833 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3834 (obj_context->codec_state.encode.num_slice_params_ext !=
3835 obj_context->codec_state.encode.slice_index)) {
3836 WARN_ONCE("packed slice_header data is missing for some slice"
3837 " under packed SLICE_HEADER mode\n");
3838 return VA_STATUS_ERROR_INVALID_PARAMETER;
3841 if (obj_context->codec_state.decode.pic_param == NULL) {
3842 return VA_STATUS_ERROR_INVALID_PARAMETER;
3844 if (obj_context->codec_state.decode.num_slice_params <= 0) {
3845 return VA_STATUS_ERROR_INVALID_PARAMETER;
3847 if (obj_context->codec_state.decode.num_slice_datas <= 0) {
3848 return VA_STATUS_ERROR_INVALID_PARAMETER;
3851 if (obj_context->codec_state.decode.num_slice_params !=
3852 obj_context->codec_state.decode.num_slice_datas) {
3853 return VA_STATUS_ERROR_INVALID_PARAMETER;
3856 if (obj_context->wrapper_context != VA_INVALID_ID) {
3857 /* call the vaEndPicture of wrapped driver */
3858 VADriverContextP pdrvctx;
3861 pdrvctx = i965->wrapper_pdrvctx;
3862 CALL_VTABLE(pdrvctx, va_status,
3863 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3869 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3870 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3874 i965_SyncSurface(VADriverContextP ctx,
3875 VASurfaceID render_target)
3877 struct i965_driver_data *i965 = i965_driver_data(ctx);
3878 struct object_surface *obj_surface = SURFACE(render_target);
3880 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3882 if (obj_surface->bo)
3883 drm_intel_bo_wait_rendering(obj_surface->bo);
3885 return VA_STATUS_SUCCESS;
3889 i965_QuerySurfaceStatus(VADriverContextP ctx,
3890 VASurfaceID render_target,
3891 VASurfaceStatus *status) /* out */
3893 struct i965_driver_data *i965 = i965_driver_data(ctx);
3894 struct object_surface *obj_surface = SURFACE(render_target);
3896 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3898 if (obj_surface->bo) {
3899 if (drm_intel_bo_busy(obj_surface->bo)) {
3900 *status = VASurfaceRendering;
3902 *status = VASurfaceReady;
3905 *status = VASurfaceReady;
3908 return VA_STATUS_SUCCESS;
3911 static VADisplayAttribute *
3912 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3914 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3917 if (!i965->display_attributes)
3920 for (i = 0; i < i965->num_display_attributes; i++) {
3921 if (i965->display_attributes[i].type == type)
3922 return &i965->display_attributes[i];
3928 i965_display_attributes_terminate(VADriverContextP ctx)
3930 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3932 if (i965->display_attributes) {
3933 free(i965->display_attributes);
3934 i965->display_attributes = NULL;
3935 i965->num_display_attributes = 0;
3940 i965_display_attributes_init(VADriverContextP ctx)
3942 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3944 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3945 i965->display_attributes = malloc(
3946 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3947 if (!i965->display_attributes)
3951 i965->display_attributes,
3952 i965_display_attributes,
3953 sizeof(i965_display_attributes)
3956 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3957 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3958 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3959 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3960 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3962 if (!i965->rotation_attrib ||
3963 !i965->brightness_attrib ||
3964 !i965->contrast_attrib ||
3965 !i965->hue_attrib ||
3966 !i965->saturation_attrib) {
3972 i965_display_attributes_terminate(ctx);
3977 * Query display attributes
3978 * The caller must provide a "attr_list" array that can hold at
3979 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3980 * returned in "attr_list" is returned in "num_attributes".
3983 i965_QueryDisplayAttributes(
3984 VADriverContextP ctx,
3985 VADisplayAttribute *attribs, /* out */
3986 int *num_attribs_ptr /* out */
3989 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3991 if (attribs && num_attribs > 0)
3992 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3994 if (num_attribs_ptr)
3995 *num_attribs_ptr = num_attribs;
3997 return VA_STATUS_SUCCESS;
4001 * Get display attributes
4002 * This function returns the current attribute values in "attr_list".
4003 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
4004 * from vaQueryDisplayAttributes() can have their values retrieved.
4007 i965_GetDisplayAttributes(
4008 VADriverContextP ctx,
4009 VADisplayAttribute *attribs, /* inout */
4010 int num_attribs /* in */
4015 for (i = 0; i < num_attribs; i++) {
4016 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
4018 src_attrib = get_display_attribute(ctx, dst_attrib->type);
4020 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
4021 dst_attrib->min_value = src_attrib->min_value;
4022 dst_attrib->max_value = src_attrib->max_value;
4023 dst_attrib->value = src_attrib->value;
4024 dst_attrib->flags = src_attrib->flags;
4025 } else if (src_attrib &&
4026 (src_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE)) {
4027 dst_attrib->flags = src_attrib->flags;
4029 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
4031 return VA_STATUS_SUCCESS;
4035 * Set display attributes
4036 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
4037 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
4038 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
4041 i965_SetDisplayAttributes(
4042 VADriverContextP ctx,
4043 VADisplayAttribute *attribs, /* in */
4044 int num_attribs /* in */
4049 for (i = 0; i < num_attribs; i++) {
4050 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
4052 dst_attrib = get_display_attribute(ctx, src_attrib->type);
4054 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
4056 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
4059 if (src_attrib->value < dst_attrib->min_value ||
4060 src_attrib->value > dst_attrib->max_value)
4061 return VA_STATUS_ERROR_INVALID_PARAMETER;
4063 dst_attrib->value = src_attrib->value;
4064 /* XXX: track modified attributes through timestamps */
4066 return VA_STATUS_SUCCESS;
4070 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
4071 VASurfaceID surface,
4072 void **buffer, /* out */
4073 unsigned int *stride) /* out */
4076 return VA_STATUS_ERROR_UNIMPLEMENTED;
4080 i965_destroy_heap(struct object_heap *heap,
4081 void (*func)(struct object_heap *heap, struct object_base *object))
4083 struct object_base *object;
4084 object_heap_iterator iter;
4086 object = object_heap_first(heap, &iter);
4092 object = object_heap_next(heap, &iter);
4095 object_heap_destroy(heap);
4100 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
4103 i965_CreateImage(VADriverContextP ctx,
4104 VAImageFormat *format,
4107 VAImage *out_image) /* out */
4109 struct i965_driver_data *i965 = i965_driver_data(ctx);
4110 struct object_image *obj_image;
4111 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4113 unsigned int size2, size, awidth, aheight;
4115 out_image->image_id = VA_INVALID_ID;
4116 out_image->buf = VA_INVALID_ID;
4118 image_id = NEW_IMAGE_ID();
4119 if (image_id == VA_INVALID_ID)
4120 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4122 obj_image = IMAGE(image_id);
4124 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4125 obj_image->bo = NULL;
4126 obj_image->palette = NULL;
4127 obj_image->derived_surface = VA_INVALID_ID;
4129 VAImage * const image = &obj_image->image;
4130 image->image_id = image_id;
4131 image->buf = VA_INVALID_ID;
4133 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
4135 if ((format->fourcc == VA_FOURCC_YV12) ||
4136 (format->fourcc == VA_FOURCC_I420)) {
4137 if (awidth % 128 != 0) {
4138 awidth = ALIGN(width, 128);
4142 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
4143 size = awidth * aheight;
4144 size2 = (awidth / 2) * (aheight / 2);
4146 image->num_palette_entries = 0;
4147 image->entry_bytes = 0;
4148 memset(image->component_order, 0, sizeof(image->component_order));
4150 switch (format->fourcc) {
4151 case VA_FOURCC_IA44:
4152 case VA_FOURCC_AI44:
4153 image->num_planes = 1;
4154 image->pitches[0] = awidth;
4155 image->offsets[0] = 0;
4156 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4157 image->num_palette_entries = 16;
4158 image->entry_bytes = 3;
4159 image->component_order[0] = 'R';
4160 image->component_order[1] = 'G';
4161 image->component_order[2] = 'B';
4163 case VA_FOURCC_IA88:
4164 case VA_FOURCC_AI88:
4165 image->num_planes = 1;
4166 image->pitches[0] = awidth * 2;
4167 image->offsets[0] = 0;
4168 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4169 image->num_palette_entries = 256;
4170 image->entry_bytes = 3;
4171 image->component_order[0] = 'R';
4172 image->component_order[1] = 'G';
4173 image->component_order[2] = 'B';
4175 case VA_FOURCC_ARGB:
4176 case VA_FOURCC_ABGR:
4177 case VA_FOURCC_BGRA:
4178 case VA_FOURCC_RGBA:
4179 case VA_FOURCC_BGRX:
4180 case VA_FOURCC_RGBX:
4181 image->num_planes = 1;
4182 image->pitches[0] = awidth * 4;
4183 image->offsets[0] = 0;
4184 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
4186 case VA_FOURCC_YV12:
4187 image->num_planes = 3;
4188 image->pitches[0] = awidth;
4189 image->offsets[0] = 0;
4190 image->pitches[1] = awidth / 2;
4191 image->offsets[1] = size;
4192 image->pitches[2] = awidth / 2;
4193 image->offsets[2] = size + size2;
4194 image->data_size = size + 2 * size2;
4196 case VA_FOURCC_I420:
4197 image->num_planes = 3;
4198 image->pitches[0] = awidth;
4199 image->offsets[0] = 0;
4200 image->pitches[1] = awidth / 2;
4201 image->offsets[1] = size;
4202 image->pitches[2] = awidth / 2;
4203 image->offsets[2] = size + size2;
4204 image->data_size = size + 2 * size2;
4206 case VA_FOURCC_422H:
4207 image->num_planes = 3;
4208 image->pitches[0] = awidth;
4209 image->offsets[0] = 0;
4210 image->pitches[1] = awidth / 2;
4211 image->offsets[1] = size;
4212 image->pitches[2] = awidth / 2;
4213 image->offsets[2] = size + (awidth / 2) * aheight;
4214 image->data_size = size + 2 * ((awidth / 2) * aheight);
4216 case VA_FOURCC_NV12:
4217 image->num_planes = 2;
4218 image->pitches[0] = awidth;
4219 image->offsets[0] = 0;
4220 image->pitches[1] = awidth;
4221 image->offsets[1] = size;
4222 image->data_size = size + 2 * size2;
4224 case VA_FOURCC_YUY2:
4225 case VA_FOURCC_UYVY:
4226 image->num_planes = 1;
4227 image->pitches[0] = awidth * 2;
4228 image->offsets[0] = 0;
4229 image->data_size = size * 2;
4231 case VA_FOURCC_P010:
4232 image->num_planes = 2;
4233 image->pitches[0] = awidth * 2;
4234 image->offsets[0] = 0;
4235 image->pitches[1] = awidth * 2;
4236 image->offsets[1] = size * 2;
4237 image->data_size = size * 2 + 2 * size2 * 2;
4243 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
4244 image->data_size, 1, NULL, &image->buf);
4245 if (va_status != VA_STATUS_SUCCESS)
4248 struct object_buffer *obj_buffer = BUFFER(image->buf);
4251 !obj_buffer->buffer_store ||
4252 !obj_buffer->buffer_store->bo)
4253 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4255 obj_image->bo = obj_buffer->buffer_store->bo;
4256 dri_bo_reference(obj_image->bo);
4258 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4259 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4260 if (!obj_image->palette)
4264 image->image_id = image_id;
4265 image->format = *format;
4266 image->width = width;
4267 image->height = height;
4269 *out_image = *image;
4270 return VA_STATUS_SUCCESS;
4273 i965_DestroyImage(ctx, image_id);
4278 i965_check_alloc_surface_bo(VADriverContextP ctx,
4279 struct object_surface *obj_surface,
4281 unsigned int fourcc,
4282 unsigned int subsampling)
4284 struct i965_driver_data *i965 = i965_driver_data(ctx);
4285 int region_width, region_height;
4287 if (obj_surface->bo) {
4288 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4289 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4290 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4291 return VA_STATUS_SUCCESS;
4294 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4295 obj_surface->x_cr_offset = 0;
4297 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4299 if ((tiled && !obj_surface->user_disable_tiling)) {
4300 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4301 fourcc != VA_FOURCC_IYUV &&
4302 fourcc != VA_FOURCC_YV12,
4303 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4305 if (obj_surface->user_h_stride_set) {
4306 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4308 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4310 if (obj_surface->user_v_stride_set) {
4311 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4313 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4315 region_height = obj_surface->height;
4318 case VA_FOURCC_NV12:
4319 case VA_FOURCC_P010:
4320 assert(subsampling == SUBSAMPLE_YUV420);
4321 obj_surface->cb_cr_pitch = obj_surface->width;
4322 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4323 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4324 obj_surface->y_cb_offset = obj_surface->height;
4325 obj_surface->y_cr_offset = obj_surface->height;
4326 region_width = obj_surface->width;
4327 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4331 case VA_FOURCC_IMC1:
4332 assert(subsampling == SUBSAMPLE_YUV420);
4333 obj_surface->cb_cr_pitch = obj_surface->width;
4334 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4335 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4336 obj_surface->y_cr_offset = obj_surface->height;
4337 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4338 region_width = obj_surface->width;
4339 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4343 case VA_FOURCC_IMC3:
4344 assert(subsampling == SUBSAMPLE_YUV420);
4345 obj_surface->cb_cr_pitch = obj_surface->width;
4346 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4347 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4348 obj_surface->y_cb_offset = obj_surface->height;
4349 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4350 region_width = obj_surface->width;
4351 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4355 case VA_FOURCC_422H:
4356 assert(subsampling == SUBSAMPLE_YUV422H);
4357 obj_surface->cb_cr_pitch = obj_surface->width;
4358 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4359 obj_surface->cb_cr_height = obj_surface->orig_height;
4360 obj_surface->y_cb_offset = obj_surface->height;
4361 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4362 region_width = obj_surface->width;
4363 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4367 case VA_FOURCC_422V:
4368 assert(subsampling == SUBSAMPLE_YUV422V);
4369 obj_surface->cb_cr_pitch = obj_surface->width;
4370 obj_surface->cb_cr_width = obj_surface->orig_width;
4371 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4372 obj_surface->y_cb_offset = obj_surface->height;
4373 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4374 region_width = obj_surface->width;
4375 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4379 case VA_FOURCC_411P:
4380 assert(subsampling == SUBSAMPLE_YUV411);
4381 obj_surface->cb_cr_pitch = obj_surface->width;
4382 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4383 obj_surface->cb_cr_height = obj_surface->orig_height;
4384 obj_surface->y_cb_offset = obj_surface->height;
4385 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4386 region_width = obj_surface->width;
4387 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4391 case VA_FOURCC_444P:
4392 assert(subsampling == SUBSAMPLE_YUV444);
4393 obj_surface->cb_cr_pitch = obj_surface->width;
4394 obj_surface->cb_cr_width = obj_surface->orig_width;
4395 obj_surface->cb_cr_height = obj_surface->orig_height;
4396 obj_surface->y_cb_offset = obj_surface->height;
4397 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4398 region_width = obj_surface->width;
4399 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4403 case VA_FOURCC_Y800:
4404 assert(subsampling == SUBSAMPLE_YUV400);
4405 obj_surface->cb_cr_pitch = 0;
4406 obj_surface->cb_cr_width = 0;
4407 obj_surface->cb_cr_height = 0;
4408 obj_surface->y_cb_offset = 0;
4409 obj_surface->y_cr_offset = 0;
4410 region_width = obj_surface->width;
4411 region_height = obj_surface->height;
4415 case VA_FOURCC_YUY2:
4416 case VA_FOURCC_UYVY:
4417 assert(subsampling == SUBSAMPLE_YUV422H);
4418 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4419 obj_surface->cb_cr_pitch = obj_surface->width;
4420 obj_surface->y_cb_offset = 0;
4421 obj_surface->y_cr_offset = 0;
4422 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4423 obj_surface->cb_cr_height = obj_surface->orig_height;
4424 region_width = obj_surface->width;
4425 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 assert(subsampling == SUBSAMPLE_RGBX);
4435 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4436 region_width = obj_surface->width;
4437 region_height = obj_surface->height;
4441 /* Never get here */
4442 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4446 assert(subsampling == SUBSAMPLE_YUV420 ||
4447 subsampling == SUBSAMPLE_YUV422H ||
4448 subsampling == SUBSAMPLE_YUV422V ||
4449 subsampling == SUBSAMPLE_RGBX);
4451 region_width = obj_surface->width;
4452 region_height = obj_surface->height;
4455 case VA_FOURCC_NV12:
4456 case VA_FOURCC_P010:
4457 obj_surface->y_cb_offset = obj_surface->height;
4458 obj_surface->y_cr_offset = obj_surface->height;
4459 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4460 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) *
4462 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4463 obj_surface->cb_cr_pitch = obj_surface->width;
4464 region_width = obj_surface->width;
4465 region_height = obj_surface->height + obj_surface->height / 2;
4468 case VA_FOURCC_YV16:
4469 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4470 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4471 obj_surface->cb_cr_height = obj_surface->orig_height;
4472 obj_surface->y_cr_offset = obj_surface->height;
4473 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4474 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4475 region_width = obj_surface->width;
4476 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4479 case VA_FOURCC_YV12:
4480 case VA_FOURCC_I420:
4481 case VA_FOURCC_IYUV:
4482 if (fourcc == VA_FOURCC_YV12) {
4483 obj_surface->y_cr_offset = obj_surface->height;
4484 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4486 obj_surface->y_cb_offset = obj_surface->height;
4487 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4490 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4491 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4492 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4493 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4494 region_width = obj_surface->width;
4495 region_height = obj_surface->height + obj_surface->height / 2;
4498 case VA_FOURCC_I010:
4499 obj_surface->y_cb_offset = obj_surface->height;
4500 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4501 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4502 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
4503 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4504 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4505 region_width = obj_surface->width;
4506 region_height = obj_surface->height + obj_surface->height / 2;
4509 case VA_FOURCC_YUY2:
4510 case VA_FOURCC_UYVY:
4511 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4512 obj_surface->y_cb_offset = 0;
4513 obj_surface->y_cr_offset = 0;
4514 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4515 obj_surface->cb_cr_height = obj_surface->orig_height;
4516 obj_surface->cb_cr_pitch = obj_surface->width;
4517 region_width = obj_surface->width;
4518 region_height = obj_surface->height;
4520 case VA_FOURCC_RGBA:
4521 case VA_FOURCC_RGBX:
4522 case VA_FOURCC_BGRA:
4523 case VA_FOURCC_BGRX:
4524 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4525 region_width = obj_surface->width;
4526 region_height = obj_surface->height;
4530 /* Never get here */
4531 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4536 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4538 if ((tiled && !obj_surface->user_disable_tiling)) {
4539 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4540 unsigned long pitch;
4542 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4550 assert(tiling_mode == I915_TILING_Y);
4551 assert(pitch == obj_surface->width);
4553 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4559 obj_surface->fourcc = fourcc;
4560 obj_surface->subsampling = subsampling;
4561 assert(obj_surface->bo);
4562 return VA_STATUS_SUCCESS;
4565 VAStatus i965_DeriveImage(VADriverContextP ctx,
4566 VASurfaceID surface,
4567 VAImage *out_image) /* out */
4569 struct i965_driver_data *i965 = i965_driver_data(ctx);
4570 struct object_image *obj_image;
4571 struct object_surface *obj_surface;
4573 unsigned int w_pitch;
4574 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4576 out_image->image_id = VA_INVALID_ID;
4577 obj_surface = SURFACE(surface);
4580 return VA_STATUS_ERROR_INVALID_SURFACE;
4582 if (!obj_surface->bo) {
4583 unsigned int is_tiled = 0;
4584 unsigned int fourcc = VA_FOURCC_YV12;
4585 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4586 int sampling = get_sampling_from_fourcc(fourcc);
4587 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4588 if (va_status != VA_STATUS_SUCCESS)
4592 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4594 w_pitch = obj_surface->width;
4596 image_id = NEW_IMAGE_ID();
4598 if (image_id == VA_INVALID_ID)
4599 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4601 obj_image = IMAGE(image_id);
4604 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4606 obj_image->bo = NULL;
4607 obj_image->palette = NULL;
4608 obj_image->derived_surface = VA_INVALID_ID;
4610 VAImage * const image = &obj_image->image;
4612 memset(image, 0, sizeof(*image));
4613 image->image_id = image_id;
4614 image->buf = VA_INVALID_ID;
4615 image->num_palette_entries = 0;
4616 image->entry_bytes = 0;
4617 image->width = obj_surface->orig_width;
4618 image->height = obj_surface->orig_height;
4619 image->data_size = obj_surface->size;
4621 image->format.fourcc = obj_surface->fourcc;
4622 image->format.byte_order = VA_LSB_FIRST;
4623 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4625 if (!image->format.bits_per_pixel)
4628 switch (image->format.fourcc) {
4629 case VA_FOURCC_YV12:
4630 image->num_planes = 3;
4631 image->pitches[0] = w_pitch; /* Y */
4632 image->offsets[0] = 0;
4633 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4634 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4635 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4636 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4639 case VA_FOURCC_YV16:
4640 image->num_planes = 3;
4641 image->pitches[0] = w_pitch; /* Y */
4642 image->offsets[0] = 0;
4643 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4644 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4645 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4646 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4649 case VA_FOURCC_NV12:
4650 case VA_FOURCC_P010:
4651 image->num_planes = 2;
4652 image->pitches[0] = w_pitch; /* Y */
4653 image->offsets[0] = 0;
4654 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4655 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4658 case VA_FOURCC_I420:
4659 case VA_FOURCC_I010:
4660 case VA_FOURCC_422H:
4661 case VA_FOURCC_IMC3:
4662 case VA_FOURCC_444P:
4663 case VA_FOURCC_422V:
4664 case VA_FOURCC_411P:
4665 image->num_planes = 3;
4666 image->pitches[0] = w_pitch; /* Y */
4667 image->offsets[0] = 0;
4668 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4669 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4670 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4671 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4674 case VA_FOURCC_YUY2:
4675 case VA_FOURCC_UYVY:
4676 case VA_FOURCC_Y800:
4677 image->num_planes = 1;
4678 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4679 image->offsets[0] = 0;
4681 case VA_FOURCC_RGBA:
4682 case VA_FOURCC_RGBX:
4683 case VA_FOURCC_BGRA:
4684 case VA_FOURCC_BGRX:
4685 image->num_planes = 1;
4686 image->pitches[0] = obj_surface->width;
4688 switch (image->format.fourcc) {
4689 case VA_FOURCC_RGBA:
4690 case VA_FOURCC_RGBX:
4691 image->format.red_mask = 0x000000ff;
4692 image->format.green_mask = 0x0000ff00;
4693 image->format.blue_mask = 0x00ff0000;
4695 case VA_FOURCC_BGRA:
4696 case VA_FOURCC_BGRX:
4697 image->format.red_mask = 0x00ff0000;
4698 image->format.green_mask = 0x0000ff00;
4699 image->format.blue_mask = 0x000000ff;
4705 switch (image->format.fourcc) {
4706 case VA_FOURCC_RGBA:
4707 case VA_FOURCC_BGRA:
4708 image->format.alpha_mask = 0xff000000;
4709 image->format.depth = 32;
4711 case VA_FOURCC_RGBX:
4712 case VA_FOURCC_BGRX:
4713 image->format.alpha_mask = 0x00000000;
4714 image->format.depth = 24;
4725 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4726 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4727 if (va_status != VA_STATUS_SUCCESS)
4730 struct object_buffer *obj_buffer = BUFFER(image->buf);
4733 !obj_buffer->buffer_store ||
4734 !obj_buffer->buffer_store->bo)
4735 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4737 obj_image->bo = obj_buffer->buffer_store->bo;
4738 dri_bo_reference(obj_image->bo);
4740 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4741 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4742 if (!obj_image->palette) {
4743 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4748 *out_image = *image;
4749 obj_surface->flags |= SURFACE_DERIVED;
4750 obj_surface->derived_image_id = image_id;
4751 obj_image->derived_surface = surface;
4753 return VA_STATUS_SUCCESS;
4756 i965_DestroyImage(ctx, image_id);
4761 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4763 object_heap_free(heap, obj);
4768 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4770 struct i965_driver_data *i965 = i965_driver_data(ctx);
4771 struct object_image *obj_image = IMAGE(image);
4772 struct object_surface *obj_surface;
4775 return VA_STATUS_SUCCESS;
4777 dri_bo_unreference(obj_image->bo);
4778 obj_image->bo = NULL;
4780 if (obj_image->image.buf != VA_INVALID_ID) {
4781 i965_DestroyBuffer(ctx, obj_image->image.buf);
4782 obj_image->image.buf = VA_INVALID_ID;
4785 if (obj_image->palette) {
4786 free(obj_image->palette);
4787 obj_image->palette = NULL;
4790 obj_surface = SURFACE(obj_image->derived_surface);
4793 obj_surface->flags &= ~SURFACE_DERIVED;
4794 obj_surface->derived_image_id = VA_INVALID_ID;
4797 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4799 return VA_STATUS_SUCCESS;
4803 * pointer to an array holding the palette data. The size of the array is
4804 * num_palette_entries * entry_bytes in size. The order of the components
4805 * in the palette is described by the component_order in VASubpicture struct
4808 i965_SetImagePalette(VADriverContextP ctx,
4810 unsigned char *palette)
4812 struct i965_driver_data *i965 = i965_driver_data(ctx);
4815 struct object_image *obj_image = IMAGE(image);
4817 return VA_STATUS_ERROR_INVALID_IMAGE;
4819 if (!obj_image->palette)
4820 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4822 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4823 obj_image->palette[i] = (((unsigned int)palette[3 * i + 0] << 16) |
4824 ((unsigned int)palette[3 * i + 1] << 8) |
4825 (unsigned int)palette[3 * i + 2]);
4826 return VA_STATUS_SUCCESS;
4830 get_sampling_from_fourcc(unsigned int fourcc)
4832 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4834 if (info && (info->flag & I_S))
4835 return info->subsampling;
4841 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4842 const uint8_t *src, unsigned int src_stride,
4843 unsigned int len, unsigned int height)
4847 for (i = 0; i < height; i++) {
4848 memcpy(dst, src, len);
4855 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4856 struct object_surface *obj_surface,
4857 const VARectangle *rect)
4859 uint8_t *dst[3], *src[3];
4861 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4862 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4863 unsigned int tiling, swizzle;
4864 VAStatus va_status = VA_STATUS_SUCCESS;
4866 if (!obj_surface->bo)
4867 return VA_STATUS_ERROR_INVALID_SURFACE;
4869 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4870 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4872 if (tiling != I915_TILING_NONE)
4873 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4875 dri_bo_map(obj_surface->bo, 0);
4877 if (!obj_surface->bo->virtual)
4878 return VA_STATUS_ERROR_INVALID_SURFACE;
4880 /* Dest VA image has either I420 or YV12 format.
4881 Source VA surface alway has I420 format */
4882 dst[Y] = image_data + obj_image->image.offsets[Y];
4883 src[0] = (uint8_t *)obj_surface->bo->virtual;
4884 dst[U] = image_data + obj_image->image.offsets[U];
4885 src[1] = src[0] + obj_surface->width * obj_surface->height;
4886 dst[V] = image_data + obj_image->image.offsets[V];
4887 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4890 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4891 src[0] += rect->y * obj_surface->width + rect->x;
4892 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4893 src[0], obj_surface->width,
4894 rect->width, rect->height);
4897 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4898 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4899 memcpy_pic(dst[U], obj_image->image.pitches[U],
4900 src[1], obj_surface->width / 2,
4901 rect->width / 2, rect->height / 2);
4904 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4905 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4906 memcpy_pic(dst[V], obj_image->image.pitches[V],
4907 src[2], obj_surface->width / 2,
4908 rect->width / 2, rect->height / 2);
4910 if (tiling != I915_TILING_NONE)
4911 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4913 dri_bo_unmap(obj_surface->bo);
4919 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4920 struct object_surface *obj_surface,
4921 const VARectangle *rect)
4923 uint8_t *dst[2], *src[2];
4924 unsigned int tiling, swizzle;
4925 VAStatus va_status = VA_STATUS_SUCCESS;
4927 if (!obj_surface->bo)
4928 return VA_STATUS_ERROR_INVALID_SURFACE;
4930 assert(obj_surface->fourcc);
4931 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4933 if (tiling != I915_TILING_NONE)
4934 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4936 dri_bo_map(obj_surface->bo, 0);
4938 if (!obj_surface->bo->virtual)
4939 return VA_STATUS_ERROR_INVALID_SURFACE;
4941 /* Both dest VA image and source surface have NV12 format */
4942 dst[0] = image_data + obj_image->image.offsets[0];
4943 src[0] = (uint8_t *)obj_surface->bo->virtual;
4944 dst[1] = image_data + obj_image->image.offsets[1];
4945 src[1] = src[0] + obj_surface->width * obj_surface->height;
4948 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4949 src[0] += rect->y * obj_surface->width + rect->x;
4950 memcpy_pic(dst[0], obj_image->image.pitches[0],
4951 src[0], obj_surface->width,
4952 rect->width, rect->height);
4955 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4956 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4957 memcpy_pic(dst[1], obj_image->image.pitches[1],
4958 src[1], obj_surface->width,
4959 rect->width, rect->height / 2);
4961 if (tiling != I915_TILING_NONE)
4962 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4964 dri_bo_unmap(obj_surface->bo);
4970 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4971 struct object_surface *obj_surface,
4972 const VARectangle *rect)
4975 unsigned int tiling, swizzle;
4976 VAStatus va_status = VA_STATUS_SUCCESS;
4978 if (!obj_surface->bo)
4979 return VA_STATUS_ERROR_INVALID_SURFACE;
4981 assert(obj_surface->fourcc);
4982 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4984 if (tiling != I915_TILING_NONE)
4985 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4987 dri_bo_map(obj_surface->bo, 0);
4989 if (!obj_surface->bo->virtual)
4990 return VA_STATUS_ERROR_INVALID_SURFACE;
4992 /* Both dest VA image and source surface have YUYV format */
4993 dst = image_data + obj_image->image.offsets[0];
4994 src = (uint8_t *)obj_surface->bo->virtual;
4997 dst += rect->y * obj_image->image.pitches[0] + rect->x * 2;
4998 src += rect->y * obj_surface->width + rect->x * 2;
4999 memcpy_pic(dst, obj_image->image.pitches[0],
5000 src, obj_surface->width * 2,
5001 rect->width * 2, rect->height);
5003 if (tiling != I915_TILING_NONE)
5004 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5006 dri_bo_unmap(obj_surface->bo);
5012 i965_sw_getimage(VADriverContextP ctx,
5013 struct object_surface *obj_surface, struct object_image *obj_image,
5014 const VARectangle *rect)
5016 void *image_data = NULL;
5019 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5020 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5022 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5023 if (va_status != VA_STATUS_SUCCESS)
5026 switch (obj_image->image.format.fourcc) {
5027 case VA_FOURCC_YV12:
5028 case VA_FOURCC_I420:
5029 get_image_i420(obj_image, image_data, obj_surface, rect);
5031 case VA_FOURCC_NV12:
5032 get_image_nv12(obj_image, image_data, obj_surface, rect);
5034 case VA_FOURCC_YUY2:
5035 /* YUY2 is the format supported by overlay plane */
5036 get_image_yuy2(obj_image, image_data, obj_surface, rect);
5039 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5042 if (va_status != VA_STATUS_SUCCESS)
5045 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5050 i965_hw_getimage(VADriverContextP ctx,
5051 struct object_surface *obj_surface, struct object_image *obj_image,
5052 const VARectangle *rect)
5054 struct i965_surface src_surface;
5055 struct i965_surface dst_surface;
5057 src_surface.base = (struct object_base *)obj_surface;
5058 src_surface.type = I965_SURFACE_TYPE_SURFACE;
5059 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5061 dst_surface.base = (struct object_base *)obj_image;
5062 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
5063 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5065 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
5069 i965_GetImage(VADriverContextP ctx,
5070 VASurfaceID surface,
5071 int x, /* coordinates of the upper left source pixel */
5073 unsigned int width, /* width and height of the region */
5074 unsigned int height,
5077 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5078 struct object_surface * const obj_surface = SURFACE(surface);
5079 struct object_image * const obj_image = IMAGE(image);
5084 return VA_STATUS_ERROR_INVALID_SURFACE;
5085 if (!obj_surface->bo) /* don't get anything, keep previous data */
5086 return VA_STATUS_SUCCESS;
5087 if (is_surface_busy(i965, obj_surface))
5088 return VA_STATUS_ERROR_SURFACE_BUSY;
5090 if (!obj_image || !obj_image->bo)
5091 return VA_STATUS_ERROR_INVALID_IMAGE;
5092 if (is_image_busy(i965, obj_image, surface))
5093 return VA_STATUS_ERROR_SURFACE_BUSY;
5096 return VA_STATUS_ERROR_INVALID_PARAMETER;
5097 if (x + width > obj_surface->orig_width ||
5098 y + height > obj_surface->orig_height)
5099 return VA_STATUS_ERROR_INVALID_PARAMETER;
5100 if (x + width > obj_image->image.width ||
5101 y + height > obj_image->image.height)
5102 return VA_STATUS_ERROR_INVALID_PARAMETER;
5107 rect.height = height;
5109 if (HAS_ACCELERATED_GETIMAGE(i965))
5110 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
5112 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
5118 put_image_i420(struct object_surface *obj_surface,
5119 const VARectangle *dst_rect,
5120 struct object_image *obj_image, uint8_t *image_data,
5121 const VARectangle *src_rect)
5123 uint8_t *dst[3], *src[3];
5125 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
5126 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
5127 unsigned int tiling, swizzle;
5128 VAStatus va_status = VA_STATUS_SUCCESS;
5130 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5132 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5133 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5134 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5135 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5137 if (tiling != I915_TILING_NONE)
5138 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5140 dri_bo_map(obj_surface->bo, 0);
5142 if (!obj_surface->bo->virtual)
5143 return VA_STATUS_ERROR_INVALID_SURFACE;
5145 /* Dest VA image has either I420 or YV12 format.
5146 Source VA surface alway has I420 format */
5147 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5148 src[Y] = image_data + obj_image->image.offsets[Y];
5149 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5150 src[U] = image_data + obj_image->image.offsets[U];
5151 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
5152 src[V] = image_data + obj_image->image.offsets[V];
5155 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5156 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
5157 memcpy_pic(dst[0], obj_surface->width,
5158 src[Y], obj_image->image.pitches[Y],
5159 src_rect->width, src_rect->height);
5162 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5163 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
5164 memcpy_pic(dst[1], obj_surface->width / 2,
5165 src[U], obj_image->image.pitches[U],
5166 src_rect->width / 2, src_rect->height / 2);
5169 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
5170 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
5171 memcpy_pic(dst[2], obj_surface->width / 2,
5172 src[V], obj_image->image.pitches[V],
5173 src_rect->width / 2, src_rect->height / 2);
5175 if (tiling != I915_TILING_NONE)
5176 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5178 dri_bo_unmap(obj_surface->bo);
5184 put_image_nv12(struct object_surface *obj_surface,
5185 const VARectangle *dst_rect,
5186 struct object_image *obj_image, uint8_t *image_data,
5187 const VARectangle *src_rect)
5189 uint8_t *dst[2], *src[2];
5190 unsigned int tiling, swizzle;
5191 VAStatus va_status = VA_STATUS_SUCCESS;
5193 if (!obj_surface->bo)
5194 return VA_STATUS_ERROR_INVALID_SURFACE;
5196 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5197 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5198 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5199 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5201 if (tiling != I915_TILING_NONE)
5202 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5204 dri_bo_map(obj_surface->bo, 0);
5206 if (!obj_surface->bo->virtual)
5207 return VA_STATUS_ERROR_INVALID_SURFACE;
5209 /* Both dest VA image and source surface have NV12 format */
5210 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5211 src[0] = image_data + obj_image->image.offsets[0];
5212 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5213 src[1] = image_data + obj_image->image.offsets[1];
5216 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5217 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
5218 memcpy_pic(dst[0], obj_surface->width,
5219 src[0], obj_image->image.pitches[0],
5220 src_rect->width, src_rect->height);
5223 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
5224 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
5225 memcpy_pic(dst[1], obj_surface->width,
5226 src[1], obj_image->image.pitches[1],
5227 src_rect->width, src_rect->height / 2);
5229 if (tiling != I915_TILING_NONE)
5230 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5232 dri_bo_unmap(obj_surface->bo);
5238 put_image_yuy2(struct object_surface *obj_surface,
5239 const VARectangle *dst_rect,
5240 struct object_image *obj_image, uint8_t *image_data,
5241 const VARectangle *src_rect)
5244 unsigned int tiling, swizzle;
5245 VAStatus va_status = VA_STATUS_SUCCESS;
5247 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5248 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5249 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5250 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5251 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5253 if (tiling != I915_TILING_NONE)
5254 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5256 dri_bo_map(obj_surface->bo, 0);
5258 if (!obj_surface->bo->virtual)
5259 return VA_STATUS_ERROR_INVALID_SURFACE;
5261 /* Both dest VA image and source surface have YUY2 format */
5262 dst = (uint8_t *)obj_surface->bo->virtual;
5263 src = image_data + obj_image->image.offsets[0];
5265 /* YUYV packed plane */
5266 dst += dst_rect->y * obj_surface->width + dst_rect->x * 2;
5267 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x * 2;
5268 memcpy_pic(dst, obj_surface->width * 2,
5269 src, obj_image->image.pitches[0],
5270 src_rect->width * 2, src_rect->height);
5272 if (tiling != I915_TILING_NONE)
5273 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5275 dri_bo_unmap(obj_surface->bo);
5281 i965_sw_putimage(VADriverContextP ctx,
5282 struct object_surface *obj_surface, struct object_image *obj_image,
5283 const VARectangle *src_rect, const VARectangle *dst_rect)
5285 VAStatus va_status = VA_STATUS_SUCCESS;
5286 void *image_data = NULL;
5288 /* XXX: don't allow scaling */
5289 if (src_rect->width != dst_rect->width ||
5290 src_rect->height != dst_rect->height)
5291 return VA_STATUS_ERROR_INVALID_PARAMETER;
5293 if (obj_surface->fourcc) {
5294 /* Don't allow format mismatch */
5295 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5296 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5300 /* VA is surface not used for decoding, use same VA image format */
5301 va_status = i965_check_alloc_surface_bo(
5304 0, /* XXX: don't use tiled surface */
5305 obj_image->image.format.fourcc,
5306 get_sampling_from_fourcc(obj_image->image.format.fourcc));
5309 if (va_status != VA_STATUS_SUCCESS)
5312 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5313 if (va_status != VA_STATUS_SUCCESS)
5316 switch (obj_image->image.format.fourcc) {
5317 case VA_FOURCC_YV12:
5318 case VA_FOURCC_I420:
5319 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5321 case VA_FOURCC_NV12:
5322 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5324 case VA_FOURCC_YUY2:
5325 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5328 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5331 if (va_status != VA_STATUS_SUCCESS)
5334 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5339 i965_hw_putimage(VADriverContextP ctx,
5340 struct object_surface *obj_surface, struct object_image *obj_image,
5341 const VARectangle *src_rect, const VARectangle *dst_rect)
5343 struct i965_surface src_surface, dst_surface;
5344 VAStatus va_status = VA_STATUS_SUCCESS;
5346 if (!obj_surface->bo) {
5347 unsigned int tiling, swizzle;
5348 int surface_sampling = get_sampling_from_fourcc(obj_image->image.format.fourcc);;
5349 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5351 i965_check_alloc_surface_bo(ctx,
5354 obj_image->image.format.fourcc,
5358 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5360 src_surface.base = (struct object_base *)obj_image;
5361 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5362 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5364 dst_surface.base = (struct object_base *)obj_surface;
5365 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5366 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5368 va_status = i965_image_processing(ctx,
5378 i965_PutImage(VADriverContextP ctx,
5379 VASurfaceID surface,
5383 unsigned int src_width,
5384 unsigned int src_height,
5387 unsigned int dest_width,
5388 unsigned int dest_height)
5390 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5391 struct object_surface * const obj_surface = SURFACE(surface);
5392 struct object_image * const obj_image = IMAGE(image);
5393 VARectangle src_rect, dst_rect;
5397 return VA_STATUS_ERROR_INVALID_SURFACE;
5398 if (is_surface_busy(i965, obj_surface))
5399 return VA_STATUS_ERROR_SURFACE_BUSY;
5401 if (!obj_image || !obj_image->bo)
5402 return VA_STATUS_ERROR_INVALID_IMAGE;
5403 if (is_image_busy(i965, obj_image, surface))
5404 return VA_STATUS_ERROR_SURFACE_BUSY;
5408 src_x + src_width > obj_image->image.width ||
5409 src_y + src_height > obj_image->image.height)
5410 return VA_STATUS_ERROR_INVALID_PARAMETER;
5414 src_rect.width = src_width;
5415 src_rect.height = src_height;
5419 dest_x + dest_width > obj_surface->orig_width ||
5420 dest_y + dest_height > obj_surface->orig_height)
5421 return VA_STATUS_ERROR_INVALID_PARAMETER;
5423 dst_rect.x = dest_x;
5424 dst_rect.y = dest_y;
5425 dst_rect.width = dest_width;
5426 dst_rect.height = dest_height;
5428 if (HAS_ACCELERATED_PUTIMAGE(i965))
5429 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5430 &src_rect, &dst_rect);
5432 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5433 &src_rect, &dst_rect);
5439 i965_PutSurface(VADriverContextP ctx,
5440 VASurfaceID surface,
5441 void *draw, /* X Drawable */
5444 unsigned short srcw,
5445 unsigned short srch,
5448 unsigned short destw,
5449 unsigned short desth,
5450 VARectangle *cliprects, /* client supplied clip list */
5451 unsigned int number_cliprects, /* number of clip rects in the clip list */
5452 unsigned int flags) /* de-interlacing flags */
5455 if (IS_VA_X11(ctx)) {
5456 VARectangle src_rect, dst_rect;
5460 src_rect.width = srcw;
5461 src_rect.height = srch;
5465 dst_rect.width = destw;
5466 dst_rect.height = desth;
5468 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5469 cliprects, number_cliprects, flags);
5472 return VA_STATUS_ERROR_UNIMPLEMENTED;
5477 VADriverContextP ctx, /* in */
5478 VABufferID buf_id, /* in */
5479 VABufferType *type, /* out */
5480 unsigned int *size, /* out */
5481 unsigned int *num_elements /* out */
5484 struct i965_driver_data *i965 = NULL;
5485 struct object_buffer *obj_buffer = NULL;
5487 i965 = i965_driver_data(ctx);
5488 obj_buffer = BUFFER(buf_id);
5490 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5492 *type = obj_buffer->type;
5493 *size = obj_buffer->size_element;
5494 *num_elements = obj_buffer->num_elements;
5496 return VA_STATUS_SUCCESS;
5501 VADriverContextP ctx, /* in */
5502 VASurfaceID surface, /* in */
5503 unsigned int *fourcc, /* out */
5504 unsigned int *luma_stride, /* out */
5505 unsigned int *chroma_u_stride, /* out */
5506 unsigned int *chroma_v_stride, /* out */
5507 unsigned int *luma_offset, /* out */
5508 unsigned int *chroma_u_offset, /* out */
5509 unsigned int *chroma_v_offset, /* out */
5510 unsigned int *buffer_name, /* out */
5511 void **buffer /* out */
5514 VAStatus vaStatus = VA_STATUS_SUCCESS;
5515 struct i965_driver_data *i965 = i965_driver_data(ctx);
5516 struct object_surface *obj_surface = NULL;
5519 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5520 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5521 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5522 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5523 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5524 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5525 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5526 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5527 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5529 tmpImage.image_id = VA_INVALID_ID;
5531 obj_surface = SURFACE(surface);
5532 if (obj_surface == NULL) {
5533 // Surface is absent.
5534 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5538 // Lock functionality is absent now.
5539 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5540 // Surface is locked already.
5541 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5545 vaStatus = i965_DeriveImage(
5549 if (vaStatus != VA_STATUS_SUCCESS) {
5553 obj_surface->locked_image_id = tmpImage.image_id;
5555 vaStatus = i965_MapBuffer(
5559 if (vaStatus != VA_STATUS_SUCCESS) {
5563 *fourcc = tmpImage.format.fourcc;
5564 *luma_offset = tmpImage.offsets[0];
5565 *luma_stride = tmpImage.pitches[0];
5566 *chroma_u_offset = tmpImage.offsets[1];
5567 *chroma_u_stride = tmpImage.pitches[1];
5568 *chroma_v_offset = tmpImage.offsets[2];
5569 *chroma_v_stride = tmpImage.pitches[2];
5570 *buffer_name = tmpImage.buf;
5573 if (vaStatus != VA_STATUS_SUCCESS) {
5582 VADriverContextP ctx, /* in */
5583 VASurfaceID surface /* in */
5586 VAStatus vaStatus = VA_STATUS_SUCCESS;
5587 struct i965_driver_data *i965 = i965_driver_data(ctx);
5588 struct object_image *locked_img = NULL;
5589 struct object_surface *obj_surface = NULL;
5591 obj_surface = SURFACE(surface);
5593 if (obj_surface == NULL) {
5594 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5597 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5598 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5602 locked_img = IMAGE(obj_surface->locked_image_id);
5603 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5604 // Work image was deallocated before i965_UnlockSurface()
5605 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5609 vaStatus = i965_UnmapBuffer(
5611 locked_img->image.buf);
5612 if (vaStatus != VA_STATUS_SUCCESS) {
5616 vaStatus = i965_DestroyImage(
5618 locked_img->image.image_id);
5619 if (vaStatus != VA_STATUS_SUCCESS) {
5623 locked_img->image.image_id = VA_INVALID_ID;
5626 obj_surface->locked_image_id = VA_INVALID_ID;
5632 i965_GetSurfaceAttributes(
5633 VADriverContextP ctx,
5635 VASurfaceAttrib *attrib_list,
5636 unsigned int num_attribs
5639 VAStatus vaStatus = VA_STATUS_SUCCESS;
5640 struct i965_driver_data *i965 = i965_driver_data(ctx);
5641 struct object_config *obj_config;
5644 if (config == VA_INVALID_ID)
5645 return VA_STATUS_ERROR_INVALID_CONFIG;
5647 obj_config = CONFIG(config);
5649 if (obj_config == NULL)
5650 return VA_STATUS_ERROR_INVALID_CONFIG;
5652 if (attrib_list == NULL || num_attribs == 0)
5653 return VA_STATUS_ERROR_INVALID_PARAMETER;
5655 for (i = 0; i < num_attribs; i++) {
5656 switch (attrib_list[i].type) {
5657 case VASurfaceAttribPixelFormat:
5658 attrib_list[i].value.type = VAGenericValueTypeInteger;
5659 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5661 if (attrib_list[i].value.value.i == 0) {
5662 if (IS_G4X(i965->intel.device_info)) {
5663 if (obj_config->profile == VAProfileMPEG2Simple ||
5664 obj_config->profile == VAProfileMPEG2Main) {
5665 attrib_list[i].value.value.i = VA_FOURCC_I420;
5668 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5670 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5671 if (obj_config->profile == VAProfileMPEG2Simple ||
5672 obj_config->profile == VAProfileMPEG2Main) {
5673 attrib_list[i].value.value.i = VA_FOURCC_I420;
5674 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5675 obj_config->profile == VAProfileH264Main ||
5676 obj_config->profile == VAProfileH264High) {
5677 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5678 } else if (obj_config->profile == VAProfileNone) {
5679 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5682 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5684 } else if (IS_GEN6(i965->intel.device_info)) {
5685 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5686 } else if (IS_GEN7(i965->intel.device_info) ||
5687 IS_GEN8(i965->intel.device_info) ||
5688 IS_GEN9(i965->intel.device_info)) {
5689 if (obj_config->profile == VAProfileJPEGBaseline)
5690 attrib_list[i].value.value.i = 0; /* internal format */
5692 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5695 if (IS_G4X(i965->intel.device_info)) {
5696 if (obj_config->profile == VAProfileMPEG2Simple ||
5697 obj_config->profile == VAProfileMPEG2Main) {
5698 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5699 attrib_list[i].value.value.i = 0;
5700 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5704 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5706 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5707 if (obj_config->profile == VAProfileMPEG2Simple ||
5708 obj_config->profile == VAProfileMPEG2Main) {
5709 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5710 attrib_list[i].value.value.i = 0;
5711 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5713 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5714 obj_config->profile == VAProfileH264Main ||
5715 obj_config->profile == VAProfileH264High) {
5716 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5717 attrib_list[i].value.value.i = 0;
5718 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5720 } else if (obj_config->profile == VAProfileNone) {
5721 switch (attrib_list[i].value.value.i) {
5722 case VA_FOURCC_NV12:
5723 case VA_FOURCC_I420:
5724 case VA_FOURCC_YV12:
5725 case VA_FOURCC_YUY2:
5726 case VA_FOURCC_BGRA:
5727 case VA_FOURCC_BGRX:
5728 case VA_FOURCC_RGBX:
5729 case VA_FOURCC_RGBA:
5732 attrib_list[i].value.value.i = 0;
5733 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5738 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5740 } else if (IS_GEN6(i965->intel.device_info)) {
5741 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5742 obj_config->entrypoint == VAEntrypointVideoProc) {
5743 switch (attrib_list[i].value.value.i) {
5744 case VA_FOURCC_NV12:
5745 case VA_FOURCC_I420:
5746 case VA_FOURCC_YV12:
5747 case VA_FOURCC_YUY2:
5748 case VA_FOURCC_BGRA:
5749 case VA_FOURCC_BGRX:
5750 case VA_FOURCC_RGBX:
5751 case VA_FOURCC_RGBA:
5754 attrib_list[i].value.value.i = 0;
5755 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5759 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5760 attrib_list[i].value.value.i = 0;
5761 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5764 } else if (IS_GEN7(i965->intel.device_info) ||
5765 IS_GEN8(i965->intel.device_info) ||
5766 IS_GEN9(i965->intel.device_info)) {
5767 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5768 obj_config->entrypoint == VAEntrypointVideoProc ||
5769 obj_config->entrypoint == VAEntrypointEncSliceLP ||
5770 obj_config->entrypoint == VAEntrypointFEI) {
5771 switch (attrib_list[i].value.value.i) {
5772 case VA_FOURCC_NV12:
5773 case VA_FOURCC_I420:
5774 case VA_FOURCC_YV12:
5777 attrib_list[i].value.value.i = 0;
5778 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5782 if (obj_config->profile == VAProfileJPEGBaseline) {
5783 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5784 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5786 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5787 attrib_list[i].value.value.i = 0;
5788 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5796 case VASurfaceAttribMinWidth:
5797 /* FIXME: add support for it later */
5798 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5800 case VASurfaceAttribMaxWidth:
5801 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5803 case VASurfaceAttribMinHeight:
5804 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5806 case VASurfaceAttribMaxHeight:
5807 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5810 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5819 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5821 VASurfaceAttrib *attrib_list,
5822 unsigned int *num_attribs)
5824 VAStatus vaStatus = VA_STATUS_SUCCESS;
5825 struct i965_driver_data *i965 = i965_driver_data(ctx);
5826 struct object_config *obj_config;
5828 VASurfaceAttrib *attribs = NULL;
5832 if (config == VA_INVALID_ID)
5833 return VA_STATUS_ERROR_INVALID_CONFIG;
5835 obj_config = CONFIG(config);
5837 if (obj_config == NULL)
5838 return VA_STATUS_ERROR_INVALID_CONFIG;
5840 if (!attrib_list && !num_attribs)
5841 return VA_STATUS_ERROR_INVALID_PARAMETER;
5843 if (attrib_list == NULL) {
5844 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5845 return VA_STATUS_SUCCESS;
5848 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES * sizeof(*attribs));
5850 if (attribs == NULL)
5851 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5853 if (IS_G4X(i965->intel.device_info)) {
5854 if (obj_config->profile == VAProfileMPEG2Simple ||
5855 obj_config->profile == VAProfileMPEG2Main) {
5856 attribs[i].type = VASurfaceAttribPixelFormat;
5857 attribs[i].value.type = VAGenericValueTypeInteger;
5858 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5859 attribs[i].value.value.i = VA_FOURCC_I420;
5862 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5863 switch (obj_config->profile) {
5864 case VAProfileMPEG2Simple:
5865 case VAProfileMPEG2Main:
5866 attribs[i].type = VASurfaceAttribPixelFormat;
5867 attribs[i].value.type = VAGenericValueTypeInteger;
5868 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5869 attribs[i].value.value.i = VA_FOURCC_I420;
5874 case VAProfileH264ConstrainedBaseline:
5875 case VAProfileH264Main:
5876 case VAProfileH264High:
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_NV12;
5884 attribs[i].type = VASurfaceAttribPixelFormat;
5885 attribs[i].value.type = VAGenericValueTypeInteger;
5886 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5887 attribs[i].value.value.i = VA_FOURCC_NV12;
5890 attribs[i].type = VASurfaceAttribPixelFormat;
5891 attribs[i].value.type = VAGenericValueTypeInteger;
5892 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5893 attribs[i].value.value.i = VA_FOURCC_I420;
5901 } else if (IS_GEN6(i965->intel.device_info)) {
5902 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5903 attribs[i].type = VASurfaceAttribPixelFormat;
5904 attribs[i].value.type = VAGenericValueTypeInteger;
5905 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5906 attribs[i].value.value.i = VA_FOURCC_NV12;
5908 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5909 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5910 attribs[i].type = VASurfaceAttribPixelFormat;
5911 attribs[i].value.type = VAGenericValueTypeInteger;
5912 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5913 attribs[i].value.value.i = VA_FOURCC_NV12;
5916 attribs[i].type = VASurfaceAttribPixelFormat;
5917 attribs[i].value.type = VAGenericValueTypeInteger;
5918 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5919 attribs[i].value.value.i = VA_FOURCC_I420;
5922 attribs[i].type = VASurfaceAttribPixelFormat;
5923 attribs[i].value.type = VAGenericValueTypeInteger;
5924 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5925 attribs[i].value.value.i = VA_FOURCC_YV12;
5928 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5929 attribs[i].type = VASurfaceAttribPixelFormat;
5930 attribs[i].value.type = VAGenericValueTypeInteger;
5931 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5932 attribs[i].value.value.i = VA_FOURCC_YUY2;
5935 attribs[i].type = VASurfaceAttribPixelFormat;
5936 attribs[i].value.type = VAGenericValueTypeInteger;
5937 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5938 attribs[i].value.value.i = VA_FOURCC_RGBA;
5941 attribs[i].type = VASurfaceAttribPixelFormat;
5942 attribs[i].value.type = VAGenericValueTypeInteger;
5943 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5944 attribs[i].value.value.i = VA_FOURCC_RGBX;
5948 } else if (IS_GEN7(i965->intel.device_info)) {
5949 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5950 if (obj_config->profile == VAProfileJPEGBaseline) {
5951 attribs[i].type = VASurfaceAttribPixelFormat;
5952 attribs[i].value.type = VAGenericValueTypeInteger;
5953 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5954 attribs[i].value.value.i = VA_FOURCC_IMC3;
5957 attribs[i].type = VASurfaceAttribPixelFormat;
5958 attribs[i].value.type = VAGenericValueTypeInteger;
5959 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5960 attribs[i].value.value.i = VA_FOURCC_IMC1;
5963 attribs[i].type = VASurfaceAttribPixelFormat;
5964 attribs[i].value.type = VAGenericValueTypeInteger;
5965 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5966 attribs[i].value.value.i = VA_FOURCC_Y800;
5969 attribs[i].type = VASurfaceAttribPixelFormat;
5970 attribs[i].value.type = VAGenericValueTypeInteger;
5971 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5972 attribs[i].value.value.i = VA_FOURCC_411P;
5975 attribs[i].type = VASurfaceAttribPixelFormat;
5976 attribs[i].value.type = VAGenericValueTypeInteger;
5977 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5978 attribs[i].value.value.i = VA_FOURCC_422H;
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_422V;
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_444P;
5992 } else if (obj_config->profile == VAProfileHEVCMain10) {
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_P010;
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_NV12;
6005 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6006 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
6007 attribs[i].type = VASurfaceAttribPixelFormat;
6008 attribs[i].value.type = VAGenericValueTypeInteger;
6009 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6010 attribs[i].value.value.i = VA_FOURCC_NV12;
6013 attribs[i].type = VASurfaceAttribPixelFormat;
6014 attribs[i].value.type = VAGenericValueTypeInteger;
6015 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6016 attribs[i].value.value.i = VA_FOURCC_I420;
6019 attribs[i].type = VASurfaceAttribPixelFormat;
6020 attribs[i].value.type = VAGenericValueTypeInteger;
6021 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6022 attribs[i].value.value.i = VA_FOURCC_YV12;
6025 attribs[i].type = VASurfaceAttribPixelFormat;
6026 attribs[i].value.type = VAGenericValueTypeInteger;
6027 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6028 attribs[i].value.value.i = VA_FOURCC_IMC3;
6031 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6032 attribs[i].type = VASurfaceAttribPixelFormat;
6033 attribs[i].value.type = VAGenericValueTypeInteger;
6034 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6035 attribs[i].value.value.i = VA_FOURCC_YUY2;
6038 attribs[i].type = VASurfaceAttribPixelFormat;
6039 attribs[i].value.type = VAGenericValueTypeInteger;
6040 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6041 attribs[i].value.value.i = VA_FOURCC_UYVY;
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_RGBA;
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_RGBX;
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_BGRA;
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_BGRX;
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_YV16;
6075 } else if (IS_GEN8(i965->intel.device_info) ||
6076 IS_GEN9(i965->intel.device_info)) {
6077 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
6078 if (obj_config->profile == VAProfileJPEGBaseline) {
6079 attribs[i].type = VASurfaceAttribPixelFormat;
6080 attribs[i].value.type = VAGenericValueTypeInteger;
6081 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6082 attribs[i].value.value.i = VA_FOURCC_IMC3;
6085 attribs[i].type = VASurfaceAttribPixelFormat;
6086 attribs[i].value.type = VAGenericValueTypeInteger;
6087 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6088 attribs[i].value.value.i = VA_FOURCC_IMC1;
6091 attribs[i].type = VASurfaceAttribPixelFormat;
6092 attribs[i].value.type = VAGenericValueTypeInteger;
6093 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6094 attribs[i].value.value.i = VA_FOURCC_Y800;
6097 attribs[i].type = VASurfaceAttribPixelFormat;
6098 attribs[i].value.type = VAGenericValueTypeInteger;
6099 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6100 attribs[i].value.value.i = VA_FOURCC_411P;
6103 attribs[i].type = VASurfaceAttribPixelFormat;
6104 attribs[i].value.type = VAGenericValueTypeInteger;
6105 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6106 attribs[i].value.value.i = VA_FOURCC_422H;
6109 attribs[i].type = VASurfaceAttribPixelFormat;
6110 attribs[i].value.type = VAGenericValueTypeInteger;
6111 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6112 attribs[i].value.value.i = VA_FOURCC_422V;
6115 attribs[i].type = VASurfaceAttribPixelFormat;
6116 attribs[i].value.type = VAGenericValueTypeInteger;
6117 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6118 attribs[i].value.value.i = VA_FOURCC_444P;
6121 attribs[i].type = VASurfaceAttribPixelFormat;
6122 attribs[i].value.type = VAGenericValueTypeInteger;
6123 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6124 attribs[i].value.value.i = VA_FOURCC_NV12;
6127 if ((obj_config->profile == VAProfileHEVCMain10) ||
6128 (obj_config->profile == VAProfileVP9Profile2)) {
6129 attribs[i].type = VASurfaceAttribPixelFormat;
6130 attribs[i].value.type = VAGenericValueTypeInteger;
6131 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6132 attribs[i].value.value.i = VA_FOURCC_P010;
6136 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
6137 obj_config->entrypoint == VAEntrypointVideoProc ||
6138 obj_config->entrypoint == VAEntrypointEncSliceLP ||
6139 obj_config->entrypoint == VAEntrypointEncPicture ||
6140 obj_config->entrypoint == VAEntrypointFEI) {
6142 if (obj_config->profile == VAProfileHEVCMain10) {
6143 attribs[i].type = VASurfaceAttribPixelFormat;
6144 attribs[i].value.type = VAGenericValueTypeInteger;
6145 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6146 attribs[i].value.value.i = VA_FOURCC_P010;
6149 attribs[i].type = VASurfaceAttribPixelFormat;
6150 attribs[i].value.type = VAGenericValueTypeInteger;
6151 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6152 attribs[i].value.value.i = VA_FOURCC_NV12;
6155 attribs[i].type = VASurfaceAttribPixelFormat;
6156 attribs[i].value.type = VAGenericValueTypeInteger;
6157 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6158 attribs[i].value.value.i = VA_FOURCC_I420;
6161 attribs[i].type = VASurfaceAttribPixelFormat;
6162 attribs[i].value.type = VAGenericValueTypeInteger;
6163 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6164 attribs[i].value.value.i = VA_FOURCC_YV12;
6167 attribs[i].type = VASurfaceAttribPixelFormat;
6168 attribs[i].value.type = VAGenericValueTypeInteger;
6169 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6170 attribs[i].value.value.i = VA_FOURCC_IMC3;
6174 if (obj_config->entrypoint == VAEntrypointVideoProc) {
6175 attribs[i].type = VASurfaceAttribPixelFormat;
6176 attribs[i].value.type = VAGenericValueTypeInteger;
6177 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6178 attribs[i].value.value.i = VA_FOURCC_YUY2;
6181 attribs[i].type = VASurfaceAttribPixelFormat;
6182 attribs[i].value.type = VAGenericValueTypeInteger;
6183 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6184 attribs[i].value.value.i = VA_FOURCC_UYVY;
6187 attribs[i].type = VASurfaceAttribPixelFormat;
6188 attribs[i].value.type = VAGenericValueTypeInteger;
6189 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6190 attribs[i].value.value.i = VA_FOURCC_RGBA;
6193 attribs[i].type = VASurfaceAttribPixelFormat;
6194 attribs[i].value.type = VAGenericValueTypeInteger;
6195 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6196 attribs[i].value.value.i = VA_FOURCC_RGBX;
6199 attribs[i].type = VASurfaceAttribPixelFormat;
6200 attribs[i].value.type = VAGenericValueTypeInteger;
6201 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6202 attribs[i].value.value.i = VA_FOURCC_BGRA;
6205 attribs[i].type = VASurfaceAttribPixelFormat;
6206 attribs[i].value.type = VAGenericValueTypeInteger;
6207 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6208 attribs[i].value.value.i = VA_FOURCC_BGRX;
6211 attribs[i].type = VASurfaceAttribPixelFormat;
6212 attribs[i].value.type = VAGenericValueTypeInteger;
6213 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6214 attribs[i].value.value.i = VA_FOURCC_YV16;
6217 if (HAS_VPP_P010(i965)) {
6218 attribs[i].type = VASurfaceAttribPixelFormat;
6219 attribs[i].value.type = VAGenericValueTypeInteger;
6220 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6221 attribs[i].value.value.i = VA_FOURCC_P010;
6224 attribs[i].type = VASurfaceAttribPixelFormat;
6225 attribs[i].value.type = VAGenericValueTypeInteger;
6226 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6227 attribs[i].value.value.i = VA_FOURCC_I010;
6232 /* Additional support for jpeg encoder */
6233 if (obj_config->profile == VAProfileJPEGBaseline
6234 && obj_config->entrypoint == VAEntrypointEncPicture) {
6235 attribs[i].type = VASurfaceAttribPixelFormat;
6236 attribs[i].value.type = VAGenericValueTypeInteger;
6237 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6238 attribs[i].value.value.i = VA_FOURCC_YUY2;
6241 attribs[i].type = VASurfaceAttribPixelFormat;
6242 attribs[i].value.type = VAGenericValueTypeInteger;
6243 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6244 attribs[i].value.value.i = VA_FOURCC_UYVY;
6247 attribs[i].type = VASurfaceAttribPixelFormat;
6248 attribs[i].value.type = VAGenericValueTypeInteger;
6249 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6250 attribs[i].value.value.i = VA_FOURCC_YV16;
6253 attribs[i].type = VASurfaceAttribPixelFormat;
6254 attribs[i].value.type = VAGenericValueTypeInteger;
6255 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6256 attribs[i].value.value.i = VA_FOURCC_Y800;
6262 attribs[i].type = VASurfaceAttribMemoryType;
6263 attribs[i].value.type = VAGenericValueTypeInteger;
6264 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6265 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
6266 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
6267 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
6270 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
6271 attribs[i].value.type = VAGenericValueTypePointer;
6272 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
6273 attribs[i].value.value.p = NULL; /* ignore */
6276 max_resolution(i965, obj_config, &max_width, &max_height);
6278 attribs[i].type = VASurfaceAttribMaxWidth;
6279 attribs[i].value.type = VAGenericValueTypeInteger;
6280 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6281 attribs[i].value.value.i = max_width;
6284 attribs[i].type = VASurfaceAttribMaxHeight;
6285 attribs[i].value.type = VAGenericValueTypeInteger;
6286 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6287 attribs[i].value.value.i = max_height;
6290 if (i > *num_attribs) {
6293 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6297 memcpy(attrib_list, attribs, i * sizeof(*attribs));
6303 /* Acquires buffer handle for external API usage (internal implementation) */
6305 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
6306 uint32_t mem_type, VABufferInfo *out_buf_info)
6308 struct buffer_store *buffer_store;
6310 buffer_store = obj_buffer->buffer_store;
6311 if (!buffer_store || !buffer_store->bo)
6312 return VA_STATUS_ERROR_INVALID_BUFFER;
6314 /* Synchronization point */
6315 drm_intel_bo_wait_rendering(buffer_store->bo);
6317 if (obj_buffer->export_refcount > 0) {
6318 if (obj_buffer->export_state.mem_type != mem_type)
6319 return VA_STATUS_ERROR_INVALID_PARAMETER;
6321 VABufferInfo * const buf_info = &obj_buffer->export_state;
6324 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
6326 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
6327 return VA_STATUS_ERROR_INVALID_BUFFER;
6328 buf_info->handle = name;
6331 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6333 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
6334 return VA_STATUS_ERROR_INVALID_BUFFER;
6335 buf_info->handle = (intptr_t)fd;
6340 buf_info->type = obj_buffer->type;
6341 buf_info->mem_type = mem_type;
6342 buf_info->mem_size =
6343 obj_buffer->num_elements * obj_buffer->size_element;
6346 obj_buffer->export_refcount++;
6347 *out_buf_info = obj_buffer->export_state;
6348 return VA_STATUS_SUCCESS;
6351 /* Releases buffer handle after usage (internal implementation) */
6353 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6355 if (obj_buffer->export_refcount == 0)
6356 return VA_STATUS_ERROR_INVALID_BUFFER;
6358 if (--obj_buffer->export_refcount == 0) {
6359 VABufferInfo * const buf_info = &obj_buffer->export_state;
6361 switch (buf_info->mem_type) {
6362 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6363 close((intptr_t)buf_info->handle);
6367 buf_info->mem_type = 0;
6369 return VA_STATUS_SUCCESS;
6372 /** Acquires buffer handle for external API usage */
6374 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6375 VABufferInfo *buf_info)
6377 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6378 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6379 uint32_t i, mem_type;
6381 /* List of supported memory types, in preferred order */
6382 static const uint32_t mem_types[] = {
6383 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6384 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6389 return VA_STATUS_ERROR_INVALID_BUFFER;
6390 /* XXX: only VA surface|image like buffers are supported for now */
6391 if (obj_buffer->type != VAImageBufferType)
6392 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6395 * As the allocated buffer by calling vaCreateBuffer is related with
6396 * the specific context, it is unnecessary to export it.
6397 * So it is not supported when the buffer is allocated from wrapped
6400 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6401 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6405 return VA_STATUS_ERROR_INVALID_PARAMETER;
6407 if (!buf_info->mem_type)
6408 mem_type = mem_types[0];
6411 for (i = 0; mem_types[i] != 0; i++) {
6412 if (buf_info->mem_type & mem_types[i]) {
6413 mem_type = buf_info->mem_type;
6418 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6420 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6423 /** Releases buffer handle after usage from external API */
6425 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6427 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6428 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6431 return VA_STATUS_ERROR_INVALID_BUFFER;
6433 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6434 return VA_STATUS_ERROR_INVALID_BUFFER;
6437 return i965_release_buffer_handle(obj_buffer);
6440 // Locally define DRM_FORMAT values not available in older but still
6441 // supported versions of libdrm.
6442 #ifndef DRM_FORMAT_R8
6443 #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ')
6445 #ifndef DRM_FORMAT_R16
6446 #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ')
6448 #ifndef DRM_FORMAT_GR88
6449 #define DRM_FORMAT_GR88 fourcc_code('G', 'R', '8', '8')
6451 #ifndef DRM_FORMAT_GR1616
6452 #define DRM_FORMAT_GR1616 fourcc_code('G', 'R', '3', '2')
6455 static uint32_t drm_format_of_separate_plane(uint32_t fourcc, int plane)
6459 case VA_FOURCC_NV12:
6460 case VA_FOURCC_I420:
6461 case VA_FOURCC_YV12:
6462 case VA_FOURCC_YV16:
6463 case VA_FOURCC_Y800:
6464 return DRM_FORMAT_R8;
6465 case VA_FOURCC_P010:
6466 case VA_FOURCC_I010:
6467 return DRM_FORMAT_R16;
6469 case VA_FOURCC_YUY2:
6470 case VA_FOURCC_UYVY:
6471 // These are not representable as separate planes.
6474 case VA_FOURCC_RGBA:
6475 return DRM_FORMAT_ABGR8888;
6476 case VA_FOURCC_RGBX:
6477 return DRM_FORMAT_XBGR8888;
6478 case VA_FOURCC_BGRA:
6479 return DRM_FORMAT_ARGB8888;
6480 case VA_FOURCC_BGRX:
6481 return DRM_FORMAT_XRGB8888;
6482 case VA_FOURCC_ARGB:
6483 return DRM_FORMAT_BGRA8888;
6484 case VA_FOURCC_ABGR:
6485 return DRM_FORMAT_RGBA8888;
6489 case VA_FOURCC_NV12:
6490 return DRM_FORMAT_GR88;
6491 case VA_FOURCC_I420:
6492 case VA_FOURCC_YV12:
6493 case VA_FOURCC_YV16:
6494 return DRM_FORMAT_R8;
6495 case VA_FOURCC_P010:
6496 return DRM_FORMAT_GR1616;
6497 case VA_FOURCC_I010:
6498 return DRM_FORMAT_R16;
6504 static uint32_t drm_format_of_composite_object(uint32_t fourcc)
6507 case VA_FOURCC_NV12:
6508 return DRM_FORMAT_NV12;
6509 case VA_FOURCC_I420:
6510 return DRM_FORMAT_YUV420;
6511 case VA_FOURCC_YV12:
6512 return DRM_FORMAT_YVU420;
6513 case VA_FOURCC_YV16:
6514 return DRM_FORMAT_YVU422;
6515 case VA_FOURCC_YUY2:
6516 return DRM_FORMAT_YUYV;
6517 case VA_FOURCC_UYVY:
6518 return DRM_FORMAT_UYVY;
6519 case VA_FOURCC_Y800:
6520 return DRM_FORMAT_R8;
6522 case VA_FOURCC_P010:
6523 case VA_FOURCC_I010:
6524 // These currently have no composite DRM format - they are usable
6525 // only as separate planes.
6528 case VA_FOURCC_RGBA:
6529 return DRM_FORMAT_ABGR8888;
6530 case VA_FOURCC_RGBX:
6531 return DRM_FORMAT_XBGR8888;
6532 case VA_FOURCC_BGRA:
6533 return DRM_FORMAT_ARGB8888;
6534 case VA_FOURCC_BGRX:
6535 return DRM_FORMAT_XRGB8888;
6536 case VA_FOURCC_ARGB:
6537 return DRM_FORMAT_BGRA8888;
6538 case VA_FOURCC_ABGR:
6539 return DRM_FORMAT_RGBA8888;
6545 i965_ExportSurfaceHandle(VADriverContextP ctx, VASurfaceID surface_id,
6546 uint32_t mem_type, uint32_t flags,
6549 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6550 struct object_surface *obj_surface = SURFACE(surface_id);
6551 const i965_fourcc_info *info;
6552 VADRMPRIMESurfaceDescriptor *desc;
6553 unsigned int tiling, swizzle;
6554 uint32_t formats[4], pitch, height, offset;
6556 int composite_object =
6557 flags & VA_EXPORT_SURFACE_COMPOSED_LAYERS;
6559 if (!obj_surface || !obj_surface->bo)
6560 return VA_STATUS_ERROR_INVALID_SURFACE;
6562 if (mem_type != VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2) {
6563 i965_log_info(ctx, "vaExportSurfaceHandle: memory type %08x "
6564 "is not supported.\n", mem_type);
6565 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6568 info = get_fourcc_info(obj_surface->fourcc);
6570 return VA_STATUS_ERROR_INVALID_SURFACE;
6571 if (composite_object) {
6573 drm_format_of_composite_object(obj_surface->fourcc);
6575 i965_log_info(ctx, "vaExportSurfaceHandle: fourcc %08x "
6576 "is not supported for export as a composite "
6577 "object.\n", obj_surface->fourcc);
6578 return VA_STATUS_ERROR_INVALID_SURFACE;
6581 for (p = 0; p < info->num_planes; p++) {
6583 drm_format_of_separate_plane(obj_surface->fourcc, p);
6585 i965_log_info(ctx, "vaExportSurfaceHandle: fourcc %08x "
6586 "is not supported for export as separate "
6587 "planes.\n", obj_surface->fourcc);
6588 return VA_STATUS_ERROR_INVALID_SURFACE;
6593 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd))
6594 return VA_STATUS_ERROR_INVALID_SURFACE;
6596 if (drm_intel_bo_get_tiling(obj_surface->bo, &tiling, &swizzle))
6597 tiling = I915_TILING_NONE;
6601 desc->fourcc = obj_surface->fourcc;
6602 desc->width = obj_surface->width;
6603 desc->height = obj_surface->height;
6605 desc->num_objects = 1;
6606 desc->objects[0].fd = fd;
6607 desc->objects[0].size = obj_surface->size;
6610 desc->objects[0].drm_format_modifier = I915_FORMAT_MOD_X_TILED;
6613 desc->objects[0].drm_format_modifier = I915_FORMAT_MOD_Y_TILED;
6615 case I915_TILING_NONE:
6617 desc->objects[0].drm_format_modifier = DRM_FORMAT_MOD_NONE;
6620 if (composite_object) {
6621 desc->num_layers = 1;
6623 desc->layers[0].drm_format = formats[0];
6624 desc->layers[0].num_planes = info->num_planes;
6627 for (p = 0; p < info->num_planes; p++) {
6628 desc->layers[0].object_index[p] = 0;
6631 pitch = obj_surface->width;
6632 height = obj_surface->height;
6634 pitch = obj_surface->cb_cr_pitch;
6635 height = obj_surface->cb_cr_height;
6638 desc->layers[0].offset[p] = offset;
6639 desc->layers[0].pitch[p] = pitch;
6641 offset += pitch * height;
6644 desc->num_layers = info->num_planes;
6647 for (p = 0; p < info->num_planes; p++) {
6648 desc->layers[p].drm_format = formats[p];
6649 desc->layers[p].num_planes = 1;
6651 desc->layers[p].object_index[0] = 0;
6654 pitch = obj_surface->width;
6655 height = obj_surface->height;
6657 pitch = obj_surface->cb_cr_pitch;
6658 height = obj_surface->cb_cr_height;
6661 desc->layers[p].offset[0] = offset;
6662 desc->layers[p].pitch[0] = pitch;
6664 offset += pitch * height;
6668 return VA_STATUS_SUCCESS;
6672 i965_os_has_ring_support(VADriverContextP ctx,
6675 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6679 return i965->intel.has_bsd;
6682 return i965->intel.has_blt;
6684 case I965_RING_VEBOX:
6685 return i965->intel.has_vebox;
6687 case I965_RING_NULL:
6688 return 1; /* Always support */
6691 /* should never get here */
6700 * Query video processing pipeline
6702 VAStatus i965_QueryVideoProcFilters(
6703 VADriverContextP ctx,
6704 VAContextID context,
6705 VAProcFilterType *filters,
6706 unsigned int *num_filters
6709 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6710 unsigned int i = 0, num = 0;
6712 if (!num_filters || !filters)
6713 return VA_STATUS_ERROR_INVALID_PARAMETER;
6715 for (i = 0; i < i965->codec_info->num_filters; i++) {
6716 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6717 if (num == *num_filters) {
6718 *num_filters = i965->codec_info->num_filters;
6720 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6723 filters[num++] = i965->codec_info->filters[i].type;
6729 return VA_STATUS_SUCCESS;
6732 VAStatus i965_QueryVideoProcFilterCaps(
6733 VADriverContextP ctx,
6734 VAContextID context,
6735 VAProcFilterType type,
6737 unsigned int *num_filter_caps
6741 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6743 if (!filter_caps || !num_filter_caps)
6744 return VA_STATUS_ERROR_INVALID_PARAMETER;
6746 for (i = 0; i < i965->codec_info->num_filters; i++) {
6747 if (type == i965->codec_info->filters[i].type &&
6748 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6752 if (i == i965->codec_info->num_filters)
6753 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6758 case VAProcFilterNoiseReduction:
6759 case VAProcFilterSharpening: {
6760 VAProcFilterCap *cap = filter_caps;
6762 if (*num_filter_caps < 1) {
6763 *num_filter_caps = 1;
6764 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6767 cap->range.min_value = 0.0;
6768 cap->range.max_value = 1.0;
6769 cap->range.default_value = 0.5;
6770 cap->range.step = 0.03125; /* 1.0 / 32 */
6776 case VAProcFilterDeinterlacing: {
6777 VAProcFilterCapDeinterlacing *cap = filter_caps;
6779 if (*num_filter_caps < VAProcDeinterlacingCount) {
6780 *num_filter_caps = VAProcDeinterlacingCount;
6781 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6784 cap->type = VAProcDeinterlacingBob;
6789 if (i965->codec_info->has_di_motion_adptive) {
6790 cap->type = VAProcDeinterlacingMotionAdaptive;
6795 if (i965->codec_info->has_di_motion_compensated) {
6796 cap->type = VAProcDeinterlacingMotionCompensated;
6804 case VAProcFilterColorBalance: {
6805 VAProcFilterCapColorBalance *cap = filter_caps;
6807 if (*num_filter_caps < VAProcColorBalanceCount) {
6808 *num_filter_caps = VAProcColorBalanceCount;
6809 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6812 cap->type = VAProcColorBalanceHue;
6813 cap->range.min_value = -180.0;
6814 cap->range.max_value = 180.0;
6815 cap->range.default_value = 0.0;
6816 cap->range.step = 1.0;
6820 cap->type = VAProcColorBalanceSaturation;
6821 cap->range.min_value = 0.0;
6822 cap->range.max_value = 10.0;
6823 cap->range.default_value = 1.0;
6824 cap->range.step = 0.1;
6828 cap->type = VAProcColorBalanceBrightness;
6829 cap->range.min_value = -100.0;
6830 cap->range.max_value = 100.0;
6831 cap->range.default_value = 0.0;
6832 cap->range.step = 1.0;
6836 cap->type = VAProcColorBalanceContrast;
6837 cap->range.min_value = 0.0;
6838 cap->range.max_value = 10.0;
6839 cap->range.default_value = 1.0;
6840 cap->range.step = 0.1;
6852 *num_filter_caps = i;
6854 return VA_STATUS_SUCCESS;
6857 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6858 VAProcColorStandardBT601,
6861 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6862 VAProcColorStandardBT601,
6865 VAStatus i965_QueryVideoProcPipelineCaps(
6866 VADriverContextP ctx,
6867 VAContextID context,
6868 VABufferID *filters,
6869 unsigned int num_filters,
6870 VAProcPipelineCaps *pipeline_cap /* out */
6873 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6876 pipeline_cap->pipeline_flags = 0;
6877 pipeline_cap->filter_flags = 0;
6878 pipeline_cap->num_forward_references = 0;
6879 pipeline_cap->num_backward_references = 0;
6880 pipeline_cap->num_input_color_standards = 1;
6881 pipeline_cap->input_color_standards = vpp_input_color_standards;
6882 pipeline_cap->num_output_color_standards = 1;
6883 pipeline_cap->output_color_standards = vpp_output_color_standards;
6885 for (i = 0; i < num_filters; i++) {
6886 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6889 !obj_buffer->buffer_store ||
6890 !obj_buffer->buffer_store->buffer)
6891 return VA_STATUS_ERROR_INVALID_BUFFER;
6893 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6895 if (base->type == VAProcFilterNoiseReduction) {
6896 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6898 } else if (base->type == VAProcFilterDeinterlacing) {
6899 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6901 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6902 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6903 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6904 VA_STATUS_ERROR_INVALID_PARAMETER);
6906 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6907 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6908 pipeline_cap->num_forward_references++;
6909 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6910 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6915 return VA_STATUS_SUCCESS;
6918 void i965_log_error(VADriverContextP ctx, const char *format, ...)
6922 va_start(vl, format);
6924 if (!ctx->error_callback) {
6925 // No error callback: this is a error message which should be
6926 // user-visible, so print it to stderr instead.
6927 vfprintf(stderr, format, vl);
6929 // Put the message on the stack. If it overruns the size of the
6930 // then it will just be truncated - callers shouldn't be sending
6931 // messages which are too long.
6934 ret = vsnprintf(tmp, sizeof(tmp), format, vl);
6936 ctx->error_callback(ctx, tmp);
6942 void i965_log_info(VADriverContextP ctx, const char *format, ...)
6946 va_start(vl, format);
6948 if (!ctx->info_callback) {
6949 // No info callback: this message is only useful for developers,
6950 // so just discard it.
6952 // Put the message on the stack. If it overruns the size of the
6953 // then it will just be truncated - callers shouldn't be sending
6954 // messages which are too long.
6957 ret = vsnprintf(tmp, sizeof(tmp), format, vl);
6959 ctx->info_callback(ctx, tmp);
6965 extern struct hw_codec_info *i965_get_codec_info(int devid);
6968 i965_driver_data_init(VADriverContextP ctx)
6970 struct i965_driver_data *i965 = i965_driver_data(ctx);
6972 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6974 if (!i965->codec_info)
6977 if (object_heap_init(&i965->config_heap,
6978 sizeof(struct object_config),
6980 goto err_config_heap;
6981 if (object_heap_init(&i965->context_heap,
6982 sizeof(struct object_context),
6984 goto err_context_heap;
6986 if (object_heap_init(&i965->surface_heap,
6987 sizeof(struct object_surface),
6989 goto err_surface_heap;
6990 if (object_heap_init(&i965->buffer_heap,
6991 sizeof(struct object_buffer),
6993 goto err_buffer_heap;
6994 if (object_heap_init(&i965->image_heap,
6995 sizeof(struct object_image),
6997 goto err_image_heap;
6998 if (object_heap_init(&i965->subpic_heap,
6999 sizeof(struct object_subpic),
7001 goto err_subpic_heap;
7003 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
7004 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
7005 _i965InitMutex(&i965->render_mutex);
7006 _i965InitMutex(&i965->pp_mutex);
7011 object_heap_destroy(&i965->image_heap);
7013 object_heap_destroy(&i965->buffer_heap);
7015 object_heap_destroy(&i965->surface_heap);
7017 object_heap_destroy(&i965->context_heap);
7019 object_heap_destroy(&i965->config_heap);
7026 i965_driver_data_terminate(VADriverContextP ctx)
7028 struct i965_driver_data *i965 = i965_driver_data(ctx);
7030 _i965DestroyMutex(&i965->pp_mutex);
7031 _i965DestroyMutex(&i965->render_mutex);
7034 intel_batchbuffer_free(i965->batch);
7037 intel_batchbuffer_free(i965->pp_batch);
7039 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
7040 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
7041 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
7042 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
7043 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
7044 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
7048 bool (*init)(VADriverContextP ctx);
7049 void (*terminate)(VADriverContextP ctx);
7051 } i965_sub_ops[] = {
7054 intel_driver_terminate,
7059 i965_driver_data_init,
7060 i965_driver_data_terminate,
7065 i965_display_attributes_init,
7066 i965_display_attributes_terminate,
7071 i965_post_processing_init,
7072 i965_post_processing_terminate,
7078 i965_render_terminate,
7082 #ifdef HAVE_VA_WAYLAND
7084 i965_output_wayland_init,
7085 i965_output_wayland_terminate,
7092 i965_output_dri_init,
7093 i965_output_dri_terminate,
7099 i965_gpe_table_init,
7100 i965_gpe_table_terminate,
7106 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
7110 if (i965->va_vendor[0] != '\0')
7114 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
7115 "%s %s driver for %s - %d.%d.%d",
7116 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
7117 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
7118 INTEL_DRIVER_MICRO_VERSION);
7119 if (ret < 0 || ret >= sizeof(i965->va_vendor))
7123 if (INTEL_DRIVER_PRE_VERSION > 0) {
7124 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
7125 ".pre%d", INTEL_DRIVER_PRE_VERSION);
7126 if (ret < 0 || ret >= sizeof(i965->va_vendor))
7130 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
7131 " (%s)", INTEL_DRIVER_GIT_VERSION);
7132 if (ret < 0 || ret >= sizeof(i965->va_vendor))
7139 i965->va_vendor[0] = '\0';
7140 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
7144 /* Only when the option of "enable-wrapper" is passed, it is possible
7145 * to initialize/load the wrapper context of backend driver.
7146 * Otherwise it is not loaded.
7148 #if HAVE_HYBRID_CODEC
7151 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
7153 #define DRIVER_EXTENSION "_drv_video.so"
7155 struct i965_driver_data *i965 = i965_driver_data(ctx);
7157 VADriverContextP wrapper_pdrvctx;
7158 struct VADriverVTable *vtable;
7159 char *search_path, *driver_dir;
7161 char driver_path[256];
7162 void *handle = NULL;
7163 VAStatus va_status = VA_STATUS_SUCCESS;
7164 bool driver_loaded = false;
7166 if (HAS_VP9_DECODING(i965)) {
7167 i965->wrapper_pdrvctx = NULL;
7171 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
7172 vtable = calloc(1, sizeof(*vtable));
7174 if (!wrapper_pdrvctx || !vtable) {
7175 fprintf(stderr, "Failed to allocate memory for wrapper \n");
7176 free(wrapper_pdrvctx);
7178 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7181 /* use the same drm_state with CTX */
7182 wrapper_pdrvctx->drm_state = ctx->drm_state;
7183 wrapper_pdrvctx->display_type = ctx->display_type;
7184 wrapper_pdrvctx->vtable = vtable;
7186 search_path = VA_DRIVERS_PATH;
7187 search_path = strdup((const char *)search_path);
7189 driver_dir = strtok_r(search_path, ":", &saveptr);
7190 while (driver_dir && !driver_loaded) {
7191 memset(driver_path, 0, sizeof(driver_path));
7192 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
7194 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
7196 fprintf(stderr, "failed to open %s\n", driver_path);
7197 driver_dir = strtok_r(NULL, ":", &saveptr);
7201 VADriverInit init_func = NULL;
7202 char init_func_s[256];
7205 static const struct {
7208 } compatible_versions[] = {
7209 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
7218 for (i = 0; compatible_versions[i].major >= 0; i++) {
7219 snprintf(init_func_s, sizeof(init_func_s),
7220 "__vaDriverInit_%d_%d",
7221 compatible_versions[i].major,
7222 compatible_versions[i].minor);
7223 init_func = (VADriverInit)dlsym(handle, init_func_s);
7228 if (compatible_versions[i].major < 0) {
7230 fprintf(stderr, "%s has no function %s\n",
7231 driver_path, init_func_s);
7232 driver_dir = strtok_r(NULL, ":", &saveptr);
7237 va_status = (*init_func)(wrapper_pdrvctx);
7239 if (va_status != VA_STATUS_SUCCESS) {
7241 fprintf(stderr, "%s init failed\n", driver_path);
7242 driver_dir = strtok_r(NULL, ":", &saveptr);
7246 wrapper_pdrvctx->handle = handle;
7247 driver_loaded = true;
7253 if (driver_loaded) {
7254 i965->wrapper_pdrvctx = wrapper_pdrvctx;
7255 return VA_STATUS_SUCCESS;
7257 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
7259 free(wrapper_pdrvctx);
7260 return VA_STATUS_ERROR_OPERATION_FAILED;
7266 i965_Init(VADriverContextP ctx)
7268 struct i965_driver_data *i965 = i965_driver_data(ctx);
7270 const char *chipset;
7272 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
7273 if ((i965_sub_ops[i].display_type == 0 ||
7274 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
7275 !i965_sub_ops[i].init(ctx))
7279 if (i == ARRAY_ELEMS(i965_sub_ops)) {
7280 switch (i965->intel.device_id) {
7282 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
7283 #include "i965_pciids.h"
7285 chipset = "Unknown Intel Chipset";
7289 if (!ensure_vendor_string(i965, chipset))
7290 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7292 i965->current_context_id = VA_INVALID_ID;
7294 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
7295 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
7297 #if HAVE_HYBRID_CODEC
7298 i965_initialize_wrapper(ctx, "hybrid");
7301 return VA_STATUS_SUCCESS;
7305 for (; i >= 0; i--) {
7306 if (i965_sub_ops[i].display_type == 0 ||
7307 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
7308 i965_sub_ops[i].terminate(ctx);
7312 return VA_STATUS_ERROR_UNKNOWN;
7317 i965_Terminate(VADriverContextP ctx)
7319 struct i965_driver_data *i965 = i965_driver_data(ctx);
7323 #if HAVE_HYBRID_CODEC
7324 if (i965->wrapper_pdrvctx) {
7325 VADriverContextP pdrvctx;
7326 pdrvctx = i965->wrapper_pdrvctx;
7327 if (pdrvctx->handle) {
7328 pdrvctx->vtable->vaTerminate(pdrvctx);
7329 dlclose(pdrvctx->handle);
7330 pdrvctx->handle = NULL;
7332 free(pdrvctx->vtable);
7334 i965->wrapper_pdrvctx = NULL;
7338 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
7339 if (i965_sub_ops[i - 1].display_type == 0 ||
7340 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
7341 i965_sub_ops[i - 1].terminate(ctx);
7345 ctx->pDriverData = NULL;
7348 return VA_STATUS_SUCCESS;
7352 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
7355 VA_DRIVER_INIT_FUNC(VADriverContextP ctx)
7357 struct VADriverVTable * const vtable = ctx->vtable;
7358 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
7360 struct i965_driver_data *i965;
7361 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
7363 ctx->version_major = VA_MAJOR_VERSION;
7364 ctx->version_minor = VA_MINOR_VERSION;
7365 ctx->max_profiles = I965_MAX_PROFILES;
7366 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
7367 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
7368 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
7369 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
7370 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
7372 vtable->vaTerminate = i965_Terminate;
7373 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
7374 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
7375 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
7376 vtable->vaCreateConfig = i965_CreateConfig;
7377 vtable->vaDestroyConfig = i965_DestroyConfig;
7378 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
7379 vtable->vaCreateSurfaces = i965_CreateSurfaces;
7380 vtable->vaDestroySurfaces = i965_DestroySurfaces;
7381 vtable->vaCreateContext = i965_CreateContext;
7382 vtable->vaDestroyContext = i965_DestroyContext;
7383 vtable->vaCreateBuffer = i965_CreateBuffer;
7384 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
7385 vtable->vaMapBuffer = i965_MapBuffer;
7386 vtable->vaUnmapBuffer = i965_UnmapBuffer;
7387 vtable->vaDestroyBuffer = i965_DestroyBuffer;
7388 vtable->vaBeginPicture = i965_BeginPicture;
7389 vtable->vaRenderPicture = i965_RenderPicture;
7390 vtable->vaEndPicture = i965_EndPicture;
7391 vtable->vaSyncSurface = i965_SyncSurface;
7392 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
7393 vtable->vaPutSurface = i965_PutSurface;
7394 vtable->vaQueryImageFormats = i965_QueryImageFormats;
7395 vtable->vaCreateImage = i965_CreateImage;
7396 vtable->vaDeriveImage = i965_DeriveImage;
7397 vtable->vaDestroyImage = i965_DestroyImage;
7398 vtable->vaSetImagePalette = i965_SetImagePalette;
7399 vtable->vaGetImage = i965_GetImage;
7400 vtable->vaPutImage = i965_PutImage;
7401 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
7402 vtable->vaCreateSubpicture = i965_CreateSubpicture;
7403 vtable->vaDestroySubpicture = i965_DestroySubpicture;
7404 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
7405 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
7406 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
7407 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
7408 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
7409 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
7410 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
7411 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
7412 vtable->vaBufferInfo = i965_BufferInfo;
7413 vtable->vaLockSurface = i965_LockSurface;
7414 vtable->vaUnlockSurface = i965_UnlockSurface;
7415 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
7416 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
7417 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
7420 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
7421 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
7424 vtable->vaExportSurfaceHandle = i965_ExportSurfaceHandle;
7426 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
7427 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
7428 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
7430 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
7433 ctx->pDriverData = NULL;
7435 return VA_STATUS_ERROR_ALLOCATION_FAILED;
7438 i965->wrapper_pdrvctx = NULL;
7439 ctx->pDriverData = (void *)i965;
7440 ret = i965_Init(ctx);
7442 if (ret == VA_STATUS_SUCCESS) {
7443 ctx->str_vendor = i965->va_vendor;
7446 ctx->pDriverData = NULL;