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>
30 #ifndef _I965_DRV_VIDEO_H_
31 #define _I965_DRV_VIDEO_H_
34 #include <va/va_enc_h264.h>
35 #include <va/va_enc_mpeg2.h>
36 #include <va/va_enc_hevc.h>
37 #include <va/va_enc_jpeg.h>
38 #include <va/va_enc_vp8.h>
39 #include <va/va_vpp.h>
40 #include <va/va_backend.h>
41 #include <va/va_backend_vpp.h>
42 #include <va/va_fei.h>
43 #include <va/va_fei_h264.h>
45 #include "va_backend_compat.h"
47 #include "i965_mutext.h"
48 #include "object_heap.h"
49 #include "intel_driver.h"
50 #include "i965_fourcc.h"
52 #define I965_MAX_PROFILES 20
53 #define I965_MAX_ENTRYPOINTS 7
54 #define I965_MAX_CONFIG_ATTRIBUTES 32
55 #define I965_MAX_IMAGE_FORMATS 10
56 #define I965_MAX_SUBPIC_FORMATS 6
57 #define I965_MAX_SUBPIC_SUM 4
58 #define I965_MAX_SURFACE_ATTRIBUTES 32
60 #define INTEL_STR_DRIVER_VENDOR "Intel"
61 #define INTEL_STR_DRIVER_NAME "i965"
63 #define I965_SURFACE_TYPE_IMAGE 0
64 #define I965_SURFACE_TYPE_SURFACE 1
66 #define I965_SURFACE_FLAG_FRAME 0x00000000
67 #define I965_SURFACE_FLAG_TOP_FIELD_FIRST 0x00000001
68 #define I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST 0x00000002
70 #define DEFAULT_BRIGHTNESS 0
71 #define DEFAULT_CONTRAST 50
73 #define DEFAULT_SATURATION 50
75 #define ENCODER_QUALITY_RANGE 2
76 #define ENCODER_QUALITY_RANGE_AVC 7
77 #define ENCODER_QUALITY_RANGE_HEVC 7
78 #define ENCODER_QUALITY_RANGE_VP9 7
79 #define ENCODER_DEFAULT_QUALITY 1
80 #define ENCODER_DEFAULT_QUALITY_AVC 4
81 #define ENCODER_DEFAULT_QUALITY_HEVC 4
82 #define ENCODER_DEFAULT_QUALITY_VP9 4
83 #define ENCODER_HIGH_QUALITY ENCODER_DEFAULT_QUALITY
84 #define ENCODER_LOW_QUALITY 2
86 #define I965_MIN_CODEC_ENC_RESOLUTION_WIDTH_HEIGHT 32
87 #define I965_MAX_NUM_ROI_REGIONS 8
88 #define I965_MAX_NUM_SLICE 32
90 #define ENCODER_LP_QUALITY_RANGE 8
92 #define STATS_MAX_NUM_PAST_REFS 1
93 #define STATS_MAX_NUM_FUTURE_REFS 1
94 #define STATS_MAX_NUM_OUTPUTS 2
95 #define STATS_INTERLACED_SUPPORT 0
97 #define HAS_MPEG2_DECODING(ctx) ((ctx)->codec_info->has_mpeg2_decoding && \
100 #define HAS_MPEG2_ENCODING(ctx) ((ctx)->codec_info->has_mpeg2_encoding && \
101 (ctx)->intel.has_bsd)
103 #define HAS_H264_DECODING(ctx) ((ctx)->codec_info->has_h264_decoding && \
104 (ctx)->intel.has_bsd)
106 #define HAS_H264_ENCODING(ctx) ((ctx)->codec_info->has_h264_encoding && \
107 (ctx)->intel.has_bsd)
109 #define HAS_LP_H264_ENCODING(ctx) ((ctx)->codec_info->has_lp_h264_encoding && \
110 (ctx)->intel.has_bsd)
112 #define HAS_FEI_H264_ENCODING(ctx) ((ctx)->codec_info->has_fei_h264_encoding && \
113 (ctx)->intel.has_bsd)
115 #define HAS_H264_PREENC(ctx) ((ctx)->codec_info->has_h264_preenc)
117 #define HAS_VC1_DECODING(ctx) ((ctx)->codec_info->has_vc1_decoding && \
118 (ctx)->intel.has_bsd)
120 #define HAS_JPEG_DECODING(ctx) ((ctx)->codec_info->has_jpeg_decoding && \
121 (ctx)->intel.has_bsd)
123 #define HAS_JPEG_ENCODING(ctx) ((ctx)->codec_info->has_jpeg_encoding && \
124 (ctx)->intel.has_bsd)
126 #define HAS_VPP(ctx) ((ctx)->codec_info->has_vpp)
128 #define HAS_ACCELERATED_GETIMAGE(ctx) ((ctx)->codec_info->has_accelerated_getimage)
130 #define HAS_ACCELERATED_PUTIMAGE(ctx) ((ctx)->codec_info->has_accelerated_putimage)
132 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
134 #define HAS_VP8_DECODING(ctx) ((ctx)->codec_info->has_vp8_decoding && \
135 (ctx)->intel.has_bsd)
137 #define HAS_VP8_ENCODING(ctx) ((ctx)->codec_info->has_vp8_encoding && \
138 (ctx)->intel.has_bsd)
140 #define HAS_H264_MVC_DECODING(ctx) \
141 (HAS_H264_DECODING(ctx) && (ctx)->codec_info->h264_mvc_dec_profiles)
143 #define HAS_H264_MVC_DECODING_PROFILE(ctx, profile) \
144 (HAS_H264_MVC_DECODING(ctx) && \
145 ((ctx)->codec_info->h264_mvc_dec_profiles & (1U << profile)))
147 #define HAS_H264_MVC_ENCODING(ctx) ((ctx)->codec_info->has_h264_mvc_encoding && \
148 (ctx)->intel.has_bsd)
150 #define HAS_HEVC_DECODING(ctx) ((ctx)->codec_info->has_hevc_decoding && \
151 (ctx)->intel.has_bsd)
153 #define HAS_HEVC_ENCODING(ctx) ((ctx)->codec_info->has_hevc_encoding && \
154 (ctx)->intel.has_bsd)
156 #define HAS_VP9_DECODING(ctx) ((ctx)->codec_info->has_vp9_decoding && \
157 (ctx)->intel.has_bsd)
159 #define HAS_VP9_DECODING_PROFILE(ctx, profile) \
160 (HAS_VP9_DECODING(ctx) && \
161 ((ctx)->codec_info->vp9_dec_profiles & (1U << (profile - VAProfileVP9Profile0))))
163 #define HAS_HEVC10_DECODING(ctx) ((ctx)->codec_info->has_hevc10_decoding && \
164 (ctx)->intel.has_bsd)
165 #define HAS_HEVC10_ENCODING(ctx) ((ctx)->codec_info->has_hevc10_encoding && \
166 (ctx)->intel.has_bsd)
168 #define HAS_VPP_P010(ctx) ((ctx)->codec_info->has_vpp_p010 && \
169 (ctx)->intel.has_bsd)
171 #define HAS_VP9_ENCODING(ctx) ((ctx)->codec_info->has_vp9_encoding && \
172 (ctx)->intel.has_bsd)
174 #define HAS_LP_VP9_ENCODING(ctx) ((ctx)->codec_info->has_lp_vp9_encoding && \
175 (ctx)->intel.has_huc)
177 #define HAS_VP9_ENCODING_PROFILE(ctx, profile) \
178 (HAS_VP9_ENCODING(ctx) && \
179 ((ctx)->codec_info->vp9_enc_profiles & (1U << (profile - VAProfileVP9Profile0))))
181 struct i965_surface {
182 struct object_base *base;
190 const uint32_t (*bin)[4];
193 unsigned int kernel_offset;
196 struct buffer_store {
197 unsigned char *buffer;
203 struct object_config {
204 struct object_base base;
206 VAEntrypoint entrypoint;
207 VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
210 VAGenericID wrapper_config;
213 #define NUM_SLICES 10
215 struct codec_state_base {
216 uint32_t chroma_formats;
219 struct decode_state {
220 struct codec_state_base base;
221 struct buffer_store *pic_param;
222 struct buffer_store **slice_params;
223 struct buffer_store *iq_matrix;
224 struct buffer_store *bit_plane;
225 struct buffer_store *huffman_table;
226 struct buffer_store **slice_datas;
227 struct buffer_store *probability_data;
228 VASurfaceID current_render_target;
229 int max_slice_params;
231 int num_slice_params;
234 struct object_surface *render_object;
235 struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
238 #define SLICE_PACKED_DATA_INDEX_TYPE 0x80000000
239 #define SLICE_PACKED_DATA_INDEX_MASK 0x00FFFFFF
241 struct encode_state {
242 struct codec_state_base base;
243 struct buffer_store *iq_matrix;
244 struct buffer_store *q_matrix;
245 struct buffer_store *huffman_table;
248 struct buffer_store *seq_param_ext;
249 struct buffer_store *pic_param_ext;
250 struct buffer_store *packed_header_param[5];
251 struct buffer_store *packed_header_data[5];
252 struct buffer_store **slice_params_ext;
253 struct buffer_store *encmb_map;
254 int max_slice_params_ext;
255 int num_slice_params_ext;
257 /* Check the user-configurable packed_header attribute.
258 * Currently it is mainly used to check whether the packed slice_header data
259 * is provided by user or the driver.
260 * TBD: It will check for the packed SPS/PPS/MISC/RAWDATA and so on.
262 unsigned int packed_header_flag;
263 /* For the packed data that needs to be inserted into video clip */
264 /* currently it is mainly to track packed raw data and packed slice_header data. */
265 struct buffer_store **packed_header_params_ext;
266 int max_packed_header_params_ext;
267 int num_packed_header_params_ext;
268 struct buffer_store **packed_header_data_ext;
269 int max_packed_header_data_ext;
270 int num_packed_header_data_ext;
272 /* the index of current vps and sps ,special for HEVC*/
273 int vps_sps_seq_index;
274 /* the index of current slice */
276 /* the array is determined by max_slice_params_ext */
278 /* This is to store the first index of packed data for one slice */
279 int *slice_rawdata_index;
280 /* This is to store the number of packed data for one slice.
281 * Both packed rawdata and slice_header data are tracked by this
282 * variable. That is to say: When one packed slice_header is parsed,
283 * this variable will also be increased.
285 int *slice_rawdata_count;
287 /* This is to store the index of packed slice header for one slice */
288 int *slice_header_index;
290 int last_packed_header_type;
294 struct buffer_store *misc_param[19][8];
296 /* To store the VAStatsStatisticsParameterBufferType buffers */
297 struct buffer_store *stat_param_ext;
299 VASurfaceID current_render_target;
300 struct object_surface *input_yuv_object;
301 struct object_surface *reconstructed_object;
302 struct object_buffer *coded_buf_object;
303 struct object_surface *reference_objects[16]; /* Up to 2 reference surfaces are valid for MPEG-2,*/
307 struct codec_state_base base;
308 struct buffer_store *pipeline_param;
310 VASurfaceID current_render_target;
316 #define CODEC_PREENC 3
319 struct codec_state_base base;
320 struct decode_state decode;
321 struct encode_state encode;
322 struct proc_state proc;
326 VAStatus(*run)(VADriverContextP ctx,
328 union codec_state *codec_state,
329 struct hw_context *hw_context);
330 void (*destroy)(void *);
331 VAStatus(*get_status)(VADriverContextP ctx,
332 struct hw_context *hw_context,
334 struct intel_batchbuffer *batch;
337 struct object_context {
338 struct object_base base;
339 VAContextID context_id;
340 struct object_config *obj_config;
341 VASurfaceID *render_targets; //input->encode, output->decode
342 int num_render_targets;
347 union codec_state codec_state;
348 struct hw_context *hw_context;
350 VAGenericID wrapper_context;
353 #define SURFACE_REFERENCED (1 << 0)
354 #define SURFACE_DERIVED (1 << 2)
355 #define SURFACE_ALL_MASK ((SURFACE_REFERENCED) | \
358 struct object_surface {
359 struct object_base base;
360 VASurfaceStatus status;
361 VASubpictureID subpic[I965_MAX_SUBPIC_SUM];
362 struct object_subpic *obj_subpic[I965_MAX_SUBPIC_SUM];
363 unsigned int subpic_render_idx;
365 int width; /* the pitch of plane 0 in bytes in horizontal direction */
366 int height; /* the pitch of plane 0 in bytes in vertical direction */
368 int orig_width; /* the width of plane 0 in pixels */
369 int orig_height; /* the height of plane 0 in pixels */
373 unsigned int expected_format;
374 VAImageID locked_image_id;
375 VAImageID derived_image_id;
376 void (*free_private_data)(void **data);
378 unsigned int subsampling;
386 /* user specified attributes see: VASurfaceAttribExternalBuffers/VA_SURFACE_ATTRIB_MEM_TYPE_VA */
387 uint32_t user_disable_tiling : 1;
388 uint32_t user_h_stride_set : 1;
389 uint32_t user_v_stride_set : 1;
390 /* we need clear right and bottom border for NV12.
391 * to avoid encode run to run issue*/
392 uint32_t border_cleared : 1;
394 VAGenericID wrapper_surface;
396 int exported_primefd;
399 struct object_buffer {
400 struct object_base base;
401 struct buffer_store *buffer_store;
402 int max_num_elements;
408 unsigned int export_refcount;
409 VABufferInfo export_state;
411 VAGenericID wrapper_buffer;
412 VAContextID context_id;
415 struct object_image {
416 struct object_base base;
419 unsigned int *palette;
420 VASurfaceID derived_surface;
423 struct object_subpic {
424 struct object_base base;
426 struct object_image *obj_image;
427 VARectangle src_rect;
428 VARectangle dst_rect;
438 #define I965_RING_NULL 0
439 #define I965_RING_BSD 1
440 #define I965_RING_BLT 2
441 #define I965_RING_VEBOX 3
444 VAProcFilterType type;
448 struct i965_driver_data;
450 struct hw_codec_info {
451 struct hw_context *(*dec_hw_context_init)(VADriverContextP, struct object_config *);
452 struct hw_context *(*enc_hw_context_init)(VADriverContextP, struct object_config *);
453 struct hw_context *(*proc_hw_context_init)(VADriverContextP, struct object_config *);
454 bool (*render_init)(VADriverContextP);
455 void (*post_processing_context_init)(VADriverContextP, void *, struct intel_batchbuffer *);
456 void (*preinit_hw_codec)(VADriverContextP, struct hw_codec_info *);
459 * Allows HW info to support per-codec max resolution. If this functor is
460 * not initialized, then @max_width and @max_height will be used as the
461 * default maximum resolution for all codecs on this HW info.
463 void (*max_resolution)(struct i965_driver_data *, struct object_config *, int *, int *);
467 int min_linear_wpitch;
468 int min_linear_hpitch;
470 unsigned int h264_mvc_dec_profiles;
471 unsigned int vp9_dec_profiles;
472 unsigned int vp9_enc_profiles;
474 unsigned int h264_dec_chroma_formats;
475 unsigned int jpeg_dec_chroma_formats;
476 unsigned int jpeg_enc_chroma_formats;
477 unsigned int hevc_dec_chroma_formats;
478 unsigned int vp9_dec_chroma_formats;
480 unsigned int has_mpeg2_decoding: 1;
481 unsigned int has_mpeg2_encoding: 1;
482 unsigned int has_h264_decoding: 1;
483 unsigned int has_h264_encoding: 1;
484 unsigned int has_vc1_decoding: 1;
485 unsigned int has_vc1_encoding: 1;
486 unsigned int has_jpeg_decoding: 1;
487 unsigned int has_jpeg_encoding: 1;
488 unsigned int has_vpp: 1;
489 unsigned int has_accelerated_getimage: 1;
490 unsigned int has_accelerated_putimage: 1;
491 unsigned int has_tiled_surface: 1;
492 unsigned int has_di_motion_adptive: 1;
493 unsigned int has_di_motion_compensated: 1;
494 unsigned int has_vp8_decoding: 1;
495 unsigned int has_vp8_encoding: 1;
496 unsigned int has_h264_mvc_encoding: 1;
497 unsigned int has_hevc_decoding: 1;
498 unsigned int has_hevc_encoding: 1;
499 unsigned int has_hevc10_encoding: 1;
500 unsigned int has_hevc10_decoding: 1;
501 unsigned int has_vp9_decoding: 1;
502 unsigned int has_vpp_p010: 1;
503 unsigned int has_lp_h264_encoding: 1;
504 unsigned int has_vp9_encoding: 1;
505 unsigned int has_fei_h264_encoding: 1;
506 unsigned int has_h264_preenc: 1;
507 unsigned int has_lp_vp9_encoding: 1;
509 unsigned int lp_h264_brc_mode;
510 unsigned int lp_vp9_brc_mode;
512 unsigned int h264_brc_mode;
513 unsigned int vp9_brc_mode;
515 unsigned int num_filters;
516 struct i965_filter filters[VAProcFilterCount];
520 #include "i965_render.h"
521 #include "i965_gpe_utils.h"
523 struct i965_driver_data {
524 struct intel_driver_data intel;
525 struct object_heap config_heap;
526 struct object_heap context_heap;
527 struct object_heap surface_heap;
528 struct object_heap buffer_heap;
529 struct object_heap image_heap;
530 struct object_heap subpic_heap;
531 struct hw_codec_info *codec_info;
533 _I965Mutex render_mutex;
535 struct intel_batchbuffer *batch;
536 struct intel_batchbuffer *pp_batch;
537 struct i965_render_state render_state;
541 VADisplayAttribute *display_attributes;
542 unsigned int num_display_attributes;
543 VADisplayAttribute *rotation_attrib;
544 VADisplayAttribute *brightness_attrib;
545 VADisplayAttribute *contrast_attrib;
546 VADisplayAttribute *hue_attrib;
547 VADisplayAttribute *saturation_attrib;
548 VAContextID current_context_id;
550 /* VA/DRI (X11) specific data */
551 struct va_dri_output *dri_output;
553 /* VA/Wayland specific data */
554 struct va_wl_output *wl_output;
556 VADriverContextP wrapper_pdrvctx;
558 struct i965_gpe_table gpe_table;
561 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
562 #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
563 #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
564 #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
565 #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
566 #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
568 #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
569 #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
570 #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
571 #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
572 #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
573 #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
575 #define FOURCC_IA44 0x34344149
576 #define FOURCC_AI44 0x34344941
578 #define STRIDE(w) (((w) + 0xf) & ~0xf)
579 #define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
581 static INLINE struct i965_driver_data *
582 i965_driver_data(VADriverContextP ctx)
584 return (struct i965_driver_data *)(ctx->pDriverData);
588 i965_check_alloc_surface_bo(VADriverContextP ctx,
589 struct object_surface *obj_surface,
592 unsigned int subsampling);
595 va_enc_packed_type_to_idx(int packed_type);
597 /* reserve 2 byte for internal using */
599 #define CODEC_MPEG2 1
600 #define CODEC_H264_MVC 2
606 #define H264_DELIMITER0 0x00
607 #define H264_DELIMITER1 0x00
608 #define H264_DELIMITER2 0x00
609 #define H264_DELIMITER3 0x00
610 #define H264_DELIMITER4 0x00
612 #define MPEG2_DELIMITER0 0x00
613 #define MPEG2_DELIMITER1 0x00
614 #define MPEG2_DELIMITER2 0x00
615 #define MPEG2_DELIMITER3 0x00
616 #define MPEG2_DELIMITER4 0xb0
618 #define HEVC_DELIMITER0 0x00
619 #define HEVC_DELIMITER1 0x00
620 #define HEVC_DELIMITER2 0x00
621 #define HEVC_DELIMITER3 0x00
622 #define HEVC_DELIMITER4 0x00
624 struct i965_coded_buffer_segment {
626 VACodedBufferSegment base;
627 unsigned char pad0[64]; /* change the size if sizeof(VACodedBufferSegment) > 64 */
632 unsigned int status_support;
635 unsigned int codec_private_data[512]; /* Store codec private data, must be 16-bytes aligned */
638 #define I965_CODEDBUFFER_HEADER_SIZE ALIGN(sizeof(struct i965_coded_buffer_segment), 0x1000)
640 extern VAStatus i965_MapBuffer(VADriverContextP ctx,
641 VABufferID buf_id, /* in */
642 void **pbuf); /* out */
644 extern VAStatus i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
646 extern VAStatus i965_DestroySurfaces(VADriverContextP ctx,
647 VASurfaceID *surface_list,
650 extern VAStatus i965_CreateSurfaces(VADriverContextP ctx,
655 VASurfaceID *surfaces);
657 #define I965_SURFACE_MEM_NATIVE 0
658 #define I965_SURFACE_MEM_GEM_FLINK 1
659 #define I965_SURFACE_MEM_DRM_PRIME 2
662 i965_destroy_surface_storage(struct object_surface *obj_surface);
664 // Logging functions for errors (to be shown to users) and info (useful for developers).
665 void i965_log_error(VADriverContextP ctx, const char *format, ...);
666 void i965_log_info(VADriverContextP ctx, const char *format, ...);
668 #endif /* _I965_DRV_VIDEO_H_ */