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 static int get_sampling_from_fourcc(unsigned int fourcc);
62 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
63 #define IS_VA_X11(ctx) \
64 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
66 /* Check whether we are rendering to Wayland */
67 #define IS_VA_WAYLAND(ctx) \
68 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
71 #define I965_2BITS (I965_BIT << 1)
72 #define I965_4BITS (I965_BIT << 2)
73 #define I965_8BITS (I965_BIT << 3)
74 #define I965_16BITS (I965_BIT << 4)
75 #define I965_32BITS (I965_BIT << 5)
87 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
88 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
89 #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} }
92 #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} }
95 #define I_P010 2, 2, 2, {I965_16BITS, I965_8BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_16} }
97 #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} }
98 #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} }
99 #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} }
100 #define I_YUY2 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
101 #define I_UYVY 2, 1, 1, {I965_16BITS}, 3, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_16} }
103 #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} }
105 #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} }
107 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
109 #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} }
110 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
111 #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} }
112 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
114 #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} }
115 #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} }
117 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
118 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
120 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
121 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
126 #define I_SI (I_S | I_I)
128 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
129 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
130 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
131 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
133 static const i965_fourcc_info i965_fourcc_infos[] = {
134 DEF_YUV(NV12, YUV420, I_SI),
135 DEF_YUV(I420, YUV420, I_SI),
136 DEF_YUV(IYUV, YUV420, I_S),
137 DEF_YUV(IMC3, YUV420, I_S),
138 DEF_YUV(YV12, YUV420, I_SI),
139 DEF_YUV(IMC1, YUV420, I_S),
141 DEF_YUV(P010, YUV420, I_SI),
143 DEF_YUV(422H, YUV422H, I_SI),
144 DEF_YUV(422V, YUV422V, I_S),
145 DEF_YUV(YV16, YUV422H, I_S),
146 DEF_YUV(YUY2, YUV422H, I_SI),
147 DEF_YUV(UYVY, YUV422H, I_SI),
149 DEF_YUV(444P, YUV444, I_S),
151 DEF_YUV(411P, YUV411, I_S),
153 DEF_YUV(Y800, YUV400, I_S),
155 DEF_RGB(RGBA, RGBX, I_SI),
156 DEF_RGB(RGBX, RGBX, I_SI),
157 DEF_RGB(BGRA, RGBX, I_SI),
158 DEF_RGB(BGRX, RGBX, I_SI),
160 DEF_RGB(ARGB, RGBX, I_I),
161 DEF_RGB(ABGR, RGBX, I_I),
163 DEF_INDEX(IA88, RGBX, I_I),
164 DEF_INDEX(AI88, RGBX, I_I),
166 DEF_INDEX(IA44, RGBX, I_I),
167 DEF_INDEX(AI44, RGBX, I_I)
170 const i965_fourcc_info *
171 get_fourcc_info(unsigned int fourcc)
175 for (i = 0; i < ARRAY_ELEMS(i965_fourcc_infos); i++) {
176 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
178 if (info->fourcc == fourcc)
186 get_bpp_from_fourcc(unsigned int fourcc)
188 const i965_fourcc_info *info = get_fourcc_info(fourcc);
190 unsigned int bpp = 0;
195 for (i = 0; i < info->num_planes; i++)
202 I965_SURFACETYPE_RGBA = 1,
203 I965_SURFACETYPE_YUV,
204 I965_SURFACETYPE_INDEXED
207 /* List of supported display attributes */
208 static const VADisplayAttribute i965_display_attributes[] = {
210 VADisplayAttribBrightness,
211 -100, 100, DEFAULT_BRIGHTNESS,
212 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
216 VADisplayAttribContrast,
217 0, 100, DEFAULT_CONTRAST,
218 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
223 -180, 180, DEFAULT_HUE,
224 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
228 VADisplayAttribSaturation,
229 0, 100, DEFAULT_SATURATION,
230 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
234 VADisplayAttribRotation,
235 0, 3, VA_ROTATION_NONE,
236 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
240 /* List of supported image formats */
243 VAImageFormat va_format;
244 } i965_image_format_map_t;
246 static const i965_image_format_map_t
247 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
248 { I965_SURFACETYPE_YUV,
249 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
250 { I965_SURFACETYPE_YUV,
251 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
252 { I965_SURFACETYPE_YUV,
253 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
254 { I965_SURFACETYPE_YUV,
255 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
256 { I965_SURFACETYPE_YUV,
257 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
258 { I965_SURFACETYPE_YUV,
259 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
260 { I965_SURFACETYPE_RGBA,
261 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
262 { I965_SURFACETYPE_RGBA,
263 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
264 { I965_SURFACETYPE_YUV,
265 { VA_FOURCC_P010, VA_LSB_FIRST, 24, } },
268 /* List of supported subpicture formats */
272 VAImageFormat va_format;
273 unsigned int va_flags;
274 } i965_subpic_format_map_t;
276 #define COMMON_SUBPICTURE_FLAGS \
277 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
278 VA_SUBPICTURE_GLOBAL_ALPHA)
280 static const i965_subpic_format_map_t
281 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
282 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
283 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
284 COMMON_SUBPICTURE_FLAGS },
285 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
286 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
287 COMMON_SUBPICTURE_FLAGS },
288 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
289 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
290 COMMON_SUBPICTURE_FLAGS },
291 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
292 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
293 COMMON_SUBPICTURE_FLAGS },
294 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
295 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
296 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
297 COMMON_SUBPICTURE_FLAGS },
298 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
299 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
300 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
301 COMMON_SUBPICTURE_FLAGS },
304 static const i965_subpic_format_map_t *
305 get_subpic_format(const VAImageFormat *va_format)
308 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
309 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
310 if (m->va_format.fourcc == va_format->fourcc &&
311 (m->type == I965_SURFACETYPE_RGBA ?
312 (m->va_format.byte_order == va_format->byte_order &&
313 m->va_format.red_mask == va_format->red_mask &&
314 m->va_format.green_mask == va_format->green_mask &&
315 m->va_format.blue_mask == va_format->blue_mask &&
316 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
322 /* Checks whether the surface is in busy state */
324 is_surface_busy(struct i965_driver_data *i965,
325 struct object_surface *obj_surface)
327 assert(obj_surface != NULL);
329 if (obj_surface->locked_image_id != VA_INVALID_ID)
331 if (obj_surface->derived_image_id != VA_INVALID_ID)
336 /* Checks whether the image is in busy state */
338 is_image_busy(struct i965_driver_data *i965, struct object_image *obj_image, VASurfaceID surface)
340 struct object_buffer *obj_buffer;
342 assert(obj_image != NULL);
344 if (obj_image->derived_surface != VA_INVALID_ID &&
345 obj_image->derived_surface == surface)
348 obj_buffer = BUFFER(obj_image->image.buf);
349 if (obj_buffer && obj_buffer->export_refcount > 0)
354 #define I965_PACKED_HEADER_BASE 0
355 #define I965_SEQ_PACKED_HEADER_BASE 0
356 #define I965_SEQ_PACKED_HEADER_END 2
357 #define I965_PIC_PACKED_HEADER_BASE 2
358 #define I965_PACKED_MISC_HEADER_BASE 4
361 va_enc_packed_type_to_idx(int packed_type)
365 if (packed_type & VAEncPackedHeaderMiscMask) {
366 idx = I965_PACKED_MISC_HEADER_BASE;
367 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
368 ASSERT_RET(packed_type > 0, 0);
369 idx += (packed_type - 1);
371 idx = I965_PACKED_HEADER_BASE;
373 switch (packed_type) {
374 case VAEncPackedHeaderSequence:
375 idx = I965_SEQ_PACKED_HEADER_BASE + 0;
378 case VAEncPackedHeaderPicture:
379 idx = I965_PIC_PACKED_HEADER_BASE + 0;
382 case VAEncPackedHeaderSlice:
383 idx = I965_PIC_PACKED_HEADER_BASE + 1;
387 /* Should not get here */
393 ASSERT_RET(idx < 5, 0);
397 #define CALL_VTABLE(vawr, status, param) status = (vawr->vtable->param)
400 i965_surface_wrapper(VADriverContextP ctx, VASurfaceID surface)
402 struct i965_driver_data *i965 = i965_driver_data(ctx);
403 struct object_surface *obj_surface = SURFACE(surface);
404 VAStatus va_status = VA_STATUS_SUCCESS;
407 return VA_STATUS_ERROR_INVALID_SURFACE;
410 if (obj_surface->wrapper_surface != VA_INVALID_ID) {
411 /* the wrapped surface already exists. just return it */
415 if (obj_surface->fourcc == 0)
416 i965_check_alloc_surface_bo(ctx, obj_surface,
417 1, VA_FOURCC_NV12, SUBSAMPLE_YUV420);
420 * TBD: Support more surface formats.
421 * Currently only NV12 is support as NV12 is used by decoding.
423 if (obj_surface->fourcc != VA_FOURCC_NV12 )
424 return VA_STATUS_ERROR_INVALID_PARAMETER;
426 if ((i965->wrapper_pdrvctx == NULL) ||
427 (obj_surface->bo == NULL))
428 return VA_STATUS_ERROR_INVALID_PARAMETER;
432 VASurfaceAttrib attrib_list[2];
433 VASurfaceAttribExternalBuffers buffer_descriptor;
434 VAGenericID wrapper_surface;
436 if (drm_intel_bo_gem_export_to_prime(obj_surface->bo, &fd_handle) != 0)
437 return VA_STATUS_ERROR_OPERATION_FAILED;
439 obj_surface->exported_primefd = fd_handle;
441 memset(&attrib_list, 0, sizeof(attrib_list));
442 memset(&buffer_descriptor, 0, sizeof(buffer_descriptor));
444 attrib_list[0].type = VASurfaceAttribExternalBufferDescriptor;
445 attrib_list[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
446 attrib_list[0].value.value.p = &buffer_descriptor;
447 attrib_list[0].value.type = VAGenericValueTypePointer;
449 attrib_list[1].type = VASurfaceAttribMemoryType;
450 attrib_list[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
451 attrib_list[1].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
452 attrib_list[1].value.type = VAGenericValueTypeInteger;
454 buffer_descriptor.num_buffers = 1;
455 buffer_descriptor.num_planes = 2;
456 buffer_descriptor.width = obj_surface->orig_width;
457 buffer_descriptor.height = obj_surface->orig_height;
458 buffer_descriptor.pixel_format = obj_surface->fourcc;
459 buffer_descriptor.data_size = obj_surface->size;
460 buffer_descriptor.pitches[0] = obj_surface->width;
461 buffer_descriptor.pitches[1] = obj_surface->cb_cr_pitch;
462 buffer_descriptor.offsets[0] = 0;
463 buffer_descriptor.offsets[1] = obj_surface->width * obj_surface->height;
464 buffer_descriptor.buffers = (void *)&fd_handle;
466 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
467 vaCreateSurfaces2(i965->wrapper_pdrvctx,
469 obj_surface->orig_width,
470 obj_surface->orig_height,
474 if (va_status == VA_STATUS_SUCCESS) {
475 obj_surface->wrapper_surface = wrapper_surface;
477 /* This needs to be checked */
478 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
486 i965_QueryConfigProfiles(VADriverContextP ctx,
487 VAProfile *profile_list, /* out */
488 int *num_profiles) /* out */
490 struct i965_driver_data * const i965 = i965_driver_data(ctx);
493 if (HAS_MPEG2_DECODING(i965) ||
494 HAS_MPEG2_ENCODING(i965)) {
495 profile_list[i++] = VAProfileMPEG2Simple;
496 profile_list[i++] = VAProfileMPEG2Main;
499 if (HAS_H264_DECODING(i965) ||
500 HAS_H264_ENCODING(i965) ||
501 HAS_LP_H264_ENCODING(i965)) {
502 profile_list[i++] = VAProfileH264ConstrainedBaseline;
503 profile_list[i++] = VAProfileH264Main;
504 profile_list[i++] = VAProfileH264High;
506 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264MultiviewHigh) ||
507 HAS_H264_MVC_ENCODING(i965))
508 profile_list[i++] = VAProfileH264MultiviewHigh;
509 if (HAS_H264_MVC_DECODING_PROFILE(i965, VAProfileH264StereoHigh) ||
510 HAS_H264_MVC_ENCODING(i965))
511 profile_list[i++] = VAProfileH264StereoHigh;
513 if (HAS_VC1_DECODING(i965)) {
514 profile_list[i++] = VAProfileVC1Simple;
515 profile_list[i++] = VAProfileVC1Main;
516 profile_list[i++] = VAProfileVC1Advanced;
520 profile_list[i++] = VAProfileNone;
523 if (HAS_JPEG_DECODING(i965) ||
524 HAS_JPEG_ENCODING(i965)) {
525 profile_list[i++] = VAProfileJPEGBaseline;
528 if (HAS_VP8_DECODING(i965) ||
529 HAS_VP8_ENCODING(i965)) {
530 profile_list[i++] = VAProfileVP8Version0_3;
533 if (HAS_HEVC_DECODING(i965)||
534 HAS_HEVC_ENCODING(i965)) {
535 profile_list[i++] = VAProfileHEVCMain;
538 if (HAS_HEVC10_DECODING(i965)||
539 HAS_HEVC10_ENCODING(i965)) {
540 profile_list[i++] = VAProfileHEVCMain10;
543 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile0) ||
544 HAS_VP9_ENCODING(i965)) {
545 profile_list[i++] = VAProfileVP9Profile0;
548 if(HAS_VP9_DECODING_PROFILE(i965, VAProfileVP9Profile2)) {
549 profile_list[i++] = VAProfileVP9Profile2;
552 if (i965->wrapper_pdrvctx) {
553 VAProfile wrapper_list[4];
555 VADriverContextP pdrvctx;
558 pdrvctx = i965->wrapper_pdrvctx;
559 CALL_VTABLE(pdrvctx, va_status,
560 vaQueryConfigProfiles(pdrvctx,
561 wrapper_list, &wrapper_num));
563 if (va_status == VA_STATUS_SUCCESS) {
565 for (j = 0; j < wrapper_num; j++)
566 if (wrapper_list[j] != VAProfileNone)
567 profile_list[i++] = wrapper_list[j];
571 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
572 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
575 return VA_STATUS_SUCCESS;
579 i965_QueryConfigEntrypoints(VADriverContextP ctx,
581 VAEntrypoint *entrypoint_list, /* out */
582 int *num_entrypoints) /* out */
584 struct i965_driver_data * const i965 = i965_driver_data(ctx);
588 case VAProfileMPEG2Simple:
589 case VAProfileMPEG2Main:
590 if (HAS_MPEG2_DECODING(i965))
591 entrypoint_list[n++] = VAEntrypointVLD;
593 if (HAS_MPEG2_ENCODING(i965))
594 entrypoint_list[n++] = VAEntrypointEncSlice;
598 case VAProfileH264ConstrainedBaseline:
599 case VAProfileH264Main:
600 case VAProfileH264High:
601 if (HAS_H264_DECODING(i965))
602 entrypoint_list[n++] = VAEntrypointVLD;
604 if (HAS_H264_ENCODING(i965))
605 entrypoint_list[n++] = VAEntrypointEncSlice;
607 if (HAS_LP_H264_ENCODING(i965))
608 entrypoint_list[n++] = VAEntrypointEncSliceLP;
611 case VAProfileH264MultiviewHigh:
612 case VAProfileH264StereoHigh:
613 if (HAS_H264_MVC_DECODING_PROFILE(i965, profile))
614 entrypoint_list[n++] = VAEntrypointVLD;
616 if (HAS_H264_MVC_ENCODING(i965))
617 entrypoint_list[n++] = VAEntrypointEncSlice;
620 case VAProfileVC1Simple:
621 case VAProfileVC1Main:
622 case VAProfileVC1Advanced:
623 if (HAS_VC1_DECODING(i965))
624 entrypoint_list[n++] = VAEntrypointVLD;
629 entrypoint_list[n++] = VAEntrypointVideoProc;
632 case VAProfileJPEGBaseline:
633 if (HAS_JPEG_DECODING(i965))
634 entrypoint_list[n++] = VAEntrypointVLD;
636 if (HAS_JPEG_ENCODING(i965))
637 entrypoint_list[n++] = VAEntrypointEncPicture;
640 case VAProfileVP8Version0_3:
641 if (HAS_VP8_DECODING(i965))
642 entrypoint_list[n++] = VAEntrypointVLD;
644 if (HAS_VP8_ENCODING(i965))
645 entrypoint_list[n++] = VAEntrypointEncSlice;
649 case VAProfileHEVCMain:
650 if (HAS_HEVC_DECODING(i965))
651 entrypoint_list[n++] = VAEntrypointVLD;
653 if (HAS_HEVC_ENCODING(i965))
654 entrypoint_list[n++] = VAEntrypointEncSlice;
658 case VAProfileHEVCMain10:
659 if (HAS_HEVC10_DECODING(i965))
660 entrypoint_list[n++] = VAEntrypointVLD;
662 if (HAS_HEVC10_ENCODING(i965))
663 entrypoint_list[n++] = VAEntrypointEncSlice;
667 case VAProfileVP9Profile0:
668 case VAProfileVP9Profile2:
669 if(HAS_VP9_DECODING_PROFILE(i965, profile))
670 entrypoint_list[n++] = VAEntrypointVLD;
672 if (HAS_VP9_ENCODING(i965) && (profile == VAProfileVP9Profile0))
673 entrypoint_list[n++] = VAEntrypointEncSlice;
675 if(profile == VAProfileVP9Profile0) {
676 if (i965->wrapper_pdrvctx) {
677 VAStatus va_status = VA_STATUS_SUCCESS;
678 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
680 CALL_VTABLE(pdrvctx, va_status,
681 vaQueryConfigEntrypoints(pdrvctx, profile,
694 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
695 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
696 *num_entrypoints = n;
697 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
701 i965_validate_config(VADriverContextP ctx, VAProfile profile,
702 VAEntrypoint entrypoint)
704 struct i965_driver_data * const i965 = i965_driver_data(ctx);
707 /* Validate profile & entrypoint */
709 case VAProfileMPEG2Simple:
710 case VAProfileMPEG2Main:
711 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
712 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
713 va_status = VA_STATUS_SUCCESS;
715 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
719 case VAProfileH264ConstrainedBaseline:
720 case VAProfileH264Main:
721 case VAProfileH264High:
722 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
723 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice) ||
724 (HAS_LP_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSliceLP)) {
725 va_status = VA_STATUS_SUCCESS;
727 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
731 case VAProfileVC1Simple:
732 case VAProfileVC1Main:
733 case VAProfileVC1Advanced:
734 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
735 va_status = VA_STATUS_SUCCESS;
737 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
742 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
743 va_status = VA_STATUS_SUCCESS;
745 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
749 case VAProfileJPEGBaseline:
750 if ((HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
751 (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)) {
752 va_status = VA_STATUS_SUCCESS;
754 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
758 case VAProfileVP8Version0_3:
759 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
760 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
761 va_status = VA_STATUS_SUCCESS;
763 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
767 case VAProfileH264MultiviewHigh:
768 case VAProfileH264StereoHigh:
769 if ((HAS_H264_MVC_DECODING_PROFILE(i965, profile) &&
770 entrypoint == VAEntrypointVLD) ||
771 (HAS_H264_MVC_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
772 va_status = VA_STATUS_SUCCESS;
774 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
779 case VAProfileHEVCMain:
780 if ((HAS_HEVC_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
781 (HAS_HEVC_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice)))
782 va_status = VA_STATUS_SUCCESS;
784 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
788 case VAProfileHEVCMain10:
789 if ((HAS_HEVC10_DECODING(i965) && (entrypoint == VAEntrypointVLD))||
790 (HAS_HEVC10_ENCODING(i965) && (entrypoint == VAEntrypointEncSlice)))
791 va_status = VA_STATUS_SUCCESS;
793 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
797 case VAProfileVP9Profile0:
798 case VAProfileVP9Profile2:
799 if ((HAS_VP9_DECODING_PROFILE(i965, profile)) && (entrypoint == VAEntrypointVLD))
800 va_status = VA_STATUS_SUCCESS;
801 else if ((HAS_VP9_ENCODING(i965)) && (entrypoint == VAEntrypointEncSlice))
802 va_status = VA_STATUS_SUCCESS;
803 else if ((profile == VAProfileVP9Profile0) && i965->wrapper_pdrvctx)
804 va_status = VA_STATUS_SUCCESS;
806 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
810 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
817 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
818 VAEntrypoint entrypoint)
820 struct i965_driver_data * const i965 = i965_driver_data(ctx);
821 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
824 case VAProfileH264ConstrainedBaseline:
825 case VAProfileH264Main:
826 case VAProfileH264High:
827 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
828 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
831 case VAProfileH264MultiviewHigh:
832 case VAProfileH264StereoHigh:
833 if (HAS_H264_MVC_DECODING(i965) && entrypoint == VAEntrypointVLD)
834 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
837 case VAProfileJPEGBaseline:
838 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
839 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
840 if (HAS_JPEG_ENCODING(i965) && entrypoint == VAEntrypointEncPicture)
841 chroma_formats |= i965->codec_info->jpeg_enc_chroma_formats;
844 case VAProfileHEVCMain10:
845 if (HAS_HEVC10_DECODING(i965) && entrypoint == VAEntrypointVLD)
846 chroma_formats |= i965->codec_info->hevc_dec_chroma_formats;
850 if(HAS_VPP_P010(i965))
851 chroma_formats |= VA_RT_FORMAT_YUV420_10BPP;
854 case VAProfileVP9Profile0:
855 case VAProfileVP9Profile2:
856 if (HAS_VP9_DECODING_PROFILE(i965, profile) && entrypoint == VAEntrypointVLD)
857 chroma_formats |= i965->codec_info->vp9_dec_chroma_formats;
863 return chroma_formats;
867 i965_GetConfigAttributes(VADriverContextP ctx,
869 VAEntrypoint entrypoint,
870 VAConfigAttrib *attrib_list, /* in/out */
876 va_status = i965_validate_config(ctx, profile, entrypoint);
877 if (va_status != VA_STATUS_SUCCESS)
880 /* Other attributes don't seem to be defined */
881 /* What to do if we don't know the attribute? */
882 for (i = 0; i < num_attribs; i++) {
883 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
884 switch (attrib_list[i].type) {
885 case VAConfigAttribRTFormat:
886 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
887 profile, entrypoint);
890 case VAConfigAttribRateControl:
891 if (entrypoint == VAEntrypointEncSlice) {
892 attrib_list[i].value = VA_RC_CQP;
894 if (profile != VAProfileMPEG2Main &&
895 profile != VAProfileMPEG2Simple)
896 attrib_list[i].value |= VA_RC_CBR;
898 if (profile == VAProfileVP9Profile0)
899 attrib_list[i].value |= VA_RC_VBR;
902 } else if (entrypoint == VAEntrypointEncSliceLP) {
903 struct i965_driver_data * const i965 = i965_driver_data(ctx);
905 /* Support low power encoding for H.264 only by now */
906 if (profile == VAProfileH264ConstrainedBaseline ||
907 profile == VAProfileH264Main ||
908 profile == VAProfileH264High)
909 attrib_list[i].value = i965->codec_info->lp_h264_brc_mode;
911 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
913 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
917 case VAConfigAttribEncPackedHeaders:
918 if (entrypoint == VAEntrypointEncSlice ||
919 entrypoint == VAEntrypointEncSliceLP) {
920 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
921 if (profile == VAProfileH264ConstrainedBaseline ||
922 profile == VAProfileH264Main ||
923 profile == VAProfileH264High ||
924 profile == VAProfileH264StereoHigh ||
925 profile == VAProfileH264MultiviewHigh ||
926 profile == VAProfileHEVCMain ||
927 profile == VAProfileHEVCMain10) {
928 attrib_list[i].value |= (VA_ENC_PACKED_HEADER_RAW_DATA |
929 VA_ENC_PACKED_HEADER_SLICE);
931 else if (profile == VAProfileVP9Profile0)
932 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
935 else if (entrypoint == VAEntrypointEncPicture) {
936 if (profile == VAProfileJPEGBaseline)
937 attrib_list[i].value = VA_ENC_PACKED_HEADER_RAW_DATA;
941 case VAConfigAttribEncMaxRefFrames:
942 if (entrypoint == VAEntrypointEncSlice)
943 attrib_list[i].value = (1 << 16) | (1 << 0);
944 else if (entrypoint == VAEntrypointEncSliceLP) {
945 /* Don't support B frame for low power mode */
946 if (profile == VAProfileH264ConstrainedBaseline ||
947 profile == VAProfileH264Main ||
948 profile == VAProfileH264High)
949 attrib_list[i].value = (1 << 0);
951 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
956 case VAConfigAttribEncQualityRange:
957 if (entrypoint == VAEntrypointEncSlice ||
958 entrypoint == VAEntrypointEncSliceLP) {
959 attrib_list[i].value = 1;
960 if (profile == VAProfileH264ConstrainedBaseline ||
961 profile == VAProfileH264Main ||
962 profile == VAProfileH264High )
963 attrib_list[i].value = ENCODER_QUALITY_RANGE;
968 case VAConfigAttribEncJPEG:
969 if( entrypoint == VAEntrypointEncPicture) {
970 VAConfigAttribValEncJPEG *configVal = (VAConfigAttribValEncJPEG*)&(attrib_list[i].value);
971 (configVal->bits).arithmatic_coding_mode = 0; // Huffman coding is used
972 (configVal->bits).progressive_dct_mode = 0; // Only Sequential DCT is supported
973 (configVal->bits).non_interleaved_mode = 1; // Support both interleaved and non-interleaved
974 (configVal->bits).differential_mode = 0; // Baseline DCT is non-differential
975 (configVal->bits).max_num_components = 3; // Only 3 components supported
976 (configVal->bits).max_num_scans = 1; // Only 1 scan per frame
977 (configVal->bits).max_num_huffman_tables = 3; // Max 3 huffman tables
978 (configVal->bits).max_num_quantization_tables = 3; // Max 3 quantization tables
982 case VAConfigAttribDecSliceMode:
983 attrib_list[i].value = VA_DEC_SLICE_MODE_NORMAL;
986 case VAConfigAttribEncROI:
987 if (profile == VAProfileH264ConstrainedBaseline ||
988 profile == VAProfileH264Main ||
989 profile == VAProfileH264High) {
990 VAConfigAttribValEncROI *roi_config = (VAConfigAttribValEncROI *)&(attrib_list[i].value);
992 if(entrypoint == VAEntrypointEncSliceLP) {
993 roi_config->bits.num_roi_regions = 3;
994 roi_config->bits.roi_rc_priority_support = 0;
995 roi_config->bits.roi_rc_qp_delat_support = 0;
997 roi_config->bits.num_roi_regions = I965_MAX_NUM_ROI_REGIONS;
998 roi_config->bits.roi_rc_priority_support = 0;
999 roi_config->bits.roi_rc_qp_delat_support = 1;
1002 attrib_list[i].value = 0;
1009 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
1014 return VA_STATUS_SUCCESS;
1018 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
1020 object_heap_free(heap, obj);
1023 static VAConfigAttrib *
1024 i965_lookup_config_attribute(struct object_config *obj_config,
1025 VAConfigAttribType type)
1029 for (i = 0; i < obj_config->num_attribs; i++) {
1030 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
1031 if (attrib->type == type)
1038 i965_append_config_attribute(struct object_config *obj_config,
1039 const VAConfigAttrib *new_attrib)
1041 VAConfigAttrib *attrib;
1043 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
1044 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1046 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
1047 attrib->type = new_attrib->type;
1048 attrib->value = new_attrib->value;
1049 return VA_STATUS_SUCCESS;
1053 i965_ensure_config_attribute(struct object_config *obj_config,
1054 const VAConfigAttrib *new_attrib)
1056 VAConfigAttrib *attrib;
1058 /* Check for existing attributes */
1059 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
1061 /* Update existing attribute */
1062 attrib->value = new_attrib->value;
1063 return VA_STATUS_SUCCESS;
1065 return i965_append_config_attribute(obj_config, new_attrib);
1069 i965_CreateConfig(VADriverContextP ctx,
1071 VAEntrypoint entrypoint,
1072 VAConfigAttrib *attrib_list,
1074 VAConfigID *config_id) /* out */
1076 struct i965_driver_data * const i965 = i965_driver_data(ctx);
1077 struct object_config *obj_config;
1082 vaStatus = i965_validate_config(ctx, profile, entrypoint);
1084 if (VA_STATUS_SUCCESS != vaStatus) {
1088 configID = NEW_CONFIG_ID();
1089 obj_config = CONFIG(configID);
1091 if (NULL == obj_config) {
1092 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1096 obj_config->profile = profile;
1097 obj_config->entrypoint = entrypoint;
1098 obj_config->num_attribs = 0;
1099 obj_config->wrapper_config = VA_INVALID_ID;
1101 for (i = 0; i < num_attribs; i++) {
1102 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
1103 if (vaStatus != VA_STATUS_SUCCESS)
1107 if (vaStatus == VA_STATUS_SUCCESS) {
1108 VAConfigAttrib attrib, *attrib_found;
1109 attrib.type = VAConfigAttribRTFormat;
1110 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
1111 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
1112 if (!attrib_found || !attrib_found->value)
1113 vaStatus = i965_append_config_attribute(obj_config, &attrib);
1114 else if (!(attrib_found->value & attrib.value))
1115 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1118 if ((vaStatus == VA_STATUS_SUCCESS) &&
1119 (profile == VAProfileVP9Profile0) &&
1120 (entrypoint == VAEntrypointVLD) &&
1121 !HAS_VP9_DECODING(i965)) {
1123 if (i965->wrapper_pdrvctx) {
1124 VAGenericID wrapper_config;
1126 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1127 vaCreateConfig(i965->wrapper_pdrvctx, profile,
1128 entrypoint, attrib_list,
1129 num_attribs, &wrapper_config));
1131 if (vaStatus == VA_STATUS_SUCCESS)
1132 obj_config->wrapper_config = wrapper_config;
1136 /* Error recovery */
1137 if (VA_STATUS_SUCCESS != vaStatus) {
1138 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1140 *config_id = configID;
1147 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
1149 struct i965_driver_data *i965 = i965_driver_data(ctx);
1150 struct object_config *obj_config = CONFIG(config_id);
1153 if (NULL == obj_config) {
1154 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1158 if ((obj_config->wrapper_config != VA_INVALID_ID) &&
1159 i965->wrapper_pdrvctx) {
1160 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
1161 vaDestroyConfig(i965->wrapper_pdrvctx,
1162 obj_config->wrapper_config));
1163 obj_config->wrapper_config = VA_INVALID_ID;
1166 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
1167 return VA_STATUS_SUCCESS;
1170 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
1171 VAConfigID config_id,
1172 VAProfile *profile, /* out */
1173 VAEntrypoint *entrypoint, /* out */
1174 VAConfigAttrib *attrib_list, /* out */
1175 int *num_attribs) /* out */
1177 struct i965_driver_data *i965 = i965_driver_data(ctx);
1178 struct object_config *obj_config = CONFIG(config_id);
1179 VAStatus vaStatus = VA_STATUS_SUCCESS;
1182 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
1183 *profile = obj_config->profile;
1184 *entrypoint = obj_config->entrypoint;
1185 *num_attribs = obj_config->num_attribs;
1187 for(i = 0; i < obj_config->num_attribs; i++) {
1188 attrib_list[i] = obj_config->attrib_list[i];
1195 i965_destroy_surface_storage(struct object_surface *obj_surface)
1200 dri_bo_unreference(obj_surface->bo);
1201 obj_surface->bo = NULL;
1203 if (obj_surface->free_private_data != NULL) {
1204 obj_surface->free_private_data(&obj_surface->private_data);
1205 obj_surface->private_data = NULL;
1210 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1212 struct object_surface *obj_surface = (struct object_surface *)obj;
1214 i965_destroy_surface_storage(obj_surface);
1215 object_heap_free(heap, obj);
1219 i965_surface_native_memory(VADriverContextP ctx,
1220 struct object_surface *obj_surface,
1222 int expected_fourcc)
1224 struct i965_driver_data *i965 = i965_driver_data(ctx);
1225 int tiling = HAS_TILED_SURFACE(i965);
1227 if (!expected_fourcc)
1228 return VA_STATUS_SUCCESS;
1230 // todo, should we disable tiling for 422 format?
1231 if (expected_fourcc == VA_FOURCC_I420 ||
1232 expected_fourcc == VA_FOURCC_IYUV ||
1233 expected_fourcc == VA_FOURCC_YV12 ||
1234 expected_fourcc == VA_FOURCC_YV16)
1237 return i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
1241 i965_suface_external_memory(VADriverContextP ctx,
1242 struct object_surface *obj_surface,
1243 int external_memory_type,
1244 VASurfaceAttribExternalBuffers *memory_attibute,
1247 struct i965_driver_data *i965 = i965_driver_data(ctx);
1249 if (!memory_attibute ||
1250 !memory_attibute->buffers ||
1251 index > memory_attibute->num_buffers)
1252 return VA_STATUS_ERROR_INVALID_PARAMETER;
1254 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
1255 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
1256 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1258 obj_surface->fourcc = memory_attibute->pixel_format;
1259 obj_surface->width = memory_attibute->pitches[0];
1260 obj_surface->size = memory_attibute->data_size;
1262 if (memory_attibute->num_planes == 1)
1263 obj_surface->height = memory_attibute->data_size / obj_surface->width;
1265 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1267 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
1268 obj_surface->x_cr_offset = 0;
1270 switch (obj_surface->fourcc) {
1271 case VA_FOURCC_NV12:
1272 case VA_FOURCC_P010:
1273 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
1274 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
1276 obj_surface->subsampling = SUBSAMPLE_YUV420;
1277 obj_surface->y_cb_offset = obj_surface->height;
1278 obj_surface->y_cr_offset = obj_surface->height;
1279 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1280 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1281 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1285 case VA_FOURCC_YV12:
1286 case VA_FOURCC_IMC1:
1287 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1288 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1290 obj_surface->subsampling = SUBSAMPLE_YUV420;
1291 obj_surface->y_cr_offset = obj_surface->height;
1292 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1293 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1294 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1295 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1299 case VA_FOURCC_I420:
1300 case VA_FOURCC_IYUV:
1301 case VA_FOURCC_IMC3:
1302 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1303 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1305 obj_surface->subsampling = SUBSAMPLE_YUV420;
1306 obj_surface->y_cb_offset = obj_surface->height;
1307 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1308 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1309 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1310 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1314 case VA_FOURCC_YUY2:
1315 case VA_FOURCC_UYVY:
1316 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1318 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1319 obj_surface->y_cb_offset = 0;
1320 obj_surface->y_cr_offset = 0;
1321 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1322 obj_surface->cb_cr_height = obj_surface->orig_height;
1323 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
1327 case VA_FOURCC_RGBA:
1328 case VA_FOURCC_RGBX:
1329 case VA_FOURCC_BGRA:
1330 case VA_FOURCC_BGRX:
1331 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1333 obj_surface->subsampling = SUBSAMPLE_RGBX;
1334 obj_surface->y_cb_offset = 0;
1335 obj_surface->y_cr_offset = 0;
1336 obj_surface->cb_cr_width = 0;
1337 obj_surface->cb_cr_height = 0;
1338 obj_surface->cb_cr_pitch = 0;
1342 case VA_FOURCC_Y800: /* monochrome surface */
1343 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1345 obj_surface->subsampling = SUBSAMPLE_YUV400;
1346 obj_surface->y_cb_offset = 0;
1347 obj_surface->y_cr_offset = 0;
1348 obj_surface->cb_cr_width = 0;
1349 obj_surface->cb_cr_height = 0;
1350 obj_surface->cb_cr_pitch = 0;
1354 case VA_FOURCC_411P:
1355 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1356 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1358 obj_surface->subsampling = SUBSAMPLE_YUV411;
1359 obj_surface->y_cb_offset = 0;
1360 obj_surface->y_cr_offset = 0;
1361 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
1362 obj_surface->cb_cr_height = obj_surface->orig_height;
1363 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1367 case VA_FOURCC_422H:
1368 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1369 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1371 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1372 obj_surface->y_cb_offset = obj_surface->height;
1373 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1374 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1375 obj_surface->cb_cr_height = obj_surface->orig_height;
1376 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1380 case VA_FOURCC_YV16:
1381 assert(memory_attibute->num_planes == 3);
1382 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1384 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1385 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
1386 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
1387 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
1388 obj_surface->cb_cr_height = obj_surface->orig_height;
1389 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1393 case VA_FOURCC_422V:
1394 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1395 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1397 obj_surface->subsampling = SUBSAMPLE_YUV422H;
1398 obj_surface->y_cb_offset = obj_surface->height;
1399 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1400 obj_surface->cb_cr_width = obj_surface->orig_width;
1401 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
1402 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1406 case VA_FOURCC_444P:
1407 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1408 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
1410 obj_surface->subsampling = SUBSAMPLE_YUV444;
1411 obj_surface->y_cb_offset = obj_surface->height;
1412 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1413 obj_surface->cb_cr_width = obj_surface->orig_width;
1414 obj_surface->cb_cr_height = obj_surface->orig_height;
1415 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1421 return VA_STATUS_ERROR_INVALID_PARAMETER;
1424 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1425 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1426 "gem flinked vaapi surface",
1427 memory_attibute->buffers[index]);
1428 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1429 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1430 memory_attibute->buffers[index],
1433 if (!obj_surface->bo)
1434 return VA_STATUS_ERROR_INVALID_PARAMETER;
1436 return VA_STATUS_SUCCESS;
1439 /* byte-per-pixel of the first plane */
1441 bpp_1stplane_by_fourcc(unsigned int fourcc)
1443 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1445 if (info && (info->flag & I_S))
1446 return info->bpp[0] / 8;
1452 i965_CreateSurfaces2(
1453 VADriverContextP ctx,
1454 unsigned int format,
1456 unsigned int height,
1457 VASurfaceID *surfaces,
1458 unsigned int num_surfaces,
1459 VASurfaceAttrib *attrib_list,
1460 unsigned int num_attribs
1463 struct i965_driver_data *i965 = i965_driver_data(ctx);
1465 VAStatus vaStatus = VA_STATUS_SUCCESS;
1466 int expected_fourcc = 0;
1467 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1468 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1470 for (i = 0; i < num_attribs && attrib_list; i++) {
1471 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1472 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1473 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1474 expected_fourcc = attrib_list[i].value.value.i;
1477 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1478 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1480 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1482 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1483 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1484 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1485 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1486 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1487 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1490 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1491 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1492 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1493 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1497 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1498 * for post-processing (including color conversion) */
1499 if (VA_RT_FORMAT_YUV420 != format &&
1500 VA_RT_FORMAT_YUV420_10BPP != format &&
1501 VA_RT_FORMAT_YUV422 != format &&
1502 VA_RT_FORMAT_YUV444 != format &&
1503 VA_RT_FORMAT_YUV411 != format &&
1504 VA_RT_FORMAT_YUV400 != format &&
1505 VA_RT_FORMAT_RGB32 != format) {
1506 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1509 for (i = 0; i < num_surfaces; i++) {
1510 int surfaceID = NEW_SURFACE_ID();
1511 struct object_surface *obj_surface = SURFACE(surfaceID);
1513 if (NULL == obj_surface) {
1514 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1518 surfaces[i] = surfaceID;
1519 obj_surface->status = VASurfaceReady;
1520 obj_surface->orig_width = width;
1521 obj_surface->orig_height = height;
1522 obj_surface->user_disable_tiling = false;
1523 obj_surface->user_h_stride_set = false;
1524 obj_surface->user_v_stride_set = false;
1525 obj_surface->border_cleared = false;
1527 obj_surface->subpic_render_idx = 0;
1528 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1529 obj_surface->subpic[j] = VA_INVALID_ID;
1530 obj_surface->obj_subpic[j] = NULL;
1533 assert(i965->codec_info->min_linear_wpitch);
1534 assert(i965->codec_info->min_linear_hpitch);
1535 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1536 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1537 obj_surface->flags = SURFACE_REFERENCED;
1538 obj_surface->fourcc = 0;
1539 obj_surface->expected_format = format;
1540 obj_surface->bo = NULL;
1541 obj_surface->locked_image_id = VA_INVALID_ID;
1542 obj_surface->derived_image_id = VA_INVALID_ID;
1543 obj_surface->private_data = NULL;
1544 obj_surface->free_private_data = NULL;
1545 obj_surface->subsampling = SUBSAMPLE_YUV420;
1547 obj_surface->wrapper_surface = VA_INVALID_ID;
1548 obj_surface->exported_primefd = -1;
1550 switch (memory_type) {
1551 case I965_SURFACE_MEM_NATIVE:
1552 if (memory_attibute) {
1553 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1554 obj_surface->user_disable_tiling = true;
1556 if (memory_attibute->pixel_format) {
1557 if (expected_fourcc)
1558 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1560 expected_fourcc = memory_attibute->pixel_format;
1562 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1563 if (memory_attibute->pitches[0]) {
1564 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1565 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1566 obj_surface->width = memory_attibute->pitches[0];
1567 obj_surface->user_h_stride_set = true;
1568 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1569 ASSERT_RET(obj_surface->width >= width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1571 if (memory_attibute->offsets[1]) {
1572 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1573 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1574 obj_surface->user_v_stride_set = true;
1575 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1576 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1580 vaStatus = i965_surface_native_memory(ctx,
1586 case I965_SURFACE_MEM_GEM_FLINK:
1587 case I965_SURFACE_MEM_DRM_PRIME:
1588 vaStatus = i965_suface_external_memory(ctx,
1595 if (VA_STATUS_SUCCESS != vaStatus) {
1596 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1601 /* Error recovery */
1602 if (VA_STATUS_SUCCESS != vaStatus) {
1603 /* surfaces[i-1] was the last successful allocation */
1605 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1607 surfaces[i] = VA_INVALID_SURFACE;
1608 assert(obj_surface);
1609 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1617 i965_CreateSurfaces(VADriverContextP ctx,
1622 VASurfaceID *surfaces) /* out */
1624 return i965_CreateSurfaces2(ctx,
1635 i965_DestroySurfaces(VADriverContextP ctx,
1636 VASurfaceID *surface_list,
1639 struct i965_driver_data *i965 = i965_driver_data(ctx);
1641 VAStatus va_status = VA_STATUS_SUCCESS;
1643 for (i = num_surfaces; i--; ) {
1644 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1646 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1648 if ((obj_surface->wrapper_surface != VA_INVALID_ID) &&
1649 i965->wrapper_pdrvctx) {
1650 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
1651 vaDestroySurfaces(i965->wrapper_pdrvctx,
1652 &(obj_surface->wrapper_surface),
1654 obj_surface->wrapper_surface = VA_INVALID_ID;
1656 if (obj_surface->exported_primefd >= 0) {
1657 close(obj_surface->exported_primefd);
1658 obj_surface->exported_primefd = -1;
1661 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1668 i965_QueryImageFormats(VADriverContextP ctx,
1669 VAImageFormat *format_list, /* out */
1670 int *num_formats) /* out */
1674 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1675 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1677 format_list[n] = m->va_format;
1683 return VA_STATUS_SUCCESS;
1687 * Guess the format when the usage of a VA surface is unknown
1688 * 1. Without a valid context: YV12
1689 * 2. The current context is valid:
1690 * a) always NV12 on GEN6 and later
1691 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1694 i965_guess_surface_format(VADriverContextP ctx,
1695 VASurfaceID surface,
1696 unsigned int *fourcc,
1697 unsigned int *is_tiled)
1699 struct i965_driver_data *i965 = i965_driver_data(ctx);
1700 struct object_context *obj_context = NULL;
1701 struct object_config *obj_config = NULL;
1703 *fourcc = VA_FOURCC_YV12;
1706 if (i965->current_context_id == VA_INVALID_ID)
1709 obj_context = CONTEXT(i965->current_context_id);
1714 obj_config = obj_context->obj_config;
1720 if (IS_GEN6(i965->intel.device_info) ||
1721 IS_GEN7(i965->intel.device_info) ||
1722 IS_GEN8(i965->intel.device_info) ||
1723 IS_GEN9(i965->intel.device_info)) {
1724 *fourcc = VA_FOURCC_NV12;
1729 switch (obj_config->profile) {
1730 case VAProfileMPEG2Simple:
1731 case VAProfileMPEG2Main:
1732 *fourcc = VA_FOURCC_I420;
1737 *fourcc = VA_FOURCC_NV12;
1744 i965_QuerySubpictureFormats(VADriverContextP ctx,
1745 VAImageFormat *format_list, /* out */
1746 unsigned int *flags, /* out */
1747 unsigned int *num_formats) /* out */
1751 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1752 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1754 format_list[n] = m->va_format;
1756 flags[n] = m->va_flags;
1762 return VA_STATUS_SUCCESS;
1766 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1768 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1770 object_heap_free(heap, obj);
1774 i965_CreateSubpicture(VADriverContextP ctx,
1776 VASubpictureID *subpicture) /* out */
1778 struct i965_driver_data *i965 = i965_driver_data(ctx);
1779 VASubpictureID subpicID = NEW_SUBPIC_ID()
1780 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1783 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1785 struct object_image *obj_image = IMAGE(image);
1787 return VA_STATUS_ERROR_INVALID_IMAGE;
1789 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1791 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1793 *subpicture = subpicID;
1794 obj_subpic->image = image;
1795 obj_subpic->obj_image = obj_image;
1796 obj_subpic->format = m->format;
1797 obj_subpic->width = obj_image->image.width;
1798 obj_subpic->height = obj_image->image.height;
1799 obj_subpic->pitch = obj_image->image.pitches[0];
1800 obj_subpic->bo = obj_image->bo;
1801 obj_subpic->global_alpha = 1.0;
1803 return VA_STATUS_SUCCESS;
1807 i965_DestroySubpicture(VADriverContextP ctx,
1808 VASubpictureID subpicture)
1810 struct i965_driver_data *i965 = i965_driver_data(ctx);
1811 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1814 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1816 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1817 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1818 return VA_STATUS_SUCCESS;
1822 i965_SetSubpictureImage(VADriverContextP ctx,
1823 VASubpictureID subpicture,
1827 return VA_STATUS_ERROR_UNIMPLEMENTED;
1831 i965_SetSubpictureChromakey(VADriverContextP ctx,
1832 VASubpictureID subpicture,
1833 unsigned int chromakey_min,
1834 unsigned int chromakey_max,
1835 unsigned int chromakey_mask)
1838 return VA_STATUS_ERROR_UNIMPLEMENTED;
1842 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1843 VASubpictureID subpicture,
1846 struct i965_driver_data *i965 = i965_driver_data(ctx);
1847 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1849 if(global_alpha > 1.0 || global_alpha < 0.0){
1850 return VA_STATUS_ERROR_INVALID_PARAMETER;
1854 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1856 obj_subpic->global_alpha = global_alpha;
1858 return VA_STATUS_SUCCESS;
1862 i965_AssociateSubpicture(VADriverContextP ctx,
1863 VASubpictureID subpicture,
1864 VASurfaceID *target_surfaces,
1866 short src_x, /* upper left offset in subpicture */
1868 unsigned short src_width,
1869 unsigned short src_height,
1870 short dest_x, /* upper left offset in surface */
1872 unsigned short dest_width,
1873 unsigned short dest_height,
1875 * whether to enable chroma-keying or global-alpha
1876 * see VA_SUBPICTURE_XXX values
1880 struct i965_driver_data *i965 = i965_driver_data(ctx);
1881 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1885 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1887 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1889 obj_subpic->src_rect.x = src_x;
1890 obj_subpic->src_rect.y = src_y;
1891 obj_subpic->src_rect.width = src_width;
1892 obj_subpic->src_rect.height = src_height;
1893 obj_subpic->dst_rect.x = dest_x;
1894 obj_subpic->dst_rect.y = dest_y;
1895 obj_subpic->dst_rect.width = dest_width;
1896 obj_subpic->dst_rect.height = dest_height;
1897 obj_subpic->flags = flags;
1899 for (i = 0; i < num_surfaces; i++) {
1900 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1902 return VA_STATUS_ERROR_INVALID_SURFACE;
1904 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1905 if(obj_surface->subpic[j] == VA_INVALID_ID){
1906 assert(obj_surface->obj_subpic[j] == NULL);
1907 obj_surface->subpic[j] = subpicture;
1908 obj_surface->obj_subpic[j] = obj_subpic;
1913 if(j == I965_MAX_SUBPIC_SUM){
1914 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1918 return VA_STATUS_SUCCESS;
1923 i965_DeassociateSubpicture(VADriverContextP ctx,
1924 VASubpictureID subpicture,
1925 VASurfaceID *target_surfaces,
1928 struct i965_driver_data *i965 = i965_driver_data(ctx);
1929 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1933 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1935 for (i = 0; i < num_surfaces; i++) {
1936 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1938 return VA_STATUS_ERROR_INVALID_SURFACE;
1940 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1941 if (obj_surface->subpic[j] == subpicture) {
1942 assert(obj_surface->obj_subpic[j] == obj_subpic);
1943 obj_surface->subpic[j] = VA_INVALID_ID;
1944 obj_surface->obj_subpic[j] = NULL;
1949 if(j == I965_MAX_SUBPIC_SUM){
1950 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1953 return VA_STATUS_SUCCESS;
1957 i965_reference_buffer_store(struct buffer_store **ptr,
1958 struct buffer_store *buffer_store)
1960 assert(*ptr == NULL);
1963 buffer_store->ref_count++;
1964 *ptr = buffer_store;
1969 i965_release_buffer_store(struct buffer_store **ptr)
1971 struct buffer_store *buffer_store = *ptr;
1973 if (buffer_store == NULL)
1976 assert(buffer_store->bo || buffer_store->buffer);
1977 assert(!(buffer_store->bo && buffer_store->buffer));
1978 buffer_store->ref_count--;
1980 if (buffer_store->ref_count == 0) {
1981 dri_bo_unreference(buffer_store->bo);
1982 free(buffer_store->buffer);
1983 buffer_store->bo = NULL;
1984 buffer_store->buffer = NULL;
1992 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1994 struct object_context *obj_context = (struct object_context *)obj;
1997 if (obj_context->hw_context) {
1998 obj_context->hw_context->destroy(obj_context->hw_context);
1999 obj_context->hw_context = NULL;
2002 if (obj_context->codec_type == CODEC_PROC) {
2003 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
2005 } else if (obj_context->codec_type == CODEC_ENC) {
2006 i965_release_buffer_store(&obj_context->codec_state.encode.q_matrix);
2007 i965_release_buffer_store(&obj_context->codec_state.encode.huffman_table);
2009 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
2010 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2011 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2013 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2014 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2016 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2017 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2019 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2020 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2021 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2023 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2024 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2026 free(obj_context->codec_state.encode.slice_params_ext);
2027 if (obj_context->codec_state.encode.slice_rawdata_index) {
2028 free(obj_context->codec_state.encode.slice_rawdata_index);
2029 obj_context->codec_state.encode.slice_rawdata_index = NULL;
2031 if (obj_context->codec_state.encode.slice_rawdata_count) {
2032 free(obj_context->codec_state.encode.slice_rawdata_count);
2033 obj_context->codec_state.encode.slice_rawdata_count = NULL;
2036 if (obj_context->codec_state.encode.slice_header_index) {
2037 free(obj_context->codec_state.encode.slice_header_index);
2038 obj_context->codec_state.encode.slice_header_index = NULL;
2041 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2042 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2043 free(obj_context->codec_state.encode.packed_header_params_ext);
2045 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2046 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2047 free(obj_context->codec_state.encode.packed_header_data_ext);
2049 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2051 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
2052 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
2054 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2055 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2056 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2058 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
2059 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2061 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
2062 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2064 free(obj_context->codec_state.decode.slice_params);
2065 free(obj_context->codec_state.decode.slice_datas);
2068 free(obj_context->render_targets);
2069 object_heap_free(heap, obj);
2073 max_resolution(struct i965_driver_data *i965,
2074 struct object_config *obj_config,
2078 if (i965->codec_info->max_resolution) {
2079 i965->codec_info->max_resolution(i965, obj_config, w, h);
2081 *w = i965->codec_info->max_width;
2082 *h = i965->codec_info->max_height;
2087 i965_CreateContext(VADriverContextP ctx,
2088 VAConfigID config_id,
2092 VASurfaceID *render_targets,
2093 int num_render_targets,
2094 VAContextID *context) /* out */
2096 struct i965_driver_data *i965 = i965_driver_data(ctx);
2097 struct object_config *obj_config = CONFIG(config_id);
2098 struct object_context *obj_context = NULL;
2099 VAConfigAttrib *attrib;
2100 VAStatus vaStatus = VA_STATUS_SUCCESS;
2106 if (NULL == obj_config) {
2107 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
2111 max_resolution(i965, obj_config, &max_width, &max_height);
2113 if (picture_width > max_width ||
2114 picture_height > max_height) {
2115 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
2120 /* Validate picture dimensions */
2121 contextID = NEW_CONTEXT_ID();
2122 obj_context = CONTEXT(contextID);
2124 if (NULL == obj_context) {
2125 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
2129 *context = contextID;
2130 obj_context->flags = flag;
2131 obj_context->context_id = contextID;
2132 obj_context->obj_config = obj_config;
2133 obj_context->picture_width = picture_width;
2134 obj_context->picture_height = picture_height;
2135 obj_context->num_render_targets = num_render_targets;
2136 obj_context->render_targets =
2137 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
2138 obj_context->hw_context = NULL;
2139 obj_context->wrapper_context = VA_INVALID_ID;
2141 if (!obj_context->render_targets)
2142 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2144 for(i = 0; i < num_render_targets; i++) {
2145 if (NULL == SURFACE(render_targets[i])) {
2146 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
2150 obj_context->render_targets[i] = render_targets[i];
2153 if (VA_STATUS_SUCCESS == vaStatus) {
2154 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2155 obj_context->codec_type = CODEC_PROC;
2156 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
2157 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
2158 assert(i965->codec_info->proc_hw_context_init);
2159 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
2160 } else if ((VAEntrypointEncSlice == obj_config->entrypoint) ||
2161 (VAEntrypointEncPicture == obj_config->entrypoint) ||
2162 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
2163 VAConfigAttrib *packed_attrib;
2164 obj_context->codec_type = CODEC_ENC;
2165 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
2166 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
2167 obj_context->codec_state.encode.max_packed_header_params_ext = NUM_SLICES;
2168 obj_context->codec_state.encode.packed_header_params_ext =
2169 calloc(obj_context->codec_state.encode.max_packed_header_params_ext,
2170 sizeof(struct buffer_store *));
2172 obj_context->codec_state.encode.max_packed_header_data_ext = NUM_SLICES;
2173 obj_context->codec_state.encode.packed_header_data_ext =
2174 calloc(obj_context->codec_state.encode.max_packed_header_data_ext,
2175 sizeof(struct buffer_store *));
2177 obj_context->codec_state.encode.max_slice_num = NUM_SLICES;
2178 obj_context->codec_state.encode.slice_rawdata_index =
2179 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2180 obj_context->codec_state.encode.slice_rawdata_count =
2181 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2183 obj_context->codec_state.encode.slice_header_index =
2184 calloc(obj_context->codec_state.encode.max_slice_num, sizeof(int));
2186 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2188 obj_context->codec_state.encode.slice_index = 0;
2189 packed_attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribEncPackedHeaders);
2190 if (packed_attrib) {
2191 obj_context->codec_state.encode.packed_header_flag = packed_attrib->value;
2192 if (obj_config->profile == VAProfileVP9Profile0)
2193 obj_context->codec_state.encode.packed_header_flag =
2194 packed_attrib->value & VA_ENC_PACKED_HEADER_RAW_DATA;
2196 /* use the default value. SPS/PPS/RAWDATA is passed from user
2197 * while Slice_header data is generated by driver.
2199 obj_context->codec_state.encode.packed_header_flag =
2200 VA_ENC_PACKED_HEADER_SEQUENCE |
2201 VA_ENC_PACKED_HEADER_PICTURE |
2202 VA_ENC_PACKED_HEADER_RAW_DATA;
2204 /* it is not used for VP9 */
2205 if (obj_config->profile == VAProfileVP9Profile0)
2206 obj_context->codec_state.encode.packed_header_flag = 0;
2208 assert(i965->codec_info->enc_hw_context_init);
2209 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
2211 obj_context->codec_type = CODEC_DEC;
2212 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
2213 obj_context->codec_state.decode.current_render_target = -1;
2214 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
2215 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
2216 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
2217 sizeof(*obj_context->codec_state.decode.slice_params));
2218 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
2219 sizeof(*obj_context->codec_state.decode.slice_datas));
2221 assert(i965->codec_info->dec_hw_context_init);
2222 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
2226 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
2228 return VA_STATUS_ERROR_INVALID_CONFIG;
2229 obj_context->codec_state.base.chroma_formats = attrib->value;
2231 if (obj_config->wrapper_config != VA_INVALID_ID) {
2232 /* The wrapper_pdrvctx should exist when wrapper_config is valid.
2233 * So it won't check i965->wrapper_pdrvctx again.
2234 * Fixme if it is incorrect.
2236 VAGenericID wrapper_context;
2239 * The render_surface is not passed when calling
2241 * If it is needed, we must get the wrapped surface
2242 * for the corresponding Surface_list.
2243 * So the wrapped surface conversion is deferred.
2245 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2246 vaCreateContext(i965->wrapper_pdrvctx,
2247 obj_config->wrapper_config,
2248 picture_width, picture_height,
2252 if (vaStatus == VA_STATUS_SUCCESS)
2253 obj_context->wrapper_context = wrapper_context;
2255 /* Error recovery */
2256 if (VA_STATUS_SUCCESS != vaStatus) {
2257 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2260 i965->current_context_id = contextID;
2266 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
2268 struct i965_driver_data *i965 = i965_driver_data(ctx);
2269 struct object_context *obj_context = CONTEXT(context);
2270 VAStatus va_status = VA_STATUS_SUCCESS;
2272 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2274 if (i965->current_context_id == context)
2275 i965->current_context_id = VA_INVALID_ID;
2277 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2278 i965->wrapper_pdrvctx) {
2279 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2280 vaDestroyContext(i965->wrapper_pdrvctx,
2281 obj_context->wrapper_context));
2283 obj_context->wrapper_context = VA_INVALID_ID;
2286 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
2292 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
2294 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
2296 assert(obj_buffer->buffer_store);
2297 i965_release_buffer_store(&obj_buffer->buffer_store);
2298 object_heap_free(heap, obj);
2302 i965_create_buffer_internal(VADriverContextP ctx,
2303 VAContextID context,
2306 unsigned int num_elements,
2311 struct i965_driver_data *i965 = i965_driver_data(ctx);
2312 struct object_buffer *obj_buffer = NULL;
2313 struct buffer_store *buffer_store = NULL;
2315 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2316 struct object_context *obj_context = CONTEXT(context);
2317 int wrapper_flag = 0;
2321 case VAPictureParameterBufferType:
2322 case VAIQMatrixBufferType:
2323 case VAQMatrixBufferType:
2324 case VABitPlaneBufferType:
2325 case VASliceGroupMapBufferType:
2326 case VASliceParameterBufferType:
2327 case VASliceDataBufferType:
2328 case VAMacroblockParameterBufferType:
2329 case VAResidualDataBufferType:
2330 case VADeblockingParameterBufferType:
2331 case VAImageBufferType:
2332 case VAEncCodedBufferType:
2333 case VAEncSequenceParameterBufferType:
2334 case VAEncPictureParameterBufferType:
2335 case VAEncSliceParameterBufferType:
2336 case VAEncPackedHeaderParameterBufferType:
2337 case VAEncPackedHeaderDataBufferType:
2338 case VAEncMiscParameterBufferType:
2339 case VAProcPipelineParameterBufferType:
2340 case VAProcFilterParameterBufferType:
2341 case VAHuffmanTableBufferType:
2342 case VAProbabilityBufferType:
2343 case VAEncMacroblockMapBufferType:
2348 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2351 bufferID = NEW_BUFFER_ID();
2352 obj_buffer = BUFFER(bufferID);
2354 if (NULL == obj_buffer) {
2355 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2358 if (type == VAEncCodedBufferType) {
2359 size += I965_CODEDBUFFER_HEADER_SIZE;
2360 size += 0x1000; /* for upper bound check */
2363 obj_buffer->max_num_elements = num_elements;
2364 obj_buffer->num_elements = num_elements;
2365 obj_buffer->size_element = size;
2366 obj_buffer->type = type;
2367 obj_buffer->export_refcount = 0;
2368 obj_buffer->buffer_store = NULL;
2369 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2370 obj_buffer->context_id = context;
2372 buffer_store = calloc(1, sizeof(struct buffer_store));
2373 assert(buffer_store);
2374 buffer_store->ref_count = 1;
2377 (obj_context->wrapper_context != VA_INVALID_ID) &&
2378 i965->wrapper_pdrvctx) {
2379 VAGenericID wrapper_buffer;
2380 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2382 CALL_VTABLE(pdrvctx, vaStatus,
2383 vaCreateBuffer(pdrvctx, obj_context->wrapper_context, type, size, num_elements,
2384 data, &wrapper_buffer));
2385 if (vaStatus == VA_STATUS_SUCCESS) {
2386 obj_buffer->wrapper_buffer = wrapper_buffer;
2394 if (store_bo != NULL) {
2395 buffer_store->bo = store_bo;
2396 dri_bo_reference(buffer_store->bo);
2398 /* If the buffer is wrapped, the buffer_store is bogus. Unnecessary to copy it */
2399 if (data && !wrapper_flag)
2400 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2401 } else if (type == VASliceDataBufferType ||
2402 type == VAImageBufferType ||
2403 type == VAEncCodedBufferType ||
2404 type == VAEncMacroblockMapBufferType ||
2405 type == VAProbabilityBufferType) {
2407 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2408 * So it is enough to allocate one 64 byte bo
2411 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, "Bogus buffer",
2414 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
2416 size * num_elements, 64);
2417 assert(buffer_store->bo);
2419 /* If the buffer is wrapped, the bo/buffer of buffer_store is bogus.
2420 * In fact it can be skipped. But it is still allocated and it is
2421 * only to follow the normal flowchart of buffer_allocation/release.
2423 if (!wrapper_flag) {
2424 if (type == VAEncCodedBufferType) {
2425 struct i965_coded_buffer_segment *coded_buffer_segment;
2427 dri_bo_map(buffer_store->bo, 1);
2428 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
2429 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
2430 coded_buffer_segment->base.bit_offset = 0;
2431 coded_buffer_segment->base.status = 0;
2432 coded_buffer_segment->base.buf = NULL;
2433 coded_buffer_segment->base.next = NULL;
2434 coded_buffer_segment->mapped = 0;
2435 coded_buffer_segment->codec = 0;
2436 coded_buffer_segment->status_support = 0;
2437 dri_bo_unmap(buffer_store->bo);
2439 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
2446 if (type == VAEncPackedHeaderDataBufferType) {
2447 msize = ALIGN(size, 4);
2450 /* If the buffer is wrapped, it is enough to allocate 4 bytes */
2452 buffer_store->buffer = malloc(4);
2454 buffer_store->buffer = malloc(msize * num_elements);
2455 assert(buffer_store->buffer);
2457 if (data && (!wrapper_flag))
2458 memcpy(buffer_store->buffer, data, size * num_elements);
2461 buffer_store->num_elements = obj_buffer->num_elements;
2462 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
2463 i965_release_buffer_store(&buffer_store);
2466 return VA_STATUS_SUCCESS;
2470 i965_CreateBuffer(VADriverContextP ctx,
2471 VAContextID context, /* in */
2472 VABufferType type, /* in */
2473 unsigned int size, /* in */
2474 unsigned int num_elements, /* in */
2475 void *data, /* in */
2476 VABufferID *buf_id) /* out */
2478 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
2483 i965_BufferSetNumElements(VADriverContextP ctx,
2484 VABufferID buf_id, /* in */
2485 unsigned int num_elements) /* in */
2487 struct i965_driver_data *i965 = i965_driver_data(ctx);
2488 struct object_buffer *obj_buffer = BUFFER(buf_id);
2489 VAStatus vaStatus = VA_STATUS_SUCCESS;
2491 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2493 /* When the wrapper_buffer exists, it will wrapper to the
2494 * buffer allocated from backend driver.
2496 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2497 i965->wrapper_pdrvctx) {
2498 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2500 CALL_VTABLE(pdrvctx, vaStatus,
2501 vaBufferSetNumElements(pdrvctx, obj_buffer->wrapper_buffer,
2506 if ((num_elements < 0) ||
2507 (num_elements > obj_buffer->max_num_elements)) {
2508 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
2510 obj_buffer->num_elements = num_elements;
2511 if (obj_buffer->buffer_store != NULL) {
2512 obj_buffer->buffer_store->num_elements = num_elements;
2520 i965_MapBuffer(VADriverContextP ctx,
2521 VABufferID buf_id, /* in */
2522 void **pbuf) /* out */
2524 struct i965_driver_data *i965 = i965_driver_data(ctx);
2525 struct object_buffer *obj_buffer = BUFFER(buf_id);
2526 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2527 struct object_context *obj_context;
2529 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2531 obj_context = CONTEXT(obj_buffer->context_id);
2533 /* When the wrapper_buffer exists, it will wrapper to the
2534 * buffer allocated from backend driver.
2536 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2537 i965->wrapper_pdrvctx) {
2538 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2540 CALL_VTABLE(pdrvctx, vaStatus,
2541 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer, pbuf));
2545 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2546 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
2548 if (obj_buffer->export_refcount > 0)
2549 return VA_STATUS_ERROR_INVALID_BUFFER;
2551 if (NULL != obj_buffer->buffer_store->bo) {
2552 unsigned int tiling, swizzle;
2554 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2556 if (tiling != I915_TILING_NONE)
2557 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
2559 dri_bo_map(obj_buffer->buffer_store->bo, 1);
2561 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
2562 *pbuf = obj_buffer->buffer_store->bo->virtual;
2563 vaStatus = VA_STATUS_SUCCESS;
2565 if (obj_buffer->type == VAEncCodedBufferType) {
2567 unsigned char *buffer = NULL;
2568 unsigned int header_offset = I965_CODEDBUFFER_HEADER_SIZE;
2569 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
2571 if (!coded_buffer_segment->mapped) {
2572 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
2574 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
2577 obj_context->hw_context &&
2578 obj_context->hw_context->get_status &&
2579 coded_buffer_segment->status_support) {
2580 vaStatus = obj_context->hw_context->get_status(ctx, obj_context->hw_context, coded_buffer_segment);
2582 if (coded_buffer_segment->codec == CODEC_H264 ||
2583 coded_buffer_segment->codec == CODEC_H264_MVC) {
2584 delimiter0 = H264_DELIMITER0;
2585 delimiter1 = H264_DELIMITER1;
2586 delimiter2 = H264_DELIMITER2;
2587 delimiter3 = H264_DELIMITER3;
2588 delimiter4 = H264_DELIMITER4;
2589 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
2590 delimiter0 = MPEG2_DELIMITER0;
2591 delimiter1 = MPEG2_DELIMITER1;
2592 delimiter2 = MPEG2_DELIMITER2;
2593 delimiter3 = MPEG2_DELIMITER3;
2594 delimiter4 = MPEG2_DELIMITER4;
2595 } else if(coded_buffer_segment->codec == CODEC_JPEG) {
2596 //In JPEG End of Image (EOI = 0xDDF9) marker can be used for delimiter.
2599 } else if (coded_buffer_segment->codec == CODEC_HEVC) {
2600 delimiter0 = HEVC_DELIMITER0;
2601 delimiter1 = HEVC_DELIMITER1;
2602 delimiter2 = HEVC_DELIMITER2;
2603 delimiter3 = HEVC_DELIMITER3;
2604 delimiter4 = HEVC_DELIMITER4;
2605 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2606 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2609 if(coded_buffer_segment->codec == CODEC_JPEG) {
2610 for(i = 0; i < obj_buffer->size_element - header_offset - 1 - 0x1000; i++) {
2611 if( (buffer[i] == 0xFF) && (buffer[i + 1] == 0xD9)) {
2615 coded_buffer_segment->base.size = i + 2;
2616 } else if (coded_buffer_segment->codec != CODEC_VP8) {
2617 /* vp8 coded buffer size can be told by vp8 internal statistics buffer,
2618 so it don't need to traversal the coded buffer */
2619 for (i = 0; i < obj_buffer->size_element - header_offset - 3 - 0x1000; i++) {
2620 if ((buffer[i] == delimiter0) &&
2621 (buffer[i + 1] == delimiter1) &&
2622 (buffer[i + 2] == delimiter2) &&
2623 (buffer[i + 3] == delimiter3) &&
2624 (buffer[i + 4] == delimiter4))
2628 if (i == obj_buffer->size_element - header_offset - 3 - 0x1000) {
2629 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2631 coded_buffer_segment->base.size = i;
2634 if (coded_buffer_segment->base.size >= obj_buffer->size_element - header_offset - 0x1000) {
2635 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
2638 vaStatus = VA_STATUS_SUCCESS;
2641 coded_buffer_segment->mapped = 1;
2643 assert(coded_buffer_segment->base.buf);
2644 vaStatus = VA_STATUS_SUCCESS;
2647 } else if (NULL != obj_buffer->buffer_store->buffer) {
2648 *pbuf = obj_buffer->buffer_store->buffer;
2649 vaStatus = VA_STATUS_SUCCESS;
2656 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2658 struct i965_driver_data *i965 = i965_driver_data(ctx);
2659 struct object_buffer *obj_buffer = BUFFER(buf_id);
2660 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2662 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2663 return VA_STATUS_ERROR_INVALID_BUFFER;
2665 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2666 /* When the wrapper_buffer exists, it will wrapper to the
2667 * buffer allocated from backend driver.
2669 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2670 i965->wrapper_pdrvctx) {
2671 VADriverContextP pdrvctx = i965->wrapper_pdrvctx;
2673 CALL_VTABLE(pdrvctx, vaStatus,
2674 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2678 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2679 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2681 if (NULL != obj_buffer->buffer_store->bo) {
2682 unsigned int tiling, swizzle;
2684 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2686 if (tiling != I915_TILING_NONE)
2687 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2689 dri_bo_unmap(obj_buffer->buffer_store->bo);
2691 vaStatus = VA_STATUS_SUCCESS;
2692 } else if (NULL != obj_buffer->buffer_store->buffer) {
2694 vaStatus = VA_STATUS_SUCCESS;
2701 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2703 struct i965_driver_data *i965 = i965_driver_data(ctx);
2704 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2705 VAStatus va_status = VA_STATUS_SUCCESS;
2707 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2709 if ((obj_buffer->wrapper_buffer != VA_INVALID_ID) &&
2710 i965->wrapper_pdrvctx) {
2711 CALL_VTABLE(i965->wrapper_pdrvctx, va_status,
2712 vaDestroyBuffer(i965->wrapper_pdrvctx,
2713 obj_buffer->wrapper_buffer));
2714 obj_buffer->wrapper_buffer = VA_INVALID_ID;
2717 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2723 i965_BeginPicture(VADriverContextP ctx,
2724 VAContextID context,
2725 VASurfaceID render_target)
2727 struct i965_driver_data *i965 = i965_driver_data(ctx);
2728 struct object_context *obj_context = CONTEXT(context);
2729 struct object_surface *obj_surface = SURFACE(render_target);
2730 struct object_config *obj_config;
2731 VAStatus vaStatus = VA_STATUS_SUCCESS;
2734 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2735 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2736 obj_config = obj_context->obj_config;
2737 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2739 if (is_surface_busy(i965, obj_surface))
2740 return VA_STATUS_ERROR_SURFACE_BUSY;
2742 if (obj_context->codec_type == CODEC_PROC) {
2743 obj_context->codec_state.proc.current_render_target = render_target;
2744 } else if (obj_context->codec_type == CODEC_ENC) {
2746 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2748 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2749 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2751 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2752 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2754 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2755 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2757 obj_context->codec_state.encode.num_slice_params_ext = 0;
2758 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2759 obj_context->codec_state.encode.last_packed_header_type = 0;
2760 memset(obj_context->codec_state.encode.slice_rawdata_index, 0,
2761 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2762 memset(obj_context->codec_state.encode.slice_rawdata_count, 0,
2763 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2764 memset(obj_context->codec_state.encode.slice_header_index, 0,
2765 sizeof(int) * obj_context->codec_state.encode.max_slice_num);
2767 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_params_ext; i++)
2768 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_params_ext[i]);
2769 for (i = 0; i < obj_context->codec_state.encode.num_packed_header_data_ext; i++)
2770 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data_ext[i]);
2771 obj_context->codec_state.encode.num_packed_header_params_ext = 0;
2772 obj_context->codec_state.encode.num_packed_header_data_ext = 0;
2773 obj_context->codec_state.encode.slice_index = 0;
2774 obj_context->codec_state.encode.vps_sps_seq_index = 0;
2776 * Based on ROI definition in va/va.h, the ROI set through this
2777 * structure is applicable only to the current frame or field.
2778 * That is to say: it is on-the-fly setting. If it is not set,
2779 * the current frame doesn't use ROI.
2780 * It is uncertain whether the other misc buffer should be released.
2781 * So only release the previous ROI buffer.
2783 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[VAEncMiscParameterTypeROI][0]);
2785 i965_release_buffer_store(&obj_context->codec_state.encode.encmb_map);
2787 if (obj_config->profile == VAProfileVP9Profile0) {
2788 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
2789 for (j = 0; j < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param[0]); j++)
2790 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i][j]);
2792 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
2795 obj_context->codec_state.decode.current_render_target = render_target;
2796 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2797 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2798 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2799 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2801 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2802 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2803 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2806 obj_context->codec_state.decode.num_slice_params = 0;
2807 obj_context->codec_state.decode.num_slice_datas = 0;
2809 if ((obj_context->wrapper_context != VA_INVALID_ID) &&
2810 i965->wrapper_pdrvctx) {
2811 if (obj_surface->wrapper_surface == VA_INVALID_ID)
2812 vaStatus = i965_surface_wrapper(ctx, render_target);
2814 if (vaStatus != VA_STATUS_SUCCESS)
2817 CALL_VTABLE(i965->wrapper_pdrvctx, vaStatus,
2818 vaBeginPicture(i965->wrapper_pdrvctx,
2819 obj_context->wrapper_context,
2820 obj_surface->wrapper_surface));
2827 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2829 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2831 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2832 struct object_context *obj_context, \
2833 struct object_buffer *obj_buffer) \
2835 struct category##_state *category = &obj_context->codec_state.category; \
2836 i965_release_buffer_store(&category->member); \
2837 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2838 return VA_STATUS_SUCCESS; \
2841 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2843 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2844 struct object_context *obj_context, \
2845 struct object_buffer *obj_buffer) \
2847 struct category##_state *category = &obj_context->codec_state.category; \
2848 if (category->num_##member == category->max_##member) { \
2849 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2850 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2851 category->max_##member += NUM_SLICES; \
2853 i965_release_buffer_store(&category->member[category->num_##member]); \
2854 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2855 category->num_##member++; \
2856 return VA_STATUS_SUCCESS; \
2859 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2861 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2862 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2863 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2864 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2865 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2866 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2868 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2869 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2870 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2874 i965_decoder_vp9_wrapper_picture(VADriverContextP ctx,
2875 VABufferID *buffers,
2878 struct i965_driver_data *i965 = i965_driver_data(ctx);
2879 VAStatus vaStatus = VA_STATUS_SUCCESS;
2881 VADecPictureParameterBufferVP9 *pVp9PicParams;
2882 VADriverContextP pdrvctx;
2883 struct object_buffer *obj_buffer;
2885 pdrvctx = i965->wrapper_pdrvctx;
2886 /* do the conversion of VADecPictureParameterBufferVP9 */
2887 for (i = 0; i < num_buffers; i++) {
2888 obj_buffer = BUFFER(buffers[i]);
2893 if (obj_buffer->wrapper_buffer == VA_INVALID_ID)
2896 if (obj_buffer->type == VAPictureParameterBufferType) {
2898 VASurfaceID surface_id;
2899 struct object_surface *obj_surface;
2901 pdrvctx = i965->wrapper_pdrvctx;
2903 CALL_VTABLE(pdrvctx, vaStatus,
2904 vaMapBuffer(pdrvctx, obj_buffer->wrapper_buffer,
2905 (void **)(&pVp9PicParams)));
2907 if (vaStatus != VA_STATUS_SUCCESS)
2910 for (j = 0; j < 8; j++) {
2911 surface_id = pVp9PicParams->reference_frames[j];
2912 obj_surface = SURFACE(surface_id);
2917 if (obj_surface->wrapper_surface == VA_INVALID_ID) {
2918 vaStatus = i965_surface_wrapper(ctx, surface_id);
2919 if (vaStatus != VA_STATUS_SUCCESS) {
2920 pdrvctx->vtable->vaUnmapBuffer(pdrvctx,
2921 obj_buffer->wrapper_buffer);
2926 pVp9PicParams->reference_frames[j] = obj_surface->wrapper_surface;
2928 CALL_VTABLE(pdrvctx, vaStatus,
2929 vaUnmapBuffer(pdrvctx, obj_buffer->wrapper_buffer));
2934 return VA_STATUS_SUCCESS;
2941 i965_decoder_wrapper_picture(VADriverContextP ctx,
2942 VAContextID context,
2943 VABufferID *buffers,
2946 struct i965_driver_data *i965 = i965_driver_data(ctx);
2947 struct object_context *obj_context = CONTEXT(context);
2948 VAStatus vaStatus = VA_STATUS_SUCCESS;
2950 VADriverContextP pdrvctx;
2951 struct object_buffer *obj_buffer;
2953 if (obj_context == NULL)
2954 return VA_STATUS_ERROR_INVALID_CONTEXT;
2956 /* When it is not wrapped context, continue the normal flowchart */
2957 if (obj_context->wrapper_context == VA_INVALID_ID)
2960 if (obj_context->obj_config &&
2961 (obj_context->obj_config->profile == VAProfileVP9Profile0)) {
2962 vaStatus = i965_decoder_vp9_wrapper_picture(ctx, buffers, num_buffers);
2964 return VA_STATUS_ERROR_INVALID_PARAMETER;
2966 pdrvctx = i965->wrapper_pdrvctx;
2968 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2969 obj_buffer = BUFFER(buffers[i]);
2974 if (obj_buffer->wrapper_buffer == VA_INVALID_ID) {
2975 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
2979 CALL_VTABLE(pdrvctx, vaStatus,
2980 vaRenderPicture(pdrvctx, obj_context->wrapper_context,
2981 &(obj_buffer->wrapper_buffer), 1));
2987 i965_decoder_render_picture(VADriverContextP ctx,
2988 VAContextID context,
2989 VABufferID *buffers,
2992 struct i965_driver_data *i965 = i965_driver_data(ctx);
2993 struct object_context *obj_context = CONTEXT(context);
2994 VAStatus vaStatus = VA_STATUS_SUCCESS;
2997 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2999 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3000 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3003 return VA_STATUS_ERROR_INVALID_BUFFER;
3005 switch (obj_buffer->type) {
3006 case VAPictureParameterBufferType:
3007 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
3010 case VAIQMatrixBufferType:
3011 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
3014 case VABitPlaneBufferType:
3015 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
3018 case VASliceParameterBufferType:
3019 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
3022 case VASliceDataBufferType:
3023 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
3026 case VAHuffmanTableBufferType:
3027 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
3030 case VAProbabilityBufferType:
3031 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
3035 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3040 if ((vaStatus == VA_STATUS_SUCCESS) &&
3041 (obj_context->wrapper_context != VA_INVALID_ID))
3042 vaStatus = i965_decoder_wrapper_picture(ctx, context, buffers, num_buffers);
3047 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
3049 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
3050 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
3051 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
3052 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
3053 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
3054 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
3055 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
3056 /* extended buffer */
3057 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
3058 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
3059 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(encmb_map, encmb_map)
3061 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
3062 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
3063 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
3065 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_params_ext, packed_header_params_ext)
3066 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(packed_header_data_ext, packed_header_data_ext)
3069 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
3070 struct object_context *obj_context,
3071 struct object_buffer *obj_buffer,
3074 struct encode_state *encode = &obj_context->codec_state.encode;
3076 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3077 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3078 i965_release_buffer_store(&encode->packed_header_param[type_index]);
3079 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
3081 return VA_STATUS_SUCCESS;
3085 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
3086 struct object_context *obj_context,
3087 struct object_buffer *obj_buffer,
3090 struct encode_state *encode = &obj_context->codec_state.encode;
3092 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3093 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3094 i965_release_buffer_store(&encode->packed_header_data[type_index]);
3095 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
3097 return VA_STATUS_SUCCESS;
3101 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
3102 struct object_context *obj_context,
3103 struct object_buffer *obj_buffer)
3105 struct encode_state *encode = &obj_context->codec_state.encode;
3106 VAEncMiscParameterBuffer *param = NULL;
3108 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
3109 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
3111 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
3113 if (param->type >= ARRAY_ELEMS(encode->misc_param))
3114 return VA_STATUS_ERROR_INVALID_PARAMETER;
3116 i965_release_buffer_store(&encode->misc_param[param->type][0]);
3117 i965_reference_buffer_store(&encode->misc_param[param->type][0], obj_buffer->buffer_store);
3119 return VA_STATUS_SUCCESS;
3123 i965_encoder_render_picture(VADriverContextP ctx,
3124 VAContextID context,
3125 VABufferID *buffers,
3128 struct i965_driver_data *i965 = i965_driver_data(ctx);
3129 struct object_context *obj_context = CONTEXT(context);
3130 struct object_config *obj_config;
3131 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3132 struct encode_state *encode;
3135 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3136 obj_config = obj_context->obj_config;
3137 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3139 encode = &obj_context->codec_state.encode;
3140 for (i = 0; i < num_buffers; i++) {
3141 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3144 return VA_STATUS_ERROR_INVALID_BUFFER;
3146 switch (obj_buffer->type) {
3147 case VAQMatrixBufferType:
3148 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
3151 case VAIQMatrixBufferType:
3152 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
3155 case VAEncSequenceParameterBufferType:
3156 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
3159 case VAEncPictureParameterBufferType:
3160 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
3163 case VAHuffmanTableBufferType:
3164 vaStatus = I965_RENDER_ENCODE_BUFFER(huffman_table);
3167 case VAEncSliceParameterBufferType:
3168 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
3169 if (vaStatus == VA_STATUS_SUCCESS) {
3170 /* When the max number of slices is updated, it also needs
3171 * to reallocate the arrays that is used to store
3172 * the packed data index/count for the slice
3174 if (!(encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE)) {
3175 encode->slice_index++;
3177 if (encode->slice_index == encode->max_slice_num) {
3178 int slice_num = encode->max_slice_num;
3179 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3180 (slice_num + NUM_SLICES) * sizeof(int));
3181 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3182 (slice_num + NUM_SLICES) * sizeof(int));
3183 encode->slice_header_index = realloc(encode->slice_header_index,
3184 (slice_num + NUM_SLICES) * sizeof(int));
3185 memset(encode->slice_rawdata_index + slice_num, 0,
3186 sizeof(int) * NUM_SLICES);
3187 memset(encode->slice_rawdata_count + slice_num, 0,
3188 sizeof(int) * NUM_SLICES);
3189 memset(encode->slice_header_index + slice_num, 0,
3190 sizeof(int) * NUM_SLICES);
3192 encode->max_slice_num += NUM_SLICES;
3193 if ((encode->slice_rawdata_index == NULL) ||
3194 (encode->slice_header_index == NULL) ||
3195 (encode->slice_rawdata_count == NULL)) {
3196 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
3203 case VAEncPackedHeaderParameterBufferType:
3205 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
3206 encode->last_packed_header_type = param->type;
3208 if ((param->type == VAEncPackedHeaderRawData) ||
3209 (param->type == VAEncPackedHeaderSlice)) {
3210 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_params_ext);
3211 } else if((obj_config->profile == VAProfileHEVCMain ||
3212 obj_config->profile == VAProfileHEVCMain10) &&
3213 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3214 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3217 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3219 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
3222 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3227 case VAEncPackedHeaderDataBufferType:
3229 if (encode->last_packed_header_type == 0) {
3230 WARN_ONCE("the packed header data is passed without type!\n");
3231 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3235 if (encode->last_packed_header_type == VAEncPackedHeaderRawData ||
3236 encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3237 vaStatus = I965_RENDER_ENCODE_BUFFER(packed_header_data_ext);
3239 if (obj_config->profile == VAProfileVP9Profile0)
3242 /* When the PACKED_SLICE_HEADER flag is passed, it will use
3243 * the packed_slice_header as the delimeter to decide how
3244 * the packed rawdata is inserted for the given slice.
3245 * Otherwise it will use the VAEncSequenceParameterBuffer
3248 if (encode->packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) {
3249 /* store the first index of the packed header data for current slice */
3250 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3251 encode->slice_rawdata_index[encode->slice_index] =
3252 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3254 encode->slice_rawdata_count[encode->slice_index]++;
3255 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3256 /* find one packed slice_header delimeter. And the following
3257 * packed data is for the next slice
3259 encode->slice_header_index[encode->slice_index] =
3260 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3261 encode->slice_index++;
3262 /* Reallocate the buffer to record the index/count of
3263 * packed_data for one slice.
3265 if (encode->slice_index == encode->max_slice_num) {
3266 int slice_num = encode->max_slice_num;
3268 encode->slice_rawdata_index = realloc(encode->slice_rawdata_index,
3269 (slice_num + NUM_SLICES) * sizeof(int));
3270 encode->slice_rawdata_count = realloc(encode->slice_rawdata_count,
3271 (slice_num + NUM_SLICES) * sizeof(int));
3272 encode->slice_header_index = realloc(encode->slice_header_index,
3273 (slice_num + NUM_SLICES) * sizeof(int));
3274 memset(encode->slice_rawdata_index + slice_num, 0,
3275 sizeof(int) * NUM_SLICES);
3276 memset(encode->slice_rawdata_count + slice_num, 0,
3277 sizeof(int) * NUM_SLICES);
3278 memset(encode->slice_header_index + slice_num, 0,
3279 sizeof(int) * NUM_SLICES);
3280 encode->max_slice_num += NUM_SLICES;
3284 if (vaStatus == VA_STATUS_SUCCESS) {
3285 /* store the first index of the packed header data for current slice */
3286 if (encode->slice_rawdata_index[encode->slice_index] == 0) {
3287 encode->slice_rawdata_index[encode->slice_index] =
3288 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3290 encode->slice_rawdata_count[encode->slice_index]++;
3291 if (encode->last_packed_header_type == VAEncPackedHeaderSlice) {
3292 if (encode->slice_header_index[encode->slice_index] == 0) {
3293 encode->slice_header_index[encode->slice_index] =
3294 SLICE_PACKED_DATA_INDEX_TYPE | (encode->num_packed_header_data_ext - 1);
3296 WARN_ONCE("Multi slice header data is passed for"
3297 " slice %d!\n", encode->slice_index);
3303 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
3304 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
3305 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
3306 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
3307 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
3308 VA_STATUS_ERROR_ENCODING_ERROR);
3310 if((obj_config->profile == VAProfileHEVCMain ||
3311 obj_config->profile == VAProfileHEVCMain10) &&
3312 (encode->last_packed_header_type == VAEncPackedHeaderSequence)) {
3314 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3317 va_enc_packed_type_to_idx(encode->last_packed_header_type) + encode->vps_sps_seq_index);
3318 encode->vps_sps_seq_index = (encode->vps_sps_seq_index + 1) % I965_SEQ_PACKED_HEADER_END;
3320 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
3323 va_enc_packed_type_to_idx(encode->last_packed_header_type));
3327 encode->last_packed_header_type = 0;
3331 case VAEncMiscParameterBufferType:
3332 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
3337 case VAEncMacroblockMapBufferType:
3338 vaStatus = I965_RENDER_ENCODE_BUFFER(encmb_map);
3342 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3350 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
3352 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
3353 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
3356 i965_proc_render_picture(VADriverContextP ctx,
3357 VAContextID context,
3358 VABufferID *buffers,
3361 struct i965_driver_data *i965 = i965_driver_data(ctx);
3362 struct object_context *obj_context = CONTEXT(context);
3363 VAStatus vaStatus = VA_STATUS_SUCCESS;
3366 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3368 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
3369 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
3372 return VA_STATUS_ERROR_INVALID_BUFFER;
3374 switch (obj_buffer->type) {
3375 case VAProcPipelineParameterBufferType:
3376 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
3380 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
3389 i965_RenderPicture(VADriverContextP ctx,
3390 VAContextID context,
3391 VABufferID *buffers,
3394 struct i965_driver_data *i965 = i965_driver_data(ctx);
3395 struct object_context *obj_context;
3396 struct object_config *obj_config;
3397 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
3399 obj_context = CONTEXT(context);
3400 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3402 if (num_buffers <= 0)
3403 return VA_STATUS_ERROR_INVALID_PARAMETER;
3405 obj_config = obj_context->obj_config;
3406 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3408 if (VAEntrypointVideoProc == obj_config->entrypoint) {
3409 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
3410 } else if ((VAEntrypointEncSlice == obj_config->entrypoint ) ||
3411 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3412 (VAEntrypointEncSliceLP == obj_config->entrypoint)) {
3413 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
3415 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
3422 i965_EndPicture(VADriverContextP ctx, VAContextID context)
3424 struct i965_driver_data *i965 = i965_driver_data(ctx);
3425 struct object_context *obj_context = CONTEXT(context);
3426 struct object_config *obj_config;
3428 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
3429 obj_config = obj_context->obj_config;
3430 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
3432 if (obj_context->codec_type == CODEC_PROC) {
3433 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3434 } else if (obj_context->codec_type == CODEC_ENC) {
3435 ASSERT_RET(((VAEntrypointEncSlice == obj_config->entrypoint) ||
3436 (VAEntrypointEncPicture == obj_config->entrypoint) ||
3437 (VAEntrypointEncSliceLP == obj_config->entrypoint)),
3438 VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
3440 if (obj_context->codec_state.encode.num_packed_header_params_ext !=
3441 obj_context->codec_state.encode.num_packed_header_data_ext) {
3442 WARN_ONCE("the packed header/data is not paired for encoding!\n");
3443 return VA_STATUS_ERROR_INVALID_PARAMETER;
3445 if (!obj_context->codec_state.encode.pic_param_ext) {
3446 return VA_STATUS_ERROR_INVALID_PARAMETER;
3448 if (!obj_context->codec_state.encode.seq_param_ext &&
3449 (VAEntrypointEncPicture != obj_config->entrypoint)) {
3450 /* The seq_param is not mandatory for VP9 encoding */
3451 if (obj_config->profile != VAProfileVP9Profile0)
3452 return VA_STATUS_ERROR_INVALID_PARAMETER;
3454 if ((obj_context->codec_state.encode.num_slice_params_ext <=0) &&
3455 ((obj_config->profile != VAProfileVP8Version0_3) &&
3456 (obj_config->profile != VAProfileVP9Profile0))) {
3457 return VA_STATUS_ERROR_INVALID_PARAMETER;
3460 if ((obj_context->codec_state.encode.packed_header_flag & VA_ENC_PACKED_HEADER_SLICE) &&
3461 (obj_context->codec_state.encode.num_slice_params_ext !=
3462 obj_context->codec_state.encode.slice_index)) {
3463 WARN_ONCE("packed slice_header data is missing for some slice"
3464 " under packed SLICE_HEADER mode\n");
3465 return VA_STATUS_ERROR_INVALID_PARAMETER;
3468 if (obj_context->codec_state.decode.pic_param == NULL) {
3469 return VA_STATUS_ERROR_INVALID_PARAMETER;
3471 if (obj_context->codec_state.decode.num_slice_params <=0) {
3472 return VA_STATUS_ERROR_INVALID_PARAMETER;
3474 if (obj_context->codec_state.decode.num_slice_datas <=0) {
3475 return VA_STATUS_ERROR_INVALID_PARAMETER;
3478 if (obj_context->codec_state.decode.num_slice_params !=
3479 obj_context->codec_state.decode.num_slice_datas) {
3480 return VA_STATUS_ERROR_INVALID_PARAMETER;
3483 if (obj_context->wrapper_context != VA_INVALID_ID) {
3484 /* call the vaEndPicture of wrapped driver */
3485 VADriverContextP pdrvctx;
3488 pdrvctx = i965->wrapper_pdrvctx;
3489 CALL_VTABLE(pdrvctx, va_status,
3490 vaEndPicture(pdrvctx, obj_context->wrapper_context));
3496 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
3497 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
3501 i965_SyncSurface(VADriverContextP ctx,
3502 VASurfaceID render_target)
3504 struct i965_driver_data *i965 = i965_driver_data(ctx);
3505 struct object_surface *obj_surface = SURFACE(render_target);
3507 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3510 drm_intel_bo_wait_rendering(obj_surface->bo);
3512 return VA_STATUS_SUCCESS;
3516 i965_QuerySurfaceStatus(VADriverContextP ctx,
3517 VASurfaceID render_target,
3518 VASurfaceStatus *status) /* out */
3520 struct i965_driver_data *i965 = i965_driver_data(ctx);
3521 struct object_surface *obj_surface = SURFACE(render_target);
3523 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3525 if (obj_surface->bo) {
3526 if (drm_intel_bo_busy(obj_surface->bo)){
3527 *status = VASurfaceRendering;
3530 *status = VASurfaceReady;
3533 *status = VASurfaceReady;
3536 return VA_STATUS_SUCCESS;
3539 static VADisplayAttribute *
3540 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
3542 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3545 if (!i965->display_attributes)
3548 for (i = 0; i < i965->num_display_attributes; i++) {
3549 if (i965->display_attributes[i].type == type)
3550 return &i965->display_attributes[i];
3556 i965_display_attributes_terminate(VADriverContextP ctx)
3558 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3560 if (i965->display_attributes) {
3561 free(i965->display_attributes);
3562 i965->display_attributes = NULL;
3563 i965->num_display_attributes = 0;
3568 i965_display_attributes_init(VADriverContextP ctx)
3570 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3572 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
3573 i965->display_attributes = malloc(
3574 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
3575 if (!i965->display_attributes)
3579 i965->display_attributes,
3580 i965_display_attributes,
3581 sizeof(i965_display_attributes)
3584 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
3585 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
3586 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
3587 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
3588 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
3590 if (!i965->rotation_attrib ||
3591 !i965->brightness_attrib ||
3592 !i965->contrast_attrib ||
3593 !i965->hue_attrib ||
3594 !i965->saturation_attrib) {
3600 i965_display_attributes_terminate(ctx);
3605 * Query display attributes
3606 * The caller must provide a "attr_list" array that can hold at
3607 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3608 * returned in "attr_list" is returned in "num_attributes".
3611 i965_QueryDisplayAttributes(
3612 VADriverContextP ctx,
3613 VADisplayAttribute *attribs, /* out */
3614 int *num_attribs_ptr /* out */
3617 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
3619 if (attribs && num_attribs > 0)
3620 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
3622 if (num_attribs_ptr)
3623 *num_attribs_ptr = num_attribs;
3625 return VA_STATUS_SUCCESS;
3629 * Get display attributes
3630 * This function returns the current attribute values in "attr_list".
3631 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3632 * from vaQueryDisplayAttributes() can have their values retrieved.
3635 i965_GetDisplayAttributes(
3636 VADriverContextP ctx,
3637 VADisplayAttribute *attribs, /* inout */
3638 int num_attribs /* in */
3643 for (i = 0; i < num_attribs; i++) {
3644 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
3646 src_attrib = get_display_attribute(ctx, dst_attrib->type);
3647 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
3648 dst_attrib->min_value = src_attrib->min_value;
3649 dst_attrib->max_value = src_attrib->max_value;
3650 dst_attrib->value = src_attrib->value;
3653 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
3655 return VA_STATUS_SUCCESS;
3659 * Set display attributes
3660 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3661 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
3662 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3665 i965_SetDisplayAttributes(
3666 VADriverContextP ctx,
3667 VADisplayAttribute *attribs, /* in */
3668 int num_attribs /* in */
3673 for (i = 0; i < num_attribs; i++) {
3674 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
3676 dst_attrib = get_display_attribute(ctx, src_attrib->type);
3678 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
3680 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
3683 if (src_attrib->value < dst_attrib->min_value ||
3684 src_attrib->value > dst_attrib->max_value)
3685 return VA_STATUS_ERROR_INVALID_PARAMETER;
3687 dst_attrib->value = src_attrib->value;
3688 /* XXX: track modified attributes through timestamps */
3690 return VA_STATUS_SUCCESS;
3694 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
3695 VASurfaceID surface,
3696 void **buffer, /* out */
3697 unsigned int *stride) /* out */
3700 return VA_STATUS_ERROR_UNIMPLEMENTED;
3704 i965_destroy_heap(struct object_heap *heap,
3705 void (*func)(struct object_heap *heap, struct object_base *object))
3707 struct object_base *object;
3708 object_heap_iterator iter;
3710 object = object_heap_first(heap, &iter);
3716 object = object_heap_next(heap, &iter);
3719 object_heap_destroy(heap);
3724 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
3727 i965_CreateImage(VADriverContextP ctx,
3728 VAImageFormat *format,
3731 VAImage *out_image) /* out */
3733 struct i965_driver_data *i965 = i965_driver_data(ctx);
3734 struct object_image *obj_image;
3735 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3737 unsigned int size2, size, awidth, aheight;
3739 out_image->image_id = VA_INVALID_ID;
3740 out_image->buf = VA_INVALID_ID;
3742 image_id = NEW_IMAGE_ID();
3743 if (image_id == VA_INVALID_ID)
3744 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3746 obj_image = IMAGE(image_id);
3748 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3749 obj_image->bo = NULL;
3750 obj_image->palette = NULL;
3751 obj_image->derived_surface = VA_INVALID_ID;
3753 VAImage * const image = &obj_image->image;
3754 image->image_id = image_id;
3755 image->buf = VA_INVALID_ID;
3757 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
3759 if ((format->fourcc == VA_FOURCC_YV12) ||
3760 (format->fourcc == VA_FOURCC_I420)) {
3761 if (awidth % 128 != 0) {
3762 awidth = ALIGN(width, 128);
3766 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
3767 size = awidth * aheight;
3768 size2 = (awidth / 2) * (aheight / 2);
3770 image->num_palette_entries = 0;
3771 image->entry_bytes = 0;
3772 memset(image->component_order, 0, sizeof(image->component_order));
3774 switch (format->fourcc) {
3775 case VA_FOURCC_IA44:
3776 case VA_FOURCC_AI44:
3777 image->num_planes = 1;
3778 image->pitches[0] = awidth;
3779 image->offsets[0] = 0;
3780 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3781 image->num_palette_entries = 16;
3782 image->entry_bytes = 3;
3783 image->component_order[0] = 'R';
3784 image->component_order[1] = 'G';
3785 image->component_order[2] = 'B';
3787 case VA_FOURCC_IA88:
3788 case VA_FOURCC_AI88:
3789 image->num_planes = 1;
3790 image->pitches[0] = awidth * 2;
3791 image->offsets[0] = 0;
3792 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3793 image->num_palette_entries = 256;
3794 image->entry_bytes = 3;
3795 image->component_order[0] = 'R';
3796 image->component_order[1] = 'G';
3797 image->component_order[2] = 'B';
3799 case VA_FOURCC_ARGB:
3800 case VA_FOURCC_ABGR:
3801 case VA_FOURCC_BGRA:
3802 case VA_FOURCC_RGBA:
3803 case VA_FOURCC_BGRX:
3804 case VA_FOURCC_RGBX:
3805 image->num_planes = 1;
3806 image->pitches[0] = awidth * 4;
3807 image->offsets[0] = 0;
3808 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
3810 case VA_FOURCC_YV12:
3811 image->num_planes = 3;
3812 image->pitches[0] = awidth;
3813 image->offsets[0] = 0;
3814 image->pitches[1] = awidth / 2;
3815 image->offsets[1] = size;
3816 image->pitches[2] = awidth / 2;
3817 image->offsets[2] = size + size2;
3818 image->data_size = size + 2 * size2;
3820 case VA_FOURCC_I420:
3821 image->num_planes = 3;
3822 image->pitches[0] = awidth;
3823 image->offsets[0] = 0;
3824 image->pitches[1] = awidth / 2;
3825 image->offsets[1] = size;
3826 image->pitches[2] = awidth / 2;
3827 image->offsets[2] = size + size2;
3828 image->data_size = size + 2 * size2;
3830 case VA_FOURCC_422H:
3831 image->num_planes = 3;
3832 image->pitches[0] = awidth;
3833 image->offsets[0] = 0;
3834 image->pitches[1] = awidth / 2;
3835 image->offsets[1] = size;
3836 image->pitches[2] = awidth / 2;
3837 image->offsets[2] = size + (awidth / 2) * aheight;
3838 image->data_size = size + 2 * ((awidth / 2) * aheight);
3840 case VA_FOURCC_NV12:
3841 image->num_planes = 2;
3842 image->pitches[0] = awidth;
3843 image->offsets[0] = 0;
3844 image->pitches[1] = awidth;
3845 image->offsets[1] = size;
3846 image->data_size = size + 2 * size2;
3848 case VA_FOURCC_YUY2:
3849 case VA_FOURCC_UYVY:
3850 image->num_planes = 1;
3851 image->pitches[0] = awidth * 2;
3852 image->offsets[0] = 0;
3853 image->data_size = size * 2;
3855 case VA_FOURCC_P010:
3856 image->num_planes = 2;
3857 image->pitches[0] = awidth * 2;
3858 image->offsets[0] = 0;
3859 image->pitches[1] = awidth * 2;
3860 image->offsets[1] = size * 2;
3861 image->data_size = size * 2 + 2 * size2 * 2;
3867 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
3868 image->data_size, 1, NULL, &image->buf);
3869 if (va_status != VA_STATUS_SUCCESS)
3872 struct object_buffer *obj_buffer = BUFFER(image->buf);
3875 !obj_buffer->buffer_store ||
3876 !obj_buffer->buffer_store->bo)
3877 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3879 obj_image->bo = obj_buffer->buffer_store->bo;
3880 dri_bo_reference(obj_image->bo);
3882 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3883 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3884 if (!obj_image->palette)
3888 image->image_id = image_id;
3889 image->format = *format;
3890 image->width = width;
3891 image->height = height;
3893 *out_image = *image;
3894 return VA_STATUS_SUCCESS;
3897 i965_DestroyImage(ctx, image_id);
3902 i965_check_alloc_surface_bo(VADriverContextP ctx,
3903 struct object_surface *obj_surface,
3905 unsigned int fourcc,
3906 unsigned int subsampling)
3908 struct i965_driver_data *i965 = i965_driver_data(ctx);
3909 int region_width, region_height;
3911 if (obj_surface->bo) {
3912 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3913 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3914 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
3915 return VA_STATUS_SUCCESS;
3918 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
3919 obj_surface->x_cr_offset = 0;
3921 int bpp_1stplane = bpp_1stplane_by_fourcc(fourcc);
3923 if ((tiled && !obj_surface->user_disable_tiling)) {
3924 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
3925 fourcc != VA_FOURCC_IYUV &&
3926 fourcc != VA_FOURCC_YV12,
3927 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3929 if (obj_surface->user_h_stride_set) {
3930 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
3932 obj_surface->width = ALIGN(obj_surface->orig_width * bpp_1stplane, 128);
3934 if (obj_surface->user_v_stride_set) {
3935 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
3937 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
3939 region_height = obj_surface->height;
3942 case VA_FOURCC_NV12:
3943 case VA_FOURCC_P010:
3944 assert(subsampling == SUBSAMPLE_YUV420);
3945 obj_surface->cb_cr_pitch = obj_surface->width;
3946 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3947 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3948 obj_surface->y_cb_offset = obj_surface->height;
3949 obj_surface->y_cr_offset = obj_surface->height;
3950 region_width = obj_surface->width;
3951 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
3955 case VA_FOURCC_IMC1:
3956 assert(subsampling == SUBSAMPLE_YUV420);
3957 obj_surface->cb_cr_pitch = obj_surface->width;
3958 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3959 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3960 obj_surface->y_cr_offset = obj_surface->height;
3961 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
3962 region_width = obj_surface->width;
3963 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3967 case VA_FOURCC_IMC3:
3968 assert(subsampling == SUBSAMPLE_YUV420);
3969 obj_surface->cb_cr_pitch = obj_surface->width;
3970 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3971 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3972 obj_surface->y_cb_offset = obj_surface->height;
3973 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3974 region_width = obj_surface->width;
3975 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3979 case VA_FOURCC_422H:
3980 assert(subsampling == SUBSAMPLE_YUV422H);
3981 obj_surface->cb_cr_pitch = obj_surface->width;
3982 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3983 obj_surface->cb_cr_height = obj_surface->orig_height;
3984 obj_surface->y_cb_offset = obj_surface->height;
3985 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3986 region_width = obj_surface->width;
3987 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3991 case VA_FOURCC_422V:
3992 assert(subsampling == SUBSAMPLE_YUV422V);
3993 obj_surface->cb_cr_pitch = obj_surface->width;
3994 obj_surface->cb_cr_width = obj_surface->orig_width;
3995 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3996 obj_surface->y_cb_offset = obj_surface->height;
3997 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3998 region_width = obj_surface->width;
3999 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4003 case VA_FOURCC_411P:
4004 assert(subsampling == SUBSAMPLE_YUV411);
4005 obj_surface->cb_cr_pitch = obj_surface->width;
4006 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
4007 obj_surface->cb_cr_height = obj_surface->orig_height;
4008 obj_surface->y_cb_offset = obj_surface->height;
4009 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4010 region_width = obj_surface->width;
4011 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4015 case VA_FOURCC_444P:
4016 assert(subsampling == SUBSAMPLE_YUV444);
4017 obj_surface->cb_cr_pitch = obj_surface->width;
4018 obj_surface->cb_cr_width = obj_surface->orig_width;
4019 obj_surface->cb_cr_height = obj_surface->orig_height;
4020 obj_surface->y_cb_offset = obj_surface->height;
4021 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
4022 region_width = obj_surface->width;
4023 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
4027 case VA_FOURCC_Y800:
4028 assert(subsampling == SUBSAMPLE_YUV400);
4029 obj_surface->cb_cr_pitch = 0;
4030 obj_surface->cb_cr_width = 0;
4031 obj_surface->cb_cr_height = 0;
4032 obj_surface->y_cb_offset = 0;
4033 obj_surface->y_cr_offset = 0;
4034 region_width = obj_surface->width;
4035 region_height = obj_surface->height;
4039 case VA_FOURCC_YUY2:
4040 case VA_FOURCC_UYVY:
4041 assert(subsampling == SUBSAMPLE_YUV422H);
4042 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
4043 obj_surface->cb_cr_pitch = obj_surface->width;
4044 obj_surface->y_cb_offset = 0;
4045 obj_surface->y_cr_offset = 0;
4046 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4047 obj_surface->cb_cr_height = obj_surface->orig_height;
4048 region_width = obj_surface->width;
4049 region_height = obj_surface->height;
4053 case VA_FOURCC_RGBA:
4054 case VA_FOURCC_RGBX:
4055 case VA_FOURCC_BGRA:
4056 case VA_FOURCC_BGRX:
4057 assert(subsampling == SUBSAMPLE_RGBX);
4059 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
4060 region_width = obj_surface->width;
4061 region_height = obj_surface->height;
4065 /* Never get here */
4066 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4070 assert(subsampling == SUBSAMPLE_YUV420 ||
4071 subsampling == SUBSAMPLE_YUV422H ||
4072 subsampling == SUBSAMPLE_YUV422V ||
4073 subsampling == SUBSAMPLE_RGBX);
4075 region_width = obj_surface->width;
4076 region_height = obj_surface->height;
4079 case VA_FOURCC_NV12:
4080 case VA_FOURCC_P010:
4081 obj_surface->y_cb_offset = obj_surface->height;
4082 obj_surface->y_cr_offset = obj_surface->height;
4083 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4084 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4085 obj_surface->cb_cr_pitch = obj_surface->width;
4086 region_height = obj_surface->height + obj_surface->height / 2;
4089 case VA_FOURCC_YV16:
4090 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4091 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4092 obj_surface->cb_cr_height = obj_surface->orig_height;
4093 obj_surface->y_cr_offset = obj_surface->height;
4094 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
4095 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4096 region_width = obj_surface->width;
4097 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
4100 case VA_FOURCC_YV12:
4101 case VA_FOURCC_I420:
4102 if (fourcc == VA_FOURCC_YV12) {
4103 obj_surface->y_cr_offset = obj_surface->height;
4104 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
4106 obj_surface->y_cb_offset = obj_surface->height;
4107 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
4110 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4111 obj_surface->width = ALIGN(obj_surface->cb_cr_width, i965->codec_info->min_linear_wpitch) * 2;
4112 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
4113 obj_surface->cb_cr_pitch = obj_surface->width / 2;
4114 region_width = obj_surface->width;
4115 region_height = obj_surface->height + obj_surface->height / 2;
4118 case VA_FOURCC_YUY2:
4119 case VA_FOURCC_UYVY:
4120 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
4121 obj_surface->y_cb_offset = 0;
4122 obj_surface->y_cr_offset = 0;
4123 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
4124 obj_surface->cb_cr_height = obj_surface->orig_height;
4125 obj_surface->cb_cr_pitch = obj_surface->width;
4126 region_width = obj_surface->width;
4127 region_height = obj_surface->height;
4129 case VA_FOURCC_RGBA:
4130 case VA_FOURCC_RGBX:
4131 case VA_FOURCC_BGRA:
4132 case VA_FOURCC_BGRX:
4133 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
4134 region_width = obj_surface->width;
4135 region_height = obj_surface->height;
4139 /* Never get here */
4140 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
4145 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
4147 if ((tiled && !obj_surface->user_disable_tiling)) {
4148 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
4149 unsigned long pitch;
4151 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
4159 assert(tiling_mode == I915_TILING_Y);
4160 assert(pitch == obj_surface->width);
4162 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
4168 obj_surface->fourcc = fourcc;
4169 obj_surface->subsampling = subsampling;
4170 assert(obj_surface->bo);
4171 return VA_STATUS_SUCCESS;
4174 VAStatus i965_DeriveImage(VADriverContextP ctx,
4175 VASurfaceID surface,
4176 VAImage *out_image) /* out */
4178 struct i965_driver_data *i965 = i965_driver_data(ctx);
4179 struct object_image *obj_image;
4180 struct object_surface *obj_surface;
4182 unsigned int w_pitch;
4183 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4185 out_image->image_id = VA_INVALID_ID;
4186 obj_surface = SURFACE(surface);
4189 return VA_STATUS_ERROR_INVALID_SURFACE;
4191 if (!obj_surface->bo) {
4192 unsigned int is_tiled = 0;
4193 unsigned int fourcc = VA_FOURCC_YV12;
4194 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
4195 int sampling = get_sampling_from_fourcc(fourcc);
4196 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
4197 if (va_status != VA_STATUS_SUCCESS)
4201 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4203 w_pitch = obj_surface->width;
4205 image_id = NEW_IMAGE_ID();
4207 if (image_id == VA_INVALID_ID)
4208 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4210 obj_image = IMAGE(image_id);
4213 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4215 obj_image->bo = NULL;
4216 obj_image->palette = NULL;
4217 obj_image->derived_surface = VA_INVALID_ID;
4219 VAImage * const image = &obj_image->image;
4221 memset(image, 0, sizeof(*image));
4222 image->image_id = image_id;
4223 image->buf = VA_INVALID_ID;
4224 image->num_palette_entries = 0;
4225 image->entry_bytes = 0;
4226 image->width = obj_surface->orig_width;
4227 image->height = obj_surface->orig_height;
4228 image->data_size = obj_surface->size;
4230 image->format.fourcc = obj_surface->fourcc;
4231 image->format.byte_order = VA_LSB_FIRST;
4232 image->format.bits_per_pixel = get_bpp_from_fourcc(obj_surface->fourcc);
4234 if (!image->format.bits_per_pixel)
4237 switch (image->format.fourcc) {
4238 case VA_FOURCC_YV12:
4239 image->num_planes = 3;
4240 image->pitches[0] = w_pitch; /* Y */
4241 image->offsets[0] = 0;
4242 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4243 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4244 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4245 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4248 case VA_FOURCC_YV16:
4249 image->num_planes = 3;
4250 image->pitches[0] = w_pitch; /* Y */
4251 image->offsets[0] = 0;
4252 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
4253 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
4254 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
4255 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
4258 case VA_FOURCC_NV12:
4259 case VA_FOURCC_P010:
4260 image->num_planes = 2;
4261 image->pitches[0] = w_pitch; /* Y */
4262 image->offsets[0] = 0;
4263 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
4264 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4267 case VA_FOURCC_I420:
4268 case VA_FOURCC_422H:
4269 case VA_FOURCC_IMC3:
4270 case VA_FOURCC_444P:
4271 case VA_FOURCC_422V:
4272 case VA_FOURCC_411P:
4273 image->num_planes = 3;
4274 image->pitches[0] = w_pitch; /* Y */
4275 image->offsets[0] = 0;
4276 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
4277 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
4278 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
4279 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
4282 case VA_FOURCC_YUY2:
4283 case VA_FOURCC_UYVY:
4284 case VA_FOURCC_Y800:
4285 image->num_planes = 1;
4286 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
4287 image->offsets[0] = 0;
4289 case VA_FOURCC_RGBA:
4290 case VA_FOURCC_RGBX:
4291 case VA_FOURCC_BGRA:
4292 case VA_FOURCC_BGRX:
4293 image->num_planes = 1;
4294 image->pitches[0] = obj_surface->width;
4296 switch (image->format.fourcc) {
4297 case VA_FOURCC_RGBA:
4298 case VA_FOURCC_RGBX:
4299 image->format.red_mask = 0x000000ff;
4300 image->format.green_mask = 0x0000ff00;
4301 image->format.blue_mask = 0x00ff0000;
4303 case VA_FOURCC_BGRA:
4304 case VA_FOURCC_BGRX:
4305 image->format.red_mask = 0x00ff0000;
4306 image->format.green_mask = 0x0000ff00;
4307 image->format.blue_mask = 0x000000ff;
4313 switch (image->format.fourcc) {
4314 case VA_FOURCC_RGBA:
4315 case VA_FOURCC_BGRA:
4316 image->format.alpha_mask = 0xff000000;
4317 image->format.depth = 32;
4319 case VA_FOURCC_RGBX:
4320 case VA_FOURCC_BGRX:
4321 image->format.alpha_mask = 0x00000000;
4322 image->format.depth = 24;
4333 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
4334 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
4335 if (va_status != VA_STATUS_SUCCESS)
4338 struct object_buffer *obj_buffer = BUFFER(image->buf);
4341 !obj_buffer->buffer_store ||
4342 !obj_buffer->buffer_store->bo)
4343 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4345 obj_image->bo = obj_buffer->buffer_store->bo;
4346 dri_bo_reference(obj_image->bo);
4348 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
4349 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
4350 if (!obj_image->palette) {
4351 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
4356 *out_image = *image;
4357 obj_surface->flags |= SURFACE_DERIVED;
4358 obj_surface->derived_image_id = image_id;
4359 obj_image->derived_surface = surface;
4361 return VA_STATUS_SUCCESS;
4364 i965_DestroyImage(ctx, image_id);
4369 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
4371 object_heap_free(heap, obj);
4376 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
4378 struct i965_driver_data *i965 = i965_driver_data(ctx);
4379 struct object_image *obj_image = IMAGE(image);
4380 struct object_surface *obj_surface;
4383 return VA_STATUS_SUCCESS;
4385 dri_bo_unreference(obj_image->bo);
4386 obj_image->bo = NULL;
4388 if (obj_image->image.buf != VA_INVALID_ID) {
4389 i965_DestroyBuffer(ctx, obj_image->image.buf);
4390 obj_image->image.buf = VA_INVALID_ID;
4393 if (obj_image->palette) {
4394 free(obj_image->palette);
4395 obj_image->palette = NULL;
4398 obj_surface = SURFACE(obj_image->derived_surface);
4401 obj_surface->flags &= ~SURFACE_DERIVED;
4402 obj_surface->derived_image_id = VA_INVALID_ID;
4405 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
4407 return VA_STATUS_SUCCESS;
4411 * pointer to an array holding the palette data. The size of the array is
4412 * num_palette_entries * entry_bytes in size. The order of the components
4413 * in the palette is described by the component_order in VASubpicture struct
4416 i965_SetImagePalette(VADriverContextP ctx,
4418 unsigned char *palette)
4420 struct i965_driver_data *i965 = i965_driver_data(ctx);
4423 struct object_image *obj_image = IMAGE(image);
4425 return VA_STATUS_ERROR_INVALID_IMAGE;
4427 if (!obj_image->palette)
4428 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
4430 for (i = 0; i < obj_image->image.num_palette_entries; i++)
4431 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
4432 ((unsigned int)palette[3*i + 1] << 8) |
4433 (unsigned int)palette[3*i + 2]);
4434 return VA_STATUS_SUCCESS;
4438 get_sampling_from_fourcc(unsigned int fourcc)
4440 const i965_fourcc_info *info = get_fourcc_info(fourcc);
4442 if (info && (info->flag & I_S))
4443 return info->subsampling;
4449 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
4450 const uint8_t *src, unsigned int src_stride,
4451 unsigned int len, unsigned int height)
4455 for (i = 0; i < height; i++) {
4456 memcpy(dst, src, len);
4463 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
4464 struct object_surface *obj_surface,
4465 const VARectangle *rect)
4467 uint8_t *dst[3], *src[3];
4469 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4470 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4471 unsigned int tiling, swizzle;
4472 VAStatus va_status = VA_STATUS_SUCCESS;
4474 if (!obj_surface->bo)
4475 return VA_STATUS_ERROR_INVALID_SURFACE;
4477 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4478 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4480 if (tiling != I915_TILING_NONE)
4481 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4483 dri_bo_map(obj_surface->bo, 0);
4485 if (!obj_surface->bo->virtual)
4486 return VA_STATUS_ERROR_INVALID_SURFACE;
4488 /* Dest VA image has either I420 or YV12 format.
4489 Source VA surface alway has I420 format */
4490 dst[Y] = image_data + obj_image->image.offsets[Y];
4491 src[0] = (uint8_t *)obj_surface->bo->virtual;
4492 dst[U] = image_data + obj_image->image.offsets[U];
4493 src[1] = src[0] + obj_surface->width * obj_surface->height;
4494 dst[V] = image_data + obj_image->image.offsets[V];
4495 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4498 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
4499 src[0] += rect->y * obj_surface->width + rect->x;
4500 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
4501 src[0], obj_surface->width,
4502 rect->width, rect->height);
4505 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
4506 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4507 memcpy_pic(dst[U], obj_image->image.pitches[U],
4508 src[1], obj_surface->width / 2,
4509 rect->width / 2, rect->height / 2);
4512 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
4513 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
4514 memcpy_pic(dst[V], obj_image->image.pitches[V],
4515 src[2], obj_surface->width / 2,
4516 rect->width / 2, rect->height / 2);
4518 if (tiling != I915_TILING_NONE)
4519 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4521 dri_bo_unmap(obj_surface->bo);
4527 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
4528 struct object_surface *obj_surface,
4529 const VARectangle *rect)
4531 uint8_t *dst[2], *src[2];
4532 unsigned int tiling, swizzle;
4533 VAStatus va_status = VA_STATUS_SUCCESS;
4535 if (!obj_surface->bo)
4536 return VA_STATUS_ERROR_INVALID_SURFACE;
4538 assert(obj_surface->fourcc);
4539 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4541 if (tiling != I915_TILING_NONE)
4542 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4544 dri_bo_map(obj_surface->bo, 0);
4546 if (!obj_surface->bo->virtual)
4547 return VA_STATUS_ERROR_INVALID_SURFACE;
4549 /* Both dest VA image and source surface have NV12 format */
4550 dst[0] = image_data + obj_image->image.offsets[0];
4551 src[0] = (uint8_t *)obj_surface->bo->virtual;
4552 dst[1] = image_data + obj_image->image.offsets[1];
4553 src[1] = src[0] + obj_surface->width * obj_surface->height;
4556 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
4557 src[0] += rect->y * obj_surface->width + rect->x;
4558 memcpy_pic(dst[0], obj_image->image.pitches[0],
4559 src[0], obj_surface->width,
4560 rect->width, rect->height);
4563 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
4564 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
4565 memcpy_pic(dst[1], obj_image->image.pitches[1],
4566 src[1], obj_surface->width,
4567 rect->width, rect->height / 2);
4569 if (tiling != I915_TILING_NONE)
4570 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4572 dri_bo_unmap(obj_surface->bo);
4578 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
4579 struct object_surface *obj_surface,
4580 const VARectangle *rect)
4583 unsigned int tiling, swizzle;
4584 VAStatus va_status = VA_STATUS_SUCCESS;
4586 if (!obj_surface->bo)
4587 return VA_STATUS_ERROR_INVALID_SURFACE;
4589 assert(obj_surface->fourcc);
4590 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4592 if (tiling != I915_TILING_NONE)
4593 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4595 dri_bo_map(obj_surface->bo, 0);
4597 if (!obj_surface->bo->virtual)
4598 return VA_STATUS_ERROR_INVALID_SURFACE;
4600 /* Both dest VA image and source surface have YUYV format */
4601 dst = image_data + obj_image->image.offsets[0];
4602 src = (uint8_t *)obj_surface->bo->virtual;
4605 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
4606 src += rect->y * obj_surface->width + rect->x*2;
4607 memcpy_pic(dst, obj_image->image.pitches[0],
4608 src, obj_surface->width*2,
4609 rect->width*2, rect->height);
4611 if (tiling != I915_TILING_NONE)
4612 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4614 dri_bo_unmap(obj_surface->bo);
4620 i965_sw_getimage(VADriverContextP ctx,
4621 struct object_surface *obj_surface, struct object_image *obj_image,
4622 const VARectangle *rect)
4624 void *image_data = NULL;
4627 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4628 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4630 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4631 if (va_status != VA_STATUS_SUCCESS)
4634 switch (obj_image->image.format.fourcc) {
4635 case VA_FOURCC_YV12:
4636 case VA_FOURCC_I420:
4637 get_image_i420(obj_image, image_data, obj_surface, rect);
4639 case VA_FOURCC_NV12:
4640 get_image_nv12(obj_image, image_data, obj_surface, rect);
4642 case VA_FOURCC_YUY2:
4643 /* YUY2 is the format supported by overlay plane */
4644 get_image_yuy2(obj_image, image_data, obj_surface, rect);
4647 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4650 if (va_status != VA_STATUS_SUCCESS)
4653 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4658 i965_hw_getimage(VADriverContextP ctx,
4659 struct object_surface *obj_surface, struct object_image *obj_image,
4660 const VARectangle *rect)
4662 struct i965_surface src_surface;
4663 struct i965_surface dst_surface;
4665 src_surface.base = (struct object_base *)obj_surface;
4666 src_surface.type = I965_SURFACE_TYPE_SURFACE;
4667 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4669 dst_surface.base = (struct object_base *)obj_image;
4670 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
4671 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4673 return i965_image_processing(ctx, &src_surface, rect, &dst_surface, rect);
4677 i965_GetImage(VADriverContextP ctx,
4678 VASurfaceID surface,
4679 int x, /* coordinates of the upper left source pixel */
4681 unsigned int width, /* width and height of the region */
4682 unsigned int height,
4685 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4686 struct object_surface * const obj_surface = SURFACE(surface);
4687 struct object_image * const obj_image = IMAGE(image);
4692 return VA_STATUS_ERROR_INVALID_SURFACE;
4693 if (!obj_surface->bo) /* don't get anything, keep previous data */
4694 return VA_STATUS_SUCCESS;
4695 if (is_surface_busy(i965, obj_surface))
4696 return VA_STATUS_ERROR_SURFACE_BUSY;
4698 if (!obj_image || !obj_image->bo)
4699 return VA_STATUS_ERROR_INVALID_IMAGE;
4700 if (is_image_busy(i965, obj_image, surface))
4701 return VA_STATUS_ERROR_SURFACE_BUSY;
4704 return VA_STATUS_ERROR_INVALID_PARAMETER;
4705 if (x + width > obj_surface->orig_width ||
4706 y + height > obj_surface->orig_height)
4707 return VA_STATUS_ERROR_INVALID_PARAMETER;
4708 if (x + width > obj_image->image.width ||
4709 y + height > obj_image->image.height)
4710 return VA_STATUS_ERROR_INVALID_PARAMETER;
4715 rect.height = height;
4717 if (HAS_ACCELERATED_GETIMAGE(i965))
4718 va_status = i965_hw_getimage(ctx, obj_surface, obj_image, &rect);
4720 va_status = i965_sw_getimage(ctx, obj_surface, obj_image, &rect);
4726 put_image_i420(struct object_surface *obj_surface,
4727 const VARectangle *dst_rect,
4728 struct object_image *obj_image, uint8_t *image_data,
4729 const VARectangle *src_rect)
4731 uint8_t *dst[3], *src[3];
4733 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
4734 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
4735 unsigned int tiling, swizzle;
4736 VAStatus va_status = VA_STATUS_SUCCESS;
4738 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4740 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4741 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4742 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4743 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4745 if (tiling != I915_TILING_NONE)
4746 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4748 dri_bo_map(obj_surface->bo, 0);
4750 if (!obj_surface->bo->virtual)
4751 return VA_STATUS_ERROR_INVALID_SURFACE;
4753 /* Dest VA image has either I420 or YV12 format.
4754 Source VA surface alway has I420 format */
4755 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4756 src[Y] = image_data + obj_image->image.offsets[Y];
4757 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4758 src[U] = image_data + obj_image->image.offsets[U];
4759 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
4760 src[V] = image_data + obj_image->image.offsets[V];
4763 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4764 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
4765 memcpy_pic(dst[0], obj_surface->width,
4766 src[Y], obj_image->image.pitches[Y],
4767 src_rect->width, src_rect->height);
4770 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4771 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
4772 memcpy_pic(dst[1], obj_surface->width / 2,
4773 src[U], obj_image->image.pitches[U],
4774 src_rect->width / 2, src_rect->height / 2);
4777 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
4778 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
4779 memcpy_pic(dst[2], obj_surface->width / 2,
4780 src[V], obj_image->image.pitches[V],
4781 src_rect->width / 2, src_rect->height / 2);
4783 if (tiling != I915_TILING_NONE)
4784 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4786 dri_bo_unmap(obj_surface->bo);
4792 put_image_nv12(struct object_surface *obj_surface,
4793 const VARectangle *dst_rect,
4794 struct object_image *obj_image, uint8_t *image_data,
4795 const VARectangle *src_rect)
4797 uint8_t *dst[2], *src[2];
4798 unsigned int tiling, swizzle;
4799 VAStatus va_status = VA_STATUS_SUCCESS;
4801 if (!obj_surface->bo)
4802 return VA_STATUS_ERROR_INVALID_SURFACE;
4804 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4805 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4806 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4807 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4809 if (tiling != I915_TILING_NONE)
4810 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4812 dri_bo_map(obj_surface->bo, 0);
4814 if (!obj_surface->bo->virtual)
4815 return VA_STATUS_ERROR_INVALID_SURFACE;
4817 /* Both dest VA image and source surface have NV12 format */
4818 dst[0] = (uint8_t *)obj_surface->bo->virtual;
4819 src[0] = image_data + obj_image->image.offsets[0];
4820 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
4821 src[1] = image_data + obj_image->image.offsets[1];
4824 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
4825 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
4826 memcpy_pic(dst[0], obj_surface->width,
4827 src[0], obj_image->image.pitches[0],
4828 src_rect->width, src_rect->height);
4831 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
4832 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
4833 memcpy_pic(dst[1], obj_surface->width,
4834 src[1], obj_image->image.pitches[1],
4835 src_rect->width, src_rect->height / 2);
4837 if (tiling != I915_TILING_NONE)
4838 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4840 dri_bo_unmap(obj_surface->bo);
4846 put_image_yuy2(struct object_surface *obj_surface,
4847 const VARectangle *dst_rect,
4848 struct object_image *obj_image, uint8_t *image_data,
4849 const VARectangle *src_rect)
4852 unsigned int tiling, swizzle;
4853 VAStatus va_status = VA_STATUS_SUCCESS;
4855 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
4856 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4857 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
4858 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
4859 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
4861 if (tiling != I915_TILING_NONE)
4862 drm_intel_gem_bo_map_gtt(obj_surface->bo);
4864 dri_bo_map(obj_surface->bo, 0);
4866 if (!obj_surface->bo->virtual)
4867 return VA_STATUS_ERROR_INVALID_SURFACE;
4869 /* Both dest VA image and source surface have YUY2 format */
4870 dst = (uint8_t *)obj_surface->bo->virtual;
4871 src = image_data + obj_image->image.offsets[0];
4873 /* YUYV packed plane */
4874 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
4875 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
4876 memcpy_pic(dst, obj_surface->width*2,
4877 src, obj_image->image.pitches[0],
4878 src_rect->width*2, src_rect->height);
4880 if (tiling != I915_TILING_NONE)
4881 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
4883 dri_bo_unmap(obj_surface->bo);
4889 i965_sw_putimage(VADriverContextP ctx,
4890 struct object_surface *obj_surface, struct object_image *obj_image,
4891 const VARectangle *src_rect, const VARectangle *dst_rect)
4893 VAStatus va_status = VA_STATUS_SUCCESS;
4894 void *image_data = NULL;
4896 /* XXX: don't allow scaling */
4897 if (src_rect->width != dst_rect->width ||
4898 src_rect->height != dst_rect->height)
4899 return VA_STATUS_ERROR_INVALID_PARAMETER;
4901 if (obj_surface->fourcc) {
4902 /* Don't allow format mismatch */
4903 if (obj_surface->fourcc != obj_image->image.format.fourcc)
4904 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
4908 /* VA is surface not used for decoding, use same VA image format */
4909 va_status = i965_check_alloc_surface_bo(
4912 0, /* XXX: don't use tiled surface */
4913 obj_image->image.format.fourcc,
4914 get_sampling_from_fourcc (obj_image->image.format.fourcc));
4917 if (va_status != VA_STATUS_SUCCESS)
4920 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
4921 if (va_status != VA_STATUS_SUCCESS)
4924 switch (obj_image->image.format.fourcc) {
4925 case VA_FOURCC_YV12:
4926 case VA_FOURCC_I420:
4927 va_status = put_image_i420(obj_surface, dst_rect, obj_image, image_data, src_rect);
4929 case VA_FOURCC_NV12:
4930 va_status = put_image_nv12(obj_surface, dst_rect, obj_image, image_data, src_rect);
4932 case VA_FOURCC_YUY2:
4933 va_status = put_image_yuy2(obj_surface, dst_rect, obj_image, image_data, src_rect);
4936 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
4939 if (va_status != VA_STATUS_SUCCESS)
4942 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4947 i965_hw_putimage(VADriverContextP ctx,
4948 struct object_surface *obj_surface, struct object_image *obj_image,
4949 const VARectangle *src_rect, const VARectangle *dst_rect)
4951 struct i965_surface src_surface, dst_surface;
4952 VAStatus va_status = VA_STATUS_SUCCESS;
4954 if (!obj_surface->bo) {
4955 unsigned int tiling, swizzle;
4956 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
4957 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
4959 i965_check_alloc_surface_bo(ctx,
4962 obj_image->image.format.fourcc,
4966 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4968 src_surface.base = (struct object_base *)obj_image;
4969 src_surface.type = I965_SURFACE_TYPE_IMAGE;
4970 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4972 dst_surface.base = (struct object_base *)obj_surface;
4973 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4974 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4976 va_status = i965_image_processing(ctx,
4986 i965_PutImage(VADriverContextP ctx,
4987 VASurfaceID surface,
4991 unsigned int src_width,
4992 unsigned int src_height,
4995 unsigned int dest_width,
4996 unsigned int dest_height)
4998 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4999 struct object_surface * const obj_surface = SURFACE(surface);
5000 struct object_image * const obj_image = IMAGE(image);
5001 VARectangle src_rect, dst_rect;
5005 return VA_STATUS_ERROR_INVALID_SURFACE;
5006 if (is_surface_busy(i965, obj_surface))
5007 return VA_STATUS_ERROR_SURFACE_BUSY;
5009 if (!obj_image || !obj_image->bo)
5010 return VA_STATUS_ERROR_INVALID_IMAGE;
5011 if (is_image_busy(i965, obj_image, surface))
5012 return VA_STATUS_ERROR_SURFACE_BUSY;
5016 src_x + src_width > obj_image->image.width ||
5017 src_y + src_height > obj_image->image.height)
5018 return VA_STATUS_ERROR_INVALID_PARAMETER;
5022 src_rect.width = src_width;
5023 src_rect.height = src_height;
5027 dest_x + dest_width > obj_surface->orig_width ||
5028 dest_y + dest_height > obj_surface->orig_height)
5029 return VA_STATUS_ERROR_INVALID_PARAMETER;
5031 dst_rect.x = dest_x;
5032 dst_rect.y = dest_y;
5033 dst_rect.width = dest_width;
5034 dst_rect.height = dest_height;
5036 if (HAS_ACCELERATED_PUTIMAGE(i965))
5037 va_status = i965_hw_putimage(ctx, obj_surface, obj_image,
5038 &src_rect, &dst_rect);
5040 va_status = i965_sw_putimage(ctx, obj_surface, obj_image,
5041 &src_rect, &dst_rect);
5047 i965_PutSurface(VADriverContextP ctx,
5048 VASurfaceID surface,
5049 void *draw, /* X Drawable */
5052 unsigned short srcw,
5053 unsigned short srch,
5056 unsigned short destw,
5057 unsigned short desth,
5058 VARectangle *cliprects, /* client supplied clip list */
5059 unsigned int number_cliprects, /* number of clip rects in the clip list */
5060 unsigned int flags) /* de-interlacing flags */
5063 if (IS_VA_X11(ctx)) {
5064 VARectangle src_rect, dst_rect;
5068 src_rect.width = srcw;
5069 src_rect.height = srch;
5073 dst_rect.width = destw;
5074 dst_rect.height = desth;
5076 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
5077 cliprects, number_cliprects, flags);
5080 return VA_STATUS_ERROR_UNIMPLEMENTED;
5085 VADriverContextP ctx, /* in */
5086 VABufferID buf_id, /* in */
5087 VABufferType *type, /* out */
5088 unsigned int *size, /* out */
5089 unsigned int *num_elements /* out */
5092 struct i965_driver_data *i965 = NULL;
5093 struct object_buffer *obj_buffer = NULL;
5095 i965 = i965_driver_data(ctx);
5096 obj_buffer = BUFFER(buf_id);
5098 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
5100 *type = obj_buffer->type;
5101 *size = obj_buffer->size_element;
5102 *num_elements = obj_buffer->num_elements;
5104 return VA_STATUS_SUCCESS;
5109 VADriverContextP ctx, /* in */
5110 VASurfaceID surface, /* in */
5111 unsigned int *fourcc, /* out */
5112 unsigned int *luma_stride, /* out */
5113 unsigned int *chroma_u_stride, /* out */
5114 unsigned int *chroma_v_stride, /* out */
5115 unsigned int *luma_offset, /* out */
5116 unsigned int *chroma_u_offset, /* out */
5117 unsigned int *chroma_v_offset, /* out */
5118 unsigned int *buffer_name, /* out */
5119 void **buffer /* out */
5122 VAStatus vaStatus = VA_STATUS_SUCCESS;
5123 struct i965_driver_data *i965 = i965_driver_data(ctx);
5124 struct object_surface *obj_surface = NULL;
5127 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
5128 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5129 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5130 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
5131 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5132 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5133 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
5134 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
5135 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
5137 tmpImage.image_id = VA_INVALID_ID;
5139 obj_surface = SURFACE(surface);
5140 if (obj_surface == NULL) {
5141 // Surface is absent.
5142 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5146 // Lock functionality is absent now.
5147 if (obj_surface->locked_image_id != VA_INVALID_ID) {
5148 // Surface is locked already.
5149 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5153 vaStatus = i965_DeriveImage(
5157 if (vaStatus != VA_STATUS_SUCCESS) {
5161 obj_surface->locked_image_id = tmpImage.image_id;
5163 vaStatus = i965_MapBuffer(
5167 if (vaStatus != VA_STATUS_SUCCESS) {
5171 *fourcc = tmpImage.format.fourcc;
5172 *luma_offset = tmpImage.offsets[0];
5173 *luma_stride = tmpImage.pitches[0];
5174 *chroma_u_offset = tmpImage.offsets[1];
5175 *chroma_u_stride = tmpImage.pitches[1];
5176 *chroma_v_offset = tmpImage.offsets[2];
5177 *chroma_v_stride = tmpImage.pitches[2];
5178 *buffer_name = tmpImage.buf;
5181 if (vaStatus != VA_STATUS_SUCCESS) {
5190 VADriverContextP ctx, /* in */
5191 VASurfaceID surface /* in */
5194 VAStatus vaStatus = VA_STATUS_SUCCESS;
5195 struct i965_driver_data *i965 = i965_driver_data(ctx);
5196 struct object_image *locked_img = NULL;
5197 struct object_surface *obj_surface = NULL;
5199 obj_surface = SURFACE(surface);
5201 if (obj_surface == NULL) {
5202 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
5205 if (obj_surface->locked_image_id == VA_INVALID_ID) {
5206 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
5210 locked_img = IMAGE(obj_surface->locked_image_id);
5211 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
5212 // Work image was deallocated before i965_UnlockSurface()
5213 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
5217 vaStatus = i965_UnmapBuffer(
5219 locked_img->image.buf);
5220 if (vaStatus != VA_STATUS_SUCCESS) {
5224 vaStatus = i965_DestroyImage(
5226 locked_img->image.image_id);
5227 if (vaStatus != VA_STATUS_SUCCESS) {
5231 locked_img->image.image_id = VA_INVALID_ID;
5234 obj_surface->locked_image_id = VA_INVALID_ID;
5240 i965_GetSurfaceAttributes(
5241 VADriverContextP ctx,
5243 VASurfaceAttrib *attrib_list,
5244 unsigned int num_attribs
5247 VAStatus vaStatus = VA_STATUS_SUCCESS;
5248 struct i965_driver_data *i965 = i965_driver_data(ctx);
5249 struct object_config *obj_config;
5252 if (config == VA_INVALID_ID)
5253 return VA_STATUS_ERROR_INVALID_CONFIG;
5255 obj_config = CONFIG(config);
5257 if (obj_config == NULL)
5258 return VA_STATUS_ERROR_INVALID_CONFIG;
5260 if (attrib_list == NULL || num_attribs == 0)
5261 return VA_STATUS_ERROR_INVALID_PARAMETER;
5263 for (i = 0; i < num_attribs; i++) {
5264 switch (attrib_list[i].type) {
5265 case VASurfaceAttribPixelFormat:
5266 attrib_list[i].value.type = VAGenericValueTypeInteger;
5267 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5269 if (attrib_list[i].value.value.i == 0) {
5270 if (IS_G4X(i965->intel.device_info)) {
5271 if (obj_config->profile == VAProfileMPEG2Simple ||
5272 obj_config->profile == VAProfileMPEG2Main) {
5273 attrib_list[i].value.value.i = VA_FOURCC_I420;
5276 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5278 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5279 if (obj_config->profile == VAProfileMPEG2Simple ||
5280 obj_config->profile == VAProfileMPEG2Main) {
5281 attrib_list[i].value.value.i = VA_FOURCC_I420;
5282 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5283 obj_config->profile == VAProfileH264Main ||
5284 obj_config->profile == VAProfileH264High) {
5285 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5286 } else if (obj_config->profile == VAProfileNone) {
5287 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5290 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5292 } else if (IS_GEN6(i965->intel.device_info)) {
5293 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5294 } else if (IS_GEN7(i965->intel.device_info) ||
5295 IS_GEN8(i965->intel.device_info) ||
5296 IS_GEN9(i965->intel.device_info)) {
5297 if (obj_config->profile == VAProfileJPEGBaseline)
5298 attrib_list[i].value.value.i = 0; /* internal format */
5300 attrib_list[i].value.value.i = VA_FOURCC_NV12;
5303 if (IS_G4X(i965->intel.device_info)) {
5304 if (obj_config->profile == VAProfileMPEG2Simple ||
5305 obj_config->profile == VAProfileMPEG2Main) {
5306 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5307 attrib_list[i].value.value.i = 0;
5308 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5312 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5314 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5315 if (obj_config->profile == VAProfileMPEG2Simple ||
5316 obj_config->profile == VAProfileMPEG2Main) {
5317 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
5318 attrib_list[i].value.value.i = 0;
5319 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5321 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
5322 obj_config->profile == VAProfileH264Main ||
5323 obj_config->profile == VAProfileH264High) {
5324 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5325 attrib_list[i].value.value.i = 0;
5326 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5328 } else if (obj_config->profile == VAProfileNone) {
5329 switch (attrib_list[i].value.value.i) {
5330 case VA_FOURCC_NV12:
5331 case VA_FOURCC_I420:
5332 case VA_FOURCC_YV12:
5333 case VA_FOURCC_YUY2:
5334 case VA_FOURCC_BGRA:
5335 case VA_FOURCC_BGRX:
5336 case VA_FOURCC_RGBX:
5337 case VA_FOURCC_RGBA:
5340 attrib_list[i].value.value.i = 0;
5341 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5346 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5348 } else if (IS_GEN6(i965->intel.device_info)) {
5349 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5350 obj_config->entrypoint == VAEntrypointVideoProc) {
5351 switch (attrib_list[i].value.value.i) {
5352 case VA_FOURCC_NV12:
5353 case VA_FOURCC_I420:
5354 case VA_FOURCC_YV12:
5355 case VA_FOURCC_YUY2:
5356 case VA_FOURCC_BGRA:
5357 case VA_FOURCC_BGRX:
5358 case VA_FOURCC_RGBX:
5359 case VA_FOURCC_RGBA:
5362 attrib_list[i].value.value.i = 0;
5363 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5367 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5368 attrib_list[i].value.value.i = 0;
5369 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5372 } else if (IS_GEN7(i965->intel.device_info) ||
5373 IS_GEN8(i965->intel.device_info) ||
5374 IS_GEN9(i965->intel.device_info)) {
5375 if (obj_config->entrypoint == VAEntrypointEncSlice ||
5376 obj_config->entrypoint == VAEntrypointVideoProc ||
5377 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5378 switch (attrib_list[i].value.value.i) {
5379 case VA_FOURCC_NV12:
5380 case VA_FOURCC_I420:
5381 case VA_FOURCC_YV12:
5384 attrib_list[i].value.value.i = 0;
5385 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5389 if (obj_config->profile == VAProfileJPEGBaseline) {
5390 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
5391 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5393 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
5394 attrib_list[i].value.value.i = 0;
5395 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
5403 case VASurfaceAttribMinWidth:
5404 /* FIXME: add support for it later */
5405 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5407 case VASurfaceAttribMaxWidth:
5408 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5410 case VASurfaceAttribMinHeight:
5411 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5413 case VASurfaceAttribMaxHeight:
5414 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5417 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
5426 i965_QuerySurfaceAttributes(VADriverContextP ctx,
5428 VASurfaceAttrib *attrib_list,
5429 unsigned int *num_attribs)
5431 VAStatus vaStatus = VA_STATUS_SUCCESS;
5432 struct i965_driver_data *i965 = i965_driver_data(ctx);
5433 struct object_config *obj_config;
5435 VASurfaceAttrib *attribs = NULL;
5439 if (config == VA_INVALID_ID)
5440 return VA_STATUS_ERROR_INVALID_CONFIG;
5442 obj_config = CONFIG(config);
5444 if (obj_config == NULL)
5445 return VA_STATUS_ERROR_INVALID_CONFIG;
5447 if (!attrib_list && !num_attribs)
5448 return VA_STATUS_ERROR_INVALID_PARAMETER;
5450 if (attrib_list == NULL) {
5451 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
5452 return VA_STATUS_SUCCESS;
5455 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
5457 if (attribs == NULL)
5458 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5460 if (IS_G4X(i965->intel.device_info)) {
5461 if (obj_config->profile == VAProfileMPEG2Simple ||
5462 obj_config->profile == VAProfileMPEG2Main) {
5463 attribs[i].type = VASurfaceAttribPixelFormat;
5464 attribs[i].value.type = VAGenericValueTypeInteger;
5465 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5466 attribs[i].value.value.i = VA_FOURCC_I420;
5469 } else if (IS_IRONLAKE(i965->intel.device_info)) {
5470 switch (obj_config->profile) {
5471 case VAProfileMPEG2Simple:
5472 case VAProfileMPEG2Main:
5473 attribs[i].type = VASurfaceAttribPixelFormat;
5474 attribs[i].value.type = VAGenericValueTypeInteger;
5475 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5476 attribs[i].value.value.i = VA_FOURCC_I420;
5481 case VAProfileH264ConstrainedBaseline:
5482 case VAProfileH264Main:
5483 case VAProfileH264High:
5484 attribs[i].type = VASurfaceAttribPixelFormat;
5485 attribs[i].value.type = VAGenericValueTypeInteger;
5486 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5487 attribs[i].value.value.i = VA_FOURCC_NV12;
5491 attribs[i].type = VASurfaceAttribPixelFormat;
5492 attribs[i].value.type = VAGenericValueTypeInteger;
5493 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5494 attribs[i].value.value.i = VA_FOURCC_NV12;
5497 attribs[i].type = VASurfaceAttribPixelFormat;
5498 attribs[i].value.type = VAGenericValueTypeInteger;
5499 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5500 attribs[i].value.value.i = VA_FOURCC_I420;
5508 } else if (IS_GEN6(i965->intel.device_info)) {
5509 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5510 attribs[i].type = VASurfaceAttribPixelFormat;
5511 attribs[i].value.type = VAGenericValueTypeInteger;
5512 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5513 attribs[i].value.value.i = VA_FOURCC_NV12;
5515 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5516 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5517 attribs[i].type = VASurfaceAttribPixelFormat;
5518 attribs[i].value.type = VAGenericValueTypeInteger;
5519 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5520 attribs[i].value.value.i = VA_FOURCC_NV12;
5523 attribs[i].type = VASurfaceAttribPixelFormat;
5524 attribs[i].value.type = VAGenericValueTypeInteger;
5525 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5526 attribs[i].value.value.i = VA_FOURCC_I420;
5529 attribs[i].type = VASurfaceAttribPixelFormat;
5530 attribs[i].value.type = VAGenericValueTypeInteger;
5531 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5532 attribs[i].value.value.i = VA_FOURCC_YV12;
5535 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5536 attribs[i].type = VASurfaceAttribPixelFormat;
5537 attribs[i].value.type = VAGenericValueTypeInteger;
5538 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5539 attribs[i].value.value.i = VA_FOURCC_YUY2;
5542 attribs[i].type = VASurfaceAttribPixelFormat;
5543 attribs[i].value.type = VAGenericValueTypeInteger;
5544 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5545 attribs[i].value.value.i = VA_FOURCC_RGBA;
5548 attribs[i].type = VASurfaceAttribPixelFormat;
5549 attribs[i].value.type = VAGenericValueTypeInteger;
5550 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5551 attribs[i].value.value.i = VA_FOURCC_RGBX;
5555 } else if (IS_GEN7(i965->intel.device_info)) {
5556 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5557 if (obj_config->profile == VAProfileJPEGBaseline) {
5558 attribs[i].type = VASurfaceAttribPixelFormat;
5559 attribs[i].value.type = VAGenericValueTypeInteger;
5560 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5561 attribs[i].value.value.i = VA_FOURCC_IMC3;
5564 attribs[i].type = VASurfaceAttribPixelFormat;
5565 attribs[i].value.type = VAGenericValueTypeInteger;
5566 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5567 attribs[i].value.value.i = VA_FOURCC_IMC1;
5570 attribs[i].type = VASurfaceAttribPixelFormat;
5571 attribs[i].value.type = VAGenericValueTypeInteger;
5572 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5573 attribs[i].value.value.i = VA_FOURCC_Y800;
5576 attribs[i].type = VASurfaceAttribPixelFormat;
5577 attribs[i].value.type = VAGenericValueTypeInteger;
5578 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5579 attribs[i].value.value.i = VA_FOURCC_411P;
5582 attribs[i].type = VASurfaceAttribPixelFormat;
5583 attribs[i].value.type = VAGenericValueTypeInteger;
5584 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5585 attribs[i].value.value.i = VA_FOURCC_422H;
5588 attribs[i].type = VASurfaceAttribPixelFormat;
5589 attribs[i].value.type = VAGenericValueTypeInteger;
5590 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5591 attribs[i].value.value.i = VA_FOURCC_422V;
5594 attribs[i].type = VASurfaceAttribPixelFormat;
5595 attribs[i].value.type = VAGenericValueTypeInteger;
5596 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5597 attribs[i].value.value.i = VA_FOURCC_444P;
5599 } else if (obj_config->profile == VAProfileHEVCMain10) {
5600 attribs[i].type = VASurfaceAttribPixelFormat;
5601 attribs[i].value.type = VAGenericValueTypeInteger;
5602 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5603 attribs[i].value.value.i = VA_FOURCC_P010;
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_NV12;
5612 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5613 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
5614 attribs[i].type = VASurfaceAttribPixelFormat;
5615 attribs[i].value.type = VAGenericValueTypeInteger;
5616 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5617 attribs[i].value.value.i = VA_FOURCC_NV12;
5620 attribs[i].type = VASurfaceAttribPixelFormat;
5621 attribs[i].value.type = VAGenericValueTypeInteger;
5622 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5623 attribs[i].value.value.i = VA_FOURCC_I420;
5626 attribs[i].type = VASurfaceAttribPixelFormat;
5627 attribs[i].value.type = VAGenericValueTypeInteger;
5628 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5629 attribs[i].value.value.i = VA_FOURCC_YV12;
5632 attribs[i].type = VASurfaceAttribPixelFormat;
5633 attribs[i].value.type = VAGenericValueTypeInteger;
5634 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5635 attribs[i].value.value.i = VA_FOURCC_IMC3;
5638 if (obj_config->entrypoint == VAEntrypointVideoProc) {
5639 attribs[i].type = VASurfaceAttribPixelFormat;
5640 attribs[i].value.type = VAGenericValueTypeInteger;
5641 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5642 attribs[i].value.value.i = VA_FOURCC_YUY2;
5645 attribs[i].type = VASurfaceAttribPixelFormat;
5646 attribs[i].value.type = VAGenericValueTypeInteger;
5647 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5648 attribs[i].value.value.i = VA_FOURCC_RGBA;
5651 attribs[i].type = VASurfaceAttribPixelFormat;
5652 attribs[i].value.type = VAGenericValueTypeInteger;
5653 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5654 attribs[i].value.value.i = VA_FOURCC_RGBX;
5657 attribs[i].type = VASurfaceAttribPixelFormat;
5658 attribs[i].value.type = VAGenericValueTypeInteger;
5659 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5660 attribs[i].value.value.i = VA_FOURCC_BGRA;
5663 attribs[i].type = VASurfaceAttribPixelFormat;
5664 attribs[i].value.type = VAGenericValueTypeInteger;
5665 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5666 attribs[i].value.value.i = VA_FOURCC_BGRX;
5669 attribs[i].type = VASurfaceAttribPixelFormat;
5670 attribs[i].value.type = VAGenericValueTypeInteger;
5671 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5672 attribs[i].value.value.i = VA_FOURCC_YV16;
5676 } else if (IS_GEN8(i965->intel.device_info) ||
5677 IS_GEN9(i965->intel.device_info)) {
5678 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
5679 if (obj_config->profile == VAProfileJPEGBaseline) {
5680 attribs[i].type = VASurfaceAttribPixelFormat;
5681 attribs[i].value.type = VAGenericValueTypeInteger;
5682 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5683 attribs[i].value.value.i = VA_FOURCC_IMC3;
5686 attribs[i].type = VASurfaceAttribPixelFormat;
5687 attribs[i].value.type = VAGenericValueTypeInteger;
5688 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5689 attribs[i].value.value.i = VA_FOURCC_IMC1;
5692 attribs[i].type = VASurfaceAttribPixelFormat;
5693 attribs[i].value.type = VAGenericValueTypeInteger;
5694 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5695 attribs[i].value.value.i = VA_FOURCC_Y800;
5698 attribs[i].type = VASurfaceAttribPixelFormat;
5699 attribs[i].value.type = VAGenericValueTypeInteger;
5700 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5701 attribs[i].value.value.i = VA_FOURCC_411P;
5704 attribs[i].type = VASurfaceAttribPixelFormat;
5705 attribs[i].value.type = VAGenericValueTypeInteger;
5706 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5707 attribs[i].value.value.i = VA_FOURCC_422H;
5710 attribs[i].type = VASurfaceAttribPixelFormat;
5711 attribs[i].value.type = VAGenericValueTypeInteger;
5712 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5713 attribs[i].value.value.i = VA_FOURCC_422V;
5716 attribs[i].type = VASurfaceAttribPixelFormat;
5717 attribs[i].value.type = VAGenericValueTypeInteger;
5718 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5719 attribs[i].value.value.i = VA_FOURCC_444P;
5722 attribs[i].type = VASurfaceAttribPixelFormat;
5723 attribs[i].value.type = VAGenericValueTypeInteger;
5724 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5725 attribs[i].value.value.i = VA_FOURCC_NV12;
5728 if ((obj_config->profile == VAProfileHEVCMain10) ||
5729 (obj_config->profile == VAProfileVP9Profile2)) {
5730 attribs[i].type = VASurfaceAttribPixelFormat;
5731 attribs[i].value.type = VAGenericValueTypeInteger;
5732 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5733 attribs[i].value.value.i = VA_FOURCC_P010;
5737 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
5738 obj_config->entrypoint == VAEntrypointVideoProc ||
5739 obj_config->entrypoint == VAEntrypointEncSliceLP) {
5741 if (obj_config->profile == VAProfileHEVCMain10) {
5742 attribs[i].type = VASurfaceAttribPixelFormat;
5743 attribs[i].value.type = VAGenericValueTypeInteger;
5744 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5745 attribs[i].value.value.i = VA_FOURCC_P010;
5748 attribs[i].type = VASurfaceAttribPixelFormat;
5749 attribs[i].value.type = VAGenericValueTypeInteger;
5750 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5751 attribs[i].value.value.i = VA_FOURCC_NV12;
5754 attribs[i].type = VASurfaceAttribPixelFormat;
5755 attribs[i].value.type = VAGenericValueTypeInteger;
5756 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5757 attribs[i].value.value.i = VA_FOURCC_I420;
5760 attribs[i].type = VASurfaceAttribPixelFormat;
5761 attribs[i].value.type = VAGenericValueTypeInteger;
5762 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5763 attribs[i].value.value.i = VA_FOURCC_YV12;
5766 attribs[i].type = VASurfaceAttribPixelFormat;
5767 attribs[i].value.type = VAGenericValueTypeInteger;
5768 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5769 attribs[i].value.value.i = VA_FOURCC_IMC3;
5773 if (obj_config->entrypoint == VAEntrypointVideoProc) {
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_YUY2;
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_RGBA;
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_RGBX;
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_BGRA;
5798 attribs[i].type = VASurfaceAttribPixelFormat;
5799 attribs[i].value.type = VAGenericValueTypeInteger;
5800 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5801 attribs[i].value.value.i = VA_FOURCC_BGRX;
5804 attribs[i].type = VASurfaceAttribPixelFormat;
5805 attribs[i].value.type = VAGenericValueTypeInteger;
5806 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5807 attribs[i].value.value.i = VA_FOURCC_YV16;
5810 if(HAS_VPP_P010(i965)) {
5811 attribs[i].type = VASurfaceAttribPixelFormat;
5812 attribs[i].value.type = VAGenericValueTypeInteger;
5813 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5814 attribs[i].value.value.i = VA_FOURCC_P010;
5821 attribs[i].type = VASurfaceAttribMemoryType;
5822 attribs[i].value.type = VAGenericValueTypeInteger;
5823 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
5824 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
5825 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
5826 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
5829 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
5830 attribs[i].value.type = VAGenericValueTypePointer;
5831 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
5832 attribs[i].value.value.p = NULL; /* ignore */
5835 max_resolution(i965, obj_config, &max_width, &max_height);
5837 attribs[i].type = VASurfaceAttribMaxWidth;
5838 attribs[i].value.type = VAGenericValueTypeInteger;
5839 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5840 attribs[i].value.value.i = max_width;
5843 attribs[i].type = VASurfaceAttribMaxHeight;
5844 attribs[i].value.type = VAGenericValueTypeInteger;
5845 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE;
5846 attribs[i].value.value.i = max_height;
5849 if (i > *num_attribs) {
5852 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5856 memcpy(attrib_list, attribs, i * sizeof(*attribs));
5862 /* Acquires buffer handle for external API usage (internal implementation) */
5864 i965_acquire_buffer_handle(struct object_buffer *obj_buffer,
5865 uint32_t mem_type, VABufferInfo *out_buf_info)
5867 struct buffer_store *buffer_store;
5869 buffer_store = obj_buffer->buffer_store;
5870 if (!buffer_store || !buffer_store->bo)
5871 return VA_STATUS_ERROR_INVALID_BUFFER;
5873 /* Synchronization point */
5874 drm_intel_bo_wait_rendering(buffer_store->bo);
5876 if (obj_buffer->export_refcount > 0) {
5877 if (obj_buffer->export_state.mem_type != mem_type)
5878 return VA_STATUS_ERROR_INVALID_PARAMETER;
5881 VABufferInfo * const buf_info = &obj_buffer->export_state;
5884 case VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: {
5886 if (drm_intel_bo_flink(buffer_store->bo, &name) != 0)
5887 return VA_STATUS_ERROR_INVALID_BUFFER;
5888 buf_info->handle = name;
5891 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5893 if (drm_intel_bo_gem_export_to_prime(buffer_store->bo, &fd) != 0)
5894 return VA_STATUS_ERROR_INVALID_BUFFER;
5895 buf_info->handle = (intptr_t)fd;
5900 buf_info->type = obj_buffer->type;
5901 buf_info->mem_type = mem_type;
5902 buf_info->mem_size =
5903 obj_buffer->num_elements * obj_buffer->size_element;
5906 obj_buffer->export_refcount++;
5907 *out_buf_info = obj_buffer->export_state;
5908 return VA_STATUS_SUCCESS;
5911 /* Releases buffer handle after usage (internal implementation) */
5913 i965_release_buffer_handle(struct object_buffer *obj_buffer)
5915 if (obj_buffer->export_refcount == 0)
5916 return VA_STATUS_ERROR_INVALID_BUFFER;
5918 if (--obj_buffer->export_refcount == 0) {
5919 VABufferInfo * const buf_info = &obj_buffer->export_state;
5921 switch (buf_info->mem_type) {
5922 case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: {
5923 close((intptr_t)buf_info->handle);
5927 buf_info->mem_type = 0;
5929 return VA_STATUS_SUCCESS;
5932 /** Acquires buffer handle for external API usage */
5934 i965_AcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
5935 VABufferInfo *buf_info)
5937 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5938 struct object_buffer * const obj_buffer = BUFFER(buf_id);
5939 uint32_t i, mem_type;
5941 /* List of supported memory types, in preferred order */
5942 static const uint32_t mem_types[] = {
5943 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
5944 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM,
5949 return VA_STATUS_ERROR_INVALID_BUFFER;
5950 /* XXX: only VA surface|image like buffers are supported for now */
5951 if (obj_buffer->type != VAImageBufferType)
5952 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
5955 * As the allocated buffer by calling vaCreateBuffer is related with
5956 * the specific context, it is unnecessary to export it.
5957 * So it is not supported when the buffer is allocated from wrapped
5960 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
5961 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
5965 return VA_STATUS_ERROR_INVALID_PARAMETER;
5967 if (!buf_info->mem_type)
5968 mem_type = mem_types[0];
5971 for (i = 0; mem_types[i] != 0; i++) {
5972 if (buf_info->mem_type & mem_types[i]) {
5973 mem_type = buf_info->mem_type;
5978 return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
5980 return i965_acquire_buffer_handle(obj_buffer, mem_type, buf_info);
5983 /** Releases buffer handle after usage from external API */
5985 i965_ReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
5987 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5988 struct object_buffer * const obj_buffer = BUFFER(buf_id);
5991 return VA_STATUS_ERROR_INVALID_BUFFER;
5993 if (obj_buffer->wrapper_buffer != VA_INVALID_ID) {
5994 return VA_STATUS_ERROR_INVALID_BUFFER;
5997 return i965_release_buffer_handle(obj_buffer);
6001 i965_os_has_ring_support(VADriverContextP ctx,
6004 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6008 return i965->intel.has_bsd;
6011 return i965->intel.has_blt;
6013 case I965_RING_VEBOX:
6014 return i965->intel.has_vebox;
6016 case I965_RING_NULL:
6017 return 1; /* Always support */
6020 /* should never get here */
6029 * Query video processing pipeline
6031 VAStatus i965_QueryVideoProcFilters(
6032 VADriverContextP ctx,
6033 VAContextID context,
6034 VAProcFilterType *filters,
6035 unsigned int *num_filters
6038 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6039 unsigned int i = 0, num = 0;
6041 if (!num_filters || !filters)
6042 return VA_STATUS_ERROR_INVALID_PARAMETER;
6044 for (i = 0; i < i965->codec_info->num_filters; i++) {
6045 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
6046 if (num == *num_filters) {
6047 *num_filters = i965->codec_info->num_filters;
6049 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6052 filters[num++] = i965->codec_info->filters[i].type;
6058 return VA_STATUS_SUCCESS;
6061 VAStatus i965_QueryVideoProcFilterCaps(
6062 VADriverContextP ctx,
6063 VAContextID context,
6064 VAProcFilterType type,
6066 unsigned int *num_filter_caps
6070 struct i965_driver_data *const i965 = i965_driver_data(ctx);
6072 if (!filter_caps || !num_filter_caps)
6073 return VA_STATUS_ERROR_INVALID_PARAMETER;
6075 for (i = 0; i < i965->codec_info->num_filters; i++) {
6076 if (type == i965->codec_info->filters[i].type &&
6077 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
6081 if (i == i965->codec_info->num_filters)
6082 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
6087 case VAProcFilterNoiseReduction:
6088 case VAProcFilterSharpening:
6090 VAProcFilterCap *cap = filter_caps;
6092 if (*num_filter_caps < 1) {
6093 *num_filter_caps = 1;
6094 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6097 cap->range.min_value = 0.0;
6098 cap->range.max_value = 1.0;
6099 cap->range.default_value = 0.5;
6100 cap->range.step = 0.03125; /* 1.0 / 32 */
6106 case VAProcFilterDeinterlacing:
6108 VAProcFilterCapDeinterlacing *cap = filter_caps;
6110 if (*num_filter_caps < VAProcDeinterlacingCount) {
6111 *num_filter_caps = VAProcDeinterlacingCount;
6112 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6115 cap->type = VAProcDeinterlacingBob;
6120 if (i965->codec_info->has_di_motion_adptive) {
6121 cap->type = VAProcDeinterlacingMotionAdaptive;
6126 if (i965->codec_info->has_di_motion_compensated) {
6127 cap->type = VAProcDeinterlacingMotionCompensated;
6135 case VAProcFilterColorBalance:
6137 VAProcFilterCapColorBalance *cap = filter_caps;
6139 if (*num_filter_caps < VAProcColorBalanceCount) {
6140 *num_filter_caps = VAProcColorBalanceCount;
6141 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
6144 cap->type = VAProcColorBalanceHue;
6145 cap->range.min_value = -180.0;
6146 cap->range.max_value = 180.0;
6147 cap->range.default_value = 0.0;
6148 cap->range.step = 1.0;
6152 cap->type = VAProcColorBalanceSaturation;
6153 cap->range.min_value = 0.0;
6154 cap->range.max_value = 10.0;
6155 cap->range.default_value = 1.0;
6156 cap->range.step = 0.1;
6160 cap->type = VAProcColorBalanceBrightness;
6161 cap->range.min_value = -100.0;
6162 cap->range.max_value = 100.0;
6163 cap->range.default_value = 0.0;
6164 cap->range.step = 1.0;
6168 cap->type = VAProcColorBalanceContrast;
6169 cap->range.min_value = 0.0;
6170 cap->range.max_value = 10.0;
6171 cap->range.default_value = 1.0;
6172 cap->range.step = 0.1;
6184 *num_filter_caps = i;
6186 return VA_STATUS_SUCCESS;
6189 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
6190 VAProcColorStandardBT601,
6193 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
6194 VAProcColorStandardBT601,
6197 VAStatus i965_QueryVideoProcPipelineCaps(
6198 VADriverContextP ctx,
6199 VAContextID context,
6200 VABufferID *filters,
6201 unsigned int num_filters,
6202 VAProcPipelineCaps *pipeline_cap /* out */
6205 struct i965_driver_data * const i965 = i965_driver_data(ctx);
6208 pipeline_cap->pipeline_flags = 0;
6209 pipeline_cap->filter_flags = 0;
6210 pipeline_cap->num_forward_references = 0;
6211 pipeline_cap->num_backward_references = 0;
6212 pipeline_cap->num_input_color_standards = 1;
6213 pipeline_cap->input_color_standards = vpp_input_color_standards;
6214 pipeline_cap->num_output_color_standards = 1;
6215 pipeline_cap->output_color_standards = vpp_output_color_standards;
6217 for (i = 0; i < num_filters; i++) {
6218 struct object_buffer *obj_buffer = BUFFER(filters[i]);
6221 !obj_buffer->buffer_store ||
6222 !obj_buffer->buffer_store->buffer)
6223 return VA_STATUS_ERROR_INVALID_BUFFER;
6225 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
6227 if (base->type == VAProcFilterNoiseReduction) {
6228 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
6230 } else if (base->type == VAProcFilterDeinterlacing) {
6231 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
6233 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
6234 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6235 deint->algorithm == VAProcDeinterlacingMotionCompensated,
6236 VA_STATUS_ERROR_INVALID_PARAMETER);
6238 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
6239 deint->algorithm == VAProcDeinterlacingMotionCompensated)
6240 pipeline_cap->num_forward_references++;
6241 } else if (base->type == VAProcFilterSkinToneEnhancement) {
6242 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
6247 return VA_STATUS_SUCCESS;
6250 extern struct hw_codec_info *i965_get_codec_info(int devid);
6253 i965_driver_data_init(VADriverContextP ctx)
6255 struct i965_driver_data *i965 = i965_driver_data(ctx);
6257 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
6259 if (!i965->codec_info)
6262 if (object_heap_init(&i965->config_heap,
6263 sizeof(struct object_config),
6265 goto err_config_heap;
6266 if (object_heap_init(&i965->context_heap,
6267 sizeof(struct object_context),
6269 goto err_context_heap;
6271 if (object_heap_init(&i965->surface_heap,
6272 sizeof(struct object_surface),
6274 goto err_surface_heap;
6275 if (object_heap_init(&i965->buffer_heap,
6276 sizeof(struct object_buffer),
6278 goto err_buffer_heap;
6279 if (object_heap_init(&i965->image_heap,
6280 sizeof(struct object_image),
6282 goto err_image_heap;
6283 if (object_heap_init(&i965->subpic_heap,
6284 sizeof(struct object_subpic),
6286 goto err_subpic_heap;
6288 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6289 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
6290 _i965InitMutex(&i965->render_mutex);
6291 _i965InitMutex(&i965->pp_mutex);
6296 object_heap_destroy(&i965->image_heap);
6298 object_heap_destroy(&i965->buffer_heap);
6300 object_heap_destroy(&i965->surface_heap);
6302 object_heap_destroy(&i965->context_heap);
6304 object_heap_destroy(&i965->config_heap);
6311 i965_driver_data_terminate(VADriverContextP ctx)
6313 struct i965_driver_data *i965 = i965_driver_data(ctx);
6315 _i965DestroyMutex(&i965->pp_mutex);
6316 _i965DestroyMutex(&i965->render_mutex);
6319 intel_batchbuffer_free(i965->batch);
6322 intel_batchbuffer_free(i965->pp_batch);
6324 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
6325 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
6326 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
6327 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
6328 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
6329 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
6333 bool (*init)(VADriverContextP ctx);
6334 void (*terminate)(VADriverContextP ctx);
6336 } i965_sub_ops[] = {
6339 intel_driver_terminate,
6344 i965_driver_data_init,
6345 i965_driver_data_terminate,
6350 i965_display_attributes_init,
6351 i965_display_attributes_terminate,
6356 i965_post_processing_init,
6357 i965_post_processing_terminate,
6363 i965_render_terminate,
6367 #ifdef HAVE_VA_WAYLAND
6369 i965_output_wayland_init,
6370 i965_output_wayland_terminate,
6377 i965_output_dri_init,
6378 i965_output_dri_terminate,
6385 ensure_vendor_string(struct i965_driver_data *i965, const char *chipset)
6389 if (i965->va_vendor[0] != '\0')
6393 ret = snprintf(i965->va_vendor, sizeof(i965->va_vendor),
6394 "%s %s driver for %s - %d.%d.%d",
6395 INTEL_STR_DRIVER_VENDOR, INTEL_STR_DRIVER_NAME, chipset,
6396 INTEL_DRIVER_MAJOR_VERSION, INTEL_DRIVER_MINOR_VERSION,
6397 INTEL_DRIVER_MICRO_VERSION);
6398 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6402 if (INTEL_DRIVER_PRE_VERSION > 0) {
6403 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6404 ".pre%d", INTEL_DRIVER_PRE_VERSION);
6405 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6409 ret = snprintf(&i965->va_vendor[len], sizeof(i965->va_vendor) - len,
6410 " (%s)", INTEL_DRIVER_GIT_VERSION);
6411 if (ret < 0 || ret >= sizeof(i965->va_vendor))
6418 i965->va_vendor[0] = '\0';
6419 ASSERT_RET(ret > 0 && len < sizeof(i965->va_vendor), false);
6423 /* Only when the option of "enable-wrapper" is passed, it is possible
6424 * to initialize/load the wrapper context of backend driver.
6425 * Otherwise it is not loaded.
6427 #if HAVE_HYBRID_CODEC
6430 i965_initialize_wrapper(VADriverContextP ctx, const char *driver_name)
6432 #define DRIVER_EXTENSION "_drv_video.so"
6434 struct i965_driver_data *i965 = i965_driver_data(ctx);
6436 VADriverContextP wrapper_pdrvctx;
6437 struct VADriverVTable *vtable;
6438 char *search_path, *driver_dir;
6440 char driver_path[256];
6441 void *handle = NULL;
6442 VAStatus va_status = VA_STATUS_SUCCESS;
6443 bool driver_loaded = false;
6445 if (HAS_VP9_DECODING(i965)) {
6446 i965->wrapper_pdrvctx = NULL;
6450 wrapper_pdrvctx = calloc(1, sizeof(*wrapper_pdrvctx));
6451 vtable = calloc(1, sizeof(*vtable));
6453 if (!wrapper_pdrvctx || !vtable) {
6454 fprintf(stderr, "Failed to allocate memory for wrapper \n");
6455 free(wrapper_pdrvctx);
6457 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6460 /* use the same drm_state with CTX */
6461 wrapper_pdrvctx->drm_state = ctx->drm_state;
6462 wrapper_pdrvctx->display_type = ctx->display_type;
6463 wrapper_pdrvctx->vtable = vtable;
6465 search_path = VA_DRIVERS_PATH;
6466 search_path = strdup((const char *)search_path);
6468 driver_dir = strtok_r(search_path, ":", &saveptr);
6469 while (driver_dir && !driver_loaded) {
6470 memset(driver_path, 0, sizeof(driver_path));
6471 sprintf(driver_path, "%s/%s%s", driver_dir, driver_name, DRIVER_EXTENSION);
6473 handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
6475 fprintf(stderr, "failed to open %s\n", driver_path);
6476 driver_dir = strtok_r(NULL, ":", &saveptr);
6480 VADriverInit init_func = NULL;
6481 char init_func_s[256];
6484 static const struct {
6487 } compatible_versions[] = {
6488 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
6497 for (i = 0; compatible_versions[i].major >= 0; i++) {
6498 snprintf(init_func_s, sizeof(init_func_s),
6499 "__vaDriverInit_%d_%d",
6500 compatible_versions[i].major,
6501 compatible_versions[i].minor);
6502 init_func = (VADriverInit)dlsym(handle, init_func_s);
6507 if (compatible_versions[i].major < 0) {
6509 fprintf(stderr, "%s has no function %s\n",
6510 driver_path, init_func_s);
6511 driver_dir = strtok_r(NULL, ":", &saveptr);
6516 va_status = (*init_func)(wrapper_pdrvctx);
6518 if (va_status != VA_STATUS_SUCCESS) {
6520 fprintf(stderr, "%s init failed\n", driver_path);
6521 driver_dir = strtok_r(NULL, ":", &saveptr);
6525 wrapper_pdrvctx->handle = handle;
6526 driver_loaded = true;
6532 if (driver_loaded) {
6533 i965->wrapper_pdrvctx = wrapper_pdrvctx;
6534 return VA_STATUS_SUCCESS;
6536 fprintf(stderr, "Failed to wrapper %s%s\n", driver_name, DRIVER_EXTENSION);
6538 free(wrapper_pdrvctx);
6539 return VA_STATUS_ERROR_OPERATION_FAILED;
6545 i965_Init(VADriverContextP ctx)
6547 struct i965_driver_data *i965 = i965_driver_data(ctx);
6549 const char *chipset;
6551 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
6552 if ((i965_sub_ops[i].display_type == 0 ||
6553 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
6554 !i965_sub_ops[i].init(ctx))
6558 if (i == ARRAY_ELEMS(i965_sub_ops)) {
6559 switch (i965->intel.device_id) {
6561 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
6562 #include "i965_pciids.h"
6564 chipset = "Unknown Intel Chipset";
6568 if (!ensure_vendor_string(i965, chipset))
6569 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6571 i965->current_context_id = VA_INVALID_ID;
6573 if (i965->codec_info && i965->codec_info->preinit_hw_codec)
6574 i965->codec_info->preinit_hw_codec(ctx, i965->codec_info);
6576 #if HAVE_HYBRID_CODEC
6577 i965_initialize_wrapper(ctx, "hybrid");
6580 return VA_STATUS_SUCCESS;
6584 for (; i >= 0; i--) {
6585 if (i965_sub_ops[i].display_type == 0 ||
6586 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6587 i965_sub_ops[i].terminate(ctx);
6591 return VA_STATUS_ERROR_UNKNOWN;
6596 i965_Terminate(VADriverContextP ctx)
6598 struct i965_driver_data *i965 = i965_driver_data(ctx);
6602 if (i965->wrapper_pdrvctx) {
6603 VADriverContextP pdrvctx;
6604 pdrvctx = i965->wrapper_pdrvctx;
6605 if (pdrvctx->handle) {
6606 pdrvctx->vtable->vaTerminate(pdrvctx);
6607 dlclose(pdrvctx->handle);
6608 pdrvctx->handle = NULL;
6610 free(pdrvctx->vtable);
6612 i965->wrapper_pdrvctx = NULL;
6615 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
6616 if (i965_sub_ops[i - 1].display_type == 0 ||
6617 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
6618 i965_sub_ops[i - 1].terminate(ctx);
6622 ctx->pDriverData = NULL;
6625 return VA_STATUS_SUCCESS;
6629 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
6632 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
6634 struct VADriverVTable * const vtable = ctx->vtable;
6635 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
6637 struct i965_driver_data *i965;
6638 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
6640 ctx->version_major = VA_MAJOR_VERSION;
6641 ctx->version_minor = VA_MINOR_VERSION;
6642 ctx->max_profiles = I965_MAX_PROFILES;
6643 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
6644 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
6645 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
6646 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
6647 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
6649 vtable->vaTerminate = i965_Terminate;
6650 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
6651 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
6652 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
6653 vtable->vaCreateConfig = i965_CreateConfig;
6654 vtable->vaDestroyConfig = i965_DestroyConfig;
6655 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
6656 vtable->vaCreateSurfaces = i965_CreateSurfaces;
6657 vtable->vaDestroySurfaces = i965_DestroySurfaces;
6658 vtable->vaCreateContext = i965_CreateContext;
6659 vtable->vaDestroyContext = i965_DestroyContext;
6660 vtable->vaCreateBuffer = i965_CreateBuffer;
6661 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
6662 vtable->vaMapBuffer = i965_MapBuffer;
6663 vtable->vaUnmapBuffer = i965_UnmapBuffer;
6664 vtable->vaDestroyBuffer = i965_DestroyBuffer;
6665 vtable->vaBeginPicture = i965_BeginPicture;
6666 vtable->vaRenderPicture = i965_RenderPicture;
6667 vtable->vaEndPicture = i965_EndPicture;
6668 vtable->vaSyncSurface = i965_SyncSurface;
6669 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
6670 vtable->vaPutSurface = i965_PutSurface;
6671 vtable->vaQueryImageFormats = i965_QueryImageFormats;
6672 vtable->vaCreateImage = i965_CreateImage;
6673 vtable->vaDeriveImage = i965_DeriveImage;
6674 vtable->vaDestroyImage = i965_DestroyImage;
6675 vtable->vaSetImagePalette = i965_SetImagePalette;
6676 vtable->vaGetImage = i965_GetImage;
6677 vtable->vaPutImage = i965_PutImage;
6678 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
6679 vtable->vaCreateSubpicture = i965_CreateSubpicture;
6680 vtable->vaDestroySubpicture = i965_DestroySubpicture;
6681 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
6682 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
6683 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
6684 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
6685 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
6686 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
6687 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
6688 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
6689 vtable->vaBufferInfo = i965_BufferInfo;
6690 vtable->vaLockSurface = i965_LockSurface;
6691 vtable->vaUnlockSurface = i965_UnlockSurface;
6692 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
6693 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
6694 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
6697 vtable->vaAcquireBufferHandle = i965_AcquireBufferHandle;
6698 vtable->vaReleaseBufferHandle = i965_ReleaseBufferHandle;
6700 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
6701 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
6702 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
6704 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
6707 ctx->pDriverData = NULL;
6709 return VA_STATUS_ERROR_ALLOCATION_FAILED;
6712 i965->wrapper_pdrvctx = NULL;
6713 ctx->pDriverData = (void *)i965;
6714 ret = i965_Init(ctx);
6716 if (ret == VA_STATUS_SUCCESS) {
6717 ctx->str_vendor = i965->va_vendor;
6720 ctx->pDriverData = NULL;