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 I965_SURFACETYPE_RGBA = 1,
100 I965_SURFACETYPE_YUV,
101 I965_SURFACETYPE_INDEXED
104 /* List of supported display attributes */
105 static const VADisplayAttribute i965_display_attributes[] = {
107 VADisplayAttribBrightness,
108 -100, 100, DEFAULT_BRIGHTNESS,
109 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
113 VADisplayAttribContrast,
114 0, 100, DEFAULT_CONTRAST,
115 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
120 -180, 180, DEFAULT_HUE,
121 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
125 VADisplayAttribSaturation,
126 0, 100, DEFAULT_SATURATION,
127 VA_DISPLAY_ATTRIB_GETTABLE | VA_DISPLAY_ATTRIB_SETTABLE
131 VADisplayAttribRotation,
132 0, 3, VA_ROTATION_NONE,
133 VA_DISPLAY_ATTRIB_GETTABLE|VA_DISPLAY_ATTRIB_SETTABLE
137 /* List of supported image formats */
140 VAImageFormat va_format;
141 } i965_image_format_map_t;
143 static const i965_image_format_map_t
144 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
145 { I965_SURFACETYPE_YUV,
146 { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } },
147 { I965_SURFACETYPE_YUV,
148 { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } },
149 { I965_SURFACETYPE_YUV,
150 { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } },
151 { I965_SURFACETYPE_YUV,
152 { VA_FOURCC('Y','U','Y','2'), VA_LSB_FIRST, 16, } },
153 { I965_SURFACETYPE_YUV,
154 { VA_FOURCC('U','Y','V','Y'), VA_LSB_FIRST, 16, } },
155 { I965_SURFACETYPE_RGBA,
156 { VA_FOURCC('R','G','B','X'), VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
157 { I965_SURFACETYPE_RGBA,
158 { VA_FOURCC('B','G','R','X'), VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
161 /* List of supported subpicture formats */
165 VAImageFormat va_format;
166 unsigned int va_flags;
167 } i965_subpic_format_map_t;
169 #define COMMON_SUBPICTURE_FLAGS \
170 (VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD| \
171 VA_SUBPICTURE_GLOBAL_ALPHA)
173 static const i965_subpic_format_map_t
174 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
175 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
176 { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, },
177 COMMON_SUBPICTURE_FLAGS },
178 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
179 { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, },
180 COMMON_SUBPICTURE_FLAGS },
181 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
182 { VA_FOURCC('I','A','8','8'), VA_MSB_FIRST, 16, },
183 COMMON_SUBPICTURE_FLAGS },
184 { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
185 { VA_FOURCC('A','I','8','8'), VA_MSB_FIRST, 16, },
186 COMMON_SUBPICTURE_FLAGS },
187 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
188 { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
189 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
190 COMMON_SUBPICTURE_FLAGS },
191 { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
192 { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
193 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
194 COMMON_SUBPICTURE_FLAGS },
197 static const i965_subpic_format_map_t *
198 get_subpic_format(const VAImageFormat *va_format)
201 for (i = 0; i965_subpic_formats_map[i].type != 0; i++) {
202 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[i];
203 if (m->va_format.fourcc == va_format->fourcc &&
204 (m->type == I965_SURFACETYPE_RGBA ?
205 (m->va_format.byte_order == va_format->byte_order &&
206 m->va_format.red_mask == va_format->red_mask &&
207 m->va_format.green_mask == va_format->green_mask &&
208 m->va_format.blue_mask == va_format->blue_mask &&
209 m->va_format.alpha_mask == va_format->alpha_mask) : 1))
215 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
216 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
217 static struct hw_codec_info g4x_hw_codec_info = {
218 .dec_hw_context_init = g4x_dec_hw_context_init,
219 .enc_hw_context_init = NULL,
220 .proc_hw_context_init = NULL,
224 .has_mpeg2_decoding = 1,
229 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
230 static struct hw_codec_info ironlake_hw_codec_info = {
231 .dec_hw_context_init = ironlake_dec_hw_context_init,
232 .enc_hw_context_init = NULL,
233 .proc_hw_context_init = i965_proc_context_init,
237 .has_mpeg2_decoding = 1,
238 .has_h264_decoding = 1,
240 .has_accelerated_putimage = 1,
245 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
246 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
247 static struct hw_codec_info gen6_hw_codec_info = {
248 .dec_hw_context_init = gen6_dec_hw_context_init,
249 .enc_hw_context_init = gen6_enc_hw_context_init,
250 .proc_hw_context_init = i965_proc_context_init,
254 .has_mpeg2_decoding = 1,
255 .has_h264_decoding = 1,
256 .has_h264_encoding = 1,
257 .has_vc1_decoding = 1,
259 .has_accelerated_getimage = 1,
260 .has_accelerated_putimage = 1,
261 .has_tiled_surface = 1,
265 { VAProcFilterNoiseReduction, I965_RING_NULL },
266 { VAProcFilterDeinterlacing, I965_RING_NULL },
270 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
271 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
272 static struct hw_codec_info gen7_hw_codec_info = {
273 .dec_hw_context_init = gen7_dec_hw_context_init,
274 .enc_hw_context_init = gen7_enc_hw_context_init,
275 .proc_hw_context_init = i965_proc_context_init,
279 .has_mpeg2_decoding = 1,
280 .has_mpeg2_encoding = 1,
281 .has_h264_decoding = 1,
282 .has_h264_encoding = 1,
283 .has_vc1_decoding = 1,
284 .has_jpeg_decoding = 1,
286 .has_accelerated_getimage = 1,
287 .has_accelerated_putimage = 1,
288 .has_tiled_surface = 1,
289 .has_di_motion_adptive = 1,
293 { VAProcFilterNoiseReduction, I965_RING_NULL },
294 { VAProcFilterDeinterlacing, I965_RING_NULL },
298 extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
299 static struct hw_codec_info gen75_hw_codec_info = {
300 .dec_hw_context_init = gen75_dec_hw_context_init,
301 .enc_hw_context_init = gen75_enc_hw_context_init,
302 .proc_hw_context_init = gen75_proc_context_init,
306 .has_mpeg2_decoding = 1,
307 .has_mpeg2_encoding = 1,
308 .has_h264_decoding = 1,
309 .has_h264_encoding = 1,
310 .has_vc1_decoding = 1,
311 .has_jpeg_decoding = 1,
313 .has_accelerated_getimage = 1,
314 .has_accelerated_putimage = 1,
315 .has_tiled_surface = 1,
316 .has_di_motion_adptive = 1,
317 .has_di_motion_compensated = 1,
321 { VAProcFilterNoiseReduction, I965_RING_VEBOX },
322 { VAProcFilterDeinterlacing, I965_RING_VEBOX },
323 { VAProcFilterSharpening, I965_RING_NULL },
324 { VAProcFilterColorBalance, I965_RING_VEBOX},
328 /* TODO: Add the separate call back function for Gen8 */
329 static struct hw_codec_info gen8_hw_codec_info = {
330 .dec_hw_context_init = gen8_dec_hw_context_init,
331 .enc_hw_context_init = gen8_enc_hw_context_init,
332 .proc_hw_context_init = gen75_proc_context_init,
336 .has_mpeg2_decoding = 1,
337 .has_mpeg2_encoding = 1,
338 .has_h264_decoding = 1,
339 .has_h264_encoding = 1,
340 .has_vc1_decoding = 1,
341 .has_jpeg_decoding = 1,
343 .has_accelerated_getimage = 1,
344 .has_accelerated_putimage = 1,
345 .has_tiled_surface = 1,
346 .has_di_motion_adptive = 1,
347 .has_di_motion_compensated = 1,
348 .has_vp8_decoding = 1,
352 { VAProcFilterNoiseReduction, I965_RING_VEBOX },
353 { VAProcFilterDeinterlacing, I965_RING_VEBOX },
354 { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
355 { VAProcFilterColorBalance, I965_RING_VEBOX},
359 #define I965_PACKED_HEADER_BASE 0
360 #define I965_PACKED_MISC_HEADER_BASE 3
363 va_enc_packed_type_to_idx(int packed_type)
367 if (packed_type & VAEncPackedHeaderMiscMask) {
368 idx = I965_PACKED_MISC_HEADER_BASE;
369 packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
370 assert(packed_type > 0);
371 idx += (packed_type - 1);
373 idx = I965_PACKED_HEADER_BASE;
375 switch (packed_type) {
376 case VAEncPackedHeaderSequence:
377 idx = I965_PACKED_HEADER_BASE + 0;
380 case VAEncPackedHeaderPicture:
381 idx = I965_PACKED_HEADER_BASE + 1;
384 case VAEncPackedHeaderSlice:
385 idx = I965_PACKED_HEADER_BASE + 2;
389 /* Should not get here */
400 i965_QueryConfigProfiles(VADriverContextP ctx,
401 VAProfile *profile_list, /* out */
402 int *num_profiles) /* out */
404 struct i965_driver_data * const i965 = i965_driver_data(ctx);
407 if (HAS_MPEG2_DECODING(i965) ||
408 HAS_MPEG2_ENCODING(i965)) {
409 profile_list[i++] = VAProfileMPEG2Simple;
410 profile_list[i++] = VAProfileMPEG2Main;
413 if (HAS_H264_DECODING(i965) ||
414 HAS_H264_ENCODING(i965)) {
415 profile_list[i++] = VAProfileH264ConstrainedBaseline;
416 profile_list[i++] = VAProfileH264Main;
417 profile_list[i++] = VAProfileH264High;
420 if (HAS_VC1_DECODING(i965)) {
421 profile_list[i++] = VAProfileVC1Simple;
422 profile_list[i++] = VAProfileVC1Main;
423 profile_list[i++] = VAProfileVC1Advanced;
427 profile_list[i++] = VAProfileNone;
430 if (HAS_JPEG_DECODING(i965)) {
431 profile_list[i++] = VAProfileJPEGBaseline;
434 if (HAS_VP8_DECODING(i965) ||
435 HAS_VP8_ENCODING(i965)) {
436 profile_list[i++] = VAProfileVP8Version0_3;
439 /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
440 assert(i <= I965_MAX_PROFILES);
443 return VA_STATUS_SUCCESS;
447 i965_QueryConfigEntrypoints(VADriverContextP ctx,
449 VAEntrypoint *entrypoint_list, /* out */
450 int *num_entrypoints) /* out */
452 struct i965_driver_data * const i965 = i965_driver_data(ctx);
456 case VAProfileMPEG2Simple:
457 case VAProfileMPEG2Main:
458 if (HAS_MPEG2_DECODING(i965))
459 entrypoint_list[n++] = VAEntrypointVLD;
461 if (HAS_MPEG2_ENCODING(i965))
462 entrypoint_list[n++] = VAEntrypointEncSlice;
466 case VAProfileH264ConstrainedBaseline:
467 case VAProfileH264Main:
468 case VAProfileH264High:
469 if (HAS_H264_DECODING(i965))
470 entrypoint_list[n++] = VAEntrypointVLD;
472 if (HAS_H264_ENCODING(i965))
473 entrypoint_list[n++] = VAEntrypointEncSlice;
477 case VAProfileVC1Simple:
478 case VAProfileVC1Main:
479 case VAProfileVC1Advanced:
480 if (HAS_VC1_DECODING(i965))
481 entrypoint_list[n++] = VAEntrypointVLD;
486 entrypoint_list[n++] = VAEntrypointVideoProc;
489 case VAProfileJPEGBaseline:
490 if (HAS_JPEG_DECODING(i965))
491 entrypoint_list[n++] = VAEntrypointVLD;
494 case VAProfileVP8Version0_3:
495 if (HAS_VP8_DECODING(i965))
496 entrypoint_list[n++] = VAEntrypointVLD;
498 if (HAS_VP8_ENCODING(i965))
499 entrypoint_list[n++] = VAEntrypointEncSlice;
505 /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
506 assert(n <= I965_MAX_ENTRYPOINTS);
507 *num_entrypoints = n;
508 return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
512 i965_GetConfigAttributes(VADriverContextP ctx,
514 VAEntrypoint entrypoint,
515 VAConfigAttrib *attrib_list, /* in/out */
520 /* Other attributes don't seem to be defined */
521 /* What to do if we don't know the attribute? */
522 for (i = 0; i < num_attribs; i++) {
523 switch (attrib_list[i].type) {
524 case VAConfigAttribRTFormat:
525 attrib_list[i].value = VA_RT_FORMAT_YUV420;
528 case VAConfigAttribRateControl:
529 if (entrypoint == VAEntrypointEncSlice) {
530 attrib_list[i].value = VA_RC_CQP;
532 if (profile != VAProfileMPEG2Main &&
533 profile != VAProfileMPEG2Simple)
534 attrib_list[i].value |= VA_RC_CBR;
538 case VAConfigAttribEncPackedHeaders:
539 if (entrypoint == VAEntrypointEncSlice) {
540 attrib_list[i].value = VA_ENC_PACKED_HEADER_SEQUENCE | VA_ENC_PACKED_HEADER_PICTURE | VA_ENC_PACKED_HEADER_MISC;
544 case VAConfigAttribEncMaxRefFrames:
545 if (entrypoint == VAEntrypointEncSlice) {
546 attrib_list[i].value = (1 << 16) | (1 << 0);
552 attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
557 return VA_STATUS_SUCCESS;
561 i965_destroy_config(struct object_heap *heap, struct object_base *obj)
563 object_heap_free(heap, obj);
567 i965_update_attribute(struct object_config *obj_config, VAConfigAttrib *attrib)
571 /* Check existing attrbiutes */
572 for (i = 0; i < obj_config->num_attribs; i++) {
573 if (obj_config->attrib_list[i].type == attrib->type) {
574 /* Update existing attribute */
575 obj_config->attrib_list[i].value = attrib->value;
576 return VA_STATUS_SUCCESS;
580 if (obj_config->num_attribs < I965_MAX_CONFIG_ATTRIBUTES) {
581 i = obj_config->num_attribs;
582 obj_config->attrib_list[i].type = attrib->type;
583 obj_config->attrib_list[i].value = attrib->value;
584 obj_config->num_attribs++;
585 return VA_STATUS_SUCCESS;
588 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
592 i965_CreateConfig(VADriverContextP ctx,
594 VAEntrypoint entrypoint,
595 VAConfigAttrib *attrib_list,
597 VAConfigID *config_id) /* out */
599 struct i965_driver_data * const i965 = i965_driver_data(ctx);
600 struct object_config *obj_config;
605 /* Validate profile & entrypoint */
607 case VAProfileMPEG2Simple:
608 case VAProfileMPEG2Main:
609 if ((HAS_MPEG2_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
610 (HAS_MPEG2_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
611 vaStatus = VA_STATUS_SUCCESS;
613 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
617 case VAProfileH264ConstrainedBaseline:
618 case VAProfileH264Main:
619 case VAProfileH264High:
620 if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
621 (HAS_H264_ENCODING(i965) && VAEntrypointEncSlice == entrypoint)) {
622 vaStatus = VA_STATUS_SUCCESS;
624 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
629 case VAProfileVC1Simple:
630 case VAProfileVC1Main:
631 case VAProfileVC1Advanced:
632 if (HAS_VC1_DECODING(i965) && VAEntrypointVLD == entrypoint) {
633 vaStatus = VA_STATUS_SUCCESS;
635 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
641 if (HAS_VPP(i965) && VAEntrypointVideoProc == entrypoint) {
642 vaStatus = VA_STATUS_SUCCESS;
644 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
649 case VAProfileJPEGBaseline:
650 if (HAS_JPEG_DECODING(i965) && VAEntrypointVLD == entrypoint) {
651 vaStatus = VA_STATUS_SUCCESS;
653 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
658 case VAProfileVP8Version0_3:
659 if ((HAS_VP8_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
660 (HAS_VP8_ENCODING(i965) && VAEntrypointEncSlice == entrypoint))
661 vaStatus = VA_STATUS_SUCCESS;
663 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
668 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
672 if (VA_STATUS_SUCCESS != vaStatus) {
676 configID = NEW_CONFIG_ID();
677 obj_config = CONFIG(configID);
679 if (NULL == obj_config) {
680 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
684 obj_config->profile = profile;
685 obj_config->entrypoint = entrypoint;
686 obj_config->attrib_list[0].type = VAConfigAttribRTFormat;
687 obj_config->attrib_list[0].value = VA_RT_FORMAT_YUV420;
688 obj_config->num_attribs = 1;
690 for(i = 0; i < num_attribs; i++) {
691 vaStatus = i965_update_attribute(obj_config, &(attrib_list[i]));
693 if (VA_STATUS_SUCCESS != vaStatus) {
699 if (VA_STATUS_SUCCESS != vaStatus) {
700 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
702 *config_id = configID;
709 i965_DestroyConfig(VADriverContextP ctx, VAConfigID config_id)
711 struct i965_driver_data *i965 = i965_driver_data(ctx);
712 struct object_config *obj_config = CONFIG(config_id);
715 if (NULL == obj_config) {
716 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
720 i965_destroy_config(&i965->config_heap, (struct object_base *)obj_config);
721 return VA_STATUS_SUCCESS;
724 VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
725 VAConfigID config_id,
726 VAProfile *profile, /* out */
727 VAEntrypoint *entrypoint, /* out */
728 VAConfigAttrib *attrib_list, /* out */
729 int *num_attribs) /* out */
731 struct i965_driver_data *i965 = i965_driver_data(ctx);
732 struct object_config *obj_config = CONFIG(config_id);
733 VAStatus vaStatus = VA_STATUS_SUCCESS;
737 *profile = obj_config->profile;
738 *entrypoint = obj_config->entrypoint;
739 *num_attribs = obj_config->num_attribs;
741 for(i = 0; i < obj_config->num_attribs; i++) {
742 attrib_list[i] = obj_config->attrib_list[i];
749 i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
751 struct object_surface *obj_surface = (struct object_surface *)obj;
753 dri_bo_unreference(obj_surface->bo);
754 obj_surface->bo = NULL;
756 if (obj_surface->free_private_data != NULL) {
757 obj_surface->free_private_data(&obj_surface->private_data);
758 obj_surface->private_data = NULL;
761 object_heap_free(heap, obj);
765 i965_surface_native_memory(VADriverContextP ctx,
766 struct object_surface *obj_surface,
770 struct i965_driver_data *i965 = i965_driver_data(ctx);
771 int tiling = HAS_TILED_SURFACE(i965);
773 if (!expected_fourcc)
774 return VA_STATUS_SUCCESS;
776 // todo, should we disable tiling for 422 format?
777 if (expected_fourcc == VA_FOURCC('I', '4', '2', '0') ||
778 expected_fourcc == VA_FOURCC('I', 'Y', 'U', 'V') ||
779 expected_fourcc == VA_FOURCC('Y', 'V', '1', '2'))
782 i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
784 return VA_STATUS_SUCCESS;
788 i965_suface_external_memory(VADriverContextP ctx,
789 struct object_surface *obj_surface,
790 int external_memory_type,
791 VASurfaceAttribExternalBuffers *memory_attibute,
794 struct i965_driver_data *i965 = i965_driver_data(ctx);
796 if (!memory_attibute ||
797 !memory_attibute->buffers ||
798 index > memory_attibute->num_buffers)
799 return VA_STATUS_ERROR_INVALID_PARAMETER;
801 assert(obj_surface->orig_width == memory_attibute->width);
802 assert(obj_surface->orig_height == memory_attibute->height);
803 assert(memory_attibute->num_planes >= 1);
805 obj_surface->fourcc = memory_attibute->pixel_format;
806 obj_surface->width = memory_attibute->pitches[0];
807 obj_surface->size = memory_attibute->data_size;
809 if (memory_attibute->num_planes == 1)
810 obj_surface->height = memory_attibute->data_size / obj_surface->width;
812 obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
814 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
815 obj_surface->x_cr_offset = 0;
817 switch (obj_surface->fourcc) {
818 case VA_FOURCC('N', 'V', '1', '2'):
819 assert(memory_attibute->num_planes == 2);
820 assert(memory_attibute->pitches[0] == memory_attibute->pitches[1]);
822 obj_surface->subsampling = SUBSAMPLE_YUV420;
823 obj_surface->y_cb_offset = obj_surface->height;
824 obj_surface->y_cr_offset = obj_surface->height;
825 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
826 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
827 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
831 case VA_FOURCC('Y', 'V', '1', '2'):
832 case VA_FOURCC('I', 'M', 'C', '1'):
833 assert(memory_attibute->num_planes == 3);
834 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
836 obj_surface->subsampling = SUBSAMPLE_YUV420;
837 obj_surface->y_cr_offset = obj_surface->height;
838 obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
839 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
840 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
841 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
845 case VA_FOURCC('I', '4', '2', '0'):
846 case VA_FOURCC('I', 'Y', 'U', 'V'):
847 case VA_FOURCC('I', 'M', 'C', '3'):
848 assert(memory_attibute->num_planes == 3);
849 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
851 obj_surface->subsampling = SUBSAMPLE_YUV420;
852 obj_surface->y_cb_offset = obj_surface->height;
853 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
854 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
855 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
856 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
860 case VA_FOURCC('Y', 'U', 'Y', '2'):
861 case VA_FOURCC('U', 'Y', 'V', 'Y'):
862 assert(memory_attibute->num_planes == 1);
864 obj_surface->subsampling = SUBSAMPLE_YUV422H;
865 obj_surface->y_cb_offset = 0;
866 obj_surface->y_cr_offset = 0;
867 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
868 obj_surface->cb_cr_height = obj_surface->orig_height;
869 obj_surface->cb_cr_pitch = memory_attibute->pitches[0];
873 case VA_FOURCC('R', 'G', 'B', 'A'):
874 case VA_FOURCC('R', 'G', 'B', 'X'):
875 case VA_FOURCC('B', 'G', 'R', 'A'):
876 case VA_FOURCC('B', 'G', 'R', 'X'):
877 assert(memory_attibute->num_planes == 1);
879 obj_surface->subsampling = SUBSAMPLE_RGBX;
880 obj_surface->y_cb_offset = 0;
881 obj_surface->y_cr_offset = 0;
882 obj_surface->cb_cr_width = 0;
883 obj_surface->cb_cr_height = 0;
884 obj_surface->cb_cr_pitch = 0;
888 case VA_FOURCC('Y', '8', '0', '0'): /* monochrome surface */
889 assert(memory_attibute->num_planes == 1);
891 obj_surface->subsampling = SUBSAMPLE_YUV400;
892 obj_surface->y_cb_offset = 0;
893 obj_surface->y_cr_offset = 0;
894 obj_surface->cb_cr_width = 0;
895 obj_surface->cb_cr_height = 0;
896 obj_surface->cb_cr_pitch = 0;
900 case VA_FOURCC('4', '1', '1', 'P'):
901 assert(memory_attibute->num_planes == 3);
902 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
904 obj_surface->subsampling = SUBSAMPLE_YUV411;
905 obj_surface->y_cb_offset = 0;
906 obj_surface->y_cr_offset = 0;
907 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
908 obj_surface->cb_cr_height = obj_surface->orig_height;
909 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
913 case VA_FOURCC('4', '2', '2', 'H'):
914 assert(memory_attibute->num_planes == 3);
915 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
917 obj_surface->subsampling = SUBSAMPLE_YUV422H;
918 obj_surface->y_cb_offset = obj_surface->height;
919 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
920 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
921 obj_surface->cb_cr_height = obj_surface->orig_height;
922 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
926 case VA_FOURCC('4', '2', '2', 'V'):
927 assert(memory_attibute->num_planes == 3);
928 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
930 obj_surface->subsampling = SUBSAMPLE_YUV422H;
931 obj_surface->y_cb_offset = obj_surface->height;
932 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
933 obj_surface->cb_cr_width = obj_surface->orig_width;
934 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
935 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
939 case VA_FOURCC('4', '4', '4', 'P'):
940 assert(memory_attibute->num_planes == 3);
941 assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
943 obj_surface->subsampling = SUBSAMPLE_YUV444;
944 obj_surface->y_cb_offset = obj_surface->height;
945 obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
946 obj_surface->cb_cr_width = obj_surface->orig_width;
947 obj_surface->cb_cr_height = obj_surface->orig_height;
948 obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
954 return VA_STATUS_ERROR_INVALID_PARAMETER;
957 if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
958 obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
959 "gem flinked vaapi surface",
960 memory_attibute->buffers[index]);
961 else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
962 obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
963 memory_attibute->buffers[index],
966 if (!obj_surface->bo)
967 return VA_STATUS_ERROR_INVALID_PARAMETER;
969 return VA_STATUS_SUCCESS;
973 i965_CreateSurfaces2(
974 VADriverContextP ctx,
978 VASurfaceID *surfaces,
979 unsigned int num_surfaces,
980 VASurfaceAttrib *attrib_list,
981 unsigned int num_attribs
984 struct i965_driver_data *i965 = i965_driver_data(ctx);
986 VAStatus vaStatus = VA_STATUS_SUCCESS;
987 int expected_fourcc = 0;
988 int memory_type = I965_SURFACE_MEM_NATIVE; /* native */
989 VASurfaceAttribExternalBuffers *memory_attibute = NULL;
991 for (i = 0; i < num_attribs && attrib_list; i++) {
992 if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
993 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
994 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
995 expected_fourcc = attrib_list[i].value.value.i;
998 if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
999 (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
1001 assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
1003 if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
1004 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
1005 else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
1006 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
1009 if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
1010 (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
1011 assert(attrib_list[i].value.type == VAGenericValueTypePointer);
1012 memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
1016 /* support 420 & 422 & RGB32 format, 422 and RGB32 are only used
1017 * for post-processing (including color conversion) */
1018 if (VA_RT_FORMAT_YUV420 != format &&
1019 VA_RT_FORMAT_YUV422 != format &&
1020 VA_RT_FORMAT_YUV444 != format &&
1021 VA_RT_FORMAT_YUV411 != format &&
1022 VA_RT_FORMAT_YUV400 != format &&
1023 VA_RT_FORMAT_RGB32 != format) {
1024 return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
1027 for (i = 0; i < num_surfaces; i++) {
1028 int surfaceID = NEW_SURFACE_ID();
1029 struct object_surface *obj_surface = SURFACE(surfaceID);
1031 if (NULL == obj_surface) {
1032 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1036 surfaces[i] = surfaceID;
1037 obj_surface->status = VASurfaceReady;
1038 obj_surface->orig_width = width;
1039 obj_surface->orig_height = height;
1041 obj_surface->subpic_render_idx = 0;
1042 for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
1043 obj_surface->subpic[j] = VA_INVALID_ID;
1044 obj_surface->obj_subpic[j] = NULL;
1047 obj_surface->width = ALIGN(width, 16);
1048 obj_surface->height = ALIGN(height, 16);
1049 obj_surface->flags = SURFACE_REFERENCED;
1050 obj_surface->fourcc = 0;
1051 obj_surface->bo = NULL;
1052 obj_surface->locked_image_id = VA_INVALID_ID;
1053 obj_surface->private_data = NULL;
1054 obj_surface->free_private_data = NULL;
1055 obj_surface->subsampling = SUBSAMPLE_YUV420;
1057 switch (memory_type) {
1058 case I965_SURFACE_MEM_NATIVE:
1059 i965_surface_native_memory(ctx,
1065 case I965_SURFACE_MEM_GEM_FLINK:
1066 case I965_SURFACE_MEM_DRM_PRIME:
1067 i965_suface_external_memory(ctx,
1076 /* Error recovery */
1077 if (VA_STATUS_SUCCESS != vaStatus) {
1078 /* surfaces[i-1] was the last successful allocation */
1080 struct object_surface *obj_surface = SURFACE(surfaces[i]);
1082 surfaces[i] = VA_INVALID_SURFACE;
1083 assert(obj_surface);
1084 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1092 i965_CreateSurfaces(VADriverContextP ctx,
1097 VASurfaceID *surfaces) /* out */
1099 return i965_CreateSurfaces2(ctx,
1110 i965_DestroySurfaces(VADriverContextP ctx,
1111 VASurfaceID *surface_list,
1114 struct i965_driver_data *i965 = i965_driver_data(ctx);
1117 for (i = num_surfaces; i--; ) {
1118 struct object_surface *obj_surface = SURFACE(surface_list[i]);
1120 assert(obj_surface);
1121 i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
1124 return VA_STATUS_SUCCESS;
1128 i965_QueryImageFormats(VADriverContextP ctx,
1129 VAImageFormat *format_list, /* out */
1130 int *num_formats) /* out */
1134 for (n = 0; i965_image_formats_map[n].va_format.fourcc != 0; n++) {
1135 const i965_image_format_map_t * const m = &i965_image_formats_map[n];
1137 format_list[n] = m->va_format;
1143 return VA_STATUS_SUCCESS;
1147 * Guess the format when the usage of a VA surface is unknown
1148 * 1. Without a valid context: YV12
1149 * 2. The current context is valid:
1150 * a) always NV12 on GEN6 and later
1151 * b) I420 for MPEG-2 and NV12 for other codec on GEN4 & GEN5
1154 i965_guess_surface_format(VADriverContextP ctx,
1155 VASurfaceID surface,
1156 unsigned int *fourcc,
1157 unsigned int *is_tiled)
1159 struct i965_driver_data *i965 = i965_driver_data(ctx);
1160 struct object_context *obj_context = NULL;
1161 struct object_config *obj_config = NULL;
1163 *fourcc = VA_FOURCC('Y', 'V', '1', '2');
1166 if (i965->current_context_id == VA_INVALID_ID)
1169 obj_context = CONTEXT(i965->current_context_id);
1174 obj_config = obj_context->obj_config;
1180 if (IS_GEN6(i965->intel.device_id) ||
1181 IS_GEN7(i965->intel.device_id) ||
1182 IS_GEN8(i965->intel.device_id)) {
1183 *fourcc = VA_FOURCC('N', 'V', '1', '2');
1188 switch (obj_config->profile) {
1189 case VAProfileMPEG2Simple:
1190 case VAProfileMPEG2Main:
1191 *fourcc = VA_FOURCC('I', '4', '2', '0');
1196 *fourcc = VA_FOURCC('N', 'V', '1', '2');
1203 i965_QuerySubpictureFormats(VADriverContextP ctx,
1204 VAImageFormat *format_list, /* out */
1205 unsigned int *flags, /* out */
1206 unsigned int *num_formats) /* out */
1210 for (n = 0; i965_subpic_formats_map[n].va_format.fourcc != 0; n++) {
1211 const i965_subpic_format_map_t * const m = &i965_subpic_formats_map[n];
1213 format_list[n] = m->va_format;
1215 flags[n] = m->va_flags;
1221 return VA_STATUS_SUCCESS;
1225 i965_destroy_subpic(struct object_heap *heap, struct object_base *obj)
1227 // struct object_subpic *obj_subpic = (struct object_subpic *)obj;
1229 object_heap_free(heap, obj);
1233 i965_CreateSubpicture(VADriverContextP ctx,
1235 VASubpictureID *subpicture) /* out */
1237 struct i965_driver_data *i965 = i965_driver_data(ctx);
1238 VASubpictureID subpicID = NEW_SUBPIC_ID()
1239 struct object_subpic *obj_subpic = SUBPIC(subpicID);
1242 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1244 struct object_image *obj_image = IMAGE(image);
1246 return VA_STATUS_ERROR_INVALID_IMAGE;
1248 const i965_subpic_format_map_t * const m = get_subpic_format(&obj_image->image.format);
1250 return VA_STATUS_ERROR_UNKNOWN; /* XXX: VA_STATUS_ERROR_UNSUPPORTED_FORMAT? */
1252 *subpicture = subpicID;
1253 obj_subpic->image = image;
1254 obj_subpic->obj_image = obj_image;
1255 obj_subpic->format = m->format;
1256 obj_subpic->width = obj_image->image.width;
1257 obj_subpic->height = obj_image->image.height;
1258 obj_subpic->pitch = obj_image->image.pitches[0];
1259 obj_subpic->bo = obj_image->bo;
1260 obj_subpic->global_alpha = 1.0;
1262 return VA_STATUS_SUCCESS;
1266 i965_DestroySubpicture(VADriverContextP ctx,
1267 VASubpictureID subpicture)
1269 struct i965_driver_data *i965 = i965_driver_data(ctx);
1270 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1273 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1275 assert(obj_subpic->obj_image);
1276 i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
1277 return VA_STATUS_SUCCESS;
1281 i965_SetSubpictureImage(VADriverContextP ctx,
1282 VASubpictureID subpicture,
1286 return VA_STATUS_ERROR_UNIMPLEMENTED;
1290 i965_SetSubpictureChromakey(VADriverContextP ctx,
1291 VASubpictureID subpicture,
1292 unsigned int chromakey_min,
1293 unsigned int chromakey_max,
1294 unsigned int chromakey_mask)
1297 return VA_STATUS_ERROR_UNIMPLEMENTED;
1301 i965_SetSubpictureGlobalAlpha(VADriverContextP ctx,
1302 VASubpictureID subpicture,
1305 struct i965_driver_data *i965 = i965_driver_data(ctx);
1306 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1308 if(global_alpha > 1.0 || global_alpha < 0.0){
1309 return VA_STATUS_ERROR_INVALID_PARAMETER;
1313 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1315 obj_subpic->global_alpha = global_alpha;
1317 return VA_STATUS_SUCCESS;
1321 i965_AssociateSubpicture(VADriverContextP ctx,
1322 VASubpictureID subpicture,
1323 VASurfaceID *target_surfaces,
1325 short src_x, /* upper left offset in subpicture */
1327 unsigned short src_width,
1328 unsigned short src_height,
1329 short dest_x, /* upper left offset in surface */
1331 unsigned short dest_width,
1332 unsigned short dest_height,
1334 * whether to enable chroma-keying or global-alpha
1335 * see VA_SUBPICTURE_XXX values
1339 struct i965_driver_data *i965 = i965_driver_data(ctx);
1340 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1344 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1346 assert(obj_subpic->obj_image);
1348 obj_subpic->src_rect.x = src_x;
1349 obj_subpic->src_rect.y = src_y;
1350 obj_subpic->src_rect.width = src_width;
1351 obj_subpic->src_rect.height = src_height;
1352 obj_subpic->dst_rect.x = dest_x;
1353 obj_subpic->dst_rect.y = dest_y;
1354 obj_subpic->dst_rect.width = dest_width;
1355 obj_subpic->dst_rect.height = dest_height;
1356 obj_subpic->flags = flags;
1358 for (i = 0; i < num_surfaces; i++) {
1359 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1361 return VA_STATUS_ERROR_INVALID_SURFACE;
1363 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1364 if(obj_surface->subpic[j] == VA_INVALID_ID){
1365 assert(obj_surface->obj_subpic[j] == NULL);
1366 obj_surface->subpic[j] = subpicture;
1367 obj_surface->obj_subpic[j] = obj_subpic;
1372 if(j == I965_MAX_SUBPIC_SUM){
1373 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1377 return VA_STATUS_SUCCESS;
1382 i965_DeassociateSubpicture(VADriverContextP ctx,
1383 VASubpictureID subpicture,
1384 VASurfaceID *target_surfaces,
1387 struct i965_driver_data *i965 = i965_driver_data(ctx);
1388 struct object_subpic *obj_subpic = SUBPIC(subpicture);
1392 return VA_STATUS_ERROR_INVALID_SUBPICTURE;
1394 for (i = 0; i < num_surfaces; i++) {
1395 struct object_surface *obj_surface = SURFACE(target_surfaces[i]);
1397 return VA_STATUS_ERROR_INVALID_SURFACE;
1399 for(j = 0; j < I965_MAX_SUBPIC_SUM; j ++){
1400 if (obj_surface->subpic[j] == subpicture) {
1401 assert(obj_surface->obj_subpic[j] == obj_subpic);
1402 obj_surface->subpic[j] = VA_INVALID_ID;
1403 obj_surface->obj_subpic[j] = NULL;
1408 if(j == I965_MAX_SUBPIC_SUM){
1409 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1412 return VA_STATUS_SUCCESS;
1416 i965_reference_buffer_store(struct buffer_store **ptr,
1417 struct buffer_store *buffer_store)
1419 assert(*ptr == NULL);
1422 buffer_store->ref_count++;
1423 *ptr = buffer_store;
1428 i965_release_buffer_store(struct buffer_store **ptr)
1430 struct buffer_store *buffer_store = *ptr;
1432 if (buffer_store == NULL)
1435 assert(buffer_store->bo || buffer_store->buffer);
1436 assert(!(buffer_store->bo && buffer_store->buffer));
1437 buffer_store->ref_count--;
1439 if (buffer_store->ref_count == 0) {
1440 dri_bo_unreference(buffer_store->bo);
1441 free(buffer_store->buffer);
1442 buffer_store->bo = NULL;
1443 buffer_store->buffer = NULL;
1451 i965_destroy_context(struct object_heap *heap, struct object_base *obj)
1453 struct object_context *obj_context = (struct object_context *)obj;
1456 if (obj_context->hw_context) {
1457 obj_context->hw_context->destroy(obj_context->hw_context);
1458 obj_context->hw_context = NULL;
1461 if (obj_context->codec_type == CODEC_PROC) {
1462 i965_release_buffer_store(&obj_context->codec_state.proc.pipeline_param);
1464 } else if (obj_context->codec_type == CODEC_ENC) {
1465 assert(obj_context->codec_state.encode.num_slice_params <= obj_context->codec_state.encode.max_slice_params);
1466 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
1467 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param);
1469 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++)
1470 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
1472 free(obj_context->codec_state.encode.slice_params);
1474 assert(obj_context->codec_state.encode.num_slice_params_ext <= obj_context->codec_state.encode.max_slice_params_ext);
1475 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
1476 i965_release_buffer_store(&obj_context->codec_state.encode.seq_param_ext);
1478 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
1479 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
1481 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
1482 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
1484 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.misc_param); i++)
1485 i965_release_buffer_store(&obj_context->codec_state.encode.misc_param[i]);
1487 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
1488 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
1490 free(obj_context->codec_state.encode.slice_params_ext);
1492 assert(obj_context->codec_state.decode.num_slice_params <= obj_context->codec_state.decode.max_slice_params);
1493 assert(obj_context->codec_state.decode.num_slice_datas <= obj_context->codec_state.decode.max_slice_datas);
1495 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
1496 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
1497 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
1499 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++)
1500 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
1502 for (i = 0; i < obj_context->codec_state.decode.num_slice_datas; i++)
1503 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
1505 free(obj_context->codec_state.decode.slice_params);
1506 free(obj_context->codec_state.decode.slice_datas);
1509 free(obj_context->render_targets);
1510 object_heap_free(heap, obj);
1514 i965_CreateContext(VADriverContextP ctx,
1515 VAConfigID config_id,
1519 VASurfaceID *render_targets,
1520 int num_render_targets,
1521 VAContextID *context) /* out */
1523 struct i965_driver_data *i965 = i965_driver_data(ctx);
1524 struct i965_render_state *render_state = &i965->render_state;
1525 struct object_config *obj_config = CONFIG(config_id);
1526 struct object_context *obj_context = NULL;
1527 VAStatus vaStatus = VA_STATUS_SUCCESS;
1531 if (NULL == obj_config) {
1532 vaStatus = VA_STATUS_ERROR_INVALID_CONFIG;
1536 if (picture_width > i965->codec_info->max_width ||
1537 picture_height > i965->codec_info->max_height) {
1538 vaStatus = VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED;
1543 /* Validate picture dimensions */
1544 contextID = NEW_CONTEXT_ID();
1545 obj_context = CONTEXT(contextID);
1547 if (NULL == obj_context) {
1548 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1552 render_state->inited = 1;
1554 switch (obj_config->profile) {
1555 case VAProfileH264ConstrainedBaseline:
1556 case VAProfileH264Main:
1557 case VAProfileH264High:
1558 if (!HAS_H264_DECODING(i965) &&
1559 !HAS_H264_ENCODING(i965))
1560 return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
1561 render_state->interleaved_uv = 1;
1564 render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id) || IS_GEN8(i965->intel.device_id));
1568 *context = contextID;
1569 obj_context->flags = flag;
1570 obj_context->context_id = contextID;
1571 obj_context->obj_config = obj_config;
1572 obj_context->picture_width = picture_width;
1573 obj_context->picture_height = picture_height;
1574 obj_context->num_render_targets = num_render_targets;
1575 obj_context->render_targets =
1576 (VASurfaceID *)calloc(num_render_targets, sizeof(VASurfaceID));
1577 obj_context->hw_context = NULL;
1579 for(i = 0; i < num_render_targets; i++) {
1580 if (NULL == SURFACE(render_targets[i])) {
1581 vaStatus = VA_STATUS_ERROR_INVALID_SURFACE;
1585 obj_context->render_targets[i] = render_targets[i];
1588 if (VA_STATUS_SUCCESS == vaStatus) {
1589 if (VAEntrypointVideoProc == obj_config->entrypoint) {
1590 obj_context->codec_type = CODEC_PROC;
1591 memset(&obj_context->codec_state.proc, 0, sizeof(obj_context->codec_state.proc));
1592 obj_context->codec_state.proc.current_render_target = VA_INVALID_ID;
1593 assert(i965->codec_info->proc_hw_context_init);
1594 obj_context->hw_context = i965->codec_info->proc_hw_context_init(ctx, obj_config);
1595 } else if (VAEntrypointEncSlice == obj_config->entrypoint) { /*encode routin only*/
1596 obj_context->codec_type = CODEC_ENC;
1597 memset(&obj_context->codec_state.encode, 0, sizeof(obj_context->codec_state.encode));
1598 obj_context->codec_state.encode.current_render_target = VA_INVALID_ID;
1599 obj_context->codec_state.encode.max_slice_params = NUM_SLICES;
1600 obj_context->codec_state.encode.slice_params = calloc(obj_context->codec_state.encode.max_slice_params,
1601 sizeof(*obj_context->codec_state.encode.slice_params));
1602 assert(i965->codec_info->enc_hw_context_init);
1603 obj_context->hw_context = i965->codec_info->enc_hw_context_init(ctx, obj_config);
1605 obj_context->codec_type = CODEC_DEC;
1606 memset(&obj_context->codec_state.decode, 0, sizeof(obj_context->codec_state.decode));
1607 obj_context->codec_state.decode.current_render_target = -1;
1608 obj_context->codec_state.decode.max_slice_params = NUM_SLICES;
1609 obj_context->codec_state.decode.max_slice_datas = NUM_SLICES;
1610 obj_context->codec_state.decode.slice_params = calloc(obj_context->codec_state.decode.max_slice_params,
1611 sizeof(*obj_context->codec_state.decode.slice_params));
1612 obj_context->codec_state.decode.slice_datas = calloc(obj_context->codec_state.decode.max_slice_datas,
1613 sizeof(*obj_context->codec_state.decode.slice_datas));
1615 assert(i965->codec_info->dec_hw_context_init);
1616 obj_context->hw_context = i965->codec_info->dec_hw_context_init(ctx, obj_config);
1620 /* Error recovery */
1621 if (VA_STATUS_SUCCESS != vaStatus) {
1622 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1625 i965->current_context_id = contextID;
1631 i965_DestroyContext(VADriverContextP ctx, VAContextID context)
1633 struct i965_driver_data *i965 = i965_driver_data(ctx);
1634 struct object_context *obj_context = CONTEXT(context);
1636 assert(obj_context);
1638 if (i965->current_context_id == context)
1639 i965->current_context_id = VA_INVALID_ID;
1641 i965_destroy_context(&i965->context_heap, (struct object_base *)obj_context);
1643 return VA_STATUS_SUCCESS;
1647 i965_destroy_buffer(struct object_heap *heap, struct object_base *obj)
1649 struct object_buffer *obj_buffer = (struct object_buffer *)obj;
1651 assert(obj_buffer->buffer_store);
1652 i965_release_buffer_store(&obj_buffer->buffer_store);
1653 object_heap_free(heap, obj);
1657 i965_create_buffer_internal(VADriverContextP ctx,
1658 VAContextID context,
1661 unsigned int num_elements,
1666 struct i965_driver_data *i965 = i965_driver_data(ctx);
1667 struct object_buffer *obj_buffer = NULL;
1668 struct buffer_store *buffer_store = NULL;
1673 case VAPictureParameterBufferType:
1674 case VAIQMatrixBufferType:
1675 case VAQMatrixBufferType:
1676 case VABitPlaneBufferType:
1677 case VASliceGroupMapBufferType:
1678 case VASliceParameterBufferType:
1679 case VASliceDataBufferType:
1680 case VAMacroblockParameterBufferType:
1681 case VAResidualDataBufferType:
1682 case VADeblockingParameterBufferType:
1683 case VAImageBufferType:
1684 case VAEncCodedBufferType:
1685 case VAEncSequenceParameterBufferType:
1686 case VAEncPictureParameterBufferType:
1687 case VAEncSliceParameterBufferType:
1688 case VAEncPackedHeaderParameterBufferType:
1689 case VAEncPackedHeaderDataBufferType:
1690 case VAEncMiscParameterBufferType:
1691 case VAProcPipelineParameterBufferType:
1692 case VAProcFilterParameterBufferType:
1693 case VAHuffmanTableBufferType:
1694 case VAProbabilityBufferType:
1699 return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
1702 bufferID = NEW_BUFFER_ID();
1703 obj_buffer = BUFFER(bufferID);
1705 if (NULL == obj_buffer) {
1706 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1709 if (type == VAEncCodedBufferType) {
1710 size += I965_CODEDBUFFER_HEADER_SIZE;
1711 size += 0x1000; /* for upper bound check */
1714 obj_buffer->max_num_elements = num_elements;
1715 obj_buffer->num_elements = num_elements;
1716 obj_buffer->size_element = size;
1717 obj_buffer->type = type;
1718 obj_buffer->buffer_store = NULL;
1719 buffer_store = calloc(1, sizeof(struct buffer_store));
1720 assert(buffer_store);
1721 buffer_store->ref_count = 1;
1723 if (store_bo != NULL) {
1724 buffer_store->bo = store_bo;
1725 dri_bo_reference(buffer_store->bo);
1728 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1729 } else if (type == VASliceDataBufferType ||
1730 type == VAImageBufferType ||
1731 type == VAEncCodedBufferType ||
1732 type == VAProbabilityBufferType) {
1733 buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr,
1735 size * num_elements, 64);
1736 assert(buffer_store->bo);
1738 if (type == VAEncCodedBufferType) {
1739 struct i965_coded_buffer_segment *coded_buffer_segment;
1741 dri_bo_map(buffer_store->bo, 1);
1742 coded_buffer_segment = (struct i965_coded_buffer_segment *)buffer_store->bo->virtual;
1743 coded_buffer_segment->base.size = size - I965_CODEDBUFFER_HEADER_SIZE;
1744 coded_buffer_segment->base.bit_offset = 0;
1745 coded_buffer_segment->base.status = 0;
1746 coded_buffer_segment->base.buf = NULL;
1747 coded_buffer_segment->base.next = NULL;
1748 coded_buffer_segment->mapped = 0;
1749 coded_buffer_segment->codec = 0;
1750 dri_bo_unmap(buffer_store->bo);
1752 dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
1758 if (type == VAEncPackedHeaderDataBufferType) {
1759 msize = ALIGN(size, 4);
1762 buffer_store->buffer = malloc(msize * num_elements);
1763 assert(buffer_store->buffer);
1766 memcpy(buffer_store->buffer, data, size * num_elements);
1769 buffer_store->num_elements = obj_buffer->num_elements;
1770 i965_reference_buffer_store(&obj_buffer->buffer_store, buffer_store);
1771 i965_release_buffer_store(&buffer_store);
1774 return VA_STATUS_SUCCESS;
1778 i965_CreateBuffer(VADriverContextP ctx,
1779 VAContextID context, /* in */
1780 VABufferType type, /* in */
1781 unsigned int size, /* in */
1782 unsigned int num_elements, /* in */
1783 void *data, /* in */
1784 VABufferID *buf_id) /* out */
1786 return i965_create_buffer_internal(ctx, context, type, size, num_elements, data, NULL, buf_id);
1791 i965_BufferSetNumElements(VADriverContextP ctx,
1792 VABufferID buf_id, /* in */
1793 unsigned int num_elements) /* in */
1795 struct i965_driver_data *i965 = i965_driver_data(ctx);
1796 struct object_buffer *obj_buffer = BUFFER(buf_id);
1797 VAStatus vaStatus = VA_STATUS_SUCCESS;
1802 return VA_STATUS_ERROR_INVALID_BUFFER;
1804 if ((num_elements < 0) ||
1805 (num_elements > obj_buffer->max_num_elements)) {
1806 vaStatus = VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1808 obj_buffer->num_elements = num_elements;
1809 if (obj_buffer->buffer_store != NULL) {
1810 obj_buffer->buffer_store->num_elements = num_elements;
1818 i965_MapBuffer(VADriverContextP ctx,
1819 VABufferID buf_id, /* in */
1820 void **pbuf) /* out */
1822 struct i965_driver_data *i965 = i965_driver_data(ctx);
1823 struct object_buffer *obj_buffer = BUFFER(buf_id);
1824 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1826 assert(obj_buffer && obj_buffer->buffer_store);
1827 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1828 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1830 if (!obj_buffer || !obj_buffer->buffer_store)
1831 return VA_STATUS_ERROR_INVALID_BUFFER;
1833 if (NULL != obj_buffer->buffer_store->bo) {
1834 unsigned int tiling, swizzle;
1836 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1838 if (tiling != I915_TILING_NONE)
1839 drm_intel_gem_bo_map_gtt(obj_buffer->buffer_store->bo);
1841 dri_bo_map(obj_buffer->buffer_store->bo, 1);
1843 assert(obj_buffer->buffer_store->bo->virtual);
1844 *pbuf = obj_buffer->buffer_store->bo->virtual;
1846 if (obj_buffer->type == VAEncCodedBufferType) {
1848 unsigned char *buffer = NULL;
1849 struct i965_coded_buffer_segment *coded_buffer_segment = (struct i965_coded_buffer_segment *)(obj_buffer->buffer_store->bo->virtual);
1851 if (!coded_buffer_segment->mapped) {
1852 unsigned char delimiter0, delimiter1, delimiter2, delimiter3, delimiter4;
1854 coded_buffer_segment->base.buf = buffer = (unsigned char *)(obj_buffer->buffer_store->bo->virtual) + I965_CODEDBUFFER_HEADER_SIZE;
1856 if (coded_buffer_segment->codec == CODEC_H264) {
1857 delimiter0 = H264_DELIMITER0;
1858 delimiter1 = H264_DELIMITER1;
1859 delimiter2 = H264_DELIMITER2;
1860 delimiter3 = H264_DELIMITER3;
1861 delimiter4 = H264_DELIMITER4;
1862 } else if (coded_buffer_segment->codec == CODEC_MPEG2) {
1863 delimiter0 = MPEG2_DELIMITER0;
1864 delimiter1 = MPEG2_DELIMITER1;
1865 delimiter2 = MPEG2_DELIMITER2;
1866 delimiter3 = MPEG2_DELIMITER3;
1867 delimiter4 = MPEG2_DELIMITER4;
1872 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
1873 if ((buffer[i] == delimiter0) &&
1874 (buffer[i + 1] == delimiter1) &&
1875 (buffer[i + 2] == delimiter2) &&
1876 (buffer[i + 3] == delimiter3) &&
1877 (buffer[i + 4] == delimiter4))
1881 if (i == obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000) {
1882 coded_buffer_segment->base.status |= VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK;
1885 coded_buffer_segment->base.size = i;
1886 coded_buffer_segment->mapped = 1;
1888 assert(coded_buffer_segment->base.buf);
1892 vaStatus = VA_STATUS_SUCCESS;
1893 } else if (NULL != obj_buffer->buffer_store->buffer) {
1894 *pbuf = obj_buffer->buffer_store->buffer;
1895 vaStatus = VA_STATUS_SUCCESS;
1902 i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
1904 struct i965_driver_data *i965 = i965_driver_data(ctx);
1905 struct object_buffer *obj_buffer = BUFFER(buf_id);
1906 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
1908 if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
1909 return VA_STATUS_ERROR_INVALID_BUFFER;
1911 assert(obj_buffer && obj_buffer->buffer_store);
1912 assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
1913 assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
1915 if (!obj_buffer || !obj_buffer->buffer_store)
1916 return VA_STATUS_ERROR_INVALID_BUFFER;
1918 if (NULL != obj_buffer->buffer_store->bo) {
1919 unsigned int tiling, swizzle;
1921 dri_bo_get_tiling(obj_buffer->buffer_store->bo, &tiling, &swizzle);
1923 if (tiling != I915_TILING_NONE)
1924 drm_intel_gem_bo_unmap_gtt(obj_buffer->buffer_store->bo);
1926 dri_bo_unmap(obj_buffer->buffer_store->bo);
1928 vaStatus = VA_STATUS_SUCCESS;
1929 } else if (NULL != obj_buffer->buffer_store->buffer) {
1931 vaStatus = VA_STATUS_SUCCESS;
1938 i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
1940 struct i965_driver_data *i965 = i965_driver_data(ctx);
1941 struct object_buffer *obj_buffer = BUFFER(buffer_id);
1946 return VA_STATUS_ERROR_INVALID_BUFFER;
1948 i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
1950 return VA_STATUS_SUCCESS;
1954 i965_BeginPicture(VADriverContextP ctx,
1955 VAContextID context,
1956 VASurfaceID render_target)
1958 struct i965_driver_data *i965 = i965_driver_data(ctx);
1959 struct object_context *obj_context = CONTEXT(context);
1960 struct object_surface *obj_surface = SURFACE(render_target);
1961 struct object_config *obj_config;
1965 assert(obj_context);
1968 return VA_STATUS_ERROR_INVALID_CONTEXT;
1970 assert(obj_surface);
1973 return VA_STATUS_ERROR_INVALID_SURFACE;
1975 obj_config = obj_context->obj_config;
1978 switch (obj_config->profile) {
1979 case VAProfileMPEG2Simple:
1980 case VAProfileMPEG2Main:
1981 vaStatus = VA_STATUS_SUCCESS;
1984 case VAProfileH264ConstrainedBaseline:
1985 case VAProfileH264Main:
1986 case VAProfileH264High:
1987 vaStatus = VA_STATUS_SUCCESS;
1990 case VAProfileVC1Simple:
1991 case VAProfileVC1Main:
1992 case VAProfileVC1Advanced:
1993 vaStatus = VA_STATUS_SUCCESS;
1996 case VAProfileJPEGBaseline:
1997 vaStatus = VA_STATUS_SUCCESS;
2001 vaStatus = VA_STATUS_SUCCESS;
2004 case VAProfileVP8Version0_3:
2005 vaStatus = VA_STATUS_SUCCESS;
2010 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
2014 if (obj_context->codec_type == CODEC_PROC) {
2015 obj_context->codec_state.proc.current_render_target = render_target;
2016 } else if (obj_context->codec_type == CODEC_ENC) {
2017 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param);
2019 for (i = 0; i < obj_context->codec_state.encode.num_slice_params; i++) {
2020 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params[i]);
2023 obj_context->codec_state.encode.num_slice_params = 0;
2026 i965_release_buffer_store(&obj_context->codec_state.encode.pic_param_ext);
2028 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_param); i++)
2029 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_param[i]);
2031 for (i = 0; i < ARRAY_ELEMS(obj_context->codec_state.encode.packed_header_data); i++)
2032 i965_release_buffer_store(&obj_context->codec_state.encode.packed_header_data[i]);
2034 for (i = 0; i < obj_context->codec_state.encode.num_slice_params_ext; i++)
2035 i965_release_buffer_store(&obj_context->codec_state.encode.slice_params_ext[i]);
2037 obj_context->codec_state.encode.num_slice_params_ext = 0;
2038 obj_context->codec_state.encode.current_render_target = render_target; /*This is input new frame*/
2039 obj_context->codec_state.encode.last_packed_header_type = 0;
2041 obj_context->codec_state.decode.current_render_target = render_target;
2042 i965_release_buffer_store(&obj_context->codec_state.decode.pic_param);
2043 i965_release_buffer_store(&obj_context->codec_state.decode.iq_matrix);
2044 i965_release_buffer_store(&obj_context->codec_state.decode.bit_plane);
2045 i965_release_buffer_store(&obj_context->codec_state.decode.huffman_table);
2047 for (i = 0; i < obj_context->codec_state.decode.num_slice_params; i++) {
2048 i965_release_buffer_store(&obj_context->codec_state.decode.slice_params[i]);
2049 i965_release_buffer_store(&obj_context->codec_state.decode.slice_datas[i]);
2052 obj_context->codec_state.decode.num_slice_params = 0;
2053 obj_context->codec_state.decode.num_slice_datas = 0;
2059 #define I965_RENDER_BUFFER(category, name) i965_render_##category##_##name##_buffer(ctx, obj_context, obj_buffer)
2061 #define DEF_RENDER_SINGLE_BUFFER_FUNC(category, name, member) \
2063 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2064 struct object_context *obj_context, \
2065 struct object_buffer *obj_buffer) \
2067 struct category##_state *category = &obj_context->codec_state.category; \
2068 i965_release_buffer_store(&category->member); \
2069 i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
2070 return VA_STATUS_SUCCESS; \
2073 #define DEF_RENDER_MULTI_BUFFER_FUNC(category, name, member) \
2075 i965_render_##category##_##name##_buffer(VADriverContextP ctx, \
2076 struct object_context *obj_context, \
2077 struct object_buffer *obj_buffer) \
2079 struct category##_state *category = &obj_context->codec_state.category; \
2080 if (category->num_##member == category->max_##member) { \
2081 category->member = realloc(category->member, (category->max_##member + NUM_SLICES) * sizeof(*category->member)); \
2082 memset(category->member + category->max_##member, 0, NUM_SLICES * sizeof(*category->member)); \
2083 category->max_##member += NUM_SLICES; \
2085 i965_release_buffer_store(&category->member[category->num_##member]); \
2086 i965_reference_buffer_store(&category->member[category->num_##member], obj_buffer->buffer_store); \
2087 category->num_##member++; \
2088 return VA_STATUS_SUCCESS; \
2091 #define I965_RENDER_DECODE_BUFFER(name) I965_RENDER_BUFFER(decode, name)
2093 #define DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(decode, name, member)
2094 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2095 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
2096 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
2097 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
2098 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
2100 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
2101 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2102 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_data, slice_datas)
2105 i965_decoder_render_picture(VADriverContextP ctx,
2106 VAContextID context,
2107 VABufferID *buffers,
2110 struct i965_driver_data *i965 = i965_driver_data(ctx);
2111 struct object_context *obj_context = CONTEXT(context);
2112 VAStatus vaStatus = VA_STATUS_SUCCESS;
2115 assert(obj_context);
2118 return VA_STATUS_ERROR_INVALID_CONTEXT;
2120 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2121 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2124 return VA_STATUS_ERROR_INVALID_BUFFER;
2126 switch (obj_buffer->type) {
2127 case VAPictureParameterBufferType:
2128 vaStatus = I965_RENDER_DECODE_BUFFER(picture_parameter);
2131 case VAIQMatrixBufferType:
2132 vaStatus = I965_RENDER_DECODE_BUFFER(iq_matrix);
2135 case VABitPlaneBufferType:
2136 vaStatus = I965_RENDER_DECODE_BUFFER(bit_plane);
2139 case VASliceParameterBufferType:
2140 vaStatus = I965_RENDER_DECODE_BUFFER(slice_parameter);
2143 case VASliceDataBufferType:
2144 vaStatus = I965_RENDER_DECODE_BUFFER(slice_data);
2147 case VAHuffmanTableBufferType:
2148 vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
2151 case VAProbabilityBufferType:
2152 vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
2156 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2164 #define I965_RENDER_ENCODE_BUFFER(name) I965_RENDER_BUFFER(encode, name)
2166 #define DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(encode, name, member)
2167 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter, seq_param)
2168 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
2169 // DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_control, pic_control)
2170 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(qmatrix, q_matrix)
2171 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(iqmatrix, iq_matrix)
2172 /* extended buffer */
2173 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(sequence_parameter_ext, seq_param_ext)
2174 DEF_RENDER_ENCODE_SINGLE_BUFFER_FUNC(picture_parameter_ext, pic_param_ext)
2176 #define DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(encode, name, member)
2177 // DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
2178 DEF_RENDER_ENCODE_MULTI_BUFFER_FUNC(slice_parameter_ext, slice_params_ext)
2181 i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
2182 struct object_context *obj_context,
2183 struct object_buffer *obj_buffer,
2186 struct encode_state *encode = &obj_context->codec_state.encode;
2188 assert(obj_buffer->buffer_store->bo == NULL);
2189 assert(obj_buffer->buffer_store->buffer);
2190 i965_release_buffer_store(&encode->packed_header_param[type_index]);
2191 i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
2193 return VA_STATUS_SUCCESS;
2197 i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
2198 struct object_context *obj_context,
2199 struct object_buffer *obj_buffer,
2202 struct encode_state *encode = &obj_context->codec_state.encode;
2204 assert(obj_buffer->buffer_store->bo == NULL);
2205 assert(obj_buffer->buffer_store->buffer);
2206 i965_release_buffer_store(&encode->packed_header_data[type_index]);
2207 i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
2209 return VA_STATUS_SUCCESS;
2213 i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
2214 struct object_context *obj_context,
2215 struct object_buffer *obj_buffer)
2217 struct encode_state *encode = &obj_context->codec_state.encode;
2218 VAEncMiscParameterBuffer *param = NULL;
2220 assert(obj_buffer->buffer_store->bo == NULL);
2221 assert(obj_buffer->buffer_store->buffer);
2223 param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
2225 if (param->type > ARRAY_ELEMS(encode->misc_param))
2226 return VA_STATUS_ERROR_INVALID_PARAMETER;
2228 i965_release_buffer_store(&encode->misc_param[param->type]);
2229 i965_reference_buffer_store(&encode->misc_param[param->type], obj_buffer->buffer_store);
2231 return VA_STATUS_SUCCESS;
2235 i965_encoder_render_picture(VADriverContextP ctx,
2236 VAContextID context,
2237 VABufferID *buffers,
2240 struct i965_driver_data *i965 = i965_driver_data(ctx);
2241 struct object_context *obj_context = CONTEXT(context);
2242 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2245 assert(obj_context);
2248 return VA_STATUS_ERROR_INVALID_CONTEXT;
2250 for (i = 0; i < num_buffers; i++) {
2251 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2254 return VA_STATUS_ERROR_INVALID_BUFFER;
2256 switch (obj_buffer->type) {
2257 case VAQMatrixBufferType:
2258 vaStatus = I965_RENDER_ENCODE_BUFFER(qmatrix);
2261 case VAIQMatrixBufferType:
2262 vaStatus = I965_RENDER_ENCODE_BUFFER(iqmatrix);
2265 case VAEncSequenceParameterBufferType:
2266 vaStatus = I965_RENDER_ENCODE_BUFFER(sequence_parameter_ext);
2269 case VAEncPictureParameterBufferType:
2270 vaStatus = I965_RENDER_ENCODE_BUFFER(picture_parameter_ext);
2273 case VAEncSliceParameterBufferType:
2274 vaStatus = I965_RENDER_ENCODE_BUFFER(slice_parameter_ext);
2277 case VAEncPackedHeaderParameterBufferType:
2279 struct encode_state *encode = &obj_context->codec_state.encode;
2280 VAEncPackedHeaderParameterBuffer *param = (VAEncPackedHeaderParameterBuffer *)obj_buffer->buffer_store->buffer;
2281 encode->last_packed_header_type = param->type;
2283 vaStatus = i965_encoder_render_packed_header_parameter_buffer(ctx,
2286 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2290 case VAEncPackedHeaderDataBufferType:
2292 struct encode_state *encode = &obj_context->codec_state.encode;
2294 assert(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
2295 encode->last_packed_header_type == VAEncPackedHeaderPicture ||
2296 encode->last_packed_header_type == VAEncPackedHeaderSlice ||
2297 (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
2298 ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)));
2299 vaStatus = i965_encoder_render_packed_header_data_buffer(ctx,
2302 va_enc_packed_type_to_idx(encode->last_packed_header_type));
2306 case VAEncMiscParameterBufferType:
2307 vaStatus = i965_encoder_render_misc_parameter_buffer(ctx,
2313 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2321 #define I965_RENDER_PROC_BUFFER(name) I965_RENDER_BUFFER(proc, name)
2323 #define DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(name, member) DEF_RENDER_SINGLE_BUFFER_FUNC(proc, name, member)
2324 DEF_RENDER_PROC_SINGLE_BUFFER_FUNC(pipeline_parameter, pipeline_param)
2327 i965_proc_render_picture(VADriverContextP ctx,
2328 VAContextID context,
2329 VABufferID *buffers,
2332 struct i965_driver_data *i965 = i965_driver_data(ctx);
2333 struct object_context *obj_context = CONTEXT(context);
2334 VAStatus vaStatus = VA_STATUS_SUCCESS;
2337 assert(obj_context);
2340 return VA_STATUS_ERROR_INVALID_CONTEXT;
2342 for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
2343 struct object_buffer *obj_buffer = BUFFER(buffers[i]);
2346 return VA_STATUS_ERROR_INVALID_BUFFER;
2348 switch (obj_buffer->type) {
2349 case VAProcPipelineParameterBufferType:
2350 vaStatus = I965_RENDER_PROC_BUFFER(pipeline_parameter);
2354 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
2363 i965_RenderPicture(VADriverContextP ctx,
2364 VAContextID context,
2365 VABufferID *buffers,
2368 struct i965_driver_data *i965 = i965_driver_data(ctx);
2369 struct object_context *obj_context;
2370 struct object_config *obj_config;
2371 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
2373 obj_context = CONTEXT(context);
2374 assert(obj_context);
2377 return VA_STATUS_ERROR_INVALID_CONTEXT;
2379 if (num_buffers <= 0)
2380 return VA_STATUS_ERROR_INVALID_PARAMETER;
2382 obj_config = obj_context->obj_config;
2385 if (VAEntrypointVideoProc == obj_config->entrypoint) {
2386 vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
2387 } else if (VAEntrypointEncSlice == obj_config->entrypoint ) {
2388 vaStatus = i965_encoder_render_picture(ctx, context, buffers, num_buffers);
2390 vaStatus = i965_decoder_render_picture(ctx, context, buffers, num_buffers);
2397 i965_EndPicture(VADriverContextP ctx, VAContextID context)
2399 struct i965_driver_data *i965 = i965_driver_data(ctx);
2400 struct object_context *obj_context = CONTEXT(context);
2401 struct object_config *obj_config;
2403 assert(obj_context);
2406 return VA_STATUS_ERROR_INVALID_CONTEXT;
2408 obj_config = obj_context->obj_config;
2411 if (obj_context->codec_type == CODEC_PROC) {
2412 assert(VAEntrypointVideoProc == obj_config->entrypoint);
2413 } else if (obj_context->codec_type == CODEC_ENC) {
2414 assert(VAEntrypointEncSlice == obj_config->entrypoint);
2416 if (!(obj_context->codec_state.encode.pic_param ||
2417 obj_context->codec_state.encode.pic_param_ext)) {
2418 return VA_STATUS_ERROR_INVALID_PARAMETER;
2420 if (!(obj_context->codec_state.encode.seq_param ||
2421 obj_context->codec_state.encode.seq_param_ext)) {
2422 return VA_STATUS_ERROR_INVALID_PARAMETER;
2424 if ((obj_context->codec_state.encode.num_slice_params <=0) &&
2425 (obj_context->codec_state.encode.num_slice_params_ext <=0)) {
2426 return VA_STATUS_ERROR_INVALID_PARAMETER;
2429 if (obj_context->codec_state.decode.pic_param == NULL) {
2430 return VA_STATUS_ERROR_INVALID_PARAMETER;
2432 if (obj_context->codec_state.decode.num_slice_params <=0) {
2433 return VA_STATUS_ERROR_INVALID_PARAMETER;
2435 if (obj_context->codec_state.decode.num_slice_datas <=0) {
2436 return VA_STATUS_ERROR_INVALID_PARAMETER;
2439 if (obj_context->codec_state.decode.num_slice_params !=
2440 obj_context->codec_state.decode.num_slice_datas) {
2441 return VA_STATUS_ERROR_INVALID_PARAMETER;
2445 assert(obj_context->hw_context->run);
2446 return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
2450 i965_SyncSurface(VADriverContextP ctx,
2451 VASurfaceID render_target)
2453 struct i965_driver_data *i965 = i965_driver_data(ctx);
2454 struct object_surface *obj_surface = SURFACE(render_target);
2456 assert(obj_surface);
2459 drm_intel_bo_wait_rendering(obj_surface->bo);
2461 return VA_STATUS_SUCCESS;
2465 i965_QuerySurfaceStatus(VADriverContextP ctx,
2466 VASurfaceID render_target,
2467 VASurfaceStatus *status) /* out */
2469 struct i965_driver_data *i965 = i965_driver_data(ctx);
2470 struct object_surface *obj_surface = SURFACE(render_target);
2472 assert(obj_surface);
2474 if (obj_surface->bo) {
2475 if (drm_intel_bo_busy(obj_surface->bo)){
2476 *status = VASurfaceRendering;
2479 *status = VASurfaceReady;
2482 *status = VASurfaceReady;
2485 return VA_STATUS_SUCCESS;
2488 static VADisplayAttribute *
2489 get_display_attribute(VADriverContextP ctx, VADisplayAttribType type)
2491 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2494 if (!i965->display_attributes)
2497 for (i = 0; i < i965->num_display_attributes; i++) {
2498 if (i965->display_attributes[i].type == type)
2499 return &i965->display_attributes[i];
2505 i965_display_attributes_terminate(VADriverContextP ctx)
2507 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2509 if (i965->display_attributes) {
2510 free(i965->display_attributes);
2511 i965->display_attributes = NULL;
2512 i965->num_display_attributes = 0;
2517 i965_display_attributes_init(VADriverContextP ctx)
2519 struct i965_driver_data * const i965 = i965_driver_data(ctx);
2521 i965->num_display_attributes = ARRAY_ELEMS(i965_display_attributes);
2522 i965->display_attributes = malloc(
2523 i965->num_display_attributes * sizeof(i965->display_attributes[0]));
2524 if (!i965->display_attributes)
2528 i965->display_attributes,
2529 i965_display_attributes,
2530 sizeof(i965_display_attributes)
2533 i965->rotation_attrib = get_display_attribute(ctx, VADisplayAttribRotation);
2534 i965->brightness_attrib = get_display_attribute(ctx, VADisplayAttribBrightness);
2535 i965->contrast_attrib = get_display_attribute(ctx, VADisplayAttribContrast);
2536 i965->hue_attrib = get_display_attribute(ctx, VADisplayAttribHue);
2537 i965->saturation_attrib = get_display_attribute(ctx, VADisplayAttribSaturation);
2539 if (!i965->rotation_attrib ||
2540 !i965->brightness_attrib ||
2541 !i965->contrast_attrib ||
2542 !i965->hue_attrib ||
2543 !i965->saturation_attrib) {
2549 i965_display_attributes_terminate(ctx);
2554 * Query display attributes
2555 * The caller must provide a "attr_list" array that can hold at
2556 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2557 * returned in "attr_list" is returned in "num_attributes".
2560 i965_QueryDisplayAttributes(
2561 VADriverContextP ctx,
2562 VADisplayAttribute *attribs, /* out */
2563 int *num_attribs_ptr /* out */
2566 const int num_attribs = ARRAY_ELEMS(i965_display_attributes);
2568 if (attribs && num_attribs > 0)
2569 memcpy(attribs, i965_display_attributes, sizeof(i965_display_attributes));
2571 if (num_attribs_ptr)
2572 *num_attribs_ptr = num_attribs;
2574 return VA_STATUS_SUCCESS;
2578 * Get display attributes
2579 * This function returns the current attribute values in "attr_list".
2580 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2581 * from vaQueryDisplayAttributes() can have their values retrieved.
2584 i965_GetDisplayAttributes(
2585 VADriverContextP ctx,
2586 VADisplayAttribute *attribs, /* inout */
2587 int num_attribs /* in */
2592 for (i = 0; i < num_attribs; i++) {
2593 VADisplayAttribute *src_attrib, * const dst_attrib = &attribs[i];
2595 src_attrib = get_display_attribute(ctx, dst_attrib->type);
2596 if (src_attrib && (src_attrib->flags & VA_DISPLAY_ATTRIB_GETTABLE)) {
2597 dst_attrib->min_value = src_attrib->min_value;
2598 dst_attrib->max_value = src_attrib->max_value;
2599 dst_attrib->value = src_attrib->value;
2602 dst_attrib->flags = VA_DISPLAY_ATTRIB_NOT_SUPPORTED;
2604 return VA_STATUS_SUCCESS;
2608 * Set display attributes
2609 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2610 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
2611 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2614 i965_SetDisplayAttributes(
2615 VADriverContextP ctx,
2616 VADisplayAttribute *attribs, /* in */
2617 int num_attribs /* in */
2622 for (i = 0; i < num_attribs; i++) {
2623 VADisplayAttribute *dst_attrib, * const src_attrib = &attribs[i];
2625 dst_attrib = get_display_attribute(ctx, src_attrib->type);
2627 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
2629 if (!(dst_attrib->flags & VA_DISPLAY_ATTRIB_SETTABLE))
2632 if (src_attrib->value < dst_attrib->min_value ||
2633 src_attrib->value > dst_attrib->max_value)
2634 return VA_STATUS_ERROR_INVALID_PARAMETER;
2636 dst_attrib->value = src_attrib->value;
2637 /* XXX: track modified attributes through timestamps */
2639 return VA_STATUS_SUCCESS;
2643 i965_DbgCopySurfaceToBuffer(VADriverContextP ctx,
2644 VASurfaceID surface,
2645 void **buffer, /* out */
2646 unsigned int *stride) /* out */
2649 return VA_STATUS_ERROR_UNIMPLEMENTED;
2653 i965_destroy_heap(struct object_heap *heap,
2654 void (*func)(struct object_heap *heap, struct object_base *object))
2656 struct object_base *object;
2657 object_heap_iterator iter;
2659 object = object_heap_first(heap, &iter);
2665 object = object_heap_next(heap, &iter);
2668 object_heap_destroy(heap);
2673 i965_DestroyImage(VADriverContextP ctx, VAImageID image);
2676 i965_CreateImage(VADriverContextP ctx,
2677 VAImageFormat *format,
2680 VAImage *out_image) /* out */
2682 struct i965_driver_data *i965 = i965_driver_data(ctx);
2683 struct object_image *obj_image;
2684 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
2686 unsigned int size2, size, awidth, aheight;
2688 out_image->image_id = VA_INVALID_ID;
2689 out_image->buf = VA_INVALID_ID;
2691 image_id = NEW_IMAGE_ID();
2692 if (image_id == VA_INVALID_ID)
2693 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2695 obj_image = IMAGE(image_id);
2697 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2698 obj_image->bo = NULL;
2699 obj_image->palette = NULL;
2700 obj_image->derived_surface = VA_INVALID_ID;
2702 VAImage * const image = &obj_image->image;
2703 image->image_id = image_id;
2704 image->buf = VA_INVALID_ID;
2706 awidth = ALIGN(width, 64);
2708 if ((format->fourcc == VA_FOURCC('Y','V','1','2')) ||
2709 (format->fourcc == VA_FOURCC('I','4','2','0'))) {
2710 if (awidth % 128 != 0) {
2711 awidth = ALIGN(width, 128);
2715 aheight = ALIGN(height, 16);
2716 size = awidth * aheight;
2717 size2 = (awidth / 2) * (aheight / 2);
2719 image->num_palette_entries = 0;
2720 image->entry_bytes = 0;
2721 memset(image->component_order, 0, sizeof(image->component_order));
2723 switch (format->fourcc) {
2724 case VA_FOURCC('I','A','4','4'):
2725 case VA_FOURCC('A','I','4','4'):
2726 image->num_planes = 1;
2727 image->pitches[0] = awidth;
2728 image->offsets[0] = 0;
2729 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2730 image->num_palette_entries = 16;
2731 image->entry_bytes = 3;
2732 image->component_order[0] = 'R';
2733 image->component_order[1] = 'G';
2734 image->component_order[2] = 'B';
2736 case VA_FOURCC('I','A','8','8'):
2737 case VA_FOURCC('A','I','8','8'):
2738 image->num_planes = 1;
2739 image->pitches[0] = awidth * 2;
2740 image->offsets[0] = 0;
2741 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2742 image->num_palette_entries = 256;
2743 image->entry_bytes = 3;
2744 image->component_order[0] = 'R';
2745 image->component_order[1] = 'G';
2746 image->component_order[2] = 'B';
2748 case VA_FOURCC('A','R','G','B'):
2749 case VA_FOURCC('A','B','G','R'):
2750 case VA_FOURCC('B','G','R','A'):
2751 case VA_FOURCC('R','G','B','A'):
2752 case VA_FOURCC('B','G','R','X'):
2753 case VA_FOURCC('R','G','B','X'):
2754 image->num_planes = 1;
2755 image->pitches[0] = awidth * 4;
2756 image->offsets[0] = 0;
2757 image->data_size = image->offsets[0] + image->pitches[0] * aheight;
2759 case VA_FOURCC('Y','V','1','2'):
2760 image->num_planes = 3;
2761 image->pitches[0] = awidth;
2762 image->offsets[0] = 0;
2763 image->pitches[1] = awidth / 2;
2764 image->offsets[1] = size;
2765 image->pitches[2] = awidth / 2;
2766 image->offsets[2] = size + size2;
2767 image->data_size = size + 2 * size2;
2769 case VA_FOURCC('I','4','2','0'):
2770 image->num_planes = 3;
2771 image->pitches[0] = awidth;
2772 image->offsets[0] = 0;
2773 image->pitches[1] = awidth / 2;
2774 image->offsets[1] = size;
2775 image->pitches[2] = awidth / 2;
2776 image->offsets[2] = size + size2;
2777 image->data_size = size + 2 * size2;
2779 case VA_FOURCC('N','V','1','2'):
2780 image->num_planes = 2;
2781 image->pitches[0] = awidth;
2782 image->offsets[0] = 0;
2783 image->pitches[1] = awidth;
2784 image->offsets[1] = size;
2785 image->data_size = size + 2 * size2;
2787 case VA_FOURCC('Y','U','Y','2'):
2788 case VA_FOURCC('U','Y','V','Y'):
2789 image->num_planes = 1;
2790 image->pitches[0] = awidth * 2;
2791 image->offsets[0] = 0;
2792 image->data_size = size * 2;
2798 va_status = i965_CreateBuffer(ctx, 0, VAImageBufferType,
2799 image->data_size, 1, NULL, &image->buf);
2800 if (va_status != VA_STATUS_SUCCESS)
2803 struct object_buffer *obj_buffer = BUFFER(image->buf);
2806 !obj_buffer->buffer_store ||
2807 !obj_buffer->buffer_store->bo)
2808 return VA_STATUS_ERROR_ALLOCATION_FAILED;
2810 obj_image->bo = obj_buffer->buffer_store->bo;
2811 dri_bo_reference(obj_image->bo);
2813 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
2814 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
2815 if (!obj_image->palette)
2819 image->image_id = image_id;
2820 image->format = *format;
2821 image->width = width;
2822 image->height = height;
2824 *out_image = *image;
2825 return VA_STATUS_SUCCESS;
2828 i965_DestroyImage(ctx, image_id);
2833 i965_check_alloc_surface_bo(VADriverContextP ctx,
2834 struct object_surface *obj_surface,
2836 unsigned int fourcc,
2837 unsigned int subsampling)
2839 struct i965_driver_data *i965 = i965_driver_data(ctx);
2840 int region_width, region_height;
2842 if (obj_surface->bo) {
2843 assert(obj_surface->fourcc);
2844 assert(obj_surface->fourcc == fourcc);
2845 assert(obj_surface->subsampling == subsampling);
2849 obj_surface->x_cb_offset = 0; /* X offset is always 0 */
2850 obj_surface->x_cr_offset = 0;
2853 assert(fourcc != VA_FOURCC('I', '4', '2', '0') &&
2854 fourcc != VA_FOURCC('I', 'Y', 'U', 'V') &&
2855 fourcc != VA_FOURCC('Y', 'V', '1', '2'));
2857 obj_surface->width = ALIGN(obj_surface->orig_width, 128);
2858 obj_surface->height = ALIGN(obj_surface->orig_height, 32);
2859 region_height = obj_surface->height;
2862 case VA_FOURCC('N', 'V', '1', '2'):
2863 assert(subsampling == SUBSAMPLE_YUV420);
2864 obj_surface->cb_cr_pitch = obj_surface->width;
2865 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2866 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2867 obj_surface->y_cb_offset = obj_surface->height;
2868 obj_surface->y_cr_offset = obj_surface->height;
2869 region_width = obj_surface->width;
2870 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
2874 case VA_FOURCC('I', 'M', 'C', '1'):
2875 assert(subsampling == SUBSAMPLE_YUV420);
2876 obj_surface->cb_cr_pitch = obj_surface->width;
2877 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2878 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2879 obj_surface->y_cr_offset = obj_surface->height;
2880 obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32);
2881 region_width = obj_surface->width;
2882 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2886 case VA_FOURCC('I', 'M', 'C', '3'):
2887 assert(subsampling == SUBSAMPLE_YUV420);
2888 obj_surface->cb_cr_pitch = obj_surface->width;
2889 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2890 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2891 obj_surface->y_cb_offset = obj_surface->height;
2892 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2893 region_width = obj_surface->width;
2894 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2898 case VA_FOURCC('4', '2', '2', 'H'):
2899 assert(subsampling == SUBSAMPLE_YUV422H);
2900 obj_surface->cb_cr_pitch = obj_surface->width;
2901 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2902 obj_surface->cb_cr_height = obj_surface->orig_height;
2903 obj_surface->y_cb_offset = obj_surface->height;
2904 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2905 region_width = obj_surface->width;
2906 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2910 case VA_FOURCC('4', '2', '2', 'V'):
2911 assert(subsampling == SUBSAMPLE_YUV422V);
2912 obj_surface->cb_cr_pitch = obj_surface->width;
2913 obj_surface->cb_cr_width = obj_surface->orig_width;
2914 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2915 obj_surface->y_cb_offset = obj_surface->height;
2916 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2917 region_width = obj_surface->width;
2918 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2922 case VA_FOURCC('4', '1', '1', 'P'):
2923 assert(subsampling == SUBSAMPLE_YUV411);
2924 obj_surface->cb_cr_pitch = obj_surface->width;
2925 obj_surface->cb_cr_width = obj_surface->orig_width / 4;
2926 obj_surface->cb_cr_height = obj_surface->orig_height;
2927 obj_surface->y_cb_offset = obj_surface->height;
2928 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2929 region_width = obj_surface->width;
2930 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2934 case VA_FOURCC('4', '4', '4', 'P'):
2935 assert(subsampling == SUBSAMPLE_YUV444);
2936 obj_surface->cb_cr_pitch = obj_surface->width;
2937 obj_surface->cb_cr_width = obj_surface->orig_width;
2938 obj_surface->cb_cr_height = obj_surface->orig_height;
2939 obj_surface->y_cb_offset = obj_surface->height;
2940 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2941 region_width = obj_surface->width;
2942 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2946 case VA_FOURCC('Y', '8', '0', '0'):
2947 assert(subsampling == SUBSAMPLE_YUV400);
2948 obj_surface->cb_cr_pitch = obj_surface->width;
2949 obj_surface->cb_cr_width = 0;
2950 obj_surface->cb_cr_height = 0;
2951 obj_surface->y_cb_offset = obj_surface->height;
2952 obj_surface->y_cr_offset = obj_surface->y_cb_offset + ALIGN(obj_surface->cb_cr_height, 32);
2953 region_width = obj_surface->width;
2954 region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32) * 2;
2958 case VA_FOURCC('Y', 'U', 'Y', '2'):
2959 case VA_FOURCC('U', 'Y', 'V', 'Y'):
2960 assert(subsampling == SUBSAMPLE_YUV422H);
2961 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
2962 obj_surface->cb_cr_pitch = obj_surface->width;
2963 obj_surface->y_cb_offset = 0;
2964 obj_surface->y_cr_offset = 0;
2965 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
2966 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
2967 region_width = obj_surface->width;
2968 region_height = obj_surface->height;
2972 case VA_FOURCC('R', 'G', 'B', 'A'):
2973 case VA_FOURCC('R', 'G', 'B', 'X'):
2974 case VA_FOURCC('B', 'G', 'R', 'A'):
2975 case VA_FOURCC('B', 'G', 'R', 'X'):
2976 assert(subsampling == SUBSAMPLE_RGBX);
2978 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
2979 region_width = obj_surface->width;
2980 region_height = obj_surface->height;
2984 /* Never get here */
2989 assert(subsampling == SUBSAMPLE_YUV420 ||
2990 subsampling == SUBSAMPLE_YUV422H ||
2991 subsampling == SUBSAMPLE_YUV422V ||
2992 subsampling == SUBSAMPLE_RGBX);
2994 region_width = obj_surface->width;
2995 region_height = obj_surface->height;
2998 case VA_FOURCC('N', 'V', '1', '2'):
2999 obj_surface->y_cb_offset = obj_surface->height;
3000 obj_surface->y_cr_offset = obj_surface->height;
3001 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3002 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3003 obj_surface->cb_cr_pitch = obj_surface->width;
3004 region_height = obj_surface->height + obj_surface->height / 2;
3007 case VA_FOURCC('Y', 'V', '1', '2'):
3008 case VA_FOURCC('I', '4', '2', '0'):
3009 if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) {
3010 obj_surface->y_cr_offset = obj_surface->height;
3011 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
3013 obj_surface->y_cb_offset = obj_surface->height;
3014 obj_surface->y_cr_offset = obj_surface->height + obj_surface->height / 4;
3017 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3018 obj_surface->cb_cr_height = obj_surface->orig_height / 2;
3019 obj_surface->cb_cr_pitch = obj_surface->width / 2;
3020 region_height = obj_surface->height + obj_surface->height / 2;
3023 case VA_FOURCC('Y', 'U', 'Y', '2'):
3024 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3025 obj_surface->width = ALIGN(obj_surface->orig_width * 2, 16);
3026 obj_surface->y_cb_offset = 0;
3027 obj_surface->y_cr_offset = 0;
3028 obj_surface->cb_cr_width = obj_surface->orig_width / 2;
3029 obj_surface->cb_cr_height = obj_surface->orig_height;
3030 obj_surface->cb_cr_pitch = obj_surface->width;
3031 region_width = obj_surface->width;
3032 region_height = obj_surface->height;
3034 case VA_FOURCC('R', 'G', 'B', 'A'):
3035 case VA_FOURCC('R', 'G', 'B', 'X'):
3036 case VA_FOURCC('B', 'G', 'R', 'A'):
3037 case VA_FOURCC('B', 'G', 'R', 'X'):
3038 obj_surface->width = ALIGN(obj_surface->orig_width * 4, 16);
3039 region_width = obj_surface->width;
3040 region_height = obj_surface->height;
3044 /* Never get here */
3050 obj_surface->size = ALIGN(region_width * region_height, 0x1000);
3053 uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
3054 unsigned long pitch;
3056 obj_surface->bo = drm_intel_bo_alloc_tiled(i965->intel.bufmgr,
3064 assert(tiling_mode == I915_TILING_Y);
3065 assert(pitch == obj_surface->width);
3067 obj_surface->bo = dri_bo_alloc(i965->intel.bufmgr,
3073 obj_surface->fourcc = fourcc;
3074 obj_surface->subsampling = subsampling;
3075 assert(obj_surface->bo);
3078 VAStatus i965_DeriveImage(VADriverContextP ctx,
3079 VASurfaceID surface,
3080 VAImage *out_image) /* out */
3082 struct i965_driver_data *i965 = i965_driver_data(ctx);
3083 struct object_image *obj_image;
3084 struct object_surface *obj_surface;
3086 unsigned int w_pitch;
3087 VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3089 out_image->image_id = VA_INVALID_ID;
3090 obj_surface = SURFACE(surface);
3093 return VA_STATUS_ERROR_INVALID_SURFACE;
3095 if (!obj_surface->bo) {
3096 unsigned int is_tiled = 0;
3097 unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2');
3098 i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
3099 int sampling = get_sampling_from_fourcc(fourcc);
3100 i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
3103 assert(obj_surface->fourcc);
3105 w_pitch = obj_surface->width;
3107 image_id = NEW_IMAGE_ID();
3109 if (image_id == VA_INVALID_ID)
3110 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3112 obj_image = IMAGE(image_id);
3115 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3117 obj_image->bo = NULL;
3118 obj_image->palette = NULL;
3119 obj_image->derived_surface = VA_INVALID_ID;
3121 VAImage * const image = &obj_image->image;
3123 memset(image, 0, sizeof(*image));
3124 image->image_id = image_id;
3125 image->buf = VA_INVALID_ID;
3126 image->num_palette_entries = 0;
3127 image->entry_bytes = 0;
3128 image->width = obj_surface->orig_width;
3129 image->height = obj_surface->orig_height;
3130 image->data_size = obj_surface->size;
3132 image->format.fourcc = obj_surface->fourcc;
3133 image->format.byte_order = VA_LSB_FIRST;
3134 image->format.bits_per_pixel = 12;
3136 switch (image->format.fourcc) {
3137 case VA_FOURCC('Y', 'V', '1', '2'):
3138 image->num_planes = 3;
3139 image->pitches[0] = w_pitch; /* Y */
3140 image->offsets[0] = 0;
3141 image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
3142 image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
3143 image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
3144 image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
3147 case VA_FOURCC('N', 'V', '1', '2'):
3148 image->num_planes = 2;
3149 image->pitches[0] = w_pitch; /* Y */
3150 image->offsets[0] = 0;
3151 image->pitches[1] = obj_surface->cb_cr_pitch; /* UV */
3152 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3155 case VA_FOURCC('I', '4', '2', '0'):
3156 image->num_planes = 3;
3157 image->pitches[0] = w_pitch; /* Y */
3158 image->offsets[0] = 0;
3159 image->pitches[1] = obj_surface->cb_cr_pitch; /* U */
3160 image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
3161 image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
3162 image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
3164 case VA_FOURCC('Y', 'U', 'Y', '2'):
3165 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3166 image->num_planes = 1;
3167 image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
3168 image->offsets[0] = 0;
3170 case VA_FOURCC('R', 'G', 'B', 'A'):
3171 case VA_FOURCC('R', 'G', 'B', 'X'):
3172 case VA_FOURCC('B', 'G', 'R', 'A'):
3173 case VA_FOURCC('B', 'G', 'R', 'X'):
3174 image->num_planes = 1;
3175 image->pitches[0] = obj_surface->width;
3181 va_status = i965_create_buffer_internal(ctx, 0, VAImageBufferType,
3182 obj_surface->size, 1, NULL, obj_surface->bo, &image->buf);
3183 if (va_status != VA_STATUS_SUCCESS)
3186 struct object_buffer *obj_buffer = BUFFER(image->buf);
3189 !obj_buffer->buffer_store ||
3190 !obj_buffer->buffer_store->bo)
3191 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3193 obj_image->bo = obj_buffer->buffer_store->bo;
3194 dri_bo_reference(obj_image->bo);
3196 if (image->num_palette_entries > 0 && image->entry_bytes > 0) {
3197 obj_image->palette = malloc(image->num_palette_entries * sizeof(*obj_image->palette));
3198 if (!obj_image->palette) {
3199 va_status = VA_STATUS_ERROR_ALLOCATION_FAILED;
3204 *out_image = *image;
3205 obj_surface->flags |= SURFACE_DERIVED;
3206 obj_image->derived_surface = surface;
3208 return VA_STATUS_SUCCESS;
3211 i965_DestroyImage(ctx, image_id);
3216 i965_destroy_image(struct object_heap *heap, struct object_base *obj)
3218 object_heap_free(heap, obj);
3223 i965_DestroyImage(VADriverContextP ctx, VAImageID image)
3225 struct i965_driver_data *i965 = i965_driver_data(ctx);
3226 struct object_image *obj_image = IMAGE(image);
3227 struct object_surface *obj_surface;
3230 return VA_STATUS_SUCCESS;
3232 dri_bo_unreference(obj_image->bo);
3233 obj_image->bo = NULL;
3235 if (obj_image->image.buf != VA_INVALID_ID) {
3236 i965_DestroyBuffer(ctx, obj_image->image.buf);
3237 obj_image->image.buf = VA_INVALID_ID;
3240 if (obj_image->palette) {
3241 free(obj_image->palette);
3242 obj_image->palette = NULL;
3245 obj_surface = SURFACE(obj_image->derived_surface);
3248 obj_surface->flags &= ~SURFACE_DERIVED;
3251 i965_destroy_image(&i965->image_heap, (struct object_base *)obj_image);
3253 return VA_STATUS_SUCCESS;
3257 * pointer to an array holding the palette data. The size of the array is
3258 * num_palette_entries * entry_bytes in size. The order of the components
3259 * in the palette is described by the component_order in VASubpicture struct
3262 i965_SetImagePalette(VADriverContextP ctx,
3264 unsigned char *palette)
3266 struct i965_driver_data *i965 = i965_driver_data(ctx);
3269 struct object_image *obj_image = IMAGE(image);
3271 return VA_STATUS_ERROR_INVALID_IMAGE;
3273 if (!obj_image->palette)
3274 return VA_STATUS_ERROR_ALLOCATION_FAILED; /* XXX: unpaletted/error */
3276 for (i = 0; i < obj_image->image.num_palette_entries; i++)
3277 obj_image->palette[i] = (((unsigned int)palette[3*i + 0] << 16) |
3278 ((unsigned int)palette[3*i + 1] << 8) |
3279 (unsigned int)palette[3*i + 2]);
3280 return VA_STATUS_SUCCESS;
3284 get_sampling_from_fourcc(unsigned int fourcc)
3286 int surface_sampling = -1;
3289 case VA_FOURCC('N', 'V', '1', '2'):
3290 case VA_FOURCC('Y', 'V', '1', '2'):
3291 case VA_FOURCC('I', '4', '2', '0'):
3292 case VA_FOURCC('I', 'Y', 'U', 'V'):
3293 case VA_FOURCC('I', 'M', 'C', '1'):
3294 case VA_FOURCC('I', 'M', 'C', '3'):
3295 surface_sampling = SUBSAMPLE_YUV420;
3297 case VA_FOURCC('Y', 'U', 'Y', '2'):
3298 case VA_FOURCC('U', 'Y', 'V', 'Y'):
3299 case VA_FOURCC('4', '2', '2', 'H'):
3300 surface_sampling = SUBSAMPLE_YUV422H;
3302 case VA_FOURCC('4', '2', '2', 'V'):
3303 surface_sampling = SUBSAMPLE_YUV422V;
3306 case VA_FOURCC('4', '4', '4', 'P'):
3307 surface_sampling = SUBSAMPLE_YUV444;
3310 case VA_FOURCC('4', '1', '1', 'P'):
3311 surface_sampling = SUBSAMPLE_YUV411;
3314 case VA_FOURCC('Y', '8', '0', '0'):
3315 surface_sampling = SUBSAMPLE_YUV400;
3317 case VA_FOURCC('R','G','B','A'):
3318 case VA_FOURCC('R','G','B','X'):
3319 case VA_FOURCC('B','G','R','A'):
3320 case VA_FOURCC('B','G','R','X'):
3321 surface_sampling = SUBSAMPLE_RGBX;
3324 /* Never get here */
3330 return surface_sampling;
3334 memcpy_pic(uint8_t *dst, unsigned int dst_stride,
3335 const uint8_t *src, unsigned int src_stride,
3336 unsigned int len, unsigned int height)
3340 for (i = 0; i < height; i++) {
3341 memcpy(dst, src, len);
3348 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
3349 struct object_surface *obj_surface,
3350 const VARectangle *rect)
3352 uint8_t *dst[3], *src[3];
3354 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3355 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3356 unsigned int tiling, swizzle;
3358 if (!obj_surface->bo)
3361 assert(obj_surface->fourcc);
3362 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3364 if (tiling != I915_TILING_NONE)
3365 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3367 dri_bo_map(obj_surface->bo, 0);
3369 if (!obj_surface->bo->virtual)
3372 /* Dest VA image has either I420 or YV12 format.
3373 Source VA surface alway has I420 format */
3374 dst[Y] = image_data + obj_image->image.offsets[Y];
3375 src[0] = (uint8_t *)obj_surface->bo->virtual;
3376 dst[U] = image_data + obj_image->image.offsets[U];
3377 src[1] = src[0] + obj_surface->width * obj_surface->height;
3378 dst[V] = image_data + obj_image->image.offsets[V];
3379 src[2] = src[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3382 dst[Y] += rect->y * obj_image->image.pitches[Y] + rect->x;
3383 src[0] += rect->y * obj_surface->width + rect->x;
3384 memcpy_pic(dst[Y], obj_image->image.pitches[Y],
3385 src[0], obj_surface->width,
3386 rect->width, rect->height);
3389 dst[U] += (rect->y / 2) * obj_image->image.pitches[U] + rect->x / 2;
3390 src[1] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3391 memcpy_pic(dst[U], obj_image->image.pitches[U],
3392 src[1], obj_surface->width / 2,
3393 rect->width / 2, rect->height / 2);
3396 dst[V] += (rect->y / 2) * obj_image->image.pitches[V] + rect->x / 2;
3397 src[2] += (rect->y / 2) * obj_surface->width / 2 + rect->x / 2;
3398 memcpy_pic(dst[V], obj_image->image.pitches[V],
3399 src[2], obj_surface->width / 2,
3400 rect->width / 2, rect->height / 2);
3402 if (tiling != I915_TILING_NONE)
3403 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3405 dri_bo_unmap(obj_surface->bo);
3409 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
3410 struct object_surface *obj_surface,
3411 const VARectangle *rect)
3413 uint8_t *dst[2], *src[2];
3414 unsigned int tiling, swizzle;
3416 if (!obj_surface->bo)
3419 assert(obj_surface->fourcc);
3420 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3422 if (tiling != I915_TILING_NONE)
3423 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3425 dri_bo_map(obj_surface->bo, 0);
3427 if (!obj_surface->bo->virtual)
3430 /* Both dest VA image and source surface have NV12 format */
3431 dst[0] = image_data + obj_image->image.offsets[0];
3432 src[0] = (uint8_t *)obj_surface->bo->virtual;
3433 dst[1] = image_data + obj_image->image.offsets[1];
3434 src[1] = src[0] + obj_surface->width * obj_surface->height;
3437 dst[0] += rect->y * obj_image->image.pitches[0] + rect->x;
3438 src[0] += rect->y * obj_surface->width + rect->x;
3439 memcpy_pic(dst[0], obj_image->image.pitches[0],
3440 src[0], obj_surface->width,
3441 rect->width, rect->height);
3444 dst[1] += (rect->y / 2) * obj_image->image.pitches[1] + (rect->x & -2);
3445 src[1] += (rect->y / 2) * obj_surface->width + (rect->x & -2);
3446 memcpy_pic(dst[1], obj_image->image.pitches[1],
3447 src[1], obj_surface->width,
3448 rect->width, rect->height / 2);
3450 if (tiling != I915_TILING_NONE)
3451 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3453 dri_bo_unmap(obj_surface->bo);
3457 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
3458 struct object_surface *obj_surface,
3459 const VARectangle *rect)
3462 unsigned int tiling, swizzle;
3464 if (!obj_surface->bo)
3467 assert(obj_surface->fourcc);
3468 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3470 if (tiling != I915_TILING_NONE)
3471 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3473 dri_bo_map(obj_surface->bo, 0);
3475 if (!obj_surface->bo->virtual)
3478 /* Both dest VA image and source surface have YUYV format */
3479 dst = image_data + obj_image->image.offsets[0];
3480 src = (uint8_t *)obj_surface->bo->virtual;
3483 dst += rect->y * obj_image->image.pitches[0] + rect->x*2;
3484 src += rect->y * obj_surface->width + rect->x*2;
3485 memcpy_pic(dst, obj_image->image.pitches[0],
3486 src, obj_surface->width*2,
3487 rect->width*2, rect->height);
3489 if (tiling != I915_TILING_NONE)
3490 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3492 dri_bo_unmap(obj_surface->bo);
3496 i965_sw_getimage(VADriverContextP ctx,
3497 VASurfaceID surface,
3498 int x, /* coordinates of the upper left source pixel */
3500 unsigned int width, /* width and height of the region */
3501 unsigned int height,
3504 struct i965_driver_data *i965 = i965_driver_data(ctx);
3505 struct i965_render_state *render_state = &i965->render_state;
3507 struct object_surface *obj_surface = SURFACE(surface);
3509 return VA_STATUS_ERROR_INVALID_SURFACE;
3511 struct object_image *obj_image = IMAGE(image);
3513 return VA_STATUS_ERROR_INVALID_IMAGE;
3516 return VA_STATUS_ERROR_INVALID_PARAMETER;
3517 if (x + width > obj_surface->orig_width ||
3518 y + height > obj_surface->orig_height)
3519 return VA_STATUS_ERROR_INVALID_PARAMETER;
3520 if (x + width > obj_image->image.width ||
3521 y + height > obj_image->image.height)
3522 return VA_STATUS_ERROR_INVALID_PARAMETER;
3524 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3525 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3528 void *image_data = NULL;
3530 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3531 if (va_status != VA_STATUS_SUCCESS)
3538 rect.height = height;
3540 switch (obj_image->image.format.fourcc) {
3541 case VA_FOURCC('Y','V','1','2'):
3542 case VA_FOURCC('I','4','2','0'):
3543 /* I420 is native format for MPEG-2 decoded surfaces */
3544 if (render_state->interleaved_uv)
3545 goto operation_failed;
3546 get_image_i420(obj_image, image_data, obj_surface, &rect);
3548 case VA_FOURCC('N','V','1','2'):
3549 /* NV12 is native format for H.264 decoded surfaces */
3550 if (!render_state->interleaved_uv)
3551 goto operation_failed;
3552 get_image_nv12(obj_image, image_data, obj_surface, &rect);
3554 case VA_FOURCC('Y','U','Y','2'):
3555 /* YUY2 is the format supported by overlay plane */
3556 get_image_yuy2(obj_image, image_data, obj_surface, &rect);
3560 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3564 i965_UnmapBuffer(ctx, obj_image->image.buf);
3569 i965_hw_getimage(VADriverContextP ctx,
3570 VASurfaceID surface,
3571 int x, /* coordinates of the upper left source pixel */
3573 unsigned int width, /* width and height of the region */
3574 unsigned int height,
3577 struct i965_driver_data *i965 = i965_driver_data(ctx);
3578 struct i965_surface src_surface;
3579 struct i965_surface dst_surface;
3582 struct object_surface *obj_surface = SURFACE(surface);
3583 struct object_image *obj_image = IMAGE(image);
3586 return VA_STATUS_ERROR_INVALID_SURFACE;
3589 return VA_STATUS_ERROR_INVALID_IMAGE;
3592 return VA_STATUS_ERROR_INVALID_PARAMETER;
3593 if (x + width > obj_surface->orig_width ||
3594 y + height > obj_surface->orig_height)
3595 return VA_STATUS_ERROR_INVALID_PARAMETER;
3596 if (x + width > obj_image->image.width ||
3597 y + height > obj_image->image.height)
3598 return VA_STATUS_ERROR_INVALID_PARAMETER;
3600 if (!obj_surface->bo)
3601 return VA_STATUS_SUCCESS;
3602 assert(obj_image->bo); // image bo is always created, see i965_CreateImage()
3607 rect.height = height;
3609 src_surface.base = (struct object_base *)obj_surface;
3610 src_surface.type = I965_SURFACE_TYPE_SURFACE;
3611 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3613 dst_surface.base = (struct object_base *)obj_image;
3614 dst_surface.type = I965_SURFACE_TYPE_IMAGE;
3615 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3617 va_status = i965_image_processing(ctx,
3628 i965_GetImage(VADriverContextP ctx,
3629 VASurfaceID surface,
3630 int x, /* coordinates of the upper left source pixel */
3632 unsigned int width, /* width and height of the region */
3633 unsigned int height,
3636 struct i965_driver_data * const i965 = i965_driver_data(ctx);
3639 if (HAS_ACCELERATED_GETIMAGE(i965))
3640 va_status = i965_hw_getimage(ctx,
3646 va_status = i965_sw_getimage(ctx,
3656 put_image_i420(struct object_surface *obj_surface,
3657 const VARectangle *dst_rect,
3658 struct object_image *obj_image, uint8_t *image_data,
3659 const VARectangle *src_rect)
3661 uint8_t *dst[3], *src[3];
3663 const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
3664 const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
3665 unsigned int tiling, swizzle;
3667 if (!obj_surface->bo)
3670 assert(obj_surface->fourcc);
3671 assert(dst_rect->width == src_rect->width);
3672 assert(dst_rect->height == src_rect->height);
3673 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3675 if (tiling != I915_TILING_NONE)
3676 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3678 dri_bo_map(obj_surface->bo, 0);
3680 if (!obj_surface->bo->virtual)
3683 /* Dest VA image has either I420 or YV12 format.
3684 Source VA surface alway has I420 format */
3685 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3686 src[Y] = image_data + obj_image->image.offsets[Y];
3687 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3688 src[U] = image_data + obj_image->image.offsets[U];
3689 dst[2] = dst[1] + (obj_surface->width / 2) * (obj_surface->height / 2);
3690 src[V] = image_data + obj_image->image.offsets[V];
3693 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3694 src[Y] += src_rect->y * obj_image->image.pitches[Y] + src_rect->x;
3695 memcpy_pic(dst[0], obj_surface->width,
3696 src[Y], obj_image->image.pitches[Y],
3697 src_rect->width, src_rect->height);
3700 dst[1] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3701 src[U] += (src_rect->y / 2) * obj_image->image.pitches[U] + src_rect->x / 2;
3702 memcpy_pic(dst[1], obj_surface->width / 2,
3703 src[U], obj_image->image.pitches[U],
3704 src_rect->width / 2, src_rect->height / 2);
3707 dst[2] += (dst_rect->y / 2) * obj_surface->width / 2 + dst_rect->x / 2;
3708 src[V] += (src_rect->y / 2) * obj_image->image.pitches[V] + src_rect->x / 2;
3709 memcpy_pic(dst[2], obj_surface->width / 2,
3710 src[V], obj_image->image.pitches[V],
3711 src_rect->width / 2, src_rect->height / 2);
3713 if (tiling != I915_TILING_NONE)
3714 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3716 dri_bo_unmap(obj_surface->bo);
3720 put_image_nv12(struct object_surface *obj_surface,
3721 const VARectangle *dst_rect,
3722 struct object_image *obj_image, uint8_t *image_data,
3723 const VARectangle *src_rect)
3725 uint8_t *dst[2], *src[2];
3726 unsigned int tiling, swizzle;
3728 if (!obj_surface->bo)
3731 assert(obj_surface->fourcc);
3732 assert(dst_rect->width == src_rect->width);
3733 assert(dst_rect->height == src_rect->height);
3734 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3736 if (tiling != I915_TILING_NONE)
3737 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3739 dri_bo_map(obj_surface->bo, 0);
3741 if (!obj_surface->bo->virtual)
3744 /* Both dest VA image and source surface have NV12 format */
3745 dst[0] = (uint8_t *)obj_surface->bo->virtual;
3746 src[0] = image_data + obj_image->image.offsets[0];
3747 dst[1] = dst[0] + obj_surface->width * obj_surface->height;
3748 src[1] = image_data + obj_image->image.offsets[1];
3751 dst[0] += dst_rect->y * obj_surface->width + dst_rect->x;
3752 src[0] += src_rect->y * obj_image->image.pitches[0] + src_rect->x;
3753 memcpy_pic(dst[0], obj_surface->width,
3754 src[0], obj_image->image.pitches[0],
3755 src_rect->width, src_rect->height);
3758 dst[1] += (dst_rect->y / 2) * obj_surface->width + (dst_rect->x & -2);
3759 src[1] += (src_rect->y / 2) * obj_image->image.pitches[1] + (src_rect->x & -2);
3760 memcpy_pic(dst[1], obj_surface->width,
3761 src[1], obj_image->image.pitches[1],
3762 src_rect->width, src_rect->height / 2);
3764 if (tiling != I915_TILING_NONE)
3765 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3767 dri_bo_unmap(obj_surface->bo);
3771 put_image_yuy2(struct object_surface *obj_surface,
3772 const VARectangle *dst_rect,
3773 struct object_image *obj_image, uint8_t *image_data,
3774 const VARectangle *src_rect)
3777 unsigned int tiling, swizzle;
3779 if (!obj_surface->bo)
3782 assert(obj_surface->fourcc);
3783 assert(dst_rect->width == src_rect->width);
3784 assert(dst_rect->height == src_rect->height);
3785 dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
3787 if (tiling != I915_TILING_NONE)
3788 drm_intel_gem_bo_map_gtt(obj_surface->bo);
3790 dri_bo_map(obj_surface->bo, 0);
3792 if (!obj_surface->bo->virtual)
3795 /* Both dest VA image and source surface have YUY2 format */
3796 dst = (uint8_t *)obj_surface->bo->virtual;
3797 src = image_data + obj_image->image.offsets[0];
3799 /* YUYV packed plane */
3800 dst += dst_rect->y * obj_surface->width + dst_rect->x*2;
3801 src += src_rect->y * obj_image->image.pitches[0] + src_rect->x*2;
3802 memcpy_pic(dst, obj_surface->width*2,
3803 src, obj_image->image.pitches[0],
3804 src_rect->width*2, src_rect->height);
3806 if (tiling != I915_TILING_NONE)
3807 drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
3809 dri_bo_unmap(obj_surface->bo);
3814 i965_sw_putimage(VADriverContextP ctx,
3815 VASurfaceID surface,
3819 unsigned int src_width,
3820 unsigned int src_height,
3823 unsigned int dest_width,
3824 unsigned int dest_height)
3826 struct i965_driver_data *i965 = i965_driver_data(ctx);
3827 struct object_surface *obj_surface = SURFACE(surface);
3830 return VA_STATUS_ERROR_INVALID_SURFACE;
3832 struct object_image *obj_image = IMAGE(image);
3834 return VA_STATUS_ERROR_INVALID_IMAGE;
3836 if (src_x < 0 || src_y < 0)
3837 return VA_STATUS_ERROR_INVALID_PARAMETER;
3838 if (src_x + src_width > obj_image->image.width ||
3839 src_y + src_height > obj_image->image.height)
3840 return VA_STATUS_ERROR_INVALID_PARAMETER;
3841 if (dest_x < 0 || dest_y < 0)
3842 return VA_STATUS_ERROR_INVALID_PARAMETER;
3843 if (dest_x + dest_width > obj_surface->orig_width ||
3844 dest_y + dest_height > obj_surface->orig_height)
3845 return VA_STATUS_ERROR_INVALID_PARAMETER;
3847 /* XXX: don't allow scaling */
3848 if (src_width != dest_width || src_height != dest_height)
3849 return VA_STATUS_ERROR_INVALID_PARAMETER;
3851 if (obj_surface->fourcc) {
3852 /* Don't allow format mismatch */
3853 if (obj_surface->fourcc != obj_image->image.format.fourcc)
3854 return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
3858 /* VA is surface not used for decoding, use same VA image format */
3859 i965_check_alloc_surface_bo(
3862 0, /* XXX: don't use tiled surface */
3863 obj_image->image.format.fourcc,
3864 get_sampling_from_fourcc (obj_image->image.format.fourcc));
3868 void *image_data = NULL;
3870 va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
3871 if (va_status != VA_STATUS_SUCCESS)
3874 VARectangle src_rect, dest_rect;
3877 src_rect.width = src_width;
3878 src_rect.height = src_height;
3879 dest_rect.x = dest_x;
3880 dest_rect.y = dest_y;
3881 dest_rect.width = dest_width;
3882 dest_rect.height = dest_height;
3884 switch (obj_image->image.format.fourcc) {
3885 case VA_FOURCC('Y','V','1','2'):
3886 case VA_FOURCC('I','4','2','0'):
3887 put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3889 case VA_FOURCC('N','V','1','2'):
3890 put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3892 case VA_FOURCC('Y','U','Y','2'):
3893 put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
3896 va_status = VA_STATUS_ERROR_OPERATION_FAILED;
3900 i965_UnmapBuffer(ctx, obj_image->image.buf);
3905 i965_hw_putimage(VADriverContextP ctx,
3906 VASurfaceID surface,
3910 unsigned int src_width,
3911 unsigned int src_height,
3914 unsigned int dest_width,
3915 unsigned int dest_height)
3917 struct i965_driver_data *i965 = i965_driver_data(ctx);
3918 struct object_surface *obj_surface = SURFACE(surface);
3919 struct object_image *obj_image = IMAGE(image);
3920 struct i965_surface src_surface, dst_surface;
3921 VAStatus va_status = VA_STATUS_SUCCESS;
3922 VARectangle src_rect, dst_rect;
3925 return VA_STATUS_ERROR_INVALID_SURFACE;
3927 if (!obj_image || !obj_image->bo)
3928 return VA_STATUS_ERROR_INVALID_IMAGE;
3932 src_x + src_width > obj_image->image.width ||
3933 src_y + src_height > obj_image->image.height)
3934 return VA_STATUS_ERROR_INVALID_PARAMETER;
3938 dest_x + dest_width > obj_surface->orig_width ||
3939 dest_y + dest_height > obj_surface->orig_height)
3940 return VA_STATUS_ERROR_INVALID_PARAMETER;
3942 if (!obj_surface->bo) {
3943 unsigned int tiling, swizzle;
3944 int surface_sampling = get_sampling_from_fourcc (obj_image->image.format.fourcc);;
3945 dri_bo_get_tiling(obj_image->bo, &tiling, &swizzle);
3947 i965_check_alloc_surface_bo(ctx,
3950 obj_image->image.format.fourcc,
3954 assert(obj_surface->fourcc);
3956 src_surface.base = (struct object_base *)obj_image;
3957 src_surface.type = I965_SURFACE_TYPE_IMAGE;
3958 src_surface.flags = I965_SURFACE_FLAG_FRAME;
3961 src_rect.width = src_width;
3962 src_rect.height = src_height;
3964 dst_surface.base = (struct object_base *)obj_surface;
3965 dst_surface.type = I965_SURFACE_TYPE_SURFACE;
3966 dst_surface.flags = I965_SURFACE_FLAG_FRAME;
3967 dst_rect.x = dest_x;
3968 dst_rect.y = dest_y;
3969 dst_rect.width = dest_width;
3970 dst_rect.height = dest_height;
3972 va_status = i965_image_processing(ctx,
3982 i965_PutImage(VADriverContextP ctx,
3983 VASurfaceID surface,
3987 unsigned int src_width,
3988 unsigned int src_height,
3991 unsigned int dest_width,
3992 unsigned int dest_height)
3994 struct i965_driver_data *i965 = i965_driver_data(ctx);
3995 VAStatus va_status = VA_STATUS_SUCCESS;
3997 if (HAS_ACCELERATED_PUTIMAGE(i965))
3998 va_status = i965_hw_putimage(ctx,
4010 va_status = i965_sw_putimage(ctx,
4026 i965_PutSurface(VADriverContextP ctx,
4027 VASurfaceID surface,
4028 void *draw, /* X Drawable */
4031 unsigned short srcw,
4032 unsigned short srch,
4035 unsigned short destw,
4036 unsigned short desth,
4037 VARectangle *cliprects, /* client supplied clip list */
4038 unsigned int number_cliprects, /* number of clip rects in the clip list */
4039 unsigned int flags) /* de-interlacing flags */
4042 if (IS_VA_X11(ctx)) {
4043 VARectangle src_rect, dst_rect;
4047 src_rect.width = srcw;
4048 src_rect.height = srch;
4052 dst_rect.width = destw;
4053 dst_rect.height = desth;
4055 return i965_put_surface_dri(ctx, surface, draw, &src_rect, &dst_rect,
4056 cliprects, number_cliprects, flags);
4059 return VA_STATUS_ERROR_UNIMPLEMENTED;
4064 VADriverContextP ctx, /* in */
4065 VABufferID buf_id, /* in */
4066 VABufferType *type, /* out */
4067 unsigned int *size, /* out */
4068 unsigned int *num_elements /* out */
4071 struct i965_driver_data *i965 = NULL;
4072 struct object_buffer *obj_buffer = NULL;
4074 i965 = i965_driver_data(ctx);
4075 obj_buffer = BUFFER(buf_id);
4080 return VA_STATUS_ERROR_INVALID_BUFFER;
4082 *type = obj_buffer->type;
4083 *size = obj_buffer->size_element;
4084 *num_elements = obj_buffer->num_elements;
4086 return VA_STATUS_SUCCESS;
4091 VADriverContextP ctx, /* in */
4092 VASurfaceID surface, /* in */
4093 unsigned int *fourcc, /* out */
4094 unsigned int *luma_stride, /* out */
4095 unsigned int *chroma_u_stride, /* out */
4096 unsigned int *chroma_v_stride, /* out */
4097 unsigned int *luma_offset, /* out */
4098 unsigned int *chroma_u_offset, /* out */
4099 unsigned int *chroma_v_offset, /* out */
4100 unsigned int *buffer_name, /* out */
4101 void **buffer /* out */
4104 VAStatus vaStatus = VA_STATUS_SUCCESS;
4105 struct i965_driver_data *i965 = i965_driver_data(ctx);
4106 struct object_surface *obj_surface = NULL;
4110 assert(luma_stride);
4111 assert(chroma_u_stride);
4112 assert(chroma_v_stride);
4113 assert(luma_offset);
4114 assert(chroma_u_offset);
4115 assert(chroma_v_offset);
4116 assert(buffer_name);
4119 tmpImage.image_id = VA_INVALID_ID;
4121 obj_surface = SURFACE(surface);
4122 if (obj_surface == NULL) {
4123 // Surface is absent.
4124 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4128 // Lock functionality is absent now.
4129 if (obj_surface->locked_image_id != VA_INVALID_ID) {
4130 // Surface is locked already.
4131 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4135 vaStatus = i965_DeriveImage(
4139 if (vaStatus != VA_STATUS_SUCCESS) {
4143 obj_surface->locked_image_id = tmpImage.image_id;
4145 vaStatus = i965_MapBuffer(
4149 if (vaStatus != VA_STATUS_SUCCESS) {
4153 *fourcc = tmpImage.format.fourcc;
4154 *luma_offset = tmpImage.offsets[0];
4155 *luma_stride = tmpImage.pitches[0];
4156 *chroma_u_offset = tmpImage.offsets[1];
4157 *chroma_u_stride = tmpImage.pitches[1];
4158 *chroma_v_offset = tmpImage.offsets[2];
4159 *chroma_v_stride = tmpImage.pitches[2];
4160 *buffer_name = tmpImage.buf;
4163 if (vaStatus != VA_STATUS_SUCCESS) {
4172 VADriverContextP ctx, /* in */
4173 VASurfaceID surface /* in */
4176 VAStatus vaStatus = VA_STATUS_SUCCESS;
4177 struct i965_driver_data *i965 = i965_driver_data(ctx);
4178 struct object_image *locked_img = NULL;
4179 struct object_surface *obj_surface = NULL;
4181 obj_surface = SURFACE(surface);
4183 if (obj_surface == NULL) {
4184 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is absent
4187 if (obj_surface->locked_image_id == VA_INVALID_ID) {
4188 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER; // Surface is not locked
4192 locked_img = IMAGE(obj_surface->locked_image_id);
4193 if (locked_img == NULL || (locked_img->image.image_id == VA_INVALID_ID)) {
4194 // Work image was deallocated before i965_UnlockSurface()
4195 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
4199 vaStatus = i965_UnmapBuffer(
4201 locked_img->image.buf);
4202 if (vaStatus != VA_STATUS_SUCCESS) {
4206 vaStatus = i965_DestroyImage(
4208 locked_img->image.image_id);
4209 if (vaStatus != VA_STATUS_SUCCESS) {
4213 locked_img->image.image_id = VA_INVALID_ID;
4216 obj_surface->locked_image_id = VA_INVALID_ID;
4222 i965_GetSurfaceAttributes(
4223 VADriverContextP ctx,
4225 VASurfaceAttrib *attrib_list,
4226 unsigned int num_attribs
4229 VAStatus vaStatus = VA_STATUS_SUCCESS;
4230 struct i965_driver_data *i965 = i965_driver_data(ctx);
4231 struct object_config *obj_config;
4234 if (config == VA_INVALID_ID)
4235 return VA_STATUS_ERROR_INVALID_CONFIG;
4237 obj_config = CONFIG(config);
4239 if (obj_config == NULL)
4240 return VA_STATUS_ERROR_INVALID_CONFIG;
4242 if (attrib_list == NULL || num_attribs == 0)
4243 return VA_STATUS_ERROR_INVALID_PARAMETER;
4245 for (i = 0; i < num_attribs; i++) {
4246 switch (attrib_list[i].type) {
4247 case VASurfaceAttribPixelFormat:
4248 attrib_list[i].value.type = VAGenericValueTypeInteger;
4249 attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4251 if (attrib_list[i].value.value.i == 0) {
4252 if (IS_G4X(i965->intel.device_id)) {
4253 if (obj_config->profile == VAProfileMPEG2Simple ||
4254 obj_config->profile == VAProfileMPEG2Main) {
4255 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4258 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4260 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4261 if (obj_config->profile == VAProfileMPEG2Simple ||
4262 obj_config->profile == VAProfileMPEG2Main) {
4263 attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4264 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4265 obj_config->profile == VAProfileH264Main ||
4266 obj_config->profile == VAProfileH264High) {
4267 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4268 } else if (obj_config->profile == VAProfileNone) {
4269 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4272 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4274 } else if (IS_GEN6(i965->intel.device_id)) {
4275 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4276 } else if (IS_GEN7(i965->intel.device_id) ||
4277 IS_GEN8(i965->intel.device_id)) {
4278 if (obj_config->profile == VAProfileJPEGBaseline)
4279 attrib_list[i].value.value.i = 0; /* internal format */
4281 attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4284 if (IS_G4X(i965->intel.device_id)) {
4285 if (obj_config->profile == VAProfileMPEG2Simple ||
4286 obj_config->profile == VAProfileMPEG2Main) {
4287 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
4288 attrib_list[i].value.value.i = 0;
4289 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4293 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4295 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4296 if (obj_config->profile == VAProfileMPEG2Simple ||
4297 obj_config->profile == VAProfileMPEG2Main) {
4298 if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
4299 attrib_list[i].value.value.i = 0;
4300 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4302 } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
4303 obj_config->profile == VAProfileH264Main ||
4304 obj_config->profile == VAProfileH264High) {
4305 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4306 attrib_list[i].value.value.i = 0;
4307 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4309 } else if (obj_config->profile == VAProfileNone) {
4310 switch (attrib_list[i].value.value.i) {
4311 case VA_FOURCC('N', 'V', '1', '2'):
4312 case VA_FOURCC('I', '4', '2', '0'):
4313 case VA_FOURCC('Y', 'V', '1', '2'):
4314 case VA_FOURCC('Y', 'U', 'Y', '2'):
4315 case VA_FOURCC('B', 'G', 'R', 'A'):
4316 case VA_FOURCC('B', 'G', 'R', 'X'):
4317 case VA_FOURCC('R', 'G', 'B', 'X'):
4318 case VA_FOURCC('R', 'G', 'B', 'A'):
4321 attrib_list[i].value.value.i = 0;
4322 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4327 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4329 } else if (IS_GEN6(i965->intel.device_id)) {
4330 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4331 obj_config->entrypoint == VAEntrypointVideoProc) {
4332 switch (attrib_list[i].value.value.i) {
4333 case VA_FOURCC('N', 'V', '1', '2'):
4334 case VA_FOURCC('I', '4', '2', '0'):
4335 case VA_FOURCC('Y', 'V', '1', '2'):
4336 case VA_FOURCC('Y', 'U', 'Y', '2'):
4337 case VA_FOURCC('B', 'G', 'R', 'A'):
4338 case VA_FOURCC('B', 'G', 'R', 'X'):
4339 case VA_FOURCC('R', 'G', 'B', 'X'):
4340 case VA_FOURCC('R', 'G', 'B', 'A'):
4343 attrib_list[i].value.value.i = 0;
4344 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4348 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4349 attrib_list[i].value.value.i = 0;
4350 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4353 } else if (IS_GEN7(i965->intel.device_id) ||
4354 IS_GEN8(i965->intel.device_id)) {
4355 if (obj_config->entrypoint == VAEntrypointEncSlice ||
4356 obj_config->entrypoint == VAEntrypointVideoProc) {
4357 switch (attrib_list[i].value.value.i) {
4358 case VA_FOURCC('N', 'V', '1', '2'):
4359 case VA_FOURCC('I', '4', '2', '0'):
4360 case VA_FOURCC('Y', 'V', '1', '2'):
4363 attrib_list[i].value.value.i = 0;
4364 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4368 if (obj_config->profile == VAProfileJPEGBaseline) {
4369 attrib_list[i].value.value.i = 0; /* JPEG decoding always uses an internal format */
4370 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4372 if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
4373 attrib_list[i].value.value.i = 0;
4374 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
4382 case VASurfaceAttribMinWidth:
4383 /* FIXME: add support for it later */
4384 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4386 case VASurfaceAttribMaxWidth:
4387 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4389 case VASurfaceAttribMinHeight:
4390 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4392 case VASurfaceAttribMaxHeight:
4393 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4396 attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
4405 i965_QuerySurfaceAttributes(VADriverContextP ctx,
4407 VASurfaceAttrib *attrib_list,
4408 unsigned int *num_attribs)
4410 VAStatus vaStatus = VA_STATUS_SUCCESS;
4411 struct i965_driver_data *i965 = i965_driver_data(ctx);
4412 struct object_config *obj_config;
4414 VASurfaceAttrib *attribs = NULL;
4416 if (config == VA_INVALID_ID)
4417 return VA_STATUS_ERROR_INVALID_CONFIG;
4419 obj_config = CONFIG(config);
4421 if (obj_config == NULL)
4422 return VA_STATUS_ERROR_INVALID_CONFIG;
4424 if (!attrib_list && !num_attribs)
4425 return VA_STATUS_ERROR_INVALID_PARAMETER;
4427 if (attrib_list == NULL) {
4428 *num_attribs = I965_MAX_SURFACE_ATTRIBUTES;
4429 return VA_STATUS_SUCCESS;
4432 attribs = malloc(I965_MAX_SURFACE_ATTRIBUTES *sizeof(*attribs));
4434 if (attribs == NULL)
4435 return VA_STATUS_ERROR_ALLOCATION_FAILED;
4437 if (IS_G4X(i965->intel.device_id)) {
4438 if (obj_config->profile == VAProfileMPEG2Simple ||
4439 obj_config->profile == VAProfileMPEG2Main) {
4440 attribs[i].type = VASurfaceAttribPixelFormat;
4441 attribs[i].value.type = VAGenericValueTypeInteger;
4442 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4443 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4446 } else if (IS_IRONLAKE(i965->intel.device_id)) {
4447 switch (obj_config->profile) {
4448 case VAProfileMPEG2Simple:
4449 case VAProfileMPEG2Main:
4450 attribs[i].type = VASurfaceAttribPixelFormat;
4451 attribs[i].value.type = VAGenericValueTypeInteger;
4452 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4453 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4458 case VAProfileH264ConstrainedBaseline:
4459 case VAProfileH264Main:
4460 case VAProfileH264High:
4461 attribs[i].type = VASurfaceAttribPixelFormat;
4462 attribs[i].value.type = VAGenericValueTypeInteger;
4463 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4464 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4468 attribs[i].type = VASurfaceAttribPixelFormat;
4469 attribs[i].value.type = VAGenericValueTypeInteger;
4470 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4471 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4474 attribs[i].type = VASurfaceAttribPixelFormat;
4475 attribs[i].value.type = VAGenericValueTypeInteger;
4476 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4477 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4485 } else if (IS_GEN6(i965->intel.device_id)) {
4486 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4487 attribs[i].type = VASurfaceAttribPixelFormat;
4488 attribs[i].value.type = VAGenericValueTypeInteger;
4489 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4490 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4492 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4493 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4494 attribs[i].type = VASurfaceAttribPixelFormat;
4495 attribs[i].value.type = VAGenericValueTypeInteger;
4496 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4497 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4500 attribs[i].type = VASurfaceAttribPixelFormat;
4501 attribs[i].value.type = VAGenericValueTypeInteger;
4502 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4503 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4506 attribs[i].type = VASurfaceAttribPixelFormat;
4507 attribs[i].value.type = VAGenericValueTypeInteger;
4508 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4509 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4512 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4513 attribs[i].type = VASurfaceAttribPixelFormat;
4514 attribs[i].value.type = VAGenericValueTypeInteger;
4515 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4516 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4519 attribs[i].type = VASurfaceAttribPixelFormat;
4520 attribs[i].value.type = VAGenericValueTypeInteger;
4521 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4522 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4525 attribs[i].type = VASurfaceAttribPixelFormat;
4526 attribs[i].value.type = VAGenericValueTypeInteger;
4527 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4528 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4532 } else if (IS_GEN7(i965->intel.device_id)) {
4533 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4534 if (obj_config->profile == VAProfileJPEGBaseline) {
4535 attribs[i].type = VASurfaceAttribPixelFormat;
4536 attribs[i].value.type = VAGenericValueTypeInteger;
4537 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4538 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4541 attribs[i].type = VASurfaceAttribPixelFormat;
4542 attribs[i].value.type = VAGenericValueTypeInteger;
4543 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4544 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '1');
4547 attribs[i].type = VASurfaceAttribPixelFormat;
4548 attribs[i].value.type = VAGenericValueTypeInteger;
4549 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4550 attribs[i].value.value.i = VA_FOURCC('Y', '8', '0', '0');
4553 attribs[i].type = VASurfaceAttribPixelFormat;
4554 attribs[i].value.type = VAGenericValueTypeInteger;
4555 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4556 attribs[i].value.value.i = VA_FOURCC('4', '1', '1', 'P');
4559 attribs[i].type = VASurfaceAttribPixelFormat;
4560 attribs[i].value.type = VAGenericValueTypeInteger;
4561 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4562 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'H');
4565 attribs[i].type = VASurfaceAttribPixelFormat;
4566 attribs[i].value.type = VAGenericValueTypeInteger;
4567 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4568 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'V');
4571 attribs[i].type = VASurfaceAttribPixelFormat;
4572 attribs[i].value.type = VAGenericValueTypeInteger;
4573 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4574 attribs[i].value.value.i = VA_FOURCC('4', '4', '4', 'P');
4577 attribs[i].type = VASurfaceAttribPixelFormat;
4578 attribs[i].value.type = VAGenericValueTypeInteger;
4579 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4580 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4583 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4584 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4585 attribs[i].type = VASurfaceAttribPixelFormat;
4586 attribs[i].value.type = VAGenericValueTypeInteger;
4587 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4588 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4591 attribs[i].type = VASurfaceAttribPixelFormat;
4592 attribs[i].value.type = VAGenericValueTypeInteger;
4593 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4594 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4597 attribs[i].type = VASurfaceAttribPixelFormat;
4598 attribs[i].value.type = VAGenericValueTypeInteger;
4599 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4600 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4603 attribs[i].type = VASurfaceAttribPixelFormat;
4604 attribs[i].value.type = VAGenericValueTypeInteger;
4605 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4606 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4609 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4610 attribs[i].type = VASurfaceAttribPixelFormat;
4611 attribs[i].value.type = VAGenericValueTypeInteger;
4612 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4613 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4616 attribs[i].type = VASurfaceAttribPixelFormat;
4617 attribs[i].value.type = VAGenericValueTypeInteger;
4618 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4619 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4622 attribs[i].type = VASurfaceAttribPixelFormat;
4623 attribs[i].value.type = VAGenericValueTypeInteger;
4624 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4625 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4629 } else if (IS_GEN8(i965->intel.device_id)) {
4630 if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
4631 if (obj_config->profile == VAProfileJPEGBaseline) {
4632 attribs[i].type = VASurfaceAttribPixelFormat;
4633 attribs[i].value.type = VAGenericValueTypeInteger;
4634 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4635 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4638 attribs[i].type = VASurfaceAttribPixelFormat;
4639 attribs[i].value.type = VAGenericValueTypeInteger;
4640 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4641 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '1');
4644 attribs[i].type = VASurfaceAttribPixelFormat;
4645 attribs[i].value.type = VAGenericValueTypeInteger;
4646 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4647 attribs[i].value.value.i = VA_FOURCC('Y', '8', '0', '0');
4650 attribs[i].type = VASurfaceAttribPixelFormat;
4651 attribs[i].value.type = VAGenericValueTypeInteger;
4652 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4653 attribs[i].value.value.i = VA_FOURCC('4', '1', '1', 'P');
4656 attribs[i].type = VASurfaceAttribPixelFormat;
4657 attribs[i].value.type = VAGenericValueTypeInteger;
4658 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4659 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'H');
4662 attribs[i].type = VASurfaceAttribPixelFormat;
4663 attribs[i].value.type = VAGenericValueTypeInteger;
4664 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4665 attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'V');
4668 attribs[i].type = VASurfaceAttribPixelFormat;
4669 attribs[i].value.type = VAGenericValueTypeInteger;
4670 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4671 attribs[i].value.value.i = VA_FOURCC('4', '4', '4', 'P');
4674 attribs[i].type = VASurfaceAttribPixelFormat;
4675 attribs[i].value.type = VAGenericValueTypeInteger;
4676 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4677 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4680 } else if (obj_config->entrypoint == VAEntrypointEncSlice || /* encode */
4681 obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
4683 attribs[i].type = VASurfaceAttribPixelFormat;
4684 attribs[i].value.type = VAGenericValueTypeInteger;
4685 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4686 attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
4689 attribs[i].type = VASurfaceAttribPixelFormat;
4690 attribs[i].value.type = VAGenericValueTypeInteger;
4691 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4692 attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
4695 attribs[i].type = VASurfaceAttribPixelFormat;
4696 attribs[i].value.type = VAGenericValueTypeInteger;
4697 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4698 attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
4701 attribs[i].type = VASurfaceAttribPixelFormat;
4702 attribs[i].value.type = VAGenericValueTypeInteger;
4703 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4704 attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
4707 if (obj_config->entrypoint == VAEntrypointVideoProc) {
4708 attribs[i].type = VASurfaceAttribPixelFormat;
4709 attribs[i].value.type = VAGenericValueTypeInteger;
4710 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4711 attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
4714 attribs[i].type = VASurfaceAttribPixelFormat;
4715 attribs[i].value.type = VAGenericValueTypeInteger;
4716 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4717 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
4720 attribs[i].type = VASurfaceAttribPixelFormat;
4721 attribs[i].value.type = VAGenericValueTypeInteger;
4722 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4723 attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
4726 attribs[i].type = VASurfaceAttribPixelFormat;
4727 attribs[i].value.type = VAGenericValueTypeInteger;
4728 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4729 attribs[i].value.value.i = VA_FOURCC('B', 'G', 'R', 'A');
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('B', 'G', 'R', 'X');
4741 attribs[i].type = VASurfaceAttribMemoryType;
4742 attribs[i].value.type = VAGenericValueTypeInteger;
4743 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
4744 attribs[i].value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA |
4745 VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM |
4746 VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
4749 attribs[i].type = VASurfaceAttribExternalBufferDescriptor;
4750 attribs[i].value.type = VAGenericValueTypePointer;
4751 attribs[i].flags = VA_SURFACE_ATTRIB_SETTABLE;
4752 attribs[i].value.value.p = NULL; /* ignore */
4755 if (i > *num_attribs) {
4758 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4762 memcpy(attrib_list, attribs, i * sizeof(*attribs));
4769 i965_os_has_ring_support(VADriverContextP ctx,
4772 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4776 return i965->intel.has_bsd;
4779 return i965->intel.has_blt;
4781 case I965_RING_VEBOX:
4782 return i965->intel.has_vebox;
4784 case I965_RING_NULL:
4785 return 1; /* Always support */
4788 /* should never get here */
4797 * Query video processing pipeline
4799 VAStatus i965_QueryVideoProcFilters(
4800 VADriverContextP ctx,
4801 VAContextID context,
4802 VAProcFilterType *filters,
4803 unsigned int *num_filters
4806 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4807 unsigned int i = 0, num = 0;
4809 if (!num_filters || !filters)
4810 return VA_STATUS_ERROR_INVALID_PARAMETER;
4812 for (i = 0; i < i965->codec_info->num_filters; i++) {
4813 if (i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring)) {
4814 if (num == *num_filters) {
4815 *num_filters = i965->codec_info->num_filters;
4817 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4820 filters[num++] = i965->codec_info->filters[i].type;
4826 return VA_STATUS_SUCCESS;
4829 VAStatus i965_QueryVideoProcFilterCaps(
4830 VADriverContextP ctx,
4831 VAContextID context,
4832 VAProcFilterType type,
4834 unsigned int *num_filter_caps
4838 struct i965_driver_data *const i965 = i965_driver_data(ctx);
4840 if (!filter_caps || !num_filter_caps)
4841 return VA_STATUS_ERROR_INVALID_PARAMETER;
4843 for (i = 0; i < i965->codec_info->num_filters; i++) {
4844 if (type == i965->codec_info->filters[i].type &&
4845 i965_os_has_ring_support(ctx, i965->codec_info->filters[i].ring))
4849 if (i == i965->codec_info->num_filters)
4850 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4855 case VAProcFilterNoiseReduction:
4856 case VAProcFilterSharpening:
4858 VAProcFilterCap *cap = filter_caps;
4860 if (*num_filter_caps < 1) {
4861 *num_filter_caps = 1;
4862 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4865 cap->range.min_value = 0.0;
4866 cap->range.max_value = 1.0;
4867 cap->range.default_value = 0.5;
4868 cap->range.step = 0.03125; /* 1.0 / 32 */
4874 case VAProcFilterDeinterlacing:
4876 VAProcFilterCapDeinterlacing *cap = filter_caps;
4878 if (*num_filter_caps < VAProcDeinterlacingCount) {
4879 *num_filter_caps = VAProcDeinterlacingCount;
4880 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4883 cap->type = VAProcDeinterlacingBob;
4888 if (i965->codec_info->has_di_motion_adptive) {
4889 cap->type = VAProcDeinterlacingMotionAdaptive;
4894 if (i965->codec_info->has_di_motion_compensated) {
4895 cap->type = VAProcDeinterlacingMotionCompensated;
4903 case VAProcFilterColorBalance:
4905 VAProcFilterCapColorBalance *cap = filter_caps;
4907 if (*num_filter_caps < VAProcColorBalanceCount) {
4908 *num_filter_caps = VAProcColorBalanceCount;
4909 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4912 cap->type = VAProcColorBalanceHue;
4913 cap->range.min_value = -180.0;
4914 cap->range.max_value = 180.0;
4915 cap->range.default_value = 0.0;
4916 cap->range.step = 1.0;
4920 cap->type = VAProcColorBalanceSaturation;
4921 cap->range.min_value = 0.0;
4922 cap->range.max_value = 10.0;
4923 cap->range.default_value = 1.0;
4924 cap->range.step = 0.1;
4928 cap->type = VAProcColorBalanceBrightness;
4929 cap->range.min_value = -100.0;
4930 cap->range.max_value = 100.0;
4931 cap->range.default_value = 0.0;
4932 cap->range.step = 1.0;
4936 cap->type = VAProcColorBalanceContrast;
4937 cap->range.min_value = 0.0;
4938 cap->range.max_value = 10.0;
4939 cap->range.default_value = 1.0;
4940 cap->range.step = 0.1;
4952 *num_filter_caps = i;
4954 return VA_STATUS_SUCCESS;
4957 static VAProcColorStandardType vpp_input_color_standards[VAProcColorStandardCount] = {
4958 VAProcColorStandardBT601,
4961 static VAProcColorStandardType vpp_output_color_standards[VAProcColorStandardCount] = {
4962 VAProcColorStandardBT601,
4965 VAStatus i965_QueryVideoProcPipelineCaps(
4966 VADriverContextP ctx,
4967 VAContextID context,
4968 VABufferID *filters,
4969 unsigned int num_filters,
4970 VAProcPipelineCaps *pipeline_cap /* out */
4973 struct i965_driver_data * const i965 = i965_driver_data(ctx);
4976 pipeline_cap->pipeline_flags = 0;
4977 pipeline_cap->filter_flags = 0;
4978 pipeline_cap->num_forward_references = 0;
4979 pipeline_cap->num_backward_references = 0;
4980 pipeline_cap->num_input_color_standards = 1;
4981 pipeline_cap->input_color_standards = vpp_input_color_standards;
4982 pipeline_cap->num_output_color_standards = 1;
4983 pipeline_cap->output_color_standards = vpp_output_color_standards;
4985 for (i = 0; i < num_filters; i++) {
4986 struct object_buffer *obj_buffer = BUFFER(filters[i]);
4989 !obj_buffer->buffer_store ||
4990 !obj_buffer->buffer_store->buffer)
4991 return VA_STATUS_ERROR_INVALID_BUFFER;
4993 VAProcFilterParameterBufferBase *base = (VAProcFilterParameterBufferBase *)obj_buffer->buffer_store->buffer;
4995 if (base->type == VAProcFilterNoiseReduction) {
4996 VAProcFilterParameterBuffer *denoise = (VAProcFilterParameterBuffer *)base;
4998 } else if (base->type == VAProcFilterDeinterlacing) {
4999 VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
5001 assert(deint->algorithm == VAProcDeinterlacingBob ||
5002 deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5003 deint->algorithm == VAProcDeinterlacingMotionCompensated);
5005 if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
5006 deint->algorithm == VAProcDeinterlacingMotionCompensated);
5007 pipeline_cap->num_forward_references++;
5011 return VA_STATUS_SUCCESS;
5015 i965_driver_data_init(VADriverContextP ctx)
5017 struct i965_driver_data *i965 = i965_driver_data(ctx);
5019 if (IS_GEN8(i965->intel.device_id))
5020 i965->codec_info = &gen8_hw_codec_info;
5021 else if (IS_HASWELL(i965->intel.device_id))
5022 i965->codec_info = &gen75_hw_codec_info;
5023 else if (IS_G4X(i965->intel.device_id))
5024 i965->codec_info = &g4x_hw_codec_info;
5025 else if (IS_IRONLAKE(i965->intel.device_id))
5026 i965->codec_info = &ironlake_hw_codec_info;
5027 else if (IS_GEN6(i965->intel.device_id))
5028 i965->codec_info = &gen6_hw_codec_info;
5029 else if (IS_GEN7(i965->intel.device_id))
5030 i965->codec_info = &gen7_hw_codec_info;
5034 if (object_heap_init(&i965->config_heap,
5035 sizeof(struct object_config),
5037 goto err_config_heap;
5038 if (object_heap_init(&i965->context_heap,
5039 sizeof(struct object_context),
5041 goto err_context_heap;
5043 if (object_heap_init(&i965->surface_heap,
5044 sizeof(struct object_surface),
5046 goto err_surface_heap;
5047 if (object_heap_init(&i965->buffer_heap,
5048 sizeof(struct object_buffer),
5050 goto err_buffer_heap;
5051 if (object_heap_init(&i965->image_heap,
5052 sizeof(struct object_image),
5054 goto err_image_heap;
5055 if (object_heap_init(&i965->subpic_heap,
5056 sizeof(struct object_subpic),
5058 goto err_subpic_heap;
5060 i965->batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5061 i965->pp_batch = intel_batchbuffer_new(&i965->intel, I915_EXEC_RENDER, 0);
5062 _i965InitMutex(&i965->render_mutex);
5063 _i965InitMutex(&i965->pp_mutex);
5068 object_heap_destroy(&i965->image_heap);
5070 object_heap_destroy(&i965->buffer_heap);
5072 object_heap_destroy(&i965->surface_heap);
5074 object_heap_destroy(&i965->context_heap);
5076 object_heap_destroy(&i965->config_heap);
5083 i965_driver_data_terminate(VADriverContextP ctx)
5085 struct i965_driver_data *i965 = i965_driver_data(ctx);
5087 _i965DestroyMutex(&i965->pp_mutex);
5088 _i965DestroyMutex(&i965->render_mutex);
5091 intel_batchbuffer_free(i965->batch);
5094 intel_batchbuffer_free(i965->pp_batch);
5096 i965_destroy_heap(&i965->subpic_heap, i965_destroy_subpic);
5097 i965_destroy_heap(&i965->image_heap, i965_destroy_image);
5098 i965_destroy_heap(&i965->buffer_heap, i965_destroy_buffer);
5099 i965_destroy_heap(&i965->surface_heap, i965_destroy_surface);
5100 i965_destroy_heap(&i965->context_heap, i965_destroy_context);
5101 i965_destroy_heap(&i965->config_heap, i965_destroy_config);
5105 bool (*init)(VADriverContextP ctx);
5106 void (*terminate)(VADriverContextP ctx);
5108 } i965_sub_ops[] = {
5111 intel_driver_terminate,
5116 i965_driver_data_init,
5117 i965_driver_data_terminate,
5122 i965_display_attributes_init,
5123 i965_display_attributes_terminate,
5128 i965_post_processing_init,
5129 i965_post_processing_terminate,
5135 i965_render_terminate,
5139 #ifdef HAVE_VA_WAYLAND
5141 i965_output_wayland_init,
5142 i965_output_wayland_terminate,
5149 i965_output_dri_init,
5150 i965_output_dri_terminate,
5157 i965_Init(VADriverContextP ctx)
5159 struct i965_driver_data *i965 = i965_driver_data(ctx);
5162 for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
5163 if ((i965_sub_ops[i].display_type == 0 ||
5164 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) &&
5165 !i965_sub_ops[i].init(ctx))
5169 if (i == ARRAY_ELEMS(i965_sub_ops)) {
5170 sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d",
5171 INTEL_STR_DRIVER_VENDOR,
5172 INTEL_STR_DRIVER_NAME,
5173 INTEL_DRIVER_MAJOR_VERSION,
5174 INTEL_DRIVER_MINOR_VERSION,
5175 INTEL_DRIVER_MICRO_VERSION);
5177 if (INTEL_DRIVER_PRE_VERSION > 0) {
5178 const int len = strlen(i965->va_vendor);
5179 sprintf(&i965->va_vendor[len], ".pre%d", INTEL_DRIVER_PRE_VERSION);
5182 i965->current_context_id = VA_INVALID_ID;
5184 return VA_STATUS_SUCCESS;
5188 for (; i >= 0; i--) {
5189 if (i965_sub_ops[i].display_type == 0 ||
5190 i965_sub_ops[i].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5191 i965_sub_ops[i].terminate(ctx);
5195 return VA_STATUS_ERROR_UNKNOWN;
5200 i965_Terminate(VADriverContextP ctx)
5202 struct i965_driver_data *i965 = i965_driver_data(ctx);
5206 for (i = ARRAY_ELEMS(i965_sub_ops); i > 0; i--)
5207 if (i965_sub_ops[i - 1].display_type == 0 ||
5208 i965_sub_ops[i - 1].display_type == (ctx->display_type & VA_DISPLAY_MAJOR_MASK)) {
5209 i965_sub_ops[i - 1].terminate(ctx);
5213 ctx->pDriverData = NULL;
5216 return VA_STATUS_SUCCESS;
5220 VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
5223 VA_DRIVER_INIT_FUNC( VADriverContextP ctx )
5225 struct VADriverVTable * const vtable = ctx->vtable;
5226 struct VADriverVTableVPP * const vtable_vpp = ctx->vtable_vpp;
5228 struct i965_driver_data *i965;
5229 VAStatus ret = VA_STATUS_ERROR_UNKNOWN;
5231 ctx->version_major = VA_MAJOR_VERSION;
5232 ctx->version_minor = VA_MINOR_VERSION;
5233 ctx->max_profiles = I965_MAX_PROFILES;
5234 ctx->max_entrypoints = I965_MAX_ENTRYPOINTS;
5235 ctx->max_attributes = I965_MAX_CONFIG_ATTRIBUTES;
5236 ctx->max_image_formats = I965_MAX_IMAGE_FORMATS;
5237 ctx->max_subpic_formats = I965_MAX_SUBPIC_FORMATS;
5238 ctx->max_display_attributes = 1 + ARRAY_ELEMS(i965_display_attributes);
5240 vtable->vaTerminate = i965_Terminate;
5241 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5242 vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
5243 vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
5244 vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
5245 vtable->vaCreateConfig = i965_CreateConfig;
5246 vtable->vaDestroyConfig = i965_DestroyConfig;
5247 vtable->vaGetConfigAttributes = i965_GetConfigAttributes;
5248 vtable->vaCreateSurfaces = i965_CreateSurfaces;
5249 vtable->vaDestroySurfaces = i965_DestroySurfaces;
5250 vtable->vaCreateContext = i965_CreateContext;
5251 vtable->vaDestroyContext = i965_DestroyContext;
5252 vtable->vaCreateBuffer = i965_CreateBuffer;
5253 vtable->vaBufferSetNumElements = i965_BufferSetNumElements;
5254 vtable->vaMapBuffer = i965_MapBuffer;
5255 vtable->vaUnmapBuffer = i965_UnmapBuffer;
5256 vtable->vaDestroyBuffer = i965_DestroyBuffer;
5257 vtable->vaBeginPicture = i965_BeginPicture;
5258 vtable->vaRenderPicture = i965_RenderPicture;
5259 vtable->vaEndPicture = i965_EndPicture;
5260 vtable->vaSyncSurface = i965_SyncSurface;
5261 vtable->vaQuerySurfaceStatus = i965_QuerySurfaceStatus;
5262 vtable->vaPutSurface = i965_PutSurface;
5263 vtable->vaQueryImageFormats = i965_QueryImageFormats;
5264 vtable->vaCreateImage = i965_CreateImage;
5265 vtable->vaDeriveImage = i965_DeriveImage;
5266 vtable->vaDestroyImage = i965_DestroyImage;
5267 vtable->vaSetImagePalette = i965_SetImagePalette;
5268 vtable->vaGetImage = i965_GetImage;
5269 vtable->vaPutImage = i965_PutImage;
5270 vtable->vaQuerySubpictureFormats = i965_QuerySubpictureFormats;
5271 vtable->vaCreateSubpicture = i965_CreateSubpicture;
5272 vtable->vaDestroySubpicture = i965_DestroySubpicture;
5273 vtable->vaSetSubpictureImage = i965_SetSubpictureImage;
5274 vtable->vaSetSubpictureChromakey = i965_SetSubpictureChromakey;
5275 vtable->vaSetSubpictureGlobalAlpha = i965_SetSubpictureGlobalAlpha;
5276 vtable->vaAssociateSubpicture = i965_AssociateSubpicture;
5277 vtable->vaDeassociateSubpicture = i965_DeassociateSubpicture;
5278 vtable->vaQueryDisplayAttributes = i965_QueryDisplayAttributes;
5279 vtable->vaGetDisplayAttributes = i965_GetDisplayAttributes;
5280 vtable->vaSetDisplayAttributes = i965_SetDisplayAttributes;
5281 vtable->vaBufferInfo = i965_BufferInfo;
5282 vtable->vaLockSurface = i965_LockSurface;
5283 vtable->vaUnlockSurface = i965_UnlockSurface;
5284 vtable->vaGetSurfaceAttributes = i965_GetSurfaceAttributes;
5285 vtable->vaQuerySurfaceAttributes = i965_QuerySurfaceAttributes;
5286 vtable->vaCreateSurfaces2 = i965_CreateSurfaces2;
5288 vtable_vpp->vaQueryVideoProcFilters = i965_QueryVideoProcFilters;
5289 vtable_vpp->vaQueryVideoProcFilterCaps = i965_QueryVideoProcFilterCaps;
5290 vtable_vpp->vaQueryVideoProcPipelineCaps = i965_QueryVideoProcPipelineCaps;
5292 i965 = (struct i965_driver_data *)calloc(1, sizeof(*i965));
5295 ctx->pDriverData = NULL;
5297 return VA_STATUS_ERROR_ALLOCATION_FAILED;
5300 ctx->pDriverData = (void *)i965;
5301 ret = i965_Init(ctx);
5303 if (ret == VA_STATUS_SUCCESS) {
5304 ctx->str_vendor = i965->va_vendor;
5307 ctx->pDriverData = NULL;