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 &&
835 entrypoint == VAEntrypointVLD &&
836 i965->wrapper_pdrvctx) {
837 va_status = VA_STATUS_SUCCESS;
838 } else if(!HAS_VP9_DECODING_PROFILE(i965, profile) &&
839 !HAS_VP9_ENCODING(i965) && !i965->wrapper_pdrvctx) {
840 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
842 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
848 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
855 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
856 VAEntrypoint entrypoint)
858 struct i965_driver_data * const i965 = i965_driver_data(ctx);
859 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
862 case VAProfileH264ConstrainedBaseline:
863 case VAProfileH264Main:
864 case VAProfileH264High:
865 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
866 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
869 case VAProfileH264MultiviewHigh:
870 case VAProfileH264StereoHigh:
871 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
872 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
875 case VAProfileJPEGBaseline:
876 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
877 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
878 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
879 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
882 case VAProfileHEVCMain10:
883 if (HAS_HEVC10_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)
884 chroma_formats = VA_RT_FORMAT_YUV420_10BPP;
885 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
886 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
890 if (HAS_VPP_P010(i965))
891 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
894 chroma_formats |= VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_RGB32;
897 case VAProfileVP9Profile0:
898 case VAProfileVP9Profile2:
899 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
900 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
906 return chroma_formats;
910 i965_GetConfigAttributes(VADriverContextP ctx,
912 VAEntrypoint entrypoint,
913 VAConfigAttrib *attrib_list, /* in/out */
916 struct i965_driver_data * const i965 = i965_driver_data(ctx);
920 va_status = i965_validate_config(ctx, profile, entrypoint);
921 if (va_status != VA_STATUS_SUCCESS)
924 /* Other attributes don't seem to be defined */
925 /* What to do if we don't know the attribute? */
926 for (i = 0; i < num_attribs; i++) {
927 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
928 switch (attrib_list[i].type) {
929 case VAConfigAttribRTFormat:
930 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
931 profile, entrypoint);
934 case VAConfigAttribRateControl:
935 if (entrypoint == VAEntrypointEncSlice) {
936 attrib_list[i].value = VA_RC_CQP;
938 if (profile != VAProfileMPEG2Main &&
939 profile != VAProfileMPEG2Simple)
940 attrib_list[i].value |= VA_RC_CBR;
942 if (profile == VAProfileVP9Profile0 ||
943 profile == VAProfileH264ConstrainedBaseline ||
944 profile == VAProfileH264Main ||
945 profile == VAProfileH264High)
946 attrib_list[i].value |= VA_RC_VBR;
949 } else if (entrypoint == VAEntrypointEncSliceLP) {
950 struct i965_driver_data * const i965 = i965_driver_data(ctx);
952 /* Support low power encoding for H.264 only by now */
953 if (profile == VAProfileH264ConstrainedBaseline ||
954 profile == VAProfileH264Main ||
955 profile == VAProfileH264High)
956 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
958 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
960 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
964 case VAConfigAttribEncPackedHeaders:
965 if (entrypoint == VAEntrypointEncSlice ||
966 entrypoint == VAEntrypointEncSliceLP) {
967 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
968 if (profile == VAProfileH264ConstrainedBaseline ||
969 profile == VAProfileH264Main ||
970 profile == VAProfileH264High ||
971 profile == VAProfileH264StereoHigh ||
972 profile == VAProfileH264MultiviewHigh ||
973 profile == VAProfileHEVCMain ||
974 profile == VAProfileHEVCMain10) {
975 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
976 VA_ENC_PACKED_HEADER_SLICE);
978 else if (profile == VAProfileVP9Profile0)
979 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
982 else if (entrypoint == VAEntrypointEncPicture) {
983 if (profile == VAProfileJPEGBaseline)
984 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
988 case VAConfigAttribEncMaxRefFrames:
989 if (entrypoint == VAEntrypointEncSlice)
990 attrib_list[i].value = (1 << 16) | (1 << 0);
991 else if (entrypoint == VAEntrypointEncSliceLP) {
992 /* Don't support B frame for low power mode */
993 if (profile == VAProfileH264ConstrainedBaseline ||
994 profile == VAProfileH264Main ||
995 profile == VAProfileH264High)
996 attrib_list[i].value = (1 << 0);
998 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1003 case VAConfigAttribEncQualityRange:
1004 if (entrypoint == VAEntrypointEncSlice ||
1005 entrypoint == VAEntrypointEncSliceLP) {
1006 attrib_list[i].value = 1;
1007 if (profile == VAProfileH264ConstrainedBaseline ||
1008 profile == VAProfileH264Main ||
1009 profile == VAProfileH264High ){
1010 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1011 if(entrypoint == VAEntrypointEncSlice){
1012 if (IS_GEN9(i965->intel.device_info))
1013 attrib_list[i].value = ENCODER_QUALITY_RANGE_AVC;
1020 case VAConfigAttribEncJPEG:
1021 if( entrypoint == VAEntrypointEncPicture) {
1022 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*)&(attrib_list[i].value);
1023 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1024 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1025 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1026 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1027 (configVal->bits).max_num_components = 3; // Only 3 components supported
1028 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1029 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1030 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1034 case VAConfigAttribDecSliceMode:
1035 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1038 case VAConfigAttribEncROI:
1039 if (entrypoint == VAEntrypointEncSlice ||
1040 entrypoint == VAEntrypointEncSliceLP) {
1042 if (profile == VAProfileH264ConstrainedBaseline ||
1043 profile == VAProfileH264Main ||
1044 profile == VAProfileH264High) {
1046 if (IS_GEN9(i965->intel.device_info)&&
1047 entrypoint == VAEntrypointEncSlice)
1048 attrib_list[i].value = 0;
1051 VAConfigAttribValEncROI *roi_config =
1052 (VAConfigAttribValEncROI *)&(attrib_list[i].value);
1054 if(entrypoint == VAEntrypointEncSliceLP) {
1055 roi_config->bits.num_roi_regions = 3;
1056 roi_config->bits.roi_rc_priority_support = 0;
1057 roi_config->bits.roi_rc_qp_delat_support = 0;
1059 roi_config->bits.num_roi_regions =
1060 I965_MAX_NUM_ROI_REGIONS;
1061 roi_config->bits.roi_rc_priority_support = 0;
1062 roi_config->bits.roi_rc_qp_delat_support = 1;
1066 attrib_list[i].value = 0;
1072 case VAConfigAttribEncRateControlExt:
1073 if ((profile == VAProfileH264ConstrainedBaseline ||
1074 profile == VAProfileH264Main ||
1075 profile == VAProfileH264High) &&
1076 entrypoint == VAEntrypointEncSlice) {
1077 if (IS_GEN9(i965->intel.device_info))
1078 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1080 VAConfigAttribValEncRateControlExt *val_config = (VAConfigAttribValEncRateControlExt *)&(attrib_list[i].value);
1082 val_config->bits.max_num_temporal_layers_minus1 = MAX_TEMPORAL_LAYERS - 1;
1083 val_config->bits.temporal_layer_bitrate_control_flag = 1;
1086 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1091 case VAConfigAttribEncMaxSlices:
1092 if (entrypoint == VAEntrypointEncSlice) {
1093 if ((profile == VAProfileH264ConstrainedBaseline ||
1094 profile == VAProfileH264Main ||
1095 profile == VAProfileH264High) ||
1096 profile == VAProfileH264StereoHigh ||
1097 profile == VAProfileH264MultiviewHigh) {
1098 if (IS_GEN9(i965->intel.device_info))
1099 attrib_list[i].value = 1;
1101 attrib_list[i].value = I965_MAX_NUM_SLICE;
1102 }else if (profile == VAProfileHEVCMain ||
1103 profile == VAProfileHEVCMain10) {
1104 attrib_list[i].value = I965_MAX_NUM_SLICE;
1106 } else if (entrypoint == VAEntrypointEncSliceLP) {
1107 if ((profile == VAProfileH264ConstrainedBaseline ||
1108 profile == VAProfileH264Main ||
1109 profile == VAProfileH264High) ||
1110 profile == VAProfileH264StereoHigh ||
1111 profile == VAProfileH264MultiviewHigh)
1112 attrib_list[i].value = I965_MAX_NUM_SLICE;
1114 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1120 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1125 return VA_STATUS_SUCCESS;
1129 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1131 object_heap_free(heap, obj);
1134 static VAConfigAttrib *
1135 i965_lookup_config_attribute(struct object_config *obj_config,
1136 VAConfigAttribType type)
1140 for (i = 0; i < obj_config->num_attribs; i++) {
1141 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1142 if (attrib->type == type)
1149 i965_append_config_attribute(struct object_config *obj_config,
1150 const VAConfigAttrib *new_attrib)
1152 VAConfigAttrib *attrib;
1154 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1155 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1157 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1158 attrib->type = new_attrib->type;
1159 attrib->value = new_attrib->value;
1160 return VA_STATUS_SUCCESS;
1164 i965_ensure_config_attribute(struct object_config *obj_config,
1165 const VAConfigAttrib *new_attrib)
1167 VAConfigAttrib *attrib;
1169 /* Check for existing attributes */
1170 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1172 /* Update existing attribute */
1173 attrib->value = new_attrib->value;
1174 return VA_STATUS_SUCCESS;
1176 return i965_append_config_attribute(obj_config, new_attrib);
1180 i965_CreateConfig(VADriverContextP ctx,
1182 VAEntrypoint entrypoint,
1183 VAConfigAttrib *attrib_list,
1185 VAConfigID *config_id) /* out */
1187 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1188 struct object_config *obj_config;
1193 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1195 if (VA_STATUS_SUCCESS != vaStatus) {
1199 configID = NEW_CONFIG_ID();
1200 obj_config = CONFIG(configID);
1202 if (NULL == obj_config) {
1203 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1207 obj_config->profile = profile;
1208 obj_config->entrypoint = entrypoint;
1209 obj_config->num_attribs = 0;
1210 obj_config->wrapper_config = VA_INVALID_ID;
1212 for (i = 0; i < num_attribs; i++) {
1213 // add it later and ignore the user input for VAConfigAttribEncMaxSlices
1214 if(attrib_list[i].type == VAConfigAttribEncMaxSlices)
1216 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1217 if (vaStatus != VA_STATUS_SUCCESS)
1221 if (vaStatus == VA_STATUS_SUCCESS) {
1222 VAConfigAttrib attrib, *attrib_found;
1223 attrib.type = VAConfigAttribRTFormat;
1224 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1225 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1226 if (!attrib_found || !attrib_found->value)
1227 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1228 else if (!(attrib_found->value & attrib.value))
1229 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1232 if (vaStatus == VA_STATUS_SUCCESS) {
1233 VAConfigAttrib attrib;
1234 attrib.type = VAConfigAttribEncMaxSlices;
1235 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1236 if (entrypoint == VAEntrypointEncSlice) {
1237 if ((profile == VAProfileH264ConstrainedBaseline ||
1238 profile == VAProfileH264Main ||
1239 profile == VAProfileH264High) ||
1240 profile == VAProfileH264StereoHigh ||
1241 profile == VAProfileH264MultiviewHigh) {
1242 if (IS_GEN9(i965->intel.device_info))
1245 attrib.value = I965_MAX_NUM_SLICE;
1246 }else if (profile == VAProfileHEVCMain ||
1247 profile == VAProfileHEVCMain10) {
1248 attrib.value = I965_MAX_NUM_SLICE;
1250 } else if (entrypoint == VAEntrypointEncSliceLP) {
1251 if ((profile == VAProfileH264ConstrainedBaseline ||
1252 profile == VAProfileH264Main ||
1253 profile == VAProfileH264High) ||
1254 profile == VAProfileH264StereoHigh ||
1255 profile == VAProfileH264MultiviewHigh)
1256 attrib.value = I965_MAX_NUM_SLICE;
1258 attrib.value = VA_ATTRIB_NOT_SUPPORTED;
1260 if(attrib.value != VA_ATTRIB_NOT_SUPPORTED)
1261 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1264 if ((vaStatus == VA_STATUS_SUCCESS) &&
1265 (profile == VAProfileVP9Profile0) &&
1266 (entrypoint == VAEntrypointVLD) &&
1267 !HAS_VP9_DECODING(i965)) {
1269 if (i965->wrapper_pdrvctx) {
1270 VAGenericID wrapper_config;
1272 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1273 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1274 entrypoint, attrib_list,
1275 num_attribs, &wrapper_config));
1277 if (vaStatus == VA_STATUS_SUCCESS)
1278 obj_config->wrapper_config = wrapper_config;
1282 /* Error recovery */
1283 if (VA_STATUS_SUCCESS != vaStatus) {
1284 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1286 *config_id = configID;
1293 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1295 struct i965_driver_data *i965 = i965_driver_data(ctx);
1296 struct object_config *obj_config = CONFIG(config_id);
1299 if (NULL == obj_config) {
1300 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1304 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1305 i965->wrapper_pdrvctx) {
1306 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1307 vaDestroyConfig(i965->wrapper_pdrvctx,
1308 obj_config->wrapper_config));
1309 obj_config->wrapper_config = VA_INVALID_ID;
1312 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1313 return VA_STATUS_SUCCESS;
1316 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1317 VAConfigID config_id,
1318 VAProfile *profile, /* out */
1319 VAEntrypoint *entrypoint, /* out */
1320 VAConfigAttrib *attrib_list, /* out */
1321 int *num_attribs) /* out */
1323 struct i965_driver_data *i965 = i965_driver_data(ctx);
1324 struct object_config *obj_config = CONFIG(config_id);
1325 VAStatus vaStatus = VA_STATUS_SUCCESS;
1328 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1329 *profile = obj_config->profile;
1330 *entrypoint = obj_config->entrypoint;
1331 *num_attribs = obj_config->num_attribs;
1333 for(i = 0; i < obj_config->num_attribs; i++) {
1334 attrib_list[i] = obj_config->attrib_list[i];
1341 i965_destroy_surface_storage(struct object_surface *obj_surface)
1346 dri_bo_unreference(obj_surface->bo);
1347 obj_surface->bo = NULL;
1349 if (obj_surface->free_private_data != NULL) {
1350 obj_surface->free_private_data(&obj_surface->private_data);
1351 obj_surface->private_data = NULL;
1356 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1358 struct object_surface *obj_surface = (struct object_surface *)obj;
1360 i965_destroy_surface_storage(obj_surface);
1361 object_heap_free(heap, obj);
1365 i965_surface_native_memory(VADriverContextP ctx,
1366 struct object_surface *obj_surface,
1368 int expected_fourcc)
1370 struct i965_driver_data *i965 = i965_driver_data(ctx);
1371 int tiling = HAS_TILED_SURFACE(i965);
1373 if (!expected_fourcc)
1374 return VA_STATUS_SUCCESS;
1376 // todo, should we disable tiling for 422 format?
1377 if (expected_fourcc == VA_FOURCC_I420 ||
1378 expected_fourcc == VA_FOURCC_IYUV ||
1379 expected_fourcc == VA_FOURCC_I010 ||
1380 expected_fourcc == VA_FOURCC_YV12 ||
1381 expected_fourcc == VA_FOURCC_YV16)
1384 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1388 i965_suface_external_memory(VADriverContextP ctx,
1389 struct object_surface *obj_surface,
1390 int external_memory_type,
1391 VASurfaceAttribExternalBuffers *memory_attibute,
1394 struct i965_driver_data *i965 = i965_driver_data(ctx);
1396 if (!memory_attibute ||
1397 !memory_attibute->buffers ||
1398 index > memory_attibute->num_buffers)
1399 return VA_STATUS_ERROR_INVALID_PARAMETER;
1401 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1402 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1403 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1405 obj_surface->fourcc = memory_attibute->pixel_format;
1406 obj_surface->width = memory_attibute->pitches[0];
1407 obj_surface->size = memory_attibute->data_size;
1409 if (memory_attibute->num_planes == 1)
1410 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1412 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1414 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1415 obj_surface->x_cr_offset = 0;
1417 switch (obj_surface->fourcc) {
1418 case VA_FOURCC_NV12:
1419 case VA_FOURCC_P010:
1420 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1421 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1423 obj_surface->subsampling = SUBSAMPLE_YUV420;
1424 obj_surface->y_cb_offset = obj_surface->height;
1425 obj_surface->y_cr_offset = obj_surface->height;
1426 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1427 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1428 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1432 case VA_FOURCC_YV12:
1433 case VA_FOURCC_IMC1:
1434 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1435 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1437 obj_surface->subsampling = SUBSAMPLE_YUV420;
1438 obj_surface->y_cr_offset = obj_surface->height;
1439 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1440 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1441 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1442 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1446 case VA_FOURCC_I420:
1447 case VA_FOURCC_IYUV:
1448 case VA_FOURCC_IMC3:
1449 case VA_FOURCC_I010:
1450 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1451 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1453 obj_surface->subsampling = SUBSAMPLE_YUV420;
1454 obj_surface->y_cb_offset = obj_surface->height;
1455 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1456 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1457 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1458 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1462 case VA_FOURCC_YUY2:
1463 case VA_FOURCC_UYVY:
1464 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1466 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1467 obj_surface->y_cb_offset = 0;
1468 obj_surface->y_cr_offset = 0;
1469 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1470 obj_surface->cb_cr_height = obj_surface->orig_height;
1471 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1475 case VA_FOURCC_RGBA:
1476 case VA_FOURCC_RGBX:
1477 case VA_FOURCC_BGRA:
1478 case VA_FOURCC_BGRX:
1479 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1481 obj_surface->subsampling = SUBSAMPLE_RGBX;
1482 obj_surface->y_cb_offset = 0;
1483 obj_surface->y_cr_offset = 0;
1484 obj_surface->cb_cr_width = 0;
1485 obj_surface->cb_cr_height = 0;
1486 obj_surface->cb_cr_pitch = 0;
1490 case VA_FOURCC_Y800: /* monochrome surface */
1491 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1493 obj_surface->subsampling = SUBSAMPLE_YUV400;
1494 obj_surface->y_cb_offset = 0;
1495 obj_surface->y_cr_offset = 0;
1496 obj_surface->cb_cr_width = 0;
1497 obj_surface->cb_cr_height = 0;
1498 obj_surface->cb_cr_pitch = 0;
1502 case VA_FOURCC_411P:
1503 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1504 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1506 obj_surface->subsampling = SUBSAMPLE_YUV411;
1507 obj_surface->y_cb_offset = obj_surface->height;
1508 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1509 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1510 obj_surface->cb_cr_height = obj_surface->orig_height;
1511 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1515 case VA_FOURCC_422H:
1516 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1517 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1519 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1520 obj_surface->y_cb_offset = obj_surface->height;
1521 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1522 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1523 obj_surface->cb_cr_height = obj_surface->orig_height;
1524 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1528 case VA_FOURCC_YV16:
1529 assert(memory_attibute->num_planes == 3);
1530 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1532 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1533 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1534 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1535 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1536 obj_surface->cb_cr_height = obj_surface->orig_height;
1537 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1541 case VA_FOURCC_422V:
1542 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1543 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1545 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1546 obj_surface->y_cb_offset = obj_surface->height;
1547 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1548 obj_surface->cb_cr_width = obj_surface->orig_width;
1549 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1550 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1554 case VA_FOURCC_444P:
1555 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1556 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1558 obj_surface->subsampling = SUBSAMPLE_YUV444;
1559 obj_surface->y_cb_offset = obj_surface->height;
1560 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1561 obj_surface->cb_cr_width = obj_surface->orig_width;
1562 obj_surface->cb_cr_height = obj_surface->orig_height;
1563 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1569 return VA_STATUS_ERROR_INVALID_PARAMETER;
1572 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1573 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1574 "gem flinked vaapi surface",
1575 memory_attibute->buffers[index]);
1576 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1577 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1578 memory_attibute->buffers[index],
1581 if (!obj_surface->bo)
1582 return VA_STATUS_ERROR_INVALID_PARAMETER;
1584 return VA_STATUS_SUCCESS;
1587 /* byte-per-pixel of the first plane */
1589 bpp_1stplane_by_fourcc(unsigned int fourcc)
1591 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1593 if (info && (info->flag & I_S))
1594 return info->bpp[0] / 8;
1600 i965_CreateSurfaces2(
1601 VADriverContextP ctx,
1602 unsigned int format,
1604 unsigned int height,
1605 VASurfaceID *surfaces,
1606 unsigned int num_surfaces,
1607 VASurfaceAttrib *attrib_list,
1608 unsigned int num_attribs
1611 struct i965_driver_data *i965 = i965_driver_data(ctx);
1613 VAStatus vaStatus = VA_STATUS_SUCCESS;
1614 int expected_fourcc = 0;
1615 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1616 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1618 for (i = 0; i < num_attribs && attrib_list; i++) {
1619 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1620 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1621 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1622 expected_fourcc = attrib_list[i].value.value.i;
1625 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1626 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1628 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1630 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1631 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1632 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1633 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1634 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1635 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1638 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1639 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1640 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1641 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1645 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1646 * for post-processing (including color conversion) */
1647 if (VA_RT_FORMAT_YUV420 != format &&
1648 VA_RT_FORMAT_YUV420_10BPP != format &&
1649 VA_RT_FORMAT_YUV422 != format &&
1650 VA_RT_FORMAT_YUV444 != format &&
1651 VA_RT_FORMAT_YUV411 != format &&
1652 VA_RT_FORMAT_YUV400 != format &&
1653 VA_RT_FORMAT_RGB32 != format) {
1654 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1657 for (i = 0; i < num_surfaces; i++) {
1658 int surfaceID = NEW_SURFACE_ID();
1659 struct object_surface *obj_surface = SURFACE(surfaceID);
1661 if (NULL == obj_surface) {
1662 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1666 surfaces[i] = surfaceID;
1667 obj_surface->status = VASurfaceReady;
1668 obj_surface->orig_width = width;
1669 obj_surface->orig_height = height;
1670 obj_surface->user_disable_tiling = false;
1671 obj_surface->user_h_stride_set = false;
1672 obj_surface->user_v_stride_set = false;
1673 obj_surface->border_cleared = false;
1675 obj_surface->subpic_render_idx = 0;
1676 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1677 obj_surface->subpic[j] = VA_INVALID_ID;
1678 obj_surface->obj_subpic[j] = NULL;
1681 assert(i965->codec_info->min_linear_wpitch);
1682 assert(i965->codec_info->min_linear_hpitch);
1683 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1684 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1685 obj_surface->flags = SURFACE_REFERENCED;
1686 obj_surface->fourcc = 0;
1687 obj_surface->expected_format = format;
1688 obj_surface->bo = NULL;
1689 obj_surface->locked_image_id = VA_INVALID_ID;
1690 obj_surface->derived_image_id = VA_INVALID_ID;
1691 obj_surface->private_data = NULL;
1692 obj_surface->free_private_data = NULL;
1693 obj_surface->subsampling = SUBSAMPLE_YUV420;
1695 obj_surface->wrapper_surface = VA_INVALID_ID;
1696 obj_surface->exported_primefd = -1;
1698 switch (memory_type) {
1699 case I965_SURFACE_MEM_NATIVE:
1700 if (memory_attibute) {
1701 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1702 obj_surface->user_disable_tiling = true;
1704 if (memory_attibute->pixel_format) {
1705 if (expected_fourcc)
1706 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1708 expected_fourcc = memory_attibute->pixel_format;
1710 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1711 if (memory_attibute->pitches[0]) {
1712 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1713 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1714 obj_surface->width = memory_attibute->pitches[0];
1715 obj_surface->user_h_stride_set = true;
1716 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1717 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1719 if (memory_attibute->offsets[1]) {
1720 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1721 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1722 obj_surface->user_v_stride_set = true;
1723 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1724 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1728 vaStatus = i965_surface_native_memory(ctx,
1734 case I965_SURFACE_MEM_GEM_FLINK:
1735 case I965_SURFACE_MEM_DRM_PRIME:
1736 vaStatus = i965_suface_external_memory(ctx,
1743 if (VA_STATUS_SUCCESS != vaStatus) {
1744 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1749 /* Error recovery */
1750 if (VA_STATUS_SUCCESS != vaStatus) {
1751 /* surfaces[i-1] was the last successful allocation */
1753 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1755 surfaces[i] = VA_INVALID_SURFACE;
1756 assert(obj_surface);
1757 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1765 i965_CreateSurfaces(VADriverContextP ctx,
1770 VASurfaceID *surfaces) /* out */
1772 return i965_CreateSurfaces2(ctx,
1783 i965_DestroySurfaces(VADriverContextP ctx,
1784 VASurfaceID *surface_list,
1787 struct i965_driver_data *i965 = i965_driver_data(ctx);
1789 VAStatus va_status = VA_STATUS_SUCCESS;
1791 for (i = num_surfaces; i--; ) {
1792 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1794 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1796 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1797 i965->wrapper_pdrvctx) {
1798 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1799 vaDestroySurfaces(i965->wrapper_pdrvctx,
1800 &(obj_surface->wrapper_surface),
1802 obj_surface->wrapper_surface = VA_INVALID_ID;
1804 if (obj_surface->exported_primefd >= 0) {
1805 close(obj_surface->exported_primefd);
1806 obj_surface->exported_primefd = -1;
1809 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1816 i965_QueryImageFormats(VADriverContextP ctx,
1817 VAImageFormat *format_list, /* out */
1818 int *num_formats) /* out */
1822 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1823 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1825 format_list[n] = m->va_format;
1831 return VA_STATUS_SUCCESS;
1835 * Guess the format when the usage of a VA surface is unknown
1836 * 1. Without a valid context: YV12
1837 * 2. The current context is valid:
1838 * a) always NV12 on GEN6 and later
1839 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1842 i965_guess_surface_format(VADriverContextP ctx,
1843 VASurfaceID surface,
1844 unsigned int *fourcc,
1845 unsigned int *is_tiled)
1847 struct i965_driver_data *i965 = i965_driver_data(ctx);
1848 struct object_context *obj_context = NULL;
1849 struct object_config *obj_config = NULL;
1851 *fourcc = VA_FOURCC_YV12;
1854 if (i965->current_context_id == VA_INVALID_ID)
1857 obj_context = CONTEXT(i965->current_context_id);
1862 obj_config = obj_context->obj_config;
1868 if (IS_GEN6(i965->intel.device_info) ||
1869 IS_GEN7(i965->intel.device_info) ||
1870 IS_GEN8(i965->intel.device_info) ||
1871 IS_GEN9(i965->intel.device_info)) {
1872 *fourcc = VA_FOURCC_NV12;
1877 switch (obj_config->profile) {
1878 case VAProfileMPEG2Simple:
1879 case VAProfileMPEG2Main:
1880 *fourcc = VA_FOURCC_I420;
1885 *fourcc = VA_FOURCC_NV12;
1892 i965_QuerySubpictureFormats(VADriverContextP ctx,
1893 VAImageFormat *format_list, /* out */
1894 unsigned int *flags, /* out */
1895 unsigned int *num_formats) /* out */
1899 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1900 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1902 format_list[n] = m->va_format;
1904 flags[n] = m->va_flags;
1910 return VA_STATUS_SUCCESS;
1914 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1916 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1918 object_heap_free(heap, obj);
1922 i965_CreateSubpicture(VADriverContextP ctx,
1924 VASubpictureID *subpicture) /* out */
1926 struct i965_driver_data *i965 = i965_driver_data(ctx);
1927 VASubpictureID subpicID = NEW_SUBPIC_ID()
1928 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1931 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1933 struct object_image *obj_image = IMAGE(image);
1935 return VA_STATUS_ERROR_INVALID_IMAGE;
1937 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1939 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1941 *subpicture = subpicID;
1942 obj_subpic->image = image;
1943 obj_subpic->obj_image = obj_image;
1944 obj_subpic->format = m->format;
1945 obj_subpic->width = obj_image->image.width;
1946 obj_subpic->height = obj_image->image.height;
1947 obj_subpic->pitch = obj_image->image.pitches[0];
1948 obj_subpic->bo = obj_image->bo;
1949 obj_subpic->global_alpha = 1.0;
1951 return VA_STATUS_SUCCESS;
1955 i965_DestroySubpicture(VADriverContextP ctx,
1956 VASubpictureID subpicture)
1958 struct i965_driver_data *i965 = i965_driver_data(ctx);
1959 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1962 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1964 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1965 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1966 return VA_STATUS_SUCCESS;
1970 i965_SetSubpictureImage(VADriverContextP ctx,
1971 VASubpictureID subpicture,
1975 return VA_STATUS_ERROR_UNIMPLEMENTED;
1979 i965_SetSubpictureChromakey(VADriverContextP ctx,
1980 VASubpictureID subpicture,
1981 unsigned int chromakey_min,
1982 unsigned int chromakey_max,
1983 unsigned int chromakey_mask)
1986 return VA_STATUS_ERROR_UNIMPLEMENTED;
1990 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1991 VASubpictureID subpicture,
1994 struct i965_driver_data *i965 = i965_driver_data(ctx);
1995 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1997 if(global_alpha > 1.0 || global_alpha < 0.0){
1998 return VA_STATUS_ERROR_INVALID_PARAMETER;
2002 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2004 obj_subpic->global_alpha = global_alpha;
2006 return VA_STATUS_SUCCESS;
2010 i965_AssociateSubpicture(VADriverContextP ctx,
2011 VASubpictureID subpicture,
2012 VASurfaceID *target_surfaces,
2014 short src_x, /* upper left offset in subpicture */
2016 unsigned short src_width,
2017 unsigned short src_height,
2018 short dest_x, /* upper left offset in surface */
2020 unsigned short dest_width,
2021 unsigned short dest_height,
2023 * whether to enable chroma-keying or global-alpha
2024 * see VA_SUBPICTURE_XXX values
2028 struct i965_driver_data *i965 = i965_driver_data(ctx);
2029 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2033 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2035 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
2037 obj_subpic->src_rect.x = src_x;
2038 obj_subpic->src_rect.y = src_y;
2039 obj_subpic->src_rect.width = src_width;
2040 obj_subpic->src_rect.height = src_height;
2041 obj_subpic->dst_rect.x = dest_x;
2042 obj_subpic->dst_rect.y = dest_y;
2043 obj_subpic->dst_rect.width = dest_width;
2044 obj_subpic->dst_rect.height = dest_height;
2045 obj_subpic->flags = flags;
2047 for (i = 0; i < num_surfaces; i++) {
2048 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2050 return VA_STATUS_ERROR_INVALID_SURFACE;
2052 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
2053 if(obj_surface->subpic[j] == VA_INVALID_ID){
2054 assert(obj_surface->obj_subpic[j] == NULL);
2055 obj_surface->subpic[j] = subpicture;
2056 obj_surface->obj_subpic[j] = obj_subpic;
2061 if(j == I965_MAX_SUBPIC_SUM){
2062 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2066 return VA_STATUS_SUCCESS;
2071 i965_DeassociateSubpicture(VADriverContextP ctx,
2072 VASubpictureID subpicture,
2073 VASurfaceID *target_surfaces,
2076 struct i965_driver_data *i965 = i965_driver_data(ctx);
2077 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2081 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2083 for (i = 0; i < num_surfaces; i++) {
2084 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2086 return VA_STATUS_ERROR_INVALID_SURFACE;
2088 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
2089 if (obj_surface->subpic[j] == subpicture) {
2090 assert(obj_surface->obj_subpic[j] == obj_subpic);
2091 obj_surface->subpic[j] = VA_INVALID_ID;
2092 obj_surface->obj_subpic[j] = NULL;
2097 if(j == I965_MAX_SUBPIC_SUM){
2098 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2101 return VA_STATUS_SUCCESS;
2105 i965_reference_buffer_store(struct buffer_store **ptr,
2106 struct buffer_store *buffer_store)
2108 assert(*ptr == NULL);
2111 buffer_store->ref_count++;
2112 *ptr = buffer_store;
2117 i965_release_buffer_store(struct buffer_store **ptr)
2119 struct buffer_store *buffer_store = *ptr;
2121 if (buffer_store == NULL)
2124 assert(buffer_store->bo || buffer_store->buffer);
2125 assert(!(buffer_store->bo && buffer_store->buffer));
2126 buffer_store->ref_count--;
2128 if (buffer_store->ref_count == 0) {
2129 dri_bo_unreference(buffer_store->bo);
2130 free(buffer_store->buffer);
2131 buffer_store->bo = NULL;
2132 buffer_store->buffer = NULL;
2140 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2142 struct object_context *obj_context = (struct object_context *)obj;
2145 if (obj_context->hw_context) {
2146 obj_context->hw_context->destroy(obj_context->hw_context);
2147 obj_context->hw_context = NULL;
2150 if (obj_context->codec_type == CODEC_PROC) {
2151 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2153 } else if (obj_context->codec_type == CODEC_ENC) {
2154 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2155 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2157 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2158 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2159 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2161 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2162 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2164 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2165 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2167 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2168 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2169 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2171 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2172 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2174 free(obj_context->codec_state.encode.slice_params_ext);
2175 if (obj_context->codec_state.encode.slice_rawdata_index) {
2176 free(obj_context->codec_state.encode.slice_rawdata_index);
2177 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2179 if (obj_context->codec_state.encode.slice_rawdata_count) {
2180 free(obj_context->codec_state.encode.slice_rawdata_count);
2181 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2184 if (obj_context->codec_state.encode.slice_header_index) {
2185 free(obj_context->codec_state.encode.slice_header_index);
2186 obj_context->codec_state.encode.slice_header_index = NULL;
2189 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2190 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2191 free(obj_context->codec_state.encode.packed_header_params_ext);
2193 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2194 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2195 free(obj_context->codec_state.encode.packed_header_data_ext);
2197 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2199 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2200 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2202 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2203 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2204 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2206 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2207 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2209 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2210 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2212 free(obj_context->codec_state.decode.slice_params);
2213 free(obj_context->codec_state.decode.slice_datas);
2216 free(obj_context->render_targets);
2217 object_heap_free(heap, obj);
2221 max_resolution(struct i965_driver_data *i965,
2222 struct object_config *obj_config,
2226 if (i965->codec_info->max_resolution) {
2227 i965->codec_info->max_resolution(i965, obj_config, w, h);
2229 *w = i965->codec_info->max_width;
2230 *h = i965->codec_info->max_height;
2235 i965_CreateContext(VADriverContextP ctx,
2236 VAConfigID config_id,
2240 VASurfaceID *render_targets,
2241 int num_render_targets,
2242 VAContextID *context) /* out */
2244 struct i965_driver_data *i965 = i965_driver_data(ctx);
2245 struct object_config *obj_config = CONFIG(config_id);
2246 struct object_context *obj_context = NULL;
2247 VAConfigAttrib *attrib;
2248 VAStatus vaStatus = VA_STATUS_SUCCESS;
2254 if (NULL == obj_config) {
2255 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2259 max_resolution(i965, obj_config, &max_width, &max_height);
2261 if (picture_width > max_width ||
2262 picture_height > max_height) {
2263 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2268 /* Validate picture dimensions */
2269 contextID = NEW_CONTEXT_ID();
2270 obj_context = CONTEXT(contextID);
2272 if (NULL == obj_context) {
2273 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2277 *context = contextID;
2278 obj_context->flags = flag;
2279 obj_context->context_id = contextID;
2280 obj_context->obj_config = obj_config;
2281 obj_context->picture_width = picture_width;
2282 obj_context->picture_height = picture_height;
2283 obj_context->num_render_targets = num_render_targets;
2284 obj_context->render_targets =
2285 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2286 obj_context->hw_context = NULL;
2287 obj_context->wrapper_context = VA_INVALID_ID;
2289 if (!obj_context->render_targets)
2290 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2292 for(i = 0; i < num_render_targets; i++) {
2293 if (NULL == SURFACE(render_targets[i])) {
2294 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2298 obj_context->render_targets[i] = render_targets[i];
2301 if (VA_STATUS_SUCCESS == vaStatus) {
2302 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2303 obj_context->codec_type = CODEC_PROC;
2304 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2305 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2306 assert(i965->codec_info->proc_hw_context_init);
2307 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2308 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2309 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2310 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2311 VAConfigAttrib *packed_attrib;
2312 obj_context->codec_type = CODEC_ENC;
2313 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2314 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2315 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2316 obj_context->codec_state.encode.packed_header_params_ext =
2317 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2318 sizeof(struct buffer_store *));
2320 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2321 obj_context->codec_state.encode.packed_header_data_ext =
2322 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2323 sizeof(struct buffer_store *));
2325 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2326 obj_context->codec_state.encode.slice_rawdata_index =
2327 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2328 obj_context->codec_state.encode.slice_rawdata_count =
2329 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2331 obj_context->codec_state.encode.slice_header_index =
2332 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2334 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2336 obj_context->codec_state.encode.slice_index = 0;
2337 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2338 if (packed_attrib) {
2339 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2340 if (obj_config->profile == VAProfileVP9Profile0)
2341 obj_context->codec_state.encode.packed_header_flag =
2342 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2344 /* use the default value. SPS/PPS/RAWDATA is passed from user
2345 * while Slice_header data is generated by driver.
2347 obj_context->codec_state.encode.packed_header_flag =
2348 VA_ENC_PACKED_HEADER_SEQUENCE |
2349 VA_ENC_PACKED_HEADER_PICTURE |
2350 VA_ENC_PACKED_HEADER_RAW_DATA;
2352 /* it is not used for VP9 */
2353 if (obj_config->profile == VAProfileVP9Profile0)
2354 obj_context->codec_state.encode.packed_header_flag = 0;
2356 assert(i965->codec_info->enc_hw_context_init);
2357 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2359 obj_context->codec_type = CODEC_DEC;
2360 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2361 obj_context->codec_state.decode.current_render_target = -1;
2362 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2363 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2364 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2365 sizeof(*obj_context->codec_state.decode.slice_params));
2366 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2367 sizeof(*obj_context->codec_state.decode.slice_datas));
2369 assert(i965->codec_info->dec_hw_context_init);
2370 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2374 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2376 return VA_STATUS_ERROR_INVALID_CONFIG;
2377 obj_context->codec_state.base.chroma_formats = attrib->value;
2379 if (obj_config->wrapper_config != VA_INVALID_ID) {
2380 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2381 * So it won't check i965->wrapper_pdrvctx again.
2382 * Fixme if it is incorrect.
2384 VAGenericID wrapper_context;
2387 * The render_surface is not passed when calling
2389 * If it is needed, we must get the wrapped surface
2390 * for the corresponding Surface_list.
2391 * So the wrapped surface conversion is deferred.
2393 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2394 vaCreateContext(i965->wrapper_pdrvctx,
2395 obj_config->wrapper_config,
2396 picture_width, picture_height,
2400 if (vaStatus == VA_STATUS_SUCCESS)
2401 obj_context->wrapper_context = wrapper_context;
2403 /* Error recovery */
2404 if (VA_STATUS_SUCCESS != vaStatus) {
2405 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2408 i965->current_context_id = contextID;
2414 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2416 struct i965_driver_data *i965 = i965_driver_data(ctx);
2417 struct object_context *obj_context = CONTEXT(context);
2418 VAStatus va_status = VA_STATUS_SUCCESS;
2420 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2422 if (i965->current_context_id == context)
2423 i965->current_context_id = VA_INVALID_ID;
2425 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2426 i965->wrapper_pdrvctx) {
2427 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2428 vaDestroyContext(i965->wrapper_pdrvctx,
2429 obj_context->wrapper_context));
2431 obj_context->wrapper_context = VA_INVALID_ID;
2434 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2440 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2442 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2444 assert(obj_buffer->buffer_store);
2445 i965_release_buffer_store(&obj_buffer->buffer_store);
2446 object_heap_free(heap, obj);
2450 i965_create_buffer_internal(VADriverContextP ctx,
2451 VAContextID context,
2454 unsigned int num_elements,
2459 struct i965_driver_data *i965 = i965_driver_data(ctx);
2460 struct object_buffer *obj_buffer = NULL;
2461 struct buffer_store *buffer_store = NULL;
2463 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2464 struct object_context *obj_context = CONTEXT(context);
2465 int wrapper_flag = 0;
2469 case VAPictureParameterBufferType:
2470 case VAIQMatrixBufferType:
2471 case VAQMatrixBufferType:
2472 case VABitPlaneBufferType:
2473 case VASliceGroupMapBufferType:
2474 case VASliceParameterBufferType:
2475 case VASliceDataBufferType:
2476 case VAMacroblockParameterBufferType:
2477 case VAResidualDataBufferType:
2478 case VADeblockingParameterBufferType:
2479 case VAImageBufferType:
2480 case VAEncCodedBufferType:
2481 case VAEncSequenceParameterBufferType:
2482 case VAEncPictureParameterBufferType:
2483 case VAEncSliceParameterBufferType:
2484 case VAEncPackedHeaderParameterBufferType:
2485 case VAEncPackedHeaderDataBufferType:
2486 case VAEncMiscParameterBufferType:
2487 case VAProcPipelineParameterBufferType:
2488 case VAProcFilterParameterBufferType:
2489 case VAHuffmanTableBufferType:
2490 case VAProbabilityBufferType:
2491 case VAEncMacroblockMapBufferType:
2496 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2499 bufferID = NEW_BUFFER_ID();
2500 obj_buffer = BUFFER(bufferID);
2502 if (NULL == obj_buffer) {
2503 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2506 if (type == VAEncCodedBufferType) {
2507 size += I965_CODEDBUFFER_HEADER_SIZE;
2508 size += 0x1000; /* for upper bound check */
2511 obj_buffer->max_num_elements = num_elements;
2512 obj_buffer->num_elements = num_elements;
2513 obj_buffer->size_element = size;
2514 obj_buffer->type = type;
2515 obj_buffer->export_refcount = 0;
2516 obj_buffer->buffer_store = NULL;
2517 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2518 obj_buffer->context_id = context;
2520 buffer_store = calloc(1, sizeof(struct buffer_store));
2521 assert(buffer_store);
2522 buffer_store->ref_count = 1;
2525 (obj_context->wrapper_context != VA_INVALID_ID) &&
2526 i965->wrapper_pdrvctx) {
2527 VAGenericID wrapper_buffer;
2528 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2530 CALL_VTABLE(pdrvctx, vaStatus,
2531 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2532 data, &wrapper_buffer));
2533 if (vaStatus == VA_STATUS_SUCCESS) {
2534 obj_buffer->wrapper_buffer = wrapper_buffer;
2542 if (store_bo != NULL) {
2543 buffer_store->bo = store_bo;
2544 dri_bo_reference(buffer_store->bo);
2546 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2547 if (data && !wrapper_flag)
2548 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2549 } else if (type == VASliceDataBufferType ||
2550 type == VAImageBufferType ||
2551 type == VAEncCodedBufferType ||
2552 type == VAEncMacroblockMapBufferType ||
2553 type == VAProbabilityBufferType) {
2555 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2556 * So it is enough to allocate one 64 byte bo
2559 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2562 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2564 size * num_elements, 64);
2565 assert(buffer_store->bo);
2567 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2568 * In fact it can be skipped. But it is still allocated and it is
2569 * only to follow the normal flowchart of buffer_allocation/release.
2571 if (!wrapper_flag) {
2572 if (type == VAEncCodedBufferType) {
2573 struct i965_coded_buffer_segment *coded_buffer_segment;
2575 dri_bo_map(buffer_store->bo, 1);
2576 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2577 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2578 coded_buffer_segment->base.bit_offset = 0;
2579 coded_buffer_segment->base.status = 0;
2580 coded_buffer_segment->base.buf = NULL;
2581 coded_buffer_segment->base.next = NULL;
2582 coded_buffer_segment->mapped = 0;
2583 coded_buffer_segment->codec = 0;
2584 coded_buffer_segment->status_support = 0;
2585 dri_bo_unmap(buffer_store->bo);
2587 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2594 if (type == VAEncPackedHeaderDataBufferType) {
2595 msize = ALIGN(size, 4);
2598 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2600 buffer_store->buffer = malloc(4);
2602 buffer_store->buffer = malloc(msize * num_elements);
2603 assert(buffer_store->buffer);
2605 if (!wrapper_flag) {
2607 memcpy(buffer_store->buffer, data, size * num_elements);
2609 memset(buffer_store->buffer, 0, size * num_elements);
2613 buffer_store->num_elements = obj_buffer->num_elements;
2614 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2615 i965_release_buffer_store(&buffer_store);
2618 return VA_STATUS_SUCCESS;
2622 i965_CreateBuffer(VADriverContextP ctx,
2623 VAContextID context, /* in */
2624 VABufferType type, /* in */
2625 unsigned int size, /* in */
2626 unsigned int num_elements, /* in */
2627 void *data, /* in */
2628 VABufferID *buf_id) /* out */
2630 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2635 i965_BufferSetNumElements(VADriverContextP ctx,
2636 VABufferID buf_id, /* in */
2637 unsigned int num_elements) /* in */
2639 struct i965_driver_data *i965 = i965_driver_data(ctx);
2640 struct object_buffer *obj_buffer = BUFFER(buf_id);
2641 VAStatus vaStatus = VA_STATUS_SUCCESS;
2643 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2645 /* When the wrapper_buffer exists, it will wrapper to the
2646 * buffer allocated from backend driver.
2648 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2649 i965->wrapper_pdrvctx) {
2650 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2652 CALL_VTABLE(pdrvctx, vaStatus,
2653 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2658 if ((num_elements < 0) ||
2659 (num_elements > obj_buffer->max_num_elements)) {
2660 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2662 obj_buffer->num_elements = num_elements;
2663 if (obj_buffer->buffer_store != NULL) {
2664 obj_buffer->buffer_store->num_elements = num_elements;
2672 i965_MapBuffer(VADriverContextP ctx,
2673 VABufferID buf_id, /* in */
2674 void **pbuf) /* out */
2676 struct i965_driver_data *i965 = i965_driver_data(ctx);
2677 struct object_buffer *obj_buffer = BUFFER(buf_id);
2678 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2679 struct object_context *obj_context;
2681 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2683 obj_context = CONTEXT(obj_buffer->context_id);
2685 /* When the wrapper_buffer exists, it will wrapper to the
2686 * buffer allocated from backend driver.
2688 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2689 i965->wrapper_pdrvctx) {
2690 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2692 CALL_VTABLE(pdrvctx, vaStatus,
2693 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2697 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2698 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2700 if (obj_buffer->export_refcount > 0)
2701 return VA_STATUS_ERROR_INVALID_BUFFER;
2703 if (NULL != obj_buffer->buffer_store->bo) {
2704 unsigned int tiling, swizzle;
2706 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2708 if (tiling != I915_TILING_NONE)
2709 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2711 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2713 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2714 *pbuf = obj_buffer->buffer_store->bo->virtual;
2715 vaStatus = VA_STATUS_SUCCESS;
2717 if (obj_buffer->type == VAEncCodedBufferType) {
2719 unsigned char *buffer = NULL;
2720 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2721 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2723 if (!coded_buffer_segment->mapped) {
2724 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2726 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2729 obj_context->hw_context &&
2730 obj_context->hw_context->get_status &&
2731 coded_buffer_segment->status_support) {
2732 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2734 if (coded_buffer_segment->codec == CODEC_H264 ||
2735 coded_buffer_segment->codec == CODEC_H264_MVC) {
2736 delimiter0 = H264_DELIMITER0;
2737 delimiter1 = H264_DELIMITER1;
2738 delimiter2 = H264_DELIMITER2;
2739 delimiter3 = H264_DELIMITER3;
2740 delimiter4 = H264_DELIMITER4;
2741 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2742 delimiter0 = MPEG2_DELIMITER0;
2743 delimiter1 = MPEG2_DELIMITER1;
2744 delimiter2 = MPEG2_DELIMITER2;
2745 delimiter3 = MPEG2_DELIMITER3;
2746 delimiter4 = MPEG2_DELIMITER4;
2747 } else if(coded_buffer_segment->codec == CODEC_JPEG) {
2748 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2751 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2752 delimiter0 = HEVC_DELIMITER0;
2753 delimiter1 = HEVC_DELIMITER1;
2754 delimiter2 = HEVC_DELIMITER2;
2755 delimiter3 = HEVC_DELIMITER3;
2756 delimiter4 = HEVC_DELIMITER4;
2757 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2758 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2761 if(coded_buffer_segment->codec == CODEC_JPEG) {
2762 for(i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2763 if( (buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2767 coded_buffer_segment->base.size = i + 2;
2768 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2769 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2770 so it don't need to traversal the coded buffer */
2771 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2772 if ((buffer[i] == delimiter0) &&
2773 (buffer[i + 1] == delimiter1) &&
2774 (buffer[i + 2] == delimiter2) &&
2775 (buffer[i + 3] == delimiter3) &&
2776 (buffer[i + 4] == delimiter4))
2780 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2781 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2783 coded_buffer_segment->base.size = i;
2786 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2787 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2790 vaStatus = VA_STATUS_SUCCESS;
2793 coded_buffer_segment->mapped = 1;
2795 assert(coded_buffer_segment->base.buf);
2796 vaStatus = VA_STATUS_SUCCESS;
2799 } else if (NULL != obj_buffer->buffer_store->buffer) {
2800 *pbuf = obj_buffer->buffer_store->buffer;
2801 vaStatus = VA_STATUS_SUCCESS;
2808 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2810 struct i965_driver_data *i965 = i965_driver_data(ctx);
2811 struct object_buffer *obj_buffer = BUFFER(buf_id);
2812 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2814 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2815 return VA_STATUS_ERROR_INVALID_BUFFER;
2817 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2818 /* When the wrapper_buffer exists, it will wrapper to the
2819 * buffer allocated from backend driver.
2821 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2822 i965->wrapper_pdrvctx) {
2823 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2825 CALL_VTABLE(pdrvctx, vaStatus,
2826 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2830 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2831 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2833 if (NULL != obj_buffer->buffer_store->bo) {
2834 unsigned int tiling, swizzle;
2836 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2838 if (tiling != I915_TILING_NONE)
2839 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2841 dri_bo_unmap(obj_buffer->buffer_store->bo);
2843 vaStatus = VA_STATUS_SUCCESS;
2844 } else if (NULL != obj_buffer->buffer_store->buffer) {
2846 vaStatus = VA_STATUS_SUCCESS;
2853 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2855 struct i965_driver_data *i965 = i965_driver_data(ctx);
2856 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2857 VAStatus va_status = VA_STATUS_SUCCESS;
2859 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2861 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2862 i965->wrapper_pdrvctx) {
2863 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2864 vaDestroyBuffer(i965->wrapper_pdrvctx,
2865 obj_buffer->wrapper_buffer));
2866 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2869 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2875 i965_BeginPicture(VADriverContextP ctx,
2876 VAContextID context,
2877 VASurfaceID render_target)
2879 struct i965_driver_data *i965 = i965_driver_data(ctx);
2880 struct object_context *obj_context = CONTEXT(context);
2881 struct object_surface *obj_surface = SURFACE(render_target);
2882 struct object_config *obj_config;
2883 VAStatus vaStatus = VA_STATUS_SUCCESS;
2886 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2887 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2888 obj_config = obj_context->obj_config;
2889 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2891 if (is_surface_busy(i965, obj_surface))
2892 return VA_STATUS_ERROR_SURFACE_BUSY;
2894 if (obj_context->codec_type == CODEC_PROC) {
2895 obj_context->codec_state.proc.current_render_target = render_target;
2896 } else if (obj_context->codec_type == CODEC_ENC) {
2898 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2900 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2901 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2903 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2904 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2906 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2907 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2909 obj_context->codec_state.encode.num_slice_params_ext = 0;
2910 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2911 obj_context->codec_state.encode.last_packed_header_type = 0;
2912 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2913 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2914 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2915 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2916 memset(obj_context->codec_state.encode.slice_header_index, 0,
2917 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2919 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2920 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2921 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2922 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2923 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2924 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2925 obj_context->codec_state.encode.slice_index = 0;
2926 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2928 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2929 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2930 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2932 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2934 obj_context->codec_state.decode.current_render_target = render_target;
2935 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2936 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2937 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2938 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2940 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2941 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2942 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2945 obj_context->codec_state.decode.num_slice_params = 0;
2946 obj_context->codec_state.decode.num_slice_datas = 0;
2948 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2949 i965->wrapper_pdrvctx) {
2950 if (obj_surface->wrapper_surface == VA_INVALID_ID)
2951 vaStatus = i965_surface_wrapper(ctx, render_target);
2953 if (vaStatus != VA_STATUS_SUCCESS)
2956 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2957 vaBeginPicture(i965->wrapper_pdrvctx,
2958 obj_context->wrapper_context,
2959 obj_surface->wrapper_surface));
2966 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2968 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2970 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2971 struct object_context *obj_context, \
2972 struct object_buffer *obj_buffer) \
2974 struct category##_state *category = &obj_context->codec_state.category; \
2975 i965_release_buffer_store(&category->member); \
2976 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2977 return VA_STATUS_SUCCESS; \
2980 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2982 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2983 struct object_context *obj_context, \
2984 struct object_buffer *obj_buffer) \
2986 struct category##_state *category = &obj_context->codec_state.category; \
2987 if (category->num_##member == category->max_##member) { \
2988 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2989 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2990 category->max_##member += NUM_SLICES; \
2992 i965_release_buffer_store(&category->member[category->num_##member]); \
2993 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2994 category->num_##member++; \
2995 return VA_STATUS_SUCCESS; \
2998 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
3000 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
3001 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3002 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
3003 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
3004 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3005 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
3007 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
3008 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3009 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
3013 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
3014 VABufferID *buffers,
3017 struct i965_driver_data *i965 = i965_driver_data(ctx);
3018 VAStatus vaStatus = VA_STATUS_SUCCESS;
3020 VADecPictureParameterBufferVP9 *pVp9PicParams;
3021 VADriverContextP pdrvctx;
3022 struct object_buffer *obj_buffer;
3024 pdrvctx = i965->wrapper_pdrvctx;
3025 /* do the conversion of VADecPictureParameterBufferVP9 */
3026 for (i = 0; i < num_buffers; i++) {
3027 obj_buffer = BUFFER(buffers[i]);
3032 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
3035 if (obj_buffer->type == VAPictureParameterBufferType) {
3037 VASurfaceID surface_id;
3038 struct object_surface *obj_surface;
3040 pdrvctx = i965->wrapper_pdrvctx;
3042 CALL_VTABLE(pdrvctx, vaStatus,
3043 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
3044 (void **)(&pVp9PicParams)));
3046 if (vaStatus != VA_STATUS_SUCCESS)
3049 for (j = 0; j < 8; j++) {
3050 surface_id = pVp9PicParams->reference_frames[j];
3051 obj_surface = SURFACE(surface_id);
3056 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
3057 vaStatus = i965_surface_wrapper(ctx, surface_id);
3058 if (vaStatus != VA_STATUS_SUCCESS) {
3059 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
3060 obj_buffer->wrapper_buffer);
3065 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
3067 CALL_VTABLE(pdrvctx, vaStatus,
3068 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3073 return VA_STATUS_SUCCESS;
3080 i965_decoder_wrapper_picture(VADriverContextP ctx,
3081 VAContextID context,
3082 VABufferID *buffers,
3085 struct i965_driver_data *i965 = i965_driver_data(ctx);
3086 struct object_context *obj_context = CONTEXT(context);
3087 VAStatus vaStatus = VA_STATUS_SUCCESS;
3089 VADriverContextP pdrvctx;
3090 struct object_buffer *obj_buffer;
3092 if (obj_context == NULL)
3093 return VA_STATUS_ERROR_INVALID_CONTEXT;
3095 /* When it is not wrapped context, continue the normal flowchart */
3096 if (obj_context->wrapper_context == VA_INVALID_ID)
3099 if (obj_context->obj_config &&
3100 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3101 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3103 return VA_STATUS_ERROR_INVALID_PARAMETER;
3105 pdrvctx = i965->wrapper_pdrvctx;
3107 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3108 obj_buffer = BUFFER(buffers[i]);
3113 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3114 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3118 CALL_VTABLE(pdrvctx, vaStatus,
3119 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3120 &(obj_buffer->wrapper_buffer), 1));
3126 i965_decoder_render_picture(VADriverContextP ctx,
3127 VAContextID context,
3128 VABufferID *buffers,
3131 struct i965_driver_data *i965 = i965_driver_data(ctx);
3132 struct object_context *obj_context = CONTEXT(context);
3133 VAStatus vaStatus = VA_STATUS_SUCCESS;
3136 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3138 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3139 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3142 return VA_STATUS_ERROR_INVALID_BUFFER;
3144 switch (obj_buffer->type) {
3145 case VAPictureParameterBufferType:
3146 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3149 case VAIQMatrixBufferType:
3150 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3153 case VABitPlaneBufferType:
3154 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3157 case VASliceParameterBufferType:
3158 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3161 case VASliceDataBufferType:
3162 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3165 case VAHuffmanTableBufferType:
3166 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3169 case VAProbabilityBufferType:
3170 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3174 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3179 if ((vaStatus == VA_STATUS_SUCCESS) &&
3180 (obj_context->wrapper_context != VA_INVALID_ID))
3181 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3186 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3188 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3189 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3190 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3191 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3192 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3193 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3194 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3195 /* extended buffer */
3196 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3197 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3198 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3200 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3201 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3202 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3204 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3205 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3208 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3209 struct object_context *obj_context,
3210 struct object_buffer *obj_buffer,
3213 struct encode_state *encode = &obj_context->codec_state.encode;
3215 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3216 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3217 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3218 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3220 return VA_STATUS_SUCCESS;
3224 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3225 struct object_context *obj_context,
3226 struct object_buffer *obj_buffer,
3229 struct encode_state *encode = &obj_context->codec_state.encode;
3231 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3232 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3233 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3234 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3236 return VA_STATUS_SUCCESS;
3240 i965_encoder_get_misc_paramerter_buffer_index(VADriverContextP ctx,
3241 struct encode_state *encode,
3242 VAEncMiscParameterBuffer *misc_param)
3246 if (!encode->has_layers)
3249 if (misc_param->type == VAEncMiscParameterTypeRateControl) {
3250 VAEncMiscParameterRateControl *misc_rate_control = (VAEncMiscParameterRateControl *)misc_param->data;
3252 index = misc_rate_control->rc_flags.bits.temporal_id;
3253 } else if (misc_param->type == VAEncMiscParameterTypeFrameRate) {
3254 VAEncMiscParameterFrameRate *misc_frame_rate = (VAEncMiscParameterFrameRate *)misc_param->data;
3256 index = misc_frame_rate->framerate_flags.bits.temporal_id;
3263 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3264 struct object_context *obj_context,
3265 struct object_buffer *obj_buffer)
3267 struct encode_state *encode = &obj_context->codec_state.encode;
3268 VAEncMiscParameterBuffer *param = NULL;
3271 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3272 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3274 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3276 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3277 return VA_STATUS_ERROR_INVALID_PARAMETER;
3279 if (param->type == VAEncMiscParameterTypeTemporalLayerStructure)
3280 encode->has_layers = 1;
3282 index = i965_encoder_get_misc_paramerter_buffer_index(ctx, encode, param);
3284 if (index >= ARRAY_ELEMS(encode->misc_param[0]))
3285 return VA_STATUS_ERROR_INVALID_PARAMETER;
3287 i965_release_buffer_store(&encode->misc_param[param->type][index]);
3288 i965_reference_buffer_store(&encode->misc_param[param->type][index], obj_buffer->buffer_store);
3290 return VA_STATUS_SUCCESS;
3294 i965_encoder_render_picture(VADriverContextP ctx,
3295 VAContextID context,
3296 VABufferID *buffers,
3299 struct i965_driver_data *i965 = i965_driver_data(ctx);
3300 struct object_context *obj_context = CONTEXT(context);
3301 struct object_config *obj_config;
3302 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3303 struct encode_state *encode;
3306 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3307 obj_config = obj_context->obj_config;
3308 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3310 encode = &obj_context->codec_state.encode;
3311 for (i = 0; i < num_buffers; i++) {
3312 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3315 return VA_STATUS_ERROR_INVALID_BUFFER;
3317 switch (obj_buffer->type) {
3318 case VAQMatrixBufferType:
3319 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3322 case VAIQMatrixBufferType:
3323 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3326 case VAEncSequenceParameterBufferType:
3327 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3330 case VAEncPictureParameterBufferType:
3331 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3334 case VAHuffmanTableBufferType:
3335 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3338 case VAEncSliceParameterBufferType:
3339 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3340 if (vaStatus == VA_STATUS_SUCCESS) {
3341 /* When the max number of slices is updated, it also needs
3342 * to reallocate the arrays that is used to store
3343 * the packed data index/count for the slice
3345 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3346 encode->slice_index++;
3348 if (encode->slice_index == encode->max_slice_num) {
3349 int slice_num = encode->max_slice_num;
3350 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3351 (slice_num + NUM_SLICES) * sizeof(int));
3352 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3353 (slice_num + NUM_SLICES) * sizeof(int));
3354 encode->slice_header_index = realloc(encode->slice_header_index,
3355 (slice_num + NUM_SLICES) * sizeof(int));
3356 memset(encode->slice_rawdata_index + slice_num, 0,
3357 sizeof(int) * NUM_SLICES);
3358 memset(encode->slice_rawdata_count + slice_num, 0,
3359 sizeof(int) * NUM_SLICES);
3360 memset(encode->slice_header_index + slice_num, 0,
3361 sizeof(int) * NUM_SLICES);
3363 encode->max_slice_num += NUM_SLICES;
3364 if ((encode->slice_rawdata_index == NULL) ||
3365 (encode->slice_header_index == NULL) ||
3366 (encode->slice_rawdata_count == NULL)) {
3367 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3374 case VAEncPackedHeaderParameterBufferType:
3376 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3377 encode->last_packed_header_type = param->type;
3379 if ((param->type == VAEncPackedHeaderRawData) ||
3380 (param->type == VAEncPackedHeaderSlice)) {
3381 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3382 } else if((obj_config->profile == VAProfileHEVCMain ||
3383 obj_config->profile == VAProfileHEVCMain10) &&
3384 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3385 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3388 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3390 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3393 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3398 case VAEncPackedHeaderDataBufferType:
3400 if (encode->last_packed_header_type == 0) {
3401 WARN_ONCE("the packed header data is passed without type!\n");
3402 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3406 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3407 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3408 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3410 if (obj_config->profile == VAProfileVP9Profile0)
3413 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3414 * the packed_slice_header as the delimeter to decide how
3415 * the packed rawdata is inserted for the given slice.
3416 * Otherwise it will use the VAEncSequenceParameterBuffer
3419 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3420 /* store the first index of the packed header data for current slice */
3421 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3422 encode->slice_rawdata_index[encode->slice_index] =
3423 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3425 encode->slice_rawdata_count[encode->slice_index]++;
3426 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3427 /* find one packed slice_header delimeter. And the following
3428 * packed data is for the next slice
3430 encode->slice_header_index[encode->slice_index] =
3431 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3432 encode->slice_index++;
3433 /* Reallocate the buffer to record the index/count of
3434 * packed_data for one slice.
3436 if (encode->slice_index == encode->max_slice_num) {
3437 int slice_num = encode->max_slice_num;
3439 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3440 (slice_num + NUM_SLICES) * sizeof(int));
3441 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3442 (slice_num + NUM_SLICES) * sizeof(int));
3443 encode->slice_header_index = realloc(encode->slice_header_index,
3444 (slice_num + NUM_SLICES) * sizeof(int));
3445 memset(encode->slice_rawdata_index + slice_num, 0,
3446 sizeof(int) * NUM_SLICES);
3447 memset(encode->slice_rawdata_count + slice_num, 0,
3448 sizeof(int) * NUM_SLICES);
3449 memset(encode->slice_header_index + slice_num, 0,
3450 sizeof(int) * NUM_SLICES);
3451 encode->max_slice_num += NUM_SLICES;
3455 if (vaStatus == VA_STATUS_SUCCESS) {
3456 /* store the first index of the packed header data for current slice */
3457 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3458 encode->slice_rawdata_index[encode->slice_index] =
3459 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3461 encode->slice_rawdata_count[encode->slice_index]++;
3462 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3463 if (encode->slice_header_index[encode->slice_index] == 0) {
3464 encode->slice_header_index[encode->slice_index] =
3465 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3467 WARN_ONCE("Multi slice header data is passed for"
3468 " slice %d!\n", encode->slice_index);
3474 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3475 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3476 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3477 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3478 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3479 VA_STATUS_ERROR_ENCODING_ERROR);
3481 if((obj_config->profile == VAProfileHEVCMain ||
3482 obj_config->profile == VAProfileHEVCMain10) &&
3483 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3485 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3488 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3489 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3491 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3494 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3498 encode->last_packed_header_type = 0;
3502 case VAEncMiscParameterBufferType:
3503 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3508 case VAEncMacroblockMapBufferType:
3509 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3513 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3521 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3523 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3524 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3527 i965_proc_render_picture(VADriverContextP ctx,
3528 VAContextID context,
3529 VABufferID *buffers,
3532 struct i965_driver_data *i965 = i965_driver_data(ctx);
3533 struct object_context *obj_context = CONTEXT(context);
3534 VAStatus vaStatus = VA_STATUS_SUCCESS;
3537 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3539 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3540 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3543 return VA_STATUS_ERROR_INVALID_BUFFER;
3545 switch (obj_buffer->type) {
3546 case VAProcPipelineParameterBufferType:
3547 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3551 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3560 i965_RenderPicture(VADriverContextP ctx,
3561 VAContextID context,
3562 VABufferID *buffers,
3565 struct i965_driver_data *i965 = i965_driver_data(ctx);
3566 struct object_context *obj_context;
3567 struct object_config *obj_config;
3568 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3570 obj_context = CONTEXT(context);
3571 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3573 if (num_buffers <= 0)
3574 return VA_STATUS_ERROR_INVALID_PARAMETER;
3576 obj_config = obj_context->obj_config;
3577 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3579 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3580 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3581 } else if ((VAEntrypointEncSlice == obj_config->entrypoint ) ||
3582 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3583 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3584 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3586 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3593 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3595 struct i965_driver_data *i965 = i965_driver_data(ctx);
3596 struct object_context *obj_context = CONTEXT(context);
3597 struct object_config *obj_config;
3599 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3600 obj_config = obj_context->obj_config;
3601 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3603 if (obj_context->codec_type == CODEC_PROC) {
3604 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3605 } else if (obj_context->codec_type == CODEC_ENC) {
3606 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3607 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3608 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3609 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3611 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3612 obj_context->codec_state.encode.num_packed_header_data_ext) {
3613 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3614 return VA_STATUS_ERROR_INVALID_PARAMETER;
3616 if (!obj_context->codec_state.encode.pic_param_ext) {
3617 return VA_STATUS_ERROR_INVALID_PARAMETER;
3619 if (!obj_context->codec_state.encode.seq_param_ext &&
3620 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3621 /* The seq_param is not mandatory for VP9 encoding */
3622 if (obj_config->profile != VAProfileVP9Profile0)
3623 return VA_STATUS_ERROR_INVALID_PARAMETER;
3625 if ((obj_context->codec_state.encode.num_slice_params_ext <=0) &&
3626 ((obj_config->profile != VAProfileVP8Version0_3) &&
3627 (obj_config->profile != VAProfileVP9Profile0))) {
3628 return VA_STATUS_ERROR_INVALID_PARAMETER;
3631 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3632 (obj_context->codec_state.encode.num_slice_params_ext !=
3633 obj_context->codec_state.encode.slice_index)) {
3634 WARN_ONCE("packed slice_header data is missing for some slice"
3635 " under packed SLICE_HEADER mode\n");
3636 return VA_STATUS_ERROR_INVALID_PARAMETER;
3639 if (obj_context->codec_state.decode.pic_param == NULL) {
3640 return VA_STATUS_ERROR_INVALID_PARAMETER;
3642 if (obj_context->codec_state.decode.num_slice_params <=0) {
3643 return VA_STATUS_ERROR_INVALID_PARAMETER;
3645 if (obj_context->codec_state.decode.num_slice_datas <=0) {
3646 return VA_STATUS_ERROR_INVALID_PARAMETER;
3649 if (obj_context->codec_state.decode.num_slice_params !=
3650 obj_context->codec_state.decode.num_slice_datas) {
3651 return VA_STATUS_ERROR_INVALID_PARAMETER;
3654 if (obj_context->wrapper_context != VA_INVALID_ID) {
3655 /* call the vaEndPicture of wrapped driver */
3656 VADriverContextP pdrvctx;
3659 pdrvctx = i965->wrapper_pdrvctx;
3660 CALL_VTABLE(pdrvctx, va_status,
3661 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3667 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3668 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3672 i965_SyncSurface(VADriverContextP ctx,
3673 VASurfaceID render_target)
3675 struct i965_driver_data *i965 = i965_driver_data(ctx);
3676 struct object_surface *obj_surface = SURFACE(render_target);
3678 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3681 drm_intel_bo_wait_rendering(obj_surface->bo);
3683 return VA_STATUS_SUCCESS;
3687 i965_QuerySurfaceStatus(VADriverContextP ctx,
3688 VASurfaceID render_target,
3689 VASurfaceStatus *status) /* out */
3691 struct i965_driver_data *i965 = i965_driver_data(ctx);
3692 struct object_surface *obj_surface = SURFACE(render_target);
3694 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3696 if (obj_surface->bo) {
3697 if (drm_intel_bo_busy(obj_surface->bo)){
3698 *status = VASurfaceRendering;
3701 *status = VASurfaceReady;
3704 *status = VASurfaceReady;
3707 return VA_STATUS_SUCCESS;
3710 static VADisplayAttribute *
3711 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3713 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3716 if (!i965->display_attributes)
3719 for (i = 0; i < i965->num_display_attributes; i++) {
3720 if (i965->display_attributes[i].type == type)
3721 return &i965->display_attributes[i];
3727 i965_display_attributes_terminate(VADriverContextP ctx)
3729 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3731 if (i965->display_attributes) {
3732 free(i965->display_attributes);
3733 i965->display_attributes = NULL;
3734 i965->num_display_attributes = 0;
3739 i965_display_attributes_init(VADriverContextP ctx)
3741 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3743 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3744 i965->display_attributes = malloc(
3745 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3746 if (!i965->display_attributes)
3750 i965->display_attributes,
3751 i965_display_attributes,
3752 sizeof(i965_display_attributes)
3755 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3756 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3757 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3758 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3759 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3761 if (!i965->rotation_attrib ||
3762 !i965->brightness_attrib ||
3763 !i965->contrast_attrib ||
3764 !i965->hue_attrib ||
3765 !i965->saturation_attrib) {
3771 i965_display_attributes_terminate(ctx);
3776 * Query display attributes
3777 * The caller must provide a "attr_list" array that can hold at
3778 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3779 * returned in "attr_list" is returned in "num_attributes".
3782 i965_QueryDisplayAttributes(
3783 VADriverContextP ctx,
3784 VADisplayAttribute *attribs, /* out */
3785 int *num_attribs_ptr /* out */
3788 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3790 if (attribs && num_attribs > 0)
3791 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3793 if (num_attribs_ptr)
3794 *num_attribs_ptr = num_attribs;
3796 return VA_STATUS_SUCCESS;
3800 * Get display attributes
3801 * This function returns the current attribute values in "attr_list".
3802 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3803 * from vaQueryDisplayAttributes() can have their values retrieved.
3806 i965_GetDisplayAttributes(
3807 VADriverContextP ctx,
3808 VADisplayAttribute *attribs, /* inout */
3809 int num_attribs /* in */
3814 for (i = 0; i < num_attribs; i++) {
3815 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3817 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3819 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3820 dst_attrib->min_value = src_attrib->min_value;
3821 dst_attrib->max_value = src_attrib->max_value;
3822 dst_attrib->value = src_attrib->value;
3823 dst_attrib->flags = src_attrib->flags;
3824 } else if (src_attrib &&
3825 (src_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE)) {
3826 dst_attrib->flags = src_attrib->flags;
3829 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3831 return VA_STATUS_SUCCESS;
3835 * Set display attributes
3836 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3837 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3838 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3841 i965_SetDisplayAttributes(
3842 VADriverContextP ctx,
3843 VADisplayAttribute *attribs, /* in */
3844 int num_attribs /* in */
3849 for (i = 0; i < num_attribs; i++) {
3850 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3852 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3854 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3856 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3859 if (src_attrib->value < dst_attrib->min_value ||
3860 src_attrib->value > dst_attrib->max_value)
3861 return VA_STATUS_ERROR_INVALID_PARAMETER;
3863 dst_attrib->value = src_attrib->value;
3864 /* XXX: track modified attributes through timestamps */
3866 return VA_STATUS_SUCCESS;
3870 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3871 VASurfaceID surface,
3872 void **buffer, /* out */
3873 unsigned int *stride) /* out */
3876 return VA_STATUS_ERROR_UNIMPLEMENTED;
3880 i965_destroy_heap(struct object_heap *heap,
3881 void (*func)(struct object_heap *heap, struct object_base *object))
3883 struct object_base *object;
3884 object_heap_iterator iter;
3886 object = object_heap_first(heap, &iter);
3892 object = object_heap_next(heap, &iter);
3895 object_heap_destroy(heap);
3900 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3903 i965_CreateImage(VADriverContextP ctx,
3904 VAImageFormat *format,
3907 VAImage *out_image) /* out */
3909 struct i965_driver_data *i965 = i965_driver_data(ctx);
3910 struct object_image *obj_image;
3911 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3913 unsigned int size2, size, awidth, aheight;
3915 out_image->image_id = VA_INVALID_ID;
3916 out_image->buf = VA_INVALID_ID;
3918 image_id = NEW_IMAGE_ID();
3919 if (image_id == VA_INVALID_ID)
3920 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3922 obj_image = IMAGE(image_id);
3924 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3925 obj_image->bo = NULL;
3926 obj_image->palette = NULL;
3927 obj_image->derived_surface = VA_INVALID_ID;
3929 VAImage * const image = &obj_image->image;
3930 image->image_id = image_id;
3931 image->buf = VA_INVALID_ID;
3933 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3935 if ((format->fourcc == VA_FOURCC_YV12) ||
3936 (format->fourcc == VA_FOURCC_I420)) {
3937 if (awidth % 128 != 0) {
3938 awidth = ALIGN(width, 128);
3942 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3943 size = awidth * aheight;
3944 size2 = (awidth / 2) * (aheight / 2);
3946 image->num_palette_entries = 0;
3947 image->entry_bytes = 0;
3948 memset(image->component_order, 0, sizeof(image->component_order));
3950 switch (format->fourcc) {
3951 case VA_FOURCC_IA44:
3952 case VA_FOURCC_AI44:
3953 image->num_planes = 1;
3954 image->pitches[0] = awidth;
3955 image->offsets[0] = 0;
3956 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3957 image->num_palette_entries = 16;
3958 image->entry_bytes = 3;
3959 image->component_order[0] = 'R';
3960 image->component_order[1] = 'G';
3961 image->component_order[2] = 'B';
3963 case VA_FOURCC_IA88:
3964 case VA_FOURCC_AI88:
3965 image->num_planes = 1;
3966 image->pitches[0] = awidth * 2;
3967 image->offsets[0] = 0;
3968 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3969 image->num_palette_entries = 256;
3970 image->entry_bytes = 3;
3971 image->component_order[0] = 'R';
3972 image->component_order[1] = 'G';
3973 image->component_order[2] = 'B';
3975 case VA_FOURCC_ARGB:
3976 case VA_FOURCC_ABGR:
3977 case VA_FOURCC_BGRA:
3978 case VA_FOURCC_RGBA:
3979 case VA_FOURCC_BGRX:
3980 case VA_FOURCC_RGBX:
3981 image->num_planes = 1;
3982 image->pitches[0] = awidth * 4;
3983 image->offsets[0] = 0;
3984 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3986 case VA_FOURCC_YV12:
3987 image->num_planes = 3;
3988 image->pitches[0] = awidth;
3989 image->offsets[0] = 0;
3990 image->pitches[1] = awidth / 2;
3991 image->offsets[1] = size;
3992 image->pitches[2] = awidth / 2;
3993 image->offsets[2] = size + size2;
3994 image->data_size = size + 2 * size2;
3996 case VA_FOURCC_I420:
3997 image->num_planes = 3;
3998 image->pitches[0] = awidth;
3999 image->offsets[0] = 0;
4000 image->pitches[1] = awidth / 2;
4001 image->offsets[1] = size;
4002 image->pitches[2] = awidth / 2;
4003 image->offsets[2] = size + size2;
4004 image->data_size = size + 2 * size2;
4006 case VA_FOURCC_422H:
4007 image->num_planes = 3;
4008 image->pitches[0] = awidth;
4009 image->offsets[0] = 0;
4010 image->pitches[1] = awidth / 2;
4011 image->offsets[1] = size;
4012 image->pitches[2] = awidth / 2;
4013 image->offsets[2] = size + (awidth / 2) * aheight;
4014 image->data_size = size + 2 * ((awidth / 2) * aheight);
4016 case VA_FOURCC_NV12:
4017 image->num_planes = 2;
4018 image->pitches[0] = awidth;
4019 image->offsets[0] = 0;
4020 image->pitches[1] = awidth;
4021 image->offsets[1] = size;
4022 image->data_size = size + 2 * size2;
4024 case VA_FOURCC_YUY2:
4025 case VA_FOURCC_UYVY:
4026 image->num_planes = 1;
4027 image->pitches[0] = awidth * 2;
4028 image->offsets[0] = 0;
4029 image->data_size = size * 2;
4031 case VA_FOURCC_P010:
4032 image->num_planes = 2;
4033 image->pitches[0] = awidth * 2;
4034 image->offsets[0] = 0;
4035 image->pitches[1] = awidth * 2;
4036 image->offsets[1] = size * 2;
4037 image->data_size = size * 2 + 2 * size2 * 2;
4043 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
4044 image->data_size, 1, NULL, &image->buf);
4045 if (va_status != VA_STATUS_SUCCESS)
4048 struct object_buffer *obj_buffer = BUFFER(image->buf);
4051 !obj_buffer->buffer_store ||
4052 !obj_buffer->buffer_store->bo)
4053 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4055 obj_image->bo = obj_buffer->buffer_store->bo;
4056 dri_bo_reference(obj_image->bo);
4058 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4059 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4060 if (!obj_image->palette)
4064 image->image_id = image_id;
4065 image->format = *format;
4066 image->width = width;
4067 image->height = height;
4069 *out_image = *image;
4070 return VA_STATUS_SUCCESS;
4073 i965_DestroyImage(ctx, image_id);
4078 i965_check_alloc_surface_bo(VADriverContextP ctx,
4079 struct object_surface *obj_surface,
4081 unsigned int fourcc,
4082 unsigned int subsampling)
4084 struct i965_driver_data *i965 = i965_driver_data(ctx);
4085 int region_width, region_height;
4087 if (obj_surface->bo) {
4088 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4089 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4090 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4091 return VA_STATUS_SUCCESS;
4094 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4095 obj_surface->x_cr_offset = 0;
4097 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4099 if ((tiled && !obj_surface->user_disable_tiling)) {
4100 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4101 fourcc != VA_FOURCC_IYUV &&
4102 fourcc != VA_FOURCC_YV12,
4103 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4105 if (obj_surface->user_h_stride_set) {
4106 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4108 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4110 if (obj_surface->user_v_stride_set) {
4111 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4113 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4115 region_height = obj_surface->height;
4118 case VA_FOURCC_NV12:
4119 case VA_FOURCC_P010:
4120 assert(subsampling == SUBSAMPLE_YUV420);
4121 obj_surface->cb_cr_pitch = obj_surface->width;
4122 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4123 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4124 obj_surface->y_cb_offset = obj_surface->height;
4125 obj_surface->y_cr_offset = obj_surface->height;
4126 region_width = obj_surface->width;
4127 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4131 case VA_FOURCC_IMC1:
4132 assert(subsampling == SUBSAMPLE_YUV420);
4133 obj_surface->cb_cr_pitch = obj_surface->width;
4134 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4135 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4136 obj_surface->y_cr_offset = obj_surface->height;
4137 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4138 region_width = obj_surface->width;
4139 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4143 case VA_FOURCC_IMC3:
4144 assert(subsampling == SUBSAMPLE_YUV420);
4145 obj_surface->cb_cr_pitch = obj_surface->width;
4146 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4147 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4148 obj_surface->y_cb_offset = obj_surface->height;
4149 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4150 region_width = obj_surface->width;
4151 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4155 case VA_FOURCC_422H:
4156 assert(subsampling == SUBSAMPLE_YUV422H);
4157 obj_surface->cb_cr_pitch = obj_surface->width;
4158 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4159 obj_surface->cb_cr_height = obj_surface->orig_height;
4160 obj_surface->y_cb_offset = obj_surface->height;
4161 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4162 region_width = obj_surface->width;
4163 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4167 case VA_FOURCC_422V:
4168 assert(subsampling == SUBSAMPLE_YUV422V);
4169 obj_surface->cb_cr_pitch = obj_surface->width;
4170 obj_surface->cb_cr_width = obj_surface->orig_width;
4171 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4172 obj_surface->y_cb_offset = obj_surface->height;
4173 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4174 region_width = obj_surface->width;
4175 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4179 case VA_FOURCC_411P:
4180 assert(subsampling == SUBSAMPLE_YUV411);
4181 obj_surface->cb_cr_pitch = obj_surface->width;
4182 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4183 obj_surface->cb_cr_height = obj_surface->orig_height;
4184 obj_surface->y_cb_offset = obj_surface->height;
4185 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4186 region_width = obj_surface->width;
4187 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4191 case VA_FOURCC_444P:
4192 assert(subsampling == SUBSAMPLE_YUV444);
4193 obj_surface->cb_cr_pitch = obj_surface->width;
4194 obj_surface->cb_cr_width = obj_surface->orig_width;
4195 obj_surface->cb_cr_height = obj_surface->orig_height;
4196 obj_surface->y_cb_offset = obj_surface->height;
4197 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4198 region_width = obj_surface->width;
4199 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4203 case VA_FOURCC_Y800:
4204 assert(subsampling == SUBSAMPLE_YUV400);
4205 obj_surface->cb_cr_pitch = 0;
4206 obj_surface->cb_cr_width = 0;
4207 obj_surface->cb_cr_height = 0;
4208 obj_surface->y_cb_offset = 0;
4209 obj_surface->y_cr_offset = 0;
4210 region_width = obj_surface->width;
4211 region_height = obj_surface->height;
4215 case VA_FOURCC_YUY2:
4216 case VA_FOURCC_UYVY:
4217 assert(subsampling == SUBSAMPLE_YUV422H);
4218 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4219 obj_surface->cb_cr_pitch = obj_surface->width;
4220 obj_surface->y_cb_offset = 0;
4221 obj_surface->y_cr_offset = 0;
4222 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4223 obj_surface->cb_cr_height = obj_surface->orig_height;
4224 region_width = obj_surface->width;
4225 region_height = obj_surface->height;
4229 case VA_FOURCC_RGBA:
4230 case VA_FOURCC_RGBX:
4231 case VA_FOURCC_BGRA:
4232 case VA_FOURCC_BGRX:
4233 assert(subsampling == SUBSAMPLE_RGBX);
4235 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4236 region_width = obj_surface->width;
4237 region_height = obj_surface->height;
4241 /* Never get here */
4242 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4246 assert(subsampling == SUBSAMPLE_YUV420 ||
4247 subsampling == SUBSAMPLE_YUV422H ||
4248 subsampling == SUBSAMPLE_YUV422V ||
4249 subsampling == SUBSAMPLE_RGBX);
4251 region_width = obj_surface->width;
4252 region_height = obj_surface->height;
4255 case VA_FOURCC_NV12:
4256 case VA_FOURCC_P010:
4257 obj_surface->y_cb_offset = obj_surface->height;
4258 obj_surface->y_cr_offset = obj_surface->height;
4259 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4260 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) *
4262 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4263 obj_surface->cb_cr_pitch = obj_surface->width;
4264 region_width = obj_surface->width;
4265 region_height = obj_surface->height + obj_surface->height / 2;
4268 case VA_FOURCC_YV16:
4269 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4270 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4271 obj_surface->cb_cr_height = obj_surface->orig_height;
4272 obj_surface->y_cr_offset = obj_surface->height;
4273 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4274 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4275 region_width = obj_surface->width;
4276 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4279 case VA_FOURCC_YV12:
4280 case VA_FOURCC_I420:
4281 case VA_FOURCC_IYUV:
4282 if (fourcc == VA_FOURCC_YV12) {
4283 obj_surface->y_cr_offset = obj_surface->height;
4284 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4286 obj_surface->y_cb_offset = obj_surface->height;
4287 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4290 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4291 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4292 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4293 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4294 region_width = obj_surface->width;
4295 region_height = obj_surface->height + obj_surface->height / 2;
4298 case VA_FOURCC_I010:
4299 obj_surface->y_cb_offset = obj_surface->height;
4300 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4301 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4302 obj_surface->width = ALIGN(obj_surface->cb_cr_width * 2, i965->codec_info->min_linear_wpitch) * 2;
4303 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4304 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4305 region_width = obj_surface->width;
4306 region_height = obj_surface->height + obj_surface->height / 2;
4309 case VA_FOURCC_YUY2:
4310 case VA_FOURCC_UYVY:
4311 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4312 obj_surface->y_cb_offset = 0;
4313 obj_surface->y_cr_offset = 0;
4314 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4315 obj_surface->cb_cr_height = obj_surface->orig_height;
4316 obj_surface->cb_cr_pitch = obj_surface->width;
4317 region_width = obj_surface->width;
4318 region_height = obj_surface->height;
4320 case VA_FOURCC_RGBA:
4321 case VA_FOURCC_RGBX:
4322 case VA_FOURCC_BGRA:
4323 case VA_FOURCC_BGRX:
4324 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4325 region_width = obj_surface->width;
4326 region_height = obj_surface->height;
4330 /* Never get here */
4331 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4336 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4338 if ((tiled && !obj_surface->user_disable_tiling)) {
4339 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4340 unsigned long pitch;
4342 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4350 assert(tiling_mode == I915_TILING_Y);
4351 assert(pitch == obj_surface->width);
4353 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4359 obj_surface->fourcc = fourcc;
4360 obj_surface->subsampling = subsampling;
4361 assert(obj_surface->bo);
4362 return VA_STATUS_SUCCESS;
4365 VAStatus i965_DeriveImage(VADriverContextP ctx,
4366 VASurfaceID surface,
4367 VAImage *out_image) /* out */
4369 struct i965_driver_data *i965 = i965_driver_data(ctx);
4370 struct object_image *obj_image;
4371 struct object_surface *obj_surface;
4373 unsigned int w_pitch;
4374 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4376 out_image->image_id = VA_INVALID_ID;
4377 obj_surface = SURFACE(surface);
4380 return VA_STATUS_ERROR_INVALID_SURFACE;
4382 if (!obj_surface->bo) {
4383 unsigned int is_tiled = 0;
4384 unsigned int fourcc = VA_FOURCC_YV12;
4385 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4386 int sampling = get_sampling_from_fourcc(fourcc);
4387 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4388 if (va_status != VA_STATUS_SUCCESS)
4392 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4394 w_pitch = obj_surface->width;
4396 image_id = NEW_IMAGE_ID();
4398 if (image_id == VA_INVALID_ID)
4399 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4401 obj_image = IMAGE(image_id);
4404 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4406 obj_image->bo = NULL;
4407 obj_image->palette = NULL;
4408 obj_image->derived_surface = VA_INVALID_ID;
4410 VAImage * const image = &obj_image->image;
4412 memset(image, 0, sizeof(*image));
4413 image->image_id = image_id;
4414 image->buf = VA_INVALID_ID;
4415 image->num_palette_entries = 0;
4416 image->entry_bytes = 0;
4417 image->width = obj_surface->orig_width;
4418 image->height = obj_surface->orig_height;
4419 image->data_size = obj_surface->size;
4421 image->format.fourcc = obj_surface->fourcc;
4422 image->format.byte_order = VA_LSB_FIRST;
4423 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4425 if (!image->format.bits_per_pixel)
4428 switch (image->format.fourcc) {
4429 case VA_FOURCC_YV12:
4430 image->num_planes = 3;
4431 image->pitches[0] = w_pitch; /* Y */
4432 image->offsets[0] = 0;
4433 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4434 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4435 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4436 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4439 case VA_FOURCC_YV16:
4440 image->num_planes = 3;
4441 image->pitches[0] = w_pitch; /* Y */
4442 image->offsets[0] = 0;
4443 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4444 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4445 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4446 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4449 case VA_FOURCC_NV12:
4450 case VA_FOURCC_P010:
4451 image->num_planes = 2;
4452 image->pitches[0] = w_pitch; /* Y */
4453 image->offsets[0] = 0;
4454 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4455 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4458 case VA_FOURCC_I420:
4459 case VA_FOURCC_I010:
4460 case VA_FOURCC_422H:
4461 case VA_FOURCC_IMC3:
4462 case VA_FOURCC_444P:
4463 case VA_FOURCC_422V:
4464 case VA_FOURCC_411P:
4465 image->num_planes = 3;
4466 image->pitches[0] = w_pitch; /* Y */
4467 image->offsets[0] = 0;
4468 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4469 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4470 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4471 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4474 case VA_FOURCC_YUY2:
4475 case VA_FOURCC_UYVY:
4476 case VA_FOURCC_Y800:
4477 image->num_planes = 1;
4478 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4479 image->offsets[0] = 0;
4481 case VA_FOURCC_RGBA:
4482 case VA_FOURCC_RGBX:
4483 case VA_FOURCC_BGRA:
4484 case VA_FOURCC_BGRX:
4485 image->num_planes = 1;
4486 image->pitches[0] = obj_surface->width;
4488 switch (image->format.fourcc) {
4489 case VA_FOURCC_RGBA:
4490 case VA_FOURCC_RGBX:
4491 image->format.red_mask = 0x000000ff;
4492 image->format.green_mask = 0x0000ff00;
4493 image->format.blue_mask = 0x00ff0000;
4495 case VA_FOURCC_BGRA:
4496 case VA_FOURCC_BGRX:
4497 image->format.red_mask = 0x00ff0000;
4498 image->format.green_mask = 0x0000ff00;
4499 image->format.blue_mask = 0x000000ff;
4505 switch (image->format.fourcc) {
4506 case VA_FOURCC_RGBA:
4507 case VA_FOURCC_BGRA:
4508 image->format.alpha_mask = 0xff000000;
4509 image->format.depth = 32;
4511 case VA_FOURCC_RGBX:
4512 case VA_FOURCC_BGRX:
4513 image->format.alpha_mask = 0x00000000;
4514 image->format.depth = 24;
4525 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4526 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4527 if (va_status != VA_STATUS_SUCCESS)
4530 struct object_buffer *obj_buffer = BUFFER(image->buf);
4533 !obj_buffer->buffer_store ||
4534 !obj_buffer->buffer_store->bo)
4535 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4537 obj_image->bo = obj_buffer->buffer_store->bo;
4538 dri_bo_reference(obj_image->bo);
4540 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4541 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4542 if (!obj_image->palette) {
4543 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4548 *out_image = *image;
4549 obj_surface->flags |= SURFACE_DERIVED;
4550 obj_surface->derived_image_id = image_id;
4551 obj_image->derived_surface = surface;
4553 return VA_STATUS_SUCCESS;
4556 i965_DestroyImage(ctx, image_id);
4561 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4563 object_heap_free(heap, obj);
4568 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4570 struct i965_driver_data *i965 = i965_driver_data(ctx);
4571 struct object_image *obj_image = IMAGE(image);
4572 struct object_surface *obj_surface;
4575 return VA_STATUS_SUCCESS;
4577 dri_bo_unreference(obj_image->bo);
4578 obj_image->bo = NULL;
4580 if (obj_image->image.buf != VA_INVALID_ID) {
4581 i965_DestroyBuffer(ctx, obj_image->image.buf);
4582 obj_image->image.buf = VA_INVALID_ID;
4585 if (obj_image->palette) {
4586 free(obj_image->palette);
4587 obj_image->palette = NULL;
4590 obj_surface = SURFACE(obj_image->derived_surface);
4593 obj_surface->flags &= ~SURFACE_DERIVED;
4594 obj_surface->derived_image_id = VA_INVALID_ID;
4597 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4599 return VA_STATUS_SUCCESS;
4603 * pointer to an array holding the palette data. The size of the array is
4604 * num_palette_entries * entry_bytes in size. The order of the components
4605 * in the palette is described by the component_order in VASubpicture struct
4608 i965_SetImagePalette(VADriverContextP ctx,
4610 unsigned char *palette)
4612 struct i965_driver_data *i965 = i965_driver_data(ctx);
4615 struct object_image *obj_image = IMAGE(image);
4617 return VA_STATUS_ERROR_INVALID_IMAGE;
4619 if (!obj_image->palette)
4620 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4622 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4623 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
4624 ((unsigned int)palette[3*i + 1] << 8) |
4625 (unsigned int)palette[3*i + 2]);
4626 return VA_STATUS_SUCCESS;
4630 get_sampling_from_fourcc(unsigned int fourcc)
4632 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4634 if (info && (info->flag & I_S))
4635 return info->subsampling;
4641 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4642 const uint8_t *src, unsigned int src_stride,
4643 unsigned int len, unsigned int height)
4647 for (i = 0; i < height; i++) {
4648 memcpy(dst, src, len);
4655 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4656 struct object_surface *obj_surface,
4657 const VARectangle *rect)
4659 uint8_t *dst[3], *src[3];
4661 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4662 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4663 unsigned int tiling, swizzle;
4664 VAStatus va_status = VA_STATUS_SUCCESS;
4666 if (!obj_surface->bo)
4667 return VA_STATUS_ERROR_INVALID_SURFACE;
4669 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4670 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4672 if (tiling != I915_TILING_NONE)
4673 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4675 dri_bo_map(obj_surface->bo, 0);
4677 if (!obj_surface->bo->virtual)
4678 return VA_STATUS_ERROR_INVALID_SURFACE;
4680 /* Dest VA image has either I420 or YV12 format.
4681 Source VA surface alway has I420 format */
4682 dst[Y] = image_data + obj_image->image.offsets[Y];
4683 src[0] = (uint8_t *)obj_surface->bo->virtual;
4684 dst[U] = image_data + obj_image->image.offsets[U];
4685 src[1] = src[0] + obj_surface->width * obj_surface->height;
4686 dst[V] = image_data + obj_image->image.offsets[V];
4687 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4690 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4691 src[0] += rect->y * obj_surface->width + rect->x;
4692 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4693 src[0], obj_surface->width,
4694 rect->width, rect->height);
4697 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4698 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4699 memcpy_pic(dst[U], obj_image->image.pitches[U],
4700 src[1], obj_surface->width / 2,
4701 rect->width / 2, rect->height / 2);
4704 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4705 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4706 memcpy_pic(dst[V], obj_image->image.pitches[V],
4707 src[2], obj_surface->width / 2,
4708 rect->width / 2, rect->height / 2);
4710 if (tiling != I915_TILING_NONE)
4711 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4713 dri_bo_unmap(obj_surface->bo);
4719 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4720 struct object_surface *obj_surface,
4721 const VARectangle *rect)
4723 uint8_t *dst[2], *src[2];
4724 unsigned int tiling, swizzle;
4725 VAStatus va_status = VA_STATUS_SUCCESS;
4727 if (!obj_surface->bo)
4728 return VA_STATUS_ERROR_INVALID_SURFACE;
4730 assert(obj_surface->fourcc);
4731 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4733 if (tiling != I915_TILING_NONE)
4734 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4736 dri_bo_map(obj_surface->bo, 0);
4738 if (!obj_surface->bo->virtual)
4739 return VA_STATUS_ERROR_INVALID_SURFACE;
4741 /* Both dest VA image and source surface have NV12 format */
4742 dst[0] = image_data + obj_image->image.offsets[0];
4743 src[0] = (uint8_t *)obj_surface->bo->virtual;
4744 dst[1] = image_data + obj_image->image.offsets[1];
4745 src[1] = src[0] + obj_surface->width * obj_surface->height;
4748 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4749 src[0] += rect->y * obj_surface->width + rect->x;
4750 memcpy_pic(dst[0], obj_image->image.pitches[0],
4751 src[0], obj_surface->width,
4752 rect->width, rect->height);
4755 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4756 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4757 memcpy_pic(dst[1], obj_image->image.pitches[1],
4758 src[1], obj_surface->width,
4759 rect->width, rect->height / 2);
4761 if (tiling != I915_TILING_NONE)
4762 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4764 dri_bo_unmap(obj_surface->bo);
4770 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4771 struct object_surface *obj_surface,
4772 const VARectangle *rect)
4775 unsigned int tiling, swizzle;
4776 VAStatus va_status = VA_STATUS_SUCCESS;
4778 if (!obj_surface->bo)
4779 return VA_STATUS_ERROR_INVALID_SURFACE;
4781 assert(obj_surface->fourcc);
4782 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4784 if (tiling != I915_TILING_NONE)
4785 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4787 dri_bo_map(obj_surface->bo, 0);
4789 if (!obj_surface->bo->virtual)
4790 return VA_STATUS_ERROR_INVALID_SURFACE;
4792 /* Both dest VA image and source surface have YUYV format */
4793 dst = image_data + obj_image->image.offsets[0];
4794 src = (uint8_t *)obj_surface->bo->virtual;
4797 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
4798 src += rect->y * obj_surface->width + rect->x*2;
4799 memcpy_pic(dst, obj_image->image.pitches[0],
4800 src, obj_surface->width*2,
4801 rect->width*2, rect->height);
4803 if (tiling != I915_TILING_NONE)
4804 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4806 dri_bo_unmap(obj_surface->bo);
4812 i965_sw_getimage(VADriverContextP ctx,
4813 struct object_surface *obj_surface, struct object_image *obj_image,
4814 const VARectangle *rect)
4816 void *image_data = NULL;
4819 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4820 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4822 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4823 if (va_status != VA_STATUS_SUCCESS)
4826 switch (obj_image->image.format.fourcc) {
4827 case VA_FOURCC_YV12:
4828 case VA_FOURCC_I420:
4829 get_image_i420(obj_image, image_data, obj_surface, rect);
4831 case VA_FOURCC_NV12:
4832 get_image_nv12(obj_image, image_data, obj_surface, rect);
4834 case VA_FOURCC_YUY2:
4835 /* YUY2 is the format supported by overlay plane */
4836 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4839 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4842 if (va_status != VA_STATUS_SUCCESS)
4845 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4850 i965_hw_getimage(VADriverContextP ctx,
4851 struct object_surface *obj_surface, struct object_image *obj_image,
4852 const VARectangle *rect)
4854 struct i965_surface src_surface;
4855 struct i965_surface dst_surface;
4857 src_surface.base = (struct object_base *)obj_surface;
4858 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4859 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4861 dst_surface.base = (struct object_base *)obj_image;
4862 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4863 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4865 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4869 i965_GetImage(VADriverContextP ctx,
4870 VASurfaceID surface,
4871 int x, /* coordinates of the upper left source pixel */
4873 unsigned int width, /* width and height of the region */
4874 unsigned int height,
4877 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4878 struct object_surface * const obj_surface = SURFACE(surface);
4879 struct object_image * const obj_image = IMAGE(image);
4884 return VA_STATUS_ERROR_INVALID_SURFACE;
4885 if (!obj_surface->bo) /* don't get anything, keep previous data */
4886 return VA_STATUS_SUCCESS;
4887 if (is_surface_busy(i965, obj_surface))
4888 return VA_STATUS_ERROR_SURFACE_BUSY;
4890 if (!obj_image || !obj_image->bo)
4891 return VA_STATUS_ERROR_INVALID_IMAGE;
4892 if (is_image_busy(i965, obj_image, surface))
4893 return VA_STATUS_ERROR_SURFACE_BUSY;
4896 return VA_STATUS_ERROR_INVALID_PARAMETER;
4897 if (x + width > obj_surface->orig_width ||
4898 y + height > obj_surface->orig_height)
4899 return VA_STATUS_ERROR_INVALID_PARAMETER;
4900 if (x + width > obj_image->image.width ||
4901 y + height > obj_image->image.height)
4902 return VA_STATUS_ERROR_INVALID_PARAMETER;
4907 rect.height = height;
4909 if (HAS_ACCELERATED_GETIMAGE(i965))
4910 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
4912 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
4918 put_image_i420(struct object_surface *obj_surface,
4919 const VARectangle *dst_rect,
4920 struct object_image *obj_image, uint8_t *image_data,
4921 const VARectangle *src_rect)
4923 uint8_t *dst[3], *src[3];
4925 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4926 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4927 unsigned int tiling, swizzle;
4928 VAStatus va_status = VA_STATUS_SUCCESS;
4930 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4932 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4933 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4934 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4935 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4937 if (tiling != I915_TILING_NONE)
4938 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4940 dri_bo_map(obj_surface->bo, 0);
4942 if (!obj_surface->bo->virtual)
4943 return VA_STATUS_ERROR_INVALID_SURFACE;
4945 /* Dest VA image has either I420 or YV12 format.
4946 Source VA surface alway has I420 format */
4947 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4948 src[Y] = image_data + obj_image->image.offsets[Y];
4949 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4950 src[U] = image_data + obj_image->image.offsets[U];
4951 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4952 src[V] = image_data + obj_image->image.offsets[V];
4955 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4956 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4957 memcpy_pic(dst[0], obj_surface->width,
4958 src[Y], obj_image->image.pitches[Y],
4959 src_rect->width, src_rect->height);
4962 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4963 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4964 memcpy_pic(dst[1], obj_surface->width / 2,
4965 src[U], obj_image->image.pitches[U],
4966 src_rect->width / 2, src_rect->height / 2);
4969 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4970 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4971 memcpy_pic(dst[2], obj_surface->width / 2,
4972 src[V], obj_image->image.pitches[V],
4973 src_rect->width / 2, src_rect->height / 2);
4975 if (tiling != I915_TILING_NONE)
4976 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4978 dri_bo_unmap(obj_surface->bo);
4984 put_image_nv12(struct object_surface *obj_surface,
4985 const VARectangle *dst_rect,
4986 struct object_image *obj_image, uint8_t *image_data,
4987 const VARectangle *src_rect)
4989 uint8_t *dst[2], *src[2];
4990 unsigned int tiling, swizzle;
4991 VAStatus va_status = VA_STATUS_SUCCESS;
4993 if (!obj_surface->bo)
4994 return VA_STATUS_ERROR_INVALID_SURFACE;
4996 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4997 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4998 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4999 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5001 if (tiling != I915_TILING_NONE)
5002 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5004 dri_bo_map(obj_surface->bo, 0);
5006 if (!obj_surface->bo->virtual)
5007 return VA_STATUS_ERROR_INVALID_SURFACE;
5009 /* Both dest VA image and source surface have NV12 format */
5010 dst[0] = (uint8_t *)obj_surface->bo->virtual;
5011 src[0] = image_data + obj_image->image.offsets[0];
5012 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
5013 src[1] = image_data + obj_image->image.offsets[1];
5016 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
5017 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
5018 memcpy_pic(dst[0], obj_surface->width,
5019 src[0], obj_image->image.pitches[0],
5020 src_rect->width, src_rect->height);
5023 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
5024 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
5025 memcpy_pic(dst[1], obj_surface->width,
5026 src[1], obj_image->image.pitches[1],
5027 src_rect->width, src_rect->height / 2);
5029 if (tiling != I915_TILING_NONE)
5030 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5032 dri_bo_unmap(obj_surface->bo);
5038 put_image_yuy2(struct object_surface *obj_surface,
5039 const VARectangle *dst_rect,
5040 struct object_image *obj_image, uint8_t *image_data,
5041 const VARectangle *src_rect)
5044 unsigned int tiling, swizzle;
5045 VAStatus va_status = VA_STATUS_SUCCESS;
5047 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
5048 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5049 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
5050 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
5051 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
5053 if (tiling != I915_TILING_NONE)
5054 drm_intel_gem_bo_map_gtt(obj_surface->bo);
5056 dri_bo_map(obj_surface->bo, 0);
5058 if (!obj_surface->bo->virtual)
5059 return VA_STATUS_ERROR_INVALID_SURFACE;
5061 /* Both dest VA image and source surface have YUY2 format */
5062 dst = (uint8_t *)obj_surface->bo->virtual;
5063 src = image_data + obj_image->image.offsets[0];
5065 /* YUYV packed plane */
5066 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
5067 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
5068 memcpy_pic(dst, obj_surface->width*2,
5069 src, obj_image->image.pitches[0],
5070 src_rect->width*2, src_rect->height);
5072 if (tiling != I915_TILING_NONE)
5073 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
5075 dri_bo_unmap(obj_surface->bo);
5081 i965_sw_putimage(VADriverContextP ctx,
5082 struct object_surface *obj_surface, struct object_image *obj_image,
5083 const VARectangle *src_rect, const VARectangle *dst_rect)
5085 VAStatus va_status = VA_STATUS_SUCCESS;
5086 void *image_data = NULL;
5088 /* XXX: don't allow scaling */
5089 if (src_rect->width != dst_rect->width ||
5090 src_rect->height != dst_rect->height)
5091 return VA_STATUS_ERROR_INVALID_PARAMETER;
5093 if (obj_surface->fourcc) {
5094 /* Don't allow format mismatch */
5095 if (obj_surface->fourcc != obj_image->image.format.fourcc)
5096 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5100 /* VA is surface not used for decoding, use same VA image format */
5101 va_status = i965_check_alloc_surface_bo(
5104 0, /* XXX: don't use tiled surface */
5105 obj_image->image.format.fourcc,
5106 get_sampling_from_fourcc (obj_image->image.format.fourcc));
5109 if (va_status != VA_STATUS_SUCCESS)
5112 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5113 if (va_status != VA_STATUS_SUCCESS)
5116 switch (obj_image->image.format.fourcc) {
5117 case VA_FOURCC_YV12:
5118 case VA_FOURCC_I420:
5119 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5121 case VA_FOURCC_NV12:
5122 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5124 case VA_FOURCC_YUY2:
5125 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5128 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5131 if (va_status != VA_STATUS_SUCCESS)
5134 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5139 i965_hw_putimage(VADriverContextP ctx,
5140 struct object_surface *obj_surface, struct object_image *obj_image,
5141 const VARectangle *src_rect, const VARectangle *dst_rect)
5143 struct i965_surface src_surface, dst_surface;
5144 VAStatus va_status = VA_STATUS_SUCCESS;
5146 if (!obj_surface->bo) {
5147 unsigned int tiling, swizzle;
5148 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
5149 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5151 i965_check_alloc_surface_bo(ctx,
5154 obj_image->image.format.fourcc,
5158 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5160 src_surface.base = (struct object_base *)obj_image;
5161 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5162 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5164 dst_surface.base = (struct object_base *)obj_surface;
5165 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5166 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5168 va_status = i965_image_processing(ctx,
5178 i965_PutImage(VADriverContextP ctx,
5179 VASurfaceID surface,
5183 unsigned int src_width,
5184 unsigned int src_height,
5187 unsigned int dest_width,
5188 unsigned int dest_height)
5190 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5191 struct object_surface * const obj_surface = SURFACE(surface);
5192 struct object_image * const obj_image = IMAGE(image);
5193 VARectangle src_rect, dst_rect;
5197 return VA_STATUS_ERROR_INVALID_SURFACE;
5198 if (is_surface_busy(i965, obj_surface))
5199 return VA_STATUS_ERROR_SURFACE_BUSY;
5201 if (!obj_image || !obj_image->bo)
5202 return VA_STATUS_ERROR_INVALID_IMAGE;
5203 if (is_image_busy(i965, obj_image, surface))
5204 return VA_STATUS_ERROR_SURFACE_BUSY;
5208 src_x + src_width > obj_image->image.width ||
5209 src_y + src_height > obj_image->image.height)
5210 return VA_STATUS_ERROR_INVALID_PARAMETER;
5214 src_rect.width = src_width;
5215 src_rect.height = src_height;
5219 dest_x + dest_width > obj_surface->orig_width ||
5220 dest_y + dest_height > obj_surface->orig_height)
5221 return VA_STATUS_ERROR_INVALID_PARAMETER;
5223 dst_rect.x = dest_x;
5224 dst_rect.y = dest_y;
5225 dst_rect.width = dest_width;
5226 dst_rect.height = dest_height;
5228 if (HAS_ACCELERATED_PUTIMAGE(i965))
5229 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5230 &src_rect, &dst_rect);
5232 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5233 &src_rect, &dst_rect);
5239 i965_PutSurface(VADriverContextP ctx,
5240 VASurfaceID surface,
5241 void *draw, /* X Drawable */
5244 unsigned short srcw,
5245 unsigned short srch,
5248 unsigned short destw,
5249 unsigned short desth,
5250 VARectangle *cliprects, /* client supplied clip list */
5251 unsigned int number_cliprects, /* number of clip rects in the clip list */
5252 unsigned int flags) /* de-interlacing flags */
5255 if (IS_VA_X11(ctx)) {
5256 VARectangle src_rect, dst_rect;
5260 src_rect.width = srcw;
5261 src_rect.height = srch;
5265 dst_rect.width = destw;
5266 dst_rect.height = desth;
5268 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5269 cliprects, number_cliprects, flags);
5272 return VA_STATUS_ERROR_UNIMPLEMENTED;
5277 VADriverContextP ctx, /* in */
5278 VABufferID buf_id, /* in */
5279 VABufferType *type, /* out */
5280 unsigned int *size, /* out */
5281 unsigned int *num_elements /* out */
5284 struct i965_driver_data *i965 = NULL;
5285 struct object_buffer *obj_buffer = NULL;
5287 i965 = i965_driver_data(ctx);
5288 obj_buffer = BUFFER(buf_id);
5290 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5292 *type = obj_buffer->type;
5293 *size = obj_buffer->size_element;
5294 *num_elements = obj_buffer->num_elements;
5296 return VA_STATUS_SUCCESS;
5301 VADriverContextP ctx, /* in */
5302 VASurfaceID surface, /* in */
5303 unsigned int *fourcc, /* out */
5304 unsigned int *luma_stride, /* out */
5305 unsigned int *chroma_u_stride, /* out */
5306 unsigned int *chroma_v_stride, /* out */
5307 unsigned int *luma_offset, /* out */
5308 unsigned int *chroma_u_offset, /* out */
5309 unsigned int *chroma_v_offset, /* out */
5310 unsigned int *buffer_name, /* out */
5311 void **buffer /* out */
5314 VAStatus vaStatus = VA_STATUS_SUCCESS;
5315 struct i965_driver_data *i965 = i965_driver_data(ctx);
5316 struct object_surface *obj_surface = NULL;
5319 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5320 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5321 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5322 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5323 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5324 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5325 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5326 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5327 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5329 tmpImage.image_id = VA_INVALID_ID;
5331 obj_surface = SURFACE(surface);
5332 if (obj_surface == NULL) {
5333 // Surface is absent.
5334 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5338 // Lock functionality is absent now.
5339 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5340 // Surface is locked already.
5341 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5345 vaStatus = i965_DeriveImage(
5349 if (vaStatus != VA_STATUS_SUCCESS) {
5353 obj_surface->locked_image_id = tmpImage.image_id;
5355 vaStatus = i965_MapBuffer(
5359 if (vaStatus != VA_STATUS_SUCCESS) {
5363 *fourcc = tmpImage.format.fourcc;
5364 *luma_offset = tmpImage.offsets[0];
5365 *luma_stride = tmpImage.pitches[0];
5366 *chroma_u_offset = tmpImage.offsets[1];
5367 *chroma_u_stride = tmpImage.pitches[1];
5368 *chroma_v_offset = tmpImage.offsets[2];
5369 *chroma_v_stride = tmpImage.pitches[2];
5370 *buffer_name = tmpImage.buf;
5373 if (vaStatus != VA_STATUS_SUCCESS) {
5382 VADriverContextP ctx, /* in */
5383 VASurfaceID surface /* in */
5386 VAStatus vaStatus = VA_STATUS_SUCCESS;
5387 struct i965_driver_data *i965 = i965_driver_data(ctx);
5388 struct object_image *locked_img = NULL;
5389 struct object_surface *obj_surface = NULL;
5391 obj_surface = SURFACE(surface);
5393 if (obj_surface == NULL) {
5394 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5397 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5398 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5402 locked_img = IMAGE(obj_surface->locked_image_id);
5403 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5404 // Work image was deallocated before i965_UnlockSurface()
5405 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5409 vaStatus = i965_UnmapBuffer(
5411 locked_img->image.buf);
5412 if (vaStatus != VA_STATUS_SUCCESS) {
5416 vaStatus = i965_DestroyImage(
5418 locked_img->image.image_id);
5419 if (vaStatus != VA_STATUS_SUCCESS) {
5423 locked_img->image.image_id = VA_INVALID_ID;
5426 obj_surface->locked_image_id = VA_INVALID_ID;
5432 i965_GetSurfaceAttributes(
5433 VADriverContextP ctx,
5435 VASurfaceAttrib *attrib_list,
5436 unsigned int num_attribs
5439 VAStatus vaStatus = VA_STATUS_SUCCESS;
5440 struct i965_driver_data *i965 = i965_driver_data(ctx);
5441 struct object_config *obj_config;
5444 if (config == VA_INVALID_ID)
5445 return VA_STATUS_ERROR_INVALID_CONFIG;
5447 obj_config = CONFIG(config);
5449 if (obj_config == NULL)
5450 return VA_STATUS_ERROR_INVALID_CONFIG;
5452 if (attrib_list == NULL || num_attribs == 0)
5453 return VA_STATUS_ERROR_INVALID_PARAMETER;
5455 for (i = 0; i < num_attribs; i++) {
5456 switch (attrib_list[i].type) {
5457 case VASurfaceAttribPixelFormat:
5458 attrib_list[i].value.type = VAGenericValueTypeInteger;
5459 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5461 if (attrib_list[i].value.value.i == 0) {
5462 if (IS_G4X(i965->intel.device_info)) {
5463 if (obj_config->profile == VAProfileMPEG2Simple ||
5464 obj_config->profile == VAProfileMPEG2Main) {
5465 attrib_list[i].value.value.i = VA_FOURCC_I420;
5468 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5470 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5471 if (obj_config->profile == VAProfileMPEG2Simple ||
5472 obj_config->profile == VAProfileMPEG2Main) {
5473 attrib_list[i].value.value.i = VA_FOURCC_I420;
5474 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5475 obj_config->profile == VAProfileH264Main ||
5476 obj_config->profile == VAProfileH264High) {
5477 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5478 } else if (obj_config->profile == VAProfileNone) {
5479 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5482 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5484 } else if (IS_GEN6(i965->intel.device_info)) {
5485 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5486 } else if (IS_GEN7(i965->intel.device_info) ||
5487 IS_GEN8(i965->intel.device_info) ||
5488 IS_GEN9(i965->intel.device_info)) {
5489 if (obj_config->profile == VAProfileJPEGBaseline)
5490 attrib_list[i].value.value.i = 0; /* internal format */
5492 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5495 if (IS_G4X(i965->intel.device_info)) {
5496 if (obj_config->profile == VAProfileMPEG2Simple ||
5497 obj_config->profile == VAProfileMPEG2Main) {
5498 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5499 attrib_list[i].value.value.i = 0;
5500 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5504 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5506 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5507 if (obj_config->profile == VAProfileMPEG2Simple ||
5508 obj_config->profile == VAProfileMPEG2Main) {
5509 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5510 attrib_list[i].value.value.i = 0;
5511 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5513 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5514 obj_config->profile == VAProfileH264Main ||
5515 obj_config->profile == VAProfileH264High) {
5516 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5517 attrib_list[i].value.value.i = 0;
5518 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5520 } else if (obj_config->profile == VAProfileNone) {
5521 switch (attrib_list[i].value.value.i) {
5522 case VA_FOURCC_NV12:
5523 case VA_FOURCC_I420:
5524 case VA_FOURCC_YV12:
5525 case VA_FOURCC_YUY2:
5526 case VA_FOURCC_BGRA:
5527 case VA_FOURCC_BGRX:
5528 case VA_FOURCC_RGBX:
5529 case VA_FOURCC_RGBA:
5532 attrib_list[i].value.value.i = 0;
5533 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5538 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5540 } else if (IS_GEN6(i965->intel.device_info)) {
5541 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5542 obj_config->entrypoint == VAEntrypointVideoProc) {
5543 switch (attrib_list[i].value.value.i) {
5544 case VA_FOURCC_NV12:
5545 case VA_FOURCC_I420:
5546 case VA_FOURCC_YV12:
5547 case VA_FOURCC_YUY2:
5548 case VA_FOURCC_BGRA:
5549 case VA_FOURCC_BGRX:
5550 case VA_FOURCC_RGBX:
5551 case VA_FOURCC_RGBA:
5554 attrib_list[i].value.value.i = 0;
5555 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5559 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5560 attrib_list[i].value.value.i = 0;
5561 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5564 } else if (IS_GEN7(i965->intel.device_info) ||
5565 IS_GEN8(i965->intel.device_info) ||
5566 IS_GEN9(i965->intel.device_info)) {
5567 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5568 obj_config->entrypoint == VAEntrypointVideoProc ||
5569 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5570 switch (attrib_list[i].value.value.i) {
5571 case VA_FOURCC_NV12:
5572 case VA_FOURCC_I420:
5573 case VA_FOURCC_YV12:
5576 attrib_list[i].value.value.i = 0;
5577 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5581 if (obj_config->profile == VAProfileJPEGBaseline) {
5582 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5583 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5585 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5586 attrib_list[i].value.value.i = 0;
5587 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5595 case VASurfaceAttribMinWidth:
5596 /* FIXME: add support for it later */
5597 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5599 case VASurfaceAttribMaxWidth:
5600 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5602 case VASurfaceAttribMinHeight:
5603 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5605 case VASurfaceAttribMaxHeight:
5606 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5609 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5618 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5620 VASurfaceAttrib *attrib_list,
5621 unsigned int *num_attribs)
5623 VAStatus vaStatus = VA_STATUS_SUCCESS;
5624 struct i965_driver_data *i965 = i965_driver_data(ctx);
5625 struct object_config *obj_config;
5627 VASurfaceAttrib *attribs = NULL;
5631 if (config == VA_INVALID_ID)
5632 return VA_STATUS_ERROR_INVALID_CONFIG;
5634 obj_config = CONFIG(config);
5636 if (obj_config == NULL)
5637 return VA_STATUS_ERROR_INVALID_CONFIG;
5639 if (!attrib_list && !num_attribs)
5640 return VA_STATUS_ERROR_INVALID_PARAMETER;
5642 if (attrib_list == NULL) {
5643 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5644 return VA_STATUS_SUCCESS;
5647 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
5649 if (attribs == NULL)
5650 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5652 if (IS_G4X(i965->intel.device_info)) {
5653 if (obj_config->profile == VAProfileMPEG2Simple ||
5654 obj_config->profile == VAProfileMPEG2Main) {
5655 attribs[i].type = VASurfaceAttribPixelFormat;
5656 attribs[i].value.type = VAGenericValueTypeInteger;
5657 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5658 attribs[i].value.value.i = VA_FOURCC_I420;
5661 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5662 switch (obj_config->profile) {
5663 case VAProfileMPEG2Simple:
5664 case VAProfileMPEG2Main:
5665 attribs[i].type = VASurfaceAttribPixelFormat;
5666 attribs[i].value.type = VAGenericValueTypeInteger;
5667 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5668 attribs[i].value.value.i = VA_FOURCC_I420;
5673 case VAProfileH264ConstrainedBaseline:
5674 case VAProfileH264Main:
5675 case VAProfileH264High:
5676 attribs[i].type = VASurfaceAttribPixelFormat;
5677 attribs[i].value.type = VAGenericValueTypeInteger;
5678 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5679 attribs[i].value.value.i = VA_FOURCC_NV12;
5683 attribs[i].type = VASurfaceAttribPixelFormat;
5684 attribs[i].value.type = VAGenericValueTypeInteger;
5685 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5686 attribs[i].value.value.i = VA_FOURCC_NV12;
5689 attribs[i].type = VASurfaceAttribPixelFormat;
5690 attribs[i].value.type = VAGenericValueTypeInteger;
5691 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5692 attribs[i].value.value.i = VA_FOURCC_I420;
5700 } else if (IS_GEN6(i965->intel.device_info)) {
5701 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5702 attribs[i].type = VASurfaceAttribPixelFormat;
5703 attribs[i].value.type = VAGenericValueTypeInteger;
5704 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5705 attribs[i].value.value.i = VA_FOURCC_NV12;
5707 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5708 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
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_NV12;
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_I420;
5721 attribs[i].type = VASurfaceAttribPixelFormat;
5722 attribs[i].value.type = VAGenericValueTypeInteger;
5723 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5724 attribs[i].value.value.i = VA_FOURCC_YV12;
5727 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5728 attribs[i].type = VASurfaceAttribPixelFormat;
5729 attribs[i].value.type = VAGenericValueTypeInteger;
5730 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5731 attribs[i].value.value.i = VA_FOURCC_YUY2;
5734 attribs[i].type = VASurfaceAttribPixelFormat;
5735 attribs[i].value.type = VAGenericValueTypeInteger;
5736 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5737 attribs[i].value.value.i = VA_FOURCC_RGBA;
5740 attribs[i].type = VASurfaceAttribPixelFormat;
5741 attribs[i].value.type = VAGenericValueTypeInteger;
5742 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5743 attribs[i].value.value.i = VA_FOURCC_RGBX;
5747 } else if (IS_GEN7(i965->intel.device_info)) {
5748 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5749 if (obj_config->profile == VAProfileJPEGBaseline) {
5750 attribs[i].type = VASurfaceAttribPixelFormat;
5751 attribs[i].value.type = VAGenericValueTypeInteger;
5752 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5753 attribs[i].value.value.i = VA_FOURCC_IMC3;
5756 attribs[i].type = VASurfaceAttribPixelFormat;
5757 attribs[i].value.type = VAGenericValueTypeInteger;
5758 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5759 attribs[i].value.value.i = VA_FOURCC_IMC1;
5762 attribs[i].type = VASurfaceAttribPixelFormat;
5763 attribs[i].value.type = VAGenericValueTypeInteger;
5764 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5765 attribs[i].value.value.i = VA_FOURCC_Y800;
5768 attribs[i].type = VASurfaceAttribPixelFormat;
5769 attribs[i].value.type = VAGenericValueTypeInteger;
5770 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5771 attribs[i].value.value.i = VA_FOURCC_411P;
5774 attribs[i].type = VASurfaceAttribPixelFormat;
5775 attribs[i].value.type = VAGenericValueTypeInteger;
5776 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5777 attribs[i].value.value.i = VA_FOURCC_422H;
5780 attribs[i].type = VASurfaceAttribPixelFormat;
5781 attribs[i].value.type = VAGenericValueTypeInteger;
5782 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5783 attribs[i].value.value.i = VA_FOURCC_422V;
5786 attribs[i].type = VASurfaceAttribPixelFormat;
5787 attribs[i].value.type = VAGenericValueTypeInteger;
5788 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5789 attribs[i].value.value.i = VA_FOURCC_444P;
5791 } else if (obj_config->profile == VAProfileHEVCMain10) {
5792 attribs[i].type = VASurfaceAttribPixelFormat;
5793 attribs[i].value.type = VAGenericValueTypeInteger;
5794 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5795 attribs[i].value.value.i = VA_FOURCC_P010;
5798 attribs[i].type = VASurfaceAttribPixelFormat;
5799 attribs[i].value.type = VAGenericValueTypeInteger;
5800 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5801 attribs[i].value.value.i = VA_FOURCC_NV12;
5804 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5805 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5806 attribs[i].type = VASurfaceAttribPixelFormat;
5807 attribs[i].value.type = VAGenericValueTypeInteger;
5808 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5809 attribs[i].value.value.i = VA_FOURCC_NV12;
5812 attribs[i].type = VASurfaceAttribPixelFormat;
5813 attribs[i].value.type = VAGenericValueTypeInteger;
5814 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5815 attribs[i].value.value.i = VA_FOURCC_I420;
5818 attribs[i].type = VASurfaceAttribPixelFormat;
5819 attribs[i].value.type = VAGenericValueTypeInteger;
5820 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5821 attribs[i].value.value.i = VA_FOURCC_YV12;
5824 attribs[i].type = VASurfaceAttribPixelFormat;
5825 attribs[i].value.type = VAGenericValueTypeInteger;
5826 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5827 attribs[i].value.value.i = VA_FOURCC_IMC3;
5830 if (obj_config->entrypoint == VAEntrypointVideoProc) {
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_YUY2;
5837 attribs[i].type = VASurfaceAttribPixelFormat;
5838 attribs[i].value.type = VAGenericValueTypeInteger;
5839 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5840 attribs[i].value.value.i = VA_FOURCC_RGBA;
5843 attribs[i].type = VASurfaceAttribPixelFormat;
5844 attribs[i].value.type = VAGenericValueTypeInteger;
5845 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5846 attribs[i].value.value.i = VA_FOURCC_RGBX;
5849 attribs[i].type = VASurfaceAttribPixelFormat;
5850 attribs[i].value.type = VAGenericValueTypeInteger;
5851 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5852 attribs[i].value.value.i = VA_FOURCC_BGRA;
5855 attribs[i].type = VASurfaceAttribPixelFormat;
5856 attribs[i].value.type = VAGenericValueTypeInteger;
5857 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5858 attribs[i].value.value.i = VA_FOURCC_BGRX;
5861 attribs[i].type = VASurfaceAttribPixelFormat;
5862 attribs[i].value.type = VAGenericValueTypeInteger;
5863 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5864 attribs[i].value.value.i = VA_FOURCC_YV16;
5868 } else if (IS_GEN8(i965->intel.device_info) ||
5869 IS_GEN9(i965->intel.device_info)) {
5870 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5871 if (obj_config->profile == VAProfileJPEGBaseline) {
5872 attribs[i].type = VASurfaceAttribPixelFormat;
5873 attribs[i].value.type = VAGenericValueTypeInteger;
5874 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5875 attribs[i].value.value.i = VA_FOURCC_IMC3;
5878 attribs[i].type = VASurfaceAttribPixelFormat;
5879 attribs[i].value.type = VAGenericValueTypeInteger;
5880 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5881 attribs[i].value.value.i = VA_FOURCC_IMC1;
5884 attribs[i].type = VASurfaceAttribPixelFormat;
5885 attribs[i].value.type = VAGenericValueTypeInteger;
5886 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5887 attribs[i].value.value.i = VA_FOURCC_Y800;
5890 attribs[i].type = VASurfaceAttribPixelFormat;
5891 attribs[i].value.type = VAGenericValueTypeInteger;
5892 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5893 attribs[i].value.value.i = VA_FOURCC_411P;
5896 attribs[i].type = VASurfaceAttribPixelFormat;
5897 attribs[i].value.type = VAGenericValueTypeInteger;
5898 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5899 attribs[i].value.value.i = VA_FOURCC_422H;
5902 attribs[i].type = VASurfaceAttribPixelFormat;
5903 attribs[i].value.type = VAGenericValueTypeInteger;
5904 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5905 attribs[i].value.value.i = VA_FOURCC_422V;
5908 attribs[i].type = VASurfaceAttribPixelFormat;
5909 attribs[i].value.type = VAGenericValueTypeInteger;
5910 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5911 attribs[i].value.value.i = VA_FOURCC_444P;
5914 attribs[i].type = VASurfaceAttribPixelFormat;
5915 attribs[i].value.type = VAGenericValueTypeInteger;
5916 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5917 attribs[i].value.value.i = VA_FOURCC_NV12;
5920 if ((obj_config->profile == VAProfileHEVCMain10) ||
5921 (obj_config->profile == VAProfileVP9Profile2)) {
5922 attribs[i].type = VASurfaceAttribPixelFormat;
5923 attribs[i].value.type = VAGenericValueTypeInteger;
5924 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5925 attribs[i].value.value.i = VA_FOURCC_P010;
5929 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5930 obj_config->entrypoint == VAEntrypointVideoProc ||
5931 obj_config->entrypoint == VAEntrypointEncSliceLP ||
5932 obj_config->entrypoint == VAEntrypointEncPicture) {
5934 if (obj_config->profile == VAProfileHEVCMain10) {
5935 attribs[i].type = VASurfaceAttribPixelFormat;
5936 attribs[i].value.type = VAGenericValueTypeInteger;
5937 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5938 attribs[i].value.value.i = VA_FOURCC_P010;
5941 attribs[i].type = VASurfaceAttribPixelFormat;
5942 attribs[i].value.type = VAGenericValueTypeInteger;
5943 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5944 attribs[i].value.value.i = VA_FOURCC_NV12;
5947 attribs[i].type = VASurfaceAttribPixelFormat;
5948 attribs[i].value.type = VAGenericValueTypeInteger;
5949 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5950 attribs[i].value.value.i = VA_FOURCC_I420;
5953 attribs[i].type = VASurfaceAttribPixelFormat;
5954 attribs[i].value.type = VAGenericValueTypeInteger;
5955 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5956 attribs[i].value.value.i = VA_FOURCC_YV12;
5959 attribs[i].type = VASurfaceAttribPixelFormat;
5960 attribs[i].value.type = VAGenericValueTypeInteger;
5961 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5962 attribs[i].value.value.i = VA_FOURCC_IMC3;
5966 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5967 attribs[i].type = VASurfaceAttribPixelFormat;
5968 attribs[i].value.type = VAGenericValueTypeInteger;
5969 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5970 attribs[i].value.value.i = VA_FOURCC_YUY2;
5973 attribs[i].type = VASurfaceAttribPixelFormat;
5974 attribs[i].value.type = VAGenericValueTypeInteger;
5975 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5976 attribs[i].value.value.i = VA_FOURCC_RGBA;
5979 attribs[i].type = VASurfaceAttribPixelFormat;
5980 attribs[i].value.type = VAGenericValueTypeInteger;
5981 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5982 attribs[i].value.value.i = VA_FOURCC_RGBX;
5985 attribs[i].type = VASurfaceAttribPixelFormat;
5986 attribs[i].value.type = VAGenericValueTypeInteger;
5987 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5988 attribs[i].value.value.i = VA_FOURCC_BGRA;
5991 attribs[i].type = VASurfaceAttribPixelFormat;
5992 attribs[i].value.type = VAGenericValueTypeInteger;
5993 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5994 attribs[i].value.value.i = VA_FOURCC_BGRX;
5997 attribs[i].type = VASurfaceAttribPixelFormat;
5998 attribs[i].value.type = VAGenericValueTypeInteger;
5999 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6000 attribs[i].value.value.i = VA_FOURCC_YV16;
6003 if(HAS_VPP_P010(i965)) {
6004 attribs[i].type = VASurfaceAttribPixelFormat;
6005 attribs[i].value.type = VAGenericValueTypeInteger;
6006 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6007 attribs[i].value.value.i = VA_FOURCC_P010;
6010 attribs[i].type = VASurfaceAttribPixelFormat;
6011 attribs[i].value.type = VAGenericValueTypeInteger;
6012 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6013 attribs[i].value.value.i = VA_FOURCC_I010;
6018 /* Additional support for jpeg encoder */
6019 if (obj_config->profile == VAProfileJPEGBaseline
6020 && obj_config->entrypoint == VAEntrypointEncPicture) {
6021 attribs[i].type = VASurfaceAttribPixelFormat;
6022 attribs[i].value.type = VAGenericValueTypeInteger;
6023 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6024 attribs[i].value.value.i = VA_FOURCC_YUY2;
6027 attribs[i].type = VASurfaceAttribPixelFormat;
6028 attribs[i].value.type = VAGenericValueTypeInteger;
6029 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6030 attribs[i].value.value.i = VA_FOURCC_UYVY;
6033 attribs[i].type = VASurfaceAttribPixelFormat;
6034 attribs[i].value.type = VAGenericValueTypeInteger;
6035 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6036 attribs[i].value.value.i = VA_FOURCC_YV16;
6039 attribs[i].type = VASurfaceAttribPixelFormat;
6040 attribs[i].value.type = VAGenericValueTypeInteger;
6041 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6042 attribs[i].value.value.i = VA_FOURCC_Y800;
6048 attribs[i].type = VASurfaceAttribMemoryType;
6049 attribs[i].value.type = VAGenericValueTypeInteger;
6050 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
6051 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
6052 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
6053 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
6056 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
6057 attribs[i].value.type = VAGenericValueTypePointer;
6058 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
6059 attribs[i].value.value.p = NULL; /* ignore */
6062 max_resolution(i965, obj_config, &max_width, &max_height);
6064 attribs[i].type = VASurfaceAttribMaxWidth;
6065 attribs[i].value.type = VAGenericValueTypeInteger;
6066 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6067 attribs[i].value.value.i = max_width;
6070 attribs[i].type = VASurfaceAttribMaxHeight;
6071 attribs[i].value.type = VAGenericValueTypeInteger;
6072 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
6073 attribs[i].value.value.i = max_height;
6076 if (i > *num_attribs) {
6079 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6083 memcpy(attrib_list, attribs, i * sizeof(*attribs));
6089 /* Acquires buffer handle for external API usage (internal implementation) */
6091 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
6092 uint32_t mem_type, VABufferInfo *out_buf_info)
6094 struct buffer_store *buffer_store;
6096 buffer_store = obj_buffer->buffer_store;
6097 if (!buffer_store || !buffer_store->bo)
6098 return VA_STATUS_ERROR_INVALID_BUFFER;
6100 /* Synchronization point */
6101 drm_intel_bo_wait_rendering(buffer_store->bo);
6103 if (obj_buffer->export_refcount > 0) {
6104 if (obj_buffer->export_state.mem_type != mem_type)
6105 return VA_STATUS_ERROR_INVALID_PARAMETER;
6108 VABufferInfo * const buf_info = &obj_buffer->export_state;
6111 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
6113 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
6114 return VA_STATUS_ERROR_INVALID_BUFFER;
6115 buf_info->handle = name;
6118 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6120 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
6121 return VA_STATUS_ERROR_INVALID_BUFFER;
6122 buf_info->handle = (intptr_t)fd;
6127 buf_info->type = obj_buffer->type;
6128 buf_info->mem_type = mem_type;
6129 buf_info->mem_size =
6130 obj_buffer->num_elements * obj_buffer->size_element;
6133 obj_buffer->export_refcount++;
6134 *out_buf_info = obj_buffer->export_state;
6135 return VA_STATUS_SUCCESS;
6138 /* Releases buffer handle after usage (internal implementation) */
6140 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6142 if (obj_buffer->export_refcount == 0)
6143 return VA_STATUS_ERROR_INVALID_BUFFER;
6145 if (--obj_buffer->export_refcount == 0) {
6146 VABufferInfo * const buf_info = &obj_buffer->export_state;
6148 switch (buf_info->mem_type) {
6149 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6150 close((intptr_t)buf_info->handle);
6154 buf_info->mem_type = 0;
6156 return VA_STATUS_SUCCESS;
6159 /** Acquires buffer handle for external API usage */
6161 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6162 VABufferInfo *buf_info)
6164 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6165 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6166 uint32_t i, mem_type;
6168 /* List of supported memory types, in preferred order */
6169 static const uint32_t mem_types[] = {
6170 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6171 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6176 return VA_STATUS_ERROR_INVALID_BUFFER;
6177 /* XXX: only VA surface|image like buffers are supported for now */
6178 if (obj_buffer->type != VAImageBufferType)
6179 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6182 * As the allocated buffer by calling vaCreateBuffer is related with
6183 * the specific context, it is unnecessary to export it.
6184 * So it is not supported when the buffer is allocated from wrapped
6187 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6188 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6192 return VA_STATUS_ERROR_INVALID_PARAMETER;
6194 if (!buf_info->mem_type)
6195 mem_type = mem_types[0];
6198 for (i = 0; mem_types[i] != 0; i++) {
6199 if (buf_info->mem_type & mem_types[i]) {
6200 mem_type = buf_info->mem_type;
6205 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6207 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6210 /** Releases buffer handle after usage from external API */
6212 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6214 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6215 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6218 return VA_STATUS_ERROR_INVALID_BUFFER;
6220 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6221 return VA_STATUS_ERROR_INVALID_BUFFER;
6224 return i965_release_buffer_handle(obj_buffer);
6228 i965_os_has_ring_support(VADriverContextP ctx,
6231 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6235 return i965->intel.has_bsd;
6238 return i965->intel.has_blt;
6240 case I965_RING_VEBOX:
6241 return i965->intel.has_vebox;
6243 case I965_RING_NULL:
6244 return 1; /* Always support */
6247 /* should never get here */
6256 * Query video processing pipeline
6258 VAStatus i965_QueryVideoProcFilters(
6259 VADriverContextP ctx,
6260 VAContextID context,
6261 VAProcFilterType *filters,
6262 unsigned int *num_filters
6265 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6266 unsigned int i = 0, num = 0;
6268 if (!num_filters || !filters)
6269 return VA_STATUS_ERROR_INVALID_PARAMETER;
6271 for (i = 0; i < i965->codec_info->num_filters; i++) {
6272 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6273 if (num == *num_filters) {
6274 *num_filters = i965->codec_info->num_filters;
6276 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6279 filters[num++] = i965->codec_info->filters[i].type;
6285 return VA_STATUS_SUCCESS;
6288 VAStatus i965_QueryVideoProcFilterCaps(
6289 VADriverContextP ctx,
6290 VAContextID context,
6291 VAProcFilterType type,
6293 unsigned int *num_filter_caps
6297 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6299 if (!filter_caps || !num_filter_caps)
6300 return VA_STATUS_ERROR_INVALID_PARAMETER;
6302 for (i = 0; i < i965->codec_info->num_filters; i++) {
6303 if (type == i965->codec_info->filters[i].type &&
6304 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6308 if (i == i965->codec_info->num_filters)
6309 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6314 case VAProcFilterNoiseReduction:
6315 case VAProcFilterSharpening:
6317 VAProcFilterCap *cap = filter_caps;
6319 if (*num_filter_caps < 1) {
6320 *num_filter_caps = 1;
6321 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6324 cap->range.min_value = 0.0;
6325 cap->range.max_value = 1.0;
6326 cap->range.default_value = 0.5;
6327 cap->range.step = 0.03125; /* 1.0 / 32 */
6333 case VAProcFilterDeinterlacing:
6335 VAProcFilterCapDeinterlacing *cap = filter_caps;
6337 if (*num_filter_caps < VAProcDeinterlacingCount) {
6338 *num_filter_caps = VAProcDeinterlacingCount;
6339 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6342 cap->type = VAProcDeinterlacingBob;
6347 if (i965->codec_info->has_di_motion_adptive) {
6348 cap->type = VAProcDeinterlacingMotionAdaptive;
6353 if (i965->codec_info->has_di_motion_compensated) {
6354 cap->type = VAProcDeinterlacingMotionCompensated;
6362 case VAProcFilterColorBalance:
6364 VAProcFilterCapColorBalance *cap = filter_caps;
6366 if (*num_filter_caps < VAProcColorBalanceCount) {
6367 *num_filter_caps = VAProcColorBalanceCount;
6368 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6371 cap->type = VAProcColorBalanceHue;
6372 cap->range.min_value = -180.0;
6373 cap->range.max_value = 180.0;
6374 cap->range.default_value = 0.0;
6375 cap->range.step = 1.0;
6379 cap->type = VAProcColorBalanceSaturation;
6380 cap->range.min_value = 0.0;
6381 cap->range.max_value = 10.0;
6382 cap->range.default_value = 1.0;
6383 cap->range.step = 0.1;
6387 cap->type = VAProcColorBalanceBrightness;
6388 cap->range.min_value = -100.0;
6389 cap->range.max_value = 100.0;
6390 cap->range.default_value = 0.0;
6391 cap->range.step = 1.0;
6395 cap->type = VAProcColorBalanceContrast;
6396 cap->range.min_value = 0.0;
6397 cap->range.max_value = 10.0;
6398 cap->range.default_value = 1.0;
6399 cap->range.step = 0.1;
6411 *num_filter_caps = i;
6413 return VA_STATUS_SUCCESS;
6416 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6417 VAProcColorStandardBT601,
6420 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6421 VAProcColorStandardBT601,
6424 VAStatus i965_QueryVideoProcPipelineCaps(
6425 VADriverContextP ctx,
6426 VAContextID context,
6427 VABufferID *filters,
6428 unsigned int num_filters,
6429 VAProcPipelineCaps *pipeline_cap /* out */
6432 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6435 pipeline_cap->pipeline_flags = 0;
6436 pipeline_cap->filter_flags = 0;
6437 pipeline_cap->num_forward_references = 0;
6438 pipeline_cap->num_backward_references = 0;
6439 pipeline_cap->num_input_color_standards = 1;
6440 pipeline_cap->input_color_standards = vpp_input_color_standards;
6441 pipeline_cap->num_output_color_standards = 1;
6442 pipeline_cap->output_color_standards = vpp_output_color_standards;
6444 for (i = 0; i < num_filters; i++) {
6445 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6448 !obj_buffer->buffer_store ||
6449 !obj_buffer->buffer_store->buffer)
6450 return VA_STATUS_ERROR_INVALID_BUFFER;
6452 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6454 if (base->type == VAProcFilterNoiseReduction) {
6455 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6457 } else if (base->type == VAProcFilterDeinterlacing) {
6458 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6460 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6461 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6462 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6463 VA_STATUS_ERROR_INVALID_PARAMETER);
6465 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6466 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6467 pipeline_cap->num_forward_references++;
6468 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6469 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6474 return VA_STATUS_SUCCESS;
6477 extern struct hw_codec_info *i965_get_codec_info(int devid);
6480 i965_driver_data_init(VADriverContextP ctx)
6482 struct i965_driver_data *i965 = i965_driver_data(ctx);
6484 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6486 if (!i965->codec_info)
6489 if (object_heap_init(&i965->config_heap,
6490 sizeof(struct object_config),
6492 goto err_config_heap;
6493 if (object_heap_init(&i965->context_heap,
6494 sizeof(struct object_context),
6496 goto err_context_heap;
6498 if (object_heap_init(&i965->surface_heap,
6499 sizeof(struct object_surface),
6501 goto err_surface_heap;
6502 if (object_heap_init(&i965->buffer_heap,
6503 sizeof(struct object_buffer),
6505 goto err_buffer_heap;
6506 if (object_heap_init(&i965->image_heap,
6507 sizeof(struct object_image),
6509 goto err_image_heap;
6510 if (object_heap_init(&i965->subpic_heap,
6511 sizeof(struct object_subpic),
6513 goto err_subpic_heap;
6515 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6516 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6517 _i965InitMutex(&i965->render_mutex);
6518 _i965InitMutex(&i965->pp_mutex);
6523 object_heap_destroy(&i965->image_heap);
6525 object_heap_destroy(&i965->buffer_heap);
6527 object_heap_destroy(&i965->surface_heap);
6529 object_heap_destroy(&i965->context_heap);
6531 object_heap_destroy(&i965->config_heap);
6538 i965_driver_data_terminate(VADriverContextP ctx)
6540 struct i965_driver_data *i965 = i965_driver_data(ctx);
6542 _i965DestroyMutex(&i965->pp_mutex);
6543 _i965DestroyMutex(&i965->render_mutex);
6546 intel_batchbuffer_free(i965->batch);
6549 intel_batchbuffer_free(i965->pp_batch);
6551 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6552 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6553 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6554 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6555 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6556 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6560 bool (*init)(VADriverContextP ctx);
6561 void (*terminate)(VADriverContextP ctx);
6563 } i965_sub_ops[] = {
6566 intel_driver_terminate,
6571 i965_driver_data_init,
6572 i965_driver_data_terminate,
6577 i965_display_attributes_init,
6578 i965_display_attributes_terminate,
6583 i965_post_processing_init,
6584 i965_post_processing_terminate,
6590 i965_render_terminate,
6594 #ifdef HAVE_VA_WAYLAND
6596 i965_output_wayland_init,
6597 i965_output_wayland_terminate,
6604 i965_output_dri_init,
6605 i965_output_dri_terminate,
6611 i965_gpe_table_init,
6612 i965_gpe_table_terminate,
6618 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6622 if (i965->va_vendor[0] != '\0')
6626 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6627 "%s %s driver for %s - %d.%d.%d",
6628 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6629 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6630 INTEL_DRIVER_MICRO_VERSION);
6631 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6635 if (INTEL_DRIVER_PRE_VERSION > 0) {
6636 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6637 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6638 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6642 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6643 " (%s)", INTEL_DRIVER_GIT_VERSION);
6644 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6651 i965->va_vendor[0] = '\0';
6652 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6656 /* Only when the option of "enable-wrapper" is passed, it is possible
6657 * to initialize/load the wrapper context of backend driver.
6658 * Otherwise it is not loaded.
6660 #if HAVE_HYBRID_CODEC
6663 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6665 #define DRIVER_EXTENSION "_drv_video.so"
6667 struct i965_driver_data *i965 = i965_driver_data(ctx);
6669 VADriverContextP wrapper_pdrvctx;
6670 struct VADriverVTable *vtable;
6671 char *search_path, *driver_dir;
6673 char driver_path[256];
6674 void *handle = NULL;
6675 VAStatus va_status = VA_STATUS_SUCCESS;
6676 bool driver_loaded = false;
6678 if (HAS_VP9_DECODING(i965)) {
6679 i965->wrapper_pdrvctx = NULL;
6683 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6684 vtable = calloc(1, sizeof(*vtable));
6686 if (!wrapper_pdrvctx || !vtable) {
6687 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6688 free(wrapper_pdrvctx);
6690 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6693 /* use the same drm_state with CTX */
6694 wrapper_pdrvctx->drm_state = ctx->drm_state;
6695 wrapper_pdrvctx->display_type = ctx->display_type;
6696 wrapper_pdrvctx->vtable = vtable;
6698 search_path = VA_DRIVERS_PATH;
6699 search_path = strdup((const char *)search_path);
6701 driver_dir = strtok_r(search_path, ":", &saveptr);
6702 while (driver_dir && !driver_loaded) {
6703 memset(driver_path, 0, sizeof(driver_path));
6704 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6706 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6708 fprintf(stderr, "failed to open %s\n", driver_path);
6709 driver_dir = strtok_r(NULL, ":", &saveptr);
6713 VADriverInit init_func = NULL;
6714 char init_func_s[256];
6717 static const struct {
6720 } compatible_versions[] = {
6721 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6730 for (i = 0; compatible_versions[i].major >= 0; i++) {
6731 snprintf(init_func_s, sizeof(init_func_s),
6732 "__vaDriverInit_%d_%d",
6733 compatible_versions[i].major,
6734 compatible_versions[i].minor);
6735 init_func = (VADriverInit)dlsym(handle, init_func_s);
6740 if (compatible_versions[i].major < 0) {
6742 fprintf(stderr, "%s has no function %s\n",
6743 driver_path, init_func_s);
6744 driver_dir = strtok_r(NULL, ":", &saveptr);
6749 va_status = (*init_func)(wrapper_pdrvctx);
6751 if (va_status != VA_STATUS_SUCCESS) {
6753 fprintf(stderr, "%s init failed\n", driver_path);
6754 driver_dir = strtok_r(NULL, ":", &saveptr);
6758 wrapper_pdrvctx->handle = handle;
6759 driver_loaded = true;
6765 if (driver_loaded) {
6766 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6767 return VA_STATUS_SUCCESS;
6769 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6771 free(wrapper_pdrvctx);
6772 return VA_STATUS_ERROR_OPERATION_FAILED;
6778 i965_Init(VADriverContextP ctx)
6780 struct i965_driver_data *i965 = i965_driver_data(ctx);
6782 const char *chipset;
6784 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6785 if ((i965_sub_ops[i].display_type == 0 ||
6786 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6787 !i965_sub_ops[i].init(ctx))
6791 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6792 switch (i965->intel.device_id) {
6794 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6795 #include "i965_pciids.h"
6797 chipset = "Unknown Intel Chipset";
6801 if (!ensure_vendor_string(i965, chipset))
6802 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6804 i965->current_context_id = VA_INVALID_ID;
6806 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6807 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6809 #if HAVE_HYBRID_CODEC
6810 i965_initialize_wrapper(ctx, "hybrid");
6813 return VA_STATUS_SUCCESS;
6817 for (; i >= 0; i--) {
6818 if (i965_sub_ops[i].display_type == 0 ||
6819 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6820 i965_sub_ops[i].terminate(ctx);
6824 return VA_STATUS_ERROR_UNKNOWN;
6829 i965_Terminate(VADriverContextP ctx)
6831 struct i965_driver_data *i965 = i965_driver_data(ctx);
6835 #if HAVE_HYBRID_CODEC
6836 if (i965->wrapper_pdrvctx) {
6837 VADriverContextP pdrvctx;
6838 pdrvctx = i965->wrapper_pdrvctx;
6839 if (pdrvctx->handle) {
6840 pdrvctx->vtable->vaTerminate(pdrvctx);
6841 dlclose(pdrvctx->handle);
6842 pdrvctx->handle = NULL;
6844 free(pdrvctx->vtable);
6846 i965->wrapper_pdrvctx = NULL;
6850 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6851 if (i965_sub_ops[i - 1].display_type == 0 ||
6852 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6853 i965_sub_ops[i - 1].terminate(ctx);
6857 ctx->pDriverData = NULL;
6860 return VA_STATUS_SUCCESS;
6864 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6867 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
6869 struct VADriverVTable * const vtable = ctx->vtable;
6870 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6872 struct i965_driver_data *i965;
6873 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6875 ctx->version_major = VA_MAJOR_VERSION;
6876 ctx->version_minor = VA_MINOR_VERSION;
6877 ctx->max_profiles = I965_MAX_PROFILES;
6878 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6879 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6880 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6881 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6882 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6884 vtable->vaTerminate = i965_Terminate;
6885 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6886 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6887 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6888 vtable->vaCreateConfig = i965_CreateConfig;
6889 vtable->vaDestroyConfig = i965_DestroyConfig;
6890 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6891 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6892 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6893 vtable->vaCreateContext = i965_CreateContext;
6894 vtable->vaDestroyContext = i965_DestroyContext;
6895 vtable->vaCreateBuffer = i965_CreateBuffer;
6896 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
6897 vtable->vaMapBuffer = i965_MapBuffer;
6898 vtable->vaUnmapBuffer = i965_UnmapBuffer;
6899 vtable->vaDestroyBuffer = i965_DestroyBuffer;
6900 vtable->vaBeginPicture = i965_BeginPicture;
6901 vtable->vaRenderPicture = i965_RenderPicture;
6902 vtable->vaEndPicture = i965_EndPicture;
6903 vtable->vaSyncSurface = i965_SyncSurface;
6904 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
6905 vtable->vaPutSurface = i965_PutSurface;
6906 vtable->vaQueryImageFormats = i965_QueryImageFormats;
6907 vtable->vaCreateImage = i965_CreateImage;
6908 vtable->vaDeriveImage = i965_DeriveImage;
6909 vtable->vaDestroyImage = i965_DestroyImage;
6910 vtable->vaSetImagePalette = i965_SetImagePalette;
6911 vtable->vaGetImage = i965_GetImage;
6912 vtable->vaPutImage = i965_PutImage;
6913 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
6914 vtable->vaCreateSubpicture = i965_CreateSubpicture;
6915 vtable->vaDestroySubpicture = i965_DestroySubpicture;
6916 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
6917 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
6918 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
6919 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
6920 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
6921 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
6922 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
6923 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
6924 vtable->vaBufferInfo = i965_BufferInfo;
6925 vtable->vaLockSurface = i965_LockSurface;
6926 vtable->vaUnlockSurface = i965_UnlockSurface;
6927 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
6928 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
6929 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
6932 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
6933 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
6935 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
6936 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
6937 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
6939 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
6942 ctx->pDriverData = NULL;
6944 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6947 i965->wrapper_pdrvctx = NULL;
6948 ctx->pDriverData = (void *)i965;
6949 ret = i965_Init(ctx);
6951 if (ret == VA_STATUS_SUCCESS) {
6952 ctx->str_vendor = i965->va_vendor;
6955 ctx->pDriverData = NULL;