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