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 (1 << 0)
58 #define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
61 #define SVGA_RELOC_WRITE 0x1
62 #define SVGA_RELOC_READ 0x2
66 /** Opaque surface handle */
67 struct svga_winsys_surface
;
69 /** Opaque buffer handle */
70 struct svga_winsys_handle
;
74 * SVGA per-context winsys interface.
76 struct svga_winsys_context
79 (*destroy
)(struct svga_winsys_context
*swc
);
82 (*reserve
)(struct svga_winsys_context
*swc
,
83 uint32_t nr_bytes
, uint32_t nr_relocs
);
86 * Emit a relocation for a host surface.
88 * @param flags bitmask of SVGA_RELOC_* flags
90 * NOTE: Order of this call does matter. It should be the same order
91 * as relocations appear in the command buffer.
94 (*surface_relocation
)(struct svga_winsys_context
*swc
,
96 struct svga_winsys_surface
*surface
,
100 * Emit a relocation for a guest memory region.
102 * @param flags bitmask of SVGA_RELOC_* flags
104 * NOTE: Order of this call does matter. It should be the same order
105 * as relocations appear in the command buffer.
108 (*region_relocation
)(struct svga_winsys_context
*swc
,
109 struct SVGAGuestPtr
*ptr
,
110 struct svga_winsys_buffer
*buffer
,
115 (*commit
)(struct svga_winsys_context
*swc
);
118 (*flush
)(struct svga_winsys_context
*swc
,
119 struct pipe_fence_handle
**pfence
);
122 * Context ID used to fill in the commands
124 * Context IDs are arbitrary small non-negative integers,
125 * global to the entire SVGA device.
132 * SVGA per-screen winsys interface.
134 struct svga_winsys_screen
137 (*destroy
)(struct svga_winsys_screen
*sws
);
139 SVGA3dHardwareVersion
140 (*get_hw_version
)(struct svga_winsys_screen
*sws
);
143 (*get_cap
)(struct svga_winsys_screen
*sws
,
144 SVGA3dDevCapIndex index
,
145 SVGA3dDevCapResult
*result
);
148 * Create a new context.
150 * Context objects encapsulate all render state, and shader
151 * objects are per-context.
153 * Surfaces are not per-context. The same surface can be shared
154 * between multiple contexts, and surface operations can occur
157 struct svga_winsys_context
*
158 (*context_create
)(struct svga_winsys_screen
*sws
);
162 * This creates a "surface" object in the SVGA3D device,
163 * and returns the surface ID (sid). Surfaces are generic
164 * containers for host VRAM objects like textures, vertex
165 * buffers, and depth/stencil buffers.
167 * Surfaces are hierarchial:
169 * - Surface may have multiple faces (for cube maps)
171 * - Each face has a list of mipmap levels
173 * - Each mipmap image may have multiple volume
174 * slices, if the image is three dimensional.
176 * - Each slice is a 2D array of 'blocks'
178 * - Each block may be one or more pixels.
179 * (Usually 1, more for DXT or YUV formats.)
181 * Surfaces are generic host VRAM objects. The SVGA3D device
182 * may optimize surfaces according to the format they were
183 * created with, but this format does not limit the ways in
184 * which the surface may be used. For example, a depth surface
185 * can be used as a texture, or a floating point image may
186 * be used as a vertex buffer. Some surface usages may be
187 * lower performance, due to software emulation, but any
188 * usage should work with any surface.
190 struct svga_winsys_surface
*
191 (*surface_create
)(struct svga_winsys_screen
*sws
,
192 SVGA3dSurfaceFlags flags
,
193 SVGA3dSurfaceFormat format
,
196 uint32 numMipLevels
);
199 * Creates a surface from a winsys handle.
200 * Used to implement pipe_screen::resource_from_handle.
202 struct svga_winsys_surface
*
203 (*surface_from_handle
)(struct svga_winsys_screen
*sws
,
204 struct winsys_handle
*whandle
,
205 SVGA3dSurfaceFormat
*format
);
208 * Get a winsys_handle from a surface.
209 * Used to implement pipe_screen::resource_get_handle.
212 (*surface_get_handle
)(struct svga_winsys_screen
*sws
,
213 struct svga_winsys_surface
*surface
,
215 struct winsys_handle
*whandle
);
218 * Whether this surface is sitting in a validate list
221 (*surface_is_flushed
)(struct svga_winsys_screen
*sws
,
222 struct svga_winsys_surface
*surface
);
225 * Reference a SVGA3D surface object. This allows sharing of a
226 * surface between different objects.
229 (*surface_reference
)(struct svga_winsys_screen
*sws
,
230 struct svga_winsys_surface
**pdst
,
231 struct svga_winsys_surface
*src
);
234 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
236 * @param usage bitmask of SVGA_BUFFER_USAGE_* flags.
238 * alignment indicates the client's alignment requirements, eg for
241 struct svga_winsys_buffer
*
242 (*buffer_create
)( struct svga_winsys_screen
*sws
,
248 * Map the entire data store of a buffer object into the client's address.
249 * usage is a bitmask of PIPE_TRANSFER_*
252 (*buffer_map
)( struct svga_winsys_screen
*sws
,
253 struct svga_winsys_buffer
*buf
,
257 (*buffer_unmap
)( struct svga_winsys_screen
*sws
,
258 struct svga_winsys_buffer
*buf
);
261 (*buffer_destroy
)( struct svga_winsys_screen
*sws
,
262 struct svga_winsys_buffer
*buf
);
266 * Reference a fence object.
269 (*fence_reference
)( struct svga_winsys_screen
*sws
,
270 struct pipe_fence_handle
**pdst
,
271 struct pipe_fence_handle
*src
);
274 * Checks whether the fence has been signalled.
275 * \param flags driver-specific meaning
276 * \return zero on success.
278 int (*fence_signalled
)( struct svga_winsys_screen
*sws
,
279 struct pipe_fence_handle
*fence
,
283 * Wait for the fence to finish.
284 * \param flags driver-specific meaning
285 * \return zero on success.
287 int (*fence_finish
)( struct svga_winsys_screen
*sws
,
288 struct pipe_fence_handle
*fence
,
294 struct svga_winsys_screen
*
295 svga_winsys_screen(struct pipe_screen
*screen
);
297 struct svga_winsys_context
*
298 svga_winsys_context(struct pipe_context
*context
);
300 struct pipe_resource
*
301 svga_screen_buffer_wrap_surface(struct pipe_screen
*screen
,
302 enum SVGA3dSurfaceFormat format
,
303 struct svga_winsys_surface
*srf
);
305 struct svga_winsys_surface
*
306 svga_screen_buffer_get_winsys_surface(struct pipe_resource
*buffer
);
308 #endif /* SVGA_WINSYS_H_ */