Merge branch 'gallium-nopointsizeminmax'
[mesa.git] / src / gallium / include / pipe / p_screen.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 *
31 * Screen, Adapter or GPU
32 *
33 * These are driver functions/facilities that are context independent.
34 */
35
36
37 #ifndef P_SCREEN_H
38 #define P_SCREEN_H
39
40
41 #include "pipe/p_compiler.h"
42 #include "pipe/p_format.h"
43 #include "pipe/p_defines.h"
44
45
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51
52 /** Opaque type */
53 struct pipe_fence_handle;
54 struct pipe_winsys;
55 struct pipe_buffer;
56 struct pipe_texture;
57 struct pipe_surface;
58 struct pipe_video_surface;
59 struct pipe_transfer;
60
61
62 /**
63 * Gallium screen/adapter context. Basically everything
64 * hardware-specific that doesn't actually require a rendering
65 * context.
66 */
67 struct pipe_screen {
68 struct pipe_winsys *winsys;
69
70 void (*destroy)( struct pipe_screen * );
71
72
73 const char *(*get_name)( struct pipe_screen * );
74
75 const char *(*get_vendor)( struct pipe_screen * );
76
77 /**
78 * Query an integer-valued capability/parameter/limit
79 * \param param one of PIPE_CAP_x
80 */
81 int (*get_param)( struct pipe_screen *, int param );
82
83 /**
84 * Query a float-valued capability/parameter/limit
85 * \param param one of PIPE_CAP_x
86 */
87 float (*get_paramf)( struct pipe_screen *, int param );
88
89 struct pipe_context * (*context_create)( struct pipe_screen *,
90 void *priv );
91
92 /**
93 * Check if the given pipe_format is supported as a texture or
94 * drawing surface.
95 * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_*
96 * \param geom_flags bitmask of PIPE_TEXTURE_GEOM_*
97 */
98 boolean (*is_format_supported)( struct pipe_screen *,
99 enum pipe_format format,
100 enum pipe_texture_target target,
101 unsigned tex_usage,
102 unsigned geom_flags );
103
104 /**
105 * Create a new texture object, using the given template info.
106 */
107 struct pipe_texture * (*texture_create)(struct pipe_screen *,
108 const struct pipe_texture *templat);
109
110 /**
111 * Create a new texture object, using the given template info, but on top of
112 * existing memory.
113 *
114 * It is assumed that the buffer data is layed out according to the expected
115 * by the hardware. NULL will be returned if any inconsistency is found.
116 */
117 struct pipe_texture * (*texture_blanket)(struct pipe_screen *,
118 const struct pipe_texture *templat,
119 const unsigned *stride,
120 struct pipe_buffer *buffer);
121
122 void (*texture_destroy)(struct pipe_texture *pt);
123
124 /** Get a surface which is a "view" into a texture */
125 struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
126 struct pipe_texture *texture,
127 unsigned face, unsigned level,
128 unsigned zslice,
129 unsigned usage );
130
131 void (*tex_surface_destroy)(struct pipe_surface *);
132
133
134 /** Get a transfer object for transferring data to/from a texture */
135 struct pipe_transfer *(*get_tex_transfer)(struct pipe_screen *,
136 struct pipe_texture *texture,
137 unsigned face, unsigned level,
138 unsigned zslice,
139 enum pipe_transfer_usage usage,
140 unsigned x, unsigned y,
141 unsigned w, unsigned h);
142
143 void (*tex_transfer_destroy)(struct pipe_transfer *);
144
145 void *(*transfer_map)( struct pipe_screen *,
146 struct pipe_transfer *transfer );
147
148 void (*transfer_unmap)( struct pipe_screen *,
149 struct pipe_transfer *transfer );
150
151
152 /**
153 * Create a new buffer.
154 * \param alignment buffer start address alignment in bytes
155 * \param usage bitmask of PIPE_BUFFER_USAGE_x
156 * \param size size in bytes
157 */
158 struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen,
159 unsigned alignment,
160 unsigned usage,
161 unsigned size );
162
163 /**
164 * Create a buffer that wraps user-space data.
165 *
166 * Effectively this schedules a delayed call to buffer_create
167 * followed by an upload of the data at *some point in the future*,
168 * or perhaps never. Basically the allocate/upload is delayed
169 * until the buffer is actually passed to hardware.
170 *
171 * The intention is to provide a quick way to turn regular data
172 * into a buffer, and secondly to avoid a copy operation if that
173 * data subsequently turns out to be only accessed by the CPU.
174 *
175 * Common example is OpenGL vertex buffers that are subsequently
176 * processed either by software TNL in the driver or by passing to
177 * hardware.
178 *
179 * XXX: What happens if the delayed call to buffer_create() fails?
180 *
181 * Note that ptr may be accessed at any time upto the time when the
182 * buffer is destroyed, so the data must not be freed before then.
183 */
184 struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen,
185 void *ptr,
186 unsigned bytes);
187
188 /**
189 * Allocate storage for a display target surface.
190 *
191 * Often surfaces which are meant to be blitted to the front screen (i.e.,
192 * display targets) must be allocated with special characteristics, memory
193 * pools, or obtained directly from the windowing system.
194 *
195 * This callback is invoked by the pipe_screenwhen creating a texture marked
196 * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
197 * buffer storage.
198 */
199 struct pipe_buffer *(*surface_buffer_create)(struct pipe_screen *screen,
200 unsigned width, unsigned height,
201 enum pipe_format format,
202 unsigned usage,
203 unsigned tex_usage,
204 unsigned *stride);
205
206
207 /**
208 * Map the entire data store of a buffer object into the client's address.
209 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
210 */
211 void *(*buffer_map)( struct pipe_screen *screen,
212 struct pipe_buffer *buf,
213 unsigned usage );
214 /**
215 * Map a subrange of the buffer data store into the client's address space.
216 *
217 * The returned pointer is always relative to buffer start, regardless of
218 * the specified range. This is different from the ARB_map_buffer_range
219 * semantics because we don't forbid multiple mappings of the same buffer
220 * (yet).
221 */
222 void *(*buffer_map_range)( struct pipe_screen *screen,
223 struct pipe_buffer *buf,
224 unsigned offset,
225 unsigned length,
226 unsigned usage);
227
228 /**
229 * Notify a range that was actually written into.
230 *
231 * Can only be used if the buffer was mapped with the
232 * PIPE_BUFFER_USAGE_CPU_WRITE and PIPE_BUFFER_USAGE_FLUSH_EXPLICIT flags
233 * set.
234 *
235 * The range is relative to the buffer start, regardless of the range
236 * specified to buffer_map_range. This is different from the
237 * ARB_map_buffer_range semantics because we don't forbid multiple mappings
238 * of the same buffer (yet).
239 *
240 */
241 void (*buffer_flush_mapped_range)( struct pipe_screen *screen,
242 struct pipe_buffer *buf,
243 unsigned offset,
244 unsigned length);
245
246 /**
247 * Unmap buffer.
248 *
249 * If the buffer was mapped with PIPE_BUFFER_USAGE_CPU_WRITE flag but not
250 * PIPE_BUFFER_USAGE_FLUSH_EXPLICIT then the pipe driver will
251 * assume that the whole buffer was written. This is mostly for backward
252 * compatibility purposes and may affect performance -- the state tracker
253 * should always specify exactly what got written while the buffer was
254 * mapped.
255 */
256 void (*buffer_unmap)( struct pipe_screen *screen,
257 struct pipe_buffer *buf );
258
259 void (*buffer_destroy)( struct pipe_buffer *buf );
260
261 /**
262 * Create a video surface suitable for use as a decoding target by the
263 * driver's pipe_video_context.
264 */
265 struct pipe_video_surface*
266 (*video_surface_create)( struct pipe_screen *screen,
267 enum pipe_video_chroma_format chroma_format,
268 unsigned width, unsigned height );
269
270 void (*video_surface_destroy)( struct pipe_video_surface *vsfc );
271
272 /**
273 * Do any special operations to ensure buffer size is correct
274 */
275 void (*update_buffer)( struct pipe_screen *ws,
276 void *context_private );
277
278 /**
279 * Do any special operations to ensure frontbuffer contents are
280 * displayed, eg copy fake frontbuffer.
281 */
282 void (*flush_frontbuffer)( struct pipe_screen *screen,
283 struct pipe_surface *surf,
284 void *context_private );
285
286
287
288 /** Set ptr = fence, with reference counting */
289 void (*fence_reference)( struct pipe_screen *screen,
290 struct pipe_fence_handle **ptr,
291 struct pipe_fence_handle *fence );
292
293 /**
294 * Checks whether the fence has been signalled.
295 * \param flags driver-specific meaning
296 * \return zero on success.
297 */
298 int (*fence_signalled)( struct pipe_screen *screen,
299 struct pipe_fence_handle *fence,
300 unsigned flags );
301
302 /**
303 * Wait for the fence to finish.
304 * \param flags driver-specific meaning
305 * \return zero on success.
306 */
307 int (*fence_finish)( struct pipe_screen *screen,
308 struct pipe_fence_handle *fence,
309 unsigned flags );
310
311 };
312
313
314 #ifdef __cplusplus
315 }
316 #endif
317
318 #endif /* P_SCREEN_H */