2 * Copyright ?2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
35 # include "i965_output_dri.h"
38 #ifdef HAVE_VA_WAYLAND
39 # include "i965_output_wayland.h"
42 #include "intel_version.h"
43 #include "intel_driver.h"
44 #include "intel_memman.h"
45 #include "intel_batchbuffer.h"
46 #include "i965_defines.h"
47 #include "i965_drv_video.h"
48 #include "i965_decoder.h"
49 #include "i965_encoder.h"
51 #include "i965_post_processing.h"
53 #include "gen9_vp9_encapi.h"
55 #define CONFIG_ID_OFFSET 0x01000000
56 #define CONTEXT_ID_OFFSET 0x02000000
57 #define SURFACE_ID_OFFSET 0x04000000
58 #define BUFFER_ID_OFFSET 0x08000000
59 #define IMAGE_ID_OFFSET 0x0a000000
60 #define SUBPIC_ID_OFFSET 0x10000000
62 static int get_sampling_from_fourcc(unsigned int fourcc);
64 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
65 #define IS_VA_X11(ctx) \
66 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
68 /* Check whether we are rendering to Wayland */
69 #define IS_VA_WAYLAND(ctx) \
70 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
73 #define I965_2BITS (I965_BIT << 1)
74 #define I965_4BITS (I965_BIT << 2)
75 #define I965_8BITS (I965_BIT << 3)
76 #define I965_16BITS (I965_BIT << 4)
77 #define I965_32BITS (I965_BIT << 5)
89 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
90 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
91 #define I_I420 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
94 #define I_YV12 2, 2, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
97 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
99 #define I_I010 2, 2, 3, {I965_16BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
101 #define I_422H 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
102 #define I_422V 1, 2, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
103 #define I_YV16 2, 1, 3, {I965_8BITS, I965_4BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_2, OFFSET_0}, {PLANE_1, OFFSET_0} }
104 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
105 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
107 #define I_444P 1, 1, 3, {I965_8BITS, I965_8BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
109 #define I_411P 4, 1, 3, {I965_8BITS, I965_2BITS, I965_2BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_2, OFFSET_0} }
111 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
113 #define I_RGBA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24} }
114 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
115 #define I_BGRA 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_24} }
116 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
118 #define I_ARGB 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_0} }
119 #define I_ABGR 1, 1, 1, {I965_32BITS}, 4, { {PLANE_0, OFFSET_24}, {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
121 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
122 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
124 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
125 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
130 #define I_SI (I_S | I_I)
132 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
133 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
134 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
135 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
137 static const i965_fourcc_info i965_fourcc_infos[] = {
138 DEF_YUV(NV12, YUV420, I_SI),
139 DEF_YUV(I420, YUV420, I_SI),
140 DEF_YUV(IYUV, YUV420, I_S),
141 DEF_YUV(IMC3, YUV420, I_S),
142 DEF_YUV(YV12, YUV420, I_SI),
143 DEF_YUV(IMC1, YUV420, I_S),
145 DEF_YUV(P010, YUV420, I_SI),
146 DEF_YUV(I010, YUV420, I_S),
148 DEF_YUV(422H, YUV422H, I_SI),
149 DEF_YUV(422V, YUV422V, I_S),
150 DEF_YUV(YV16, YUV422H, I_S),
151 DEF_YUV(YUY2, YUV422H, I_SI),
152 DEF_YUV(UYVY, YUV422H, I_SI),
154 DEF_YUV(444P, YUV444, I_S),
156 DEF_YUV(411P, YUV411, I_S),
158 DEF_YUV(Y800, YUV400, I_S),
160 DEF_RGB(RGBA, RGBX, I_SI),
161 DEF_RGB(RGBX, RGBX, I_SI),
162 DEF_RGB(BGRA, RGBX, I_SI),
163 DEF_RGB(BGRX, RGBX, I_SI),
165 DEF_RGB(ARGB, RGBX, I_I),
166 DEF_RGB(ABGR, RGBX, I_I),
168 DEF_INDEX(IA88, RGBX, I_I),
169 DEF_INDEX(AI88, RGBX, I_I),
171 DEF_INDEX(IA44, RGBX, I_I),
172 DEF_INDEX(AI44, RGBX, I_I)
175 const i965_fourcc_info *
176 get_fourcc_info(unsigned int fourcc)
180 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
181 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
183 if (info->fourcc == fourcc)
191 get_bpp_from_fourcc(unsigned int fourcc)
193 const i965_fourcc_info *info = get_fourcc_info(fourcc);
195 unsigned int bpp = 0;
200 for (i = 0; i < info->num_planes; i++)
207 I965_SURFACETYPE_RGBA = 1,
208 I965_SURFACETYPE_YUV,
209 I965_SURFACETYPE_INDEXED
212 /* List of supported display attributes */
213 static const VADisplayAttribute i965_display_attributes[] = {
215 VADisplayAttribBrightness,
216 -100, 100, DEFAULT_BRIGHTNESS,
217 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
221 VADisplayAttribContrast,
222 0, 100, DEFAULT_CONTRAST,
223 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
228 -180, 180, DEFAULT_HUE,
229 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
233 VADisplayAttribSaturation,
234 0, 100, DEFAULT_SATURATION,
235 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
239 VADisplayAttribRotation,
240 0, 3, VA_ROTATION_NONE,
241 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
245 /* List of supported image formats */
248 VAImageFormat va_format;
249 } i965_image_format_map_t;
251 static const i965_image_format_map_t
252 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
253 { I965_SURFACETYPE_YUV,
254 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
255 { I965_SURFACETYPE_YUV,
256 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
257 { I965_SURFACETYPE_YUV,
258 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
259 { I965_SURFACETYPE_YUV,
260 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
261 { I965_SURFACETYPE_YUV,
262 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
263 { I965_SURFACETYPE_YUV,
264 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
265 { I965_SURFACETYPE_RGBA,
266 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
267 { I965_SURFACETYPE_RGBA,
268 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
269 { I965_SURFACETYPE_YUV,
270 { VA_FOURCC_P010, VA_LSB_FIRST, 24, } },
273 /* List of supported subpicture formats */
277 VAImageFormat va_format;
278 unsigned int va_flags;
279 } i965_subpic_format_map_t;
281 #define COMMON_SUBPICTURE_FLAGS \
282 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
283 VA_SUBPICTURE_GLOBAL_ALPHA)
285 static const i965_subpic_format_map_t
286 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
287 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
288 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
289 COMMON_SUBPICTURE_FLAGS },
290 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
291 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
292 COMMON_SUBPICTURE_FLAGS },
293 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
294 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
295 COMMON_SUBPICTURE_FLAGS },
296 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
297 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
298 COMMON_SUBPICTURE_FLAGS },
299 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
300 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
301 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
302 COMMON_SUBPICTURE_FLAGS },
303 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
304 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
305 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
306 COMMON_SUBPICTURE_FLAGS },
309 static const i965_subpic_format_map_t *
310 get_subpic_format(const VAImageFormat *va_format)
313 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
314 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
315 if (m->va_format.fourcc == va_format->fourcc &&
316 (m->type == I965_SURFACETYPE_RGBA ?
317 (m->va_format.byte_order == va_format->byte_order &&
318 m->va_format.red_mask == va_format->red_mask &&
319 m->va_format.green_mask == va_format->green_mask &&
320 m->va_format.blue_mask == va_format->blue_mask &&
321 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
327 /* Checks whether the surface is in busy state */
329 is_surface_busy(struct i965_driver_data *i965,
330 struct object_surface *obj_surface)
332 assert(obj_surface != NULL);
334 if (obj_surface->locked_image_id != VA_INVALID_ID)
336 if (obj_surface->derived_image_id != VA_INVALID_ID)
341 /* Checks whether the image is in busy state */
343 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
345 struct object_buffer *obj_buffer;
347 assert(obj_image != NULL);
349 if (obj_image->derived_surface != VA_INVALID_ID &&
350 obj_image->derived_surface == surface)
353 obj_buffer = BUFFER(obj_image->image.buf);
354 if (obj_buffer && obj_buffer->export_refcount > 0)
359 #define I965_PACKED_HEADER_BASE 0
360 #define I965_SEQ_PACKED_HEADER_BASE 0
361 #define I965_SEQ_PACKED_HEADER_END 2
362 #define I965_PIC_PACKED_HEADER_BASE 2
363 #define I965_PACKED_MISC_HEADER_BASE 4
366 va_enc_packed_type_to_idx(int packed_type)
370 if (packed_type & VAEncPackedHeaderMiscMask) {
371 idx = I965_PACKED_MISC_HEADER_BASE;
372 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
373 ASSERT_RET(packed_type > 0, 0);
374 idx += (packed_type - 1);
376 idx = I965_PACKED_HEADER_BASE;
378 switch (packed_type) {
379 case VAEncPackedHeaderSequence:
380 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
383 case VAEncPackedHeaderPicture:
384 idx = I965_PIC_PACKED_HEADER_BASE + 0;
387 case VAEncPackedHeaderSlice:
388 idx = I965_PIC_PACKED_HEADER_BASE + 1;
392 /* Should not get here */
398 ASSERT_RET(idx < 5, 0);
402 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
405 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
407 struct i965_driver_data *i965 = i965_driver_data(ctx);
408 struct object_surface *obj_surface = SURFACE(surface);
409 VAStatus va_status = VA_STATUS_SUCCESS;
412 return VA_STATUS_ERROR_INVALID_SURFACE;
415 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
416 /* the wrapped surface already exists. just return it */
420 if (obj_surface->fourcc == 0)
421 i965_check_alloc_surface_bo(ctx, obj_surface,
422 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
425 * TBD: Support more surface formats.
426 * Currently only NV12 is support as NV12 is used by decoding.
428 if (obj_surface->fourcc != VA_FOURCC_NV12 )
429 return VA_STATUS_ERROR_INVALID_PARAMETER;
431 if ((i965->wrapper_pdrvctx == NULL) ||
432 (obj_surface->bo == NULL))
433 return VA_STATUS_ERROR_INVALID_PARAMETER;
437 VASurfaceAttrib attrib_list[2];
438 VASurfaceAttribExternalBuffers buffer_descriptor;
439 VAGenericID wrapper_surface;
441 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
442 return VA_STATUS_ERROR_OPERATION_FAILED;
444 obj_surface->exported_primefd = fd_handle;
446 memset(&attrib_list, 0, sizeof(attrib_list));
447 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
449 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
450 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
451 attrib_list[0].value.value.p = &buffer_descriptor;
452 attrib_list[0].value.type = VAGenericValueTypePointer;
454 attrib_list[1].type = VASurfaceAttribMemoryType;
455 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
456 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
457 attrib_list[1].value.type = VAGenericValueTypeInteger;
459 buffer_descriptor.num_buffers = 1;
460 buffer_descriptor.num_planes = 2;
461 buffer_descriptor.width = obj_surface->orig_width;
462 buffer_descriptor.height = obj_surface->orig_height;
463 buffer_descriptor.pixel_format = obj_surface->fourcc;
464 buffer_descriptor.data_size = obj_surface->size;
465 buffer_descriptor.pitches[0] = obj_surface->width;
466 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
467 buffer_descriptor.offsets[0] = 0;
468 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
469 buffer_descriptor.buffers = (void *)&fd_handle;
471 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
472 vaCreateSurfaces2(i965->wrapper_pdrvctx,
474 obj_surface->orig_width,
475 obj_surface->orig_height,
479 if (va_status == VA_STATUS_SUCCESS) {
480 obj_surface->wrapper_surface = wrapper_surface;
482 /* This needs to be checked */
483 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
491 i965_QueryConfigProfiles(VADriverContextP ctx,
492 VAProfile *profile_list, /* out */
493 int *num_profiles) /* out */
495 struct i965_driver_data * const i965 = i965_driver_data(ctx);
498 if (HAS_MPEG2_DECODING(i965) ||
499 HAS_MPEG2_ENCODING(i965)) {
500 profile_list[i++] = VAProfileMPEG2Simple;
501 profile_list[i++] = VAProfileMPEG2Main;
504 if (HAS_H264_DECODING(i965) ||
505 HAS_H264_ENCODING(i965) ||
506 HAS_LP_H264_ENCODING(i965)) {
507 profile_list[i++] = VAProfileH264ConstrainedBaseline;
508 profile_list[i++] = VAProfileH264Main;
509 profile_list[i++] = VAProfileH264High;
511 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
512 HAS_H264_MVC_ENCODING(i965))
513 profile_list[i++] = VAProfileH264MultiviewHigh;
514 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
515 HAS_H264_MVC_ENCODING(i965))
516 profile_list[i++] = VAProfileH264StereoHigh;
518 if (HAS_VC1_DECODING(i965)) {
519 profile_list[i++] = VAProfileVC1Simple;
520 profile_list[i++] = VAProfileVC1Main;
521 profile_list[i++] = VAProfileVC1Advanced;
525 profile_list[i++] = VAProfileNone;
528 if (HAS_JPEG_DECODING(i965) ||
529 HAS_JPEG_ENCODING(i965)) {
530 profile_list[i++] = VAProfileJPEGBaseline;
533 if (HAS_VP8_DECODING(i965) ||
534 HAS_VP8_ENCODING(i965)) {
535 profile_list[i++] = VAProfileVP8Version0_3;
538 if (HAS_HEVC_DECODING(i965)||
539 HAS_HEVC_ENCODING(i965)) {
540 profile_list[i++] = VAProfileHEVCMain;
543 if (HAS_HEVC10_DECODING(i965)||
544 HAS_HEVC10_ENCODING(i965)) {
545 profile_list[i++] = VAProfileHEVCMain10;
548 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
549 HAS_VP9_ENCODING(i965)) {
550 profile_list[i++] = VAProfileVP9Profile0;
553 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
554 profile_list[i++] = VAProfileVP9Profile2;
557 if (i965->wrapper_pdrvctx) {
558 VAProfile wrapper_list[4];
560 VADriverContextP pdrvctx;
563 pdrvctx = i965->wrapper_pdrvctx;
564 CALL_VTABLE(pdrvctx, va_status,
565 vaQueryConfigProfiles(pdrvctx,
566 wrapper_list, &wrapper_num));
568 if (va_status == VA_STATUS_SUCCESS) {
570 for (j = 0; j < wrapper_num; j++)
571 if (wrapper_list[j] != VAProfileNone)
572 profile_list[i++] = wrapper_list[j];
576 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
577 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
580 return VA_STATUS_SUCCESS;
584 i965_QueryConfigEntrypoints(VADriverContextP ctx,
586 VAEntrypoint *entrypoint_list, /* out */
587 int *num_entrypoints) /* out */
589 struct i965_driver_data * const i965 = i965_driver_data(ctx);
593 case VAProfileMPEG2Simple:
594 case VAProfileMPEG2Main:
595 if (HAS_MPEG2_DECODING(i965))
596 entrypoint_list[n++] = VAEntrypointVLD;
598 if (HAS_MPEG2_ENCODING(i965))
599 entrypoint_list[n++] = VAEntrypointEncSlice;
603 case VAProfileH264ConstrainedBaseline:
604 case VAProfileH264Main:
605 case VAProfileH264High:
606 if (HAS_H264_DECODING(i965))
607 entrypoint_list[n++] = VAEntrypointVLD;
609 if (HAS_H264_ENCODING(i965))
610 entrypoint_list[n++] = VAEntrypointEncSlice;
612 if (HAS_LP_H264_ENCODING(i965))
613 entrypoint_list[n++] = VAEntrypointEncSliceLP;
616 case VAProfileH264MultiviewHigh:
617 case VAProfileH264StereoHigh:
618 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
619 entrypoint_list[n++] = VAEntrypointVLD;
621 if (HAS_H264_MVC_ENCODING(i965))
622 entrypoint_list[n++] = VAEntrypointEncSlice;
625 case VAProfileVC1Simple:
626 case VAProfileVC1Main:
627 case VAProfileVC1Advanced:
628 if (HAS_VC1_DECODING(i965))
629 entrypoint_list[n++] = VAEntrypointVLD;
634 entrypoint_list[n++] = VAEntrypointVideoProc;
637 case VAProfileJPEGBaseline:
638 if (HAS_JPEG_DECODING(i965))
639 entrypoint_list[n++] = VAEntrypointVLD;
641 if (HAS_JPEG_ENCODING(i965))
642 entrypoint_list[n++] = VAEntrypointEncPicture;
645 case VAProfileVP8Version0_3:
646 if (HAS_VP8_DECODING(i965))
647 entrypoint_list[n++] = VAEntrypointVLD;
649 if (HAS_VP8_ENCODING(i965))
650 entrypoint_list[n++] = VAEntrypointEncSlice;
654 case VAProfileHEVCMain:
655 if (HAS_HEVC_DECODING(i965))
656 entrypoint_list[n++] = VAEntrypointVLD;
658 if (HAS_HEVC_ENCODING(i965))
659 entrypoint_list[n++] = VAEntrypointEncSlice;
663 case VAProfileHEVCMain10:
664 if (HAS_HEVC10_DECODING(i965))
665 entrypoint_list[n++] = VAEntrypointVLD;
667 if (HAS_HEVC10_ENCODING(i965))
668 entrypoint_list[n++] = VAEntrypointEncSlice;
672 case VAProfileVP9Profile0:
673 case VAProfileVP9Profile2:
674 if(HAS_VP9_DECODING_PROFILE(i965, profile))
675 entrypoint_list[n++] = VAEntrypointVLD;
677 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
678 entrypoint_list[n++] = VAEntrypointEncSlice;
680 if(profile == VAProfileVP9Profile0) {
681 if (i965->wrapper_pdrvctx) {
682 VAStatus va_status = VA_STATUS_SUCCESS;
683 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
685 CALL_VTABLE(pdrvctx, va_status,
686 vaQueryConfigEntrypoints(pdrvctx, profile,
699 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
700 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
701 *num_entrypoints = n;
702 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
706 i965_validate_config(VADriverContextP ctx, VAProfile profile,
707 VAEntrypoint entrypoint)
709 struct i965_driver_data * const i965 = i965_driver_data(ctx);
712 /* Validate profile & entrypoint */
714 case VAProfileMPEG2Simple:
715 case VAProfileMPEG2Main:
716 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
717 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
718 va_status = VA_STATUS_SUCCESS;
719 } else if (!HAS_MPEG2_DECODING(i965) && !HAS_MPEG2_ENCODING(i965)){
720 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
722 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
726 case VAProfileH264ConstrainedBaseline:
727 case VAProfileH264Main:
728 case VAProfileH264High:
729 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
730 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
731 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP)) {
732 va_status = VA_STATUS_SUCCESS;
733 } else if (!HAS_H264_DECODING(i965) && !HAS_H264_ENCODING(i965) &&
734 !HAS_LP_H264_ENCODING(i965)){
735 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
737 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
741 case VAProfileVC1Simple:
742 case VAProfileVC1Main:
743 case VAProfileVC1Advanced:
744 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
745 va_status = VA_STATUS_SUCCESS;
746 } else if (!HAS_VC1_DECODING(i965)) {
747 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
749 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
754 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
755 va_status = VA_STATUS_SUCCESS;
756 } else if (!HAS_VPP(i965)){
757 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
759 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
763 case VAProfileJPEGBaseline:
764 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
765 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
766 va_status = VA_STATUS_SUCCESS;
767 } else if (!HAS_JPEG_DECODING(i965) && !HAS_JPEG_ENCODING(i965)){
768 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
770 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
774 case VAProfileVP8Version0_3:
775 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
776 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
777 va_status = VA_STATUS_SUCCESS;
778 } else if (!HAS_VP8_DECODING(i965) && !HAS_VP8_ENCODING(i965)){
779 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
781 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
785 case VAProfileH264MultiviewHigh:
786 case VAProfileH264StereoHigh:
787 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
788 entrypoint == VAEntrypointVLD) ||
789 (HAS_H264_MVC_ENCODING(i965) &&
790 entrypoint == VAEntrypointEncSlice)) {
791 va_status = VA_STATUS_SUCCESS;
792 } else if(!HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
793 !HAS_H264_MVC_ENCODING(i965)) {
794 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
796 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
801 case VAProfileHEVCMain:
802 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
803 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice))) {
804 va_status = VA_STATUS_SUCCESS;
805 } else if (!HAS_HEVC_DECODING(i965) && !HAS_HEVC_ENCODING(i965)) {
806 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
808 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
813 case VAProfileHEVCMain10:
814 if ((HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
815 (HAS_HEVC10_ENCODING(i965) &&
816 (entrypoint == VAEntrypointEncSlice))) {
817 va_status = VA_STATUS_SUCCESS;
818 } else if (!HAS_HEVC10_DECODING(i965) && !HAS_HEVC10_ENCODING(i965)) {
819 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
821 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
826 case VAProfileVP9Profile0:
827 case VAProfileVP9Profile2:
828 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) &&
829 (entrypoint == VAEntrypointVLD)) {
830 va_status = VA_STATUS_SUCCESS;
831 } else if ((HAS_VP9_ENCODING_PROFILE(i965, profile)) &&
832 (entrypoint == VAEntrypointEncSlice)) {
833 va_status = VA_STATUS_SUCCESS;
834 } else if (profile == VAProfileVP9Profile0 && i965->wrapper_pdrvctx) {
835 va_status = VA_STATUS_SUCCESS;
836 } else if(!HAS_VP9_DECODING_PROFILE(i965, profile) &&
837 !HAS_VP9_ENCODING(i965) && !i965->wrapper_pdrvctx) {
838 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
840 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
846 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
853 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
854 VAEntrypoint entrypoint)
856 struct i965_driver_data * const i965 = i965_driver_data(ctx);
857 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
860 case VAProfileH264ConstrainedBaseline:
861 case VAProfileH264Main:
862 case VAProfileH264High:
863 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
864 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
867 case VAProfileH264MultiviewHigh:
868 case VAProfileH264StereoHigh:
869 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
870 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
873 case VAProfileJPEGBaseline:
874 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
875 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
876 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
877 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
880 case VAProfileHEVCMain10:
881 if (HAS_HEVC10_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)
882 chroma_formats = VA_RT_FORMAT_YUV420_10BPP;
883 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
884 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
888 if (HAS_VPP_P010(i965))
889 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
892 chroma_formats |= VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_RGB32;
895 case VAProfileVP9Profile0:
896 case VAProfileVP9Profile2:
897 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
898 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
904 return chroma_formats;
908 i965_GetConfigAttributes(VADriverContextP ctx,
910 VAEntrypoint entrypoint,
911 VAConfigAttrib *attrib_list, /* in/out */
917 va_status = i965_validate_config(ctx, profile, entrypoint);
918 if (va_status != VA_STATUS_SUCCESS)
921 /* Other attributes don't seem to be defined */
922 /* What to do if we don't know the attribute? */
923 for (i = 0; i < num_attribs; i++) {
924 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
925 switch (attrib_list[i].type) {
926 case VAConfigAttribRTFormat:
927 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
928 profile, entrypoint);
931 case VAConfigAttribRateControl:
932 if (entrypoint == VAEntrypointEncSlice) {
933 attrib_list[i].value = VA_RC_CQP;
935 if (profile != VAProfileMPEG2Main &&
936 profile != VAProfileMPEG2Simple)
937 attrib_list[i].value |= VA_RC_CBR;
939 if (profile == VAProfileVP9Profile0 ||
940 profile == VAProfileH264ConstrainedBaseline ||
941 profile == VAProfileH264Main ||
942 profile == VAProfileH264High)
943 attrib_list[i].value |= VA_RC_VBR;
946 } else if (entrypoint == VAEntrypointEncSliceLP) {
947 struct i965_driver_data * const i965 = i965_driver_data(ctx);
949 /* Support low power encoding for H.264 only by now */
950 if (profile == VAProfileH264ConstrainedBaseline ||
951 profile == VAProfileH264Main ||
952 profile == VAProfileH264High)
953 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
955 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
957 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
961 case VAConfigAttribEncPackedHeaders:
962 if (entrypoint == VAEntrypointEncSlice ||
963 entrypoint == VAEntrypointEncSliceLP) {
964 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
965 if (profile == VAProfileH264ConstrainedBaseline ||
966 profile == VAProfileH264Main ||
967 profile == VAProfileH264High ||
968 profile == VAProfileH264StereoHigh ||
969 profile == VAProfileH264MultiviewHigh ||
970 profile == VAProfileHEVCMain ||
971 profile == VAProfileHEVCMain10) {
972 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
973 VA_ENC_PACKED_HEADER_SLICE);
975 else if (profile == VAProfileVP9Profile0)
976 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
979 else if (entrypoint == VAEntrypointEncPicture) {
980 if (profile == VAProfileJPEGBaseline)
981 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
985 case VAConfigAttribEncMaxRefFrames:
986 if (entrypoint == VAEntrypointEncSlice)
987 attrib_list[i].value = (1 << 16) | (1 << 0);
988 else if (entrypoint == VAEntrypointEncSliceLP) {
989 /* Don't support B frame for low power mode */
990 if (profile == VAProfileH264ConstrainedBaseline ||
991 profile == VAProfileH264Main ||
992 profile == VAProfileH264High)
993 attrib_list[i].value = (1 << 0);
995 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1000 case VAConfigAttribEncQualityRange:
1001 if (entrypoint == VAEntrypointEncSlice ||
1002 entrypoint == VAEntrypointEncSliceLP) {
1003 attrib_list[i].value = 1;
1004 if (profile == VAProfileH264ConstrainedBaseline ||
1005 profile == VAProfileH264Main ||
1006 profile == VAProfileH264High )
1007 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1012 case VAConfigAttribEncJPEG:
1013 if( entrypoint == VAEntrypointEncPicture) {
1014 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*)&(attrib_list[i].value);
1015 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1016 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1017 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1018 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1019 (configVal->bits).max_num_components = 3; // Only 3 components supported
1020 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1021 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1022 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1026 case VAConfigAttribDecSliceMode:
1027 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1030 case VAConfigAttribEncROI:
1031 if (entrypoint == VAEntrypointEncSlice ||
1032 entrypoint == VAEntrypointEncSliceLP) {
1034 if (profile == VAProfileH264ConstrainedBaseline ||
1035 profile == VAProfileH264Main ||
1036 profile == VAProfileH264High) {
1038 VAConfigAttribValEncROI *roi_config =
1039 (VAConfigAttribValEncROI *)&(attrib_list[i].value);
1041 if(entrypoint == VAEntrypointEncSliceLP) {
1042 roi_config->bits.num_roi_regions = 3;
1043 roi_config->bits.roi_rc_priority_support = 0;
1044 roi_config->bits.roi_rc_qp_delat_support = 0;
1046 roi_config->bits.num_roi_regions =
1047 I965_MAX_NUM_ROI_REGIONS;
1048 roi_config->bits.roi_rc_priority_support = 0;
1049 roi_config->bits.roi_rc_qp_delat_support = 1;
1052 attrib_list[i].value = 0;
1058 case VAConfigAttribEncRateControlExt:
1059 if ((profile == VAProfileH264ConstrainedBaseline ||
1060 profile == VAProfileH264Main ||
1061 profile == VAProfileH264High) &&
1062 entrypoint == VAEntrypointEncSlice) {
1063 VAConfigAttribValEncRateControlExt *val_config = (VAConfigAttribValEncRateControlExt *)&(attrib_list[i].value);
1065 val_config->bits.max_num_temporal_layers_minus1 = MAX_TEMPORAL_LAYERS - 1;
1066 val_config->bits.temporal_layer_bitrate_control_flag = 1;
1068 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1075 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1080 return VA_STATUS_SUCCESS;
1084 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1086 object_heap_free(heap, obj);
1089 static VAConfigAttrib *
1090 i965_lookup_config_attribute(struct object_config *obj_config,
1091 VAConfigAttribType type)
1095 for (i = 0; i < obj_config->num_attribs; i++) {
1096 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1097 if (attrib->type == type)
1104 i965_append_config_attribute(struct object_config *obj_config,
1105 const VAConfigAttrib *new_attrib)
1107 VAConfigAttrib *attrib;
1109 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1110 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1112 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1113 attrib->type = new_attrib->type;
1114 attrib->value = new_attrib->value;
1115 return VA_STATUS_SUCCESS;
1119 i965_ensure_config_attribute(struct object_config *obj_config,
1120 const VAConfigAttrib *new_attrib)
1122 VAConfigAttrib *attrib;
1124 /* Check for existing attributes */
1125 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1127 /* Update existing attribute */
1128 attrib->value = new_attrib->value;
1129 return VA_STATUS_SUCCESS;
1131 return i965_append_config_attribute(obj_config, new_attrib);
1135 i965_CreateConfig(VADriverContextP ctx,
1137 VAEntrypoint entrypoint,
1138 VAConfigAttrib *attrib_list,
1140 VAConfigID *config_id) /* out */
1142 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1143 struct object_config *obj_config;
1148 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1150 if (VA_STATUS_SUCCESS != vaStatus) {
1154 configID = NEW_CONFIG_ID();
1155 obj_config = CONFIG(configID);
1157 if (NULL == obj_config) {
1158 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1162 obj_config->profile = profile;
1163 obj_config->entrypoint = entrypoint;
1164 obj_config->num_attribs = 0;
1165 obj_config->wrapper_config = VA_INVALID_ID;
1167 for (i = 0; i < num_attribs; i++) {
1168 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1169 if (vaStatus != VA_STATUS_SUCCESS)
1173 if (vaStatus == VA_STATUS_SUCCESS) {
1174 VAConfigAttrib attrib, *attrib_found;
1175 attrib.type = VAConfigAttribRTFormat;
1176 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1177 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1178 if (!attrib_found || !attrib_found->value)
1179 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1180 else if (!(attrib_found->value & attrib.value))
1181 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1184 if ((vaStatus == VA_STATUS_SUCCESS) &&
1185 (profile == VAProfileVP9Profile0) &&
1186 (entrypoint == VAEntrypointVLD) &&
1187 !HAS_VP9_DECODING(i965)) {
1189 if (i965->wrapper_pdrvctx) {
1190 VAGenericID wrapper_config;
1192 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1193 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1194 entrypoint, attrib_list,
1195 num_attribs, &wrapper_config));
1197 if (vaStatus == VA_STATUS_SUCCESS)
1198 obj_config->wrapper_config = wrapper_config;
1202 /* Error recovery */
1203 if (VA_STATUS_SUCCESS != vaStatus) {
1204 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1206 *config_id = configID;
1213 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1215 struct i965_driver_data *i965 = i965_driver_data(ctx);
1216 struct object_config *obj_config = CONFIG(config_id);
1219 if (NULL == obj_config) {
1220 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1224 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1225 i965->wrapper_pdrvctx) {
1226 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1227 vaDestroyConfig(i965->wrapper_pdrvctx,
1228 obj_config->wrapper_config));
1229 obj_config->wrapper_config = VA_INVALID_ID;
1232 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1233 return VA_STATUS_SUCCESS;
1236 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1237 VAConfigID config_id,
1238 VAProfile *profile, /* out */
1239 VAEntrypoint *entrypoint, /* out */
1240 VAConfigAttrib *attrib_list, /* out */
1241 int *num_attribs) /* out */
1243 struct i965_driver_data *i965 = i965_driver_data(ctx);
1244 struct object_config *obj_config = CONFIG(config_id);
1245 VAStatus vaStatus = VA_STATUS_SUCCESS;
1248 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1249 *profile = obj_config->profile;
1250 *entrypoint = obj_config->entrypoint;
1251 *num_attribs = obj_config->num_attribs;
1253 for(i = 0; i < obj_config->num_attribs; i++) {
1254 attrib_list[i] = obj_config->attrib_list[i];
1261 i965_destroy_surface_storage(struct object_surface *obj_surface)
1266 dri_bo_unreference(obj_surface->bo);
1267 obj_surface->bo = NULL;
1269 if (obj_surface->free_private_data != NULL) {
1270 obj_surface->free_private_data(&obj_surface->private_data);
1271 obj_surface->private_data = NULL;
1276 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1278 struct object_surface *obj_surface = (struct object_surface *)obj;
1280 i965_destroy_surface_storage(obj_surface);
1281 object_heap_free(heap, obj);
1285 i965_surface_native_memory(VADriverContextP ctx,
1286 struct object_surface *obj_surface,
1288 int expected_fourcc)
1290 struct i965_driver_data *i965 = i965_driver_data(ctx);
1291 int tiling = HAS_TILED_SURFACE(i965);
1293 if (!expected_fourcc)
1294 return VA_STATUS_SUCCESS;
1296 // todo, should we disable tiling for 422 format?
1297 if (expected_fourcc == VA_FOURCC_I420 ||
1298 expected_fourcc == VA_FOURCC_IYUV ||
1299 expected_fourcc == VA_FOURCC_I010 ||
1300 expected_fourcc == VA_FOURCC_YV12 ||
1301 expected_fourcc == VA_FOURCC_YV16)
1304 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1308 i965_suface_external_memory(VADriverContextP ctx,
1309 struct object_surface *obj_surface,
1310 int external_memory_type,
1311 VASurfaceAttribExternalBuffers *memory_attibute,
1314 struct i965_driver_data *i965 = i965_driver_data(ctx);
1316 if (!memory_attibute ||
1317 !memory_attibute->buffers ||
1318 index > memory_attibute->num_buffers)
1319 return VA_STATUS_ERROR_INVALID_PARAMETER;
1321 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1322 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1323 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1325 obj_surface->fourcc = memory_attibute->pixel_format;
1326 obj_surface->width = memory_attibute->pitches[0];
1327 obj_surface->size = memory_attibute->data_size;
1329 if (memory_attibute->num_planes == 1)
1330 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1332 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1334 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1335 obj_surface->x_cr_offset = 0;
1337 switch (obj_surface->fourcc) {
1338 case VA_FOURCC_NV12:
1339 case VA_FOURCC_P010:
1340 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1341 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1343 obj_surface->subsampling = SUBSAMPLE_YUV420;
1344 obj_surface->y_cb_offset = obj_surface->height;
1345 obj_surface->y_cr_offset = obj_surface->height;
1346 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1347 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1348 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1352 case VA_FOURCC_YV12:
1353 case VA_FOURCC_IMC1:
1354 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1355 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1357 obj_surface->subsampling = SUBSAMPLE_YUV420;
1358 obj_surface->y_cr_offset = obj_surface->height;
1359 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1360 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1361 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1362 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1366 case VA_FOURCC_I420:
1367 case VA_FOURCC_IYUV:
1368 case VA_FOURCC_IMC3:
1369 case VA_FOURCC_I010:
1370 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1371 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1373 obj_surface->subsampling = SUBSAMPLE_YUV420;
1374 obj_surface->y_cb_offset = obj_surface->height;
1375 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1376 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1377 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1378 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1382 case VA_FOURCC_YUY2:
1383 case VA_FOURCC_UYVY:
1384 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1386 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1387 obj_surface->y_cb_offset = 0;
1388 obj_surface->y_cr_offset = 0;
1389 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1390 obj_surface->cb_cr_height = obj_surface->orig_height;
1391 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1395 case VA_FOURCC_RGBA:
1396 case VA_FOURCC_RGBX:
1397 case VA_FOURCC_BGRA:
1398 case VA_FOURCC_BGRX:
1399 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1401 obj_surface->subsampling = SUBSAMPLE_RGBX;
1402 obj_surface->y_cb_offset = 0;
1403 obj_surface->y_cr_offset = 0;
1404 obj_surface->cb_cr_width = 0;
1405 obj_surface->cb_cr_height = 0;
1406 obj_surface->cb_cr_pitch = 0;
1410 case VA_FOURCC_Y800: /* monochrome surface */
1411 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1413 obj_surface->subsampling = SUBSAMPLE_YUV400;
1414 obj_surface->y_cb_offset = 0;
1415 obj_surface->y_cr_offset = 0;
1416 obj_surface->cb_cr_width = 0;
1417 obj_surface->cb_cr_height = 0;
1418 obj_surface->cb_cr_pitch = 0;
1422 case VA_FOURCC_411P:
1423 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1424 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1426 obj_surface->subsampling = SUBSAMPLE_YUV411;
1427 obj_surface->y_cb_offset = 0;
1428 obj_surface->y_cr_offset = 0;
1429 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1430 obj_surface->cb_cr_height = obj_surface->orig_height;
1431 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1435 case VA_FOURCC_422H:
1436 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1437 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1439 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1440 obj_surface->y_cb_offset = obj_surface->height;
1441 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1442 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1443 obj_surface->cb_cr_height = obj_surface->orig_height;
1444 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1448 case VA_FOURCC_YV16:
1449 assert(memory_attibute->num_planes == 3);
1450 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1452 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1453 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1454 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1455 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1456 obj_surface->cb_cr_height = obj_surface->orig_height;
1457 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1461 case VA_FOURCC_422V:
1462 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1463 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1465 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1466 obj_surface->y_cb_offset = obj_surface->height;
1467 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1468 obj_surface->cb_cr_width = obj_surface->orig_width;
1469 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1470 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1474 case VA_FOURCC_444P:
1475 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1476 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1478 obj_surface->subsampling = SUBSAMPLE_YUV444;
1479 obj_surface->y_cb_offset = obj_surface->height;
1480 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1481 obj_surface->cb_cr_width = obj_surface->orig_width;
1482 obj_surface->cb_cr_height = obj_surface->orig_height;
1483 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1489 return VA_STATUS_ERROR_INVALID_PARAMETER;
1492 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1493 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1494 "gem flinked vaapi surface",
1495 memory_attibute->buffers[index]);
1496 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1497 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1498 memory_attibute->buffers[index],
1501 if (!obj_surface->bo)
1502 return VA_STATUS_ERROR_INVALID_PARAMETER;
1504 return VA_STATUS_SUCCESS;
1507 /* byte-per-pixel of the first plane */
1509 bpp_1stplane_by_fourcc(unsigned int fourcc)
1511 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1513 if (info && (info->flag & I_S))
1514 return info->bpp[0] / 8;
1520 i965_CreateSurfaces2(
1521 VADriverContextP ctx,
1522 unsigned int format,
1524 unsigned int height,
1525 VASurfaceID *surfaces,
1526 unsigned int num_surfaces,
1527 VASurfaceAttrib *attrib_list,
1528 unsigned int num_attribs
1531 struct i965_driver_data *i965 = i965_driver_data(ctx);
1533 VAStatus vaStatus = VA_STATUS_SUCCESS;
1534 int expected_fourcc = 0;
1535 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1536 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1538 for (i = 0; i < num_attribs && attrib_list; i++) {
1539 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1540 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1541 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1542 expected_fourcc = attrib_list[i].value.value.i;
1545 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1546 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1548 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1550 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1551 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1552 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1553 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1554 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1555 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1558 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1559 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1560 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1561 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1565 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1566 * for post-processing (including color conversion) */
1567 if (VA_RT_FORMAT_YUV420 != format &&
1568 VA_RT_FORMAT_YUV420_10BPP != format &&
1569 VA_RT_FORMAT_YUV422 != format &&
1570 VA_RT_FORMAT_YUV444 != format &&
1571 VA_RT_FORMAT_YUV411 != format &&
1572 VA_RT_FORMAT_YUV400 != format &&
1573 VA_RT_FORMAT_RGB32 != format) {
1574 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1577 for (i = 0; i < num_surfaces; i++) {
1578 int surfaceID = NEW_SURFACE_ID();
1579 struct object_surface *obj_surface = SURFACE(surfaceID);
1581 if (NULL == obj_surface) {
1582 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1586 surfaces[i] = surfaceID;
1587 obj_surface->status = VASurfaceReady;
1588 obj_surface->orig_width = width;
1589 obj_surface->orig_height = height;
1590 obj_surface->user_disable_tiling = false;
1591 obj_surface->user_h_stride_set = false;
1592 obj_surface->user_v_stride_set = false;
1593 obj_surface->border_cleared = false;
1595 obj_surface->subpic_render_idx = 0;
1596 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1597 obj_surface->subpic[j] = VA_INVALID_ID;
1598 obj_surface->obj_subpic[j] = NULL;
1601 assert(i965->codec_info->min_linear_wpitch);
1602 assert(i965->codec_info->min_linear_hpitch);
1603 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1604 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1605 obj_surface->flags = SURFACE_REFERENCED;
1606 obj_surface->fourcc = 0;
1607 obj_surface->expected_format = format;
1608 obj_surface->bo = NULL;
1609 obj_surface->locked_image_id = VA_INVALID_ID;
1610 obj_surface->derived_image_id = VA_INVALID_ID;
1611 obj_surface->private_data = NULL;
1612 obj_surface->free_private_data = NULL;
1613 obj_surface->subsampling = SUBSAMPLE_YUV420;
1615 obj_surface->wrapper_surface = VA_INVALID_ID;
1616 obj_surface->exported_primefd = -1;
1618 switch (memory_type) {
1619 case I965_SURFACE_MEM_NATIVE:
1620 if (memory_attibute) {
1621 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1622 obj_surface->user_disable_tiling = true;
1624 if (memory_attibute->pixel_format) {
1625 if (expected_fourcc)
1626 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1628 expected_fourcc = memory_attibute->pixel_format;
1630 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1631 if (memory_attibute->pitches[0]) {
1632 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1633 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1634 obj_surface->width = memory_attibute->pitches[0];
1635 obj_surface->user_h_stride_set = true;
1636 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1637 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1639 if (memory_attibute->offsets[1]) {
1640 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1641 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1642 obj_surface->user_v_stride_set = true;
1643 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1644 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1648 vaStatus = i965_surface_native_memory(ctx,
1654 case I965_SURFACE_MEM_GEM_FLINK:
1655 case I965_SURFACE_MEM_DRM_PRIME:
1656 vaStatus = i965_suface_external_memory(ctx,
1663 if (VA_STATUS_SUCCESS != vaStatus) {
1664 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1669 /* Error recovery */
1670 if (VA_STATUS_SUCCESS != vaStatus) {
1671 /* surfaces[i-1] was the last successful allocation */
1673 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1675 surfaces[i] = VA_INVALID_SURFACE;
1676 assert(obj_surface);
1677 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1685 i965_CreateSurfaces(VADriverContextP ctx,
1690 VASurfaceID *surfaces) /* out */
1692 return i965_CreateSurfaces2(ctx,
1703 i965_DestroySurfaces(VADriverContextP ctx,
1704 VASurfaceID *surface_list,
1707 struct i965_driver_data *i965 = i965_driver_data(ctx);
1709 VAStatus va_status = VA_STATUS_SUCCESS;
1711 for (i = num_surfaces; i--; ) {
1712 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1714 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1716 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1717 i965->wrapper_pdrvctx) {
1718 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1719 vaDestroySurfaces(i965->wrapper_pdrvctx,
1720 &(obj_surface->wrapper_surface),
1722 obj_surface->wrapper_surface = VA_INVALID_ID;
1724 if (obj_surface->exported_primefd >= 0) {
1725 close(obj_surface->exported_primefd);
1726 obj_surface->exported_primefd = -1;
1729 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1736 i965_QueryImageFormats(VADriverContextP ctx,
1737 VAImageFormat *format_list, /* out */
1738 int *num_formats) /* out */
1742 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1743 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1745 format_list[n] = m->va_format;
1751 return VA_STATUS_SUCCESS;
1755 * Guess the format when the usage of a VA surface is unknown
1756 * 1. Without a valid context: YV12
1757 * 2. The current context is valid:
1758 * a) always NV12 on GEN6 and later
1759 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1762 i965_guess_surface_format(VADriverContextP ctx,
1763 VASurfaceID surface,
1764 unsigned int *fourcc,
1765 unsigned int *is_tiled)
1767 struct i965_driver_data *i965 = i965_driver_data(ctx);
1768 struct object_context *obj_context = NULL;
1769 struct object_config *obj_config = NULL;
1771 *fourcc = VA_FOURCC_YV12;
1774 if (i965->current_context_id == VA_INVALID_ID)
1777 obj_context = CONTEXT(i965->current_context_id);
1782 obj_config = obj_context->obj_config;
1788 if (IS_GEN6(i965->intel.device_info) ||
1789 IS_GEN7(i965->intel.device_info) ||
1790 IS_GEN8(i965->intel.device_info) ||
1791 IS_GEN9(i965->intel.device_info)) {
1792 *fourcc = VA_FOURCC_NV12;
1797 switch (obj_config->profile) {
1798 case VAProfileMPEG2Simple:
1799 case VAProfileMPEG2Main:
1800 *fourcc = VA_FOURCC_I420;
1805 *fourcc = VA_FOURCC_NV12;
1812 i965_QuerySubpictureFormats(VADriverContextP ctx,
1813 VAImageFormat *format_list, /* out */
1814 unsigned int *flags, /* out */
1815 unsigned int *num_formats) /* out */
1819 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1820 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1822 format_list[n] = m->va_format;
1824 flags[n] = m->va_flags;
1830 return VA_STATUS_SUCCESS;
1834 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1836 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1838 object_heap_free(heap, obj);
1842 i965_CreateSubpicture(VADriverContextP ctx,
1844 VASubpictureID *subpicture) /* out */
1846 struct i965_driver_data *i965 = i965_driver_data(ctx);
1847 VASubpictureID subpicID = NEW_SUBPIC_ID()
1848 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1851 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1853 struct object_image *obj_image = IMAGE(image);
1855 return VA_STATUS_ERROR_INVALID_IMAGE;
1857 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1859 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1861 *subpicture = subpicID;
1862 obj_subpic->image = image;
1863 obj_subpic->obj_image = obj_image;
1864 obj_subpic->format = m->format;
1865 obj_subpic->width = obj_image->image.width;
1866 obj_subpic->height = obj_image->image.height;
1867 obj_subpic->pitch = obj_image->image.pitches[0];
1868 obj_subpic->bo = obj_image->bo;
1869 obj_subpic->global_alpha = 1.0;
1871 return VA_STATUS_SUCCESS;
1875 i965_DestroySubpicture(VADriverContextP ctx,
1876 VASubpictureID subpicture)
1878 struct i965_driver_data *i965 = i965_driver_data(ctx);
1879 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1882 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1884 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1885 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1886 return VA_STATUS_SUCCESS;
1890 i965_SetSubpictureImage(VADriverContextP ctx,
1891 VASubpictureID subpicture,
1895 return VA_STATUS_ERROR_UNIMPLEMENTED;
1899 i965_SetSubpictureChromakey(VADriverContextP ctx,
1900 VASubpictureID subpicture,
1901 unsigned int chromakey_min,
1902 unsigned int chromakey_max,
1903 unsigned int chromakey_mask)
1906 return VA_STATUS_ERROR_UNIMPLEMENTED;
1910 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1911 VASubpictureID subpicture,
1914 struct i965_driver_data *i965 = i965_driver_data(ctx);
1915 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1917 if(global_alpha > 1.0 || global_alpha < 0.0){
1918 return VA_STATUS_ERROR_INVALID_PARAMETER;
1922 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1924 obj_subpic->global_alpha = global_alpha;
1926 return VA_STATUS_SUCCESS;
1930 i965_AssociateSubpicture(VADriverContextP ctx,
1931 VASubpictureID subpicture,
1932 VASurfaceID *target_surfaces,
1934 short src_x, /* upper left offset in subpicture */
1936 unsigned short src_width,
1937 unsigned short src_height,
1938 short dest_x, /* upper left offset in surface */
1940 unsigned short dest_width,
1941 unsigned short dest_height,
1943 * whether to enable chroma-keying or global-alpha
1944 * see VA_SUBPICTURE_XXX values
1948 struct i965_driver_data *i965 = i965_driver_data(ctx);
1949 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1953 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1955 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1957 obj_subpic->src_rect.x = src_x;
1958 obj_subpic->src_rect.y = src_y;
1959 obj_subpic->src_rect.width = src_width;
1960 obj_subpic->src_rect.height = src_height;
1961 obj_subpic->dst_rect.x = dest_x;
1962 obj_subpic->dst_rect.y = dest_y;
1963 obj_subpic->dst_rect.width = dest_width;
1964 obj_subpic->dst_rect.height = dest_height;
1965 obj_subpic->flags = flags;
1967 for (i = 0; i < num_surfaces; i++) {
1968 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1970 return VA_STATUS_ERROR_INVALID_SURFACE;
1972 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1973 if(obj_surface->subpic[j] == VA_INVALID_ID){
1974 assert(obj_surface->obj_subpic[j] == NULL);
1975 obj_surface->subpic[j] = subpicture;
1976 obj_surface->obj_subpic[j] = obj_subpic;
1981 if(j == I965_MAX_SUBPIC_SUM){
1982 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1986 return VA_STATUS_SUCCESS;
1991 i965_DeassociateSubpicture(VADriverContextP ctx,
1992 VASubpictureID subpicture,
1993 VASurfaceID *target_surfaces,
1996 struct i965_driver_data *i965 = i965_driver_data(ctx);
1997 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2001 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2003 for (i = 0; i < num_surfaces; i++) {
2004 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2006 return VA_STATUS_ERROR_INVALID_SURFACE;
2008 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
2009 if (obj_surface->subpic[j] == subpicture) {
2010 assert(obj_surface->obj_subpic[j] == obj_subpic);
2011 obj_surface->subpic[j] = VA_INVALID_ID;
2012 obj_surface->obj_subpic[j] = NULL;
2017 if(j == I965_MAX_SUBPIC_SUM){
2018 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2021 return VA_STATUS_SUCCESS;
2025 i965_reference_buffer_store(struct buffer_store **ptr,
2026 struct buffer_store *buffer_store)
2028 assert(*ptr == NULL);
2031 buffer_store->ref_count++;
2032 *ptr = buffer_store;
2037 i965_release_buffer_store(struct buffer_store **ptr)
2039 struct buffer_store *buffer_store = *ptr;
2041 if (buffer_store == NULL)
2044 assert(buffer_store->bo || buffer_store->buffer);
2045 assert(!(buffer_store->bo && buffer_store->buffer));
2046 buffer_store->ref_count--;
2048 if (buffer_store->ref_count == 0) {
2049 dri_bo_unreference(buffer_store->bo);
2050 free(buffer_store->buffer);
2051 buffer_store->bo = NULL;
2052 buffer_store->buffer = NULL;
2060 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2062 struct object_context *obj_context = (struct object_context *)obj;
2065 if (obj_context->hw_context) {
2066 obj_context->hw_context->destroy(obj_context->hw_context);
2067 obj_context->hw_context = NULL;
2070 if (obj_context->codec_type == CODEC_PROC) {
2071 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2073 } else if (obj_context->codec_type == CODEC_ENC) {
2074 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2075 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2077 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2078 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2079 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2081 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2082 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2084 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2085 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2087 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2088 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2089 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2091 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2092 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2094 free(obj_context->codec_state.encode.slice_params_ext);
2095 if (obj_context->codec_state.encode.slice_rawdata_index) {
2096 free(obj_context->codec_state.encode.slice_rawdata_index);
2097 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2099 if (obj_context->codec_state.encode.slice_rawdata_count) {
2100 free(obj_context->codec_state.encode.slice_rawdata_count);
2101 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2104 if (obj_context->codec_state.encode.slice_header_index) {
2105 free(obj_context->codec_state.encode.slice_header_index);
2106 obj_context->codec_state.encode.slice_header_index = NULL;
2109 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2110 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2111 free(obj_context->codec_state.encode.packed_header_params_ext);
2113 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2114 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2115 free(obj_context->codec_state.encode.packed_header_data_ext);
2117 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2119 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2120 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2122 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2123 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2124 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2126 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2127 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2129 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2130 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2132 free(obj_context->codec_state.decode.slice_params);
2133 free(obj_context->codec_state.decode.slice_datas);
2136 free(obj_context->render_targets);
2137 object_heap_free(heap, obj);
2141 max_resolution(struct i965_driver_data *i965,
2142 struct object_config *obj_config,
2146 if (i965->codec_info->max_resolution) {
2147 i965->codec_info->max_resolution(i965, obj_config, w, h);
2149 *w = i965->codec_info->max_width;
2150 *h = i965->codec_info->max_height;
2155 i965_CreateContext(VADriverContextP ctx,
2156 VAConfigID config_id,
2160 VASurfaceID *render_targets,
2161 int num_render_targets,
2162 VAContextID *context) /* out */
2164 struct i965_driver_data *i965 = i965_driver_data(ctx);
2165 struct object_config *obj_config = CONFIG(config_id);
2166 struct object_context *obj_context = NULL;
2167 VAConfigAttrib *attrib;
2168 VAStatus vaStatus = VA_STATUS_SUCCESS;
2174 if (NULL == obj_config) {
2175 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2179 max_resolution(i965, obj_config, &max_width, &max_height);
2181 if (picture_width > max_width ||
2182 picture_height > max_height) {
2183 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2188 /* Validate picture dimensions */
2189 contextID = NEW_CONTEXT_ID();
2190 obj_context = CONTEXT(contextID);
2192 if (NULL == obj_context) {
2193 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2197 *context = contextID;
2198 obj_context->flags = flag;
2199 obj_context->context_id = contextID;
2200 obj_context->obj_config = obj_config;
2201 obj_context->picture_width = picture_width;
2202 obj_context->picture_height = picture_height;
2203 obj_context->num_render_targets = num_render_targets;
2204 obj_context->render_targets =
2205 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2206 obj_context->hw_context = NULL;
2207 obj_context->wrapper_context = VA_INVALID_ID;
2209 if (!obj_context->render_targets)
2210 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2212 for(i = 0; i < num_render_targets; i++) {
2213 if (NULL == SURFACE(render_targets[i])) {
2214 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2218 obj_context->render_targets[i] = render_targets[i];
2221 if (VA_STATUS_SUCCESS == vaStatus) {
2222 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2223 obj_context->codec_type = CODEC_PROC;
2224 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2225 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2226 assert(i965->codec_info->proc_hw_context_init);
2227 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2228 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2229 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2230 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2231 VAConfigAttrib *packed_attrib;
2232 obj_context->codec_type = CODEC_ENC;
2233 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2234 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2235 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2236 obj_context->codec_state.encode.packed_header_params_ext =
2237 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2238 sizeof(struct buffer_store *));
2240 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2241 obj_context->codec_state.encode.packed_header_data_ext =
2242 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2243 sizeof(struct buffer_store *));
2245 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2246 obj_context->codec_state.encode.slice_rawdata_index =
2247 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2248 obj_context->codec_state.encode.slice_rawdata_count =
2249 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2251 obj_context->codec_state.encode.slice_header_index =
2252 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2254 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2256 obj_context->codec_state.encode.slice_index = 0;
2257 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2258 if (packed_attrib) {
2259 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2260 if (obj_config->profile == VAProfileVP9Profile0)
2261 obj_context->codec_state.encode.packed_header_flag =
2262 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2264 /* use the default value. SPS/PPS/RAWDATA is passed from user
2265 * while Slice_header data is generated by driver.
2267 obj_context->codec_state.encode.packed_header_flag =
2268 VA_ENC_PACKED_HEADER_SEQUENCE |
2269 VA_ENC_PACKED_HEADER_PICTURE |
2270 VA_ENC_PACKED_HEADER_RAW_DATA;
2272 /* it is not used for VP9 */
2273 if (obj_config->profile == VAProfileVP9Profile0)
2274 obj_context->codec_state.encode.packed_header_flag = 0;
2276 assert(i965->codec_info->enc_hw_context_init);
2277 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2279 obj_context->codec_type = CODEC_DEC;
2280 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2281 obj_context->codec_state.decode.current_render_target = -1;
2282 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2283 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2284 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2285 sizeof(*obj_context->codec_state.decode.slice_params));
2286 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2287 sizeof(*obj_context->codec_state.decode.slice_datas));
2289 assert(i965->codec_info->dec_hw_context_init);
2290 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2294 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2296 return VA_STATUS_ERROR_INVALID_CONFIG;
2297 obj_context->codec_state.base.chroma_formats = attrib->value;
2299 if (obj_config->wrapper_config != VA_INVALID_ID) {
2300 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2301 * So it won't check i965->wrapper_pdrvctx again.
2302 * Fixme if it is incorrect.
2304 VAGenericID wrapper_context;
2307 * The render_surface is not passed when calling
2309 * If it is needed, we must get the wrapped surface
2310 * for the corresponding Surface_list.
2311 * So the wrapped surface conversion is deferred.
2313 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2314 vaCreateContext(i965->wrapper_pdrvctx,
2315 obj_config->wrapper_config,
2316 picture_width, picture_height,
2320 if (vaStatus == VA_STATUS_SUCCESS)
2321 obj_context->wrapper_context = wrapper_context;
2323 /* Error recovery */
2324 if (VA_STATUS_SUCCESS != vaStatus) {
2325 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2328 i965->current_context_id = contextID;
2334 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2336 struct i965_driver_data *i965 = i965_driver_data(ctx);
2337 struct object_context *obj_context = CONTEXT(context);
2338 VAStatus va_status = VA_STATUS_SUCCESS;
2340 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2342 if (i965->current_context_id == context)
2343 i965->current_context_id = VA_INVALID_ID;
2345 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2346 i965->wrapper_pdrvctx) {
2347 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2348 vaDestroyContext(i965->wrapper_pdrvctx,
2349 obj_context->wrapper_context));
2351 obj_context->wrapper_context = VA_INVALID_ID;
2354 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2360 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2362 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2364 assert(obj_buffer->buffer_store);
2365 i965_release_buffer_store(&obj_buffer->buffer_store);
2366 object_heap_free(heap, obj);
2370 i965_create_buffer_internal(VADriverContextP ctx,
2371 VAContextID context,
2374 unsigned int num_elements,
2379 struct i965_driver_data *i965 = i965_driver_data(ctx);
2380 struct object_buffer *obj_buffer = NULL;
2381 struct buffer_store *buffer_store = NULL;
2383 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2384 struct object_context *obj_context = CONTEXT(context);
2385 int wrapper_flag = 0;
2389 case VAPictureParameterBufferType:
2390 case VAIQMatrixBufferType:
2391 case VAQMatrixBufferType:
2392 case VABitPlaneBufferType:
2393 case VASliceGroupMapBufferType:
2394 case VASliceParameterBufferType:
2395 case VASliceDataBufferType:
2396 case VAMacroblockParameterBufferType:
2397 case VAResidualDataBufferType:
2398 case VADeblockingParameterBufferType:
2399 case VAImageBufferType:
2400 case VAEncCodedBufferType:
2401 case VAEncSequenceParameterBufferType:
2402 case VAEncPictureParameterBufferType:
2403 case VAEncSliceParameterBufferType:
2404 case VAEncPackedHeaderParameterBufferType:
2405 case VAEncPackedHeaderDataBufferType:
2406 case VAEncMiscParameterBufferType:
2407 case VAProcPipelineParameterBufferType:
2408 case VAProcFilterParameterBufferType:
2409 case VAHuffmanTableBufferType:
2410 case VAProbabilityBufferType:
2411 case VAEncMacroblockMapBufferType:
2416 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2419 bufferID = NEW_BUFFER_ID();
2420 obj_buffer = BUFFER(bufferID);
2422 if (NULL == obj_buffer) {
2423 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2426 if (type == VAEncCodedBufferType) {
2427 size += I965_CODEDBUFFER_HEADER_SIZE;
2428 size += 0x1000; /* for upper bound check */
2431 obj_buffer->max_num_elements = num_elements;
2432 obj_buffer->num_elements = num_elements;
2433 obj_buffer->size_element = size;
2434 obj_buffer->type = type;
2435 obj_buffer->export_refcount = 0;
2436 obj_buffer->buffer_store = NULL;
2437 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2438 obj_buffer->context_id = context;
2440 buffer_store = calloc(1, sizeof(struct buffer_store));
2441 assert(buffer_store);
2442 buffer_store->ref_count = 1;
2445 (obj_context->wrapper_context != VA_INVALID_ID) &&
2446 i965->wrapper_pdrvctx) {
2447 VAGenericID wrapper_buffer;
2448 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2450 CALL_VTABLE(pdrvctx, vaStatus,
2451 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2452 data, &wrapper_buffer));
2453 if (vaStatus == VA_STATUS_SUCCESS) {
2454 obj_buffer->wrapper_buffer = wrapper_buffer;
2462 if (store_bo != NULL) {
2463 buffer_store->bo = store_bo;
2464 dri_bo_reference(buffer_store->bo);
2466 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2467 if (data && !wrapper_flag)
2468 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2469 } else if (type == VASliceDataBufferType ||
2470 type == VAImageBufferType ||
2471 type == VAEncCodedBufferType ||
2472 type == VAEncMacroblockMapBufferType ||
2473 type == VAProbabilityBufferType) {
2475 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2476 * So it is enough to allocate one 64 byte bo
2479 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2482 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2484 size * num_elements, 64);
2485 assert(buffer_store->bo);
2487 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2488 * In fact it can be skipped. But it is still allocated and it is
2489 * only to follow the normal flowchart of buffer_allocation/release.
2491 if (!wrapper_flag) {
2492 if (type == VAEncCodedBufferType) {
2493 struct i965_coded_buffer_segment *coded_buffer_segment;
2495 dri_bo_map(buffer_store->bo, 1);
2496 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2497 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2498 coded_buffer_segment->base.bit_offset = 0;
2499 coded_buffer_segment->base.status = 0;
2500 coded_buffer_segment->base.buf = NULL;
2501 coded_buffer_segment->base.next = NULL;
2502 coded_buffer_segment->mapped = 0;
2503 coded_buffer_segment->codec = 0;
2504 coded_buffer_segment->status_support = 0;
2505 dri_bo_unmap(buffer_store->bo);
2507 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2514 if (type == VAEncPackedHeaderDataBufferType) {
2515 msize = ALIGN(size, 4);
2518 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2520 buffer_store->buffer = malloc(4);
2522 buffer_store->buffer = malloc(msize * num_elements);
2523 assert(buffer_store->buffer);
2525 if (!wrapper_flag) {
2527 memcpy(buffer_store->buffer, data, size * num_elements);
2529 memset(buffer_store->buffer, 0, size * num_elements);
2533 buffer_store->num_elements = obj_buffer->num_elements;
2534 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2535 i965_release_buffer_store(&buffer_store);
2538 return VA_STATUS_SUCCESS;
2542 i965_CreateBuffer(VADriverContextP ctx,
2543 VAContextID context, /* in */
2544 VABufferType type, /* in */
2545 unsigned int size, /* in */
2546 unsigned int num_elements, /* in */
2547 void *data, /* in */
2548 VABufferID *buf_id) /* out */
2550 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2555 i965_BufferSetNumElements(VADriverContextP ctx,
2556 VABufferID buf_id, /* in */
2557 unsigned int num_elements) /* in */
2559 struct i965_driver_data *i965 = i965_driver_data(ctx);
2560 struct object_buffer *obj_buffer = BUFFER(buf_id);
2561 VAStatus vaStatus = VA_STATUS_SUCCESS;
2563 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2565 /* When the wrapper_buffer exists, it will wrapper to the
2566 * buffer allocated from backend driver.
2568 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2569 i965->wrapper_pdrvctx) {
2570 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2572 CALL_VTABLE(pdrvctx, vaStatus,
2573 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2578 if ((num_elements < 0) ||
2579 (num_elements > obj_buffer->max_num_elements)) {
2580 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2582 obj_buffer->num_elements = num_elements;
2583 if (obj_buffer->buffer_store != NULL) {
2584 obj_buffer->buffer_store->num_elements = num_elements;
2592 i965_MapBuffer(VADriverContextP ctx,
2593 VABufferID buf_id, /* in */
2594 void **pbuf) /* out */
2596 struct i965_driver_data *i965 = i965_driver_data(ctx);
2597 struct object_buffer *obj_buffer = BUFFER(buf_id);
2598 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2599 struct object_context *obj_context;
2601 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2603 obj_context = CONTEXT(obj_buffer->context_id);
2605 /* When the wrapper_buffer exists, it will wrapper to the
2606 * buffer allocated from backend driver.
2608 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2609 i965->wrapper_pdrvctx) {
2610 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2612 CALL_VTABLE(pdrvctx, vaStatus,
2613 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2617 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2618 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2620 if (obj_buffer->export_refcount > 0)
2621 return VA_STATUS_ERROR_INVALID_BUFFER;
2623 if (NULL != obj_buffer->buffer_store->bo) {
2624 unsigned int tiling, swizzle;
2626 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2628 if (tiling != I915_TILING_NONE)
2629 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2631 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2633 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2634 *pbuf = obj_buffer->buffer_store->bo->virtual;
2635 vaStatus = VA_STATUS_SUCCESS;
2637 if (obj_buffer->type == VAEncCodedBufferType) {
2639 unsigned char *buffer = NULL;
2640 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2641 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2643 if (!coded_buffer_segment->mapped) {
2644 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2646 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2649 obj_context->hw_context &&
2650 obj_context->hw_context->get_status &&
2651 coded_buffer_segment->status_support) {
2652 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2654 if (coded_buffer_segment->codec == CODEC_H264 ||
2655 coded_buffer_segment->codec == CODEC_H264_MVC) {
2656 delimiter0 = H264_DELIMITER0;
2657 delimiter1 = H264_DELIMITER1;
2658 delimiter2 = H264_DELIMITER2;
2659 delimiter3 = H264_DELIMITER3;
2660 delimiter4 = H264_DELIMITER4;
2661 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2662 delimiter0 = MPEG2_DELIMITER0;
2663 delimiter1 = MPEG2_DELIMITER1;
2664 delimiter2 = MPEG2_DELIMITER2;
2665 delimiter3 = MPEG2_DELIMITER3;
2666 delimiter4 = MPEG2_DELIMITER4;
2667 } else if(coded_buffer_segment->codec == CODEC_JPEG) {
2668 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2671 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2672 delimiter0 = HEVC_DELIMITER0;
2673 delimiter1 = HEVC_DELIMITER1;
2674 delimiter2 = HEVC_DELIMITER2;
2675 delimiter3 = HEVC_DELIMITER3;
2676 delimiter4 = HEVC_DELIMITER4;
2677 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2678 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2681 if(coded_buffer_segment->codec == CODEC_JPEG) {
2682 for(i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2683 if( (buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2687 coded_buffer_segment->base.size = i + 2;
2688 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2689 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2690 so it don't need to traversal the coded buffer */
2691 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2692 if ((buffer[i] == delimiter0) &&
2693 (buffer[i + 1] == delimiter1) &&
2694 (buffer[i + 2] == delimiter2) &&
2695 (buffer[i + 3] == delimiter3) &&
2696 (buffer[i + 4] == delimiter4))
2700 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2701 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2703 coded_buffer_segment->base.size = i;
2706 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2707 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2710 vaStatus = VA_STATUS_SUCCESS;
2713 coded_buffer_segment->mapped = 1;
2715 assert(coded_buffer_segment->base.buf);
2716 vaStatus = VA_STATUS_SUCCESS;
2719 } else if (NULL != obj_buffer->buffer_store->buffer) {
2720 *pbuf = obj_buffer->buffer_store->buffer;
2721 vaStatus = VA_STATUS_SUCCESS;
2728 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2730 struct i965_driver_data *i965 = i965_driver_data(ctx);
2731 struct object_buffer *obj_buffer = BUFFER(buf_id);
2732 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2734 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2735 return VA_STATUS_ERROR_INVALID_BUFFER;
2737 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2738 /* When the wrapper_buffer exists, it will wrapper to the
2739 * buffer allocated from backend driver.
2741 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2742 i965->wrapper_pdrvctx) {
2743 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2745 CALL_VTABLE(pdrvctx, vaStatus,
2746 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2750 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2751 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2753 if (NULL != obj_buffer->buffer_store->bo) {
2754 unsigned int tiling, swizzle;
2756 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2758 if (tiling != I915_TILING_NONE)
2759 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2761 dri_bo_unmap(obj_buffer->buffer_store->bo);
2763 vaStatus = VA_STATUS_SUCCESS;
2764 } else if (NULL != obj_buffer->buffer_store->buffer) {
2766 vaStatus = VA_STATUS_SUCCESS;
2773 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2775 struct i965_driver_data *i965 = i965_driver_data(ctx);
2776 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2777 VAStatus va_status = VA_STATUS_SUCCESS;
2779 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2781 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2782 i965->wrapper_pdrvctx) {
2783 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2784 vaDestroyBuffer(i965->wrapper_pdrvctx,
2785 obj_buffer->wrapper_buffer));
2786 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2789 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2795 i965_BeginPicture(VADriverContextP ctx,
2796 VAContextID context,
2797 VASurfaceID render_target)
2799 struct i965_driver_data *i965 = i965_driver_data(ctx);
2800 struct object_context *obj_context = CONTEXT(context);
2801 struct object_surface *obj_surface = SURFACE(render_target);
2802 struct object_config *obj_config;
2803 VAStatus vaStatus = VA_STATUS_SUCCESS;
2806 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2807 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2808 obj_config = obj_context->obj_config;
2809 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2811 if (is_surface_busy(i965, obj_surface))
2812 return VA_STATUS_ERROR_SURFACE_BUSY;
2814 if (obj_context->codec_type == CODEC_PROC) {
2815 obj_context->codec_state.proc.current_render_target = render_target;
2816 } else if (obj_context->codec_type == CODEC_ENC) {
2818 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2820 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2821 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2823 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2824 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2826 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2827 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2829 obj_context->codec_state.encode.num_slice_params_ext = 0;
2830 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2831 obj_context->codec_state.encode.last_packed_header_type = 0;
2832 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2833 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2834 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2835 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2836 memset(obj_context->codec_state.encode.slice_header_index, 0,
2837 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2839 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2840 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2841 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2842 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2843 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2844 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2845 obj_context->codec_state.encode.slice_index = 0;
2846 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2848 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2849 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2850 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2852 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2854 obj_context->codec_state.decode.current_render_target = render_target;
2855 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2856 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2857 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2858 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2860 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2861 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2862 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2865 obj_context->codec_state.decode.num_slice_params = 0;
2866 obj_context->codec_state.decode.num_slice_datas = 0;
2868 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2869 i965->wrapper_pdrvctx) {
2870 if (obj_surface->wrapper_surface == VA_INVALID_ID)
2871 vaStatus = i965_surface_wrapper(ctx, render_target);
2873 if (vaStatus != VA_STATUS_SUCCESS)
2876 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2877 vaBeginPicture(i965->wrapper_pdrvctx,
2878 obj_context->wrapper_context,
2879 obj_surface->wrapper_surface));
2886 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2888 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2890 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2891 struct object_context *obj_context, \
2892 struct object_buffer *obj_buffer) \
2894 struct category##_state *category = &obj_context->codec_state.category; \
2895 i965_release_buffer_store(&category->member); \
2896 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2897 return VA_STATUS_SUCCESS; \
2900 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2902 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2903 struct object_context *obj_context, \
2904 struct object_buffer *obj_buffer) \
2906 struct category##_state *category = &obj_context->codec_state.category; \
2907 if (category->num_##member == category->max_##member) { \
2908 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2909 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2910 category->max_##member += NUM_SLICES; \
2912 i965_release_buffer_store(&category->member[category->num_##member]); \
2913 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2914 category->num_##member++; \
2915 return VA_STATUS_SUCCESS; \
2918 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2920 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2921 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2922 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2923 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2924 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2925 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2927 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2928 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2929 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2933 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
2934 VABufferID *buffers,
2937 struct i965_driver_data *i965 = i965_driver_data(ctx);
2938 VAStatus vaStatus = VA_STATUS_SUCCESS;
2940 VADecPictureParameterBufferVP9 *pVp9PicParams;
2941 VADriverContextP pdrvctx;
2942 struct object_buffer *obj_buffer;
2944 pdrvctx = i965->wrapper_pdrvctx;
2945 /* do the conversion of VADecPictureParameterBufferVP9 */
2946 for (i = 0; i < num_buffers; i++) {
2947 obj_buffer = BUFFER(buffers[i]);
2952 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
2955 if (obj_buffer->type == VAPictureParameterBufferType) {
2957 VASurfaceID surface_id;
2958 struct object_surface *obj_surface;
2960 pdrvctx = i965->wrapper_pdrvctx;
2962 CALL_VTABLE(pdrvctx, vaStatus,
2963 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
2964 (void **)(&pVp9PicParams)));
2966 if (vaStatus != VA_STATUS_SUCCESS)
2969 for (j = 0; j < 8; j++) {
2970 surface_id = pVp9PicParams->reference_frames[j];
2971 obj_surface = SURFACE(surface_id);
2976 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
2977 vaStatus = i965_surface_wrapper(ctx, surface_id);
2978 if (vaStatus != VA_STATUS_SUCCESS) {
2979 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
2980 obj_buffer->wrapper_buffer);
2985 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
2987 CALL_VTABLE(pdrvctx, vaStatus,
2988 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2993 return VA_STATUS_SUCCESS;
3000 i965_decoder_wrapper_picture(VADriverContextP ctx,
3001 VAContextID context,
3002 VABufferID *buffers,
3005 struct i965_driver_data *i965 = i965_driver_data(ctx);
3006 struct object_context *obj_context = CONTEXT(context);
3007 VAStatus vaStatus = VA_STATUS_SUCCESS;
3009 VADriverContextP pdrvctx;
3010 struct object_buffer *obj_buffer;
3012 if (obj_context == NULL)
3013 return VA_STATUS_ERROR_INVALID_CONTEXT;
3015 /* When it is not wrapped context, continue the normal flowchart */
3016 if (obj_context->wrapper_context == VA_INVALID_ID)
3019 if (obj_context->obj_config &&
3020 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3021 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3023 return VA_STATUS_ERROR_INVALID_PARAMETER;
3025 pdrvctx = i965->wrapper_pdrvctx;
3027 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3028 obj_buffer = BUFFER(buffers[i]);
3033 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3034 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3038 CALL_VTABLE(pdrvctx, vaStatus,
3039 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3040 &(obj_buffer->wrapper_buffer), 1));
3046 i965_decoder_render_picture(VADriverContextP ctx,
3047 VAContextID context,
3048 VABufferID *buffers,
3051 struct i965_driver_data *i965 = i965_driver_data(ctx);
3052 struct object_context *obj_context = CONTEXT(context);
3053 VAStatus vaStatus = VA_STATUS_SUCCESS;
3056 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3058 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3059 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3062 return VA_STATUS_ERROR_INVALID_BUFFER;
3064 switch (obj_buffer->type) {
3065 case VAPictureParameterBufferType:
3066 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3069 case VAIQMatrixBufferType:
3070 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3073 case VABitPlaneBufferType:
3074 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3077 case VASliceParameterBufferType:
3078 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3081 case VASliceDataBufferType:
3082 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3085 case VAHuffmanTableBufferType:
3086 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3089 case VAProbabilityBufferType:
3090 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3094 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3099 if ((vaStatus == VA_STATUS_SUCCESS) &&
3100 (obj_context->wrapper_context != VA_INVALID_ID))
3101 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3106 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3108 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3109 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3110 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3111 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3112 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3113 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3114 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3115 /* extended buffer */
3116 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3117 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3118 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3120 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3121 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3122 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3124 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3125 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3128 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3129 struct object_context *obj_context,
3130 struct object_buffer *obj_buffer,
3133 struct encode_state *encode = &obj_context->codec_state.encode;
3135 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3136 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3137 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3138 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3140 return VA_STATUS_SUCCESS;
3144 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3145 struct object_context *obj_context,
3146 struct object_buffer *obj_buffer,
3149 struct encode_state *encode = &obj_context->codec_state.encode;
3151 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3152 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3153 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3154 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3156 return VA_STATUS_SUCCESS;
3160 i965_encoder_get_misc_paramerter_buffer_index(VADriverContextP ctx,
3161 struct encode_state *encode,
3162 VAEncMiscParameterBuffer *misc_param)
3166 if (!encode->has_layers)
3169 if (misc_param->type == VAEncMiscParameterTypeRateControl) {
3170 VAEncMiscParameterRateControl *misc_rate_control = (VAEncMiscParameterRateControl *)misc_param->data;
3172 index = misc_rate_control->rc_flags.bits.temporal_id;
3173 } else if (misc_param->type == VAEncMiscParameterTypeFrameRate) {
3174 VAEncMiscParameterFrameRate *misc_frame_rate = (VAEncMiscParameterFrameRate *)misc_param->data;
3176 index = misc_frame_rate->framerate_flags.bits.temporal_id;
3183 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3184 struct object_context *obj_context,
3185 struct object_buffer *obj_buffer)
3187 struct encode_state *encode = &obj_context->codec_state.encode;
3188 VAEncMiscParameterBuffer *param = NULL;
3191 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3192 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3194 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3196 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3197 return VA_STATUS_ERROR_INVALID_PARAMETER;
3199 if (param->type == VAEncMiscParameterTypeTemporalLayerStructure)
3200 encode->has_layers = 1;
3202 index = i965_encoder_get_misc_paramerter_buffer_index(ctx, encode, param);
3204 if (index >= ARRAY_ELEMS(encode->misc_param[0]))
3205 return VA_STATUS_ERROR_INVALID_PARAMETER;
3207 i965_release_buffer_store(&encode->misc_param[param->type][index]);
3208 i965_reference_buffer_store(&encode->misc_param[param->type][index], obj_buffer->buffer_store);
3210 return VA_STATUS_SUCCESS;
3214 i965_encoder_render_picture(VADriverContextP ctx,
3215 VAContextID context,
3216 VABufferID *buffers,
3219 struct i965_driver_data *i965 = i965_driver_data(ctx);
3220 struct object_context *obj_context = CONTEXT(context);
3221 struct object_config *obj_config;
3222 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3223 struct encode_state *encode;
3226 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3227 obj_config = obj_context->obj_config;
3228 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3230 encode = &obj_context->codec_state.encode;
3231 for (i = 0; i < num_buffers; i++) {
3232 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3235 return VA_STATUS_ERROR_INVALID_BUFFER;
3237 switch (obj_buffer->type) {
3238 case VAQMatrixBufferType:
3239 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3242 case VAIQMatrixBufferType:
3243 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3246 case VAEncSequenceParameterBufferType:
3247 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3250 case VAEncPictureParameterBufferType:
3251 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3254 case VAHuffmanTableBufferType:
3255 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3258 case VAEncSliceParameterBufferType:
3259 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3260 if (vaStatus == VA_STATUS_SUCCESS) {
3261 /* When the max number of slices is updated, it also needs
3262 * to reallocate the arrays that is used to store
3263 * the packed data index/count for the slice
3265 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3266 encode->slice_index++;
3268 if (encode->slice_index == encode->max_slice_num) {
3269 int slice_num = encode->max_slice_num;
3270 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3271 (slice_num + NUM_SLICES) * sizeof(int));
3272 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3273 (slice_num + NUM_SLICES) * sizeof(int));
3274 encode->slice_header_index = realloc(encode->slice_header_index,
3275 (slice_num + NUM_SLICES) * sizeof(int));
3276 memset(encode->slice_rawdata_index + slice_num, 0,
3277 sizeof(int) * NUM_SLICES);
3278 memset(encode->slice_rawdata_count + slice_num, 0,
3279 sizeof(int) * NUM_SLICES);
3280 memset(encode->slice_header_index + slice_num, 0,
3281 sizeof(int) * NUM_SLICES);
3283 encode->max_slice_num += NUM_SLICES;
3284 if ((encode->slice_rawdata_index == NULL) ||
3285 (encode->slice_header_index == NULL) ||
3286 (encode->slice_rawdata_count == NULL)) {
3287 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3294 case VAEncPackedHeaderParameterBufferType:
3296 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3297 encode->last_packed_header_type = param->type;
3299 if ((param->type == VAEncPackedHeaderRawData) ||
3300 (param->type == VAEncPackedHeaderSlice)) {
3301 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3302 } else if((obj_config->profile == VAProfileHEVCMain ||
3303 obj_config->profile == VAProfileHEVCMain10) &&
3304 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3305 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3308 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3310 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3313 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3318 case VAEncPackedHeaderDataBufferType:
3320 if (encode->last_packed_header_type == 0) {
3321 WARN_ONCE("the packed header data is passed without type!\n");
3322 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3326 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3327 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3328 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3330 if (obj_config->profile == VAProfileVP9Profile0)
3333 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3334 * the packed_slice_header as the delimeter to decide how
3335 * the packed rawdata is inserted for the given slice.
3336 * Otherwise it will use the VAEncSequenceParameterBuffer
3339 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3340 /* store the first index of the packed header data for current slice */
3341 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3342 encode->slice_rawdata_index[encode->slice_index] =
3343 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3345 encode->slice_rawdata_count[encode->slice_index]++;
3346 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3347 /* find one packed slice_header delimeter. And the following
3348 * packed data is for the next slice
3350 encode->slice_header_index[encode->slice_index] =
3351 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3352 encode->slice_index++;
3353 /* Reallocate the buffer to record the index/count of
3354 * packed_data for one slice.
3356 if (encode->slice_index == encode->max_slice_num) {
3357 int slice_num = encode->max_slice_num;
3359 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3360 (slice_num + NUM_SLICES) * sizeof(int));
3361 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3362 (slice_num + NUM_SLICES) * sizeof(int));
3363 encode->slice_header_index = realloc(encode->slice_header_index,
3364 (slice_num + NUM_SLICES) * sizeof(int));
3365 memset(encode->slice_rawdata_index + slice_num, 0,
3366 sizeof(int) * NUM_SLICES);
3367 memset(encode->slice_rawdata_count + slice_num, 0,
3368 sizeof(int) * NUM_SLICES);
3369 memset(encode->slice_header_index + slice_num, 0,
3370 sizeof(int) * NUM_SLICES);
3371 encode->max_slice_num += NUM_SLICES;
3375 if (vaStatus == VA_STATUS_SUCCESS) {
3376 /* store the first index of the packed header data for current slice */
3377 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3378 encode->slice_rawdata_index[encode->slice_index] =
3379 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3381 encode->slice_rawdata_count[encode->slice_index]++;
3382 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3383 if (encode->slice_header_index[encode->slice_index] == 0) {
3384 encode->slice_header_index[encode->slice_index] =
3385 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3387 WARN_ONCE("Multi slice header data is passed for"
3388 " slice %d!\n", encode->slice_index);
3394 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3395 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3396 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3397 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3398 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3399 VA_STATUS_ERROR_ENCODING_ERROR);
3401 if((obj_config->profile == VAProfileHEVCMain ||
3402 obj_config->profile == VAProfileHEVCMain10) &&
3403 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3405 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3408 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3409 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3411 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3414 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3418 encode->last_packed_header_type = 0;
3422 case VAEncMiscParameterBufferType:
3423 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3428 case VAEncMacroblockMapBufferType:
3429 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3433 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3441 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3443 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3444 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3447 i965_proc_render_picture(VADriverContextP ctx,
3448 VAContextID context,
3449 VABufferID *buffers,
3452 struct i965_driver_data *i965 = i965_driver_data(ctx);
3453 struct object_context *obj_context = CONTEXT(context);
3454 VAStatus vaStatus = VA_STATUS_SUCCESS;
3457 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3459 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3460 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3463 return VA_STATUS_ERROR_INVALID_BUFFER;
3465 switch (obj_buffer->type) {
3466 case VAProcPipelineParameterBufferType:
3467 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3471 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3480 i965_RenderPicture(VADriverContextP ctx,
3481 VAContextID context,
3482 VABufferID *buffers,
3485 struct i965_driver_data *i965 = i965_driver_data(ctx);
3486 struct object_context *obj_context;
3487 struct object_config *obj_config;
3488 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3490 obj_context = CONTEXT(context);
3491 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3493 if (num_buffers <= 0)
3494 return VA_STATUS_ERROR_INVALID_PARAMETER;
3496 obj_config = obj_context->obj_config;
3497 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3499 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3500 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3501 } else if ((VAEntrypointEncSlice == obj_config->entrypoint ) ||
3502 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3503 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3504 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3506 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3513 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3515 struct i965_driver_data *i965 = i965_driver_data(ctx);
3516 struct object_context *obj_context = CONTEXT(context);
3517 struct object_config *obj_config;
3519 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3520 obj_config = obj_context->obj_config;
3521 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3523 if (obj_context->codec_type == CODEC_PROC) {
3524 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3525 } else if (obj_context->codec_type == CODEC_ENC) {
3526 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3527 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3528 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3529 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3531 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3532 obj_context->codec_state.encode.num_packed_header_data_ext) {
3533 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3534 return VA_STATUS_ERROR_INVALID_PARAMETER;
3536 if (!obj_context->codec_state.encode.pic_param_ext) {
3537 return VA_STATUS_ERROR_INVALID_PARAMETER;
3539 if (!obj_context->codec_state.encode.seq_param_ext &&
3540 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3541 /* The seq_param is not mandatory for VP9 encoding */
3542 if (obj_config->profile != VAProfileVP9Profile0)
3543 return VA_STATUS_ERROR_INVALID_PARAMETER;
3545 if ((obj_context->codec_state.encode.num_slice_params_ext <=0) &&
3546 ((obj_config->profile != VAProfileVP8Version0_3) &&
3547 (obj_config->profile != VAProfileVP9Profile0))) {
3548 return VA_STATUS_ERROR_INVALID_PARAMETER;
3551 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3552 (obj_context->codec_state.encode.num_slice_params_ext !=
3553 obj_context->codec_state.encode.slice_index)) {
3554 WARN_ONCE("packed slice_header data is missing for some slice"
3555 " under packed SLICE_HEADER mode\n");
3556 return VA_STATUS_ERROR_INVALID_PARAMETER;
3559 if (obj_context->codec_state.decode.pic_param == NULL) {
3560 return VA_STATUS_ERROR_INVALID_PARAMETER;
3562 if (obj_context->codec_state.decode.num_slice_params <=0) {
3563 return VA_STATUS_ERROR_INVALID_PARAMETER;
3565 if (obj_context->codec_state.decode.num_slice_datas <=0) {
3566 return VA_STATUS_ERROR_INVALID_PARAMETER;
3569 if (obj_context->codec_state.decode.num_slice_params !=
3570 obj_context->codec_state.decode.num_slice_datas) {
3571 return VA_STATUS_ERROR_INVALID_PARAMETER;
3574 if (obj_context->wrapper_context != VA_INVALID_ID) {
3575 /* call the vaEndPicture of wrapped driver */
3576 VADriverContextP pdrvctx;
3579 pdrvctx = i965->wrapper_pdrvctx;
3580 CALL_VTABLE(pdrvctx, va_status,
3581 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3587 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3588 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3592 i965_SyncSurface(VADriverContextP ctx,
3593 VASurfaceID render_target)
3595 struct i965_driver_data *i965 = i965_driver_data(ctx);
3596 struct object_surface *obj_surface = SURFACE(render_target);
3598 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3601 drm_intel_bo_wait_rendering(obj_surface->bo);
3603 return VA_STATUS_SUCCESS;
3607 i965_QuerySurfaceStatus(VADriverContextP ctx,
3608 VASurfaceID render_target,
3609 VASurfaceStatus *status) /* out */
3611 struct i965_driver_data *i965 = i965_driver_data(ctx);
3612 struct object_surface *obj_surface = SURFACE(render_target);
3614 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3616 if (obj_surface->bo) {
3617 if (drm_intel_bo_busy(obj_surface->bo)){
3618 *status = VASurfaceRendering;
3621 *status = VASurfaceReady;
3624 *status = VASurfaceReady;
3627 return VA_STATUS_SUCCESS;
3630 static VADisplayAttribute *
3631 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3633 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3636 if (!i965->display_attributes)
3639 for (i = 0; i < i965->num_display_attributes; i++) {
3640 if (i965->display_attributes[i].type == type)
3641 return &i965->display_attributes[i];
3647 i965_display_attributes_terminate(VADriverContextP ctx)
3649 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3651 if (i965->display_attributes) {
3652 free(i965->display_attributes);
3653 i965->display_attributes = NULL;
3654 i965->num_display_attributes = 0;
3659 i965_display_attributes_init(VADriverContextP ctx)
3661 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3663 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3664 i965->display_attributes = malloc(
3665 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3666 if (!i965->display_attributes)
3670 i965->display_attributes,
3671 i965_display_attributes,
3672 sizeof(i965_display_attributes)
3675 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3676 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3677 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3678 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3679 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3681 if (!i965->rotation_attrib ||
3682 !i965->brightness_attrib ||
3683 !i965->contrast_attrib ||
3684 !i965->hue_attrib ||
3685 !i965->saturation_attrib) {
3691 i965_display_attributes_terminate(ctx);
3696 * Query display attributes
3697 * The caller must provide a "attr_list" array that can hold at
3698 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3699 * returned in "attr_list" is returned in "num_attributes".
3702 i965_QueryDisplayAttributes(
3703 VADriverContextP ctx,
3704 VADisplayAttribute *attribs, /* out */
3705 int *num_attribs_ptr /* out */
3708 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3710 if (attribs && num_attribs > 0)
3711 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3713 if (num_attribs_ptr)
3714 *num_attribs_ptr = num_attribs;
3716 return VA_STATUS_SUCCESS;
3720 * Get display attributes
3721 * This function returns the current attribute values in "attr_list".
3722 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3723 * from vaQueryDisplayAttributes() can have their values retrieved.
3726 i965_GetDisplayAttributes(
3727 VADriverContextP ctx,
3728 VADisplayAttribute *attribs, /* inout */
3729 int num_attribs /* in */
3734 for (i = 0; i < num_attribs; i++) {
3735 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3737 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3739 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3740 dst_attrib->min_value = src_attrib->min_value;
3741 dst_attrib->max_value = src_attrib->max_value;
3742 dst_attrib->value = src_attrib->value;
3743 dst_attrib->flags = src_attrib->flags;
3744 } else if (src_attrib &&
3745 (src_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE)) {
3746 dst_attrib->flags = src_attrib->flags;
3749 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3751 return VA_STATUS_SUCCESS;
3755 * Set display attributes
3756 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3757 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3758 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3761 i965_SetDisplayAttributes(
3762 VADriverContextP ctx,
3763 VADisplayAttribute *attribs, /* in */
3764 int num_attribs /* in */
3769 for (i = 0; i < num_attribs; i++) {
3770 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3772 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3774 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3776 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3779 if (src_attrib->value < dst_attrib->min_value ||
3780 src_attrib->value > dst_attrib->max_value)
3781 return VA_STATUS_ERROR_INVALID_PARAMETER;
3783 dst_attrib->value = src_attrib->value;
3784 /* XXX: track modified attributes through timestamps */
3786 return VA_STATUS_SUCCESS;
3790 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3791 VASurfaceID surface,
3792 void **buffer, /* out */
3793 unsigned int *stride) /* out */
3796 return VA_STATUS_ERROR_UNIMPLEMENTED;
3800 i965_destroy_heap(struct object_heap *heap,
3801 void (*func)(struct object_heap *heap, struct object_base *object))
3803 struct object_base *object;
3804 object_heap_iterator iter;
3806 object = object_heap_first(heap, &iter);
3812 object = object_heap_next(heap, &iter);
3815 object_heap_destroy(heap);
3820 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3823 i965_CreateImage(VADriverContextP ctx,
3824 VAImageFormat *format,
3827 VAImage *out_image) /* out */
3829 struct i965_driver_data *i965 = i965_driver_data(ctx);
3830 struct object_image *obj_image;
3831 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3833 unsigned int size2, size, awidth, aheight;
3835 out_image->image_id = VA_INVALID_ID;
3836 out_image->buf = VA_INVALID_ID;
3838 image_id = NEW_IMAGE_ID();
3839 if (image_id == VA_INVALID_ID)
3840 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3842 obj_image = IMAGE(image_id);
3844 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3845 obj_image->bo = NULL;
3846 obj_image->palette = NULL;
3847 obj_image->derived_surface = VA_INVALID_ID;
3849 VAImage * const image = &obj_image->image;
3850 image->image_id = image_id;
3851 image->buf = VA_INVALID_ID;
3853 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3855 if ((format->fourcc == VA_FOURCC_YV12) ||
3856 (format->fourcc == VA_FOURCC_I420)) {
3857 if (awidth % 128 != 0) {
3858 awidth = ALIGN(width, 128);
3862 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3863 size = awidth * aheight;
3864 size2 = (awidth / 2) * (aheight / 2);
3866 image->num_palette_entries = 0;
3867 image->entry_bytes = 0;
3868 memset(image->component_order, 0, sizeof(image->component_order));
3870 switch (format->fourcc) {
3871 case VA_FOURCC_IA44:
3872 case VA_FOURCC_AI44:
3873 image->num_planes = 1;
3874 image->pitches[0] = awidth;
3875 image->offsets[0] = 0;
3876 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3877 image->num_palette_entries = 16;
3878 image->entry_bytes = 3;
3879 image->component_order[0] = 'R';
3880 image->component_order[1] = 'G';
3881 image->component_order[2] = 'B';
3883 case VA_FOURCC_IA88:
3884 case VA_FOURCC_AI88:
3885 image->num_planes = 1;
3886 image->pitches[0] = awidth * 2;
3887 image->offsets[0] = 0;
3888 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3889 image->num_palette_entries = 256;
3890 image->entry_bytes = 3;
3891 image->component_order[0] = 'R';
3892 image->component_order[1] = 'G';
3893 image->component_order[2] = 'B';
3895 case VA_FOURCC_ARGB:
3896 case VA_FOURCC_ABGR:
3897 case VA_FOURCC_BGRA:
3898 case VA_FOURCC_RGBA:
3899 case VA_FOURCC_BGRX:
3900 case VA_FOURCC_RGBX:
3901 image->num_planes = 1;
3902 image->pitches[0] = awidth * 4;
3903 image->offsets[0] = 0;
3904 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3906 case VA_FOURCC_YV12:
3907 image->num_planes = 3;
3908 image->pitches[0] = awidth;
3909 image->offsets[0] = 0;
3910 image->pitches[1] = awidth / 2;
3911 image->offsets[1] = size;
3912 image->pitches[2] = awidth / 2;
3913 image->offsets[2] = size + size2;
3914 image->data_size = size + 2 * size2;
3916 case VA_FOURCC_I420:
3917 image->num_planes = 3;
3918 image->pitches[0] = awidth;
3919 image->offsets[0] = 0;
3920 image->pitches[1] = awidth / 2;
3921 image->offsets[1] = size;
3922 image->pitches[2] = awidth / 2;
3923 image->offsets[2] = size + size2;
3924 image->data_size = size + 2 * size2;
3926 case VA_FOURCC_422H:
3927 image->num_planes = 3;
3928 image->pitches[0] = awidth;
3929 image->offsets[0] = 0;
3930 image->pitches[1] = awidth / 2;
3931 image->offsets[1] = size;
3932 image->pitches[2] = awidth / 2;
3933 image->offsets[2] = size + (awidth / 2) * aheight;
3934 image->data_size = size + 2 * ((awidth / 2) * aheight);
3936 case VA_FOURCC_NV12:
3937 image->num_planes = 2;
3938 image->pitches[0] = awidth;
3939 image->offsets[0] = 0;
3940 image->pitches[1] = awidth;
3941 image->offsets[1] = size;
3942 image->data_size = size + 2 * size2;
3944 case VA_FOURCC_YUY2:
3945 case VA_FOURCC_UYVY:
3946 image->num_planes = 1;
3947 image->pitches[0] = awidth * 2;
3948 image->offsets[0] = 0;
3949 image->data_size = size * 2;
3951 case VA_FOURCC_P010:
3952 image->num_planes = 2;
3953 image->pitches[0] = awidth * 2;
3954 image->offsets[0] = 0;
3955 image->pitches[1] = awidth * 2;
3956 image->offsets[1] = size * 2;
3957 image->data_size = size * 2 + 2 * size2 * 2;
3963 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
3964 image->data_size, 1, NULL, &image->buf);
3965 if (va_status != VA_STATUS_SUCCESS)
3968 struct object_buffer *obj_buffer = BUFFER(image->buf);
3971 !obj_buffer->buffer_store ||
3972 !obj_buffer->buffer_store->bo)
3973 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3975 obj_image->bo = obj_buffer->buffer_store->bo;
3976 dri_bo_reference(obj_image->bo);
3978 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3979 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3980 if (!obj_image->palette)
3984 image->image_id = image_id;
3985 image->format = *format;
3986 image->width = width;
3987 image->height = height;
3989 *out_image = *image;
3990 return VA_STATUS_SUCCESS;
3993 i965_DestroyImage(ctx, image_id);
3998 i965_check_alloc_surface_bo(VADriverContextP ctx,
3999 struct object_surface *obj_surface,
4001 unsigned int fourcc,
4002 unsigned int subsampling)
4004 struct i965_driver_data *i965 = i965_driver_data(ctx);
4005 int region_width, region_height;
4007 if (obj_surface->bo) {
4008 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4009 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4010 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4011 return VA_STATUS_SUCCESS;
4014 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4015 obj_surface->x_cr_offset = 0;
4017 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4019 if ((tiled && !obj_surface->user_disable_tiling)) {
4020 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4021 fourcc != VA_FOURCC_IYUV &&
4022 fourcc != VA_FOURCC_YV12,
4023 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4025 if (obj_surface->user_h_stride_set) {
4026 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4028 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4030 if (obj_surface->user_v_stride_set) {
4031 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4033 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4035 region_height = obj_surface->height;
4038 case VA_FOURCC_NV12:
4039 case VA_FOURCC_P010:
4040 assert(subsampling == SUBSAMPLE_YUV420);
4041 obj_surface->cb_cr_pitch = obj_surface->width;
4042 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4043 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4044 obj_surface->y_cb_offset = obj_surface->height;
4045 obj_surface->y_cr_offset = obj_surface->height;
4046 region_width = obj_surface->width;
4047 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4051 case VA_FOURCC_IMC1:
4052 assert(subsampling == SUBSAMPLE_YUV420);
4053 obj_surface->cb_cr_pitch = obj_surface->width;
4054 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4055 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4056 obj_surface->y_cr_offset = obj_surface->height;
4057 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4058 region_width = obj_surface->width;
4059 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4063 case VA_FOURCC_IMC3:
4064 assert(subsampling == SUBSAMPLE_YUV420);
4065 obj_surface->cb_cr_pitch = obj_surface->width;
4066 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4067 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4068 obj_surface->y_cb_offset = obj_surface->height;
4069 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4070 region_width = obj_surface->width;
4071 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4075 case VA_FOURCC_422H:
4076 assert(subsampling == SUBSAMPLE_YUV422H);
4077 obj_surface->cb_cr_pitch = obj_surface->width;
4078 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4079 obj_surface->cb_cr_height = obj_surface->orig_height;
4080 obj_surface->y_cb_offset = obj_surface->height;
4081 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4082 region_width = obj_surface->width;
4083 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4087 case VA_FOURCC_422V:
4088 assert(subsampling == SUBSAMPLE_YUV422V);
4089 obj_surface->cb_cr_pitch = obj_surface->width;
4090 obj_surface->cb_cr_width = obj_surface->orig_width;
4091 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4092 obj_surface->y_cb_offset = obj_surface->height;
4093 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4094 region_width = obj_surface->width;
4095 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4099 case VA_FOURCC_411P:
4100 assert(subsampling == SUBSAMPLE_YUV411);
4101 obj_surface->cb_cr_pitch = obj_surface->width;
4102 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4103 obj_surface->cb_cr_height = obj_surface->orig_height;
4104 obj_surface->y_cb_offset = obj_surface->height;
4105 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4106 region_width = obj_surface->width;
4107 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4111 case VA_FOURCC_444P:
4112 assert(subsampling == SUBSAMPLE_YUV444);
4113 obj_surface->cb_cr_pitch = obj_surface->width;
4114 obj_surface->cb_cr_width = obj_surface->orig_width;
4115 obj_surface->cb_cr_height = obj_surface->orig_height;
4116 obj_surface->y_cb_offset = obj_surface->height;
4117 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4118 region_width = obj_surface->width;
4119 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4123 case VA_FOURCC_Y800:
4124 assert(subsampling == SUBSAMPLE_YUV400);
4125 obj_surface->cb_cr_pitch = 0;
4126 obj_surface->cb_cr_width = 0;
4127 obj_surface->cb_cr_height = 0;
4128 obj_surface->y_cb_offset = 0;
4129 obj_surface->y_cr_offset = 0;
4130 region_width = obj_surface->width;
4131 region_height = obj_surface->height;
4135 case VA_FOURCC_YUY2:
4136 case VA_FOURCC_UYVY:
4137 assert(subsampling == SUBSAMPLE_YUV422H);
4138 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4139 obj_surface->cb_cr_pitch = obj_surface->width;
4140 obj_surface->y_cb_offset = 0;
4141 obj_surface->y_cr_offset = 0;
4142 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4143 obj_surface->cb_cr_height = obj_surface->orig_height;
4144 region_width = obj_surface->width;
4145 region_height = obj_surface->height;
4149 case VA_FOURCC_RGBA:
4150 case VA_FOURCC_RGBX:
4151 case VA_FOURCC_BGRA:
4152 case VA_FOURCC_BGRX:
4153 assert(subsampling == SUBSAMPLE_RGBX);
4155 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4156 region_width = obj_surface->width;
4157 region_height = obj_surface->height;
4161 /* Never get here */
4162 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4166 assert(subsampling == SUBSAMPLE_YUV420 ||
4167 subsampling == SUBSAMPLE_YUV422H ||
4168 subsampling == SUBSAMPLE_YUV422V ||
4169 subsampling == SUBSAMPLE_RGBX);
4171 region_width = obj_surface->width;
4172 region_height = obj_surface->height;
4175 case VA_FOURCC_NV12:
4176 case VA_FOURCC_P010:
4177 obj_surface->y_cb_offset = obj_surface->height;
4178 obj_surface->y_cr_offset = obj_surface->height;
4179 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4180 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4181 obj_surface->cb_cr_pitch = obj_surface->width;
4182 region_height = obj_surface->height + obj_surface->height / 2;
4185 case VA_FOURCC_YV16:
4186 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4187 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4188 obj_surface->cb_cr_height = obj_surface->orig_height;
4189 obj_surface->y_cr_offset = obj_surface->height;
4190 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4191 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4192 region_width = obj_surface->width;
4193 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4196 case VA_FOURCC_YV12:
4197 case VA_FOURCC_I420:
4198 case VA_FOURCC_IYUV:
4199 if (fourcc == VA_FOURCC_YV12) {
4200 obj_surface->y_cr_offset = obj_surface->height;
4201 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4203 obj_surface->y_cb_offset = obj_surface->height;
4204 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4207 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4208 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4209 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4210 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4211 region_width = obj_surface->width;
4212 region_height = obj_surface->height + obj_surface->height / 2;
4215 case VA_FOURCC_I010:
4216 obj_surface->y_cb_offset = obj_surface->height;
4217 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4218 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4219 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
4220 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4221 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4222 region_width = obj_surface->width;
4223 region_height = obj_surface->height + obj_surface->height / 2;
4226 case VA_FOURCC_YUY2:
4227 case VA_FOURCC_UYVY:
4228 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4229 obj_surface->y_cb_offset = 0;
4230 obj_surface->y_cr_offset = 0;
4231 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4232 obj_surface->cb_cr_height = obj_surface->orig_height;
4233 obj_surface->cb_cr_pitch = obj_surface->width;
4234 region_width = obj_surface->width;
4235 region_height = obj_surface->height;
4237 case VA_FOURCC_RGBA:
4238 case VA_FOURCC_RGBX:
4239 case VA_FOURCC_BGRA:
4240 case VA_FOURCC_BGRX:
4241 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4242 region_width = obj_surface->width;
4243 region_height = obj_surface->height;
4247 /* Never get here */
4248 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4253 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4255 if ((tiled && !obj_surface->user_disable_tiling)) {
4256 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4257 unsigned long pitch;
4259 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4267 assert(tiling_mode == I915_TILING_Y);
4268 assert(pitch == obj_surface->width);
4270 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4276 obj_surface->fourcc = fourcc;
4277 obj_surface->subsampling = subsampling;
4278 assert(obj_surface->bo);
4279 return VA_STATUS_SUCCESS;
4282 VAStatus i965_DeriveImage(VADriverContextP ctx,
4283 VASurfaceID surface,
4284 VAImage *out_image) /* out */
4286 struct i965_driver_data *i965 = i965_driver_data(ctx);
4287 struct object_image *obj_image;
4288 struct object_surface *obj_surface;
4290 unsigned int w_pitch;
4291 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4293 out_image->image_id = VA_INVALID_ID;
4294 obj_surface = SURFACE(surface);
4297 return VA_STATUS_ERROR_INVALID_SURFACE;
4299 if (!obj_surface->bo) {
4300 unsigned int is_tiled = 0;
4301 unsigned int fourcc = VA_FOURCC_YV12;
4302 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4303 int sampling = get_sampling_from_fourcc(fourcc);
4304 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4305 if (va_status != VA_STATUS_SUCCESS)
4309 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4311 w_pitch = obj_surface->width;
4313 image_id = NEW_IMAGE_ID();
4315 if (image_id == VA_INVALID_ID)
4316 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4318 obj_image = IMAGE(image_id);
4321 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4323 obj_image->bo = NULL;
4324 obj_image->palette = NULL;
4325 obj_image->derived_surface = VA_INVALID_ID;
4327 VAImage * const image = &obj_image->image;
4329 memset(image, 0, sizeof(*image));
4330 image->image_id = image_id;
4331 image->buf = VA_INVALID_ID;
4332 image->num_palette_entries = 0;
4333 image->entry_bytes = 0;
4334 image->width = obj_surface->orig_width;
4335 image->height = obj_surface->orig_height;
4336 image->data_size = obj_surface->size;
4338 image->format.fourcc = obj_surface->fourcc;
4339 image->format.byte_order = VA_LSB_FIRST;
4340 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4342 if (!image->format.bits_per_pixel)
4345 switch (image->format.fourcc) {
4346 case VA_FOURCC_YV12:
4347 image->num_planes = 3;
4348 image->pitches[0] = w_pitch; /* Y */
4349 image->offsets[0] = 0;
4350 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4351 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4352 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4353 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4356 case VA_FOURCC_YV16:
4357 image->num_planes = 3;
4358 image->pitches[0] = w_pitch; /* Y */
4359 image->offsets[0] = 0;
4360 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4361 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4362 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4363 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4366 case VA_FOURCC_NV12:
4367 case VA_FOURCC_P010:
4368 image->num_planes = 2;
4369 image->pitches[0] = w_pitch; /* Y */
4370 image->offsets[0] = 0;
4371 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4372 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4375 case VA_FOURCC_I420:
4376 case VA_FOURCC_I010:
4377 case VA_FOURCC_422H:
4378 case VA_FOURCC_IMC3:
4379 case VA_FOURCC_444P:
4380 case VA_FOURCC_422V:
4381 case VA_FOURCC_411P:
4382 image->num_planes = 3;
4383 image->pitches[0] = w_pitch; /* Y */
4384 image->offsets[0] = 0;
4385 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4386 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4387 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4388 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4391 case VA_FOURCC_YUY2:
4392 case VA_FOURCC_UYVY:
4393 case VA_FOURCC_Y800:
4394 image->num_planes = 1;
4395 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4396 image->offsets[0] = 0;
4398 case VA_FOURCC_RGBA:
4399 case VA_FOURCC_RGBX:
4400 case VA_FOURCC_BGRA:
4401 case VA_FOURCC_BGRX:
4402 image->num_planes = 1;
4403 image->pitches[0] = obj_surface->width;
4405 switch (image->format.fourcc) {
4406 case VA_FOURCC_RGBA:
4407 case VA_FOURCC_RGBX:
4408 image->format.red_mask = 0x000000ff;
4409 image->format.green_mask = 0x0000ff00;
4410 image->format.blue_mask = 0x00ff0000;
4412 case VA_FOURCC_BGRA:
4413 case VA_FOURCC_BGRX:
4414 image->format.red_mask = 0x00ff0000;
4415 image->format.green_mask = 0x0000ff00;
4416 image->format.blue_mask = 0x000000ff;
4422 switch (image->format.fourcc) {
4423 case VA_FOURCC_RGBA:
4424 case VA_FOURCC_BGRA:
4425 image->format.alpha_mask = 0xff000000;
4426 image->format.depth = 32;
4428 case VA_FOURCC_RGBX:
4429 case VA_FOURCC_BGRX:
4430 image->format.alpha_mask = 0x00000000;
4431 image->format.depth = 24;
4442 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4443 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4444 if (va_status != VA_STATUS_SUCCESS)
4447 struct object_buffer *obj_buffer = BUFFER(image->buf);
4450 !obj_buffer->buffer_store ||
4451 !obj_buffer->buffer_store->bo)
4452 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4454 obj_image->bo = obj_buffer->buffer_store->bo;
4455 dri_bo_reference(obj_image->bo);
4457 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4458 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4459 if (!obj_image->palette) {
4460 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4465 *out_image = *image;
4466 obj_surface->flags |= SURFACE_DERIVED;
4467 obj_surface->derived_image_id = image_id;
4468 obj_image->derived_surface = surface;
4470 return VA_STATUS_SUCCESS;
4473 i965_DestroyImage(ctx, image_id);
4478 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4480 object_heap_free(heap, obj);
4485 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4487 struct i965_driver_data *i965 = i965_driver_data(ctx);
4488 struct object_image *obj_image = IMAGE(image);
4489 struct object_surface *obj_surface;
4492 return VA_STATUS_SUCCESS;
4494 dri_bo_unreference(obj_image->bo);
4495 obj_image->bo = NULL;
4497 if (obj_image->image.buf != VA_INVALID_ID) {
4498 i965_DestroyBuffer(ctx, obj_image->image.buf);
4499 obj_image->image.buf = VA_INVALID_ID;
4502 if (obj_image->palette) {
4503 free(obj_image->palette);
4504 obj_image->palette = NULL;
4507 obj_surface = SURFACE(obj_image->derived_surface);
4510 obj_surface->flags &= ~SURFACE_DERIVED;
4511 obj_surface->derived_image_id = VA_INVALID_ID;
4514 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4516 return VA_STATUS_SUCCESS;
4520 * pointer to an array holding the palette data. The size of the array is
4521 * num_palette_entries * entry_bytes in size. The order of the components
4522 * in the palette is described by the component_order in VASubpicture struct
4525 i965_SetImagePalette(VADriverContextP ctx,
4527 unsigned char *palette)
4529 struct i965_driver_data *i965 = i965_driver_data(ctx);
4532 struct object_image *obj_image = IMAGE(image);
4534 return VA_STATUS_ERROR_INVALID_IMAGE;
4536 if (!obj_image->palette)
4537 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4539 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4540 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
4541 ((unsigned int)palette[3*i + 1] << 8) |
4542 (unsigned int)palette[3*i + 2]);
4543 return VA_STATUS_SUCCESS;
4547 get_sampling_from_fourcc(unsigned int fourcc)
4549 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4551 if (info && (info->flag & I_S))
4552 return info->subsampling;
4558 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4559 const uint8_t *src, unsigned int src_stride,
4560 unsigned int len, unsigned int height)
4564 for (i = 0; i < height; i++) {
4565 memcpy(dst, src, len);
4572 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4573 struct object_surface *obj_surface,
4574 const VARectangle *rect)
4576 uint8_t *dst[3], *src[3];
4578 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4579 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4580 unsigned int tiling, swizzle;
4581 VAStatus va_status = VA_STATUS_SUCCESS;
4583 if (!obj_surface->bo)
4584 return VA_STATUS_ERROR_INVALID_SURFACE;
4586 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4587 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4589 if (tiling != I915_TILING_NONE)
4590 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4592 dri_bo_map(obj_surface->bo, 0);
4594 if (!obj_surface->bo->virtual)
4595 return VA_STATUS_ERROR_INVALID_SURFACE;
4597 /* Dest VA image has either I420 or YV12 format.
4598 Source VA surface alway has I420 format */
4599 dst[Y] = image_data + obj_image->image.offsets[Y];
4600 src[0] = (uint8_t *)obj_surface->bo->virtual;
4601 dst[U] = image_data + obj_image->image.offsets[U];
4602 src[1] = src[0] + obj_surface->width * obj_surface->height;
4603 dst[V] = image_data + obj_image->image.offsets[V];
4604 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4607 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4608 src[0] += rect->y * obj_surface->width + rect->x;
4609 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4610 src[0], obj_surface->width,
4611 rect->width, rect->height);
4614 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4615 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4616 memcpy_pic(dst[U], obj_image->image.pitches[U],
4617 src[1], obj_surface->width / 2,
4618 rect->width / 2, rect->height / 2);
4621 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4622 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4623 memcpy_pic(dst[V], obj_image->image.pitches[V],
4624 src[2], obj_surface->width / 2,
4625 rect->width / 2, rect->height / 2);
4627 if (tiling != I915_TILING_NONE)
4628 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4630 dri_bo_unmap(obj_surface->bo);
4636 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4637 struct object_surface *obj_surface,
4638 const VARectangle *rect)
4640 uint8_t *dst[2], *src[2];
4641 unsigned int tiling, swizzle;
4642 VAStatus va_status = VA_STATUS_SUCCESS;
4644 if (!obj_surface->bo)
4645 return VA_STATUS_ERROR_INVALID_SURFACE;
4647 assert(obj_surface->fourcc);
4648 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4650 if (tiling != I915_TILING_NONE)
4651 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4653 dri_bo_map(obj_surface->bo, 0);
4655 if (!obj_surface->bo->virtual)
4656 return VA_STATUS_ERROR_INVALID_SURFACE;
4658 /* Both dest VA image and source surface have NV12 format */
4659 dst[0] = image_data + obj_image->image.offsets[0];
4660 src[0] = (uint8_t *)obj_surface->bo->virtual;
4661 dst[1] = image_data + obj_image->image.offsets[1];
4662 src[1] = src[0] + obj_surface->width * obj_surface->height;
4665 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4666 src[0] += rect->y * obj_surface->width + rect->x;
4667 memcpy_pic(dst[0], obj_image->image.pitches[0],
4668 src[0], obj_surface->width,
4669 rect->width, rect->height);
4672 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4673 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4674 memcpy_pic(dst[1], obj_image->image.pitches[1],
4675 src[1], obj_surface->width,
4676 rect->width, rect->height / 2);
4678 if (tiling != I915_TILING_NONE)
4679 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4681 dri_bo_unmap(obj_surface->bo);
4687 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4688 struct object_surface *obj_surface,
4689 const VARectangle *rect)
4692 unsigned int tiling, swizzle;
4693 VAStatus va_status = VA_STATUS_SUCCESS;
4695 if (!obj_surface->bo)
4696 return VA_STATUS_ERROR_INVALID_SURFACE;
4698 assert(obj_surface->fourcc);
4699 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4701 if (tiling != I915_TILING_NONE)
4702 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4704 dri_bo_map(obj_surface->bo, 0);
4706 if (!obj_surface->bo->virtual)
4707 return VA_STATUS_ERROR_INVALID_SURFACE;
4709 /* Both dest VA image and source surface have YUYV format */
4710 dst = image_data + obj_image->image.offsets[0];
4711 src = (uint8_t *)obj_surface->bo->virtual;
4714 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
4715 src += rect->y * obj_surface->width + rect->x*2;
4716 memcpy_pic(dst, obj_image->image.pitches[0],
4717 src, obj_surface->width*2,
4718 rect->width*2, rect->height);
4720 if (tiling != I915_TILING_NONE)
4721 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4723 dri_bo_unmap(obj_surface->bo);
4729 i965_sw_getimage(VADriverContextP ctx,
4730 struct object_surface *obj_surface, struct object_image *obj_image,
4731 const VARectangle *rect)
4733 void *image_data = NULL;
4736 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4737 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4739 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4740 if (va_status != VA_STATUS_SUCCESS)
4743 switch (obj_image->image.format.fourcc) {
4744 case VA_FOURCC_YV12:
4745 case VA_FOURCC_I420:
4746 get_image_i420(obj_image, image_data, obj_surface, rect);
4748 case VA_FOURCC_NV12:
4749 get_image_nv12(obj_image, image_data, obj_surface, rect);
4751 case VA_FOURCC_YUY2:
4752 /* YUY2 is the format supported by overlay plane */
4753 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4756 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4759 if (va_status != VA_STATUS_SUCCESS)
4762 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4767 i965_hw_getimage(VADriverContextP ctx,
4768 struct object_surface *obj_surface, struct object_image *obj_image,
4769 const VARectangle *rect)
4771 struct i965_surface src_surface;
4772 struct i965_surface dst_surface;
4774 src_surface.base = (struct object_base *)obj_surface;
4775 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4776 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4778 dst_surface.base = (struct object_base *)obj_image;
4779 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4780 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4782 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4786 i965_GetImage(VADriverContextP ctx,
4787 VASurfaceID surface,
4788 int x, /* coordinates of the upper left source pixel */
4790 unsigned int width, /* width and height of the region */
4791 unsigned int height,
4794 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4795 struct object_surface * const obj_surface = SURFACE(surface);
4796 struct object_image * const obj_image = IMAGE(image);
4801 return VA_STATUS_ERROR_INVALID_SURFACE;
4802 if (!obj_surface->bo) /* don't get anything, keep previous data */
4803 return VA_STATUS_SUCCESS;
4804 if (is_surface_busy(i965, obj_surface))
4805 return VA_STATUS_ERROR_SURFACE_BUSY;
4807 if (!obj_image || !obj_image->bo)
4808 return VA_STATUS_ERROR_INVALID_IMAGE;
4809 if (is_image_busy(i965, obj_image, surface))
4810 return VA_STATUS_ERROR_SURFACE_BUSY;
4813 return VA_STATUS_ERROR_INVALID_PARAMETER;
4814 if (x + width > obj_surface->orig_width ||
4815 y + height > obj_surface->orig_height)
4816 return VA_STATUS_ERROR_INVALID_PARAMETER;
4817 if (x + width > obj_image->image.width ||
4818 y + height > obj_image->image.height)
4819 return VA_STATUS_ERROR_INVALID_PARAMETER;
4824 rect.height = height;
4826 if (HAS_ACCELERATED_GETIMAGE(i965))
4827 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
4829 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
4835 put_image_i420(struct object_surface *obj_surface,
4836 const VARectangle *dst_rect,
4837 struct object_image *obj_image, uint8_t *image_data,
4838 const VARectangle *src_rect)
4840 uint8_t *dst[3], *src[3];
4842 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4843 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4844 unsigned int tiling, swizzle;
4845 VAStatus va_status = VA_STATUS_SUCCESS;
4847 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4849 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4850 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4851 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4852 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4854 if (tiling != I915_TILING_NONE)
4855 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4857 dri_bo_map(obj_surface->bo, 0);
4859 if (!obj_surface->bo->virtual)
4860 return VA_STATUS_ERROR_INVALID_SURFACE;
4862 /* Dest VA image has either I420 or YV12 format.
4863 Source VA surface alway has I420 format */
4864 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4865 src[Y] = image_data + obj_image->image.offsets[Y];
4866 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4867 src[U] = image_data + obj_image->image.offsets[U];
4868 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4869 src[V] = image_data + obj_image->image.offsets[V];
4872 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4873 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4874 memcpy_pic(dst[0], obj_surface->width,
4875 src[Y], obj_image->image.pitches[Y],
4876 src_rect->width, src_rect->height);
4879 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4880 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4881 memcpy_pic(dst[1], obj_surface->width / 2,
4882 src[U], obj_image->image.pitches[U],
4883 src_rect->width / 2, src_rect->height / 2);
4886 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4887 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4888 memcpy_pic(dst[2], obj_surface->width / 2,
4889 src[V], obj_image->image.pitches[V],
4890 src_rect->width / 2, src_rect->height / 2);
4892 if (tiling != I915_TILING_NONE)
4893 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4895 dri_bo_unmap(obj_surface->bo);
4901 put_image_nv12(struct object_surface *obj_surface,
4902 const VARectangle *dst_rect,
4903 struct object_image *obj_image, uint8_t *image_data,
4904 const VARectangle *src_rect)
4906 uint8_t *dst[2], *src[2];
4907 unsigned int tiling, swizzle;
4908 VAStatus va_status = VA_STATUS_SUCCESS;
4910 if (!obj_surface->bo)
4911 return VA_STATUS_ERROR_INVALID_SURFACE;
4913 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4914 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4915 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4916 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4918 if (tiling != I915_TILING_NONE)
4919 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4921 dri_bo_map(obj_surface->bo, 0);
4923 if (!obj_surface->bo->virtual)
4924 return VA_STATUS_ERROR_INVALID_SURFACE;
4926 /* Both dest VA image and source surface have NV12 format */
4927 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4928 src[0] = image_data + obj_image->image.offsets[0];
4929 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4930 src[1] = image_data + obj_image->image.offsets[1];
4933 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4934 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
4935 memcpy_pic(dst[0], obj_surface->width,
4936 src[0], obj_image->image.pitches[0],
4937 src_rect->width, src_rect->height);
4940 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
4941 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
4942 memcpy_pic(dst[1], obj_surface->width,
4943 src[1], obj_image->image.pitches[1],
4944 src_rect->width, src_rect->height / 2);
4946 if (tiling != I915_TILING_NONE)
4947 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4949 dri_bo_unmap(obj_surface->bo);
4955 put_image_yuy2(struct object_surface *obj_surface,
4956 const VARectangle *dst_rect,
4957 struct object_image *obj_image, uint8_t *image_data,
4958 const VARectangle *src_rect)
4961 unsigned int tiling, swizzle;
4962 VAStatus va_status = VA_STATUS_SUCCESS;
4964 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4965 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4966 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4967 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4968 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4970 if (tiling != I915_TILING_NONE)
4971 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4973 dri_bo_map(obj_surface->bo, 0);
4975 if (!obj_surface->bo->virtual)
4976 return VA_STATUS_ERROR_INVALID_SURFACE;
4978 /* Both dest VA image and source surface have YUY2 format */
4979 dst = (uint8_t *)obj_surface->bo->virtual;
4980 src = image_data + obj_image->image.offsets[0];
4982 /* YUYV packed plane */
4983 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
4984 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
4985 memcpy_pic(dst, obj_surface->width*2,
4986 src, obj_image->image.pitches[0],
4987 src_rect->width*2, src_rect->height);
4989 if (tiling != I915_TILING_NONE)
4990 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4992 dri_bo_unmap(obj_surface->bo);
4998 i965_sw_putimage(VADriverContextP ctx,
4999 struct object_surface *obj_surface, struct object_image *obj_image,
5000 const VARectangle *src_rect, const VARectangle *dst_rect)
5002 VAStatus va_status = VA_STATUS_SUCCESS;
5003 void *image_data = NULL;
5005 /* XXX: don't allow scaling */
5006 if (src_rect->width != dst_rect->width ||
5007 src_rect->height != dst_rect->height)
5008 return VA_STATUS_ERROR_INVALID_PARAMETER;
5010 if (obj_surface->fourcc) {
5011 /* Don't allow format mismatch */
5012 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5013 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5017 /* VA is surface not used for decoding, use same VA image format */
5018 va_status = i965_check_alloc_surface_bo(
5021 0, /* XXX: don't use tiled surface */
5022 obj_image->image.format.fourcc,
5023 get_sampling_from_fourcc (obj_image->image.format.fourcc));
5026 if (va_status != VA_STATUS_SUCCESS)
5029 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5030 if (va_status != VA_STATUS_SUCCESS)
5033 switch (obj_image->image.format.fourcc) {
5034 case VA_FOURCC_YV12:
5035 case VA_FOURCC_I420:
5036 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5038 case VA_FOURCC_NV12:
5039 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5041 case VA_FOURCC_YUY2:
5042 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5045 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5048 if (va_status != VA_STATUS_SUCCESS)
5051 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5056 i965_hw_putimage(VADriverContextP ctx,
5057 struct object_surface *obj_surface, struct object_image *obj_image,
5058 const VARectangle *src_rect, const VARectangle *dst_rect)
5060 struct i965_surface src_surface, dst_surface;
5061 VAStatus va_status = VA_STATUS_SUCCESS;
5063 if (!obj_surface->bo) {
5064 unsigned int tiling, swizzle;
5065 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
5066 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5068 i965_check_alloc_surface_bo(ctx,
5071 obj_image->image.format.fourcc,
5075 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5077 src_surface.base = (struct object_base *)obj_image;
5078 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5079 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5081 dst_surface.base = (struct object_base *)obj_surface;
5082 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5083 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5085 va_status = i965_image_processing(ctx,
5095 i965_PutImage(VADriverContextP ctx,
5096 VASurfaceID surface,
5100 unsigned int src_width,
5101 unsigned int src_height,
5104 unsigned int dest_width,
5105 unsigned int dest_height)
5107 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5108 struct object_surface * const obj_surface = SURFACE(surface);
5109 struct object_image * const obj_image = IMAGE(image);
5110 VARectangle src_rect, dst_rect;
5114 return VA_STATUS_ERROR_INVALID_SURFACE;
5115 if (is_surface_busy(i965, obj_surface))
5116 return VA_STATUS_ERROR_SURFACE_BUSY;
5118 if (!obj_image || !obj_image->bo)
5119 return VA_STATUS_ERROR_INVALID_IMAGE;
5120 if (is_image_busy(i965, obj_image, surface))
5121 return VA_STATUS_ERROR_SURFACE_BUSY;
5125 src_x + src_width > obj_image->image.width ||
5126 src_y + src_height > obj_image->image.height)
5127 return VA_STATUS_ERROR_INVALID_PARAMETER;
5131 src_rect.width = src_width;
5132 src_rect.height = src_height;
5136 dest_x + dest_width > obj_surface->orig_width ||
5137 dest_y + dest_height > obj_surface->orig_height)
5138 return VA_STATUS_ERROR_INVALID_PARAMETER;
5140 dst_rect.x = dest_x;
5141 dst_rect.y = dest_y;
5142 dst_rect.width = dest_width;
5143 dst_rect.height = dest_height;
5145 if (HAS_ACCELERATED_PUTIMAGE(i965))
5146 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5147 &src_rect, &dst_rect);
5149 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5150 &src_rect, &dst_rect);
5156 i965_PutSurface(VADriverContextP ctx,
5157 VASurfaceID surface,
5158 void *draw, /* X Drawable */
5161 unsigned short srcw,
5162 unsigned short srch,
5165 unsigned short destw,
5166 unsigned short desth,
5167 VARectangle *cliprects, /* client supplied clip list */
5168 unsigned int number_cliprects, /* number of clip rects in the clip list */
5169 unsigned int flags) /* de-interlacing flags */
5172 if (IS_VA_X11(ctx)) {
5173 VARectangle src_rect, dst_rect;
5177 src_rect.width = srcw;
5178 src_rect.height = srch;
5182 dst_rect.width = destw;
5183 dst_rect.height = desth;
5185 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5186 cliprects, number_cliprects, flags);
5189 return VA_STATUS_ERROR_UNIMPLEMENTED;
5194 VADriverContextP ctx, /* in */
5195 VABufferID buf_id, /* in */
5196 VABufferType *type, /* out */
5197 unsigned int *size, /* out */
5198 unsigned int *num_elements /* out */
5201 struct i965_driver_data *i965 = NULL;
5202 struct object_buffer *obj_buffer = NULL;
5204 i965 = i965_driver_data(ctx);
5205 obj_buffer = BUFFER(buf_id);
5207 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5209 *type = obj_buffer->type;
5210 *size = obj_buffer->size_element;
5211 *num_elements = obj_buffer->num_elements;
5213 return VA_STATUS_SUCCESS;
5218 VADriverContextP ctx, /* in */
5219 VASurfaceID surface, /* in */
5220 unsigned int *fourcc, /* out */
5221 unsigned int *luma_stride, /* out */
5222 unsigned int *chroma_u_stride, /* out */
5223 unsigned int *chroma_v_stride, /* out */
5224 unsigned int *luma_offset, /* out */
5225 unsigned int *chroma_u_offset, /* out */
5226 unsigned int *chroma_v_offset, /* out */
5227 unsigned int *buffer_name, /* out */
5228 void **buffer /* out */
5231 VAStatus vaStatus = VA_STATUS_SUCCESS;
5232 struct i965_driver_data *i965 = i965_driver_data(ctx);
5233 struct object_surface *obj_surface = NULL;
5236 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5237 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5238 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5239 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5240 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5241 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5242 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5243 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5244 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5246 tmpImage.image_id = VA_INVALID_ID;
5248 obj_surface = SURFACE(surface);
5249 if (obj_surface == NULL) {
5250 // Surface is absent.
5251 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5255 // Lock functionality is absent now.
5256 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5257 // Surface is locked already.
5258 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5262 vaStatus = i965_DeriveImage(
5266 if (vaStatus != VA_STATUS_SUCCESS) {
5270 obj_surface->locked_image_id = tmpImage.image_id;
5272 vaStatus = i965_MapBuffer(
5276 if (vaStatus != VA_STATUS_SUCCESS) {
5280 *fourcc = tmpImage.format.fourcc;
5281 *luma_offset = tmpImage.offsets[0];
5282 *luma_stride = tmpImage.pitches[0];
5283 *chroma_u_offset = tmpImage.offsets[1];
5284 *chroma_u_stride = tmpImage.pitches[1];
5285 *chroma_v_offset = tmpImage.offsets[2];
5286 *chroma_v_stride = tmpImage.pitches[2];
5287 *buffer_name = tmpImage.buf;
5290 if (vaStatus != VA_STATUS_SUCCESS) {
5299 VADriverContextP ctx, /* in */
5300 VASurfaceID surface /* in */
5303 VAStatus vaStatus = VA_STATUS_SUCCESS;
5304 struct i965_driver_data *i965 = i965_driver_data(ctx);
5305 struct object_image *locked_img = NULL;
5306 struct object_surface *obj_surface = NULL;
5308 obj_surface = SURFACE(surface);
5310 if (obj_surface == NULL) {
5311 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5314 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5315 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5319 locked_img = IMAGE(obj_surface->locked_image_id);
5320 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5321 // Work image was deallocated before i965_UnlockSurface()
5322 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5326 vaStatus = i965_UnmapBuffer(
5328 locked_img->image.buf);
5329 if (vaStatus != VA_STATUS_SUCCESS) {
5333 vaStatus = i965_DestroyImage(
5335 locked_img->image.image_id);
5336 if (vaStatus != VA_STATUS_SUCCESS) {
5340 locked_img->image.image_id = VA_INVALID_ID;
5343 obj_surface->locked_image_id = VA_INVALID_ID;
5349 i965_GetSurfaceAttributes(
5350 VADriverContextP ctx,
5352 VASurfaceAttrib *attrib_list,
5353 unsigned int num_attribs
5356 VAStatus vaStatus = VA_STATUS_SUCCESS;
5357 struct i965_driver_data *i965 = i965_driver_data(ctx);
5358 struct object_config *obj_config;
5361 if (config == VA_INVALID_ID)
5362 return VA_STATUS_ERROR_INVALID_CONFIG;
5364 obj_config = CONFIG(config);
5366 if (obj_config == NULL)
5367 return VA_STATUS_ERROR_INVALID_CONFIG;
5369 if (attrib_list == NULL || num_attribs == 0)
5370 return VA_STATUS_ERROR_INVALID_PARAMETER;
5372 for (i = 0; i < num_attribs; i++) {
5373 switch (attrib_list[i].type) {
5374 case VASurfaceAttribPixelFormat:
5375 attrib_list[i].value.type = VAGenericValueTypeInteger;
5376 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5378 if (attrib_list[i].value.value.i == 0) {
5379 if (IS_G4X(i965->intel.device_info)) {
5380 if (obj_config->profile == VAProfileMPEG2Simple ||
5381 obj_config->profile == VAProfileMPEG2Main) {
5382 attrib_list[i].value.value.i = VA_FOURCC_I420;
5385 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5387 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5388 if (obj_config->profile == VAProfileMPEG2Simple ||
5389 obj_config->profile == VAProfileMPEG2Main) {
5390 attrib_list[i].value.value.i = VA_FOURCC_I420;
5391 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5392 obj_config->profile == VAProfileH264Main ||
5393 obj_config->profile == VAProfileH264High) {
5394 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5395 } else if (obj_config->profile == VAProfileNone) {
5396 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5399 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5401 } else if (IS_GEN6(i965->intel.device_info)) {
5402 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5403 } else if (IS_GEN7(i965->intel.device_info) ||
5404 IS_GEN8(i965->intel.device_info) ||
5405 IS_GEN9(i965->intel.device_info)) {
5406 if (obj_config->profile == VAProfileJPEGBaseline)
5407 attrib_list[i].value.value.i = 0; /* internal format */
5409 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5412 if (IS_G4X(i965->intel.device_info)) {
5413 if (obj_config->profile == VAProfileMPEG2Simple ||
5414 obj_config->profile == VAProfileMPEG2Main) {
5415 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5416 attrib_list[i].value.value.i = 0;
5417 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5421 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5423 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5424 if (obj_config->profile == VAProfileMPEG2Simple ||
5425 obj_config->profile == VAProfileMPEG2Main) {
5426 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5427 attrib_list[i].value.value.i = 0;
5428 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5430 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5431 obj_config->profile == VAProfileH264Main ||
5432 obj_config->profile == VAProfileH264High) {
5433 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5434 attrib_list[i].value.value.i = 0;
5435 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5437 } else if (obj_config->profile == VAProfileNone) {
5438 switch (attrib_list[i].value.value.i) {
5439 case VA_FOURCC_NV12:
5440 case VA_FOURCC_I420:
5441 case VA_FOURCC_YV12:
5442 case VA_FOURCC_YUY2:
5443 case VA_FOURCC_BGRA:
5444 case VA_FOURCC_BGRX:
5445 case VA_FOURCC_RGBX:
5446 case VA_FOURCC_RGBA:
5449 attrib_list[i].value.value.i = 0;
5450 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5455 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5457 } else if (IS_GEN6(i965->intel.device_info)) {
5458 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5459 obj_config->entrypoint == VAEntrypointVideoProc) {
5460 switch (attrib_list[i].value.value.i) {
5461 case VA_FOURCC_NV12:
5462 case VA_FOURCC_I420:
5463 case VA_FOURCC_YV12:
5464 case VA_FOURCC_YUY2:
5465 case VA_FOURCC_BGRA:
5466 case VA_FOURCC_BGRX:
5467 case VA_FOURCC_RGBX:
5468 case VA_FOURCC_RGBA:
5471 attrib_list[i].value.value.i = 0;
5472 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5476 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5477 attrib_list[i].value.value.i = 0;
5478 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5481 } else if (IS_GEN7(i965->intel.device_info) ||
5482 IS_GEN8(i965->intel.device_info) ||
5483 IS_GEN9(i965->intel.device_info)) {
5484 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5485 obj_config->entrypoint == VAEntrypointVideoProc ||
5486 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5487 switch (attrib_list[i].value.value.i) {
5488 case VA_FOURCC_NV12:
5489 case VA_FOURCC_I420:
5490 case VA_FOURCC_YV12:
5493 attrib_list[i].value.value.i = 0;
5494 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5498 if (obj_config->profile == VAProfileJPEGBaseline) {
5499 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5500 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5502 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5503 attrib_list[i].value.value.i = 0;
5504 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5512 case VASurfaceAttribMinWidth:
5513 /* FIXME: add support for it later */
5514 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5516 case VASurfaceAttribMaxWidth:
5517 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5519 case VASurfaceAttribMinHeight:
5520 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5522 case VASurfaceAttribMaxHeight:
5523 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5526 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5535 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5537 VASurfaceAttrib *attrib_list,
5538 unsigned int *num_attribs)
5540 VAStatus vaStatus = VA_STATUS_SUCCESS;
5541 struct i965_driver_data *i965 = i965_driver_data(ctx);
5542 struct object_config *obj_config;
5544 VASurfaceAttrib *attribs = NULL;
5548 if (config == VA_INVALID_ID)
5549 return VA_STATUS_ERROR_INVALID_CONFIG;
5551 obj_config = CONFIG(config);
5553 if (obj_config == NULL)
5554 return VA_STATUS_ERROR_INVALID_CONFIG;
5556 if (!attrib_list && !num_attribs)
5557 return VA_STATUS_ERROR_INVALID_PARAMETER;
5559 if (attrib_list == NULL) {
5560 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5561 return VA_STATUS_SUCCESS;
5564 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
5566 if (attribs == NULL)
5567 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5569 if (IS_G4X(i965->intel.device_info)) {
5570 if (obj_config->profile == VAProfileMPEG2Simple ||
5571 obj_config->profile == VAProfileMPEG2Main) {
5572 attribs[i].type = VASurfaceAttribPixelFormat;
5573 attribs[i].value.type = VAGenericValueTypeInteger;
5574 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5575 attribs[i].value.value.i = VA_FOURCC_I420;
5578 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5579 switch (obj_config->profile) {
5580 case VAProfileMPEG2Simple:
5581 case VAProfileMPEG2Main:
5582 attribs[i].type = VASurfaceAttribPixelFormat;
5583 attribs[i].value.type = VAGenericValueTypeInteger;
5584 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5585 attribs[i].value.value.i = VA_FOURCC_I420;
5590 case VAProfileH264ConstrainedBaseline:
5591 case VAProfileH264Main:
5592 case VAProfileH264High:
5593 attribs[i].type = VASurfaceAttribPixelFormat;
5594 attribs[i].value.type = VAGenericValueTypeInteger;
5595 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5596 attribs[i].value.value.i = VA_FOURCC_NV12;
5600 attribs[i].type = VASurfaceAttribPixelFormat;
5601 attribs[i].value.type = VAGenericValueTypeInteger;
5602 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5603 attribs[i].value.value.i = VA_FOURCC_NV12;
5606 attribs[i].type = VASurfaceAttribPixelFormat;
5607 attribs[i].value.type = VAGenericValueTypeInteger;
5608 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5609 attribs[i].value.value.i = VA_FOURCC_I420;
5617 } else if (IS_GEN6(i965->intel.device_info)) {
5618 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5619 attribs[i].type = VASurfaceAttribPixelFormat;
5620 attribs[i].value.type = VAGenericValueTypeInteger;
5621 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5622 attribs[i].value.value.i = VA_FOURCC_NV12;
5624 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5625 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5626 attribs[i].type = VASurfaceAttribPixelFormat;
5627 attribs[i].value.type = VAGenericValueTypeInteger;
5628 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5629 attribs[i].value.value.i = VA_FOURCC_NV12;
5632 attribs[i].type = VASurfaceAttribPixelFormat;
5633 attribs[i].value.type = VAGenericValueTypeInteger;
5634 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5635 attribs[i].value.value.i = VA_FOURCC_I420;
5638 attribs[i].type = VASurfaceAttribPixelFormat;
5639 attribs[i].value.type = VAGenericValueTypeInteger;
5640 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5641 attribs[i].value.value.i = VA_FOURCC_YV12;
5644 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5645 attribs[i].type = VASurfaceAttribPixelFormat;
5646 attribs[i].value.type = VAGenericValueTypeInteger;
5647 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5648 attribs[i].value.value.i = VA_FOURCC_YUY2;
5651 attribs[i].type = VASurfaceAttribPixelFormat;
5652 attribs[i].value.type = VAGenericValueTypeInteger;
5653 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5654 attribs[i].value.value.i = VA_FOURCC_RGBA;
5657 attribs[i].type = VASurfaceAttribPixelFormat;
5658 attribs[i].value.type = VAGenericValueTypeInteger;
5659 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5660 attribs[i].value.value.i = VA_FOURCC_RGBX;
5664 } else if (IS_GEN7(i965->intel.device_info)) {
5665 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5666 if (obj_config->profile == VAProfileJPEGBaseline) {
5667 attribs[i].type = VASurfaceAttribPixelFormat;
5668 attribs[i].value.type = VAGenericValueTypeInteger;
5669 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5670 attribs[i].value.value.i = VA_FOURCC_IMC3;
5673 attribs[i].type = VASurfaceAttribPixelFormat;
5674 attribs[i].value.type = VAGenericValueTypeInteger;
5675 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5676 attribs[i].value.value.i = VA_FOURCC_IMC1;
5679 attribs[i].type = VASurfaceAttribPixelFormat;
5680 attribs[i].value.type = VAGenericValueTypeInteger;
5681 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5682 attribs[i].value.value.i = VA_FOURCC_Y800;
5685 attribs[i].type = VASurfaceAttribPixelFormat;
5686 attribs[i].value.type = VAGenericValueTypeInteger;
5687 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5688 attribs[i].value.value.i = VA_FOURCC_411P;
5691 attribs[i].type = VASurfaceAttribPixelFormat;
5692 attribs[i].value.type = VAGenericValueTypeInteger;
5693 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5694 attribs[i].value.value.i = VA_FOURCC_422H;
5697 attribs[i].type = VASurfaceAttribPixelFormat;
5698 attribs[i].value.type = VAGenericValueTypeInteger;
5699 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5700 attribs[i].value.value.i = VA_FOURCC_422V;
5703 attribs[i].type = VASurfaceAttribPixelFormat;
5704 attribs[i].value.type = VAGenericValueTypeInteger;
5705 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5706 attribs[i].value.value.i = VA_FOURCC_444P;
5708 } else if (obj_config->profile == VAProfileHEVCMain10) {
5709 attribs[i].type = VASurfaceAttribPixelFormat;
5710 attribs[i].value.type = VAGenericValueTypeInteger;
5711 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5712 attribs[i].value.value.i = VA_FOURCC_P010;
5715 attribs[i].type = VASurfaceAttribPixelFormat;
5716 attribs[i].value.type = VAGenericValueTypeInteger;
5717 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5718 attribs[i].value.value.i = VA_FOURCC_NV12;
5721 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5722 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5723 attribs[i].type = VASurfaceAttribPixelFormat;
5724 attribs[i].value.type = VAGenericValueTypeInteger;
5725 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5726 attribs[i].value.value.i = VA_FOURCC_NV12;
5729 attribs[i].type = VASurfaceAttribPixelFormat;
5730 attribs[i].value.type = VAGenericValueTypeInteger;
5731 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5732 attribs[i].value.value.i = VA_FOURCC_I420;
5735 attribs[i].type = VASurfaceAttribPixelFormat;
5736 attribs[i].value.type = VAGenericValueTypeInteger;
5737 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5738 attribs[i].value.value.i = VA_FOURCC_YV12;
5741 attribs[i].type = VASurfaceAttribPixelFormat;
5742 attribs[i].value.type = VAGenericValueTypeInteger;
5743 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5744 attribs[i].value.value.i = VA_FOURCC_IMC3;
5747 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5748 attribs[i].type = VASurfaceAttribPixelFormat;
5749 attribs[i].value.type = VAGenericValueTypeInteger;
5750 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5751 attribs[i].value.value.i = VA_FOURCC_YUY2;
5754 attribs[i].type = VASurfaceAttribPixelFormat;
5755 attribs[i].value.type = VAGenericValueTypeInteger;
5756 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5757 attribs[i].value.value.i = VA_FOURCC_RGBA;
5760 attribs[i].type = VASurfaceAttribPixelFormat;
5761 attribs[i].value.type = VAGenericValueTypeInteger;
5762 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5763 attribs[i].value.value.i = VA_FOURCC_RGBX;
5766 attribs[i].type = VASurfaceAttribPixelFormat;
5767 attribs[i].value.type = VAGenericValueTypeInteger;
5768 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5769 attribs[i].value.value.i = VA_FOURCC_BGRA;
5772 attribs[i].type = VASurfaceAttribPixelFormat;
5773 attribs[i].value.type = VAGenericValueTypeInteger;
5774 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5775 attribs[i].value.value.i = VA_FOURCC_BGRX;
5778 attribs[i].type = VASurfaceAttribPixelFormat;
5779 attribs[i].value.type = VAGenericValueTypeInteger;
5780 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5781 attribs[i].value.value.i = VA_FOURCC_YV16;
5785 } else if (IS_GEN8(i965->intel.device_info) ||
5786 IS_GEN9(i965->intel.device_info)) {
5787 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5788 if (obj_config->profile == VAProfileJPEGBaseline) {
5789 attribs[i].type = VASurfaceAttribPixelFormat;
5790 attribs[i].value.type = VAGenericValueTypeInteger;
5791 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5792 attribs[i].value.value.i = VA_FOURCC_IMC3;
5795 attribs[i].type = VASurfaceAttribPixelFormat;
5796 attribs[i].value.type = VAGenericValueTypeInteger;
5797 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5798 attribs[i].value.value.i = VA_FOURCC_IMC1;
5801 attribs[i].type = VASurfaceAttribPixelFormat;
5802 attribs[i].value.type = VAGenericValueTypeInteger;
5803 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5804 attribs[i].value.value.i = VA_FOURCC_Y800;
5807 attribs[i].type = VASurfaceAttribPixelFormat;
5808 attribs[i].value.type = VAGenericValueTypeInteger;
5809 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5810 attribs[i].value.value.i = VA_FOURCC_411P;
5813 attribs[i].type = VASurfaceAttribPixelFormat;
5814 attribs[i].value.type = VAGenericValueTypeInteger;
5815 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5816 attribs[i].value.value.i = VA_FOURCC_422H;
5819 attribs[i].type = VASurfaceAttribPixelFormat;
5820 attribs[i].value.type = VAGenericValueTypeInteger;
5821 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5822 attribs[i].value.value.i = VA_FOURCC_422V;
5825 attribs[i].type = VASurfaceAttribPixelFormat;
5826 attribs[i].value.type = VAGenericValueTypeInteger;
5827 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5828 attribs[i].value.value.i = VA_FOURCC_444P;
5831 attribs[i].type = VASurfaceAttribPixelFormat;
5832 attribs[i].value.type = VAGenericValueTypeInteger;
5833 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5834 attribs[i].value.value.i = VA_FOURCC_NV12;
5837 if ((obj_config->profile == VAProfileHEVCMain10) ||
5838 (obj_config->profile == VAProfileVP9Profile2)) {
5839 attribs[i].type = VASurfaceAttribPixelFormat;
5840 attribs[i].value.type = VAGenericValueTypeInteger;
5841 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5842 attribs[i].value.value.i = VA_FOURCC_P010;
5846 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5847 obj_config->entrypoint == VAEntrypointVideoProc ||
5848 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5850 if (obj_config->profile == VAProfileHEVCMain10) {
5851 attribs[i].type = VASurfaceAttribPixelFormat;
5852 attribs[i].value.type = VAGenericValueTypeInteger;
5853 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5854 attribs[i].value.value.i = VA_FOURCC_P010;
5857 attribs[i].type = VASurfaceAttribPixelFormat;
5858 attribs[i].value.type = VAGenericValueTypeInteger;
5859 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5860 attribs[i].value.value.i = VA_FOURCC_NV12;
5863 attribs[i].type = VASurfaceAttribPixelFormat;
5864 attribs[i].value.type = VAGenericValueTypeInteger;
5865 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5866 attribs[i].value.value.i = VA_FOURCC_I420;
5869 attribs[i].type = VASurfaceAttribPixelFormat;
5870 attribs[i].value.type = VAGenericValueTypeInteger;
5871 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5872 attribs[i].value.value.i = VA_FOURCC_YV12;
5875 attribs[i].type = VASurfaceAttribPixelFormat;
5876 attribs[i].value.type = VAGenericValueTypeInteger;
5877 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5878 attribs[i].value.value.i = VA_FOURCC_IMC3;
5882 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5883 attribs[i].type = VASurfaceAttribPixelFormat;
5884 attribs[i].value.type = VAGenericValueTypeInteger;
5885 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5886 attribs[i].value.value.i = VA_FOURCC_YUY2;
5889 attribs[i].type = VASurfaceAttribPixelFormat;
5890 attribs[i].value.type = VAGenericValueTypeInteger;
5891 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5892 attribs[i].value.value.i = VA_FOURCC_RGBA;
5895 attribs[i].type = VASurfaceAttribPixelFormat;
5896 attribs[i].value.type = VAGenericValueTypeInteger;
5897 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5898 attribs[i].value.value.i = VA_FOURCC_RGBX;
5901 attribs[i].type = VASurfaceAttribPixelFormat;
5902 attribs[i].value.type = VAGenericValueTypeInteger;
5903 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5904 attribs[i].value.value.i = VA_FOURCC_BGRA;
5907 attribs[i].type = VASurfaceAttribPixelFormat;
5908 attribs[i].value.type = VAGenericValueTypeInteger;
5909 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5910 attribs[i].value.value.i = VA_FOURCC_BGRX;
5913 attribs[i].type = VASurfaceAttribPixelFormat;
5914 attribs[i].value.type = VAGenericValueTypeInteger;
5915 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5916 attribs[i].value.value.i = VA_FOURCC_YV16;
5919 if(HAS_VPP_P010(i965)) {
5920 attribs[i].type = VASurfaceAttribPixelFormat;
5921 attribs[i].value.type = VAGenericValueTypeInteger;
5922 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5923 attribs[i].value.value.i = VA_FOURCC_P010;
5926 attribs[i].type = VASurfaceAttribPixelFormat;
5927 attribs[i].value.type = VAGenericValueTypeInteger;
5928 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5929 attribs[i].value.value.i = VA_FOURCC_I010;
5936 attribs[i].type = VASurfaceAttribMemoryType;
5937 attribs[i].value.type = VAGenericValueTypeInteger;
5938 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5939 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
5940 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
5941 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
5944 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
5945 attribs[i].value.type = VAGenericValueTypePointer;
5946 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
5947 attribs[i].value.value.p = NULL; /* ignore */
5950 max_resolution(i965, obj_config, &max_width, &max_height);
5952 attribs[i].type = VASurfaceAttribMaxWidth;
5953 attribs[i].value.type = VAGenericValueTypeInteger;
5954 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5955 attribs[i].value.value.i = max_width;
5958 attribs[i].type = VASurfaceAttribMaxHeight;
5959 attribs[i].value.type = VAGenericValueTypeInteger;
5960 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5961 attribs[i].value.value.i = max_height;
5964 if (i > *num_attribs) {
5967 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5971 memcpy(attrib_list, attribs, i * sizeof(*attribs));
5977 /* Acquires buffer handle for external API usage (internal implementation) */
5979 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
5980 uint32_t mem_type, VABufferInfo *out_buf_info)
5982 struct buffer_store *buffer_store;
5984 buffer_store = obj_buffer->buffer_store;
5985 if (!buffer_store || !buffer_store->bo)
5986 return VA_STATUS_ERROR_INVALID_BUFFER;
5988 /* Synchronization point */
5989 drm_intel_bo_wait_rendering(buffer_store->bo);
5991 if (obj_buffer->export_refcount > 0) {
5992 if (obj_buffer->export_state.mem_type != mem_type)
5993 return VA_STATUS_ERROR_INVALID_PARAMETER;
5996 VABufferInfo * const buf_info = &obj_buffer->export_state;
5999 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
6001 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
6002 return VA_STATUS_ERROR_INVALID_BUFFER;
6003 buf_info->handle = name;
6006 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6008 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
6009 return VA_STATUS_ERROR_INVALID_BUFFER;
6010 buf_info->handle = (intptr_t)fd;
6015 buf_info->type = obj_buffer->type;
6016 buf_info->mem_type = mem_type;
6017 buf_info->mem_size =
6018 obj_buffer->num_elements * obj_buffer->size_element;
6021 obj_buffer->export_refcount++;
6022 *out_buf_info = obj_buffer->export_state;
6023 return VA_STATUS_SUCCESS;
6026 /* Releases buffer handle after usage (internal implementation) */
6028 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6030 if (obj_buffer->export_refcount == 0)
6031 return VA_STATUS_ERROR_INVALID_BUFFER;
6033 if (--obj_buffer->export_refcount == 0) {
6034 VABufferInfo * const buf_info = &obj_buffer->export_state;
6036 switch (buf_info->mem_type) {
6037 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6038 close((intptr_t)buf_info->handle);
6042 buf_info->mem_type = 0;
6044 return VA_STATUS_SUCCESS;
6047 /** Acquires buffer handle for external API usage */
6049 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6050 VABufferInfo *buf_info)
6052 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6053 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6054 uint32_t i, mem_type;
6056 /* List of supported memory types, in preferred order */
6057 static const uint32_t mem_types[] = {
6058 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6059 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6064 return VA_STATUS_ERROR_INVALID_BUFFER;
6065 /* XXX: only VA surface|image like buffers are supported for now */
6066 if (obj_buffer->type != VAImageBufferType)
6067 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6070 * As the allocated buffer by calling vaCreateBuffer is related with
6071 * the specific context, it is unnecessary to export it.
6072 * So it is not supported when the buffer is allocated from wrapped
6075 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6076 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6080 return VA_STATUS_ERROR_INVALID_PARAMETER;
6082 if (!buf_info->mem_type)
6083 mem_type = mem_types[0];
6086 for (i = 0; mem_types[i] != 0; i++) {
6087 if (buf_info->mem_type & mem_types[i]) {
6088 mem_type = buf_info->mem_type;
6093 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6095 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6098 /** Releases buffer handle after usage from external API */
6100 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6102 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6103 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6106 return VA_STATUS_ERROR_INVALID_BUFFER;
6108 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6109 return VA_STATUS_ERROR_INVALID_BUFFER;
6112 return i965_release_buffer_handle(obj_buffer);
6116 i965_os_has_ring_support(VADriverContextP ctx,
6119 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6123 return i965->intel.has_bsd;
6126 return i965->intel.has_blt;
6128 case I965_RING_VEBOX:
6129 return i965->intel.has_vebox;
6131 case I965_RING_NULL:
6132 return 1; /* Always support */
6135 /* should never get here */
6144 * Query video processing pipeline
6146 VAStatus i965_QueryVideoProcFilters(
6147 VADriverContextP ctx,
6148 VAContextID context,
6149 VAProcFilterType *filters,
6150 unsigned int *num_filters
6153 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6154 unsigned int i = 0, num = 0;
6156 if (!num_filters || !filters)
6157 return VA_STATUS_ERROR_INVALID_PARAMETER;
6159 for (i = 0; i < i965->codec_info->num_filters; i++) {
6160 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6161 if (num == *num_filters) {
6162 *num_filters = i965->codec_info->num_filters;
6164 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6167 filters[num++] = i965->codec_info->filters[i].type;
6173 return VA_STATUS_SUCCESS;
6176 VAStatus i965_QueryVideoProcFilterCaps(
6177 VADriverContextP ctx,
6178 VAContextID context,
6179 VAProcFilterType type,
6181 unsigned int *num_filter_caps
6185 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6187 if (!filter_caps || !num_filter_caps)
6188 return VA_STATUS_ERROR_INVALID_PARAMETER;
6190 for (i = 0; i < i965->codec_info->num_filters; i++) {
6191 if (type == i965->codec_info->filters[i].type &&
6192 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6196 if (i == i965->codec_info->num_filters)
6197 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6202 case VAProcFilterNoiseReduction:
6203 case VAProcFilterSharpening:
6205 VAProcFilterCap *cap = filter_caps;
6207 if (*num_filter_caps < 1) {
6208 *num_filter_caps = 1;
6209 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6212 cap->range.min_value = 0.0;
6213 cap->range.max_value = 1.0;
6214 cap->range.default_value = 0.5;
6215 cap->range.step = 0.03125; /* 1.0 / 32 */
6221 case VAProcFilterDeinterlacing:
6223 VAProcFilterCapDeinterlacing *cap = filter_caps;
6225 if (*num_filter_caps < VAProcDeinterlacingCount) {
6226 *num_filter_caps = VAProcDeinterlacingCount;
6227 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6230 cap->type = VAProcDeinterlacingBob;
6235 if (i965->codec_info->has_di_motion_adptive) {
6236 cap->type = VAProcDeinterlacingMotionAdaptive;
6241 if (i965->codec_info->has_di_motion_compensated) {
6242 cap->type = VAProcDeinterlacingMotionCompensated;
6250 case VAProcFilterColorBalance:
6252 VAProcFilterCapColorBalance *cap = filter_caps;
6254 if (*num_filter_caps < VAProcColorBalanceCount) {
6255 *num_filter_caps = VAProcColorBalanceCount;
6256 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6259 cap->type = VAProcColorBalanceHue;
6260 cap->range.min_value = -180.0;
6261 cap->range.max_value = 180.0;
6262 cap->range.default_value = 0.0;
6263 cap->range.step = 1.0;
6267 cap->type = VAProcColorBalanceSaturation;
6268 cap->range.min_value = 0.0;
6269 cap->range.max_value = 10.0;
6270 cap->range.default_value = 1.0;
6271 cap->range.step = 0.1;
6275 cap->type = VAProcColorBalanceBrightness;
6276 cap->range.min_value = -100.0;
6277 cap->range.max_value = 100.0;
6278 cap->range.default_value = 0.0;
6279 cap->range.step = 1.0;
6283 cap->type = VAProcColorBalanceContrast;
6284 cap->range.min_value = 0.0;
6285 cap->range.max_value = 10.0;
6286 cap->range.default_value = 1.0;
6287 cap->range.step = 0.1;
6299 *num_filter_caps = i;
6301 return VA_STATUS_SUCCESS;
6304 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6305 VAProcColorStandardBT601,
6308 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6309 VAProcColorStandardBT601,
6312 VAStatus i965_QueryVideoProcPipelineCaps(
6313 VADriverContextP ctx,
6314 VAContextID context,
6315 VABufferID *filters,
6316 unsigned int num_filters,
6317 VAProcPipelineCaps *pipeline_cap /* out */
6320 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6323 pipeline_cap->pipeline_flags = 0;
6324 pipeline_cap->filter_flags = 0;
6325 pipeline_cap->num_forward_references = 0;
6326 pipeline_cap->num_backward_references = 0;
6327 pipeline_cap->num_input_color_standards = 1;
6328 pipeline_cap->input_color_standards = vpp_input_color_standards;
6329 pipeline_cap->num_output_color_standards = 1;
6330 pipeline_cap->output_color_standards = vpp_output_color_standards;
6332 for (i = 0; i < num_filters; i++) {
6333 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6336 !obj_buffer->buffer_store ||
6337 !obj_buffer->buffer_store->buffer)
6338 return VA_STATUS_ERROR_INVALID_BUFFER;
6340 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6342 if (base->type == VAProcFilterNoiseReduction) {
6343 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6345 } else if (base->type == VAProcFilterDeinterlacing) {
6346 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6348 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6349 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6350 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6351 VA_STATUS_ERROR_INVALID_PARAMETER);
6353 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6354 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6355 pipeline_cap->num_forward_references++;
6356 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6357 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6362 return VA_STATUS_SUCCESS;
6365 extern struct hw_codec_info *i965_get_codec_info(int devid);
6368 i965_driver_data_init(VADriverContextP ctx)
6370 struct i965_driver_data *i965 = i965_driver_data(ctx);
6372 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6374 if (!i965->codec_info)
6377 if (object_heap_init(&i965->config_heap,
6378 sizeof(struct object_config),
6380 goto err_config_heap;
6381 if (object_heap_init(&i965->context_heap,
6382 sizeof(struct object_context),
6384 goto err_context_heap;
6386 if (object_heap_init(&i965->surface_heap,
6387 sizeof(struct object_surface),
6389 goto err_surface_heap;
6390 if (object_heap_init(&i965->buffer_heap,
6391 sizeof(struct object_buffer),
6393 goto err_buffer_heap;
6394 if (object_heap_init(&i965->image_heap,
6395 sizeof(struct object_image),
6397 goto err_image_heap;
6398 if (object_heap_init(&i965->subpic_heap,
6399 sizeof(struct object_subpic),
6401 goto err_subpic_heap;
6403 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6404 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6405 _i965InitMutex(&i965->render_mutex);
6406 _i965InitMutex(&i965->pp_mutex);
6411 object_heap_destroy(&i965->image_heap);
6413 object_heap_destroy(&i965->buffer_heap);
6415 object_heap_destroy(&i965->surface_heap);
6417 object_heap_destroy(&i965->context_heap);
6419 object_heap_destroy(&i965->config_heap);
6426 i965_driver_data_terminate(VADriverContextP ctx)
6428 struct i965_driver_data *i965 = i965_driver_data(ctx);
6430 _i965DestroyMutex(&i965->pp_mutex);
6431 _i965DestroyMutex(&i965->render_mutex);
6434 intel_batchbuffer_free(i965->batch);
6437 intel_batchbuffer_free(i965->pp_batch);
6439 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6440 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6441 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6442 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6443 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6444 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6448 bool (*init)(VADriverContextP ctx);
6449 void (*terminate)(VADriverContextP ctx);
6451 } i965_sub_ops[] = {
6454 intel_driver_terminate,
6459 i965_driver_data_init,
6460 i965_driver_data_terminate,
6465 i965_display_attributes_init,
6466 i965_display_attributes_terminate,
6471 i965_post_processing_init,
6472 i965_post_processing_terminate,
6478 i965_render_terminate,
6482 #ifdef HAVE_VA_WAYLAND
6484 i965_output_wayland_init,
6485 i965_output_wayland_terminate,
6492 i965_output_dri_init,
6493 i965_output_dri_terminate,
6499 i965_gpe_table_init,
6500 i965_gpe_table_terminate,
6506 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6510 if (i965->va_vendor[0] != '\0')
6514 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6515 "%s %s driver for %s - %d.%d.%d",
6516 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6517 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6518 INTEL_DRIVER_MICRO_VERSION);
6519 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6523 if (INTEL_DRIVER_PRE_VERSION > 0) {
6524 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6525 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6526 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6530 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6531 " (%s)", INTEL_DRIVER_GIT_VERSION);
6532 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6539 i965->va_vendor[0] = '\0';
6540 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6544 /* Only when the option of "enable-wrapper" is passed, it is possible
6545 * to initialize/load the wrapper context of backend driver.
6546 * Otherwise it is not loaded.
6548 #if HAVE_HYBRID_CODEC
6551 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6553 #define DRIVER_EXTENSION "_drv_video.so"
6555 struct i965_driver_data *i965 = i965_driver_data(ctx);
6557 VADriverContextP wrapper_pdrvctx;
6558 struct VADriverVTable *vtable;
6559 char *search_path, *driver_dir;
6561 char driver_path[256];
6562 void *handle = NULL;
6563 VAStatus va_status = VA_STATUS_SUCCESS;
6564 bool driver_loaded = false;
6566 if (HAS_VP9_DECODING(i965)) {
6567 i965->wrapper_pdrvctx = NULL;
6571 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6572 vtable = calloc(1, sizeof(*vtable));
6574 if (!wrapper_pdrvctx || !vtable) {
6575 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6576 free(wrapper_pdrvctx);
6578 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6581 /* use the same drm_state with CTX */
6582 wrapper_pdrvctx->drm_state = ctx->drm_state;
6583 wrapper_pdrvctx->display_type = ctx->display_type;
6584 wrapper_pdrvctx->vtable = vtable;
6586 search_path = VA_DRIVERS_PATH;
6587 search_path = strdup((const char *)search_path);
6589 driver_dir = strtok_r(search_path, ":", &saveptr);
6590 while (driver_dir && !driver_loaded) {
6591 memset(driver_path, 0, sizeof(driver_path));
6592 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6594 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6596 fprintf(stderr, "failed to open %s\n", driver_path);
6597 driver_dir = strtok_r(NULL, ":", &saveptr);
6601 VADriverInit init_func = NULL;
6602 char init_func_s[256];
6605 static const struct {
6608 } compatible_versions[] = {
6609 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6618 for (i = 0; compatible_versions[i].major >= 0; i++) {
6619 snprintf(init_func_s, sizeof(init_func_s),
6620 "__vaDriverInit_%d_%d",
6621 compatible_versions[i].major,
6622 compatible_versions[i].minor);
6623 init_func = (VADriverInit)dlsym(handle, init_func_s);
6628 if (compatible_versions[i].major < 0) {
6630 fprintf(stderr, "%s has no function %s\n",
6631 driver_path, init_func_s);
6632 driver_dir = strtok_r(NULL, ":", &saveptr);
6637 va_status = (*init_func)(wrapper_pdrvctx);
6639 if (va_status != VA_STATUS_SUCCESS) {
6641 fprintf(stderr, "%s init failed\n", driver_path);
6642 driver_dir = strtok_r(NULL, ":", &saveptr);
6646 wrapper_pdrvctx->handle = handle;
6647 driver_loaded = true;
6653 if (driver_loaded) {
6654 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6655 return VA_STATUS_SUCCESS;
6657 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6659 free(wrapper_pdrvctx);
6660 return VA_STATUS_ERROR_OPERATION_FAILED;
6666 i965_Init(VADriverContextP ctx)
6668 struct i965_driver_data *i965 = i965_driver_data(ctx);
6670 const char *chipset;
6672 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6673 if ((i965_sub_ops[i].display_type == 0 ||
6674 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6675 !i965_sub_ops[i].init(ctx))
6679 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6680 switch (i965->intel.device_id) {
6682 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6683 #include "i965_pciids.h"
6685 chipset = "Unknown Intel Chipset";
6689 if (!ensure_vendor_string(i965, chipset))
6690 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6692 i965->current_context_id = VA_INVALID_ID;
6694 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6695 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6697 #if HAVE_HYBRID_CODEC
6698 i965_initialize_wrapper(ctx, "hybrid");
6701 return VA_STATUS_SUCCESS;
6705 for (; i >= 0; i--) {
6706 if (i965_sub_ops[i].display_type == 0 ||
6707 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6708 i965_sub_ops[i].terminate(ctx);
6712 return VA_STATUS_ERROR_UNKNOWN;
6717 i965_Terminate(VADriverContextP ctx)
6719 struct i965_driver_data *i965 = i965_driver_data(ctx);
6723 #if HAVE_HYBRID_CODEC
6724 if (i965->wrapper_pdrvctx) {
6725 VADriverContextP pdrvctx;
6726 pdrvctx = i965->wrapper_pdrvctx;
6727 if (pdrvctx->handle) {
6728 pdrvctx->vtable->vaTerminate(pdrvctx);
6729 dlclose(pdrvctx->handle);
6730 pdrvctx->handle = NULL;
6732 free(pdrvctx->vtable);
6734 i965->wrapper_pdrvctx = NULL;
6738 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6739 if (i965_sub_ops[i - 1].display_type == 0 ||
6740 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6741 i965_sub_ops[i - 1].terminate(ctx);
6745 ctx->pDriverData = NULL;
6748 return VA_STATUS_SUCCESS;
6752 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6755 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
6757 struct VADriverVTable * const vtable = ctx->vtable;
6758 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6760 struct i965_driver_data *i965;
6761 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6763 ctx->version_major = VA_MAJOR_VERSION;
6764 ctx->version_minor = VA_MINOR_VERSION;
6765 ctx->max_profiles = I965_MAX_PROFILES;
6766 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6767 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6768 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6769 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6770 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6772 vtable->vaTerminate = i965_Terminate;
6773 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6774 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6775 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6776 vtable->vaCreateConfig = i965_CreateConfig;
6777 vtable->vaDestroyConfig = i965_DestroyConfig;
6778 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6779 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6780 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6781 vtable->vaCreateContext = i965_CreateContext;
6782 vtable->vaDestroyContext = i965_DestroyContext;
6783 vtable->vaCreateBuffer = i965_CreateBuffer;
6784 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
6785 vtable->vaMapBuffer = i965_MapBuffer;
6786 vtable->vaUnmapBuffer = i965_UnmapBuffer;
6787 vtable->vaDestroyBuffer = i965_DestroyBuffer;
6788 vtable->vaBeginPicture = i965_BeginPicture;
6789 vtable->vaRenderPicture = i965_RenderPicture;
6790 vtable->vaEndPicture = i965_EndPicture;
6791 vtable->vaSyncSurface = i965_SyncSurface;
6792 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
6793 vtable->vaPutSurface = i965_PutSurface;
6794 vtable->vaQueryImageFormats = i965_QueryImageFormats;
6795 vtable->vaCreateImage = i965_CreateImage;
6796 vtable->vaDeriveImage = i965_DeriveImage;
6797 vtable->vaDestroyImage = i965_DestroyImage;
6798 vtable->vaSetImagePalette = i965_SetImagePalette;
6799 vtable->vaGetImage = i965_GetImage;
6800 vtable->vaPutImage = i965_PutImage;
6801 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
6802 vtable->vaCreateSubpicture = i965_CreateSubpicture;
6803 vtable->vaDestroySubpicture = i965_DestroySubpicture;
6804 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
6805 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
6806 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
6807 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
6808 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
6809 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
6810 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
6811 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
6812 vtable->vaBufferInfo = i965_BufferInfo;
6813 vtable->vaLockSurface = i965_LockSurface;
6814 vtable->vaUnlockSurface = i965_UnlockSurface;
6815 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
6816 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
6817 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
6820 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
6821 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
6823 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
6824 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
6825 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
6827 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
6830 ctx->pDriverData = NULL;
6832 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6835 i965->wrapper_pdrvctx = NULL;
6836 ctx->pDriverData = (void *)i965;
6837 ret = i965_Init(ctx);
6839 if (ret == VA_STATUS_SUCCESS) {
6840 ctx->str_vendor = i965->va_vendor;
6843 ctx->pDriverData = NULL;