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 #define CONFIG_ID_OFFSET 0x01000000
52 #define CONTEXT_ID_OFFSET 0x02000000
53 #define SURFACE_ID_OFFSET 0x04000000
54 #define BUFFER_ID_OFFSET 0x08000000
55 #define IMAGE_ID_OFFSET 0x0a000000
56 #define SUBPIC_ID_OFFSET 0x10000000
58 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
61 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
64 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
67 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
70 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
73 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
76 #define HAS_JPEG_ENCODING(ctx) ((ctx)->codec_info->has_jpeg_encoding && \
79 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
81 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
83 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
85 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
87 #define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \
90 #define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \
93 #define HAS_H264_MVC_DECODING(ctx) \
94 (HAS_H264_DECODING(ctx) && (ctx)->codec_info->h264_mvc_dec_profiles)
96 #define HAS_H264_MVC_DECODING_PROFILE(ctx, profile) \
97 (HAS_H264_MVC_DECODING(ctx) && \
98 ((ctx)->codec_info->h264_mvc_dec_profiles & (1U << profile)))
100 #define HAS_H264_MVC_ENCODING(ctx) ((ctx)->codec_info->has_h264_mvc_encoding && \
101 (ctx)->intel.has_bsd)
103 #define HAS_HEVC_DECODING(ctx) ((ctx)->codec_info->has_hevc_decoding && \
104 (ctx)->intel.has_bsd)
106 #define HAS_HEVC_ENCODING(ctx) ((ctx)->codec_info->has_hevc_encoding && \
107 (ctx)->intel.has_bsd)
109 #define HAS_VP9_DECODING(ctx) ((ctx)->codec_info->has_vp9_decoding && \
110 (ctx)->intel.has_bsd)
112 #define HAS_VP9_DECODING_PROFILE(ctx, profile) \
113 (HAS_VP9_DECODING(ctx) && \
114 ((ctx)->codec_info->vp9_dec_profiles & (1U << (profile - VAProfileVP9Profile0))))
116 #define HAS_HEVC10_DECODING(ctx) ((ctx)->codec_info->has_hevc10_decoding && \
117 (ctx)->intel.has_bsd)
119 #define HAS_VPP_P010(ctx) ((ctx)->codec_info->has_vpp_p010 && \
120 (ctx)->intel.has_bsd)
122 static int get_sampling_from_fourcc(unsigned int fourcc);
124 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
125 #define IS_VA_X11(ctx) \
126 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
128 /* Check whether we are rendering to Wayland */
129 #define IS_VA_WAYLAND(ctx) \
130 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
133 #define I965_2BITS (I965_BIT << 1)
134 #define I965_4BITS (I965_BIT << 2)
135 #define I965_8BITS (I965_BIT << 3)
136 #define I965_16BITS (I965_BIT << 4)
137 #define I965_32BITS (I965_BIT << 5)
149 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
150 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
151 #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} }
152 #define I_IYUV I_I420
153 #define I_IMC3 I_I420
154 #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} }
155 #define I_IMC1 I_YV12
157 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
159 #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} }
160 #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} }
161 #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} }
162 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
163 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
165 #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} }
167 #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} }
169 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
171 #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} }
172 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
173 #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} }
174 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
176 #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} }
177 #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} }
179 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
180 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
182 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
183 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
188 #define I_SI (I_S | I_I)
190 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
191 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
192 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
193 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
195 static const i965_fourcc_info i965_fourcc_infos[] = {
196 DEF_YUV(NV12, YUV420, I_SI),
197 DEF_YUV(I420, YUV420, I_SI),
198 DEF_YUV(IYUV, YUV420, I_S),
199 DEF_YUV(IMC3, YUV420, I_S),
200 DEF_YUV(YV12, YUV420, I_SI),
201 DEF_YUV(IMC1, YUV420, I_S),
203 DEF_YUV(P010, YUV420, I_SI),
205 DEF_YUV(422H, YUV422H, I_SI),
206 DEF_YUV(422V, YUV422V, I_S),
207 DEF_YUV(YV16, YUV422H, I_S),
208 DEF_YUV(YUY2, YUV422H, I_SI),
209 DEF_YUV(UYVY, YUV422H, I_SI),
211 DEF_YUV(444P, YUV444, I_S),
213 DEF_YUV(411P, YUV411, I_S),
215 DEF_YUV(Y800, YUV400, I_S),
217 DEF_RGB(RGBA, RGBX, I_SI),
218 DEF_RGB(RGBX, RGBX, I_SI),
219 DEF_RGB(BGRA, RGBX, I_SI),
220 DEF_RGB(BGRX, RGBX, I_SI),
222 DEF_RGB(ARGB, RGBX, I_I),
223 DEF_RGB(ABGR, RGBX, I_I),
225 DEF_INDEX(IA88, RGBX, I_I),
226 DEF_INDEX(AI88, RGBX, I_I),
228 DEF_INDEX(IA44, RGBX, I_I),
229 DEF_INDEX(AI44, RGBX, I_I)
232 const i965_fourcc_info *
233 get_fourcc_info(unsigned int fourcc)
237 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
238 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
240 if (info->fourcc == fourcc)
248 get_bpp_from_fourcc(unsigned int fourcc)
250 const i965_fourcc_info *info = get_fourcc_info(fourcc);
252 unsigned int bpp = 0;
257 for (i = 0; i < info->num_planes; i++)
264 I965_SURFACETYPE_RGBA = 1,
265 I965_SURFACETYPE_YUV,
266 I965_SURFACETYPE_INDEXED
269 /* List of supported display attributes */
270 static const VADisplayAttribute i965_display_attributes[] = {
272 VADisplayAttribBrightness,
273 -100, 100, DEFAULT_BRIGHTNESS,
274 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
278 VADisplayAttribContrast,
279 0, 100, DEFAULT_CONTRAST,
280 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
285 -180, 180, DEFAULT_HUE,
286 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
290 VADisplayAttribSaturation,
291 0, 100, DEFAULT_SATURATION,
292 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
296 VADisplayAttribRotation,
297 0, 3, VA_ROTATION_NONE,
298 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
302 /* List of supported image formats */
305 VAImageFormat va_format;
306 } i965_image_format_map_t;
308 static const i965_image_format_map_t
309 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
310 { I965_SURFACETYPE_YUV,
311 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
312 { I965_SURFACETYPE_YUV,
313 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
314 { I965_SURFACETYPE_YUV,
315 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
316 { I965_SURFACETYPE_YUV,
317 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
318 { I965_SURFACETYPE_YUV,
319 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
320 { I965_SURFACETYPE_YUV,
321 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
322 { I965_SURFACETYPE_RGBA,
323 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
324 { I965_SURFACETYPE_RGBA,
325 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
326 { I965_SURFACETYPE_YUV,
327 { VA_FOURCC_P010, VA_LSB_FIRST, 24, } },
330 /* List of supported subpicture formats */
334 VAImageFormat va_format;
335 unsigned int va_flags;
336 } i965_subpic_format_map_t;
338 #define COMMON_SUBPICTURE_FLAGS \
339 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
340 VA_SUBPICTURE_GLOBAL_ALPHA)
342 static const i965_subpic_format_map_t
343 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
344 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
345 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
346 COMMON_SUBPICTURE_FLAGS },
347 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
348 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
349 COMMON_SUBPICTURE_FLAGS },
350 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
351 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
352 COMMON_SUBPICTURE_FLAGS },
353 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
354 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
355 COMMON_SUBPICTURE_FLAGS },
356 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
357 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
358 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
359 COMMON_SUBPICTURE_FLAGS },
360 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
361 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
362 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
363 COMMON_SUBPICTURE_FLAGS },
366 static const i965_subpic_format_map_t *
367 get_subpic_format(const VAImageFormat *va_format)
370 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
371 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
372 if (m->va_format.fourcc == va_format->fourcc &&
373 (m->type == I965_SURFACETYPE_RGBA ?
374 (m->va_format.byte_order == va_format->byte_order &&
375 m->va_format.red_mask == va_format->red_mask &&
376 m->va_format.green_mask == va_format->green_mask &&
377 m->va_format.blue_mask == va_format->blue_mask &&
378 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
384 /* Checks whether the surface is in busy state */
386 is_surface_busy(struct i965_driver_data *i965,
387 struct object_surface *obj_surface)
389 assert(obj_surface != NULL);
391 if (obj_surface->locked_image_id != VA_INVALID_ID)
393 if (obj_surface->derived_image_id != VA_INVALID_ID)
398 /* Checks whether the image is in busy state */
400 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
402 struct object_buffer *obj_buffer;
404 assert(obj_image != NULL);
406 if (obj_image->derived_surface != VA_INVALID_ID &&
407 obj_image->derived_surface == surface)
410 obj_buffer = BUFFER(obj_image->image.buf);
411 if (obj_buffer && obj_buffer->export_refcount > 0)
416 #define I965_PACKED_HEADER_BASE 0
417 #define I965_SEQ_PACKED_HEADER_BASE 0
418 #define I965_SEQ_PACKED_HEADER_END 2
419 #define I965_PIC_PACKED_HEADER_BASE 2
420 #define I965_PACKED_MISC_HEADER_BASE 4
423 va_enc_packed_type_to_idx(int packed_type)
427 if (packed_type & VAEncPackedHeaderMiscMask) {
428 idx = I965_PACKED_MISC_HEADER_BASE;
429 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
430 ASSERT_RET(packed_type > 0, 0);
431 idx += (packed_type - 1);
433 idx = I965_PACKED_HEADER_BASE;
435 switch (packed_type) {
436 case VAEncPackedHeaderSequence:
437 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
440 case VAEncPackedHeaderPicture:
441 idx = I965_PIC_PACKED_HEADER_BASE + 0;
444 case VAEncPackedHeaderSlice:
445 idx = I965_PIC_PACKED_HEADER_BASE + 1;
449 /* Should not get here */
455 ASSERT_RET(idx < 5, 0);
459 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
462 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
464 struct i965_driver_data *i965 = i965_driver_data(ctx);
465 struct object_surface *obj_surface = SURFACE(surface);
466 VAStatus va_status = VA_STATUS_SUCCESS;
469 return VA_STATUS_ERROR_INVALID_SURFACE;
472 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
473 /* the wrapped surface already exists. just return it */
477 if (obj_surface->fourcc == 0)
478 i965_check_alloc_surface_bo(ctx, obj_surface,
479 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
482 * TBD: Support more surface formats.
483 * Currently only NV12 is support as NV12 is used by decoding.
485 if (obj_surface->fourcc != VA_FOURCC_NV12 )
486 return VA_STATUS_ERROR_INVALID_PARAMETER;
488 if ((i965->wrapper_pdrvctx == NULL) ||
489 (obj_surface->bo == NULL))
490 return VA_STATUS_ERROR_INVALID_PARAMETER;
494 VASurfaceAttrib attrib_list[2];
495 VASurfaceAttribExternalBuffers buffer_descriptor;
496 VAGenericID wrapper_surface;
498 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
499 return VA_STATUS_ERROR_OPERATION_FAILED;
501 obj_surface->exported_primefd = fd_handle;
503 memset(&attrib_list, 0, sizeof(attrib_list));
504 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
506 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
507 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
508 attrib_list[0].value.value.p = &buffer_descriptor;
509 attrib_list[0].value.type = VAGenericValueTypePointer;
511 attrib_list[1].type = VASurfaceAttribMemoryType;
512 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
513 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
514 attrib_list[1].value.type = VAGenericValueTypeInteger;
516 buffer_descriptor.num_buffers = 1;
517 buffer_descriptor.num_planes = 2;
518 buffer_descriptor.width = obj_surface->orig_width;
519 buffer_descriptor.height = obj_surface->orig_height;
520 buffer_descriptor.pixel_format = obj_surface->fourcc;
521 buffer_descriptor.data_size = obj_surface->size;
522 buffer_descriptor.pitches[0] = obj_surface->width;
523 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
524 buffer_descriptor.offsets[0] = 0;
525 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
526 buffer_descriptor.buffers = (void *)&fd_handle;
528 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
529 vaCreateSurfaces2(i965->wrapper_pdrvctx,
531 obj_surface->orig_width,
532 obj_surface->orig_height,
536 if (va_status == VA_STATUS_SUCCESS) {
537 obj_surface->wrapper_surface = wrapper_surface;
539 /* This needs to be checked */
540 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
548 i965_QueryConfigProfiles(VADriverContextP ctx,
549 VAProfile *profile_list, /* out */
550 int *num_profiles) /* out */
552 struct i965_driver_data * const i965 = i965_driver_data(ctx);
555 if (HAS_MPEG2_DECODING(i965) ||
556 HAS_MPEG2_ENCODING(i965)) {
557 profile_list[i++] = VAProfileMPEG2Simple;
558 profile_list[i++] = VAProfileMPEG2Main;
561 if (HAS_H264_DECODING(i965) ||
562 HAS_H264_ENCODING(i965)) {
563 profile_list[i++] = VAProfileH264ConstrainedBaseline;
564 profile_list[i++] = VAProfileH264Main;
565 profile_list[i++] = VAProfileH264High;
567 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
568 HAS_H264_MVC_ENCODING(i965))
569 profile_list[i++] = VAProfileH264MultiviewHigh;
570 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
571 HAS_H264_MVC_ENCODING(i965))
572 profile_list[i++] = VAProfileH264StereoHigh;
574 if (HAS_VC1_DECODING(i965)) {
575 profile_list[i++] = VAProfileVC1Simple;
576 profile_list[i++] = VAProfileVC1Main;
577 profile_list[i++] = VAProfileVC1Advanced;
581 profile_list[i++] = VAProfileNone;
584 if (HAS_JPEG_DECODING(i965) ||
585 HAS_JPEG_ENCODING(i965)) {
586 profile_list[i++] = VAProfileJPEGBaseline;
589 if (HAS_VP8_DECODING(i965) ||
590 HAS_VP8_ENCODING(i965)) {
591 profile_list[i++] = VAProfileVP8Version0_3;
594 if (HAS_HEVC_DECODING(i965)||
595 HAS_HEVC_ENCODING(i965)) {
596 profile_list[i++] = VAProfileHEVCMain;
599 if (HAS_HEVC10_DECODING(i965)) {
600 profile_list[i++] = VAProfileHEVCMain10;
603 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0)) {
604 profile_list[i++] = VAProfileVP9Profile0;
607 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
608 profile_list[i++] = VAProfileVP9Profile2;
611 if (i965->wrapper_pdrvctx) {
612 VAProfile wrapper_list[4];
614 VADriverContextP pdrvctx;
617 pdrvctx = i965->wrapper_pdrvctx;
618 CALL_VTABLE(pdrvctx, va_status,
619 vaQueryConfigProfiles(pdrvctx,
620 wrapper_list, &wrapper_num));
622 if (va_status == VA_STATUS_SUCCESS) {
624 for (j = 0; j < wrapper_num; j++)
625 if (wrapper_list[j] != VAProfileNone)
626 profile_list[i++] = wrapper_list[j];
630 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
631 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
634 return VA_STATUS_SUCCESS;
638 i965_QueryConfigEntrypoints(VADriverContextP ctx,
640 VAEntrypoint *entrypoint_list, /* out */
641 int *num_entrypoints) /* out */
643 struct i965_driver_data * const i965 = i965_driver_data(ctx);
647 case VAProfileMPEG2Simple:
648 case VAProfileMPEG2Main:
649 if (HAS_MPEG2_DECODING(i965))
650 entrypoint_list[n++] = VAEntrypointVLD;
652 if (HAS_MPEG2_ENCODING(i965))
653 entrypoint_list[n++] = VAEntrypointEncSlice;
657 case VAProfileH264ConstrainedBaseline:
658 case VAProfileH264Main:
659 case VAProfileH264High:
660 if (HAS_H264_DECODING(i965))
661 entrypoint_list[n++] = VAEntrypointVLD;
663 if (HAS_H264_ENCODING(i965))
664 entrypoint_list[n++] = VAEntrypointEncSlice;
667 case VAProfileH264MultiviewHigh:
668 case VAProfileH264StereoHigh:
669 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
670 entrypoint_list[n++] = VAEntrypointVLD;
672 if (HAS_H264_MVC_ENCODING(i965))
673 entrypoint_list[n++] = VAEntrypointEncSlice;
676 case VAProfileVC1Simple:
677 case VAProfileVC1Main:
678 case VAProfileVC1Advanced:
679 if (HAS_VC1_DECODING(i965))
680 entrypoint_list[n++] = VAEntrypointVLD;
685 entrypoint_list[n++] = VAEntrypointVideoProc;
688 case VAProfileJPEGBaseline:
689 if (HAS_JPEG_DECODING(i965))
690 entrypoint_list[n++] = VAEntrypointVLD;
692 if (HAS_JPEG_ENCODING(i965))
693 entrypoint_list[n++] = VAEntrypointEncPicture;
696 case VAProfileVP8Version0_3:
697 if (HAS_VP8_DECODING(i965))
698 entrypoint_list[n++] = VAEntrypointVLD;
700 if (HAS_VP8_ENCODING(i965))
701 entrypoint_list[n++] = VAEntrypointEncSlice;
705 case VAProfileHEVCMain:
706 if (HAS_HEVC_DECODING(i965))
707 entrypoint_list[n++] = VAEntrypointVLD;
709 if (HAS_HEVC_ENCODING(i965))
710 entrypoint_list[n++] = VAEntrypointEncSlice;
714 case VAProfileHEVCMain10:
715 if (HAS_HEVC10_DECODING(i965))
716 entrypoint_list[n++] = VAEntrypointVLD;
720 case VAProfileVP9Profile0:
721 case VAProfileVP9Profile2:
722 if(HAS_VP9_DECODING_PROFILE(i965, profile))
723 entrypoint_list[n++] = VAEntrypointVLD;
725 if(profile == VAProfileVP9Profile0) {
726 if (i965->wrapper_pdrvctx) {
727 VAStatus va_status = VA_STATUS_SUCCESS;
728 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
730 CALL_VTABLE(pdrvctx, va_status,
731 vaQueryConfigEntrypoints(pdrvctx, profile,
744 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
745 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
746 *num_entrypoints = n;
747 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
751 i965_validate_config(VADriverContextP ctx, VAProfile profile,
752 VAEntrypoint entrypoint)
754 struct i965_driver_data * const i965 = i965_driver_data(ctx);
757 /* Validate profile & entrypoint */
759 case VAProfileMPEG2Simple:
760 case VAProfileMPEG2Main:
761 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
762 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
763 va_status = VA_STATUS_SUCCESS;
765 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
769 case VAProfileH264ConstrainedBaseline:
770 case VAProfileH264Main:
771 case VAProfileH264High:
772 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
773 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
774 va_status = VA_STATUS_SUCCESS;
776 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
780 case VAProfileVC1Simple:
781 case VAProfileVC1Main:
782 case VAProfileVC1Advanced:
783 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
784 va_status = VA_STATUS_SUCCESS;
786 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
791 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
792 va_status = VA_STATUS_SUCCESS;
794 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
798 case VAProfileJPEGBaseline:
799 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
800 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
801 va_status = VA_STATUS_SUCCESS;
803 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
807 case VAProfileVP8Version0_3:
808 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
809 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
810 va_status = VA_STATUS_SUCCESS;
812 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
816 case VAProfileH264MultiviewHigh:
817 case VAProfileH264StereoHigh:
818 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
819 entrypoint == VAEntrypointVLD) ||
820 (HAS_H264_MVC_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
821 va_status = VA_STATUS_SUCCESS;
823 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
828 case VAProfileHEVCMain:
829 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
830 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice)))
831 va_status = VA_STATUS_SUCCESS;
833 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
837 case VAProfileHEVCMain10:
838 if (HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD))
839 va_status = VA_STATUS_SUCCESS;
841 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
845 case VAProfileVP9Profile0:
846 case VAProfileVP9Profile2:
847 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) && (entrypoint == VAEntrypointVLD))
848 va_status = VA_STATUS_SUCCESS;
849 else if ((profile == VAProfileVP9Profile0) && i965->wrapper_pdrvctx)
850 va_status = VA_STATUS_SUCCESS;
852 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
856 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
863 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
864 VAEntrypoint entrypoint)
866 struct i965_driver_data * const i965 = i965_driver_data(ctx);
867 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
870 case VAProfileH264ConstrainedBaseline:
871 case VAProfileH264Main:
872 case VAProfileH264High:
873 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
874 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
877 case VAProfileH264MultiviewHigh:
878 case VAProfileH264StereoHigh:
879 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
880 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
883 case VAProfileJPEGBaseline:
884 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
885 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
886 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
887 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
890 case VAProfileHEVCMain10:
891 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
892 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
896 if(HAS_VPP_P010(i965))
897 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
900 case VAProfileVP9Profile0:
901 case VAProfileVP9Profile2:
902 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
903 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
909 return chroma_formats;
913 i965_GetConfigAttributes(VADriverContextP ctx,
915 VAEntrypoint entrypoint,
916 VAConfigAttrib *attrib_list, /* in/out */
922 va_status = i965_validate_config(ctx, profile, entrypoint);
923 if (va_status != VA_STATUS_SUCCESS)
926 /* Other attributes don't seem to be defined */
927 /* What to do if we don't know the attribute? */
928 for (i = 0; i < num_attribs; i++) {
929 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
930 switch (attrib_list[i].type) {
931 case VAConfigAttribRTFormat:
932 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
933 profile, entrypoint);
936 case VAConfigAttribRateControl:
937 if (entrypoint == VAEntrypointEncSlice) {
938 attrib_list[i].value = VA_RC_CQP;
940 if (profile != VAProfileMPEG2Main &&
941 profile != VAProfileMPEG2Simple)
942 attrib_list[i].value |= VA_RC_CBR;
947 case VAConfigAttribEncPackedHeaders:
948 if (entrypoint == VAEntrypointEncSlice) {
949 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
950 if (profile == VAProfileH264ConstrainedBaseline ||
951 profile == VAProfileH264Main ||
952 profile == VAProfileH264High ||
953 profile == VAProfileH264StereoHigh ||
954 profile == VAProfileH264MultiviewHigh ||
955 profile == VAProfileHEVCMain) {
956 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
957 VA_ENC_PACKED_HEADER_SLICE);
961 else if (entrypoint == VAEntrypointEncPicture) {
962 if (profile == VAProfileJPEGBaseline)
963 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
967 case VAConfigAttribEncMaxRefFrames:
968 if (entrypoint == VAEntrypointEncSlice) {
969 attrib_list[i].value = (1 << 16) | (1 << 0);
974 case VAConfigAttribEncQualityRange:
975 if (entrypoint == VAEntrypointEncSlice) {
976 attrib_list[i].value = 1;
977 if (profile == VAProfileH264ConstrainedBaseline ||
978 profile == VAProfileH264Main ||
979 profile == VAProfileH264High )
980 attrib_list[i].value = ENCODER_QUALITY_RANGE;
985 case VAConfigAttribEncJPEG:
986 if( entrypoint == VAEntrypointEncPicture) {
987 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*)&(attrib_list[i].value);
988 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
989 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
990 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
991 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
992 (configVal->bits).max_num_components = 3; // Only 3 components supported
993 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
994 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
995 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
999 case VAConfigAttribDecSliceMode:
1000 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1005 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1010 return VA_STATUS_SUCCESS;
1014 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1016 object_heap_free(heap, obj);
1019 static VAConfigAttrib *
1020 i965_lookup_config_attribute(struct object_config *obj_config,
1021 VAConfigAttribType type)
1025 for (i = 0; i < obj_config->num_attribs; i++) {
1026 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1027 if (attrib->type == type)
1034 i965_append_config_attribute(struct object_config *obj_config,
1035 const VAConfigAttrib *new_attrib)
1037 VAConfigAttrib *attrib;
1039 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1040 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1042 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1043 attrib->type = new_attrib->type;
1044 attrib->value = new_attrib->value;
1045 return VA_STATUS_SUCCESS;
1049 i965_ensure_config_attribute(struct object_config *obj_config,
1050 const VAConfigAttrib *new_attrib)
1052 VAConfigAttrib *attrib;
1054 /* Check for existing attributes */
1055 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1057 /* Update existing attribute */
1058 attrib->value = new_attrib->value;
1059 return VA_STATUS_SUCCESS;
1061 return i965_append_config_attribute(obj_config, new_attrib);
1065 i965_CreateConfig(VADriverContextP ctx,
1067 VAEntrypoint entrypoint,
1068 VAConfigAttrib *attrib_list,
1070 VAConfigID *config_id) /* out */
1072 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1073 struct object_config *obj_config;
1078 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1080 if (VA_STATUS_SUCCESS != vaStatus) {
1084 configID = NEW_CONFIG_ID();
1085 obj_config = CONFIG(configID);
1087 if (NULL == obj_config) {
1088 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1092 obj_config->profile = profile;
1093 obj_config->entrypoint = entrypoint;
1094 obj_config->num_attribs = 0;
1095 obj_config->wrapper_config = VA_INVALID_ID;
1097 for (i = 0; i < num_attribs; i++) {
1098 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1099 if (vaStatus != VA_STATUS_SUCCESS)
1103 if (vaStatus == VA_STATUS_SUCCESS) {
1104 VAConfigAttrib attrib, *attrib_found;
1105 attrib.type = VAConfigAttribRTFormat;
1106 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1107 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1108 if (!attrib_found || !attrib_found->value)
1109 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1110 else if (!(attrib_found->value & attrib.value))
1111 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1114 if ((vaStatus == VA_STATUS_SUCCESS) &&
1115 (profile == VAProfileVP9Profile0) &&
1116 (entrypoint == VAEntrypointVLD) &&
1117 !HAS_VP9_DECODING(i965)) {
1119 if (i965->wrapper_pdrvctx) {
1120 VAGenericID wrapper_config;
1122 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1123 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1124 entrypoint, attrib_list,
1125 num_attribs, &wrapper_config));
1127 if (vaStatus == VA_STATUS_SUCCESS)
1128 obj_config->wrapper_config = wrapper_config;
1132 /* Error recovery */
1133 if (VA_STATUS_SUCCESS != vaStatus) {
1134 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1136 *config_id = configID;
1143 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1145 struct i965_driver_data *i965 = i965_driver_data(ctx);
1146 struct object_config *obj_config = CONFIG(config_id);
1149 if (NULL == obj_config) {
1150 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1154 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1155 i965->wrapper_pdrvctx) {
1156 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1157 vaDestroyConfig(i965->wrapper_pdrvctx,
1158 obj_config->wrapper_config));
1159 obj_config->wrapper_config = VA_INVALID_ID;
1162 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1163 return VA_STATUS_SUCCESS;
1166 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1167 VAConfigID config_id,
1168 VAProfile *profile, /* out */
1169 VAEntrypoint *entrypoint, /* out */
1170 VAConfigAttrib *attrib_list, /* out */
1171 int *num_attribs) /* out */
1173 struct i965_driver_data *i965 = i965_driver_data(ctx);
1174 struct object_config *obj_config = CONFIG(config_id);
1175 VAStatus vaStatus = VA_STATUS_SUCCESS;
1178 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1179 *profile = obj_config->profile;
1180 *entrypoint = obj_config->entrypoint;
1181 *num_attribs = obj_config->num_attribs;
1183 for(i = 0; i < obj_config->num_attribs; i++) {
1184 attrib_list[i] = obj_config->attrib_list[i];
1191 i965_destroy_surface_storage(struct object_surface *obj_surface)
1196 dri_bo_unreference(obj_surface->bo);
1197 obj_surface->bo = NULL;
1199 if (obj_surface->free_private_data != NULL) {
1200 obj_surface->free_private_data(&obj_surface->private_data);
1201 obj_surface->private_data = NULL;
1206 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1208 struct object_surface *obj_surface = (struct object_surface *)obj;
1210 i965_destroy_surface_storage(obj_surface);
1211 object_heap_free(heap, obj);
1215 i965_surface_native_memory(VADriverContextP ctx,
1216 struct object_surface *obj_surface,
1218 int expected_fourcc)
1220 struct i965_driver_data *i965 = i965_driver_data(ctx);
1221 int tiling = HAS_TILED_SURFACE(i965);
1223 if (!expected_fourcc)
1224 return VA_STATUS_SUCCESS;
1226 // todo, should we disable tiling for 422 format?
1227 if (expected_fourcc == VA_FOURCC_I420 ||
1228 expected_fourcc == VA_FOURCC_IYUV ||
1229 expected_fourcc == VA_FOURCC_YV12 ||
1230 expected_fourcc == VA_FOURCC_YV16)
1233 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1237 i965_suface_external_memory(VADriverContextP ctx,
1238 struct object_surface *obj_surface,
1239 int external_memory_type,
1240 VASurfaceAttribExternalBuffers *memory_attibute,
1243 struct i965_driver_data *i965 = i965_driver_data(ctx);
1245 if (!memory_attibute ||
1246 !memory_attibute->buffers ||
1247 index > memory_attibute->num_buffers)
1248 return VA_STATUS_ERROR_INVALID_PARAMETER;
1250 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1251 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1252 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1254 obj_surface->fourcc = memory_attibute->pixel_format;
1255 obj_surface->width = memory_attibute->pitches[0];
1256 obj_surface->size = memory_attibute->data_size;
1258 if (memory_attibute->num_planes == 1)
1259 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1261 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1263 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1264 obj_surface->x_cr_offset = 0;
1266 switch (obj_surface->fourcc) {
1267 case VA_FOURCC_NV12:
1268 case VA_FOURCC_P010:
1269 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1270 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1272 obj_surface->subsampling = SUBSAMPLE_YUV420;
1273 obj_surface->y_cb_offset = obj_surface->height;
1274 obj_surface->y_cr_offset = obj_surface->height;
1275 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1276 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1277 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1281 case VA_FOURCC_YV12:
1282 case VA_FOURCC_IMC1:
1283 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1284 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1286 obj_surface->subsampling = SUBSAMPLE_YUV420;
1287 obj_surface->y_cr_offset = obj_surface->height;
1288 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1289 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1290 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1291 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1295 case VA_FOURCC_I420:
1296 case VA_FOURCC_IYUV:
1297 case VA_FOURCC_IMC3:
1298 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1299 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1301 obj_surface->subsampling = SUBSAMPLE_YUV420;
1302 obj_surface->y_cb_offset = obj_surface->height;
1303 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1304 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1305 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1306 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1310 case VA_FOURCC_YUY2:
1311 case VA_FOURCC_UYVY:
1312 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1314 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1315 obj_surface->y_cb_offset = 0;
1316 obj_surface->y_cr_offset = 0;
1317 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1318 obj_surface->cb_cr_height = obj_surface->orig_height;
1319 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1323 case VA_FOURCC_RGBA:
1324 case VA_FOURCC_RGBX:
1325 case VA_FOURCC_BGRA:
1326 case VA_FOURCC_BGRX:
1327 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1329 obj_surface->subsampling = SUBSAMPLE_RGBX;
1330 obj_surface->y_cb_offset = 0;
1331 obj_surface->y_cr_offset = 0;
1332 obj_surface->cb_cr_width = 0;
1333 obj_surface->cb_cr_height = 0;
1334 obj_surface->cb_cr_pitch = 0;
1338 case VA_FOURCC_Y800: /* monochrome surface */
1339 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1341 obj_surface->subsampling = SUBSAMPLE_YUV400;
1342 obj_surface->y_cb_offset = 0;
1343 obj_surface->y_cr_offset = 0;
1344 obj_surface->cb_cr_width = 0;
1345 obj_surface->cb_cr_height = 0;
1346 obj_surface->cb_cr_pitch = 0;
1350 case VA_FOURCC_411P:
1351 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1352 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1354 obj_surface->subsampling = SUBSAMPLE_YUV411;
1355 obj_surface->y_cb_offset = 0;
1356 obj_surface->y_cr_offset = 0;
1357 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1358 obj_surface->cb_cr_height = obj_surface->orig_height;
1359 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1363 case VA_FOURCC_422H:
1364 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1365 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1367 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1368 obj_surface->y_cb_offset = obj_surface->height;
1369 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1370 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1371 obj_surface->cb_cr_height = obj_surface->orig_height;
1372 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1376 case VA_FOURCC_YV16:
1377 assert(memory_attibute->num_planes == 3);
1378 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1380 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1381 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1382 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1383 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1384 obj_surface->cb_cr_height = obj_surface->orig_height;
1385 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1389 case VA_FOURCC_422V:
1390 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1391 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1393 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1394 obj_surface->y_cb_offset = obj_surface->height;
1395 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1396 obj_surface->cb_cr_width = obj_surface->orig_width;
1397 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1398 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1402 case VA_FOURCC_444P:
1403 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1404 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1406 obj_surface->subsampling = SUBSAMPLE_YUV444;
1407 obj_surface->y_cb_offset = obj_surface->height;
1408 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1409 obj_surface->cb_cr_width = obj_surface->orig_width;
1410 obj_surface->cb_cr_height = obj_surface->orig_height;
1411 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1417 return VA_STATUS_ERROR_INVALID_PARAMETER;
1420 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1421 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1422 "gem flinked vaapi surface",
1423 memory_attibute->buffers[index]);
1424 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1425 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1426 memory_attibute->buffers[index],
1429 if (!obj_surface->bo)
1430 return VA_STATUS_ERROR_INVALID_PARAMETER;
1432 return VA_STATUS_SUCCESS;
1435 /* byte-per-pixel of the first plane */
1437 bpp_1stplane_by_fourcc(unsigned int fourcc)
1439 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1441 if (info && (info->flag & I_S))
1442 return info->bpp[0] / 8;
1448 i965_CreateSurfaces2(
1449 VADriverContextP ctx,
1450 unsigned int format,
1452 unsigned int height,
1453 VASurfaceID *surfaces,
1454 unsigned int num_surfaces,
1455 VASurfaceAttrib *attrib_list,
1456 unsigned int num_attribs
1459 struct i965_driver_data *i965 = i965_driver_data(ctx);
1461 VAStatus vaStatus = VA_STATUS_SUCCESS;
1462 int expected_fourcc = 0;
1463 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1464 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1466 for (i = 0; i < num_attribs && attrib_list; i++) {
1467 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1468 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1469 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1470 expected_fourcc = attrib_list[i].value.value.i;
1473 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1474 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1476 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1478 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1479 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1480 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1481 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1482 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1483 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1486 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1487 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1488 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1489 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1493 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1494 * for post-processing (including color conversion) */
1495 if (VA_RT_FORMAT_YUV420 != format &&
1496 VA_RT_FORMAT_YUV420_10BPP != format &&
1497 VA_RT_FORMAT_YUV422 != format &&
1498 VA_RT_FORMAT_YUV444 != format &&
1499 VA_RT_FORMAT_YUV411 != format &&
1500 VA_RT_FORMAT_YUV400 != format &&
1501 VA_RT_FORMAT_RGB32 != format) {
1502 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1505 for (i = 0; i < num_surfaces; i++) {
1506 int surfaceID = NEW_SURFACE_ID();
1507 struct object_surface *obj_surface = SURFACE(surfaceID);
1509 if (NULL == obj_surface) {
1510 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1514 surfaces[i] = surfaceID;
1515 obj_surface->status = VASurfaceReady;
1516 obj_surface->orig_width = width;
1517 obj_surface->orig_height = height;
1518 obj_surface->user_disable_tiling = false;
1519 obj_surface->user_h_stride_set = false;
1520 obj_surface->user_v_stride_set = false;
1522 obj_surface->subpic_render_idx = 0;
1523 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1524 obj_surface->subpic[j] = VA_INVALID_ID;
1525 obj_surface->obj_subpic[j] = NULL;
1528 assert(i965->codec_info->min_linear_wpitch);
1529 assert(i965->codec_info->min_linear_hpitch);
1530 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1531 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1532 obj_surface->flags = SURFACE_REFERENCED;
1533 obj_surface->fourcc = 0;
1534 obj_surface->expected_format = format;
1535 obj_surface->bo = NULL;
1536 obj_surface->locked_image_id = VA_INVALID_ID;
1537 obj_surface->derived_image_id = VA_INVALID_ID;
1538 obj_surface->private_data = NULL;
1539 obj_surface->free_private_data = NULL;
1540 obj_surface->subsampling = SUBSAMPLE_YUV420;
1542 obj_surface->wrapper_surface = VA_INVALID_ID;
1543 obj_surface->exported_primefd = -1;
1545 switch (memory_type) {
1546 case I965_SURFACE_MEM_NATIVE:
1547 if (memory_attibute) {
1548 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1549 obj_surface->user_disable_tiling = true;
1551 if (memory_attibute->pixel_format) {
1552 if (expected_fourcc)
1553 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1555 expected_fourcc = memory_attibute->pixel_format;
1557 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1558 if (memory_attibute->pitches[0]) {
1559 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1560 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1561 obj_surface->width = memory_attibute->pitches[0];
1562 obj_surface->user_h_stride_set = true;
1563 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1564 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1566 if (memory_attibute->offsets[1]) {
1567 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1568 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1569 obj_surface->user_v_stride_set = true;
1570 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1571 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1575 vaStatus = i965_surface_native_memory(ctx,
1581 case I965_SURFACE_MEM_GEM_FLINK:
1582 case I965_SURFACE_MEM_DRM_PRIME:
1583 vaStatus = i965_suface_external_memory(ctx,
1590 if (VA_STATUS_SUCCESS != vaStatus) {
1591 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1596 /* Error recovery */
1597 if (VA_STATUS_SUCCESS != vaStatus) {
1598 /* surfaces[i-1] was the last successful allocation */
1600 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1602 surfaces[i] = VA_INVALID_SURFACE;
1603 assert(obj_surface);
1604 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1612 i965_CreateSurfaces(VADriverContextP ctx,
1617 VASurfaceID *surfaces) /* out */
1619 return i965_CreateSurfaces2(ctx,
1630 i965_DestroySurfaces(VADriverContextP ctx,
1631 VASurfaceID *surface_list,
1634 struct i965_driver_data *i965 = i965_driver_data(ctx);
1636 VAStatus va_status = VA_STATUS_SUCCESS;
1638 for (i = num_surfaces; i--; ) {
1639 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1641 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1643 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1644 i965->wrapper_pdrvctx) {
1645 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1646 vaDestroySurfaces(i965->wrapper_pdrvctx,
1647 &(obj_surface->wrapper_surface),
1649 obj_surface->wrapper_surface = VA_INVALID_ID;
1651 if (obj_surface->exported_primefd >= 0) {
1652 close(obj_surface->exported_primefd);
1653 obj_surface->exported_primefd = -1;
1656 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1663 i965_QueryImageFormats(VADriverContextP ctx,
1664 VAImageFormat *format_list, /* out */
1665 int *num_formats) /* out */
1669 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1670 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1672 format_list[n] = m->va_format;
1678 return VA_STATUS_SUCCESS;
1682 * Guess the format when the usage of a VA surface is unknown
1683 * 1. Without a valid context: YV12
1684 * 2. The current context is valid:
1685 * a) always NV12 on GEN6 and later
1686 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1689 i965_guess_surface_format(VADriverContextP ctx,
1690 VASurfaceID surface,
1691 unsigned int *fourcc,
1692 unsigned int *is_tiled)
1694 struct i965_driver_data *i965 = i965_driver_data(ctx);
1695 struct object_context *obj_context = NULL;
1696 struct object_config *obj_config = NULL;
1698 *fourcc = VA_FOURCC_YV12;
1701 if (i965->current_context_id == VA_INVALID_ID)
1704 obj_context = CONTEXT(i965->current_context_id);
1709 obj_config = obj_context->obj_config;
1715 if (IS_GEN6(i965->intel.device_info) ||
1716 IS_GEN7(i965->intel.device_info) ||
1717 IS_GEN8(i965->intel.device_info) ||
1718 IS_GEN9(i965->intel.device_info)) {
1719 *fourcc = VA_FOURCC_NV12;
1724 switch (obj_config->profile) {
1725 case VAProfileMPEG2Simple:
1726 case VAProfileMPEG2Main:
1727 *fourcc = VA_FOURCC_I420;
1732 *fourcc = VA_FOURCC_NV12;
1739 i965_QuerySubpictureFormats(VADriverContextP ctx,
1740 VAImageFormat *format_list, /* out */
1741 unsigned int *flags, /* out */
1742 unsigned int *num_formats) /* out */
1746 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1747 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1749 format_list[n] = m->va_format;
1751 flags[n] = m->va_flags;
1757 return VA_STATUS_SUCCESS;
1761 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1763 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1765 object_heap_free(heap, obj);
1769 i965_CreateSubpicture(VADriverContextP ctx,
1771 VASubpictureID *subpicture) /* out */
1773 struct i965_driver_data *i965 = i965_driver_data(ctx);
1774 VASubpictureID subpicID = NEW_SUBPIC_ID()
1775 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1778 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1780 struct object_image *obj_image = IMAGE(image);
1782 return VA_STATUS_ERROR_INVALID_IMAGE;
1784 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1786 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1788 *subpicture = subpicID;
1789 obj_subpic->image = image;
1790 obj_subpic->obj_image = obj_image;
1791 obj_subpic->format = m->format;
1792 obj_subpic->width = obj_image->image.width;
1793 obj_subpic->height = obj_image->image.height;
1794 obj_subpic->pitch = obj_image->image.pitches[0];
1795 obj_subpic->bo = obj_image->bo;
1796 obj_subpic->global_alpha = 1.0;
1798 return VA_STATUS_SUCCESS;
1802 i965_DestroySubpicture(VADriverContextP ctx,
1803 VASubpictureID subpicture)
1805 struct i965_driver_data *i965 = i965_driver_data(ctx);
1806 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1809 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1811 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1812 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1813 return VA_STATUS_SUCCESS;
1817 i965_SetSubpictureImage(VADriverContextP ctx,
1818 VASubpictureID subpicture,
1822 return VA_STATUS_ERROR_UNIMPLEMENTED;
1826 i965_SetSubpictureChromakey(VADriverContextP ctx,
1827 VASubpictureID subpicture,
1828 unsigned int chromakey_min,
1829 unsigned int chromakey_max,
1830 unsigned int chromakey_mask)
1833 return VA_STATUS_ERROR_UNIMPLEMENTED;
1837 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1838 VASubpictureID subpicture,
1841 struct i965_driver_data *i965 = i965_driver_data(ctx);
1842 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1844 if(global_alpha > 1.0 || global_alpha < 0.0){
1845 return VA_STATUS_ERROR_INVALID_PARAMETER;
1849 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1851 obj_subpic->global_alpha = global_alpha;
1853 return VA_STATUS_SUCCESS;
1857 i965_AssociateSubpicture(VADriverContextP ctx,
1858 VASubpictureID subpicture,
1859 VASurfaceID *target_surfaces,
1861 short src_x, /* upper left offset in subpicture */
1863 unsigned short src_width,
1864 unsigned short src_height,
1865 short dest_x, /* upper left offset in surface */
1867 unsigned short dest_width,
1868 unsigned short dest_height,
1870 * whether to enable chroma-keying or global-alpha
1871 * see VA_SUBPICTURE_XXX values
1875 struct i965_driver_data *i965 = i965_driver_data(ctx);
1876 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1880 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1882 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1884 obj_subpic->src_rect.x = src_x;
1885 obj_subpic->src_rect.y = src_y;
1886 obj_subpic->src_rect.width = src_width;
1887 obj_subpic->src_rect.height = src_height;
1888 obj_subpic->dst_rect.x = dest_x;
1889 obj_subpic->dst_rect.y = dest_y;
1890 obj_subpic->dst_rect.width = dest_width;
1891 obj_subpic->dst_rect.height = dest_height;
1892 obj_subpic->flags = flags;
1894 for (i = 0; i < num_surfaces; i++) {
1895 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1897 return VA_STATUS_ERROR_INVALID_SURFACE;
1899 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1900 if(obj_surface->subpic[j] == VA_INVALID_ID){
1901 assert(obj_surface->obj_subpic[j] == NULL);
1902 obj_surface->subpic[j] = subpicture;
1903 obj_surface->obj_subpic[j] = obj_subpic;
1908 if(j == I965_MAX_SUBPIC_SUM){
1909 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1913 return VA_STATUS_SUCCESS;
1918 i965_DeassociateSubpicture(VADriverContextP ctx,
1919 VASubpictureID subpicture,
1920 VASurfaceID *target_surfaces,
1923 struct i965_driver_data *i965 = i965_driver_data(ctx);
1924 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1928 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1930 for (i = 0; i < num_surfaces; i++) {
1931 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1933 return VA_STATUS_ERROR_INVALID_SURFACE;
1935 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1936 if (obj_surface->subpic[j] == subpicture) {
1937 assert(obj_surface->obj_subpic[j] == obj_subpic);
1938 obj_surface->subpic[j] = VA_INVALID_ID;
1939 obj_surface->obj_subpic[j] = NULL;
1944 if(j == I965_MAX_SUBPIC_SUM){
1945 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1948 return VA_STATUS_SUCCESS;
1952 i965_reference_buffer_store(struct buffer_store **ptr,
1953 struct buffer_store *buffer_store)
1955 assert(*ptr == NULL);
1958 buffer_store->ref_count++;
1959 *ptr = buffer_store;
1964 i965_release_buffer_store(struct buffer_store **ptr)
1966 struct buffer_store *buffer_store = *ptr;
1968 if (buffer_store == NULL)
1971 assert(buffer_store->bo || buffer_store->buffer);
1972 assert(!(buffer_store->bo && buffer_store->buffer));
1973 buffer_store->ref_count--;
1975 if (buffer_store->ref_count == 0) {
1976 dri_bo_unreference(buffer_store->bo);
1977 free(buffer_store->buffer);
1978 buffer_store->bo = NULL;
1979 buffer_store->buffer = NULL;
1987 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1989 struct object_context *obj_context = (struct object_context *)obj;
1992 if (obj_context->hw_context) {
1993 obj_context->hw_context->destroy(obj_context->hw_context);
1994 obj_context->hw_context = NULL;
1997 if (obj_context->codec_type == CODEC_PROC) {
1998 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2000 } else if (obj_context->codec_type == CODEC_ENC) {
2001 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
2002 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2003 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
2005 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2006 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2008 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
2009 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2011 free(obj_context->codec_state.encode.slice_params);
2013 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2014 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2015 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2017 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2018 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2020 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2021 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2023 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2024 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
2026 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2027 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2029 free(obj_context->codec_state.encode.slice_params_ext);
2030 if (obj_context->codec_state.encode.slice_rawdata_index) {
2031 free(obj_context->codec_state.encode.slice_rawdata_index);
2032 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2034 if (obj_context->codec_state.encode.slice_rawdata_count) {
2035 free(obj_context->codec_state.encode.slice_rawdata_count);
2036 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2039 if (obj_context->codec_state.encode.slice_header_index) {
2040 free(obj_context->codec_state.encode.slice_header_index);
2041 obj_context->codec_state.encode.slice_header_index = NULL;
2044 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2045 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2046 free(obj_context->codec_state.encode.packed_header_params_ext);
2048 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2049 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2050 free(obj_context->codec_state.encode.packed_header_data_ext);
2053 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2054 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2056 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2057 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2058 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2060 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2061 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2063 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2064 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2066 free(obj_context->codec_state.decode.slice_params);
2067 free(obj_context->codec_state.decode.slice_datas);
2070 free(obj_context->render_targets);
2071 object_heap_free(heap, obj);
2075 i965_CreateContext(VADriverContextP ctx,
2076 VAConfigID config_id,
2080 VASurfaceID *render_targets,
2081 int num_render_targets,
2082 VAContextID *context) /* out */
2084 struct i965_driver_data *i965 = i965_driver_data(ctx);
2085 struct object_config *obj_config = CONFIG(config_id);
2086 struct object_context *obj_context = NULL;
2087 VAConfigAttrib *attrib;
2088 VAStatus vaStatus = VA_STATUS_SUCCESS;
2092 if (NULL == obj_config) {
2093 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2097 if (picture_width > i965->codec_info->max_width ||
2098 picture_height > i965->codec_info->max_height) {
2099 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2104 /* Validate picture dimensions */
2105 contextID = NEW_CONTEXT_ID();
2106 obj_context = CONTEXT(contextID);
2108 if (NULL == obj_context) {
2109 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2113 *context = contextID;
2114 obj_context->flags = flag;
2115 obj_context->context_id = contextID;
2116 obj_context->obj_config = obj_config;
2117 obj_context->picture_width = picture_width;
2118 obj_context->picture_height = picture_height;
2119 obj_context->num_render_targets = num_render_targets;
2120 obj_context->render_targets =
2121 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2122 obj_context->hw_context = NULL;
2123 obj_context->wrapper_context = VA_INVALID_ID;
2125 if (!obj_context->render_targets)
2126 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2128 for(i = 0; i < num_render_targets; i++) {
2129 if (NULL == SURFACE(render_targets[i])) {
2130 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2134 obj_context->render_targets[i] = render_targets[i];
2137 if (VA_STATUS_SUCCESS == vaStatus) {
2138 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2139 obj_context->codec_type = CODEC_PROC;
2140 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2141 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2142 assert(i965->codec_info->proc_hw_context_init);
2143 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2144 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2145 (VAEntrypointEncPicture == obj_config->entrypoint)) { /*encode routine only*/
2146 VAConfigAttrib *packed_attrib;
2147 obj_context->codec_type = CODEC_ENC;
2148 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2149 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2150 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
2151 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
2152 sizeof(*obj_context->codec_state.encode.slice_params));
2153 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2154 obj_context->codec_state.encode.packed_header_params_ext =
2155 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2156 sizeof(struct buffer_store *));
2158 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2159 obj_context->codec_state.encode.packed_header_data_ext =
2160 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2161 sizeof(struct buffer_store *));
2163 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2164 obj_context->codec_state.encode.slice_rawdata_index =
2165 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2166 obj_context->codec_state.encode.slice_rawdata_count =
2167 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2169 obj_context->codec_state.encode.slice_header_index =
2170 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2172 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2174 obj_context->codec_state.encode.slice_index = 0;
2175 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2177 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2179 /* use the default value. SPS/PPS/RAWDATA is passed from user
2180 * while Slice_header data is generated by driver.
2182 obj_context->codec_state.encode.packed_header_flag =
2183 VA_ENC_PACKED_HEADER_SEQUENCE |
2184 VA_ENC_PACKED_HEADER_PICTURE |
2185 VA_ENC_PACKED_HEADER_RAW_DATA;
2187 assert(i965->codec_info->enc_hw_context_init);
2188 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2190 obj_context->codec_type = CODEC_DEC;
2191 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2192 obj_context->codec_state.decode.current_render_target = -1;
2193 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2194 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2195 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2196 sizeof(*obj_context->codec_state.decode.slice_params));
2197 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2198 sizeof(*obj_context->codec_state.decode.slice_datas));
2200 assert(i965->codec_info->dec_hw_context_init);
2201 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2205 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2207 return VA_STATUS_ERROR_INVALID_CONFIG;
2208 obj_context->codec_state.base.chroma_formats = attrib->value;
2210 if (obj_config->wrapper_config != VA_INVALID_ID) {
2211 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2212 * So it won't check i965->wrapper_pdrvctx again.
2213 * Fixme if it is incorrect.
2215 VAGenericID wrapper_context;
2218 * The render_surface is not passed when calling
2220 * If it is needed, we must get the wrapped surface
2221 * for the corresponding Surface_list.
2222 * So the wrapped surface conversion is deferred.
2224 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2225 vaCreateContext(i965->wrapper_pdrvctx,
2226 obj_config->wrapper_config,
2227 picture_width, picture_height,
2231 if (vaStatus == VA_STATUS_SUCCESS)
2232 obj_context->wrapper_context = wrapper_context;
2234 /* Error recovery */
2235 if (VA_STATUS_SUCCESS != vaStatus) {
2236 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2239 i965->current_context_id = contextID;
2245 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2247 struct i965_driver_data *i965 = i965_driver_data(ctx);
2248 struct object_context *obj_context = CONTEXT(context);
2249 VAStatus va_status = VA_STATUS_SUCCESS;
2251 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2253 if (i965->current_context_id == context)
2254 i965->current_context_id = VA_INVALID_ID;
2256 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2257 i965->wrapper_pdrvctx) {
2258 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2259 vaDestroyContext(i965->wrapper_pdrvctx,
2260 obj_context->wrapper_context));
2262 obj_context->wrapper_context = VA_INVALID_ID;
2265 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2271 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2273 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2275 assert(obj_buffer->buffer_store);
2276 i965_release_buffer_store(&obj_buffer->buffer_store);
2277 object_heap_free(heap, obj);
2281 i965_create_buffer_internal(VADriverContextP ctx,
2282 VAContextID context,
2285 unsigned int num_elements,
2290 struct i965_driver_data *i965 = i965_driver_data(ctx);
2291 struct object_buffer *obj_buffer = NULL;
2292 struct buffer_store *buffer_store = NULL;
2294 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2295 struct object_context *obj_context = CONTEXT(context);
2296 int wrapper_flag = 0;
2300 case VAPictureParameterBufferType:
2301 case VAIQMatrixBufferType:
2302 case VAQMatrixBufferType:
2303 case VABitPlaneBufferType:
2304 case VASliceGroupMapBufferType:
2305 case VASliceParameterBufferType:
2306 case VASliceDataBufferType:
2307 case VAMacroblockParameterBufferType:
2308 case VAResidualDataBufferType:
2309 case VADeblockingParameterBufferType:
2310 case VAImageBufferType:
2311 case VAEncCodedBufferType:
2312 case VAEncSequenceParameterBufferType:
2313 case VAEncPictureParameterBufferType:
2314 case VAEncSliceParameterBufferType:
2315 case VAEncPackedHeaderParameterBufferType:
2316 case VAEncPackedHeaderDataBufferType:
2317 case VAEncMiscParameterBufferType:
2318 case VAProcPipelineParameterBufferType:
2319 case VAProcFilterParameterBufferType:
2320 case VAHuffmanTableBufferType:
2321 case VAProbabilityBufferType:
2326 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2329 bufferID = NEW_BUFFER_ID();
2330 obj_buffer = BUFFER(bufferID);
2332 if (NULL == obj_buffer) {
2333 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2336 if (type == VAEncCodedBufferType) {
2337 size += I965_CODEDBUFFER_HEADER_SIZE;
2338 size += 0x1000; /* for upper bound check */
2341 obj_buffer->max_num_elements = num_elements;
2342 obj_buffer->num_elements = num_elements;
2343 obj_buffer->size_element = size;
2344 obj_buffer->type = type;
2345 obj_buffer->export_refcount = 0;
2346 obj_buffer->buffer_store = NULL;
2347 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2348 obj_buffer->context_id = context;
2350 buffer_store = calloc(1, sizeof(struct buffer_store));
2351 assert(buffer_store);
2352 buffer_store->ref_count = 1;
2355 (obj_context->wrapper_context != VA_INVALID_ID) &&
2356 i965->wrapper_pdrvctx) {
2357 VAGenericID wrapper_buffer;
2358 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2360 CALL_VTABLE(pdrvctx, vaStatus,
2361 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2362 data, &wrapper_buffer));
2363 if (vaStatus == VA_STATUS_SUCCESS) {
2364 obj_buffer->wrapper_buffer = wrapper_buffer;
2372 if (store_bo != NULL) {
2373 buffer_store->bo = store_bo;
2374 dri_bo_reference(buffer_store->bo);
2376 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2377 if (data && !wrapper_flag)
2378 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2379 } else if (type == VASliceDataBufferType ||
2380 type == VAImageBufferType ||
2381 type == VAEncCodedBufferType ||
2382 type == VAProbabilityBufferType) {
2384 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2385 * So it is enough to allocate one 64 byte bo
2388 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2391 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2393 size * num_elements, 64);
2394 assert(buffer_store->bo);
2396 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2397 * In fact it can be skipped. But it is still allocated and it is
2398 * only to follow the normal flowchart of buffer_allocation/release.
2400 if (!wrapper_flag) {
2401 if (type == VAEncCodedBufferType) {
2402 struct i965_coded_buffer_segment *coded_buffer_segment;
2404 dri_bo_map(buffer_store->bo, 1);
2405 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2406 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2407 coded_buffer_segment->base.bit_offset = 0;
2408 coded_buffer_segment->base.status = 0;
2409 coded_buffer_segment->base.buf = NULL;
2410 coded_buffer_segment->base.next = NULL;
2411 coded_buffer_segment->mapped = 0;
2412 coded_buffer_segment->codec = 0;
2413 coded_buffer_segment->status_support = 0;
2414 dri_bo_unmap(buffer_store->bo);
2416 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2423 if (type == VAEncPackedHeaderDataBufferType) {
2424 msize = ALIGN(size, 4);
2427 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2429 buffer_store->buffer = malloc(4);
2431 buffer_store->buffer = malloc(msize * num_elements);
2432 assert(buffer_store->buffer);
2434 if (data && (!wrapper_flag))
2435 memcpy(buffer_store->buffer, data, size * num_elements);
2438 buffer_store->num_elements = obj_buffer->num_elements;
2439 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2440 i965_release_buffer_store(&buffer_store);
2443 return VA_STATUS_SUCCESS;
2447 i965_CreateBuffer(VADriverContextP ctx,
2448 VAContextID context, /* in */
2449 VABufferType type, /* in */
2450 unsigned int size, /* in */
2451 unsigned int num_elements, /* in */
2452 void *data, /* in */
2453 VABufferID *buf_id) /* out */
2455 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2460 i965_BufferSetNumElements(VADriverContextP ctx,
2461 VABufferID buf_id, /* in */
2462 unsigned int num_elements) /* in */
2464 struct i965_driver_data *i965 = i965_driver_data(ctx);
2465 struct object_buffer *obj_buffer = BUFFER(buf_id);
2466 VAStatus vaStatus = VA_STATUS_SUCCESS;
2468 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2470 /* When the wrapper_buffer exists, it will wrapper to the
2471 * buffer allocated from backend driver.
2473 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2474 i965->wrapper_pdrvctx) {
2475 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2477 CALL_VTABLE(pdrvctx, vaStatus,
2478 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2483 if ((num_elements < 0) ||
2484 (num_elements > obj_buffer->max_num_elements)) {
2485 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2487 obj_buffer->num_elements = num_elements;
2488 if (obj_buffer->buffer_store != NULL) {
2489 obj_buffer->buffer_store->num_elements = num_elements;
2497 i965_MapBuffer(VADriverContextP ctx,
2498 VABufferID buf_id, /* in */
2499 void **pbuf) /* out */
2501 struct i965_driver_data *i965 = i965_driver_data(ctx);
2502 struct object_buffer *obj_buffer = BUFFER(buf_id);
2503 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2504 struct object_context *obj_context = CONTEXT(obj_buffer->context_id);
2506 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2508 /* When the wrapper_buffer exists, it will wrapper to the
2509 * buffer allocated from backend driver.
2511 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2512 i965->wrapper_pdrvctx) {
2513 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2515 CALL_VTABLE(pdrvctx, vaStatus,
2516 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2520 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2521 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2523 if (obj_buffer->export_refcount > 0)
2524 return VA_STATUS_ERROR_INVALID_BUFFER;
2526 if (NULL != obj_buffer->buffer_store->bo) {
2527 unsigned int tiling, swizzle;
2529 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2531 if (tiling != I915_TILING_NONE)
2532 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2534 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2536 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2537 *pbuf = obj_buffer->buffer_store->bo->virtual;
2538 vaStatus = VA_STATUS_SUCCESS;
2540 if (obj_buffer->type == VAEncCodedBufferType) {
2542 unsigned char *buffer = NULL;
2543 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2544 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2546 if (!coded_buffer_segment->mapped) {
2547 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2549 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2552 obj_context->hw_context &&
2553 obj_context->hw_context->get_status &&
2554 coded_buffer_segment->status_support) {
2555 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2557 if (coded_buffer_segment->codec == CODEC_H264 ||
2558 coded_buffer_segment->codec == CODEC_H264_MVC) {
2559 delimiter0 = H264_DELIMITER0;
2560 delimiter1 = H264_DELIMITER1;
2561 delimiter2 = H264_DELIMITER2;
2562 delimiter3 = H264_DELIMITER3;
2563 delimiter4 = H264_DELIMITER4;
2564 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2565 delimiter0 = MPEG2_DELIMITER0;
2566 delimiter1 = MPEG2_DELIMITER1;
2567 delimiter2 = MPEG2_DELIMITER2;
2568 delimiter3 = MPEG2_DELIMITER3;
2569 delimiter4 = MPEG2_DELIMITER4;
2570 } else if(coded_buffer_segment->codec == CODEC_JPEG) {
2571 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2574 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2575 delimiter0 = HEVC_DELIMITER0;
2576 delimiter1 = HEVC_DELIMITER1;
2577 delimiter2 = HEVC_DELIMITER2;
2578 delimiter3 = HEVC_DELIMITER3;
2579 delimiter4 = HEVC_DELIMITER4;
2580 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2581 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2584 if(coded_buffer_segment->codec == CODEC_JPEG) {
2585 for(i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2586 if( (buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2590 coded_buffer_segment->base.size = i + 2;
2591 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2592 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2593 so it don't need to traversal the coded buffer */
2594 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2595 if ((buffer[i] == delimiter0) &&
2596 (buffer[i + 1] == delimiter1) &&
2597 (buffer[i + 2] == delimiter2) &&
2598 (buffer[i + 3] == delimiter3) &&
2599 (buffer[i + 4] == delimiter4))
2603 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2604 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2606 coded_buffer_segment->base.size = i;
2609 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2610 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2613 vaStatus = VA_STATUS_SUCCESS;
2616 coded_buffer_segment->mapped = 1;
2618 assert(coded_buffer_segment->base.buf);
2619 vaStatus = VA_STATUS_SUCCESS;
2622 } else if (NULL != obj_buffer->buffer_store->buffer) {
2623 *pbuf = obj_buffer->buffer_store->buffer;
2624 vaStatus = VA_STATUS_SUCCESS;
2631 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2633 struct i965_driver_data *i965 = i965_driver_data(ctx);
2634 struct object_buffer *obj_buffer = BUFFER(buf_id);
2635 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2637 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2638 return VA_STATUS_ERROR_INVALID_BUFFER;
2640 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2641 /* When the wrapper_buffer exists, it will wrapper to the
2642 * buffer allocated from backend driver.
2644 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2645 i965->wrapper_pdrvctx) {
2646 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2648 CALL_VTABLE(pdrvctx, vaStatus,
2649 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2653 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2654 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2656 if (NULL != obj_buffer->buffer_store->bo) {
2657 unsigned int tiling, swizzle;
2659 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2661 if (tiling != I915_TILING_NONE)
2662 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2664 dri_bo_unmap(obj_buffer->buffer_store->bo);
2666 vaStatus = VA_STATUS_SUCCESS;
2667 } else if (NULL != obj_buffer->buffer_store->buffer) {
2669 vaStatus = VA_STATUS_SUCCESS;
2676 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2678 struct i965_driver_data *i965 = i965_driver_data(ctx);
2679 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2680 VAStatus va_status = VA_STATUS_SUCCESS;
2682 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2684 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2685 i965->wrapper_pdrvctx) {
2686 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2687 vaDestroyBuffer(i965->wrapper_pdrvctx,
2688 obj_buffer->wrapper_buffer));
2689 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2692 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2698 i965_BeginPicture(VADriverContextP ctx,
2699 VAContextID context,
2700 VASurfaceID render_target)
2702 struct i965_driver_data *i965 = i965_driver_data(ctx);
2703 struct object_context *obj_context = CONTEXT(context);
2704 struct object_surface *obj_surface = SURFACE(render_target);
2705 struct object_config *obj_config;
2706 VAStatus vaStatus = VA_STATUS_SUCCESS;
2709 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2710 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2711 obj_config = obj_context->obj_config;
2712 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2714 if (is_surface_busy(i965, obj_surface))
2715 return VA_STATUS_ERROR_SURFACE_BUSY;
2717 if (obj_context->codec_type == CODEC_PROC) {
2718 obj_context->codec_state.proc.current_render_target = render_target;
2719 } else if (obj_context->codec_type == CODEC_ENC) {
2720 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2722 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
2723 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2726 obj_context->codec_state.encode.num_slice_params = 0;
2729 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2731 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2732 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2734 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2735 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2737 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2738 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2740 obj_context->codec_state.encode.num_slice_params_ext = 0;
2741 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2742 obj_context->codec_state.encode.last_packed_header_type = 0;
2743 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2744 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2745 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2746 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2747 memset(obj_context->codec_state.encode.slice_header_index, 0,
2748 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2750 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2751 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2752 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2753 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2754 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2755 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2756 obj_context->codec_state.encode.slice_index = 0;
2757 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2759 obj_context->codec_state.decode.current_render_target = render_target;
2760 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2761 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2762 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2763 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2765 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2766 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2767 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2770 obj_context->codec_state.decode.num_slice_params = 0;
2771 obj_context->codec_state.decode.num_slice_datas = 0;
2773 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2774 i965->wrapper_pdrvctx) {
2775 if (obj_surface->wrapper_surface == VA_INVALID_ID)
2776 vaStatus = i965_surface_wrapper(ctx, render_target);
2778 if (vaStatus != VA_STATUS_SUCCESS)
2781 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2782 vaBeginPicture(i965->wrapper_pdrvctx,
2783 obj_context->wrapper_context,
2784 obj_surface->wrapper_surface));
2791 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2793 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2795 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2796 struct object_context *obj_context, \
2797 struct object_buffer *obj_buffer) \
2799 struct category##_state *category = &obj_context->codec_state.category; \
2800 i965_release_buffer_store(&category->member); \
2801 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2802 return VA_STATUS_SUCCESS; \
2805 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2807 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2808 struct object_context *obj_context, \
2809 struct object_buffer *obj_buffer) \
2811 struct category##_state *category = &obj_context->codec_state.category; \
2812 if (category->num_##member == category->max_##member) { \
2813 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2814 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2815 category->max_##member += NUM_SLICES; \
2817 i965_release_buffer_store(&category->member[category->num_##member]); \
2818 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2819 category->num_##member++; \
2820 return VA_STATUS_SUCCESS; \
2823 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2825 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2826 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2827 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2828 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2829 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2830 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2832 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2833 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2834 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2838 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
2839 VABufferID *buffers,
2842 struct i965_driver_data *i965 = i965_driver_data(ctx);
2843 VAStatus vaStatus = VA_STATUS_SUCCESS;
2845 VADecPictureParameterBufferVP9 *pVp9PicParams;
2846 VADriverContextP pdrvctx;
2847 struct object_buffer *obj_buffer;
2849 pdrvctx = i965->wrapper_pdrvctx;
2850 /* do the conversion of VADecPictureParameterBufferVP9 */
2851 for (i = 0; i < num_buffers; i++) {
2852 obj_buffer = BUFFER(buffers[i]);
2857 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
2860 if (obj_buffer->type == VAPictureParameterBufferType) {
2862 VASurfaceID surface_id;
2863 struct object_surface *obj_surface;
2865 pdrvctx = i965->wrapper_pdrvctx;
2867 CALL_VTABLE(pdrvctx, vaStatus,
2868 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
2869 (void **)(&pVp9PicParams)));
2871 if (vaStatus != VA_STATUS_SUCCESS)
2874 for (j = 0; j < 8; j++) {
2875 surface_id = pVp9PicParams->reference_frames[j];
2876 obj_surface = SURFACE(surface_id);
2881 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
2882 vaStatus = i965_surface_wrapper(ctx, surface_id);
2883 if (vaStatus != VA_STATUS_SUCCESS) {
2884 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
2885 obj_buffer->wrapper_buffer);
2890 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
2892 CALL_VTABLE(pdrvctx, vaStatus,
2893 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2898 return VA_STATUS_SUCCESS;
2905 i965_decoder_wrapper_picture(VADriverContextP ctx,
2906 VAContextID context,
2907 VABufferID *buffers,
2910 struct i965_driver_data *i965 = i965_driver_data(ctx);
2911 struct object_context *obj_context = CONTEXT(context);
2912 VAStatus vaStatus = VA_STATUS_SUCCESS;
2914 VADriverContextP pdrvctx;
2915 struct object_buffer *obj_buffer;
2917 if (obj_context == NULL)
2918 return VA_STATUS_ERROR_INVALID_CONTEXT;
2920 /* When it is not wrapped context, continue the normal flowchart */
2921 if (obj_context->wrapper_context == VA_INVALID_ID)
2924 if (obj_context->obj_config &&
2925 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
2926 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
2928 return VA_STATUS_ERROR_INVALID_PARAMETER;
2930 pdrvctx = i965->wrapper_pdrvctx;
2932 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2933 obj_buffer = BUFFER(buffers[i]);
2938 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
2939 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
2943 CALL_VTABLE(pdrvctx, vaStatus,
2944 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
2945 &(obj_buffer->wrapper_buffer), 1));
2951 i965_decoder_render_picture(VADriverContextP ctx,
2952 VAContextID context,
2953 VABufferID *buffers,
2956 struct i965_driver_data *i965 = i965_driver_data(ctx);
2957 struct object_context *obj_context = CONTEXT(context);
2958 VAStatus vaStatus = VA_STATUS_SUCCESS;
2961 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2963 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2964 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2967 return VA_STATUS_ERROR_INVALID_BUFFER;
2969 switch (obj_buffer->type) {
2970 case VAPictureParameterBufferType:
2971 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2974 case VAIQMatrixBufferType:
2975 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2978 case VABitPlaneBufferType:
2979 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2982 case VASliceParameterBufferType:
2983 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2986 case VASliceDataBufferType:
2987 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2990 case VAHuffmanTableBufferType:
2991 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2994 case VAProbabilityBufferType:
2995 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
2999 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3004 if ((vaStatus == VA_STATUS_SUCCESS) &&
3005 (obj_context->wrapper_context != VA_INVALID_ID))
3006 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3011 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3013 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3014 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3015 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3016 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3017 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3018 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3019 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3020 /* extended buffer */
3021 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3022 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3024 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3025 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3026 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3028 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3029 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3032 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3033 struct object_context *obj_context,
3034 struct object_buffer *obj_buffer,
3037 struct encode_state *encode = &obj_context->codec_state.encode;
3039 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3040 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3041 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3042 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3044 return VA_STATUS_SUCCESS;
3048 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3049 struct object_context *obj_context,
3050 struct object_buffer *obj_buffer,
3053 struct encode_state *encode = &obj_context->codec_state.encode;
3055 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3056 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3057 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3058 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3060 return VA_STATUS_SUCCESS;
3064 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3065 struct object_context *obj_context,
3066 struct object_buffer *obj_buffer)
3068 struct encode_state *encode = &obj_context->codec_state.encode;
3069 VAEncMiscParameterBuffer *param = NULL;
3071 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3072 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3074 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3076 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3077 return VA_STATUS_ERROR_INVALID_PARAMETER;
3079 i965_release_buffer_store(&encode->misc_param[param->type]);
3080 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
3082 return VA_STATUS_SUCCESS;
3086 i965_encoder_render_picture(VADriverContextP ctx,
3087 VAContextID context,
3088 VABufferID *buffers,
3091 struct i965_driver_data *i965 = i965_driver_data(ctx);
3092 struct object_context *obj_context = CONTEXT(context);
3093 struct object_config *obj_config;
3094 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3095 struct encode_state *encode;
3098 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3099 obj_config = obj_context->obj_config;
3100 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3102 encode = &obj_context->codec_state.encode;
3103 for (i = 0; i < num_buffers; i++) {
3104 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3107 return VA_STATUS_ERROR_INVALID_BUFFER;
3109 switch (obj_buffer->type) {
3110 case VAQMatrixBufferType:
3111 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3114 case VAIQMatrixBufferType:
3115 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3118 case VAEncSequenceParameterBufferType:
3119 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3122 case VAEncPictureParameterBufferType:
3123 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3126 case VAHuffmanTableBufferType:
3127 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3130 case VAEncSliceParameterBufferType:
3131 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3132 if (vaStatus == VA_STATUS_SUCCESS) {
3133 /* When the max number of slices is updated, it also needs
3134 * to reallocate the arrays that is used to store
3135 * the packed data index/count for the slice
3137 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3138 encode->slice_index++;
3140 if (encode->slice_index == encode->max_slice_num) {
3141 int slice_num = encode->max_slice_num;
3142 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3143 (slice_num + NUM_SLICES) * sizeof(int));
3144 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3145 (slice_num + NUM_SLICES) * sizeof(int));
3146 encode->slice_header_index = realloc(encode->slice_header_index,
3147 (slice_num + NUM_SLICES) * sizeof(int));
3148 memset(encode->slice_rawdata_index + slice_num, 0,
3149 sizeof(int) * NUM_SLICES);
3150 memset(encode->slice_rawdata_count + slice_num, 0,
3151 sizeof(int) * NUM_SLICES);
3152 memset(encode->slice_header_index + slice_num, 0,
3153 sizeof(int) * NUM_SLICES);
3155 encode->max_slice_num += NUM_SLICES;
3156 if ((encode->slice_rawdata_index == NULL) ||
3157 (encode->slice_header_index == NULL) ||
3158 (encode->slice_rawdata_count == NULL)) {
3159 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3166 case VAEncPackedHeaderParameterBufferType:
3168 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3169 encode->last_packed_header_type = param->type;
3171 if ((param->type == VAEncPackedHeaderRawData) ||
3172 (param->type == VAEncPackedHeaderSlice)) {
3173 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3174 } else if((obj_config->profile == VAProfileHEVCMain) &&
3175 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3176 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3179 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3181 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3184 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3189 case VAEncPackedHeaderDataBufferType:
3191 if (encode->last_packed_header_type == 0) {
3192 WARN_ONCE("the packed header data is passed without type!\n");
3193 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3196 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3197 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3198 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3200 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3201 * the packed_slice_header as the delimeter to decide how
3202 * the packed rawdata is inserted for the given slice.
3203 * Otherwise it will use the VAEncSequenceParameterBuffer
3206 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3207 /* store the first index of the packed header data for current slice */
3208 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3209 encode->slice_rawdata_index[encode->slice_index] =
3210 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3212 encode->slice_rawdata_count[encode->slice_index]++;
3213 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3214 /* find one packed slice_header delimeter. And the following
3215 * packed data is for the next slice
3217 encode->slice_header_index[encode->slice_index] =
3218 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3219 encode->slice_index++;
3220 /* Reallocate the buffer to record the index/count of
3221 * packed_data for one slice.
3223 if (encode->slice_index == encode->max_slice_num) {
3224 int slice_num = encode->max_slice_num;
3226 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3227 (slice_num + NUM_SLICES) * sizeof(int));
3228 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3229 (slice_num + NUM_SLICES) * sizeof(int));
3230 encode->slice_header_index = realloc(encode->slice_header_index,
3231 (slice_num + NUM_SLICES) * sizeof(int));
3232 memset(encode->slice_rawdata_index + slice_num, 0,
3233 sizeof(int) * NUM_SLICES);
3234 memset(encode->slice_rawdata_count + slice_num, 0,
3235 sizeof(int) * NUM_SLICES);
3236 memset(encode->slice_header_index + slice_num, 0,
3237 sizeof(int) * NUM_SLICES);
3238 encode->max_slice_num += NUM_SLICES;
3242 if (vaStatus == VA_STATUS_SUCCESS) {
3243 /* store the first index of the packed header data for current slice */
3244 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3245 encode->slice_rawdata_index[encode->slice_index] =
3246 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3248 encode->slice_rawdata_count[encode->slice_index]++;
3249 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3250 if (encode->slice_header_index[encode->slice_index] == 0) {
3251 encode->slice_header_index[encode->slice_index] =
3252 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3254 WARN_ONCE("Multi slice header data is passed for"
3255 " slice %d!\n", encode->slice_index);
3261 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3262 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3263 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3264 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3265 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3266 VA_STATUS_ERROR_ENCODING_ERROR);
3268 if((obj_config->profile == VAProfileHEVCMain) &&
3269 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3271 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3274 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3275 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3277 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3280 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3284 encode->last_packed_header_type = 0;
3288 case VAEncMiscParameterBufferType:
3289 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3295 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3303 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3305 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3306 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3309 i965_proc_render_picture(VADriverContextP ctx,
3310 VAContextID context,
3311 VABufferID *buffers,
3314 struct i965_driver_data *i965 = i965_driver_data(ctx);
3315 struct object_context *obj_context = CONTEXT(context);
3316 VAStatus vaStatus = VA_STATUS_SUCCESS;
3319 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3321 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3322 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3325 return VA_STATUS_ERROR_INVALID_BUFFER;
3327 switch (obj_buffer->type) {
3328 case VAProcPipelineParameterBufferType:
3329 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3333 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3342 i965_RenderPicture(VADriverContextP ctx,
3343 VAContextID context,
3344 VABufferID *buffers,
3347 struct i965_driver_data *i965 = i965_driver_data(ctx);
3348 struct object_context *obj_context;
3349 struct object_config *obj_config;
3350 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3352 obj_context = CONTEXT(context);
3353 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3355 if (num_buffers <= 0)
3356 return VA_STATUS_ERROR_INVALID_PARAMETER;
3358 obj_config = obj_context->obj_config;
3359 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3361 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3362 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3363 } else if ((VAEntrypointEncSlice == obj_config->entrypoint ) ||
3364 (VAEntrypointEncPicture == obj_config->entrypoint)) {
3365 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3367 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3374 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3376 struct i965_driver_data *i965 = i965_driver_data(ctx);
3377 struct object_context *obj_context = CONTEXT(context);
3378 struct object_config *obj_config;
3380 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3381 obj_config = obj_context->obj_config;
3382 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3384 if (obj_context->codec_type == CODEC_PROC) {
3385 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3386 } else if (obj_context->codec_type == CODEC_ENC) {
3387 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) || (VAEntrypointEncPicture == obj_config->entrypoint)), VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3389 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3390 obj_context->codec_state.encode.num_packed_header_data_ext) {
3391 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3392 return VA_STATUS_ERROR_INVALID_PARAMETER;
3394 if (!(obj_context->codec_state.encode.pic_param ||
3395 obj_context->codec_state.encode.pic_param_ext)) {
3396 return VA_STATUS_ERROR_INVALID_PARAMETER;
3398 if (!(obj_context->codec_state.encode.seq_param ||
3399 obj_context->codec_state.encode.seq_param_ext) &&
3400 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3401 return VA_STATUS_ERROR_INVALID_PARAMETER;
3403 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
3404 (obj_context->codec_state.encode.num_slice_params_ext <=0) &&
3405 (obj_config->profile != VAProfileVP8Version0_3)) {
3406 return VA_STATUS_ERROR_INVALID_PARAMETER;
3409 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3410 (obj_context->codec_state.encode.num_slice_params_ext !=
3411 obj_context->codec_state.encode.slice_index)) {
3412 WARN_ONCE("packed slice_header data is missing for some slice"
3413 " under packed SLICE_HEADER mode\n");
3414 return VA_STATUS_ERROR_INVALID_PARAMETER;
3417 if (obj_context->codec_state.decode.pic_param == NULL) {
3418 return VA_STATUS_ERROR_INVALID_PARAMETER;
3420 if (obj_context->codec_state.decode.num_slice_params <=0) {
3421 return VA_STATUS_ERROR_INVALID_PARAMETER;
3423 if (obj_context->codec_state.decode.num_slice_datas <=0) {
3424 return VA_STATUS_ERROR_INVALID_PARAMETER;
3427 if (obj_context->codec_state.decode.num_slice_params !=
3428 obj_context->codec_state.decode.num_slice_datas) {
3429 return VA_STATUS_ERROR_INVALID_PARAMETER;
3432 if (obj_context->wrapper_context != VA_INVALID_ID) {
3433 /* call the vaEndPicture of wrapped driver */
3434 VADriverContextP pdrvctx;
3437 pdrvctx = i965->wrapper_pdrvctx;
3438 CALL_VTABLE(pdrvctx, va_status,
3439 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3445 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3446 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3450 i965_SyncSurface(VADriverContextP ctx,
3451 VASurfaceID render_target)
3453 struct i965_driver_data *i965 = i965_driver_data(ctx);
3454 struct object_surface *obj_surface = SURFACE(render_target);
3456 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3459 drm_intel_bo_wait_rendering(obj_surface->bo);
3461 return VA_STATUS_SUCCESS;
3465 i965_QuerySurfaceStatus(VADriverContextP ctx,
3466 VASurfaceID render_target,
3467 VASurfaceStatus *status) /* out */
3469 struct i965_driver_data *i965 = i965_driver_data(ctx);
3470 struct object_surface *obj_surface = SURFACE(render_target);
3472 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3474 if (obj_surface->bo) {
3475 if (drm_intel_bo_busy(obj_surface->bo)){
3476 *status = VASurfaceRendering;
3479 *status = VASurfaceReady;
3482 *status = VASurfaceReady;
3485 return VA_STATUS_SUCCESS;
3488 static VADisplayAttribute *
3489 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3491 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3494 if (!i965->display_attributes)
3497 for (i = 0; i < i965->num_display_attributes; i++) {
3498 if (i965->display_attributes[i].type == type)
3499 return &i965->display_attributes[i];
3505 i965_display_attributes_terminate(VADriverContextP ctx)
3507 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3509 if (i965->display_attributes) {
3510 free(i965->display_attributes);
3511 i965->display_attributes = NULL;
3512 i965->num_display_attributes = 0;
3517 i965_display_attributes_init(VADriverContextP ctx)
3519 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3521 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3522 i965->display_attributes = malloc(
3523 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3524 if (!i965->display_attributes)
3528 i965->display_attributes,
3529 i965_display_attributes,
3530 sizeof(i965_display_attributes)
3533 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3534 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3535 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3536 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3537 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3539 if (!i965->rotation_attrib ||
3540 !i965->brightness_attrib ||
3541 !i965->contrast_attrib ||
3542 !i965->hue_attrib ||
3543 !i965->saturation_attrib) {
3549 i965_display_attributes_terminate(ctx);
3554 * Query display attributes
3555 * The caller must provide a "attr_list" array that can hold at
3556 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3557 * returned in "attr_list" is returned in "num_attributes".
3560 i965_QueryDisplayAttributes(
3561 VADriverContextP ctx,
3562 VADisplayAttribute *attribs, /* out */
3563 int *num_attribs_ptr /* out */
3566 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3568 if (attribs && num_attribs > 0)
3569 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3571 if (num_attribs_ptr)
3572 *num_attribs_ptr = num_attribs;
3574 return VA_STATUS_SUCCESS;
3578 * Get display attributes
3579 * This function returns the current attribute values in "attr_list".
3580 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3581 * from vaQueryDisplayAttributes() can have their values retrieved.
3584 i965_GetDisplayAttributes(
3585 VADriverContextP ctx,
3586 VADisplayAttribute *attribs, /* inout */
3587 int num_attribs /* in */
3592 for (i = 0; i < num_attribs; i++) {
3593 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3595 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3596 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3597 dst_attrib->min_value = src_attrib->min_value;
3598 dst_attrib->max_value = src_attrib->max_value;
3599 dst_attrib->value = src_attrib->value;
3602 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3604 return VA_STATUS_SUCCESS;
3608 * Set display attributes
3609 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3610 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3611 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3614 i965_SetDisplayAttributes(
3615 VADriverContextP ctx,
3616 VADisplayAttribute *attribs, /* in */
3617 int num_attribs /* in */
3622 for (i = 0; i < num_attribs; i++) {
3623 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3625 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3627 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3629 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3632 if (src_attrib->value < dst_attrib->min_value ||
3633 src_attrib->value > dst_attrib->max_value)
3634 return VA_STATUS_ERROR_INVALID_PARAMETER;
3636 dst_attrib->value = src_attrib->value;
3637 /* XXX: track modified attributes through timestamps */
3639 return VA_STATUS_SUCCESS;
3643 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3644 VASurfaceID surface,
3645 void **buffer, /* out */
3646 unsigned int *stride) /* out */
3649 return VA_STATUS_ERROR_UNIMPLEMENTED;
3653 i965_destroy_heap(struct object_heap *heap,
3654 void (*func)(struct object_heap *heap, struct object_base *object))
3656 struct object_base *object;
3657 object_heap_iterator iter;
3659 object = object_heap_first(heap, &iter);
3665 object = object_heap_next(heap, &iter);
3668 object_heap_destroy(heap);
3673 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3676 i965_CreateImage(VADriverContextP ctx,
3677 VAImageFormat *format,
3680 VAImage *out_image) /* out */
3682 struct i965_driver_data *i965 = i965_driver_data(ctx);
3683 struct object_image *obj_image;
3684 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3686 unsigned int size2, size, awidth, aheight;
3688 out_image->image_id = VA_INVALID_ID;
3689 out_image->buf = VA_INVALID_ID;
3691 image_id = NEW_IMAGE_ID();
3692 if (image_id == VA_INVALID_ID)
3693 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3695 obj_image = IMAGE(image_id);
3697 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3698 obj_image->bo = NULL;
3699 obj_image->palette = NULL;
3700 obj_image->derived_surface = VA_INVALID_ID;
3702 VAImage * const image = &obj_image->image;
3703 image->image_id = image_id;
3704 image->buf = VA_INVALID_ID;
3706 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3708 if ((format->fourcc == VA_FOURCC_YV12) ||
3709 (format->fourcc == VA_FOURCC_I420)) {
3710 if (awidth % 128 != 0) {
3711 awidth = ALIGN(width, 128);
3715 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3716 size = awidth * aheight;
3717 size2 = (awidth / 2) * (aheight / 2);
3719 image->num_palette_entries = 0;
3720 image->entry_bytes = 0;
3721 memset(image->component_order, 0, sizeof(image->component_order));
3723 switch (format->fourcc) {
3724 case VA_FOURCC_IA44:
3725 case VA_FOURCC_AI44:
3726 image->num_planes = 1;
3727 image->pitches[0] = awidth;
3728 image->offsets[0] = 0;
3729 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3730 image->num_palette_entries = 16;
3731 image->entry_bytes = 3;
3732 image->component_order[0] = 'R';
3733 image->component_order[1] = 'G';
3734 image->component_order[2] = 'B';
3736 case VA_FOURCC_IA88:
3737 case VA_FOURCC_AI88:
3738 image->num_planes = 1;
3739 image->pitches[0] = awidth * 2;
3740 image->offsets[0] = 0;
3741 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3742 image->num_palette_entries = 256;
3743 image->entry_bytes = 3;
3744 image->component_order[0] = 'R';
3745 image->component_order[1] = 'G';
3746 image->component_order[2] = 'B';
3748 case VA_FOURCC_ARGB:
3749 case VA_FOURCC_ABGR:
3750 case VA_FOURCC_BGRA:
3751 case VA_FOURCC_RGBA:
3752 case VA_FOURCC_BGRX:
3753 case VA_FOURCC_RGBX:
3754 image->num_planes = 1;
3755 image->pitches[0] = awidth * 4;
3756 image->offsets[0] = 0;
3757 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3759 case VA_FOURCC_YV12:
3760 image->num_planes = 3;
3761 image->pitches[0] = awidth;
3762 image->offsets[0] = 0;
3763 image->pitches[1] = awidth / 2;
3764 image->offsets[1] = size;
3765 image->pitches[2] = awidth / 2;
3766 image->offsets[2] = size + size2;
3767 image->data_size = size + 2 * size2;
3769 case VA_FOURCC_I420:
3770 image->num_planes = 3;
3771 image->pitches[0] = awidth;
3772 image->offsets[0] = 0;
3773 image->pitches[1] = awidth / 2;
3774 image->offsets[1] = size;
3775 image->pitches[2] = awidth / 2;
3776 image->offsets[2] = size + size2;
3777 image->data_size = size + 2 * size2;
3779 case VA_FOURCC_422H:
3780 image->num_planes = 3;
3781 image->pitches[0] = awidth;
3782 image->offsets[0] = 0;
3783 image->pitches[1] = awidth / 2;
3784 image->offsets[1] = size;
3785 image->pitches[2] = awidth / 2;
3786 image->offsets[2] = size + (awidth / 2) * aheight;
3787 image->data_size = size + 2 * ((awidth / 2) * aheight);
3789 case VA_FOURCC_NV12:
3790 image->num_planes = 2;
3791 image->pitches[0] = awidth;
3792 image->offsets[0] = 0;
3793 image->pitches[1] = awidth;
3794 image->offsets[1] = size;
3795 image->data_size = size + 2 * size2;
3797 case VA_FOURCC_YUY2:
3798 case VA_FOURCC_UYVY:
3799 image->num_planes = 1;
3800 image->pitches[0] = awidth * 2;
3801 image->offsets[0] = 0;
3802 image->data_size = size * 2;
3804 case VA_FOURCC_P010:
3805 image->num_planes = 2;
3806 image->pitches[0] = awidth * 2;
3807 image->offsets[0] = 0;
3808 image->pitches[1] = awidth * 2;
3809 image->offsets[1] = size * 2;
3810 image->data_size = size * 2 + 2 * size2 * 2;
3816 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
3817 image->data_size, 1, NULL, &image->buf);
3818 if (va_status != VA_STATUS_SUCCESS)
3821 struct object_buffer *obj_buffer = BUFFER(image->buf);
3824 !obj_buffer->buffer_store ||
3825 !obj_buffer->buffer_store->bo)
3826 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3828 obj_image->bo = obj_buffer->buffer_store->bo;
3829 dri_bo_reference(obj_image->bo);
3831 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3832 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3833 if (!obj_image->palette)
3837 image->image_id = image_id;
3838 image->format = *format;
3839 image->width = width;
3840 image->height = height;
3842 *out_image = *image;
3843 return VA_STATUS_SUCCESS;
3846 i965_DestroyImage(ctx, image_id);
3851 i965_check_alloc_surface_bo(VADriverContextP ctx,
3852 struct object_surface *obj_surface,
3854 unsigned int fourcc,
3855 unsigned int subsampling)
3857 struct i965_driver_data *i965 = i965_driver_data(ctx);
3858 int region_width, region_height;
3860 if (obj_surface->bo) {
3861 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3862 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3863 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
3864 return VA_STATUS_SUCCESS;
3867 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
3868 obj_surface->x_cr_offset = 0;
3870 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
3872 if ((tiled && !obj_surface->user_disable_tiling)) {
3873 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
3874 fourcc != VA_FOURCC_IYUV &&
3875 fourcc != VA_FOURCC_YV12,
3876 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3878 if (obj_surface->user_h_stride_set) {
3879 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
3881 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
3883 if (obj_surface->user_v_stride_set) {
3884 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
3886 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
3888 region_height = obj_surface->height;
3891 case VA_FOURCC_NV12:
3892 case VA_FOURCC_P010:
3893 assert(subsampling == SUBSAMPLE_YUV420);
3894 obj_surface->cb_cr_pitch = obj_surface->width;
3895 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3896 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3897 obj_surface->y_cb_offset = obj_surface->height;
3898 obj_surface->y_cr_offset = obj_surface->height;
3899 region_width = obj_surface->width;
3900 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
3904 case VA_FOURCC_IMC1:
3905 assert(subsampling == SUBSAMPLE_YUV420);
3906 obj_surface->cb_cr_pitch = obj_surface->width;
3907 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3908 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3909 obj_surface->y_cr_offset = obj_surface->height;
3910 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
3911 region_width = obj_surface->width;
3912 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3916 case VA_FOURCC_IMC3:
3917 assert(subsampling == SUBSAMPLE_YUV420);
3918 obj_surface->cb_cr_pitch = obj_surface->width;
3919 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3920 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3921 obj_surface->y_cb_offset = obj_surface->height;
3922 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3923 region_width = obj_surface->width;
3924 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3928 case VA_FOURCC_422H:
3929 assert(subsampling == SUBSAMPLE_YUV422H);
3930 obj_surface->cb_cr_pitch = obj_surface->width;
3931 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3932 obj_surface->cb_cr_height = obj_surface->orig_height;
3933 obj_surface->y_cb_offset = obj_surface->height;
3934 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3935 region_width = obj_surface->width;
3936 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3940 case VA_FOURCC_422V:
3941 assert(subsampling == SUBSAMPLE_YUV422V);
3942 obj_surface->cb_cr_pitch = obj_surface->width;
3943 obj_surface->cb_cr_width = obj_surface->orig_width;
3944 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3945 obj_surface->y_cb_offset = obj_surface->height;
3946 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3947 region_width = obj_surface->width;
3948 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3952 case VA_FOURCC_411P:
3953 assert(subsampling == SUBSAMPLE_YUV411);
3954 obj_surface->cb_cr_pitch = obj_surface->width;
3955 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
3956 obj_surface->cb_cr_height = obj_surface->orig_height;
3957 obj_surface->y_cb_offset = obj_surface->height;
3958 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3959 region_width = obj_surface->width;
3960 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3964 case VA_FOURCC_444P:
3965 assert(subsampling == SUBSAMPLE_YUV444);
3966 obj_surface->cb_cr_pitch = obj_surface->width;
3967 obj_surface->cb_cr_width = obj_surface->orig_width;
3968 obj_surface->cb_cr_height = obj_surface->orig_height;
3969 obj_surface->y_cb_offset = obj_surface->height;
3970 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3971 region_width = obj_surface->width;
3972 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3976 case VA_FOURCC_Y800:
3977 assert(subsampling == SUBSAMPLE_YUV400);
3978 obj_surface->cb_cr_pitch = 0;
3979 obj_surface->cb_cr_width = 0;
3980 obj_surface->cb_cr_height = 0;
3981 obj_surface->y_cb_offset = 0;
3982 obj_surface->y_cr_offset = 0;
3983 region_width = obj_surface->width;
3984 region_height = obj_surface->height;
3988 case VA_FOURCC_YUY2:
3989 case VA_FOURCC_UYVY:
3990 assert(subsampling == SUBSAMPLE_YUV422H);
3991 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
3992 obj_surface->cb_cr_pitch = obj_surface->width;
3993 obj_surface->y_cb_offset = 0;
3994 obj_surface->y_cr_offset = 0;
3995 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3996 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3997 region_width = obj_surface->width;
3998 region_height = obj_surface->height;
4002 case VA_FOURCC_RGBA:
4003 case VA_FOURCC_RGBX:
4004 case VA_FOURCC_BGRA:
4005 case VA_FOURCC_BGRX:
4006 assert(subsampling == SUBSAMPLE_RGBX);
4008 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4009 region_width = obj_surface->width;
4010 region_height = obj_surface->height;
4014 /* Never get here */
4015 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4019 assert(subsampling == SUBSAMPLE_YUV420 ||
4020 subsampling == SUBSAMPLE_YUV422H ||
4021 subsampling == SUBSAMPLE_YUV422V ||
4022 subsampling == SUBSAMPLE_RGBX);
4024 region_width = obj_surface->width;
4025 region_height = obj_surface->height;
4028 case VA_FOURCC_NV12:
4029 case VA_FOURCC_P010:
4030 obj_surface->y_cb_offset = obj_surface->height;
4031 obj_surface->y_cr_offset = obj_surface->height;
4032 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4033 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4034 obj_surface->cb_cr_pitch = obj_surface->width;
4035 region_height = obj_surface->height + obj_surface->height / 2;
4038 case VA_FOURCC_YV16:
4039 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4040 obj_surface->cb_cr_height = obj_surface->orig_height;
4041 obj_surface->y_cr_offset = obj_surface->height;
4042 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4043 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4044 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4047 case VA_FOURCC_YV12:
4048 case VA_FOURCC_I420:
4049 if (fourcc == VA_FOURCC_YV12) {
4050 obj_surface->y_cr_offset = obj_surface->height;
4051 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4053 obj_surface->y_cb_offset = obj_surface->height;
4054 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4057 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4058 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4059 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4060 region_height = obj_surface->height + obj_surface->height / 2;
4063 case VA_FOURCC_YUY2:
4064 case VA_FOURCC_UYVY:
4065 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4066 obj_surface->y_cb_offset = 0;
4067 obj_surface->y_cr_offset = 0;
4068 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4069 obj_surface->cb_cr_height = obj_surface->orig_height;
4070 obj_surface->cb_cr_pitch = obj_surface->width;
4071 region_width = obj_surface->width;
4072 region_height = obj_surface->height;
4074 case VA_FOURCC_RGBA:
4075 case VA_FOURCC_RGBX:
4076 case VA_FOURCC_BGRA:
4077 case VA_FOURCC_BGRX:
4078 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4079 region_width = obj_surface->width;
4080 region_height = obj_surface->height;
4084 /* Never get here */
4085 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4090 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4092 if ((tiled && !obj_surface->user_disable_tiling)) {
4093 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4094 unsigned long pitch;
4096 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4104 assert(tiling_mode == I915_TILING_Y);
4105 assert(pitch == obj_surface->width);
4107 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4113 obj_surface->fourcc = fourcc;
4114 obj_surface->subsampling = subsampling;
4115 assert(obj_surface->bo);
4116 return VA_STATUS_SUCCESS;
4119 VAStatus i965_DeriveImage(VADriverContextP ctx,
4120 VASurfaceID surface,
4121 VAImage *out_image) /* out */
4123 struct i965_driver_data *i965 = i965_driver_data(ctx);
4124 struct object_image *obj_image;
4125 struct object_surface *obj_surface;
4127 unsigned int w_pitch;
4128 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4130 out_image->image_id = VA_INVALID_ID;
4131 obj_surface = SURFACE(surface);
4134 return VA_STATUS_ERROR_INVALID_SURFACE;
4136 if (!obj_surface->bo) {
4137 unsigned int is_tiled = 0;
4138 unsigned int fourcc = VA_FOURCC_YV12;
4139 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4140 int sampling = get_sampling_from_fourcc(fourcc);
4141 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4142 if (va_status != VA_STATUS_SUCCESS)
4146 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4148 w_pitch = obj_surface->width;
4150 image_id = NEW_IMAGE_ID();
4152 if (image_id == VA_INVALID_ID)
4153 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4155 obj_image = IMAGE(image_id);
4158 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4160 obj_image->bo = NULL;
4161 obj_image->palette = NULL;
4162 obj_image->derived_surface = VA_INVALID_ID;
4164 VAImage * const image = &obj_image->image;
4166 memset(image, 0, sizeof(*image));
4167 image->image_id = image_id;
4168 image->buf = VA_INVALID_ID;
4169 image->num_palette_entries = 0;
4170 image->entry_bytes = 0;
4171 image->width = obj_surface->orig_width;
4172 image->height = obj_surface->orig_height;
4173 image->data_size = obj_surface->size;
4175 image->format.fourcc = obj_surface->fourcc;
4176 image->format.byte_order = VA_LSB_FIRST;
4177 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4179 if (!image->format.bits_per_pixel)
4182 switch (image->format.fourcc) {
4183 case VA_FOURCC_YV12:
4184 image->num_planes = 3;
4185 image->pitches[0] = w_pitch; /* Y */
4186 image->offsets[0] = 0;
4187 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4188 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4189 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4190 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4193 case VA_FOURCC_YV16:
4194 image->num_planes = 3;
4195 image->pitches[0] = w_pitch; /* Y */
4196 image->offsets[0] = 0;
4197 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4198 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4199 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4200 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4203 case VA_FOURCC_NV12:
4204 case VA_FOURCC_P010:
4205 image->num_planes = 2;
4206 image->pitches[0] = w_pitch; /* Y */
4207 image->offsets[0] = 0;
4208 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4209 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4212 case VA_FOURCC_I420:
4213 case VA_FOURCC_422H:
4214 case VA_FOURCC_IMC3:
4215 case VA_FOURCC_444P:
4216 case VA_FOURCC_422V:
4217 case VA_FOURCC_411P:
4218 image->num_planes = 3;
4219 image->pitches[0] = w_pitch; /* Y */
4220 image->offsets[0] = 0;
4221 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4222 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4223 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4224 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4227 case VA_FOURCC_YUY2:
4228 case VA_FOURCC_UYVY:
4229 case VA_FOURCC_Y800:
4230 image->num_planes = 1;
4231 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4232 image->offsets[0] = 0;
4234 case VA_FOURCC_RGBA:
4235 case VA_FOURCC_RGBX:
4236 case VA_FOURCC_BGRA:
4237 case VA_FOURCC_BGRX:
4238 image->num_planes = 1;
4239 image->pitches[0] = obj_surface->width;
4241 switch (image->format.fourcc) {
4242 case VA_FOURCC_RGBA:
4243 case VA_FOURCC_RGBX:
4244 image->format.red_mask = 0x000000ff;
4245 image->format.green_mask = 0x0000ff00;
4246 image->format.blue_mask = 0x00ff0000;
4247 image->format.alpha_mask = 0x00000000;
4249 case VA_FOURCC_BGRA:
4250 case VA_FOURCC_BGRX:
4251 image->format.red_mask = 0x00ff0000;
4252 image->format.green_mask = 0x0000ff00;
4253 image->format.blue_mask = 0x000000ff;
4254 image->format.alpha_mask = 0x00000000;
4260 switch (image->format.fourcc) {
4261 case VA_FOURCC_RGBA:
4262 case VA_FOURCC_BGRA:
4263 image->format.depth = 32;
4265 case VA_FOURCC_RGBX:
4266 case VA_FOURCC_BGRX:
4267 image->format.depth = 24;
4278 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4279 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4280 if (va_status != VA_STATUS_SUCCESS)
4283 struct object_buffer *obj_buffer = BUFFER(image->buf);
4286 !obj_buffer->buffer_store ||
4287 !obj_buffer->buffer_store->bo)
4288 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4290 obj_image->bo = obj_buffer->buffer_store->bo;
4291 dri_bo_reference(obj_image->bo);
4293 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4294 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4295 if (!obj_image->palette) {
4296 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4301 *out_image = *image;
4302 obj_surface->flags |= SURFACE_DERIVED;
4303 obj_surface->derived_image_id = image_id;
4304 obj_image->derived_surface = surface;
4306 return VA_STATUS_SUCCESS;
4309 i965_DestroyImage(ctx, image_id);
4314 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4316 object_heap_free(heap, obj);
4321 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4323 struct i965_driver_data *i965 = i965_driver_data(ctx);
4324 struct object_image *obj_image = IMAGE(image);
4325 struct object_surface *obj_surface;
4328 return VA_STATUS_SUCCESS;
4330 dri_bo_unreference(obj_image->bo);
4331 obj_image->bo = NULL;
4333 if (obj_image->image.buf != VA_INVALID_ID) {
4334 i965_DestroyBuffer(ctx, obj_image->image.buf);
4335 obj_image->image.buf = VA_INVALID_ID;
4338 if (obj_image->palette) {
4339 free(obj_image->palette);
4340 obj_image->palette = NULL;
4343 obj_surface = SURFACE(obj_image->derived_surface);
4346 obj_surface->flags &= ~SURFACE_DERIVED;
4347 obj_surface->derived_image_id = VA_INVALID_ID;
4350 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4352 return VA_STATUS_SUCCESS;
4356 * pointer to an array holding the palette data. The size of the array is
4357 * num_palette_entries * entry_bytes in size. The order of the components
4358 * in the palette is described by the component_order in VASubpicture struct
4361 i965_SetImagePalette(VADriverContextP ctx,
4363 unsigned char *palette)
4365 struct i965_driver_data *i965 = i965_driver_data(ctx);
4368 struct object_image *obj_image = IMAGE(image);
4370 return VA_STATUS_ERROR_INVALID_IMAGE;
4372 if (!obj_image->palette)
4373 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4375 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4376 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
4377 ((unsigned int)palette[3*i + 1] << 8) |
4378 (unsigned int)palette[3*i + 2]);
4379 return VA_STATUS_SUCCESS;
4383 get_sampling_from_fourcc(unsigned int fourcc)
4385 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4387 if (info && (info->flag & I_S))
4388 return info->subsampling;
4394 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4395 const uint8_t *src, unsigned int src_stride,
4396 unsigned int len, unsigned int height)
4400 for (i = 0; i < height; i++) {
4401 memcpy(dst, src, len);
4408 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4409 struct object_surface *obj_surface,
4410 const VARectangle *rect)
4412 uint8_t *dst[3], *src[3];
4414 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4415 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4416 unsigned int tiling, swizzle;
4417 VAStatus va_status = VA_STATUS_SUCCESS;
4419 if (!obj_surface->bo)
4420 return VA_STATUS_ERROR_INVALID_SURFACE;
4422 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4423 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4425 if (tiling != I915_TILING_NONE)
4426 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4428 dri_bo_map(obj_surface->bo, 0);
4430 if (!obj_surface->bo->virtual)
4431 return VA_STATUS_ERROR_INVALID_SURFACE;
4433 /* Dest VA image has either I420 or YV12 format.
4434 Source VA surface alway has I420 format */
4435 dst[Y] = image_data + obj_image->image.offsets[Y];
4436 src[0] = (uint8_t *)obj_surface->bo->virtual;
4437 dst[U] = image_data + obj_image->image.offsets[U];
4438 src[1] = src[0] + obj_surface->width * obj_surface->height;
4439 dst[V] = image_data + obj_image->image.offsets[V];
4440 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4443 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4444 src[0] += rect->y * obj_surface->width + rect->x;
4445 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4446 src[0], obj_surface->width,
4447 rect->width, rect->height);
4450 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4451 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4452 memcpy_pic(dst[U], obj_image->image.pitches[U],
4453 src[1], obj_surface->width / 2,
4454 rect->width / 2, rect->height / 2);
4457 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4458 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4459 memcpy_pic(dst[V], obj_image->image.pitches[V],
4460 src[2], obj_surface->width / 2,
4461 rect->width / 2, rect->height / 2);
4463 if (tiling != I915_TILING_NONE)
4464 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4466 dri_bo_unmap(obj_surface->bo);
4472 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4473 struct object_surface *obj_surface,
4474 const VARectangle *rect)
4476 uint8_t *dst[2], *src[2];
4477 unsigned int tiling, swizzle;
4478 VAStatus va_status = VA_STATUS_SUCCESS;
4480 if (!obj_surface->bo)
4481 return VA_STATUS_ERROR_INVALID_SURFACE;
4483 assert(obj_surface->fourcc);
4484 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4486 if (tiling != I915_TILING_NONE)
4487 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4489 dri_bo_map(obj_surface->bo, 0);
4491 if (!obj_surface->bo->virtual)
4492 return VA_STATUS_ERROR_INVALID_SURFACE;
4494 /* Both dest VA image and source surface have NV12 format */
4495 dst[0] = image_data + obj_image->image.offsets[0];
4496 src[0] = (uint8_t *)obj_surface->bo->virtual;
4497 dst[1] = image_data + obj_image->image.offsets[1];
4498 src[1] = src[0] + obj_surface->width * obj_surface->height;
4501 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4502 src[0] += rect->y * obj_surface->width + rect->x;
4503 memcpy_pic(dst[0], obj_image->image.pitches[0],
4504 src[0], obj_surface->width,
4505 rect->width, rect->height);
4508 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4509 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4510 memcpy_pic(dst[1], obj_image->image.pitches[1],
4511 src[1], obj_surface->width,
4512 rect->width, rect->height / 2);
4514 if (tiling != I915_TILING_NONE)
4515 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4517 dri_bo_unmap(obj_surface->bo);
4523 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4524 struct object_surface *obj_surface,
4525 const VARectangle *rect)
4528 unsigned int tiling, swizzle;
4529 VAStatus va_status = VA_STATUS_SUCCESS;
4531 if (!obj_surface->bo)
4532 return VA_STATUS_ERROR_INVALID_SURFACE;
4534 assert(obj_surface->fourcc);
4535 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4537 if (tiling != I915_TILING_NONE)
4538 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4540 dri_bo_map(obj_surface->bo, 0);
4542 if (!obj_surface->bo->virtual)
4543 return VA_STATUS_ERROR_INVALID_SURFACE;
4545 /* Both dest VA image and source surface have YUYV format */
4546 dst = image_data + obj_image->image.offsets[0];
4547 src = (uint8_t *)obj_surface->bo->virtual;
4550 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
4551 src += rect->y * obj_surface->width + rect->x*2;
4552 memcpy_pic(dst, obj_image->image.pitches[0],
4553 src, obj_surface->width*2,
4554 rect->width*2, rect->height);
4556 if (tiling != I915_TILING_NONE)
4557 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4559 dri_bo_unmap(obj_surface->bo);
4565 i965_sw_getimage(VADriverContextP ctx,
4566 struct object_surface *obj_surface, struct object_image *obj_image,
4567 const VARectangle *rect)
4569 void *image_data = NULL;
4572 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4573 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4575 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4576 if (va_status != VA_STATUS_SUCCESS)
4579 switch (obj_image->image.format.fourcc) {
4580 case VA_FOURCC_YV12:
4581 case VA_FOURCC_I420:
4582 get_image_i420(obj_image, image_data, obj_surface, rect);
4584 case VA_FOURCC_NV12:
4585 get_image_nv12(obj_image, image_data, obj_surface, rect);
4587 case VA_FOURCC_YUY2:
4588 /* YUY2 is the format supported by overlay plane */
4589 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4592 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4595 if (va_status != VA_STATUS_SUCCESS)
4598 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4603 i965_hw_getimage(VADriverContextP ctx,
4604 struct object_surface *obj_surface, struct object_image *obj_image,
4605 const VARectangle *rect)
4607 struct i965_surface src_surface;
4608 struct i965_surface dst_surface;
4610 src_surface.base = (struct object_base *)obj_surface;
4611 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4612 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4614 dst_surface.base = (struct object_base *)obj_image;
4615 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4616 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4618 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4622 i965_GetImage(VADriverContextP ctx,
4623 VASurfaceID surface,
4624 int x, /* coordinates of the upper left source pixel */
4626 unsigned int width, /* width and height of the region */
4627 unsigned int height,
4630 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4631 struct object_surface * const obj_surface = SURFACE(surface);
4632 struct object_image * const obj_image = IMAGE(image);
4637 return VA_STATUS_ERROR_INVALID_SURFACE;
4638 if (!obj_surface->bo) /* don't get anything, keep previous data */
4639 return VA_STATUS_SUCCESS;
4640 if (is_surface_busy(i965, obj_surface))
4641 return VA_STATUS_ERROR_SURFACE_BUSY;
4643 if (!obj_image || !obj_image->bo)
4644 return VA_STATUS_ERROR_INVALID_IMAGE;
4645 if (is_image_busy(i965, obj_image, surface))
4646 return VA_STATUS_ERROR_SURFACE_BUSY;
4649 return VA_STATUS_ERROR_INVALID_PARAMETER;
4650 if (x + width > obj_surface->orig_width ||
4651 y + height > obj_surface->orig_height)
4652 return VA_STATUS_ERROR_INVALID_PARAMETER;
4653 if (x + width > obj_image->image.width ||
4654 y + height > obj_image->image.height)
4655 return VA_STATUS_ERROR_INVALID_PARAMETER;
4660 rect.height = height;
4662 if (HAS_ACCELERATED_GETIMAGE(i965))
4663 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
4665 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
4671 put_image_i420(struct object_surface *obj_surface,
4672 const VARectangle *dst_rect,
4673 struct object_image *obj_image, uint8_t *image_data,
4674 const VARectangle *src_rect)
4676 uint8_t *dst[3], *src[3];
4678 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4679 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4680 unsigned int tiling, swizzle;
4681 VAStatus va_status = VA_STATUS_SUCCESS;
4683 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4685 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4686 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4687 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4688 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4690 if (tiling != I915_TILING_NONE)
4691 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4693 dri_bo_map(obj_surface->bo, 0);
4695 if (!obj_surface->bo->virtual)
4696 return VA_STATUS_ERROR_INVALID_SURFACE;
4698 /* Dest VA image has either I420 or YV12 format.
4699 Source VA surface alway has I420 format */
4700 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4701 src[Y] = image_data + obj_image->image.offsets[Y];
4702 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4703 src[U] = image_data + obj_image->image.offsets[U];
4704 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4705 src[V] = image_data + obj_image->image.offsets[V];
4708 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4709 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4710 memcpy_pic(dst[0], obj_surface->width,
4711 src[Y], obj_image->image.pitches[Y],
4712 src_rect->width, src_rect->height);
4715 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4716 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4717 memcpy_pic(dst[1], obj_surface->width / 2,
4718 src[U], obj_image->image.pitches[U],
4719 src_rect->width / 2, src_rect->height / 2);
4722 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4723 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4724 memcpy_pic(dst[2], obj_surface->width / 2,
4725 src[V], obj_image->image.pitches[V],
4726 src_rect->width / 2, src_rect->height / 2);
4728 if (tiling != I915_TILING_NONE)
4729 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4731 dri_bo_unmap(obj_surface->bo);
4737 put_image_nv12(struct object_surface *obj_surface,
4738 const VARectangle *dst_rect,
4739 struct object_image *obj_image, uint8_t *image_data,
4740 const VARectangle *src_rect)
4742 uint8_t *dst[2], *src[2];
4743 unsigned int tiling, swizzle;
4744 VAStatus va_status = VA_STATUS_SUCCESS;
4746 if (!obj_surface->bo)
4747 return VA_STATUS_ERROR_INVALID_SURFACE;
4749 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4750 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4751 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4752 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4754 if (tiling != I915_TILING_NONE)
4755 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4757 dri_bo_map(obj_surface->bo, 0);
4759 if (!obj_surface->bo->virtual)
4760 return VA_STATUS_ERROR_INVALID_SURFACE;
4762 /* Both dest VA image and source surface have NV12 format */
4763 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4764 src[0] = image_data + obj_image->image.offsets[0];
4765 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4766 src[1] = image_data + obj_image->image.offsets[1];
4769 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4770 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
4771 memcpy_pic(dst[0], obj_surface->width,
4772 src[0], obj_image->image.pitches[0],
4773 src_rect->width, src_rect->height);
4776 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
4777 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
4778 memcpy_pic(dst[1], obj_surface->width,
4779 src[1], obj_image->image.pitches[1],
4780 src_rect->width, src_rect->height / 2);
4782 if (tiling != I915_TILING_NONE)
4783 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4785 dri_bo_unmap(obj_surface->bo);
4791 put_image_yuy2(struct object_surface *obj_surface,
4792 const VARectangle *dst_rect,
4793 struct object_image *obj_image, uint8_t *image_data,
4794 const VARectangle *src_rect)
4797 unsigned int tiling, swizzle;
4798 VAStatus va_status = VA_STATUS_SUCCESS;
4800 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4801 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4802 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4803 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4804 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4806 if (tiling != I915_TILING_NONE)
4807 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4809 dri_bo_map(obj_surface->bo, 0);
4811 if (!obj_surface->bo->virtual)
4812 return VA_STATUS_ERROR_INVALID_SURFACE;
4814 /* Both dest VA image and source surface have YUY2 format */
4815 dst = (uint8_t *)obj_surface->bo->virtual;
4816 src = image_data + obj_image->image.offsets[0];
4818 /* YUYV packed plane */
4819 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
4820 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
4821 memcpy_pic(dst, obj_surface->width*2,
4822 src, obj_image->image.pitches[0],
4823 src_rect->width*2, src_rect->height);
4825 if (tiling != I915_TILING_NONE)
4826 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4828 dri_bo_unmap(obj_surface->bo);
4834 i965_sw_putimage(VADriverContextP ctx,
4835 struct object_surface *obj_surface, struct object_image *obj_image,
4836 const VARectangle *src_rect, const VARectangle *dst_rect)
4838 VAStatus va_status = VA_STATUS_SUCCESS;
4839 void *image_data = NULL;
4841 /* XXX: don't allow scaling */
4842 if (src_rect->width != dst_rect->width ||
4843 src_rect->height != dst_rect->height)
4844 return VA_STATUS_ERROR_INVALID_PARAMETER;
4846 if (obj_surface->fourcc) {
4847 /* Don't allow format mismatch */
4848 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4849 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4853 /* VA is surface not used for decoding, use same VA image format */
4854 va_status = i965_check_alloc_surface_bo(
4857 0, /* XXX: don't use tiled surface */
4858 obj_image->image.format.fourcc,
4859 get_sampling_from_fourcc (obj_image->image.format.fourcc));
4862 if (va_status != VA_STATUS_SUCCESS)
4865 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4866 if (va_status != VA_STATUS_SUCCESS)
4869 switch (obj_image->image.format.fourcc) {
4870 case VA_FOURCC_YV12:
4871 case VA_FOURCC_I420:
4872 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
4874 case VA_FOURCC_NV12:
4875 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
4877 case VA_FOURCC_YUY2:
4878 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
4881 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4884 if (va_status != VA_STATUS_SUCCESS)
4887 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4892 i965_hw_putimage(VADriverContextP ctx,
4893 struct object_surface *obj_surface, struct object_image *obj_image,
4894 const VARectangle *src_rect, const VARectangle *dst_rect)
4896 struct i965_surface src_surface, dst_surface;
4897 VAStatus va_status = VA_STATUS_SUCCESS;
4899 if (!obj_surface->bo) {
4900 unsigned int tiling, swizzle;
4901 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
4902 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
4904 i965_check_alloc_surface_bo(ctx,
4907 obj_image->image.format.fourcc,
4911 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4913 src_surface.base = (struct object_base *)obj_image;
4914 src_surface.type = I965_SURFACE_TYPE_IMAGE;
4915 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4917 dst_surface.base = (struct object_base *)obj_surface;
4918 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4919 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4921 va_status = i965_image_processing(ctx,
4931 i965_PutImage(VADriverContextP ctx,
4932 VASurfaceID surface,
4936 unsigned int src_width,
4937 unsigned int src_height,
4940 unsigned int dest_width,
4941 unsigned int dest_height)
4943 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4944 struct object_surface * const obj_surface = SURFACE(surface);
4945 struct object_image * const obj_image = IMAGE(image);
4946 VARectangle src_rect, dst_rect;
4950 return VA_STATUS_ERROR_INVALID_SURFACE;
4951 if (is_surface_busy(i965, obj_surface))
4952 return VA_STATUS_ERROR_SURFACE_BUSY;
4954 if (!obj_image || !obj_image->bo)
4955 return VA_STATUS_ERROR_INVALID_IMAGE;
4956 if (is_image_busy(i965, obj_image, surface))
4957 return VA_STATUS_ERROR_SURFACE_BUSY;
4961 src_x + src_width > obj_image->image.width ||
4962 src_y + src_height > obj_image->image.height)
4963 return VA_STATUS_ERROR_INVALID_PARAMETER;
4967 src_rect.width = src_width;
4968 src_rect.height = src_height;
4972 dest_x + dest_width > obj_surface->orig_width ||
4973 dest_y + dest_height > obj_surface->orig_height)
4974 return VA_STATUS_ERROR_INVALID_PARAMETER;
4976 dst_rect.x = dest_x;
4977 dst_rect.y = dest_y;
4978 dst_rect.width = dest_width;
4979 dst_rect.height = dest_height;
4981 if (HAS_ACCELERATED_PUTIMAGE(i965))
4982 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
4983 &src_rect, &dst_rect);
4985 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
4986 &src_rect, &dst_rect);
4992 i965_PutSurface(VADriverContextP ctx,
4993 VASurfaceID surface,
4994 void *draw, /* X Drawable */
4997 unsigned short srcw,
4998 unsigned short srch,
5001 unsigned short destw,
5002 unsigned short desth,
5003 VARectangle *cliprects, /* client supplied clip list */
5004 unsigned int number_cliprects, /* number of clip rects in the clip list */
5005 unsigned int flags) /* de-interlacing flags */
5008 if (IS_VA_X11(ctx)) {
5009 VARectangle src_rect, dst_rect;
5013 src_rect.width = srcw;
5014 src_rect.height = srch;
5018 dst_rect.width = destw;
5019 dst_rect.height = desth;
5021 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5022 cliprects, number_cliprects, flags);
5025 return VA_STATUS_ERROR_UNIMPLEMENTED;
5030 VADriverContextP ctx, /* in */
5031 VABufferID buf_id, /* in */
5032 VABufferType *type, /* out */
5033 unsigned int *size, /* out */
5034 unsigned int *num_elements /* out */
5037 struct i965_driver_data *i965 = NULL;
5038 struct object_buffer *obj_buffer = NULL;
5040 i965 = i965_driver_data(ctx);
5041 obj_buffer = BUFFER(buf_id);
5043 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5045 *type = obj_buffer->type;
5046 *size = obj_buffer->size_element;
5047 *num_elements = obj_buffer->num_elements;
5049 return VA_STATUS_SUCCESS;
5054 VADriverContextP ctx, /* in */
5055 VASurfaceID surface, /* in */
5056 unsigned int *fourcc, /* out */
5057 unsigned int *luma_stride, /* out */
5058 unsigned int *chroma_u_stride, /* out */
5059 unsigned int *chroma_v_stride, /* out */
5060 unsigned int *luma_offset, /* out */
5061 unsigned int *chroma_u_offset, /* out */
5062 unsigned int *chroma_v_offset, /* out */
5063 unsigned int *buffer_name, /* out */
5064 void **buffer /* out */
5067 VAStatus vaStatus = VA_STATUS_SUCCESS;
5068 struct i965_driver_data *i965 = i965_driver_data(ctx);
5069 struct object_surface *obj_surface = NULL;
5072 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5073 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5074 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5075 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5076 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5077 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5078 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5079 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5080 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5082 tmpImage.image_id = VA_INVALID_ID;
5084 obj_surface = SURFACE(surface);
5085 if (obj_surface == NULL) {
5086 // Surface is absent.
5087 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5091 // Lock functionality is absent now.
5092 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5093 // Surface is locked already.
5094 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5098 vaStatus = i965_DeriveImage(
5102 if (vaStatus != VA_STATUS_SUCCESS) {
5106 obj_surface->locked_image_id = tmpImage.image_id;
5108 vaStatus = i965_MapBuffer(
5112 if (vaStatus != VA_STATUS_SUCCESS) {
5116 *fourcc = tmpImage.format.fourcc;
5117 *luma_offset = tmpImage.offsets[0];
5118 *luma_stride = tmpImage.pitches[0];
5119 *chroma_u_offset = tmpImage.offsets[1];
5120 *chroma_u_stride = tmpImage.pitches[1];
5121 *chroma_v_offset = tmpImage.offsets[2];
5122 *chroma_v_stride = tmpImage.pitches[2];
5123 *buffer_name = tmpImage.buf;
5126 if (vaStatus != VA_STATUS_SUCCESS) {
5135 VADriverContextP ctx, /* in */
5136 VASurfaceID surface /* in */
5139 VAStatus vaStatus = VA_STATUS_SUCCESS;
5140 struct i965_driver_data *i965 = i965_driver_data(ctx);
5141 struct object_image *locked_img = NULL;
5142 struct object_surface *obj_surface = NULL;
5144 obj_surface = SURFACE(surface);
5146 if (obj_surface == NULL) {
5147 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5150 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5151 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5155 locked_img = IMAGE(obj_surface->locked_image_id);
5156 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5157 // Work image was deallocated before i965_UnlockSurface()
5158 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5162 vaStatus = i965_UnmapBuffer(
5164 locked_img->image.buf);
5165 if (vaStatus != VA_STATUS_SUCCESS) {
5169 vaStatus = i965_DestroyImage(
5171 locked_img->image.image_id);
5172 if (vaStatus != VA_STATUS_SUCCESS) {
5176 locked_img->image.image_id = VA_INVALID_ID;
5179 obj_surface->locked_image_id = VA_INVALID_ID;
5185 i965_GetSurfaceAttributes(
5186 VADriverContextP ctx,
5188 VASurfaceAttrib *attrib_list,
5189 unsigned int num_attribs
5192 VAStatus vaStatus = VA_STATUS_SUCCESS;
5193 struct i965_driver_data *i965 = i965_driver_data(ctx);
5194 struct object_config *obj_config;
5197 if (config == VA_INVALID_ID)
5198 return VA_STATUS_ERROR_INVALID_CONFIG;
5200 obj_config = CONFIG(config);
5202 if (obj_config == NULL)
5203 return VA_STATUS_ERROR_INVALID_CONFIG;
5205 if (attrib_list == NULL || num_attribs == 0)
5206 return VA_STATUS_ERROR_INVALID_PARAMETER;
5208 for (i = 0; i < num_attribs; i++) {
5209 switch (attrib_list[i].type) {
5210 case VASurfaceAttribPixelFormat:
5211 attrib_list[i].value.type = VAGenericValueTypeInteger;
5212 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5214 if (attrib_list[i].value.value.i == 0) {
5215 if (IS_G4X(i965->intel.device_info)) {
5216 if (obj_config->profile == VAProfileMPEG2Simple ||
5217 obj_config->profile == VAProfileMPEG2Main) {
5218 attrib_list[i].value.value.i = VA_FOURCC_I420;
5221 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5223 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5224 if (obj_config->profile == VAProfileMPEG2Simple ||
5225 obj_config->profile == VAProfileMPEG2Main) {
5226 attrib_list[i].value.value.i = VA_FOURCC_I420;
5227 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5228 obj_config->profile == VAProfileH264Main ||
5229 obj_config->profile == VAProfileH264High) {
5230 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5231 } else if (obj_config->profile == VAProfileNone) {
5232 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5235 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5237 } else if (IS_GEN6(i965->intel.device_info)) {
5238 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5239 } else if (IS_GEN7(i965->intel.device_info) ||
5240 IS_GEN8(i965->intel.device_info) ||
5241 IS_GEN9(i965->intel.device_info)) {
5242 if (obj_config->profile == VAProfileJPEGBaseline)
5243 attrib_list[i].value.value.i = 0; /* internal format */
5245 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5248 if (IS_G4X(i965->intel.device_info)) {
5249 if (obj_config->profile == VAProfileMPEG2Simple ||
5250 obj_config->profile == VAProfileMPEG2Main) {
5251 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5252 attrib_list[i].value.value.i = 0;
5253 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5257 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5259 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5260 if (obj_config->profile == VAProfileMPEG2Simple ||
5261 obj_config->profile == VAProfileMPEG2Main) {
5262 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5263 attrib_list[i].value.value.i = 0;
5264 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5266 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5267 obj_config->profile == VAProfileH264Main ||
5268 obj_config->profile == VAProfileH264High) {
5269 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5270 attrib_list[i].value.value.i = 0;
5271 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5273 } else if (obj_config->profile == VAProfileNone) {
5274 switch (attrib_list[i].value.value.i) {
5275 case VA_FOURCC_NV12:
5276 case VA_FOURCC_I420:
5277 case VA_FOURCC_YV12:
5278 case VA_FOURCC_YUY2:
5279 case VA_FOURCC_BGRA:
5280 case VA_FOURCC_BGRX:
5281 case VA_FOURCC_RGBX:
5282 case VA_FOURCC_RGBA:
5285 attrib_list[i].value.value.i = 0;
5286 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5291 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5293 } else if (IS_GEN6(i965->intel.device_info)) {
5294 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5295 obj_config->entrypoint == VAEntrypointVideoProc) {
5296 switch (attrib_list[i].value.value.i) {
5297 case VA_FOURCC_NV12:
5298 case VA_FOURCC_I420:
5299 case VA_FOURCC_YV12:
5300 case VA_FOURCC_YUY2:
5301 case VA_FOURCC_BGRA:
5302 case VA_FOURCC_BGRX:
5303 case VA_FOURCC_RGBX:
5304 case VA_FOURCC_RGBA:
5307 attrib_list[i].value.value.i = 0;
5308 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5312 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5313 attrib_list[i].value.value.i = 0;
5314 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5317 } else if (IS_GEN7(i965->intel.device_info) ||
5318 IS_GEN8(i965->intel.device_info) ||
5319 IS_GEN9(i965->intel.device_info)) {
5320 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5321 obj_config->entrypoint == VAEntrypointVideoProc) {
5322 switch (attrib_list[i].value.value.i) {
5323 case VA_FOURCC_NV12:
5324 case VA_FOURCC_I420:
5325 case VA_FOURCC_YV12:
5328 attrib_list[i].value.value.i = 0;
5329 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5333 if (obj_config->profile == VAProfileJPEGBaseline) {
5334 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5335 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5337 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5338 attrib_list[i].value.value.i = 0;
5339 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5347 case VASurfaceAttribMinWidth:
5348 /* FIXME: add support for it later */
5349 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5351 case VASurfaceAttribMaxWidth:
5352 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5354 case VASurfaceAttribMinHeight:
5355 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5357 case VASurfaceAttribMaxHeight:
5358 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5361 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5370 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5372 VASurfaceAttrib *attrib_list,
5373 unsigned int *num_attribs)
5375 VAStatus vaStatus = VA_STATUS_SUCCESS;
5376 struct i965_driver_data *i965 = i965_driver_data(ctx);
5377 struct object_config *obj_config;
5379 VASurfaceAttrib *attribs = NULL;
5381 if (config == VA_INVALID_ID)
5382 return VA_STATUS_ERROR_INVALID_CONFIG;
5384 obj_config = CONFIG(config);
5386 if (obj_config == NULL)
5387 return VA_STATUS_ERROR_INVALID_CONFIG;
5389 if (!attrib_list && !num_attribs)
5390 return VA_STATUS_ERROR_INVALID_PARAMETER;
5392 if (attrib_list == NULL) {
5393 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5394 return VA_STATUS_SUCCESS;
5397 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
5399 if (attribs == NULL)
5400 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5402 if (IS_G4X(i965->intel.device_info)) {
5403 if (obj_config->profile == VAProfileMPEG2Simple ||
5404 obj_config->profile == VAProfileMPEG2Main) {
5405 attribs[i].type = VASurfaceAttribPixelFormat;
5406 attribs[i].value.type = VAGenericValueTypeInteger;
5407 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5408 attribs[i].value.value.i = VA_FOURCC_I420;
5411 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5412 switch (obj_config->profile) {
5413 case VAProfileMPEG2Simple:
5414 case VAProfileMPEG2Main:
5415 attribs[i].type = VASurfaceAttribPixelFormat;
5416 attribs[i].value.type = VAGenericValueTypeInteger;
5417 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5418 attribs[i].value.value.i = VA_FOURCC_I420;
5423 case VAProfileH264ConstrainedBaseline:
5424 case VAProfileH264Main:
5425 case VAProfileH264High:
5426 attribs[i].type = VASurfaceAttribPixelFormat;
5427 attribs[i].value.type = VAGenericValueTypeInteger;
5428 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5429 attribs[i].value.value.i = VA_FOURCC_NV12;
5433 attribs[i].type = VASurfaceAttribPixelFormat;
5434 attribs[i].value.type = VAGenericValueTypeInteger;
5435 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5436 attribs[i].value.value.i = VA_FOURCC_NV12;
5439 attribs[i].type = VASurfaceAttribPixelFormat;
5440 attribs[i].value.type = VAGenericValueTypeInteger;
5441 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5442 attribs[i].value.value.i = VA_FOURCC_I420;
5450 } else if (IS_GEN6(i965->intel.device_info)) {
5451 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5452 attribs[i].type = VASurfaceAttribPixelFormat;
5453 attribs[i].value.type = VAGenericValueTypeInteger;
5454 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5455 attribs[i].value.value.i = VA_FOURCC_NV12;
5457 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5458 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5459 attribs[i].type = VASurfaceAttribPixelFormat;
5460 attribs[i].value.type = VAGenericValueTypeInteger;
5461 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5462 attribs[i].value.value.i = VA_FOURCC_NV12;
5465 attribs[i].type = VASurfaceAttribPixelFormat;
5466 attribs[i].value.type = VAGenericValueTypeInteger;
5467 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5468 attribs[i].value.value.i = VA_FOURCC_I420;
5471 attribs[i].type = VASurfaceAttribPixelFormat;
5472 attribs[i].value.type = VAGenericValueTypeInteger;
5473 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5474 attribs[i].value.value.i = VA_FOURCC_YV12;
5477 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5478 attribs[i].type = VASurfaceAttribPixelFormat;
5479 attribs[i].value.type = VAGenericValueTypeInteger;
5480 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5481 attribs[i].value.value.i = VA_FOURCC_YUY2;
5484 attribs[i].type = VASurfaceAttribPixelFormat;
5485 attribs[i].value.type = VAGenericValueTypeInteger;
5486 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5487 attribs[i].value.value.i = VA_FOURCC_RGBA;
5490 attribs[i].type = VASurfaceAttribPixelFormat;
5491 attribs[i].value.type = VAGenericValueTypeInteger;
5492 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5493 attribs[i].value.value.i = VA_FOURCC_RGBX;
5497 } else if (IS_GEN7(i965->intel.device_info)) {
5498 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5499 if (obj_config->profile == VAProfileJPEGBaseline) {
5500 attribs[i].type = VASurfaceAttribPixelFormat;
5501 attribs[i].value.type = VAGenericValueTypeInteger;
5502 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5503 attribs[i].value.value.i = VA_FOURCC_IMC3;
5506 attribs[i].type = VASurfaceAttribPixelFormat;
5507 attribs[i].value.type = VAGenericValueTypeInteger;
5508 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5509 attribs[i].value.value.i = VA_FOURCC_IMC1;
5512 attribs[i].type = VASurfaceAttribPixelFormat;
5513 attribs[i].value.type = VAGenericValueTypeInteger;
5514 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5515 attribs[i].value.value.i = VA_FOURCC_Y800;
5518 attribs[i].type = VASurfaceAttribPixelFormat;
5519 attribs[i].value.type = VAGenericValueTypeInteger;
5520 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5521 attribs[i].value.value.i = VA_FOURCC_411P;
5524 attribs[i].type = VASurfaceAttribPixelFormat;
5525 attribs[i].value.type = VAGenericValueTypeInteger;
5526 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5527 attribs[i].value.value.i = VA_FOURCC_422H;
5530 attribs[i].type = VASurfaceAttribPixelFormat;
5531 attribs[i].value.type = VAGenericValueTypeInteger;
5532 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5533 attribs[i].value.value.i = VA_FOURCC_422V;
5536 attribs[i].type = VASurfaceAttribPixelFormat;
5537 attribs[i].value.type = VAGenericValueTypeInteger;
5538 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5539 attribs[i].value.value.i = VA_FOURCC_444P;
5541 } else if (obj_config->profile == VAProfileHEVCMain10) {
5542 attribs[i].type = VASurfaceAttribPixelFormat;
5543 attribs[i].value.type = VAGenericValueTypeInteger;
5544 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5545 attribs[i].value.value.i = VA_FOURCC_P010;
5548 attribs[i].type = VASurfaceAttribPixelFormat;
5549 attribs[i].value.type = VAGenericValueTypeInteger;
5550 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5551 attribs[i].value.value.i = VA_FOURCC_NV12;
5554 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5555 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5556 attribs[i].type = VASurfaceAttribPixelFormat;
5557 attribs[i].value.type = VAGenericValueTypeInteger;
5558 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5559 attribs[i].value.value.i = VA_FOURCC_NV12;
5562 attribs[i].type = VASurfaceAttribPixelFormat;
5563 attribs[i].value.type = VAGenericValueTypeInteger;
5564 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5565 attribs[i].value.value.i = VA_FOURCC_I420;
5568 attribs[i].type = VASurfaceAttribPixelFormat;
5569 attribs[i].value.type = VAGenericValueTypeInteger;
5570 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5571 attribs[i].value.value.i = VA_FOURCC_YV12;
5574 attribs[i].type = VASurfaceAttribPixelFormat;
5575 attribs[i].value.type = VAGenericValueTypeInteger;
5576 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5577 attribs[i].value.value.i = VA_FOURCC_IMC3;
5580 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5581 attribs[i].type = VASurfaceAttribPixelFormat;
5582 attribs[i].value.type = VAGenericValueTypeInteger;
5583 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5584 attribs[i].value.value.i = VA_FOURCC_YUY2;
5587 attribs[i].type = VASurfaceAttribPixelFormat;
5588 attribs[i].value.type = VAGenericValueTypeInteger;
5589 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5590 attribs[i].value.value.i = VA_FOURCC_RGBA;
5593 attribs[i].type = VASurfaceAttribPixelFormat;
5594 attribs[i].value.type = VAGenericValueTypeInteger;
5595 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5596 attribs[i].value.value.i = VA_FOURCC_RGBX;
5599 attribs[i].type = VASurfaceAttribPixelFormat;
5600 attribs[i].value.type = VAGenericValueTypeInteger;
5601 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5602 attribs[i].value.value.i = VA_FOURCC_BGRA;
5605 attribs[i].type = VASurfaceAttribPixelFormat;
5606 attribs[i].value.type = VAGenericValueTypeInteger;
5607 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5608 attribs[i].value.value.i = VA_FOURCC_BGRX;
5611 attribs[i].type = VASurfaceAttribPixelFormat;
5612 attribs[i].value.type = VAGenericValueTypeInteger;
5613 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5614 attribs[i].value.value.i = VA_FOURCC_YV16;
5618 } else if (IS_GEN8(i965->intel.device_info) ||
5619 IS_GEN9(i965->intel.device_info)) {
5620 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5621 if (obj_config->profile == VAProfileJPEGBaseline) {
5622 attribs[i].type = VASurfaceAttribPixelFormat;
5623 attribs[i].value.type = VAGenericValueTypeInteger;
5624 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5625 attribs[i].value.value.i = VA_FOURCC_IMC3;
5628 attribs[i].type = VASurfaceAttribPixelFormat;
5629 attribs[i].value.type = VAGenericValueTypeInteger;
5630 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5631 attribs[i].value.value.i = VA_FOURCC_IMC1;
5634 attribs[i].type = VASurfaceAttribPixelFormat;
5635 attribs[i].value.type = VAGenericValueTypeInteger;
5636 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5637 attribs[i].value.value.i = VA_FOURCC_Y800;
5640 attribs[i].type = VASurfaceAttribPixelFormat;
5641 attribs[i].value.type = VAGenericValueTypeInteger;
5642 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5643 attribs[i].value.value.i = VA_FOURCC_411P;
5646 attribs[i].type = VASurfaceAttribPixelFormat;
5647 attribs[i].value.type = VAGenericValueTypeInteger;
5648 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5649 attribs[i].value.value.i = VA_FOURCC_422H;
5652 attribs[i].type = VASurfaceAttribPixelFormat;
5653 attribs[i].value.type = VAGenericValueTypeInteger;
5654 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5655 attribs[i].value.value.i = VA_FOURCC_422V;
5658 attribs[i].type = VASurfaceAttribPixelFormat;
5659 attribs[i].value.type = VAGenericValueTypeInteger;
5660 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5661 attribs[i].value.value.i = VA_FOURCC_444P;
5664 attribs[i].type = VASurfaceAttribPixelFormat;
5665 attribs[i].value.type = VAGenericValueTypeInteger;
5666 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5667 attribs[i].value.value.i = VA_FOURCC_NV12;
5670 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5671 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5673 if (obj_config->profile == VAProfileHEVCMain10) {
5674 attribs[i].type = VASurfaceAttribPixelFormat;
5675 attribs[i].value.type = VAGenericValueTypeInteger;
5676 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5677 attribs[i].value.value.i = VA_FOURCC_P010;
5680 attribs[i].type = VASurfaceAttribPixelFormat;
5681 attribs[i].value.type = VAGenericValueTypeInteger;
5682 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5683 attribs[i].value.value.i = VA_FOURCC_NV12;
5686 attribs[i].type = VASurfaceAttribPixelFormat;
5687 attribs[i].value.type = VAGenericValueTypeInteger;
5688 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5689 attribs[i].value.value.i = VA_FOURCC_I420;
5692 attribs[i].type = VASurfaceAttribPixelFormat;
5693 attribs[i].value.type = VAGenericValueTypeInteger;
5694 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5695 attribs[i].value.value.i = VA_FOURCC_YV12;
5698 attribs[i].type = VASurfaceAttribPixelFormat;
5699 attribs[i].value.type = VAGenericValueTypeInteger;
5700 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5701 attribs[i].value.value.i = VA_FOURCC_IMC3;
5705 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5706 attribs[i].type = VASurfaceAttribPixelFormat;
5707 attribs[i].value.type = VAGenericValueTypeInteger;
5708 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5709 attribs[i].value.value.i = VA_FOURCC_YUY2;
5712 attribs[i].type = VASurfaceAttribPixelFormat;
5713 attribs[i].value.type = VAGenericValueTypeInteger;
5714 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5715 attribs[i].value.value.i = VA_FOURCC_RGBA;
5718 attribs[i].type = VASurfaceAttribPixelFormat;
5719 attribs[i].value.type = VAGenericValueTypeInteger;
5720 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5721 attribs[i].value.value.i = VA_FOURCC_RGBX;
5724 attribs[i].type = VASurfaceAttribPixelFormat;
5725 attribs[i].value.type = VAGenericValueTypeInteger;
5726 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5727 attribs[i].value.value.i = VA_FOURCC_BGRA;
5730 attribs[i].type = VASurfaceAttribPixelFormat;
5731 attribs[i].value.type = VAGenericValueTypeInteger;
5732 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5733 attribs[i].value.value.i = VA_FOURCC_BGRX;
5736 attribs[i].type = VASurfaceAttribPixelFormat;
5737 attribs[i].value.type = VAGenericValueTypeInteger;
5738 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5739 attribs[i].value.value.i = VA_FOURCC_YV16;
5742 if(HAS_VPP_P010(i965)) {
5743 attribs[i].type = VASurfaceAttribPixelFormat;
5744 attribs[i].value.type = VAGenericValueTypeInteger;
5745 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5746 attribs[i].value.value.i = VA_FOURCC_P010;
5753 attribs[i].type = VASurfaceAttribMemoryType;
5754 attribs[i].value.type = VAGenericValueTypeInteger;
5755 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5756 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
5757 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
5758 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
5761 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
5762 attribs[i].value.type = VAGenericValueTypePointer;
5763 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
5764 attribs[i].value.value.p = NULL; /* ignore */
5767 attribs[i].type = VASurfaceAttribMaxWidth;
5768 attribs[i].value.type = VAGenericValueTypeInteger;
5769 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5770 attribs[i].value.value.i = i965->codec_info->max_width;
5773 attribs[i].type = VASurfaceAttribMaxHeight;
5774 attribs[i].value.type = VAGenericValueTypeInteger;
5775 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5776 attribs[i].value.value.i = i965->codec_info->max_height;
5779 if (i > *num_attribs) {
5782 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5786 memcpy(attrib_list, attribs, i * sizeof(*attribs));
5792 /* Acquires buffer handle for external API usage (internal implementation) */
5794 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
5795 uint32_t mem_type, VABufferInfo *out_buf_info)
5797 struct buffer_store *buffer_store;
5799 buffer_store = obj_buffer->buffer_store;
5800 if (!buffer_store || !buffer_store->bo)
5801 return VA_STATUS_ERROR_INVALID_BUFFER;
5803 /* Synchronization point */
5804 drm_intel_bo_wait_rendering(buffer_store->bo);
5806 if (obj_buffer->export_refcount > 0) {
5807 if (obj_buffer->export_state.mem_type != mem_type)
5808 return VA_STATUS_ERROR_INVALID_PARAMETER;
5811 VABufferInfo * const buf_info = &obj_buffer->export_state;
5814 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
5816 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
5817 return VA_STATUS_ERROR_INVALID_BUFFER;
5818 buf_info->handle = name;
5821 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5823 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
5824 return VA_STATUS_ERROR_INVALID_BUFFER;
5825 buf_info->handle = (intptr_t)fd;
5830 buf_info->type = obj_buffer->type;
5831 buf_info->mem_type = mem_type;
5832 buf_info->mem_size =
5833 obj_buffer->num_elements * obj_buffer->size_element;
5836 obj_buffer->export_refcount++;
5837 *out_buf_info = obj_buffer->export_state;
5838 return VA_STATUS_SUCCESS;
5841 /* Releases buffer handle after usage (internal implementation) */
5843 i965_release_buffer_handle(struct object_buffer *obj_buffer)
5845 if (obj_buffer->export_refcount == 0)
5846 return VA_STATUS_ERROR_INVALID_BUFFER;
5848 if (--obj_buffer->export_refcount == 0) {
5849 VABufferInfo * const buf_info = &obj_buffer->export_state;
5851 switch (buf_info->mem_type) {
5852 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5853 close((intptr_t)buf_info->handle);
5857 buf_info->mem_type = 0;
5859 return VA_STATUS_SUCCESS;
5862 /** Acquires buffer handle for external API usage */
5864 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
5865 VABufferInfo *buf_info)
5867 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5868 struct object_buffer * const obj_buffer = BUFFER(buf_id);
5869 uint32_t i, mem_type;
5871 /* List of supported memory types, in preferred order */
5872 static const uint32_t mem_types[] = {
5873 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
5874 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
5879 return VA_STATUS_ERROR_INVALID_BUFFER;
5880 /* XXX: only VA surface|image like buffers are supported for now */
5881 if (obj_buffer->type != VAImageBufferType)
5882 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
5885 * As the allocated buffer by calling vaCreateBuffer is related with
5886 * the specific context, it is unnecessary to export it.
5887 * So it is not supported when the buffer is allocated from wrapped
5890 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
5891 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
5895 return VA_STATUS_ERROR_INVALID_PARAMETER;
5897 if (!buf_info->mem_type)
5898 mem_type = mem_types[0];
5901 for (i = 0; mem_types[i] != 0; i++) {
5902 if (buf_info->mem_type & mem_types[i]) {
5903 mem_type = buf_info->mem_type;
5908 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
5910 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
5913 /** Releases buffer handle after usage from external API */
5915 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
5917 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5918 struct object_buffer * const obj_buffer = BUFFER(buf_id);
5921 return VA_STATUS_ERROR_INVALID_BUFFER;
5923 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
5924 return VA_STATUS_ERROR_INVALID_BUFFER;
5927 return i965_release_buffer_handle(obj_buffer);
5931 i965_os_has_ring_support(VADriverContextP ctx,
5934 struct i965_driver_data *const i965 = i965_driver_data(ctx);
5938 return i965->intel.has_bsd;
5941 return i965->intel.has_blt;
5943 case I965_RING_VEBOX:
5944 return i965->intel.has_vebox;
5946 case I965_RING_NULL:
5947 return 1; /* Always support */
5950 /* should never get here */
5959 * Query video processing pipeline
5961 VAStatus i965_QueryVideoProcFilters(
5962 VADriverContextP ctx,
5963 VAContextID context,
5964 VAProcFilterType *filters,
5965 unsigned int *num_filters
5968 struct i965_driver_data *const i965 = i965_driver_data(ctx);
5969 unsigned int i = 0, num = 0;
5971 if (!num_filters || !filters)
5972 return VA_STATUS_ERROR_INVALID_PARAMETER;
5974 for (i = 0; i < i965->codec_info->num_filters; i++) {
5975 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
5976 if (num == *num_filters) {
5977 *num_filters = i965->codec_info->num_filters;
5979 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5982 filters[num++] = i965->codec_info->filters[i].type;
5988 return VA_STATUS_SUCCESS;
5991 VAStatus i965_QueryVideoProcFilterCaps(
5992 VADriverContextP ctx,
5993 VAContextID context,
5994 VAProcFilterType type,
5996 unsigned int *num_filter_caps
6000 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6002 if (!filter_caps || !num_filter_caps)
6003 return VA_STATUS_ERROR_INVALID_PARAMETER;
6005 for (i = 0; i < i965->codec_info->num_filters; i++) {
6006 if (type == i965->codec_info->filters[i].type &&
6007 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6011 if (i == i965->codec_info->num_filters)
6012 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6017 case VAProcFilterNoiseReduction:
6018 case VAProcFilterSharpening:
6020 VAProcFilterCap *cap = filter_caps;
6022 if (*num_filter_caps < 1) {
6023 *num_filter_caps = 1;
6024 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6027 cap->range.min_value = 0.0;
6028 cap->range.max_value = 1.0;
6029 cap->range.default_value = 0.5;
6030 cap->range.step = 0.03125; /* 1.0 / 32 */
6036 case VAProcFilterDeinterlacing:
6038 VAProcFilterCapDeinterlacing *cap = filter_caps;
6040 if (*num_filter_caps < VAProcDeinterlacingCount) {
6041 *num_filter_caps = VAProcDeinterlacingCount;
6042 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6045 cap->type = VAProcDeinterlacingBob;
6050 if (i965->codec_info->has_di_motion_adptive) {
6051 cap->type = VAProcDeinterlacingMotionAdaptive;
6056 if (i965->codec_info->has_di_motion_compensated) {
6057 cap->type = VAProcDeinterlacingMotionCompensated;
6065 case VAProcFilterColorBalance:
6067 VAProcFilterCapColorBalance *cap = filter_caps;
6069 if (*num_filter_caps < VAProcColorBalanceCount) {
6070 *num_filter_caps = VAProcColorBalanceCount;
6071 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6074 cap->type = VAProcColorBalanceHue;
6075 cap->range.min_value = -180.0;
6076 cap->range.max_value = 180.0;
6077 cap->range.default_value = 0.0;
6078 cap->range.step = 1.0;
6082 cap->type = VAProcColorBalanceSaturation;
6083 cap->range.min_value = 0.0;
6084 cap->range.max_value = 10.0;
6085 cap->range.default_value = 1.0;
6086 cap->range.step = 0.1;
6090 cap->type = VAProcColorBalanceBrightness;
6091 cap->range.min_value = -100.0;
6092 cap->range.max_value = 100.0;
6093 cap->range.default_value = 0.0;
6094 cap->range.step = 1.0;
6098 cap->type = VAProcColorBalanceContrast;
6099 cap->range.min_value = 0.0;
6100 cap->range.max_value = 10.0;
6101 cap->range.default_value = 1.0;
6102 cap->range.step = 0.1;
6114 *num_filter_caps = i;
6116 return VA_STATUS_SUCCESS;
6119 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6120 VAProcColorStandardBT601,
6123 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6124 VAProcColorStandardBT601,
6127 VAStatus i965_QueryVideoProcPipelineCaps(
6128 VADriverContextP ctx,
6129 VAContextID context,
6130 VABufferID *filters,
6131 unsigned int num_filters,
6132 VAProcPipelineCaps *pipeline_cap /* out */
6135 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6138 pipeline_cap->pipeline_flags = 0;
6139 pipeline_cap->filter_flags = 0;
6140 pipeline_cap->num_forward_references = 0;
6141 pipeline_cap->num_backward_references = 0;
6142 pipeline_cap->num_input_color_standards = 1;
6143 pipeline_cap->input_color_standards = vpp_input_color_standards;
6144 pipeline_cap->num_output_color_standards = 1;
6145 pipeline_cap->output_color_standards = vpp_output_color_standards;
6147 for (i = 0; i < num_filters; i++) {
6148 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6151 !obj_buffer->buffer_store ||
6152 !obj_buffer->buffer_store->buffer)
6153 return VA_STATUS_ERROR_INVALID_BUFFER;
6155 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6157 if (base->type == VAProcFilterNoiseReduction) {
6158 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6160 } else if (base->type == VAProcFilterDeinterlacing) {
6161 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6163 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6164 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6165 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6166 VA_STATUS_ERROR_INVALID_PARAMETER);
6168 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6169 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6170 pipeline_cap->num_forward_references++;
6171 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6172 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6177 return VA_STATUS_SUCCESS;
6180 extern struct hw_codec_info *i965_get_codec_info(int devid);
6183 i965_driver_data_init(VADriverContextP ctx)
6185 struct i965_driver_data *i965 = i965_driver_data(ctx);
6187 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6189 if (!i965->codec_info)
6192 if (object_heap_init(&i965->config_heap,
6193 sizeof(struct object_config),
6195 goto err_config_heap;
6196 if (object_heap_init(&i965->context_heap,
6197 sizeof(struct object_context),
6199 goto err_context_heap;
6201 if (object_heap_init(&i965->surface_heap,
6202 sizeof(struct object_surface),
6204 goto err_surface_heap;
6205 if (object_heap_init(&i965->buffer_heap,
6206 sizeof(struct object_buffer),
6208 goto err_buffer_heap;
6209 if (object_heap_init(&i965->image_heap,
6210 sizeof(struct object_image),
6212 goto err_image_heap;
6213 if (object_heap_init(&i965->subpic_heap,
6214 sizeof(struct object_subpic),
6216 goto err_subpic_heap;
6218 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6219 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6220 _i965InitMutex(&i965->render_mutex);
6221 _i965InitMutex(&i965->pp_mutex);
6226 object_heap_destroy(&i965->image_heap);
6228 object_heap_destroy(&i965->buffer_heap);
6230 object_heap_destroy(&i965->surface_heap);
6232 object_heap_destroy(&i965->context_heap);
6234 object_heap_destroy(&i965->config_heap);
6241 i965_driver_data_terminate(VADriverContextP ctx)
6243 struct i965_driver_data *i965 = i965_driver_data(ctx);
6245 _i965DestroyMutex(&i965->pp_mutex);
6246 _i965DestroyMutex(&i965->render_mutex);
6249 intel_batchbuffer_free(i965->batch);
6252 intel_batchbuffer_free(i965->pp_batch);
6254 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6255 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6256 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6257 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6258 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6259 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6263 bool (*init)(VADriverContextP ctx);
6264 void (*terminate)(VADriverContextP ctx);
6266 } i965_sub_ops[] = {
6269 intel_driver_terminate,
6274 i965_driver_data_init,
6275 i965_driver_data_terminate,
6280 i965_display_attributes_init,
6281 i965_display_attributes_terminate,
6286 i965_post_processing_init,
6287 i965_post_processing_terminate,
6293 i965_render_terminate,
6297 #ifdef HAVE_VA_WAYLAND
6299 i965_output_wayland_init,
6300 i965_output_wayland_terminate,
6307 i965_output_dri_init,
6308 i965_output_dri_terminate,
6315 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6319 if (i965->va_vendor[0] != '\0')
6323 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6324 "%s %s driver for %s - %d.%d.%d",
6325 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6326 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6327 INTEL_DRIVER_MICRO_VERSION);
6328 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6332 if (INTEL_DRIVER_PRE_VERSION > 0) {
6333 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6334 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6335 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6339 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6340 " (%s)", INTEL_DRIVER_GIT_VERSION);
6341 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6348 i965->va_vendor[0] = '\0';
6349 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6353 /* Only when the option of "enable-wrapper" is passed, it is possible
6354 * to initialize/load the wrapper context of backend driver.
6355 * Otherwise it is not loaded.
6357 #if HAVE_HYBRID_CODEC
6360 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6362 #define DRIVER_EXTENSION "_drv_video.so"
6364 struct i965_driver_data *i965 = i965_driver_data(ctx);
6366 VADriverContextP wrapper_pdrvctx;
6367 struct VADriverVTable *vtable;
6368 char *search_path, *driver_dir;
6370 char driver_path[256];
6371 void *handle = NULL;
6372 VAStatus va_status = VA_STATUS_SUCCESS;
6373 bool driver_loaded = false;
6375 if (HAS_VP9_DECODING(i965)) {
6376 i965->wrapper_pdrvctx = NULL;
6380 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6381 vtable = calloc(1, sizeof(*vtable));
6383 if (!wrapper_pdrvctx || !vtable) {
6384 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6385 free(wrapper_pdrvctx);
6387 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6390 /* use the same drm_state with CTX */
6391 wrapper_pdrvctx->drm_state = ctx->drm_state;
6392 wrapper_pdrvctx->display_type = ctx->display_type;
6393 wrapper_pdrvctx->vtable = vtable;
6395 search_path = VA_DRIVERS_PATH;
6396 search_path = strdup((const char *)search_path);
6398 driver_dir = strtok_r(search_path, ":", &saveptr);
6399 while (driver_dir && !driver_loaded) {
6400 memset(driver_path, 0, sizeof(driver_path));
6401 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6403 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6405 fprintf(stderr, "failed to open %s\n", driver_path);
6406 driver_dir = strtok_r(NULL, ":", &saveptr);
6410 VADriverInit init_func = NULL;
6411 char init_func_s[256];
6414 static const struct {
6417 } compatible_versions[] = {
6418 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6427 for (i = 0; compatible_versions[i].major >= 0; i++) {
6428 snprintf(init_func_s, sizeof(init_func_s),
6429 "__vaDriverInit_%d_%d",
6430 compatible_versions[i].major,
6431 compatible_versions[i].minor);
6432 init_func = (VADriverInit)dlsym(handle, init_func_s);
6437 if (compatible_versions[i].major < 0) {
6439 fprintf(stderr, "%s has no function %s\n",
6440 driver_path, init_func_s);
6441 driver_dir = strtok_r(NULL, ":", &saveptr);
6446 va_status = (*init_func)(wrapper_pdrvctx);
6448 if (va_status != VA_STATUS_SUCCESS) {
6450 fprintf(stderr, "%s init failed\n", driver_path);
6451 driver_dir = strtok_r(NULL, ":", &saveptr);
6455 wrapper_pdrvctx->handle = handle;
6456 driver_loaded = true;
6462 if (driver_loaded) {
6463 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6464 return VA_STATUS_SUCCESS;
6466 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6468 free(wrapper_pdrvctx);
6469 return VA_STATUS_ERROR_OPERATION_FAILED;
6475 i965_Init(VADriverContextP ctx)
6477 struct i965_driver_data *i965 = i965_driver_data(ctx);
6479 const char *chipset;
6481 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6482 if ((i965_sub_ops[i].display_type == 0 ||
6483 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6484 !i965_sub_ops[i].init(ctx))
6488 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6489 switch (i965->intel.device_id) {
6491 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6492 #include "i965_pciids.h"
6494 chipset = "Unknown Intel Chipset";
6498 if (!ensure_vendor_string(i965, chipset))
6499 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6501 i965->current_context_id = VA_INVALID_ID;
6503 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6504 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6506 #if HAVE_HYBRID_CODEC
6507 i965_initialize_wrapper(ctx, "hybrid");
6510 return VA_STATUS_SUCCESS;
6514 for (; i >= 0; i--) {
6515 if (i965_sub_ops[i].display_type == 0 ||
6516 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6517 i965_sub_ops[i].terminate(ctx);
6521 return VA_STATUS_ERROR_UNKNOWN;
6526 i965_Terminate(VADriverContextP ctx)
6528 struct i965_driver_data *i965 = i965_driver_data(ctx);
6532 if (i965->wrapper_pdrvctx) {
6533 VADriverContextP pdrvctx;
6534 pdrvctx = i965->wrapper_pdrvctx;
6535 if (pdrvctx->handle) {
6536 pdrvctx->vtable->vaTerminate(pdrvctx);
6537 dlclose(pdrvctx->handle);
6538 pdrvctx->handle = NULL;
6540 free(pdrvctx->vtable);
6542 i965->wrapper_pdrvctx = NULL;
6545 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6546 if (i965_sub_ops[i - 1].display_type == 0 ||
6547 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6548 i965_sub_ops[i - 1].terminate(ctx);
6552 ctx->pDriverData = NULL;
6555 return VA_STATUS_SUCCESS;
6559 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6562 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
6564 struct VADriverVTable * const vtable = ctx->vtable;
6565 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6567 struct i965_driver_data *i965;
6568 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6570 ctx->version_major = VA_MAJOR_VERSION;
6571 ctx->version_minor = VA_MINOR_VERSION;
6572 ctx->max_profiles = I965_MAX_PROFILES;
6573 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6574 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6575 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6576 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6577 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6579 vtable->vaTerminate = i965_Terminate;
6580 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6581 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6582 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6583 vtable->vaCreateConfig = i965_CreateConfig;
6584 vtable->vaDestroyConfig = i965_DestroyConfig;
6585 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6586 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6587 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6588 vtable->vaCreateContext = i965_CreateContext;
6589 vtable->vaDestroyContext = i965_DestroyContext;
6590 vtable->vaCreateBuffer = i965_CreateBuffer;
6591 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
6592 vtable->vaMapBuffer = i965_MapBuffer;
6593 vtable->vaUnmapBuffer = i965_UnmapBuffer;
6594 vtable->vaDestroyBuffer = i965_DestroyBuffer;
6595 vtable->vaBeginPicture = i965_BeginPicture;
6596 vtable->vaRenderPicture = i965_RenderPicture;
6597 vtable->vaEndPicture = i965_EndPicture;
6598 vtable->vaSyncSurface = i965_SyncSurface;
6599 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
6600 vtable->vaPutSurface = i965_PutSurface;
6601 vtable->vaQueryImageFormats = i965_QueryImageFormats;
6602 vtable->vaCreateImage = i965_CreateImage;
6603 vtable->vaDeriveImage = i965_DeriveImage;
6604 vtable->vaDestroyImage = i965_DestroyImage;
6605 vtable->vaSetImagePalette = i965_SetImagePalette;
6606 vtable->vaGetImage = i965_GetImage;
6607 vtable->vaPutImage = i965_PutImage;
6608 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
6609 vtable->vaCreateSubpicture = i965_CreateSubpicture;
6610 vtable->vaDestroySubpicture = i965_DestroySubpicture;
6611 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
6612 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
6613 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
6614 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
6615 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
6616 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
6617 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
6618 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
6619 vtable->vaBufferInfo = i965_BufferInfo;
6620 vtable->vaLockSurface = i965_LockSurface;
6621 vtable->vaUnlockSurface = i965_UnlockSurface;
6622 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
6623 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
6624 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
6627 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
6628 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
6630 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
6631 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
6632 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
6634 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
6637 ctx->pDriverData = NULL;
6639 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6642 i965->wrapper_pdrvctx = NULL;
6643 ctx->pDriverData = (void *)i965;
6644 ret = i965_Init(ctx);
6646 if (ret == VA_STATUS_SUCCESS) {
6647 ctx->str_vendor = i965->va_vendor;
6650 ctx->pDriverData = NULL;