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>
33 # include "i965_output_dri.h"
36 #ifdef HAVE_VA_WAYLAND
37 # include "i965_output_wayland.h"
40 #include "intel_driver.h"
41 #include "intel_memman.h"
42 #include "intel_batchbuffer.h"
43 #include "i965_defines.h"
44 #include "i965_drv_video.h"
45 #include "i965_decoder.h"
46 #include "i965_encoder.h"
48 #define CONFIG_ID_OFFSET 0x01000000
49 #define CONTEXT_ID_OFFSET 0x02000000
50 #define SURFACE_ID_OFFSET 0x04000000
51 #define BUFFER_ID_OFFSET 0x08000000
52 #define IMAGE_ID_OFFSET 0x0a000000
53 #define SUBPIC_ID_OFFSET 0x10000000
55 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
58 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
61 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
64 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
67 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
70 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
73 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
75 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
77 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
79 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
81 #define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \
84 #define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \
88 static int get_sampling_from_fourcc(unsigned int fourcc);
90 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
91 #define IS_VA_X11(ctx) \
92 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_X11)
94 /* Check whether we are rendering to Wayland */
95 #define IS_VA_WAYLAND(ctx) \
96 (((ctx)->display_type & VA_DISPLAY_MAJOR_MASK) == VA_DISPLAY_WAYLAND)
99 #define I965_2BITS (I965_BIT << 1)
100 #define I965_4BITS (I965_BIT << 2)
101 #define I965_8BITS (I965_BIT << 3)
102 #define I965_16BITS (I965_BIT << 4)
103 #define I965_32BITS (I965_BIT << 5)
115 /* hfactor, vfactor, num_planes, bpp[], num_components, components[] */
116 #define I_NV12 2, 2, 2, {I965_8BITS, I965_4BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_1, OFFSET_0}, {PLANE_1, OFFSET_8} }
117 #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} }
118 #define I_IYUV I_I420
119 #define I_IMC3 I_I420
120 #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} }
121 #define I_IMC1 I_YV12
123 #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} }
124 #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} }
125 #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} }
126 #define I_YUY2 2, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_24} }
127 #define I_UYVY 2, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
129 #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} }
131 #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} }
133 #define I_Y800 1, 1, 1, {I965_8BITS}, 1, { {PLANE_0, OFFSET_0} }
135 #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} }
136 #define I_RGBX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_16} }
137 #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} }
138 #define I_BGRX 1, 1, 1, {I965_32BITS}, 3, { {PLANE_0, OFFSET_16}, {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
140 #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} }
141 #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} }
143 #define I_IA88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_8} }
144 #define I_AI88 1, 1, 1, {I965_16BITS}, 2, { {PLANE_0, OFFSET_8}, {PLANE_0, OFFSET_0} }
146 #define I_IA44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_0}, {PLANE_0, OFFSET_4} }
147 #define I_AI44 1, 1, 1, {I965_8BITS}, 2, { {PLANE_0, OFFSET_4}, {PLANE_0, OFFSET_0} }
152 #define I_SI (I_S | I_I)
154 #define DEF_FOUCC_INFO(FOURCC, FORMAT, SUB, FLAG) { VA_FOURCC_##FOURCC, I965_COLOR_##FORMAT, SUBSAMPLE_##SUB, FLAG, I_##FOURCC }
155 #define DEF_YUV(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, YUV, SUB, FLAG)
156 #define DEF_RGB(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, RGB, SUB, FLAG)
157 #define DEF_INDEX(FOURCC, SUB, FLAG) DEF_FOUCC_INFO(FOURCC, INDEX, SUB, FLAG)
159 static const i965_fourcc_info i965_fourcc_infos[] = {
160 DEF_YUV(NV12, YUV420, I_SI),
161 DEF_YUV(I420, YUV420, I_SI),
162 DEF_YUV(IYUV, YUV420, I_S),
163 DEF_YUV(IMC3, YUV420, I_S),
164 DEF_YUV(YV12, YUV420, I_SI),
165 DEF_YUV(IMC1, YUV420, I_S),
167 DEF_YUV(422H, YUV422H, I_SI),
168 DEF_YUV(422V, YUV422V, I_S),
169 DEF_YUV(YV16, YUV422H, I_S),
170 DEF_YUV(YUY2, YUV422H, I_SI),
171 DEF_YUV(UYVY, YUV422H, I_SI),
173 DEF_YUV(444P, YUV444, I_S),
175 DEF_YUV(411P, YUV411, I_S),
177 DEF_YUV(Y800, YUV400, I_S),
179 DEF_RGB(RGBA, RGBX, I_SI),
180 DEF_RGB(RGBX, RGBX, I_SI),
181 DEF_RGB(BGRA, RGBX, I_SI),
182 DEF_RGB(BGRX, RGBX, I_SI),
184 DEF_RGB(ARGB, RGBX, I_I),
185 DEF_RGB(ABGR, RGBX, I_I),
187 DEF_INDEX(IA88, RGBX, I_I),
188 DEF_INDEX(AI88, RGBX, I_I),
190 DEF_INDEX(IA44, RGBX, I_I),
191 DEF_INDEX(AI44, RGBX, I_I)
194 const i965_fourcc_info *
195 get_fourcc_info(unsigned int fourcc)
199 for (i = 0; ARRAY_ELEMS(i965_fourcc_infos); i++) {
200 const i965_fourcc_info * const info = &i965_fourcc_infos[i];
202 if (info->fourcc == fourcc)
210 I965_SURFACETYPE_RGBA = 1,
211 I965_SURFACETYPE_YUV,
212 I965_SURFACETYPE_INDEXED
215 /* List of supported display attributes */
216 static const VADisplayAttribute i965_display_attributes[] = {
218 VADisplayAttribBrightness,
219 -100, 100, DEFAULT_BRIGHTNESS,
220 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
224 VADisplayAttribContrast,
225 0, 100, DEFAULT_CONTRAST,
226 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
231 -180, 180, DEFAULT_HUE,
232 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
236 VADisplayAttribSaturation,
237 0, 100, DEFAULT_SATURATION,
238 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
242 VADisplayAttribRotation,
243 0, 3, VA_ROTATION_NONE,
244 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
248 /* List of supported image formats */
251 VAImageFormat va_format;
252 } i965_image_format_map_t;
254 static const i965_image_format_map_t
255 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
256 { I965_SURFACETYPE_YUV,
257 { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
258 { I965_SURFACETYPE_YUV,
259 { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
260 { I965_SURFACETYPE_YUV,
261 { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
262 { I965_SURFACETYPE_YUV,
263 { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
264 { I965_SURFACETYPE_YUV,
265 { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
266 { I965_SURFACETYPE_YUV,
267 { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
268 { I965_SURFACETYPE_RGBA,
269 { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
270 { I965_SURFACETYPE_RGBA,
271 { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
274 /* List of supported subpicture formats */
278 VAImageFormat va_format;
279 unsigned int va_flags;
280 } i965_subpic_format_map_t;
282 #define COMMON_SUBPICTURE_FLAGS \
283 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
284 VA_SUBPICTURE_GLOBAL_ALPHA)
286 static const i965_subpic_format_map_t
287 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
288 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
289 { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
290 COMMON_SUBPICTURE_FLAGS },
291 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
292 { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
293 COMMON_SUBPICTURE_FLAGS },
294 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
295 { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
296 COMMON_SUBPICTURE_FLAGS },
297 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
298 { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
299 COMMON_SUBPICTURE_FLAGS },
300 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
301 { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
302 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
303 COMMON_SUBPICTURE_FLAGS },
304 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
305 { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
306 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
307 COMMON_SUBPICTURE_FLAGS },
310 static const i965_subpic_format_map_t *
311 get_subpic_format(const VAImageFormat *va_format)
314 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
315 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
316 if (m->va_format.fourcc == va_format->fourcc &&
317 (m->type == I965_SURFACETYPE_RGBA ?
318 (m->va_format.byte_order == va_format->byte_order &&
319 m->va_format.red_mask == va_format->red_mask &&
320 m->va_format.green_mask == va_format->green_mask &&
321 m->va_format.blue_mask == va_format->blue_mask &&
322 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
328 #define I965_PACKED_HEADER_BASE 0
329 #define I965_PACKED_MISC_HEADER_BASE 3
332 va_enc_packed_type_to_idx(int packed_type)
336 if (packed_type & VAEncPackedHeaderMiscMask) {
337 idx = I965_PACKED_MISC_HEADER_BASE;
338 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
339 ASSERT_RET(packed_type > 0, 0);
340 idx += (packed_type - 1);
342 idx = I965_PACKED_HEADER_BASE;
344 switch (packed_type) {
345 case VAEncPackedHeaderSequence:
346 idx = I965_PACKED_HEADER_BASE + 0;
349 case VAEncPackedHeaderPicture:
350 idx = I965_PACKED_HEADER_BASE + 1;
353 case VAEncPackedHeaderSlice:
354 idx = I965_PACKED_HEADER_BASE + 2;
358 /* Should not get here */
364 ASSERT_RET(idx < 4, 0);
369 i965_QueryConfigProfiles(VADriverContextP ctx,
370 VAProfile *profile_list, /* out */
371 int *num_profiles) /* out */
373 struct i965_driver_data * const i965 = i965_driver_data(ctx);
376 if (HAS_MPEG2_DECODING(i965) ||
377 HAS_MPEG2_ENCODING(i965)) {
378 profile_list[i++] = VAProfileMPEG2Simple;
379 profile_list[i++] = VAProfileMPEG2Main;
382 if (HAS_H264_DECODING(i965) ||
383 HAS_H264_ENCODING(i965)) {
384 profile_list[i++] = VAProfileH264ConstrainedBaseline;
385 profile_list[i++] = VAProfileH264Main;
386 profile_list[i++] = VAProfileH264High;
389 if (HAS_VC1_DECODING(i965)) {
390 profile_list[i++] = VAProfileVC1Simple;
391 profile_list[i++] = VAProfileVC1Main;
392 profile_list[i++] = VAProfileVC1Advanced;
396 profile_list[i++] = VAProfileNone;
399 if (HAS_JPEG_DECODING(i965)) {
400 profile_list[i++] = VAProfileJPEGBaseline;
403 if (HAS_VP8_DECODING(i965) ||
404 HAS_VP8_ENCODING(i965)) {
405 profile_list[i++] = VAProfileVP8Version0_3;
408 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
409 ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
412 return VA_STATUS_SUCCESS;
416 i965_QueryConfigEntrypoints(VADriverContextP ctx,
418 VAEntrypoint *entrypoint_list, /* out */
419 int *num_entrypoints) /* out */
421 struct i965_driver_data * const i965 = i965_driver_data(ctx);
425 case VAProfileMPEG2Simple:
426 case VAProfileMPEG2Main:
427 if (HAS_MPEG2_DECODING(i965))
428 entrypoint_list[n++] = VAEntrypointVLD;
430 if (HAS_MPEG2_ENCODING(i965))
431 entrypoint_list[n++] = VAEntrypointEncSlice;
435 case VAProfileH264ConstrainedBaseline:
436 case VAProfileH264Main:
437 case VAProfileH264High:
438 if (HAS_H264_DECODING(i965))
439 entrypoint_list[n++] = VAEntrypointVLD;
441 if (HAS_H264_ENCODING(i965))
442 entrypoint_list[n++] = VAEntrypointEncSlice;
446 case VAProfileVC1Simple:
447 case VAProfileVC1Main:
448 case VAProfileVC1Advanced:
449 if (HAS_VC1_DECODING(i965))
450 entrypoint_list[n++] = VAEntrypointVLD;
455 entrypoint_list[n++] = VAEntrypointVideoProc;
458 case VAProfileJPEGBaseline:
459 if (HAS_JPEG_DECODING(i965))
460 entrypoint_list[n++] = VAEntrypointVLD;
463 case VAProfileVP8Version0_3:
464 if (HAS_VP8_DECODING(i965))
465 entrypoint_list[n++] = VAEntrypointVLD;
467 if (HAS_VP8_ENCODING(i965))
468 entrypoint_list[n++] = VAEntrypointEncSlice;
474 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
475 ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
476 *num_entrypoints = n;
477 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
481 i965_validate_config(VADriverContextP ctx, VAProfile profile,
482 VAEntrypoint entrypoint)
484 struct i965_driver_data * const i965 = i965_driver_data(ctx);
487 /* Validate profile & entrypoint */
489 case VAProfileMPEG2Simple:
490 case VAProfileMPEG2Main:
491 if ((HAS_MPEG2_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
492 (HAS_MPEG2_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
493 va_status = VA_STATUS_SUCCESS;
495 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
499 case VAProfileH264ConstrainedBaseline:
500 case VAProfileH264Main:
501 case VAProfileH264High:
502 if ((HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
503 (HAS_H264_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
504 va_status = VA_STATUS_SUCCESS;
506 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
510 case VAProfileVC1Simple:
511 case VAProfileVC1Main:
512 case VAProfileVC1Advanced:
513 if (HAS_VC1_DECODING(i965) && entrypoint == VAEntrypointVLD) {
514 va_status = VA_STATUS_SUCCESS;
516 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
521 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
522 va_status = VA_STATUS_SUCCESS;
524 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
528 case VAProfileJPEGBaseline:
529 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD) {
530 va_status = VA_STATUS_SUCCESS;
532 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
536 case VAProfileVP8Version0_3:
537 if ((HAS_VP8_DECODING(i965) && entrypoint == VAEntrypointVLD) ||
538 (HAS_VP8_ENCODING(i965) && entrypoint == VAEntrypointEncSlice)) {
539 va_status = VA_STATUS_SUCCESS;
541 va_status = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
546 va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
553 i965_get_default_chroma_formats(VADriverContextP ctx, VAProfile profile,
554 VAEntrypoint entrypoint)
556 struct i965_driver_data * const i965 = i965_driver_data(ctx);
557 uint32_t chroma_formats = VA_RT_FORMAT_YUV420;
560 case VAProfileH264ConstrainedBaseline:
561 case VAProfileH264Main:
562 case VAProfileH264High:
563 if (HAS_H264_DECODING(i965) && entrypoint == VAEntrypointVLD)
564 chroma_formats |= i965->codec_info->h264_dec_chroma_formats;
567 case VAProfileJPEGBaseline:
568 if (HAS_JPEG_DECODING(i965) && entrypoint == VAEntrypointVLD)
569 chroma_formats |= i965->codec_info->jpeg_dec_chroma_formats;
575 return chroma_formats;
579 i965_GetConfigAttributes(VADriverContextP ctx,
581 VAEntrypoint entrypoint,
582 VAConfigAttrib *attrib_list, /* in/out */
588 va_status = i965_validate_config(ctx, profile, entrypoint);
589 if (va_status != VA_STATUS_SUCCESS)
592 /* Other attributes don't seem to be defined */
593 /* What to do if we don't know the attribute? */
594 for (i = 0; i < num_attribs; i++) {
595 switch (attrib_list[i].type) {
596 case VAConfigAttribRTFormat:
597 attrib_list[i].value = i965_get_default_chroma_formats(ctx,
598 profile, entrypoint);
601 case VAConfigAttribRateControl:
602 if (entrypoint == VAEntrypointEncSlice) {
603 attrib_list[i].value = VA_RC_CQP;
605 if (profile != VAProfileMPEG2Main &&
606 profile != VAProfileMPEG2Simple)
607 attrib_list[i].value |= VA_RC_CBR;
611 case VAConfigAttribEncPackedHeaders:
612 if (entrypoint == VAEntrypointEncSlice) {
613 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
617 case VAConfigAttribEncMaxRefFrames:
618 if (entrypoint == VAEntrypointEncSlice) {
619 attrib_list[i].value = (1 << 16) | (1 << 0);
625 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
630 return VA_STATUS_SUCCESS;
634 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
636 object_heap_free(heap, obj);
639 static VAConfigAttrib *
640 i965_lookup_config_attribute(struct object_config *obj_config,
641 VAConfigAttribType type)
645 for (i = 0; i < obj_config->num_attribs; i++) {
646 VAConfigAttrib * const attrib = &obj_config->attrib_list[i];
647 if (attrib->type == type)
654 i965_append_config_attribute(struct object_config *obj_config,
655 const VAConfigAttrib *new_attrib)
657 VAConfigAttrib *attrib;
659 if (obj_config->num_attribs >= I965_MAX_CONFIG_ATTRIBUTES)
660 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
662 attrib = &obj_config->attrib_list[obj_config->num_attribs++];
663 attrib->type = new_attrib->type;
664 attrib->value = new_attrib->value;
665 return VA_STATUS_SUCCESS;
669 i965_ensure_config_attribute(struct object_config *obj_config,
670 const VAConfigAttrib *new_attrib)
672 VAConfigAttrib *attrib;
674 /* Check for existing attributes */
675 attrib = i965_lookup_config_attribute(obj_config, new_attrib->type);
677 /* Update existing attribute */
678 attrib->value = new_attrib->value;
679 return VA_STATUS_SUCCESS;
681 return i965_append_config_attribute(obj_config, new_attrib);
685 i965_CreateConfig(VADriverContextP ctx,
687 VAEntrypoint entrypoint,
688 VAConfigAttrib *attrib_list,
690 VAConfigID *config_id) /* out */
692 struct i965_driver_data * const i965 = i965_driver_data(ctx);
693 struct object_config *obj_config;
698 vaStatus = i965_validate_config(ctx, profile, entrypoint);
699 if (VA_STATUS_SUCCESS != vaStatus) {
703 configID = NEW_CONFIG_ID();
704 obj_config = CONFIG(configID);
706 if (NULL == obj_config) {
707 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
711 obj_config->profile = profile;
712 obj_config->entrypoint = entrypoint;
713 obj_config->num_attribs = 0;
715 for (i = 0; i < num_attribs; i++) {
716 vaStatus = i965_ensure_config_attribute(obj_config, &attrib_list[i]);
717 if (vaStatus != VA_STATUS_SUCCESS)
721 if (vaStatus == VA_STATUS_SUCCESS) {
722 VAConfigAttrib attrib, *attrib_found;
723 attrib.type = VAConfigAttribRTFormat;
724 attrib.value = i965_get_default_chroma_formats(ctx, profile, entrypoint);
725 attrib_found = i965_lookup_config_attribute(obj_config, attrib.type);
726 if (!attrib_found || !attrib_found->value)
727 vaStatus = i965_append_config_attribute(obj_config, &attrib);
728 else if (!(attrib_found->value & attrib.value))
729 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
733 if (VA_STATUS_SUCCESS != vaStatus) {
734 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
736 *config_id = configID;
743 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
745 struct i965_driver_data *i965 = i965_driver_data(ctx);
746 struct object_config *obj_config = CONFIG(config_id);
749 if (NULL == obj_config) {
750 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
754 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
755 return VA_STATUS_SUCCESS;
758 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
759 VAConfigID config_id,
760 VAProfile *profile, /* out */
761 VAEntrypoint *entrypoint, /* out */
762 VAConfigAttrib *attrib_list, /* out */
763 int *num_attribs) /* out */
765 struct i965_driver_data *i965 = i965_driver_data(ctx);
766 struct object_config *obj_config = CONFIG(config_id);
767 VAStatus vaStatus = VA_STATUS_SUCCESS;
770 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
771 *profile = obj_config->profile;
772 *entrypoint = obj_config->entrypoint;
773 *num_attribs = obj_config->num_attribs;
775 for(i = 0; i < obj_config->num_attribs; i++) {
776 attrib_list[i] = obj_config->attrib_list[i];
783 i965_destroy_surface_storage(struct object_surface *obj_surface)
788 dri_bo_unreference(obj_surface->bo);
789 obj_surface->bo = NULL;
791 if (obj_surface->free_private_data != NULL) {
792 obj_surface->free_private_data(&obj_surface->private_data);
793 obj_surface->private_data = NULL;
798 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
800 struct object_surface *obj_surface = (struct object_surface *)obj;
802 i965_destroy_surface_storage(obj_surface);
803 object_heap_free(heap, obj);
807 i965_surface_native_memory(VADriverContextP ctx,
808 struct object_surface *obj_surface,
812 struct i965_driver_data *i965 = i965_driver_data(ctx);
813 int tiling = HAS_TILED_SURFACE(i965);
815 if (!expected_fourcc)
816 return VA_STATUS_SUCCESS;
818 // todo, should we disable tiling for 422 format?
819 if (expected_fourcc == VA_FOURCC_I420 ||
820 expected_fourcc == VA_FOURCC_IYUV ||
821 expected_fourcc == VA_FOURCC_YV12 ||
822 expected_fourcc == VA_FOURCC_YV16)
825 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
827 return VA_STATUS_SUCCESS;
831 i965_suface_external_memory(VADriverContextP ctx,
832 struct object_surface *obj_surface,
833 int external_memory_type,
834 VASurfaceAttribExternalBuffers *memory_attibute,
837 struct i965_driver_data *i965 = i965_driver_data(ctx);
839 if (!memory_attibute ||
840 !memory_attibute->buffers ||
841 index > memory_attibute->num_buffers)
842 return VA_STATUS_ERROR_INVALID_PARAMETER;
844 ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
845 ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
846 ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
848 obj_surface->fourcc = memory_attibute->pixel_format;
849 obj_surface->width = memory_attibute->pitches[0];
850 obj_surface->size = memory_attibute->data_size;
852 if (memory_attibute->num_planes == 1)
853 obj_surface->height = memory_attibute->data_size / obj_surface->width;
855 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
857 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
858 obj_surface->x_cr_offset = 0;
860 switch (obj_surface->fourcc) {
862 ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
863 ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
865 obj_surface->subsampling = SUBSAMPLE_YUV420;
866 obj_surface->y_cb_offset = obj_surface->height;
867 obj_surface->y_cr_offset = obj_surface->height;
868 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
869 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
870 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
876 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
877 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
879 obj_surface->subsampling = SUBSAMPLE_YUV420;
880 obj_surface->y_cr_offset = obj_surface->height;
881 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
882 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
883 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
884 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
891 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
892 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
894 obj_surface->subsampling = SUBSAMPLE_YUV420;
895 obj_surface->y_cb_offset = obj_surface->height;
896 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
897 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
898 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
899 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
905 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
907 obj_surface->subsampling = SUBSAMPLE_YUV422H;
908 obj_surface->y_cb_offset = 0;
909 obj_surface->y_cr_offset = 0;
910 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
911 obj_surface->cb_cr_height = obj_surface->orig_height;
912 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
920 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
922 obj_surface->subsampling = SUBSAMPLE_RGBX;
923 obj_surface->y_cb_offset = 0;
924 obj_surface->y_cr_offset = 0;
925 obj_surface->cb_cr_width = 0;
926 obj_surface->cb_cr_height = 0;
927 obj_surface->cb_cr_pitch = 0;
931 case VA_FOURCC_Y800: /* monochrome surface */
932 ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
934 obj_surface->subsampling = SUBSAMPLE_YUV400;
935 obj_surface->y_cb_offset = 0;
936 obj_surface->y_cr_offset = 0;
937 obj_surface->cb_cr_width = 0;
938 obj_surface->cb_cr_height = 0;
939 obj_surface->cb_cr_pitch = 0;
944 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
945 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
947 obj_surface->subsampling = SUBSAMPLE_YUV411;
948 obj_surface->y_cb_offset = 0;
949 obj_surface->y_cr_offset = 0;
950 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
951 obj_surface->cb_cr_height = obj_surface->orig_height;
952 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
957 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
958 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
960 obj_surface->subsampling = SUBSAMPLE_YUV422H;
961 obj_surface->y_cb_offset = obj_surface->height;
962 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
963 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
964 obj_surface->cb_cr_height = obj_surface->orig_height;
965 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
970 assert(memory_attibute->num_planes == 3);
971 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
973 obj_surface->subsampling = SUBSAMPLE_YUV422H;
974 obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
975 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
976 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
977 obj_surface->cb_cr_height = obj_surface->orig_height;
978 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
983 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
984 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
986 obj_surface->subsampling = SUBSAMPLE_YUV422H;
987 obj_surface->y_cb_offset = obj_surface->height;
988 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
989 obj_surface->cb_cr_width = obj_surface->orig_width;
990 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
991 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
996 ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
997 ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
999 obj_surface->subsampling = SUBSAMPLE_YUV444;
1000 obj_surface->y_cb_offset = obj_surface->height;
1001 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
1002 obj_surface->cb_cr_width = obj_surface->orig_width;
1003 obj_surface->cb_cr_height = obj_surface->orig_height;
1004 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1010 return VA_STATUS_ERROR_INVALID_PARAMETER;
1013 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1014 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1015 "gem flinked vaapi surface",
1016 memory_attibute->buffers[index]);
1017 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1018 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1019 memory_attibute->buffers[index],
1022 if (!obj_surface->bo)
1023 return VA_STATUS_ERROR_INVALID_PARAMETER;
1025 return VA_STATUS_SUCCESS;
1028 /* byte-per-pixel of the first plane */
1030 bpp_1stplane_by_fourcc(unsigned int fourcc)
1032 const i965_fourcc_info *info = get_fourcc_info(fourcc);
1034 if (info && (info->flag & I_S))
1035 return info->bpp[0] / 8;
1041 i965_CreateSurfaces2(
1042 VADriverContextP ctx,
1043 unsigned int format,
1045 unsigned int height,
1046 VASurfaceID *surfaces,
1047 unsigned int num_surfaces,
1048 VASurfaceAttrib *attrib_list,
1049 unsigned int num_attribs
1052 struct i965_driver_data *i965 = i965_driver_data(ctx);
1054 VAStatus vaStatus = VA_STATUS_SUCCESS;
1055 int expected_fourcc = 0;
1056 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
1057 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
1059 for (i = 0; i < num_attribs && attrib_list; i++) {
1060 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
1061 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1062 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1063 expected_fourcc = attrib_list[i].value.value.i;
1066 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
1067 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1069 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
1071 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1072 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1073 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1074 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1075 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
1076 memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
1079 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1080 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1081 ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
1082 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1086 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1087 * for post-processing (including color conversion) */
1088 if (VA_RT_FORMAT_YUV420 != format &&
1089 VA_RT_FORMAT_YUV422 != format &&
1090 VA_RT_FORMAT_YUV444 != format &&
1091 VA_RT_FORMAT_YUV411 != format &&
1092 VA_RT_FORMAT_YUV400 != format &&
1093 VA_RT_FORMAT_RGB32 != format) {
1094 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1097 for (i = 0; i < num_surfaces; i++) {
1098 int surfaceID = NEW_SURFACE_ID();
1099 struct object_surface *obj_surface = SURFACE(surfaceID);
1101 if (NULL == obj_surface) {
1102 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1106 surfaces[i] = surfaceID;
1107 obj_surface->status = VASurfaceReady;
1108 obj_surface->orig_width = width;
1109 obj_surface->orig_height = height;
1110 obj_surface->user_disable_tiling = false;
1111 obj_surface->user_h_stride_set = false;
1112 obj_surface->user_v_stride_set = false;
1114 obj_surface->subpic_render_idx = 0;
1115 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1116 obj_surface->subpic[j] = VA_INVALID_ID;
1117 obj_surface->obj_subpic[j] = NULL;
1120 assert(i965->codec_info->min_linear_wpitch);
1121 assert(i965->codec_info->min_linear_hpitch);
1122 obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
1123 obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
1124 obj_surface->flags = SURFACE_REFERENCED;
1125 obj_surface->fourcc = 0;
1126 obj_surface->bo = NULL;
1127 obj_surface->locked_image_id = VA_INVALID_ID;
1128 obj_surface->private_data = NULL;
1129 obj_surface->free_private_data = NULL;
1130 obj_surface->subsampling = SUBSAMPLE_YUV420;
1132 switch (memory_type) {
1133 case I965_SURFACE_MEM_NATIVE:
1134 if (memory_attibute) {
1135 if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
1136 obj_surface->user_disable_tiling = true;
1138 if (memory_attibute->pixel_format) {
1139 if (expected_fourcc)
1140 ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1142 expected_fourcc = memory_attibute->pixel_format;
1144 ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
1145 if (memory_attibute->pitches[0]) {
1146 int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
1147 ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
1148 obj_surface->width = memory_attibute->pitches[0]/bpp_1stplane;
1149 obj_surface->user_h_stride_set = true;
1150 ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1151 ASSERT_RET(obj_surface->width >= width, VA_STATUS_ERROR_INVALID_PARAMETER);
1153 if (memory_attibute->offsets[1]) {
1154 ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
1155 obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
1156 obj_surface->user_v_stride_set = true;
1157 ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1158 ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
1162 i965_surface_native_memory(ctx,
1168 case I965_SURFACE_MEM_GEM_FLINK:
1169 case I965_SURFACE_MEM_DRM_PRIME:
1170 i965_suface_external_memory(ctx,
1179 /* Error recovery */
1180 if (VA_STATUS_SUCCESS != vaStatus) {
1181 /* surfaces[i-1] was the last successful allocation */
1183 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1185 surfaces[i] = VA_INVALID_SURFACE;
1186 assert(obj_surface);
1187 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1195 i965_CreateSurfaces(VADriverContextP ctx,
1200 VASurfaceID *surfaces) /* out */
1202 return i965_CreateSurfaces2(ctx,
1213 i965_DestroySurfaces(VADriverContextP ctx,
1214 VASurfaceID *surface_list,
1217 struct i965_driver_data *i965 = i965_driver_data(ctx);
1220 for (i = num_surfaces; i--; ) {
1221 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1223 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
1224 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1227 return VA_STATUS_SUCCESS;
1231 i965_QueryImageFormats(VADriverContextP ctx,
1232 VAImageFormat *format_list, /* out */
1233 int *num_formats) /* out */
1237 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1238 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1240 format_list[n] = m->va_format;
1246 return VA_STATUS_SUCCESS;
1250 * Guess the format when the usage of a VA surface is unknown
1251 * 1. Without a valid context: YV12
1252 * 2. The current context is valid:
1253 * a) always NV12 on GEN6 and later
1254 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1257 i965_guess_surface_format(VADriverContextP ctx,
1258 VASurfaceID surface,
1259 unsigned int *fourcc,
1260 unsigned int *is_tiled)
1262 struct i965_driver_data *i965 = i965_driver_data(ctx);
1263 struct object_context *obj_context = NULL;
1264 struct object_config *obj_config = NULL;
1266 *fourcc = VA_FOURCC_YV12;
1269 if (i965->current_context_id == VA_INVALID_ID)
1272 obj_context = CONTEXT(i965->current_context_id);
1277 obj_config = obj_context->obj_config;
1283 if (IS_GEN6(i965->intel.device_info) ||
1284 IS_GEN7(i965->intel.device_info) ||
1285 IS_GEN8(i965->intel.device_info)) {
1286 *fourcc = VA_FOURCC_NV12;
1291 switch (obj_config->profile) {
1292 case VAProfileMPEG2Simple:
1293 case VAProfileMPEG2Main:
1294 *fourcc = VA_FOURCC_I420;
1299 *fourcc = VA_FOURCC_NV12;
1306 i965_QuerySubpictureFormats(VADriverContextP ctx,
1307 VAImageFormat *format_list, /* out */
1308 unsigned int *flags, /* out */
1309 unsigned int *num_formats) /* out */
1313 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1314 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1316 format_list[n] = m->va_format;
1318 flags[n] = m->va_flags;
1324 return VA_STATUS_SUCCESS;
1328 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1330 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1332 object_heap_free(heap, obj);
1336 i965_CreateSubpicture(VADriverContextP ctx,
1338 VASubpictureID *subpicture) /* out */
1340 struct i965_driver_data *i965 = i965_driver_data(ctx);
1341 VASubpictureID subpicID = NEW_SUBPIC_ID()
1342 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1345 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1347 struct object_image *obj_image = IMAGE(image);
1349 return VA_STATUS_ERROR_INVALID_IMAGE;
1351 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1353 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1355 *subpicture = subpicID;
1356 obj_subpic->image = image;
1357 obj_subpic->obj_image = obj_image;
1358 obj_subpic->format = m->format;
1359 obj_subpic->width = obj_image->image.width;
1360 obj_subpic->height = obj_image->image.height;
1361 obj_subpic->pitch = obj_image->image.pitches[0];
1362 obj_subpic->bo = obj_image->bo;
1363 obj_subpic->global_alpha = 1.0;
1365 return VA_STATUS_SUCCESS;
1369 i965_DestroySubpicture(VADriverContextP ctx,
1370 VASubpictureID subpicture)
1372 struct i965_driver_data *i965 = i965_driver_data(ctx);
1373 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1376 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1378 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1379 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1380 return VA_STATUS_SUCCESS;
1384 i965_SetSubpictureImage(VADriverContextP ctx,
1385 VASubpictureID subpicture,
1389 return VA_STATUS_ERROR_UNIMPLEMENTED;
1393 i965_SetSubpictureChromakey(VADriverContextP ctx,
1394 VASubpictureID subpicture,
1395 unsigned int chromakey_min,
1396 unsigned int chromakey_max,
1397 unsigned int chromakey_mask)
1400 return VA_STATUS_ERROR_UNIMPLEMENTED;
1404 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1405 VASubpictureID subpicture,
1408 struct i965_driver_data *i965 = i965_driver_data(ctx);
1409 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1411 if(global_alpha > 1.0 || global_alpha < 0.0){
1412 return VA_STATUS_ERROR_INVALID_PARAMETER;
1416 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1418 obj_subpic->global_alpha = global_alpha;
1420 return VA_STATUS_SUCCESS;
1424 i965_AssociateSubpicture(VADriverContextP ctx,
1425 VASubpictureID subpicture,
1426 VASurfaceID *target_surfaces,
1428 short src_x, /* upper left offset in subpicture */
1430 unsigned short src_width,
1431 unsigned short src_height,
1432 short dest_x, /* upper left offset in surface */
1434 unsigned short dest_width,
1435 unsigned short dest_height,
1437 * whether to enable chroma-keying or global-alpha
1438 * see VA_SUBPICTURE_XXX values
1442 struct i965_driver_data *i965 = i965_driver_data(ctx);
1443 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1447 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1449 ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
1451 obj_subpic->src_rect.x = src_x;
1452 obj_subpic->src_rect.y = src_y;
1453 obj_subpic->src_rect.width = src_width;
1454 obj_subpic->src_rect.height = src_height;
1455 obj_subpic->dst_rect.x = dest_x;
1456 obj_subpic->dst_rect.y = dest_y;
1457 obj_subpic->dst_rect.width = dest_width;
1458 obj_subpic->dst_rect.height = dest_height;
1459 obj_subpic->flags = flags;
1461 for (i = 0; i < num_surfaces; i++) {
1462 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1464 return VA_STATUS_ERROR_INVALID_SURFACE;
1466 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1467 if(obj_surface->subpic[j] == VA_INVALID_ID){
1468 assert(obj_surface->obj_subpic[j] == NULL);
1469 obj_surface->subpic[j] = subpicture;
1470 obj_surface->obj_subpic[j] = obj_subpic;
1475 if(j == I965_MAX_SUBPIC_SUM){
1476 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1480 return VA_STATUS_SUCCESS;
1485 i965_DeassociateSubpicture(VADriverContextP ctx,
1486 VASubpictureID subpicture,
1487 VASurfaceID *target_surfaces,
1490 struct i965_driver_data *i965 = i965_driver_data(ctx);
1491 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1495 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1497 for (i = 0; i < num_surfaces; i++) {
1498 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1500 return VA_STATUS_ERROR_INVALID_SURFACE;
1502 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1503 if (obj_surface->subpic[j] == subpicture) {
1504 assert(obj_surface->obj_subpic[j] == obj_subpic);
1505 obj_surface->subpic[j] = VA_INVALID_ID;
1506 obj_surface->obj_subpic[j] = NULL;
1511 if(j == I965_MAX_SUBPIC_SUM){
1512 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1515 return VA_STATUS_SUCCESS;
1519 i965_reference_buffer_store(struct buffer_store **ptr,
1520 struct buffer_store *buffer_store)
1522 assert(*ptr == NULL);
1525 buffer_store->ref_count++;
1526 *ptr = buffer_store;
1531 i965_release_buffer_store(struct buffer_store **ptr)
1533 struct buffer_store *buffer_store = *ptr;
1535 if (buffer_store == NULL)
1538 assert(buffer_store->bo || buffer_store->buffer);
1539 assert(!(buffer_store->bo && buffer_store->buffer));
1540 buffer_store->ref_count--;
1542 if (buffer_store->ref_count == 0) {
1543 dri_bo_unreference(buffer_store->bo);
1544 free(buffer_store->buffer);
1545 buffer_store->bo = NULL;
1546 buffer_store->buffer = NULL;
1554 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1556 struct object_context *obj_context = (struct object_context *)obj;
1559 if (obj_context->hw_context) {
1560 obj_context->hw_context->destroy(obj_context->hw_context);
1561 obj_context->hw_context = NULL;
1564 if (obj_context->codec_type == CODEC_PROC) {
1565 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1567 } else if (obj_context->codec_type == CODEC_ENC) {
1568 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1569 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1570 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1572 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1573 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1575 free(obj_context->codec_state.encode.slice_params);
1577 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1578 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1579 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1581 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1582 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1584 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1585 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1587 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1588 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1590 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1591 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1593 free(obj_context->codec_state.encode.slice_params_ext);
1595 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1596 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1598 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1599 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1600 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1602 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1603 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1605 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1606 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1608 free(obj_context->codec_state.decode.slice_params);
1609 free(obj_context->codec_state.decode.slice_datas);
1612 free(obj_context->render_targets);
1613 object_heap_free(heap, obj);
1617 i965_CreateContext(VADriverContextP ctx,
1618 VAConfigID config_id,
1622 VASurfaceID *render_targets,
1623 int num_render_targets,
1624 VAContextID *context) /* out */
1626 struct i965_driver_data *i965 = i965_driver_data(ctx);
1627 struct i965_render_state *render_state = &i965->render_state;
1628 struct object_config *obj_config = CONFIG(config_id);
1629 struct object_context *obj_context = NULL;
1630 VAConfigAttrib *attrib;
1631 VAStatus vaStatus = VA_STATUS_SUCCESS;
1635 if (NULL == obj_config) {
1636 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1640 if (picture_width > i965->codec_info->max_width ||
1641 picture_height > i965->codec_info->max_height) {
1642 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1647 /* Validate picture dimensions */
1648 contextID = NEW_CONTEXT_ID();
1649 obj_context = CONTEXT(contextID);
1651 if (NULL == obj_context) {
1652 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1656 render_state->inited = 1;
1658 switch (obj_config->profile) {
1659 case VAProfileH264ConstrainedBaseline:
1660 case VAProfileH264Main:
1661 case VAProfileH264High:
1662 if (!HAS_H264_DECODING(i965) &&
1663 !HAS_H264_ENCODING(i965))
1664 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1665 render_state->interleaved_uv = 1;
1668 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_info) || IS_GEN7(i965->intel.device_info) || IS_GEN8(i965->intel.device_info));
1672 *context = contextID;
1673 obj_context->flags = flag;
1674 obj_context->context_id = contextID;
1675 obj_context->obj_config = obj_config;
1676 obj_context->picture_width = picture_width;
1677 obj_context->picture_height = picture_height;
1678 obj_context->num_render_targets = num_render_targets;
1679 obj_context->render_targets =
1680 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1681 obj_context->hw_context = NULL;
1683 for(i = 0; i < num_render_targets; i++) {
1684 if (NULL == SURFACE(render_targets[i])) {
1685 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1689 obj_context->render_targets[i] = render_targets[i];
1692 if (VA_STATUS_SUCCESS == vaStatus) {
1693 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1694 obj_context->codec_type = CODEC_PROC;
1695 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1696 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1697 assert(i965->codec_info->proc_hw_context_init);
1698 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1699 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1700 obj_context->codec_type = CODEC_ENC;
1701 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1702 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1703 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1704 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1705 sizeof(*obj_context->codec_state.encode.slice_params));
1706 assert(i965->codec_info->enc_hw_context_init);
1707 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1709 obj_context->codec_type = CODEC_DEC;
1710 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1711 obj_context->codec_state.decode.current_render_target = -1;
1712 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1713 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1714 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1715 sizeof(*obj_context->codec_state.decode.slice_params));
1716 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1717 sizeof(*obj_context->codec_state.decode.slice_datas));
1719 assert(i965->codec_info->dec_hw_context_init);
1720 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1724 attrib = i965_lookup_config_attribute(obj_config, VAConfigAttribRTFormat);
1726 return VA_STATUS_ERROR_INVALID_CONFIG;
1727 obj_context->codec_state.base.chroma_formats = attrib->value;
1729 /* Error recovery */
1730 if (VA_STATUS_SUCCESS != vaStatus) {
1731 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1734 i965->current_context_id = contextID;
1740 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1742 struct i965_driver_data *i965 = i965_driver_data(ctx);
1743 struct object_context *obj_context = CONTEXT(context);
1745 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
1747 if (i965->current_context_id == context)
1748 i965->current_context_id = VA_INVALID_ID;
1750 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1752 return VA_STATUS_SUCCESS;
1756 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1758 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1760 assert(obj_buffer->buffer_store);
1761 i965_release_buffer_store(&obj_buffer->buffer_store);
1762 object_heap_free(heap, obj);
1766 i965_create_buffer_internal(VADriverContextP ctx,
1767 VAContextID context,
1770 unsigned int num_elements,
1775 struct i965_driver_data *i965 = i965_driver_data(ctx);
1776 struct object_buffer *obj_buffer = NULL;
1777 struct buffer_store *buffer_store = NULL;
1782 case VAPictureParameterBufferType:
1783 case VAIQMatrixBufferType:
1784 case VAQMatrixBufferType:
1785 case VABitPlaneBufferType:
1786 case VASliceGroupMapBufferType:
1787 case VASliceParameterBufferType:
1788 case VASliceDataBufferType:
1789 case VAMacroblockParameterBufferType:
1790 case VAResidualDataBufferType:
1791 case VADeblockingParameterBufferType:
1792 case VAImageBufferType:
1793 case VAEncCodedBufferType:
1794 case VAEncSequenceParameterBufferType:
1795 case VAEncPictureParameterBufferType:
1796 case VAEncSliceParameterBufferType:
1797 case VAEncPackedHeaderParameterBufferType:
1798 case VAEncPackedHeaderDataBufferType:
1799 case VAEncMiscParameterBufferType:
1800 case VAProcPipelineParameterBufferType:
1801 case VAProcFilterParameterBufferType:
1802 case VAHuffmanTableBufferType:
1803 case VAProbabilityBufferType:
1808 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1811 bufferID = NEW_BUFFER_ID();
1812 obj_buffer = BUFFER(bufferID);
1814 if (NULL == obj_buffer) {
1815 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1818 if (type == VAEncCodedBufferType) {
1819 size += I965_CODEDBUFFER_HEADER_SIZE;
1820 size += 0x1000; /* for upper bound check */
1823 obj_buffer->max_num_elements = num_elements;
1824 obj_buffer->num_elements = num_elements;
1825 obj_buffer->size_element = size;
1826 obj_buffer->type = type;
1827 obj_buffer->buffer_store = NULL;
1828 buffer_store = calloc(1, sizeof(struct buffer_store));
1829 assert(buffer_store);
1830 buffer_store->ref_count = 1;
1832 if (store_bo != NULL) {
1833 buffer_store->bo = store_bo;
1834 dri_bo_reference(buffer_store->bo);
1837 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1838 } else if (type == VASliceDataBufferType ||
1839 type == VAImageBufferType ||
1840 type == VAEncCodedBufferType ||
1841 type == VAProbabilityBufferType) {
1842 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1844 size * num_elements, 64);
1845 assert(buffer_store->bo);
1847 if (type == VAEncCodedBufferType) {
1848 struct i965_coded_buffer_segment *coded_buffer_segment;
1850 dri_bo_map(buffer_store->bo, 1);
1851 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1852 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1853 coded_buffer_segment->base.bit_offset = 0;
1854 coded_buffer_segment->base.status = 0;
1855 coded_buffer_segment->base.buf = NULL;
1856 coded_buffer_segment->base.next = NULL;
1857 coded_buffer_segment->mapped = 0;
1858 coded_buffer_segment->codec = 0;
1859 dri_bo_unmap(buffer_store->bo);
1861 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1867 if (type == VAEncPackedHeaderDataBufferType) {
1868 msize = ALIGN(size, 4);
1871 buffer_store->buffer = malloc(msize * num_elements);
1872 assert(buffer_store->buffer);
1875 memcpy(buffer_store->buffer, data, size * num_elements);
1878 buffer_store->num_elements = obj_buffer->num_elements;
1879 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1880 i965_release_buffer_store(&buffer_store);
1883 return VA_STATUS_SUCCESS;
1887 i965_CreateBuffer(VADriverContextP ctx,
1888 VAContextID context, /* in */
1889 VABufferType type, /* in */
1890 unsigned int size, /* in */
1891 unsigned int num_elements, /* in */
1892 void *data, /* in */
1893 VABufferID *buf_id) /* out */
1895 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1900 i965_BufferSetNumElements(VADriverContextP ctx,
1901 VABufferID buf_id, /* in */
1902 unsigned int num_elements) /* in */
1904 struct i965_driver_data *i965 = i965_driver_data(ctx);
1905 struct object_buffer *obj_buffer = BUFFER(buf_id);
1906 VAStatus vaStatus = VA_STATUS_SUCCESS;
1908 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1910 if ((num_elements < 0) ||
1911 (num_elements > obj_buffer->max_num_elements)) {
1912 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1914 obj_buffer->num_elements = num_elements;
1915 if (obj_buffer->buffer_store != NULL) {
1916 obj_buffer->buffer_store->num_elements = num_elements;
1924 i965_MapBuffer(VADriverContextP ctx,
1925 VABufferID buf_id, /* in */
1926 void **pbuf) /* out */
1928 struct i965_driver_data *i965 = i965_driver_data(ctx);
1929 struct object_buffer *obj_buffer = BUFFER(buf_id);
1930 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1932 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
1933 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
1934 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
1936 if (NULL != obj_buffer->buffer_store->bo) {
1937 unsigned int tiling, swizzle;
1939 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1941 if (tiling != I915_TILING_NONE)
1942 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1944 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1946 ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
1947 *pbuf = obj_buffer->buffer_store->bo->virtual;
1949 if (obj_buffer->type == VAEncCodedBufferType) {
1951 unsigned char *buffer = NULL;
1952 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1954 if (!coded_buffer_segment->mapped) {
1955 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1957 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1959 if (coded_buffer_segment->codec == CODEC_H264) {
1960 delimiter0 = H264_DELIMITER0;
1961 delimiter1 = H264_DELIMITER1;
1962 delimiter2 = H264_DELIMITER2;
1963 delimiter3 = H264_DELIMITER3;
1964 delimiter4 = H264_DELIMITER4;
1965 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
1966 delimiter0 = MPEG2_DELIMITER0;
1967 delimiter1 = MPEG2_DELIMITER1;
1968 delimiter2 = MPEG2_DELIMITER2;
1969 delimiter3 = MPEG2_DELIMITER3;
1970 delimiter4 = MPEG2_DELIMITER4;
1972 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
1975 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1976 if ((buffer[i] == delimiter0) &&
1977 (buffer[i + 1] == delimiter1) &&
1978 (buffer[i + 2] == delimiter2) &&
1979 (buffer[i + 3] == delimiter3) &&
1980 (buffer[i + 4] == delimiter4))
1984 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1985 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1988 coded_buffer_segment->base.size = i;
1989 coded_buffer_segment->mapped = 1;
1991 assert(coded_buffer_segment->base.buf);
1995 vaStatus = VA_STATUS_SUCCESS;
1996 } else if (NULL != obj_buffer->buffer_store->buffer) {
1997 *pbuf = obj_buffer->buffer_store->buffer;
1998 vaStatus = VA_STATUS_SUCCESS;
2005 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
2007 struct i965_driver_data *i965 = i965_driver_data(ctx);
2008 struct object_buffer *obj_buffer = BUFFER(buf_id);
2009 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2011 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
2012 return VA_STATUS_ERROR_INVALID_BUFFER;
2014 ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
2015 ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
2016 ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
2018 if (NULL != obj_buffer->buffer_store->bo) {
2019 unsigned int tiling, swizzle;
2021 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
2023 if (tiling != I915_TILING_NONE)
2024 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
2026 dri_bo_unmap(obj_buffer->buffer_store->bo);
2028 vaStatus = VA_STATUS_SUCCESS;
2029 } else if (NULL != obj_buffer->buffer_store->buffer) {
2031 vaStatus = VA_STATUS_SUCCESS;
2038 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
2040 struct i965_driver_data *i965 = i965_driver_data(ctx);
2041 struct object_buffer *obj_buffer = BUFFER(buffer_id);
2043 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2045 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
2047 return VA_STATUS_SUCCESS;
2051 i965_BeginPicture(VADriverContextP ctx,
2052 VAContextID context,
2053 VASurfaceID render_target)
2055 struct i965_driver_data *i965 = i965_driver_data(ctx);
2056 struct object_context *obj_context = CONTEXT(context);
2057 struct object_surface *obj_surface = SURFACE(render_target);
2058 struct object_config *obj_config;
2062 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2063 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2064 obj_config = obj_context->obj_config;
2065 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2067 switch (obj_config->profile) {
2068 case VAProfileMPEG2Simple:
2069 case VAProfileMPEG2Main:
2070 vaStatus = VA_STATUS_SUCCESS;
2073 case VAProfileH264ConstrainedBaseline:
2074 case VAProfileH264Main:
2075 case VAProfileH264High:
2076 vaStatus = VA_STATUS_SUCCESS;
2079 case VAProfileVC1Simple:
2080 case VAProfileVC1Main:
2081 case VAProfileVC1Advanced:
2082 vaStatus = VA_STATUS_SUCCESS;
2085 case VAProfileJPEGBaseline:
2086 vaStatus = VA_STATUS_SUCCESS;
2090 vaStatus = VA_STATUS_SUCCESS;
2093 case VAProfileVP8Version0_3:
2094 vaStatus = VA_STATUS_SUCCESS;
2098 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
2102 if (obj_context->codec_type == CODEC_PROC) {
2103 obj_context->codec_state.proc.current_render_target = render_target;
2104 } else if (obj_context->codec_type == CODEC_ENC) {
2105 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2107 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
2108 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2111 obj_context->codec_state.encode.num_slice_params = 0;
2114 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2116 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2117 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2119 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2120 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2122 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2123 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2125 obj_context->codec_state.encode.num_slice_params_ext = 0;
2126 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2127 obj_context->codec_state.encode.last_packed_header_type = 0;
2129 obj_context->codec_state.decode.current_render_target = render_target;
2130 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2131 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2132 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2133 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2135 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2136 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2137 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2140 obj_context->codec_state.decode.num_slice_params = 0;
2141 obj_context->codec_state.decode.num_slice_datas = 0;
2147 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2149 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2151 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2152 struct object_context *obj_context, \
2153 struct object_buffer *obj_buffer) \
2155 struct category##_state *category = &obj_context->codec_state.category; \
2156 i965_release_buffer_store(&category->member); \
2157 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2158 return VA_STATUS_SUCCESS; \
2161 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2163 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2164 struct object_context *obj_context, \
2165 struct object_buffer *obj_buffer) \
2167 struct category##_state *category = &obj_context->codec_state.category; \
2168 if (category->num_##member == category->max_##member) { \
2169 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2170 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2171 category->max_##member += NUM_SLICES; \
2173 i965_release_buffer_store(&category->member[category->num_##member]); \
2174 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2175 category->num_##member++; \
2176 return VA_STATUS_SUCCESS; \
2179 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2181 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2182 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2183 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2184 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2185 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2186 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2188 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2189 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2190 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2193 i965_decoder_render_picture(VADriverContextP ctx,
2194 VAContextID context,
2195 VABufferID *buffers,
2198 struct i965_driver_data *i965 = i965_driver_data(ctx);
2199 struct object_context *obj_context = CONTEXT(context);
2200 VAStatus vaStatus = VA_STATUS_SUCCESS;
2203 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2205 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2206 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2209 return VA_STATUS_ERROR_INVALID_BUFFER;
2211 switch (obj_buffer->type) {
2212 case VAPictureParameterBufferType:
2213 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2216 case VAIQMatrixBufferType:
2217 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2220 case VABitPlaneBufferType:
2221 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2224 case VASliceParameterBufferType:
2225 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2228 case VASliceDataBufferType:
2229 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2232 case VAHuffmanTableBufferType:
2233 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2236 case VAProbabilityBufferType:
2237 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
2241 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2249 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2251 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2252 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2253 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2254 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2255 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2256 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2257 /* extended buffer */
2258 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2259 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2261 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2262 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2263 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2266 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2267 struct object_context *obj_context,
2268 struct object_buffer *obj_buffer,
2271 struct encode_state *encode = &obj_context->codec_state.encode;
2273 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2274 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2275 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2276 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2278 return VA_STATUS_SUCCESS;
2282 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2283 struct object_context *obj_context,
2284 struct object_buffer *obj_buffer,
2287 struct encode_state *encode = &obj_context->codec_state.encode;
2289 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2290 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2291 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2292 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2294 return VA_STATUS_SUCCESS;
2298 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2299 struct object_context *obj_context,
2300 struct object_buffer *obj_buffer)
2302 struct encode_state *encode = &obj_context->codec_state.encode;
2303 VAEncMiscParameterBuffer *param = NULL;
2305 ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
2306 ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
2308 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2310 if (param->type >= ARRAY_ELEMS(encode->misc_param))
2311 return VA_STATUS_ERROR_INVALID_PARAMETER;
2313 i965_release_buffer_store(&encode->misc_param[param->type]);
2314 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2316 return VA_STATUS_SUCCESS;
2320 i965_encoder_render_picture(VADriverContextP ctx,
2321 VAContextID context,
2322 VABufferID *buffers,
2325 struct i965_driver_data *i965 = i965_driver_data(ctx);
2326 struct object_context *obj_context = CONTEXT(context);
2327 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2330 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2332 for (i = 0; i < num_buffers; i++) {
2333 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2336 return VA_STATUS_ERROR_INVALID_BUFFER;
2338 switch (obj_buffer->type) {
2339 case VAQMatrixBufferType:
2340 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2343 case VAIQMatrixBufferType:
2344 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2347 case VAEncSequenceParameterBufferType:
2348 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2351 case VAEncPictureParameterBufferType:
2352 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2355 case VAEncSliceParameterBufferType:
2356 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2359 case VAEncPackedHeaderParameterBufferType:
2361 struct encode_state *encode = &obj_context->codec_state.encode;
2362 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2363 encode->last_packed_header_type = param->type;
2365 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2368 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2372 case VAEncPackedHeaderDataBufferType:
2374 struct encode_state *encode = &obj_context->codec_state.encode;
2376 ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2377 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2378 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2379 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2380 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
2381 VA_STATUS_ERROR_ENCODING_ERROR);
2382 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2385 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2389 case VAEncMiscParameterBufferType:
2390 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2396 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2404 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2406 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2407 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2410 i965_proc_render_picture(VADriverContextP ctx,
2411 VAContextID context,
2412 VABufferID *buffers,
2415 struct i965_driver_data *i965 = i965_driver_data(ctx);
2416 struct object_context *obj_context = CONTEXT(context);
2417 VAStatus vaStatus = VA_STATUS_SUCCESS;
2420 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2422 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2423 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2426 return VA_STATUS_ERROR_INVALID_BUFFER;
2428 switch (obj_buffer->type) {
2429 case VAProcPipelineParameterBufferType:
2430 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2434 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2443 i965_RenderPicture(VADriverContextP ctx,
2444 VAContextID context,
2445 VABufferID *buffers,
2448 struct i965_driver_data *i965 = i965_driver_data(ctx);
2449 struct object_context *obj_context;
2450 struct object_config *obj_config;
2451 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2453 obj_context = CONTEXT(context);
2454 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2456 if (num_buffers <= 0)
2457 return VA_STATUS_ERROR_INVALID_PARAMETER;
2459 obj_config = obj_context->obj_config;
2460 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2462 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2463 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2464 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2465 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2467 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2474 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2476 struct i965_driver_data *i965 = i965_driver_data(ctx);
2477 struct object_context *obj_context = CONTEXT(context);
2478 struct object_config *obj_config;
2480 ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
2481 obj_config = obj_context->obj_config;
2482 ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
2484 if (obj_context->codec_type == CODEC_PROC) {
2485 ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2486 } else if (obj_context->codec_type == CODEC_ENC) {
2487 ASSERT_RET(VAEntrypointEncSlice == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
2489 if (!(obj_context->codec_state.encode.pic_param ||
2490 obj_context->codec_state.encode.pic_param_ext)) {
2491 return VA_STATUS_ERROR_INVALID_PARAMETER;
2493 if (!(obj_context->codec_state.encode.seq_param ||
2494 obj_context->codec_state.encode.seq_param_ext)) {
2495 return VA_STATUS_ERROR_INVALID_PARAMETER;
2497 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2498 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2499 return VA_STATUS_ERROR_INVALID_PARAMETER;
2502 if (obj_context->codec_state.decode.pic_param == NULL) {
2503 return VA_STATUS_ERROR_INVALID_PARAMETER;
2505 if (obj_context->codec_state.decode.num_slice_params <=0) {
2506 return VA_STATUS_ERROR_INVALID_PARAMETER;
2508 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2509 return VA_STATUS_ERROR_INVALID_PARAMETER;
2512 if (obj_context->codec_state.decode.num_slice_params !=
2513 obj_context->codec_state.decode.num_slice_datas) {
2514 return VA_STATUS_ERROR_INVALID_PARAMETER;
2518 ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
2519 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2523 i965_SyncSurface(VADriverContextP ctx,
2524 VASurfaceID render_target)
2526 struct i965_driver_data *i965 = i965_driver_data(ctx);
2527 struct object_surface *obj_surface = SURFACE(render_target);
2529 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2532 drm_intel_bo_wait_rendering(obj_surface->bo);
2534 return VA_STATUS_SUCCESS;
2538 i965_QuerySurfaceStatus(VADriverContextP ctx,
2539 VASurfaceID render_target,
2540 VASurfaceStatus *status) /* out */
2542 struct i965_driver_data *i965 = i965_driver_data(ctx);
2543 struct object_surface *obj_surface = SURFACE(render_target);
2545 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
2547 if (obj_surface->bo) {
2548 if (drm_intel_bo_busy(obj_surface->bo)){
2549 *status = VASurfaceRendering;
2552 *status = VASurfaceReady;
2555 *status = VASurfaceReady;
2558 return VA_STATUS_SUCCESS;
2561 static VADisplayAttribute *
2562 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2564 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2567 if (!i965->display_attributes)
2570 for (i = 0; i < i965->num_display_attributes; i++) {
2571 if (i965->display_attributes[i].type == type)
2572 return &i965->display_attributes[i];
2578 i965_display_attributes_terminate(VADriverContextP ctx)
2580 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2582 if (i965->display_attributes) {
2583 free(i965->display_attributes);
2584 i965->display_attributes = NULL;
2585 i965->num_display_attributes = 0;
2590 i965_display_attributes_init(VADriverContextP ctx)
2592 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2594 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2595 i965->display_attributes = malloc(
2596 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2597 if (!i965->display_attributes)
2601 i965->display_attributes,
2602 i965_display_attributes,
2603 sizeof(i965_display_attributes)
2606 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2607 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
2608 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
2609 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
2610 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
2612 if (!i965->rotation_attrib ||
2613 !i965->brightness_attrib ||
2614 !i965->contrast_attrib ||
2615 !i965->hue_attrib ||
2616 !i965->saturation_attrib) {
2622 i965_display_attributes_terminate(ctx);
2627 * Query display attributes
2628 * The caller must provide a "attr_list" array that can hold at
2629 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2630 * returned in "attr_list" is returned in "num_attributes".
2633 i965_QueryDisplayAttributes(
2634 VADriverContextP ctx,
2635 VADisplayAttribute *attribs, /* out */
2636 int *num_attribs_ptr /* out */
2639 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2641 if (attribs && num_attribs > 0)
2642 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2644 if (num_attribs_ptr)
2645 *num_attribs_ptr = num_attribs;
2647 return VA_STATUS_SUCCESS;
2651 * Get display attributes
2652 * This function returns the current attribute values in "attr_list".
2653 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2654 * from vaQueryDisplayAttributes() can have their values retrieved.
2657 i965_GetDisplayAttributes(
2658 VADriverContextP ctx,
2659 VADisplayAttribute *attribs, /* inout */
2660 int num_attribs /* in */
2665 for (i = 0; i < num_attribs; i++) {
2666 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2668 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2669 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2670 dst_attrib->min_value = src_attrib->min_value;
2671 dst_attrib->max_value = src_attrib->max_value;
2672 dst_attrib->value = src_attrib->value;
2675 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2677 return VA_STATUS_SUCCESS;
2681 * Set display attributes
2682 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2683 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2684 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2687 i965_SetDisplayAttributes(
2688 VADriverContextP ctx,
2689 VADisplayAttribute *attribs, /* in */
2690 int num_attribs /* in */
2695 for (i = 0; i < num_attribs; i++) {
2696 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2698 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2700 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2702 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2705 if (src_attrib->value < dst_attrib->min_value ||
2706 src_attrib->value > dst_attrib->max_value)
2707 return VA_STATUS_ERROR_INVALID_PARAMETER;
2709 dst_attrib->value = src_attrib->value;
2710 /* XXX: track modified attributes through timestamps */
2712 return VA_STATUS_SUCCESS;
2716 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2717 VASurfaceID surface,
2718 void **buffer, /* out */
2719 unsigned int *stride) /* out */
2722 return VA_STATUS_ERROR_UNIMPLEMENTED;
2726 i965_destroy_heap(struct object_heap *heap,
2727 void (*func)(struct object_heap *heap, struct object_base *object))
2729 struct object_base *object;
2730 object_heap_iterator iter;
2732 object = object_heap_first(heap, &iter);
2738 object = object_heap_next(heap, &iter);
2741 object_heap_destroy(heap);
2746 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2749 i965_CreateImage(VADriverContextP ctx,
2750 VAImageFormat *format,
2753 VAImage *out_image) /* out */
2755 struct i965_driver_data *i965 = i965_driver_data(ctx);
2756 struct object_image *obj_image;
2757 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2759 unsigned int size2, size, awidth, aheight;
2761 out_image->image_id = VA_INVALID_ID;
2762 out_image->buf = VA_INVALID_ID;
2764 image_id = NEW_IMAGE_ID();
2765 if (image_id == VA_INVALID_ID)
2766 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2768 obj_image = IMAGE(image_id);
2770 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2771 obj_image->bo = NULL;
2772 obj_image->palette = NULL;
2773 obj_image->derived_surface = VA_INVALID_ID;
2775 VAImage * const image = &obj_image->image;
2776 image->image_id = image_id;
2777 image->buf = VA_INVALID_ID;
2779 awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
2781 if ((format->fourcc == VA_FOURCC_YV12) ||
2782 (format->fourcc == VA_FOURCC_I420)) {
2783 if (awidth % 128 != 0) {
2784 awidth = ALIGN(width, 128);
2788 aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
2789 size = awidth * aheight;
2790 size2 = (awidth / 2) * (aheight / 2);
2792 image->num_palette_entries = 0;
2793 image->entry_bytes = 0;
2794 memset(image->component_order, 0, sizeof(image->component_order));
2796 switch (format->fourcc) {
2797 case VA_FOURCC_IA44:
2798 case VA_FOURCC_AI44:
2799 image->num_planes = 1;
2800 image->pitches[0] = awidth;
2801 image->offsets[0] = 0;
2802 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2803 image->num_palette_entries = 16;
2804 image->entry_bytes = 3;
2805 image->component_order[0] = 'R';
2806 image->component_order[1] = 'G';
2807 image->component_order[2] = 'B';
2809 case VA_FOURCC_IA88:
2810 case VA_FOURCC_AI88:
2811 image->num_planes = 1;
2812 image->pitches[0] = awidth * 2;
2813 image->offsets[0] = 0;
2814 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2815 image->num_palette_entries = 256;
2816 image->entry_bytes = 3;
2817 image->component_order[0] = 'R';
2818 image->component_order[1] = 'G';
2819 image->component_order[2] = 'B';
2821 case VA_FOURCC_ARGB:
2822 case VA_FOURCC_ABGR:
2823 case VA_FOURCC_BGRA:
2824 case VA_FOURCC_RGBA:
2825 case VA_FOURCC_BGRX:
2826 case VA_FOURCC_RGBX:
2827 image->num_planes = 1;
2828 image->pitches[0] = awidth * 4;
2829 image->offsets[0] = 0;
2830 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2832 case VA_FOURCC_YV12:
2833 image->num_planes = 3;
2834 image->pitches[0] = awidth;
2835 image->offsets[0] = 0;
2836 image->pitches[1] = awidth / 2;
2837 image->offsets[1] = size;
2838 image->pitches[2] = awidth / 2;
2839 image->offsets[2] = size + size2;
2840 image->data_size = size + 2 * size2;
2842 case VA_FOURCC_I420:
2843 image->num_planes = 3;
2844 image->pitches[0] = awidth;
2845 image->offsets[0] = 0;
2846 image->pitches[1] = awidth / 2;
2847 image->offsets[1] = size;
2848 image->pitches[2] = awidth / 2;
2849 image->offsets[2] = size + size2;
2850 image->data_size = size + 2 * size2;
2852 case VA_FOURCC_422H:
2853 image->num_planes = 3;
2854 image->pitches[0] = awidth;
2855 image->offsets[0] = 0;
2856 image->pitches[1] = awidth / 2;
2857 image->offsets[1] = size;
2858 image->pitches[2] = awidth / 2;
2859 image->offsets[2] = size + (awidth / 2) * aheight;
2860 image->data_size = size + 2 * ((awidth / 2) * aheight);
2862 case VA_FOURCC_NV12:
2863 image->num_planes = 2;
2864 image->pitches[0] = awidth;
2865 image->offsets[0] = 0;
2866 image->pitches[1] = awidth;
2867 image->offsets[1] = size;
2868 image->data_size = size + 2 * size2;
2870 case VA_FOURCC_YUY2:
2871 case VA_FOURCC_UYVY:
2872 image->num_planes = 1;
2873 image->pitches[0] = awidth * 2;
2874 image->offsets[0] = 0;
2875 image->data_size = size * 2;
2881 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2882 image->data_size, 1, NULL, &image->buf);
2883 if (va_status != VA_STATUS_SUCCESS)
2886 struct object_buffer *obj_buffer = BUFFER(image->buf);
2889 !obj_buffer->buffer_store ||
2890 !obj_buffer->buffer_store->bo)
2891 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2893 obj_image->bo = obj_buffer->buffer_store->bo;
2894 dri_bo_reference(obj_image->bo);
2896 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2897 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
2898 if (!obj_image->palette)
2902 image->image_id = image_id;
2903 image->format = *format;
2904 image->width = width;
2905 image->height = height;
2907 *out_image = *image;
2908 return VA_STATUS_SUCCESS;
2911 i965_DestroyImage(ctx, image_id);
2916 i965_check_alloc_surface_bo(VADriverContextP ctx,
2917 struct object_surface *obj_surface,
2919 unsigned int fourcc,
2920 unsigned int subsampling)
2922 struct i965_driver_data *i965 = i965_driver_data(ctx);
2923 int region_width, region_height;
2925 if (obj_surface->bo) {
2926 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
2927 ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
2928 ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
2929 return VA_STATUS_SUCCESS;
2932 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2933 obj_surface->x_cr_offset = 0;
2935 if ((tiled && !obj_surface->user_disable_tiling)) {
2936 ASSERT_RET(fourcc != VA_FOURCC_I420 &&
2937 fourcc != VA_FOURCC_IYUV &&
2938 fourcc != VA_FOURCC_YV12,
2939 VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
2940 if (obj_surface->user_h_stride_set) {
2941 ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
2943 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2945 if (obj_surface->user_v_stride_set) {
2946 ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
2948 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2950 region_height = obj_surface->height;
2953 case VA_FOURCC_NV12:
2954 assert(subsampling == SUBSAMPLE_YUV420);
2955 obj_surface->cb_cr_pitch = obj_surface->width;
2956 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2957 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2958 obj_surface->y_cb_offset = obj_surface->height;
2959 obj_surface->y_cr_offset = obj_surface->height;
2960 region_width = obj_surface->width;
2961 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2965 case VA_FOURCC_IMC1:
2966 assert(subsampling == SUBSAMPLE_YUV420);
2967 obj_surface->cb_cr_pitch = obj_surface->width;
2968 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2969 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2970 obj_surface->y_cr_offset = obj_surface->height;
2971 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2972 region_width = obj_surface->width;
2973 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2977 case VA_FOURCC_IMC3:
2978 assert(subsampling == SUBSAMPLE_YUV420);
2979 obj_surface->cb_cr_pitch = obj_surface->width;
2980 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2981 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2982 obj_surface->y_cb_offset = obj_surface->height;
2983 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2984 region_width = obj_surface->width;
2985 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2989 case VA_FOURCC_422H:
2990 assert(subsampling == SUBSAMPLE_YUV422H);
2991 obj_surface->cb_cr_pitch = obj_surface->width;
2992 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2993 obj_surface->cb_cr_height = obj_surface->orig_height;
2994 obj_surface->y_cb_offset = obj_surface->height;
2995 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2996 region_width = obj_surface->width;
2997 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3001 case VA_FOURCC_422V:
3002 assert(subsampling == SUBSAMPLE_YUV422V);
3003 obj_surface->cb_cr_pitch = obj_surface->width;
3004 obj_surface->cb_cr_width = obj_surface->orig_width;
3005 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3006 obj_surface->y_cb_offset = obj_surface->height;
3007 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3008 region_width = obj_surface->width;
3009 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3013 case VA_FOURCC_411P:
3014 assert(subsampling == SUBSAMPLE_YUV411);
3015 obj_surface->cb_cr_pitch = obj_surface->width;
3016 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
3017 obj_surface->cb_cr_height = obj_surface->orig_height;
3018 obj_surface->y_cb_offset = obj_surface->height;
3019 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3020 region_width = obj_surface->width;
3021 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3025 case VA_FOURCC_444P:
3026 assert(subsampling == SUBSAMPLE_YUV444);
3027 obj_surface->cb_cr_pitch = obj_surface->width;
3028 obj_surface->cb_cr_width = obj_surface->orig_width;
3029 obj_surface->cb_cr_height = obj_surface->orig_height;
3030 obj_surface->y_cb_offset = obj_surface->height;
3031 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
3032 region_width = obj_surface->width;
3033 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
3037 case VA_FOURCC_Y800:
3038 assert(subsampling == SUBSAMPLE_YUV400);
3039 obj_surface->cb_cr_pitch = 0;
3040 obj_surface->cb_cr_width = 0;
3041 obj_surface->cb_cr_height = 0;
3042 obj_surface->y_cb_offset = 0;
3043 obj_surface->y_cr_offset = 0;
3044 region_width = obj_surface->width;
3045 region_height = obj_surface->height;
3049 case VA_FOURCC_YUY2:
3050 case VA_FOURCC_UYVY:
3051 assert(subsampling == SUBSAMPLE_YUV422H);
3052 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
3053 obj_surface->cb_cr_pitch = obj_surface->width;
3054 obj_surface->y_cb_offset = 0;
3055 obj_surface->y_cr_offset = 0;
3056 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3057 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3058 region_width = obj_surface->width;
3059 region_height = obj_surface->height;
3063 case VA_FOURCC_RGBA:
3064 case VA_FOURCC_RGBX:
3065 case VA_FOURCC_BGRA:
3066 case VA_FOURCC_BGRX:
3067 assert(subsampling == SUBSAMPLE_RGBX);
3069 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
3070 region_width = obj_surface->width;
3071 region_height = obj_surface->height;
3075 /* Never get here */
3076 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3080 assert(subsampling == SUBSAMPLE_YUV420 ||
3081 subsampling == SUBSAMPLE_YUV422H ||
3082 subsampling == SUBSAMPLE_YUV422V ||
3083 subsampling == SUBSAMPLE_RGBX);
3085 region_width = obj_surface->width;
3086 region_height = obj_surface->height;
3089 case VA_FOURCC_NV12:
3090 obj_surface->y_cb_offset = obj_surface->height;
3091 obj_surface->y_cr_offset = obj_surface->height;
3092 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3093 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3094 obj_surface->cb_cr_pitch = obj_surface->width;
3095 region_height = obj_surface->height + obj_surface->height / 2;
3098 case VA_FOURCC_YV16:
3099 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3100 obj_surface->cb_cr_height = obj_surface->orig_height;
3101 obj_surface->y_cr_offset = obj_surface->height;
3102 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
3103 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3104 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
3107 case VA_FOURCC_YV12:
3108 case VA_FOURCC_I420:
3109 if (fourcc == VA_FOURCC_YV12) {
3110 obj_surface->y_cr_offset = obj_surface->height;
3111 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
3113 obj_surface->y_cb_offset = obj_surface->height;
3114 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
3117 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3118 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3119 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3120 region_height = obj_surface->height + obj_surface->height / 2;
3123 case VA_FOURCC_YUY2:
3124 case VA_FOURCC_UYVY:
3125 obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
3126 obj_surface->y_cb_offset = 0;
3127 obj_surface->y_cr_offset = 0;
3128 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3129 obj_surface->cb_cr_height = obj_surface->orig_height;
3130 obj_surface->cb_cr_pitch = obj_surface->width;
3131 region_width = obj_surface->width;
3132 region_height = obj_surface->height;
3134 case VA_FOURCC_RGBA:
3135 case VA_FOURCC_RGBX:
3136 case VA_FOURCC_BGRA:
3137 case VA_FOURCC_BGRX:
3138 obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
3139 region_width = obj_surface->width;
3140 region_height = obj_surface->height;
3144 /* Never get here */
3145 ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
3150 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
3152 if ((tiled && !obj_surface->user_disable_tiling)) {
3153 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
3154 unsigned long pitch;
3156 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
3164 assert(tiling_mode == I915_TILING_Y);
3165 assert(pitch == obj_surface->width);
3167 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
3173 obj_surface->fourcc = fourcc;
3174 obj_surface->subsampling = subsampling;
3175 assert(obj_surface->bo);
3176 return VA_STATUS_SUCCESS;
3179 VAStatus i965_DeriveImage(VADriverContextP ctx,
3180 VASurfaceID surface,
3181 VAImage *out_image) /* out */
3183 struct i965_driver_data *i965 = i965_driver_data(ctx);
3184 struct object_image *obj_image;
3185 struct object_surface *obj_surface;
3187 unsigned int w_pitch;
3188 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3190 out_image->image_id = VA_INVALID_ID;
3191 obj_surface = SURFACE(surface);
3194 return VA_STATUS_ERROR_INVALID_SURFACE;
3196 if (!obj_surface->bo) {
3197 unsigned int is_tiled = 0;
3198 unsigned int fourcc = VA_FOURCC_YV12;
3199 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
3200 int sampling = get_sampling_from_fourcc(fourcc);
3201 va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
3202 if (va_status != VA_STATUS_SUCCESS)
3206 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3208 w_pitch = obj_surface->width;
3210 image_id = NEW_IMAGE_ID();
3212 if (image_id == VA_INVALID_ID)
3213 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3215 obj_image = IMAGE(image_id);
3218 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3220 obj_image->bo = NULL;
3221 obj_image->palette = NULL;
3222 obj_image->derived_surface = VA_INVALID_ID;
3224 VAImage * const image = &obj_image->image;
3226 memset(image, 0, sizeof(*image));
3227 image->image_id = image_id;
3228 image->buf = VA_INVALID_ID;
3229 image->num_palette_entries = 0;
3230 image->entry_bytes = 0;
3231 image->width = obj_surface->orig_width;
3232 image->height = obj_surface->orig_height;
3233 image->data_size = obj_surface->size;
3235 image->format.fourcc = obj_surface->fourcc;
3236 image->format.byte_order = VA_LSB_FIRST;
3237 image->format.bits_per_pixel = 12;
3239 switch (image->format.fourcc) {
3240 case VA_FOURCC_YV12:
3241 image->num_planes = 3;
3242 image->pitches[0] = w_pitch; /* Y */
3243 image->offsets[0] = 0;
3244 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3245 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3246 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3247 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3250 case VA_FOURCC_YV16:
3251 image->num_planes = 3;
3252 image->pitches[0] = w_pitch; /* Y */
3253 image->offsets[0] = 0;
3254 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3255 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3256 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3257 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3260 case VA_FOURCC_NV12:
3261 image->num_planes = 2;
3262 image->pitches[0] = w_pitch; /* Y */
3263 image->offsets[0] = 0;
3264 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3265 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3268 case VA_FOURCC_I420:
3269 case VA_FOURCC_422H:
3270 case VA_FOURCC_IMC3:
3271 case VA_FOURCC_444P:
3272 case VA_FOURCC_422V:
3273 case VA_FOURCC_411P:
3274 image->num_planes = 3;
3275 image->pitches[0] = w_pitch; /* Y */
3276 image->offsets[0] = 0;
3277 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3278 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3279 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3280 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3283 case VA_FOURCC_YUY2:
3284 case VA_FOURCC_UYVY:
3285 case VA_FOURCC_Y800:
3286 image->num_planes = 1;
3287 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
3288 image->offsets[0] = 0;
3290 case VA_FOURCC_RGBA:
3291 case VA_FOURCC_RGBX:
3292 case VA_FOURCC_BGRA:
3293 case VA_FOURCC_BGRX:
3294 image->num_planes = 1;
3295 image->pitches[0] = obj_surface->width;
3301 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3302 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3303 if (va_status != VA_STATUS_SUCCESS)
3306 struct object_buffer *obj_buffer = BUFFER(image->buf);
3309 !obj_buffer->buffer_store ||
3310 !obj_buffer->buffer_store->bo)
3311 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3313 obj_image->bo = obj_buffer->buffer_store->bo;
3314 dri_bo_reference(obj_image->bo);
3316 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3317 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3318 if (!obj_image->palette) {
3319 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3324 *out_image = *image;
3325 obj_surface->flags |= SURFACE_DERIVED;
3326 obj_image->derived_surface = surface;
3328 return VA_STATUS_SUCCESS;
3331 i965_DestroyImage(ctx, image_id);
3336 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3338 object_heap_free(heap, obj);
3343 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3345 struct i965_driver_data *i965 = i965_driver_data(ctx);
3346 struct object_image *obj_image = IMAGE(image);
3347 struct object_surface *obj_surface;
3350 return VA_STATUS_SUCCESS;
3352 dri_bo_unreference(obj_image->bo);
3353 obj_image->bo = NULL;
3355 if (obj_image->image.buf != VA_INVALID_ID) {
3356 i965_DestroyBuffer(ctx, obj_image->image.buf);
3357 obj_image->image.buf = VA_INVALID_ID;
3360 if (obj_image->palette) {
3361 free(obj_image->palette);
3362 obj_image->palette = NULL;
3365 obj_surface = SURFACE(obj_image->derived_surface);
3368 obj_surface->flags &= ~SURFACE_DERIVED;
3371 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3373 return VA_STATUS_SUCCESS;
3377 * pointer to an array holding the palette data. The size of the array is
3378 * num_palette_entries * entry_bytes in size. The order of the components
3379 * in the palette is described by the component_order in VASubpicture struct
3382 i965_SetImagePalette(VADriverContextP ctx,
3384 unsigned char *palette)
3386 struct i965_driver_data *i965 = i965_driver_data(ctx);
3389 struct object_image *obj_image = IMAGE(image);
3391 return VA_STATUS_ERROR_INVALID_IMAGE;
3393 if (!obj_image->palette)
3394 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3396 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3397 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3398 ((unsigned int)palette[3*i + 1] << 8) |
3399 (unsigned int)palette[3*i + 2]);
3400 return VA_STATUS_SUCCESS;
3404 get_sampling_from_fourcc(unsigned int fourcc)
3406 const i965_fourcc_info *info = get_fourcc_info(fourcc);
3408 if (info && (info->flag & I_S))
3409 return info->subsampling;
3415 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3416 const uint8_t *src, unsigned int src_stride,
3417 unsigned int len, unsigned int height)
3421 for (i = 0; i < height; i++) {
3422 memcpy(dst, src, len);
3429 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3430 struct object_surface *obj_surface,
3431 const VARectangle *rect)
3433 uint8_t *dst[3], *src[3];
3435 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3436 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3437 unsigned int tiling, swizzle;
3438 VAStatus va_status = VA_STATUS_SUCCESS;
3440 if (!obj_surface->bo)
3441 return VA_STATUS_ERROR_INVALID_SURFACE;
3443 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3444 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3446 if (tiling != I915_TILING_NONE)
3447 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3449 dri_bo_map(obj_surface->bo, 0);
3451 if (!obj_surface->bo->virtual)
3452 return VA_STATUS_ERROR_INVALID_SURFACE;
3454 /* Dest VA image has either I420 or YV12 format.
3455 Source VA surface alway has I420 format */
3456 dst[Y] = image_data + obj_image->image.offsets[Y];
3457 src[0] = (uint8_t *)obj_surface->bo->virtual;
3458 dst[U] = image_data + obj_image->image.offsets[U];
3459 src[1] = src[0] + obj_surface->width * obj_surface->height;
3460 dst[V] = image_data + obj_image->image.offsets[V];
3461 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3464 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3465 src[0] += rect->y * obj_surface->width + rect->x;
3466 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3467 src[0], obj_surface->width,
3468 rect->width, rect->height);
3471 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3472 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3473 memcpy_pic(dst[U], obj_image->image.pitches[U],
3474 src[1], obj_surface->width / 2,
3475 rect->width / 2, rect->height / 2);
3478 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3479 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3480 memcpy_pic(dst[V], obj_image->image.pitches[V],
3481 src[2], obj_surface->width / 2,
3482 rect->width / 2, rect->height / 2);
3484 if (tiling != I915_TILING_NONE)
3485 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3487 dri_bo_unmap(obj_surface->bo);
3493 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3494 struct object_surface *obj_surface,
3495 const VARectangle *rect)
3497 uint8_t *dst[2], *src[2];
3498 unsigned int tiling, swizzle;
3499 VAStatus va_status = VA_STATUS_SUCCESS;
3501 if (!obj_surface->bo)
3502 return VA_STATUS_ERROR_INVALID_SURFACE;
3504 assert(obj_surface->fourcc);
3505 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3507 if (tiling != I915_TILING_NONE)
3508 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3510 dri_bo_map(obj_surface->bo, 0);
3512 if (!obj_surface->bo->virtual)
3513 return VA_STATUS_ERROR_INVALID_SURFACE;
3515 /* Both dest VA image and source surface have NV12 format */
3516 dst[0] = image_data + obj_image->image.offsets[0];
3517 src[0] = (uint8_t *)obj_surface->bo->virtual;
3518 dst[1] = image_data + obj_image->image.offsets[1];
3519 src[1] = src[0] + obj_surface->width * obj_surface->height;
3522 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3523 src[0] += rect->y * obj_surface->width + rect->x;
3524 memcpy_pic(dst[0], obj_image->image.pitches[0],
3525 src[0], obj_surface->width,
3526 rect->width, rect->height);
3529 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3530 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3531 memcpy_pic(dst[1], obj_image->image.pitches[1],
3532 src[1], obj_surface->width,
3533 rect->width, rect->height / 2);
3535 if (tiling != I915_TILING_NONE)
3536 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3538 dri_bo_unmap(obj_surface->bo);
3544 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3545 struct object_surface *obj_surface,
3546 const VARectangle *rect)
3549 unsigned int tiling, swizzle;
3550 VAStatus va_status = VA_STATUS_SUCCESS;
3552 if (!obj_surface->bo)
3553 return VA_STATUS_ERROR_INVALID_SURFACE;
3555 assert(obj_surface->fourcc);
3556 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3558 if (tiling != I915_TILING_NONE)
3559 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3561 dri_bo_map(obj_surface->bo, 0);
3563 if (!obj_surface->bo->virtual)
3564 return VA_STATUS_ERROR_INVALID_SURFACE;
3566 /* Both dest VA image and source surface have YUYV format */
3567 dst = image_data + obj_image->image.offsets[0];
3568 src = (uint8_t *)obj_surface->bo->virtual;
3571 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3572 src += rect->y * obj_surface->width + rect->x*2;
3573 memcpy_pic(dst, obj_image->image.pitches[0],
3574 src, obj_surface->width*2,
3575 rect->width*2, rect->height);
3577 if (tiling != I915_TILING_NONE)
3578 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3580 dri_bo_unmap(obj_surface->bo);
3586 i965_sw_getimage(VADriverContextP ctx,
3587 VASurfaceID surface,
3588 int x, /* coordinates of the upper left source pixel */
3590 unsigned int width, /* width and height of the region */
3591 unsigned int height,
3594 struct i965_driver_data *i965 = i965_driver_data(ctx);
3595 struct i965_render_state *render_state = &i965->render_state;
3596 VAStatus va_status = VA_STATUS_SUCCESS;
3598 struct object_surface *obj_surface = SURFACE(surface);
3600 return VA_STATUS_ERROR_INVALID_SURFACE;
3602 struct object_image *obj_image = IMAGE(image);
3604 return VA_STATUS_ERROR_INVALID_IMAGE;
3607 return VA_STATUS_ERROR_INVALID_PARAMETER;
3608 if (x + width > obj_surface->orig_width ||
3609 y + height > obj_surface->orig_height)
3610 return VA_STATUS_ERROR_INVALID_PARAMETER;
3611 if (x + width > obj_image->image.width ||
3612 y + height > obj_image->image.height)
3613 return VA_STATUS_ERROR_INVALID_PARAMETER;
3615 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3616 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3618 void *image_data = NULL;
3620 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3621 if (va_status != VA_STATUS_SUCCESS)
3628 rect.height = height;
3630 switch (obj_image->image.format.fourcc) {
3631 case VA_FOURCC_YV12:
3632 case VA_FOURCC_I420:
3633 /* I420 is native format for MPEG-2 decoded surfaces */
3634 if (render_state->interleaved_uv)
3635 goto operation_failed;
3636 get_image_i420(obj_image, image_data, obj_surface, &rect);
3638 case VA_FOURCC_NV12:
3639 /* NV12 is native format for H.264 decoded surfaces */
3640 if (!render_state->interleaved_uv)
3641 goto operation_failed;
3642 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3644 case VA_FOURCC_YUY2:
3645 /* YUY2 is the format supported by overlay plane */
3646 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3650 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3654 if (va_status != VA_STATUS_SUCCESS)
3657 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
3662 i965_hw_getimage(VADriverContextP ctx,
3663 VASurfaceID surface,
3664 int x, /* coordinates of the upper left source pixel */
3666 unsigned int width, /* width and height of the region */
3667 unsigned int height,
3670 struct i965_driver_data *i965 = i965_driver_data(ctx);
3671 struct i965_surface src_surface;
3672 struct i965_surface dst_surface;
3673 VAStatus va_status = VA_STATUS_SUCCESS;
3675 struct object_surface *obj_surface = SURFACE(surface);
3676 struct object_image *obj_image = IMAGE(image);
3679 return VA_STATUS_ERROR_INVALID_SURFACE;
3682 return VA_STATUS_ERROR_INVALID_IMAGE;
3685 return VA_STATUS_ERROR_INVALID_PARAMETER;
3686 if (x + width > obj_surface->orig_width ||
3687 y + height > obj_surface->orig_height)
3688 return VA_STATUS_ERROR_INVALID_PARAMETER;
3689 if (x + width > obj_image->image.width ||
3690 y + height > obj_image->image.height)
3691 return VA_STATUS_ERROR_INVALID_PARAMETER;
3693 if (!obj_surface->bo)
3694 return VA_STATUS_SUCCESS;
3695 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3700 rect.height = height;
3702 src_surface.base = (struct object_base *)obj_surface;
3703 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3704 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3706 dst_surface.base = (struct object_base *)obj_image;
3707 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3708 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3710 va_status = i965_image_processing(ctx,
3721 i965_GetImage(VADriverContextP ctx,
3722 VASurfaceID surface,
3723 int x, /* coordinates of the upper left source pixel */
3725 unsigned int width, /* width and height of the region */
3726 unsigned int height,
3729 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3730 VAStatus va_status = VA_STATUS_SUCCESS;
3732 if (HAS_ACCELERATED_GETIMAGE(i965))
3733 va_status = i965_hw_getimage(ctx,
3739 va_status = i965_sw_getimage(ctx,
3749 put_image_i420(struct object_surface *obj_surface,
3750 const VARectangle *dst_rect,
3751 struct object_image *obj_image, uint8_t *image_data,
3752 const VARectangle *src_rect)
3754 uint8_t *dst[3], *src[3];
3756 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3757 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3758 unsigned int tiling, swizzle;
3759 VAStatus va_status = VA_STATUS_SUCCESS;
3761 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
3763 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3764 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3765 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3766 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3768 if (tiling != I915_TILING_NONE)
3769 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3771 dri_bo_map(obj_surface->bo, 0);
3773 if (!obj_surface->bo->virtual)
3774 return VA_STATUS_ERROR_INVALID_SURFACE;
3776 /* Dest VA image has either I420 or YV12 format.
3777 Source VA surface alway has I420 format */
3778 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3779 src[Y] = image_data + obj_image->image.offsets[Y];
3780 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3781 src[U] = image_data + obj_image->image.offsets[U];
3782 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3783 src[V] = image_data + obj_image->image.offsets[V];
3786 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3787 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3788 memcpy_pic(dst[0], obj_surface->width,
3789 src[Y], obj_image->image.pitches[Y],
3790 src_rect->width, src_rect->height);
3793 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3794 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3795 memcpy_pic(dst[1], obj_surface->width / 2,
3796 src[U], obj_image->image.pitches[U],
3797 src_rect->width / 2, src_rect->height / 2);
3800 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3801 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3802 memcpy_pic(dst[2], obj_surface->width / 2,
3803 src[V], obj_image->image.pitches[V],
3804 src_rect->width / 2, src_rect->height / 2);
3806 if (tiling != I915_TILING_NONE)
3807 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3809 dri_bo_unmap(obj_surface->bo);
3815 put_image_nv12(struct object_surface *obj_surface,
3816 const VARectangle *dst_rect,
3817 struct object_image *obj_image, uint8_t *image_data,
3818 const VARectangle *src_rect)
3820 uint8_t *dst[2], *src[2];
3821 unsigned int tiling, swizzle;
3822 VAStatus va_status = VA_STATUS_SUCCESS;
3824 if (!obj_surface->bo)
3825 return VA_STATUS_ERROR_INVALID_SURFACE;
3827 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3828 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3829 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3830 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3832 if (tiling != I915_TILING_NONE)
3833 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3835 dri_bo_map(obj_surface->bo, 0);
3837 if (!obj_surface->bo->virtual)
3838 return VA_STATUS_ERROR_INVALID_SURFACE;
3840 /* Both dest VA image and source surface have NV12 format */
3841 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3842 src[0] = image_data + obj_image->image.offsets[0];
3843 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3844 src[1] = image_data + obj_image->image.offsets[1];
3847 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3848 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3849 memcpy_pic(dst[0], obj_surface->width,
3850 src[0], obj_image->image.pitches[0],
3851 src_rect->width, src_rect->height);
3854 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3855 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3856 memcpy_pic(dst[1], obj_surface->width,
3857 src[1], obj_image->image.pitches[1],
3858 src_rect->width, src_rect->height / 2);
3860 if (tiling != I915_TILING_NONE)
3861 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3863 dri_bo_unmap(obj_surface->bo);
3869 put_image_yuy2(struct object_surface *obj_surface,
3870 const VARectangle *dst_rect,
3871 struct object_image *obj_image, uint8_t *image_data,
3872 const VARectangle *src_rect)
3875 unsigned int tiling, swizzle;
3876 VAStatus va_status = VA_STATUS_SUCCESS;
3878 ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
3879 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
3880 ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
3881 ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
3882 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3884 if (tiling != I915_TILING_NONE)
3885 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3887 dri_bo_map(obj_surface->bo, 0);
3889 if (!obj_surface->bo->virtual)
3890 return VA_STATUS_ERROR_INVALID_SURFACE;
3892 /* Both dest VA image and source surface have YUY2 format */
3893 dst = (uint8_t *)obj_surface->bo->virtual;
3894 src = image_data + obj_image->image.offsets[0];
3896 /* YUYV packed plane */
3897 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3898 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3899 memcpy_pic(dst, obj_surface->width*2,
3900 src, obj_image->image.pitches[0],
3901 src_rect->width*2, src_rect->height);
3903 if (tiling != I915_TILING_NONE)
3904 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3906 dri_bo_unmap(obj_surface->bo);
3913 i965_sw_putimage(VADriverContextP ctx,
3914 VASurfaceID surface,
3918 unsigned int src_width,
3919 unsigned int src_height,
3922 unsigned int dest_width,
3923 unsigned int dest_height)
3925 struct i965_driver_data *i965 = i965_driver_data(ctx);
3926 struct object_surface *obj_surface = SURFACE(surface);
3927 struct object_image *obj_image = IMAGE(image);
3928 VAStatus va_status = VA_STATUS_SUCCESS;
3929 void *image_data = NULL;
3931 ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
3932 ASSERT_RET(obj_image, VA_STATUS_ERROR_INVALID_IMAGE);
3934 if (src_x < 0 || src_y < 0)
3935 return VA_STATUS_ERROR_INVALID_PARAMETER;
3936 if (src_x + src_width > obj_image->image.width ||
3937 src_y + src_height > obj_image->image.height)
3938 return VA_STATUS_ERROR_INVALID_PARAMETER;
3939 if (dest_x < 0 || dest_y < 0)
3940 return VA_STATUS_ERROR_INVALID_PARAMETER;
3941 if (dest_x + dest_width > obj_surface->orig_width ||
3942 dest_y + dest_height > obj_surface->orig_height)
3943 return VA_STATUS_ERROR_INVALID_PARAMETER;
3945 /* XXX: don't allow scaling */
3946 if (src_width != dest_width || src_height != dest_height)
3947 return VA_STATUS_ERROR_INVALID_PARAMETER;
3949 if (obj_surface->fourcc) {
3950 /* Don't allow format mismatch */
3951 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3952 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3956 /* VA is surface not used for decoding, use same VA image format */
3957 va_status = i965_check_alloc_surface_bo(
3960 0, /* XXX: don't use tiled surface */
3961 obj_image->image.format.fourcc,
3962 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3965 if (va_status != VA_STATUS_SUCCESS)
3968 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3969 if (va_status != VA_STATUS_SUCCESS)
3972 VARectangle src_rect, dest_rect;
3975 src_rect.width = src_width;
3976 src_rect.height = src_height;
3977 dest_rect.x = dest_x;
3978 dest_rect.y = dest_y;
3979 dest_rect.width = dest_width;
3980 dest_rect.height = dest_height;
3982 switch (obj_image->image.format.fourcc) {
3983 case VA_FOURCC_YV12:
3984 case VA_FOURCC_I420:
3985 va_status = put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3987 case VA_FOURCC_NV12:
3988 va_status = put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3990 case VA_FOURCC_YUY2:
3991 va_status = put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3994 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3997 if (va_status != VA_STATUS_SUCCESS)
4000 va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
4005 i965_hw_putimage(VADriverContextP ctx,
4006 VASurfaceID surface,
4010 unsigned int src_width,
4011 unsigned int src_height,
4014 unsigned int dest_width,
4015 unsigned int dest_height)
4017 struct i965_driver_data *i965 = i965_driver_data(ctx);
4018 struct object_surface *obj_surface = SURFACE(surface);
4019 struct object_image *obj_image = IMAGE(image);
4020 struct i965_surface src_surface, dst_surface;
4021 VAStatus va_status = VA_STATUS_SUCCESS;
4022 VARectangle src_rect, dst_rect;
4024 ASSERT_RET(obj_surface,VA_STATUS_ERROR_INVALID_SURFACE);
4025 ASSERT_RET(obj_image && obj_image->bo, VA_STATUS_ERROR_INVALID_IMAGE);
4029 src_x + src_width > obj_image->image.width ||
4030 src_y + src_height > obj_image->image.height)
4031 return VA_STATUS_ERROR_INVALID_PARAMETER;
4035 dest_x + dest_width > obj_surface->orig_width ||
4036 dest_y + dest_height > obj_surface->orig_height)
4037 return VA_STATUS_ERROR_INVALID_PARAMETER;
4039 if (!obj_surface->bo) {
4040 unsigned int tiling, swizzle;
4041 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
4042 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
4044 i965_check_alloc_surface_bo(ctx,
4047 obj_image->image.format.fourcc,
4051 ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
4053 src_surface.base = (struct object_base *)obj_image;
4054 src_surface.type = I965_SURFACE_TYPE_IMAGE;
4055 src_surface.flags = I965_SURFACE_FLAG_FRAME;
4058 src_rect.width = src_width;
4059 src_rect.height = src_height;
4061 dst_surface.base = (struct object_base *)obj_surface;
4062 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
4063 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
4064 dst_rect.x = dest_x;
4065 dst_rect.y = dest_y;
4066 dst_rect.width = dest_width;
4067 dst_rect.height = dest_height;
4069 va_status = i965_image_processing(ctx,
4079 i965_PutImage(VADriverContextP ctx,
4080 VASurfaceID surface,
4084 unsigned int src_width,
4085 unsigned int src_height,
4088 unsigned int dest_width,
4089 unsigned int dest_height)
4091 struct i965_driver_data *i965 = i965_driver_data(ctx);
4092 VAStatus va_status = VA_STATUS_SUCCESS;
4094 if (HAS_ACCELERATED_PUTIMAGE(i965))
4095 va_status = i965_hw_putimage(ctx,
4107 va_status = i965_sw_putimage(ctx,
4123 i965_PutSurface(VADriverContextP ctx,
4124 VASurfaceID surface,
4125 void *draw, /* X Drawable */
4128 unsigned short srcw,
4129 unsigned short srch,
4132 unsigned short destw,
4133 unsigned short desth,
4134 VARectangle *cliprects, /* client supplied clip list */
4135 unsigned int number_cliprects, /* number of clip rects in the clip list */
4136 unsigned int flags) /* de-interlacing flags */
4139 if (IS_VA_X11(ctx)) {
4140 VARectangle src_rect, dst_rect;
4144 src_rect.width = srcw;
4145 src_rect.height = srch;
4149 dst_rect.width = destw;
4150 dst_rect.height = desth;
4152 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
4153 cliprects, number_cliprects, flags);
4156 return VA_STATUS_ERROR_UNIMPLEMENTED;
4161 VADriverContextP ctx, /* in */
4162 VABufferID buf_id, /* in */
4163 VABufferType *type, /* out */
4164 unsigned int *size, /* out */
4165 unsigned int *num_elements /* out */
4168 struct i965_driver_data *i965 = NULL;
4169 struct object_buffer *obj_buffer = NULL;
4171 i965 = i965_driver_data(ctx);
4172 obj_buffer = BUFFER(buf_id);
4174 ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
4176 *type = obj_buffer->type;
4177 *size = obj_buffer->size_element;
4178 *num_elements = obj_buffer->num_elements;
4180 return VA_STATUS_SUCCESS;
4185 VADriverContextP ctx, /* in */
4186 VASurfaceID surface, /* in */
4187 unsigned int *fourcc, /* out */
4188 unsigned int *luma_stride, /* out */
4189 unsigned int *chroma_u_stride, /* out */
4190 unsigned int *chroma_v_stride, /* out */
4191 unsigned int *luma_offset, /* out */
4192 unsigned int *chroma_u_offset, /* out */
4193 unsigned int *chroma_v_offset, /* out */
4194 unsigned int *buffer_name, /* out */
4195 void **buffer /* out */
4198 VAStatus vaStatus = VA_STATUS_SUCCESS;
4199 struct i965_driver_data *i965 = i965_driver_data(ctx);
4200 struct object_surface *obj_surface = NULL;
4203 ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
4204 ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4205 ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4206 ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
4207 ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4208 ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4209 ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
4210 ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
4211 ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
4213 tmpImage.image_id = VA_INVALID_ID;
4215 obj_surface = SURFACE(surface);
4216 if (obj_surface == NULL) {
4217 // Surface is absent.
4218 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4222 // Lock functionality is absent now.
4223 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4224 // Surface is locked already.
4225 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4229 vaStatus = i965_DeriveImage(
4233 if (vaStatus != VA_STATUS_SUCCESS) {
4237 obj_surface->locked_image_id = tmpImage.image_id;
4239 vaStatus = i965_MapBuffer(
4243 if (vaStatus != VA_STATUS_SUCCESS) {
4247 *fourcc = tmpImage.format.fourcc;
4248 *luma_offset = tmpImage.offsets[0];
4249 *luma_stride = tmpImage.pitches[0];
4250 *chroma_u_offset = tmpImage.offsets[1];
4251 *chroma_u_stride = tmpImage.pitches[1];
4252 *chroma_v_offset = tmpImage.offsets[2];
4253 *chroma_v_stride = tmpImage.pitches[2];
4254 *buffer_name = tmpImage.buf;
4257 if (vaStatus != VA_STATUS_SUCCESS) {
4266 VADriverContextP ctx, /* in */
4267 VASurfaceID surface /* in */
4270 VAStatus vaStatus = VA_STATUS_SUCCESS;
4271 struct i965_driver_data *i965 = i965_driver_data(ctx);
4272 struct object_image *locked_img = NULL;
4273 struct object_surface *obj_surface = NULL;
4275 obj_surface = SURFACE(surface);
4277 if (obj_surface == NULL) {
4278 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4281 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4282 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4286 locked_img = IMAGE(obj_surface->locked_image_id);
4287 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4288 // Work image was deallocated before i965_UnlockSurface()
4289 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4293 vaStatus = i965_UnmapBuffer(
4295 locked_img->image.buf);
4296 if (vaStatus != VA_STATUS_SUCCESS) {
4300 vaStatus = i965_DestroyImage(
4302 locked_img->image.image_id);
4303 if (vaStatus != VA_STATUS_SUCCESS) {
4307 locked_img->image.image_id = VA_INVALID_ID;
4310 obj_surface->locked_image_id = VA_INVALID_ID;
4316 i965_GetSurfaceAttributes(
4317 VADriverContextP ctx,
4319 VASurfaceAttrib *attrib_list,
4320 unsigned int num_attribs
4323 VAStatus vaStatus = VA_STATUS_SUCCESS;
4324 struct i965_driver_data *i965 = i965_driver_data(ctx);
4325 struct object_config *obj_config;
4328 if (config == VA_INVALID_ID)
4329 return VA_STATUS_ERROR_INVALID_CONFIG;
4331 obj_config = CONFIG(config);
4333 if (obj_config == NULL)
4334 return VA_STATUS_ERROR_INVALID_CONFIG;
4336 if (attrib_list == NULL || num_attribs == 0)
4337 return VA_STATUS_ERROR_INVALID_PARAMETER;
4339 for (i = 0; i < num_attribs; i++) {
4340 switch (attrib_list[i].type) {
4341 case VASurfaceAttribPixelFormat:
4342 attrib_list[i].value.type = VAGenericValueTypeInteger;
4343 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4345 if (attrib_list[i].value.value.i == 0) {
4346 if (IS_G4X(i965->intel.device_info)) {
4347 if (obj_config->profile == VAProfileMPEG2Simple ||
4348 obj_config->profile == VAProfileMPEG2Main) {
4349 attrib_list[i].value.value.i = VA_FOURCC_I420;
4352 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4354 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4355 if (obj_config->profile == VAProfileMPEG2Simple ||
4356 obj_config->profile == VAProfileMPEG2Main) {
4357 attrib_list[i].value.value.i = VA_FOURCC_I420;
4358 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4359 obj_config->profile == VAProfileH264Main ||
4360 obj_config->profile == VAProfileH264High) {
4361 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4362 } else if (obj_config->profile == VAProfileNone) {
4363 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4366 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4368 } else if (IS_GEN6(i965->intel.device_info)) {
4369 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4370 } else if (IS_GEN7(i965->intel.device_info) ||
4371 IS_GEN8(i965->intel.device_info)) {
4372 if (obj_config->profile == VAProfileJPEGBaseline)
4373 attrib_list[i].value.value.i = 0; /* internal format */
4375 attrib_list[i].value.value.i = VA_FOURCC_NV12;
4378 if (IS_G4X(i965->intel.device_info)) {
4379 if (obj_config->profile == VAProfileMPEG2Simple ||
4380 obj_config->profile == VAProfileMPEG2Main) {
4381 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4382 attrib_list[i].value.value.i = 0;
4383 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4387 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4389 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4390 if (obj_config->profile == VAProfileMPEG2Simple ||
4391 obj_config->profile == VAProfileMPEG2Main) {
4392 if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
4393 attrib_list[i].value.value.i = 0;
4394 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4396 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4397 obj_config->profile == VAProfileH264Main ||
4398 obj_config->profile == VAProfileH264High) {
4399 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4400 attrib_list[i].value.value.i = 0;
4401 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4403 } else if (obj_config->profile == VAProfileNone) {
4404 switch (attrib_list[i].value.value.i) {
4405 case VA_FOURCC_NV12:
4406 case VA_FOURCC_I420:
4407 case VA_FOURCC_YV12:
4408 case VA_FOURCC_YUY2:
4409 case VA_FOURCC_BGRA:
4410 case VA_FOURCC_BGRX:
4411 case VA_FOURCC_RGBX:
4412 case VA_FOURCC_RGBA:
4415 attrib_list[i].value.value.i = 0;
4416 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4421 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4423 } else if (IS_GEN6(i965->intel.device_info)) {
4424 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4425 obj_config->entrypoint == VAEntrypointVideoProc) {
4426 switch (attrib_list[i].value.value.i) {
4427 case VA_FOURCC_NV12:
4428 case VA_FOURCC_I420:
4429 case VA_FOURCC_YV12:
4430 case VA_FOURCC_YUY2:
4431 case VA_FOURCC_BGRA:
4432 case VA_FOURCC_BGRX:
4433 case VA_FOURCC_RGBX:
4434 case VA_FOURCC_RGBA:
4437 attrib_list[i].value.value.i = 0;
4438 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4442 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4443 attrib_list[i].value.value.i = 0;
4444 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4447 } else if (IS_GEN7(i965->intel.device_info) ||
4448 IS_GEN8(i965->intel.device_info)) {
4449 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4450 obj_config->entrypoint == VAEntrypointVideoProc) {
4451 switch (attrib_list[i].value.value.i) {
4452 case VA_FOURCC_NV12:
4453 case VA_FOURCC_I420:
4454 case VA_FOURCC_YV12:
4457 attrib_list[i].value.value.i = 0;
4458 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4462 if (obj_config->profile == VAProfileJPEGBaseline) {
4463 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4464 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4466 if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
4467 attrib_list[i].value.value.i = 0;
4468 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4476 case VASurfaceAttribMinWidth:
4477 /* FIXME: add support for it later */
4478 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4480 case VASurfaceAttribMaxWidth:
4481 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4483 case VASurfaceAttribMinHeight:
4484 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4486 case VASurfaceAttribMaxHeight:
4487 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4490 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4499 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4501 VASurfaceAttrib *attrib_list,
4502 unsigned int *num_attribs)
4504 VAStatus vaStatus = VA_STATUS_SUCCESS;
4505 struct i965_driver_data *i965 = i965_driver_data(ctx);
4506 struct object_config *obj_config;
4508 VASurfaceAttrib *attribs = NULL;
4510 if (config == VA_INVALID_ID)
4511 return VA_STATUS_ERROR_INVALID_CONFIG;
4513 obj_config = CONFIG(config);
4515 if (obj_config == NULL)
4516 return VA_STATUS_ERROR_INVALID_CONFIG;
4518 if (!attrib_list && !num_attribs)
4519 return VA_STATUS_ERROR_INVALID_PARAMETER;
4521 if (attrib_list == NULL) {
4522 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4523 return VA_STATUS_SUCCESS;
4526 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4528 if (attribs == NULL)
4529 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4531 if (IS_G4X(i965->intel.device_info)) {
4532 if (obj_config->profile == VAProfileMPEG2Simple ||
4533 obj_config->profile == VAProfileMPEG2Main) {
4534 attribs[i].type = VASurfaceAttribPixelFormat;
4535 attribs[i].value.type = VAGenericValueTypeInteger;
4536 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4537 attribs[i].value.value.i = VA_FOURCC_I420;
4540 } else if (IS_IRONLAKE(i965->intel.device_info)) {
4541 switch (obj_config->profile) {
4542 case VAProfileMPEG2Simple:
4543 case VAProfileMPEG2Main:
4544 attribs[i].type = VASurfaceAttribPixelFormat;
4545 attribs[i].value.type = VAGenericValueTypeInteger;
4546 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4547 attribs[i].value.value.i = VA_FOURCC_I420;
4552 case VAProfileH264ConstrainedBaseline:
4553 case VAProfileH264Main:
4554 case VAProfileH264High:
4555 attribs[i].type = VASurfaceAttribPixelFormat;
4556 attribs[i].value.type = VAGenericValueTypeInteger;
4557 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4558 attribs[i].value.value.i = VA_FOURCC_NV12;
4562 attribs[i].type = VASurfaceAttribPixelFormat;
4563 attribs[i].value.type = VAGenericValueTypeInteger;
4564 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4565 attribs[i].value.value.i = VA_FOURCC_NV12;
4568 attribs[i].type = VASurfaceAttribPixelFormat;
4569 attribs[i].value.type = VAGenericValueTypeInteger;
4570 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4571 attribs[i].value.value.i = VA_FOURCC_I420;
4579 } else if (IS_GEN6(i965->intel.device_info)) {
4580 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4581 attribs[i].type = VASurfaceAttribPixelFormat;
4582 attribs[i].value.type = VAGenericValueTypeInteger;
4583 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4584 attribs[i].value.value.i = VA_FOURCC_NV12;
4586 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4587 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4588 attribs[i].type = VASurfaceAttribPixelFormat;
4589 attribs[i].value.type = VAGenericValueTypeInteger;
4590 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4591 attribs[i].value.value.i = VA_FOURCC_NV12;
4594 attribs[i].type = VASurfaceAttribPixelFormat;
4595 attribs[i].value.type = VAGenericValueTypeInteger;
4596 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4597 attribs[i].value.value.i = VA_FOURCC_I420;
4600 attribs[i].type = VASurfaceAttribPixelFormat;
4601 attribs[i].value.type = VAGenericValueTypeInteger;
4602 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4603 attribs[i].value.value.i = VA_FOURCC_YV12;
4606 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4607 attribs[i].type = VASurfaceAttribPixelFormat;
4608 attribs[i].value.type = VAGenericValueTypeInteger;
4609 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4610 attribs[i].value.value.i = VA_FOURCC_YUY2;
4613 attribs[i].type = VASurfaceAttribPixelFormat;
4614 attribs[i].value.type = VAGenericValueTypeInteger;
4615 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4616 attribs[i].value.value.i = VA_FOURCC_RGBA;
4619 attribs[i].type = VASurfaceAttribPixelFormat;
4620 attribs[i].value.type = VAGenericValueTypeInteger;
4621 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4622 attribs[i].value.value.i = VA_FOURCC_RGBX;
4626 } else if (IS_GEN7(i965->intel.device_info)) {
4627 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4628 if (obj_config->profile == VAProfileJPEGBaseline) {
4629 attribs[i].type = VASurfaceAttribPixelFormat;
4630 attribs[i].value.type = VAGenericValueTypeInteger;
4631 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4632 attribs[i].value.value.i = VA_FOURCC_IMC3;
4635 attribs[i].type = VASurfaceAttribPixelFormat;
4636 attribs[i].value.type = VAGenericValueTypeInteger;
4637 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4638 attribs[i].value.value.i = VA_FOURCC_IMC1;
4641 attribs[i].type = VASurfaceAttribPixelFormat;
4642 attribs[i].value.type = VAGenericValueTypeInteger;
4643 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4644 attribs[i].value.value.i = VA_FOURCC_Y800;
4647 attribs[i].type = VASurfaceAttribPixelFormat;
4648 attribs[i].value.type = VAGenericValueTypeInteger;
4649 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4650 attribs[i].value.value.i = VA_FOURCC_411P;
4653 attribs[i].type = VASurfaceAttribPixelFormat;
4654 attribs[i].value.type = VAGenericValueTypeInteger;
4655 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4656 attribs[i].value.value.i = VA_FOURCC_422H;
4659 attribs[i].type = VASurfaceAttribPixelFormat;
4660 attribs[i].value.type = VAGenericValueTypeInteger;
4661 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4662 attribs[i].value.value.i = VA_FOURCC_422V;
4665 attribs[i].type = VASurfaceAttribPixelFormat;
4666 attribs[i].value.type = VAGenericValueTypeInteger;
4667 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4668 attribs[i].value.value.i = VA_FOURCC_444P;
4671 attribs[i].type = VASurfaceAttribPixelFormat;
4672 attribs[i].value.type = VAGenericValueTypeInteger;
4673 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4674 attribs[i].value.value.i = VA_FOURCC_NV12;
4677 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4678 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4679 attribs[i].type = VASurfaceAttribPixelFormat;
4680 attribs[i].value.type = VAGenericValueTypeInteger;
4681 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4682 attribs[i].value.value.i = VA_FOURCC_NV12;
4685 attribs[i].type = VASurfaceAttribPixelFormat;
4686 attribs[i].value.type = VAGenericValueTypeInteger;
4687 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4688 attribs[i].value.value.i = VA_FOURCC_I420;
4691 attribs[i].type = VASurfaceAttribPixelFormat;
4692 attribs[i].value.type = VAGenericValueTypeInteger;
4693 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4694 attribs[i].value.value.i = VA_FOURCC_YV12;
4697 attribs[i].type = VASurfaceAttribPixelFormat;
4698 attribs[i].value.type = VAGenericValueTypeInteger;
4699 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4700 attribs[i].value.value.i = VA_FOURCC_IMC3;
4703 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4704 attribs[i].type = VASurfaceAttribPixelFormat;
4705 attribs[i].value.type = VAGenericValueTypeInteger;
4706 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4707 attribs[i].value.value.i = VA_FOURCC_YUY2;
4710 attribs[i].type = VASurfaceAttribPixelFormat;
4711 attribs[i].value.type = VAGenericValueTypeInteger;
4712 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4713 attribs[i].value.value.i = VA_FOURCC_RGBA;
4716 attribs[i].type = VASurfaceAttribPixelFormat;
4717 attribs[i].value.type = VAGenericValueTypeInteger;
4718 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4719 attribs[i].value.value.i = VA_FOURCC_RGBX;
4722 attribs[i].type = VASurfaceAttribPixelFormat;
4723 attribs[i].value.type = VAGenericValueTypeInteger;
4724 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4725 attribs[i].value.value.i = VA_FOURCC_YV16;
4729 } else if (IS_GEN8(i965->intel.device_info)) {
4730 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4731 if (obj_config->profile == VAProfileJPEGBaseline) {
4732 attribs[i].type = VASurfaceAttribPixelFormat;
4733 attribs[i].value.type = VAGenericValueTypeInteger;
4734 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4735 attribs[i].value.value.i = VA_FOURCC_IMC3;
4738 attribs[i].type = VASurfaceAttribPixelFormat;
4739 attribs[i].value.type = VAGenericValueTypeInteger;
4740 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4741 attribs[i].value.value.i = VA_FOURCC_IMC1;
4744 attribs[i].type = VASurfaceAttribPixelFormat;
4745 attribs[i].value.type = VAGenericValueTypeInteger;
4746 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4747 attribs[i].value.value.i = VA_FOURCC_Y800;
4750 attribs[i].type = VASurfaceAttribPixelFormat;
4751 attribs[i].value.type = VAGenericValueTypeInteger;
4752 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4753 attribs[i].value.value.i = VA_FOURCC_411P;
4756 attribs[i].type = VASurfaceAttribPixelFormat;
4757 attribs[i].value.type = VAGenericValueTypeInteger;
4758 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4759 attribs[i].value.value.i = VA_FOURCC_422H;
4762 attribs[i].type = VASurfaceAttribPixelFormat;
4763 attribs[i].value.type = VAGenericValueTypeInteger;
4764 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4765 attribs[i].value.value.i = VA_FOURCC_422V;
4768 attribs[i].type = VASurfaceAttribPixelFormat;
4769 attribs[i].value.type = VAGenericValueTypeInteger;
4770 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4771 attribs[i].value.value.i = VA_FOURCC_444P;
4774 attribs[i].type = VASurfaceAttribPixelFormat;
4775 attribs[i].value.type = VAGenericValueTypeInteger;
4776 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4777 attribs[i].value.value.i = VA_FOURCC_NV12;
4780 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4781 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4783 attribs[i].type = VASurfaceAttribPixelFormat;
4784 attribs[i].value.type = VAGenericValueTypeInteger;
4785 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4786 attribs[i].value.value.i = VA_FOURCC_NV12;
4789 attribs[i].type = VASurfaceAttribPixelFormat;
4790 attribs[i].value.type = VAGenericValueTypeInteger;
4791 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4792 attribs[i].value.value.i = VA_FOURCC_I420;
4795 attribs[i].type = VASurfaceAttribPixelFormat;
4796 attribs[i].value.type = VAGenericValueTypeInteger;
4797 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4798 attribs[i].value.value.i = VA_FOURCC_YV12;
4801 attribs[i].type = VASurfaceAttribPixelFormat;
4802 attribs[i].value.type = VAGenericValueTypeInteger;
4803 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4804 attribs[i].value.value.i = VA_FOURCC_IMC3;
4807 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4808 attribs[i].type = VASurfaceAttribPixelFormat;
4809 attribs[i].value.type = VAGenericValueTypeInteger;
4810 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4811 attribs[i].value.value.i = VA_FOURCC_YUY2;
4814 attribs[i].type = VASurfaceAttribPixelFormat;
4815 attribs[i].value.type = VAGenericValueTypeInteger;
4816 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4817 attribs[i].value.value.i = VA_FOURCC_RGBA;
4820 attribs[i].type = VASurfaceAttribPixelFormat;
4821 attribs[i].value.type = VAGenericValueTypeInteger;
4822 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4823 attribs[i].value.value.i = VA_FOURCC_RGBX;
4826 attribs[i].type = VASurfaceAttribPixelFormat;
4827 attribs[i].value.type = VAGenericValueTypeInteger;
4828 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4829 attribs[i].value.value.i = VA_FOURCC_BGRA;
4832 attribs[i].type = VASurfaceAttribPixelFormat;
4833 attribs[i].value.type = VAGenericValueTypeInteger;
4834 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4835 attribs[i].value.value.i = VA_FOURCC_BGRX;
4838 attribs[i].type = VASurfaceAttribPixelFormat;
4839 attribs[i].value.type = VAGenericValueTypeInteger;
4840 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4841 attribs[i].value.value.i = VA_FOURCC_YV16;
4847 attribs[i].type = VASurfaceAttribMemoryType;
4848 attribs[i].value.type = VAGenericValueTypeInteger;
4849 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4850 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
4851 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
4852 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
4855 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
4856 attribs[i].value.type = VAGenericValueTypePointer;
4857 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
4858 attribs[i].value.value.p = NULL; /* ignore */
4861 if (i > *num_attribs) {
4864 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4868 memcpy(attrib_list, attribs, i * sizeof(*attribs));
4875 i965_os_has_ring_support(VADriverContextP ctx,
4878 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4882 return i965->intel.has_bsd;
4885 return i965->intel.has_blt;
4887 case I965_RING_VEBOX:
4888 return i965->intel.has_vebox;
4890 case I965_RING_NULL:
4891 return 1; /* Always support */
4894 /* should never get here */
4903 * Query video processing pipeline
4905 VAStatus i965_QueryVideoProcFilters(
4906 VADriverContextP ctx,
4907 VAContextID context,
4908 VAProcFilterType *filters,
4909 unsigned int *num_filters
4912 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4913 unsigned int i = 0, num = 0;
4915 if (!num_filters || !filters)
4916 return VA_STATUS_ERROR_INVALID_PARAMETER;
4918 for (i = 0; i < i965->codec_info->num_filters; i++) {
4919 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
4920 if (num == *num_filters) {
4921 *num_filters = i965->codec_info->num_filters;
4923 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4926 filters[num++] = i965->codec_info->filters[i].type;
4932 return VA_STATUS_SUCCESS;
4935 VAStatus i965_QueryVideoProcFilterCaps(
4936 VADriverContextP ctx,
4937 VAContextID context,
4938 VAProcFilterType type,
4940 unsigned int *num_filter_caps
4944 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4946 if (!filter_caps || !num_filter_caps)
4947 return VA_STATUS_ERROR_INVALID_PARAMETER;
4949 for (i = 0; i < i965->codec_info->num_filters; i++) {
4950 if (type == i965->codec_info->filters[i].type &&
4951 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
4955 if (i == i965->codec_info->num_filters)
4956 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4961 case VAProcFilterNoiseReduction:
4962 case VAProcFilterSharpening:
4964 VAProcFilterCap *cap = filter_caps;
4966 if (*num_filter_caps < 1) {
4967 *num_filter_caps = 1;
4968 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4971 cap->range.min_value = 0.0;
4972 cap->range.max_value = 1.0;
4973 cap->range.default_value = 0.5;
4974 cap->range.step = 0.03125; /* 1.0 / 32 */
4980 case VAProcFilterDeinterlacing:
4982 VAProcFilterCapDeinterlacing *cap = filter_caps;
4984 if (*num_filter_caps < VAProcDeinterlacingCount) {
4985 *num_filter_caps = VAProcDeinterlacingCount;
4986 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4989 cap->type = VAProcDeinterlacingBob;
4994 if (i965->codec_info->has_di_motion_adptive) {
4995 cap->type = VAProcDeinterlacingMotionAdaptive;
5000 if (i965->codec_info->has_di_motion_compensated) {
5001 cap->type = VAProcDeinterlacingMotionCompensated;
5009 case VAProcFilterColorBalance:
5011 VAProcFilterCapColorBalance *cap = filter_caps;
5013 if (*num_filter_caps < VAProcColorBalanceCount) {
5014 *num_filter_caps = VAProcColorBalanceCount;
5015 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
5018 cap->type = VAProcColorBalanceHue;
5019 cap->range.min_value = -180.0;
5020 cap->range.max_value = 180.0;
5021 cap->range.default_value = 0.0;
5022 cap->range.step = 1.0;
5026 cap->type = VAProcColorBalanceSaturation;
5027 cap->range.min_value = 0.0;
5028 cap->range.max_value = 10.0;
5029 cap->range.default_value = 1.0;
5030 cap->range.step = 0.1;
5034 cap->type = VAProcColorBalanceBrightness;
5035 cap->range.min_value = -100.0;
5036 cap->range.max_value = 100.0;
5037 cap->range.default_value = 0.0;
5038 cap->range.step = 1.0;
5042 cap->type = VAProcColorBalanceContrast;
5043 cap->range.min_value = 0.0;
5044 cap->range.max_value = 10.0;
5045 cap->range.default_value = 1.0;
5046 cap->range.step = 0.1;
5058 *num_filter_caps = i;
5060 return VA_STATUS_SUCCESS;
5063 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
5064 VAProcColorStandardBT601,
5067 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
5068 VAProcColorStandardBT601,
5071 VAStatus i965_QueryVideoProcPipelineCaps(
5072 VADriverContextP ctx,
5073 VAContextID context,
5074 VABufferID *filters,
5075 unsigned int num_filters,
5076 VAProcPipelineCaps *pipeline_cap /* out */
5079 struct i965_driver_data * const i965 = i965_driver_data(ctx);
5082 pipeline_cap->pipeline_flags = 0;
5083 pipeline_cap->filter_flags = 0;
5084 pipeline_cap->num_forward_references = 0;
5085 pipeline_cap->num_backward_references = 0;
5086 pipeline_cap->num_input_color_standards = 1;
5087 pipeline_cap->input_color_standards = vpp_input_color_standards;
5088 pipeline_cap->num_output_color_standards = 1;
5089 pipeline_cap->output_color_standards = vpp_output_color_standards;
5091 for (i = 0; i < num_filters; i++) {
5092 struct object_buffer *obj_buffer = BUFFER(filters[i]);
5095 !obj_buffer->buffer_store ||
5096 !obj_buffer->buffer_store->buffer)
5097 return VA_STATUS_ERROR_INVALID_BUFFER;
5099 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
5101 if (base->type == VAProcFilterNoiseReduction) {
5102 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
5104 } else if (base->type == VAProcFilterDeinterlacing) {
5105 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
5107 ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
5108 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5109 deint->algorithm == VAProcDeinterlacingMotionCompensated,
5110 VA_STATUS_ERROR_INVALID_PARAMETER);
5112 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5113 deint->algorithm == VAProcDeinterlacingMotionCompensated);
5114 pipeline_cap->num_forward_references++;
5115 } else if (base->type == VAProcFilterSkinToneEnhancement) {
5116 VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
5121 return VA_STATUS_SUCCESS;
5124 extern const struct hw_codec_info *i965_get_codec_info(int devid);
5127 i965_driver_data_init(VADriverContextP ctx)
5129 struct i965_driver_data *i965 = i965_driver_data(ctx);
5131 i965->codec_info = i965_get_codec_info(i965->intel.device_id);
5133 if (!i965->codec_info)
5136 if (object_heap_init(&i965->config_heap,
5137 sizeof(struct object_config),
5139 goto err_config_heap;
5140 if (object_heap_init(&i965->context_heap,
5141 sizeof(struct object_context),
5143 goto err_context_heap;
5145 if (object_heap_init(&i965->surface_heap,
5146 sizeof(struct object_surface),
5148 goto err_surface_heap;
5149 if (object_heap_init(&i965->buffer_heap,
5150 sizeof(struct object_buffer),
5152 goto err_buffer_heap;
5153 if (object_heap_init(&i965->image_heap,
5154 sizeof(struct object_image),
5156 goto err_image_heap;
5157 if (object_heap_init(&i965->subpic_heap,
5158 sizeof(struct object_subpic),
5160 goto err_subpic_heap;
5162 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5163 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5164 _i965InitMutex(&i965->render_mutex);
5165 _i965InitMutex(&i965->pp_mutex);
5170 object_heap_destroy(&i965->image_heap);
5172 object_heap_destroy(&i965->buffer_heap);
5174 object_heap_destroy(&i965->surface_heap);
5176 object_heap_destroy(&i965->context_heap);
5178 object_heap_destroy(&i965->config_heap);
5185 i965_driver_data_terminate(VADriverContextP ctx)
5187 struct i965_driver_data *i965 = i965_driver_data(ctx);
5189 _i965DestroyMutex(&i965->pp_mutex);
5190 _i965DestroyMutex(&i965->render_mutex);
5193 intel_batchbuffer_free(i965->batch);
5196 intel_batchbuffer_free(i965->pp_batch);
5198 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
5199 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
5200 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
5201 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
5202 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
5203 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
5207 bool (*init)(VADriverContextP ctx);
5208 void (*terminate)(VADriverContextP ctx);
5210 } i965_sub_ops[] = {
5213 intel_driver_terminate,
5218 i965_driver_data_init,
5219 i965_driver_data_terminate,
5224 i965_display_attributes_init,
5225 i965_display_attributes_terminate,
5230 i965_post_processing_init,
5231 i965_post_processing_terminate,
5237 i965_render_terminate,
5241 #ifdef HAVE_VA_WAYLAND
5243 i965_output_wayland_init,
5244 i965_output_wayland_terminate,
5251 i965_output_dri_init,
5252 i965_output_dri_terminate,
5259 i965_Init(VADriverContextP ctx)
5261 struct i965_driver_data *i965 = i965_driver_data(ctx);
5263 const char *chipset;
5265 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
5266 if ((i965_sub_ops[i].display_type == 0 ||
5267 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
5268 !i965_sub_ops[i].init(ctx))
5272 if (i == ARRAY_ELEMS(i965_sub_ops)) {
5273 switch (i965->intel.device_id) {
5275 #define CHIPSET(id, family, dev, str) case id: chipset = str; break;
5276 #include "i965_pciids.h"
5278 chipset = "Unknown Intel Chipset";
5282 sprintf(i965->va_vendor, "%s %s driver for %s - %d.%d.%d",
5283 INTEL_STR_DRIVER_VENDOR,
5284 INTEL_STR_DRIVER_NAME,
5286 INTEL_DRIVER_MAJOR_VERSION,
5287 INTEL_DRIVER_MINOR_VERSION,
5288 INTEL_DRIVER_MICRO_VERSION);
5290 if (INTEL_DRIVER_PRE_VERSION > 0) {
5291 const int len = strlen(i965->va_vendor);
5292 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
5295 i965->current_context_id = VA_INVALID_ID;
5297 return VA_STATUS_SUCCESS;
5301 for (; i >= 0; i--) {
5302 if (i965_sub_ops[i].display_type == 0 ||
5303 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5304 i965_sub_ops[i].terminate(ctx);
5308 return VA_STATUS_ERROR_UNKNOWN;
5313 i965_Terminate(VADriverContextP ctx)
5315 struct i965_driver_data *i965 = i965_driver_data(ctx);
5319 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
5320 if (i965_sub_ops[i - 1].display_type == 0 ||
5321 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5322 i965_sub_ops[i - 1].terminate(ctx);
5326 ctx->pDriverData = NULL;
5329 return VA_STATUS_SUCCESS;
5333 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
5336 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
5338 struct VADriverVTable * const vtable = ctx->vtable;
5339 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
5341 struct i965_driver_data *i965;
5342 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
5344 ctx->version_major = VA_MAJOR_VERSION;
5345 ctx->version_minor = VA_MINOR_VERSION;
5346 ctx->max_profiles = I965_MAX_PROFILES;
5347 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5348 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5349 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5350 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5351 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5353 vtable->vaTerminate = i965_Terminate;
5354 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5355 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5356 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5357 vtable->vaCreateConfig = i965_CreateConfig;
5358 vtable->vaDestroyConfig = i965_DestroyConfig;
5359 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5360 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5361 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5362 vtable->vaCreateContext = i965_CreateContext;
5363 vtable->vaDestroyContext = i965_DestroyContext;
5364 vtable->vaCreateBuffer = i965_CreateBuffer;
5365 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5366 vtable->vaMapBuffer = i965_MapBuffer;
5367 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5368 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5369 vtable->vaBeginPicture = i965_BeginPicture;
5370 vtable->vaRenderPicture = i965_RenderPicture;
5371 vtable->vaEndPicture = i965_EndPicture;
5372 vtable->vaSyncSurface = i965_SyncSurface;
5373 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5374 vtable->vaPutSurface = i965_PutSurface;
5375 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5376 vtable->vaCreateImage = i965_CreateImage;
5377 vtable->vaDeriveImage = i965_DeriveImage;
5378 vtable->vaDestroyImage = i965_DestroyImage;
5379 vtable->vaSetImagePalette = i965_SetImagePalette;
5380 vtable->vaGetImage = i965_GetImage;
5381 vtable->vaPutImage = i965_PutImage;
5382 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5383 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5384 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5385 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5386 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5387 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5388 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5389 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5390 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5391 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5392 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5393 vtable->vaBufferInfo = i965_BufferInfo;
5394 vtable->vaLockSurface = i965_LockSurface;
5395 vtable->vaUnlockSurface = i965_UnlockSurface;
5396 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5397 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5398 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5400 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5401 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5402 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5404 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5407 ctx->pDriverData = NULL;
5409 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5412 ctx->pDriverData = (void *)i965;
5413 ret = i965_Init(ctx);
5415 if (ret == VA_STATUS_SUCCESS) {
5416 ctx->str_vendor = i965->va_vendor;
5419 ctx->pDriverData = NULL;