winsys/svga: Update to vmwgfx kernel module 2.1
[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_resource;
53 struct svga_region;
54 struct winsys_handle;
55
56
57 #define SVGA_BUFFER_USAGE_PINNED (1 << 0)
58 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
59
60
61 #define SVGA_RELOC_WRITE 0x1
62 #define SVGA_RELOC_READ 0x2
63
64 #define SVGA_FENCE_FLAG_EXEC (1 << 0)
65 #define SVGA_FENCE_FLAG_QUERY (1 << 1)
66
67 /** Opaque surface handle */
68 struct svga_winsys_surface;
69
70 /** Opaque buffer handle */
71 struct svga_winsys_handle;
72
73
74 /**
75 * SVGA per-context winsys interface.
76 */
77 struct svga_winsys_context
78 {
79 void
80 (*destroy)(struct svga_winsys_context *swc);
81
82 void *
83 (*reserve)(struct svga_winsys_context *swc,
84 uint32_t nr_bytes, uint32_t nr_relocs );
85
86 /**
87 * Emit a relocation for a host surface.
88 *
89 * @param flags bitmask of SVGA_RELOC_* flags
90 *
91 * NOTE: Order of this call does matter. It should be the same order
92 * as relocations appear in the command buffer.
93 */
94 void
95 (*surface_relocation)(struct svga_winsys_context *swc,
96 uint32 *sid,
97 struct svga_winsys_surface *surface,
98 unsigned flags);
99
100 /**
101 * Emit a relocation for a guest memory region.
102 *
103 * @param flags bitmask of SVGA_RELOC_* flags
104 *
105 * NOTE: Order of this call does matter. It should be the same order
106 * as relocations appear in the command buffer.
107 */
108 void
109 (*region_relocation)(struct svga_winsys_context *swc,
110 struct SVGAGuestPtr *ptr,
111 struct svga_winsys_buffer *buffer,
112 uint32 offset,
113 unsigned flags);
114
115 void
116 (*commit)(struct svga_winsys_context *swc);
117
118 enum pipe_error
119 (*flush)(struct svga_winsys_context *swc,
120 struct pipe_fence_handle **pfence);
121
122 /**
123 * Context ID used to fill in the commands
124 *
125 * Context IDs are arbitrary small non-negative integers,
126 * global to the entire SVGA device.
127 */
128 uint32 cid;
129 };
130
131
132 /**
133 * SVGA per-screen winsys interface.
134 */
135 struct svga_winsys_screen
136 {
137 void
138 (*destroy)(struct svga_winsys_screen *sws);
139
140 SVGA3dHardwareVersion
141 (*get_hw_version)(struct svga_winsys_screen *sws);
142
143 boolean
144 (*get_cap)(struct svga_winsys_screen *sws,
145 SVGA3dDevCapIndex index,
146 SVGA3dDevCapResult *result);
147
148 /**
149 * Create a new context.
150 *
151 * Context objects encapsulate all render state, and shader
152 * objects are per-context.
153 *
154 * Surfaces are not per-context. The same surface can be shared
155 * between multiple contexts, and surface operations can occur
156 * without a context.
157 */
158 struct svga_winsys_context *
159 (*context_create)(struct svga_winsys_screen *sws);
160
161
162 /**
163 * This creates a "surface" object in the SVGA3D device,
164 * and returns the surface ID (sid). Surfaces are generic
165 * containers for host VRAM objects like textures, vertex
166 * buffers, and depth/stencil buffers.
167 *
168 * Surfaces are hierarchial:
169 *
170 * - Surface may have multiple faces (for cube maps)
171 *
172 * - Each face has a list of mipmap levels
173 *
174 * - Each mipmap image may have multiple volume
175 * slices, if the image is three dimensional.
176 *
177 * - Each slice is a 2D array of 'blocks'
178 *
179 * - Each block may be one or more pixels.
180 * (Usually 1, more for DXT or YUV formats.)
181 *
182 * Surfaces are generic host VRAM objects. The SVGA3D device
183 * may optimize surfaces according to the format they were
184 * created with, but this format does not limit the ways in
185 * which the surface may be used. For example, a depth surface
186 * can be used as a texture, or a floating point image may
187 * be used as a vertex buffer. Some surface usages may be
188 * lower performance, due to software emulation, but any
189 * usage should work with any surface.
190 */
191 struct svga_winsys_surface *
192 (*surface_create)(struct svga_winsys_screen *sws,
193 SVGA3dSurfaceFlags flags,
194 SVGA3dSurfaceFormat format,
195 SVGA3dSize size,
196 uint32 numFaces,
197 uint32 numMipLevels);
198
199 /**
200 * Creates a surface from a winsys handle.
201 * Used to implement pipe_screen::resource_from_handle.
202 */
203 struct svga_winsys_surface *
204 (*surface_from_handle)(struct svga_winsys_screen *sws,
205 struct winsys_handle *whandle,
206 SVGA3dSurfaceFormat *format);
207
208 /**
209 * Get a winsys_handle from a surface.
210 * Used to implement pipe_screen::resource_get_handle.
211 */
212 boolean
213 (*surface_get_handle)(struct svga_winsys_screen *sws,
214 struct svga_winsys_surface *surface,
215 unsigned stride,
216 struct winsys_handle *whandle);
217
218 /**
219 * Whether this surface is sitting in a validate list
220 */
221 boolean
222 (*surface_is_flushed)(struct svga_winsys_screen *sws,
223 struct svga_winsys_surface *surface);
224
225 /**
226 * Reference a SVGA3D surface object. This allows sharing of a
227 * surface between different objects.
228 */
229 void
230 (*surface_reference)(struct svga_winsys_screen *sws,
231 struct svga_winsys_surface **pdst,
232 struct svga_winsys_surface *src);
233
234 /**
235 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
236 *
237 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
238 *
239 * alignment indicates the client's alignment requirements, eg for
240 * SSE instructions.
241 */
242 struct svga_winsys_buffer *
243 (*buffer_create)( struct svga_winsys_screen *sws,
244 unsigned alignment,
245 unsigned usage,
246 unsigned size );
247
248 /**
249 * Map the entire data store of a buffer object into the client's address.
250 * usage is a bitmask of PIPE_TRANSFER_*
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 svga_winsys_screen *
296 svga_winsys_screen(struct pipe_screen *screen);
297
298 struct svga_winsys_context *
299 svga_winsys_context(struct pipe_context *context);
300
301 struct pipe_resource *
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_resource *buffer);
308
309 #endif /* SVGA_WINSYS_H_ */