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)
123 #define HAS_HEVC10_ENCODING(ctx) ((ctx)->codec_info->has_hevc10_encoding && \
124 (ctx)->intel.has_bsd)
126 #define HAS_VPP_P010(ctx) ((ctx)->codec_info->has_vpp_p010 && \
127 (ctx)->intel.has_bsd)
129 #define HAS_VP9_ENCODING(ctx) ((ctx)->codec_info->has_vp9_encoding && \
130 (ctx)->intel.has_bsd)
132 static int get_sampling_from_fourcc(unsigned int fourcc);
134 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
135 #define IS_VA_X11(ctx) \
136 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
138 /* Check whether we are rendering to Wayland */
139 #define IS_VA_WAYLAND(ctx) \
140 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
143 #define I965_2BITS (I965_BIT << 1)
144 #define I965_4BITS (I965_BIT << 2)
145 #define I965_8BITS (I965_BIT << 3)
146 #define I965_16BITS (I965_BIT << 4)
147 #define I965_32BITS (I965_BIT << 5)
159 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
160 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
161 #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} }
162 #define I_IYUV I_I420
163 #define I_IMC3 I_I420
164 #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} }
165 #define I_IMC1 I_YV12
167 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
169 #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} }
170 #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} }
171 #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} }
172 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
173 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
175 #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} }
177 #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} }
179 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
181 #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} }
182 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
183 #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} }
184 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
186 #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} }
187 #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} }
189 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
190 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
192 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
193 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
198 #define I_SI (I_S | I_I)
200 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
201 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
202 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
203 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
205 static const i965_fourcc_info i965_fourcc_infos[] = {
206 DEF_YUV(NV12, YUV420, I_SI),
207 DEF_YUV(I420, YUV420, I_SI),
208 DEF_YUV(IYUV, YUV420, I_S),
209 DEF_YUV(IMC3, YUV420, I_S),
210 DEF_YUV(YV12, YUV420, I_SI),
211 DEF_YUV(IMC1, YUV420, I_S),
213 DEF_YUV(P010, YUV420, I_SI),
215 DEF_YUV(422H, YUV422H, I_SI),
216 DEF_YUV(422V, YUV422V, I_S),
217 DEF_YUV(YV16, YUV422H, I_S),
218 DEF_YUV(YUY2, YUV422H, I_SI),
219 DEF_YUV(UYVY, YUV422H, I_SI),
221 DEF_YUV(444P, YUV444, I_S),
223 DEF_YUV(411P, YUV411, I_S),
225 DEF_YUV(Y800, YUV400, I_S),
227 DEF_RGB(RGBA, RGBX, I_SI),
228 DEF_RGB(RGBX, RGBX, I_SI),
229 DEF_RGB(BGRA, RGBX, I_SI),
230 DEF_RGB(BGRX, RGBX, I_SI),
232 DEF_RGB(ARGB, RGBX, I_I),
233 DEF_RGB(ABGR, RGBX, I_I),
235 DEF_INDEX(IA88, RGBX, I_I),
236 DEF_INDEX(AI88, RGBX, I_I),
238 DEF_INDEX(IA44, RGBX, I_I),
239 DEF_INDEX(AI44, RGBX, I_I)
242 const i965_fourcc_info *
243 get_fourcc_info(unsigned int fourcc)
247 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
248 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
250 if (info->fourcc == fourcc)
258 get_bpp_from_fourcc(unsigned int fourcc)
260 const i965_fourcc_info *info = get_fourcc_info(fourcc);
262 unsigned int bpp = 0;
267 for (i = 0; i < info->num_planes; i++)
274 I965_SURFACETYPE_RGBA = 1,
275 I965_SURFACETYPE_YUV,
276 I965_SURFACETYPE_INDEXED
279 /* List of supported display attributes */
280 static const VADisplayAttribute i965_display_attributes[] = {
282 VADisplayAttribBrightness,
283 -100, 100, DEFAULT_BRIGHTNESS,
284 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
288 VADisplayAttribContrast,
289 0, 100, DEFAULT_CONTRAST,
290 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
295 -180, 180, DEFAULT_HUE,
296 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
300 VADisplayAttribSaturation,
301 0, 100, DEFAULT_SATURATION,
302 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
306 VADisplayAttribRotation,
307 0, 3, VA_ROTATION_NONE,
308 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
312 /* List of supported image formats */
315 VAImageFormat va_format;
316 } i965_image_format_map_t;
318 static const i965_image_format_map_t
319 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
320 { I965_SURFACETYPE_YUV,
321 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
322 { I965_SURFACETYPE_YUV,
323 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
324 { I965_SURFACETYPE_YUV,
325 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
326 { I965_SURFACETYPE_YUV,
327 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
328 { I965_SURFACETYPE_YUV,
329 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
330 { I965_SURFACETYPE_YUV,
331 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
332 { I965_SURFACETYPE_RGBA,
333 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
334 { I965_SURFACETYPE_RGBA,
335 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
336 { I965_SURFACETYPE_YUV,
337 { VA_FOURCC_P010, VA_LSB_FIRST, 24, } },
340 /* List of supported subpicture formats */
344 VAImageFormat va_format;
345 unsigned int va_flags;
346 } i965_subpic_format_map_t;
348 #define COMMON_SUBPICTURE_FLAGS \
349 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
350 VA_SUBPICTURE_GLOBAL_ALPHA)
352 static const i965_subpic_format_map_t
353 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
354 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
355 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
356 COMMON_SUBPICTURE_FLAGS },
357 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
358 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
359 COMMON_SUBPICTURE_FLAGS },
360 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
361 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
362 COMMON_SUBPICTURE_FLAGS },
363 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
364 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
365 COMMON_SUBPICTURE_FLAGS },
366 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
367 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
368 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
369 COMMON_SUBPICTURE_FLAGS },
370 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
371 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
372 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
373 COMMON_SUBPICTURE_FLAGS },
376 static const i965_subpic_format_map_t *
377 get_subpic_format(const VAImageFormat *va_format)
380 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
381 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
382 if (m->va_format.fourcc == va_format->fourcc &&
383 (m->type == I965_SURFACETYPE_RGBA ?
384 (m->va_format.byte_order == va_format->byte_order &&
385 m->va_format.red_mask == va_format->red_mask &&
386 m->va_format.green_mask == va_format->green_mask &&
387 m->va_format.blue_mask == va_format->blue_mask &&
388 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
394 /* Checks whether the surface is in busy state */
396 is_surface_busy(struct i965_driver_data *i965,
397 struct object_surface *obj_surface)
399 assert(obj_surface != NULL);
401 if (obj_surface->locked_image_id != VA_INVALID_ID)
403 if (obj_surface->derived_image_id != VA_INVALID_ID)
408 /* Checks whether the image is in busy state */
410 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
412 struct object_buffer *obj_buffer;
414 assert(obj_image != NULL);
416 if (obj_image->derived_surface != VA_INVALID_ID &&
417 obj_image->derived_surface == surface)
420 obj_buffer = BUFFER(obj_image->image.buf);
421 if (obj_buffer && obj_buffer->export_refcount > 0)
426 #define I965_PACKED_HEADER_BASE 0
427 #define I965_SEQ_PACKED_HEADER_BASE 0
428 #define I965_SEQ_PACKED_HEADER_END 2
429 #define I965_PIC_PACKED_HEADER_BASE 2
430 #define I965_PACKED_MISC_HEADER_BASE 4
433 va_enc_packed_type_to_idx(int packed_type)
437 if (packed_type & VAEncPackedHeaderMiscMask) {
438 idx = I965_PACKED_MISC_HEADER_BASE;
439 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
440 ASSERT_RET(packed_type > 0, 0);
441 idx += (packed_type - 1);
443 idx = I965_PACKED_HEADER_BASE;
445 switch (packed_type) {
446 case VAEncPackedHeaderSequence:
447 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
450 case VAEncPackedHeaderPicture:
451 idx = I965_PIC_PACKED_HEADER_BASE + 0;
454 case VAEncPackedHeaderSlice:
455 idx = I965_PIC_PACKED_HEADER_BASE + 1;
459 /* Should not get here */
465 ASSERT_RET(idx < 5, 0);
469 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
472 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
474 struct i965_driver_data *i965 = i965_driver_data(ctx);
475 struct object_surface *obj_surface = SURFACE(surface);
476 VAStatus va_status = VA_STATUS_SUCCESS;
479 return VA_STATUS_ERROR_INVALID_SURFACE;
482 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
483 /* the wrapped surface already exists. just return it */
487 if (obj_surface->fourcc == 0)
488 i965_check_alloc_surface_bo(ctx, obj_surface,
489 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
492 * TBD: Support more surface formats.
493 * Currently only NV12 is support as NV12 is used by decoding.
495 if (obj_surface->fourcc != VA_FOURCC_NV12 )
496 return VA_STATUS_ERROR_INVALID_PARAMETER;
498 if ((i965->wrapper_pdrvctx == NULL) ||
499 (obj_surface->bo == NULL))
500 return VA_STATUS_ERROR_INVALID_PARAMETER;
504 VASurfaceAttrib attrib_list[2];
505 VASurfaceAttribExternalBuffers buffer_descriptor;
506 VAGenericID wrapper_surface;
508 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
509 return VA_STATUS_ERROR_OPERATION_FAILED;
511 obj_surface->exported_primefd = fd_handle;
513 memset(&attrib_list, 0, sizeof(attrib_list));
514 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
516 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
517 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
518 attrib_list[0].value.value.p = &buffer_descriptor;
519 attrib_list[0].value.type = VAGenericValueTypePointer;
521 attrib_list[1].type = VASurfaceAttribMemoryType;
522 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
523 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
524 attrib_list[1].value.type = VAGenericValueTypeInteger;
526 buffer_descriptor.num_buffers = 1;
527 buffer_descriptor.num_planes = 2;
528 buffer_descriptor.width = obj_surface->orig_width;
529 buffer_descriptor.height = obj_surface->orig_height;
530 buffer_descriptor.pixel_format = obj_surface->fourcc;
531 buffer_descriptor.data_size = obj_surface->size;
532 buffer_descriptor.pitches[0] = obj_surface->width;
533 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
534 buffer_descriptor.offsets[0] = 0;
535 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
536 buffer_descriptor.buffers = (void *)&fd_handle;
538 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
539 vaCreateSurfaces2(i965->wrapper_pdrvctx,
541 obj_surface->orig_width,
542 obj_surface->orig_height,
546 if (va_status == VA_STATUS_SUCCESS) {
547 obj_surface->wrapper_surface = wrapper_surface;
549 /* This needs to be checked */
550 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
558 i965_QueryConfigProfiles(VADriverContextP ctx,
559 VAProfile *profile_list, /* out */
560 int *num_profiles) /* out */
562 struct i965_driver_data * const i965 = i965_driver_data(ctx);
565 if (HAS_MPEG2_DECODING(i965) ||
566 HAS_MPEG2_ENCODING(i965)) {
567 profile_list[i++] = VAProfileMPEG2Simple;
568 profile_list[i++] = VAProfileMPEG2Main;
571 if (HAS_H264_DECODING(i965) ||
572 HAS_H264_ENCODING(i965) ||
573 HAS_LP_H264_ENCODING(i965)) {
574 profile_list[i++] = VAProfileH264ConstrainedBaseline;
575 profile_list[i++] = VAProfileH264Main;
576 profile_list[i++] = VAProfileH264High;
578 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
579 HAS_H264_MVC_ENCODING(i965))
580 profile_list[i++] = VAProfileH264MultiviewHigh;
581 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
582 HAS_H264_MVC_ENCODING(i965))
583 profile_list[i++] = VAProfileH264StereoHigh;
585 if (HAS_VC1_DECODING(i965)) {
586 profile_list[i++] = VAProfileVC1Simple;
587 profile_list[i++] = VAProfileVC1Main;
588 profile_list[i++] = VAProfileVC1Advanced;
592 profile_list[i++] = VAProfileNone;
595 if (HAS_JPEG_DECODING(i965) ||
596 HAS_JPEG_ENCODING(i965)) {
597 profile_list[i++] = VAProfileJPEGBaseline;
600 if (HAS_VP8_DECODING(i965) ||
601 HAS_VP8_ENCODING(i965)) {
602 profile_list[i++] = VAProfileVP8Version0_3;
605 if (HAS_HEVC_DECODING(i965)||
606 HAS_HEVC_ENCODING(i965)) {
607 profile_list[i++] = VAProfileHEVCMain;
610 if (HAS_HEVC10_DECODING(i965)||
611 HAS_HEVC10_ENCODING(i965)) {
612 profile_list[i++] = VAProfileHEVCMain10;
615 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
616 HAS_VP9_ENCODING(i965)) {
617 profile_list[i++] = VAProfileVP9Profile0;
620 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
621 profile_list[i++] = VAProfileVP9Profile2;
624 if (i965->wrapper_pdrvctx) {
625 VAProfile wrapper_list[4];
627 VADriverContextP pdrvctx;
630 pdrvctx = i965->wrapper_pdrvctx;
631 CALL_VTABLE(pdrvctx, va_status,
632 vaQueryConfigProfiles(pdrvctx,
633 wrapper_list, &wrapper_num));
635 if (va_status == VA_STATUS_SUCCESS) {
637 for (j = 0; j < wrapper_num; j++)
638 if (wrapper_list[j] != VAProfileNone)
639 profile_list[i++] = wrapper_list[j];
643 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
644 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
647 return VA_STATUS_SUCCESS;
651 i965_QueryConfigEntrypoints(VADriverContextP ctx,
653 VAEntrypoint *entrypoint_list, /* out */
654 int *num_entrypoints) /* out */
656 struct i965_driver_data * const i965 = i965_driver_data(ctx);
660 case VAProfileMPEG2Simple:
661 case VAProfileMPEG2Main:
662 if (HAS_MPEG2_DECODING(i965))
663 entrypoint_list[n++] = VAEntrypointVLD;
665 if (HAS_MPEG2_ENCODING(i965))
666 entrypoint_list[n++] = VAEntrypointEncSlice;
670 case VAProfileH264ConstrainedBaseline:
671 case VAProfileH264Main:
672 case VAProfileH264High:
673 if (HAS_H264_DECODING(i965))
674 entrypoint_list[n++] = VAEntrypointVLD;
676 if (HAS_H264_ENCODING(i965))
677 entrypoint_list[n++] = VAEntrypointEncSlice;
679 if (HAS_LP_H264_ENCODING(i965))
680 entrypoint_list[n++] = VAEntrypointEncSliceLP;
683 case VAProfileH264MultiviewHigh:
684 case VAProfileH264StereoHigh:
685 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
686 entrypoint_list[n++] = VAEntrypointVLD;
688 if (HAS_H264_MVC_ENCODING(i965))
689 entrypoint_list[n++] = VAEntrypointEncSlice;
692 case VAProfileVC1Simple:
693 case VAProfileVC1Main:
694 case VAProfileVC1Advanced:
695 if (HAS_VC1_DECODING(i965))
696 entrypoint_list[n++] = VAEntrypointVLD;
701 entrypoint_list[n++] = VAEntrypointVideoProc;
704 case VAProfileJPEGBaseline:
705 if (HAS_JPEG_DECODING(i965))
706 entrypoint_list[n++] = VAEntrypointVLD;
708 if (HAS_JPEG_ENCODING(i965))
709 entrypoint_list[n++] = VAEntrypointEncPicture;
712 case VAProfileVP8Version0_3:
713 if (HAS_VP8_DECODING(i965))
714 entrypoint_list[n++] = VAEntrypointVLD;
716 if (HAS_VP8_ENCODING(i965))
717 entrypoint_list[n++] = VAEntrypointEncSlice;
721 case VAProfileHEVCMain:
722 if (HAS_HEVC_DECODING(i965))
723 entrypoint_list[n++] = VAEntrypointVLD;
725 if (HAS_HEVC_ENCODING(i965))
726 entrypoint_list[n++] = VAEntrypointEncSlice;
730 case VAProfileHEVCMain10:
731 if (HAS_HEVC10_DECODING(i965))
732 entrypoint_list[n++] = VAEntrypointVLD;
734 if (HAS_HEVC10_ENCODING(i965))
735 entrypoint_list[n++] = VAEntrypointEncSlice;
739 case VAProfileVP9Profile0:
740 case VAProfileVP9Profile2:
741 if(HAS_VP9_DECODING_PROFILE(i965, profile))
742 entrypoint_list[n++] = VAEntrypointVLD;
744 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
745 entrypoint_list[n++] = VAEntrypointEncSlice;
747 if(profile == VAProfileVP9Profile0) {
748 if (i965->wrapper_pdrvctx) {
749 VAStatus va_status = VA_STATUS_SUCCESS;
750 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
752 CALL_VTABLE(pdrvctx, va_status,
753 vaQueryConfigEntrypoints(pdrvctx, profile,
766 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
767 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
768 *num_entrypoints = n;
769 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
773 i965_validate_config(VADriverContextP ctx, VAProfile profile,
774 VAEntrypoint entrypoint)
776 struct i965_driver_data * const i965 = i965_driver_data(ctx);
779 /* Validate profile & entrypoint */
781 case VAProfileMPEG2Simple:
782 case VAProfileMPEG2Main:
783 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
784 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
785 va_status = VA_STATUS_SUCCESS;
787 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
791 case VAProfileH264ConstrainedBaseline:
792 case VAProfileH264Main:
793 case VAProfileH264High:
794 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
795 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
796 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP)) {
797 va_status = VA_STATUS_SUCCESS;
799 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
803 case VAProfileVC1Simple:
804 case VAProfileVC1Main:
805 case VAProfileVC1Advanced:
806 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
807 va_status = VA_STATUS_SUCCESS;
809 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
814 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
815 va_status = VA_STATUS_SUCCESS;
817 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
821 case VAProfileJPEGBaseline:
822 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
823 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
824 va_status = VA_STATUS_SUCCESS;
826 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
830 case VAProfileVP8Version0_3:
831 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
832 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
833 va_status = VA_STATUS_SUCCESS;
835 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
839 case VAProfileH264MultiviewHigh:
840 case VAProfileH264StereoHigh:
841 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
842 entrypoint == VAEntrypointVLD) ||
843 (HAS_H264_MVC_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
844 va_status = VA_STATUS_SUCCESS;
846 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
851 case VAProfileHEVCMain:
852 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
853 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice)))
854 va_status = VA_STATUS_SUCCESS;
856 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
860 case VAProfileHEVCMain10:
861 if ((HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
862 (HAS_HEVC10_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice)))
863 va_status = VA_STATUS_SUCCESS;
865 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
869 case VAProfileVP9Profile0:
870 case VAProfileVP9Profile2:
871 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) && (entrypoint == VAEntrypointVLD))
872 va_status = VA_STATUS_SUCCESS;
873 else if ((HAS_VP9_ENCODING(i965)) && (entrypoint == VAEntrypointEncSlice))
874 va_status = VA_STATUS_SUCCESS;
875 else if ((profile == VAProfileVP9Profile0) && i965->wrapper_pdrvctx)
876 va_status = VA_STATUS_SUCCESS;
878 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
882 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
889 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
890 VAEntrypoint entrypoint)
892 struct i965_driver_data * const i965 = i965_driver_data(ctx);
893 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
896 case VAProfileH264ConstrainedBaseline:
897 case VAProfileH264Main:
898 case VAProfileH264High:
899 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
900 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
903 case VAProfileH264MultiviewHigh:
904 case VAProfileH264StereoHigh:
905 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
906 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
909 case VAProfileJPEGBaseline:
910 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
911 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
912 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
913 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
916 case VAProfileHEVCMain10:
917 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
918 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
922 if(HAS_VPP_P010(i965))
923 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
926 case VAProfileVP9Profile0:
927 case VAProfileVP9Profile2:
928 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
929 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
935 return chroma_formats;
939 i965_GetConfigAttributes(VADriverContextP ctx,
941 VAEntrypoint entrypoint,
942 VAConfigAttrib *attrib_list, /* in/out */
948 va_status = i965_validate_config(ctx, profile, entrypoint);
949 if (va_status != VA_STATUS_SUCCESS)
952 /* Other attributes don't seem to be defined */
953 /* What to do if we don't know the attribute? */
954 for (i = 0; i < num_attribs; i++) {
955 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
956 switch (attrib_list[i].type) {
957 case VAConfigAttribRTFormat:
958 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
959 profile, entrypoint);
962 case VAConfigAttribRateControl:
963 if (entrypoint == VAEntrypointEncSlice) {
964 attrib_list[i].value = VA_RC_CQP;
966 if (profile != VAProfileMPEG2Main &&
967 profile != VAProfileMPEG2Simple)
968 attrib_list[i].value |= VA_RC_CBR;
970 if (profile == VAProfileVP9Profile0)
971 attrib_list[i].value |= VA_RC_VBR;
974 } else if (entrypoint == VAEntrypointEncSliceLP) {
975 struct i965_driver_data * const i965 = i965_driver_data(ctx);
977 /* Support low power encoding for H.264 only by now */
978 if (profile == VAProfileH264ConstrainedBaseline ||
979 profile == VAProfileH264Main ||
980 profile == VAProfileH264High)
981 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
983 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
985 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
989 case VAConfigAttribEncPackedHeaders:
990 if (entrypoint == VAEntrypointEncSlice ||
991 entrypoint == VAEntrypointEncSliceLP) {
992 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
993 if (profile == VAProfileH264ConstrainedBaseline ||
994 profile == VAProfileH264Main ||
995 profile == VAProfileH264High ||
996 profile == VAProfileH264StereoHigh ||
997 profile == VAProfileH264MultiviewHigh ||
998 profile == VAProfileHEVCMain ||
999 profile == VAProfileHEVCMain10) {
1000 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
1001 VA_ENC_PACKED_HEADER_SLICE);
1003 else if (profile == VAProfileVP9Profile0)
1004 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1007 else if (entrypoint == VAEntrypointEncPicture) {
1008 if (profile == VAProfileJPEGBaseline)
1009 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
1013 case VAConfigAttribEncMaxRefFrames:
1014 if (entrypoint == VAEntrypointEncSlice)
1015 attrib_list[i].value = (1 << 16) | (1 << 0);
1016 else if (entrypoint == VAEntrypointEncSliceLP) {
1017 /* Don't support B frame for low power mode */
1018 if (profile == VAProfileH264ConstrainedBaseline ||
1019 profile == VAProfileH264Main ||
1020 profile == VAProfileH264High)
1021 attrib_list[i].value = (1 << 0);
1023 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1028 case VAConfigAttribEncQualityRange:
1029 if (entrypoint == VAEntrypointEncSlice ||
1030 entrypoint == VAEntrypointEncSliceLP) {
1031 attrib_list[i].value = 1;
1032 if (profile == VAProfileH264ConstrainedBaseline ||
1033 profile == VAProfileH264Main ||
1034 profile == VAProfileH264High )
1035 attrib_list[i].value = ENCODER_QUALITY_RANGE;
1040 case VAConfigAttribEncJPEG:
1041 if( entrypoint == VAEntrypointEncPicture) {
1042 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*)&(attrib_list[i].value);
1043 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
1044 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
1045 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
1046 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
1047 (configVal->bits).max_num_components = 3; // Only 3 components supported
1048 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
1049 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
1050 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
1054 case VAConfigAttribDecSliceMode:
1055 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
1058 case VAConfigAttribEncROI:
1059 if (profile == VAProfileH264ConstrainedBaseline ||
1060 profile == VAProfileH264Main ||
1061 profile == VAProfileH264High) {
1062 VAConfigAttribValEncROI *roi_config = (VAConfigAttribValEncROI *)&(attrib_list[i].value);
1064 if(entrypoint == VAEntrypointEncSliceLP) {
1065 roi_config->bits.num_roi_regions = 3;
1066 roi_config->bits.roi_rc_priority_support = 0;
1067 roi_config->bits.roi_rc_qp_delat_support = 0;
1069 roi_config->bits.num_roi_regions = I965_MAX_NUM_ROI_REGIONS;
1070 roi_config->bits.roi_rc_priority_support = 0;
1071 roi_config->bits.roi_rc_qp_delat_support = 1;
1074 attrib_list[i].value = 0;
1081 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1086 return VA_STATUS_SUCCESS;
1090 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1092 object_heap_free(heap, obj);
1095 static VAConfigAttrib *
1096 i965_lookup_config_attribute(struct object_config *obj_config,
1097 VAConfigAttribType type)
1101 for (i = 0; i < obj_config->num_attribs; i++) {
1102 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1103 if (attrib->type == type)
1110 i965_append_config_attribute(struct object_config *obj_config,
1111 const VAConfigAttrib *new_attrib)
1113 VAConfigAttrib *attrib;
1115 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1116 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1118 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1119 attrib->type = new_attrib->type;
1120 attrib->value = new_attrib->value;
1121 return VA_STATUS_SUCCESS;
1125 i965_ensure_config_attribute(struct object_config *obj_config,
1126 const VAConfigAttrib *new_attrib)
1128 VAConfigAttrib *attrib;
1130 /* Check for existing attributes */
1131 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1133 /* Update existing attribute */
1134 attrib->value = new_attrib->value;
1135 return VA_STATUS_SUCCESS;
1137 return i965_append_config_attribute(obj_config, new_attrib);
1141 i965_CreateConfig(VADriverContextP ctx,
1143 VAEntrypoint entrypoint,
1144 VAConfigAttrib *attrib_list,
1146 VAConfigID *config_id) /* out */
1148 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1149 struct object_config *obj_config;
1154 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1156 if (VA_STATUS_SUCCESS != vaStatus) {
1160 configID = NEW_CONFIG_ID();
1161 obj_config = CONFIG(configID);
1163 if (NULL == obj_config) {
1164 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1168 obj_config->profile = profile;
1169 obj_config->entrypoint = entrypoint;
1170 obj_config->num_attribs = 0;
1171 obj_config->wrapper_config = VA_INVALID_ID;
1173 for (i = 0; i < num_attribs; i++) {
1174 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1175 if (vaStatus != VA_STATUS_SUCCESS)
1179 if (vaStatus == VA_STATUS_SUCCESS) {
1180 VAConfigAttrib attrib, *attrib_found;
1181 attrib.type = VAConfigAttribRTFormat;
1182 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1183 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1184 if (!attrib_found || !attrib_found->value)
1185 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1186 else if (!(attrib_found->value & attrib.value))
1187 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1190 if ((vaStatus == VA_STATUS_SUCCESS) &&
1191 (profile == VAProfileVP9Profile0) &&
1192 (entrypoint == VAEntrypointVLD) &&
1193 !HAS_VP9_DECODING(i965)) {
1195 if (i965->wrapper_pdrvctx) {
1196 VAGenericID wrapper_config;
1198 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1199 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1200 entrypoint, attrib_list,
1201 num_attribs, &wrapper_config));
1203 if (vaStatus == VA_STATUS_SUCCESS)
1204 obj_config->wrapper_config = wrapper_config;
1208 /* Error recovery */
1209 if (VA_STATUS_SUCCESS != vaStatus) {
1210 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1212 *config_id = configID;
1219 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1221 struct i965_driver_data *i965 = i965_driver_data(ctx);
1222 struct object_config *obj_config = CONFIG(config_id);
1225 if (NULL == obj_config) {
1226 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1230 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1231 i965->wrapper_pdrvctx) {
1232 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1233 vaDestroyConfig(i965->wrapper_pdrvctx,
1234 obj_config->wrapper_config));
1235 obj_config->wrapper_config = VA_INVALID_ID;
1238 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1239 return VA_STATUS_SUCCESS;
1242 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1243 VAConfigID config_id,
1244 VAProfile *profile, /* out */
1245 VAEntrypoint *entrypoint, /* out */
1246 VAConfigAttrib *attrib_list, /* out */
1247 int *num_attribs) /* out */
1249 struct i965_driver_data *i965 = i965_driver_data(ctx);
1250 struct object_config *obj_config = CONFIG(config_id);
1251 VAStatus vaStatus = VA_STATUS_SUCCESS;
1254 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1255 *profile = obj_config->profile;
1256 *entrypoint = obj_config->entrypoint;
1257 *num_attribs = obj_config->num_attribs;
1259 for(i = 0; i < obj_config->num_attribs; i++) {
1260 attrib_list[i] = obj_config->attrib_list[i];
1267 i965_destroy_surface_storage(struct object_surface *obj_surface)
1272 dri_bo_unreference(obj_surface->bo);
1273 obj_surface->bo = NULL;
1275 if (obj_surface->free_private_data != NULL) {
1276 obj_surface->free_private_data(&obj_surface->private_data);
1277 obj_surface->private_data = NULL;
1282 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1284 struct object_surface *obj_surface = (struct object_surface *)obj;
1286 i965_destroy_surface_storage(obj_surface);
1287 object_heap_free(heap, obj);
1291 i965_surface_native_memory(VADriverContextP ctx,
1292 struct object_surface *obj_surface,
1294 int expected_fourcc)
1296 struct i965_driver_data *i965 = i965_driver_data(ctx);
1297 int tiling = HAS_TILED_SURFACE(i965);
1299 if (!expected_fourcc)
1300 return VA_STATUS_SUCCESS;
1302 // todo, should we disable tiling for 422 format?
1303 if (expected_fourcc == VA_FOURCC_I420 ||
1304 expected_fourcc == VA_FOURCC_IYUV ||
1305 expected_fourcc == VA_FOURCC_YV12 ||
1306 expected_fourcc == VA_FOURCC_YV16)
1309 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1313 i965_suface_external_memory(VADriverContextP ctx,
1314 struct object_surface *obj_surface,
1315 int external_memory_type,
1316 VASurfaceAttribExternalBuffers *memory_attibute,
1319 struct i965_driver_data *i965 = i965_driver_data(ctx);
1321 if (!memory_attibute ||
1322 !memory_attibute->buffers ||
1323 index > memory_attibute->num_buffers)
1324 return VA_STATUS_ERROR_INVALID_PARAMETER;
1326 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1327 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1328 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1330 obj_surface->fourcc = memory_attibute->pixel_format;
1331 obj_surface->width = memory_attibute->pitches[0];
1332 obj_surface->size = memory_attibute->data_size;
1334 if (memory_attibute->num_planes == 1)
1335 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1337 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1339 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1340 obj_surface->x_cr_offset = 0;
1342 switch (obj_surface->fourcc) {
1343 case VA_FOURCC_NV12:
1344 case VA_FOURCC_P010:
1345 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1346 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1348 obj_surface->subsampling = SUBSAMPLE_YUV420;
1349 obj_surface->y_cb_offset = obj_surface->height;
1350 obj_surface->y_cr_offset = obj_surface->height;
1351 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1352 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1353 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1357 case VA_FOURCC_YV12:
1358 case VA_FOURCC_IMC1:
1359 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1360 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1362 obj_surface->subsampling = SUBSAMPLE_YUV420;
1363 obj_surface->y_cr_offset = obj_surface->height;
1364 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1365 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1366 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1367 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1371 case VA_FOURCC_I420:
1372 case VA_FOURCC_IYUV:
1373 case VA_FOURCC_IMC3:
1374 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1375 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1377 obj_surface->subsampling = SUBSAMPLE_YUV420;
1378 obj_surface->y_cb_offset = obj_surface->height;
1379 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1380 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1381 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1382 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1386 case VA_FOURCC_YUY2:
1387 case VA_FOURCC_UYVY:
1388 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1390 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1391 obj_surface->y_cb_offset = 0;
1392 obj_surface->y_cr_offset = 0;
1393 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1394 obj_surface->cb_cr_height = obj_surface->orig_height;
1395 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1399 case VA_FOURCC_RGBA:
1400 case VA_FOURCC_RGBX:
1401 case VA_FOURCC_BGRA:
1402 case VA_FOURCC_BGRX:
1403 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1405 obj_surface->subsampling = SUBSAMPLE_RGBX;
1406 obj_surface->y_cb_offset = 0;
1407 obj_surface->y_cr_offset = 0;
1408 obj_surface->cb_cr_width = 0;
1409 obj_surface->cb_cr_height = 0;
1410 obj_surface->cb_cr_pitch = 0;
1414 case VA_FOURCC_Y800: /* monochrome surface */
1415 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1417 obj_surface->subsampling = SUBSAMPLE_YUV400;
1418 obj_surface->y_cb_offset = 0;
1419 obj_surface->y_cr_offset = 0;
1420 obj_surface->cb_cr_width = 0;
1421 obj_surface->cb_cr_height = 0;
1422 obj_surface->cb_cr_pitch = 0;
1426 case VA_FOURCC_411P:
1427 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1428 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1430 obj_surface->subsampling = SUBSAMPLE_YUV411;
1431 obj_surface->y_cb_offset = 0;
1432 obj_surface->y_cr_offset = 0;
1433 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1434 obj_surface->cb_cr_height = obj_surface->orig_height;
1435 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1439 case VA_FOURCC_422H:
1440 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1441 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1443 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1444 obj_surface->y_cb_offset = obj_surface->height;
1445 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1446 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1447 obj_surface->cb_cr_height = obj_surface->orig_height;
1448 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1452 case VA_FOURCC_YV16:
1453 assert(memory_attibute->num_planes == 3);
1454 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1456 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1457 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1458 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1459 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1460 obj_surface->cb_cr_height = obj_surface->orig_height;
1461 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1465 case VA_FOURCC_422V:
1466 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1467 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1469 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1470 obj_surface->y_cb_offset = obj_surface->height;
1471 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1472 obj_surface->cb_cr_width = obj_surface->orig_width;
1473 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1474 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1478 case VA_FOURCC_444P:
1479 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1480 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1482 obj_surface->subsampling = SUBSAMPLE_YUV444;
1483 obj_surface->y_cb_offset = obj_surface->height;
1484 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1485 obj_surface->cb_cr_width = obj_surface->orig_width;
1486 obj_surface->cb_cr_height = obj_surface->orig_height;
1487 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1493 return VA_STATUS_ERROR_INVALID_PARAMETER;
1496 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1497 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1498 "gem flinked vaapi surface",
1499 memory_attibute->buffers[index]);
1500 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1501 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1502 memory_attibute->buffers[index],
1505 if (!obj_surface->bo)
1506 return VA_STATUS_ERROR_INVALID_PARAMETER;
1508 return VA_STATUS_SUCCESS;
1511 /* byte-per-pixel of the first plane */
1513 bpp_1stplane_by_fourcc(unsigned int fourcc)
1515 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1517 if (info && (info->flag & I_S))
1518 return info->bpp[0] / 8;
1524 i965_CreateSurfaces2(
1525 VADriverContextP ctx,
1526 unsigned int format,
1528 unsigned int height,
1529 VASurfaceID *surfaces,
1530 unsigned int num_surfaces,
1531 VASurfaceAttrib *attrib_list,
1532 unsigned int num_attribs
1535 struct i965_driver_data *i965 = i965_driver_data(ctx);
1537 VAStatus vaStatus = VA_STATUS_SUCCESS;
1538 int expected_fourcc = 0;
1539 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1540 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1542 for (i = 0; i < num_attribs && attrib_list; i++) {
1543 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1544 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1545 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1546 expected_fourcc = attrib_list[i].value.value.i;
1549 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1550 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1552 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1554 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1555 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1556 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1557 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1558 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1559 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1562 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1563 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1564 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1565 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1569 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1570 * for post-processing (including color conversion) */
1571 if (VA_RT_FORMAT_YUV420 != format &&
1572 VA_RT_FORMAT_YUV420_10BPP != format &&
1573 VA_RT_FORMAT_YUV422 != format &&
1574 VA_RT_FORMAT_YUV444 != format &&
1575 VA_RT_FORMAT_YUV411 != format &&
1576 VA_RT_FORMAT_YUV400 != format &&
1577 VA_RT_FORMAT_RGB32 != format) {
1578 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1581 for (i = 0; i < num_surfaces; i++) {
1582 int surfaceID = NEW_SURFACE_ID();
1583 struct object_surface *obj_surface = SURFACE(surfaceID);
1585 if (NULL == obj_surface) {
1586 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1590 surfaces[i] = surfaceID;
1591 obj_surface->status = VASurfaceReady;
1592 obj_surface->orig_width = width;
1593 obj_surface->orig_height = height;
1594 obj_surface->user_disable_tiling = false;
1595 obj_surface->user_h_stride_set = false;
1596 obj_surface->user_v_stride_set = false;
1597 obj_surface->border_cleared = false;
1599 obj_surface->subpic_render_idx = 0;
1600 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1601 obj_surface->subpic[j] = VA_INVALID_ID;
1602 obj_surface->obj_subpic[j] = NULL;
1605 assert(i965->codec_info->min_linear_wpitch);
1606 assert(i965->codec_info->min_linear_hpitch);
1607 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1608 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1609 obj_surface->flags = SURFACE_REFERENCED;
1610 obj_surface->fourcc = 0;
1611 obj_surface->expected_format = format;
1612 obj_surface->bo = NULL;
1613 obj_surface->locked_image_id = VA_INVALID_ID;
1614 obj_surface->derived_image_id = VA_INVALID_ID;
1615 obj_surface->private_data = NULL;
1616 obj_surface->free_private_data = NULL;
1617 obj_surface->subsampling = SUBSAMPLE_YUV420;
1619 obj_surface->wrapper_surface = VA_INVALID_ID;
1620 obj_surface->exported_primefd = -1;
1622 switch (memory_type) {
1623 case I965_SURFACE_MEM_NATIVE:
1624 if (memory_attibute) {
1625 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1626 obj_surface->user_disable_tiling = true;
1628 if (memory_attibute->pixel_format) {
1629 if (expected_fourcc)
1630 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1632 expected_fourcc = memory_attibute->pixel_format;
1634 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1635 if (memory_attibute->pitches[0]) {
1636 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1637 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1638 obj_surface->width = memory_attibute->pitches[0];
1639 obj_surface->user_h_stride_set = true;
1640 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1641 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1643 if (memory_attibute->offsets[1]) {
1644 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1645 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1646 obj_surface->user_v_stride_set = true;
1647 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1648 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1652 vaStatus = i965_surface_native_memory(ctx,
1658 case I965_SURFACE_MEM_GEM_FLINK:
1659 case I965_SURFACE_MEM_DRM_PRIME:
1660 vaStatus = i965_suface_external_memory(ctx,
1667 if (VA_STATUS_SUCCESS != vaStatus) {
1668 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1673 /* Error recovery */
1674 if (VA_STATUS_SUCCESS != vaStatus) {
1675 /* surfaces[i-1] was the last successful allocation */
1677 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1679 surfaces[i] = VA_INVALID_SURFACE;
1680 assert(obj_surface);
1681 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1689 i965_CreateSurfaces(VADriverContextP ctx,
1694 VASurfaceID *surfaces) /* out */
1696 return i965_CreateSurfaces2(ctx,
1707 i965_DestroySurfaces(VADriverContextP ctx,
1708 VASurfaceID *surface_list,
1711 struct i965_driver_data *i965 = i965_driver_data(ctx);
1713 VAStatus va_status = VA_STATUS_SUCCESS;
1715 for (i = num_surfaces; i--; ) {
1716 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1718 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1720 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1721 i965->wrapper_pdrvctx) {
1722 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1723 vaDestroySurfaces(i965->wrapper_pdrvctx,
1724 &(obj_surface->wrapper_surface),
1726 obj_surface->wrapper_surface = VA_INVALID_ID;
1728 if (obj_surface->exported_primefd >= 0) {
1729 close(obj_surface->exported_primefd);
1730 obj_surface->exported_primefd = -1;
1733 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1740 i965_QueryImageFormats(VADriverContextP ctx,
1741 VAImageFormat *format_list, /* out */
1742 int *num_formats) /* out */
1746 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1747 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1749 format_list[n] = m->va_format;
1755 return VA_STATUS_SUCCESS;
1759 * Guess the format when the usage of a VA surface is unknown
1760 * 1. Without a valid context: YV12
1761 * 2. The current context is valid:
1762 * a) always NV12 on GEN6 and later
1763 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1766 i965_guess_surface_format(VADriverContextP ctx,
1767 VASurfaceID surface,
1768 unsigned int *fourcc,
1769 unsigned int *is_tiled)
1771 struct i965_driver_data *i965 = i965_driver_data(ctx);
1772 struct object_context *obj_context = NULL;
1773 struct object_config *obj_config = NULL;
1775 *fourcc = VA_FOURCC_YV12;
1778 if (i965->current_context_id == VA_INVALID_ID)
1781 obj_context = CONTEXT(i965->current_context_id);
1786 obj_config = obj_context->obj_config;
1792 if (IS_GEN6(i965->intel.device_info) ||
1793 IS_GEN7(i965->intel.device_info) ||
1794 IS_GEN8(i965->intel.device_info) ||
1795 IS_GEN9(i965->intel.device_info)) {
1796 *fourcc = VA_FOURCC_NV12;
1801 switch (obj_config->profile) {
1802 case VAProfileMPEG2Simple:
1803 case VAProfileMPEG2Main:
1804 *fourcc = VA_FOURCC_I420;
1809 *fourcc = VA_FOURCC_NV12;
1816 i965_QuerySubpictureFormats(VADriverContextP ctx,
1817 VAImageFormat *format_list, /* out */
1818 unsigned int *flags, /* out */
1819 unsigned int *num_formats) /* out */
1823 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1824 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1826 format_list[n] = m->va_format;
1828 flags[n] = m->va_flags;
1834 return VA_STATUS_SUCCESS;
1838 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1840 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1842 object_heap_free(heap, obj);
1846 i965_CreateSubpicture(VADriverContextP ctx,
1848 VASubpictureID *subpicture) /* out */
1850 struct i965_driver_data *i965 = i965_driver_data(ctx);
1851 VASubpictureID subpicID = NEW_SUBPIC_ID()
1852 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1855 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1857 struct object_image *obj_image = IMAGE(image);
1859 return VA_STATUS_ERROR_INVALID_IMAGE;
1861 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1863 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1865 *subpicture = subpicID;
1866 obj_subpic->image = image;
1867 obj_subpic->obj_image = obj_image;
1868 obj_subpic->format = m->format;
1869 obj_subpic->width = obj_image->image.width;
1870 obj_subpic->height = obj_image->image.height;
1871 obj_subpic->pitch = obj_image->image.pitches[0];
1872 obj_subpic->bo = obj_image->bo;
1873 obj_subpic->global_alpha = 1.0;
1875 return VA_STATUS_SUCCESS;
1879 i965_DestroySubpicture(VADriverContextP ctx,
1880 VASubpictureID subpicture)
1882 struct i965_driver_data *i965 = i965_driver_data(ctx);
1883 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1886 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1888 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1889 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1890 return VA_STATUS_SUCCESS;
1894 i965_SetSubpictureImage(VADriverContextP ctx,
1895 VASubpictureID subpicture,
1899 return VA_STATUS_ERROR_UNIMPLEMENTED;
1903 i965_SetSubpictureChromakey(VADriverContextP ctx,
1904 VASubpictureID subpicture,
1905 unsigned int chromakey_min,
1906 unsigned int chromakey_max,
1907 unsigned int chromakey_mask)
1910 return VA_STATUS_ERROR_UNIMPLEMENTED;
1914 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1915 VASubpictureID subpicture,
1918 struct i965_driver_data *i965 = i965_driver_data(ctx);
1919 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1921 if(global_alpha > 1.0 || global_alpha < 0.0){
1922 return VA_STATUS_ERROR_INVALID_PARAMETER;
1926 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1928 obj_subpic->global_alpha = global_alpha;
1930 return VA_STATUS_SUCCESS;
1934 i965_AssociateSubpicture(VADriverContextP ctx,
1935 VASubpictureID subpicture,
1936 VASurfaceID *target_surfaces,
1938 short src_x, /* upper left offset in subpicture */
1940 unsigned short src_width,
1941 unsigned short src_height,
1942 short dest_x, /* upper left offset in surface */
1944 unsigned short dest_width,
1945 unsigned short dest_height,
1947 * whether to enable chroma-keying or global-alpha
1948 * see VA_SUBPICTURE_XXX values
1952 struct i965_driver_data *i965 = i965_driver_data(ctx);
1953 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1957 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1959 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1961 obj_subpic->src_rect.x = src_x;
1962 obj_subpic->src_rect.y = src_y;
1963 obj_subpic->src_rect.width = src_width;
1964 obj_subpic->src_rect.height = src_height;
1965 obj_subpic->dst_rect.x = dest_x;
1966 obj_subpic->dst_rect.y = dest_y;
1967 obj_subpic->dst_rect.width = dest_width;
1968 obj_subpic->dst_rect.height = dest_height;
1969 obj_subpic->flags = flags;
1971 for (i = 0; i < num_surfaces; i++) {
1972 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1974 return VA_STATUS_ERROR_INVALID_SURFACE;
1976 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1977 if(obj_surface->subpic[j] == VA_INVALID_ID){
1978 assert(obj_surface->obj_subpic[j] == NULL);
1979 obj_surface->subpic[j] = subpicture;
1980 obj_surface->obj_subpic[j] = obj_subpic;
1985 if(j == I965_MAX_SUBPIC_SUM){
1986 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1990 return VA_STATUS_SUCCESS;
1995 i965_DeassociateSubpicture(VADriverContextP ctx,
1996 VASubpictureID subpicture,
1997 VASurfaceID *target_surfaces,
2000 struct i965_driver_data *i965 = i965_driver_data(ctx);
2001 struct object_subpic *obj_subpic = SUBPIC(subpicture);
2005 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
2007 for (i = 0; i < num_surfaces; i++) {
2008 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
2010 return VA_STATUS_ERROR_INVALID_SURFACE;
2012 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
2013 if (obj_surface->subpic[j] == subpicture) {
2014 assert(obj_surface->obj_subpic[j] == obj_subpic);
2015 obj_surface->subpic[j] = VA_INVALID_ID;
2016 obj_surface->obj_subpic[j] = NULL;
2021 if(j == I965_MAX_SUBPIC_SUM){
2022 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2025 return VA_STATUS_SUCCESS;
2029 i965_reference_buffer_store(struct buffer_store **ptr,
2030 struct buffer_store *buffer_store)
2032 assert(*ptr == NULL);
2035 buffer_store->ref_count++;
2036 *ptr = buffer_store;
2041 i965_release_buffer_store(struct buffer_store **ptr)
2043 struct buffer_store *buffer_store = *ptr;
2045 if (buffer_store == NULL)
2048 assert(buffer_store->bo || buffer_store->buffer);
2049 assert(!(buffer_store->bo && buffer_store->buffer));
2050 buffer_store->ref_count--;
2052 if (buffer_store->ref_count == 0) {
2053 dri_bo_unreference(buffer_store->bo);
2054 free(buffer_store->buffer);
2055 buffer_store->bo = NULL;
2056 buffer_store->buffer = NULL;
2064 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
2066 struct object_context *obj_context = (struct object_context *)obj;
2069 if (obj_context->hw_context) {
2070 obj_context->hw_context->destroy(obj_context->hw_context);
2071 obj_context->hw_context = NULL;
2074 if (obj_context->codec_type == CODEC_PROC) {
2075 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2077 } else if (obj_context->codec_type == CODEC_ENC) {
2078 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2079 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2081 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2082 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2083 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2085 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2086 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2088 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2089 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2091 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2092 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
2094 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2095 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2097 free(obj_context->codec_state.encode.slice_params_ext);
2098 if (obj_context->codec_state.encode.slice_rawdata_index) {
2099 free(obj_context->codec_state.encode.slice_rawdata_index);
2100 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2102 if (obj_context->codec_state.encode.slice_rawdata_count) {
2103 free(obj_context->codec_state.encode.slice_rawdata_count);
2104 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2107 if (obj_context->codec_state.encode.slice_header_index) {
2108 free(obj_context->codec_state.encode.slice_header_index);
2109 obj_context->codec_state.encode.slice_header_index = NULL;
2112 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2113 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2114 free(obj_context->codec_state.encode.packed_header_params_ext);
2116 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2117 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2118 free(obj_context->codec_state.encode.packed_header_data_ext);
2120 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2122 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2123 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2125 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2126 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2127 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2129 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2130 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2132 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2133 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2135 free(obj_context->codec_state.decode.slice_params);
2136 free(obj_context->codec_state.decode.slice_datas);
2139 free(obj_context->render_targets);
2140 object_heap_free(heap, obj);
2144 max_resolution(struct i965_driver_data *i965,
2145 struct object_config *obj_config,
2149 if (i965->codec_info->max_resolution) {
2150 i965->codec_info->max_resolution(i965, obj_config, w, h);
2152 *w = i965->codec_info->max_width;
2153 *h = i965->codec_info->max_height;
2158 i965_CreateContext(VADriverContextP ctx,
2159 VAConfigID config_id,
2163 VASurfaceID *render_targets,
2164 int num_render_targets,
2165 VAContextID *context) /* out */
2167 struct i965_driver_data *i965 = i965_driver_data(ctx);
2168 struct object_config *obj_config = CONFIG(config_id);
2169 struct object_context *obj_context = NULL;
2170 VAConfigAttrib *attrib;
2171 VAStatus vaStatus = VA_STATUS_SUCCESS;
2177 if (NULL == obj_config) {
2178 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2182 max_resolution(i965, obj_config, &max_width, &max_height);
2184 if (picture_width > max_width ||
2185 picture_height > max_height) {
2186 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2191 /* Validate picture dimensions */
2192 contextID = NEW_CONTEXT_ID();
2193 obj_context = CONTEXT(contextID);
2195 if (NULL == obj_context) {
2196 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2200 *context = contextID;
2201 obj_context->flags = flag;
2202 obj_context->context_id = contextID;
2203 obj_context->obj_config = obj_config;
2204 obj_context->picture_width = picture_width;
2205 obj_context->picture_height = picture_height;
2206 obj_context->num_render_targets = num_render_targets;
2207 obj_context->render_targets =
2208 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2209 obj_context->hw_context = NULL;
2210 obj_context->wrapper_context = VA_INVALID_ID;
2212 if (!obj_context->render_targets)
2213 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2215 for(i = 0; i < num_render_targets; i++) {
2216 if (NULL == SURFACE(render_targets[i])) {
2217 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2221 obj_context->render_targets[i] = render_targets[i];
2224 if (VA_STATUS_SUCCESS == vaStatus) {
2225 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2226 obj_context->codec_type = CODEC_PROC;
2227 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2228 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2229 assert(i965->codec_info->proc_hw_context_init);
2230 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2231 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2232 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2233 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2234 VAConfigAttrib *packed_attrib;
2235 obj_context->codec_type = CODEC_ENC;
2236 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2237 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2238 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2239 obj_context->codec_state.encode.packed_header_params_ext =
2240 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2241 sizeof(struct buffer_store *));
2243 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2244 obj_context->codec_state.encode.packed_header_data_ext =
2245 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2246 sizeof(struct buffer_store *));
2248 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2249 obj_context->codec_state.encode.slice_rawdata_index =
2250 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2251 obj_context->codec_state.encode.slice_rawdata_count =
2252 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2254 obj_context->codec_state.encode.slice_header_index =
2255 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2257 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2259 obj_context->codec_state.encode.slice_index = 0;
2260 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2261 if (packed_attrib) {
2262 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2263 if (obj_config->profile == VAProfileVP9Profile0)
2264 obj_context->codec_state.encode.packed_header_flag =
2265 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2267 /* use the default value. SPS/PPS/RAWDATA is passed from user
2268 * while Slice_header data is generated by driver.
2270 obj_context->codec_state.encode.packed_header_flag =
2271 VA_ENC_PACKED_HEADER_SEQUENCE |
2272 VA_ENC_PACKED_HEADER_PICTURE |
2273 VA_ENC_PACKED_HEADER_RAW_DATA;
2275 /* it is not used for VP9 */
2276 if (obj_config->profile == VAProfileVP9Profile0)
2277 obj_context->codec_state.encode.packed_header_flag = 0;
2279 assert(i965->codec_info->enc_hw_context_init);
2280 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2282 obj_context->codec_type = CODEC_DEC;
2283 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2284 obj_context->codec_state.decode.current_render_target = -1;
2285 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2286 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2287 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2288 sizeof(*obj_context->codec_state.decode.slice_params));
2289 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2290 sizeof(*obj_context->codec_state.decode.slice_datas));
2292 assert(i965->codec_info->dec_hw_context_init);
2293 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2297 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2299 return VA_STATUS_ERROR_INVALID_CONFIG;
2300 obj_context->codec_state.base.chroma_formats = attrib->value;
2302 if (obj_config->wrapper_config != VA_INVALID_ID) {
2303 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2304 * So it won't check i965->wrapper_pdrvctx again.
2305 * Fixme if it is incorrect.
2307 VAGenericID wrapper_context;
2310 * The render_surface is not passed when calling
2312 * If it is needed, we must get the wrapped surface
2313 * for the corresponding Surface_list.
2314 * So the wrapped surface conversion is deferred.
2316 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2317 vaCreateContext(i965->wrapper_pdrvctx,
2318 obj_config->wrapper_config,
2319 picture_width, picture_height,
2323 if (vaStatus == VA_STATUS_SUCCESS)
2324 obj_context->wrapper_context = wrapper_context;
2326 /* Error recovery */
2327 if (VA_STATUS_SUCCESS != vaStatus) {
2328 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2331 i965->current_context_id = contextID;
2337 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2339 struct i965_driver_data *i965 = i965_driver_data(ctx);
2340 struct object_context *obj_context = CONTEXT(context);
2341 VAStatus va_status = VA_STATUS_SUCCESS;
2343 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2345 if (i965->current_context_id == context)
2346 i965->current_context_id = VA_INVALID_ID;
2348 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2349 i965->wrapper_pdrvctx) {
2350 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2351 vaDestroyContext(i965->wrapper_pdrvctx,
2352 obj_context->wrapper_context));
2354 obj_context->wrapper_context = VA_INVALID_ID;
2357 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2363 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2365 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2367 assert(obj_buffer->buffer_store);
2368 i965_release_buffer_store(&obj_buffer->buffer_store);
2369 object_heap_free(heap, obj);
2373 i965_create_buffer_internal(VADriverContextP ctx,
2374 VAContextID context,
2377 unsigned int num_elements,
2382 struct i965_driver_data *i965 = i965_driver_data(ctx);
2383 struct object_buffer *obj_buffer = NULL;
2384 struct buffer_store *buffer_store = NULL;
2386 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2387 struct object_context *obj_context = CONTEXT(context);
2388 int wrapper_flag = 0;
2392 case VAPictureParameterBufferType:
2393 case VAIQMatrixBufferType:
2394 case VAQMatrixBufferType:
2395 case VABitPlaneBufferType:
2396 case VASliceGroupMapBufferType:
2397 case VASliceParameterBufferType:
2398 case VASliceDataBufferType:
2399 case VAMacroblockParameterBufferType:
2400 case VAResidualDataBufferType:
2401 case VADeblockingParameterBufferType:
2402 case VAImageBufferType:
2403 case VAEncCodedBufferType:
2404 case VAEncSequenceParameterBufferType:
2405 case VAEncPictureParameterBufferType:
2406 case VAEncSliceParameterBufferType:
2407 case VAEncPackedHeaderParameterBufferType:
2408 case VAEncPackedHeaderDataBufferType:
2409 case VAEncMiscParameterBufferType:
2410 case VAProcPipelineParameterBufferType:
2411 case VAProcFilterParameterBufferType:
2412 case VAHuffmanTableBufferType:
2413 case VAProbabilityBufferType:
2414 case VAEncMacroblockMapBufferType:
2419 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2422 bufferID = NEW_BUFFER_ID();
2423 obj_buffer = BUFFER(bufferID);
2425 if (NULL == obj_buffer) {
2426 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2429 if (type == VAEncCodedBufferType) {
2430 size += I965_CODEDBUFFER_HEADER_SIZE;
2431 size += 0x1000; /* for upper bound check */
2434 obj_buffer->max_num_elements = num_elements;
2435 obj_buffer->num_elements = num_elements;
2436 obj_buffer->size_element = size;
2437 obj_buffer->type = type;
2438 obj_buffer->export_refcount = 0;
2439 obj_buffer->buffer_store = NULL;
2440 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2441 obj_buffer->context_id = context;
2443 buffer_store = calloc(1, sizeof(struct buffer_store));
2444 assert(buffer_store);
2445 buffer_store->ref_count = 1;
2448 (obj_context->wrapper_context != VA_INVALID_ID) &&
2449 i965->wrapper_pdrvctx) {
2450 VAGenericID wrapper_buffer;
2451 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2453 CALL_VTABLE(pdrvctx, vaStatus,
2454 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2455 data, &wrapper_buffer));
2456 if (vaStatus == VA_STATUS_SUCCESS) {
2457 obj_buffer->wrapper_buffer = wrapper_buffer;
2465 if (store_bo != NULL) {
2466 buffer_store->bo = store_bo;
2467 dri_bo_reference(buffer_store->bo);
2469 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2470 if (data && !wrapper_flag)
2471 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2472 } else if (type == VASliceDataBufferType ||
2473 type == VAImageBufferType ||
2474 type == VAEncCodedBufferType ||
2475 type == VAEncMacroblockMapBufferType ||
2476 type == VAProbabilityBufferType) {
2478 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2479 * So it is enough to allocate one 64 byte bo
2482 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2485 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2487 size * num_elements, 64);
2488 assert(buffer_store->bo);
2490 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2491 * In fact it can be skipped. But it is still allocated and it is
2492 * only to follow the normal flowchart of buffer_allocation/release.
2494 if (!wrapper_flag) {
2495 if (type == VAEncCodedBufferType) {
2496 struct i965_coded_buffer_segment *coded_buffer_segment;
2498 dri_bo_map(buffer_store->bo, 1);
2499 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2500 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2501 coded_buffer_segment->base.bit_offset = 0;
2502 coded_buffer_segment->base.status = 0;
2503 coded_buffer_segment->base.buf = NULL;
2504 coded_buffer_segment->base.next = NULL;
2505 coded_buffer_segment->mapped = 0;
2506 coded_buffer_segment->codec = 0;
2507 coded_buffer_segment->status_support = 0;
2508 dri_bo_unmap(buffer_store->bo);
2510 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2517 if (type == VAEncPackedHeaderDataBufferType) {
2518 msize = ALIGN(size, 4);
2521 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2523 buffer_store->buffer = malloc(4);
2525 buffer_store->buffer = malloc(msize * num_elements);
2526 assert(buffer_store->buffer);
2528 if (data && (!wrapper_flag))
2529 memcpy(buffer_store->buffer, data, size * num_elements);
2532 buffer_store->num_elements = obj_buffer->num_elements;
2533 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2534 i965_release_buffer_store(&buffer_store);
2537 return VA_STATUS_SUCCESS;
2541 i965_CreateBuffer(VADriverContextP ctx,
2542 VAContextID context, /* in */
2543 VABufferType type, /* in */
2544 unsigned int size, /* in */
2545 unsigned int num_elements, /* in */
2546 void *data, /* in */
2547 VABufferID *buf_id) /* out */
2549 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2554 i965_BufferSetNumElements(VADriverContextP ctx,
2555 VABufferID buf_id, /* in */
2556 unsigned int num_elements) /* in */
2558 struct i965_driver_data *i965 = i965_driver_data(ctx);
2559 struct object_buffer *obj_buffer = BUFFER(buf_id);
2560 VAStatus vaStatus = VA_STATUS_SUCCESS;
2562 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2564 /* When the wrapper_buffer exists, it will wrapper to the
2565 * buffer allocated from backend driver.
2567 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2568 i965->wrapper_pdrvctx) {
2569 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2571 CALL_VTABLE(pdrvctx, vaStatus,
2572 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2577 if ((num_elements < 0) ||
2578 (num_elements > obj_buffer->max_num_elements)) {
2579 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2581 obj_buffer->num_elements = num_elements;
2582 if (obj_buffer->buffer_store != NULL) {
2583 obj_buffer->buffer_store->num_elements = num_elements;
2591 i965_MapBuffer(VADriverContextP ctx,
2592 VABufferID buf_id, /* in */
2593 void **pbuf) /* out */
2595 struct i965_driver_data *i965 = i965_driver_data(ctx);
2596 struct object_buffer *obj_buffer = BUFFER(buf_id);
2597 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2598 struct object_context *obj_context;
2600 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2602 obj_context = CONTEXT(obj_buffer->context_id);
2604 /* When the wrapper_buffer exists, it will wrapper to the
2605 * buffer allocated from backend driver.
2607 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2608 i965->wrapper_pdrvctx) {
2609 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2611 CALL_VTABLE(pdrvctx, vaStatus,
2612 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2616 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2617 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2619 if (obj_buffer->export_refcount > 0)
2620 return VA_STATUS_ERROR_INVALID_BUFFER;
2622 if (NULL != obj_buffer->buffer_store->bo) {
2623 unsigned int tiling, swizzle;
2625 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2627 if (tiling != I915_TILING_NONE)
2628 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2630 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2632 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2633 *pbuf = obj_buffer->buffer_store->bo->virtual;
2634 vaStatus = VA_STATUS_SUCCESS;
2636 if (obj_buffer->type == VAEncCodedBufferType) {
2638 unsigned char *buffer = NULL;
2639 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2640 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2642 if (!coded_buffer_segment->mapped) {
2643 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2645 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2648 obj_context->hw_context &&
2649 obj_context->hw_context->get_status &&
2650 coded_buffer_segment->status_support) {
2651 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2653 if (coded_buffer_segment->codec == CODEC_H264 ||
2654 coded_buffer_segment->codec == CODEC_H264_MVC) {
2655 delimiter0 = H264_DELIMITER0;
2656 delimiter1 = H264_DELIMITER1;
2657 delimiter2 = H264_DELIMITER2;
2658 delimiter3 = H264_DELIMITER3;
2659 delimiter4 = H264_DELIMITER4;
2660 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2661 delimiter0 = MPEG2_DELIMITER0;
2662 delimiter1 = MPEG2_DELIMITER1;
2663 delimiter2 = MPEG2_DELIMITER2;
2664 delimiter3 = MPEG2_DELIMITER3;
2665 delimiter4 = MPEG2_DELIMITER4;
2666 } else if(coded_buffer_segment->codec == CODEC_JPEG) {
2667 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2670 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2671 delimiter0 = HEVC_DELIMITER0;
2672 delimiter1 = HEVC_DELIMITER1;
2673 delimiter2 = HEVC_DELIMITER2;
2674 delimiter3 = HEVC_DELIMITER3;
2675 delimiter4 = HEVC_DELIMITER4;
2676 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2677 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2680 if(coded_buffer_segment->codec == CODEC_JPEG) {
2681 for(i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2682 if( (buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2686 coded_buffer_segment->base.size = i + 2;
2687 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2688 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2689 so it don't need to traversal the coded buffer */
2690 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2691 if ((buffer[i] == delimiter0) &&
2692 (buffer[i + 1] == delimiter1) &&
2693 (buffer[i + 2] == delimiter2) &&
2694 (buffer[i + 3] == delimiter3) &&
2695 (buffer[i + 4] == delimiter4))
2699 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2700 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2702 coded_buffer_segment->base.size = i;
2705 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2706 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2709 vaStatus = VA_STATUS_SUCCESS;
2712 coded_buffer_segment->mapped = 1;
2714 assert(coded_buffer_segment->base.buf);
2715 vaStatus = VA_STATUS_SUCCESS;
2718 } else if (NULL != obj_buffer->buffer_store->buffer) {
2719 *pbuf = obj_buffer->buffer_store->buffer;
2720 vaStatus = VA_STATUS_SUCCESS;
2727 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2729 struct i965_driver_data *i965 = i965_driver_data(ctx);
2730 struct object_buffer *obj_buffer = BUFFER(buf_id);
2731 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2733 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2734 return VA_STATUS_ERROR_INVALID_BUFFER;
2736 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2737 /* When the wrapper_buffer exists, it will wrapper to the
2738 * buffer allocated from backend driver.
2740 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2741 i965->wrapper_pdrvctx) {
2742 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2744 CALL_VTABLE(pdrvctx, vaStatus,
2745 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2749 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2750 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2752 if (NULL != obj_buffer->buffer_store->bo) {
2753 unsigned int tiling, swizzle;
2755 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2757 if (tiling != I915_TILING_NONE)
2758 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2760 dri_bo_unmap(obj_buffer->buffer_store->bo);
2762 vaStatus = VA_STATUS_SUCCESS;
2763 } else if (NULL != obj_buffer->buffer_store->buffer) {
2765 vaStatus = VA_STATUS_SUCCESS;
2772 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2774 struct i965_driver_data *i965 = i965_driver_data(ctx);
2775 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2776 VAStatus va_status = VA_STATUS_SUCCESS;
2778 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2780 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2781 i965->wrapper_pdrvctx) {
2782 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2783 vaDestroyBuffer(i965->wrapper_pdrvctx,
2784 obj_buffer->wrapper_buffer));
2785 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2788 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2794 i965_BeginPicture(VADriverContextP ctx,
2795 VAContextID context,
2796 VASurfaceID render_target)
2798 struct i965_driver_data *i965 = i965_driver_data(ctx);
2799 struct object_context *obj_context = CONTEXT(context);
2800 struct object_surface *obj_surface = SURFACE(render_target);
2801 struct object_config *obj_config;
2802 VAStatus vaStatus = VA_STATUS_SUCCESS;
2805 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2806 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2807 obj_config = obj_context->obj_config;
2808 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2810 if (is_surface_busy(i965, obj_surface))
2811 return VA_STATUS_ERROR_SURFACE_BUSY;
2813 if (obj_context->codec_type == CODEC_PROC) {
2814 obj_context->codec_state.proc.current_render_target = render_target;
2815 } else if (obj_context->codec_type == CODEC_ENC) {
2817 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2819 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2820 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2822 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2823 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2825 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2826 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2828 obj_context->codec_state.encode.num_slice_params_ext = 0;
2829 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2830 obj_context->codec_state.encode.last_packed_header_type = 0;
2831 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2832 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2833 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2834 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2835 memset(obj_context->codec_state.encode.slice_header_index, 0,
2836 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2838 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2839 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2840 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2841 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2842 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2843 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2844 obj_context->codec_state.encode.slice_index = 0;
2845 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2847 * Based on ROI definition in va/va.h, the ROI set through this
2848 * structure is applicable only to the current frame or field.
2849 * That is to say: it is on-the-fly setting. If it is not set,
2850 * the current frame doesn't use ROI.
2851 * It is uncertain whether the other misc buffer should be released.
2852 * So only release the previous ROI buffer.
2854 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[VAEncMiscParameterTypeROI]);
2856 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2858 if (obj_config->profile == VAProfileVP9Profile0) {
2859 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2860 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
2862 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2865 obj_context->codec_state.decode.current_render_target = render_target;
2866 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2867 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2868 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2869 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2871 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2872 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2873 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2876 obj_context->codec_state.decode.num_slice_params = 0;
2877 obj_context->codec_state.decode.num_slice_datas = 0;
2879 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2880 i965->wrapper_pdrvctx) {
2881 if (obj_surface->wrapper_surface == VA_INVALID_ID)
2882 vaStatus = i965_surface_wrapper(ctx, render_target);
2884 if (vaStatus != VA_STATUS_SUCCESS)
2887 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2888 vaBeginPicture(i965->wrapper_pdrvctx,
2889 obj_context->wrapper_context,
2890 obj_surface->wrapper_surface));
2897 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2899 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2901 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2902 struct object_context *obj_context, \
2903 struct object_buffer *obj_buffer) \
2905 struct category##_state *category = &obj_context->codec_state.category; \
2906 i965_release_buffer_store(&category->member); \
2907 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2908 return VA_STATUS_SUCCESS; \
2911 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2913 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2914 struct object_context *obj_context, \
2915 struct object_buffer *obj_buffer) \
2917 struct category##_state *category = &obj_context->codec_state.category; \
2918 if (category->num_##member == category->max_##member) { \
2919 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2920 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2921 category->max_##member += NUM_SLICES; \
2923 i965_release_buffer_store(&category->member[category->num_##member]); \
2924 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2925 category->num_##member++; \
2926 return VA_STATUS_SUCCESS; \
2929 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2931 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2932 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2933 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2934 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2935 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2936 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2938 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2939 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2940 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2944 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
2945 VABufferID *buffers,
2948 struct i965_driver_data *i965 = i965_driver_data(ctx);
2949 VAStatus vaStatus = VA_STATUS_SUCCESS;
2951 VADecPictureParameterBufferVP9 *pVp9PicParams;
2952 VADriverContextP pdrvctx;
2953 struct object_buffer *obj_buffer;
2955 pdrvctx = i965->wrapper_pdrvctx;
2956 /* do the conversion of VADecPictureParameterBufferVP9 */
2957 for (i = 0; i < num_buffers; i++) {
2958 obj_buffer = BUFFER(buffers[i]);
2963 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
2966 if (obj_buffer->type == VAPictureParameterBufferType) {
2968 VASurfaceID surface_id;
2969 struct object_surface *obj_surface;
2971 pdrvctx = i965->wrapper_pdrvctx;
2973 CALL_VTABLE(pdrvctx, vaStatus,
2974 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
2975 (void **)(&pVp9PicParams)));
2977 if (vaStatus != VA_STATUS_SUCCESS)
2980 for (j = 0; j < 8; j++) {
2981 surface_id = pVp9PicParams->reference_frames[j];
2982 obj_surface = SURFACE(surface_id);
2987 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
2988 vaStatus = i965_surface_wrapper(ctx, surface_id);
2989 if (vaStatus != VA_STATUS_SUCCESS) {
2990 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
2991 obj_buffer->wrapper_buffer);
2996 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
2998 CALL_VTABLE(pdrvctx, vaStatus,
2999 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
3004 return VA_STATUS_SUCCESS;
3011 i965_decoder_wrapper_picture(VADriverContextP ctx,
3012 VAContextID context,
3013 VABufferID *buffers,
3016 struct i965_driver_data *i965 = i965_driver_data(ctx);
3017 struct object_context *obj_context = CONTEXT(context);
3018 VAStatus vaStatus = VA_STATUS_SUCCESS;
3020 VADriverContextP pdrvctx;
3021 struct object_buffer *obj_buffer;
3023 if (obj_context == NULL)
3024 return VA_STATUS_ERROR_INVALID_CONTEXT;
3026 /* When it is not wrapped context, continue the normal flowchart */
3027 if (obj_context->wrapper_context == VA_INVALID_ID)
3030 if (obj_context->obj_config &&
3031 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
3032 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
3034 return VA_STATUS_ERROR_INVALID_PARAMETER;
3036 pdrvctx = i965->wrapper_pdrvctx;
3038 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3039 obj_buffer = BUFFER(buffers[i]);
3044 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
3045 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3049 CALL_VTABLE(pdrvctx, vaStatus,
3050 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
3051 &(obj_buffer->wrapper_buffer), 1));
3057 i965_decoder_render_picture(VADriverContextP ctx,
3058 VAContextID context,
3059 VABufferID *buffers,
3062 struct i965_driver_data *i965 = i965_driver_data(ctx);
3063 struct object_context *obj_context = CONTEXT(context);
3064 VAStatus vaStatus = VA_STATUS_SUCCESS;
3067 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3069 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3070 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3073 return VA_STATUS_ERROR_INVALID_BUFFER;
3075 switch (obj_buffer->type) {
3076 case VAPictureParameterBufferType:
3077 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3080 case VAIQMatrixBufferType:
3081 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3084 case VABitPlaneBufferType:
3085 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3088 case VASliceParameterBufferType:
3089 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3092 case VASliceDataBufferType:
3093 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3096 case VAHuffmanTableBufferType:
3097 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3100 case VAProbabilityBufferType:
3101 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3105 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3110 if ((vaStatus == VA_STATUS_SUCCESS) &&
3111 (obj_context->wrapper_context != VA_INVALID_ID))
3112 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3117 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3119 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3120 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3121 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3122 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3123 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3124 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3125 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3126 /* extended buffer */
3127 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3128 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3129 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3131 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3132 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3133 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3135 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3136 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3139 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3140 struct object_context *obj_context,
3141 struct object_buffer *obj_buffer,
3144 struct encode_state *encode = &obj_context->codec_state.encode;
3146 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3147 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3148 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3149 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3151 return VA_STATUS_SUCCESS;
3155 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3156 struct object_context *obj_context,
3157 struct object_buffer *obj_buffer,
3160 struct encode_state *encode = &obj_context->codec_state.encode;
3162 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3163 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3164 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3165 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3167 return VA_STATUS_SUCCESS;
3171 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3172 struct object_context *obj_context,
3173 struct object_buffer *obj_buffer)
3175 struct encode_state *encode = &obj_context->codec_state.encode;
3176 VAEncMiscParameterBuffer *param = NULL;
3178 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3179 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3181 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3183 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3184 return VA_STATUS_ERROR_INVALID_PARAMETER;
3186 i965_release_buffer_store(&encode->misc_param[param->type]);
3187 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
3189 return VA_STATUS_SUCCESS;
3193 i965_encoder_render_picture(VADriverContextP ctx,
3194 VAContextID context,
3195 VABufferID *buffers,
3198 struct i965_driver_data *i965 = i965_driver_data(ctx);
3199 struct object_context *obj_context = CONTEXT(context);
3200 struct object_config *obj_config;
3201 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3202 struct encode_state *encode;
3205 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3206 obj_config = obj_context->obj_config;
3207 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3209 encode = &obj_context->codec_state.encode;
3210 for (i = 0; i < num_buffers; i++) {
3211 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3214 return VA_STATUS_ERROR_INVALID_BUFFER;
3216 switch (obj_buffer->type) {
3217 case VAQMatrixBufferType:
3218 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3221 case VAIQMatrixBufferType:
3222 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3225 case VAEncSequenceParameterBufferType:
3226 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3229 case VAEncPictureParameterBufferType:
3230 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3233 case VAHuffmanTableBufferType:
3234 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3237 case VAEncSliceParameterBufferType:
3238 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3239 if (vaStatus == VA_STATUS_SUCCESS) {
3240 /* When the max number of slices is updated, it also needs
3241 * to reallocate the arrays that is used to store
3242 * the packed data index/count for the slice
3244 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3245 encode->slice_index++;
3247 if (encode->slice_index == encode->max_slice_num) {
3248 int slice_num = encode->max_slice_num;
3249 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3250 (slice_num + NUM_SLICES) * sizeof(int));
3251 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3252 (slice_num + NUM_SLICES) * sizeof(int));
3253 encode->slice_header_index = realloc(encode->slice_header_index,
3254 (slice_num + NUM_SLICES) * sizeof(int));
3255 memset(encode->slice_rawdata_index + slice_num, 0,
3256 sizeof(int) * NUM_SLICES);
3257 memset(encode->slice_rawdata_count + slice_num, 0,
3258 sizeof(int) * NUM_SLICES);
3259 memset(encode->slice_header_index + slice_num, 0,
3260 sizeof(int) * NUM_SLICES);
3262 encode->max_slice_num += NUM_SLICES;
3263 if ((encode->slice_rawdata_index == NULL) ||
3264 (encode->slice_header_index == NULL) ||
3265 (encode->slice_rawdata_count == NULL)) {
3266 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3273 case VAEncPackedHeaderParameterBufferType:
3275 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3276 encode->last_packed_header_type = param->type;
3278 if ((param->type == VAEncPackedHeaderRawData) ||
3279 (param->type == VAEncPackedHeaderSlice)) {
3280 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3281 } else if((obj_config->profile == VAProfileHEVCMain ||
3282 obj_config->profile == VAProfileHEVCMain10) &&
3283 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3284 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3287 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3289 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3292 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3297 case VAEncPackedHeaderDataBufferType:
3299 if (encode->last_packed_header_type == 0) {
3300 WARN_ONCE("the packed header data is passed without type!\n");
3301 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3305 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3306 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3307 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3309 if (obj_config->profile == VAProfileVP9Profile0)
3312 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3313 * the packed_slice_header as the delimeter to decide how
3314 * the packed rawdata is inserted for the given slice.
3315 * Otherwise it will use the VAEncSequenceParameterBuffer
3318 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3319 /* store the first index of the packed header data for current slice */
3320 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3321 encode->slice_rawdata_index[encode->slice_index] =
3322 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3324 encode->slice_rawdata_count[encode->slice_index]++;
3325 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3326 /* find one packed slice_header delimeter. And the following
3327 * packed data is for the next slice
3329 encode->slice_header_index[encode->slice_index] =
3330 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3331 encode->slice_index++;
3332 /* Reallocate the buffer to record the index/count of
3333 * packed_data for one slice.
3335 if (encode->slice_index == encode->max_slice_num) {
3336 int slice_num = encode->max_slice_num;
3338 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3339 (slice_num + NUM_SLICES) * sizeof(int));
3340 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3341 (slice_num + NUM_SLICES) * sizeof(int));
3342 encode->slice_header_index = realloc(encode->slice_header_index,
3343 (slice_num + NUM_SLICES) * sizeof(int));
3344 memset(encode->slice_rawdata_index + slice_num, 0,
3345 sizeof(int) * NUM_SLICES);
3346 memset(encode->slice_rawdata_count + slice_num, 0,
3347 sizeof(int) * NUM_SLICES);
3348 memset(encode->slice_header_index + slice_num, 0,
3349 sizeof(int) * NUM_SLICES);
3350 encode->max_slice_num += NUM_SLICES;
3354 if (vaStatus == VA_STATUS_SUCCESS) {
3355 /* store the first index of the packed header data for current slice */
3356 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3357 encode->slice_rawdata_index[encode->slice_index] =
3358 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3360 encode->slice_rawdata_count[encode->slice_index]++;
3361 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3362 if (encode->slice_header_index[encode->slice_index] == 0) {
3363 encode->slice_header_index[encode->slice_index] =
3364 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3366 WARN_ONCE("Multi slice header data is passed for"
3367 " slice %d!\n", encode->slice_index);
3373 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3374 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3375 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3376 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3377 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3378 VA_STATUS_ERROR_ENCODING_ERROR);
3380 if((obj_config->profile == VAProfileHEVCMain ||
3381 obj_config->profile == VAProfileHEVCMain10) &&
3382 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3384 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3387 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3388 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3390 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3393 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3397 encode->last_packed_header_type = 0;
3401 case VAEncMiscParameterBufferType:
3402 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3407 case VAEncMacroblockMapBufferType:
3408 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3412 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3420 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3422 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3423 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3426 i965_proc_render_picture(VADriverContextP ctx,
3427 VAContextID context,
3428 VABufferID *buffers,
3431 struct i965_driver_data *i965 = i965_driver_data(ctx);
3432 struct object_context *obj_context = CONTEXT(context);
3433 VAStatus vaStatus = VA_STATUS_SUCCESS;
3436 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3438 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3439 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3442 return VA_STATUS_ERROR_INVALID_BUFFER;
3444 switch (obj_buffer->type) {
3445 case VAProcPipelineParameterBufferType:
3446 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3450 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3459 i965_RenderPicture(VADriverContextP ctx,
3460 VAContextID context,
3461 VABufferID *buffers,
3464 struct i965_driver_data *i965 = i965_driver_data(ctx);
3465 struct object_context *obj_context;
3466 struct object_config *obj_config;
3467 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3469 obj_context = CONTEXT(context);
3470 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3472 if (num_buffers <= 0)
3473 return VA_STATUS_ERROR_INVALID_PARAMETER;
3475 obj_config = obj_context->obj_config;
3476 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3478 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3479 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3480 } else if ((VAEntrypointEncSlice == obj_config->entrypoint ) ||
3481 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3482 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3483 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3485 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3492 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3494 struct i965_driver_data *i965 = i965_driver_data(ctx);
3495 struct object_context *obj_context = CONTEXT(context);
3496 struct object_config *obj_config;
3498 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3499 obj_config = obj_context->obj_config;
3500 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3502 if (obj_context->codec_type == CODEC_PROC) {
3503 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3504 } else if (obj_context->codec_type == CODEC_ENC) {
3505 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3506 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3507 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3508 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3510 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3511 obj_context->codec_state.encode.num_packed_header_data_ext) {
3512 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3513 return VA_STATUS_ERROR_INVALID_PARAMETER;
3515 if (!obj_context->codec_state.encode.pic_param_ext) {
3516 return VA_STATUS_ERROR_INVALID_PARAMETER;
3518 if (!obj_context->codec_state.encode.seq_param_ext &&
3519 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3520 /* The seq_param is not mandatory for VP9 encoding */
3521 if (obj_config->profile != VAProfileVP9Profile0)
3522 return VA_STATUS_ERROR_INVALID_PARAMETER;
3524 if ((obj_context->codec_state.encode.num_slice_params_ext <=0) &&
3525 ((obj_config->profile != VAProfileVP8Version0_3) &&
3526 (obj_config->profile != VAProfileVP9Profile0))) {
3527 return VA_STATUS_ERROR_INVALID_PARAMETER;
3530 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3531 (obj_context->codec_state.encode.num_slice_params_ext !=
3532 obj_context->codec_state.encode.slice_index)) {
3533 WARN_ONCE("packed slice_header data is missing for some slice"
3534 " under packed SLICE_HEADER mode\n");
3535 return VA_STATUS_ERROR_INVALID_PARAMETER;
3538 if (obj_context->codec_state.decode.pic_param == NULL) {
3539 return VA_STATUS_ERROR_INVALID_PARAMETER;
3541 if (obj_context->codec_state.decode.num_slice_params <=0) {
3542 return VA_STATUS_ERROR_INVALID_PARAMETER;
3544 if (obj_context->codec_state.decode.num_slice_datas <=0) {
3545 return VA_STATUS_ERROR_INVALID_PARAMETER;
3548 if (obj_context->codec_state.decode.num_slice_params !=
3549 obj_context->codec_state.decode.num_slice_datas) {
3550 return VA_STATUS_ERROR_INVALID_PARAMETER;
3553 if (obj_context->wrapper_context != VA_INVALID_ID) {
3554 /* call the vaEndPicture of wrapped driver */
3555 VADriverContextP pdrvctx;
3558 pdrvctx = i965->wrapper_pdrvctx;
3559 CALL_VTABLE(pdrvctx, va_status,
3560 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3566 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3567 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3571 i965_SyncSurface(VADriverContextP ctx,
3572 VASurfaceID render_target)
3574 struct i965_driver_data *i965 = i965_driver_data(ctx);
3575 struct object_surface *obj_surface = SURFACE(render_target);
3577 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3580 drm_intel_bo_wait_rendering(obj_surface->bo);
3582 return VA_STATUS_SUCCESS;
3586 i965_QuerySurfaceStatus(VADriverContextP ctx,
3587 VASurfaceID render_target,
3588 VASurfaceStatus *status) /* out */
3590 struct i965_driver_data *i965 = i965_driver_data(ctx);
3591 struct object_surface *obj_surface = SURFACE(render_target);
3593 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3595 if (obj_surface->bo) {
3596 if (drm_intel_bo_busy(obj_surface->bo)){
3597 *status = VASurfaceRendering;
3600 *status = VASurfaceReady;
3603 *status = VASurfaceReady;
3606 return VA_STATUS_SUCCESS;
3609 static VADisplayAttribute *
3610 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3612 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3615 if (!i965->display_attributes)
3618 for (i = 0; i < i965->num_display_attributes; i++) {
3619 if (i965->display_attributes[i].type == type)
3620 return &i965->display_attributes[i];
3626 i965_display_attributes_terminate(VADriverContextP ctx)
3628 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3630 if (i965->display_attributes) {
3631 free(i965->display_attributes);
3632 i965->display_attributes = NULL;
3633 i965->num_display_attributes = 0;
3638 i965_display_attributes_init(VADriverContextP ctx)
3640 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3642 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3643 i965->display_attributes = malloc(
3644 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3645 if (!i965->display_attributes)
3649 i965->display_attributes,
3650 i965_display_attributes,
3651 sizeof(i965_display_attributes)
3654 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3655 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3656 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3657 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3658 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3660 if (!i965->rotation_attrib ||
3661 !i965->brightness_attrib ||
3662 !i965->contrast_attrib ||
3663 !i965->hue_attrib ||
3664 !i965->saturation_attrib) {
3670 i965_display_attributes_terminate(ctx);
3675 * Query display attributes
3676 * The caller must provide a "attr_list" array that can hold at
3677 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3678 * returned in "attr_list" is returned in "num_attributes".
3681 i965_QueryDisplayAttributes(
3682 VADriverContextP ctx,
3683 VADisplayAttribute *attribs, /* out */
3684 int *num_attribs_ptr /* out */
3687 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3689 if (attribs && num_attribs > 0)
3690 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3692 if (num_attribs_ptr)
3693 *num_attribs_ptr = num_attribs;
3695 return VA_STATUS_SUCCESS;
3699 * Get display attributes
3700 * This function returns the current attribute values in "attr_list".
3701 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3702 * from vaQueryDisplayAttributes() can have their values retrieved.
3705 i965_GetDisplayAttributes(
3706 VADriverContextP ctx,
3707 VADisplayAttribute *attribs, /* inout */
3708 int num_attribs /* in */
3713 for (i = 0; i < num_attribs; i++) {
3714 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3716 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3717 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3718 dst_attrib->min_value = src_attrib->min_value;
3719 dst_attrib->max_value = src_attrib->max_value;
3720 dst_attrib->value = src_attrib->value;
3723 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3725 return VA_STATUS_SUCCESS;
3729 * Set display attributes
3730 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3731 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3732 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3735 i965_SetDisplayAttributes(
3736 VADriverContextP ctx,
3737 VADisplayAttribute *attribs, /* in */
3738 int num_attribs /* in */
3743 for (i = 0; i < num_attribs; i++) {
3744 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3746 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3748 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3750 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3753 if (src_attrib->value < dst_attrib->min_value ||
3754 src_attrib->value > dst_attrib->max_value)
3755 return VA_STATUS_ERROR_INVALID_PARAMETER;
3757 dst_attrib->value = src_attrib->value;
3758 /* XXX: track modified attributes through timestamps */
3760 return VA_STATUS_SUCCESS;
3764 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3765 VASurfaceID surface,
3766 void **buffer, /* out */
3767 unsigned int *stride) /* out */
3770 return VA_STATUS_ERROR_UNIMPLEMENTED;
3774 i965_destroy_heap(struct object_heap *heap,
3775 void (*func)(struct object_heap *heap, struct object_base *object))
3777 struct object_base *object;
3778 object_heap_iterator iter;
3780 object = object_heap_first(heap, &iter);
3786 object = object_heap_next(heap, &iter);
3789 object_heap_destroy(heap);
3794 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3797 i965_CreateImage(VADriverContextP ctx,
3798 VAImageFormat *format,
3801 VAImage *out_image) /* out */
3803 struct i965_driver_data *i965 = i965_driver_data(ctx);
3804 struct object_image *obj_image;
3805 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3807 unsigned int size2, size, awidth, aheight;
3809 out_image->image_id = VA_INVALID_ID;
3810 out_image->buf = VA_INVALID_ID;
3812 image_id = NEW_IMAGE_ID();
3813 if (image_id == VA_INVALID_ID)
3814 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3816 obj_image = IMAGE(image_id);
3818 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3819 obj_image->bo = NULL;
3820 obj_image->palette = NULL;
3821 obj_image->derived_surface = VA_INVALID_ID;
3823 VAImage * const image = &obj_image->image;
3824 image->image_id = image_id;
3825 image->buf = VA_INVALID_ID;
3827 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3829 if ((format->fourcc == VA_FOURCC_YV12) ||
3830 (format->fourcc == VA_FOURCC_I420)) {
3831 if (awidth % 128 != 0) {
3832 awidth = ALIGN(width, 128);
3836 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3837 size = awidth * aheight;
3838 size2 = (awidth / 2) * (aheight / 2);
3840 image->num_palette_entries = 0;
3841 image->entry_bytes = 0;
3842 memset(image->component_order, 0, sizeof(image->component_order));
3844 switch (format->fourcc) {
3845 case VA_FOURCC_IA44:
3846 case VA_FOURCC_AI44:
3847 image->num_planes = 1;
3848 image->pitches[0] = awidth;
3849 image->offsets[0] = 0;
3850 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3851 image->num_palette_entries = 16;
3852 image->entry_bytes = 3;
3853 image->component_order[0] = 'R';
3854 image->component_order[1] = 'G';
3855 image->component_order[2] = 'B';
3857 case VA_FOURCC_IA88:
3858 case VA_FOURCC_AI88:
3859 image->num_planes = 1;
3860 image->pitches[0] = awidth * 2;
3861 image->offsets[0] = 0;
3862 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3863 image->num_palette_entries = 256;
3864 image->entry_bytes = 3;
3865 image->component_order[0] = 'R';
3866 image->component_order[1] = 'G';
3867 image->component_order[2] = 'B';
3869 case VA_FOURCC_ARGB:
3870 case VA_FOURCC_ABGR:
3871 case VA_FOURCC_BGRA:
3872 case VA_FOURCC_RGBA:
3873 case VA_FOURCC_BGRX:
3874 case VA_FOURCC_RGBX:
3875 image->num_planes = 1;
3876 image->pitches[0] = awidth * 4;
3877 image->offsets[0] = 0;
3878 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3880 case VA_FOURCC_YV12:
3881 image->num_planes = 3;
3882 image->pitches[0] = awidth;
3883 image->offsets[0] = 0;
3884 image->pitches[1] = awidth / 2;
3885 image->offsets[1] = size;
3886 image->pitches[2] = awidth / 2;
3887 image->offsets[2] = size + size2;
3888 image->data_size = size + 2 * size2;
3890 case VA_FOURCC_I420:
3891 image->num_planes = 3;
3892 image->pitches[0] = awidth;
3893 image->offsets[0] = 0;
3894 image->pitches[1] = awidth / 2;
3895 image->offsets[1] = size;
3896 image->pitches[2] = awidth / 2;
3897 image->offsets[2] = size + size2;
3898 image->data_size = size + 2 * size2;
3900 case VA_FOURCC_422H:
3901 image->num_planes = 3;
3902 image->pitches[0] = awidth;
3903 image->offsets[0] = 0;
3904 image->pitches[1] = awidth / 2;
3905 image->offsets[1] = size;
3906 image->pitches[2] = awidth / 2;
3907 image->offsets[2] = size + (awidth / 2) * aheight;
3908 image->data_size = size + 2 * ((awidth / 2) * aheight);
3910 case VA_FOURCC_NV12:
3911 image->num_planes = 2;
3912 image->pitches[0] = awidth;
3913 image->offsets[0] = 0;
3914 image->pitches[1] = awidth;
3915 image->offsets[1] = size;
3916 image->data_size = size + 2 * size2;
3918 case VA_FOURCC_YUY2:
3919 case VA_FOURCC_UYVY:
3920 image->num_planes = 1;
3921 image->pitches[0] = awidth * 2;
3922 image->offsets[0] = 0;
3923 image->data_size = size * 2;
3925 case VA_FOURCC_P010:
3926 image->num_planes = 2;
3927 image->pitches[0] = awidth * 2;
3928 image->offsets[0] = 0;
3929 image->pitches[1] = awidth * 2;
3930 image->offsets[1] = size * 2;
3931 image->data_size = size * 2 + 2 * size2 * 2;
3937 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
3938 image->data_size, 1, NULL, &image->buf);
3939 if (va_status != VA_STATUS_SUCCESS)
3942 struct object_buffer *obj_buffer = BUFFER(image->buf);
3945 !obj_buffer->buffer_store ||
3946 !obj_buffer->buffer_store->bo)
3947 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3949 obj_image->bo = obj_buffer->buffer_store->bo;
3950 dri_bo_reference(obj_image->bo);
3952 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3953 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3954 if (!obj_image->palette)
3958 image->image_id = image_id;
3959 image->format = *format;
3960 image->width = width;
3961 image->height = height;
3963 *out_image = *image;
3964 return VA_STATUS_SUCCESS;
3967 i965_DestroyImage(ctx, image_id);
3972 i965_check_alloc_surface_bo(VADriverContextP ctx,
3973 struct object_surface *obj_surface,
3975 unsigned int fourcc,
3976 unsigned int subsampling)
3978 struct i965_driver_data *i965 = i965_driver_data(ctx);
3979 int region_width, region_height;
3981 if (obj_surface->bo) {
3982 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3983 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3984 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
3985 return VA_STATUS_SUCCESS;
3988 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
3989 obj_surface->x_cr_offset = 0;
3991 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
3993 if ((tiled && !obj_surface->user_disable_tiling)) {
3994 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
3995 fourcc != VA_FOURCC_IYUV &&
3996 fourcc != VA_FOURCC_YV12,
3997 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3999 if (obj_surface->user_h_stride_set) {
4000 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
4002 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
4004 if (obj_surface->user_v_stride_set) {
4005 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
4007 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
4009 region_height = obj_surface->height;
4012 case VA_FOURCC_NV12:
4013 case VA_FOURCC_P010:
4014 assert(subsampling == SUBSAMPLE_YUV420);
4015 obj_surface->cb_cr_pitch = obj_surface->width;
4016 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4017 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4018 obj_surface->y_cb_offset = obj_surface->height;
4019 obj_surface->y_cr_offset = obj_surface->height;
4020 region_width = obj_surface->width;
4021 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4025 case VA_FOURCC_IMC1:
4026 assert(subsampling == SUBSAMPLE_YUV420);
4027 obj_surface->cb_cr_pitch = obj_surface->width;
4028 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4029 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4030 obj_surface->y_cr_offset = obj_surface->height;
4031 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
4032 region_width = obj_surface->width;
4033 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4037 case VA_FOURCC_IMC3:
4038 assert(subsampling == SUBSAMPLE_YUV420);
4039 obj_surface->cb_cr_pitch = obj_surface->width;
4040 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4041 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4042 obj_surface->y_cb_offset = obj_surface->height;
4043 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4044 region_width = obj_surface->width;
4045 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4049 case VA_FOURCC_422H:
4050 assert(subsampling == SUBSAMPLE_YUV422H);
4051 obj_surface->cb_cr_pitch = obj_surface->width;
4052 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4053 obj_surface->cb_cr_height = obj_surface->orig_height;
4054 obj_surface->y_cb_offset = obj_surface->height;
4055 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4056 region_width = obj_surface->width;
4057 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4061 case VA_FOURCC_422V:
4062 assert(subsampling == SUBSAMPLE_YUV422V);
4063 obj_surface->cb_cr_pitch = obj_surface->width;
4064 obj_surface->cb_cr_width = obj_surface->orig_width;
4065 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4066 obj_surface->y_cb_offset = obj_surface->height;
4067 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4068 region_width = obj_surface->width;
4069 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4073 case VA_FOURCC_411P:
4074 assert(subsampling == SUBSAMPLE_YUV411);
4075 obj_surface->cb_cr_pitch = obj_surface->width;
4076 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4077 obj_surface->cb_cr_height = obj_surface->orig_height;
4078 obj_surface->y_cb_offset = obj_surface->height;
4079 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4080 region_width = obj_surface->width;
4081 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4085 case VA_FOURCC_444P:
4086 assert(subsampling == SUBSAMPLE_YUV444);
4087 obj_surface->cb_cr_pitch = obj_surface->width;
4088 obj_surface->cb_cr_width = obj_surface->orig_width;
4089 obj_surface->cb_cr_height = obj_surface->orig_height;
4090 obj_surface->y_cb_offset = obj_surface->height;
4091 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4092 region_width = obj_surface->width;
4093 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4097 case VA_FOURCC_Y800:
4098 assert(subsampling == SUBSAMPLE_YUV400);
4099 obj_surface->cb_cr_pitch = 0;
4100 obj_surface->cb_cr_width = 0;
4101 obj_surface->cb_cr_height = 0;
4102 obj_surface->y_cb_offset = 0;
4103 obj_surface->y_cr_offset = 0;
4104 region_width = obj_surface->width;
4105 region_height = obj_surface->height;
4109 case VA_FOURCC_YUY2:
4110 case VA_FOURCC_UYVY:
4111 assert(subsampling == SUBSAMPLE_YUV422H);
4112 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4113 obj_surface->cb_cr_pitch = obj_surface->width;
4114 obj_surface->y_cb_offset = 0;
4115 obj_surface->y_cr_offset = 0;
4116 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4117 obj_surface->cb_cr_height = obj_surface->orig_height;
4118 region_width = obj_surface->width;
4119 region_height = obj_surface->height;
4123 case VA_FOURCC_RGBA:
4124 case VA_FOURCC_RGBX:
4125 case VA_FOURCC_BGRA:
4126 case VA_FOURCC_BGRX:
4127 assert(subsampling == SUBSAMPLE_RGBX);
4129 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4130 region_width = obj_surface->width;
4131 region_height = obj_surface->height;
4135 /* Never get here */
4136 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4140 assert(subsampling == SUBSAMPLE_YUV420 ||
4141 subsampling == SUBSAMPLE_YUV422H ||
4142 subsampling == SUBSAMPLE_YUV422V ||
4143 subsampling == SUBSAMPLE_RGBX);
4145 region_width = obj_surface->width;
4146 region_height = obj_surface->height;
4149 case VA_FOURCC_NV12:
4150 case VA_FOURCC_P010:
4151 obj_surface->y_cb_offset = obj_surface->height;
4152 obj_surface->y_cr_offset = obj_surface->height;
4153 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4154 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4155 obj_surface->cb_cr_pitch = obj_surface->width;
4156 region_height = obj_surface->height + obj_surface->height / 2;
4159 case VA_FOURCC_YV16:
4160 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4161 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4162 obj_surface->cb_cr_height = obj_surface->orig_height;
4163 obj_surface->y_cr_offset = obj_surface->height;
4164 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4165 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4166 region_width = obj_surface->width;
4167 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4170 case VA_FOURCC_YV12:
4171 case VA_FOURCC_I420:
4172 if (fourcc == VA_FOURCC_YV12) {
4173 obj_surface->y_cr_offset = obj_surface->height;
4174 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4176 obj_surface->y_cb_offset = obj_surface->height;
4177 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4180 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4181 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4182 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4183 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4184 region_width = obj_surface->width;
4185 region_height = obj_surface->height + obj_surface->height / 2;
4188 case VA_FOURCC_YUY2:
4189 case VA_FOURCC_UYVY:
4190 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4191 obj_surface->y_cb_offset = 0;
4192 obj_surface->y_cr_offset = 0;
4193 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4194 obj_surface->cb_cr_height = obj_surface->orig_height;
4195 obj_surface->cb_cr_pitch = obj_surface->width;
4196 region_width = obj_surface->width;
4197 region_height = obj_surface->height;
4199 case VA_FOURCC_RGBA:
4200 case VA_FOURCC_RGBX:
4201 case VA_FOURCC_BGRA:
4202 case VA_FOURCC_BGRX:
4203 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4204 region_width = obj_surface->width;
4205 region_height = obj_surface->height;
4209 /* Never get here */
4210 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4215 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4217 if ((tiled && !obj_surface->user_disable_tiling)) {
4218 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4219 unsigned long pitch;
4221 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4229 assert(tiling_mode == I915_TILING_Y);
4230 assert(pitch == obj_surface->width);
4232 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4238 obj_surface->fourcc = fourcc;
4239 obj_surface->subsampling = subsampling;
4240 assert(obj_surface->bo);
4241 return VA_STATUS_SUCCESS;
4244 VAStatus i965_DeriveImage(VADriverContextP ctx,
4245 VASurfaceID surface,
4246 VAImage *out_image) /* out */
4248 struct i965_driver_data *i965 = i965_driver_data(ctx);
4249 struct object_image *obj_image;
4250 struct object_surface *obj_surface;
4252 unsigned int w_pitch;
4253 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4255 out_image->image_id = VA_INVALID_ID;
4256 obj_surface = SURFACE(surface);
4259 return VA_STATUS_ERROR_INVALID_SURFACE;
4261 if (!obj_surface->bo) {
4262 unsigned int is_tiled = 0;
4263 unsigned int fourcc = VA_FOURCC_YV12;
4264 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4265 int sampling = get_sampling_from_fourcc(fourcc);
4266 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4267 if (va_status != VA_STATUS_SUCCESS)
4271 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4273 w_pitch = obj_surface->width;
4275 image_id = NEW_IMAGE_ID();
4277 if (image_id == VA_INVALID_ID)
4278 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4280 obj_image = IMAGE(image_id);
4283 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4285 obj_image->bo = NULL;
4286 obj_image->palette = NULL;
4287 obj_image->derived_surface = VA_INVALID_ID;
4289 VAImage * const image = &obj_image->image;
4291 memset(image, 0, sizeof(*image));
4292 image->image_id = image_id;
4293 image->buf = VA_INVALID_ID;
4294 image->num_palette_entries = 0;
4295 image->entry_bytes = 0;
4296 image->width = obj_surface->orig_width;
4297 image->height = obj_surface->orig_height;
4298 image->data_size = obj_surface->size;
4300 image->format.fourcc = obj_surface->fourcc;
4301 image->format.byte_order = VA_LSB_FIRST;
4302 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4304 if (!image->format.bits_per_pixel)
4307 switch (image->format.fourcc) {
4308 case VA_FOURCC_YV12:
4309 image->num_planes = 3;
4310 image->pitches[0] = w_pitch; /* Y */
4311 image->offsets[0] = 0;
4312 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4313 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4314 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4315 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4318 case VA_FOURCC_YV16:
4319 image->num_planes = 3;
4320 image->pitches[0] = w_pitch; /* Y */
4321 image->offsets[0] = 0;
4322 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4323 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4324 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4325 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4328 case VA_FOURCC_NV12:
4329 case VA_FOURCC_P010:
4330 image->num_planes = 2;
4331 image->pitches[0] = w_pitch; /* Y */
4332 image->offsets[0] = 0;
4333 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4334 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4337 case VA_FOURCC_I420:
4338 case VA_FOURCC_422H:
4339 case VA_FOURCC_IMC3:
4340 case VA_FOURCC_444P:
4341 case VA_FOURCC_422V:
4342 case VA_FOURCC_411P:
4343 image->num_planes = 3;
4344 image->pitches[0] = w_pitch; /* Y */
4345 image->offsets[0] = 0;
4346 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4347 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4348 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4349 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4352 case VA_FOURCC_YUY2:
4353 case VA_FOURCC_UYVY:
4354 case VA_FOURCC_Y800:
4355 image->num_planes = 1;
4356 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4357 image->offsets[0] = 0;
4359 case VA_FOURCC_RGBA:
4360 case VA_FOURCC_RGBX:
4361 case VA_FOURCC_BGRA:
4362 case VA_FOURCC_BGRX:
4363 image->num_planes = 1;
4364 image->pitches[0] = obj_surface->width;
4366 switch (image->format.fourcc) {
4367 case VA_FOURCC_RGBA:
4368 case VA_FOURCC_RGBX:
4369 image->format.red_mask = 0x000000ff;
4370 image->format.green_mask = 0x0000ff00;
4371 image->format.blue_mask = 0x00ff0000;
4373 case VA_FOURCC_BGRA:
4374 case VA_FOURCC_BGRX:
4375 image->format.red_mask = 0x00ff0000;
4376 image->format.green_mask = 0x0000ff00;
4377 image->format.blue_mask = 0x000000ff;
4383 switch (image->format.fourcc) {
4384 case VA_FOURCC_RGBA:
4385 case VA_FOURCC_BGRA:
4386 image->format.alpha_mask = 0xff000000;
4387 image->format.depth = 32;
4389 case VA_FOURCC_RGBX:
4390 case VA_FOURCC_BGRX:
4391 image->format.alpha_mask = 0x00000000;
4392 image->format.depth = 24;
4403 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4404 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4405 if (va_status != VA_STATUS_SUCCESS)
4408 struct object_buffer *obj_buffer = BUFFER(image->buf);
4411 !obj_buffer->buffer_store ||
4412 !obj_buffer->buffer_store->bo)
4413 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4415 obj_image->bo = obj_buffer->buffer_store->bo;
4416 dri_bo_reference(obj_image->bo);
4418 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4419 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4420 if (!obj_image->palette) {
4421 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4426 *out_image = *image;
4427 obj_surface->flags |= SURFACE_DERIVED;
4428 obj_surface->derived_image_id = image_id;
4429 obj_image->derived_surface = surface;
4431 return VA_STATUS_SUCCESS;
4434 i965_DestroyImage(ctx, image_id);
4439 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4441 object_heap_free(heap, obj);
4446 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4448 struct i965_driver_data *i965 = i965_driver_data(ctx);
4449 struct object_image *obj_image = IMAGE(image);
4450 struct object_surface *obj_surface;
4453 return VA_STATUS_SUCCESS;
4455 dri_bo_unreference(obj_image->bo);
4456 obj_image->bo = NULL;
4458 if (obj_image->image.buf != VA_INVALID_ID) {
4459 i965_DestroyBuffer(ctx, obj_image->image.buf);
4460 obj_image->image.buf = VA_INVALID_ID;
4463 if (obj_image->palette) {
4464 free(obj_image->palette);
4465 obj_image->palette = NULL;
4468 obj_surface = SURFACE(obj_image->derived_surface);
4471 obj_surface->flags &= ~SURFACE_DERIVED;
4472 obj_surface->derived_image_id = VA_INVALID_ID;
4475 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4477 return VA_STATUS_SUCCESS;
4481 * pointer to an array holding the palette data. The size of the array is
4482 * num_palette_entries * entry_bytes in size. The order of the components
4483 * in the palette is described by the component_order in VASubpicture struct
4486 i965_SetImagePalette(VADriverContextP ctx,
4488 unsigned char *palette)
4490 struct i965_driver_data *i965 = i965_driver_data(ctx);
4493 struct object_image *obj_image = IMAGE(image);
4495 return VA_STATUS_ERROR_INVALID_IMAGE;
4497 if (!obj_image->palette)
4498 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4500 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4501 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
4502 ((unsigned int)palette[3*i + 1] << 8) |
4503 (unsigned int)palette[3*i + 2]);
4504 return VA_STATUS_SUCCESS;
4508 get_sampling_from_fourcc(unsigned int fourcc)
4510 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4512 if (info && (info->flag & I_S))
4513 return info->subsampling;
4519 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4520 const uint8_t *src, unsigned int src_stride,
4521 unsigned int len, unsigned int height)
4525 for (i = 0; i < height; i++) {
4526 memcpy(dst, src, len);
4533 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4534 struct object_surface *obj_surface,
4535 const VARectangle *rect)
4537 uint8_t *dst[3], *src[3];
4539 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4540 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4541 unsigned int tiling, swizzle;
4542 VAStatus va_status = VA_STATUS_SUCCESS;
4544 if (!obj_surface->bo)
4545 return VA_STATUS_ERROR_INVALID_SURFACE;
4547 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4548 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4550 if (tiling != I915_TILING_NONE)
4551 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4553 dri_bo_map(obj_surface->bo, 0);
4555 if (!obj_surface->bo->virtual)
4556 return VA_STATUS_ERROR_INVALID_SURFACE;
4558 /* Dest VA image has either I420 or YV12 format.
4559 Source VA surface alway has I420 format */
4560 dst[Y] = image_data + obj_image->image.offsets[Y];
4561 src[0] = (uint8_t *)obj_surface->bo->virtual;
4562 dst[U] = image_data + obj_image->image.offsets[U];
4563 src[1] = src[0] + obj_surface->width * obj_surface->height;
4564 dst[V] = image_data + obj_image->image.offsets[V];
4565 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4568 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4569 src[0] += rect->y * obj_surface->width + rect->x;
4570 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4571 src[0], obj_surface->width,
4572 rect->width, rect->height);
4575 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4576 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4577 memcpy_pic(dst[U], obj_image->image.pitches[U],
4578 src[1], obj_surface->width / 2,
4579 rect->width / 2, rect->height / 2);
4582 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4583 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4584 memcpy_pic(dst[V], obj_image->image.pitches[V],
4585 src[2], obj_surface->width / 2,
4586 rect->width / 2, rect->height / 2);
4588 if (tiling != I915_TILING_NONE)
4589 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4591 dri_bo_unmap(obj_surface->bo);
4597 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4598 struct object_surface *obj_surface,
4599 const VARectangle *rect)
4601 uint8_t *dst[2], *src[2];
4602 unsigned int tiling, swizzle;
4603 VAStatus va_status = VA_STATUS_SUCCESS;
4605 if (!obj_surface->bo)
4606 return VA_STATUS_ERROR_INVALID_SURFACE;
4608 assert(obj_surface->fourcc);
4609 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4611 if (tiling != I915_TILING_NONE)
4612 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4614 dri_bo_map(obj_surface->bo, 0);
4616 if (!obj_surface->bo->virtual)
4617 return VA_STATUS_ERROR_INVALID_SURFACE;
4619 /* Both dest VA image and source surface have NV12 format */
4620 dst[0] = image_data + obj_image->image.offsets[0];
4621 src[0] = (uint8_t *)obj_surface->bo->virtual;
4622 dst[1] = image_data + obj_image->image.offsets[1];
4623 src[1] = src[0] + obj_surface->width * obj_surface->height;
4626 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4627 src[0] += rect->y * obj_surface->width + rect->x;
4628 memcpy_pic(dst[0], obj_image->image.pitches[0],
4629 src[0], obj_surface->width,
4630 rect->width, rect->height);
4633 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4634 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4635 memcpy_pic(dst[1], obj_image->image.pitches[1],
4636 src[1], obj_surface->width,
4637 rect->width, rect->height / 2);
4639 if (tiling != I915_TILING_NONE)
4640 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4642 dri_bo_unmap(obj_surface->bo);
4648 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4649 struct object_surface *obj_surface,
4650 const VARectangle *rect)
4653 unsigned int tiling, swizzle;
4654 VAStatus va_status = VA_STATUS_SUCCESS;
4656 if (!obj_surface->bo)
4657 return VA_STATUS_ERROR_INVALID_SURFACE;
4659 assert(obj_surface->fourcc);
4660 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4662 if (tiling != I915_TILING_NONE)
4663 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4665 dri_bo_map(obj_surface->bo, 0);
4667 if (!obj_surface->bo->virtual)
4668 return VA_STATUS_ERROR_INVALID_SURFACE;
4670 /* Both dest VA image and source surface have YUYV format */
4671 dst = image_data + obj_image->image.offsets[0];
4672 src = (uint8_t *)obj_surface->bo->virtual;
4675 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
4676 src += rect->y * obj_surface->width + rect->x*2;
4677 memcpy_pic(dst, obj_image->image.pitches[0],
4678 src, obj_surface->width*2,
4679 rect->width*2, rect->height);
4681 if (tiling != I915_TILING_NONE)
4682 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4684 dri_bo_unmap(obj_surface->bo);
4690 i965_sw_getimage(VADriverContextP ctx,
4691 struct object_surface *obj_surface, struct object_image *obj_image,
4692 const VARectangle *rect)
4694 void *image_data = NULL;
4697 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4698 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4700 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4701 if (va_status != VA_STATUS_SUCCESS)
4704 switch (obj_image->image.format.fourcc) {
4705 case VA_FOURCC_YV12:
4706 case VA_FOURCC_I420:
4707 get_image_i420(obj_image, image_data, obj_surface, rect);
4709 case VA_FOURCC_NV12:
4710 get_image_nv12(obj_image, image_data, obj_surface, rect);
4712 case VA_FOURCC_YUY2:
4713 /* YUY2 is the format supported by overlay plane */
4714 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4717 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4720 if (va_status != VA_STATUS_SUCCESS)
4723 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4728 i965_hw_getimage(VADriverContextP ctx,
4729 struct object_surface *obj_surface, struct object_image *obj_image,
4730 const VARectangle *rect)
4732 struct i965_surface src_surface;
4733 struct i965_surface dst_surface;
4735 src_surface.base = (struct object_base *)obj_surface;
4736 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4737 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4739 dst_surface.base = (struct object_base *)obj_image;
4740 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4741 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4743 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4747 i965_GetImage(VADriverContextP ctx,
4748 VASurfaceID surface,
4749 int x, /* coordinates of the upper left source pixel */
4751 unsigned int width, /* width and height of the region */
4752 unsigned int height,
4755 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4756 struct object_surface * const obj_surface = SURFACE(surface);
4757 struct object_image * const obj_image = IMAGE(image);
4762 return VA_STATUS_ERROR_INVALID_SURFACE;
4763 if (!obj_surface->bo) /* don't get anything, keep previous data */
4764 return VA_STATUS_SUCCESS;
4765 if (is_surface_busy(i965, obj_surface))
4766 return VA_STATUS_ERROR_SURFACE_BUSY;
4768 if (!obj_image || !obj_image->bo)
4769 return VA_STATUS_ERROR_INVALID_IMAGE;
4770 if (is_image_busy(i965, obj_image, surface))
4771 return VA_STATUS_ERROR_SURFACE_BUSY;
4774 return VA_STATUS_ERROR_INVALID_PARAMETER;
4775 if (x + width > obj_surface->orig_width ||
4776 y + height > obj_surface->orig_height)
4777 return VA_STATUS_ERROR_INVALID_PARAMETER;
4778 if (x + width > obj_image->image.width ||
4779 y + height > obj_image->image.height)
4780 return VA_STATUS_ERROR_INVALID_PARAMETER;
4785 rect.height = height;
4787 if (HAS_ACCELERATED_GETIMAGE(i965))
4788 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
4790 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
4796 put_image_i420(struct object_surface *obj_surface,
4797 const VARectangle *dst_rect,
4798 struct object_image *obj_image, uint8_t *image_data,
4799 const VARectangle *src_rect)
4801 uint8_t *dst[3], *src[3];
4803 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4804 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4805 unsigned int tiling, swizzle;
4806 VAStatus va_status = VA_STATUS_SUCCESS;
4808 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4810 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4811 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4812 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4813 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4815 if (tiling != I915_TILING_NONE)
4816 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4818 dri_bo_map(obj_surface->bo, 0);
4820 if (!obj_surface->bo->virtual)
4821 return VA_STATUS_ERROR_INVALID_SURFACE;
4823 /* Dest VA image has either I420 or YV12 format.
4824 Source VA surface alway has I420 format */
4825 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4826 src[Y] = image_data + obj_image->image.offsets[Y];
4827 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4828 src[U] = image_data + obj_image->image.offsets[U];
4829 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4830 src[V] = image_data + obj_image->image.offsets[V];
4833 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4834 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4835 memcpy_pic(dst[0], obj_surface->width,
4836 src[Y], obj_image->image.pitches[Y],
4837 src_rect->width, src_rect->height);
4840 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4841 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4842 memcpy_pic(dst[1], obj_surface->width / 2,
4843 src[U], obj_image->image.pitches[U],
4844 src_rect->width / 2, src_rect->height / 2);
4847 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4848 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4849 memcpy_pic(dst[2], obj_surface->width / 2,
4850 src[V], obj_image->image.pitches[V],
4851 src_rect->width / 2, src_rect->height / 2);
4853 if (tiling != I915_TILING_NONE)
4854 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4856 dri_bo_unmap(obj_surface->bo);
4862 put_image_nv12(struct object_surface *obj_surface,
4863 const VARectangle *dst_rect,
4864 struct object_image *obj_image, uint8_t *image_data,
4865 const VARectangle *src_rect)
4867 uint8_t *dst[2], *src[2];
4868 unsigned int tiling, swizzle;
4869 VAStatus va_status = VA_STATUS_SUCCESS;
4871 if (!obj_surface->bo)
4872 return VA_STATUS_ERROR_INVALID_SURFACE;
4874 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4875 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4876 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4877 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4879 if (tiling != I915_TILING_NONE)
4880 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4882 dri_bo_map(obj_surface->bo, 0);
4884 if (!obj_surface->bo->virtual)
4885 return VA_STATUS_ERROR_INVALID_SURFACE;
4887 /* Both dest VA image and source surface have NV12 format */
4888 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4889 src[0] = image_data + obj_image->image.offsets[0];
4890 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4891 src[1] = image_data + obj_image->image.offsets[1];
4894 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4895 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
4896 memcpy_pic(dst[0], obj_surface->width,
4897 src[0], obj_image->image.pitches[0],
4898 src_rect->width, src_rect->height);
4901 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
4902 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
4903 memcpy_pic(dst[1], obj_surface->width,
4904 src[1], obj_image->image.pitches[1],
4905 src_rect->width, src_rect->height / 2);
4907 if (tiling != I915_TILING_NONE)
4908 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4910 dri_bo_unmap(obj_surface->bo);
4916 put_image_yuy2(struct object_surface *obj_surface,
4917 const VARectangle *dst_rect,
4918 struct object_image *obj_image, uint8_t *image_data,
4919 const VARectangle *src_rect)
4922 unsigned int tiling, swizzle;
4923 VAStatus va_status = VA_STATUS_SUCCESS;
4925 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4926 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4927 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4928 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4929 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4931 if (tiling != I915_TILING_NONE)
4932 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4934 dri_bo_map(obj_surface->bo, 0);
4936 if (!obj_surface->bo->virtual)
4937 return VA_STATUS_ERROR_INVALID_SURFACE;
4939 /* Both dest VA image and source surface have YUY2 format */
4940 dst = (uint8_t *)obj_surface->bo->virtual;
4941 src = image_data + obj_image->image.offsets[0];
4943 /* YUYV packed plane */
4944 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
4945 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
4946 memcpy_pic(dst, obj_surface->width*2,
4947 src, obj_image->image.pitches[0],
4948 src_rect->width*2, src_rect->height);
4950 if (tiling != I915_TILING_NONE)
4951 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4953 dri_bo_unmap(obj_surface->bo);
4959 i965_sw_putimage(VADriverContextP ctx,
4960 struct object_surface *obj_surface, struct object_image *obj_image,
4961 const VARectangle *src_rect, const VARectangle *dst_rect)
4963 VAStatus va_status = VA_STATUS_SUCCESS;
4964 void *image_data = NULL;
4966 /* XXX: don't allow scaling */
4967 if (src_rect->width != dst_rect->width ||
4968 src_rect->height != dst_rect->height)
4969 return VA_STATUS_ERROR_INVALID_PARAMETER;
4971 if (obj_surface->fourcc) {
4972 /* Don't allow format mismatch */
4973 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4974 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4978 /* VA is surface not used for decoding, use same VA image format */
4979 va_status = i965_check_alloc_surface_bo(
4982 0, /* XXX: don't use tiled surface */
4983 obj_image->image.format.fourcc,
4984 get_sampling_from_fourcc (obj_image->image.format.fourcc));
4987 if (va_status != VA_STATUS_SUCCESS)
4990 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4991 if (va_status != VA_STATUS_SUCCESS)
4994 switch (obj_image->image.format.fourcc) {
4995 case VA_FOURCC_YV12:
4996 case VA_FOURCC_I420:
4997 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
4999 case VA_FOURCC_NV12:
5000 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
5002 case VA_FOURCC_YUY2:
5003 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
5006 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
5009 if (va_status != VA_STATUS_SUCCESS)
5012 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
5017 i965_hw_putimage(VADriverContextP ctx,
5018 struct object_surface *obj_surface, struct object_image *obj_image,
5019 const VARectangle *src_rect, const VARectangle *dst_rect)
5021 struct i965_surface src_surface, dst_surface;
5022 VAStatus va_status = VA_STATUS_SUCCESS;
5024 if (!obj_surface->bo) {
5025 unsigned int tiling, swizzle;
5026 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
5027 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
5029 i965_check_alloc_surface_bo(ctx,
5032 obj_image->image.format.fourcc,
5036 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
5038 src_surface.base = (struct object_base *)obj_image;
5039 src_surface.type = I965_SURFACE_TYPE_IMAGE;
5040 src_surface.flags = I965_SURFACE_FLAG_FRAME;
5042 dst_surface.base = (struct object_base *)obj_surface;
5043 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
5044 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
5046 va_status = i965_image_processing(ctx,
5056 i965_PutImage(VADriverContextP ctx,
5057 VASurfaceID surface,
5061 unsigned int src_width,
5062 unsigned int src_height,
5065 unsigned int dest_width,
5066 unsigned int dest_height)
5068 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5069 struct object_surface * const obj_surface = SURFACE(surface);
5070 struct object_image * const obj_image = IMAGE(image);
5071 VARectangle src_rect, dst_rect;
5075 return VA_STATUS_ERROR_INVALID_SURFACE;
5076 if (is_surface_busy(i965, obj_surface))
5077 return VA_STATUS_ERROR_SURFACE_BUSY;
5079 if (!obj_image || !obj_image->bo)
5080 return VA_STATUS_ERROR_INVALID_IMAGE;
5081 if (is_image_busy(i965, obj_image, surface))
5082 return VA_STATUS_ERROR_SURFACE_BUSY;
5086 src_x + src_width > obj_image->image.width ||
5087 src_y + src_height > obj_image->image.height)
5088 return VA_STATUS_ERROR_INVALID_PARAMETER;
5092 src_rect.width = src_width;
5093 src_rect.height = src_height;
5097 dest_x + dest_width > obj_surface->orig_width ||
5098 dest_y + dest_height > obj_surface->orig_height)
5099 return VA_STATUS_ERROR_INVALID_PARAMETER;
5101 dst_rect.x = dest_x;
5102 dst_rect.y = dest_y;
5103 dst_rect.width = dest_width;
5104 dst_rect.height = dest_height;
5106 if (HAS_ACCELERATED_PUTIMAGE(i965))
5107 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5108 &src_rect, &dst_rect);
5110 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5111 &src_rect, &dst_rect);
5117 i965_PutSurface(VADriverContextP ctx,
5118 VASurfaceID surface,
5119 void *draw, /* X Drawable */
5122 unsigned short srcw,
5123 unsigned short srch,
5126 unsigned short destw,
5127 unsigned short desth,
5128 VARectangle *cliprects, /* client supplied clip list */
5129 unsigned int number_cliprects, /* number of clip rects in the clip list */
5130 unsigned int flags) /* de-interlacing flags */
5133 if (IS_VA_X11(ctx)) {
5134 VARectangle src_rect, dst_rect;
5138 src_rect.width = srcw;
5139 src_rect.height = srch;
5143 dst_rect.width = destw;
5144 dst_rect.height = desth;
5146 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5147 cliprects, number_cliprects, flags);
5150 return VA_STATUS_ERROR_UNIMPLEMENTED;
5155 VADriverContextP ctx, /* in */
5156 VABufferID buf_id, /* in */
5157 VABufferType *type, /* out */
5158 unsigned int *size, /* out */
5159 unsigned int *num_elements /* out */
5162 struct i965_driver_data *i965 = NULL;
5163 struct object_buffer *obj_buffer = NULL;
5165 i965 = i965_driver_data(ctx);
5166 obj_buffer = BUFFER(buf_id);
5168 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5170 *type = obj_buffer->type;
5171 *size = obj_buffer->size_element;
5172 *num_elements = obj_buffer->num_elements;
5174 return VA_STATUS_SUCCESS;
5179 VADriverContextP ctx, /* in */
5180 VASurfaceID surface, /* in */
5181 unsigned int *fourcc, /* out */
5182 unsigned int *luma_stride, /* out */
5183 unsigned int *chroma_u_stride, /* out */
5184 unsigned int *chroma_v_stride, /* out */
5185 unsigned int *luma_offset, /* out */
5186 unsigned int *chroma_u_offset, /* out */
5187 unsigned int *chroma_v_offset, /* out */
5188 unsigned int *buffer_name, /* out */
5189 void **buffer /* out */
5192 VAStatus vaStatus = VA_STATUS_SUCCESS;
5193 struct i965_driver_data *i965 = i965_driver_data(ctx);
5194 struct object_surface *obj_surface = NULL;
5197 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5198 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5199 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5200 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5201 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5202 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5203 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5204 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5205 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5207 tmpImage.image_id = VA_INVALID_ID;
5209 obj_surface = SURFACE(surface);
5210 if (obj_surface == NULL) {
5211 // Surface is absent.
5212 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5216 // Lock functionality is absent now.
5217 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5218 // Surface is locked already.
5219 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5223 vaStatus = i965_DeriveImage(
5227 if (vaStatus != VA_STATUS_SUCCESS) {
5231 obj_surface->locked_image_id = tmpImage.image_id;
5233 vaStatus = i965_MapBuffer(
5237 if (vaStatus != VA_STATUS_SUCCESS) {
5241 *fourcc = tmpImage.format.fourcc;
5242 *luma_offset = tmpImage.offsets[0];
5243 *luma_stride = tmpImage.pitches[0];
5244 *chroma_u_offset = tmpImage.offsets[1];
5245 *chroma_u_stride = tmpImage.pitches[1];
5246 *chroma_v_offset = tmpImage.offsets[2];
5247 *chroma_v_stride = tmpImage.pitches[2];
5248 *buffer_name = tmpImage.buf;
5251 if (vaStatus != VA_STATUS_SUCCESS) {
5260 VADriverContextP ctx, /* in */
5261 VASurfaceID surface /* in */
5264 VAStatus vaStatus = VA_STATUS_SUCCESS;
5265 struct i965_driver_data *i965 = i965_driver_data(ctx);
5266 struct object_image *locked_img = NULL;
5267 struct object_surface *obj_surface = NULL;
5269 obj_surface = SURFACE(surface);
5271 if (obj_surface == NULL) {
5272 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5275 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5276 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5280 locked_img = IMAGE(obj_surface->locked_image_id);
5281 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5282 // Work image was deallocated before i965_UnlockSurface()
5283 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5287 vaStatus = i965_UnmapBuffer(
5289 locked_img->image.buf);
5290 if (vaStatus != VA_STATUS_SUCCESS) {
5294 vaStatus = i965_DestroyImage(
5296 locked_img->image.image_id);
5297 if (vaStatus != VA_STATUS_SUCCESS) {
5301 locked_img->image.image_id = VA_INVALID_ID;
5304 obj_surface->locked_image_id = VA_INVALID_ID;
5310 i965_GetSurfaceAttributes(
5311 VADriverContextP ctx,
5313 VASurfaceAttrib *attrib_list,
5314 unsigned int num_attribs
5317 VAStatus vaStatus = VA_STATUS_SUCCESS;
5318 struct i965_driver_data *i965 = i965_driver_data(ctx);
5319 struct object_config *obj_config;
5322 if (config == VA_INVALID_ID)
5323 return VA_STATUS_ERROR_INVALID_CONFIG;
5325 obj_config = CONFIG(config);
5327 if (obj_config == NULL)
5328 return VA_STATUS_ERROR_INVALID_CONFIG;
5330 if (attrib_list == NULL || num_attribs == 0)
5331 return VA_STATUS_ERROR_INVALID_PARAMETER;
5333 for (i = 0; i < num_attribs; i++) {
5334 switch (attrib_list[i].type) {
5335 case VASurfaceAttribPixelFormat:
5336 attrib_list[i].value.type = VAGenericValueTypeInteger;
5337 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5339 if (attrib_list[i].value.value.i == 0) {
5340 if (IS_G4X(i965->intel.device_info)) {
5341 if (obj_config->profile == VAProfileMPEG2Simple ||
5342 obj_config->profile == VAProfileMPEG2Main) {
5343 attrib_list[i].value.value.i = VA_FOURCC_I420;
5346 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5348 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5349 if (obj_config->profile == VAProfileMPEG2Simple ||
5350 obj_config->profile == VAProfileMPEG2Main) {
5351 attrib_list[i].value.value.i = VA_FOURCC_I420;
5352 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5353 obj_config->profile == VAProfileH264Main ||
5354 obj_config->profile == VAProfileH264High) {
5355 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5356 } else if (obj_config->profile == VAProfileNone) {
5357 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5360 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5362 } else if (IS_GEN6(i965->intel.device_info)) {
5363 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5364 } else if (IS_GEN7(i965->intel.device_info) ||
5365 IS_GEN8(i965->intel.device_info) ||
5366 IS_GEN9(i965->intel.device_info)) {
5367 if (obj_config->profile == VAProfileJPEGBaseline)
5368 attrib_list[i].value.value.i = 0; /* internal format */
5370 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5373 if (IS_G4X(i965->intel.device_info)) {
5374 if (obj_config->profile == VAProfileMPEG2Simple ||
5375 obj_config->profile == VAProfileMPEG2Main) {
5376 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5377 attrib_list[i].value.value.i = 0;
5378 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5382 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5384 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5385 if (obj_config->profile == VAProfileMPEG2Simple ||
5386 obj_config->profile == VAProfileMPEG2Main) {
5387 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5388 attrib_list[i].value.value.i = 0;
5389 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5391 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5392 obj_config->profile == VAProfileH264Main ||
5393 obj_config->profile == VAProfileH264High) {
5394 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5395 attrib_list[i].value.value.i = 0;
5396 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5398 } else if (obj_config->profile == VAProfileNone) {
5399 switch (attrib_list[i].value.value.i) {
5400 case VA_FOURCC_NV12:
5401 case VA_FOURCC_I420:
5402 case VA_FOURCC_YV12:
5403 case VA_FOURCC_YUY2:
5404 case VA_FOURCC_BGRA:
5405 case VA_FOURCC_BGRX:
5406 case VA_FOURCC_RGBX:
5407 case VA_FOURCC_RGBA:
5410 attrib_list[i].value.value.i = 0;
5411 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5416 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5418 } else if (IS_GEN6(i965->intel.device_info)) {
5419 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5420 obj_config->entrypoint == VAEntrypointVideoProc) {
5421 switch (attrib_list[i].value.value.i) {
5422 case VA_FOURCC_NV12:
5423 case VA_FOURCC_I420:
5424 case VA_FOURCC_YV12:
5425 case VA_FOURCC_YUY2:
5426 case VA_FOURCC_BGRA:
5427 case VA_FOURCC_BGRX:
5428 case VA_FOURCC_RGBX:
5429 case VA_FOURCC_RGBA:
5432 attrib_list[i].value.value.i = 0;
5433 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5437 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5438 attrib_list[i].value.value.i = 0;
5439 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5442 } else if (IS_GEN7(i965->intel.device_info) ||
5443 IS_GEN8(i965->intel.device_info) ||
5444 IS_GEN9(i965->intel.device_info)) {
5445 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5446 obj_config->entrypoint == VAEntrypointVideoProc ||
5447 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5448 switch (attrib_list[i].value.value.i) {
5449 case VA_FOURCC_NV12:
5450 case VA_FOURCC_I420:
5451 case VA_FOURCC_YV12:
5454 attrib_list[i].value.value.i = 0;
5455 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5459 if (obj_config->profile == VAProfileJPEGBaseline) {
5460 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5461 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5463 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5464 attrib_list[i].value.value.i = 0;
5465 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5473 case VASurfaceAttribMinWidth:
5474 /* FIXME: add support for it later */
5475 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5477 case VASurfaceAttribMaxWidth:
5478 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5480 case VASurfaceAttribMinHeight:
5481 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5483 case VASurfaceAttribMaxHeight:
5484 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5487 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5496 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5498 VASurfaceAttrib *attrib_list,
5499 unsigned int *num_attribs)
5501 VAStatus vaStatus = VA_STATUS_SUCCESS;
5502 struct i965_driver_data *i965 = i965_driver_data(ctx);
5503 struct object_config *obj_config;
5505 VASurfaceAttrib *attribs = NULL;
5509 if (config == VA_INVALID_ID)
5510 return VA_STATUS_ERROR_INVALID_CONFIG;
5512 obj_config = CONFIG(config);
5514 if (obj_config == NULL)
5515 return VA_STATUS_ERROR_INVALID_CONFIG;
5517 if (!attrib_list && !num_attribs)
5518 return VA_STATUS_ERROR_INVALID_PARAMETER;
5520 if (attrib_list == NULL) {
5521 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5522 return VA_STATUS_SUCCESS;
5525 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
5527 if (attribs == NULL)
5528 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5530 if (IS_G4X(i965->intel.device_info)) {
5531 if (obj_config->profile == VAProfileMPEG2Simple ||
5532 obj_config->profile == VAProfileMPEG2Main) {
5533 attribs[i].type = VASurfaceAttribPixelFormat;
5534 attribs[i].value.type = VAGenericValueTypeInteger;
5535 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5536 attribs[i].value.value.i = VA_FOURCC_I420;
5539 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5540 switch (obj_config->profile) {
5541 case VAProfileMPEG2Simple:
5542 case VAProfileMPEG2Main:
5543 attribs[i].type = VASurfaceAttribPixelFormat;
5544 attribs[i].value.type = VAGenericValueTypeInteger;
5545 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5546 attribs[i].value.value.i = VA_FOURCC_I420;
5551 case VAProfileH264ConstrainedBaseline:
5552 case VAProfileH264Main:
5553 case VAProfileH264High:
5554 attribs[i].type = VASurfaceAttribPixelFormat;
5555 attribs[i].value.type = VAGenericValueTypeInteger;
5556 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5557 attribs[i].value.value.i = VA_FOURCC_NV12;
5561 attribs[i].type = VASurfaceAttribPixelFormat;
5562 attribs[i].value.type = VAGenericValueTypeInteger;
5563 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5564 attribs[i].value.value.i = VA_FOURCC_NV12;
5567 attribs[i].type = VASurfaceAttribPixelFormat;
5568 attribs[i].value.type = VAGenericValueTypeInteger;
5569 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5570 attribs[i].value.value.i = VA_FOURCC_I420;
5578 } else if (IS_GEN6(i965->intel.device_info)) {
5579 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5580 attribs[i].type = VASurfaceAttribPixelFormat;
5581 attribs[i].value.type = VAGenericValueTypeInteger;
5582 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5583 attribs[i].value.value.i = VA_FOURCC_NV12;
5585 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5586 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5587 attribs[i].type = VASurfaceAttribPixelFormat;
5588 attribs[i].value.type = VAGenericValueTypeInteger;
5589 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5590 attribs[i].value.value.i = VA_FOURCC_NV12;
5593 attribs[i].type = VASurfaceAttribPixelFormat;
5594 attribs[i].value.type = VAGenericValueTypeInteger;
5595 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5596 attribs[i].value.value.i = VA_FOURCC_I420;
5599 attribs[i].type = VASurfaceAttribPixelFormat;
5600 attribs[i].value.type = VAGenericValueTypeInteger;
5601 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5602 attribs[i].value.value.i = VA_FOURCC_YV12;
5605 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5606 attribs[i].type = VASurfaceAttribPixelFormat;
5607 attribs[i].value.type = VAGenericValueTypeInteger;
5608 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5609 attribs[i].value.value.i = VA_FOURCC_YUY2;
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_RGBA;
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_RGBX;
5625 } else if (IS_GEN7(i965->intel.device_info)) {
5626 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5627 if (obj_config->profile == VAProfileJPEGBaseline) {
5628 attribs[i].type = VASurfaceAttribPixelFormat;
5629 attribs[i].value.type = VAGenericValueTypeInteger;
5630 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5631 attribs[i].value.value.i = VA_FOURCC_IMC3;
5634 attribs[i].type = VASurfaceAttribPixelFormat;
5635 attribs[i].value.type = VAGenericValueTypeInteger;
5636 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5637 attribs[i].value.value.i = VA_FOURCC_IMC1;
5640 attribs[i].type = VASurfaceAttribPixelFormat;
5641 attribs[i].value.type = VAGenericValueTypeInteger;
5642 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5643 attribs[i].value.value.i = VA_FOURCC_Y800;
5646 attribs[i].type = VASurfaceAttribPixelFormat;
5647 attribs[i].value.type = VAGenericValueTypeInteger;
5648 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5649 attribs[i].value.value.i = VA_FOURCC_411P;
5652 attribs[i].type = VASurfaceAttribPixelFormat;
5653 attribs[i].value.type = VAGenericValueTypeInteger;
5654 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5655 attribs[i].value.value.i = VA_FOURCC_422H;
5658 attribs[i].type = VASurfaceAttribPixelFormat;
5659 attribs[i].value.type = VAGenericValueTypeInteger;
5660 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5661 attribs[i].value.value.i = VA_FOURCC_422V;
5664 attribs[i].type = VASurfaceAttribPixelFormat;
5665 attribs[i].value.type = VAGenericValueTypeInteger;
5666 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5667 attribs[i].value.value.i = VA_FOURCC_444P;
5669 } else if (obj_config->profile == VAProfileHEVCMain10) {
5670 attribs[i].type = VASurfaceAttribPixelFormat;
5671 attribs[i].value.type = VAGenericValueTypeInteger;
5672 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5673 attribs[i].value.value.i = VA_FOURCC_P010;
5676 attribs[i].type = VASurfaceAttribPixelFormat;
5677 attribs[i].value.type = VAGenericValueTypeInteger;
5678 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5679 attribs[i].value.value.i = VA_FOURCC_NV12;
5682 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5683 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5684 attribs[i].type = VASurfaceAttribPixelFormat;
5685 attribs[i].value.type = VAGenericValueTypeInteger;
5686 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5687 attribs[i].value.value.i = VA_FOURCC_NV12;
5690 attribs[i].type = VASurfaceAttribPixelFormat;
5691 attribs[i].value.type = VAGenericValueTypeInteger;
5692 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5693 attribs[i].value.value.i = VA_FOURCC_I420;
5696 attribs[i].type = VASurfaceAttribPixelFormat;
5697 attribs[i].value.type = VAGenericValueTypeInteger;
5698 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5699 attribs[i].value.value.i = VA_FOURCC_YV12;
5702 attribs[i].type = VASurfaceAttribPixelFormat;
5703 attribs[i].value.type = VAGenericValueTypeInteger;
5704 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5705 attribs[i].value.value.i = VA_FOURCC_IMC3;
5708 if (obj_config->entrypoint == VAEntrypointVideoProc) {
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_YUY2;
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_RGBA;
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_RGBX;
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_BGRA;
5733 attribs[i].type = VASurfaceAttribPixelFormat;
5734 attribs[i].value.type = VAGenericValueTypeInteger;
5735 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5736 attribs[i].value.value.i = VA_FOURCC_BGRX;
5739 attribs[i].type = VASurfaceAttribPixelFormat;
5740 attribs[i].value.type = VAGenericValueTypeInteger;
5741 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5742 attribs[i].value.value.i = VA_FOURCC_YV16;
5746 } else if (IS_GEN8(i965->intel.device_info) ||
5747 IS_GEN9(i965->intel.device_info)) {
5748 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5749 if (obj_config->profile == VAProfileJPEGBaseline) {
5750 attribs[i].type = VASurfaceAttribPixelFormat;
5751 attribs[i].value.type = VAGenericValueTypeInteger;
5752 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5753 attribs[i].value.value.i = VA_FOURCC_IMC3;
5756 attribs[i].type = VASurfaceAttribPixelFormat;
5757 attribs[i].value.type = VAGenericValueTypeInteger;
5758 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5759 attribs[i].value.value.i = VA_FOURCC_IMC1;
5762 attribs[i].type = VASurfaceAttribPixelFormat;
5763 attribs[i].value.type = VAGenericValueTypeInteger;
5764 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5765 attribs[i].value.value.i = VA_FOURCC_Y800;
5768 attribs[i].type = VASurfaceAttribPixelFormat;
5769 attribs[i].value.type = VAGenericValueTypeInteger;
5770 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5771 attribs[i].value.value.i = VA_FOURCC_411P;
5774 attribs[i].type = VASurfaceAttribPixelFormat;
5775 attribs[i].value.type = VAGenericValueTypeInteger;
5776 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5777 attribs[i].value.value.i = VA_FOURCC_422H;
5780 attribs[i].type = VASurfaceAttribPixelFormat;
5781 attribs[i].value.type = VAGenericValueTypeInteger;
5782 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5783 attribs[i].value.value.i = VA_FOURCC_422V;
5786 attribs[i].type = VASurfaceAttribPixelFormat;
5787 attribs[i].value.type = VAGenericValueTypeInteger;
5788 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5789 attribs[i].value.value.i = VA_FOURCC_444P;
5792 attribs[i].type = VASurfaceAttribPixelFormat;
5793 attribs[i].value.type = VAGenericValueTypeInteger;
5794 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5795 attribs[i].value.value.i = VA_FOURCC_NV12;
5798 if ((obj_config->profile == VAProfileHEVCMain10) ||
5799 (obj_config->profile == VAProfileVP9Profile2)) {
5800 attribs[i].type = VASurfaceAttribPixelFormat;
5801 attribs[i].value.type = VAGenericValueTypeInteger;
5802 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5803 attribs[i].value.value.i = VA_FOURCC_P010;
5807 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5808 obj_config->entrypoint == VAEntrypointVideoProc ||
5809 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5811 if (obj_config->profile == VAProfileHEVCMain10) {
5812 attribs[i].type = VASurfaceAttribPixelFormat;
5813 attribs[i].value.type = VAGenericValueTypeInteger;
5814 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5815 attribs[i].value.value.i = VA_FOURCC_P010;
5818 attribs[i].type = VASurfaceAttribPixelFormat;
5819 attribs[i].value.type = VAGenericValueTypeInteger;
5820 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5821 attribs[i].value.value.i = VA_FOURCC_NV12;
5824 attribs[i].type = VASurfaceAttribPixelFormat;
5825 attribs[i].value.type = VAGenericValueTypeInteger;
5826 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5827 attribs[i].value.value.i = VA_FOURCC_I420;
5830 attribs[i].type = VASurfaceAttribPixelFormat;
5831 attribs[i].value.type = VAGenericValueTypeInteger;
5832 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5833 attribs[i].value.value.i = VA_FOURCC_YV12;
5836 attribs[i].type = VASurfaceAttribPixelFormat;
5837 attribs[i].value.type = VAGenericValueTypeInteger;
5838 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5839 attribs[i].value.value.i = VA_FOURCC_IMC3;
5843 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5844 attribs[i].type = VASurfaceAttribPixelFormat;
5845 attribs[i].value.type = VAGenericValueTypeInteger;
5846 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5847 attribs[i].value.value.i = VA_FOURCC_YUY2;
5850 attribs[i].type = VASurfaceAttribPixelFormat;
5851 attribs[i].value.type = VAGenericValueTypeInteger;
5852 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5853 attribs[i].value.value.i = VA_FOURCC_RGBA;
5856 attribs[i].type = VASurfaceAttribPixelFormat;
5857 attribs[i].value.type = VAGenericValueTypeInteger;
5858 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5859 attribs[i].value.value.i = VA_FOURCC_RGBX;
5862 attribs[i].type = VASurfaceAttribPixelFormat;
5863 attribs[i].value.type = VAGenericValueTypeInteger;
5864 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5865 attribs[i].value.value.i = VA_FOURCC_BGRA;
5868 attribs[i].type = VASurfaceAttribPixelFormat;
5869 attribs[i].value.type = VAGenericValueTypeInteger;
5870 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5871 attribs[i].value.value.i = VA_FOURCC_BGRX;
5874 attribs[i].type = VASurfaceAttribPixelFormat;
5875 attribs[i].value.type = VAGenericValueTypeInteger;
5876 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5877 attribs[i].value.value.i = VA_FOURCC_YV16;
5880 if(HAS_VPP_P010(i965)) {
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_P010;
5891 attribs[i].type = VASurfaceAttribMemoryType;
5892 attribs[i].value.type = VAGenericValueTypeInteger;
5893 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5894 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
5895 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
5896 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
5899 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
5900 attribs[i].value.type = VAGenericValueTypePointer;
5901 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
5902 attribs[i].value.value.p = NULL; /* ignore */
5905 max_resolution(i965, obj_config, &max_width, &max_height);
5907 attribs[i].type = VASurfaceAttribMaxWidth;
5908 attribs[i].value.type = VAGenericValueTypeInteger;
5909 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5910 attribs[i].value.value.i = max_width;
5913 attribs[i].type = VASurfaceAttribMaxHeight;
5914 attribs[i].value.type = VAGenericValueTypeInteger;
5915 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5916 attribs[i].value.value.i = max_height;
5919 if (i > *num_attribs) {
5922 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5926 memcpy(attrib_list, attribs, i * sizeof(*attribs));
5932 /* Acquires buffer handle for external API usage (internal implementation) */
5934 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
5935 uint32_t mem_type, VABufferInfo *out_buf_info)
5937 struct buffer_store *buffer_store;
5939 buffer_store = obj_buffer->buffer_store;
5940 if (!buffer_store || !buffer_store->bo)
5941 return VA_STATUS_ERROR_INVALID_BUFFER;
5943 /* Synchronization point */
5944 drm_intel_bo_wait_rendering(buffer_store->bo);
5946 if (obj_buffer->export_refcount > 0) {
5947 if (obj_buffer->export_state.mem_type != mem_type)
5948 return VA_STATUS_ERROR_INVALID_PARAMETER;
5951 VABufferInfo * const buf_info = &obj_buffer->export_state;
5954 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
5956 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
5957 return VA_STATUS_ERROR_INVALID_BUFFER;
5958 buf_info->handle = name;
5961 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5963 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
5964 return VA_STATUS_ERROR_INVALID_BUFFER;
5965 buf_info->handle = (intptr_t)fd;
5970 buf_info->type = obj_buffer->type;
5971 buf_info->mem_type = mem_type;
5972 buf_info->mem_size =
5973 obj_buffer->num_elements * obj_buffer->size_element;
5976 obj_buffer->export_refcount++;
5977 *out_buf_info = obj_buffer->export_state;
5978 return VA_STATUS_SUCCESS;
5981 /* Releases buffer handle after usage (internal implementation) */
5983 i965_release_buffer_handle(struct object_buffer *obj_buffer)
5985 if (obj_buffer->export_refcount == 0)
5986 return VA_STATUS_ERROR_INVALID_BUFFER;
5988 if (--obj_buffer->export_refcount == 0) {
5989 VABufferInfo * const buf_info = &obj_buffer->export_state;
5991 switch (buf_info->mem_type) {
5992 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5993 close((intptr_t)buf_info->handle);
5997 buf_info->mem_type = 0;
5999 return VA_STATUS_SUCCESS;
6002 /** Acquires buffer handle for external API usage */
6004 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
6005 VABufferInfo *buf_info)
6007 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6008 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6009 uint32_t i, mem_type;
6011 /* List of supported memory types, in preferred order */
6012 static const uint32_t mem_types[] = {
6013 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
6014 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
6019 return VA_STATUS_ERROR_INVALID_BUFFER;
6020 /* XXX: only VA surface|image like buffers are supported for now */
6021 if (obj_buffer->type != VAImageBufferType)
6022 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6025 * As the allocated buffer by calling vaCreateBuffer is related with
6026 * the specific context, it is unnecessary to export it.
6027 * So it is not supported when the buffer is allocated from wrapped
6030 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6031 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
6035 return VA_STATUS_ERROR_INVALID_PARAMETER;
6037 if (!buf_info->mem_type)
6038 mem_type = mem_types[0];
6041 for (i = 0; mem_types[i] != 0; i++) {
6042 if (buf_info->mem_type & mem_types[i]) {
6043 mem_type = buf_info->mem_type;
6048 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
6050 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
6053 /** Releases buffer handle after usage from external API */
6055 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
6057 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6058 struct object_buffer * const obj_buffer = BUFFER(buf_id);
6061 return VA_STATUS_ERROR_INVALID_BUFFER;
6063 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
6064 return VA_STATUS_ERROR_INVALID_BUFFER;
6067 return i965_release_buffer_handle(obj_buffer);
6071 i965_os_has_ring_support(VADriverContextP ctx,
6074 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6078 return i965->intel.has_bsd;
6081 return i965->intel.has_blt;
6083 case I965_RING_VEBOX:
6084 return i965->intel.has_vebox;
6086 case I965_RING_NULL:
6087 return 1; /* Always support */
6090 /* should never get here */
6099 * Query video processing pipeline
6101 VAStatus i965_QueryVideoProcFilters(
6102 VADriverContextP ctx,
6103 VAContextID context,
6104 VAProcFilterType *filters,
6105 unsigned int *num_filters
6108 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6109 unsigned int i = 0, num = 0;
6111 if (!num_filters || !filters)
6112 return VA_STATUS_ERROR_INVALID_PARAMETER;
6114 for (i = 0; i < i965->codec_info->num_filters; i++) {
6115 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6116 if (num == *num_filters) {
6117 *num_filters = i965->codec_info->num_filters;
6119 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6122 filters[num++] = i965->codec_info->filters[i].type;
6128 return VA_STATUS_SUCCESS;
6131 VAStatus i965_QueryVideoProcFilterCaps(
6132 VADriverContextP ctx,
6133 VAContextID context,
6134 VAProcFilterType type,
6136 unsigned int *num_filter_caps
6140 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6142 if (!filter_caps || !num_filter_caps)
6143 return VA_STATUS_ERROR_INVALID_PARAMETER;
6145 for (i = 0; i < i965->codec_info->num_filters; i++) {
6146 if (type == i965->codec_info->filters[i].type &&
6147 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6151 if (i == i965->codec_info->num_filters)
6152 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6157 case VAProcFilterNoiseReduction:
6158 case VAProcFilterSharpening:
6160 VAProcFilterCap *cap = filter_caps;
6162 if (*num_filter_caps < 1) {
6163 *num_filter_caps = 1;
6164 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6167 cap->range.min_value = 0.0;
6168 cap->range.max_value = 1.0;
6169 cap->range.default_value = 0.5;
6170 cap->range.step = 0.03125; /* 1.0 / 32 */
6176 case VAProcFilterDeinterlacing:
6178 VAProcFilterCapDeinterlacing *cap = filter_caps;
6180 if (*num_filter_caps < VAProcDeinterlacingCount) {
6181 *num_filter_caps = VAProcDeinterlacingCount;
6182 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6185 cap->type = VAProcDeinterlacingBob;
6190 if (i965->codec_info->has_di_motion_adptive) {
6191 cap->type = VAProcDeinterlacingMotionAdaptive;
6196 if (i965->codec_info->has_di_motion_compensated) {
6197 cap->type = VAProcDeinterlacingMotionCompensated;
6205 case VAProcFilterColorBalance:
6207 VAProcFilterCapColorBalance *cap = filter_caps;
6209 if (*num_filter_caps < VAProcColorBalanceCount) {
6210 *num_filter_caps = VAProcColorBalanceCount;
6211 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6214 cap->type = VAProcColorBalanceHue;
6215 cap->range.min_value = -180.0;
6216 cap->range.max_value = 180.0;
6217 cap->range.default_value = 0.0;
6218 cap->range.step = 1.0;
6222 cap->type = VAProcColorBalanceSaturation;
6223 cap->range.min_value = 0.0;
6224 cap->range.max_value = 10.0;
6225 cap->range.default_value = 1.0;
6226 cap->range.step = 0.1;
6230 cap->type = VAProcColorBalanceBrightness;
6231 cap->range.min_value = -100.0;
6232 cap->range.max_value = 100.0;
6233 cap->range.default_value = 0.0;
6234 cap->range.step = 1.0;
6238 cap->type = VAProcColorBalanceContrast;
6239 cap->range.min_value = 0.0;
6240 cap->range.max_value = 10.0;
6241 cap->range.default_value = 1.0;
6242 cap->range.step = 0.1;
6254 *num_filter_caps = i;
6256 return VA_STATUS_SUCCESS;
6259 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6260 VAProcColorStandardBT601,
6263 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6264 VAProcColorStandardBT601,
6267 VAStatus i965_QueryVideoProcPipelineCaps(
6268 VADriverContextP ctx,
6269 VAContextID context,
6270 VABufferID *filters,
6271 unsigned int num_filters,
6272 VAProcPipelineCaps *pipeline_cap /* out */
6275 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6278 pipeline_cap->pipeline_flags = 0;
6279 pipeline_cap->filter_flags = 0;
6280 pipeline_cap->num_forward_references = 0;
6281 pipeline_cap->num_backward_references = 0;
6282 pipeline_cap->num_input_color_standards = 1;
6283 pipeline_cap->input_color_standards = vpp_input_color_standards;
6284 pipeline_cap->num_output_color_standards = 1;
6285 pipeline_cap->output_color_standards = vpp_output_color_standards;
6287 for (i = 0; i < num_filters; i++) {
6288 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6291 !obj_buffer->buffer_store ||
6292 !obj_buffer->buffer_store->buffer)
6293 return VA_STATUS_ERROR_INVALID_BUFFER;
6295 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6297 if (base->type == VAProcFilterNoiseReduction) {
6298 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6300 } else if (base->type == VAProcFilterDeinterlacing) {
6301 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6303 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6304 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6305 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6306 VA_STATUS_ERROR_INVALID_PARAMETER);
6308 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6309 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6310 pipeline_cap->num_forward_references++;
6311 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6312 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6317 return VA_STATUS_SUCCESS;
6320 extern struct hw_codec_info *i965_get_codec_info(int devid);
6323 i965_driver_data_init(VADriverContextP ctx)
6325 struct i965_driver_data *i965 = i965_driver_data(ctx);
6327 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6329 if (!i965->codec_info)
6332 if (object_heap_init(&i965->config_heap,
6333 sizeof(struct object_config),
6335 goto err_config_heap;
6336 if (object_heap_init(&i965->context_heap,
6337 sizeof(struct object_context),
6339 goto err_context_heap;
6341 if (object_heap_init(&i965->surface_heap,
6342 sizeof(struct object_surface),
6344 goto err_surface_heap;
6345 if (object_heap_init(&i965->buffer_heap,
6346 sizeof(struct object_buffer),
6348 goto err_buffer_heap;
6349 if (object_heap_init(&i965->image_heap,
6350 sizeof(struct object_image),
6352 goto err_image_heap;
6353 if (object_heap_init(&i965->subpic_heap,
6354 sizeof(struct object_subpic),
6356 goto err_subpic_heap;
6358 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6359 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6360 _i965InitMutex(&i965->render_mutex);
6361 _i965InitMutex(&i965->pp_mutex);
6366 object_heap_destroy(&i965->image_heap);
6368 object_heap_destroy(&i965->buffer_heap);
6370 object_heap_destroy(&i965->surface_heap);
6372 object_heap_destroy(&i965->context_heap);
6374 object_heap_destroy(&i965->config_heap);
6381 i965_driver_data_terminate(VADriverContextP ctx)
6383 struct i965_driver_data *i965 = i965_driver_data(ctx);
6385 _i965DestroyMutex(&i965->pp_mutex);
6386 _i965DestroyMutex(&i965->render_mutex);
6389 intel_batchbuffer_free(i965->batch);
6392 intel_batchbuffer_free(i965->pp_batch);
6394 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6395 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6396 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6397 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6398 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6399 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6403 bool (*init)(VADriverContextP ctx);
6404 void (*terminate)(VADriverContextP ctx);
6406 } i965_sub_ops[] = {
6409 intel_driver_terminate,
6414 i965_driver_data_init,
6415 i965_driver_data_terminate,
6420 i965_display_attributes_init,
6421 i965_display_attributes_terminate,
6426 i965_post_processing_init,
6427 i965_post_processing_terminate,
6433 i965_render_terminate,
6437 #ifdef HAVE_VA_WAYLAND
6439 i965_output_wayland_init,
6440 i965_output_wayland_terminate,
6447 i965_output_dri_init,
6448 i965_output_dri_terminate,
6455 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6459 if (i965->va_vendor[0] != '\0')
6463 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6464 "%s %s driver for %s - %d.%d.%d",
6465 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6466 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6467 INTEL_DRIVER_MICRO_VERSION);
6468 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6472 if (INTEL_DRIVER_PRE_VERSION > 0) {
6473 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6474 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6475 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6479 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6480 " (%s)", INTEL_DRIVER_GIT_VERSION);
6481 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6488 i965->va_vendor[0] = '\0';
6489 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6493 /* Only when the option of "enable-wrapper" is passed, it is possible
6494 * to initialize/load the wrapper context of backend driver.
6495 * Otherwise it is not loaded.
6497 #if HAVE_HYBRID_CODEC
6500 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6502 #define DRIVER_EXTENSION "_drv_video.so"
6504 struct i965_driver_data *i965 = i965_driver_data(ctx);
6506 VADriverContextP wrapper_pdrvctx;
6507 struct VADriverVTable *vtable;
6508 char *search_path, *driver_dir;
6510 char driver_path[256];
6511 void *handle = NULL;
6512 VAStatus va_status = VA_STATUS_SUCCESS;
6513 bool driver_loaded = false;
6515 if (HAS_VP9_DECODING(i965)) {
6516 i965->wrapper_pdrvctx = NULL;
6520 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6521 vtable = calloc(1, sizeof(*vtable));
6523 if (!wrapper_pdrvctx || !vtable) {
6524 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6525 free(wrapper_pdrvctx);
6527 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6530 /* use the same drm_state with CTX */
6531 wrapper_pdrvctx->drm_state = ctx->drm_state;
6532 wrapper_pdrvctx->display_type = ctx->display_type;
6533 wrapper_pdrvctx->vtable = vtable;
6535 search_path = VA_DRIVERS_PATH;
6536 search_path = strdup((const char *)search_path);
6538 driver_dir = strtok_r(search_path, ":", &saveptr);
6539 while (driver_dir && !driver_loaded) {
6540 memset(driver_path, 0, sizeof(driver_path));
6541 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6543 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6545 fprintf(stderr, "failed to open %s\n", driver_path);
6546 driver_dir = strtok_r(NULL, ":", &saveptr);
6550 VADriverInit init_func = NULL;
6551 char init_func_s[256];
6554 static const struct {
6557 } compatible_versions[] = {
6558 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6567 for (i = 0; compatible_versions[i].major >= 0; i++) {
6568 snprintf(init_func_s, sizeof(init_func_s),
6569 "__vaDriverInit_%d_%d",
6570 compatible_versions[i].major,
6571 compatible_versions[i].minor);
6572 init_func = (VADriverInit)dlsym(handle, init_func_s);
6577 if (compatible_versions[i].major < 0) {
6579 fprintf(stderr, "%s has no function %s\n",
6580 driver_path, init_func_s);
6581 driver_dir = strtok_r(NULL, ":", &saveptr);
6586 va_status = (*init_func)(wrapper_pdrvctx);
6588 if (va_status != VA_STATUS_SUCCESS) {
6590 fprintf(stderr, "%s init failed\n", driver_path);
6591 driver_dir = strtok_r(NULL, ":", &saveptr);
6595 wrapper_pdrvctx->handle = handle;
6596 driver_loaded = true;
6602 if (driver_loaded) {
6603 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6604 return VA_STATUS_SUCCESS;
6606 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6608 free(wrapper_pdrvctx);
6609 return VA_STATUS_ERROR_OPERATION_FAILED;
6615 i965_Init(VADriverContextP ctx)
6617 struct i965_driver_data *i965 = i965_driver_data(ctx);
6619 const char *chipset;
6621 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6622 if ((i965_sub_ops[i].display_type == 0 ||
6623 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6624 !i965_sub_ops[i].init(ctx))
6628 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6629 switch (i965->intel.device_id) {
6631 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6632 #include "i965_pciids.h"
6634 chipset = "Unknown Intel Chipset";
6638 if (!ensure_vendor_string(i965, chipset))
6639 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6641 i965->current_context_id = VA_INVALID_ID;
6643 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6644 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6646 #if HAVE_HYBRID_CODEC
6647 i965_initialize_wrapper(ctx, "hybrid");
6650 return VA_STATUS_SUCCESS;
6654 for (; i >= 0; i--) {
6655 if (i965_sub_ops[i].display_type == 0 ||
6656 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6657 i965_sub_ops[i].terminate(ctx);
6661 return VA_STATUS_ERROR_UNKNOWN;
6666 i965_Terminate(VADriverContextP ctx)
6668 struct i965_driver_data *i965 = i965_driver_data(ctx);
6672 if (i965->wrapper_pdrvctx) {
6673 VADriverContextP pdrvctx;
6674 pdrvctx = i965->wrapper_pdrvctx;
6675 if (pdrvctx->handle) {
6676 pdrvctx->vtable->vaTerminate(pdrvctx);
6677 dlclose(pdrvctx->handle);
6678 pdrvctx->handle = NULL;
6680 free(pdrvctx->vtable);
6682 i965->wrapper_pdrvctx = NULL;
6685 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6686 if (i965_sub_ops[i - 1].display_type == 0 ||
6687 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6688 i965_sub_ops[i - 1].terminate(ctx);
6692 ctx->pDriverData = NULL;
6695 return VA_STATUS_SUCCESS;
6699 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6702 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
6704 struct VADriverVTable * const vtable = ctx->vtable;
6705 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6707 struct i965_driver_data *i965;
6708 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6710 ctx->version_major = VA_MAJOR_VERSION;
6711 ctx->version_minor = VA_MINOR_VERSION;
6712 ctx->max_profiles = I965_MAX_PROFILES;
6713 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6714 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6715 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6716 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6717 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6719 vtable->vaTerminate = i965_Terminate;
6720 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6721 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6722 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6723 vtable->vaCreateConfig = i965_CreateConfig;
6724 vtable->vaDestroyConfig = i965_DestroyConfig;
6725 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6726 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6727 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6728 vtable->vaCreateContext = i965_CreateContext;
6729 vtable->vaDestroyContext = i965_DestroyContext;
6730 vtable->vaCreateBuffer = i965_CreateBuffer;
6731 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
6732 vtable->vaMapBuffer = i965_MapBuffer;
6733 vtable->vaUnmapBuffer = i965_UnmapBuffer;
6734 vtable->vaDestroyBuffer = i965_DestroyBuffer;
6735 vtable->vaBeginPicture = i965_BeginPicture;
6736 vtable->vaRenderPicture = i965_RenderPicture;
6737 vtable->vaEndPicture = i965_EndPicture;
6738 vtable->vaSyncSurface = i965_SyncSurface;
6739 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
6740 vtable->vaPutSurface = i965_PutSurface;
6741 vtable->vaQueryImageFormats = i965_QueryImageFormats;
6742 vtable->vaCreateImage = i965_CreateImage;
6743 vtable->vaDeriveImage = i965_DeriveImage;
6744 vtable->vaDestroyImage = i965_DestroyImage;
6745 vtable->vaSetImagePalette = i965_SetImagePalette;
6746 vtable->vaGetImage = i965_GetImage;
6747 vtable->vaPutImage = i965_PutImage;
6748 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
6749 vtable->vaCreateSubpicture = i965_CreateSubpicture;
6750 vtable->vaDestroySubpicture = i965_DestroySubpicture;
6751 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
6752 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
6753 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
6754 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
6755 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
6756 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
6757 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
6758 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
6759 vtable->vaBufferInfo = i965_BufferInfo;
6760 vtable->vaLockSurface = i965_LockSurface;
6761 vtable->vaUnlockSurface = i965_UnlockSurface;
6762 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
6763 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
6764 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
6767 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
6768 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
6770 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
6771 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
6772 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
6774 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
6777 ctx->pDriverData = NULL;
6779 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6782 i965->wrapper_pdrvctx = NULL;
6783 ctx->pDriverData = (void *)i965;
6784 ret = i965_Init(ctx);
6786 if (ret == VA_STATUS_SUCCESS) {
6787 ctx->str_vendor = i965->va_vendor;
6790 ctx->pDriverData = NULL;