2 * Copyright ?2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Xiang Haihao <haihao.xiang@intel.com>
26 * Zou Nan hai <nanhai.zou@intel.com>
35 # include "i965_output_dri.h"
38 #ifdef HAVE_VA_WAYLAND
39 # include "i965_output_wayland.h"
42 #include "intel_version.h"
43 #include "intel_driver.h"
44 #include "intel_memman.h"
45 #include "intel_batchbuffer.h"
46 #include "i965_defines.h"
47 #include "i965_drv_video.h"
48 #include "i965_decoder.h"
49 #include "i965_encoder.h"
51 #include "gen9_vp9_encapi.h"
53 #define CONFIG_ID_OFFSET 0x01000000
54 #define CONTEXT_ID_OFFSET 0x02000000
55 #define SURFACE_ID_OFFSET 0x04000000
56 #define BUFFER_ID_OFFSET 0x08000000
57 #define IMAGE_ID_OFFSET 0x0a000000
58 #define SUBPIC_ID_OFFSET 0x10000000
60 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
63 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
66 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
69 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
72 #define HAS_LP_H264_ENCODING(ctx) ((ctx)->codec_info->has_lp_h264_encoding && \
75 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
78 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
81 #define HAS_JPEG_ENCODING(ctx) ((ctx)->codec_info->has_jpeg_encoding && \
84 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
86 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
88 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
90 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
92 #define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \
95 #define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \
98 #define HAS_H264_MVC_DECODING(ctx) \
99 (HAS_H264_DECODING(ctx) && (ctx)->codec_info->h264_mvc_dec_profiles)
101 #define HAS_H264_MVC_DECODING_PROFILE(ctx, profile) \
102 (HAS_H264_MVC_DECODING(ctx) && \
103 ((ctx)->codec_info->h264_mvc_dec_profiles & (1U << profile)))
105 #define HAS_H264_MVC_ENCODING(ctx) ((ctx)->codec_info->has_h264_mvc_encoding && \
106 (ctx)->intel.has_bsd)
108 #define HAS_HEVC_DECODING(ctx) ((ctx)->codec_info->has_hevc_decoding && \
109 (ctx)->intel.has_bsd)
111 #define HAS_HEVC_ENCODING(ctx) ((ctx)->codec_info->has_hevc_encoding && \
112 (ctx)->intel.has_bsd)
114 #define HAS_VP9_DECODING(ctx) ((ctx)->codec_info->has_vp9_decoding && \
115 (ctx)->intel.has_bsd)
117 #define HAS_VP9_DECODING_PROFILE(ctx, profile) \
118 (HAS_VP9_DECODING(ctx) && \
119 ((ctx)->codec_info->vp9_dec_profiles & (1U << (profile - VAProfileVP9Profile0))))
121 #define HAS_HEVC10_DECODING(ctx) ((ctx)->codec_info->has_hevc10_decoding && \
122 (ctx)->intel.has_bsd)
124 #define HAS_VPP_P010(ctx) ((ctx)->codec_info->has_vpp_p010 && \
125 (ctx)->intel.has_bsd)
127 #define HAS_VP9_ENCODING(ctx) ((ctx)->codec_info->has_vp9_encoding && \
128 (ctx)->intel.has_bsd)
130 static int get_sampling_from_fourcc(unsigned int fourcc);
132 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
133 #define IS_VA_X11(ctx) \
134 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
136 /* Check whether we are rendering to Wayland */
137 #define IS_VA_WAYLAND(ctx) \
138 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
141 #define I965_2BITS (I965_BIT << 1)
142 #define I965_4BITS (I965_BIT << 2)
143 #define I965_8BITS (I965_BIT << 3)
144 #define I965_16BITS (I965_BIT << 4)
145 #define I965_32BITS (I965_BIT << 5)
157 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
158 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
159 #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} }
160 #define I_IYUV I_I420
161 #define I_IMC3 I_I420
162 #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} }
163 #define I_IMC1 I_YV12
165 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
167 #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} }
168 #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} }
169 #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} }
170 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
171 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
173 #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} }
175 #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} }
177 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
179 #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} }
180 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
181 #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} }
182 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
184 #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} }
185 #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} }
187 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
188 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
190 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
191 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
196 #define I_SI (I_S | I_I)
198 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
199 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
200 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
201 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
203 static const i965_fourcc_info i965_fourcc_infos[] = {
204 DEF_YUV(NV12, YUV420, I_SI),
205 DEF_YUV(I420, YUV420, I_SI),
206 DEF_YUV(IYUV, YUV420, I_S),
207 DEF_YUV(IMC3, YUV420, I_S),
208 DEF_YUV(YV12, YUV420, I_SI),
209 DEF_YUV(IMC1, YUV420, I_S),
211 DEF_YUV(P010, YUV420, I_SI),
213 DEF_YUV(422H, YUV422H, I_SI),
214 DEF_YUV(422V, YUV422V, I_S),
215 DEF_YUV(YV16, YUV422H, I_S),
216 DEF_YUV(YUY2, YUV422H, I_SI),
217 DEF_YUV(UYVY, YUV422H, I_SI),
219 DEF_YUV(444P, YUV444, I_S),
221 DEF_YUV(411P, YUV411, I_S),
223 DEF_YUV(Y800, YUV400, I_S),
225 DEF_RGB(RGBA, RGBX, I_SI),
226 DEF_RGB(RGBX, RGBX, I_SI),
227 DEF_RGB(BGRA, RGBX, I_SI),
228 DEF_RGB(BGRX, RGBX, I_SI),
230 DEF_RGB(ARGB, RGBX, I_I),
231 DEF_RGB(ABGR, RGBX, I_I),
233 DEF_INDEX(IA88, RGBX, I_I),
234 DEF_INDEX(AI88, RGBX, I_I),
236 DEF_INDEX(IA44, RGBX, I_I),
237 DEF_INDEX(AI44, RGBX, I_I)
240 const i965_fourcc_info *
241 get_fourcc_info(unsigned int fourcc)
245 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
246 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
248 if (info->fourcc == fourcc)
256 get_bpp_from_fourcc(unsigned int fourcc)
258 const i965_fourcc_info *info = get_fourcc_info(fourcc);
260 unsigned int bpp = 0;
265 for (i = 0; i < info->num_planes; i++)
272 I965_SURFACETYPE_RGBA = 1,
273 I965_SURFACETYPE_YUV,
274 I965_SURFACETYPE_INDEXED
277 /* List of supported display attributes */
278 static const VADisplayAttribute i965_display_attributes[] = {
280 VADisplayAttribBrightness,
281 -100, 100, DEFAULT_BRIGHTNESS,
282 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
286 VADisplayAttribContrast,
287 0, 100, DEFAULT_CONTRAST,
288 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
293 -180, 180, DEFAULT_HUE,
294 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
298 VADisplayAttribSaturation,
299 0, 100, DEFAULT_SATURATION,
300 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
304 VADisplayAttribRotation,
305 0, 3, VA_ROTATION_NONE,
306 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
310 /* List of supported image formats */
313 VAImageFormat va_format;
314 } i965_image_format_map_t;
316 static const i965_image_format_map_t
317 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
318 { I965_SURFACETYPE_YUV,
319 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
320 { I965_SURFACETYPE_YUV,
321 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
322 { I965_SURFACETYPE_YUV,
323 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
324 { I965_SURFACETYPE_YUV,
325 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
326 { I965_SURFACETYPE_YUV,
327 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
328 { I965_SURFACETYPE_YUV,
329 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
330 { I965_SURFACETYPE_RGBA,
331 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
332 { I965_SURFACETYPE_RGBA,
333 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
334 { I965_SURFACETYPE_YUV,
335 { VA_FOURCC_P010, VA_LSB_FIRST, 24, } },
338 /* List of supported subpicture formats */
342 VAImageFormat va_format;
343 unsigned int va_flags;
344 } i965_subpic_format_map_t;
346 #define COMMON_SUBPICTURE_FLAGS \
347 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
348 VA_SUBPICTURE_GLOBAL_ALPHA)
350 static const i965_subpic_format_map_t
351 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
352 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
353 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
354 COMMON_SUBPICTURE_FLAGS },
355 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
356 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
357 COMMON_SUBPICTURE_FLAGS },
358 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
359 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
360 COMMON_SUBPICTURE_FLAGS },
361 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
362 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
363 COMMON_SUBPICTURE_FLAGS },
364 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
365 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
366 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
367 COMMON_SUBPICTURE_FLAGS },
368 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
369 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
370 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
371 COMMON_SUBPICTURE_FLAGS },
374 static const i965_subpic_format_map_t *
375 get_subpic_format(const VAImageFormat *va_format)
378 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
379 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
380 if (m->va_format.fourcc == va_format->fourcc &&
381 (m->type == I965_SURFACETYPE_RGBA ?
382 (m->va_format.byte_order == va_format->byte_order &&
383 m->va_format.red_mask == va_format->red_mask &&
384 m->va_format.green_mask == va_format->green_mask &&
385 m->va_format.blue_mask == va_format->blue_mask &&
386 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
392 /* Checks whether the surface is in busy state */
394 is_surface_busy(struct i965_driver_data *i965,
395 struct object_surface *obj_surface)
397 assert(obj_surface != NULL);
399 if (obj_surface->locked_image_id != VA_INVALID_ID)
401 if (obj_surface->derived_image_id != VA_INVALID_ID)
406 /* Checks whether the image is in busy state */
408 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
410 struct object_buffer *obj_buffer;
412 assert(obj_image != NULL);
414 if (obj_image->derived_surface != VA_INVALID_ID &&
415 obj_image->derived_surface == surface)
418 obj_buffer = BUFFER(obj_image->image.buf);
419 if (obj_buffer && obj_buffer->export_refcount > 0)
424 #define I965_PACKED_HEADER_BASE 0
425 #define I965_SEQ_PACKED_HEADER_BASE 0
426 #define I965_SEQ_PACKED_HEADER_END 2
427 #define I965_PIC_PACKED_HEADER_BASE 2
428 #define I965_PACKED_MISC_HEADER_BASE 4
431 va_enc_packed_type_to_idx(int packed_type)
435 if (packed_type & VAEncPackedHeaderMiscMask) {
436 idx = I965_PACKED_MISC_HEADER_BASE;
437 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
438 ASSERT_RET(packed_type > 0, 0);
439 idx += (packed_type - 1);
441 idx = I965_PACKED_HEADER_BASE;
443 switch (packed_type) {
444 case VAEncPackedHeaderSequence:
445 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
448 case VAEncPackedHeaderPicture:
449 idx = I965_PIC_PACKED_HEADER_BASE + 0;
452 case VAEncPackedHeaderSlice:
453 idx = I965_PIC_PACKED_HEADER_BASE + 1;
457 /* Should not get here */
463 ASSERT_RET(idx < 5, 0);
467 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
470 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
472 struct i965_driver_data *i965 = i965_driver_data(ctx);
473 struct object_surface *obj_surface = SURFACE(surface);
474 VAStatus va_status = VA_STATUS_SUCCESS;
477 return VA_STATUS_ERROR_INVALID_SURFACE;
480 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
481 /* the wrapped surface already exists. just return it */
485 if (obj_surface->fourcc == 0)
486 i965_check_alloc_surface_bo(ctx, obj_surface,
487 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
490 * TBD: Support more surface formats.
491 * Currently only NV12 is support as NV12 is used by decoding.
493 if (obj_surface->fourcc != VA_FOURCC_NV12 )
494 return VA_STATUS_ERROR_INVALID_PARAMETER;
496 if ((i965->wrapper_pdrvctx == NULL) ||
497 (obj_surface->bo == NULL))
498 return VA_STATUS_ERROR_INVALID_PARAMETER;
502 VASurfaceAttrib attrib_list[2];
503 VASurfaceAttribExternalBuffers buffer_descriptor;
504 VAGenericID wrapper_surface;
506 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
507 return VA_STATUS_ERROR_OPERATION_FAILED;
509 obj_surface->exported_primefd = fd_handle;
511 memset(&attrib_list, 0, sizeof(attrib_list));
512 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
514 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
515 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
516 attrib_list[0].value.value.p = &buffer_descriptor;
517 attrib_list[0].value.type = VAGenericValueTypePointer;
519 attrib_list[1].type = VASurfaceAttribMemoryType;
520 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
521 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
522 attrib_list[1].value.type = VAGenericValueTypeInteger;
524 buffer_descriptor.num_buffers = 1;
525 buffer_descriptor.num_planes = 2;
526 buffer_descriptor.width = obj_surface->orig_width;
527 buffer_descriptor.height = obj_surface->orig_height;
528 buffer_descriptor.pixel_format = obj_surface->fourcc;
529 buffer_descriptor.data_size = obj_surface->size;
530 buffer_descriptor.pitches[0] = obj_surface->width;
531 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
532 buffer_descriptor.offsets[0] = 0;
533 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
534 buffer_descriptor.buffers = (void *)&fd_handle;
536 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
537 vaCreateSurfaces2(i965->wrapper_pdrvctx,
539 obj_surface->orig_width,
540 obj_surface->orig_height,
544 if (va_status == VA_STATUS_SUCCESS) {
545 obj_surface->wrapper_surface = wrapper_surface;
547 /* This needs to be checked */
548 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
556 i965_QueryConfigProfiles(VADriverContextP ctx,
557 VAProfile *profile_list, /* out */
558 int *num_profiles) /* out */
560 struct i965_driver_data * const i965 = i965_driver_data(ctx);
563 if (HAS_MPEG2_DECODING(i965) ||
564 HAS_MPEG2_ENCODING(i965)) {
565 profile_list[i++] = VAProfileMPEG2Simple;
566 profile_list[i++] = VAProfileMPEG2Main;
569 if (HAS_H264_DECODING(i965) ||
570 HAS_H264_ENCODING(i965) ||
571 HAS_LP_H264_ENCODING(i965)) {
572 profile_list[i++] = VAProfileH264ConstrainedBaseline;
573 profile_list[i++] = VAProfileH264Main;
574 profile_list[i++] = VAProfileH264High;
576 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
577 HAS_H264_MVC_ENCODING(i965))
578 profile_list[i++] = VAProfileH264MultiviewHigh;
579 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
580 HAS_H264_MVC_ENCODING(i965))
581 profile_list[i++] = VAProfileH264StereoHigh;
583 if (HAS_VC1_DECODING(i965)) {
584 profile_list[i++] = VAProfileVC1Simple;
585 profile_list[i++] = VAProfileVC1Main;
586 profile_list[i++] = VAProfileVC1Advanced;
590 profile_list[i++] = VAProfileNone;
593 if (HAS_JPEG_DECODING(i965) ||
594 HAS_JPEG_ENCODING(i965)) {
595 profile_list[i++] = VAProfileJPEGBaseline;
598 if (HAS_VP8_DECODING(i965) ||
599 HAS_VP8_ENCODING(i965)) {
600 profile_list[i++] = VAProfileVP8Version0_3;
603 if (HAS_HEVC_DECODING(i965)||
604 HAS_HEVC_ENCODING(i965)) {
605 profile_list[i++] = VAProfileHEVCMain;
608 if (HAS_HEVC10_DECODING(i965)) {
609 profile_list[i++] = VAProfileHEVCMain10;
612 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
613 HAS_VP9_ENCODING(i965)) {
614 profile_list[i++] = VAProfileVP9Profile0;
617 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
618 profile_list[i++] = VAProfileVP9Profile2;
621 if (i965->wrapper_pdrvctx) {
622 VAProfile wrapper_list[4];
624 VADriverContextP pdrvctx;
627 pdrvctx = i965->wrapper_pdrvctx;
628 CALL_VTABLE(pdrvctx, va_status,
629 vaQueryConfigProfiles(pdrvctx,
630 wrapper_list, &wrapper_num));
632 if (va_status == VA_STATUS_SUCCESS) {
634 for (j = 0; j < wrapper_num; j++)
635 if (wrapper_list[j] != VAProfileNone)
636 profile_list[i++] = wrapper_list[j];
640 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
641 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
644 return VA_STATUS_SUCCESS;
648 i965_QueryConfigEntrypoints(VADriverContextP ctx,
650 VAEntrypoint *entrypoint_list, /* out */
651 int *num_entrypoints) /* out */
653 struct i965_driver_data * const i965 = i965_driver_data(ctx);
657 case VAProfileMPEG2Simple:
658 case VAProfileMPEG2Main:
659 if (HAS_MPEG2_DECODING(i965))
660 entrypoint_list[n++] = VAEntrypointVLD;
662 if (HAS_MPEG2_ENCODING(i965))
663 entrypoint_list[n++] = VAEntrypointEncSlice;
667 case VAProfileH264ConstrainedBaseline:
668 case VAProfileH264Main:
669 case VAProfileH264High:
670 if (HAS_H264_DECODING(i965))
671 entrypoint_list[n++] = VAEntrypointVLD;
673 if (HAS_H264_ENCODING(i965))
674 entrypoint_list[n++] = VAEntrypointEncSlice;
676 if (HAS_LP_H264_ENCODING(i965))
677 entrypoint_list[n++] = VAEntrypointEncSliceLP;
680 case VAProfileH264MultiviewHigh:
681 case VAProfileH264StereoHigh:
682 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
683 entrypoint_list[n++] = VAEntrypointVLD;
685 if (HAS_H264_MVC_ENCODING(i965))
686 entrypoint_list[n++] = VAEntrypointEncSlice;
689 case VAProfileVC1Simple:
690 case VAProfileVC1Main:
691 case VAProfileVC1Advanced:
692 if (HAS_VC1_DECODING(i965))
693 entrypoint_list[n++] = VAEntrypointVLD;
698 entrypoint_list[n++] = VAEntrypointVideoProc;
701 case VAProfileJPEGBaseline:
702 if (HAS_JPEG_DECODING(i965))
703 entrypoint_list[n++] = VAEntrypointVLD;
705 if (HAS_JPEG_ENCODING(i965))
706 entrypoint_list[n++] = VAEntrypointEncPicture;
709 case VAProfileVP8Version0_3:
710 if (HAS_VP8_DECODING(i965))
711 entrypoint_list[n++] = VAEntrypointVLD;
713 if (HAS_VP8_ENCODING(i965))
714 entrypoint_list[n++] = VAEntrypointEncSlice;
718 case VAProfileHEVCMain:
719 if (HAS_HEVC_DECODING(i965))
720 entrypoint_list[n++] = VAEntrypointVLD;
722 if (HAS_HEVC_ENCODING(i965))
723 entrypoint_list[n++] = VAEntrypointEncSlice;
727 case VAProfileHEVCMain10:
728 if (HAS_HEVC10_DECODING(i965))
729 entrypoint_list[n++] = VAEntrypointVLD;
733 case VAProfileVP9Profile0:
734 case VAProfileVP9Profile2:
735 if(HAS_VP9_DECODING_PROFILE(i965, profile))
736 entrypoint_list[n++] = VAEntrypointVLD;
738 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
739 entrypoint_list[n++] = VAEntrypointEncSlice;
741 if(profile == VAProfileVP9Profile0) {
742 if (i965->wrapper_pdrvctx) {
743 VAStatus va_status = VA_STATUS_SUCCESS;
744 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
746 CALL_VTABLE(pdrvctx, va_status,
747 vaQueryConfigEntrypoints(pdrvctx, profile,
760 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
761 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
762 *num_entrypoints = n;
763 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
767 i965_validate_config(VADriverContextP ctx, VAProfile profile,
768 VAEntrypoint entrypoint)
770 struct i965_driver_data * const i965 = i965_driver_data(ctx);
773 /* Validate profile & entrypoint */
775 case VAProfileMPEG2Simple:
776 case VAProfileMPEG2Main:
777 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
778 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
779 va_status = VA_STATUS_SUCCESS;
781 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
785 case VAProfileH264ConstrainedBaseline:
786 case VAProfileH264Main:
787 case VAProfileH264High:
788 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
789 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
790 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP)) {
791 va_status = VA_STATUS_SUCCESS;
793 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
797 case VAProfileVC1Simple:
798 case VAProfileVC1Main:
799 case VAProfileVC1Advanced:
800 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
801 va_status = VA_STATUS_SUCCESS;
803 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
808 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
809 va_status = VA_STATUS_SUCCESS;
811 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
815 case VAProfileJPEGBaseline:
816 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
817 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
818 va_status = VA_STATUS_SUCCESS;
820 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
824 case VAProfileVP8Version0_3:
825 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
826 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
827 va_status = VA_STATUS_SUCCESS;
829 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
833 case VAProfileH264MultiviewHigh:
834 case VAProfileH264StereoHigh:
835 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
836 entrypoint == VAEntrypointVLD) ||
837 (HAS_H264_MVC_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
838 va_status = VA_STATUS_SUCCESS;
840 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
845 case VAProfileHEVCMain:
846 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
847 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice)))
848 va_status = VA_STATUS_SUCCESS;
850 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
854 case VAProfileHEVCMain10:
855 if (HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD))
856 va_status = VA_STATUS_SUCCESS;
858 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
862 case VAProfileVP9Profile0:
863 case VAProfileVP9Profile2:
864 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) && (entrypoint == VAEntrypointVLD))
865 va_status = VA_STATUS_SUCCESS;
866 else if ((HAS_VP9_ENCODING(i965)) && (entrypoint == VAEntrypointEncSlice))
867 va_status = VA_STATUS_SUCCESS;
868 else if ((profile == VAProfileVP9Profile0) && i965->wrapper_pdrvctx)
869 va_status = VA_STATUS_SUCCESS;
871 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
875 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
882 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
883 VAEntrypoint entrypoint)
885 struct i965_driver_data * const i965 = i965_driver_data(ctx);
886 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
889 case VAProfileH264ConstrainedBaseline:
890 case VAProfileH264Main:
891 case VAProfileH264High:
892 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
893 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
896 case VAProfileH264MultiviewHigh:
897 case VAProfileH264StereoHigh:
898 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
899 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
902 case VAProfileJPEGBaseline:
903 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
904 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
905 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
906 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
909 case VAProfileHEVCMain10:
910 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
911 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
915 if(HAS_VPP_P010(i965))
916 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
919 case VAProfileVP9Profile0:
920 case VAProfileVP9Profile2:
921 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
922 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
928 return chroma_formats;
932 i965_GetConfigAttributes(VADriverContextP ctx,
934 VAEntrypoint entrypoint,
935 VAConfigAttrib *attrib_list, /* in/out */
941 va_status = i965_validate_config(ctx, profile, entrypoint);
942 if (va_status != VA_STATUS_SUCCESS)
945 /* Other attributes don't seem to be defined */
946 /* What to do if we don't know the attribute? */
947 for (i = 0; i < num_attribs; i++) {
948 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
949 switch (attrib_list[i].type) {
950 case VAConfigAttribRTFormat:
951 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
952 profile, entrypoint);
955 case VAConfigAttribRateControl:
956 if (entrypoint == VAEntrypointEncSlice) {
957 attrib_list[i].value = VA_RC_CQP;
959 if (profile != VAProfileMPEG2Main &&
960 profile != VAProfileMPEG2Simple)
961 attrib_list[i].value |= VA_RC_CBR;
963 if (profile == VAProfileVP9Profile0)
964 attrib_list[i].value |= VA_RC_VBR;
967 } else if (entrypoint == VAEntrypointEncSliceLP) {
968 struct i965_driver_data * const i965 = i965_driver_data(ctx);
970 /* Support low power encoding for H.264 only by now */
971 if (profile == VAProfileH264ConstrainedBaseline ||
972 profile == VAProfileH264Main ||
973 profile == VAProfileH264High)
974 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
976 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
978 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
982 case VAConfigAttribEncPackedHeaders:
983 if (entrypoint == VAEntrypointEncSlice ||
984 entrypoint == VAEntrypointEncSliceLP) {
985 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
986 if (profile == VAProfileH264ConstrainedBaseline ||
987 profile == VAProfileH264Main ||
988 profile == VAProfileH264High ||
989 profile == VAProfileH264StereoHigh ||
990 profile == VAProfileH264MultiviewHigh ||
991 profile == VAProfileHEVCMain) {
992 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
993 VA_ENC_PACKED_HEADER_SLICE);
995 else if (profile == VAProfileVP9Profile0)
996 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
999 else if (entrypoint == VAEntrypointEncPicture) {
1000 if (profile == VAProfileJPEGBaseline)
1001 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1005 case VAConfigAttribEncMaxRefFrames:
1006 if (entrypoint == VAEntrypointEncSlice)
1007 attrib_list[i].value = (1 << 16) | (1 << 0);
1008 else if (entrypoint == VAEntrypointEncSliceLP) {
1009 /* Don't support B frame for low power mode */
1010 if (profile == VAProfileH264ConstrainedBaseline ||
1011 profile == VAProfileH264Main ||
1012 profile == VAProfileH264High)
1013 attrib_list[i].value = (1 << 0);
1015 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1020 case VAConfigAttribEncQualityRange:
1021 if (entrypoint == VAEntrypointEncSlice ||
1022 entrypoint == VAEntrypointEncSliceLP) {
1023 attrib_list[i].value = 1;
1024 if (profile == VAProfileH264ConstrainedBaseline ||
1025 profile == VAProfileH264Main ||
1026 profile == VAProfileH264High )
1027 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1032 case VAConfigAttribEncJPEG:
1033 if( entrypoint == VAEntrypointEncPicture) {
1034 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*)&(attrib_list[i].value);
1035 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1036 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1037 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1038 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1039 (configVal->bits).max_num_components = 3; // Only 3 components supported
1040 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1041 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1042 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1046 case VAConfigAttribDecSliceMode:
1047 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1050 case VAConfigAttribEncROI:
1051 if (profile == VAProfileH264ConstrainedBaseline ||
1052 profile == VAProfileH264Main ||
1053 profile == VAProfileH264High) {
1054 VAConfigAttribValEncROI *roi_config = (VAConfigAttribValEncROI *)&(attrib_list[i].value);
1056 if(entrypoint == VAEntrypointEncSliceLP) {
1057 roi_config->bits.num_roi_regions = 3;
1058 roi_config->bits.roi_rc_priority_support = 0;
1059 roi_config->bits.roi_rc_qp_delat_support = 0;
1061 roi_config->bits.num_roi_regions = I965_MAX_NUM_ROI_REGIONS;
1062 roi_config->bits.roi_rc_priority_support = 0;
1063 roi_config->bits.roi_rc_qp_delat_support = 1;
1066 attrib_list[i].value = 0;
1073 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1078 return VA_STATUS_SUCCESS;
1082 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1084 object_heap_free(heap, obj);
1087 static VAConfigAttrib *
1088 i965_lookup_config_attribute(struct object_config *obj_config,
1089 VAConfigAttribType type)
1093 for (i = 0; i < obj_config->num_attribs; i++) {
1094 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1095 if (attrib->type == type)
1102 i965_append_config_attribute(struct object_config *obj_config,
1103 const VAConfigAttrib *new_attrib)
1105 VAConfigAttrib *attrib;
1107 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1108 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1110 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1111 attrib->type = new_attrib->type;
1112 attrib->value = new_attrib->value;
1113 return VA_STATUS_SUCCESS;
1117 i965_ensure_config_attribute(struct object_config *obj_config,
1118 const VAConfigAttrib *new_attrib)
1120 VAConfigAttrib *attrib;
1122 /* Check for existing attributes */
1123 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1125 /* Update existing attribute */
1126 attrib->value = new_attrib->value;
1127 return VA_STATUS_SUCCESS;
1129 return i965_append_config_attribute(obj_config, new_attrib);
1133 i965_CreateConfig(VADriverContextP ctx,
1135 VAEntrypoint entrypoint,
1136 VAConfigAttrib *attrib_list,
1138 VAConfigID *config_id) /* out */
1140 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1141 struct object_config *obj_config;
1146 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1148 if (VA_STATUS_SUCCESS != vaStatus) {
1152 configID = NEW_CONFIG_ID();
1153 obj_config = CONFIG(configID);
1155 if (NULL == obj_config) {
1156 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1160 obj_config->profile = profile;
1161 obj_config->entrypoint = entrypoint;
1162 obj_config->num_attribs = 0;
1163 obj_config->wrapper_config = VA_INVALID_ID;
1165 for (i = 0; i < num_attribs; i++) {
1166 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1167 if (vaStatus != VA_STATUS_SUCCESS)
1171 if (vaStatus == VA_STATUS_SUCCESS) {
1172 VAConfigAttrib attrib, *attrib_found;
1173 attrib.type = VAConfigAttribRTFormat;
1174 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1175 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1176 if (!attrib_found || !attrib_found->value)
1177 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1178 else if (!(attrib_found->value & attrib.value))
1179 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1182 if ((vaStatus == VA_STATUS_SUCCESS) &&
1183 (profile == VAProfileVP9Profile0) &&
1184 (entrypoint == VAEntrypointVLD) &&
1185 !HAS_VP9_DECODING(i965)) {
1187 if (i965->wrapper_pdrvctx) {
1188 VAGenericID wrapper_config;
1190 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1191 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1192 entrypoint, attrib_list,
1193 num_attribs, &wrapper_config));
1195 if (vaStatus == VA_STATUS_SUCCESS)
1196 obj_config->wrapper_config = wrapper_config;
1200 /* Error recovery */
1201 if (VA_STATUS_SUCCESS != vaStatus) {
1202 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1204 *config_id = configID;
1211 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1213 struct i965_driver_data *i965 = i965_driver_data(ctx);
1214 struct object_config *obj_config = CONFIG(config_id);
1217 if (NULL == obj_config) {
1218 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1222 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1223 i965->wrapper_pdrvctx) {
1224 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1225 vaDestroyConfig(i965->wrapper_pdrvctx,
1226 obj_config->wrapper_config));
1227 obj_config->wrapper_config = VA_INVALID_ID;
1230 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1231 return VA_STATUS_SUCCESS;
1234 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1235 VAConfigID config_id,
1236 VAProfile *profile, /* out */
1237 VAEntrypoint *entrypoint, /* out */
1238 VAConfigAttrib *attrib_list, /* out */
1239 int *num_attribs) /* out */
1241 struct i965_driver_data *i965 = i965_driver_data(ctx);
1242 struct object_config *obj_config = CONFIG(config_id);
1243 VAStatus vaStatus = VA_STATUS_SUCCESS;
1246 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1247 *profile = obj_config->profile;
1248 *entrypoint = obj_config->entrypoint;
1249 *num_attribs = obj_config->num_attribs;
1251 for(i = 0; i < obj_config->num_attribs; i++) {
1252 attrib_list[i] = obj_config->attrib_list[i];
1259 i965_destroy_surface_storage(struct object_surface *obj_surface)
1264 dri_bo_unreference(obj_surface->bo);
1265 obj_surface->bo = NULL;
1267 if (obj_surface->free_private_data != NULL) {
1268 obj_surface->free_private_data(&obj_surface->private_data);
1269 obj_surface->private_data = NULL;
1274 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1276 struct object_surface *obj_surface = (struct object_surface *)obj;
1278 i965_destroy_surface_storage(obj_surface);
1279 object_heap_free(heap, obj);
1283 i965_surface_native_memory(VADriverContextP ctx,
1284 struct object_surface *obj_surface,
1286 int expected_fourcc)
1288 struct i965_driver_data *i965 = i965_driver_data(ctx);
1289 int tiling = HAS_TILED_SURFACE(i965);
1291 if (!expected_fourcc)
1292 return VA_STATUS_SUCCESS;
1294 // todo, should we disable tiling for 422 format?
1295 if (expected_fourcc == VA_FOURCC_I420 ||
1296 expected_fourcc == VA_FOURCC_IYUV ||
1297 expected_fourcc == VA_FOURCC_YV12 ||
1298 expected_fourcc == VA_FOURCC_YV16)
1301 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1305 i965_suface_external_memory(VADriverContextP ctx,
1306 struct object_surface *obj_surface,
1307 int external_memory_type,
1308 VASurfaceAttribExternalBuffers *memory_attibute,
1311 struct i965_driver_data *i965 = i965_driver_data(ctx);
1313 if (!memory_attibute ||
1314 !memory_attibute->buffers ||
1315 index > memory_attibute->num_buffers)
1316 return VA_STATUS_ERROR_INVALID_PARAMETER;
1318 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1319 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1320 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1322 obj_surface->fourcc = memory_attibute->pixel_format;
1323 obj_surface->width = memory_attibute->pitches[0];
1324 obj_surface->size = memory_attibute->data_size;
1326 if (memory_attibute->num_planes == 1)
1327 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1329 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1331 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1332 obj_surface->x_cr_offset = 0;
1334 switch (obj_surface->fourcc) {
1335 case VA_FOURCC_NV12:
1336 case VA_FOURCC_P010:
1337 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1338 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1340 obj_surface->subsampling = SUBSAMPLE_YUV420;
1341 obj_surface->y_cb_offset = obj_surface->height;
1342 obj_surface->y_cr_offset = obj_surface->height;
1343 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1344 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1345 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1349 case VA_FOURCC_YV12:
1350 case VA_FOURCC_IMC1:
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_YUV420;
1355 obj_surface->y_cr_offset = obj_surface->height;
1356 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1357 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1358 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1359 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1363 case VA_FOURCC_I420:
1364 case VA_FOURCC_IYUV:
1365 case VA_FOURCC_IMC3:
1366 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1367 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1369 obj_surface->subsampling = SUBSAMPLE_YUV420;
1370 obj_surface->y_cb_offset = obj_surface->height;
1371 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1372 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1373 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1374 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1378 case VA_FOURCC_YUY2:
1379 case VA_FOURCC_UYVY:
1380 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1382 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1383 obj_surface->y_cb_offset = 0;
1384 obj_surface->y_cr_offset = 0;
1385 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1386 obj_surface->cb_cr_height = obj_surface->orig_height;
1387 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1391 case VA_FOURCC_RGBA:
1392 case VA_FOURCC_RGBX:
1393 case VA_FOURCC_BGRA:
1394 case VA_FOURCC_BGRX:
1395 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1397 obj_surface->subsampling = SUBSAMPLE_RGBX;
1398 obj_surface->y_cb_offset = 0;
1399 obj_surface->y_cr_offset = 0;
1400 obj_surface->cb_cr_width = 0;
1401 obj_surface->cb_cr_height = 0;
1402 obj_surface->cb_cr_pitch = 0;
1406 case VA_FOURCC_Y800: /* monochrome surface */
1407 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1409 obj_surface->subsampling = SUBSAMPLE_YUV400;
1410 obj_surface->y_cb_offset = 0;
1411 obj_surface->y_cr_offset = 0;
1412 obj_surface->cb_cr_width = 0;
1413 obj_surface->cb_cr_height = 0;
1414 obj_surface->cb_cr_pitch = 0;
1418 case VA_FOURCC_411P:
1419 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1420 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1422 obj_surface->subsampling = SUBSAMPLE_YUV411;
1423 obj_surface->y_cb_offset = 0;
1424 obj_surface->y_cr_offset = 0;
1425 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1426 obj_surface->cb_cr_height = obj_surface->orig_height;
1427 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1431 case VA_FOURCC_422H:
1432 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1433 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1435 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1436 obj_surface->y_cb_offset = obj_surface->height;
1437 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1438 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1439 obj_surface->cb_cr_height = obj_surface->orig_height;
1440 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1444 case VA_FOURCC_YV16:
1445 assert(memory_attibute->num_planes == 3);
1446 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1448 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1449 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1450 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1451 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1452 obj_surface->cb_cr_height = obj_surface->orig_height;
1453 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1457 case VA_FOURCC_422V:
1458 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1459 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1461 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1462 obj_surface->y_cb_offset = obj_surface->height;
1463 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1464 obj_surface->cb_cr_width = obj_surface->orig_width;
1465 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1466 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1470 case VA_FOURCC_444P:
1471 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1472 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1474 obj_surface->subsampling = SUBSAMPLE_YUV444;
1475 obj_surface->y_cb_offset = obj_surface->height;
1476 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1477 obj_surface->cb_cr_width = obj_surface->orig_width;
1478 obj_surface->cb_cr_height = obj_surface->orig_height;
1479 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1485 return VA_STATUS_ERROR_INVALID_PARAMETER;
1488 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1489 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1490 "gem flinked vaapi surface",
1491 memory_attibute->buffers[index]);
1492 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1493 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1494 memory_attibute->buffers[index],
1497 if (!obj_surface->bo)
1498 return VA_STATUS_ERROR_INVALID_PARAMETER;
1500 return VA_STATUS_SUCCESS;
1503 /* byte-per-pixel of the first plane */
1505 bpp_1stplane_by_fourcc(unsigned int fourcc)
1507 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1509 if (info && (info->flag & I_S))
1510 return info->bpp[0] / 8;
1516 i965_CreateSurfaces2(
1517 VADriverContextP ctx,
1518 unsigned int format,
1520 unsigned int height,
1521 VASurfaceID *surfaces,
1522 unsigned int num_surfaces,
1523 VASurfaceAttrib *attrib_list,
1524 unsigned int num_attribs
1527 struct i965_driver_data *i965 = i965_driver_data(ctx);
1529 VAStatus vaStatus = VA_STATUS_SUCCESS;
1530 int expected_fourcc = 0;
1531 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1532 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1534 for (i = 0; i < num_attribs && attrib_list; i++) {
1535 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1536 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1537 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1538 expected_fourcc = attrib_list[i].value.value.i;
1541 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1542 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1544 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1546 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1547 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1548 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1549 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1550 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1551 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1554 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1555 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1556 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1557 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1561 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1562 * for post-processing (including color conversion) */
1563 if (VA_RT_FORMAT_YUV420 != format &&
1564 VA_RT_FORMAT_YUV420_10BPP != format &&
1565 VA_RT_FORMAT_YUV422 != format &&
1566 VA_RT_FORMAT_YUV444 != format &&
1567 VA_RT_FORMAT_YUV411 != format &&
1568 VA_RT_FORMAT_YUV400 != format &&
1569 VA_RT_FORMAT_RGB32 != format) {
1570 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1573 for (i = 0; i < num_surfaces; i++) {
1574 int surfaceID = NEW_SURFACE_ID();
1575 struct object_surface *obj_surface = SURFACE(surfaceID);
1577 if (NULL == obj_surface) {
1578 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1582 surfaces[i] = surfaceID;
1583 obj_surface->status = VASurfaceReady;
1584 obj_surface->orig_width = width;
1585 obj_surface->orig_height = height;
1586 obj_surface->user_disable_tiling = false;
1587 obj_surface->user_h_stride_set = false;
1588 obj_surface->user_v_stride_set = false;
1589 obj_surface->border_cleared = false;
1591 obj_surface->subpic_render_idx = 0;
1592 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1593 obj_surface->subpic[j] = VA_INVALID_ID;
1594 obj_surface->obj_subpic[j] = NULL;
1597 assert(i965->codec_info->min_linear_wpitch);
1598 assert(i965->codec_info->min_linear_hpitch);
1599 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1600 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1601 obj_surface->flags = SURFACE_REFERENCED;
1602 obj_surface->fourcc = 0;
1603 obj_surface->expected_format = format;
1604 obj_surface->bo = NULL;
1605 obj_surface->locked_image_id = VA_INVALID_ID;
1606 obj_surface->derived_image_id = VA_INVALID_ID;
1607 obj_surface->private_data = NULL;
1608 obj_surface->free_private_data = NULL;
1609 obj_surface->subsampling = SUBSAMPLE_YUV420;
1611 obj_surface->wrapper_surface = VA_INVALID_ID;
1612 obj_surface->exported_primefd = -1;
1614 switch (memory_type) {
1615 case I965_SURFACE_MEM_NATIVE:
1616 if (memory_attibute) {
1617 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1618 obj_surface->user_disable_tiling = true;
1620 if (memory_attibute->pixel_format) {
1621 if (expected_fourcc)
1622 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1624 expected_fourcc = memory_attibute->pixel_format;
1626 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1627 if (memory_attibute->pitches[0]) {
1628 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1629 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1630 obj_surface->width = memory_attibute->pitches[0];
1631 obj_surface->user_h_stride_set = true;
1632 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1633 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1635 if (memory_attibute->offsets[1]) {
1636 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1637 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1638 obj_surface->user_v_stride_set = true;
1639 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1640 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1644 vaStatus = i965_surface_native_memory(ctx,
1650 case I965_SURFACE_MEM_GEM_FLINK:
1651 case I965_SURFACE_MEM_DRM_PRIME:
1652 vaStatus = i965_suface_external_memory(ctx,
1659 if (VA_STATUS_SUCCESS != vaStatus) {
1660 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1665 /* Error recovery */
1666 if (VA_STATUS_SUCCESS != vaStatus) {
1667 /* surfaces[i-1] was the last successful allocation */
1669 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1671 surfaces[i] = VA_INVALID_SURFACE;
1672 assert(obj_surface);
1673 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1681 i965_CreateSurfaces(VADriverContextP ctx,
1686 VASurfaceID *surfaces) /* out */
1688 return i965_CreateSurfaces2(ctx,
1699 i965_DestroySurfaces(VADriverContextP ctx,
1700 VASurfaceID *surface_list,
1703 struct i965_driver_data *i965 = i965_driver_data(ctx);
1705 VAStatus va_status = VA_STATUS_SUCCESS;
1707 for (i = num_surfaces; i--; ) {
1708 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1710 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1712 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1713 i965->wrapper_pdrvctx) {
1714 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1715 vaDestroySurfaces(i965->wrapper_pdrvctx,
1716 &(obj_surface->wrapper_surface),
1718 obj_surface->wrapper_surface = VA_INVALID_ID;
1720 if (obj_surface->exported_primefd >= 0) {
1721 close(obj_surface->exported_primefd);
1722 obj_surface->exported_primefd = -1;
1725 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1732 i965_QueryImageFormats(VADriverContextP ctx,
1733 VAImageFormat *format_list, /* out */
1734 int *num_formats) /* out */
1738 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1739 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1741 format_list[n] = m->va_format;
1747 return VA_STATUS_SUCCESS;
1751 * Guess the format when the usage of a VA surface is unknown
1752 * 1. Without a valid context: YV12
1753 * 2. The current context is valid:
1754 * a) always NV12 on GEN6 and later
1755 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1758 i965_guess_surface_format(VADriverContextP ctx,
1759 VASurfaceID surface,
1760 unsigned int *fourcc,
1761 unsigned int *is_tiled)
1763 struct i965_driver_data *i965 = i965_driver_data(ctx);
1764 struct object_context *obj_context = NULL;
1765 struct object_config *obj_config = NULL;
1767 *fourcc = VA_FOURCC_YV12;
1770 if (i965->current_context_id == VA_INVALID_ID)
1773 obj_context = CONTEXT(i965->current_context_id);
1778 obj_config = obj_context->obj_config;
1784 if (IS_GEN6(i965->intel.device_info) ||
1785 IS_GEN7(i965->intel.device_info) ||
1786 IS_GEN8(i965->intel.device_info) ||
1787 IS_GEN9(i965->intel.device_info)) {
1788 *fourcc = VA_FOURCC_NV12;
1793 switch (obj_config->profile) {
1794 case VAProfileMPEG2Simple:
1795 case VAProfileMPEG2Main:
1796 *fourcc = VA_FOURCC_I420;
1801 *fourcc = VA_FOURCC_NV12;
1808 i965_QuerySubpictureFormats(VADriverContextP ctx,
1809 VAImageFormat *format_list, /* out */
1810 unsigned int *flags, /* out */
1811 unsigned int *num_formats) /* out */
1815 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1816 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1818 format_list[n] = m->va_format;
1820 flags[n] = m->va_flags;
1826 return VA_STATUS_SUCCESS;
1830 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1832 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1834 object_heap_free(heap, obj);
1838 i965_CreateSubpicture(VADriverContextP ctx,
1840 VASubpictureID *subpicture) /* out */
1842 struct i965_driver_data *i965 = i965_driver_data(ctx);
1843 VASubpictureID subpicID = NEW_SUBPIC_ID()
1844 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1847 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1849 struct object_image *obj_image = IMAGE(image);
1851 return VA_STATUS_ERROR_INVALID_IMAGE;
1853 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1855 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1857 *subpicture = subpicID;
1858 obj_subpic->image = image;
1859 obj_subpic->obj_image = obj_image;
1860 obj_subpic->format = m->format;
1861 obj_subpic->width = obj_image->image.width;
1862 obj_subpic->height = obj_image->image.height;
1863 obj_subpic->pitch = obj_image->image.pitches[0];
1864 obj_subpic->bo = obj_image->bo;
1865 obj_subpic->global_alpha = 1.0;
1867 return VA_STATUS_SUCCESS;
1871 i965_DestroySubpicture(VADriverContextP ctx,
1872 VASubpictureID subpicture)
1874 struct i965_driver_data *i965 = i965_driver_data(ctx);
1875 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1878 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1880 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1881 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1882 return VA_STATUS_SUCCESS;
1886 i965_SetSubpictureImage(VADriverContextP ctx,
1887 VASubpictureID subpicture,
1891 return VA_STATUS_ERROR_UNIMPLEMENTED;
1895 i965_SetSubpictureChromakey(VADriverContextP ctx,
1896 VASubpictureID subpicture,
1897 unsigned int chromakey_min,
1898 unsigned int chromakey_max,
1899 unsigned int chromakey_mask)
1902 return VA_STATUS_ERROR_UNIMPLEMENTED;
1906 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1907 VASubpictureID subpicture,
1910 struct i965_driver_data *i965 = i965_driver_data(ctx);
1911 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1913 if(global_alpha > 1.0 || global_alpha < 0.0){
1914 return VA_STATUS_ERROR_INVALID_PARAMETER;
1918 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1920 obj_subpic->global_alpha = global_alpha;
1922 return VA_STATUS_SUCCESS;
1926 i965_AssociateSubpicture(VADriverContextP ctx,
1927 VASubpictureID subpicture,
1928 VASurfaceID *target_surfaces,
1930 short src_x, /* upper left offset in subpicture */
1932 unsigned short src_width,
1933 unsigned short src_height,
1934 short dest_x, /* upper left offset in surface */
1936 unsigned short dest_width,
1937 unsigned short dest_height,
1939 * whether to enable chroma-keying or global-alpha
1940 * see VA_SUBPICTURE_XXX values
1944 struct i965_driver_data *i965 = i965_driver_data(ctx);
1945 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1949 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1951 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1953 obj_subpic->src_rect.x = src_x;
1954 obj_subpic->src_rect.y = src_y;
1955 obj_subpic->src_rect.width = src_width;
1956 obj_subpic->src_rect.height = src_height;
1957 obj_subpic->dst_rect.x = dest_x;
1958 obj_subpic->dst_rect.y = dest_y;
1959 obj_subpic->dst_rect.width = dest_width;
1960 obj_subpic->dst_rect.height = dest_height;
1961 obj_subpic->flags = flags;
1963 for (i = 0; i < num_surfaces; i++) {
1964 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1966 return VA_STATUS_ERROR_INVALID_SURFACE;
1968 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1969 if(obj_surface->subpic[j] == VA_INVALID_ID){
1970 assert(obj_surface->obj_subpic[j] == NULL);
1971 obj_surface->subpic[j] = subpicture;
1972 obj_surface->obj_subpic[j] = obj_subpic;
1977 if(j == I965_MAX_SUBPIC_SUM){
1978 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1982 return VA_STATUS_SUCCESS;
1987 i965_DeassociateSubpicture(VADriverContextP ctx,
1988 VASubpictureID subpicture,
1989 VASurfaceID *target_surfaces,
1992 struct i965_driver_data *i965 = i965_driver_data(ctx);
1993 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1997 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1999 for (i = 0; i < num_surfaces; i++) {
2000 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2002 return VA_STATUS_ERROR_INVALID_SURFACE;
2004 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
2005 if (obj_surface->subpic[j] == subpicture) {
2006 assert(obj_surface->obj_subpic[j] == obj_subpic);
2007 obj_surface->subpic[j] = VA_INVALID_ID;
2008 obj_surface->obj_subpic[j] = NULL;
2013 if(j == I965_MAX_SUBPIC_SUM){
2014 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2017 return VA_STATUS_SUCCESS;
2021 i965_reference_buffer_store(struct buffer_store **ptr,
2022 struct buffer_store *buffer_store)
2024 assert(*ptr == NULL);
2027 buffer_store->ref_count++;
2028 *ptr = buffer_store;
2033 i965_release_buffer_store(struct buffer_store **ptr)
2035 struct buffer_store *buffer_store = *ptr;
2037 if (buffer_store == NULL)
2040 assert(buffer_store->bo || buffer_store->buffer);
2041 assert(!(buffer_store->bo && buffer_store->buffer));
2042 buffer_store->ref_count--;
2044 if (buffer_store->ref_count == 0) {
2045 dri_bo_unreference(buffer_store->bo);
2046 free(buffer_store->buffer);
2047 buffer_store->bo = NULL;
2048 buffer_store->buffer = NULL;
2056 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2058 struct object_context *obj_context = (struct object_context *)obj;
2061 if (obj_context->hw_context) {
2062 obj_context->hw_context->destroy(obj_context->hw_context);
2063 obj_context->hw_context = NULL;
2066 if (obj_context->codec_type == CODEC_PROC) {
2067 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2069 } else if (obj_context->codec_type == CODEC_ENC) {
2070 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
2071 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2072 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
2074 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2075 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2077 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
2078 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2080 free(obj_context->codec_state.encode.slice_params);
2082 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2083 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2084 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2086 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2087 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2089 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2090 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2092 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2093 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
2095 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2096 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2098 free(obj_context->codec_state.encode.slice_params_ext);
2099 if (obj_context->codec_state.encode.slice_rawdata_index) {
2100 free(obj_context->codec_state.encode.slice_rawdata_index);
2101 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2103 if (obj_context->codec_state.encode.slice_rawdata_count) {
2104 free(obj_context->codec_state.encode.slice_rawdata_count);
2105 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2108 if (obj_context->codec_state.encode.slice_header_index) {
2109 free(obj_context->codec_state.encode.slice_header_index);
2110 obj_context->codec_state.encode.slice_header_index = NULL;
2113 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2114 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2115 free(obj_context->codec_state.encode.packed_header_params_ext);
2117 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2118 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2119 free(obj_context->codec_state.encode.packed_header_data_ext);
2121 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2123 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2124 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2126 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2127 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2128 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2130 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2131 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2133 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2134 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2136 free(obj_context->codec_state.decode.slice_params);
2137 free(obj_context->codec_state.decode.slice_datas);
2140 free(obj_context->render_targets);
2141 object_heap_free(heap, obj);
2145 max_resolution(struct i965_driver_data *i965,
2146 struct object_config *obj_config,
2150 if (i965->codec_info->max_resolution) {
2151 i965->codec_info->max_resolution(i965, obj_config, w, h);
2153 *w = i965->codec_info->max_width;
2154 *h = i965->codec_info->max_height;
2159 i965_CreateContext(VADriverContextP ctx,
2160 VAConfigID config_id,
2164 VASurfaceID *render_targets,
2165 int num_render_targets,
2166 VAContextID *context) /* out */
2168 struct i965_driver_data *i965 = i965_driver_data(ctx);
2169 struct object_config *obj_config = CONFIG(config_id);
2170 struct object_context *obj_context = NULL;
2171 VAConfigAttrib *attrib;
2172 VAStatus vaStatus = VA_STATUS_SUCCESS;
2178 if (NULL == obj_config) {
2179 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2183 max_resolution(i965, obj_config, &max_width, &max_height);
2185 if (picture_width > max_width ||
2186 picture_height > max_height) {
2187 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2192 /* Validate picture dimensions */
2193 contextID = NEW_CONTEXT_ID();
2194 obj_context = CONTEXT(contextID);
2196 if (NULL == obj_context) {
2197 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2201 *context = contextID;
2202 obj_context->flags = flag;
2203 obj_context->context_id = contextID;
2204 obj_context->obj_config = obj_config;
2205 obj_context->picture_width = picture_width;
2206 obj_context->picture_height = picture_height;
2207 obj_context->num_render_targets = num_render_targets;
2208 obj_context->render_targets =
2209 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2210 obj_context->hw_context = NULL;
2211 obj_context->wrapper_context = VA_INVALID_ID;
2213 if (!obj_context->render_targets)
2214 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2216 for(i = 0; i < num_render_targets; i++) {
2217 if (NULL == SURFACE(render_targets[i])) {
2218 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2222 obj_context->render_targets[i] = render_targets[i];
2225 if (VA_STATUS_SUCCESS == vaStatus) {
2226 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2227 obj_context->codec_type = CODEC_PROC;
2228 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2229 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2230 assert(i965->codec_info->proc_hw_context_init);
2231 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2232 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2233 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2234 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2235 VAConfigAttrib *packed_attrib;
2236 obj_context->codec_type = CODEC_ENC;
2237 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2238 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2239 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
2240 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
2241 sizeof(*obj_context->codec_state.encode.slice_params));
2242 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2243 obj_context->codec_state.encode.packed_header_params_ext =
2244 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2245 sizeof(struct buffer_store *));
2247 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2248 obj_context->codec_state.encode.packed_header_data_ext =
2249 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2250 sizeof(struct buffer_store *));
2252 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2253 obj_context->codec_state.encode.slice_rawdata_index =
2254 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2255 obj_context->codec_state.encode.slice_rawdata_count =
2256 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2258 obj_context->codec_state.encode.slice_header_index =
2259 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2261 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2263 obj_context->codec_state.encode.slice_index = 0;
2264 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2265 if (packed_attrib) {
2266 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2267 if (obj_config->profile == VAProfileVP9Profile0)
2268 obj_context->codec_state.encode.packed_header_flag =
2269 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2271 /* use the default value. SPS/PPS/RAWDATA is passed from user
2272 * while Slice_header data is generated by driver.
2274 obj_context->codec_state.encode.packed_header_flag =
2275 VA_ENC_PACKED_HEADER_SEQUENCE |
2276 VA_ENC_PACKED_HEADER_PICTURE |
2277 VA_ENC_PACKED_HEADER_RAW_DATA;
2279 /* it is not used for VP9 */
2280 if (obj_config->profile == VAProfileVP9Profile0)
2281 obj_context->codec_state.encode.packed_header_flag = 0;
2283 assert(i965->codec_info->enc_hw_context_init);
2284 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2286 obj_context->codec_type = CODEC_DEC;
2287 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2288 obj_context->codec_state.decode.current_render_target = -1;
2289 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2290 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2291 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2292 sizeof(*obj_context->codec_state.decode.slice_params));
2293 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2294 sizeof(*obj_context->codec_state.decode.slice_datas));
2296 assert(i965->codec_info->dec_hw_context_init);
2297 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2301 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2303 return VA_STATUS_ERROR_INVALID_CONFIG;
2304 obj_context->codec_state.base.chroma_formats = attrib->value;
2306 if (obj_config->wrapper_config != VA_INVALID_ID) {
2307 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2308 * So it won't check i965->wrapper_pdrvctx again.
2309 * Fixme if it is incorrect.
2311 VAGenericID wrapper_context;
2314 * The render_surface is not passed when calling
2316 * If it is needed, we must get the wrapped surface
2317 * for the corresponding Surface_list.
2318 * So the wrapped surface conversion is deferred.
2320 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2321 vaCreateContext(i965->wrapper_pdrvctx,
2322 obj_config->wrapper_config,
2323 picture_width, picture_height,
2327 if (vaStatus == VA_STATUS_SUCCESS)
2328 obj_context->wrapper_context = wrapper_context;
2330 /* Error recovery */
2331 if (VA_STATUS_SUCCESS != vaStatus) {
2332 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2335 i965->current_context_id = contextID;
2341 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2343 struct i965_driver_data *i965 = i965_driver_data(ctx);
2344 struct object_context *obj_context = CONTEXT(context);
2345 VAStatus va_status = VA_STATUS_SUCCESS;
2347 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2349 if (i965->current_context_id == context)
2350 i965->current_context_id = VA_INVALID_ID;
2352 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2353 i965->wrapper_pdrvctx) {
2354 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2355 vaDestroyContext(i965->wrapper_pdrvctx,
2356 obj_context->wrapper_context));
2358 obj_context->wrapper_context = VA_INVALID_ID;
2361 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2367 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2369 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2371 assert(obj_buffer->buffer_store);
2372 i965_release_buffer_store(&obj_buffer->buffer_store);
2373 object_heap_free(heap, obj);
2377 i965_create_buffer_internal(VADriverContextP ctx,
2378 VAContextID context,
2381 unsigned int num_elements,
2386 struct i965_driver_data *i965 = i965_driver_data(ctx);
2387 struct object_buffer *obj_buffer = NULL;
2388 struct buffer_store *buffer_store = NULL;
2390 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2391 struct object_context *obj_context = CONTEXT(context);
2392 int wrapper_flag = 0;
2396 case VAPictureParameterBufferType:
2397 case VAIQMatrixBufferType:
2398 case VAQMatrixBufferType:
2399 case VABitPlaneBufferType:
2400 case VASliceGroupMapBufferType:
2401 case VASliceParameterBufferType:
2402 case VASliceDataBufferType:
2403 case VAMacroblockParameterBufferType:
2404 case VAResidualDataBufferType:
2405 case VADeblockingParameterBufferType:
2406 case VAImageBufferType:
2407 case VAEncCodedBufferType:
2408 case VAEncSequenceParameterBufferType:
2409 case VAEncPictureParameterBufferType:
2410 case VAEncSliceParameterBufferType:
2411 case VAEncPackedHeaderParameterBufferType:
2412 case VAEncPackedHeaderDataBufferType:
2413 case VAEncMiscParameterBufferType:
2414 case VAProcPipelineParameterBufferType:
2415 case VAProcFilterParameterBufferType:
2416 case VAHuffmanTableBufferType:
2417 case VAProbabilityBufferType:
2418 case VAEncMacroblockMapBufferType:
2423 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2426 bufferID = NEW_BUFFER_ID();
2427 obj_buffer = BUFFER(bufferID);
2429 if (NULL == obj_buffer) {
2430 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2433 if (type == VAEncCodedBufferType) {
2434 size += I965_CODEDBUFFER_HEADER_SIZE;
2435 size += 0x1000; /* for upper bound check */
2438 obj_buffer->max_num_elements = num_elements;
2439 obj_buffer->num_elements = num_elements;
2440 obj_buffer->size_element = size;
2441 obj_buffer->type = type;
2442 obj_buffer->export_refcount = 0;
2443 obj_buffer->buffer_store = NULL;
2444 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2445 obj_buffer->context_id = context;
2447 buffer_store = calloc(1, sizeof(struct buffer_store));
2448 assert(buffer_store);
2449 buffer_store->ref_count = 1;
2452 (obj_context->wrapper_context != VA_INVALID_ID) &&
2453 i965->wrapper_pdrvctx) {
2454 VAGenericID wrapper_buffer;
2455 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2457 CALL_VTABLE(pdrvctx, vaStatus,
2458 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2459 data, &wrapper_buffer));
2460 if (vaStatus == VA_STATUS_SUCCESS) {
2461 obj_buffer->wrapper_buffer = wrapper_buffer;
2469 if (store_bo != NULL) {
2470 buffer_store->bo = store_bo;
2471 dri_bo_reference(buffer_store->bo);
2473 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2474 if (data && !wrapper_flag)
2475 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2476 } else if (type == VASliceDataBufferType ||
2477 type == VAImageBufferType ||
2478 type == VAEncCodedBufferType ||
2479 type == VAEncMacroblockMapBufferType ||
2480 type == VAProbabilityBufferType) {
2482 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2483 * So it is enough to allocate one 64 byte bo
2486 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2489 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2491 size * num_elements, 64);
2492 assert(buffer_store->bo);
2494 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2495 * In fact it can be skipped. But it is still allocated and it is
2496 * only to follow the normal flowchart of buffer_allocation/release.
2498 if (!wrapper_flag) {
2499 if (type == VAEncCodedBufferType) {
2500 struct i965_coded_buffer_segment *coded_buffer_segment;
2502 dri_bo_map(buffer_store->bo, 1);
2503 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2504 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2505 coded_buffer_segment->base.bit_offset = 0;
2506 coded_buffer_segment->base.status = 0;
2507 coded_buffer_segment->base.buf = NULL;
2508 coded_buffer_segment->base.next = NULL;
2509 coded_buffer_segment->mapped = 0;
2510 coded_buffer_segment->codec = 0;
2511 coded_buffer_segment->status_support = 0;
2512 dri_bo_unmap(buffer_store->bo);
2514 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2521 if (type == VAEncPackedHeaderDataBufferType) {
2522 msize = ALIGN(size, 4);
2525 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2527 buffer_store->buffer = malloc(4);
2529 buffer_store->buffer = malloc(msize * num_elements);
2530 assert(buffer_store->buffer);
2532 if (data && (!wrapper_flag))
2533 memcpy(buffer_store->buffer, data, size * num_elements);
2536 buffer_store->num_elements = obj_buffer->num_elements;
2537 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2538 i965_release_buffer_store(&buffer_store);
2541 return VA_STATUS_SUCCESS;
2545 i965_CreateBuffer(VADriverContextP ctx,
2546 VAContextID context, /* in */
2547 VABufferType type, /* in */
2548 unsigned int size, /* in */
2549 unsigned int num_elements, /* in */
2550 void *data, /* in */
2551 VABufferID *buf_id) /* out */
2553 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2558 i965_BufferSetNumElements(VADriverContextP ctx,
2559 VABufferID buf_id, /* in */
2560 unsigned int num_elements) /* in */
2562 struct i965_driver_data *i965 = i965_driver_data(ctx);
2563 struct object_buffer *obj_buffer = BUFFER(buf_id);
2564 VAStatus vaStatus = VA_STATUS_SUCCESS;
2566 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2568 /* When the wrapper_buffer exists, it will wrapper to the
2569 * buffer allocated from backend driver.
2571 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2572 i965->wrapper_pdrvctx) {
2573 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2575 CALL_VTABLE(pdrvctx, vaStatus,
2576 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2581 if ((num_elements < 0) ||
2582 (num_elements > obj_buffer->max_num_elements)) {
2583 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2585 obj_buffer->num_elements = num_elements;
2586 if (obj_buffer->buffer_store != NULL) {
2587 obj_buffer->buffer_store->num_elements = num_elements;
2595 i965_MapBuffer(VADriverContextP ctx,
2596 VABufferID buf_id, /* in */
2597 void **pbuf) /* out */
2599 struct i965_driver_data *i965 = i965_driver_data(ctx);
2600 struct object_buffer *obj_buffer = BUFFER(buf_id);
2601 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2602 struct object_context *obj_context;
2604 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2606 obj_context = CONTEXT(obj_buffer->context_id);
2608 /* When the wrapper_buffer exists, it will wrapper to the
2609 * buffer allocated from backend driver.
2611 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2612 i965->wrapper_pdrvctx) {
2613 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2615 CALL_VTABLE(pdrvctx, vaStatus,
2616 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2620 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2621 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2623 if (obj_buffer->export_refcount > 0)
2624 return VA_STATUS_ERROR_INVALID_BUFFER;
2626 if (NULL != obj_buffer->buffer_store->bo) {
2627 unsigned int tiling, swizzle;
2629 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2631 if (tiling != I915_TILING_NONE)
2632 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2634 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2636 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2637 *pbuf = obj_buffer->buffer_store->bo->virtual;
2638 vaStatus = VA_STATUS_SUCCESS;
2640 if (obj_buffer->type == VAEncCodedBufferType) {
2642 unsigned char *buffer = NULL;
2643 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2644 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2646 if (!coded_buffer_segment->mapped) {
2647 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2649 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2652 obj_context->hw_context &&
2653 obj_context->hw_context->get_status &&
2654 coded_buffer_segment->status_support) {
2655 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2658 if (coded_buffer_segment->codec == CODEC_VP9) {
2660 if (obj_context == NULL)
2661 return VA_STATUS_ERROR_ENCODING_ERROR;
2663 gen9_vp9_get_coded_status(ctx, (char *)coded_buffer_segment,
2664 obj_context->hw_context);
2666 else if (coded_buffer_segment->codec == CODEC_H264 ||
2667 coded_buffer_segment->codec == CODEC_H264_MVC) {
2668 delimiter0 = H264_DELIMITER0;
2669 delimiter1 = H264_DELIMITER1;
2670 delimiter2 = H264_DELIMITER2;
2671 delimiter3 = H264_DELIMITER3;
2672 delimiter4 = H264_DELIMITER4;
2673 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2674 delimiter0 = MPEG2_DELIMITER0;
2675 delimiter1 = MPEG2_DELIMITER1;
2676 delimiter2 = MPEG2_DELIMITER2;
2677 delimiter3 = MPEG2_DELIMITER3;
2678 delimiter4 = MPEG2_DELIMITER4;
2679 } else if(coded_buffer_segment->codec == CODEC_JPEG) {
2680 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2683 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2684 delimiter0 = HEVC_DELIMITER0;
2685 delimiter1 = HEVC_DELIMITER1;
2686 delimiter2 = HEVC_DELIMITER2;
2687 delimiter3 = HEVC_DELIMITER3;
2688 delimiter4 = HEVC_DELIMITER4;
2689 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2690 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2693 if(coded_buffer_segment->codec == CODEC_VP9) {
2694 /* it is already handled */
2696 if(coded_buffer_segment->codec == CODEC_JPEG) {
2697 for(i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2698 if( (buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2702 coded_buffer_segment->base.size = i + 2;
2703 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2704 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2705 so it don't need to traversal the coded buffer */
2706 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2707 if ((buffer[i] == delimiter0) &&
2708 (buffer[i + 1] == delimiter1) &&
2709 (buffer[i + 2] == delimiter2) &&
2710 (buffer[i + 3] == delimiter3) &&
2711 (buffer[i + 4] == delimiter4))
2715 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2716 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2718 coded_buffer_segment->base.size = i;
2721 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2722 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2725 vaStatus = VA_STATUS_SUCCESS;
2728 coded_buffer_segment->mapped = 1;
2730 assert(coded_buffer_segment->base.buf);
2731 vaStatus = VA_STATUS_SUCCESS;
2734 } else if (NULL != obj_buffer->buffer_store->buffer) {
2735 *pbuf = obj_buffer->buffer_store->buffer;
2736 vaStatus = VA_STATUS_SUCCESS;
2743 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2745 struct i965_driver_data *i965 = i965_driver_data(ctx);
2746 struct object_buffer *obj_buffer = BUFFER(buf_id);
2747 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2749 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2750 return VA_STATUS_ERROR_INVALID_BUFFER;
2752 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2753 /* When the wrapper_buffer exists, it will wrapper to the
2754 * buffer allocated from backend driver.
2756 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2757 i965->wrapper_pdrvctx) {
2758 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2760 CALL_VTABLE(pdrvctx, vaStatus,
2761 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2765 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2766 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2768 if (NULL != obj_buffer->buffer_store->bo) {
2769 unsigned int tiling, swizzle;
2771 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2773 if (tiling != I915_TILING_NONE)
2774 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2776 dri_bo_unmap(obj_buffer->buffer_store->bo);
2778 vaStatus = VA_STATUS_SUCCESS;
2779 } else if (NULL != obj_buffer->buffer_store->buffer) {
2781 vaStatus = VA_STATUS_SUCCESS;
2788 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2790 struct i965_driver_data *i965 = i965_driver_data(ctx);
2791 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2792 VAStatus va_status = VA_STATUS_SUCCESS;
2794 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2796 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2797 i965->wrapper_pdrvctx) {
2798 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2799 vaDestroyBuffer(i965->wrapper_pdrvctx,
2800 obj_buffer->wrapper_buffer));
2801 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2804 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2810 i965_BeginPicture(VADriverContextP ctx,
2811 VAContextID context,
2812 VASurfaceID render_target)
2814 struct i965_driver_data *i965 = i965_driver_data(ctx);
2815 struct object_context *obj_context = CONTEXT(context);
2816 struct object_surface *obj_surface = SURFACE(render_target);
2817 struct object_config *obj_config;
2818 VAStatus vaStatus = VA_STATUS_SUCCESS;
2821 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2822 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2823 obj_config = obj_context->obj_config;
2824 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2826 if (is_surface_busy(i965, obj_surface))
2827 return VA_STATUS_ERROR_SURFACE_BUSY;
2829 if (obj_context->codec_type == CODEC_PROC) {
2830 obj_context->codec_state.proc.current_render_target = render_target;
2831 } else if (obj_context->codec_type == CODEC_ENC) {
2832 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2834 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
2835 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2838 obj_context->codec_state.encode.num_slice_params = 0;
2841 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2843 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2844 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2846 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2847 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2849 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2850 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2852 obj_context->codec_state.encode.num_slice_params_ext = 0;
2853 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2854 obj_context->codec_state.encode.last_packed_header_type = 0;
2855 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2856 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2857 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2858 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2859 memset(obj_context->codec_state.encode.slice_header_index, 0,
2860 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2862 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2863 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2864 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2865 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2866 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2867 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2868 obj_context->codec_state.encode.slice_index = 0;
2869 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2871 * Based on ROI definition in va/va.h, the ROI set through this
2872 * structure is applicable only to the current frame or field.
2873 * That is to say: it is on-the-fly setting. If it is not set,
2874 * the current frame doesn't use ROI.
2875 * It is uncertain whether the other misc buffer should be released.
2876 * So only release the previous ROI buffer.
2878 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[VAEncMiscParameterTypeROI]);
2880 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2882 if (obj_config->profile == VAProfileVP9Profile0) {
2883 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2884 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
2886 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2889 obj_context->codec_state.decode.current_render_target = render_target;
2890 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2891 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2892 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2893 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2895 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2896 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2897 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2900 obj_context->codec_state.decode.num_slice_params = 0;
2901 obj_context->codec_state.decode.num_slice_datas = 0;
2903 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2904 i965->wrapper_pdrvctx) {
2905 if (obj_surface->wrapper_surface == VA_INVALID_ID)
2906 vaStatus = i965_surface_wrapper(ctx, render_target);
2908 if (vaStatus != VA_STATUS_SUCCESS)
2911 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2912 vaBeginPicture(i965->wrapper_pdrvctx,
2913 obj_context->wrapper_context,
2914 obj_surface->wrapper_surface));
2921 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2923 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2925 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2926 struct object_context *obj_context, \
2927 struct object_buffer *obj_buffer) \
2929 struct category##_state *category = &obj_context->codec_state.category; \
2930 i965_release_buffer_store(&category->member); \
2931 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2932 return VA_STATUS_SUCCESS; \
2935 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2937 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2938 struct object_context *obj_context, \
2939 struct object_buffer *obj_buffer) \
2941 struct category##_state *category = &obj_context->codec_state.category; \
2942 if (category->num_##member == category->max_##member) { \
2943 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2944 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2945 category->max_##member += NUM_SLICES; \
2947 i965_release_buffer_store(&category->member[category->num_##member]); \
2948 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2949 category->num_##member++; \
2950 return VA_STATUS_SUCCESS; \
2953 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2955 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2956 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2957 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2958 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2959 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2960 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2962 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2963 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2964 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2968 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
2969 VABufferID *buffers,
2972 struct i965_driver_data *i965 = i965_driver_data(ctx);
2973 VAStatus vaStatus = VA_STATUS_SUCCESS;
2975 VADecPictureParameterBufferVP9 *pVp9PicParams;
2976 VADriverContextP pdrvctx;
2977 struct object_buffer *obj_buffer;
2979 pdrvctx = i965->wrapper_pdrvctx;
2980 /* do the conversion of VADecPictureParameterBufferVP9 */
2981 for (i = 0; i < num_buffers; i++) {
2982 obj_buffer = BUFFER(buffers[i]);
2987 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
2990 if (obj_buffer->type == VAPictureParameterBufferType) {
2992 VASurfaceID surface_id;
2993 struct object_surface *obj_surface;
2995 pdrvctx = i965->wrapper_pdrvctx;
2997 CALL_VTABLE(pdrvctx, vaStatus,
2998 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
2999 (void **)(&pVp9PicParams)));
3001 if (vaStatus != VA_STATUS_SUCCESS)
3004 for (j = 0; j < 8; j++) {
3005 surface_id = pVp9PicParams->reference_frames[j];
3006 obj_surface = SURFACE(surface_id);
3011 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
3012 vaStatus = i965_surface_wrapper(ctx, surface_id);
3013 if (vaStatus != VA_STATUS_SUCCESS) {
3014 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
3015 obj_buffer->wrapper_buffer);
3020 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
3022 CALL_VTABLE(pdrvctx, vaStatus,
3023 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3028 return VA_STATUS_SUCCESS;
3035 i965_decoder_wrapper_picture(VADriverContextP ctx,
3036 VAContextID context,
3037 VABufferID *buffers,
3040 struct i965_driver_data *i965 = i965_driver_data(ctx);
3041 struct object_context *obj_context = CONTEXT(context);
3042 VAStatus vaStatus = VA_STATUS_SUCCESS;
3044 VADriverContextP pdrvctx;
3045 struct object_buffer *obj_buffer;
3047 if (obj_context == NULL)
3048 return VA_STATUS_ERROR_INVALID_CONTEXT;
3050 /* When it is not wrapped context, continue the normal flowchart */
3051 if (obj_context->wrapper_context == VA_INVALID_ID)
3054 if (obj_context->obj_config &&
3055 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3056 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3058 return VA_STATUS_ERROR_INVALID_PARAMETER;
3060 pdrvctx = i965->wrapper_pdrvctx;
3062 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3063 obj_buffer = BUFFER(buffers[i]);
3068 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3069 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3073 CALL_VTABLE(pdrvctx, vaStatus,
3074 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3075 &(obj_buffer->wrapper_buffer), 1));
3081 i965_decoder_render_picture(VADriverContextP ctx,
3082 VAContextID context,
3083 VABufferID *buffers,
3086 struct i965_driver_data *i965 = i965_driver_data(ctx);
3087 struct object_context *obj_context = CONTEXT(context);
3088 VAStatus vaStatus = VA_STATUS_SUCCESS;
3091 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3093 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3094 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3097 return VA_STATUS_ERROR_INVALID_BUFFER;
3099 switch (obj_buffer->type) {
3100 case VAPictureParameterBufferType:
3101 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3104 case VAIQMatrixBufferType:
3105 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3108 case VABitPlaneBufferType:
3109 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3112 case VASliceParameterBufferType:
3113 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3116 case VASliceDataBufferType:
3117 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3120 case VAHuffmanTableBufferType:
3121 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3124 case VAProbabilityBufferType:
3125 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3129 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3134 if ((vaStatus == VA_STATUS_SUCCESS) &&
3135 (obj_context->wrapper_context != VA_INVALID_ID))
3136 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3141 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3143 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3144 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3145 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3146 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3147 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3148 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3149 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3150 /* extended buffer */
3151 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3152 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3153 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3155 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3156 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3157 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3159 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3160 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3163 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3164 struct object_context *obj_context,
3165 struct object_buffer *obj_buffer,
3168 struct encode_state *encode = &obj_context->codec_state.encode;
3170 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3171 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3172 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3173 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3175 return VA_STATUS_SUCCESS;
3179 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3180 struct object_context *obj_context,
3181 struct object_buffer *obj_buffer,
3184 struct encode_state *encode = &obj_context->codec_state.encode;
3186 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3187 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3188 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3189 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3191 return VA_STATUS_SUCCESS;
3195 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3196 struct object_context *obj_context,
3197 struct object_buffer *obj_buffer)
3199 struct encode_state *encode = &obj_context->codec_state.encode;
3200 VAEncMiscParameterBuffer *param = NULL;
3202 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3203 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3205 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3207 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3208 return VA_STATUS_ERROR_INVALID_PARAMETER;
3210 i965_release_buffer_store(&encode->misc_param[param->type]);
3211 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
3213 return VA_STATUS_SUCCESS;
3217 i965_encoder_render_picture(VADriverContextP ctx,
3218 VAContextID context,
3219 VABufferID *buffers,
3222 struct i965_driver_data *i965 = i965_driver_data(ctx);
3223 struct object_context *obj_context = CONTEXT(context);
3224 struct object_config *obj_config;
3225 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3226 struct encode_state *encode;
3229 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3230 obj_config = obj_context->obj_config;
3231 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3233 encode = &obj_context->codec_state.encode;
3234 for (i = 0; i < num_buffers; i++) {
3235 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3238 return VA_STATUS_ERROR_INVALID_BUFFER;
3240 switch (obj_buffer->type) {
3241 case VAQMatrixBufferType:
3242 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3245 case VAIQMatrixBufferType:
3246 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3249 case VAEncSequenceParameterBufferType:
3250 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3253 case VAEncPictureParameterBufferType:
3254 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3257 case VAHuffmanTableBufferType:
3258 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3261 case VAEncSliceParameterBufferType:
3262 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3263 if (vaStatus == VA_STATUS_SUCCESS) {
3264 /* When the max number of slices is updated, it also needs
3265 * to reallocate the arrays that is used to store
3266 * the packed data index/count for the slice
3268 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3269 encode->slice_index++;
3271 if (encode->slice_index == encode->max_slice_num) {
3272 int slice_num = encode->max_slice_num;
3273 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3274 (slice_num + NUM_SLICES) * sizeof(int));
3275 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3276 (slice_num + NUM_SLICES) * sizeof(int));
3277 encode->slice_header_index = realloc(encode->slice_header_index,
3278 (slice_num + NUM_SLICES) * sizeof(int));
3279 memset(encode->slice_rawdata_index + slice_num, 0,
3280 sizeof(int) * NUM_SLICES);
3281 memset(encode->slice_rawdata_count + slice_num, 0,
3282 sizeof(int) * NUM_SLICES);
3283 memset(encode->slice_header_index + slice_num, 0,
3284 sizeof(int) * NUM_SLICES);
3286 encode->max_slice_num += NUM_SLICES;
3287 if ((encode->slice_rawdata_index == NULL) ||
3288 (encode->slice_header_index == NULL) ||
3289 (encode->slice_rawdata_count == NULL)) {
3290 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3297 case VAEncPackedHeaderParameterBufferType:
3299 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3300 encode->last_packed_header_type = param->type;
3302 if ((param->type == VAEncPackedHeaderRawData) ||
3303 (param->type == VAEncPackedHeaderSlice)) {
3304 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3305 } else if((obj_config->profile == VAProfileHEVCMain) &&
3306 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3307 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3310 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3312 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3315 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3320 case VAEncPackedHeaderDataBufferType:
3322 if (encode->last_packed_header_type == 0) {
3323 WARN_ONCE("the packed header data is passed without type!\n");
3324 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3328 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3329 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3330 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3332 if (obj_config->profile == VAProfileVP9Profile0)
3335 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3336 * the packed_slice_header as the delimeter to decide how
3337 * the packed rawdata is inserted for the given slice.
3338 * Otherwise it will use the VAEncSequenceParameterBuffer
3341 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3342 /* store the first index of the packed header data for current slice */
3343 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3344 encode->slice_rawdata_index[encode->slice_index] =
3345 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3347 encode->slice_rawdata_count[encode->slice_index]++;
3348 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3349 /* find one packed slice_header delimeter. And the following
3350 * packed data is for the next slice
3352 encode->slice_header_index[encode->slice_index] =
3353 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3354 encode->slice_index++;
3355 /* Reallocate the buffer to record the index/count of
3356 * packed_data for one slice.
3358 if (encode->slice_index == encode->max_slice_num) {
3359 int slice_num = encode->max_slice_num;
3361 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3362 (slice_num + NUM_SLICES) * sizeof(int));
3363 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3364 (slice_num + NUM_SLICES) * sizeof(int));
3365 encode->slice_header_index = realloc(encode->slice_header_index,
3366 (slice_num + NUM_SLICES) * sizeof(int));
3367 memset(encode->slice_rawdata_index + slice_num, 0,
3368 sizeof(int) * NUM_SLICES);
3369 memset(encode->slice_rawdata_count + slice_num, 0,
3370 sizeof(int) * NUM_SLICES);
3371 memset(encode->slice_header_index + slice_num, 0,
3372 sizeof(int) * NUM_SLICES);
3373 encode->max_slice_num += NUM_SLICES;
3377 if (vaStatus == VA_STATUS_SUCCESS) {
3378 /* store the first index of the packed header data for current slice */
3379 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3380 encode->slice_rawdata_index[encode->slice_index] =
3381 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3383 encode->slice_rawdata_count[encode->slice_index]++;
3384 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3385 if (encode->slice_header_index[encode->slice_index] == 0) {
3386 encode->slice_header_index[encode->slice_index] =
3387 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3389 WARN_ONCE("Multi slice header data is passed for"
3390 " slice %d!\n", encode->slice_index);
3396 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3397 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3398 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3399 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3400 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3401 VA_STATUS_ERROR_ENCODING_ERROR);
3403 if((obj_config->profile == VAProfileHEVCMain) &&
3404 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3406 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3409 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3410 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3412 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3415 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3419 encode->last_packed_header_type = 0;
3423 case VAEncMiscParameterBufferType:
3424 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3429 case VAEncMacroblockMapBufferType:
3430 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3434 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3442 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3444 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3445 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3448 i965_proc_render_picture(VADriverContextP ctx,
3449 VAContextID context,
3450 VABufferID *buffers,
3453 struct i965_driver_data *i965 = i965_driver_data(ctx);
3454 struct object_context *obj_context = CONTEXT(context);
3455 VAStatus vaStatus = VA_STATUS_SUCCESS;
3458 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3460 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3461 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3464 return VA_STATUS_ERROR_INVALID_BUFFER;
3466 switch (obj_buffer->type) {
3467 case VAProcPipelineParameterBufferType:
3468 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3472 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3481 i965_RenderPicture(VADriverContextP ctx,
3482 VAContextID context,
3483 VABufferID *buffers,
3486 struct i965_driver_data *i965 = i965_driver_data(ctx);
3487 struct object_context *obj_context;
3488 struct object_config *obj_config;
3489 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3491 obj_context = CONTEXT(context);
3492 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3494 if (num_buffers <= 0)
3495 return VA_STATUS_ERROR_INVALID_PARAMETER;
3497 obj_config = obj_context->obj_config;
3498 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3500 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3501 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3502 } else if ((VAEntrypointEncSlice == obj_config->entrypoint ) ||
3503 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3504 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3505 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3507 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3514 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3516 struct i965_driver_data *i965 = i965_driver_data(ctx);
3517 struct object_context *obj_context = CONTEXT(context);
3518 struct object_config *obj_config;
3520 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3521 obj_config = obj_context->obj_config;
3522 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3524 if (obj_context->codec_type == CODEC_PROC) {
3525 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3526 } else if (obj_context->codec_type == CODEC_ENC) {
3527 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3528 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3529 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3530 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3532 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3533 obj_context->codec_state.encode.num_packed_header_data_ext) {
3534 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3535 return VA_STATUS_ERROR_INVALID_PARAMETER;
3537 if (!(obj_context->codec_state.encode.pic_param ||
3538 obj_context->codec_state.encode.pic_param_ext)) {
3539 return VA_STATUS_ERROR_INVALID_PARAMETER;
3541 if (!(obj_context->codec_state.encode.seq_param ||
3542 obj_context->codec_state.encode.seq_param_ext) &&
3543 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3544 /* The seq_param is not mandatory for VP9 encoding */
3545 if (obj_config->profile != VAProfileVP9Profile0)
3546 return VA_STATUS_ERROR_INVALID_PARAMETER;
3548 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
3549 (obj_context->codec_state.encode.num_slice_params_ext <=0) &&
3550 ((obj_config->profile != VAProfileVP8Version0_3) &&
3551 (obj_config->profile != VAProfileVP9Profile0))) {
3552 return VA_STATUS_ERROR_INVALID_PARAMETER;
3555 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3556 (obj_context->codec_state.encode.num_slice_params_ext !=
3557 obj_context->codec_state.encode.slice_index)) {
3558 WARN_ONCE("packed slice_header data is missing for some slice"
3559 " under packed SLICE_HEADER mode\n");
3560 return VA_STATUS_ERROR_INVALID_PARAMETER;
3563 if (obj_context->codec_state.decode.pic_param == NULL) {
3564 return VA_STATUS_ERROR_INVALID_PARAMETER;
3566 if (obj_context->codec_state.decode.num_slice_params <=0) {
3567 return VA_STATUS_ERROR_INVALID_PARAMETER;
3569 if (obj_context->codec_state.decode.num_slice_datas <=0) {
3570 return VA_STATUS_ERROR_INVALID_PARAMETER;
3573 if (obj_context->codec_state.decode.num_slice_params !=
3574 obj_context->codec_state.decode.num_slice_datas) {
3575 return VA_STATUS_ERROR_INVALID_PARAMETER;
3578 if (obj_context->wrapper_context != VA_INVALID_ID) {
3579 /* call the vaEndPicture of wrapped driver */
3580 VADriverContextP pdrvctx;
3583 pdrvctx = i965->wrapper_pdrvctx;
3584 CALL_VTABLE(pdrvctx, va_status,
3585 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3591 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3592 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3596 i965_SyncSurface(VADriverContextP ctx,
3597 VASurfaceID render_target)
3599 struct i965_driver_data *i965 = i965_driver_data(ctx);
3600 struct object_surface *obj_surface = SURFACE(render_target);
3602 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3605 drm_intel_bo_wait_rendering(obj_surface->bo);
3607 return VA_STATUS_SUCCESS;
3611 i965_QuerySurfaceStatus(VADriverContextP ctx,
3612 VASurfaceID render_target,
3613 VASurfaceStatus *status) /* out */
3615 struct i965_driver_data *i965 = i965_driver_data(ctx);
3616 struct object_surface *obj_surface = SURFACE(render_target);
3618 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3620 if (obj_surface->bo) {
3621 if (drm_intel_bo_busy(obj_surface->bo)){
3622 *status = VASurfaceRendering;
3625 *status = VASurfaceReady;
3628 *status = VASurfaceReady;
3631 return VA_STATUS_SUCCESS;
3634 static VADisplayAttribute *
3635 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3637 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3640 if (!i965->display_attributes)
3643 for (i = 0; i < i965->num_display_attributes; i++) {
3644 if (i965->display_attributes[i].type == type)
3645 return &i965->display_attributes[i];
3651 i965_display_attributes_terminate(VADriverContextP ctx)
3653 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3655 if (i965->display_attributes) {
3656 free(i965->display_attributes);
3657 i965->display_attributes = NULL;
3658 i965->num_display_attributes = 0;
3663 i965_display_attributes_init(VADriverContextP ctx)
3665 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3667 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3668 i965->display_attributes = malloc(
3669 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3670 if (!i965->display_attributes)
3674 i965->display_attributes,
3675 i965_display_attributes,
3676 sizeof(i965_display_attributes)
3679 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3680 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3681 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3682 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3683 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3685 if (!i965->rotation_attrib ||
3686 !i965->brightness_attrib ||
3687 !i965->contrast_attrib ||
3688 !i965->hue_attrib ||
3689 !i965->saturation_attrib) {
3695 i965_display_attributes_terminate(ctx);
3700 * Query display attributes
3701 * The caller must provide a "attr_list" array that can hold at
3702 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3703 * returned in "attr_list" is returned in "num_attributes".
3706 i965_QueryDisplayAttributes(
3707 VADriverContextP ctx,
3708 VADisplayAttribute *attribs, /* out */
3709 int *num_attribs_ptr /* out */
3712 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3714 if (attribs && num_attribs > 0)
3715 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3717 if (num_attribs_ptr)
3718 *num_attribs_ptr = num_attribs;
3720 return VA_STATUS_SUCCESS;
3724 * Get display attributes
3725 * This function returns the current attribute values in "attr_list".
3726 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3727 * from vaQueryDisplayAttributes() can have their values retrieved.
3730 i965_GetDisplayAttributes(
3731 VADriverContextP ctx,
3732 VADisplayAttribute *attribs, /* inout */
3733 int num_attribs /* in */
3738 for (i = 0; i < num_attribs; i++) {
3739 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3741 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3742 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3743 dst_attrib->min_value = src_attrib->min_value;
3744 dst_attrib->max_value = src_attrib->max_value;
3745 dst_attrib->value = src_attrib->value;
3748 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3750 return VA_STATUS_SUCCESS;
3754 * Set display attributes
3755 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3756 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3757 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3760 i965_SetDisplayAttributes(
3761 VADriverContextP ctx,
3762 VADisplayAttribute *attribs, /* in */
3763 int num_attribs /* in */
3768 for (i = 0; i < num_attribs; i++) {
3769 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3771 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3773 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3775 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3778 if (src_attrib->value < dst_attrib->min_value ||
3779 src_attrib->value > dst_attrib->max_value)
3780 return VA_STATUS_ERROR_INVALID_PARAMETER;
3782 dst_attrib->value = src_attrib->value;
3783 /* XXX: track modified attributes through timestamps */
3785 return VA_STATUS_SUCCESS;
3789 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3790 VASurfaceID surface,
3791 void **buffer, /* out */
3792 unsigned int *stride) /* out */
3795 return VA_STATUS_ERROR_UNIMPLEMENTED;
3799 i965_destroy_heap(struct object_heap *heap,
3800 void (*func)(struct object_heap *heap, struct object_base *object))
3802 struct object_base *object;
3803 object_heap_iterator iter;
3805 object = object_heap_first(heap, &iter);
3811 object = object_heap_next(heap, &iter);
3814 object_heap_destroy(heap);
3819 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3822 i965_CreateImage(VADriverContextP ctx,
3823 VAImageFormat *format,
3826 VAImage *out_image) /* out */
3828 struct i965_driver_data *i965 = i965_driver_data(ctx);
3829 struct object_image *obj_image;
3830 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3832 unsigned int size2, size, awidth, aheight;
3834 out_image->image_id = VA_INVALID_ID;
3835 out_image->buf = VA_INVALID_ID;
3837 image_id = NEW_IMAGE_ID();
3838 if (image_id == VA_INVALID_ID)
3839 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3841 obj_image = IMAGE(image_id);
3843 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3844 obj_image->bo = NULL;
3845 obj_image->palette = NULL;
3846 obj_image->derived_surface = VA_INVALID_ID;
3848 VAImage * const image = &obj_image->image;
3849 image->image_id = image_id;
3850 image->buf = VA_INVALID_ID;
3852 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3854 if ((format->fourcc == VA_FOURCC_YV12) ||
3855 (format->fourcc == VA_FOURCC_I420)) {
3856 if (awidth % 128 != 0) {
3857 awidth = ALIGN(width, 128);
3861 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3862 size = awidth * aheight;
3863 size2 = (awidth / 2) * (aheight / 2);
3865 image->num_palette_entries = 0;
3866 image->entry_bytes = 0;
3867 memset(image->component_order, 0, sizeof(image->component_order));
3869 switch (format->fourcc) {
3870 case VA_FOURCC_IA44:
3871 case VA_FOURCC_AI44:
3872 image->num_planes = 1;
3873 image->pitches[0] = awidth;
3874 image->offsets[0] = 0;
3875 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3876 image->num_palette_entries = 16;
3877 image->entry_bytes = 3;
3878 image->component_order[0] = 'R';
3879 image->component_order[1] = 'G';
3880 image->component_order[2] = 'B';
3882 case VA_FOURCC_IA88:
3883 case VA_FOURCC_AI88:
3884 image->num_planes = 1;
3885 image->pitches[0] = awidth * 2;
3886 image->offsets[0] = 0;
3887 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3888 image->num_palette_entries = 256;
3889 image->entry_bytes = 3;
3890 image->component_order[0] = 'R';
3891 image->component_order[1] = 'G';
3892 image->component_order[2] = 'B';
3894 case VA_FOURCC_ARGB:
3895 case VA_FOURCC_ABGR:
3896 case VA_FOURCC_BGRA:
3897 case VA_FOURCC_RGBA:
3898 case VA_FOURCC_BGRX:
3899 case VA_FOURCC_RGBX:
3900 image->num_planes = 1;
3901 image->pitches[0] = awidth * 4;
3902 image->offsets[0] = 0;
3903 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3905 case VA_FOURCC_YV12:
3906 image->num_planes = 3;
3907 image->pitches[0] = awidth;
3908 image->offsets[0] = 0;
3909 image->pitches[1] = awidth / 2;
3910 image->offsets[1] = size;
3911 image->pitches[2] = awidth / 2;
3912 image->offsets[2] = size + size2;
3913 image->data_size = size + 2 * size2;
3915 case VA_FOURCC_I420:
3916 image->num_planes = 3;
3917 image->pitches[0] = awidth;
3918 image->offsets[0] = 0;
3919 image->pitches[1] = awidth / 2;
3920 image->offsets[1] = size;
3921 image->pitches[2] = awidth / 2;
3922 image->offsets[2] = size + size2;
3923 image->data_size = size + 2 * size2;
3925 case VA_FOURCC_422H:
3926 image->num_planes = 3;
3927 image->pitches[0] = awidth;
3928 image->offsets[0] = 0;
3929 image->pitches[1] = awidth / 2;
3930 image->offsets[1] = size;
3931 image->pitches[2] = awidth / 2;
3932 image->offsets[2] = size + (awidth / 2) * aheight;
3933 image->data_size = size + 2 * ((awidth / 2) * aheight);
3935 case VA_FOURCC_NV12:
3936 image->num_planes = 2;
3937 image->pitches[0] = awidth;
3938 image->offsets[0] = 0;
3939 image->pitches[1] = awidth;
3940 image->offsets[1] = size;
3941 image->data_size = size + 2 * size2;
3943 case VA_FOURCC_YUY2:
3944 case VA_FOURCC_UYVY:
3945 image->num_planes = 1;
3946 image->pitches[0] = awidth * 2;
3947 image->offsets[0] = 0;
3948 image->data_size = size * 2;
3950 case VA_FOURCC_P010:
3951 image->num_planes = 2;
3952 image->pitches[0] = awidth * 2;
3953 image->offsets[0] = 0;
3954 image->pitches[1] = awidth * 2;
3955 image->offsets[1] = size * 2;
3956 image->data_size = size * 2 + 2 * size2 * 2;
3962 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
3963 image->data_size, 1, NULL, &image->buf);
3964 if (va_status != VA_STATUS_SUCCESS)
3967 struct object_buffer *obj_buffer = BUFFER(image->buf);
3970 !obj_buffer->buffer_store ||
3971 !obj_buffer->buffer_store->bo)
3972 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3974 obj_image->bo = obj_buffer->buffer_store->bo;
3975 dri_bo_reference(obj_image->bo);
3977 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3978 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3979 if (!obj_image->palette)
3983 image->image_id = image_id;
3984 image->format = *format;
3985 image->width = width;
3986 image->height = height;
3988 *out_image = *image;
3989 return VA_STATUS_SUCCESS;
3992 i965_DestroyImage(ctx, image_id);
3997 i965_check_alloc_surface_bo(VADriverContextP ctx,
3998 struct object_surface *obj_surface,
4000 unsigned int fourcc,
4001 unsigned int subsampling)
4003 struct i965_driver_data *i965 = i965_driver_data(ctx);
4004 int region_width, region_height;
4006 if (obj_surface->bo) {
4007 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4008 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4009 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
4010 return VA_STATUS_SUCCESS;
4013 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
4014 obj_surface->x_cr_offset = 0;
4016 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
4018 if ((tiled && !obj_surface->user_disable_tiling)) {
4019 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
4020 fourcc != VA_FOURCC_IYUV &&
4021 fourcc != VA_FOURCC_YV12,
4022 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4024 if (obj_surface->user_h_stride_set) {
4025 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4027 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4029 if (obj_surface->user_v_stride_set) {
4030 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4032 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4034 region_height = obj_surface->height;
4037 case VA_FOURCC_NV12:
4038 case VA_FOURCC_P010:
4039 assert(subsampling == SUBSAMPLE_YUV420);
4040 obj_surface->cb_cr_pitch = obj_surface->width;
4041 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4042 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4043 obj_surface->y_cb_offset = obj_surface->height;
4044 obj_surface->y_cr_offset = obj_surface->height;
4045 region_width = obj_surface->width;
4046 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4050 case VA_FOURCC_IMC1:
4051 assert(subsampling == SUBSAMPLE_YUV420);
4052 obj_surface->cb_cr_pitch = obj_surface->width;
4053 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4054 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4055 obj_surface->y_cr_offset = obj_surface->height;
4056 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4057 region_width = obj_surface->width;
4058 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4062 case VA_FOURCC_IMC3:
4063 assert(subsampling == SUBSAMPLE_YUV420);
4064 obj_surface->cb_cr_pitch = obj_surface->width;
4065 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4066 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4067 obj_surface->y_cb_offset = obj_surface->height;
4068 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4069 region_width = obj_surface->width;
4070 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4074 case VA_FOURCC_422H:
4075 assert(subsampling == SUBSAMPLE_YUV422H);
4076 obj_surface->cb_cr_pitch = obj_surface->width;
4077 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4078 obj_surface->cb_cr_height = obj_surface->orig_height;
4079 obj_surface->y_cb_offset = obj_surface->height;
4080 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4081 region_width = obj_surface->width;
4082 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4086 case VA_FOURCC_422V:
4087 assert(subsampling == SUBSAMPLE_YUV422V);
4088 obj_surface->cb_cr_pitch = obj_surface->width;
4089 obj_surface->cb_cr_width = obj_surface->orig_width;
4090 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4091 obj_surface->y_cb_offset = obj_surface->height;
4092 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4093 region_width = obj_surface->width;
4094 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4098 case VA_FOURCC_411P:
4099 assert(subsampling == SUBSAMPLE_YUV411);
4100 obj_surface->cb_cr_pitch = obj_surface->width;
4101 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4102 obj_surface->cb_cr_height = obj_surface->orig_height;
4103 obj_surface->y_cb_offset = obj_surface->height;
4104 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4105 region_width = obj_surface->width;
4106 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4110 case VA_FOURCC_444P:
4111 assert(subsampling == SUBSAMPLE_YUV444);
4112 obj_surface->cb_cr_pitch = obj_surface->width;
4113 obj_surface->cb_cr_width = obj_surface->orig_width;
4114 obj_surface->cb_cr_height = obj_surface->orig_height;
4115 obj_surface->y_cb_offset = obj_surface->height;
4116 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4117 region_width = obj_surface->width;
4118 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4122 case VA_FOURCC_Y800:
4123 assert(subsampling == SUBSAMPLE_YUV400);
4124 obj_surface->cb_cr_pitch = 0;
4125 obj_surface->cb_cr_width = 0;
4126 obj_surface->cb_cr_height = 0;
4127 obj_surface->y_cb_offset = 0;
4128 obj_surface->y_cr_offset = 0;
4129 region_width = obj_surface->width;
4130 region_height = obj_surface->height;
4134 case VA_FOURCC_YUY2:
4135 case VA_FOURCC_UYVY:
4136 assert(subsampling == SUBSAMPLE_YUV422H);
4137 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4138 obj_surface->cb_cr_pitch = obj_surface->width;
4139 obj_surface->y_cb_offset = 0;
4140 obj_surface->y_cr_offset = 0;
4141 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4142 obj_surface->cb_cr_height = obj_surface->orig_height;
4143 region_width = obj_surface->width;
4144 region_height = obj_surface->height;
4148 case VA_FOURCC_RGBA:
4149 case VA_FOURCC_RGBX:
4150 case VA_FOURCC_BGRA:
4151 case VA_FOURCC_BGRX:
4152 assert(subsampling == SUBSAMPLE_RGBX);
4154 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4155 region_width = obj_surface->width;
4156 region_height = obj_surface->height;
4160 /* Never get here */
4161 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4165 assert(subsampling == SUBSAMPLE_YUV420 ||
4166 subsampling == SUBSAMPLE_YUV422H ||
4167 subsampling == SUBSAMPLE_YUV422V ||
4168 subsampling == SUBSAMPLE_RGBX);
4170 region_width = obj_surface->width;
4171 region_height = obj_surface->height;
4174 case VA_FOURCC_NV12:
4175 case VA_FOURCC_P010:
4176 obj_surface->y_cb_offset = obj_surface->height;
4177 obj_surface->y_cr_offset = obj_surface->height;
4178 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4179 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4180 obj_surface->cb_cr_pitch = obj_surface->width;
4181 region_height = obj_surface->height + obj_surface->height / 2;
4184 case VA_FOURCC_YV16:
4185 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4186 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4187 obj_surface->cb_cr_height = obj_surface->orig_height;
4188 obj_surface->y_cr_offset = obj_surface->height;
4189 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4190 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4191 region_width = obj_surface->width;
4192 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4195 case VA_FOURCC_YV12:
4196 case VA_FOURCC_I420:
4197 if (fourcc == VA_FOURCC_YV12) {
4198 obj_surface->y_cr_offset = obj_surface->height;
4199 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4201 obj_surface->y_cb_offset = obj_surface->height;
4202 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4205 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4206 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4207 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4208 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4209 region_width = obj_surface->width;
4210 region_height = obj_surface->height + obj_surface->height / 2;
4213 case VA_FOURCC_YUY2:
4214 case VA_FOURCC_UYVY:
4215 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4216 obj_surface->y_cb_offset = 0;
4217 obj_surface->y_cr_offset = 0;
4218 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4219 obj_surface->cb_cr_height = obj_surface->orig_height;
4220 obj_surface->cb_cr_pitch = obj_surface->width;
4221 region_width = obj_surface->width;
4222 region_height = obj_surface->height;
4224 case VA_FOURCC_RGBA:
4225 case VA_FOURCC_RGBX:
4226 case VA_FOURCC_BGRA:
4227 case VA_FOURCC_BGRX:
4228 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4229 region_width = obj_surface->width;
4230 region_height = obj_surface->height;
4234 /* Never get here */
4235 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4240 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4242 if ((tiled && !obj_surface->user_disable_tiling)) {
4243 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4244 unsigned long pitch;
4246 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4254 assert(tiling_mode == I915_TILING_Y);
4255 assert(pitch == obj_surface->width);
4257 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4263 obj_surface->fourcc = fourcc;
4264 obj_surface->subsampling = subsampling;
4265 assert(obj_surface->bo);
4266 return VA_STATUS_SUCCESS;
4269 VAStatus i965_DeriveImage(VADriverContextP ctx,
4270 VASurfaceID surface,
4271 VAImage *out_image) /* out */
4273 struct i965_driver_data *i965 = i965_driver_data(ctx);
4274 struct object_image *obj_image;
4275 struct object_surface *obj_surface;
4277 unsigned int w_pitch;
4278 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4280 out_image->image_id = VA_INVALID_ID;
4281 obj_surface = SURFACE(surface);
4284 return VA_STATUS_ERROR_INVALID_SURFACE;
4286 if (!obj_surface->bo) {
4287 unsigned int is_tiled = 0;
4288 unsigned int fourcc = VA_FOURCC_YV12;
4289 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4290 int sampling = get_sampling_from_fourcc(fourcc);
4291 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4292 if (va_status != VA_STATUS_SUCCESS)
4296 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4298 w_pitch = obj_surface->width;
4300 image_id = NEW_IMAGE_ID();
4302 if (image_id == VA_INVALID_ID)
4303 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4305 obj_image = IMAGE(image_id);
4308 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4310 obj_image->bo = NULL;
4311 obj_image->palette = NULL;
4312 obj_image->derived_surface = VA_INVALID_ID;
4314 VAImage * const image = &obj_image->image;
4316 memset(image, 0, sizeof(*image));
4317 image->image_id = image_id;
4318 image->buf = VA_INVALID_ID;
4319 image->num_palette_entries = 0;
4320 image->entry_bytes = 0;
4321 image->width = obj_surface->orig_width;
4322 image->height = obj_surface->orig_height;
4323 image->data_size = obj_surface->size;
4325 image->format.fourcc = obj_surface->fourcc;
4326 image->format.byte_order = VA_LSB_FIRST;
4327 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4329 if (!image->format.bits_per_pixel)
4332 switch (image->format.fourcc) {
4333 case VA_FOURCC_YV12:
4334 image->num_planes = 3;
4335 image->pitches[0] = w_pitch; /* Y */
4336 image->offsets[0] = 0;
4337 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4338 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4339 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4340 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4343 case VA_FOURCC_YV16:
4344 image->num_planes = 3;
4345 image->pitches[0] = w_pitch; /* Y */
4346 image->offsets[0] = 0;
4347 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4348 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4349 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4350 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4353 case VA_FOURCC_NV12:
4354 case VA_FOURCC_P010:
4355 image->num_planes = 2;
4356 image->pitches[0] = w_pitch; /* Y */
4357 image->offsets[0] = 0;
4358 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4359 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4362 case VA_FOURCC_I420:
4363 case VA_FOURCC_422H:
4364 case VA_FOURCC_IMC3:
4365 case VA_FOURCC_444P:
4366 case VA_FOURCC_422V:
4367 case VA_FOURCC_411P:
4368 image->num_planes = 3;
4369 image->pitches[0] = w_pitch; /* Y */
4370 image->offsets[0] = 0;
4371 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4372 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4373 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4374 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4377 case VA_FOURCC_YUY2:
4378 case VA_FOURCC_UYVY:
4379 case VA_FOURCC_Y800:
4380 image->num_planes = 1;
4381 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4382 image->offsets[0] = 0;
4384 case VA_FOURCC_RGBA:
4385 case VA_FOURCC_RGBX:
4386 case VA_FOURCC_BGRA:
4387 case VA_FOURCC_BGRX:
4388 image->num_planes = 1;
4389 image->pitches[0] = obj_surface->width;
4391 switch (image->format.fourcc) {
4392 case VA_FOURCC_RGBA:
4393 case VA_FOURCC_RGBX:
4394 image->format.red_mask = 0x000000ff;
4395 image->format.green_mask = 0x0000ff00;
4396 image->format.blue_mask = 0x00ff0000;
4398 case VA_FOURCC_BGRA:
4399 case VA_FOURCC_BGRX:
4400 image->format.red_mask = 0x00ff0000;
4401 image->format.green_mask = 0x0000ff00;
4402 image->format.blue_mask = 0x000000ff;
4408 switch (image->format.fourcc) {
4409 case VA_FOURCC_RGBA:
4410 case VA_FOURCC_BGRA:
4411 image->format.alpha_mask = 0xff000000;
4412 image->format.depth = 32;
4414 case VA_FOURCC_RGBX:
4415 case VA_FOURCC_BGRX:
4416 image->format.alpha_mask = 0x00000000;
4417 image->format.depth = 24;
4428 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4429 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4430 if (va_status != VA_STATUS_SUCCESS)
4433 struct object_buffer *obj_buffer = BUFFER(image->buf);
4436 !obj_buffer->buffer_store ||
4437 !obj_buffer->buffer_store->bo)
4438 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4440 obj_image->bo = obj_buffer->buffer_store->bo;
4441 dri_bo_reference(obj_image->bo);
4443 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4444 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4445 if (!obj_image->palette) {
4446 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4451 *out_image = *image;
4452 obj_surface->flags |= SURFACE_DERIVED;
4453 obj_surface->derived_image_id = image_id;
4454 obj_image->derived_surface = surface;
4456 return VA_STATUS_SUCCESS;
4459 i965_DestroyImage(ctx, image_id);
4464 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4466 object_heap_free(heap, obj);
4471 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4473 struct i965_driver_data *i965 = i965_driver_data(ctx);
4474 struct object_image *obj_image = IMAGE(image);
4475 struct object_surface *obj_surface;
4478 return VA_STATUS_SUCCESS;
4480 dri_bo_unreference(obj_image->bo);
4481 obj_image->bo = NULL;
4483 if (obj_image->image.buf != VA_INVALID_ID) {
4484 i965_DestroyBuffer(ctx, obj_image->image.buf);
4485 obj_image->image.buf = VA_INVALID_ID;
4488 if (obj_image->palette) {
4489 free(obj_image->palette);
4490 obj_image->palette = NULL;
4493 obj_surface = SURFACE(obj_image->derived_surface);
4496 obj_surface->flags &= ~SURFACE_DERIVED;
4497 obj_surface->derived_image_id = VA_INVALID_ID;
4500 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4502 return VA_STATUS_SUCCESS;
4506 * pointer to an array holding the palette data. The size of the array is
4507 * num_palette_entries * entry_bytes in size. The order of the components
4508 * in the palette is described by the component_order in VASubpicture struct
4511 i965_SetImagePalette(VADriverContextP ctx,
4513 unsigned char *palette)
4515 struct i965_driver_data *i965 = i965_driver_data(ctx);
4518 struct object_image *obj_image = IMAGE(image);
4520 return VA_STATUS_ERROR_INVALID_IMAGE;
4522 if (!obj_image->palette)
4523 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4525 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4526 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
4527 ((unsigned int)palette[3*i + 1] << 8) |
4528 (unsigned int)palette[3*i + 2]);
4529 return VA_STATUS_SUCCESS;
4533 get_sampling_from_fourcc(unsigned int fourcc)
4535 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4537 if (info && (info->flag & I_S))
4538 return info->subsampling;
4544 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4545 const uint8_t *src, unsigned int src_stride,
4546 unsigned int len, unsigned int height)
4550 for (i = 0; i < height; i++) {
4551 memcpy(dst, src, len);
4558 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4559 struct object_surface *obj_surface,
4560 const VARectangle *rect)
4562 uint8_t *dst[3], *src[3];
4564 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4565 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4566 unsigned int tiling, swizzle;
4567 VAStatus va_status = VA_STATUS_SUCCESS;
4569 if (!obj_surface->bo)
4570 return VA_STATUS_ERROR_INVALID_SURFACE;
4572 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4573 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4575 if (tiling != I915_TILING_NONE)
4576 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4578 dri_bo_map(obj_surface->bo, 0);
4580 if (!obj_surface->bo->virtual)
4581 return VA_STATUS_ERROR_INVALID_SURFACE;
4583 /* Dest VA image has either I420 or YV12 format.
4584 Source VA surface alway has I420 format */
4585 dst[Y] = image_data + obj_image->image.offsets[Y];
4586 src[0] = (uint8_t *)obj_surface->bo->virtual;
4587 dst[U] = image_data + obj_image->image.offsets[U];
4588 src[1] = src[0] + obj_surface->width * obj_surface->height;
4589 dst[V] = image_data + obj_image->image.offsets[V];
4590 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4593 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4594 src[0] += rect->y * obj_surface->width + rect->x;
4595 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4596 src[0], obj_surface->width,
4597 rect->width, rect->height);
4600 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4601 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4602 memcpy_pic(dst[U], obj_image->image.pitches[U],
4603 src[1], obj_surface->width / 2,
4604 rect->width / 2, rect->height / 2);
4607 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4608 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4609 memcpy_pic(dst[V], obj_image->image.pitches[V],
4610 src[2], obj_surface->width / 2,
4611 rect->width / 2, rect->height / 2);
4613 if (tiling != I915_TILING_NONE)
4614 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4616 dri_bo_unmap(obj_surface->bo);
4622 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4623 struct object_surface *obj_surface,
4624 const VARectangle *rect)
4626 uint8_t *dst[2], *src[2];
4627 unsigned int tiling, swizzle;
4628 VAStatus va_status = VA_STATUS_SUCCESS;
4630 if (!obj_surface->bo)
4631 return VA_STATUS_ERROR_INVALID_SURFACE;
4633 assert(obj_surface->fourcc);
4634 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4636 if (tiling != I915_TILING_NONE)
4637 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4639 dri_bo_map(obj_surface->bo, 0);
4641 if (!obj_surface->bo->virtual)
4642 return VA_STATUS_ERROR_INVALID_SURFACE;
4644 /* Both dest VA image and source surface have NV12 format */
4645 dst[0] = image_data + obj_image->image.offsets[0];
4646 src[0] = (uint8_t *)obj_surface->bo->virtual;
4647 dst[1] = image_data + obj_image->image.offsets[1];
4648 src[1] = src[0] + obj_surface->width * obj_surface->height;
4651 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4652 src[0] += rect->y * obj_surface->width + rect->x;
4653 memcpy_pic(dst[0], obj_image->image.pitches[0],
4654 src[0], obj_surface->width,
4655 rect->width, rect->height);
4658 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4659 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4660 memcpy_pic(dst[1], obj_image->image.pitches[1],
4661 src[1], obj_surface->width,
4662 rect->width, rect->height / 2);
4664 if (tiling != I915_TILING_NONE)
4665 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4667 dri_bo_unmap(obj_surface->bo);
4673 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4674 struct object_surface *obj_surface,
4675 const VARectangle *rect)
4678 unsigned int tiling, swizzle;
4679 VAStatus va_status = VA_STATUS_SUCCESS;
4681 if (!obj_surface->bo)
4682 return VA_STATUS_ERROR_INVALID_SURFACE;
4684 assert(obj_surface->fourcc);
4685 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4687 if (tiling != I915_TILING_NONE)
4688 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4690 dri_bo_map(obj_surface->bo, 0);
4692 if (!obj_surface->bo->virtual)
4693 return VA_STATUS_ERROR_INVALID_SURFACE;
4695 /* Both dest VA image and source surface have YUYV format */
4696 dst = image_data + obj_image->image.offsets[0];
4697 src = (uint8_t *)obj_surface->bo->virtual;
4700 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
4701 src += rect->y * obj_surface->width + rect->x*2;
4702 memcpy_pic(dst, obj_image->image.pitches[0],
4703 src, obj_surface->width*2,
4704 rect->width*2, rect->height);
4706 if (tiling != I915_TILING_NONE)
4707 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4709 dri_bo_unmap(obj_surface->bo);
4715 i965_sw_getimage(VADriverContextP ctx,
4716 struct object_surface *obj_surface, struct object_image *obj_image,
4717 const VARectangle *rect)
4719 void *image_data = NULL;
4722 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4723 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4725 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4726 if (va_status != VA_STATUS_SUCCESS)
4729 switch (obj_image->image.format.fourcc) {
4730 case VA_FOURCC_YV12:
4731 case VA_FOURCC_I420:
4732 get_image_i420(obj_image, image_data, obj_surface, rect);
4734 case VA_FOURCC_NV12:
4735 get_image_nv12(obj_image, image_data, obj_surface, rect);
4737 case VA_FOURCC_YUY2:
4738 /* YUY2 is the format supported by overlay plane */
4739 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4742 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4745 if (va_status != VA_STATUS_SUCCESS)
4748 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4753 i965_hw_getimage(VADriverContextP ctx,
4754 struct object_surface *obj_surface, struct object_image *obj_image,
4755 const VARectangle *rect)
4757 struct i965_surface src_surface;
4758 struct i965_surface dst_surface;
4760 src_surface.base = (struct object_base *)obj_surface;
4761 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4762 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4764 dst_surface.base = (struct object_base *)obj_image;
4765 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4766 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4768 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4772 i965_GetImage(VADriverContextP ctx,
4773 VASurfaceID surface,
4774 int x, /* coordinates of the upper left source pixel */
4776 unsigned int width, /* width and height of the region */
4777 unsigned int height,
4780 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4781 struct object_surface * const obj_surface = SURFACE(surface);
4782 struct object_image * const obj_image = IMAGE(image);
4787 return VA_STATUS_ERROR_INVALID_SURFACE;
4788 if (!obj_surface->bo) /* don't get anything, keep previous data */
4789 return VA_STATUS_SUCCESS;
4790 if (is_surface_busy(i965, obj_surface))
4791 return VA_STATUS_ERROR_SURFACE_BUSY;
4793 if (!obj_image || !obj_image->bo)
4794 return VA_STATUS_ERROR_INVALID_IMAGE;
4795 if (is_image_busy(i965, obj_image, surface))
4796 return VA_STATUS_ERROR_SURFACE_BUSY;
4799 return VA_STATUS_ERROR_INVALID_PARAMETER;
4800 if (x + width > obj_surface->orig_width ||
4801 y + height > obj_surface->orig_height)
4802 return VA_STATUS_ERROR_INVALID_PARAMETER;
4803 if (x + width > obj_image->image.width ||
4804 y + height > obj_image->image.height)
4805 return VA_STATUS_ERROR_INVALID_PARAMETER;
4810 rect.height = height;
4812 if (HAS_ACCELERATED_GETIMAGE(i965))
4813 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
4815 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
4821 put_image_i420(struct object_surface *obj_surface,
4822 const VARectangle *dst_rect,
4823 struct object_image *obj_image, uint8_t *image_data,
4824 const VARectangle *src_rect)
4826 uint8_t *dst[3], *src[3];
4828 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4829 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4830 unsigned int tiling, swizzle;
4831 VAStatus va_status = VA_STATUS_SUCCESS;
4833 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4835 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4836 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4837 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4838 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4840 if (tiling != I915_TILING_NONE)
4841 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4843 dri_bo_map(obj_surface->bo, 0);
4845 if (!obj_surface->bo->virtual)
4846 return VA_STATUS_ERROR_INVALID_SURFACE;
4848 /* Dest VA image has either I420 or YV12 format.
4849 Source VA surface alway has I420 format */
4850 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4851 src[Y] = image_data + obj_image->image.offsets[Y];
4852 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4853 src[U] = image_data + obj_image->image.offsets[U];
4854 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4855 src[V] = image_data + obj_image->image.offsets[V];
4858 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4859 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4860 memcpy_pic(dst[0], obj_surface->width,
4861 src[Y], obj_image->image.pitches[Y],
4862 src_rect->width, src_rect->height);
4865 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4866 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4867 memcpy_pic(dst[1], obj_surface->width / 2,
4868 src[U], obj_image->image.pitches[U],
4869 src_rect->width / 2, src_rect->height / 2);
4872 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4873 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4874 memcpy_pic(dst[2], obj_surface->width / 2,
4875 src[V], obj_image->image.pitches[V],
4876 src_rect->width / 2, src_rect->height / 2);
4878 if (tiling != I915_TILING_NONE)
4879 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4881 dri_bo_unmap(obj_surface->bo);
4887 put_image_nv12(struct object_surface *obj_surface,
4888 const VARectangle *dst_rect,
4889 struct object_image *obj_image, uint8_t *image_data,
4890 const VARectangle *src_rect)
4892 uint8_t *dst[2], *src[2];
4893 unsigned int tiling, swizzle;
4894 VAStatus va_status = VA_STATUS_SUCCESS;
4896 if (!obj_surface->bo)
4897 return VA_STATUS_ERROR_INVALID_SURFACE;
4899 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4900 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4901 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4902 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4904 if (tiling != I915_TILING_NONE)
4905 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4907 dri_bo_map(obj_surface->bo, 0);
4909 if (!obj_surface->bo->virtual)
4910 return VA_STATUS_ERROR_INVALID_SURFACE;
4912 /* Both dest VA image and source surface have NV12 format */
4913 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4914 src[0] = image_data + obj_image->image.offsets[0];
4915 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4916 src[1] = image_data + obj_image->image.offsets[1];
4919 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4920 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
4921 memcpy_pic(dst[0], obj_surface->width,
4922 src[0], obj_image->image.pitches[0],
4923 src_rect->width, src_rect->height);
4926 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
4927 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
4928 memcpy_pic(dst[1], obj_surface->width,
4929 src[1], obj_image->image.pitches[1],
4930 src_rect->width, src_rect->height / 2);
4932 if (tiling != I915_TILING_NONE)
4933 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4935 dri_bo_unmap(obj_surface->bo);
4941 put_image_yuy2(struct object_surface *obj_surface,
4942 const VARectangle *dst_rect,
4943 struct object_image *obj_image, uint8_t *image_data,
4944 const VARectangle *src_rect)
4947 unsigned int tiling, swizzle;
4948 VAStatus va_status = VA_STATUS_SUCCESS;
4950 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4951 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4952 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4953 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4954 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4956 if (tiling != I915_TILING_NONE)
4957 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4959 dri_bo_map(obj_surface->bo, 0);
4961 if (!obj_surface->bo->virtual)
4962 return VA_STATUS_ERROR_INVALID_SURFACE;
4964 /* Both dest VA image and source surface have YUY2 format */
4965 dst = (uint8_t *)obj_surface->bo->virtual;
4966 src = image_data + obj_image->image.offsets[0];
4968 /* YUYV packed plane */
4969 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
4970 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
4971 memcpy_pic(dst, obj_surface->width*2,
4972 src, obj_image->image.pitches[0],
4973 src_rect->width*2, src_rect->height);
4975 if (tiling != I915_TILING_NONE)
4976 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4978 dri_bo_unmap(obj_surface->bo);
4984 i965_sw_putimage(VADriverContextP ctx,
4985 struct object_surface *obj_surface, struct object_image *obj_image,
4986 const VARectangle *src_rect, const VARectangle *dst_rect)
4988 VAStatus va_status = VA_STATUS_SUCCESS;
4989 void *image_data = NULL;
4991 /* XXX: don't allow scaling */
4992 if (src_rect->width != dst_rect->width ||
4993 src_rect->height != dst_rect->height)
4994 return VA_STATUS_ERROR_INVALID_PARAMETER;
4996 if (obj_surface->fourcc) {
4997 /* Don't allow format mismatch */
4998 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4999 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
5003 /* VA is surface not used for decoding, use same VA image format */
5004 va_status = i965_check_alloc_surface_bo(
5007 0, /* XXX: don't use tiled surface */
5008 obj_image->image.format.fourcc,
5009 get_sampling_from_fourcc (obj_image->image.format.fourcc));
5012 if (va_status != VA_STATUS_SUCCESS)
5015 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
5016 if (va_status != VA_STATUS_SUCCESS)
5019 switch (obj_image->image.format.fourcc) {
5020 case VA_FOURCC_YV12:
5021 case VA_FOURCC_I420:
5022 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
5024 case VA_FOURCC_NV12:
5025 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5027 case VA_FOURCC_YUY2:
5028 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5031 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5034 if (va_status != VA_STATUS_SUCCESS)
5037 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5042 i965_hw_putimage(VADriverContextP ctx,
5043 struct object_surface *obj_surface, struct object_image *obj_image,
5044 const VARectangle *src_rect, const VARectangle *dst_rect)
5046 struct i965_surface src_surface, dst_surface;
5047 VAStatus va_status = VA_STATUS_SUCCESS;
5049 if (!obj_surface->bo) {
5050 unsigned int tiling, swizzle;
5051 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
5052 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5054 i965_check_alloc_surface_bo(ctx,
5057 obj_image->image.format.fourcc,
5061 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5063 src_surface.base = (struct object_base *)obj_image;
5064 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5065 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5067 dst_surface.base = (struct object_base *)obj_surface;
5068 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5069 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5071 va_status = i965_image_processing(ctx,
5081 i965_PutImage(VADriverContextP ctx,
5082 VASurfaceID surface,
5086 unsigned int src_width,
5087 unsigned int src_height,
5090 unsigned int dest_width,
5091 unsigned int dest_height)
5093 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5094 struct object_surface * const obj_surface = SURFACE(surface);
5095 struct object_image * const obj_image = IMAGE(image);
5096 VARectangle src_rect, dst_rect;
5100 return VA_STATUS_ERROR_INVALID_SURFACE;
5101 if (is_surface_busy(i965, obj_surface))
5102 return VA_STATUS_ERROR_SURFACE_BUSY;
5104 if (!obj_image || !obj_image->bo)
5105 return VA_STATUS_ERROR_INVALID_IMAGE;
5106 if (is_image_busy(i965, obj_image, surface))
5107 return VA_STATUS_ERROR_SURFACE_BUSY;
5111 src_x + src_width > obj_image->image.width ||
5112 src_y + src_height > obj_image->image.height)
5113 return VA_STATUS_ERROR_INVALID_PARAMETER;
5117 src_rect.width = src_width;
5118 src_rect.height = src_height;
5122 dest_x + dest_width > obj_surface->orig_width ||
5123 dest_y + dest_height > obj_surface->orig_height)
5124 return VA_STATUS_ERROR_INVALID_PARAMETER;
5126 dst_rect.x = dest_x;
5127 dst_rect.y = dest_y;
5128 dst_rect.width = dest_width;
5129 dst_rect.height = dest_height;
5131 if (HAS_ACCELERATED_PUTIMAGE(i965))
5132 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5133 &src_rect, &dst_rect);
5135 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5136 &src_rect, &dst_rect);
5142 i965_PutSurface(VADriverContextP ctx,
5143 VASurfaceID surface,
5144 void *draw, /* X Drawable */
5147 unsigned short srcw,
5148 unsigned short srch,
5151 unsigned short destw,
5152 unsigned short desth,
5153 VARectangle *cliprects, /* client supplied clip list */
5154 unsigned int number_cliprects, /* number of clip rects in the clip list */
5155 unsigned int flags) /* de-interlacing flags */
5158 if (IS_VA_X11(ctx)) {
5159 VARectangle src_rect, dst_rect;
5163 src_rect.width = srcw;
5164 src_rect.height = srch;
5168 dst_rect.width = destw;
5169 dst_rect.height = desth;
5171 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5172 cliprects, number_cliprects, flags);
5175 return VA_STATUS_ERROR_UNIMPLEMENTED;
5180 VADriverContextP ctx, /* in */
5181 VABufferID buf_id, /* in */
5182 VABufferType *type, /* out */
5183 unsigned int *size, /* out */
5184 unsigned int *num_elements /* out */
5187 struct i965_driver_data *i965 = NULL;
5188 struct object_buffer *obj_buffer = NULL;
5190 i965 = i965_driver_data(ctx);
5191 obj_buffer = BUFFER(buf_id);
5193 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5195 *type = obj_buffer->type;
5196 *size = obj_buffer->size_element;
5197 *num_elements = obj_buffer->num_elements;
5199 return VA_STATUS_SUCCESS;
5204 VADriverContextP ctx, /* in */
5205 VASurfaceID surface, /* in */
5206 unsigned int *fourcc, /* out */
5207 unsigned int *luma_stride, /* out */
5208 unsigned int *chroma_u_stride, /* out */
5209 unsigned int *chroma_v_stride, /* out */
5210 unsigned int *luma_offset, /* out */
5211 unsigned int *chroma_u_offset, /* out */
5212 unsigned int *chroma_v_offset, /* out */
5213 unsigned int *buffer_name, /* out */
5214 void **buffer /* out */
5217 VAStatus vaStatus = VA_STATUS_SUCCESS;
5218 struct i965_driver_data *i965 = i965_driver_data(ctx);
5219 struct object_surface *obj_surface = NULL;
5222 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5223 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5224 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5225 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5226 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5227 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5228 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5229 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5230 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5232 tmpImage.image_id = VA_INVALID_ID;
5234 obj_surface = SURFACE(surface);
5235 if (obj_surface == NULL) {
5236 // Surface is absent.
5237 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5241 // Lock functionality is absent now.
5242 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5243 // Surface is locked already.
5244 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5248 vaStatus = i965_DeriveImage(
5252 if (vaStatus != VA_STATUS_SUCCESS) {
5256 obj_surface->locked_image_id = tmpImage.image_id;
5258 vaStatus = i965_MapBuffer(
5262 if (vaStatus != VA_STATUS_SUCCESS) {
5266 *fourcc = tmpImage.format.fourcc;
5267 *luma_offset = tmpImage.offsets[0];
5268 *luma_stride = tmpImage.pitches[0];
5269 *chroma_u_offset = tmpImage.offsets[1];
5270 *chroma_u_stride = tmpImage.pitches[1];
5271 *chroma_v_offset = tmpImage.offsets[2];
5272 *chroma_v_stride = tmpImage.pitches[2];
5273 *buffer_name = tmpImage.buf;
5276 if (vaStatus != VA_STATUS_SUCCESS) {
5285 VADriverContextP ctx, /* in */
5286 VASurfaceID surface /* in */
5289 VAStatus vaStatus = VA_STATUS_SUCCESS;
5290 struct i965_driver_data *i965 = i965_driver_data(ctx);
5291 struct object_image *locked_img = NULL;
5292 struct object_surface *obj_surface = NULL;
5294 obj_surface = SURFACE(surface);
5296 if (obj_surface == NULL) {
5297 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5300 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5301 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5305 locked_img = IMAGE(obj_surface->locked_image_id);
5306 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5307 // Work image was deallocated before i965_UnlockSurface()
5308 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5312 vaStatus = i965_UnmapBuffer(
5314 locked_img->image.buf);
5315 if (vaStatus != VA_STATUS_SUCCESS) {
5319 vaStatus = i965_DestroyImage(
5321 locked_img->image.image_id);
5322 if (vaStatus != VA_STATUS_SUCCESS) {
5326 locked_img->image.image_id = VA_INVALID_ID;
5329 obj_surface->locked_image_id = VA_INVALID_ID;
5335 i965_GetSurfaceAttributes(
5336 VADriverContextP ctx,
5338 VASurfaceAttrib *attrib_list,
5339 unsigned int num_attribs
5342 VAStatus vaStatus = VA_STATUS_SUCCESS;
5343 struct i965_driver_data *i965 = i965_driver_data(ctx);
5344 struct object_config *obj_config;
5347 if (config == VA_INVALID_ID)
5348 return VA_STATUS_ERROR_INVALID_CONFIG;
5350 obj_config = CONFIG(config);
5352 if (obj_config == NULL)
5353 return VA_STATUS_ERROR_INVALID_CONFIG;
5355 if (attrib_list == NULL || num_attribs == 0)
5356 return VA_STATUS_ERROR_INVALID_PARAMETER;
5358 for (i = 0; i < num_attribs; i++) {
5359 switch (attrib_list[i].type) {
5360 case VASurfaceAttribPixelFormat:
5361 attrib_list[i].value.type = VAGenericValueTypeInteger;
5362 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5364 if (attrib_list[i].value.value.i == 0) {
5365 if (IS_G4X(i965->intel.device_info)) {
5366 if (obj_config->profile == VAProfileMPEG2Simple ||
5367 obj_config->profile == VAProfileMPEG2Main) {
5368 attrib_list[i].value.value.i = VA_FOURCC_I420;
5371 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5373 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5374 if (obj_config->profile == VAProfileMPEG2Simple ||
5375 obj_config->profile == VAProfileMPEG2Main) {
5376 attrib_list[i].value.value.i = VA_FOURCC_I420;
5377 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5378 obj_config->profile == VAProfileH264Main ||
5379 obj_config->profile == VAProfileH264High) {
5380 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5381 } else if (obj_config->profile == VAProfileNone) {
5382 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5385 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5387 } else if (IS_GEN6(i965->intel.device_info)) {
5388 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5389 } else if (IS_GEN7(i965->intel.device_info) ||
5390 IS_GEN8(i965->intel.device_info) ||
5391 IS_GEN9(i965->intel.device_info)) {
5392 if (obj_config->profile == VAProfileJPEGBaseline)
5393 attrib_list[i].value.value.i = 0; /* internal format */
5395 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5398 if (IS_G4X(i965->intel.device_info)) {
5399 if (obj_config->profile == VAProfileMPEG2Simple ||
5400 obj_config->profile == VAProfileMPEG2Main) {
5401 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5402 attrib_list[i].value.value.i = 0;
5403 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5407 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5409 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5410 if (obj_config->profile == VAProfileMPEG2Simple ||
5411 obj_config->profile == VAProfileMPEG2Main) {
5412 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5413 attrib_list[i].value.value.i = 0;
5414 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5416 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5417 obj_config->profile == VAProfileH264Main ||
5418 obj_config->profile == VAProfileH264High) {
5419 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5420 attrib_list[i].value.value.i = 0;
5421 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5423 } else if (obj_config->profile == VAProfileNone) {
5424 switch (attrib_list[i].value.value.i) {
5425 case VA_FOURCC_NV12:
5426 case VA_FOURCC_I420:
5427 case VA_FOURCC_YV12:
5428 case VA_FOURCC_YUY2:
5429 case VA_FOURCC_BGRA:
5430 case VA_FOURCC_BGRX:
5431 case VA_FOURCC_RGBX:
5432 case VA_FOURCC_RGBA:
5435 attrib_list[i].value.value.i = 0;
5436 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5441 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5443 } else if (IS_GEN6(i965->intel.device_info)) {
5444 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5445 obj_config->entrypoint == VAEntrypointVideoProc) {
5446 switch (attrib_list[i].value.value.i) {
5447 case VA_FOURCC_NV12:
5448 case VA_FOURCC_I420:
5449 case VA_FOURCC_YV12:
5450 case VA_FOURCC_YUY2:
5451 case VA_FOURCC_BGRA:
5452 case VA_FOURCC_BGRX:
5453 case VA_FOURCC_RGBX:
5454 case VA_FOURCC_RGBA:
5457 attrib_list[i].value.value.i = 0;
5458 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5462 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5463 attrib_list[i].value.value.i = 0;
5464 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5467 } else if (IS_GEN7(i965->intel.device_info) ||
5468 IS_GEN8(i965->intel.device_info) ||
5469 IS_GEN9(i965->intel.device_info)) {
5470 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5471 obj_config->entrypoint == VAEntrypointVideoProc ||
5472 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5473 switch (attrib_list[i].value.value.i) {
5474 case VA_FOURCC_NV12:
5475 case VA_FOURCC_I420:
5476 case VA_FOURCC_YV12:
5479 attrib_list[i].value.value.i = 0;
5480 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5484 if (obj_config->profile == VAProfileJPEGBaseline) {
5485 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5486 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5488 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5489 attrib_list[i].value.value.i = 0;
5490 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5498 case VASurfaceAttribMinWidth:
5499 /* FIXME: add support for it later */
5500 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5502 case VASurfaceAttribMaxWidth:
5503 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5505 case VASurfaceAttribMinHeight:
5506 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5508 case VASurfaceAttribMaxHeight:
5509 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5512 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5521 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5523 VASurfaceAttrib *attrib_list,
5524 unsigned int *num_attribs)
5526 VAStatus vaStatus = VA_STATUS_SUCCESS;
5527 struct i965_driver_data *i965 = i965_driver_data(ctx);
5528 struct object_config *obj_config;
5530 VASurfaceAttrib *attribs = NULL;
5534 if (config == VA_INVALID_ID)
5535 return VA_STATUS_ERROR_INVALID_CONFIG;
5537 obj_config = CONFIG(config);
5539 if (obj_config == NULL)
5540 return VA_STATUS_ERROR_INVALID_CONFIG;
5542 if (!attrib_list && !num_attribs)
5543 return VA_STATUS_ERROR_INVALID_PARAMETER;
5545 if (attrib_list == NULL) {
5546 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5547 return VA_STATUS_SUCCESS;
5550 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
5552 if (attribs == NULL)
5553 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5555 if (IS_G4X(i965->intel.device_info)) {
5556 if (obj_config->profile == VAProfileMPEG2Simple ||
5557 obj_config->profile == VAProfileMPEG2Main) {
5558 attribs[i].type = VASurfaceAttribPixelFormat;
5559 attribs[i].value.type = VAGenericValueTypeInteger;
5560 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5561 attribs[i].value.value.i = VA_FOURCC_I420;
5564 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5565 switch (obj_config->profile) {
5566 case VAProfileMPEG2Simple:
5567 case VAProfileMPEG2Main:
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_I420;
5576 case VAProfileH264ConstrainedBaseline:
5577 case VAProfileH264Main:
5578 case VAProfileH264High:
5579 attribs[i].type = VASurfaceAttribPixelFormat;
5580 attribs[i].value.type = VAGenericValueTypeInteger;
5581 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5582 attribs[i].value.value.i = VA_FOURCC_NV12;
5586 attribs[i].type = VASurfaceAttribPixelFormat;
5587 attribs[i].value.type = VAGenericValueTypeInteger;
5588 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5589 attribs[i].value.value.i = VA_FOURCC_NV12;
5592 attribs[i].type = VASurfaceAttribPixelFormat;
5593 attribs[i].value.type = VAGenericValueTypeInteger;
5594 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5595 attribs[i].value.value.i = VA_FOURCC_I420;
5603 } else if (IS_GEN6(i965->intel.device_info)) {
5604 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
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_NV12;
5610 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5611 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5612 attribs[i].type = VASurfaceAttribPixelFormat;
5613 attribs[i].value.type = VAGenericValueTypeInteger;
5614 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5615 attribs[i].value.value.i = VA_FOURCC_NV12;
5618 attribs[i].type = VASurfaceAttribPixelFormat;
5619 attribs[i].value.type = VAGenericValueTypeInteger;
5620 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5621 attribs[i].value.value.i = VA_FOURCC_I420;
5624 attribs[i].type = VASurfaceAttribPixelFormat;
5625 attribs[i].value.type = VAGenericValueTypeInteger;
5626 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5627 attribs[i].value.value.i = VA_FOURCC_YV12;
5630 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5631 attribs[i].type = VASurfaceAttribPixelFormat;
5632 attribs[i].value.type = VAGenericValueTypeInteger;
5633 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5634 attribs[i].value.value.i = VA_FOURCC_YUY2;
5637 attribs[i].type = VASurfaceAttribPixelFormat;
5638 attribs[i].value.type = VAGenericValueTypeInteger;
5639 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5640 attribs[i].value.value.i = VA_FOURCC_RGBA;
5643 attribs[i].type = VASurfaceAttribPixelFormat;
5644 attribs[i].value.type = VAGenericValueTypeInteger;
5645 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5646 attribs[i].value.value.i = VA_FOURCC_RGBX;
5650 } else if (IS_GEN7(i965->intel.device_info)) {
5651 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5652 if (obj_config->profile == VAProfileJPEGBaseline) {
5653 attribs[i].type = VASurfaceAttribPixelFormat;
5654 attribs[i].value.type = VAGenericValueTypeInteger;
5655 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5656 attribs[i].value.value.i = VA_FOURCC_IMC3;
5659 attribs[i].type = VASurfaceAttribPixelFormat;
5660 attribs[i].value.type = VAGenericValueTypeInteger;
5661 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5662 attribs[i].value.value.i = VA_FOURCC_IMC1;
5665 attribs[i].type = VASurfaceAttribPixelFormat;
5666 attribs[i].value.type = VAGenericValueTypeInteger;
5667 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5668 attribs[i].value.value.i = VA_FOURCC_Y800;
5671 attribs[i].type = VASurfaceAttribPixelFormat;
5672 attribs[i].value.type = VAGenericValueTypeInteger;
5673 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5674 attribs[i].value.value.i = VA_FOURCC_411P;
5677 attribs[i].type = VASurfaceAttribPixelFormat;
5678 attribs[i].value.type = VAGenericValueTypeInteger;
5679 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5680 attribs[i].value.value.i = VA_FOURCC_422H;
5683 attribs[i].type = VASurfaceAttribPixelFormat;
5684 attribs[i].value.type = VAGenericValueTypeInteger;
5685 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5686 attribs[i].value.value.i = VA_FOURCC_422V;
5689 attribs[i].type = VASurfaceAttribPixelFormat;
5690 attribs[i].value.type = VAGenericValueTypeInteger;
5691 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5692 attribs[i].value.value.i = VA_FOURCC_444P;
5694 } else if (obj_config->profile == VAProfileHEVCMain10) {
5695 attribs[i].type = VASurfaceAttribPixelFormat;
5696 attribs[i].value.type = VAGenericValueTypeInteger;
5697 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5698 attribs[i].value.value.i = VA_FOURCC_P010;
5701 attribs[i].type = VASurfaceAttribPixelFormat;
5702 attribs[i].value.type = VAGenericValueTypeInteger;
5703 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5704 attribs[i].value.value.i = VA_FOURCC_NV12;
5707 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5708 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5709 attribs[i].type = VASurfaceAttribPixelFormat;
5710 attribs[i].value.type = VAGenericValueTypeInteger;
5711 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5712 attribs[i].value.value.i = VA_FOURCC_NV12;
5715 attribs[i].type = VASurfaceAttribPixelFormat;
5716 attribs[i].value.type = VAGenericValueTypeInteger;
5717 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5718 attribs[i].value.value.i = VA_FOURCC_I420;
5721 attribs[i].type = VASurfaceAttribPixelFormat;
5722 attribs[i].value.type = VAGenericValueTypeInteger;
5723 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5724 attribs[i].value.value.i = VA_FOURCC_YV12;
5727 attribs[i].type = VASurfaceAttribPixelFormat;
5728 attribs[i].value.type = VAGenericValueTypeInteger;
5729 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5730 attribs[i].value.value.i = VA_FOURCC_IMC3;
5733 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5734 attribs[i].type = VASurfaceAttribPixelFormat;
5735 attribs[i].value.type = VAGenericValueTypeInteger;
5736 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5737 attribs[i].value.value.i = VA_FOURCC_YUY2;
5740 attribs[i].type = VASurfaceAttribPixelFormat;
5741 attribs[i].value.type = VAGenericValueTypeInteger;
5742 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5743 attribs[i].value.value.i = VA_FOURCC_RGBA;
5746 attribs[i].type = VASurfaceAttribPixelFormat;
5747 attribs[i].value.type = VAGenericValueTypeInteger;
5748 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5749 attribs[i].value.value.i = VA_FOURCC_RGBX;
5752 attribs[i].type = VASurfaceAttribPixelFormat;
5753 attribs[i].value.type = VAGenericValueTypeInteger;
5754 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5755 attribs[i].value.value.i = VA_FOURCC_BGRA;
5758 attribs[i].type = VASurfaceAttribPixelFormat;
5759 attribs[i].value.type = VAGenericValueTypeInteger;
5760 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5761 attribs[i].value.value.i = VA_FOURCC_BGRX;
5764 attribs[i].type = VASurfaceAttribPixelFormat;
5765 attribs[i].value.type = VAGenericValueTypeInteger;
5766 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5767 attribs[i].value.value.i = VA_FOURCC_YV16;
5771 } else if (IS_GEN8(i965->intel.device_info) ||
5772 IS_GEN9(i965->intel.device_info)) {
5773 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5774 if (obj_config->profile == VAProfileJPEGBaseline) {
5775 attribs[i].type = VASurfaceAttribPixelFormat;
5776 attribs[i].value.type = VAGenericValueTypeInteger;
5777 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5778 attribs[i].value.value.i = VA_FOURCC_IMC3;
5781 attribs[i].type = VASurfaceAttribPixelFormat;
5782 attribs[i].value.type = VAGenericValueTypeInteger;
5783 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5784 attribs[i].value.value.i = VA_FOURCC_IMC1;
5787 attribs[i].type = VASurfaceAttribPixelFormat;
5788 attribs[i].value.type = VAGenericValueTypeInteger;
5789 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5790 attribs[i].value.value.i = VA_FOURCC_Y800;
5793 attribs[i].type = VASurfaceAttribPixelFormat;
5794 attribs[i].value.type = VAGenericValueTypeInteger;
5795 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5796 attribs[i].value.value.i = VA_FOURCC_411P;
5799 attribs[i].type = VASurfaceAttribPixelFormat;
5800 attribs[i].value.type = VAGenericValueTypeInteger;
5801 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5802 attribs[i].value.value.i = VA_FOURCC_422H;
5805 attribs[i].type = VASurfaceAttribPixelFormat;
5806 attribs[i].value.type = VAGenericValueTypeInteger;
5807 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5808 attribs[i].value.value.i = VA_FOURCC_422V;
5811 attribs[i].type = VASurfaceAttribPixelFormat;
5812 attribs[i].value.type = VAGenericValueTypeInteger;
5813 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5814 attribs[i].value.value.i = VA_FOURCC_444P;
5817 attribs[i].type = VASurfaceAttribPixelFormat;
5818 attribs[i].value.type = VAGenericValueTypeInteger;
5819 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5820 attribs[i].value.value.i = VA_FOURCC_NV12;
5823 if ((obj_config->profile == VAProfileHEVCMain10) ||
5824 (obj_config->profile == VAProfileVP9Profile2)) {
5825 attribs[i].type = VASurfaceAttribPixelFormat;
5826 attribs[i].value.type = VAGenericValueTypeInteger;
5827 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5828 attribs[i].value.value.i = VA_FOURCC_P010;
5832 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5833 obj_config->entrypoint == VAEntrypointVideoProc ||
5834 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5836 if (obj_config->profile == VAProfileHEVCMain10) {
5837 attribs[i].type = VASurfaceAttribPixelFormat;
5838 attribs[i].value.type = VAGenericValueTypeInteger;
5839 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5840 attribs[i].value.value.i = VA_FOURCC_P010;
5843 attribs[i].type = VASurfaceAttribPixelFormat;
5844 attribs[i].value.type = VAGenericValueTypeInteger;
5845 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5846 attribs[i].value.value.i = VA_FOURCC_NV12;
5849 attribs[i].type = VASurfaceAttribPixelFormat;
5850 attribs[i].value.type = VAGenericValueTypeInteger;
5851 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5852 attribs[i].value.value.i = VA_FOURCC_I420;
5855 attribs[i].type = VASurfaceAttribPixelFormat;
5856 attribs[i].value.type = VAGenericValueTypeInteger;
5857 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5858 attribs[i].value.value.i = VA_FOURCC_YV12;
5861 attribs[i].type = VASurfaceAttribPixelFormat;
5862 attribs[i].value.type = VAGenericValueTypeInteger;
5863 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5864 attribs[i].value.value.i = VA_FOURCC_IMC3;
5868 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5869 attribs[i].type = VASurfaceAttribPixelFormat;
5870 attribs[i].value.type = VAGenericValueTypeInteger;
5871 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5872 attribs[i].value.value.i = VA_FOURCC_YUY2;
5875 attribs[i].type = VASurfaceAttribPixelFormat;
5876 attribs[i].value.type = VAGenericValueTypeInteger;
5877 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5878 attribs[i].value.value.i = VA_FOURCC_RGBA;
5881 attribs[i].type = VASurfaceAttribPixelFormat;
5882 attribs[i].value.type = VAGenericValueTypeInteger;
5883 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5884 attribs[i].value.value.i = VA_FOURCC_RGBX;
5887 attribs[i].type = VASurfaceAttribPixelFormat;
5888 attribs[i].value.type = VAGenericValueTypeInteger;
5889 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5890 attribs[i].value.value.i = VA_FOURCC_BGRA;
5893 attribs[i].type = VASurfaceAttribPixelFormat;
5894 attribs[i].value.type = VAGenericValueTypeInteger;
5895 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5896 attribs[i].value.value.i = VA_FOURCC_BGRX;
5899 attribs[i].type = VASurfaceAttribPixelFormat;
5900 attribs[i].value.type = VAGenericValueTypeInteger;
5901 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5902 attribs[i].value.value.i = VA_FOURCC_YV16;
5905 if(HAS_VPP_P010(i965)) {
5906 attribs[i].type = VASurfaceAttribPixelFormat;
5907 attribs[i].value.type = VAGenericValueTypeInteger;
5908 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5909 attribs[i].value.value.i = VA_FOURCC_P010;
5916 attribs[i].type = VASurfaceAttribMemoryType;
5917 attribs[i].value.type = VAGenericValueTypeInteger;
5918 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5919 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
5920 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
5921 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
5924 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
5925 attribs[i].value.type = VAGenericValueTypePointer;
5926 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
5927 attribs[i].value.value.p = NULL; /* ignore */
5930 max_resolution(i965, obj_config, &max_width, &max_height);
5932 attribs[i].type = VASurfaceAttribMaxWidth;
5933 attribs[i].value.type = VAGenericValueTypeInteger;
5934 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5935 attribs[i].value.value.i = max_width;
5938 attribs[i].type = VASurfaceAttribMaxHeight;
5939 attribs[i].value.type = VAGenericValueTypeInteger;
5940 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5941 attribs[i].value.value.i = max_height;
5944 if (i > *num_attribs) {
5947 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5951 memcpy(attrib_list, attribs, i * sizeof(*attribs));
5957 /* Acquires buffer handle for external API usage (internal implementation) */
5959 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
5960 uint32_t mem_type, VABufferInfo *out_buf_info)
5962 struct buffer_store *buffer_store;
5964 buffer_store = obj_buffer->buffer_store;
5965 if (!buffer_store || !buffer_store->bo)
5966 return VA_STATUS_ERROR_INVALID_BUFFER;
5968 /* Synchronization point */
5969 drm_intel_bo_wait_rendering(buffer_store->bo);
5971 if (obj_buffer->export_refcount > 0) {
5972 if (obj_buffer->export_state.mem_type != mem_type)
5973 return VA_STATUS_ERROR_INVALID_PARAMETER;
5976 VABufferInfo * const buf_info = &obj_buffer->export_state;
5979 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
5981 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
5982 return VA_STATUS_ERROR_INVALID_BUFFER;
5983 buf_info->handle = name;
5986 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5988 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
5989 return VA_STATUS_ERROR_INVALID_BUFFER;
5990 buf_info->handle = (intptr_t)fd;
5995 buf_info->type = obj_buffer->type;
5996 buf_info->mem_type = mem_type;
5997 buf_info->mem_size =
5998 obj_buffer->num_elements * obj_buffer->size_element;
6001 obj_buffer->export_refcount++;
6002 *out_buf_info = obj_buffer->export_state;
6003 return VA_STATUS_SUCCESS;
6006 /* Releases buffer handle after usage (internal implementation) */
6008 i965_release_buffer_handle(struct object_buffer *obj_buffer)
6010 if (obj_buffer->export_refcount == 0)
6011 return VA_STATUS_ERROR_INVALID_BUFFER;
6013 if (--obj_buffer->export_refcount == 0) {
6014 VABufferInfo * const buf_info = &obj_buffer->export_state;
6016 switch (buf_info->mem_type) {
6017 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
6018 close((intptr_t)buf_info->handle);
6022 buf_info->mem_type = 0;
6024 return VA_STATUS_SUCCESS;
6027 /** Acquires buffer handle for external API usage */
6029 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6030 VABufferInfo *buf_info)
6032 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6033 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6034 uint32_t i, mem_type;
6036 /* List of supported memory types, in preferred order */
6037 static const uint32_t mem_types[] = {
6038 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6039 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6044 return VA_STATUS_ERROR_INVALID_BUFFER;
6045 /* XXX: only VA surface|image like buffers are supported for now */
6046 if (obj_buffer->type != VAImageBufferType)
6047 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6050 * As the allocated buffer by calling vaCreateBuffer is related with
6051 * the specific context, it is unnecessary to export it.
6052 * So it is not supported when the buffer is allocated from wrapped
6055 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6056 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6060 return VA_STATUS_ERROR_INVALID_PARAMETER;
6062 if (!buf_info->mem_type)
6063 mem_type = mem_types[0];
6066 for (i = 0; mem_types[i] != 0; i++) {
6067 if (buf_info->mem_type & mem_types[i]) {
6068 mem_type = buf_info->mem_type;
6073 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6075 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6078 /** Releases buffer handle after usage from external API */
6080 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6082 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6083 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6086 return VA_STATUS_ERROR_INVALID_BUFFER;
6088 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6089 return VA_STATUS_ERROR_INVALID_BUFFER;
6092 return i965_release_buffer_handle(obj_buffer);
6096 i965_os_has_ring_support(VADriverContextP ctx,
6099 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6103 return i965->intel.has_bsd;
6106 return i965->intel.has_blt;
6108 case I965_RING_VEBOX:
6109 return i965->intel.has_vebox;
6111 case I965_RING_NULL:
6112 return 1; /* Always support */
6115 /* should never get here */
6124 * Query video processing pipeline
6126 VAStatus i965_QueryVideoProcFilters(
6127 VADriverContextP ctx,
6128 VAContextID context,
6129 VAProcFilterType *filters,
6130 unsigned int *num_filters
6133 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6134 unsigned int i = 0, num = 0;
6136 if (!num_filters || !filters)
6137 return VA_STATUS_ERROR_INVALID_PARAMETER;
6139 for (i = 0; i < i965->codec_info->num_filters; i++) {
6140 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6141 if (num == *num_filters) {
6142 *num_filters = i965->codec_info->num_filters;
6144 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6147 filters[num++] = i965->codec_info->filters[i].type;
6153 return VA_STATUS_SUCCESS;
6156 VAStatus i965_QueryVideoProcFilterCaps(
6157 VADriverContextP ctx,
6158 VAContextID context,
6159 VAProcFilterType type,
6161 unsigned int *num_filter_caps
6165 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6167 if (!filter_caps || !num_filter_caps)
6168 return VA_STATUS_ERROR_INVALID_PARAMETER;
6170 for (i = 0; i < i965->codec_info->num_filters; i++) {
6171 if (type == i965->codec_info->filters[i].type &&
6172 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6176 if (i == i965->codec_info->num_filters)
6177 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6182 case VAProcFilterNoiseReduction:
6183 case VAProcFilterSharpening:
6185 VAProcFilterCap *cap = filter_caps;
6187 if (*num_filter_caps < 1) {
6188 *num_filter_caps = 1;
6189 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6192 cap->range.min_value = 0.0;
6193 cap->range.max_value = 1.0;
6194 cap->range.default_value = 0.5;
6195 cap->range.step = 0.03125; /* 1.0 / 32 */
6201 case VAProcFilterDeinterlacing:
6203 VAProcFilterCapDeinterlacing *cap = filter_caps;
6205 if (*num_filter_caps < VAProcDeinterlacingCount) {
6206 *num_filter_caps = VAProcDeinterlacingCount;
6207 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6210 cap->type = VAProcDeinterlacingBob;
6215 if (i965->codec_info->has_di_motion_adptive) {
6216 cap->type = VAProcDeinterlacingMotionAdaptive;
6221 if (i965->codec_info->has_di_motion_compensated) {
6222 cap->type = VAProcDeinterlacingMotionCompensated;
6230 case VAProcFilterColorBalance:
6232 VAProcFilterCapColorBalance *cap = filter_caps;
6234 if (*num_filter_caps < VAProcColorBalanceCount) {
6235 *num_filter_caps = VAProcColorBalanceCount;
6236 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6239 cap->type = VAProcColorBalanceHue;
6240 cap->range.min_value = -180.0;
6241 cap->range.max_value = 180.0;
6242 cap->range.default_value = 0.0;
6243 cap->range.step = 1.0;
6247 cap->type = VAProcColorBalanceSaturation;
6248 cap->range.min_value = 0.0;
6249 cap->range.max_value = 10.0;
6250 cap->range.default_value = 1.0;
6251 cap->range.step = 0.1;
6255 cap->type = VAProcColorBalanceBrightness;
6256 cap->range.min_value = -100.0;
6257 cap->range.max_value = 100.0;
6258 cap->range.default_value = 0.0;
6259 cap->range.step = 1.0;
6263 cap->type = VAProcColorBalanceContrast;
6264 cap->range.min_value = 0.0;
6265 cap->range.max_value = 10.0;
6266 cap->range.default_value = 1.0;
6267 cap->range.step = 0.1;
6279 *num_filter_caps = i;
6281 return VA_STATUS_SUCCESS;
6284 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6285 VAProcColorStandardBT601,
6288 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6289 VAProcColorStandardBT601,
6292 VAStatus i965_QueryVideoProcPipelineCaps(
6293 VADriverContextP ctx,
6294 VAContextID context,
6295 VABufferID *filters,
6296 unsigned int num_filters,
6297 VAProcPipelineCaps *pipeline_cap /* out */
6300 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6303 pipeline_cap->pipeline_flags = 0;
6304 pipeline_cap->filter_flags = 0;
6305 pipeline_cap->num_forward_references = 0;
6306 pipeline_cap->num_backward_references = 0;
6307 pipeline_cap->num_input_color_standards = 1;
6308 pipeline_cap->input_color_standards = vpp_input_color_standards;
6309 pipeline_cap->num_output_color_standards = 1;
6310 pipeline_cap->output_color_standards = vpp_output_color_standards;
6312 for (i = 0; i < num_filters; i++) {
6313 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6316 !obj_buffer->buffer_store ||
6317 !obj_buffer->buffer_store->buffer)
6318 return VA_STATUS_ERROR_INVALID_BUFFER;
6320 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6322 if (base->type == VAProcFilterNoiseReduction) {
6323 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6325 } else if (base->type == VAProcFilterDeinterlacing) {
6326 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6328 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6329 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6330 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6331 VA_STATUS_ERROR_INVALID_PARAMETER);
6333 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6334 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6335 pipeline_cap->num_forward_references++;
6336 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6337 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6342 return VA_STATUS_SUCCESS;
6345 extern struct hw_codec_info *i965_get_codec_info(int devid);
6348 i965_driver_data_init(VADriverContextP ctx)
6350 struct i965_driver_data *i965 = i965_driver_data(ctx);
6352 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6354 if (!i965->codec_info)
6357 if (object_heap_init(&i965->config_heap,
6358 sizeof(struct object_config),
6360 goto err_config_heap;
6361 if (object_heap_init(&i965->context_heap,
6362 sizeof(struct object_context),
6364 goto err_context_heap;
6366 if (object_heap_init(&i965->surface_heap,
6367 sizeof(struct object_surface),
6369 goto err_surface_heap;
6370 if (object_heap_init(&i965->buffer_heap,
6371 sizeof(struct object_buffer),
6373 goto err_buffer_heap;
6374 if (object_heap_init(&i965->image_heap,
6375 sizeof(struct object_image),
6377 goto err_image_heap;
6378 if (object_heap_init(&i965->subpic_heap,
6379 sizeof(struct object_subpic),
6381 goto err_subpic_heap;
6383 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6384 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6385 _i965InitMutex(&i965->render_mutex);
6386 _i965InitMutex(&i965->pp_mutex);
6391 object_heap_destroy(&i965->image_heap);
6393 object_heap_destroy(&i965->buffer_heap);
6395 object_heap_destroy(&i965->surface_heap);
6397 object_heap_destroy(&i965->context_heap);
6399 object_heap_destroy(&i965->config_heap);
6406 i965_driver_data_terminate(VADriverContextP ctx)
6408 struct i965_driver_data *i965 = i965_driver_data(ctx);
6410 _i965DestroyMutex(&i965->pp_mutex);
6411 _i965DestroyMutex(&i965->render_mutex);
6414 intel_batchbuffer_free(i965->batch);
6417 intel_batchbuffer_free(i965->pp_batch);
6419 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6420 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6421 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6422 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6423 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6424 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6428 bool (*init)(VADriverContextP ctx);
6429 void (*terminate)(VADriverContextP ctx);
6431 } i965_sub_ops[] = {
6434 intel_driver_terminate,
6439 i965_driver_data_init,
6440 i965_driver_data_terminate,
6445 i965_display_attributes_init,
6446 i965_display_attributes_terminate,
6451 i965_post_processing_init,
6452 i965_post_processing_terminate,
6458 i965_render_terminate,
6462 #ifdef HAVE_VA_WAYLAND
6464 i965_output_wayland_init,
6465 i965_output_wayland_terminate,
6472 i965_output_dri_init,
6473 i965_output_dri_terminate,
6480 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6484 if (i965->va_vendor[0] != '\0')
6488 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6489 "%s %s driver for %s - %d.%d.%d",
6490 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6491 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6492 INTEL_DRIVER_MICRO_VERSION);
6493 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6497 if (INTEL_DRIVER_PRE_VERSION > 0) {
6498 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6499 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6500 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6504 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6505 " (%s)", INTEL_DRIVER_GIT_VERSION);
6506 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6513 i965->va_vendor[0] = '\0';
6514 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6518 /* Only when the option of "enable-wrapper" is passed, it is possible
6519 * to initialize/load the wrapper context of backend driver.
6520 * Otherwise it is not loaded.
6522 #if HAVE_HYBRID_CODEC
6525 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6527 #define DRIVER_EXTENSION "_drv_video.so"
6529 struct i965_driver_data *i965 = i965_driver_data(ctx);
6531 VADriverContextP wrapper_pdrvctx;
6532 struct VADriverVTable *vtable;
6533 char *search_path, *driver_dir;
6535 char driver_path[256];
6536 void *handle = NULL;
6537 VAStatus va_status = VA_STATUS_SUCCESS;
6538 bool driver_loaded = false;
6540 if (HAS_VP9_DECODING(i965)) {
6541 i965->wrapper_pdrvctx = NULL;
6545 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6546 vtable = calloc(1, sizeof(*vtable));
6548 if (!wrapper_pdrvctx || !vtable) {
6549 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6550 free(wrapper_pdrvctx);
6552 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6555 /* use the same drm_state with CTX */
6556 wrapper_pdrvctx->drm_state = ctx->drm_state;
6557 wrapper_pdrvctx->display_type = ctx->display_type;
6558 wrapper_pdrvctx->vtable = vtable;
6560 search_path = VA_DRIVERS_PATH;
6561 search_path = strdup((const char *)search_path);
6563 driver_dir = strtok_r(search_path, ":", &saveptr);
6564 while (driver_dir && !driver_loaded) {
6565 memset(driver_path, 0, sizeof(driver_path));
6566 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6568 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6570 fprintf(stderr, "failed to open %s\n", driver_path);
6571 driver_dir = strtok_r(NULL, ":", &saveptr);
6575 VADriverInit init_func = NULL;
6576 char init_func_s[256];
6579 static const struct {
6582 } compatible_versions[] = {
6583 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6592 for (i = 0; compatible_versions[i].major >= 0; i++) {
6593 snprintf(init_func_s, sizeof(init_func_s),
6594 "__vaDriverInit_%d_%d",
6595 compatible_versions[i].major,
6596 compatible_versions[i].minor);
6597 init_func = (VADriverInit)dlsym(handle, init_func_s);
6602 if (compatible_versions[i].major < 0) {
6604 fprintf(stderr, "%s has no function %s\n",
6605 driver_path, init_func_s);
6606 driver_dir = strtok_r(NULL, ":", &saveptr);
6611 va_status = (*init_func)(wrapper_pdrvctx);
6613 if (va_status != VA_STATUS_SUCCESS) {
6615 fprintf(stderr, "%s init failed\n", driver_path);
6616 driver_dir = strtok_r(NULL, ":", &saveptr);
6620 wrapper_pdrvctx->handle = handle;
6621 driver_loaded = true;
6627 if (driver_loaded) {
6628 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6629 return VA_STATUS_SUCCESS;
6631 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6633 free(wrapper_pdrvctx);
6634 return VA_STATUS_ERROR_OPERATION_FAILED;
6640 i965_Init(VADriverContextP ctx)
6642 struct i965_driver_data *i965 = i965_driver_data(ctx);
6644 const char *chipset;
6646 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6647 if ((i965_sub_ops[i].display_type == 0 ||
6648 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6649 !i965_sub_ops[i].init(ctx))
6653 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6654 switch (i965->intel.device_id) {
6656 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6657 #include "i965_pciids.h"
6659 chipset = "Unknown Intel Chipset";
6663 if (!ensure_vendor_string(i965, chipset))
6664 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6666 i965->current_context_id = VA_INVALID_ID;
6668 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6669 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6671 #if HAVE_HYBRID_CODEC
6672 i965_initialize_wrapper(ctx, "hybrid");
6675 return VA_STATUS_SUCCESS;
6679 for (; i >= 0; i--) {
6680 if (i965_sub_ops[i].display_type == 0 ||
6681 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6682 i965_sub_ops[i].terminate(ctx);
6686 return VA_STATUS_ERROR_UNKNOWN;
6691 i965_Terminate(VADriverContextP ctx)
6693 struct i965_driver_data *i965 = i965_driver_data(ctx);
6697 if (i965->wrapper_pdrvctx) {
6698 VADriverContextP pdrvctx;
6699 pdrvctx = i965->wrapper_pdrvctx;
6700 if (pdrvctx->handle) {
6701 pdrvctx->vtable->vaTerminate(pdrvctx);
6702 dlclose(pdrvctx->handle);
6703 pdrvctx->handle = NULL;
6705 free(pdrvctx->vtable);
6707 i965->wrapper_pdrvctx = NULL;
6710 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6711 if (i965_sub_ops[i - 1].display_type == 0 ||
6712 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6713 i965_sub_ops[i - 1].terminate(ctx);
6717 ctx->pDriverData = NULL;
6720 return VA_STATUS_SUCCESS;
6724 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6727 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
6729 struct VADriverVTable * const vtable = ctx->vtable;
6730 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6732 struct i965_driver_data *i965;
6733 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6735 ctx->version_major = VA_MAJOR_VERSION;
6736 ctx->version_minor = VA_MINOR_VERSION;
6737 ctx->max_profiles = I965_MAX_PROFILES;
6738 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6739 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6740 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6741 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6742 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6744 vtable->vaTerminate = i965_Terminate;
6745 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6746 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6747 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6748 vtable->vaCreateConfig = i965_CreateConfig;
6749 vtable->vaDestroyConfig = i965_DestroyConfig;
6750 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6751 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6752 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6753 vtable->vaCreateContext = i965_CreateContext;
6754 vtable->vaDestroyContext = i965_DestroyContext;
6755 vtable->vaCreateBuffer = i965_CreateBuffer;
6756 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
6757 vtable->vaMapBuffer = i965_MapBuffer;
6758 vtable->vaUnmapBuffer = i965_UnmapBuffer;
6759 vtable->vaDestroyBuffer = i965_DestroyBuffer;
6760 vtable->vaBeginPicture = i965_BeginPicture;
6761 vtable->vaRenderPicture = i965_RenderPicture;
6762 vtable->vaEndPicture = i965_EndPicture;
6763 vtable->vaSyncSurface = i965_SyncSurface;
6764 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
6765 vtable->vaPutSurface = i965_PutSurface;
6766 vtable->vaQueryImageFormats = i965_QueryImageFormats;
6767 vtable->vaCreateImage = i965_CreateImage;
6768 vtable->vaDeriveImage = i965_DeriveImage;
6769 vtable->vaDestroyImage = i965_DestroyImage;
6770 vtable->vaSetImagePalette = i965_SetImagePalette;
6771 vtable->vaGetImage = i965_GetImage;
6772 vtable->vaPutImage = i965_PutImage;
6773 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
6774 vtable->vaCreateSubpicture = i965_CreateSubpicture;
6775 vtable->vaDestroySubpicture = i965_DestroySubpicture;
6776 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
6777 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
6778 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
6779 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
6780 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
6781 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
6782 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
6783 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
6784 vtable->vaBufferInfo = i965_BufferInfo;
6785 vtable->vaLockSurface = i965_LockSurface;
6786 vtable->vaUnlockSurface = i965_UnlockSurface;
6787 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
6788 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
6789 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
6792 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
6793 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
6795 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
6796 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
6797 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
6799 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
6802 ctx->pDriverData = NULL;
6804 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6807 i965->wrapper_pdrvctx = NULL;
6808 ctx->pDriverData = (void *)i965;
6809 ret = i965_Init(ctx);
6811 if (ret == VA_STATUS_SUCCESS) {
6812 ctx->str_vendor = i965->va_vendor;
6815 ctx->pDriverData = NULL;