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
;
56 #define SVGA_BUFFER_USAGE_PINNED (PIPE_BUFFER_USAGE_CUSTOM << 0)
57 #define SVGA_BUFFER_USAGE_WRAPPED (PIPE_BUFFER_USAGE_CUSTOM << 1)
60 /** Opaque surface handle */
61 struct svga_winsys_surface
;
63 /** Opaque buffer handle */
64 struct svga_winsys_handle
;
68 * SVGA per-context winsys interface.
70 struct svga_winsys_context
73 (*destroy
)(struct svga_winsys_context
*swc
);
76 (*reserve
)(struct svga_winsys_context
*swc
,
77 uint32_t nr_bytes
, uint32_t nr_relocs
);
80 * Emit a relocation for a host surface.
82 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
84 * NOTE: Order of this call does matter. It should be the same order
85 * as relocations appear in the command buffer.
88 (*surface_relocation
)(struct svga_winsys_context
*swc
,
90 struct svga_winsys_surface
*surface
,
94 * Emit a relocation for a guest memory region.
96 * @param flags PIPE_BUFFER_USAGE_GPU_READ/WRITE
98 * NOTE: Order of this call does matter. It should be the same order
99 * as relocations appear in the command buffer.
102 (*region_relocation
)(struct svga_winsys_context
*swc
,
103 struct SVGAGuestPtr
*ptr
,
104 struct svga_winsys_buffer
*buffer
,
109 (*commit
)(struct svga_winsys_context
*swc
);
112 (*flush
)(struct svga_winsys_context
*swc
,
113 struct pipe_fence_handle
**pfence
);
116 * Context ID used to fill in the commands
118 * Context IDs are arbitrary small non-negative integers,
119 * global to the entire SVGA device.
126 * SVGA per-screen winsys interface.
128 struct svga_winsys_screen
131 (*destroy
)(struct svga_winsys_screen
*sws
);
134 (*get_cap
)(struct svga_winsys_screen
*sws
,
135 SVGA3dDevCapIndex index
,
136 SVGA3dDevCapResult
*result
);
139 * Create a new context.
141 * Context objects encapsulate all render state, and shader
142 * objects are per-context.
144 * Surfaces are not per-context. The same surface can be shared
145 * between multiple contexts, and surface operations can occur
148 struct svga_winsys_context
*
149 (*context_create
)(struct svga_winsys_screen
*sws
);
153 * This creates a "surface" object in the SVGA3D device,
154 * and returns the surface ID (sid). Surfaces are generic
155 * containers for host VRAM objects like textures, vertex
156 * buffers, and depth/stencil buffers.
158 * Surfaces are hierarchial:
160 * - Surface may have multiple faces (for cube maps)
162 * - Each face has a list of mipmap levels
164 * - Each mipmap image may have multiple volume
165 * slices, if the image is three dimensional.
167 * - Each slice is a 2D array of 'blocks'
169 * - Each block may be one or more pixels.
170 * (Usually 1, more for DXT or YUV formats.)
172 * Surfaces are generic host VRAM objects. The SVGA3D device
173 * may optimize surfaces according to the format they were
174 * created with, but this format does not limit the ways in
175 * which the surface may be used. For example, a depth surface
176 * can be used as a texture, or a floating point image may
177 * be used as a vertex buffer. Some surface usages may be
178 * lower performance, due to software emulation, but any
179 * usage should work with any surface.
181 struct svga_winsys_surface
*
182 (*surface_create
)(struct svga_winsys_screen
*sws
,
183 SVGA3dSurfaceFlags flags
,
184 SVGA3dSurfaceFormat format
,
187 uint32 numMipLevels
);
190 * Whether this surface is sitting in a validate list
193 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
194 struct svga_winsys_surface
*surface
);
197 * Reference a SVGA3D surface object. This allows sharing of a
198 * surface between different objects.
201 (*surface_reference
)(struct svga_winsys_screen
*sws
,
202 struct svga_winsys_surface
**pdst
,
203 struct svga_winsys_surface
*src
);
206 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
208 * Remember that gallium gets to choose the interface it needs, and the
209 * window systems must then implement that interface (rather than the
210 * other way around...).
212 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
213 * usage argument is only an optimization hint, not a guarantee, therefore
214 * proper behavior must be observed in all circumstances.
216 * alignment indicates the client's alignment requirements, eg for
219 struct svga_winsys_buffer
*
220 (*buffer_create
)( struct svga_winsys_screen
*sws
,
226 * Map the entire data store of a buffer object into the client's address.
227 * flags is a bitmask of:
228 * - PIPE_BUFFER_USAGE_CPU_READ/WRITE
229 * - PIPE_BUFFER_USAGE_DONTBLOCK
230 * - PIPE_BUFFER_USAGE_UNSYNCHRONIZED
233 (*buffer_map
)( struct svga_winsys_screen
*sws
,
234 struct svga_winsys_buffer
*buf
,
238 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
239 struct svga_winsys_buffer
*buf
);
242 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
243 struct svga_winsys_buffer
*buf
);
247 * Reference a fence object.
250 (*fence_reference
)( struct svga_winsys_screen
*sws
,
251 struct pipe_fence_handle
**pdst
,
252 struct pipe_fence_handle
*src
);
255 * Checks whether the fence has been signalled.
256 * \param flags driver-specific meaning
257 * \return zero on success.
259 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
260 struct pipe_fence_handle
*fence
,
264 * Wait for the fence to finish.
265 * \param flags driver-specific meaning
266 * \return zero on success.
268 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
269 struct pipe_fence_handle
*fence
,
275 struct pipe_context
*
276 svga_context_create(struct pipe_screen
*screen
);
279 svga_screen_create(struct svga_winsys_screen
*sws
);
281 struct svga_winsys_screen
*
282 svga_winsys_screen(struct pipe_screen
*screen
);
285 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
286 enum SVGA3dSurfaceFormat format
,
287 struct svga_winsys_surface
*srf
);
289 struct svga_winsys_surface
*
290 svga_screen_texture_get_winsys_surface(struct pipe_texture
*texture
);
291 struct svga_winsys_surface
*
292 svga_screen_buffer_get_winsys_surface(struct pipe_buffer
*buffer
);
295 svga_screen_buffer_from_texture(struct pipe_texture
*texture
,
296 struct pipe_buffer
**buffer
,
299 #endif /* SVGA_WINSYS_H_ */