Merge branch 'gallium-no-rhw-position'
[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 2D surface which is a "view" into a texture
125 * \param usage bitmaks of PIPE_BUFFER_USAGE_* read/write flags
126 */
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 void (*tex_surface_destroy)(struct pipe_surface *);
134
135
136 /** Get a transfer object for transferring data to/from a texture */
137 struct pipe_transfer *(*get_tex_transfer)(struct pipe_screen *,
138 struct pipe_texture *texture,
139 unsigned face, unsigned level,
140 unsigned zslice,
141 enum pipe_transfer_usage usage,
142 unsigned x, unsigned y,
143 unsigned w, unsigned h);
144
145 void (*tex_transfer_destroy)(struct pipe_transfer *);
146
147 void *(*transfer_map)( struct pipe_screen *,
148 struct pipe_transfer *transfer );
149
150 void (*transfer_unmap)( struct pipe_screen *,
151 struct pipe_transfer *transfer );
152
153
154 /**
155 * Create a new buffer.
156 * \param alignment buffer start address alignment in bytes
157 * \param usage bitmask of PIPE_BUFFER_USAGE_x
158 * \param size size in bytes
159 */
160 struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen,
161 unsigned alignment,
162 unsigned usage,
163 unsigned size );
164
165 /**
166 * Create a buffer that wraps user-space data.
167 *
168 * Effectively this schedules a delayed call to buffer_create
169 * followed by an upload of the data at *some point in the future*,
170 * or perhaps never. Basically the allocate/upload is delayed
171 * until the buffer is actually passed to hardware.
172 *
173 * The intention is to provide a quick way to turn regular data
174 * into a buffer, and secondly to avoid a copy operation if that
175 * data subsequently turns out to be only accessed by the CPU.
176 *
177 * Common example is OpenGL vertex buffers that are subsequently
178 * processed either by software TNL in the driver or by passing to
179 * hardware.
180 *
181 * XXX: What happens if the delayed call to buffer_create() fails?
182 *
183 * Note that ptr may be accessed at any time upto the time when the
184 * buffer is destroyed, so the data must not be freed before then.
185 */
186 struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen,
187 void *ptr,
188 unsigned bytes);
189
190 /**
191 * Allocate storage for a display target surface.
192 *
193 * Often surfaces which are meant to be blitted to the front screen (i.e.,
194 * display targets) must be allocated with special characteristics, memory
195 * pools, or obtained directly from the windowing system.
196 *
197 * This callback is invoked by the pipe_screenwhen creating a texture marked
198 * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
199 * buffer storage.
200 */
201 struct pipe_buffer *(*surface_buffer_create)(struct pipe_screen *screen,
202 unsigned width, unsigned height,
203 enum pipe_format format,
204 unsigned usage,
205 unsigned tex_usage,
206 unsigned *stride);
207
208
209 /**
210 * Map the entire data store of a buffer object into the client's address.
211 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
212 */
213 void *(*buffer_map)( struct pipe_screen *screen,
214 struct pipe_buffer *buf,
215 unsigned usage );
216 /**
217 * Map a subrange of the buffer data store into the client's address space.
218 *
219 * The returned pointer is always relative to buffer start, regardless of
220 * the specified range. This is different from the ARB_map_buffer_range
221 * semantics because we don't forbid multiple mappings of the same buffer
222 * (yet).
223 */
224 void *(*buffer_map_range)( struct pipe_screen *screen,
225 struct pipe_buffer *buf,
226 unsigned offset,
227 unsigned length,
228 unsigned usage);
229
230 /**
231 * Notify a range that was actually written into.
232 *
233 * Can only be used if the buffer was mapped with the
234 * PIPE_BUFFER_USAGE_CPU_WRITE and PIPE_BUFFER_USAGE_FLUSH_EXPLICIT flags
235 * set.
236 *
237 * The range is relative to the buffer start, regardless of the range
238 * specified to buffer_map_range. This is different from the
239 * ARB_map_buffer_range semantics because we don't forbid multiple mappings
240 * of the same buffer (yet).
241 *
242 */
243 void (*buffer_flush_mapped_range)( struct pipe_screen *screen,
244 struct pipe_buffer *buf,
245 unsigned offset,
246 unsigned length);
247
248 /**
249 * Unmap buffer.
250 *
251 * If the buffer was mapped with PIPE_BUFFER_USAGE_CPU_WRITE flag but not
252 * PIPE_BUFFER_USAGE_FLUSH_EXPLICIT then the pipe driver will
253 * assume that the whole buffer was written. This is mostly for backward
254 * compatibility purposes and may affect performance -- the state tracker
255 * should always specify exactly what got written while the buffer was
256 * mapped.
257 */
258 void (*buffer_unmap)( struct pipe_screen *screen,
259 struct pipe_buffer *buf );
260
261 void (*buffer_destroy)( struct pipe_buffer *buf );
262
263 /**
264 * Create a video surface suitable for use as a decoding target by the
265 * driver's pipe_video_context.
266 */
267 struct pipe_video_surface*
268 (*video_surface_create)( struct pipe_screen *screen,
269 enum pipe_video_chroma_format chroma_format,
270 unsigned width, unsigned height );
271
272 void (*video_surface_destroy)( struct pipe_video_surface *vsfc );
273
274 /**
275 * Do any special operations to ensure buffer size is correct
276 */
277 void (*update_buffer)( struct pipe_screen *ws,
278 void *context_private );
279
280 /**
281 * Do any special operations to ensure frontbuffer contents are
282 * displayed, eg copy fake frontbuffer.
283 */
284 void (*flush_frontbuffer)( struct pipe_screen *screen,
285 struct pipe_surface *surf,
286 void *context_private );
287
288
289
290 /** Set ptr = fence, with reference counting */
291 void (*fence_reference)( struct pipe_screen *screen,
292 struct pipe_fence_handle **ptr,
293 struct pipe_fence_handle *fence );
294
295 /**
296 * Checks whether the fence has been signalled.
297 * \param flags driver-specific meaning
298 * \return zero on success.
299 */
300 int (*fence_signalled)( struct pipe_screen *screen,
301 struct pipe_fence_handle *fence,
302 unsigned flags );
303
304 /**
305 * Wait for the fence to finish.
306 * \param flags driver-specific meaning
307 * \return zero on success.
308 */
309 int (*fence_finish)( struct pipe_screen *screen,
310 struct pipe_fence_handle *fence,
311 unsigned flags );
312
313 };
314
315
316 #ifdef __cplusplus
317 }
318 #endif
319
320 #endif /* P_SCREEN_H */