nv50: clear buffer status on all vertex bufs, not just the first one
[mesa.git] / src / gallium / state_trackers / va / va_private.h
1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4 * Copyright 2014 Advanced Micro Devices, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #ifndef VA_PRIVATE_H
30 #define VA_PRIVATE_H
31
32 #include <assert.h>
33
34 #include <va/va.h>
35 #include <va/va_backend.h>
36
37 #include "pipe/p_video_enums.h"
38 #include "pipe/p_video_codec.h"
39 #include "pipe/p_video_state.h"
40
41 #include "vl/vl_compositor.h"
42 #include "vl/vl_csc.h"
43
44 #include "util/u_dynarray.h"
45
46 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
47 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
48
49 #define VL_VA_MAX_IMAGE_FORMATS 6
50
51 static inline enum pipe_video_chroma_format
52 ChromaToPipe(int format)
53 {
54 switch (format) {
55 case VA_RT_FORMAT_YUV420:
56 return PIPE_VIDEO_CHROMA_FORMAT_420;
57 case VA_RT_FORMAT_YUV422:
58 return PIPE_VIDEO_CHROMA_FORMAT_422;
59 case VA_RT_FORMAT_YUV444:
60 return PIPE_VIDEO_CHROMA_FORMAT_444;
61 default:
62 assert(0);
63 return PIPE_VIDEO_CHROMA_FORMAT_420;
64 }
65 }
66
67 static inline enum pipe_format
68 YCbCrToPipe(unsigned format)
69 {
70 switch(format) {
71 case VA_FOURCC('N','V','1','2'):
72 return PIPE_FORMAT_NV12;
73 case VA_FOURCC('I','4','2','0'):
74 return PIPE_FORMAT_IYUV;
75 case VA_FOURCC('Y','V','1','2'):
76 return PIPE_FORMAT_YV12;
77 case VA_FOURCC('Y','U','Y','V'):
78 return PIPE_FORMAT_YUYV;
79 case VA_FOURCC('U','Y','V','Y'):
80 return PIPE_FORMAT_UYVY;
81 case VA_FOURCC('B','G','R','A'):
82 return PIPE_FORMAT_B8G8R8A8_UNORM;
83 default:
84 assert(0);
85 return PIPE_FORMAT_NONE;
86 }
87 }
88
89 static inline VAProfile
90 PipeToProfile(enum pipe_video_profile profile)
91 {
92 switch (profile) {
93 case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
94 return VAProfileMPEG2Simple;
95 case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
96 return VAProfileMPEG2Main;
97 case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
98 return VAProfileMPEG4Simple;
99 case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
100 return VAProfileMPEG4AdvancedSimple;
101 case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
102 return VAProfileVC1Simple;
103 case PIPE_VIDEO_PROFILE_VC1_MAIN:
104 return VAProfileVC1Main;
105 case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
106 return VAProfileVC1Advanced;
107 case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
108 return VAProfileH264Baseline;
109 case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
110 return VAProfileH264Main;
111 case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
112 return VAProfileH264High;
113 case PIPE_VIDEO_PROFILE_MPEG4_AVC_EXTENDED:
114 return VAProfileNone;
115 default:
116 assert(0);
117 return -1;
118 }
119 }
120
121 static inline enum pipe_video_profile
122 ProfileToPipe(VAProfile profile)
123 {
124 switch (profile) {
125 case VAProfileMPEG2Simple:
126 return PIPE_VIDEO_PROFILE_MPEG2_SIMPLE;
127 case VAProfileMPEG2Main:
128 return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
129 case VAProfileMPEG4Simple:
130 return PIPE_VIDEO_PROFILE_MPEG4_SIMPLE;
131 case VAProfileMPEG4AdvancedSimple:
132 return PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE;
133 case VAProfileVC1Simple:
134 return PIPE_VIDEO_PROFILE_VC1_SIMPLE;
135 case VAProfileVC1Main:
136 return PIPE_VIDEO_PROFILE_VC1_MAIN;
137 case VAProfileVC1Advanced:
138 return PIPE_VIDEO_PROFILE_VC1_ADVANCED;
139 case VAProfileH264Baseline:
140 return PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE;
141 case VAProfileH264Main:
142 return PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN;
143 case VAProfileH264High:
144 return PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH;
145 default:
146 return PIPE_VIDEO_PROFILE_UNKNOWN;
147 }
148 }
149
150 typedef struct {
151 struct vl_screen *vscreen;
152 struct pipe_context *pipe;
153 struct handle_table *htab;
154 struct vl_compositor compositor;
155 struct vl_compositor_state cstate;
156 vl_csc_matrix csc;
157 } vlVaDriver;
158
159 typedef struct {
160 VAImage *image;
161
162 struct u_rect src_rect;
163 struct u_rect dst_rect;
164
165 struct pipe_sampler_view *sampler;
166 } vlVaSubpicture;
167
168 typedef struct {
169 struct pipe_video_codec *decoder;
170 struct pipe_video_buffer *target;
171 union {
172 struct pipe_picture_desc base;
173 struct pipe_mpeg12_picture_desc mpeg12;
174 struct pipe_mpeg4_picture_desc mpeg4;
175 struct pipe_vc1_picture_desc vc1;
176 struct pipe_h264_picture_desc h264;
177 } desc;
178
179 struct {
180 unsigned long long int frame_num;
181 unsigned int start_code_size;
182 unsigned int vti_bits;
183 unsigned int quant_scale;
184 VAPictureParameterBufferMPEG4 pps;
185 uint8_t start_code[32];
186 } mpeg4;
187 } vlVaContext;
188
189 typedef struct {
190 VABufferType type;
191 unsigned int size;
192 unsigned int num_elements;
193 void *data;
194 } vlVaBuffer;
195
196 typedef struct {
197 struct pipe_video_buffer templat, *buffer;
198 struct pipe_fence_handle *fence;
199 struct util_dynarray subpics; /* vlVaSubpicture */
200 } vlVaSurface;
201
202 // Public functions:
203 VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP ctx);
204
205 // vtable functions:
206 VAStatus vlVaTerminate(VADriverContextP ctx);
207 VAStatus vlVaQueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list,int *num_profiles);
208 VAStatus vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,
209 VAEntrypoint *entrypoint_list, int *num_entrypoints);
210 VAStatus vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
211 VAConfigAttrib *attrib_list, int num_attribs);
212 VAStatus vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
213 VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id);
214 VAStatus vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id);
215 VAStatus vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,
216 VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs);
217 VAStatus vlVaCreateSurfaces(VADriverContextP ctx, int width, int height, int format,
218 int num_surfaces, VASurfaceID *surfaces);
219 VAStatus vlVaDestroySurfaces(VADriverContextP ctx, VASurfaceID *surface_list, int num_surfaces);
220 VAStatus vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width, int picture_height,
221 int flag, VASurfaceID *render_targets, int num_render_targets, VAContextID *context);
222 VAStatus vlVaDestroyContext(VADriverContextP ctx, VAContextID context);
223 VAStatus vlVaCreateBuffer(VADriverContextP ctx, VAContextID context, VABufferType type, unsigned int size,
224 unsigned int num_elements, void *data, VABufferID *buf_id);
225 VAStatus vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id, unsigned int num_elements);
226 VAStatus vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuf);
227 VAStatus vlVaUnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
228 VAStatus vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buffer_id);
229 VAStatus vlVaBeginPicture(VADriverContextP ctx, VAContextID context, VASurfaceID render_target);
230 VAStatus vlVaRenderPicture(VADriverContextP ctx, VAContextID context, VABufferID *buffers, int num_buffers);
231 VAStatus vlVaEndPicture(VADriverContextP ctx, VAContextID context);
232 VAStatus vlVaSyncSurface(VADriverContextP ctx, VASurfaceID render_target);
233 VAStatus vlVaQuerySurfaceStatus(VADriverContextP ctx, VASurfaceID render_target, VASurfaceStatus *status);
234 VAStatus vlVaQuerySurfaceError(VADriverContextP ctx, VASurfaceID render_target,
235 VAStatus error_status, void **error_info);
236 VAStatus vlVaPutSurface(VADriverContextP ctx, VASurfaceID surface, void* draw, short srcx, short srcy,
237 unsigned short srcw, unsigned short srch, short destx, short desty, unsigned short destw,
238 unsigned short desth, VARectangle *cliprects, unsigned int number_cliprects,
239 unsigned int flags);
240 VAStatus vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num_formats);
241 VAStatus vlVaQuerySubpictureFormats(VADriverContextP ctx, VAImageFormat *format_list,
242 unsigned int *flags, unsigned int *num_formats);
243 VAStatus vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int height, VAImage *image);
244 VAStatus vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image);
245 VAStatus vlVaDestroyImage(VADriverContextP ctx, VAImageID image);
246 VAStatus vlVaSetImagePalette(VADriverContextP ctx, VAImageID image, unsigned char *palette);
247 VAStatus vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y,
248 unsigned int width, unsigned int height, VAImageID image);
249 VAStatus vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image, int src_x, int src_y,
250 unsigned int src_width, unsigned int src_height, int dest_x, int dest_y,
251 unsigned int dest_width, unsigned int dest_height);
252 VAStatus vlVaQuerySubpictureFormats(VADriverContextP ctx, VAImageFormat *format_list,
253 unsigned int *flags, unsigned int *num_formats);
254 VAStatus vlVaCreateSubpicture(VADriverContextP ctx, VAImageID image, VASubpictureID *subpicture);
255 VAStatus vlVaDestroySubpicture(VADriverContextP ctx, VASubpictureID subpicture);
256 VAStatus vlVaSubpictureImage(VADriverContextP ctx, VASubpictureID subpicture, VAImageID image);
257 VAStatus vlVaSetSubpictureChromakey(VADriverContextP ctx, VASubpictureID subpicture,
258 unsigned int chromakey_min, unsigned int chromakey_max,
259 unsigned int chromakey_mask);
260 VAStatus vlVaSetSubpictureGlobalAlpha(VADriverContextP ctx, VASubpictureID subpicture, float global_alpha);
261 VAStatus vlVaAssociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture, VASurfaceID *target_surfaces,
262 int num_surfaces, short src_x, short src_y,
263 unsigned short src_width, unsigned short src_height,
264 short dest_x, short dest_y, unsigned short dest_width, unsigned short dest_height,
265 unsigned int flags);
266 VAStatus vlVaDeassociateSubpicture(VADriverContextP ctx, VASubpictureID subpicture,
267 VASurfaceID *target_surfaces, int num_surfaces);
268 VAStatus vlVaQueryDisplayAttributes(VADriverContextP ctx, VADisplayAttribute *attr_list, int *num_attributes);
269 VAStatus vlVaGetDisplayAttributes(VADriverContextP ctx, VADisplayAttribute *attr_list, int num_attributes);
270 VAStatus vlVaSetDisplayAttributes(VADriverContextP ctx, VADisplayAttribute *attr_list, int num_attributes);
271 VAStatus vlVaBufferInfo(VADriverContextP ctx, VABufferID buf_id, VABufferType *type,
272 unsigned int *size, unsigned int *num_elements);
273 VAStatus vlVaLockSurface(VADriverContextP ctx, VASurfaceID surface, unsigned int *fourcc,
274 unsigned int *luma_stride, unsigned int *chroma_u_stride, unsigned int *chroma_v_stride,
275 unsigned int *luma_offset, unsigned int *chroma_u_offset, unsigned int *chroma_v_offset,
276 unsigned int *buffer_name, void **buffer);
277 VAStatus vlVaUnlockSurface(VADriverContextP ctx, VASurfaceID surface);
278
279 #endif //VA_PRIVATE_H