1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
28 * VMware SVGA specific winsys interface.
30 * @author Jose Fonseca <jfonseca@vmware.com>
32 * Documentation taken from the VMware SVGA DDK.
35 #ifndef SVGA_WINSYS_H_
36 #define SVGA_WINSYS_H_
39 #include "svga_types.h"
41 #include "svga3d_reg.h"
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_defines.h"
47 struct svga_winsys_screen;
48 struct svga_winsys_buffer;
51 struct pipe_fence_handle;
57 #define SVGA_BUFFER_USAGE_PINNED (PIPE_BUFFER_USAGE_CUSTOM << 0)
58 #define SVGA_BUFFER_USAGE_WRAPPED (PIPE_BUFFER_USAGE_CUSTOM << 1)
61 /** Opaque surface handle */
62 struct svga_winsys_surface;
64 /** Opaque buffer handle */
65 struct svga_winsys_handle;
69 * SVGA per-context winsys interface.
71 struct svga_winsys_context
74 (*destroy)(struct svga_winsys_context *swc);
77 (*reserve)(struct svga_winsys_context *swc,
78 uint32_t nr_bytes, uint32_t nr_relocs );
81 * Emit a relocation for a host surface.
83 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
85 * NOTE: Order of this call does matter. It should be the same order
86 * as relocations appear in the command buffer.
89 (*surface_relocation)(struct svga_winsys_context *swc,
91 struct svga_winsys_surface *surface,
95 * Emit a relocation for a guest memory region.
97 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
99 * NOTE: Order of this call does matter. It should be the same order
100 * as relocations appear in the command buffer.
103 (*region_relocation)(struct svga_winsys_context *swc,
104 struct SVGAGuestPtr *ptr,
105 struct svga_winsys_buffer *buffer,
110 (*commit)(struct svga_winsys_context *swc);
113 (*flush)(struct svga_winsys_context *swc,
114 struct pipe_fence_handle **pfence);
117 * Context ID used to fill in the commands
119 * Context IDs are arbitrary small non-negative integers,
120 * global to the entire SVGA device.
127 * SVGA per-screen winsys interface.
129 struct svga_winsys_screen
132 (*destroy)(struct svga_winsys_screen *sws);
135 (*get_cap)(struct svga_winsys_screen *sws,
136 SVGA3dDevCapIndex index,
137 SVGA3dDevCapResult *result);
140 * Create a new context.
142 * Context objects encapsulate all render state, and shader
143 * objects are per-context.
145 * Surfaces are not per-context. The same surface can be shared
146 * between multiple contexts, and surface operations can occur
149 struct svga_winsys_context *
150 (*context_create)(struct svga_winsys_screen *sws);
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.
159 * Surfaces are hierarchial:
161 * - Surface may have multiple faces (for cube maps)
163 * - Each face has a list of mipmap levels
165 * - Each mipmap image may have multiple volume
166 * slices, if the image is three dimensional.
168 * - Each slice is a 2D array of 'blocks'
170 * - Each block may be one or more pixels.
171 * (Usually 1, more for DXT or YUV formats.)
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.
182 struct svga_winsys_surface *
183 (*surface_create)(struct svga_winsys_screen *sws,
184 SVGA3dSurfaceFlags flags,
185 SVGA3dSurfaceFormat format,
188 uint32 numMipLevels);
191 * Creates a surface from a winsys handle.
192 * Used to implement pipe_screen::texture_from_handle.
194 struct svga_winsys_surface *
195 (*surface_from_handle)(struct svga_winsys_screen *sws,
196 struct winsys_handle *whandle,
197 SVGA3dSurfaceFormat *format);
200 * Get a winsys_handle from a surface.
201 * Used to implement pipe_screen::texture_get_handle.
204 (*surface_get_handle)(struct svga_winsys_screen *sws,
205 struct svga_winsys_surface *surface,
207 struct winsys_handle *whandle);
210 * Whether this surface is sitting in a validate list
213 (*surface_is_flushed)(struct svga_winsys_screen *sws,
214 struct svga_winsys_surface *surface);
217 * Reference a SVGA3D surface object. This allows sharing of a
218 * surface between different objects.
221 (*surface_reference)(struct svga_winsys_screen *sws,
222 struct svga_winsys_surface **pdst,
223 struct svga_winsys_surface *src);
226 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
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...).
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.
236 * alignment indicates the client's alignment requirements, eg for
239 struct svga_winsys_buffer *
240 (*buffer_create)( struct svga_winsys_screen *sws,
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
253 (*buffer_map)( struct svga_winsys_screen *sws,
254 struct svga_winsys_buffer *buf,
258 (*buffer_unmap)( struct svga_winsys_screen *sws,
259 struct svga_winsys_buffer *buf );
262 (*buffer_destroy)( struct svga_winsys_screen *sws,
263 struct svga_winsys_buffer *buf );
267 * Reference a fence object.
270 (*fence_reference)( struct svga_winsys_screen *sws,
271 struct pipe_fence_handle **pdst,
272 struct pipe_fence_handle *src );
275 * Checks whether the fence has been signalled.
276 * \param flags driver-specific meaning
277 * \return zero on success.
279 int (*fence_signalled)( struct svga_winsys_screen *sws,
280 struct pipe_fence_handle *fence,
284 * Wait for the fence to finish.
285 * \param flags driver-specific meaning
286 * \return zero on success.
288 int (*fence_finish)( struct svga_winsys_screen *sws,
289 struct pipe_fence_handle *fence,
296 svga_screen_create(struct svga_winsys_screen *sws);
298 struct svga_winsys_screen *
299 svga_winsys_screen(struct pipe_screen *screen);
302 svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
303 enum SVGA3dSurfaceFormat format,
304 struct svga_winsys_surface *srf);
306 struct svga_winsys_surface *
307 svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer);
309 #endif /* SVGA_WINSYS_H_ */