Merge branch '7.8'
[mesa.git] / src / gallium / drivers / svga / svga_winsys.h
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 /**
27 * @file
28 * VMware SVGA specific winsys interface.
29 *
30 * @author Jose Fonseca <jfonseca@vmware.com>
31 *
32 * Documentation taken from the VMware SVGA DDK.
33 */
34
35 #ifndef SVGA_WINSYS_H_
36 #define SVGA_WINSYS_H_
37
38
39 #include "svga_types.h"
40 #include "svga_reg.h"
41 #include "svga3d_reg.h"
42
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_defines.h"
45
46
47 struct svga_winsys_screen;
48 struct svga_winsys_buffer;
49 struct pipe_screen;
50 struct pipe_context;
51 struct pipe_fence_handle;
52 struct pipe_texture;
53 struct svga_region;
54 struct winsys_handle;
55
56
57 #define SVGA_BUFFER_USAGE_PINNED (PIPE_BUFFER_USAGE_CUSTOM << 0)
58 #define SVGA_BUFFER_USAGE_WRAPPED (PIPE_BUFFER_USAGE_CUSTOM << 1)
59
60
61 /** Opaque surface handle */
62 struct svga_winsys_surface;
63
64 /** Opaque buffer handle */
65 struct svga_winsys_handle;
66
67
68 /**
69 * SVGA per-context winsys interface.
70 */
71 struct svga_winsys_context
72 {
73 void
74 (*destroy)(struct svga_winsys_context *swc);
75
76 void *
77 (*reserve)(struct svga_winsys_context *swc,
78 uint32_t nr_bytes, uint32_t nr_relocs );
79
80 /**
81 * Emit a relocation for a host surface.
82 *
83 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
84 *
85 * NOTE: Order of this call does matter. It should be the same order
86 * as relocations appear in the command buffer.
87 */
88 void
89 (*surface_relocation)(struct svga_winsys_context *swc,
90 uint32 *sid,
91 struct svga_winsys_surface *surface,
92 unsigned flags);
93
94 /**
95 * Emit a relocation for a guest memory region.
96 *
97 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
98 *
99 * NOTE: Order of this call does matter. It should be the same order
100 * as relocations appear in the command buffer.
101 */
102 void
103 (*region_relocation)(struct svga_winsys_context *swc,
104 struct SVGAGuestPtr *ptr,
105 struct svga_winsys_buffer *buffer,
106 uint32 offset,
107 unsigned flags);
108
109 void
110 (*commit)(struct svga_winsys_context *swc);
111
112 enum pipe_error
113 (*flush)(struct svga_winsys_context *swc,
114 struct pipe_fence_handle **pfence);
115
116 /**
117 * Context ID used to fill in the commands
118 *
119 * Context IDs are arbitrary small non-negative integers,
120 * global to the entire SVGA device.
121 */
122 uint32 cid;
123 };
124
125
126 /**
127 * SVGA per-screen winsys interface.
128 */
129 struct svga_winsys_screen
130 {
131 void
132 (*destroy)(struct svga_winsys_screen *sws);
133
134 boolean
135 (*get_cap)(struct svga_winsys_screen *sws,
136 SVGA3dDevCapIndex index,
137 SVGA3dDevCapResult *result);
138
139 /**
140 * Create a new context.
141 *
142 * Context objects encapsulate all render state, and shader
143 * objects are per-context.
144 *
145 * Surfaces are not per-context. The same surface can be shared
146 * between multiple contexts, and surface operations can occur
147 * without a context.
148 */
149 struct svga_winsys_context *
150 (*context_create)(struct svga_winsys_screen *sws);
151
152
153 /**
154 * This creates a "surface" object in the SVGA3D device,
155 * and returns the surface ID (sid). Surfaces are generic
156 * containers for host VRAM objects like textures, vertex
157 * buffers, and depth/stencil buffers.
158 *
159 * Surfaces are hierarchial:
160 *
161 * - Surface may have multiple faces (for cube maps)
162 *
163 * - Each face has a list of mipmap levels
164 *
165 * - Each mipmap image may have multiple volume
166 * slices, if the image is three dimensional.
167 *
168 * - Each slice is a 2D array of 'blocks'
169 *
170 * - Each block may be one or more pixels.
171 * (Usually 1, more for DXT or YUV formats.)
172 *
173 * Surfaces are generic host VRAM objects. The SVGA3D device
174 * may optimize surfaces according to the format they were
175 * created with, but this format does not limit the ways in
176 * which the surface may be used. For example, a depth surface
177 * can be used as a texture, or a floating point image may
178 * be used as a vertex buffer. Some surface usages may be
179 * lower performance, due to software emulation, but any
180 * usage should work with any surface.
181 */
182 struct svga_winsys_surface *
183 (*surface_create)(struct svga_winsys_screen *sws,
184 SVGA3dSurfaceFlags flags,
185 SVGA3dSurfaceFormat format,
186 SVGA3dSize size,
187 uint32 numFaces,
188 uint32 numMipLevels);
189
190 /**
191 * Creates a surface from a winsys handle.
192 * Used to implement pipe_screen::texture_from_handle.
193 */
194 struct svga_winsys_surface *
195 (*surface_from_handle)(struct svga_winsys_screen *sws,
196 struct winsys_handle *whandle,
197 SVGA3dSurfaceFormat *format);
198
199 /**
200 * Get a winsys_handle from a surface.
201 * Used to implement pipe_screen::texture_get_handle.
202 */
203 boolean
204 (*surface_get_handle)(struct svga_winsys_screen *sws,
205 struct svga_winsys_surface *surface,
206 unsigned stride,
207 struct winsys_handle *whandle);
208
209 /**
210 * Whether this surface is sitting in a validate list
211 */
212 boolean
213 (*surface_is_flushed)(struct svga_winsys_screen *sws,
214 struct svga_winsys_surface *surface);
215
216 /**
217 * Reference a SVGA3D surface object. This allows sharing of a
218 * surface between different objects.
219 */
220 void
221 (*surface_reference)(struct svga_winsys_screen *sws,
222 struct svga_winsys_surface **pdst,
223 struct svga_winsys_surface *src);
224
225 /**
226 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
227 *
228 * Remember that gallium gets to choose the interface it needs, and the
229 * window systems must then implement that interface (rather than the
230 * other way around...).
231 *
232 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
233 * usage argument is only an optimization hint, not a guarantee, therefore
234 * proper behavior must be observed in all circumstances.
235 *
236 * alignment indicates the client's alignment requirements, eg for
237 * SSE instructions.
238 */
239 struct svga_winsys_buffer *
240 (*buffer_create)( struct svga_winsys_screen *sws,
241 unsigned alignment,
242 unsigned usage,
243 unsigned size );
244
245 /**
246 * Map the entire data store of a buffer object into the client's address.
247 * flags is a bitmask of:
248 * - PIPE_BUFFER_USAGE_CPU_READ/WRITE
249 * - PIPE_BUFFER_USAGE_DONTBLOCK
250 * - PIPE_BUFFER_USAGE_UNSYNCHRONIZED
251 */
252 void *
253 (*buffer_map)( struct svga_winsys_screen *sws,
254 struct svga_winsys_buffer *buf,
255 unsigned usage );
256
257 void
258 (*buffer_unmap)( struct svga_winsys_screen *sws,
259 struct svga_winsys_buffer *buf );
260
261 void
262 (*buffer_destroy)( struct svga_winsys_screen *sws,
263 struct svga_winsys_buffer *buf );
264
265
266 /**
267 * Reference a fence object.
268 */
269 void
270 (*fence_reference)( struct svga_winsys_screen *sws,
271 struct pipe_fence_handle **pdst,
272 struct pipe_fence_handle *src );
273
274 /**
275 * Checks whether the fence has been signalled.
276 * \param flags driver-specific meaning
277 * \return zero on success.
278 */
279 int (*fence_signalled)( struct svga_winsys_screen *sws,
280 struct pipe_fence_handle *fence,
281 unsigned flag );
282
283 /**
284 * Wait for the fence to finish.
285 * \param flags driver-specific meaning
286 * \return zero on success.
287 */
288 int (*fence_finish)( struct svga_winsys_screen *sws,
289 struct pipe_fence_handle *fence,
290 unsigned flag );
291
292 };
293
294
295 struct pipe_screen *
296 svga_screen_create(struct svga_winsys_screen *sws);
297
298 struct svga_winsys_screen *
299 svga_winsys_screen(struct pipe_screen *screen);
300
301 struct pipe_buffer *
302 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
303 enum SVGA3dSurfaceFormat format,
304 struct svga_winsys_surface *srf);
305
306 struct svga_winsys_surface *
307 svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer);
308
309 #endif /* SVGA_WINSYS_H_ */