Squashed commit of the following:
[profile/ivi/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
65
66 /** Opaque surface handle */
67 struct svga_winsys_surface;
68
69 /** Opaque buffer handle */
70 struct svga_winsys_handle;
71
72
73 /**
74  * SVGA per-context winsys interface.
75  */
76 struct svga_winsys_context
77 {
78    void
79    (*destroy)(struct svga_winsys_context *swc);
80
81    void *       
82    (*reserve)(struct svga_winsys_context *swc, 
83               uint32_t nr_bytes, uint32_t nr_relocs );
84    
85    /**
86     * Emit a relocation for a host surface.
87     * 
88     * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
89     * 
90     * NOTE: Order of this call does matter. It should be the same order
91     * as relocations appear in the command buffer.
92     */
93    void
94    (*surface_relocation)(struct svga_winsys_context *swc, 
95                          uint32 *sid, 
96                          struct svga_winsys_surface *surface,
97                          unsigned flags);
98    
99    /**
100     * Emit a relocation for a guest memory region.
101     * 
102     * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
103     * 
104     * NOTE: Order of this call does matter. It should be the same order
105     * as relocations appear in the command buffer.
106     */
107    void
108    (*region_relocation)(struct svga_winsys_context *swc, 
109                         struct SVGAGuestPtr *ptr, 
110                         struct svga_winsys_buffer *buffer,
111                         uint32 offset,
112                         unsigned flags);
113
114    void
115    (*commit)(struct svga_winsys_context *swc);
116    
117    enum pipe_error
118    (*flush)(struct svga_winsys_context *swc, 
119             struct pipe_fence_handle **pfence);
120
121    /** 
122     * Context ID used to fill in the commands
123     * 
124     * Context IDs are arbitrary small non-negative integers,
125     * global to the entire SVGA device.
126     */
127    uint32 cid;
128 };
129
130
131 /**
132  * SVGA per-screen winsys interface.
133  */
134 struct svga_winsys_screen
135 {
136    void
137    (*destroy)(struct svga_winsys_screen *sws);
138    
139    boolean
140    (*get_cap)(struct svga_winsys_screen *sws,
141               SVGA3dDevCapIndex index,
142               SVGA3dDevCapResult *result);
143    
144    /**
145     * Create a new context.
146     *
147     * Context objects encapsulate all render state, and shader
148     * objects are per-context.
149     *
150     * Surfaces are not per-context. The same surface can be shared
151     * between multiple contexts, and surface operations can occur
152     * without a context.
153     */
154    struct svga_winsys_context *
155    (*context_create)(struct svga_winsys_screen *sws);
156    
157    
158    /**
159     * This creates a "surface" object in the SVGA3D device,
160     * and returns the surface ID (sid). Surfaces are generic
161     * containers for host VRAM objects like textures, vertex
162     * buffers, and depth/stencil buffers.
163     *
164     * Surfaces are hierarchial:
165     *
166     * - Surface may have multiple faces (for cube maps)
167     *
168     * - Each face has a list of mipmap levels
169     *
170     * - Each mipmap image may have multiple volume
171     *   slices, if the image is three dimensional.
172     *
173     * - Each slice is a 2D array of 'blocks'
174     *
175     * - Each block may be one or more pixels.
176     *   (Usually 1, more for DXT or YUV formats.)
177     *
178     * Surfaces are generic host VRAM objects. The SVGA3D device
179     * may optimize surfaces according to the format they were
180     * created with, but this format does not limit the ways in
181     * which the surface may be used. For example, a depth surface
182     * can be used as a texture, or a floating point image may
183     * be used as a vertex buffer. Some surface usages may be
184     * lower performance, due to software emulation, but any
185     * usage should work with any surface.
186     */
187    struct svga_winsys_surface *
188    (*surface_create)(struct svga_winsys_screen *sws,
189                      SVGA3dSurfaceFlags flags,
190                      SVGA3dSurfaceFormat format,
191                      SVGA3dSize size,
192                      uint32 numFaces,
193                      uint32 numMipLevels);
194
195    /**
196     * Creates a surface from a winsys handle.
197     * Used to implement pipe_screen::resource_from_handle.
198     */
199    struct svga_winsys_surface *
200    (*surface_from_handle)(struct svga_winsys_screen *sws,
201                           struct winsys_handle *whandle,
202                           SVGA3dSurfaceFormat *format);
203
204    /**
205     * Get a winsys_handle from a surface.
206     * Used to implement pipe_screen::resource_get_handle.
207     */
208    boolean
209    (*surface_get_handle)(struct svga_winsys_screen *sws,
210                          struct svga_winsys_surface *surface,
211                          unsigned stride,
212                          struct winsys_handle *whandle);
213
214    /**
215     * Whether this surface is sitting in a validate list
216     */
217    boolean
218    (*surface_is_flushed)(struct svga_winsys_screen *sws,
219                          struct svga_winsys_surface *surface);
220
221    /**
222     * Reference a SVGA3D surface object. This allows sharing of a
223     * surface between different objects.
224     */
225    void 
226    (*surface_reference)(struct svga_winsys_screen *sws,
227                         struct svga_winsys_surface **pdst,
228                         struct svga_winsys_surface *src);
229
230    /**
231     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
232     *
233     * XXX usage seems to be a bitmask of SVGA_BUFFER_USAGE_* flags.
234     *
235     * alignment indicates the client's alignment requirements, eg for
236     * SSE instructions.
237     */
238    struct svga_winsys_buffer *
239    (*buffer_create)( struct svga_winsys_screen *sws, 
240                      unsigned alignment, 
241                      unsigned usage,
242                      unsigned size );
243
244    /** 
245     * Map the entire data store of a buffer object into the client's address.
246     * flags is a bitmask of:
247     * - PB_USAGE_CPU_READ/WRITE
248     * - PB_USAGE_DONTBLOCK
249     * - PB_USAGE_UNSYNCHRONIZED
250     */
251    void *
252    (*buffer_map)( struct svga_winsys_screen *sws, 
253                   struct svga_winsys_buffer *buf,
254                   unsigned usage );
255    
256    void 
257    (*buffer_unmap)( struct svga_winsys_screen *sws, 
258                     struct svga_winsys_buffer *buf );
259
260    void 
261    (*buffer_destroy)( struct svga_winsys_screen *sws,
262                       struct svga_winsys_buffer *buf );
263
264
265    /**
266     * Reference a fence object.
267     */
268    void
269    (*fence_reference)( struct svga_winsys_screen *sws,
270                        struct pipe_fence_handle **pdst,
271                        struct pipe_fence_handle *src );
272
273    /**
274     * Checks whether the fence has been signalled.
275     * \param flags  driver-specific meaning
276     * \return zero on success.
277     */
278    int (*fence_signalled)( struct svga_winsys_screen *sws,
279                            struct pipe_fence_handle *fence,
280                            unsigned flag );
281
282    /**
283     * Wait for the fence to finish.
284     * \param flags  driver-specific meaning
285     * \return zero on success.
286     */
287    int (*fence_finish)( struct svga_winsys_screen *sws,
288                         struct pipe_fence_handle *fence,
289                         unsigned flag );
290
291 };
292
293
294 struct pipe_screen *
295 svga_screen_create(struct svga_winsys_screen *sws);
296
297 struct svga_winsys_screen *
298 svga_winsys_screen(struct pipe_screen *screen);
299
300 struct pipe_resource *
301 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
302                                 enum SVGA3dSurfaceFormat format,
303                                 struct svga_winsys_surface *srf);
304
305 struct svga_winsys_surface *
306 svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);
307
308 #endif /* SVGA_WINSYS_H_ */