Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[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
57
58
59 /**
60 * Gallium screen/adapter context. Basically everything
61 * hardware-specific that doesn't actually require a rendering
62 * context.
63 */
64 struct pipe_screen {
65 struct pipe_winsys *winsys;
66
67 void (*destroy)( struct pipe_screen * );
68
69
70 const char *(*get_name)( struct pipe_screen * );
71
72 const char *(*get_vendor)( struct pipe_screen * );
73
74 /**
75 * Query an integer-valued capability/parameter/limit
76 * \param param one of PIPE_CAP_x
77 */
78 int (*get_param)( struct pipe_screen *, int param );
79
80 /**
81 * Query a float-valued capability/parameter/limit
82 * \param param one of PIPE_CAP_x
83 */
84 float (*get_paramf)( struct pipe_screen *, int param );
85
86 /**
87 * Check if the given pipe_format is supported as a texture or
88 * drawing surface.
89 * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_*
90 * \param geom_flags bitmask of PIPE_TEXTURE_GEOM_*
91 */
92 boolean (*is_format_supported)( struct pipe_screen *,
93 enum pipe_format format,
94 enum pipe_texture_target target,
95 unsigned tex_usage,
96 unsigned geom_flags );
97
98 /**
99 * Create a new texture object, using the given template info.
100 */
101 struct pipe_texture * (*texture_create)(struct pipe_screen *,
102 const struct pipe_texture *templat);
103
104 /**
105 * Create a new texture object, using the given template info, but on top of
106 * existing memory.
107 *
108 * It is assumed that the buffer data is layed out according to the expected
109 * by the hardware. NULL will be returned if any inconsistency is found.
110 */
111 struct pipe_texture * (*texture_blanket)(struct pipe_screen *,
112 const struct pipe_texture *templat,
113 const unsigned *stride,
114 struct pipe_buffer *buffer);
115
116 void (*texture_destroy)(struct pipe_texture *pt);
117
118 /** Get a surface which is a "view" into a texture */
119 struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
120 struct pipe_texture *texture,
121 unsigned face, unsigned level,
122 unsigned zslice,
123 unsigned usage );
124
125 void (*tex_surface_destroy)(struct pipe_surface *);
126
127
128 /** Get a transfer object for transferring data to/from a texture */
129 struct pipe_transfer *(*get_tex_transfer)(struct pipe_screen *,
130 struct pipe_texture *texture,
131 unsigned face, unsigned level,
132 unsigned zslice,
133 enum pipe_transfer_usage usage,
134 unsigned x, unsigned y,
135 unsigned w, unsigned h);
136
137 void (*tex_transfer_destroy)(struct pipe_transfer *);
138
139 void *(*transfer_map)( struct pipe_screen *,
140 struct pipe_transfer *transfer );
141
142 void (*transfer_unmap)( struct pipe_screen *,
143 struct pipe_transfer *transfer );
144
145
146 /**
147 * Create a new buffer.
148 * \param alignment buffer start address alignment in bytes
149 * \param usage bitmask of PIPE_BUFFER_USAGE_x
150 * \param size size in bytes
151 */
152 struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen,
153 unsigned alignment,
154 unsigned usage,
155 unsigned size );
156
157 /**
158 * Create a buffer that wraps user-space data.
159 *
160 * Effectively this schedules a delayed call to buffer_create
161 * followed by an upload of the data at *some point in the future*,
162 * or perhaps never. Basically the allocate/upload is delayed
163 * until the buffer is actually passed to hardware.
164 *
165 * The intention is to provide a quick way to turn regular data
166 * into a buffer, and secondly to avoid a copy operation if that
167 * data subsequently turns out to be only accessed by the CPU.
168 *
169 * Common example is OpenGL vertex buffers that are subsequently
170 * processed either by software TNL in the driver or by passing to
171 * hardware.
172 *
173 * XXX: What happens if the delayed call to buffer_create() fails?
174 *
175 * Note that ptr may be accessed at any time upto the time when the
176 * buffer is destroyed, so the data must not be freed before then.
177 */
178 struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen,
179 void *ptr,
180 unsigned bytes);
181
182 /**
183 * Allocate storage for a display target surface.
184 *
185 * Often surfaces which are meant to be blitted to the front screen (i.e.,
186 * display targets) must be allocated with special characteristics, memory
187 * pools, or obtained directly from the windowing system.
188 *
189 * This callback is invoked by the pipe_screenwhen creating a texture marked
190 * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
191 * buffer storage.
192 */
193 struct pipe_buffer *(*surface_buffer_create)(struct pipe_screen *screen,
194 unsigned width, unsigned height,
195 enum pipe_format format,
196 unsigned usage,
197 unsigned tex_usage,
198 unsigned *stride);
199
200
201 /**
202 * Map the entire data store of a buffer object into the client's address.
203 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
204 */
205 void *(*buffer_map)( struct pipe_screen *screen,
206 struct pipe_buffer *buf,
207 unsigned usage );
208 /**
209 * Map a subrange of the buffer data store into the client's address space.
210 *
211 * The returned pointer is always relative to buffer start, regardless of
212 * the specified range. This is different from the ARB_map_buffer_range
213 * semantics because we don't forbid multiple mappings of the same buffer
214 * (yet).
215 */
216 void *(*buffer_map_range)( struct pipe_screen *screen,
217 struct pipe_buffer *buf,
218 unsigned offset,
219 unsigned length,
220 unsigned usage);
221
222 /**
223 * Notify a range that was actually written into.
224 *
225 * Can only be used if the buffer was mapped with the
226 * PIPE_BUFFER_USAGE_CPU_WRITE and PIPE_BUFFER_USAGE_FLUSH_EXPLICIT flags
227 * set.
228 *
229 * The range is relative to the buffer start, regardless of the range
230 * specified to buffer_map_range. This is different from the
231 * ARB_map_buffer_range semantics because we don't forbid multiple mappings
232 * of the same buffer (yet).
233 *
234 */
235 void (*buffer_flush_mapped_range)( struct pipe_screen *screen,
236 struct pipe_buffer *buf,
237 unsigned offset,
238 unsigned length);
239
240 /**
241 * Unmap buffer.
242 *
243 * If the buffer was mapped with PIPE_BUFFER_USAGE_CPU_WRITE flag but not
244 * PIPE_BUFFER_USAGE_FLUSH_EXPLICIT then the pipe driver will
245 * assume that the whole buffer was written. This is mostly for backward
246 * compatibility purposes and may affect performance -- the state tracker
247 * should always specify exactly what got written while the buffer was
248 * mapped.
249 */
250 void (*buffer_unmap)( struct pipe_screen *screen,
251 struct pipe_buffer *buf );
252
253 void (*buffer_destroy)( struct pipe_buffer *buf );
254
255
256 /**
257 * Do any special operations to ensure frontbuffer contents are
258 * displayed, eg copy fake frontbuffer.
259 */
260 void (*flush_frontbuffer)( struct pipe_screen *screen,
261 struct pipe_surface *surf,
262 void *context_private );
263
264
265
266 /** Set ptr = fence, with reference counting */
267 void (*fence_reference)( struct pipe_screen *screen,
268 struct pipe_fence_handle **ptr,
269 struct pipe_fence_handle *fence );
270
271 /**
272 * Checks whether the fence has been signalled.
273 * \param flags driver-specific meaning
274 * \return zero on success.
275 */
276 int (*fence_signalled)( struct pipe_screen *screen,
277 struct pipe_fence_handle *fence,
278 unsigned flags );
279
280 /**
281 * Wait for the fence to finish.
282 * \param flags driver-specific meaning
283 * \return zero on success.
284 */
285 int (*fence_finish)( struct pipe_screen *screen,
286 struct pipe_fence_handle *fence,
287 unsigned flags );
288
289 };
290
291
292 #ifdef __cplusplus
293 }
294 #endif
295
296 #endif /* P_SCREEN_H */